quite a lot of changes
[carveJwlIkooP6JGAAIwe30JlM.git] / world_routes.c
1 /*
2 * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved
3 */
4
5 #ifndef ROUTES_C
6 #define ROUTES_C
7
8 #include <time.h>
9 #include "world_routes.h"
10 #include "world_gate.h"
11 #include "world_load.h"
12 #include "highscores.h"
13
14 #include "font.h"
15 #include "pointcloud.h"
16 #include "gui.h"
17 #include "steam.h"
18
19 #include "shaders/scene_route.h"
20 #include "shaders/routeui.h"
21
22
23 VG_STATIC
24 void world_routes_local_set_record( world_instance *world, ent_route *route,
25 f64 lap_time )
26 {
27 vg_success( " NEW LAP TIME: %f\n", lap_time );
28
29 if( route->official_track_id != 0xffffffff ){
30 double time_centiseconds = lap_time * 100.0;
31 if( time_centiseconds > (float)0xfffe ) /* skill issue */
32 return;
33
34 struct track_info *ti = &track_infos[ route->official_track_id ];
35 highscore_record *record = &ti->record;
36 record->trackid = route->official_track_id;
37 record->datetime = time(NULL);
38 record->playerid = 0;
39 record->points = 0;
40 record->time = time_centiseconds;
41 ti->push = 1;
42
43 if( ti->achievement_id ){
44 steam_set_achievement( ti->achievement_id );
45 steam_store_achievements();
46 }
47 }
48 else{
49 vg_warn( "There is no associated track for this record...\n" );
50 }
51 }
52
53
54 VG_STATIC void world_routes_clear( world_instance *world )
55 {
56 for( u32 i=0; i<mdl_arrcount( &world->ent_route ); i++ ){
57 ent_route *route = mdl_arritm( &world->ent_route, i );
58 route->active_checkpoint = 0xffff;
59 }
60
61 for( u32 i=0; i<mdl_arrcount( &world->ent_gate ); i++ ){
62 ent_gate *rg = mdl_arritm( &world->ent_gate, i );
63 rg->timing_version = 0;
64 rg->timing_time = 0.0;
65 }
66
67 world_static.current_run_version += 4;
68 world_static.last_use = 0.0;
69 }
70
71 VG_STATIC void world_routes_time_lap( world_instance *world, ent_route *route )
72 {
73 vg_info( "------- time lap %s -------\n",
74 mdl_pstr(&world->meta,route->pstr_name) );
75
76 double start_time = 0.0;
77 u32 last_version=0;
78
79 u32 valid_count=0;
80
81 for( u32 i=0; i<route->checkpoints_count; i++ ){
82 u32 cpid = (i+route->active_checkpoint) % route->checkpoints_count;
83 cpid += route->checkpoints_start;
84
85 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, cpid );
86 ent_gate *rg = mdl_arritm( &world->ent_gate, cp->gate_index );
87 rg = mdl_arritm( &world->ent_gate, rg->target );
88
89 if( i == 1 ){
90 route->timing_base = rg->timing_time;
91 }
92
93 if( i == 0 )
94 start_time = rg->timing_time;
95 else{
96 if( last_version+1 == rg->timing_version ) valid_count ++;
97 else valid_count = 0;
98 }
99
100 last_version = rg->timing_version;
101 vg_info( "%u %f\n", rg->timing_version, rg->timing_time );
102 }
103
104 if( world_static.current_run_version == last_version+1 ){
105 valid_count ++;
106
107 if( route->checkpoints_count == 1 ){
108 route->timing_base = world_static.time;
109 }
110 }
111 else valid_count = 0;
112
113 vg_info( "%u %f\n", world_static.current_run_version, world_static.time );
114
115 if( valid_count==route->checkpoints_count ){
116 double lap_time = world_static.time - start_time;
117 world_routes_local_set_record( world, route, lap_time );
118 }
119
120 route->valid_checkpoints = valid_count+1;
121
122 vg_info( "valid: %u\n", valid_count );
123 vg_info( "----------------------------\n" );
124 }
125
126 /*
127 * When going through a gate this is called for bookkeeping purposes
128 */
129 VG_STATIC void world_routes_activate_entry_gate( world_instance *world,
130 ent_gate *rg )
131 {
132 world_static.last_use = world_static.time;
133
134 /* disable all routes and leave the world */
135 if( rg->type == k_gate_type_nonlocel ){
136 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
137 ent_route *route = mdl_arritm( &world->ent_route, i );
138 route->active_checkpoint = 0xffff;
139 }
140 return;
141 }
142
143 ent_gate *dest = mdl_arritm( &world->ent_gate, rg->target );
144
145 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
146 ent_route *route = mdl_arritm( &world->ent_route, i );
147
148 u32 active_prev = route->active_checkpoint;
149 route->active_checkpoint = 0xffff;
150
151 for( u32 j=0; j<4; j++ ){
152 if( dest->routes[j] == i ){
153 for( u32 k=0; k<route->checkpoints_count; k++ ){
154 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint,
155 route->checkpoints_start+k );
156
157 ent_gate *gk = mdl_arritm( &world->ent_gate, cp->gate_index );
158 gk = mdl_arritm( &world->ent_gate, gk->target );
159 if( gk == dest ){
160 route->active_checkpoint = k;
161 world_routes_time_lap( world, route );
162 break;
163 }
164 }
165 break;
166 }
167 }
168 }
169
170 dest->timing_version = world_static.current_run_version;
171 dest->timing_time = world_static.time;
172
173 world_static.current_run_version ++;
174 }
175
176 /* draw lines along the paths */
177 VG_STATIC void world_routes_debug( world_instance *world )
178 {
179 for( u32 i=0; i<mdl_arrcount(&world->ent_route_node); i++ ){
180 ent_route_node *rn = mdl_arritm(&world->ent_route_node,i);
181 vg_line_pt3( rn->co, 0.25f, VG__WHITE );
182 }
183
184 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
185 ent_route *route = mdl_arritm(&world->ent_route, i);
186
187 u32 colours[] = { 0xfff58142, 0xff42cbf5, 0xff42f56c, 0xfff542b3,
188 0xff5442f5 };
189
190 u32 cc = 0xffcccccc;
191 if( route->active_checkpoint != 0xffff ){
192 cc = colours[i%vg_list_size(colours)];
193 }
194
195 for( int i=0; i<route->checkpoints_count; i++ ){
196 int i0 = route->checkpoints_start+i,
197 i1 = route->checkpoints_start+((i+1)%route->checkpoints_count);
198
199 ent_checkpoint *c0 = mdl_arritm(&world->ent_checkpoint, i0),
200 *c1 = mdl_arritm(&world->ent_checkpoint, i1);
201
202 ent_gate *start_gate = mdl_arritm( &world->ent_gate, c0->gate_index );
203 ent_gate *end_gate = mdl_arritm( &world->ent_gate, c1->gate_index );
204
205 v3f p0, p1;
206 v3_copy( start_gate->co[1], p0 );
207
208 for( int j=0; j<c0->path_count; j ++ ){
209 ent_path_index *index = mdl_arritm( &world->ent_path_index,
210 c0->path_start+j );
211
212 ent_route_node *rn = mdl_arritm( &world->ent_route_node,
213 index->index );
214
215 v3_copy( rn->co, p1 );
216 vg_line( p0, p1, cc );
217 v3_copy( p1, p0 );
218 }
219
220 v3_copy( end_gate->co[0], p1 );
221 vg_line( p0, p1, cc );
222 }
223 }
224 }
225
226 VG_STATIC
227 void world_routes_pointcloud_spot( world_instance *world,
228 pointcloud_buffer *pcbuf,
229 v3f co, f32 radius, u32 samples, v4f colour )
230 {
231 v3f inv_ext;
232 v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
233 v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
234
235 for( u32 j=0; j<samples; j++ ){
236 if( pcbuf->count >= pcbuf->max )
237 return;
238
239 pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
240
241 v3f sample, jitter, point;
242 vg_rand_sphere( jitter );
243 v3_muladds( co, jitter, radius, sample );
244
245 if( bh_closest_point( world->geo_bh, sample, point, radius*1.5f ) == -1 ){
246 v3_copy( sample, point );
247 }
248
249 v3f pos;
250 v3_sub( point, pcbuf->boundary[0], pos );
251 v3_mul( pos, inv_ext, pos );
252
253 for( u32 i=0; i<3; i++ ){
254 vert->pos[i] = (pos[i]-0.5f) * 32767.0f;
255 }
256
257 float dist = 1.0f-(v3_length(jitter));
258
259 for( u32 i=0; i<4; i++ ){
260 vert->colour[i] = colour[i] * 255.0f * dist*dist;
261 }
262 }
263 }
264
265 /*
266 * '
267 * .
268 * |
269 * |
270 * /#\
271 * -'###`-
272 */
273 VG_STATIC
274 void world_routes_pointcloud_tower( world_instance *world,
275 pointcloud_buffer *pcbuf,
276 v3f co, f32 radius, f32 height,
277 u32 samples, v4f colour )
278 {
279 v3f inv_ext;
280 v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
281 v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
282
283 for( u32 j=0; j<samples; j++ ){
284 if( pcbuf->count >= pcbuf->max )
285 return;
286
287 pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
288
289 v3f point;
290 point[0] = vg_randf64()*2.0f-1.0f;
291 point[1] = 0.0f;
292 point[2] = vg_randf64()*2.0f-1.0f;
293 v3_normalize( point );
294 v3_muls( point, sqrtf(vg_randf64()), point );
295
296 f32 h = vg_randf64();
297 point[1] = h*h*h*height;
298 point[0] *= radius;
299 point[2] *= radius;
300
301 v3_add( point, co, point );
302 v3_sub( point, pcbuf->boundary[0], point );
303 v3_mul( point, inv_ext, point );
304
305 /* TODO....... */
306 for( u32 i=0; i<3; i++ ){
307 vert->pos[i] = (point[i]-0.5f) * 32767.0f;
308 }
309
310 for( u32 i=0; i<4; i++ ){
311 vert->colour[i] = colour[i] * 255.0f;
312 }
313 }
314 }
315
316 VG_STATIC
317 void world_routes_place_curve( world_instance *world, ent_route *route,
318 v4f h[3], v3f n0, v3f n2, scene_context *scene,
319 pointcloud_buffer *pcbuf )
320 {
321 float t;
322 v3f p, pd;
323 int last_valid=0;
324
325 float total_length = 0.0f,
326 travel_length = 0.0;
327
328 v3f last;
329 v3_copy( h[0], last );
330 for( int it=0; it<128; it ++ ){
331 t = (float)(it+1) * (1.0f/128.0f);
332 eval_bezier3( h[0], h[1], h[2], t, p );
333 total_length += v3_dist( p, last );
334 v3_copy( p, last );
335 }
336
337 float patch_size = 4.0f,
338 patch_count = ceilf( total_length / patch_size );
339
340 t = 0.0f;
341 v3_copy( h[0], last );
342
343 for( int it=0; it<128; it ++ ){
344 float const k_sample_dist = 0.0025f,
345 k_line_width = 1.5f;
346
347 eval_bezier3( h[0], h[1], h[2], t, p );
348 eval_bezier3( h[0], h[1], h[2], t+k_sample_dist, pd );
349
350 travel_length += v3_dist( p, last );
351
352 float mod = k_sample_dist / v3_dist( p, pd );
353
354 v3f v0,up, right;
355
356 v3_muls( n0, -(1.0f-t), up );
357 v3_muladds( up, n2, -t, up );
358 v3_normalize( up );
359
360 v3_sub( pd,p,v0 );
361 v3_cross( up, v0, right );
362 v3_normalize( right );
363
364 float cur_x = (1.0f-t)*h[0][3] + t*h[2][3];
365
366 v3f sc, sa, sb, down;
367 v3_muladds( p, right, cur_x * k_line_width, sc );
368 v3_muladds( sc, up, 1.5f, sc );
369 v3_muladds( sc, right, k_line_width*0.95f, sa );
370 v3_muladds( sc, right, 0.0f, sb );
371 v3_muls( up, -1.0f, down );
372
373 ray_hit ha, hb;
374 ha.dist = 8.0f;
375 hb.dist = 8.0f;
376
377 int resa = ray_world( world, sa, down, &ha ),
378 resb = ray_world( world, sb, down, &hb );
379
380 if( pcbuf && resa ){
381 world_routes_pointcloud_spot( world, pcbuf, ha.pos,
382 12.0f, 10, route->colour );
383 }
384
385 if( resa && resb ){
386 struct world_surface *surfa = ray_hit_surface( world, &ha ),
387 *surfb = ray_hit_surface( world, &hb );
388
389 if( (surfa->info.flags & k_material_flag_skate_target) &&
390 (surfb->info.flags & k_material_flag_skate_target) )
391 {
392 scene_vert va, vb;
393
394 float gap = vg_fractf(cur_x*0.5f)*0.02f;
395
396 v3_muladds( ha.pos, up, 0.06f+gap, va.co );
397 v3_muladds( hb.pos, up, 0.06f+gap, vb.co );
398
399 scene_vert_pack_norm( &va, up );
400 scene_vert_pack_norm( &vb, up );
401
402 float t1 = (travel_length / total_length) * patch_count;
403 va.uv[0] = t1;
404 va.uv[1] = 0.0f;
405 vb.uv[0] = t1;
406 vb.uv[1] = 1.0f;
407
408 scene_push_vert( scene, &va );
409 scene_push_vert( scene, &vb );
410
411 if( last_valid ){
412 /* Connect them with triangles */
413 scene_push_tri( scene, (u32[3]){
414 last_valid+0-2, last_valid+1-2, last_valid+2-2} );
415 scene_push_tri( scene, (u32[3]){
416 last_valid+1-2, last_valid+3-2, last_valid+2-2} );
417 }
418
419 last_valid = scene->vertex_count;
420 }
421 else
422 last_valid = 0;
423 }
424 else
425 last_valid = 0;
426
427 if( t == 1.0f )
428 return;
429
430 t += 1.0f*mod;
431 if( t > 1.0f )
432 t = 1.0f;
433
434 v3_copy( p, last );
435 }
436 }
437
438 VG_STATIC void world_routes_gen_meshes( world_instance *world, u32 route_id,
439 scene_context *sc,
440 pointcloud_buffer *pcbuf )
441 {
442 ent_route *route = mdl_arritm( &world->ent_route, route_id );
443 u8 colour[4];
444 colour[0] = route->colour[0] * 255.0f;
445 colour[1] = route->colour[1] * 255.0f;
446 colour[2] = route->colour[2] * 255.0f;
447 colour[3] = route->colour[3] * 255.0f;
448
449 u32 last_valid = 0;
450
451 for( int i=0; i<route->checkpoints_count; i++ ){
452 int i0 = route->checkpoints_start+i,
453 i1 = route->checkpoints_start+((i+1)%route->checkpoints_count);
454
455 ent_checkpoint *c0 = mdl_arritm(&world->ent_checkpoint, i0),
456 *c1 = mdl_arritm(&world->ent_checkpoint, i1);
457
458 ent_gate *start_gate = mdl_arritm( &world->ent_gate, c0->gate_index );
459 start_gate = mdl_arritm( &world->ent_gate, start_gate->target );
460
461 ent_gate *end_gate = mdl_arritm( &world->ent_gate, c1->gate_index ),
462 *collector = mdl_arritm( &world->ent_gate, end_gate->target );
463
464 v4f p[3];
465
466 v3_add( (v3f){0.0f,0.1f,0.0f}, start_gate->co[0], p[0] );
467 p[0][3] = start_gate->ref_count;
468 p[0][3] -= (float)start_gate->route_count * 0.5f;
469 start_gate->ref_count ++;
470
471 if( !c0->path_count )
472 continue;
473
474 /* this is so that we get nice flow through the gates */
475 v3f temp_alignments[2];
476 ent_gate *both[] = { start_gate, end_gate };
477
478 for( int j=0; j<2; j++ ){
479 int pi = c0->path_start + ((j==1)? c0->path_count-1: 0);
480
481 ent_path_index *index = mdl_arritm( &world->ent_path_index, pi );
482 ent_route_node *rn = mdl_arritm( &world->ent_route_node,
483 index->index );
484 v3f v0;
485 v3_sub( rn->co, both[j]->co[0], v0 );
486 float d = v3_dot( v0, both[j]->to_world[2] );
487
488 v3_muladds( both[j]->co[0], both[j]->to_world[2], d,
489 temp_alignments[j] );
490 v3_add( (v3f){0.0f,0.1f,0.0f}, temp_alignments[j], temp_alignments[j]);
491 }
492
493
494 for( int j=0; j<c0->path_count; j ++ ){
495 ent_path_index *index = mdl_arritm( &world->ent_path_index,
496 c0->path_start+j );
497 ent_route_node *rn = mdl_arritm( &world->ent_route_node,
498 index->index );
499 if( j==0 || j==c0->path_count-1 )
500 if( j == 0 )
501 v3_copy( temp_alignments[0], p[1] );
502 else
503 v3_copy( temp_alignments[1], p[1] );
504 else
505 v3_copy( rn->co, p[1] );
506
507 p[1][3] = rn->ref_count;
508 p[1][3] -= (float)rn->ref_total * 0.5f;
509 rn->ref_count ++;
510
511 if( j+1 < c0->path_count ){
512 index = mdl_arritm( &world->ent_path_index,
513 c0->path_start+j+1 );
514 rn = mdl_arritm( &world->ent_route_node, index->index );
515
516 if( j+1 == c0->path_count-1 )
517 v3_lerp( p[1], temp_alignments[1], 0.5f, p[2] );
518 else
519 v3_lerp( p[1], rn->co, 0.5f, p[2] );
520
521 p[2][3] = rn->ref_count;
522 p[2][3] -= (float)rn->ref_total * 0.5f;
523 }
524 else{
525 v3_copy( end_gate->co[0], p[2] );
526 v3_add( (v3f){0.0f,0.1f,0.0f}, p[2], p[2] );
527 p[2][3] = collector->ref_count;
528
529 if( i == route->checkpoints_count-1)
530 p[2][3] -= 1.0f;
531
532 p[2][3] -= (float)collector->route_count * 0.5f;
533 //collector->ref_count ++;
534 }
535
536 /* p0,p1,p2 bezier patch is complete
537 * --------------------------------------*/
538 v3f surf0, surf2, n0, n2;
539
540 if( bh_closest_point( world->geo_bh, p[0], surf0, 5.0f ) == -1 )
541 v3_add( (v3f){0.0f,-0.1f,0.0f}, p[0], surf0 );
542
543 if( bh_closest_point( world->geo_bh, p[2], surf2, 5.0f ) == -1 )
544 v3_add( (v3f){0.0f,-0.1f,0.0f}, p[2], surf2 );
545
546 v3_sub( surf0, p[0], n0 );
547 v3_sub( surf2, p[2], n2 );
548 v3_normalize( n0 );
549 v3_normalize( n2 );
550
551 world_routes_place_curve( world, route, p, n0, n2, sc, pcbuf );
552
553 /* --- */
554 v4_copy( p[2], p[0] );
555 }
556 }
557
558 scene_copy_slice( sc, &route->sm );
559 }
560
561 VG_STATIC
562 struct world_surface *world_tri_index_surface( world_instance *world,
563 u32 index );
564
565 VG_STATIC f64 world_routes_scatter_surface_points( world_instance *world,
566 pointcloud_buffer *pcbuf,
567 f32 rate )
568 {
569 static f32 densities[] = {
570 [k_surface_prop_concrete] = 2.0f,
571 [k_surface_prop_grass] = 0.8f,
572 [k_surface_prop_metal] = 1.0f,
573 [k_surface_prop_wood] = 2.5f,
574 [k_surface_prop_tiles] = 4.0f
575 };
576
577 /* calculate total area */
578 f64 total_area = 0.0f;
579 for( u32 i=0; i<world->scene_geo.indice_count/3; i++ ){
580 u32 *tri = &world->scene_geo.arrindices[i*3];
581 struct world_surface *surf = world_tri_index_surface( world, tri[0] );
582
583 if( surf->info.shader == k_shader_boundary ||
584 surf->info.shader == k_shader_invisible ) continue;
585
586 if( !(surf->info.flags & k_material_flag_preview_visibile) ) continue;
587
588 scene_vert *va = &world->scene_geo.arrvertices[tri[0]],
589 *vb = &world->scene_geo.arrvertices[tri[1]],
590 *vc = &world->scene_geo.arrvertices[tri[2]];
591
592 v3f v0, v1, vn;
593 v3_sub( vb->co, va->co, v0 );
594 v3_sub( vc->co, va->co, v1 );
595 v3_cross( v0, v1, vn );
596 if( vn[1] < 0.0f ) continue;
597
598 f32 density = 1.0f;
599 if( surf->info.surface_prop < vg_list_size(densities) )
600 density = densities[surf->info.surface_prop];
601 total_area += v3_length(vn)*0.5f*density;
602 }
603
604 f32 accum = 0.0f;
605
606 u8 colour[] = { 80,80,80,255 };
607 v3f light_dir = {0.3f,0.8f,0.1f};
608 v3_normalize( light_dir );
609
610 v3f inv_ext;
611 v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
612 v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
613
614 for( u32 i=0; i<world->scene_geo.indice_count/3; i++ ){
615 u32 *tri = &world->scene_geo.arrindices[i*3];
616 struct world_surface *surf = world_tri_index_surface( world, tri[0] );
617
618 if( surf->info.shader == k_shader_boundary ||
619 surf->info.shader == k_shader_invisible ) continue;
620
621 if( !(surf->info.flags & k_material_flag_preview_visibile) ) continue;
622
623 scene_vert *va = &world->scene_geo.arrvertices[tri[0]],
624 *vb = &world->scene_geo.arrvertices[tri[1]],
625 *vc = &world->scene_geo.arrvertices[tri[2]];
626
627 v3f v0, v1, vn;
628 v3_sub( vb->co, va->co, v0 );
629 v3_sub( vc->co, va->co, v1 );
630 v3_cross( v0, v1, vn );
631 if( vn[1] < 0.0f ) continue;
632
633 f32 density = 1.0f;
634 if( surf->info.surface_prop < vg_list_size(densities) )
635 density = densities[surf->info.surface_prop];
636
637 f32 area = v3_length(vn)*0.5f*density;
638 accum += area;
639
640 v3_normalize( vn );
641
642 while( accum > rate ){
643 accum -= rate;
644
645 if( pcbuf->count >= pcbuf->max ) return total_area;
646
647 v2f co = { vg_randf64(), vg_randf64() };
648 if( v2_length2(co) > 0.5f ){
649 co[0] = 1.0f-co[0];
650 co[1] = 1.0f-co[1];
651 }
652
653 v3f pt;
654 v3_muls( v0, co[0], pt );
655 v3_muladds( pt, v1, co[1], pt );
656 v3_add( va->co, pt, pt );
657
658 if( pt[1] < world->water.height ) continue;
659 pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
660
661 v3f pos;
662 v3_sub( pt, pcbuf->boundary[0], pos );
663 v3_mul( pos, inv_ext, pos );
664
665 for( u32 i=0; i<3; i++ ){
666 vert->pos[i] = (pos[i]-0.5f) * 32767.0f;
667 }
668
669 static v4f colours[] = {
670 [k_surface_prop_concrete] = { 0.13, 0.15, 0.17, 1.0 },
671 [k_surface_prop_grass] = { 0.07, 0.1, 0.14, 1.0 },
672 [k_surface_prop_metal] = { 0.15, 0.19, 0.22, 1.0 },
673 [k_surface_prop_wood] = { 0.1, 0.13, 0.17, 1.0 },
674 [k_surface_prop_tiles] = { 0.05, 0.06, 0.07, 1.0 },
675 };
676
677 v4f col = {0.0f,0.0f,0.0f,0.0f};
678 if( surf->info.surface_prop < vg_list_size(colours) ){
679 v4_copy( colours[surf->info.surface_prop], col );
680 }
681
682 f32 brightness = v3_dot(vn,light_dir)*0.5f+0.5f;
683 v3_muls( col, brightness, col );
684
685 for( u32 j=0; j<4; j++ ){
686 vert->colour[j] = col[j] * 255.0f;
687 }
688 }
689 }
690
691 return total_area;
692 }
693
694 VG_STATIC void world_routes_surface_grid( world_instance *world,
695 pointcloud_buffer *pcbuf )
696 {
697 i32 const k_gridlines = 32,
698 k_gridres = 255;
699
700 v3f inv_ext;
701 v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext );
702 v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext );
703 v4f colour = {0.2f,0.2f,0.2f,1.0f};
704 v3f dir = {0.0f,-1.0f,0.0f};
705
706 for( u32 k=0; k<2; k++ ){
707 u32 a = k*2,
708 b = (k^0x1)*2;
709
710 for( i32 x=0; x<=k_gridlines; x++ ){
711 f32 t = (float)x / (float)k_gridlines,
712 px = vg_lerpf( pcbuf->boundary[0][a], pcbuf->boundary[1][a], t );
713
714 for( i32 z=0; z<=k_gridres; z++ ){
715 f32 tz = (float)z / (float)k_gridres,
716 pz = vg_lerpf(pcbuf->boundary[0][b],pcbuf->boundary[1][b], tz);
717
718 v3f ro, hit;
719 ro[a] = px;
720 ro[1] = 1000.0f;
721 ro[b] = pz;
722
723 bh_iter it;
724 bh_iter_init_ray( 0, &it, ro, dir, INFINITY );
725 i32 idx;
726
727 while( bh_next( world->geo_bh, &it, &idx ) ){
728 u32 *tri = &world->scene_geo.arrindices[ idx*3 ];
729 v3f vs[3];
730
731 for( u32 i=0; i<3; i++ ){
732 v3_copy( world->scene_geo.arrvertices[tri[i]].co, vs[i] );
733 }
734
735 f32 t;
736 if( ray_tri( vs, ro, dir, &t ) ){
737 v3_muladds( ro, dir, t, hit );
738 struct world_surface *m1 =
739 world_tri_index_surface( world, tri[0] );
740
741 if( !(m1->info.flags & k_material_flag_preview_visibile) )
742 continue;
743
744 if( world->water.enabled )
745 if( hit[1] < world->water.height )
746 continue;
747
748 if( pcbuf->count >= pcbuf->max ) return;
749
750 pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ];
751
752 v3f co;
753 v3_sub( hit, pcbuf->boundary[0], co );
754 v3_mul( co, inv_ext, co );
755
756 for( u32 i=0; i<3; i++ ){
757 vert->pos[i] = (co[i]-0.5f) * 32767.0f;
758 }
759
760 for( u32 i=0; i<4; i++ ){
761 vert->colour[i] = colour[i] * 255.0f;
762 }
763 }
764 }
765 }
766 }
767 }
768 }
769
770 VG_STATIC void world_write_preview( pointcloud_buffer *pcbuf ){
771 char path_buf[4096];
772 vg_str path;
773 vg_strnull( &path, path_buf, 4096 );
774
775 if( world_loader.reg ){
776 /* Don't want to override the one we get from the workshop */
777 if( world_loader.reg->alias.workshop_id ) return;
778
779 addon_get_content_folder( world_loader.reg, &path );
780 }
781 else{
782 vg_strcat( &path, "maps/" );
783 vg_strcat( &path, world_loader.override_name );
784 }
785
786 vg_strcat( &path, "/preview.bin" );
787
788 if( !vg_strgood( &path ) ) vg_fatal_error( "Path too long\n" );
789 FILE *fp = fopen( path_buf, "wb" );
790 if( !fp ) vg_fatal_error( "Cannot open '%s' for writing\n", path_buf );
791
792 fwrite( pcbuf, sizeof(struct pointcloud_buffer) +
793 sizeof(struct pointcloud_vert)*pcbuf->count, 1, fp );
794 fclose( fp );
795 }
796
797 /*
798 * Create the strips of colour that run through the world along course paths
799 */
800 VG_STATIC void world_gen_routes_generate(void)
801 {
802 world_instance *world = world_loading_instance();
803 vg_info( "Generating route meshes\n" );
804 vg_async_stall();
805
806 vg_rand_seed( 2000 );
807 vg_async_item *call_scene = scene_alloc_async( &world->scene_lines,
808 &world->mesh_route_lines,
809 200000, 300000 );
810
811 vg_async_item *call_pointcloud = NULL;
812 pointcloud_buffer *pcbuf = NULL;
813
814 if( world_loader.generate_point_cloud ){
815 call_pointcloud = vg_async_alloc(
816 sizeof(pointcloud_buffer) +
817 sizeof(pointcloud_vert)*POINTCLOUD_POINTS );
818 pcbuf = call_pointcloud->payload;
819 pcbuf->count = 0;
820 pcbuf->max = POINTCLOUD_POINTS;
821 pcbuf->op = k_pointcloud_op_clear;
822
823 v3f ext, mid, v0;
824 v3_sub( world->scene_geo.bbx[1], world->scene_geo.bbx[0], ext );
825 f32 maxe = v3_maxf( ext );
826 v3_fill( v0, maxe * 0.5f );
827 v3_muladds( world->scene_geo.bbx[0], ext, 0.5f, mid );
828 v3_add( mid, v0, pcbuf->boundary[1] );
829 v3_sub( mid, v0, pcbuf->boundary[0] );
830 }
831
832 for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){
833 ent_gate *gate = mdl_arritm( &world->ent_gate, i );
834 gate->ref_count = 0;
835 gate->route_count = 0;
836 }
837
838 for( u32 i=0; i<mdl_arrcount(&world->ent_route_node); i++ ){
839 ent_route_node *rn = mdl_arritm( &world->ent_route_node, i );
840 rn->ref_count = 0;
841 rn->ref_total = 0;
842 }
843
844 for( u32 k=0; k<mdl_arrcount(&world->ent_route); k++ ){
845 ent_route *route = mdl_arritm( &world->ent_route, k );
846
847 for( int i=0; i<route->checkpoints_count; i++ ){
848 int i0 = route->checkpoints_start+i,
849 i1 = route->checkpoints_start+((i+1)%route->checkpoints_count);
850
851 ent_checkpoint *c0 = mdl_arritm(&world->ent_checkpoint, i0),
852 *c1 = mdl_arritm(&world->ent_checkpoint, i1);
853
854 ent_gate *start_gate = mdl_arritm( &world->ent_gate, c0->gate_index );
855 start_gate = mdl_arritm( &world->ent_gate, start_gate->target );
856 start_gate->route_count ++;
857
858 if( !c0->path_count )
859 continue;
860
861 for( int j=0; j<c0->path_count; j ++ ){
862 ent_path_index *index = mdl_arritm( &world->ent_path_index,
863 c0->path_start+j );
864 ent_route_node *rn = mdl_arritm( &world->ent_route_node,
865 index->index );
866 rn->ref_total ++;
867 }
868 }
869 }
870
871 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
872 world_routes_gen_meshes( world, i, &world->scene_lines, pcbuf );
873 }
874
875 if( world_loader.generate_point_cloud ){
876 f64 area = 0.0;
877 area = world_routes_scatter_surface_points( world, pcbuf, 16.0f );
878 world_routes_surface_grid( world, pcbuf );
879
880 for( u32 i=0; i<mdl_arrcount( &world->ent_gate ); i++ ){
881 ent_gate *gate = mdl_arritm( &world->ent_gate, i );
882
883 world_routes_pointcloud_tower( world, pcbuf, gate->co[0],
884 2.0f, 50.0f, 128,
885 (v4f){0.2f,0.2f,0.2f,1.0f} );
886 }
887
888 vg_info( "Distrubuted %u points over %fkm^2!\n",
889 pcbuf->count, area/1e6f );
890
891 world_write_preview( pcbuf );
892 vg_async_dispatch( call_pointcloud, async_pointcloud_sub );
893 }
894
895 vg_async_dispatch( call_scene, async_scene_upload );
896 world_routes_clear( world );
897 }
898
899 /* load all routes from model header */
900 VG_STATIC void world_gen_routes_ent_init(void)
901 {
902 world_instance *world = world_loading_instance();
903 vg_info( "Initializing routes\n" );
904
905 for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){
906 ent_gate *gate = mdl_arritm( &world->ent_gate, i );
907 for( u32 j=0; j<4; j++ ){
908 gate->routes[j] = 0xffff;
909 }
910 }
911
912 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
913 ent_route *route = mdl_arritm(&world->ent_route,i);
914 mdl_transform_m4x3( &route->transform, route->board_transform );
915
916 route->official_track_id = 0xffffffff;
917 for( u32 j=0; j<vg_list_size(track_infos); j ++ ){
918 if( !strcmp(track_infos[j].name,
919 mdl_pstr(&world->meta,route->pstr_name))){
920 route->official_track_id = j;
921 }
922 }
923
924 for( u32 j=0; j<route->checkpoints_count; j++ ){
925 u32 id = route->checkpoints_start + j;
926 ent_checkpoint *cp = mdl_arritm(&world->ent_checkpoint,id);
927
928 ent_gate *gate = mdl_arritm( &world->ent_gate, cp->gate_index );
929
930 for( u32 k=0; k<4; k++ ){
931 if( gate->routes[k] == 0xffff ){
932 gate->routes[k] = i;
933 break;
934 }
935 }
936
937 if( gate->type == k_gate_type_teleport ){
938 gate = mdl_arritm(&world->ent_gate, gate->target );
939
940 for( u32 k=0; k<4; k++ ){
941 if( gate->routes[k] == i ){
942 vg_error( "already assigned route to gate\n" );
943 break;
944 }
945 if( gate->routes[k] == 0xffff ){
946 gate->routes[k] = i;
947 break;
948 }
949 }
950 }
951 }
952 }
953
954 for( u32 i=0; i<mdl_arrcount(&world->ent_gate); i++ ){
955 ent_gate *gate = mdl_arritm( &world->ent_gate, i );
956 }
957
958 world_routes_clear( world );
959 }
960
961 /*
962 * -----------------------------------------------------------------------------
963 * Events
964 * -----------------------------------------------------------------------------
965 */
966
967 VG_STATIC void world_routes_init(void)
968 {
969 world_static.current_run_version = 200;
970 world_static.time = 300.0;
971 world_static.last_use = 0.0;
972
973 shader_scene_route_register();
974 shader_routeui_register();
975 }
976
977 VG_STATIC void world_routes_update( world_instance *world )
978 {
979 world_static.time += vg.time_delta;
980
981 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
982 ent_route *route = mdl_arritm( &world->ent_route, i );
983
984 int target = route->active_checkpoint == 0xffff? 0: 1;
985 route->factive = vg_lerpf( route->factive, target, 0.6f*vg.time_delta );
986 }
987
988 for( u32 i=0; i<world_render.text_particle_count; i++ ){
989 struct text_particle *particle = &world_render.text_particles[i];
990 rb_object_debug( &particle->obj, VG__RED );
991 }
992 }
993
994 VG_STATIC void world_routes_fixedupdate( world_instance *world )
995 {
996 rb_solver_reset();
997
998 for( u32 i=0; i<world_render.text_particle_count; i++ ){
999 struct text_particle *particle = &world_render.text_particles[i];
1000
1001 if( rb_global_has_space() ){
1002 rb_ct *buf = rb_global_buffer();
1003
1004 int l = rb_sphere__scene( particle->obj.rb.to_world,
1005 &particle->obj.inf.sphere,
1006 NULL, &world->rb_geo.inf.scene, buf );
1007
1008 for( int j=0; j<l; j++ ){
1009 buf[j].rba = &particle->obj.rb;
1010 buf[j].rbb = &world->rb_geo.rb;
1011 }
1012
1013 rb_contact_count += l;
1014 }
1015 }
1016
1017 rb_presolve_contacts( rb_contact_buffer, rb_contact_count );
1018
1019 for( int i=0; i<rb_contact_count; i++ ){
1020 rb_contact_restitution( rb_contact_buffer+i, vg_randf64() );
1021 }
1022
1023 for( int i=0; i<6; i++ ){
1024 rb_solve_contacts( rb_contact_buffer, rb_contact_count );
1025 }
1026
1027 for( u32 i=0; i<world_render.text_particle_count; i++ ){
1028 struct text_particle *particle = &world_render.text_particles[i];
1029 rb_iter( &particle->obj.rb );
1030 }
1031
1032 for( u32 i=0; i<world_render.text_particle_count; i++ ){
1033 struct text_particle *particle = &world_render.text_particles[i];
1034 rb_update_transform( &particle->obj.rb );
1035 }
1036 }
1037
1038 VG_STATIC void bind_terrain_noise(void);
1039 VG_STATIC void world_bind_light_array( world_instance *world,
1040 GLuint shader, GLuint location,
1041 int slot );
1042 VG_STATIC void world_bind_light_index( world_instance *world,
1043 GLuint shader, GLuint location,
1044 int slot );
1045
1046 VG_STATIC void world_routes_update_timer_texts( world_instance *world )
1047 {
1048 world_render.timer_text_count = 0;
1049
1050 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
1051 ent_route *route = mdl_arritm( &world->ent_route, i );
1052
1053 if( route->active_checkpoint != 0xffff ){
1054 u32 next = route->active_checkpoint+1;
1055 next = next % route->checkpoints_count;
1056 next += route->checkpoints_start;
1057
1058 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, next );
1059 ent_gate *gate = mdl_arritm( &world->ent_gate, cp->gate_index );
1060 ent_gate *dest = mdl_arritm( &world->ent_gate, gate->target );
1061
1062 u32 j=0;
1063 for( ; j<4; j++ ){
1064 if( dest->routes[j] == i ){
1065 break;
1066 }
1067 }
1068
1069 float h0 = 0.8f,
1070 h1 = 1.2f,
1071 depth = 0.4f,
1072 size = 0.4f;
1073
1074 struct timer_text *text =
1075 &world_render.timer_texts[ world_render.timer_text_count ++ ];
1076
1077 text->gate = gate;
1078 text->route = route;
1079
1080 if( route->valid_checkpoints >= route->checkpoints_count ){
1081 double lap_time = world_static.time - route->timing_base,
1082 time_centiseconds = lap_time * 100.0;
1083
1084 if( time_centiseconds > (float)0xfffe ) time_centiseconds = 0.0;
1085
1086 u16 centiseconds = time_centiseconds,
1087 seconds = centiseconds / 100,
1088 minutes = seconds / 60;
1089
1090 centiseconds %= 100;
1091 seconds %= 60;
1092 minutes %= 60;
1093
1094 if( minutes > 9 ) minutes = 9;
1095
1096 int j=0;
1097 if( minutes ){
1098 highscore_intr( text->text, minutes, 1, ' ' ); j++;
1099 text->text[j++] = ':';
1100 }
1101
1102 if( seconds >= 10 || minutes ){
1103 highscore_intr( text->text+j, seconds, 2, '0' ); j+=2;
1104 }
1105 else{
1106 highscore_intr( text->text+j, seconds, 1, '0' ); j++;
1107 }
1108
1109 text->text[j++] = '.';
1110 highscore_intr( text->text+j, centiseconds, 1, '0' ); j++;
1111 text->text[j] = '\0';
1112 }
1113 else{
1114 highscore_intr( text->text, route->valid_checkpoints, 1, ' ' );
1115 text->text[1] = '/';
1116 highscore_intr( text->text+2, route->checkpoints_count+1, 1, ' ' );
1117 text->text[3] = '\0';
1118 }
1119
1120 float align_r = font3d_string_width( &gui.font, 0, text->text );
1121 align_r *= size;
1122
1123 v3f positions[] = {
1124 { -0.92f, h0, depth },
1125 { 0.92f - align_r, h0, depth },
1126 { -0.92f, h1, depth },
1127 { 0.92f - align_r, h1, depth },
1128 };
1129
1130 if( dest->route_count == 1 ){
1131 positions[0][0] = -align_r*0.5f;
1132 positions[0][1] = h1;
1133 }
1134
1135 m3x3_copy( gate->to_world, text->transform );
1136 float ratio = v3_length(text->transform[0]) /
1137 v3_length(text->transform[1]);
1138
1139 m3x3_scale( text->transform, (v3f){ size, size*ratio, 0.1f } );
1140 m4x3_mulv( gate->to_world, positions[j], text->transform[3] );
1141 }
1142 }
1143 }
1144
1145 VG_STATIC void world_routes_fracture( world_instance *world, ent_gate *gate,
1146 v3f imp_co, v3f imp_v )
1147 {
1148 world_render.text_particle_count = 0;
1149
1150 for( u32 i=0; i<world_render.timer_text_count; i++ ){
1151 struct timer_text *text = &world_render.timer_texts[i];
1152
1153 if( text->gate != gate ) continue;
1154
1155 m4x3f transform;
1156 m4x3_mul( gate->transport, text->transform, transform );
1157
1158 v3f co, s;
1159 v4f q;
1160 m4x3_decompose( transform, co, q, s );
1161
1162 v3f offset;
1163 v3_zero( offset );
1164
1165 v4f colour;
1166 float brightness = 0.3f + world->ub_lighting.g_day_phase;
1167 v3_muls( text->route->colour, brightness, colour );
1168 colour[3] = 1.0f-text->route->factive;
1169
1170 for( u32 j=0;; j++ ){
1171 char c = text->text[j];
1172 if( !c ) break;
1173
1174 ent_glyph *glyph = font3d_glyph( &gui.font, 0, c );
1175 if( !glyph ) continue;
1176
1177 if( c >= (u32)'0' && c <= (u32)'9' && glyph->indice_count ){
1178 struct text_particle *particle =
1179 &world_render.text_particles[world_render.text_particle_count++];
1180
1181 particle->glyph = glyph;
1182 v4_copy( colour, particle->colour );
1183
1184 v3f origin;
1185 v2_muls( glyph->size, 0.5f, origin );
1186 origin[2] = -0.5f;
1187
1188 v3f world_co;
1189
1190 v3_add( offset, origin, world_co );
1191 m4x3_mulv( transform, world_co, world_co );
1192
1193 float r = vg_maxf( s[0]*glyph->size[0], s[1]*glyph->size[1] )*0.5f;
1194
1195 m3x3_identity( particle->mlocal );
1196 m3x3_scale( particle->mlocal, s );
1197 origin[2] *= s[2];
1198 v3_muls( origin, -1.0f, particle->mlocal[3] );
1199
1200 v3_copy( world_co, particle->obj.rb.co );
1201 v3_muls( imp_v, 1.0f+vg_randf64(), particle->obj.rb.v );
1202 particle->obj.rb.v[1] += 2.0f;
1203
1204 v4_copy( q, particle->obj.rb.q );
1205 particle->obj.rb.w[0] = vg_randf64()*2.0f-1.0f;
1206 particle->obj.rb.w[1] = vg_randf64()*2.0f-1.0f;
1207 particle->obj.rb.w[2] = vg_randf64()*2.0f-1.0f;
1208
1209 particle->obj.type = k_rb_shape_sphere;
1210 particle->obj.inf.sphere.radius = r*0.6f;
1211
1212 rb_init_object( &particle->obj );
1213 }
1214 offset[0] += glyph->size[0];
1215 }
1216 }
1217 }
1218
1219 VG_STATIC void render_world_routes( world_instance *world, camera *cam,
1220 int layer_depth )
1221 {
1222 m4x3f identity_matrix;
1223 m4x3_identity( identity_matrix );
1224
1225 shader_scene_route_use();
1226 shader_scene_route_uTexGarbage(0);
1227 world_link_lighting_ub( world, _shader_scene_route.id );
1228 world_bind_position_texture( world, _shader_scene_route.id,
1229 _uniform_scene_route_g_world_depth, 2 );
1230 world_bind_light_array( world, _shader_scene_route.id,
1231 _uniform_scene_route_uLightsArray, 3 );
1232 world_bind_light_index( world, _shader_scene_route.id,
1233 _uniform_scene_route_uLightsIndex, 4 );
1234 bind_terrain_noise();
1235
1236 shader_scene_route_uPv( cam->mtx.pv );
1237 shader_scene_route_uPvmPrev( cam->mtx_prev.pv );
1238 shader_scene_route_uMdl( identity_matrix );
1239 shader_scene_route_uCamera( cam->transform[3] );
1240
1241 mesh_bind( &world->mesh_route_lines );
1242
1243 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
1244 ent_route *route = mdl_arritm( &world->ent_route, i );
1245
1246 v4f colour;
1247 v3_lerp( (v3f){0.7f,0.7f,0.7f}, route->colour, route->factive, colour );
1248 colour[3] = route->factive*0.2f;
1249
1250 shader_scene_route_uColour( colour );
1251 mdl_draw_submesh( &route->sm );
1252 }
1253
1254 /* timers
1255 * ---------------------------------------------------- */
1256 if( layer_depth == 0 ){
1257 font3d_bind( &gui.font, cam );
1258
1259 for( u32 i=0; i<world_render.timer_text_count; i++ ){
1260 struct timer_text *text = &world_render.timer_texts[i];
1261
1262 v4f colour;
1263 float brightness = 0.3f + world->ub_lighting.g_day_phase;
1264 v3_muls( text->route->colour, brightness, colour );
1265 colour[3] = 1.0f-text->route->factive;
1266
1267 shader_model_font_uColour( colour );
1268 font3d_simple_draw( &gui.font, 0, text->text, cam, text->transform );
1269 }
1270
1271 shader_model_font_uOffset( (v4f){0.0f,0.0f,0.0f,1.0f} );
1272
1273 for( u32 i=0; i<world_render.text_particle_count; i++ ){
1274 struct text_particle *particle = &world_render.text_particles[i];
1275
1276 m4x4f prev_mtx;
1277
1278 m4x3_expand( particle->mdl, prev_mtx );
1279 m4x4_mul( cam->mtx_prev.pv, prev_mtx, prev_mtx );
1280
1281 shader_model_font_uPvmPrev( prev_mtx );
1282
1283 v4f q;
1284 m4x3f model;
1285 rb_extrapolate( &particle->obj.rb, model[3], q );
1286 q_m3x3( q, model );
1287
1288 m4x3_mul( model, particle->mlocal, particle->mdl );
1289 shader_model_font_uMdl( particle->mdl );
1290 shader_model_font_uColour( particle->colour );
1291
1292 mesh_drawn( particle->glyph->indice_start,
1293 particle->glyph->indice_count );
1294 }
1295 }
1296
1297 /* gate markers
1298 * ---------------------------------------------------- */
1299
1300 shader_model_gate_use();
1301 shader_model_gate_uPv( cam->mtx.pv );
1302 shader_model_gate_uCam( cam->pos );
1303 shader_model_gate_uTime( vg.time*0.25f );
1304 shader_model_gate_uInvRes( (v2f){
1305 1.0f / (float)vg.window_x,
1306 1.0f / (float)vg.window_y });
1307
1308 mesh_bind( &world_gates.mesh );
1309
1310 /* skip writing into the motion vectors for this */
1311 glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } );
1312
1313 for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
1314 ent_route *route = mdl_arritm( &world->ent_route, i );
1315
1316 if( route->active_checkpoint != 0xffff ){
1317 v4f colour;
1318 float brightness = 0.3f + world->ub_lighting.g_day_phase;
1319 v3_muls( route->colour, brightness, colour );
1320 colour[3] = 1.0f-route->factive;
1321
1322 shader_model_gate_uColour( colour );
1323
1324 u32 next = route->active_checkpoint+1+layer_depth;
1325 next = next % route->checkpoints_count;
1326 next += route->checkpoints_start;
1327
1328 ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, next );
1329 ent_gate *gate = mdl_arritm( &world->ent_gate, cp->gate_index );
1330 shader_model_gate_uMdl( gate->to_world );
1331
1332 for( u32 j=0; j<4; j++ ){
1333 if( gate->routes[j] == i ){
1334 mdl_draw_submesh( &world_gates.sm_marker[j] );
1335 break;
1336 }
1337 }
1338 }
1339 }
1340 glDrawBuffers( 2, (GLenum[]){ GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 } );
1341 }
1342
1343 #endif /* ROUTES_C */