2024-09-16 06:07:01 +00:00
|
|
|
#ifndef TWN_CONTEXT_H
|
|
|
|
#define TWN_CONTEXT_H
|
|
|
|
|
|
|
|
#include "twn_input.h"
|
|
|
|
#include "twn_engine_api.h"
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
2024-10-12 17:24:47 +00:00
|
|
|
/* context that is only valid for current frame */
|
|
|
|
/* any changes to it will be dropped, unless explicitly stated */
|
2024-09-23 17:43:16 +00:00
|
|
|
typedef struct Context {
|
2024-10-12 17:24:47 +00:00
|
|
|
/* you may read from and write to this one from game code */
|
|
|
|
/* it is ensured to persist between initializations */
|
2024-10-08 07:12:30 +00:00
|
|
|
void *udata;
|
2024-09-16 06:07:01 +00:00
|
|
|
|
2024-10-12 17:24:47 +00:00
|
|
|
/* which frame is it, starting from 0 at startup */
|
|
|
|
uint64_t frame_number;
|
2024-09-16 06:07:01 +00:00
|
|
|
|
2024-10-12 17:24:47 +00:00
|
|
|
/* 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;
|
2024-10-08 07:12:30 +00:00
|
|
|
|
2024-10-12 17:24:47 +00:00
|
|
|
/* 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;
|
2024-10-08 07:12:30 +00:00
|
|
|
|
2024-10-12 17:24:47 +00:00
|
|
|
/* is set on startup, should be used as source of randomness */
|
|
|
|
uint64_t random_seed;
|
2024-09-16 06:07:01 +00:00
|
|
|
|
2024-10-12 17:24:47 +00:00
|
|
|
/* whether debugging logic should be enabled in user code */
|
2024-09-16 06:07:01 +00:00
|
|
|
bool debug;
|
2024-10-12 17:24:47 +00:00
|
|
|
|
|
|
|
/* is set to true when state is invalidated and needs to be rebuilt */
|
|
|
|
/* watch for it and handle properly! */
|
2024-09-16 06:07:01 +00:00
|
|
|
bool initialization_needed;
|
2024-09-23 17:43:16 +00:00
|
|
|
} Context;
|
2024-09-16 06:07:01 +00:00
|
|
|
|
2024-10-12 17:24:47 +00:00
|
|
|
/* when included after twn_engine_context there's an 'ctx' defined already */
|
2024-09-16 13:17:00 +00:00
|
|
|
#ifndef TWN_ENGINE_CONTEXT_C_H
|
2024-09-23 17:43:16 +00:00
|
|
|
TWN_API extern Context ctx;
|
2024-09-16 13:17:00 +00:00
|
|
|
#endif
|
2024-09-16 06:07:01 +00:00
|
|
|
|
|
|
|
#endif
|