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
)
44 vg_info( "------- time lap %s -------\n",
45 mdl_pstr(&world
->meta
,route
->pstr_name
) );
47 double start_time
= 0.0;
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_count
++;
72 last_version
= rg
->timing_version
;
74 vg_info( "%u %f [%s]\n", rg
->timing_version
, rg
->timing_time
,
75 (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
;
90 vg_info( "%u %f\n", world_static
.current_run_version
, world_static
.time
);
92 if( valid_count
==route
->checkpoints_count
){
93 f64 lap_time
= world_static
.time
- start_time
;
95 if( (route
->best_laptime
== 0.0) || (lap_time
< route
->best_laptime
) ){
96 route
->best_laptime
= lap_time
;
97 route
->achievment_status
|= 0x1;
100 route
->achievment_status
|= 0x2;
103 /* for steam achievements. */
104 if( route
->anon
.official_track_id
!= 0xffffffff ){
105 struct track_info
*ti
= &track_infos
[ route
->anon
.official_track_id
];
106 if( ti
->achievement_id
){
107 steam_set_achievement( ti
->achievement_id
);
108 steam_store_achievements();
113 &world_static
.instance_addons
[ world_static
.active_instance
]->alias
;
115 char mod_uid
[ ADDON_UID_MAX
];
116 addon_alias_uid( alias
, mod_uid
);
117 network_publish_laptime( mod_uid
,
118 mdl_pstr( &world
->meta
, route
->pstr_name
),
122 route
->valid_checkpoints
= valid_count
+1;
124 vg_info( "valid: %u\n", valid_count
);
125 vg_info( "----------------------------\n" );
129 * When going through a gate this is called for bookkeeping purposes
131 static void world_routes_activate_entry_gate( world_instance
*world
,
134 world_static
.last_use
= world_static
.time
;
135 ent_gate
*dest
= mdl_arritm( &world
->ent_gate
, rg
->target
);
137 if( localplayer
.rewinded_since_last_gate
){
138 localplayer
.rewinded_since_last_gate
= 0;
139 dest
->flags
&= ~k_ent_gate_clean_pass
;
142 dest
->flags
|= k_ent_gate_clean_pass
;
144 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
145 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
147 u32 active_prev
= route
->active_checkpoint
;
148 route
->active_checkpoint
= 0xffff;
150 for( u32 j
=0; j
<4; j
++ ){
151 if( dest
->routes
[j
] == i
){
152 for( u32 k
=0; k
<route
->checkpoints_count
; k
++ ){
153 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
,
154 route
->checkpoints_start
+k
);
156 ent_gate
*gk
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
157 gk
= mdl_arritm( &world
->ent_gate
, gk
->target
);
159 route
->active_checkpoint
= k
;
160 world_routes_time_lap( world
, route
);
169 dest
->timing_version
= world_static
.current_run_version
;
170 dest
->timing_time
= world_static
.time
;
172 world_static
.current_run_version
++;
175 /* draw lines along the paths */
176 static void world_routes_debug( world_instance
*world
)
178 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route_node
); i
++ ){
179 ent_route_node
*rn
= mdl_arritm(&world
->ent_route_node
,i
);
180 vg_line_point( rn
->co
, 0.25f
, VG__WHITE
);
183 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
184 ent_route
*route
= mdl_arritm(&world
->ent_route
, i
);
186 u32 colours
[] = { 0xfff58142, 0xff42cbf5, 0xff42f56c, 0xfff542b3,
190 if( route
->active_checkpoint
!= 0xffff ){
191 cc
= colours
[i
%vg_list_size(colours
)];
194 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
195 int i0
= route
->checkpoints_start
+i
,
196 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
198 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
199 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
201 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
202 ent_gate
*end_gate
= mdl_arritm( &world
->ent_gate
, c1
->gate_index
);
205 v3_copy( start_gate
->co
[1], p0
);
207 for( int j
=0; j
<c0
->path_count
; j
++ ){
208 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
211 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
214 v3_copy( rn
->co
, p1
);
215 vg_line( p0
, p1
, cc
);
219 v3_copy( end_gate
->co
[0], p1
);
220 vg_line( p0
, p1
, cc
);
227 void world_routes_place_curve( world_instance
*world
, ent_route
*route
,
228 v4f h
[3], v3f n0
, v3f n2
, scene_context
*scene
)
234 float total_length
= 0.0f
,
238 v3_copy( h
[0], last
);
239 for( int it
=0; it
<128; it
++ ){
240 t
= (float)(it
+1) * (1.0f
/128.0f
);
241 eval_bezier3( h
[0], h
[1], h
[2], t
, p
);
242 total_length
+= v3_dist( p
, last
);
246 float patch_size
= 4.0f
,
247 patch_count
= ceilf( total_length
/ patch_size
);
250 v3_copy( h
[0], last
);
252 for( int it
=0; it
<128; it
++ ){
253 float const k_sample_dist
= 0.0025f
,
256 eval_bezier3( h
[0], h
[1], h
[2], t
, p
);
257 eval_bezier3( h
[0], h
[1], h
[2], t
+k_sample_dist
, pd
);
259 travel_length
+= v3_dist( p
, last
);
261 float mod
= k_sample_dist
/ v3_dist( p
, pd
);
265 v3_muls( n0
, -(1.0f
-t
), up
);
266 v3_muladds( up
, n2
, -t
, up
);
270 v3_cross( up
, v0
, right
);
271 v3_normalize( right
);
273 float cur_x
= (1.0f
-t
)*h
[0][3] + t
*h
[2][3];
275 v3f sc
, sa
, sb
, down
;
276 v3_muladds( p
, right
, cur_x
* k_line_width
, sc
);
277 v3_muladds( sc
, up
, 1.5f
, sc
);
278 v3_muladds( sc
, right
, k_line_width
*0.95f
, sa
);
279 v3_muladds( sc
, right
, 0.0f
, sb
);
280 v3_muls( up
, -1.0f
, down
);
286 int resa
= ray_world( world
, sa
, down
, &ha
, k_material_flag_ghosts
),
287 resb
= ray_world( world
, sb
, down
, &hb
, k_material_flag_ghosts
);
290 struct world_surface
*surfa
= ray_hit_surface( world
, &ha
),
291 *surfb
= ray_hit_surface( world
, &hb
);
293 if( (surfa
->info
.flags
& k_material_flag_skate_target
) &&
294 (surfb
->info
.flags
& k_material_flag_skate_target
) )
298 float gap
= vg_fractf(cur_x
*0.5f
)*0.02f
;
300 v3_muladds( ha
.pos
, up
, 0.06f
+gap
, va
.co
);
301 v3_muladds( hb
.pos
, up
, 0.06f
+gap
, vb
.co
);
303 scene_vert_pack_norm( &va
, up
);
304 scene_vert_pack_norm( &vb
, up
);
306 float t1
= (travel_length
/ total_length
) * patch_count
;
312 scene_push_vert( scene
, &va
);
313 scene_push_vert( scene
, &vb
);
316 /* Connect them with triangles */
317 scene_push_tri( scene
, (u32
[3]){
318 last_valid
+0-2, last_valid
+1-2, last_valid
+2-2} );
319 scene_push_tri( scene
, (u32
[3]){
320 last_valid
+1-2, last_valid
+3-2, last_valid
+2-2} );
323 last_valid
= scene
->vertex_count
;
342 static void world_routes_gen_meshes( world_instance
*world
, u32 route_id
,
345 ent_route
*route
= mdl_arritm( &world
->ent_route
, route_id
);
347 colour
[0] = route
->colour
[0] * 255.0f
;
348 colour
[1] = route
->colour
[1] * 255.0f
;
349 colour
[2] = route
->colour
[2] * 255.0f
;
350 colour
[3] = route
->colour
[3] * 255.0f
;
354 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
355 int i0
= route
->checkpoints_start
+i
,
356 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
358 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
359 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
361 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
362 start_gate
= mdl_arritm( &world
->ent_gate
, start_gate
->target
);
364 ent_gate
*end_gate
= mdl_arritm( &world
->ent_gate
, c1
->gate_index
),
365 *collector
= mdl_arritm( &world
->ent_gate
, end_gate
->target
);
369 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, start_gate
->co
[0], p
[0] );
370 p
[0][3] = start_gate
->ref_count
;
371 p
[0][3] -= (float)start_gate
->route_count
* 0.5f
;
372 start_gate
->ref_count
++;
374 if( !c0
->path_count
)
377 /* this is so that we get nice flow through the gates */
378 v3f temp_alignments
[2];
379 ent_gate
*both
[] = { start_gate
, end_gate
};
381 for( int j
=0; j
<2; j
++ ){
382 int pi
= c0
->path_start
+ ((j
==1)? c0
->path_count
-1: 0);
384 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
, pi
);
385 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
388 v3_sub( rn
->co
, both
[j
]->co
[0], v0
);
389 float d
= v3_dot( v0
, both
[j
]->to_world
[2] );
391 v3_muladds( both
[j
]->co
[0], both
[j
]->to_world
[2], d
,
392 temp_alignments
[j
] );
393 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, temp_alignments
[j
], temp_alignments
[j
]);
397 for( int j
=0; j
<c0
->path_count
; j
++ ){
398 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
400 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
402 if( j
==0 || j
==c0
->path_count
-1 )
404 v3_copy( temp_alignments
[0], p
[1] );
406 v3_copy( temp_alignments
[1], p
[1] );
408 v3_copy( rn
->co
, p
[1] );
410 p
[1][3] = rn
->ref_count
;
411 p
[1][3] -= (float)rn
->ref_total
* 0.5f
;
414 if( j
+1 < c0
->path_count
){
415 index
= mdl_arritm( &world
->ent_path_index
,
416 c0
->path_start
+j
+1 );
417 rn
= mdl_arritm( &world
->ent_route_node
, index
->index
);
419 if( j
+1 == c0
->path_count
-1 )
420 v3_lerp( p
[1], temp_alignments
[1], 0.5f
, p
[2] );
422 v3_lerp( p
[1], rn
->co
, 0.5f
, p
[2] );
424 p
[2][3] = rn
->ref_count
;
425 p
[2][3] -= (float)rn
->ref_total
* 0.5f
;
428 v3_copy( end_gate
->co
[0], p
[2] );
429 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, p
[2], p
[2] );
430 p
[2][3] = collector
->ref_count
;
432 if( i
== route
->checkpoints_count
-1)
435 p
[2][3] -= (float)collector
->route_count
* 0.5f
;
436 //collector->ref_count ++;
439 /* p0,p1,p2 bezier patch is complete
440 * --------------------------------------*/
441 v3f surf0
, surf2
, n0
, n2
;
443 if( bh_closest_point( world
->geo_bh
, p
[0], surf0
, 5.0f
) == -1 )
444 v3_add( (v3f
){0.0f
,-0.1f
,0.0f
}, p
[0], surf0
);
446 if( bh_closest_point( world
->geo_bh
, p
[2], surf2
, 5.0f
) == -1 )
447 v3_add( (v3f
){0.0f
,-0.1f
,0.0f
}, p
[2], surf2
);
449 v3_sub( surf0
, p
[0], n0
);
450 v3_sub( surf2
, p
[2], n2
);
454 world_routes_place_curve( world
, route
, p
, n0
, n2
, sc
);
457 v4_copy( p
[2], p
[0] );
461 scene_copy_slice( sc
, &route
->sm
);
465 struct world_surface
*world_tri_index_surface( world_instance
*world
,
469 * Create the strips of colour that run through the world along course paths
471 static void world_gen_routes_generate( u32 instance_id
){
472 world_instance
*world
= &world_static
.instances
[ instance_id
];
473 vg_info( "Generating route meshes\n" );
476 vg_rand_seed( 2000 );
477 vg_async_item
*call_scene
= scene_alloc_async( &world
->scene_lines
,
478 &world
->mesh_route_lines
,
481 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
482 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
484 gate
->route_count
= 0;
487 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route_node
); i
++ ){
488 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
, i
);
493 for( u32 k
=0; k
<mdl_arrcount(&world
->ent_route
); k
++ ){
494 ent_route
*route
= mdl_arritm( &world
->ent_route
, k
);
496 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
497 int i0
= route
->checkpoints_start
+i
,
498 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
500 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
501 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
503 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
504 start_gate
= mdl_arritm( &world
->ent_gate
, start_gate
->target
);
505 start_gate
->route_count
++;
507 if( !c0
->path_count
)
510 for( int j
=0; j
<c0
->path_count
; j
++ ){
511 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
513 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
520 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
521 world_routes_gen_meshes( world
, i
, &world
->scene_lines
);
524 vg_async_dispatch( call_scene
, async_scene_upload
);
525 world_routes_clear( world
);
528 /* load all routes from model header */
529 static void world_gen_routes_ent_init( world_instance
*world
){
530 vg_info( "Initializing routes\n" );
532 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
533 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
534 for( u32 j
=0; j
<4; j
++ ){
535 gate
->routes
[j
] = 0xffff;
539 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
540 ent_route
*route
= mdl_arritm(&world
->ent_route
,i
);
541 mdl_transform_m4x3( &route
->anon
.transform
, route
->board_transform
);
543 route
->anon
.official_track_id
= 0xffffffff;
544 for( u32 j
=0; j
<vg_list_size(track_infos
); j
++ ){
545 if( !strcmp(track_infos
[j
].name
,
546 mdl_pstr(&world
->meta
,route
->pstr_name
))){
547 route
->anon
.official_track_id
= j
;
551 for( u32 j
=0; j
<route
->checkpoints_count
; j
++ ){
552 u32 id
= route
->checkpoints_start
+ j
;
553 ent_checkpoint
*cp
= mdl_arritm(&world
->ent_checkpoint
,id
);
555 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
557 for( u32 k
=0; k
<4; k
++ ){
558 if( gate
->routes
[k
] == 0xffff ){
564 if( (gate
->flags
& k_ent_gate_linked
) &
565 !(gate
->flags
& k_ent_gate_nonlocal
) ){
566 gate
= mdl_arritm(&world
->ent_gate
, gate
->target
);
568 for( u32 k
=0; k
<4; k
++ ){
569 if( gate
->routes
[k
] == i
){
570 vg_error( "already assigned route to gate\n" );
573 if( gate
->routes
[k
] == 0xffff ){
582 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
583 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
586 world_routes_clear( world
);
589 static void world_routes_recv_scoreboard( world_instance
*world
,
590 vg_msg
*body
, u32 route_id
,
591 enum request_status status
){
592 if( route_id
>= mdl_arrcount( &world
->ent_route
) ){
593 vg_error( "Scoreboard route_id out of range (%u)\n", route_id
);
597 struct leaderboard_cache
*board
= &world
->leaderboard_cache
[ route_id
];
598 board
->status
= status
;
605 if( body
->max
> NETWORK_REQUEST_MAX
){
606 vg_error( "Scoreboard leaderboard too big (%u>%u)\n", body
->max
,
607 NETWORK_REQUEST_MAX
);
611 memcpy( board
->data
, body
->buf
, body
->max
);
612 board
->data_len
= body
->max
;
616 * -----------------------------------------------------------------------------
618 * -----------------------------------------------------------------------------
621 static void world_routes_init(void){
622 world_static
.current_run_version
= 200;
623 world_static
.time
= 300.0;
624 world_static
.last_use
= 0.0;
626 shader_scene_route_register();
627 shader_routeui_register();
630 static void world_routes_update( world_instance
*world
){
631 world_static
.time
+= vg
.time_delta
;
633 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
634 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
636 int target
= route
->active_checkpoint
== 0xffff? 0: 1;
637 route
->factive
= vg_lerpf( route
->factive
, target
,
638 0.6f
*vg
.time_frame_delta
);
641 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
642 struct text_particle
*particle
= &world_render
.text_particles
[i
];
643 rb_object_debug( &particle
->obj
, VG__RED
);
647 static void world_routes_fixedupdate( world_instance
*world
){
650 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
651 struct text_particle
*particle
= &world_render
.text_particles
[i
];
653 if( rb_global_has_space() ){
654 rb_ct
*buf
= rb_global_buffer();
656 int l
= rb_sphere__scene( particle
->obj
.rb
.to_world
,
657 &particle
->obj
.inf
.sphere
,
658 NULL
, &world
->rb_geo
.inf
.scene
, buf
,
659 k_material_flag_ghosts
);
661 for( int j
=0; j
<l
; j
++ ){
662 buf
[j
].rba
= &particle
->obj
.rb
;
663 buf
[j
].rbb
= &world
->rb_geo
.rb
;
666 rb_contact_count
+= l
;
670 rb_presolve_contacts( rb_contact_buffer
, rb_contact_count
);
672 for( int i
=0; i
<rb_contact_count
; i
++ ){
673 rb_contact_restitution( rb_contact_buffer
+i
, vg_randf64() );
676 for( int i
=0; i
<6; i
++ ){
677 rb_solve_contacts( rb_contact_buffer
, rb_contact_count
);
680 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
681 struct text_particle
*particle
= &world_render
.text_particles
[i
];
682 rb_iter( &particle
->obj
.rb
);
685 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
686 struct text_particle
*particle
= &world_render
.text_particles
[i
];
687 rb_update_transform( &particle
->obj
.rb
);
691 static void bind_terrain_noise(void);
692 static void world_bind_light_array( world_instance
*world
,
693 GLuint shader
, GLuint location
,
695 static void world_bind_light_index( world_instance
*world
,
696 GLuint shader
, GLuint location
,
699 static void world_routes_update_timer_texts( world_instance
*world
){
700 world_render
.timer_text_count
= 0;
702 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
703 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
705 if( route
->active_checkpoint
!= 0xffff ){
706 u32 next
= route
->active_checkpoint
+1;
707 next
= next
% route
->checkpoints_count
;
708 next
+= route
->checkpoints_start
;
710 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, next
);
711 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
712 ent_gate
*dest
= mdl_arritm( &world
->ent_gate
, gate
->target
);
716 if( dest
->routes
[j
] == i
){
726 struct timer_text
*text
=
727 &world_render
.timer_texts
[ world_render
.timer_text_count
++ ];
732 if( route
->valid_checkpoints
>= route
->checkpoints_count
){
733 double lap_time
= world_static
.time
- route
->timing_base
,
734 time_centiseconds
= lap_time
* 100.0;
736 if( time_centiseconds
> (float)0xfffe ) time_centiseconds
= 0.0;
738 u16 centiseconds
= time_centiseconds
,
739 seconds
= centiseconds
/ 100,
740 minutes
= seconds
/ 60;
746 if( minutes
> 9 ) minutes
= 9;
750 highscore_intr( text
->text
, minutes
, 1, ' ' ); j
++;
751 text
->text
[j
++] = ':';
754 if( seconds
>= 10 || minutes
){
755 highscore_intr( text
->text
+j
, seconds
, 2, '0' ); j
+=2;
758 highscore_intr( text
->text
+j
, seconds
, 1, '0' ); j
++;
761 text
->text
[j
++] = '.';
762 highscore_intr( text
->text
+j
, centiseconds
, 1, '0' ); j
++;
763 text
->text
[j
] = '\0';
766 highscore_intr( text
->text
, route
->valid_checkpoints
, 1, ' ' );
768 highscore_intr( text
->text
+2, route
->checkpoints_count
+1, 1, ' ' );
769 text
->text
[3] = '\0';
772 gui_font3d
.font
= &gui
.font
;
773 float align_r
= font3d_string_width( 0, text
->text
);
777 { -0.92f
, h0
, depth
},
778 { 0.92f
- align_r
, h0
, depth
},
779 { -0.92f
, h1
, depth
},
780 { 0.92f
- align_r
, h1
, depth
},
783 if( dest
->route_count
== 1 ){
784 positions
[0][0] = -align_r
*0.5f
;
785 positions
[0][1] = h1
;
789 ent_gate_get_mdl_mtx( gate
, mmdl
);
791 m3x3_copy( mmdl
, text
->transform
);
792 float ratio
= v3_length(text
->transform
[0]) /
793 v3_length(text
->transform
[1]);
795 m3x3_scale( text
->transform
, (v3f
){ size
, size
*ratio
, 0.1f
} );
796 m4x3_mulv( mmdl
, positions
[j
], text
->transform
[3] );
801 static void world_routes_fracture( world_instance
*world
, ent_gate
*gate
,
802 v3f imp_co
, v3f imp_v
)
804 world_render
.text_particle_count
= 0;
806 for( u32 i
=0; i
<world_render
.timer_text_count
; i
++ ){
807 struct timer_text
*text
= &world_render
.timer_texts
[i
];
809 if( text
->gate
!= gate
) continue;
812 m4x3_mul( gate
->transport
, text
->transform
, transform
);
816 m4x3_decompose( transform
, co
, q
, s
);
822 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
823 v3_muls( text
->route
->colour
, brightness
, colour
);
824 colour
[3] = 1.0f
-text
->route
->factive
;
826 for( u32 j
=0;; j
++ ){
827 char c
= text
->text
[j
];
830 ent_glyph
*glyph
= font3d_glyph( &gui
.font
, 0, c
);
831 if( !glyph
) continue;
833 if( c
>= (u32
)'0' && c
<= (u32
)'9' && glyph
->indice_count
){
834 struct text_particle
*particle
=
835 &world_render
.text_particles
[world_render
.text_particle_count
++];
837 particle
->glyph
= glyph
;
838 v4_copy( colour
, particle
->colour
);
841 v2_muls( glyph
->size
, 0.5f
, origin
);
846 v3_add( offset
, origin
, world_co
);
847 m4x3_mulv( transform
, world_co
, world_co
);
849 float r
= vg_maxf( s
[0]*glyph
->size
[0], s
[1]*glyph
->size
[1] )*0.5f
;
851 m3x3_identity( particle
->mlocal
);
852 m3x3_scale( particle
->mlocal
, s
);
854 v3_muls( origin
, -1.0f
, particle
->mlocal
[3] );
856 v3_copy( world_co
, particle
->obj
.rb
.co
);
857 v3_muls( imp_v
, 1.0f
+vg_randf64(), particle
->obj
.rb
.v
);
858 particle
->obj
.rb
.v
[1] += 2.0f
;
860 v4_copy( q
, particle
->obj
.rb
.q
);
861 particle
->obj
.rb
.w
[0] = vg_randf64()*2.0f
-1.0f
;
862 particle
->obj
.rb
.w
[1] = vg_randf64()*2.0f
-1.0f
;
863 particle
->obj
.rb
.w
[2] = vg_randf64()*2.0f
-1.0f
;
865 particle
->obj
.type
= k_rb_shape_sphere
;
866 particle
->obj
.inf
.sphere
.radius
= r
*0.6f
;
868 rb_init_object( &particle
->obj
);
870 offset
[0] += glyph
->size
[0];
875 static void render_gate_markers( m4x3f world_mmdl
, int run_id
, ent_gate
*gate
){
876 for( u32 j
=0; j
<4; j
++ ){
877 if( gate
->routes
[j
] == run_id
){
879 ent_gate_get_mdl_mtx( gate
, mmdl
);
880 m4x3_mul( world_mmdl
, mmdl
, mmdl
);
881 shader_model_gate_uMdl( mmdl
);
882 mdl_draw_submesh( &world_gates
.sm_marker
[j
] );
888 static void render_world_routes( world_instance
*world
,
889 world_instance
*host_world
,
890 m4x3f mmdl
, camera
*cam
,
891 int viewing_from_gate
, int viewing_from_hub
){
893 shader_scene_route_use();
894 shader_scene_route_uTexGarbage(0);
895 world_link_lighting_ub( host_world
, _shader_scene_route
.id
);
896 world_bind_position_texture( host_world
, _shader_scene_route
.id
,
897 _uniform_scene_route_g_world_depth
, 2 );
898 world_bind_light_array( host_world
, _shader_scene_route
.id
,
899 _uniform_scene_route_uLightsArray
, 3 );
900 world_bind_light_index( host_world
, _shader_scene_route
.id
,
901 _uniform_scene_route_uLightsIndex
, 4 );
902 bind_terrain_noise();
904 shader_scene_route_uPv( cam
->mtx
.pv
);
906 if( viewing_from_hub
){
908 m4x3_expand( mmdl
, m4mdl
);
909 m4x4_mul( cam
->mtx_prev
.pv
, m4mdl
, pvm
);
910 shader_scene_route_uMdl( mmdl
);
911 shader_scene_route_uPvmPrev( pvm
);
914 m3x3_inv( mmdl
, mnormal
);
915 m3x3_transpose( mnormal
, mnormal
);
916 v3_normalize( mnormal
[0] );
917 v3_normalize( mnormal
[1] );
918 v3_normalize( mnormal
[2] );
919 shader_scene_route_uNormalMtx( mnormal
);
922 shader_scene_route_uMdl( mmdl
);
923 shader_scene_route_uPvmPrev( cam
->mtx_prev
.pv
);
925 m3x3_identity( ident
);
926 shader_scene_route_uNormalMtx( ident
);
929 shader_scene_route_uCamera( cam
->transform
[3] );
931 mesh_bind( &world
->mesh_route_lines
);
933 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
934 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
936 f32 t
= viewing_from_hub
? 1.0f
: route
->factive
;
939 v3_lerp( (v3f
){0.7f
,0.7f
,0.7f
}, route
->colour
, t
, colour
);
942 shader_scene_route_uColour( colour
);
943 mdl_draw_submesh( &route
->sm
);
947 * ---------------------------------------------------- */
948 if( !viewing_from_gate
&& !viewing_from_hub
){
949 font3d_bind( &gui
.font
, k_font_shader_default
, 0, world
, cam
);
951 for( u32 i
=0; i
<world_render
.timer_text_count
; i
++ ){
952 struct timer_text
*text
= &world_render
.timer_texts
[i
];
955 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
956 v3_muls( text
->route
->colour
, brightness
, colour
);
957 colour
[3] = 1.0f
-text
->route
->factive
;
959 shader_model_font_uColour( colour
);
960 font3d_simple_draw( 0, text
->text
, cam
, text
->transform
);
963 shader_model_font_uOffset( (v4f
){0.0f
,0.0f
,0.0f
,1.0f
} );
965 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
966 struct text_particle
*particle
= &world_render
.text_particles
[i
];
970 m4x3_expand( particle
->mdl
, prev_mtx
);
971 m4x4_mul( cam
->mtx_prev
.pv
, prev_mtx
, prev_mtx
);
973 shader_model_font_uPvmPrev( prev_mtx
);
977 rb_extrapolate( &particle
->obj
.rb
, model
[3], q
);
980 m4x3_mul( model
, particle
->mlocal
, particle
->mdl
);
981 shader_model_font_uMdl( particle
->mdl
);
982 shader_model_font_uColour( particle
->colour
);
984 mesh_drawn( particle
->glyph
->indice_start
,
985 particle
->glyph
->indice_count
);
990 * ---------------------------------------------------- */
992 shader_model_gate_use();
993 shader_model_gate_uPv( cam
->mtx
.pv
);
994 shader_model_gate_uCam( cam
->pos
);
995 shader_model_gate_uTime( vg
.time
*0.25f
);
996 shader_model_gate_uInvRes( (v2f
){
997 1.0f
/ (float)vg
.window_x
,
998 1.0f
/ (float)vg
.window_y
});
1000 mesh_bind( &world_gates
.mesh
);
1002 /* skip writing into the motion vectors for this */
1003 glDrawBuffers( 1, (GLenum
[]){ GL_COLOR_ATTACHMENT0
} );
1004 glDisable( GL_CULL_FACE
);
1006 if( viewing_from_hub
){
1007 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
1008 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
1011 v3_muls( route
->colour
, 1.6666f
, colour
);
1014 shader_model_gate_uColour( colour
);
1016 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_gate
); j
++ ){
1017 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, j
);
1018 if( !(gate
->flags
& k_ent_gate_nonlocal
) )
1019 render_gate_markers( mmdl
, i
, gate
);
1024 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
1025 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
1027 if( route
->active_checkpoint
!= 0xffff ){
1029 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
1030 v3_muls( route
->colour
, brightness
, colour
);
1031 colour
[3] = 1.0f
-route
->factive
;
1033 shader_model_gate_uColour( colour
);
1035 u32 next
= route
->active_checkpoint
+1+viewing_from_gate
;
1036 next
= next
% route
->checkpoints_count
;
1037 next
+= route
->checkpoints_start
;
1039 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, next
);
1040 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
1041 render_gate_markers( mmdl
, i
, gate
);
1045 glEnable( GL_CULL_FACE
);
1046 glDrawBuffers( 2, (GLenum
[]){ GL_COLOR_ATTACHMENT0
, GL_COLOR_ATTACHMENT1
} );
1049 #endif /* ROUTES_C */