diff options
Diffstat (limited to 'kon/konprogram.h')
| -rw-r--r-- | kon/konprogram.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/kon/konprogram.h b/kon/konprogram.h new file mode 100644 index 0000000..f0a29b3 --- /dev/null +++ b/kon/konprogram.h @@ -0,0 +1,83 @@ +/* SPDX-License-Identifier: MIT */ +/* + * konprogram.h + * + * Copyright (c) 2026 KonAki + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef KONPROGRAM_H +#define KONPROGRAM_H + +#include <stdint.h> + +#include "konwinlib.h" +#include "konsofren.h" +#include "konpack.h" +#include "konassets.h" +#include "konfont.h" +#include "kondebug.h" + +/*** definition ***/ + +typedef struct kon_program kon_program_t; + +/* every field can be left at 0. the callbacks are all optional too */ +typedef struct kon_programConfig { + const char *title; /* "konengine" */ + int gameWidth, gameHeight; /* the size you draw at, 320 x 180 */ + int windowWidth, windowHeight; /* 3 times the game size */ + const char *assetDir; /* folder with loose files, "assets". only used with KON_DEVELOPER */ + const char *packPath; /* pack file to read assets from, none if NULL */ + void *user; /* given back to every callback */ + + /* return 0 to quit before the loop starts */ + int (*init)(kon_program_t *program, void *user); + /* gets every event the console didn't take, resizes are already handled. return 1 if you used it */ + int (*event)(kon_program_t *program, const kon_event_t *event, void *user); + void (*update)(kon_program_t *program, double dt, void *user); + /* draw into the game framebuffer, it is scaled to the window afterwards */ + void (*draw)(kon_program_t *program, kon_framebuffer_t *game, void *user); + /* draw at window resolution on top of the scaled game, for text and UI that has to stay sharp */ + void (*drawScreen)(kon_program_t *program, kon_framebuffer_t *screen, void *user); + void (*shutdown)(kon_program_t *program, void *user); +} kon_programConfig_t; + +/* what is not built is NULL, so assets is NULL without the assets module and debug is NULL without the debug module. + font is the font.ttf from your assets if there is one, otherwise the built in one, and it is NULL without the font module */ +struct kon_program { + kon_window_t *window; + kon_display_t *display; + kon_pack_t *pack; + kon_assets_t *assets; + kon_font_t *font; + kon_debug_t *debug; + double time; /* seconds since the loop started */ +}; + +/*** declarations ***/ + +/* does everything from opening the window to cleaning up and returns when the program is closed. + returns 0, or 1 if something failed to start. a program that wants its own loop doesn't need this */ +int kon_programRun(const kon_programConfig_t *config); + +void kon_programQuit(kon_program_t *program); + +#endif |
