Compare commits
2 Commits
f3848d2d52
...
83e2dc5468
Author | SHA1 | Date | |
---|---|---|---|
|
83e2dc5468 | ||
|
951d9c76c8 |
@ -16,10 +16,10 @@ typedef struct Context {
|
||||
void *udata;
|
||||
|
||||
/* which frame is it, starting from 0 at startup */
|
||||
uint64_t frame_number;
|
||||
float frame_number;
|
||||
|
||||
/* real time spent on one frame (in seconds) */
|
||||
/* townengine is fixed step based, so you don't have */
|
||||
/* townengine is fixed step based, so you don't have to use delta */
|
||||
/* TODO: actually set it */
|
||||
float frame_duration;
|
||||
|
||||
@ -30,7 +30,7 @@ typedef struct Context {
|
||||
Vec2 mouse_movement;
|
||||
|
||||
/* is set on startup, should be used as source of randomness */
|
||||
uint64_t random_seed;
|
||||
float random_seed;
|
||||
|
||||
/* whether debugging logic should be enabled in user code */
|
||||
bool debug;
|
||||
|
@ -22,16 +22,6 @@ typedef struct Vec3 {
|
||||
} Vec3;
|
||||
|
||||
|
||||
/* a point in some three dimension space (floating point) */
|
||||
/* y goes up, x goes to the right */
|
||||
typedef struct Vec4 {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
} Vec4;
|
||||
|
||||
|
||||
/* 32-bit color data */
|
||||
typedef struct Color {
|
||||
uint8_t r;
|
||||
@ -49,10 +39,5 @@ typedef struct Rect {
|
||||
float h;
|
||||
} Rect;
|
||||
|
||||
/* TODO: remove from here? */
|
||||
typedef struct Matrix4 {
|
||||
Vec4 row[4];
|
||||
} Matrix4;
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -239,16 +239,6 @@
|
||||
"c_type": "Vec3"
|
||||
},
|
||||
|
||||
"Vec4": {
|
||||
"fields": [
|
||||
{ "name": "x", "type": "float" },
|
||||
{ "name": "y", "type": "float" },
|
||||
{ "name": "z", "type": "float" },
|
||||
{ "name": "w", "type": "float" }
|
||||
],
|
||||
"c_type": "Vec4"
|
||||
},
|
||||
|
||||
"Color": {
|
||||
"fields": [
|
||||
{ "name": "r", "type": "uint8_t" },
|
||||
|
@ -19,7 +19,7 @@ static void (*game_end_callback)(void);
|
||||
static x_watcher *watcher;
|
||||
static void *handle = NULL;
|
||||
|
||||
static uint64_t last_tick_modified;
|
||||
static float last_tick_modified;
|
||||
static bool loaded_after_modification = true;
|
||||
static SDL_mutex *lock;
|
||||
|
||||
@ -59,7 +59,7 @@ static void load_game_object(void) {
|
||||
|
||||
handle = new_handle;
|
||||
|
||||
if (ctx.game.frame_number != 0)
|
||||
if (fabsf(0.0f - ctx.game.frame_number) > 0.00001f)
|
||||
log_info("Game object was reloaded\n");
|
||||
|
||||
return;
|
||||
|
@ -4,6 +4,7 @@
|
||||
/* TODO: structure more categorically */
|
||||
|
||||
#include "twn_textures_c.h"
|
||||
#include "twn_types_c.h"
|
||||
#include "twn_text_c.h"
|
||||
#include "twn_option.h"
|
||||
#include "twn_deferred_commands.h"
|
||||
|
@ -20,7 +20,7 @@ void start_render_frame(void) {
|
||||
|
||||
|
||||
void end_render_frame(void) {
|
||||
if (!ctx.render_double_buffered || ctx.game.frame_number == 1) {
|
||||
if (!ctx.render_double_buffered || (fabsf(1.0f - ctx.game.frame_number) < 0.00001f)) {
|
||||
issue_deferred_draw_commands();
|
||||
SDL_GL_SwapWindow(ctx.window);
|
||||
arrsetlen(deferred_commands, 0);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define TWN_CAMERA_H
|
||||
|
||||
#include "twn_types.h"
|
||||
#include "twn_types_c.h"
|
||||
|
||||
/* TODO: make it cached? */
|
||||
/* for example, perspective matrix only needs recaluclation on FOV change */
|
||||
|
@ -236,7 +236,7 @@ static void main_loop(void) {
|
||||
preserve_persistent_ctx_fields();
|
||||
|
||||
ctx.frame_accumulator -= ctx.desired_frametime;
|
||||
ctx.game.frame_number = (ctx.game.frame_number % ULLONG_MAX) + 1;
|
||||
ctx.game.frame_number++;
|
||||
ctx.game.initialization_needed = false;
|
||||
}
|
||||
}
|
||||
@ -584,9 +584,9 @@ static bool initialize(void) {
|
||||
/* random seeding */
|
||||
/* SDL_GetPerformanceCounter returns some platform-dependent number. */
|
||||
/* it should vary between game instances. i checked! random enough for me. */
|
||||
ctx.game.random_seed = SDL_GetPerformanceCounter();
|
||||
ctx.game.random_seed = (float)(SDL_GetPerformanceCounter() % 16777216);
|
||||
srand((unsigned int)ctx.game.random_seed);
|
||||
stbds_rand_seed(ctx.game.random_seed);
|
||||
stbds_rand_seed((size_t)ctx.game.random_seed);
|
||||
|
||||
/* main loop machinery */
|
||||
toml_datum_t datum_ticks_per_second = toml_int_in(engine, "ticks_per_second");
|
||||
|
19
src/twn_types_c.h
Normal file
19
src/twn_types_c.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef TWN_TYPES_C_H
|
||||
#define TWN_TYPES_C_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct Vec4 {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float w;
|
||||
} Vec4;
|
||||
|
||||
|
||||
typedef struct Matrix4 {
|
||||
Vec4 row[4];
|
||||
} Matrix4;
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user