disable vsync again

efd/v1
Dominik Madarász 2022-10-17 18:28:18 +02:00
parent 0d58d5f315
commit 3f6235e8a4
3 changed files with 53 additions and 53 deletions

View File

@ -36,7 +36,7 @@ void debug_push_line(debug_v2 a, debug_v2 b, int32_t color) {
debug_push_entry((debug_draw_entry){ debug_push_entry((debug_draw_entry){
.kind = DDRAW_LINE, .kind = DDRAW_LINE,
.color = color, .color = color,
.a = a, .a = a,
.b = b, .b = b,
}); });
@ -46,7 +46,7 @@ void debug_push_circle(debug_v2 pos, float radius, int32_t color) {
debug_push_entry((debug_draw_entry){ debug_push_entry((debug_draw_entry){
.kind = DDRAW_CIRCLE, .kind = DDRAW_CIRCLE,
.color = color, .color = color,
.pos = pos, .pos = pos,
.radius = radius, .radius = radius,
}); });
@ -56,7 +56,7 @@ void debug_push_rect(debug_v2 bmin, debug_v2 bmax, int32_t color) {
debug_push_entry((debug_draw_entry){ debug_push_entry((debug_draw_entry){
.kind = DDRAW_RECT, .kind = DDRAW_RECT,
.color = color, .color = color,
.bmin = bmin, .bmin = bmin,
.bmax = bmax, .bmax = bmax,
}); });

View File

@ -3,17 +3,17 @@
#include "models/assets.h" #include "models/assets.h"
#define ecs_get_mut_ex(world, entity, T) \ #define ecs_get_mut_ex(world, entity, T) \
(ECS_CAST(T*, world_component_cached(world, entity, ecs_id(T)))) (ECS_CAST(T*, world_component_cached(world, entity, ecs_id(T))))
#define ecs_get_if(world, entity, T) \ #define ecs_get_if(world, entity, T) \
(world_entity_valid(entity) ? ecs_get(world, entity, T) : NULL) (world_entity_valid(entity) ? ecs_get(world, entity, T) : NULL)
#define ecs_get_mut_if_ex(world, entity, component) \ #define ecs_get_mut_if_ex(world, entity, component) \
(ecs_get_if(world, entity, component) ? ecs_get_mut_ex(world, entity, component) : NULL) (ecs_get_if(world, entity, component) ? ecs_get_mut_ex(world, entity, component) : NULL)
#ifndef ecs_get_mut_if #ifndef ecs_get_mut_if
#define ecs_get_mut_if(world, entity, component)\ #define ecs_get_mut_if(world, entity, component)\
(ecs_get(world, entity, component) ? ecs_get_mut(world, entity, component) : NULL) (ecs_get(world, entity, component) ? ecs_get_mut(world, entity, component) : NULL)
#endif #endif
#define ITEMS_INVENTORY_SIZE 9 #define ITEMS_INVENTORY_SIZE 9
@ -52,7 +52,7 @@ typedef struct {
uint8_t is_blocked; uint8_t is_blocked;
ecs_entity_t pick_ent; ecs_entity_t pick_ent;
ecs_entity_t sel_ent; ecs_entity_t sel_ent;
// NOTE(zaklaus): inventory // NOTE(zaklaus): inventory
ecs_entity_t storage_ent; ecs_entity_t storage_ent;
uint8_t storage_action; uint8_t storage_action;
@ -63,7 +63,7 @@ typedef struct {
uint8_t swap_storage; uint8_t swap_storage;
uint8_t swap_from; uint8_t swap_from;
uint8_t swap_to; uint8_t swap_to;
// NOTE(zaklaus): build mode // NOTE(zaklaus): build mode
uint8_t num_placements; uint8_t num_placements;
float placements_x[20]; float placements_x[20];
@ -80,7 +80,7 @@ typedef struct {
typedef struct { typedef struct {
float hp; float hp;
float max_hp; float max_hp;
//NOTE(zaklaus): Intentionally global, to allow for creative use of damage combos //NOTE(zaklaus): Intentionally global, to allow for creative use of damage combos
float pain_time; float pain_time;
float heal_time; float heal_time;
@ -92,12 +92,12 @@ typedef struct {
typedef struct { typedef struct {
uint64_t seats[4]; uint64_t seats[4];
float force; float force;
float heading; float heading;
float steer; float steer;
float wheel_base; float wheel_base;
float speed; float speed;
float reverse_speed; float reverse_speed;
uint8_t veh_kind; uint8_t veh_kind;
@ -148,7 +148,7 @@ typedef struct {
typedef struct { typedef struct {
uint16_t asset; uint16_t asset;
// progress bar // progress bar
uint8_t progress_active; uint8_t progress_active;
float progress_value; float progress_value;

View File

@ -5,12 +5,12 @@
#include <emscripten.h> #include <emscripten.h>
#ifdef ARCH_IMPL #ifdef ARCH_IMPL
EM_JS(int, canvas_get_width, (), { EM_JS(int, canvas_get_width, (), {
return canvas.width; return canvas.width;
}); });
EM_JS(int, canvas_get_height, (), { EM_JS(int, canvas_get_height, (), {
return canvas.height; return canvas.height;
}); });
void UpdateDrawFrame(void) { void UpdateDrawFrame(void) {
reset_cached_time(); reset_cached_time();
@ -19,7 +19,7 @@ void UpdateDrawFrame(void) {
game_update(); game_update();
game_render(); game_render();
} }
profiler_collate(); profiler_collate();
} }
#else #else
@ -43,42 +43,42 @@ void reset_cached_time(void) {
} }
void game_run(void) { void game_run(void) {
#if !defined(PLATFORM_WEB) #if !defined(PLATFORM_WEB)
while (game_is_running()) { while (game_is_running()) {
reset_cached_time(); reset_cached_time();
profile (PROF_MAIN_LOOP) { profile (PROF_MAIN_LOOP) {
game_input(); game_input();
game_update(); game_update();
game_render(); game_render();
}
profiler_collate();
} }
#else
emscripten_set_main_loop(UpdateDrawFrame, 0, 1); profiler_collate();
#endif }
#else
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#endif
} }
void platform_create_window(const char *title) { void platform_create_window(const char *title) {
SetTraceLogLevel(LOG_ERROR); SetTraceLogLevel(LOG_ERROR);
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
screenWidth = (uint16_t)canvas_get_width(); screenWidth = (uint16_t)canvas_get_width();
screenHeight = (uint16_t)canvas_get_height(); screenHeight = (uint16_t)canvas_get_height();
#endif #endif
InitWindow(screenWidth, screenHeight, title); InitWindow(screenWidth, screenHeight, title);
uint32_t flags = /*FLAG_WINDOW_UNDECORATED|*/FLAG_WINDOW_MAXIMIZED|FLAG_WINDOW_RESIZABLE|FLAG_MSAA_4X_HINT; uint32_t flags = /*FLAG_WINDOW_UNDECORATED|*/FLAG_WINDOW_MAXIMIZED|FLAG_WINDOW_RESIZABLE|FLAG_MSAA_4X_HINT;
#if !defined(PLATFORM_WEB) #if !defined(PLATFORM_WEB)
flags |= FLAG_VSYNC_HINT; //flags |= FLAG_VSYNC_HINT;
#endif #endif
SetWindowState(flags); SetWindowState(flags);
#if !defined(PLATFORM_WEB) #if !defined(PLATFORM_WEB)
screenWidth = (uint16_t)GetScreenWidth(); screenWidth = (uint16_t)GetScreenWidth();
screenHeight = (uint16_t)GetScreenHeight(); screenHeight = (uint16_t)GetScreenHeight();
#endif #endif
// ToggleFullscreen(); // ToggleFullscreen();
// SetTargetFPS(60.0); // SetTargetFPS(60.0);
} }
void platform_resize_window() { void platform_resize_window() {
@ -121,13 +121,13 @@ inline static
void platform_input_update_input_frame(game_keystate_data data) { void platform_input_update_input_frame(game_keystate_data data) {
float mx = 0, my = 0; float mx = 0, my = 0;
platform_get_block_realpos(&mx, &my); platform_get_block_realpos(&mx, &my);
if (mx != last_blockpos_data.mx || my != last_blockpos_data.my){ if (mx != last_blockpos_data.mx || my != last_blockpos_data.my){
last_blockpos_data.mx = mx; last_blockpos_data.mx = mx;
last_blockpos_data.my = my; last_blockpos_data.my = my;
game_action_send_blockpos(mx, my); game_action_send_blockpos(mx, my);
} }
// NOTE(zaklaus): Test if there are any changes // NOTE(zaklaus): Test if there are any changes
if (data.x != last_input_data.x) goto send_data; if (data.x != last_input_data.x) goto send_data;
if (data.y != last_input_data.y) goto send_data; if (data.y != last_input_data.y) goto send_data;
@ -145,7 +145,7 @@ void platform_input_update_input_frame(game_keystate_data data) {
if (data.deletion_mode != last_input_data.deletion_mode) goto send_data; if (data.deletion_mode != last_input_data.deletion_mode) goto send_data;
if (zpl_memcompare(data.placements, last_input_data.placements, zpl_size_of(data.placements))) goto send_data; if (zpl_memcompare(data.placements, last_input_data.placements, zpl_size_of(data.placements))) goto send_data;
return; return;
send_data: send_data:
last_input_data = data; last_input_data = data;
game_action_send_keystate(&data); game_action_send_keystate(&data);