rework to context: now there's engine and user code copies, renaming of fields, most things that shouldn't be there are hidden

This commit is contained in:
2024-10-12 20:24:47 +03:00
parent 7886650339
commit e70366f82f
14 changed files with 106 additions and 97 deletions

View File

@ -8,40 +8,39 @@
#include <stdint.h>
/* context that is valid for current frame */
/* changes to it should not have an effect, unless specified */
/* TODO: ensure the statement above */
/* context that is only valid for current frame */
/* any changes to it will be dropped, unless explicitly stated */
typedef struct Context {
/* you may read from and write to these from game code */
/* you may read from and write to this one from game code */
/* it is ensured to persist between initializations */
void *udata;
/* TODO: is it what we actually want? */
int64_t delta_time; /* preserves real time frame delta with no manipilation */
uint64_t tick_count;
/* which frame is it, starting from 0 at startup */
uint64_t frame_number;
Vec2i mouse_window_position;
Vec2i mouse_relative_position;
/* real time spent on one frame (in seconds) */
/* townengine is fixed step based, so you don't have */
/* TODO: actually set it */
float frame_duration;
/* set just once on startup */
/* resolution is set from config and dictates both logical and drawing space, as they're related */
/* even if scaling is done, game logic should never change over that */
Vec2i resolution;
Vec2i mouse_position;
Vec2i mouse_movement;
/* is set on startup, should be used as source of randomness */
uint64_t random_seed;
/* this should be a multiple of the current ticks per second */
/* use it to simulate low framerate (e.g. at 60 tps, set to 2 for 30 fps) */
/* it can be changed at runtime; any resulting logic anomalies are bugs */
unsigned int update_multiplicity;
/* TODO: use Vec2i? */
int window_w;
int window_h;
int base_draw_w;
int base_draw_h;
/* whether debugging logic should be enabled in user code */
bool debug;
bool is_running;
bool window_size_has_changed;
/* is set to true when state is invalidated and needs to be rebuilt */
/* watch for it and handle properly! */
bool initialization_needed;
} Context;
/* when included after twn_engine_context there's an 'ctx' defined already */
#ifndef TWN_ENGINE_CONTEXT_C_H
TWN_API extern Context ctx;
#endif

View File

@ -1,6 +1,6 @@
/* include this header in game code to get the usable parts of the engine */
#ifndef GAME_API_H
#define GAME_API_H
#ifndef TWN_GAME_API_H
#define TWN_GAME_API_H
#include "twn_context.h"

View File

@ -1,5 +1,5 @@
#ifndef UTIL_H
#define UTIL_H
#ifndef TWN_UTIL_H
#define TWN_UTIL_H
#include "twn_types.h"
#include "twn_engine_api.h"