2 * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved
10 #include "world_routes.h"
11 #include "world_gate.h"
12 #include "world_load.h"
13 #include "highscores.h"
19 #include "network_msg.h"
20 #include "network_common.h"
22 #include "shaders/scene_route.h"
23 #include "shaders/routeui.h"
24 #include "ent_region.h"
26 static void world_routes_clear( world_instance
*world
)
28 for( u32 i
=0; i
<mdl_arrcount( &world
->ent_route
); i
++ ){
29 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
30 route
->active_checkpoint
= 0xffff;
33 for( u32 i
=0; i
<mdl_arrcount( &world
->ent_gate
); i
++ ){
34 ent_gate
*rg
= mdl_arritm( &world
->ent_gate
, i
);
35 rg
->timing_version
= 0;
36 rg
->timing_time
= 0.0;
39 world_static
.current_run_version
+= 4;
40 world_static
.last_use
= 0.0;
43 static void world_routes_time_lap( world_instance
*world
, ent_route
*route
){
44 vg_info( "------- time lap %s -------\n",
45 mdl_pstr(&world
->meta
,route
->pstr_name
) );
47 double start_time
= 0.0;
51 int clean
= !localplayer
.rewinded_since_last_gate
;
53 for( u32 i
=0; i
<route
->checkpoints_count
; i
++ ){
54 u32 cpid
= (i
+route
->active_checkpoint
) % route
->checkpoints_count
;
55 cpid
+= route
->checkpoints_start
;
57 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, cpid
);
58 ent_gate
*rg
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
59 rg
= mdl_arritm( &world
->ent_gate
, rg
->target
);
62 route
->timing_base
= rg
->timing_time
;
66 start_time
= rg
->timing_time
;
68 if( last_version
+1 == rg
->timing_version
) valid_sections
++;
69 else valid_sections
= 0;
72 last_version
= rg
->timing_version
;
74 vg_info( "%u %f [%s]\n", rg
->timing_version
, rg
->timing_time
,
75 i
? ((rg
->flags
& k_ent_gate_clean_pass
)? "CLEAN": " "):
78 if( !(rg
->flags
& k_ent_gate_clean_pass
) )
82 if( world_static
.current_run_version
== last_version
+1 ){
85 if( route
->checkpoints_count
== 1 ){
86 route
->timing_base
= world_static
.time
;
89 else valid_sections
= 0;
91 vg_info( "%u %f [%s]\n",
92 world_static
.current_run_version
, world_static
.time
,
93 !localplayer
.rewinded_since_last_gate
? "CLEAN": " " );
95 if( valid_sections
==route
->checkpoints_count
){
96 f64 lap_time
= world_static
.time
- start_time
;
98 if( (route
->best_laptime
== 0.0) || (lap_time
< route
->best_laptime
) ){
99 route
->best_laptime
= lap_time
;
102 route
->flags
|= k_ent_route_flag_achieve_silver
;
103 if( clean
) route
->flags
|= k_ent_route_flag_achieve_gold
;
104 ent_region_re_eval( world
);
106 /* for steam achievements. */
107 if( route
->anon
.official_track_id
!= 0xffffffff ){
108 struct track_info
*ti
= &track_infos
[ route
->anon
.official_track_id
];
109 if( ti
->achievement_id
){
110 steam_set_achievement( ti
->achievement_id
);
111 steam_store_achievements();
116 &world_static
.instance_addons
[ world_static
.active_instance
]->alias
;
118 char mod_uid
[ ADDON_UID_MAX
];
119 addon_alias_uid( alias
, mod_uid
);
120 network_publish_laptime( mod_uid
,
121 mdl_pstr( &world
->meta
, route
->pstr_name
),
125 route
->valid_checkpoints
= valid_sections
+1;
127 vg_info( "valid sections: %u\n", valid_sections
);
128 vg_info( "----------------------------\n" );
132 * When going through a gate this is called for bookkeeping purposes
134 static void world_routes_activate_entry_gate( world_instance
*world
,
137 world_static
.last_use
= world_static
.time
;
138 ent_gate
*dest
= mdl_arritm( &world
->ent_gate
, rg
->target
);
140 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
141 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
143 u32 active_prev
= route
->active_checkpoint
;
144 route
->active_checkpoint
= 0xffff;
146 for( u32 j
=0; j
<4; j
++ ){
147 if( dest
->routes
[j
] == i
){
148 for( u32 k
=0; k
<route
->checkpoints_count
; k
++ ){
149 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
,
150 route
->checkpoints_start
+k
);
152 ent_gate
*gk
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
153 gk
= mdl_arritm( &world
->ent_gate
, gk
->target
);
155 route
->active_checkpoint
= k
;
156 world_routes_time_lap( world
, route
);
165 dest
->timing_version
= world_static
.current_run_version
;
166 dest
->timing_time
= world_static
.time
;
168 if( localplayer
.rewinded_since_last_gate
){
169 localplayer
.rewinded_since_last_gate
= 0;
170 dest
->flags
&= ~k_ent_gate_clean_pass
;
173 dest
->flags
|= k_ent_gate_clean_pass
;
175 world_static
.current_run_version
++;
178 /* draw lines along the paths */
179 static void world_routes_debug( world_instance
*world
)
181 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route_node
); i
++ ){
182 ent_route_node
*rn
= mdl_arritm(&world
->ent_route_node
,i
);
183 vg_line_point( rn
->co
, 0.25f
, VG__WHITE
);
186 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
187 ent_route
*route
= mdl_arritm(&world
->ent_route
, i
);
189 u32 colours
[] = { 0xfff58142, 0xff42cbf5, 0xff42f56c, 0xfff542b3,
193 if( route
->active_checkpoint
!= 0xffff ){
194 cc
= colours
[i
%vg_list_size(colours
)];
197 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
198 int i0
= route
->checkpoints_start
+i
,
199 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
201 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
202 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
204 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
205 ent_gate
*end_gate
= mdl_arritm( &world
->ent_gate
, c1
->gate_index
);
208 v3_copy( start_gate
->co
[1], p0
);
210 for( int j
=0; j
<c0
->path_count
; j
++ ){
211 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
214 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
217 v3_copy( rn
->co
, p1
);
218 vg_line( p0
, p1
, cc
);
222 v3_copy( end_gate
->co
[0], p1
);
223 vg_line( p0
, p1
, cc
);
230 void world_routes_place_curve( world_instance
*world
, ent_route
*route
,
231 v4f h
[3], v3f n0
, v3f n2
, scene_context
*scene
)
237 float total_length
= 0.0f
,
241 v3_copy( h
[0], last
);
242 for( int it
=0; it
<128; it
++ ){
243 t
= (float)(it
+1) * (1.0f
/128.0f
);
244 eval_bezier3( h
[0], h
[1], h
[2], t
, p
);
245 total_length
+= v3_dist( p
, last
);
249 float patch_size
= 4.0f
,
250 patch_count
= ceilf( total_length
/ patch_size
);
253 v3_copy( h
[0], last
);
255 for( int it
=0; it
<128; it
++ ){
256 float const k_sample_dist
= 0.0025f
,
259 eval_bezier3( h
[0], h
[1], h
[2], t
, p
);
260 eval_bezier3( h
[0], h
[1], h
[2], t
+k_sample_dist
, pd
);
262 travel_length
+= v3_dist( p
, last
);
264 float mod
= k_sample_dist
/ v3_dist( p
, pd
);
268 v3_muls( n0
, -(1.0f
-t
), up
);
269 v3_muladds( up
, n2
, -t
, up
);
273 v3_cross( up
, v0
, right
);
274 v3_normalize( right
);
276 float cur_x
= (1.0f
-t
)*h
[0][3] + t
*h
[2][3];
278 v3f sc
, sa
, sb
, down
;
279 v3_muladds( p
, right
, cur_x
* k_line_width
, sc
);
280 v3_muladds( sc
, up
, 1.5f
, sc
);
281 v3_muladds( sc
, right
, k_line_width
*0.95f
, sa
);
282 v3_muladds( sc
, right
, 0.0f
, sb
);
283 v3_muls( up
, -1.0f
, down
);
289 int resa
= ray_world( world
, sa
, down
, &ha
, k_material_flag_ghosts
),
290 resb
= ray_world( world
, sb
, down
, &hb
, k_material_flag_ghosts
);
293 struct world_surface
*surfa
= ray_hit_surface( world
, &ha
),
294 *surfb
= ray_hit_surface( world
, &hb
);
296 if( (surfa
->info
.flags
& k_material_flag_skate_target
) &&
297 (surfb
->info
.flags
& k_material_flag_skate_target
) )
301 float gap
= vg_fractf(cur_x
*0.5f
)*0.02f
;
303 v3_muladds( ha
.pos
, up
, 0.06f
+gap
, va
.co
);
304 v3_muladds( hb
.pos
, up
, 0.06f
+gap
, vb
.co
);
306 scene_vert_pack_norm( &va
, up
);
307 scene_vert_pack_norm( &vb
, up
);
309 float t1
= (travel_length
/ total_length
) * patch_count
;
315 scene_push_vert( scene
, &va
);
316 scene_push_vert( scene
, &vb
);
319 /* Connect them with triangles */
320 scene_push_tri( scene
, (u32
[3]){
321 last_valid
+0-2, last_valid
+1-2, last_valid
+2-2} );
322 scene_push_tri( scene
, (u32
[3]){
323 last_valid
+1-2, last_valid
+3-2, last_valid
+2-2} );
326 last_valid
= scene
->vertex_count
;
345 static void world_routes_gen_meshes( world_instance
*world
, u32 route_id
,
348 ent_route
*route
= mdl_arritm( &world
->ent_route
, route_id
);
350 colour
[0] = route
->colour
[0] * 255.0f
;
351 colour
[1] = route
->colour
[1] * 255.0f
;
352 colour
[2] = route
->colour
[2] * 255.0f
;
353 colour
[3] = route
->colour
[3] * 255.0f
;
357 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
358 int i0
= route
->checkpoints_start
+i
,
359 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
361 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
362 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
364 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
365 start_gate
= mdl_arritm( &world
->ent_gate
, start_gate
->target
);
367 ent_gate
*end_gate
= mdl_arritm( &world
->ent_gate
, c1
->gate_index
),
368 *collector
= mdl_arritm( &world
->ent_gate
, end_gate
->target
);
372 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, start_gate
->co
[0], p
[0] );
373 p
[0][3] = start_gate
->ref_count
;
374 p
[0][3] -= (float)start_gate
->route_count
* 0.5f
;
375 start_gate
->ref_count
++;
377 if( !c0
->path_count
)
380 /* this is so that we get nice flow through the gates */
381 v3f temp_alignments
[2];
382 ent_gate
*both
[] = { start_gate
, end_gate
};
384 for( int j
=0; j
<2; j
++ ){
385 int pi
= c0
->path_start
+ ((j
==1)? c0
->path_count
-1: 0);
387 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
, pi
);
388 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
391 v3_sub( rn
->co
, both
[j
]->co
[0], v0
);
392 float d
= v3_dot( v0
, both
[j
]->to_world
[2] );
394 v3_muladds( both
[j
]->co
[0], both
[j
]->to_world
[2], d
,
395 temp_alignments
[j
] );
396 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, temp_alignments
[j
], temp_alignments
[j
]);
400 for( int j
=0; j
<c0
->path_count
; j
++ ){
401 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
403 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
405 if( j
==0 || j
==c0
->path_count
-1 )
407 v3_copy( temp_alignments
[0], p
[1] );
409 v3_copy( temp_alignments
[1], p
[1] );
411 v3_copy( rn
->co
, p
[1] );
413 p
[1][3] = rn
->ref_count
;
414 p
[1][3] -= (float)rn
->ref_total
* 0.5f
;
417 if( j
+1 < c0
->path_count
){
418 index
= mdl_arritm( &world
->ent_path_index
,
419 c0
->path_start
+j
+1 );
420 rn
= mdl_arritm( &world
->ent_route_node
, index
->index
);
422 if( j
+1 == c0
->path_count
-1 )
423 v3_lerp( p
[1], temp_alignments
[1], 0.5f
, p
[2] );
425 v3_lerp( p
[1], rn
->co
, 0.5f
, p
[2] );
427 p
[2][3] = rn
->ref_count
;
428 p
[2][3] -= (float)rn
->ref_total
* 0.5f
;
431 v3_copy( end_gate
->co
[0], p
[2] );
432 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, p
[2], p
[2] );
433 p
[2][3] = collector
->ref_count
;
435 if( i
== route
->checkpoints_count
-1)
438 p
[2][3] -= (float)collector
->route_count
* 0.5f
;
439 //collector->ref_count ++;
442 /* p0,p1,p2 bezier patch is complete
443 * --------------------------------------*/
444 v3f surf0
, surf2
, n0
, n2
;
446 if( bh_closest_point( world
->geo_bh
, p
[0], surf0
, 5.0f
) == -1 )
447 v3_add( (v3f
){0.0f
,-0.1f
,0.0f
}, p
[0], surf0
);
449 if( bh_closest_point( world
->geo_bh
, p
[2], surf2
, 5.0f
) == -1 )
450 v3_add( (v3f
){0.0f
,-0.1f
,0.0f
}, p
[2], surf2
);
452 v3_sub( surf0
, p
[0], n0
);
453 v3_sub( surf2
, p
[2], n2
);
457 world_routes_place_curve( world
, route
, p
, n0
, n2
, sc
);
460 v4_copy( p
[2], p
[0] );
464 scene_copy_slice( sc
, &route
->sm
);
468 struct world_surface
*world_tri_index_surface( world_instance
*world
,
472 * Create the strips of colour that run through the world along course paths
474 static void world_gen_routes_generate( u32 instance_id
){
475 world_instance
*world
= &world_static
.instances
[ instance_id
];
476 vg_info( "Generating route meshes\n" );
479 vg_rand_seed( 2000 );
480 vg_async_item
*call_scene
= scene_alloc_async( &world
->scene_lines
,
481 &world
->mesh_route_lines
,
484 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
485 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
487 gate
->route_count
= 0;
490 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route_node
); i
++ ){
491 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
, i
);
496 for( u32 k
=0; k
<mdl_arrcount(&world
->ent_route
); k
++ ){
497 ent_route
*route
= mdl_arritm( &world
->ent_route
, k
);
499 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
500 int i0
= route
->checkpoints_start
+i
,
501 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
503 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
504 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
506 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
507 start_gate
= mdl_arritm( &world
->ent_gate
, start_gate
->target
);
508 start_gate
->route_count
++;
510 if( !c0
->path_count
)
513 for( int j
=0; j
<c0
->path_count
; j
++ ){
514 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
516 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
523 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
524 world_routes_gen_meshes( world
, i
, &world
->scene_lines
);
527 vg_async_dispatch( call_scene
, async_scene_upload
);
528 world_routes_clear( world
);
531 /* load all routes from model header */
532 static void world_gen_routes_ent_init( world_instance
*world
){
533 vg_info( "Initializing routes\n" );
535 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
536 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
537 for( u32 j
=0; j
<4; j
++ ){
538 gate
->routes
[j
] = 0xffff;
542 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
543 ent_route
*route
= mdl_arritm(&world
->ent_route
,i
);
544 mdl_transform_m4x3( &route
->anon
.transform
, route
->board_transform
);
547 route
->best_laptime
= 0.0;
549 if( mdl_arrcount(&world
->ent_region
) )
550 route
->flags
|= k_ent_route_flag_out_of_zone
;
552 route
->anon
.official_track_id
= 0xffffffff;
553 for( u32 j
=0; j
<vg_list_size(track_infos
); j
++ ){
554 if( !strcmp(track_infos
[j
].name
,
555 mdl_pstr(&world
->meta
,route
->pstr_name
))){
556 route
->anon
.official_track_id
= j
;
560 for( u32 j
=0; j
<route
->checkpoints_count
; j
++ ){
561 u32 id
= route
->checkpoints_start
+ j
;
562 ent_checkpoint
*cp
= mdl_arritm(&world
->ent_checkpoint
,id
);
564 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
566 for( u32 k
=0; k
<4; k
++ ){
567 if( gate
->routes
[k
] == 0xffff ){
573 if( (gate
->flags
& k_ent_gate_linked
) &
574 !(gate
->flags
& k_ent_gate_nonlocal
) ){
575 gate
= mdl_arritm(&world
->ent_gate
, gate
->target
);
577 for( u32 k
=0; k
<4; k
++ ){
578 if( gate
->routes
[k
] == i
){
579 vg_error( "already assigned route to gate\n" );
582 if( gate
->routes
[k
] == 0xffff ){
591 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
592 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
595 world_routes_clear( world
);
598 static void world_routes_recv_scoreboard( world_instance
*world
,
599 vg_msg
*body
, u32 route_id
,
600 enum request_status status
){
601 if( route_id
>= mdl_arrcount( &world
->ent_route
) ){
602 vg_error( "Scoreboard route_id out of range (%u)\n", route_id
);
606 struct leaderboard_cache
*board
= &world
->leaderboard_cache
[ route_id
];
607 board
->status
= status
;
614 if( body
->max
> NETWORK_REQUEST_MAX
){
615 vg_error( "Scoreboard leaderboard too big (%u>%u)\n", body
->max
,
616 NETWORK_REQUEST_MAX
);
620 memcpy( board
->data
, body
->buf
, body
->max
);
621 board
->data_len
= body
->max
;
625 * -----------------------------------------------------------------------------
627 * -----------------------------------------------------------------------------
630 static void world_routes_init(void){
631 world_static
.current_run_version
= 200;
632 world_static
.time
= 300.0;
633 world_static
.last_use
= 0.0;
635 shader_scene_route_register();
636 shader_routeui_register();
639 static void world_routes_update( world_instance
*world
){
640 world_static
.time
+= vg
.time_delta
;
642 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
643 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
645 int target
= route
->active_checkpoint
== 0xffff? 0: 1;
646 route
->factive
= vg_lerpf( route
->factive
, target
,
647 0.6f
*vg
.time_frame_delta
);
650 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
651 struct text_particle
*particle
= &world_render
.text_particles
[i
];
652 rb_object_debug( &particle
->obj
, VG__RED
);
656 static void world_routes_fixedupdate( world_instance
*world
){
659 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
660 struct text_particle
*particle
= &world_render
.text_particles
[i
];
662 if( rb_global_has_space() ){
663 rb_ct
*buf
= rb_global_buffer();
665 int l
= rb_sphere__scene( particle
->obj
.rb
.to_world
,
666 &particle
->obj
.inf
.sphere
,
667 NULL
, &world
->rb_geo
.inf
.scene
, buf
,
668 k_material_flag_ghosts
);
670 for( int j
=0; j
<l
; j
++ ){
671 buf
[j
].rba
= &particle
->obj
.rb
;
672 buf
[j
].rbb
= &world
->rb_geo
.rb
;
675 rb_contact_count
+= l
;
679 rb_presolve_contacts( rb_contact_buffer
, rb_contact_count
);
681 for( int i
=0; i
<rb_contact_count
; i
++ ){
682 rb_contact_restitution( rb_contact_buffer
+i
, vg_randf64() );
685 for( int i
=0; i
<6; i
++ ){
686 rb_solve_contacts( rb_contact_buffer
, rb_contact_count
);
689 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
690 struct text_particle
*particle
= &world_render
.text_particles
[i
];
691 rb_iter( &particle
->obj
.rb
);
694 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
695 struct text_particle
*particle
= &world_render
.text_particles
[i
];
696 rb_update_transform( &particle
->obj
.rb
);
700 static void bind_terrain_noise(void);
701 static void world_bind_light_array( world_instance
*world
,
702 GLuint shader
, GLuint location
,
704 static void world_bind_light_index( world_instance
*world
,
705 GLuint shader
, GLuint location
,
708 static void world_routes_update_timer_texts( world_instance
*world
){
709 world_render
.timer_text_count
= 0;
711 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
712 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
714 if( route
->active_checkpoint
!= 0xffff ){
715 u32 next
= route
->active_checkpoint
+1;
716 next
= next
% route
->checkpoints_count
;
717 next
+= route
->checkpoints_start
;
719 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, next
);
720 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
721 ent_gate
*dest
= mdl_arritm( &world
->ent_gate
, gate
->target
);
725 if( dest
->routes
[j
] == i
){
735 struct timer_text
*text
=
736 &world_render
.timer_texts
[ world_render
.timer_text_count
++ ];
741 if( route
->valid_checkpoints
>= route
->checkpoints_count
){
742 double lap_time
= world_static
.time
- route
->timing_base
,
743 time_centiseconds
= lap_time
* 100.0;
745 if( time_centiseconds
> (float)0xfffe ) time_centiseconds
= 0.0;
747 u16 centiseconds
= time_centiseconds
,
748 seconds
= centiseconds
/ 100,
749 minutes
= seconds
/ 60;
755 if( minutes
> 9 ) minutes
= 9;
759 highscore_intr( text
->text
, minutes
, 1, ' ' ); j
++;
760 text
->text
[j
++] = ':';
763 if( seconds
>= 10 || minutes
){
764 highscore_intr( text
->text
+j
, seconds
, 2, '0' ); j
+=2;
767 highscore_intr( text
->text
+j
, seconds
, 1, '0' ); j
++;
770 text
->text
[j
++] = '.';
771 highscore_intr( text
->text
+j
, centiseconds
, 1, '0' ); j
++;
772 text
->text
[j
] = '\0';
775 highscore_intr( text
->text
, route
->valid_checkpoints
, 1, ' ' );
777 highscore_intr( text
->text
+2, route
->checkpoints_count
+1, 1, ' ' );
778 text
->text
[3] = '\0';
781 gui_font3d
.font
= &gui
.font
;
782 float align_r
= font3d_string_width( 0, text
->text
);
786 { -0.92f
, h0
, depth
},
787 { 0.92f
- align_r
, h0
, depth
},
788 { -0.92f
, h1
, depth
},
789 { 0.92f
- align_r
, h1
, depth
},
792 if( dest
->route_count
== 1 ){
793 positions
[0][0] = -align_r
*0.5f
;
794 positions
[0][1] = h1
;
798 ent_gate_get_mdl_mtx( gate
, mmdl
);
800 m3x3_copy( mmdl
, text
->transform
);
801 float ratio
= v3_length(text
->transform
[0]) /
802 v3_length(text
->transform
[1]);
804 m3x3_scale( text
->transform
, (v3f
){ size
, size
*ratio
, 0.1f
} );
805 m4x3_mulv( mmdl
, positions
[j
], text
->transform
[3] );
810 static void world_routes_fracture( world_instance
*world
, ent_gate
*gate
,
811 v3f imp_co
, v3f imp_v
)
813 world_render
.text_particle_count
= 0;
815 for( u32 i
=0; i
<world_render
.timer_text_count
; i
++ ){
816 struct timer_text
*text
= &world_render
.timer_texts
[i
];
818 if( text
->gate
!= gate
) continue;
821 m4x3_mul( gate
->transport
, text
->transform
, transform
);
825 m4x3_decompose( transform
, co
, q
, s
);
831 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
832 v3_muls( text
->route
->colour
, brightness
, colour
);
833 colour
[3] = 1.0f
-text
->route
->factive
;
835 for( u32 j
=0;; j
++ ){
836 char c
= text
->text
[j
];
839 ent_glyph
*glyph
= font3d_glyph( &gui
.font
, 0, c
);
840 if( !glyph
) continue;
842 if( c
>= (u32
)'0' && c
<= (u32
)'9' && glyph
->indice_count
){
843 struct text_particle
*particle
=
844 &world_render
.text_particles
[world_render
.text_particle_count
++];
846 particle
->glyph
= glyph
;
847 v4_copy( colour
, particle
->colour
);
850 v2_muls( glyph
->size
, 0.5f
, origin
);
855 v3_add( offset
, origin
, world_co
);
856 m4x3_mulv( transform
, world_co
, world_co
);
858 float r
= vg_maxf( s
[0]*glyph
->size
[0], s
[1]*glyph
->size
[1] )*0.5f
;
860 m3x3_identity( particle
->mlocal
);
861 m3x3_scale( particle
->mlocal
, s
);
863 v3_muls( origin
, -1.0f
, particle
->mlocal
[3] );
865 v3_copy( world_co
, particle
->obj
.rb
.co
);
866 v3_muls( imp_v
, 1.0f
+vg_randf64(), particle
->obj
.rb
.v
);
867 particle
->obj
.rb
.v
[1] += 2.0f
;
869 v4_copy( q
, particle
->obj
.rb
.q
);
870 particle
->obj
.rb
.w
[0] = vg_randf64()*2.0f
-1.0f
;
871 particle
->obj
.rb
.w
[1] = vg_randf64()*2.0f
-1.0f
;
872 particle
->obj
.rb
.w
[2] = vg_randf64()*2.0f
-1.0f
;
874 particle
->obj
.type
= k_rb_shape_sphere
;
875 particle
->obj
.inf
.sphere
.radius
= r
*0.6f
;
877 rb_init_object( &particle
->obj
);
879 offset
[0] += glyph
->size
[0];
884 static void render_gate_markers( m4x3f world_mmdl
, int run_id
, ent_gate
*gate
){
885 for( u32 j
=0; j
<4; j
++ ){
886 if( gate
->routes
[j
] == run_id
){
888 ent_gate_get_mdl_mtx( gate
, mmdl
);
889 m4x3_mul( world_mmdl
, mmdl
, mmdl
);
890 shader_model_gate_uMdl( mmdl
);
891 mdl_draw_submesh( &world_gates
.sm_marker
[j
] );
897 static void render_world_routes( world_instance
*world
,
898 world_instance
*host_world
,
899 m4x3f mmdl
, camera
*cam
,
900 int viewing_from_gate
, int viewing_from_hub
){
902 shader_scene_route_use();
903 shader_scene_route_uTexGarbage(0);
904 world_link_lighting_ub( host_world
, _shader_scene_route
.id
);
905 world_bind_position_texture( host_world
, _shader_scene_route
.id
,
906 _uniform_scene_route_g_world_depth
, 2 );
907 world_bind_light_array( host_world
, _shader_scene_route
.id
,
908 _uniform_scene_route_uLightsArray
, 3 );
909 world_bind_light_index( host_world
, _shader_scene_route
.id
,
910 _uniform_scene_route_uLightsIndex
, 4 );
911 bind_terrain_noise();
913 shader_scene_route_uPv( cam
->mtx
.pv
);
915 if( viewing_from_hub
){
917 m4x3_expand( mmdl
, m4mdl
);
918 m4x4_mul( cam
->mtx_prev
.pv
, m4mdl
, pvm
);
919 shader_scene_route_uMdl( mmdl
);
920 shader_scene_route_uPvmPrev( pvm
);
923 m3x3_inv( mmdl
, mnormal
);
924 m3x3_transpose( mnormal
, mnormal
);
925 v3_normalize( mnormal
[0] );
926 v3_normalize( mnormal
[1] );
927 v3_normalize( mnormal
[2] );
928 shader_scene_route_uNormalMtx( mnormal
);
931 shader_scene_route_uMdl( mmdl
);
932 shader_scene_route_uPvmPrev( cam
->mtx_prev
.pv
);
934 m3x3_identity( ident
);
935 shader_scene_route_uNormalMtx( ident
);
938 shader_scene_route_uCamera( cam
->transform
[3] );
940 mesh_bind( &world
->mesh_route_lines
);
942 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
943 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
945 f32 t
= viewing_from_hub
? 1.0f
: route
->factive
;
948 v3_lerp( (v3f
){0.7f
,0.7f
,0.7f
}, route
->colour
, t
, colour
);
951 shader_scene_route_uColour( colour
);
952 mdl_draw_submesh( &route
->sm
);
956 * ---------------------------------------------------- */
957 if( !viewing_from_gate
&& !viewing_from_hub
){
958 font3d_bind( &gui
.font
, k_font_shader_default
, 0, world
, cam
);
960 for( u32 i
=0; i
<world_render
.timer_text_count
; i
++ ){
961 struct timer_text
*text
= &world_render
.timer_texts
[i
];
964 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
965 v3_muls( text
->route
->colour
, brightness
, colour
);
966 colour
[3] = 1.0f
-text
->route
->factive
;
968 shader_model_font_uColour( colour
);
969 font3d_simple_draw( 0, text
->text
, cam
, text
->transform
);
972 shader_model_font_uOffset( (v4f
){0.0f
,0.0f
,0.0f
,1.0f
} );
974 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
975 struct text_particle
*particle
= &world_render
.text_particles
[i
];
979 m4x3_expand( particle
->mdl
, prev_mtx
);
980 m4x4_mul( cam
->mtx_prev
.pv
, prev_mtx
, prev_mtx
);
982 shader_model_font_uPvmPrev( prev_mtx
);
986 rb_extrapolate( &particle
->obj
.rb
, model
[3], q
);
989 m4x3_mul( model
, particle
->mlocal
, particle
->mdl
);
990 shader_model_font_uMdl( particle
->mdl
);
991 shader_model_font_uColour( particle
->colour
);
993 mesh_drawn( particle
->glyph
->indice_start
,
994 particle
->glyph
->indice_count
);
999 * ---------------------------------------------------- */
1001 shader_model_gate_use();
1002 shader_model_gate_uPv( cam
->mtx
.pv
);
1003 shader_model_gate_uCam( cam
->pos
);
1004 shader_model_gate_uTime( vg
.time
*0.25f
);
1005 shader_model_gate_uInvRes( (v2f
){
1006 1.0f
/ (float)vg
.window_x
,
1007 1.0f
/ (float)vg
.window_y
});
1009 mesh_bind( &world_gates
.mesh
);
1011 /* skip writing into the motion vectors for this */
1012 glDrawBuffers( 1, (GLenum
[]){ GL_COLOR_ATTACHMENT0
} );
1013 glDisable( GL_CULL_FACE
);
1015 if( viewing_from_hub
){
1016 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
1017 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
1020 v3_muls( route
->colour
, 1.6666f
, colour
);
1023 shader_model_gate_uColour( colour
);
1025 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_gate
); j
++ ){
1026 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, j
);
1027 if( !(gate
->flags
& k_ent_gate_nonlocal
) )
1028 render_gate_markers( mmdl
, i
, gate
);
1033 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
1034 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
1036 if( route
->active_checkpoint
!= 0xffff ){
1038 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
1039 v3_muls( route
->colour
, brightness
, colour
);
1040 colour
[3] = 1.0f
-route
->factive
;
1042 shader_model_gate_uColour( colour
);
1044 u32 next
= route
->active_checkpoint
+1+viewing_from_gate
;
1045 next
= next
% route
->checkpoints_count
;
1046 next
+= route
->checkpoints_start
;
1048 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, next
);
1049 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
1050 render_gate_markers( mmdl
, i
, gate
);
1054 glEnable( GL_CULL_FACE
);
1055 glDrawBuffers( 2, (GLenum
[]){ GL_COLOR_ATTACHMENT0
, GL_COLOR_ATTACHMENT1
} );
1058 #endif /* ROUTES_C */