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;
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_count
++;
71 last_version
= rg
->timing_version
;
72 vg_info( "%u %f\n", rg
->timing_version
, rg
->timing_time
);
75 if( world_static
.current_run_version
== last_version
+1 ){
78 if( route
->checkpoints_count
== 1 ){
79 route
->timing_base
= world_static
.time
;
84 vg_info( "%u %f\n", world_static
.current_run_version
, world_static
.time
);
86 if( valid_count
==route
->checkpoints_count
){
87 f64 lap_time
= world_static
.time
- start_time
;
88 //world_routes_local_set_record( world, route, lap_time );
90 if( route
->anon
.official_track_id
!= 0xffffffff ){
91 struct track_info
*ti
= &track_infos
[ route
->anon
.official_track_id
];
92 if( ti
->achievement_id
){
93 steam_set_achievement( ti
->achievement_id
);
94 steam_store_achievements();
99 &world_static
.instance_addons
[ world_static
.active_instance
]->alias
;
101 char mod_uid
[ ADDON_UID_MAX
];
102 addon_alias_uid( alias
, mod_uid
);
103 network_publish_laptime( mod_uid
,
104 mdl_pstr( &world
->meta
, route
->pstr_name
),
108 route
->valid_checkpoints
= valid_count
+1;
110 vg_info( "valid: %u\n", valid_count
);
111 vg_info( "----------------------------\n" );
115 * When going through a gate this is called for bookkeeping purposes
117 static void world_routes_activate_entry_gate( world_instance
*world
,
120 world_static
.last_use
= world_static
.time
;
121 ent_gate
*dest
= mdl_arritm( &world
->ent_gate
, rg
->target
);
123 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
124 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
126 u32 active_prev
= route
->active_checkpoint
;
127 route
->active_checkpoint
= 0xffff;
129 for( u32 j
=0; j
<4; j
++ ){
130 if( dest
->routes
[j
] == i
){
131 for( u32 k
=0; k
<route
->checkpoints_count
; k
++ ){
132 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
,
133 route
->checkpoints_start
+k
);
135 ent_gate
*gk
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
136 gk
= mdl_arritm( &world
->ent_gate
, gk
->target
);
138 route
->active_checkpoint
= k
;
139 world_routes_time_lap( world
, route
);
148 dest
->timing_version
= world_static
.current_run_version
;
149 dest
->timing_time
= world_static
.time
;
151 world_static
.current_run_version
++;
154 /* draw lines along the paths */
155 static void world_routes_debug( world_instance
*world
)
157 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route_node
); i
++ ){
158 ent_route_node
*rn
= mdl_arritm(&world
->ent_route_node
,i
);
159 vg_line_point( rn
->co
, 0.25f
, VG__WHITE
);
162 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
163 ent_route
*route
= mdl_arritm(&world
->ent_route
, i
);
165 u32 colours
[] = { 0xfff58142, 0xff42cbf5, 0xff42f56c, 0xfff542b3,
169 if( route
->active_checkpoint
!= 0xffff ){
170 cc
= colours
[i
%vg_list_size(colours
)];
173 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
174 int i0
= route
->checkpoints_start
+i
,
175 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
177 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
178 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
180 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
181 ent_gate
*end_gate
= mdl_arritm( &world
->ent_gate
, c1
->gate_index
);
184 v3_copy( start_gate
->co
[1], p0
);
186 for( int j
=0; j
<c0
->path_count
; j
++ ){
187 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
190 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
193 v3_copy( rn
->co
, p1
);
194 vg_line( p0
, p1
, cc
);
198 v3_copy( end_gate
->co
[0], p1
);
199 vg_line( p0
, p1
, cc
);
206 void world_routes_place_curve( world_instance
*world
, ent_route
*route
,
207 v4f h
[3], v3f n0
, v3f n2
, scene_context
*scene
)
213 float total_length
= 0.0f
,
217 v3_copy( h
[0], last
);
218 for( int it
=0; it
<128; it
++ ){
219 t
= (float)(it
+1) * (1.0f
/128.0f
);
220 eval_bezier3( h
[0], h
[1], h
[2], t
, p
);
221 total_length
+= v3_dist( p
, last
);
225 float patch_size
= 4.0f
,
226 patch_count
= ceilf( total_length
/ patch_size
);
229 v3_copy( h
[0], last
);
231 for( int it
=0; it
<128; it
++ ){
232 float const k_sample_dist
= 0.0025f
,
235 eval_bezier3( h
[0], h
[1], h
[2], t
, p
);
236 eval_bezier3( h
[0], h
[1], h
[2], t
+k_sample_dist
, pd
);
238 travel_length
+= v3_dist( p
, last
);
240 float mod
= k_sample_dist
/ v3_dist( p
, pd
);
244 v3_muls( n0
, -(1.0f
-t
), up
);
245 v3_muladds( up
, n2
, -t
, up
);
249 v3_cross( up
, v0
, right
);
250 v3_normalize( right
);
252 float cur_x
= (1.0f
-t
)*h
[0][3] + t
*h
[2][3];
254 v3f sc
, sa
, sb
, down
;
255 v3_muladds( p
, right
, cur_x
* k_line_width
, sc
);
256 v3_muladds( sc
, up
, 1.5f
, sc
);
257 v3_muladds( sc
, right
, k_line_width
*0.95f
, sa
);
258 v3_muladds( sc
, right
, 0.0f
, sb
);
259 v3_muls( up
, -1.0f
, down
);
265 int resa
= ray_world( world
, sa
, down
, &ha
, k_material_flag_ghosts
),
266 resb
= ray_world( world
, sb
, down
, &hb
, k_material_flag_ghosts
);
269 struct world_surface
*surfa
= ray_hit_surface( world
, &ha
),
270 *surfb
= ray_hit_surface( world
, &hb
);
272 if( (surfa
->info
.flags
& k_material_flag_skate_target
) &&
273 (surfb
->info
.flags
& k_material_flag_skate_target
) )
277 float gap
= vg_fractf(cur_x
*0.5f
)*0.02f
;
279 v3_muladds( ha
.pos
, up
, 0.06f
+gap
, va
.co
);
280 v3_muladds( hb
.pos
, up
, 0.06f
+gap
, vb
.co
);
282 scene_vert_pack_norm( &va
, up
);
283 scene_vert_pack_norm( &vb
, up
);
285 float t1
= (travel_length
/ total_length
) * patch_count
;
291 scene_push_vert( scene
, &va
);
292 scene_push_vert( scene
, &vb
);
295 /* Connect them with triangles */
296 scene_push_tri( scene
, (u32
[3]){
297 last_valid
+0-2, last_valid
+1-2, last_valid
+2-2} );
298 scene_push_tri( scene
, (u32
[3]){
299 last_valid
+1-2, last_valid
+3-2, last_valid
+2-2} );
302 last_valid
= scene
->vertex_count
;
321 static void world_routes_gen_meshes( world_instance
*world
, u32 route_id
,
324 ent_route
*route
= mdl_arritm( &world
->ent_route
, route_id
);
326 colour
[0] = route
->colour
[0] * 255.0f
;
327 colour
[1] = route
->colour
[1] * 255.0f
;
328 colour
[2] = route
->colour
[2] * 255.0f
;
329 colour
[3] = route
->colour
[3] * 255.0f
;
333 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
334 int i0
= route
->checkpoints_start
+i
,
335 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
337 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
338 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
340 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
341 start_gate
= mdl_arritm( &world
->ent_gate
, start_gate
->target
);
343 ent_gate
*end_gate
= mdl_arritm( &world
->ent_gate
, c1
->gate_index
),
344 *collector
= mdl_arritm( &world
->ent_gate
, end_gate
->target
);
348 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, start_gate
->co
[0], p
[0] );
349 p
[0][3] = start_gate
->ref_count
;
350 p
[0][3] -= (float)start_gate
->route_count
* 0.5f
;
351 start_gate
->ref_count
++;
353 if( !c0
->path_count
)
356 /* this is so that we get nice flow through the gates */
357 v3f temp_alignments
[2];
358 ent_gate
*both
[] = { start_gate
, end_gate
};
360 for( int j
=0; j
<2; j
++ ){
361 int pi
= c0
->path_start
+ ((j
==1)? c0
->path_count
-1: 0);
363 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
, pi
);
364 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
367 v3_sub( rn
->co
, both
[j
]->co
[0], v0
);
368 float d
= v3_dot( v0
, both
[j
]->to_world
[2] );
370 v3_muladds( both
[j
]->co
[0], both
[j
]->to_world
[2], d
,
371 temp_alignments
[j
] );
372 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, temp_alignments
[j
], temp_alignments
[j
]);
376 for( int j
=0; j
<c0
->path_count
; j
++ ){
377 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
379 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
381 if( j
==0 || j
==c0
->path_count
-1 )
383 v3_copy( temp_alignments
[0], p
[1] );
385 v3_copy( temp_alignments
[1], p
[1] );
387 v3_copy( rn
->co
, p
[1] );
389 p
[1][3] = rn
->ref_count
;
390 p
[1][3] -= (float)rn
->ref_total
* 0.5f
;
393 if( j
+1 < c0
->path_count
){
394 index
= mdl_arritm( &world
->ent_path_index
,
395 c0
->path_start
+j
+1 );
396 rn
= mdl_arritm( &world
->ent_route_node
, index
->index
);
398 if( j
+1 == c0
->path_count
-1 )
399 v3_lerp( p
[1], temp_alignments
[1], 0.5f
, p
[2] );
401 v3_lerp( p
[1], rn
->co
, 0.5f
, p
[2] );
403 p
[2][3] = rn
->ref_count
;
404 p
[2][3] -= (float)rn
->ref_total
* 0.5f
;
407 v3_copy( end_gate
->co
[0], p
[2] );
408 v3_add( (v3f
){0.0f
,0.1f
,0.0f
}, p
[2], p
[2] );
409 p
[2][3] = collector
->ref_count
;
411 if( i
== route
->checkpoints_count
-1)
414 p
[2][3] -= (float)collector
->route_count
* 0.5f
;
415 //collector->ref_count ++;
418 /* p0,p1,p2 bezier patch is complete
419 * --------------------------------------*/
420 v3f surf0
, surf2
, n0
, n2
;
422 if( bh_closest_point( world
->geo_bh
, p
[0], surf0
, 5.0f
) == -1 )
423 v3_add( (v3f
){0.0f
,-0.1f
,0.0f
}, p
[0], surf0
);
425 if( bh_closest_point( world
->geo_bh
, p
[2], surf2
, 5.0f
) == -1 )
426 v3_add( (v3f
){0.0f
,-0.1f
,0.0f
}, p
[2], surf2
);
428 v3_sub( surf0
, p
[0], n0
);
429 v3_sub( surf2
, p
[2], n2
);
433 world_routes_place_curve( world
, route
, p
, n0
, n2
, sc
);
436 v4_copy( p
[2], p
[0] );
440 scene_copy_slice( sc
, &route
->sm
);
444 struct world_surface
*world_tri_index_surface( world_instance
*world
,
448 * Create the strips of colour that run through the world along course paths
450 static void world_gen_routes_generate( u32 instance_id
){
451 world_instance
*world
= &world_static
.instances
[ instance_id
];
452 vg_info( "Generating route meshes\n" );
455 vg_rand_seed( 2000 );
456 vg_async_item
*call_scene
= scene_alloc_async( &world
->scene_lines
,
457 &world
->mesh_route_lines
,
460 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
461 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
463 gate
->route_count
= 0;
466 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route_node
); i
++ ){
467 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
, i
);
472 for( u32 k
=0; k
<mdl_arrcount(&world
->ent_route
); k
++ ){
473 ent_route
*route
= mdl_arritm( &world
->ent_route
, k
);
475 for( int i
=0; i
<route
->checkpoints_count
; i
++ ){
476 int i0
= route
->checkpoints_start
+i
,
477 i1
= route
->checkpoints_start
+((i
+1)%route
->checkpoints_count
);
479 ent_checkpoint
*c0
= mdl_arritm(&world
->ent_checkpoint
, i0
),
480 *c1
= mdl_arritm(&world
->ent_checkpoint
, i1
);
482 ent_gate
*start_gate
= mdl_arritm( &world
->ent_gate
, c0
->gate_index
);
483 start_gate
= mdl_arritm( &world
->ent_gate
, start_gate
->target
);
484 start_gate
->route_count
++;
486 if( !c0
->path_count
)
489 for( int j
=0; j
<c0
->path_count
; j
++ ){
490 ent_path_index
*index
= mdl_arritm( &world
->ent_path_index
,
492 ent_route_node
*rn
= mdl_arritm( &world
->ent_route_node
,
499 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
500 world_routes_gen_meshes( world
, i
, &world
->scene_lines
);
503 vg_async_dispatch( call_scene
, async_scene_upload
);
504 world_routes_clear( world
);
507 /* load all routes from model header */
508 static void world_gen_routes_ent_init( world_instance
*world
){
509 vg_info( "Initializing routes\n" );
511 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
512 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
513 for( u32 j
=0; j
<4; j
++ ){
514 gate
->routes
[j
] = 0xffff;
518 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
519 ent_route
*route
= mdl_arritm(&world
->ent_route
,i
);
520 mdl_transform_m4x3( &route
->anon
.transform
, route
->board_transform
);
522 route
->anon
.official_track_id
= 0xffffffff;
523 for( u32 j
=0; j
<vg_list_size(track_infos
); j
++ ){
524 if( !strcmp(track_infos
[j
].name
,
525 mdl_pstr(&world
->meta
,route
->pstr_name
))){
526 route
->anon
.official_track_id
= j
;
530 for( u32 j
=0; j
<route
->checkpoints_count
; j
++ ){
531 u32 id
= route
->checkpoints_start
+ j
;
532 ent_checkpoint
*cp
= mdl_arritm(&world
->ent_checkpoint
,id
);
534 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
536 for( u32 k
=0; k
<4; k
++ ){
537 if( gate
->routes
[k
] == 0xffff ){
543 if( (gate
->flags
& k_ent_gate_linked
) &
544 !(gate
->flags
& k_ent_gate_nonlocal_DELETED
) ){
545 gate
= mdl_arritm(&world
->ent_gate
, gate
->target
);
547 for( u32 k
=0; k
<4; k
++ ){
548 if( gate
->routes
[k
] == i
){
549 vg_error( "already assigned route to gate\n" );
552 if( gate
->routes
[k
] == 0xffff ){
561 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_gate
); i
++ ){
562 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, i
);
565 world_routes_clear( world
);
568 static void world_routes_recv_scoreboard( world_instance
*world
,
569 vg_msg
*body
, u32 route_id
,
570 enum request_status status
){
571 if( route_id
>= mdl_arrcount( &world
->ent_route
) ){
572 vg_error( "Scoreboard route_id out of range (%u)\n", route_id
);
576 struct leaderboard_cache
*board
= &world
->leaderboard_cache
[ route_id
];
577 board
->status
= status
;
584 if( body
->max
> NETWORK_REQUEST_MAX
){
585 vg_error( "Scoreboard leaderboard too big (%u>%u)\n", body
->max
,
586 NETWORK_REQUEST_MAX
);
590 memcpy( board
->data
, body
->buf
, body
->max
);
591 board
->data_len
= body
->max
;
595 * -----------------------------------------------------------------------------
597 * -----------------------------------------------------------------------------
600 static void world_routes_init(void){
601 world_static
.current_run_version
= 200;
602 world_static
.time
= 300.0;
603 world_static
.last_use
= 0.0;
605 shader_scene_route_register();
606 shader_routeui_register();
609 static void world_routes_update( world_instance
*world
){
610 world_static
.time
+= vg
.time_delta
;
612 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
613 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
615 int target
= (route
->active_checkpoint
== 0xffff? 0: 1) ||
616 skaterift
.activity
== k_skaterift_respawning
;
617 route
->factive
= vg_lerpf( route
->factive
, target
,
618 0.6f
*vg
.time_frame_delta
);
621 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
622 struct text_particle
*particle
= &world_render
.text_particles
[i
];
623 rb_object_debug( &particle
->obj
, VG__RED
);
627 static void world_routes_fixedupdate( world_instance
*world
){
630 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
631 struct text_particle
*particle
= &world_render
.text_particles
[i
];
633 if( rb_global_has_space() ){
634 rb_ct
*buf
= rb_global_buffer();
636 int l
= rb_sphere__scene( particle
->obj
.rb
.to_world
,
637 &particle
->obj
.inf
.sphere
,
638 NULL
, &world
->rb_geo
.inf
.scene
, buf
,
639 k_material_flag_ghosts
);
641 for( int j
=0; j
<l
; j
++ ){
642 buf
[j
].rba
= &particle
->obj
.rb
;
643 buf
[j
].rbb
= &world
->rb_geo
.rb
;
646 rb_contact_count
+= l
;
650 rb_presolve_contacts( rb_contact_buffer
, rb_contact_count
);
652 for( int i
=0; i
<rb_contact_count
; i
++ ){
653 rb_contact_restitution( rb_contact_buffer
+i
, vg_randf64() );
656 for( int i
=0; i
<6; i
++ ){
657 rb_solve_contacts( rb_contact_buffer
, rb_contact_count
);
660 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
661 struct text_particle
*particle
= &world_render
.text_particles
[i
];
662 rb_iter( &particle
->obj
.rb
);
665 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
666 struct text_particle
*particle
= &world_render
.text_particles
[i
];
667 rb_update_transform( &particle
->obj
.rb
);
671 static void bind_terrain_noise(void);
672 static void world_bind_light_array( world_instance
*world
,
673 GLuint shader
, GLuint location
,
675 static void world_bind_light_index( world_instance
*world
,
676 GLuint shader
, GLuint location
,
679 static void world_routes_update_timer_texts( world_instance
*world
){
680 world_render
.timer_text_count
= 0;
682 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
683 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
685 if( route
->active_checkpoint
!= 0xffff ){
686 u32 next
= route
->active_checkpoint
+1;
687 next
= next
% route
->checkpoints_count
;
688 next
+= route
->checkpoints_start
;
690 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, next
);
691 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
692 ent_gate
*dest
= mdl_arritm( &world
->ent_gate
, gate
->target
);
696 if( dest
->routes
[j
] == i
){
706 struct timer_text
*text
=
707 &world_render
.timer_texts
[ world_render
.timer_text_count
++ ];
712 if( route
->valid_checkpoints
>= route
->checkpoints_count
){
713 double lap_time
= world_static
.time
- route
->timing_base
,
714 time_centiseconds
= lap_time
* 100.0;
716 if( time_centiseconds
> (float)0xfffe ) time_centiseconds
= 0.0;
718 u16 centiseconds
= time_centiseconds
,
719 seconds
= centiseconds
/ 100,
720 minutes
= seconds
/ 60;
726 if( minutes
> 9 ) minutes
= 9;
730 highscore_intr( text
->text
, minutes
, 1, ' ' ); j
++;
731 text
->text
[j
++] = ':';
734 if( seconds
>= 10 || minutes
){
735 highscore_intr( text
->text
+j
, seconds
, 2, '0' ); j
+=2;
738 highscore_intr( text
->text
+j
, seconds
, 1, '0' ); j
++;
741 text
->text
[j
++] = '.';
742 highscore_intr( text
->text
+j
, centiseconds
, 1, '0' ); j
++;
743 text
->text
[j
] = '\0';
746 highscore_intr( text
->text
, route
->valid_checkpoints
, 1, ' ' );
748 highscore_intr( text
->text
+2, route
->checkpoints_count
+1, 1, ' ' );
749 text
->text
[3] = '\0';
752 gui_font3d
.font
= &gui
.font
;
753 float align_r
= font3d_string_width( 0, text
->text
);
757 { -0.92f
, h0
, depth
},
758 { 0.92f
- align_r
, h0
, depth
},
759 { -0.92f
, h1
, depth
},
760 { 0.92f
- align_r
, h1
, depth
},
763 if( dest
->route_count
== 1 ){
764 positions
[0][0] = -align_r
*0.5f
;
765 positions
[0][1] = h1
;
769 ent_gate_get_mdl_mtx( gate
, mmdl
);
771 m3x3_copy( mmdl
, text
->transform
);
772 float ratio
= v3_length(text
->transform
[0]) /
773 v3_length(text
->transform
[1]);
775 m3x3_scale( text
->transform
, (v3f
){ size
, size
*ratio
, 0.1f
} );
776 m4x3_mulv( mmdl
, positions
[j
], text
->transform
[3] );
781 static void world_routes_fracture( world_instance
*world
, ent_gate
*gate
,
782 v3f imp_co
, v3f imp_v
)
784 world_render
.text_particle_count
= 0;
786 for( u32 i
=0; i
<world_render
.timer_text_count
; i
++ ){
787 struct timer_text
*text
= &world_render
.timer_texts
[i
];
789 if( text
->gate
!= gate
) continue;
792 m4x3_mul( gate
->transport
, text
->transform
, transform
);
796 m4x3_decompose( transform
, co
, q
, s
);
802 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
803 v3_muls( text
->route
->colour
, brightness
, colour
);
804 colour
[3] = 1.0f
-text
->route
->factive
;
806 for( u32 j
=0;; j
++ ){
807 char c
= text
->text
[j
];
810 ent_glyph
*glyph
= font3d_glyph( &gui
.font
, 0, c
);
811 if( !glyph
) continue;
813 if( c
>= (u32
)'0' && c
<= (u32
)'9' && glyph
->indice_count
){
814 struct text_particle
*particle
=
815 &world_render
.text_particles
[world_render
.text_particle_count
++];
817 particle
->glyph
= glyph
;
818 v4_copy( colour
, particle
->colour
);
821 v2_muls( glyph
->size
, 0.5f
, origin
);
826 v3_add( offset
, origin
, world_co
);
827 m4x3_mulv( transform
, world_co
, world_co
);
829 float r
= vg_maxf( s
[0]*glyph
->size
[0], s
[1]*glyph
->size
[1] )*0.5f
;
831 m3x3_identity( particle
->mlocal
);
832 m3x3_scale( particle
->mlocal
, s
);
834 v3_muls( origin
, -1.0f
, particle
->mlocal
[3] );
836 v3_copy( world_co
, particle
->obj
.rb
.co
);
837 v3_muls( imp_v
, 1.0f
+vg_randf64(), particle
->obj
.rb
.v
);
838 particle
->obj
.rb
.v
[1] += 2.0f
;
840 v4_copy( q
, particle
->obj
.rb
.q
);
841 particle
->obj
.rb
.w
[0] = vg_randf64()*2.0f
-1.0f
;
842 particle
->obj
.rb
.w
[1] = vg_randf64()*2.0f
-1.0f
;
843 particle
->obj
.rb
.w
[2] = vg_randf64()*2.0f
-1.0f
;
845 particle
->obj
.type
= k_rb_shape_sphere
;
846 particle
->obj
.inf
.sphere
.radius
= r
*0.6f
;
848 rb_init_object( &particle
->obj
);
850 offset
[0] += glyph
->size
[0];
855 static void render_gate_markers( int run_id
, ent_gate
*gate
){
856 for( u32 j
=0; j
<4; j
++ ){
857 if( gate
->routes
[j
] == run_id
){
859 ent_gate_get_mdl_mtx( gate
, mmdl
);
860 shader_model_gate_uMdl( mmdl
);
861 mdl_draw_submesh( &world_gates
.sm_marker
[j
] );
867 static void render_world_routes( world_instance
*world
, camera
*cam
,
868 int viewing_from_gate
){
869 m4x3f identity_matrix
;
870 m4x3_identity( identity_matrix
);
872 shader_scene_route_use();
873 shader_scene_route_uTexGarbage(0);
874 world_link_lighting_ub( world
, _shader_scene_route
.id
);
875 world_bind_position_texture( world
, _shader_scene_route
.id
,
876 _uniform_scene_route_g_world_depth
, 2 );
877 world_bind_light_array( world
, _shader_scene_route
.id
,
878 _uniform_scene_route_uLightsArray
, 3 );
879 world_bind_light_index( world
, _shader_scene_route
.id
,
880 _uniform_scene_route_uLightsIndex
, 4 );
881 bind_terrain_noise();
883 shader_scene_route_uPv( cam
->mtx
.pv
);
884 shader_scene_route_uPvmPrev( cam
->mtx_prev
.pv
);
885 shader_scene_route_uMdl( identity_matrix
);
886 shader_scene_route_uCamera( cam
->transform
[3] );
888 mesh_bind( &world
->mesh_route_lines
);
890 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
891 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
894 v3_lerp( (v3f
){0.7f
,0.7f
,0.7f
}, route
->colour
, route
->factive
, colour
);
895 colour
[3] = route
->factive
*0.2f
;
897 shader_scene_route_uColour( colour
);
898 mdl_draw_submesh( &route
->sm
);
902 * ---------------------------------------------------- */
903 if( !viewing_from_gate
){
904 font3d_bind( &gui
.font
, k_font_shader_default
, 0, world
, cam
);
906 for( u32 i
=0; i
<world_render
.timer_text_count
; i
++ ){
907 struct timer_text
*text
= &world_render
.timer_texts
[i
];
910 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
911 v3_muls( text
->route
->colour
, brightness
, colour
);
912 colour
[3] = 1.0f
-text
->route
->factive
;
914 shader_model_font_uColour( colour
);
915 font3d_simple_draw( 0, text
->text
, cam
, text
->transform
);
918 shader_model_font_uOffset( (v4f
){0.0f
,0.0f
,0.0f
,1.0f
} );
920 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
921 struct text_particle
*particle
= &world_render
.text_particles
[i
];
925 m4x3_expand( particle
->mdl
, prev_mtx
);
926 m4x4_mul( cam
->mtx_prev
.pv
, prev_mtx
, prev_mtx
);
928 shader_model_font_uPvmPrev( prev_mtx
);
932 rb_extrapolate( &particle
->obj
.rb
, model
[3], q
);
935 m4x3_mul( model
, particle
->mlocal
, particle
->mdl
);
936 shader_model_font_uMdl( particle
->mdl
);
937 shader_model_font_uColour( particle
->colour
);
939 mesh_drawn( particle
->glyph
->indice_start
,
940 particle
->glyph
->indice_count
);
945 * ---------------------------------------------------- */
947 shader_model_gate_use();
948 shader_model_gate_uPv( cam
->mtx
.pv
);
949 shader_model_gate_uCam( cam
->pos
);
950 shader_model_gate_uTime( vg
.time
*0.25f
);
951 shader_model_gate_uInvRes( (v2f
){
952 1.0f
/ (float)vg
.window_x
,
953 1.0f
/ (float)vg
.window_y
});
955 mesh_bind( &world_gates
.mesh
);
957 /* skip writing into the motion vectors for this */
958 glDrawBuffers( 1, (GLenum
[]){ GL_COLOR_ATTACHMENT0
} );
959 glDisable( GL_CULL_FACE
);
961 if( skaterift
.activity
== k_skaterift_respawning
){
962 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
963 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
966 v3_muls( route
->colour
, 1.6666f
, colour
);
969 shader_model_gate_uColour( colour
);
971 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_gate
); j
++ ){
972 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, j
);
973 if( !(gate
->flags
& k_ent_gate_nonlocal_DELETED
) )
974 render_gate_markers( i
, gate
);
979 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
980 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
982 if( route
->active_checkpoint
!= 0xffff ){
984 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
985 v3_muls( route
->colour
, brightness
, colour
);
986 colour
[3] = 1.0f
-route
->factive
;
988 shader_model_gate_uColour( colour
);
990 u32 next
= route
->active_checkpoint
+1+viewing_from_gate
;
991 next
= next
% route
->checkpoints_count
;
992 next
+= route
->checkpoints_start
;
994 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, next
);
995 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
996 render_gate_markers( i
, gate
);
1000 glEnable( GL_CULL_FACE
);
1001 glDrawBuffers( 2, (GLenum
[]){ GL_COLOR_ATTACHMENT0
, GL_COLOR_ATTACHMENT1
} );
1004 #endif /* ROUTES_C */