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"
25 static void world_routes_clear( world_instance
*world
)
27 for( u32 i
=0; i
<mdl_arrcount( &world
->ent_route
); i
++ ){
28 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
29 route
->active_checkpoint
= 0xffff;
32 for( u32 i
=0; i
<mdl_arrcount( &world
->ent_gate
); i
++ ){
33 ent_gate
*rg
= mdl_arritm( &world
->ent_gate
, i
);
34 rg
->timing_version
= 0;
35 rg
->timing_time
= 0.0;
38 world_static
.current_run_version
+= 4;
39 world_static
.last_use
= 0.0;
42 static void world_routes_time_lap( world_instance
*world
, ent_route
*route
){
43 vg_info( "------- time lap %s -------\n",
44 mdl_pstr(&world
->meta
,route
->pstr_name
) );
46 double start_time
= 0.0;
50 int clean
= !localplayer
.rewinded_since_last_gate
;
52 for( u32 i
=0; i
<route
->checkpoints_count
; i
++ ){
53 u32 cpid
= (i
+route
->active_checkpoint
) % route
->checkpoints_count
;
54 cpid
+= route
->checkpoints_start
;
56 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, cpid
);
57 ent_gate
*rg
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
58 rg
= mdl_arritm( &world
->ent_gate
, rg
->target
);
61 route
->timing_base
= rg
->timing_time
;
65 start_time
= rg
->timing_time
;
67 if( last_version
+1 == rg
->timing_version
) valid_sections
++;
68 else valid_sections
= 0;
71 last_version
= rg
->timing_version
;
73 vg_info( "%u %f [%s]\n", rg
->timing_version
, rg
->timing_time
,
74 i
? ((rg
->flags
& k_ent_gate_clean_pass
)? "CLEAN": " "):
77 if( !(rg
->flags
& k_ent_gate_clean_pass
) )
81 if( world_static
.current_run_version
== last_version
+1 ){
84 if( route
->checkpoints_count
== 1 ){
85 route
->timing_base
= world_static
.time
;
88 else valid_sections
= 0;
90 vg_info( "%u %f [%s]\n",
91 world_static
.current_run_version
, world_static
.time
,
92 !localplayer
.rewinded_since_last_gate
? "CLEAN": " " );
94 if( valid_sections
==route
->checkpoints_count
){
95 f64 lap_time
= world_static
.time
- start_time
;
97 if( (route
->best_laptime
== 0.0) || (lap_time
< route
->best_laptime
) ){
98 route
->best_laptime
= lap_time
;
99 route
->achievment_status
|= 0x1;
102 route
->achievment_status
|= 0x2;
105 /* for steam achievements. */
106 if( route
->anon
.official_track_id
!= 0xffffffff ){
107 struct track_info
*ti
= &track_infos
[ route
->anon
.official_track_id
];
108 if( ti
->achievement_id
){
109 steam_set_achievement( ti
->achievement_id
);
110 steam_store_achievements();
115 &world_static
.instance_addons
[ world_static
.active_instance
]->alias
;
117 char mod_uid
[ ADDON_UID_MAX
];
118 addon_alias_uid( alias
, mod_uid
);
119 network_publish_laptime( mod_uid
,
120 mdl_pstr( &world
->meta
, route
->pstr_name
),
124 route
->valid_checkpoints
= valid_sections
+1;
126 vg_info( "valid sections: %u\n", valid_sections
);
127 vg_info( "----------------------------\n" );
131 * When going through a gate this is called for bookkeeping purposes
133 static void world_routes_activate_entry_gate( world_instance
*world
,
136 world_static
.last_use
= world_static
.time
;
137 ent_gate
*dest
= mdl_arritm( &world
->ent_gate
, rg
->target
);
139 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
140 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
142 u32 active_prev
= route
->active_checkpoint
;
143 route
->active_checkpoint
= 0xffff;
145 for( u32 j
=0; j
<4; j
++ ){
146 if( dest
->routes
[j
] == i
){
147 for( u32 k
=0; k
<route
->checkpoints_count
; k
++ ){
148 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
,
149 route
->checkpoints_start
+k
);
151 ent_gate
*gk
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
152 gk
= mdl_arritm( &world
->ent_gate
, gk
->target
);
154 route
->active_checkpoint
= k
;
155 world_routes_time_lap( world
, route
);
164 dest
->timing_version
= world_static
.current_run_version
;
165 dest
->timing_time
= world_static
.time
;
167 if( localplayer
.rewinded_since_last_gate
){
168 localplayer
.rewinded_since_last_gate
= 0;
169 dest
->flags
&= ~k_ent_gate_clean_pass
;
172 dest
->flags
|= k_ent_gate_clean_pass
;
174 world_static
.current_run_version
++;
177 /* draw lines along the paths */
178 static void world_routes_debug( world_instance
*world
)
180 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route_node
); i
++ ){
181 ent_route_node
*rn
= mdl_arritm(&world
->ent_route_node
,i
);
182 vg_line_point( rn
->co
, 0.25f
, VG__WHITE
);
185 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
186 ent_route
*route
= mdl_arritm(&world
->ent_route
, i
);
188 u32 colours
[] = { 0xfff58142, 0xff42cbf5, 0xff42f56c, 0xfff542b3,
192 if( route
->active_checkpoint
!= 0xffff ){
193 cc
= colours
[i
%vg_list_size(colours
)];
196 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
197 int i0
= route
->checkpoints_start
+i
,
198 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
200 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
201 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
203 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
204 ent_gate
*end_gate
= mdl_arritm( &world
->ent_gate
, c1
->gate_index
);
207 v3_copy( start_gate
->co
[1], p0
);
209 for( int j
=0; j
<c0
->path_count
; j
++ ){
210 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
213 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
216 v3_copy( rn
->co
, p1
);
217 vg_line( p0
, p1
, cc
);
221 v3_copy( end_gate
->co
[0], p1
);
222 vg_line( p0
, p1
, cc
);
229 void world_routes_place_curve( world_instance
*world
, ent_route
*route
,
230 v4f h
[3], v3f n0
, v3f n2
, scene_context
*scene
)
236 float total_length
= 0.0f
,
240 v3_copy( h
[0], last
);
241 for( int it
=0; it
<128; it
++ ){
242 t
= (float)(it
+1) * (1.0f
/128.0f
);
243 eval_bezier3( h
[0], h
[1], h
[2], t
, p
);
244 total_length
+= v3_dist( p
, last
);
248 float patch_size
= 4.0f
,
249 patch_count
= ceilf( total_length
/ patch_size
);
252 v3_copy( h
[0], last
);
254 for( int it
=0; it
<128; it
++ ){
255 float const k_sample_dist
= 0.0025f
,
258 eval_bezier3( h
[0], h
[1], h
[2], t
, p
);
259 eval_bezier3( h
[0], h
[1], h
[2], t
+k_sample_dist
, pd
);
261 travel_length
+= v3_dist( p
, last
);
263 float mod
= k_sample_dist
/ v3_dist( p
, pd
);
267 v3_muls( n0
, -(1.0f
-t
), up
);
268 v3_muladds( up
, n2
, -t
, up
);
272 v3_cross( up
, v0
, right
);
273 v3_normalize( right
);
275 float cur_x
= (1.0f
-t
)*h
[0][3] + t
*h
[2][3];
277 v3f sc
, sa
, sb
, down
;
278 v3_muladds( p
, right
, cur_x
* k_line_width
, sc
);
279 v3_muladds( sc
, up
, 1.5f
, sc
);
280 v3_muladds( sc
, right
, k_line_width
*0.95f
, sa
);
281 v3_muladds( sc
, right
, 0.0f
, sb
);
282 v3_muls( up
, -1.0f
, down
);
288 int resa
= ray_world( world
, sa
, down
, &ha
, k_material_flag_ghosts
),
289 resb
= ray_world( world
, sb
, down
, &hb
, k_material_flag_ghosts
);
292 struct world_surface
*surfa
= ray_hit_surface( world
, &ha
),
293 *surfb
= ray_hit_surface( world
, &hb
);
295 if( (surfa
->info
.flags
& k_material_flag_skate_target
) &&
296 (surfb
->info
.flags
& k_material_flag_skate_target
) )
300 float gap
= vg_fractf(cur_x
*0.5f
)*0.02f
;
302 v3_muladds( ha
.pos
, up
, 0.06f
+gap
, va
.co
);
303 v3_muladds( hb
.pos
, up
, 0.06f
+gap
, vb
.co
);
305 scene_vert_pack_norm( &va
, up
);
306 scene_vert_pack_norm( &vb
, up
);
308 float t1
= (travel_length
/ total_length
) * patch_count
;
314 scene_push_vert( scene
, &va
);
315 scene_push_vert( scene
, &vb
);
318 /* Connect them with triangles */
319 scene_push_tri( scene
, (u32
[3]){
320 last_valid
+0-2, last_valid
+1-2, last_valid
+2-2} );
321 scene_push_tri( scene
, (u32
[3]){
322 last_valid
+1-2, last_valid
+3-2, last_valid
+2-2} );
325 last_valid
= scene
->vertex_count
;
344 static void world_routes_gen_meshes( world_instance
*world
, u32 route_id
,
347 ent_route
*route
= mdl_arritm( &world
->ent_route
, route_id
);
349 colour
[0] = route
->colour
[0] * 255.0f
;
350 colour
[1] = route
->colour
[1] * 255.0f
;
351 colour
[2] = route
->colour
[2] * 255.0f
;
352 colour
[3] = route
->colour
[3] * 255.0f
;
356 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
357 int i0
= route
->checkpoints_start
+i
,
358 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
360 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
361 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
363 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
364 start_gate
= mdl_arritm( &world
->ent_gate
, start_gate
->target
);
366 ent_gate
*end_gate
= mdl_arritm( &world
->ent_gate
, c1
->gate_index
),
367 *collector
= mdl_arritm( &world
->ent_gate
, end_gate
->target
);
371 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, start_gate
->co
[0], p
[0] );
372 p
[0][3] = start_gate
->ref_count
;
373 p
[0][3] -= (float)start_gate
->route_count
* 0.5f
;
374 start_gate
->ref_count
++;
376 if( !c0
->path_count
)
379 /* this is so that we get nice flow through the gates */
380 v3f temp_alignments
[2];
381 ent_gate
*both
[] = { start_gate
, end_gate
};
383 for( int j
=0; j
<2; j
++ ){
384 int pi
= c0
->path_start
+ ((j
==1)? c0
->path_count
-1: 0);
386 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
, pi
);
387 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
390 v3_sub( rn
->co
, both
[j
]->co
[0], v0
);
391 float d
= v3_dot( v0
, both
[j
]->to_world
[2] );
393 v3_muladds( both
[j
]->co
[0], both
[j
]->to_world
[2], d
,
394 temp_alignments
[j
] );
395 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, temp_alignments
[j
], temp_alignments
[j
]);
399 for( int j
=0; j
<c0
->path_count
; j
++ ){
400 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
402 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
404 if( j
==0 || j
==c0
->path_count
-1 )
406 v3_copy( temp_alignments
[0], p
[1] );
408 v3_copy( temp_alignments
[1], p
[1] );
410 v3_copy( rn
->co
, p
[1] );
412 p
[1][3] = rn
->ref_count
;
413 p
[1][3] -= (float)rn
->ref_total
* 0.5f
;
416 if( j
+1 < c0
->path_count
){
417 index
= mdl_arritm( &world
->ent_path_index
,
418 c0
->path_start
+j
+1 );
419 rn
= mdl_arritm( &world
->ent_route_node
, index
->index
);
421 if( j
+1 == c0
->path_count
-1 )
422 v3_lerp( p
[1], temp_alignments
[1], 0.5f
, p
[2] );
424 v3_lerp( p
[1], rn
->co
, 0.5f
, p
[2] );
426 p
[2][3] = rn
->ref_count
;
427 p
[2][3] -= (float)rn
->ref_total
* 0.5f
;
430 v3_copy( end_gate
->co
[0], p
[2] );
431 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, p
[2], p
[2] );
432 p
[2][3] = collector
->ref_count
;
434 if( i
== route
->checkpoints_count
-1)
437 p
[2][3] -= (float)collector
->route_count
* 0.5f
;
438 //collector->ref_count ++;
441 /* p0,p1,p2 bezier patch is complete
442 * --------------------------------------*/
443 v3f surf0
, surf2
, n0
, n2
;
445 if( bh_closest_point( world
->geo_bh
, p
[0], surf0
, 5.0f
) == -1 )
446 v3_add( (v3f
){0.0f
,-0.1f
,0.0f
}, p
[0], surf0
);
448 if( bh_closest_point( world
->geo_bh
, p
[2], surf2
, 5.0f
) == -1 )
449 v3_add( (v3f
){0.0f
,-0.1f
,0.0f
}, p
[2], surf2
);
451 v3_sub( surf0
, p
[0], n0
);
452 v3_sub( surf2
, p
[2], n2
);
456 world_routes_place_curve( world
, route
, p
, n0
, n2
, sc
);
459 v4_copy( p
[2], p
[0] );
463 scene_copy_slice( sc
, &route
->sm
);
467 struct world_surface
*world_tri_index_surface( world_instance
*world
,
471 * Create the strips of colour that run through the world along course paths
473 static void world_gen_routes_generate( u32 instance_id
){
474 world_instance
*world
= &world_static
.instances
[ instance_id
];
475 vg_info( "Generating route meshes\n" );
478 vg_rand_seed( 2000 );
479 vg_async_item
*call_scene
= scene_alloc_async( &world
->scene_lines
,
480 &world
->mesh_route_lines
,
483 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
484 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
486 gate
->route_count
= 0;
489 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route_node
); i
++ ){
490 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
, i
);
495 for( u32 k
=0; k
<mdl_arrcount(&world
->ent_route
); k
++ ){
496 ent_route
*route
= mdl_arritm( &world
->ent_route
, k
);
498 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
499 int i0
= route
->checkpoints_start
+i
,
500 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
502 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
503 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
505 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
506 start_gate
= mdl_arritm( &world
->ent_gate
, start_gate
->target
);
507 start_gate
->route_count
++;
509 if( !c0
->path_count
)
512 for( int j
=0; j
<c0
->path_count
; j
++ ){
513 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
515 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
522 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
523 world_routes_gen_meshes( world
, i
, &world
->scene_lines
);
526 vg_async_dispatch( call_scene
, async_scene_upload
);
527 world_routes_clear( world
);
530 /* load all routes from model header */
531 static void world_gen_routes_ent_init( world_instance
*world
){
532 vg_info( "Initializing routes\n" );
534 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
535 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
536 for( u32 j
=0; j
<4; j
++ ){
537 gate
->routes
[j
] = 0xffff;
541 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
542 ent_route
*route
= mdl_arritm(&world
->ent_route
,i
);
543 mdl_transform_m4x3( &route
->anon
.transform
, route
->board_transform
);
545 route
->anon
.official_track_id
= 0xffffffff;
546 for( u32 j
=0; j
<vg_list_size(track_infos
); j
++ ){
547 if( !strcmp(track_infos
[j
].name
,
548 mdl_pstr(&world
->meta
,route
->pstr_name
))){
549 route
->anon
.official_track_id
= j
;
553 for( u32 j
=0; j
<route
->checkpoints_count
; j
++ ){
554 u32 id
= route
->checkpoints_start
+ j
;
555 ent_checkpoint
*cp
= mdl_arritm(&world
->ent_checkpoint
,id
);
557 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
559 for( u32 k
=0; k
<4; k
++ ){
560 if( gate
->routes
[k
] == 0xffff ){
566 if( (gate
->flags
& k_ent_gate_linked
) &
567 !(gate
->flags
& k_ent_gate_nonlocal
) ){
568 gate
= mdl_arritm(&world
->ent_gate
, gate
->target
);
570 for( u32 k
=0; k
<4; k
++ ){
571 if( gate
->routes
[k
] == i
){
572 vg_error( "already assigned route to gate\n" );
575 if( gate
->routes
[k
] == 0xffff ){
584 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
585 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
588 world_routes_clear( world
);
591 static void world_routes_recv_scoreboard( world_instance
*world
,
592 vg_msg
*body
, u32 route_id
,
593 enum request_status status
){
594 if( route_id
>= mdl_arrcount( &world
->ent_route
) ){
595 vg_error( "Scoreboard route_id out of range (%u)\n", route_id
);
599 struct leaderboard_cache
*board
= &world
->leaderboard_cache
[ route_id
];
600 board
->status
= status
;
607 if( body
->max
> NETWORK_REQUEST_MAX
){
608 vg_error( "Scoreboard leaderboard too big (%u>%u)\n", body
->max
,
609 NETWORK_REQUEST_MAX
);
613 memcpy( board
->data
, body
->buf
, body
->max
);
614 board
->data_len
= body
->max
;
618 * -----------------------------------------------------------------------------
620 * -----------------------------------------------------------------------------
623 static void world_routes_init(void){
624 world_static
.current_run_version
= 200;
625 world_static
.time
= 300.0;
626 world_static
.last_use
= 0.0;
628 shader_scene_route_register();
629 shader_routeui_register();
632 static void world_routes_update( world_instance
*world
){
633 world_static
.time
+= vg
.time_delta
;
635 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
636 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
638 int target
= route
->active_checkpoint
== 0xffff? 0: 1;
639 route
->factive
= vg_lerpf( route
->factive
, target
,
640 0.6f
*vg
.time_frame_delta
);
643 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
644 struct text_particle
*particle
= &world_render
.text_particles
[i
];
645 rb_object_debug( &particle
->obj
, VG__RED
);
649 static void world_routes_fixedupdate( world_instance
*world
){
652 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
653 struct text_particle
*particle
= &world_render
.text_particles
[i
];
655 if( rb_global_has_space() ){
656 rb_ct
*buf
= rb_global_buffer();
658 int l
= rb_sphere__scene( particle
->obj
.rb
.to_world
,
659 &particle
->obj
.inf
.sphere
,
660 NULL
, &world
->rb_geo
.inf
.scene
, buf
,
661 k_material_flag_ghosts
);
663 for( int j
=0; j
<l
; j
++ ){
664 buf
[j
].rba
= &particle
->obj
.rb
;
665 buf
[j
].rbb
= &world
->rb_geo
.rb
;
668 rb_contact_count
+= l
;
672 rb_presolve_contacts( rb_contact_buffer
, rb_contact_count
);
674 for( int i
=0; i
<rb_contact_count
; i
++ ){
675 rb_contact_restitution( rb_contact_buffer
+i
, vg_randf64() );
678 for( int i
=0; i
<6; i
++ ){
679 rb_solve_contacts( rb_contact_buffer
, rb_contact_count
);
682 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
683 struct text_particle
*particle
= &world_render
.text_particles
[i
];
684 rb_iter( &particle
->obj
.rb
);
687 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
688 struct text_particle
*particle
= &world_render
.text_particles
[i
];
689 rb_update_transform( &particle
->obj
.rb
);
693 static void bind_terrain_noise(void);
694 static void world_bind_light_array( world_instance
*world
,
695 GLuint shader
, GLuint location
,
697 static void world_bind_light_index( world_instance
*world
,
698 GLuint shader
, GLuint location
,
701 static void world_routes_update_timer_texts( world_instance
*world
){
702 world_render
.timer_text_count
= 0;
704 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
705 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
707 if( route
->active_checkpoint
!= 0xffff ){
708 u32 next
= route
->active_checkpoint
+1;
709 next
= next
% route
->checkpoints_count
;
710 next
+= route
->checkpoints_start
;
712 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, next
);
713 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
714 ent_gate
*dest
= mdl_arritm( &world
->ent_gate
, gate
->target
);
718 if( dest
->routes
[j
] == i
){
728 struct timer_text
*text
=
729 &world_render
.timer_texts
[ world_render
.timer_text_count
++ ];
734 if( route
->valid_checkpoints
>= route
->checkpoints_count
){
735 double lap_time
= world_static
.time
- route
->timing_base
,
736 time_centiseconds
= lap_time
* 100.0;
738 if( time_centiseconds
> (float)0xfffe ) time_centiseconds
= 0.0;
740 u16 centiseconds
= time_centiseconds
,
741 seconds
= centiseconds
/ 100,
742 minutes
= seconds
/ 60;
748 if( minutes
> 9 ) minutes
= 9;
752 highscore_intr( text
->text
, minutes
, 1, ' ' ); j
++;
753 text
->text
[j
++] = ':';
756 if( seconds
>= 10 || minutes
){
757 highscore_intr( text
->text
+j
, seconds
, 2, '0' ); j
+=2;
760 highscore_intr( text
->text
+j
, seconds
, 1, '0' ); j
++;
763 text
->text
[j
++] = '.';
764 highscore_intr( text
->text
+j
, centiseconds
, 1, '0' ); j
++;
765 text
->text
[j
] = '\0';
768 highscore_intr( text
->text
, route
->valid_checkpoints
, 1, ' ' );
770 highscore_intr( text
->text
+2, route
->checkpoints_count
+1, 1, ' ' );
771 text
->text
[3] = '\0';
774 gui_font3d
.font
= &gui
.font
;
775 float align_r
= font3d_string_width( 0, text
->text
);
779 { -0.92f
, h0
, depth
},
780 { 0.92f
- align_r
, h0
, depth
},
781 { -0.92f
, h1
, depth
},
782 { 0.92f
- align_r
, h1
, depth
},
785 if( dest
->route_count
== 1 ){
786 positions
[0][0] = -align_r
*0.5f
;
787 positions
[0][1] = h1
;
791 ent_gate_get_mdl_mtx( gate
, mmdl
);
793 m3x3_copy( mmdl
, text
->transform
);
794 float ratio
= v3_length(text
->transform
[0]) /
795 v3_length(text
->transform
[1]);
797 m3x3_scale( text
->transform
, (v3f
){ size
, size
*ratio
, 0.1f
} );
798 m4x3_mulv( mmdl
, positions
[j
], text
->transform
[3] );
803 static void world_routes_fracture( world_instance
*world
, ent_gate
*gate
,
804 v3f imp_co
, v3f imp_v
)
806 world_render
.text_particle_count
= 0;
808 for( u32 i
=0; i
<world_render
.timer_text_count
; i
++ ){
809 struct timer_text
*text
= &world_render
.timer_texts
[i
];
811 if( text
->gate
!= gate
) continue;
814 m4x3_mul( gate
->transport
, text
->transform
, transform
);
818 m4x3_decompose( transform
, co
, q
, s
);
824 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
825 v3_muls( text
->route
->colour
, brightness
, colour
);
826 colour
[3] = 1.0f
-text
->route
->factive
;
828 for( u32 j
=0;; j
++ ){
829 char c
= text
->text
[j
];
832 ent_glyph
*glyph
= font3d_glyph( &gui
.font
, 0, c
);
833 if( !glyph
) continue;
835 if( c
>= (u32
)'0' && c
<= (u32
)'9' && glyph
->indice_count
){
836 struct text_particle
*particle
=
837 &world_render
.text_particles
[world_render
.text_particle_count
++];
839 particle
->glyph
= glyph
;
840 v4_copy( colour
, particle
->colour
);
843 v2_muls( glyph
->size
, 0.5f
, origin
);
848 v3_add( offset
, origin
, world_co
);
849 m4x3_mulv( transform
, world_co
, world_co
);
851 float r
= vg_maxf( s
[0]*glyph
->size
[0], s
[1]*glyph
->size
[1] )*0.5f
;
853 m3x3_identity( particle
->mlocal
);
854 m3x3_scale( particle
->mlocal
, s
);
856 v3_muls( origin
, -1.0f
, particle
->mlocal
[3] );
858 v3_copy( world_co
, particle
->obj
.rb
.co
);
859 v3_muls( imp_v
, 1.0f
+vg_randf64(), particle
->obj
.rb
.v
);
860 particle
->obj
.rb
.v
[1] += 2.0f
;
862 v4_copy( q
, particle
->obj
.rb
.q
);
863 particle
->obj
.rb
.w
[0] = vg_randf64()*2.0f
-1.0f
;
864 particle
->obj
.rb
.w
[1] = vg_randf64()*2.0f
-1.0f
;
865 particle
->obj
.rb
.w
[2] = vg_randf64()*2.0f
-1.0f
;
867 particle
->obj
.type
= k_rb_shape_sphere
;
868 particle
->obj
.inf
.sphere
.radius
= r
*0.6f
;
870 rb_init_object( &particle
->obj
);
872 offset
[0] += glyph
->size
[0];
877 static void render_gate_markers( m4x3f world_mmdl
, int run_id
, ent_gate
*gate
){
878 for( u32 j
=0; j
<4; j
++ ){
879 if( gate
->routes
[j
] == run_id
){
881 ent_gate_get_mdl_mtx( gate
, mmdl
);
882 m4x3_mul( world_mmdl
, mmdl
, mmdl
);
883 shader_model_gate_uMdl( mmdl
);
884 mdl_draw_submesh( &world_gates
.sm_marker
[j
] );
890 static void render_world_routes( world_instance
*world
,
891 world_instance
*host_world
,
892 m4x3f mmdl
, camera
*cam
,
893 int viewing_from_gate
, int viewing_from_hub
){
895 shader_scene_route_use();
896 shader_scene_route_uTexGarbage(0);
897 world_link_lighting_ub( host_world
, _shader_scene_route
.id
);
898 world_bind_position_texture( host_world
, _shader_scene_route
.id
,
899 _uniform_scene_route_g_world_depth
, 2 );
900 world_bind_light_array( host_world
, _shader_scene_route
.id
,
901 _uniform_scene_route_uLightsArray
, 3 );
902 world_bind_light_index( host_world
, _shader_scene_route
.id
,
903 _uniform_scene_route_uLightsIndex
, 4 );
904 bind_terrain_noise();
906 shader_scene_route_uPv( cam
->mtx
.pv
);
908 if( viewing_from_hub
){
910 m4x3_expand( mmdl
, m4mdl
);
911 m4x4_mul( cam
->mtx_prev
.pv
, m4mdl
, pvm
);
912 shader_scene_route_uMdl( mmdl
);
913 shader_scene_route_uPvmPrev( pvm
);
916 m3x3_inv( mmdl
, mnormal
);
917 m3x3_transpose( mnormal
, mnormal
);
918 v3_normalize( mnormal
[0] );
919 v3_normalize( mnormal
[1] );
920 v3_normalize( mnormal
[2] );
921 shader_scene_route_uNormalMtx( mnormal
);
924 shader_scene_route_uMdl( mmdl
);
925 shader_scene_route_uPvmPrev( cam
->mtx_prev
.pv
);
927 m3x3_identity( ident
);
928 shader_scene_route_uNormalMtx( ident
);
931 shader_scene_route_uCamera( cam
->transform
[3] );
933 mesh_bind( &world
->mesh_route_lines
);
935 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
936 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
938 f32 t
= viewing_from_hub
? 1.0f
: route
->factive
;
941 v3_lerp( (v3f
){0.7f
,0.7f
,0.7f
}, route
->colour
, t
, colour
);
944 shader_scene_route_uColour( colour
);
945 mdl_draw_submesh( &route
->sm
);
949 * ---------------------------------------------------- */
950 if( !viewing_from_gate
&& !viewing_from_hub
){
951 font3d_bind( &gui
.font
, k_font_shader_default
, 0, world
, cam
);
953 for( u32 i
=0; i
<world_render
.timer_text_count
; i
++ ){
954 struct timer_text
*text
= &world_render
.timer_texts
[i
];
957 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
958 v3_muls( text
->route
->colour
, brightness
, colour
);
959 colour
[3] = 1.0f
-text
->route
->factive
;
961 shader_model_font_uColour( colour
);
962 font3d_simple_draw( 0, text
->text
, cam
, text
->transform
);
965 shader_model_font_uOffset( (v4f
){0.0f
,0.0f
,0.0f
,1.0f
} );
967 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
968 struct text_particle
*particle
= &world_render
.text_particles
[i
];
972 m4x3_expand( particle
->mdl
, prev_mtx
);
973 m4x4_mul( cam
->mtx_prev
.pv
, prev_mtx
, prev_mtx
);
975 shader_model_font_uPvmPrev( prev_mtx
);
979 rb_extrapolate( &particle
->obj
.rb
, model
[3], q
);
982 m4x3_mul( model
, particle
->mlocal
, particle
->mdl
);
983 shader_model_font_uMdl( particle
->mdl
);
984 shader_model_font_uColour( particle
->colour
);
986 mesh_drawn( particle
->glyph
->indice_start
,
987 particle
->glyph
->indice_count
);
992 * ---------------------------------------------------- */
994 shader_model_gate_use();
995 shader_model_gate_uPv( cam
->mtx
.pv
);
996 shader_model_gate_uCam( cam
->pos
);
997 shader_model_gate_uTime( vg
.time
*0.25f
);
998 shader_model_gate_uInvRes( (v2f
){
999 1.0f
/ (float)vg
.window_x
,
1000 1.0f
/ (float)vg
.window_y
});
1002 mesh_bind( &world_gates
.mesh
);
1004 /* skip writing into the motion vectors for this */
1005 glDrawBuffers( 1, (GLenum
[]){ GL_COLOR_ATTACHMENT0
} );
1006 glDisable( GL_CULL_FACE
);
1008 if( viewing_from_hub
){
1009 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
1010 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
1013 v3_muls( route
->colour
, 1.6666f
, colour
);
1016 shader_model_gate_uColour( colour
);
1018 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_gate
); j
++ ){
1019 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, j
);
1020 if( !(gate
->flags
& k_ent_gate_nonlocal
) )
1021 render_gate_markers( mmdl
, i
, gate
);
1026 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
1027 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
1029 if( route
->active_checkpoint
!= 0xffff ){
1031 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
1032 v3_muls( route
->colour
, brightness
, colour
);
1033 colour
[3] = 1.0f
-route
->factive
;
1035 shader_model_gate_uColour( colour
);
1037 u32 next
= route
->active_checkpoint
+1+viewing_from_gate
;
1038 next
= next
% route
->checkpoints_count
;
1039 next
+= route
->checkpoints_start
;
1041 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, next
);
1042 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
1043 render_gate_markers( mmdl
, i
, gate
);
1047 glEnable( GL_CULL_FACE
);
1048 glDrawBuffers( 2, (GLenum
[]){ GL_COLOR_ATTACHMENT0
, GL_COLOR_ATTACHMENT1
} );
1051 #endif /* ROUTES_C */