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 route
->factive
= vg_lerpf( route
->factive
, target
,
617 0.6f
*vg
.time_frame_delta
);
620 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
621 struct text_particle
*particle
= &world_render
.text_particles
[i
];
622 rb_object_debug( &particle
->obj
, VG__RED
);
626 static void world_routes_fixedupdate( world_instance
*world
){
629 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
630 struct text_particle
*particle
= &world_render
.text_particles
[i
];
632 if( rb_global_has_space() ){
633 rb_ct
*buf
= rb_global_buffer();
635 int l
= rb_sphere__scene( particle
->obj
.rb
.to_world
,
636 &particle
->obj
.inf
.sphere
,
637 NULL
, &world
->rb_geo
.inf
.scene
, buf
,
638 k_material_flag_ghosts
);
640 for( int j
=0; j
<l
; j
++ ){
641 buf
[j
].rba
= &particle
->obj
.rb
;
642 buf
[j
].rbb
= &world
->rb_geo
.rb
;
645 rb_contact_count
+= l
;
649 rb_presolve_contacts( rb_contact_buffer
, rb_contact_count
);
651 for( int i
=0; i
<rb_contact_count
; i
++ ){
652 rb_contact_restitution( rb_contact_buffer
+i
, vg_randf64() );
655 for( int i
=0; i
<6; i
++ ){
656 rb_solve_contacts( rb_contact_buffer
, rb_contact_count
);
659 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
660 struct text_particle
*particle
= &world_render
.text_particles
[i
];
661 rb_iter( &particle
->obj
.rb
);
664 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
665 struct text_particle
*particle
= &world_render
.text_particles
[i
];
666 rb_update_transform( &particle
->obj
.rb
);
670 static void bind_terrain_noise(void);
671 static void world_bind_light_array( world_instance
*world
,
672 GLuint shader
, GLuint location
,
674 static void world_bind_light_index( world_instance
*world
,
675 GLuint shader
, GLuint location
,
678 static void world_routes_update_timer_texts( world_instance
*world
){
679 world_render
.timer_text_count
= 0;
681 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
682 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
684 if( route
->active_checkpoint
!= 0xffff ){
685 u32 next
= route
->active_checkpoint
+1;
686 next
= next
% route
->checkpoints_count
;
687 next
+= route
->checkpoints_start
;
689 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, next
);
690 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
691 ent_gate
*dest
= mdl_arritm( &world
->ent_gate
, gate
->target
);
695 if( dest
->routes
[j
] == i
){
705 struct timer_text
*text
=
706 &world_render
.timer_texts
[ world_render
.timer_text_count
++ ];
711 if( route
->valid_checkpoints
>= route
->checkpoints_count
){
712 double lap_time
= world_static
.time
- route
->timing_base
,
713 time_centiseconds
= lap_time
* 100.0;
715 if( time_centiseconds
> (float)0xfffe ) time_centiseconds
= 0.0;
717 u16 centiseconds
= time_centiseconds
,
718 seconds
= centiseconds
/ 100,
719 minutes
= seconds
/ 60;
725 if( minutes
> 9 ) minutes
= 9;
729 highscore_intr( text
->text
, minutes
, 1, ' ' ); j
++;
730 text
->text
[j
++] = ':';
733 if( seconds
>= 10 || minutes
){
734 highscore_intr( text
->text
+j
, seconds
, 2, '0' ); j
+=2;
737 highscore_intr( text
->text
+j
, seconds
, 1, '0' ); j
++;
740 text
->text
[j
++] = '.';
741 highscore_intr( text
->text
+j
, centiseconds
, 1, '0' ); j
++;
742 text
->text
[j
] = '\0';
745 highscore_intr( text
->text
, route
->valid_checkpoints
, 1, ' ' );
747 highscore_intr( text
->text
+2, route
->checkpoints_count
+1, 1, ' ' );
748 text
->text
[3] = '\0';
751 gui_font3d
.font
= &gui
.font
;
752 float align_r
= font3d_string_width( 0, text
->text
);
756 { -0.92f
, h0
, depth
},
757 { 0.92f
- align_r
, h0
, depth
},
758 { -0.92f
, h1
, depth
},
759 { 0.92f
- align_r
, h1
, depth
},
762 if( dest
->route_count
== 1 ){
763 positions
[0][0] = -align_r
*0.5f
;
764 positions
[0][1] = h1
;
768 ent_gate_get_mdl_mtx( gate
, mmdl
);
770 m3x3_copy( mmdl
, text
->transform
);
771 float ratio
= v3_length(text
->transform
[0]) /
772 v3_length(text
->transform
[1]);
774 m3x3_scale( text
->transform
, (v3f
){ size
, size
*ratio
, 0.1f
} );
775 m4x3_mulv( mmdl
, positions
[j
], text
->transform
[3] );
780 static void world_routes_fracture( world_instance
*world
, ent_gate
*gate
,
781 v3f imp_co
, v3f imp_v
)
783 world_render
.text_particle_count
= 0;
785 for( u32 i
=0; i
<world_render
.timer_text_count
; i
++ ){
786 struct timer_text
*text
= &world_render
.timer_texts
[i
];
788 if( text
->gate
!= gate
) continue;
791 m4x3_mul( gate
->transport
, text
->transform
, transform
);
795 m4x3_decompose( transform
, co
, q
, s
);
801 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
802 v3_muls( text
->route
->colour
, brightness
, colour
);
803 colour
[3] = 1.0f
-text
->route
->factive
;
805 for( u32 j
=0;; j
++ ){
806 char c
= text
->text
[j
];
809 ent_glyph
*glyph
= font3d_glyph( &gui
.font
, 0, c
);
810 if( !glyph
) continue;
812 if( c
>= (u32
)'0' && c
<= (u32
)'9' && glyph
->indice_count
){
813 struct text_particle
*particle
=
814 &world_render
.text_particles
[world_render
.text_particle_count
++];
816 particle
->glyph
= glyph
;
817 v4_copy( colour
, particle
->colour
);
820 v2_muls( glyph
->size
, 0.5f
, origin
);
825 v3_add( offset
, origin
, world_co
);
826 m4x3_mulv( transform
, world_co
, world_co
);
828 float r
= vg_maxf( s
[0]*glyph
->size
[0], s
[1]*glyph
->size
[1] )*0.5f
;
830 m3x3_identity( particle
->mlocal
);
831 m3x3_scale( particle
->mlocal
, s
);
833 v3_muls( origin
, -1.0f
, particle
->mlocal
[3] );
835 v3_copy( world_co
, particle
->obj
.rb
.co
);
836 v3_muls( imp_v
, 1.0f
+vg_randf64(), particle
->obj
.rb
.v
);
837 particle
->obj
.rb
.v
[1] += 2.0f
;
839 v4_copy( q
, particle
->obj
.rb
.q
);
840 particle
->obj
.rb
.w
[0] = vg_randf64()*2.0f
-1.0f
;
841 particle
->obj
.rb
.w
[1] = vg_randf64()*2.0f
-1.0f
;
842 particle
->obj
.rb
.w
[2] = vg_randf64()*2.0f
-1.0f
;
844 particle
->obj
.type
= k_rb_shape_sphere
;
845 particle
->obj
.inf
.sphere
.radius
= r
*0.6f
;
847 rb_init_object( &particle
->obj
);
849 offset
[0] += glyph
->size
[0];
854 static void render_gate_markers( m4x3f world_mmdl
, int run_id
, ent_gate
*gate
){
855 for( u32 j
=0; j
<4; j
++ ){
856 if( gate
->routes
[j
] == run_id
){
858 ent_gate_get_mdl_mtx( gate
, mmdl
);
859 m4x3_mul( world_mmdl
, mmdl
, 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
,
868 world_instance
*host_world
,
869 m4x3f mmdl
, camera
*cam
,
870 int viewing_from_gate
, int viewing_from_hub
){
872 shader_scene_route_use();
873 shader_scene_route_uTexGarbage(0);
874 world_link_lighting_ub( host_world
, _shader_scene_route
.id
);
875 world_bind_position_texture( host_world
, _shader_scene_route
.id
,
876 _uniform_scene_route_g_world_depth
, 2 );
877 world_bind_light_array( host_world
, _shader_scene_route
.id
,
878 _uniform_scene_route_uLightsArray
, 3 );
879 world_bind_light_index( host_world
, _shader_scene_route
.id
,
880 _uniform_scene_route_uLightsIndex
, 4 );
881 bind_terrain_noise();
883 shader_scene_route_uPv( cam
->mtx
.pv
);
885 if( viewing_from_hub
){
887 m4x3_expand( mmdl
, m4mdl
);
888 m4x4_mul( cam
->mtx_prev
.pv
, m4mdl
, pvm
);
889 shader_scene_route_uMdl( mmdl
);
890 shader_scene_route_uPvmPrev( pvm
);
893 m3x3_inv( mmdl
, mnormal
);
894 m3x3_transpose( mnormal
, mnormal
);
895 v3_normalize( mnormal
[0] );
896 v3_normalize( mnormal
[1] );
897 v3_normalize( mnormal
[2] );
898 shader_scene_route_uNormalMtx( mnormal
);
901 shader_scene_route_uMdl( mmdl
);
902 shader_scene_route_uPvmPrev( cam
->mtx_prev
.pv
);
904 m3x3_identity( ident
);
905 shader_scene_route_uNormalMtx( ident
);
908 shader_scene_route_uCamera( cam
->transform
[3] );
910 mesh_bind( &world
->mesh_route_lines
);
912 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
913 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
915 f32 t
= viewing_from_hub
? 1.0f
: route
->factive
;
918 v3_lerp( (v3f
){0.7f
,0.7f
,0.7f
}, route
->colour
, t
, colour
);
921 shader_scene_route_uColour( colour
);
922 mdl_draw_submesh( &route
->sm
);
926 * ---------------------------------------------------- */
927 if( !viewing_from_gate
&& !viewing_from_hub
){
928 font3d_bind( &gui
.font
, k_font_shader_default
, 0, world
, cam
);
930 for( u32 i
=0; i
<world_render
.timer_text_count
; i
++ ){
931 struct timer_text
*text
= &world_render
.timer_texts
[i
];
934 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
935 v3_muls( text
->route
->colour
, brightness
, colour
);
936 colour
[3] = 1.0f
-text
->route
->factive
;
938 shader_model_font_uColour( colour
);
939 font3d_simple_draw( 0, text
->text
, cam
, text
->transform
);
942 shader_model_font_uOffset( (v4f
){0.0f
,0.0f
,0.0f
,1.0f
} );
944 for( u32 i
=0; i
<world_render
.text_particle_count
; i
++ ){
945 struct text_particle
*particle
= &world_render
.text_particles
[i
];
949 m4x3_expand( particle
->mdl
, prev_mtx
);
950 m4x4_mul( cam
->mtx_prev
.pv
, prev_mtx
, prev_mtx
);
952 shader_model_font_uPvmPrev( prev_mtx
);
956 rb_extrapolate( &particle
->obj
.rb
, model
[3], q
);
959 m4x3_mul( model
, particle
->mlocal
, particle
->mdl
);
960 shader_model_font_uMdl( particle
->mdl
);
961 shader_model_font_uColour( particle
->colour
);
963 mesh_drawn( particle
->glyph
->indice_start
,
964 particle
->glyph
->indice_count
);
969 * ---------------------------------------------------- */
971 shader_model_gate_use();
972 shader_model_gate_uPv( cam
->mtx
.pv
);
973 shader_model_gate_uCam( cam
->pos
);
974 shader_model_gate_uTime( vg
.time
*0.25f
);
975 shader_model_gate_uInvRes( (v2f
){
976 1.0f
/ (float)vg
.window_x
,
977 1.0f
/ (float)vg
.window_y
});
979 mesh_bind( &world_gates
.mesh
);
981 /* skip writing into the motion vectors for this */
982 glDrawBuffers( 1, (GLenum
[]){ GL_COLOR_ATTACHMENT0
} );
983 glDisable( GL_CULL_FACE
);
985 if( viewing_from_hub
){
986 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
987 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
990 v3_muls( route
->colour
, 1.6666f
, colour
);
993 shader_model_gate_uColour( colour
);
995 for( u32 j
=0; j
<mdl_arrcount(&world
->ent_gate
); j
++ ){
996 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, j
);
997 if( !(gate
->flags
& k_ent_gate_nonlocal_DELETED
) )
998 render_gate_markers( mmdl
, i
, gate
);
1003 for( u32 i
=0; i
<mdl_arrcount(&world
->ent_route
); i
++ ){
1004 ent_route
*route
= mdl_arritm( &world
->ent_route
, i
);
1006 if( route
->active_checkpoint
!= 0xffff ){
1008 float brightness
= 0.3f
+ world
->ub_lighting
.g_day_phase
;
1009 v3_muls( route
->colour
, brightness
, colour
);
1010 colour
[3] = 1.0f
-route
->factive
;
1012 shader_model_gate_uColour( colour
);
1014 u32 next
= route
->active_checkpoint
+1+viewing_from_gate
;
1015 next
= next
% route
->checkpoints_count
;
1016 next
+= route
->checkpoints_start
;
1018 ent_checkpoint
*cp
= mdl_arritm( &world
->ent_checkpoint
, next
);
1019 ent_gate
*gate
= mdl_arritm( &world
->ent_gate
, cp
->gate_index
);
1020 render_gate_markers( mmdl
, i
, gate
);
1024 glEnable( GL_CULL_FACE
);
1025 glDrawBuffers( 2, (GLenum
[]){ GL_COLOR_ATTACHMENT0
, GL_COLOR_ATTACHMENT1
} );
1028 #endif /* ROUTES_C */