From: hgn Date: Sat, 4 Nov 2023 16:53:36 +0000 (+0000) Subject: sync time between clients to utc X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=6f65127266e9c27e11af3f72de903f23ff3c706e;p=carveJwlIkooP6JGAAIwe30JlM.git sync time between clients to utc --- diff --git a/world_load.c b/world_load.c index fd75aa8..f907a2b 100644 --- a/world_load.c +++ b/world_load.c @@ -80,11 +80,9 @@ static void world_instance_load_mdl( u32 instance_id, const char *path ){ world->info.timezone = 0.0f; } - time_t t; - struct tm *tm; - time( &t ); - tm = gmtime( &t ); - world->time = (float)tm->tm_min/20.0f + (world->info.timezone/24.0f); + time_t seconds = time(NULL) % ((u32)k_day_length*60); + world->time = ((f64)(seconds)/(k_day_length*60.0)); + world->time += (world->info.timezone/24.0); /* process resources from pack */ world_gen_load_surfaces( world ); diff --git a/world_render.c b/world_render.c index e6c709a..aa74bbf 100644 --- a/world_render.c +++ b/world_render.c @@ -12,13 +12,11 @@ #include "respawn.h" static int ccmd_set_time( int argc, const char *argv[] ){ - if( argc == 1 ){ - world_instance *world = world_current_instance(); + world_instance *world = world_current_instance(); + if( argc == 1 ) world->time = atof( argv[0] ); - } - else { - vg_error( "Usage set_time <0-1.0>\n" ); - } + else + vg_error( "Usage set_time <0-1.0> (current time: %f)\n", world->time ); return 0; } @@ -735,12 +733,10 @@ static void render_world_gates( world_instance *world, camera *cam, } } -static void world_prerender( world_instance *world ) -{ - +static void world_prerender( world_instance *world ){ if( mdl_arrcount( &world->ent_light ) ){ f32 rate = vg_maxf(0.1f, fabsf(k_day_length)) * vg_signf(k_day_length); - world->time += vg.time_delta * (1.0/(rate*60.0)); + world->time += vg.time_frame_delta * (1.0/(rate*60.0)); } else{ world->time = 0.834;