Files
librefront/src/client/client.c
T
2025-09-09 10:05:07 +02:00

93 lines
2.1 KiB
C

/*
LibreFront --- an OpenFront clone
Copyright (C) 2025 Adrien Jaguenet
Copyright (C) 2025 Emil Kosz
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define SDL_MAIN_USE_CALLBACKS 1
#include <stdlib.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <glib-2.0/glib.h>
#include <common/util.h>
#include <client/gfx_context.h>
static GfxContext *gfx_ctx;
SDL_AppResult
SDL_AppInit (void **appstate, int argc, char **argv)
{
UNUSED (appstate, argc, argv);
/* Makes GLib use less dumb useless shit. */
setenv ("GIO_USE_VFS", "local", 1);
setenv ("GSETTINGS_BACKEND", "memory", 1);
/* This is set in the Makefile. By default it's 1, so we get all the
debug messages printed. */
#ifdef DEBUG
setenv ("G_MESSAGES_DEBUG", "all", 1);
#endif
SDL_SetAppMetadata (GAME_NAME, GAME_VERSION, GAME_URL);
if (!SDL_Init (SDL_INIT_VIDEO))
{
g_error ("Couldn't initialize SDL: %s", SDL_GetError ());
}
gfx_ctx = GfxContext_new ();
return SDL_APP_CONTINUE;
}
SDL_AppResult
SDL_AppEvent (void *appstate, SDL_Event *event)
{
UNUSED (appstate);
if (event->type == SDL_EVENT_QUIT)
{
return SDL_APP_SUCCESS;
}
return SDL_APP_CONTINUE;
}
SDL_AppResult
SDL_AppIterate (void *appstate)
{
UNUSED (appstate);
GfxContext_prerender (gfx_ctx);
GfxContext_postrender (gfx_ctx);
return SDL_APP_CONTINUE;
}
void
SDL_AppQuit (void *appstate, SDL_AppResult result)
{
UNUSED (appstate, result);
GfxContext_free (gfx_ctx);
}