2024-09-16 13:17:00 +00:00
|
|
|
#ifndef TWN_ENGINE_CONTEXT_C_H
|
|
|
|
#define TWN_ENGINE_CONTEXT_C_H
|
2024-07-08 00:44:20 +00:00
|
|
|
|
2024-09-16 06:07:01 +00:00
|
|
|
#include "twn_context.h"
|
2024-09-16 13:17:00 +00:00
|
|
|
#include "twn_textures_c.h"
|
2024-09-23 17:43:16 +00:00
|
|
|
#include "twn_audio_c.h"
|
2024-09-18 17:36:00 +00:00
|
|
|
#include "twn_engine_api.h"
|
2024-09-16 13:17:00 +00:00
|
|
|
#include "rendering/twn_rendering_c.h"
|
2024-07-08 00:44:20 +00:00
|
|
|
|
|
|
|
#include <SDL2/SDL.h>
|
2024-10-01 00:13:58 +00:00
|
|
|
#include <toml.h>
|
2024-07-08 00:44:20 +00:00
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
2024-09-23 17:43:16 +00:00
|
|
|
typedef struct EngineContext {
|
2024-09-16 13:17:00 +00:00
|
|
|
/* user code facing context */
|
2024-09-23 17:43:16 +00:00
|
|
|
Context game;
|
2024-09-16 06:07:01 +00:00
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
/* the program's actual argc and argv */
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
2024-10-07 10:22:25 +00:00
|
|
|
/* where the app was run from, used as the root for packs */
|
|
|
|
char *base_dir;
|
2024-07-08 00:44:20 +00:00
|
|
|
|
2024-10-01 00:13:58 +00:00
|
|
|
/* configuration */
|
|
|
|
toml_table_t *config_table;
|
|
|
|
int64_t base_render_width;
|
|
|
|
int64_t base_render_height;
|
|
|
|
int64_t ticks_per_second;
|
|
|
|
int64_t keybind_slots;
|
|
|
|
int64_t texture_atlas_size;
|
|
|
|
int64_t font_texture_size;
|
|
|
|
int64_t font_oversampling;
|
|
|
|
TextureFilter font_filtering;
|
|
|
|
|
|
|
|
/* rendering */
|
|
|
|
Primitive2D *render_queue_2d;
|
2024-09-23 17:43:16 +00:00
|
|
|
MeshBatchItem *uncolored_mesh_batches;
|
2024-10-01 00:13:58 +00:00
|
|
|
TextCache text_cache;
|
2024-09-23 17:43:16 +00:00
|
|
|
TextureCache texture_cache;
|
2024-07-10 16:15:28 +00:00
|
|
|
|
2024-10-01 00:13:58 +00:00
|
|
|
/* audio */
|
2024-09-23 17:43:16 +00:00
|
|
|
AudioChannelItem *audio_channels;
|
2024-07-08 06:46:12 +00:00
|
|
|
SDL_AudioDeviceID audio_device;
|
|
|
|
int audio_stream_frequency;
|
|
|
|
SDL_AudioFormat audio_stream_format;
|
|
|
|
uint8_t audio_stream_channel_count;
|
2024-07-08 00:44:20 +00:00
|
|
|
|
|
|
|
/* main loop machinery */
|
|
|
|
int64_t clocks_per_second;
|
|
|
|
int64_t prev_frame_time;
|
|
|
|
int64_t desired_frametime; /* how long one tick should be */
|
|
|
|
int64_t frame_accumulator;
|
2024-07-16 02:31:54 +00:00
|
|
|
int64_t delta_averager_residual;
|
2024-07-08 00:44:20 +00:00
|
|
|
int64_t time_averager[4];
|
|
|
|
|
2024-07-09 12:35:54 +00:00
|
|
|
SDL_GLContext *gl_context;
|
2024-07-08 00:44:20 +00:00
|
|
|
SDL_Window *window;
|
|
|
|
uint32_t window_id;
|
2024-07-30 15:19:04 +00:00
|
|
|
|
2024-07-08 00:44:20 +00:00
|
|
|
bool resync_flag;
|
2024-07-30 15:19:04 +00:00
|
|
|
bool was_successful;
|
2024-09-23 17:43:16 +00:00
|
|
|
} EngineContext;
|
2024-07-08 00:44:20 +00:00
|
|
|
|
2024-09-23 17:43:16 +00:00
|
|
|
TWN_API extern EngineContext ctx;
|
2024-07-08 00:44:20 +00:00
|
|
|
|
|
|
|
#endif
|