sync time between clients to utc
authorhgn <hgodden00@gmail.com>
Sat, 4 Nov 2023 16:53:36 +0000 (16:53 +0000)
committerhgn <hgodden00@gmail.com>
Sat, 4 Nov 2023 16:53:36 +0000 (16:53 +0000)
world_load.c
world_render.c

index fd75aa8f8cca887ca34443154fbaf071800936ff..f907a2bda23d58ca0b7885826a21a1c4ee18e5c8 100644 (file)
@@ -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 );
index e6c709afb0d141438a9726256d4889cf06f74a46..aa74bbfb6a2f6c4ab7e045348795cc33dd67eb43 100644 (file)
 #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;