summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
m---------external/STC0
-rw-r--r--include/rodeo.h6
-rw-r--r--src/rodeo.c38
-rw-r--r--src/rodeo_internal.h3
-rw-r--r--src/rodeo_internal_types.h2
-rw-r--r--src/rodeo_log.c11
-rw-r--r--src/rodeo_string.c13
7 files changed, 43 insertions, 30 deletions
diff --git a/external/STC b/external/STC
-Subproject bdbfc5dcbddc52c8bea5dc1a99464b2de724157
+Subproject 554f3e8acf7855b5d6a90cc68cefb7445460b03
diff --git a/include/rodeo.h b/include/rodeo.h
index a0ffb08..c261cc7 100644
--- a/include/rodeo.h
+++ b/include/rodeo.h
@@ -147,6 +147,9 @@ rodeo_string_clone(const rodeo_string_t self);
rodeo_string_t
rodeo_string_format(const char *format, ...);
+rodeo_string_t
+rodeo_string_vargs_format(const char *format, va_list vargs);
+
/// --- Log ---
void
@@ -170,6 +173,9 @@ rodeo_frame_persecond_get(void);
void
rodeo_frame_limit_set(uint32_t limit);
+uint32_t
+rodeo_frame_limit_get(void);
+
/// --- Input ---
int32_t
diff --git a/src/rodeo.c b/src/rodeo.c
index 225548e..24c6a4d 100644
--- a/src/rodeo.c
+++ b/src/rodeo.c
@@ -125,7 +125,7 @@ rodeo_window_init(
//init.type = BGFX_RENDERER_TYPE_OPENGL; // force opengl renderer
init.resolution.width = state.screen_width;
init.resolution.height = state.screen_height;
- //init.resolution.reset = BGFX_RESET_VSYNC;
+ init.resolution.reset = BGFX_RESET_VSYNC;
init.platformData = pd;
bgfx_init(&init);
@@ -151,7 +151,6 @@ rodeo_window_init(
state.index_buffer_handle = bgfx_create_dynamic_index_buffer((mrodeo_vertex_size_max / 4) * 6, BGFX_BUFFER_NONE);
// load shaders
- //const char* shader_path = "???";
rodeo_string_t shader_path = rodeo_string_create("???");
switch(bgfx_get_renderer_type()) {
case BGFX_RENDERER_TYPE_NOOP:
@@ -175,7 +174,7 @@ rodeo_window_init(
default:
rodeo_log(
rodeo_loglevel_error,
- "No shaders compiled for BGFX renderer chosen."
+ "No shaders implemented for BGFX renderer chosen."
);
exit(EXIT_FAILURE);
}
@@ -435,8 +434,8 @@ irodeo_shader_load(const rodeo_string_t path)
bgfx_shader_handle_t shader = bgfx_create_shader(mem);
rodeo_log(
rodeo_loglevel_info,
- "Shader loaded with idx: %hu",
- (uint8_t)shader.idx
+ "Shader loaded with idx: %"PRIu8"",
+ shader.idx
);
return shader;
@@ -457,7 +456,7 @@ rodeo_frame_time_get(void)
float
rodeo_frame_persecond_get(void)
{
- return 1.0f / (state.frame_time / 1000.0f);
+ return 1.0f / (rodeo_frame_time_get() / 1000.0f);
}
void
@@ -469,7 +468,7 @@ rodeo_frame_limit_set(uint32_t limit)
"Framerate limit cannot be set on web platform. Limit is enforced by platform to 60fps"
);
#else
- state.target_framerate = limit;
+ state.frame_limit = limit;
#endif
}
@@ -479,10 +478,13 @@ rodeo_frame_limit_get(void)
#ifdef __EMSCRIPTEN__
return 60;
#else
- return state.target_framerate;
+ return state.frame_limit;
#endif
}
+// measures how much time there is left in the remaining frame until
+// the frame target time is reached. If we surpassed the target time
+// then this will be negative
float
irodeo_frame_remaining_get(void)
{
@@ -502,34 +504,24 @@ irodeo_frame_remaining_get(void)
void
irodeo_frame_stall(void)
{
+ // if no frame limit then run as fast as possible
if(rodeo_frame_limit_get() == 0)
{
return;
}
+
+ // sleep isnt perfectly accurate so we sleep for a slightly shorter
+ // amount of time
float stall_time = irodeo_frame_remaining_get();
- printf(
- "%.001f time left of stall\n",
- stall_time
- );
if(stall_time > 0.0005)
{
SDL_Delay(stall_time * 0.9995);
}
+ // then we spinlock for the small remaining amount of time
stall_time = irodeo_frame_remaining_get();
-
while(stall_time > 0.0005) {
stall_time = irodeo_frame_remaining_get();
- printf(
- "%.001f time left of stall\n",
- stall_time
- );
- //rodeo_log(
- // rodeo_loglevel_info,
- // "%.001f time left of stall",
- // stall_time
- //);
}
- printf("frame complete\n");
}
diff --git a/src/rodeo_internal.h b/src/rodeo_internal.h
index 10cade7..576bc9b 100644
--- a/src/rodeo_internal.h
+++ b/src/rodeo_internal.h
@@ -6,5 +6,8 @@ bgfx_shader_handle_t
irodeo_\
shader_load(const rodeo_string_t path);
+float
+irodeo_frame_remaining_get(void);
+
void
irodeo_frame_stall(void);
diff --git a/src/rodeo_internal_types.h b/src/rodeo_internal_types.h
index aa091c6..82a3140 100644
--- a/src/rodeo_internal_types.h
+++ b/src/rodeo_internal_types.h
@@ -38,6 +38,6 @@ typedef struct
uint64_t start_frame;
uint64_t end_frame;
float frame_time;
- uint32_t target_framerate;
+ uint32_t frame_limit;
}
irodeo_state_t;
diff --git a/src/rodeo_log.c b/src/rodeo_log.c
index e9976ce..1a37ffe 100644
--- a/src/rodeo_log.c
+++ b/src/rodeo_log.c
@@ -1,8 +1,11 @@
-// public external
+// public internal
#include "rodeo_types.h"
#include "rodeo.h"
+// external
+#include "SDL2/SDL.h"
+
static rodeo_log_function logging_function = NULL;
void
@@ -15,9 +18,7 @@ rodeo_log(
rodeo_string_t formatted;
mrodeo_vargs_do(format)
{
- formatted = rodeo_string_format(format, vargs);
- printf("%s\n", rodeo_string_to_cstr(&formatted));
- printf(rodeo_string_to_cstr(&formatted));
+ formatted = rodeo_string_vargs_format(format, vargs);
}
switch(loglevel)
@@ -48,7 +49,7 @@ rodeo_log(
if(logging_function == NULL)
{
- printf("%s", rodeo_string_to_constcstr(&formatted));
+ printf("%s", rodeo_string_to_constcstr(&formatted));
}
else
{
diff --git a/src/rodeo_string.c b/src/rodeo_string.c
index a0a08a1..8e82b6b 100644
--- a/src/rodeo_string.c
+++ b/src/rodeo_string.c
@@ -6,10 +6,13 @@
// external
#define i_implement
#include "stc/cstr.h"
+#include "SDL2/SDL.h"
// system
#include <stdarg.h>
+// TODO: the create and destroy functions arent actually used together.
+// one is a pointer and the other isnt
rodeo_string_t
rodeo_string_create(const char *c_string)
{
@@ -104,9 +107,17 @@ rodeo_string_format(const char *format, ...)
rodeo_string_t result;
mrodeo_vargs_do(format)
{
- cstr temp = cstr_from_fmt(format, vargs);
+ cstr temp = cstr_from_vfmt(format, vargs);
result = *(rodeo_string_t*)&temp;
}
return result;
}
+rodeo_string_t
+rodeo_string_vargs_format(const char *format, va_list vargs)
+{
+ cstr temp = cstr_from_vfmt(format, vargs);
+ rodeo_string_t result = *(rodeo_string_t*)&temp;
+ return result;
+}
+