4 * Copyright (C) 2021-2024 Mt.ZERO Software - All Rights Reserved
11 #include "world_routes.h"
12 #include "world_gate.h"
13 #include "world_load.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"
25 #include "scene_rigidbody.h"
27 void world_routes_clear( world_instance
*world
)
29 for( u32 i
=0; i
<mdl_arrcount( &world
->ent_route
); i
++ ){
30 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
31 route
->active_checkpoint
= 0xffff;
34 for( u32 i
=0; i
<mdl_arrcount( &world
->ent_gate
); i
++ ){
35 ent_gate
*rg
= mdl_arritm( &world
->ent_gate
, i
);
36 rg
->timing_version
= 0;
37 rg
->timing_time
= 0.0;
40 world_static
.current_run_version
+= 4;
41 world_static
.last_use
= 0.0;
44 static void world_routes_time_lap( world_instance
*world
, ent_route
*route
){
45 vg_info( "------- time lap %s -------\n",
46 mdl_pstr(&world
->meta
,route
->pstr_name
) );
48 double start_time
= 0.0;
51 ent_checkpoint
*last_cp
= NULL
;
54 int clean
= !localplayer
.rewinded_since_last_gate
;
56 for( u32 i
=0; i
<route
->checkpoints_count
; i
++ ){
57 u32 cpid
= (i
+route
->active_checkpoint
) % route
->checkpoints_count
;
58 cpid
+= route
->checkpoints_start
;
60 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, cpid
);
61 ent_gate
*rg
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
62 rg
= mdl_arritm( &world
->ent_gate
, rg
->target
);
65 route
->timing_base
= rg
->timing_time
;
69 start_time
= rg
->timing_time
;
71 if( last_version
+1 == rg
->timing_version
) valid_sections
++;
72 else valid_sections
= 0;
75 vg_info( "%u %f [%s]\n", rg
->timing_version
, rg
->timing_time
,
76 i
? ((rg
->flags
& k_ent_gate_clean_pass
)? "CLEAN": " "):
79 if( !(rg
->flags
& k_ent_gate_clean_pass
) )
82 last_version
= rg
->timing_version
;
83 last_time
= rg
->timing_time
;
87 if( world_static
.current_run_version
== last_version
+1 ){
90 if( route
->checkpoints_count
== 1 ){
91 route
->timing_base
= world_static
.time
;
94 f32 section
= world_static
.time
- last_time
;
95 if( (section
< last_cp
->best_time
) || (last_cp
->best_time
== 0.0f
) ){
96 last_cp
->best_time
= section
;
99 else valid_sections
= 0;
101 vg_info( "%u %f [%s]\n",
102 world_static
.current_run_version
, world_static
.time
,
103 !localplayer
.rewinded_since_last_gate
? "CLEAN": " " );
105 if( valid_sections
==route
->checkpoints_count
){
106 f64 lap_time
= world_static
.time
- start_time
;
108 if( (route
->best_laptime
== 0.0) || (lap_time
< route
->best_laptime
) ){
109 route
->best_laptime
= lap_time
;
112 route
->flags
|= k_ent_route_flag_achieve_silver
;
113 if( clean
) route
->flags
|= k_ent_route_flag_achieve_gold
;
114 ent_region_re_eval( world
);
116 /* for steam achievements. */
117 if( route
->anon
.official_track_id
!= 0xffffffff ){
118 struct track_info
*ti
= &track_infos
[ route
->anon
.official_track_id
];
119 if( ti
->achievement_id
){
120 steam_set_achievement( ti
->achievement_id
);
121 steam_store_achievements();
126 &world_static
.instance_addons
[ world_static
.active_instance
]->alias
;
128 char mod_uid
[ ADDON_UID_MAX
];
129 addon_alias_uid( alias
, mod_uid
);
130 network_publish_laptime( mod_uid
,
131 mdl_pstr( &world
->meta
, route
->pstr_name
),
135 route
->valid_checkpoints
= valid_sections
+1;
137 vg_info( "valid sections: %u\n", valid_sections
);
138 vg_info( "----------------------------\n" );
140 route
->ui_residual
= 1.0f
;
141 route
->ui_residual_block_w
= route
->ui_first_block_width
;
145 * When going through a gate this is called for bookkeeping purposes
147 void world_routes_activate_entry_gate( world_instance
*world
, ent_gate
*rg
)
149 world_static
.last_use
= world_static
.time
;
150 ent_gate
*dest
= mdl_arritm( &world
->ent_gate
, rg
->target
);
152 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
153 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
155 u32 active_prev
= route
->active_checkpoint
;
156 route
->active_checkpoint
= 0xffff;
158 for( u32 j
=0; j
<4; j
++ ){
159 if( dest
->routes
[j
] == i
){
160 for( u32 k
=0; k
<route
->checkpoints_count
; k
++ ){
161 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
,
162 route
->checkpoints_start
+k
);
164 ent_gate
*gk
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
165 gk
= mdl_arritm( &world
->ent_gate
, gk
->target
);
167 route
->active_checkpoint
= k
;
168 world_routes_time_lap( world
, route
);
177 dest
->timing_version
= world_static
.current_run_version
;
178 dest
->timing_time
= world_static
.time
;
180 if( localplayer
.rewinded_since_last_gate
){
181 localplayer
.rewinded_since_last_gate
= 0;
182 dest
->flags
&= ~k_ent_gate_clean_pass
;
185 dest
->flags
|= k_ent_gate_clean_pass
;
187 world_static
.current_run_version
++;
190 /* draw lines along the paths */
191 static void world_routes_debug( world_instance
*world
)
193 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route_node
); i
++ ){
194 ent_route_node
*rn
= mdl_arritm(&world
->ent_route_node
,i
);
195 vg_line_point( rn
->co
, 0.25f
, VG__WHITE
);
198 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
199 ent_route
*route
= mdl_arritm(&world
->ent_route
, i
);
201 u32 colours
[] = { 0xfff58142, 0xff42cbf5, 0xff42f56c, 0xfff542b3,
205 if( route
->active_checkpoint
!= 0xffff ){
206 cc
= colours
[i
%vg_list_size(colours
)];
209 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
210 int i0
= route
->checkpoints_start
+i
,
211 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
213 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
214 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
216 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
217 ent_gate
*end_gate
= mdl_arritm( &world
->ent_gate
, c1
->gate_index
);
220 v3_copy( start_gate
->co
[1], p0
);
222 for( int j
=0; j
<c0
->path_count
; j
++ ){
223 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
226 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
229 v3_copy( rn
->co
, p1
);
230 vg_line( p0
, p1
, cc
);
234 v3_copy( end_gate
->co
[0], p1
);
235 vg_line( p0
, p1
, cc
);
242 void world_routes_place_curve( world_instance
*world
, ent_route
*route
,
243 v4f h
[3], v3f n0
, v3f n2
, scene_context
*scene
)
249 float total_length
= 0.0f
,
253 v3_copy( h
[0], last
);
254 for( int it
=0; it
<128; it
++ ){
255 t
= (float)(it
+1) * (1.0f
/128.0f
);
256 eval_bezier3( h
[0], h
[1], h
[2], t
, p
);
257 total_length
+= v3_dist( p
, last
);
261 float patch_size
= 4.0f
,
262 patch_count
= ceilf( total_length
/ patch_size
);
265 v3_copy( h
[0], last
);
267 for( int it
=0; it
<128; it
++ ){
268 float const k_sample_dist
= 0.0025f
,
271 eval_bezier3( h
[0], h
[1], h
[2], t
, p
);
272 eval_bezier3( h
[0], h
[1], h
[2], t
+k_sample_dist
, pd
);
274 travel_length
+= v3_dist( p
, last
);
276 float mod
= k_sample_dist
/ v3_dist( p
, pd
);
280 v3_muls( n0
, -(1.0f
-t
), up
);
281 v3_muladds( up
, n2
, -t
, up
);
285 v3_cross( up
, v0
, right
);
286 v3_normalize( right
);
288 float cur_x
= (1.0f
-t
)*h
[0][3] + t
*h
[2][3];
290 v3f sc
, sa
, sb
, down
;
291 v3_muladds( p
, right
, cur_x
* k_line_width
, sc
);
292 v3_muladds( sc
, up
, 1.5f
, sc
);
293 v3_muladds( sc
, right
, k_line_width
*0.95f
, sa
);
294 v3_muladds( sc
, right
, 0.0f
, sb
);
295 v3_muls( up
, -1.0f
, down
);
301 int resa
= ray_world( world
, sa
, down
, &ha
, k_material_flag_ghosts
),
302 resb
= ray_world( world
, sb
, down
, &hb
, k_material_flag_ghosts
);
305 struct world_surface
*surfa
= ray_hit_surface( world
, &ha
),
306 *surfb
= ray_hit_surface( world
, &hb
);
308 if( (surfa
->info
.flags
& k_material_flag_skate_target
) &&
309 (surfb
->info
.flags
& k_material_flag_skate_target
) )
313 float gap
= vg_fractf(cur_x
*0.5f
)*0.02f
;
315 v3_muladds( ha
.pos
, up
, 0.06f
+gap
, va
.co
);
316 v3_muladds( hb
.pos
, up
, 0.06f
+gap
, vb
.co
);
318 scene_vert_pack_norm( &va
, up
, 0.0f
);
319 scene_vert_pack_norm( &vb
, up
, 0.0f
);
321 float t1
= (travel_length
/ total_length
) * patch_count
;
327 scene_push_vert( scene
, &va
);
328 scene_push_vert( scene
, &vb
);
331 /* Connect them with triangles */
332 scene_push_tri( scene
, (u32
[3]){
333 last_valid
+0-2, last_valid
+1-2, last_valid
+2-2} );
334 scene_push_tri( scene
, (u32
[3]){
335 last_valid
+1-2, last_valid
+3-2, last_valid
+2-2} );
338 last_valid
= scene
->vertex_count
;
357 static void world_routes_gen_meshes( world_instance
*world
, u32 route_id
,
360 ent_route
*route
= mdl_arritm( &world
->ent_route
, route_id
);
362 colour
[0] = route
->colour
[0] * 255.0f
;
363 colour
[1] = route
->colour
[1] * 255.0f
;
364 colour
[2] = route
->colour
[2] * 255.0f
;
365 colour
[3] = route
->colour
[3] * 255.0f
;
369 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
370 int i0
= route
->checkpoints_start
+i
,
371 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
373 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
374 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
376 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
377 start_gate
= mdl_arritm( &world
->ent_gate
, start_gate
->target
);
379 ent_gate
*end_gate
= mdl_arritm( &world
->ent_gate
, c1
->gate_index
),
380 *collector
= mdl_arritm( &world
->ent_gate
, end_gate
->target
);
384 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, start_gate
->co
[0], p
[0] );
385 p
[0][3] = start_gate
->ref_count
;
386 p
[0][3] -= (float)start_gate
->route_count
* 0.5f
;
387 start_gate
->ref_count
++;
389 if( !c0
->path_count
)
392 /* this is so that we get nice flow through the gates */
393 v3f temp_alignments
[2];
394 ent_gate
*both
[] = { start_gate
, end_gate
};
396 for( int j
=0; j
<2; j
++ ){
397 int pi
= c0
->path_start
+ ((j
==1)? c0
->path_count
-1: 0);
399 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
, pi
);
400 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
403 v3_sub( rn
->co
, both
[j
]->co
[0], v0
);
404 float d
= v3_dot( v0
, both
[j
]->to_world
[2] );
406 v3_muladds( both
[j
]->co
[0], both
[j
]->to_world
[2], d
,
407 temp_alignments
[j
] );
408 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, temp_alignments
[j
], temp_alignments
[j
]);
412 for( int j
=0; j
<c0
->path_count
; j
++ ){
413 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
415 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
417 if( j
==0 || j
==c0
->path_count
-1 )
419 v3_copy( temp_alignments
[0], p
[1] );
421 v3_copy( temp_alignments
[1], p
[1] );
423 v3_copy( rn
->co
, p
[1] );
425 p
[1][3] = rn
->ref_count
;
426 p
[1][3] -= (float)rn
->ref_total
* 0.5f
;
429 if( j
+1 < c0
->path_count
){
430 index
= mdl_arritm( &world
->ent_path_index
,
431 c0
->path_start
+j
+1 );
432 rn
= mdl_arritm( &world
->ent_route_node
, index
->index
);
434 if( j
+1 == c0
->path_count
-1 )
435 v3_lerp( p
[1], temp_alignments
[1], 0.5f
, p
[2] );
437 v3_lerp( p
[1], rn
->co
, 0.5f
, p
[2] );
439 p
[2][3] = rn
->ref_count
;
440 p
[2][3] -= (float)rn
->ref_total
* 0.5f
;
443 v3_copy( end_gate
->co
[0], p
[2] );
444 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, p
[2], p
[2] );
445 p
[2][3] = collector
->ref_count
;
447 if( i
== route
->checkpoints_count
-1)
450 p
[2][3] -= (float)collector
->route_count
* 0.5f
;
451 //collector->ref_count ++;
454 /* p0,p1,p2 bezier patch is complete
455 * --------------------------------------*/
456 v3f surf0
, surf2
, n0
, n2
;
458 if( bh_closest_point( world
->geo_bh
, p
[0], surf0
, 5.0f
) == -1 )
459 v3_add( (v3f
){0.0f
,-0.1f
,0.0f
}, p
[0], surf0
);
461 if( bh_closest_point( world
->geo_bh
, p
[2], surf2
, 5.0f
) == -1 )
462 v3_add( (v3f
){0.0f
,-0.1f
,0.0f
}, p
[2], surf2
);
464 v3_sub( surf0
, p
[0], n0
);
465 v3_sub( surf2
, p
[2], n2
);
469 world_routes_place_curve( world
, route
, p
, n0
, n2
, sc
);
472 v4_copy( p
[2], p
[0] );
476 scene_copy_slice( sc
, &route
->sm
);
479 struct world_surface
*world_tri_index_surface( world_instance
*world
,
483 * Create the strips of colour that run through the world along course paths
485 void world_gen_routes_generate( u32 instance_id
)
487 world_instance
*world
= &world_static
.instances
[ instance_id
];
488 vg_info( "Generating route meshes\n" );
491 vg_async_item
*call_scene
= scene_alloc_async( &world
->scene_lines
,
492 &world
->mesh_route_lines
,
495 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
496 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
498 gate
->route_count
= 0;
501 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route_node
); i
++ ){
502 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
, i
);
507 for( u32 k
=0; k
<mdl_arrcount(&world
->ent_route
); k
++ ){
508 ent_route
*route
= mdl_arritm( &world
->ent_route
, k
);
510 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
511 int i0
= route
->checkpoints_start
+i
,
512 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
514 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
515 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
517 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
518 start_gate
= mdl_arritm( &world
->ent_gate
, start_gate
->target
);
519 start_gate
->route_count
++;
521 if( !c0
->path_count
)
524 for( int j
=0; j
<c0
->path_count
; j
++ ){
525 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
527 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
534 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
535 world_routes_gen_meshes( world
, i
, &world
->scene_lines
);
538 vg_async_dispatch( call_scene
, async_scene_upload
);
539 world_routes_clear( world
);
542 /* load all routes from model header */
543 void world_gen_routes_ent_init( world_instance
*world
)
545 vg_info( "Initializing routes\n" );
547 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
548 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
549 for( u32 j
=0; j
<4; j
++ ){
550 gate
->routes
[j
] = 0xffff;
554 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
555 ent_route
*route
= mdl_arritm(&world
->ent_route
,i
);
556 mdl_transform_m4x3( &route
->anon
.transform
, route
->board_transform
);
559 route
->best_laptime
= 0.0;
560 route
->ui_stopper
= 0.0f
;
561 route
->ui_residual
= 0.0f
;
563 if( mdl_arrcount(&world
->ent_region
) )
564 route
->flags
|= k_ent_route_flag_out_of_zone
;
566 route
->anon
.official_track_id
= 0xffffffff;
567 for( u32 j
=0; j
<vg_list_size(track_infos
); j
++ ){
568 if( !strcmp(track_infos
[j
].name
,
569 mdl_pstr(&world
->meta
,route
->pstr_name
))){
570 route
->anon
.official_track_id
= j
;
574 for( u32 j
=0; j
<route
->checkpoints_count
; j
++ ){
575 u32 id
= route
->checkpoints_start
+ j
;
576 ent_checkpoint
*cp
= mdl_arritm(&world
->ent_checkpoint
,id
);
578 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
580 for( u32 k
=0; k
<4; k
++ ){
581 if( gate
->routes
[k
] == 0xffff ){
587 if( (gate
->flags
& k_ent_gate_linked
) &
588 !(gate
->flags
& k_ent_gate_nonlocal
) ){
589 gate
= mdl_arritm(&world
->ent_gate
, gate
->target
);
591 for( u32 k
=0; k
<4; k
++ ){
592 if( gate
->routes
[k
] == i
){
593 vg_error( "already assigned route to gate\n" );
596 if( gate
->routes
[k
] == 0xffff ){
605 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
606 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
609 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_checkpoint
); i
++ ){
610 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, i
);
614 world_routes_clear( world
);
617 void world_routes_recv_scoreboard( world_instance
*world
,
618 vg_msg
*body
, u32 route_id
,
619 enum request_status status
)
621 if( route_id
>= mdl_arrcount( &world
->ent_route
) ){
622 vg_error( "Scoreboard route_id out of range (%u)\n", route_id
);
626 struct leaderboard_cache
*board
= &world
->leaderboard_cache
[ route_id
];
627 board
->status
= status
;
634 if( body
->max
> NETWORK_REQUEST_MAX
){
635 vg_error( "Scoreboard leaderboard too big (%u>%u)\n", body
->max
,
636 NETWORK_REQUEST_MAX
);
640 memcpy( board
->data
, body
->buf
, body
->max
);
641 board
->data_len
= body
->max
;
645 * -----------------------------------------------------------------------------
647 * -----------------------------------------------------------------------------
650 void world_routes_init(void)
652 world_static
.current_run_version
= 200;
653 world_static
.time
= 300.0;
654 world_static
.last_use
= 0.0;
657 void world_routes_update( world_instance
*world
)
659 world_static
.time
+= vg
.time_delta
;
661 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
662 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
664 int target
= route
->active_checkpoint
== 0xffff? 0: 1;
665 route
->factive
= vg_lerpf( route
->factive
, target
,
666 0.6f
*vg
.time_frame_delta
);
669 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
670 struct text_particle
*particle
= &world_render
.text_particles
[i
];
671 //rb_object_debug( &particle->obj, VG__RED );
675 void world_routes_fixedupdate( world_instance
*world
)
679 rigidbody _null
= {0};
680 _null
.inv_mass
= 0.0f
;
681 m3x3_zero( _null
.iI
);
683 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
684 struct text_particle
*particle
= &world_render
.text_particles
[i
];
686 if( rb_global_has_space() ){
687 rb_ct
*buf
= rb_global_buffer();
689 int l
= rb_sphere__scene( particle
->rb
.to_world
,
691 NULL
, world
->geo_bh
, buf
,
692 k_material_flag_ghosts
);
694 for( int j
=0; j
<l
; j
++ ){
695 buf
[j
].rba
= &particle
->rb
;
699 rb_contact_count
+= l
;
703 rb_presolve_contacts( rb_contact_buffer
,
704 vg
.time_fixed_delta
, rb_contact_count
);
706 for( int i
=0; i
<rb_contact_count
; i
++ ){
707 rb_contact_restitution( rb_contact_buffer
+i
, vg_randf64(&vg
.rand
) );
710 for( int i
=0; i
<6; i
++ ){
711 rb_solve_contacts( rb_contact_buffer
, rb_contact_count
);
714 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
715 struct text_particle
*particle
= &world_render
.text_particles
[i
];
716 rb_iter( &particle
->rb
);
719 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
720 struct text_particle
*particle
= &world_render
.text_particles
[i
];
721 rb_update_matrices( &particle
->rb
);
725 void bind_terrain_noise(void);
726 void world_bind_light_array( world_instance
*world
,
727 GLuint shader
, GLuint location
,
729 void world_bind_light_index( world_instance
*world
,
730 GLuint shader
, GLuint location
,
733 void world_routes_update_timer_texts( world_instance
*world
)
735 world_render
.timer_text_count
= 0;
737 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
738 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
740 if( route
->active_checkpoint
!= 0xffff ){
741 u32 next
= route
->active_checkpoint
+1;
742 next
= next
% route
->checkpoints_count
;
743 next
+= route
->checkpoints_start
;
745 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, next
);
746 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
747 ent_gate
*dest
= mdl_arritm( &world
->ent_gate
, gate
->target
);
751 if( dest
->routes
[j
] == i
){
761 struct timer_text
*text
=
762 &world_render
.timer_texts
[ world_render
.timer_text_count
++ ];
768 vg_strnull( &str
, text
->text
, sizeof(text
->text
) );
770 if( route
->valid_checkpoints
>= route
->checkpoints_count
)
772 double lap_time
= world_static
.time
- route
->timing_base
,
773 time_centiseconds
= lap_time
* 100.0;
775 if( time_centiseconds
> (float)0xfffe ) time_centiseconds
= 0.0;
777 u16 centiseconds
= time_centiseconds
,
778 seconds
= centiseconds
/ 100,
779 minutes
= seconds
/ 60;
790 vg_strcati32r( &str
, minutes
, 1, ' ' );
791 vg_strcatch( &str
, ':' );
794 if( seconds
>= 10 || minutes
)
796 vg_strcati32r( &str
, seconds
, 2, '0' );
800 vg_strcati32r( &str
, seconds
, 1, '0' );
803 vg_strcatch( &str
, '.' );
804 vg_strcati32r( &str
, centiseconds
, 1, '0' );
808 vg_strcati32r( &str
, route
->valid_checkpoints
, 1, ' ' );
809 vg_strcatch( &str
, '/' );
810 vg_strcati32r( &str
, route
->checkpoints_count
+ 1, 1, ' ' );
813 gui_font3d
.font
= &gui
.font
;
814 float align_r
= font3d_string_width( 0, text
->text
);
818 { -0.92f
, h0
, depth
},
819 { 0.92f
- align_r
, h0
, depth
},
820 { -0.92f
, h1
, depth
},
821 { 0.92f
- align_r
, h1
, depth
},
824 if( dest
->route_count
== 1 ){
825 positions
[0][0] = -align_r
*0.5f
;
826 positions
[0][1] = h1
;
830 ent_gate_get_mdl_mtx( gate
, mmdl
);
832 m3x3_copy( mmdl
, text
->transform
);
833 float ratio
= v3_length(text
->transform
[0]) /
834 v3_length(text
->transform
[1]);
836 m3x3_scale( text
->transform
, (v3f
){ size
, size
*ratio
, 0.1f
} );
837 m4x3_mulv( mmdl
, positions
[j
], text
->transform
[3] );
842 void world_routes_fracture( world_instance
*world
, ent_gate
*gate
,
843 v3f imp_co
, v3f imp_v
)
845 world_render
.text_particle_count
= 0;
847 for( u32 i
=0; i
<world_render
.timer_text_count
; i
++ ){
848 struct timer_text
*text
= &world_render
.timer_texts
[i
];
850 if( text
->gate
!= gate
) continue;
853 m4x3_mul( gate
->transport
, text
->transform
, transform
);
857 m4x3_decompose( transform
, co
, q
, s
);
863 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
864 v3_muls( text
->route
->colour
, brightness
, colour
);
865 colour
[3] = 1.0f
-text
->route
->factive
;
867 for( u32 j
=0;; j
++ ){
868 char c
= text
->text
[j
];
871 ent_glyph
*glyph
= font3d_glyph( &gui
.font
, 0, c
);
872 if( !glyph
) continue;
874 if( c
>= (u32
)'0' && c
<= (u32
)'9' && glyph
->indice_count
){
875 struct text_particle
*particle
=
876 &world_render
.text_particles
[world_render
.text_particle_count
++];
878 particle
->glyph
= glyph
;
879 v4_copy( colour
, particle
->colour
);
882 v2_muls( glyph
->size
, 0.5f
, origin
);
887 v3_add( offset
, origin
, world_co
);
888 m4x3_mulv( transform
, world_co
, world_co
);
891 m3x3_identity( particle
->mlocal
);
892 m3x3_scale( particle
->mlocal
, s
);
894 v3_muls( origin
, -1.0f
, particle
->mlocal
[3] );
896 v3_copy( world_co
, particle
->rb
.co
);
897 v3_muls( imp_v
, 1.0f
+vg_randf64(&vg
.rand
), particle
->rb
.v
);
898 particle
->rb
.v
[1] += 2.0f
;
900 v4_copy( q
, particle
->rb
.q
);
901 particle
->rb
.w
[0] = vg_randf64(&vg
.rand
)*2.0f
-1.0f
;
902 particle
->rb
.w
[1] = vg_randf64(&vg
.rand
)*2.0f
-1.0f
;
903 particle
->rb
.w
[2] = vg_randf64(&vg
.rand
)*2.0f
-1.0f
;
905 f32 r
= vg_maxf( s
[0]*glyph
->size
[0], s
[1]*glyph
->size
[1] )*0.5f
;
906 particle
->radius
= r
*0.6f
;
907 rb_setbody_sphere( &particle
->rb
, particle
->radius
, 1.0f
, 1.0f
);
909 offset
[0] += glyph
->size
[0];
914 static void render_gate_markers( m4x3f world_mmdl
, int run_id
, ent_gate
*gate
){
915 for( u32 j
=0; j
<4; j
++ ){
916 if( gate
->routes
[j
] == run_id
){
918 m4x3_copy( gate
->to_world
, mmdl
);
919 m3x3_scale( mmdl
, (v3f
){ gate
->dimensions
[0],
920 gate
->dimensions
[1], 1.0f
} );
922 m4x3_mul( world_mmdl
, mmdl
, mmdl
);
923 shader_model_gate_uMdl( mmdl
);
924 mdl_draw_submesh( &world_gates
.sm_marker
[j
] );
930 void render_world_routes( world_instance
*world
,
931 world_instance
*host_world
,
932 m4x3f mmdl
, vg_camera
*cam
,
933 int viewing_from_gate
, int viewing_from_hub
)
935 shader_scene_route_use();
936 shader_scene_route_uTexGarbage(0);
937 world_link_lighting_ub( host_world
, _shader_scene_route
.id
);
938 world_bind_position_texture( host_world
, _shader_scene_route
.id
,
939 _uniform_scene_route_g_world_depth
, 2 );
940 world_bind_light_array( host_world
, _shader_scene_route
.id
,
941 _uniform_scene_route_uLightsArray
, 3 );
942 world_bind_light_index( host_world
, _shader_scene_route
.id
,
943 _uniform_scene_route_uLightsIndex
, 4 );
944 bind_terrain_noise();
946 shader_scene_route_uPv( cam
->mtx
.pv
);
948 if( viewing_from_hub
){
950 m4x3_expand( mmdl
, m4mdl
);
951 m4x4_mul( cam
->mtx_prev
.pv
, m4mdl
, pvm
);
952 shader_scene_route_uMdl( mmdl
);
953 shader_scene_route_uPvmPrev( pvm
);
956 m3x3_inv( mmdl
, mnormal
);
957 m3x3_transpose( mnormal
, mnormal
);
958 v3_normalize( mnormal
[0] );
959 v3_normalize( mnormal
[1] );
960 v3_normalize( mnormal
[2] );
961 shader_scene_route_uNormalMtx( mnormal
);
964 shader_scene_route_uMdl( mmdl
);
965 shader_scene_route_uPvmPrev( cam
->mtx_prev
.pv
);
967 m3x3_identity( ident
);
968 shader_scene_route_uNormalMtx( ident
);
971 shader_scene_route_uCamera( cam
->transform
[3] );
973 mesh_bind( &world
->mesh_route_lines
);
975 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
976 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
978 f32 t
= viewing_from_hub
? 1.0f
: route
->factive
;
981 v3_lerp( (v3f
){0.7f
,0.7f
,0.7f
}, route
->colour
, t
, colour
);
984 shader_scene_route_uColour( colour
);
985 mdl_draw_submesh( &route
->sm
);
989 * ---------------------------------------------------- */
990 if( !viewing_from_gate
&& !viewing_from_hub
){
991 font3d_bind( &gui
.font
, k_font_shader_default
, 0, world
, cam
);
993 for( u32 i
=0; i
<world_render
.timer_text_count
; i
++ ){
994 struct timer_text
*text
= &world_render
.timer_texts
[i
];
997 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
998 v3_muls( text
->route
->colour
, brightness
, colour
);
999 colour
[3] = 1.0f
-text
->route
->factive
;
1001 shader_model_font_uColour( colour
);
1002 font3d_simple_draw( 0, text
->text
, cam
, text
->transform
);
1005 shader_model_font_uOffset( (v4f
){0.0f
,0.0f
,0.0f
,1.0f
} );
1007 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
1008 struct text_particle
*particle
= &world_render
.text_particles
[i
];
1012 m4x3_expand( particle
->mdl
, prev_mtx
);
1013 m4x4_mul( cam
->mtx_prev
.pv
, prev_mtx
, prev_mtx
);
1015 shader_model_font_uPvmPrev( prev_mtx
);
1019 rb_extrapolate( &particle
->rb
, model
[3], q
);
1022 m4x3_mul( model
, particle
->mlocal
, particle
->mdl
);
1023 shader_model_font_uMdl( particle
->mdl
);
1024 shader_model_font_uColour( particle
->colour
);
1026 mesh_drawn( particle
->glyph
->indice_start
,
1027 particle
->glyph
->indice_count
);
1032 * ---------------------------------------------------- */
1034 shader_model_gate_use();
1035 shader_model_gate_uPv( cam
->mtx
.pv
);
1036 shader_model_gate_uCam( cam
->pos
);
1037 shader_model_gate_uTime( vg
.time
*0.25f
);
1038 shader_model_gate_uInvRes( (v2f
){
1039 1.0f
/ (float)vg
.window_x
,
1040 1.0f
/ (float)vg
.window_y
});
1042 mesh_bind( &world_gates
.mesh
);
1044 /* skip writing into the motion vectors for this */
1045 glDrawBuffers( 1, (GLenum
[]){ GL_COLOR_ATTACHMENT0
} );
1046 glDisable( GL_CULL_FACE
);
1048 if( viewing_from_hub
){
1049 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
1050 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
1053 v3_muls( route
->colour
, 1.6666f
, colour
);
1056 shader_model_gate_uColour( colour
);
1058 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_gate
); j
++ ){
1059 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, j
);
1060 if( !(gate
->flags
& k_ent_gate_nonlocal
) )
1061 render_gate_markers( mmdl
, i
, gate
);
1066 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
1067 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
1069 if( route
->active_checkpoint
!= 0xffff ){
1071 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
1072 v3_muls( route
->colour
, brightness
, colour
);
1073 colour
[3] = 1.0f
-route
->factive
;
1075 shader_model_gate_uColour( colour
);
1077 u32 next
= route
->active_checkpoint
+1+viewing_from_gate
;
1078 next
= next
% route
->checkpoints_count
;
1079 next
+= route
->checkpoints_start
;
1081 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, next
);
1082 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
1083 render_gate_markers( mmdl
, i
, gate
);
1087 glEnable( GL_CULL_FACE
);
1088 glDrawBuffers( 2, (GLenum
[]){ GL_COLOR_ATTACHMENT0
, GL_COLOR_ATTACHMENT1
} );