Compare commits

..

No commits in common. "83e2dc54685acc6c6d4501abd2ad786866bf3649" and "f3848d2d5208f7a36773f5b77e0321f758d4015b" have entirely different histories.

9 changed files with 34 additions and 30 deletions

View File

@ -16,10 +16,10 @@ typedef struct Context {
void *udata;
/* which frame is it, starting from 0 at startup */
float frame_number;
uint64_t frame_number;
/* real time spent on one frame (in seconds) */
/* townengine is fixed step based, so you don't have to use delta */
/* townengine is fixed step based, so you don't have */
/* 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 */
float random_seed;
uint64_t random_seed;
/* whether debugging logic should be enabled in user code */
bool debug;

View File

@ -22,6 +22,16 @@ 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;
@ -39,5 +49,10 @@ typedef struct Rect {
float h;
} Rect;
/* TODO: remove from here? */
typedef struct Matrix4 {
Vec4 row[4];
} Matrix4;
#endif

View File

@ -239,6 +239,16 @@
"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" },

View File

@ -19,7 +19,7 @@ static void (*game_end_callback)(void);
static x_watcher *watcher;
static void *handle = NULL;
static float last_tick_modified;
static uint64_t 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 (fabsf(0.0f - ctx.game.frame_number) > 0.00001f)
if (ctx.game.frame_number != 0)
log_info("Game object was reloaded\n");
return;

View File

@ -4,7 +4,6 @@
/* 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"

View File

@ -20,7 +20,7 @@ void start_render_frame(void) {
void end_render_frame(void) {
if (!ctx.render_double_buffered || (fabsf(1.0f - ctx.game.frame_number) < 0.00001f)) {
if (!ctx.render_double_buffered || ctx.game.frame_number == 1) {
issue_deferred_draw_commands();
SDL_GL_SwapWindow(ctx.window);
arrsetlen(deferred_commands, 0);

View File

@ -2,7 +2,6 @@
#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 */

View File

@ -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 = (ctx.game.frame_number % ULLONG_MAX) + 1;
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 = (float)(SDL_GetPerformanceCounter() % 16777216);
ctx.game.random_seed = SDL_GetPerformanceCounter();
srand((unsigned int)ctx.game.random_seed);
stbds_rand_seed((size_t)ctx.game.random_seed);
stbds_rand_seed(ctx.game.random_seed);
/* main loop machinery */
toml_datum_t datum_ticks_per_second = toml_int_in(engine, "ticks_per_second");

View File

@ -1,19 +0,0 @@
#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