added SANE mesh api
[fishladder.git] / fishladder.c
1 // Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
2
3 //#define VG_STEAM
4 #include "vg/vg.h"
5
6 SHADER_DEFINE( shader_tile_colour,
7
8 // VERTEX
9 "layout (location=0) in vec2 a_co;"
10 "uniform mat3 uPv;"
11 "uniform vec3 uOffset;"
12 ""
13 "void main()"
14 "{"
15 "gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );"
16 "}",
17
18 // FRAGMENT
19 "out vec4 FragColor;"
20 "uniform vec4 uColour;"
21 ""
22 "void main()"
23 "{"
24 "FragColor = uColour;"
25 "}"
26 ,
27 UNIFORMS({ "uPv", "uOffset", "uColour" })
28 )
29
30 m3x3f m_projection;
31 m3x3f m_view;
32 m3x3f m_mdl;
33
34 #define FLAG_INPUT 0x1
35 #define FLAG_OUTPUT 0x2
36 #define FLAG_CANAL 0x4
37 #define FLAG_WALL 0x8
38 #define FLAG_DROP_L 0x10
39 #define FLAG_SPLIT 0x20
40 #define FLAG_MERGER 0x40
41 #define FLAG_DROP_R 0x80
42 #define FLAG_FLIP_FLOP 0x100
43
44 v3f colour_sets[] =
45 { { 0.9f, 0.2f, 0.01f },
46 { 0.2f, 0.9f, 0.14f },
47 { 0.1f, 0.3f, 0.85f } };
48
49 static void colour_code_v3( char cc, v3f target )
50 {
51 if( cc >= 'a' && cc <= 'z' )
52 {
53 int id = cc - 'a';
54
55 if( id < vg_list_size( colour_sets ) )
56 {
57 v3_copy( colour_sets[ id ], target );
58 return;
59 }
60 }
61
62 v3_copy( (v3f){0.0f,0.0f,0.0f}, target );
63 }
64
65 struct mesh
66 {
67 GLuint vao, vbo;
68 u32 elements;
69 };
70
71 static void init_mesh( struct mesh *m, float *tris, u32 length )
72 {
73 m->elements = length/3;
74 glGenVertexArrays( 1, &m->vao );
75 glGenBuffers( 1, &m->vbo );
76
77 glBindVertexArray( m->vao );
78 glBindBuffer( GL_ARRAY_BUFFER, m->vbo );
79 glBufferData( GL_ARRAY_BUFFER, length*sizeof(float), tris, GL_STATIC_DRAW );
80
81 glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0 );
82 glEnableVertexAttribArray( 0 );
83
84 VG_CHECK_GL();
85 }
86
87 static void free_mesh( struct mesh *m )
88 {
89 glDeleteVertexArrays( 1, &m->vao );
90 glDeleteBuffers( 1, &m->vbo );
91 }
92
93 static void draw_mesh( int const start, int const count )
94 {
95 glDrawArrays( GL_TRIANGLES, start*3, count*3 );
96 }
97
98 static void use_mesh( struct mesh *m )
99 {
100 glBindVertexArray( m->vao );
101 }
102
103 struct world
104 {
105 struct cell
106 {
107 u32 state;
108 u8 config;
109 }
110 *data;
111
112 u32 frame;
113
114 u32 sim_frame;
115 float sim_start;
116 int simulating;
117
118 struct cell_terminal
119 {
120 // TODO: Split into input/output structures
121 char *conditions;
122 char recv[12];
123 int recv_count;
124 int id;
125 }
126 *io;
127
128 u32 w, h;
129
130 struct mesh tile, circle;
131
132 int selected;
133
134 struct fish
135 {
136 v2i pos;
137 v2i dir;
138 int alive;
139 char payload;
140 }
141 fishes[16];
142
143 int num_fishes;
144 } world = {};
145
146 static void map_free(void)
147 {
148 for( int i = 0; i < arrlen( world.io ); i ++ )
149 arrfree( world.io[ i ].conditions );
150
151 arrfree( world.data );
152 arrfree( world.io );
153
154 world.w = 0;
155 world.h = 0;
156 world.data = NULL;
157 world.io = NULL;
158 }
159
160 static int map_load( const char *str )
161 {
162 map_free();
163
164 char const *c = str;
165
166 // Scan for width
167 for(;; world.w ++)
168 {
169 if( str[world.w] == ';' )
170 break;
171 else if( !str[world.w] )
172 {
173 vg_error( "Unexpected EOF when parsing level\n" );
174 return 0;
175 }
176 }
177
178 struct cell *row = arraddnptr( world.data, world.w );
179 int cx = 0;
180 int reg_start = 0, reg_end = 0;
181
182 for(;;)
183 {
184 if( !*c )
185 break;
186
187 if( *c == ';' )
188 {
189 c ++;
190
191 // Parse attribs
192 if( *c != '\n' )
193 {
194 while( *c )
195 {
196 if( reg_start < reg_end )
197 {
198 if( *c >= 'a' && *c <= 'z' )
199 {
200 arrpush( world.io[ reg_start ].conditions, *c );
201 }
202 else
203 {
204 if( *c == ',' || *c == '\n' )
205 {
206 reg_start ++;
207
208 if( *c == '\n' )
209 break;
210 }
211 else
212 {
213 vg_error( "Unkown attribute '%c' (row: %u)\n", *c, world.h );
214 return 0;
215 }
216 }
217 }
218 else
219 {
220 vg_error( "Too many values to assign (row: %u)\n", world.h );
221 return 0;
222 }
223
224 c ++;
225 }
226 }
227
228 if( reg_start != reg_end )
229 {
230 vg_error( "Not enough values assigned (row: %u, %u of %u)\n", world.h, reg_start, reg_end );
231 return 0;
232 }
233
234 if( cx != world.w )
235 {
236 vg_error( "Not enough cells to match previous row definition (row: %u, %u<%u)\n", world.h, cx, world.w );
237 return 0;
238 }
239
240 row = arraddnptr( world.data, world.w );
241 cx = 0;
242 world.h ++;
243 reg_end = reg_start = arrlen( world.io );
244 }
245 else
246 {
247 if( cx == world.w )
248 {
249 vg_error( "Too many cells to match previous row definition (row: %u, %u>%u)\n", world.h, cx, world.w );
250 return 0;
251 }
252
253 // Tile initialization
254 // row[ cx ] .. etc
255
256 if( *c == '+' || *c == '-' )
257 {
258 struct cell_terminal term = { .id = cx + world.h*world.w };
259 arrpush( world.io, term );
260 row[ cx ++ ].state = *c == '+'? FLAG_INPUT: FLAG_OUTPUT;
261 reg_end ++;
262 }
263 else if( *c == '#' )
264 {
265 row[ cx ++ ].state = FLAG_WALL;
266 }
267 else
268 {
269 row[ cx ++ ].state = 0x00;
270 }
271 }
272
273 c ++;
274 }
275
276 vg_success( "Map loaded! (%u:%u)\n", world.w, world.h );
277 return 1;
278 }
279
280 static struct cell *pcell( v2i pos )
281 {
282 return &world.data[ pos[1]*world.w + pos[0] ];
283 }
284
285 int main( int argc, char *argv[] )
286 {
287 vg_init( argc, argv, "FishLadder" );
288 }
289
290 void vg_register(void)
291 {
292 SHADER_INIT( shader_tile_colour );
293 }
294
295 void vg_start(void)
296 {
297 // Quad mesh
298 {
299 float quad_mesh[] =
300 {
301 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
302 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f,
303
304 0.48f, 0.48f, 0.5f, 0.52f, 0.52f, 0.52f, // Static dot
305 0.375f, 0.25f, 0.5f, 0.75f, 0.625f, 0.25f, // Downwards pointing arrow
306 0.25f, 0.625f, 0.75f, 0.5f, 0.25f, 0.375f, // Left
307 0.625f, 0.75f, 0.5f, 0.25f, 0.375f, 0.75f, // up
308 0.75f, 0.375f, 0.25f, 0.5f, 0.75f, 0.625f
309 };
310
311 init_mesh( &world.tile, quad_mesh, vg_list_size(quad_mesh) );
312 }
313
314 // Circle mesh
315 {
316 float circle_mesh[32*6*3];
317 int res = vg_list_size( circle_mesh ) / (6*3);
318
319 for( int i = 0; i < res; i ++ )
320 {
321 v2f v0 = { sinf( ((float)i/(float)res)*VG_TAUf ), cosf( ((float)i/(float)res)*VG_TAUf ) };
322 v2f v1 = { sinf( ((float)(i+1)/(float)res)*VG_TAUf ), cosf( ((float)(i+1)/(float)res)*VG_TAUf ) };
323
324 circle_mesh[ i*6+0 ] = 0.0f;
325 circle_mesh[ i*6+1 ] = 0.0f;
326
327 v2_copy( v0, circle_mesh + 32*6 + i*12 );
328 v2_muls( v0, 0.8f, circle_mesh + 32*6 + i*12+2 );
329 v2_copy( v1, circle_mesh + 32*6 + i*12+4 );
330
331 v2_copy( v1, circle_mesh + 32*6 + i*12+6 );
332 v2_muls( v1, 0.8f, circle_mesh + 32*6 + i*12+8 );
333 v2_muls( v0, 0.8f, circle_mesh + 32*6 + i*12+10 );
334
335 v2_copy( v0, circle_mesh + i*6+4 );
336 v2_copy( v1, circle_mesh + i*6+2 );
337 v2_copy( v0, circle_mesh+i*6+4 );
338 v2_copy( v1, circle_mesh+i*6+2 );
339 }
340
341 init_mesh( &world.circle, circle_mesh, vg_list_size( circle_mesh ) );
342 }
343
344 map_load
345 (
346 "#############;\n"
347 "###-#####-###;aaa,aa\n"
348 "## ##;\n"
349 "## ##;\n"
350 "## ##;\n"
351 "## ##;\n"
352 "## ##;\n"
353 "## ##;\n"
354 "###+#####+###;aa,aaa\n"
355 "#############;\n"
356 );
357 }
358
359 void vg_free(void)
360 {
361 free_mesh( &world.tile );
362 free_mesh( &world.circle );
363
364 map_free();
365 }
366
367 static int cell_interactive( v2i co )
368 {
369 // Bounds check
370 if( co[0] < 2 || co[0] >= world.w-2 || co[1] < 2 || co[1] >= world.h-2 )
371 return 0;
372
373 // Flags check
374 if( world.data[ world.w*co[1] + co[0] ].state & (FLAG_WALL|FLAG_INPUT|FLAG_OUTPUT) )
375 return 0;
376
377 // List of 3x3 configurations that we do not allow
378 static u32 invalid_src[][9] =
379 {
380 { 0,1,0,
381 1,1,1,
382 0,1,0
383 },
384 { 0,0,0,
385 0,1,1,
386 0,1,1
387 },
388 { 0,0,0,
389 1,1,0,
390 1,1,0
391 },
392 { 0,1,1,
393 0,1,1,
394 0,0,0
395 },
396 { 1,1,0,
397 1,1,0,
398 0,0,0
399 },
400 { 0,1,0,
401 0,1,1,
402 0,1,0
403 },
404 { 0,1,0,
405 1,1,0,
406 0,1,0
407 }
408 };
409
410 // Statically compile invalid configurations into bitmasks
411 static u32 invalid[ vg_list_size(invalid_src) ];
412
413 for( int i = 0; i < vg_list_size(invalid_src); i ++ )
414 {
415 u32 comped = 0x00;
416
417 for( int j = 0; j < 3; j ++ )
418 for( int k = 0; k < 3; k ++ )
419 comped |= invalid_src[i][ j*3+k ] << ((j*5)+k);
420
421 invalid[i] = comped;
422 }
423
424 // Extract 5x5 grid surrounding tile
425 u32 blob = 0x1000;
426 for( int y = co[1]-2; y < co[1]+3; y ++ )
427 for( int x = co[0]-2; x < co[0]+3; x ++ )
428 {
429 struct cell *cell = pcell((v2i){x,y});
430
431 if( cell && (cell->state & (FLAG_CANAL|FLAG_INPUT|FLAG_OUTPUT)) )
432 blob |= 0x1 << ((y-(co[1]-2))*5 + x-(co[0]-2));
433 }
434
435 // Run filter over center 3x3 grid to check for invalid configurations
436 int kernel[] = { 0, 1, 2, 5, 6, 7, 10, 11, 12 };
437 for( int i = 0; i < vg_list_size(kernel); i ++ )
438 {
439 if( blob & (0x1 << (6+kernel[i])) )
440 {
441 u32 window = blob >> kernel[i];
442
443 for( int j = 0; j < vg_list_size(invalid); j ++ )
444 if((window & invalid[j]) == invalid[j])
445 return 0;
446 }
447 }
448
449 return 1;
450 }
451
452 void vg_update(void)
453 {
454 float ratio = (float)vg_window_y / (float)vg_window_x;
455 float const size = 9.5f;
456
457 v3f origin;
458 origin[0] = -0.5f * world.w;
459 origin[1] = -0.5f * world.h;
460 origin[2] = 0.0f;
461
462 m3x3_projection( m_projection, -size, size, -size*ratio, size*ratio );
463 m3x3_identity( m_view );
464 m3x3_translate( m_view, origin );
465 m3x3_mul( m_projection, m_view, vg_pv );
466 vg_projection_update();
467
468 // Input stuff
469
470 v2f tile_pos;
471 v2_copy( vg_mouse_ws, tile_pos );
472
473 int tile_x = floorf( tile_pos[0] );
474 int tile_y = floorf( tile_pos[1] );
475
476 // Tilemap editing
477 if( !world.simulating )
478 {
479 if( cell_interactive( (v2i){ tile_x, tile_y } ))
480 {
481 world.selected = tile_y * world.w + tile_x;
482
483 if( vg_get_button_down("primary") )
484 {
485 world.data[ world.selected ].state ^= FLAG_CANAL;
486 }
487 }
488 else
489 world.selected = -1;
490 }
491
492 // Simulation stop/start
493 if( vg_get_button_down("go") )
494 {
495 if( world.simulating )
496 {
497 world.simulating = 0;
498 world.num_fishes = 0;
499 world.sim_frame = 0;
500
501 for( int i = 0; i < arrlen( world.io ); i ++ )
502 world.io[i].recv_count = 0;
503
504 vg_info( "Stopping simulation!\n" );
505 }
506 else
507 {
508 vg_success( "Starting simulation!\n" );
509
510 world.simulating = 1;
511 world.num_fishes = 0;
512 world.sim_frame = 0;
513 world.sim_start = vg_time;
514
515 for( int i = 0; i < world.w*world.h; i ++ )
516 {
517 world.data[ i ].state &= ~FLAG_FLIP_FLOP;
518 }
519
520 for( int i = 0; i < arrlen( world.io ); i ++ )
521 world.io[i].recv_count = 0;
522 }
523 }
524
525 // Simulation stuff
526 // ========================================================
527
528 // Reclassify world. TODO: Move into own function
529 for( int y = 2; y < world.h-2; y ++ )
530 {
531 for( int x = 2; x < world.w-2; x ++ )
532 {
533 v2i dirs[] = {{1,0},{0,1},{-1,0},{0,-1}};
534
535 u8 config = 0x00;
536
537 if( pcell((v2i){x,y})->state & FLAG_CANAL )
538 {
539 for( int i = 0; i < vg_list_size( dirs ); i ++ )
540 {
541 struct cell *neighbour = pcell((v2i){x+dirs[i][0], y+dirs[i][1]});
542 if( neighbour->state & (FLAG_CANAL|FLAG_INPUT|FLAG_OUTPUT) )
543 config |= 0x1 << i;
544 }
545 } else config = 0xF;
546
547 pcell((v2i){x,y})->config = config;
548 pcell((v2i){x,y})->state &= ~(FLAG_DROP_L|FLAG_DROP_R|FLAG_SPLIT|FLAG_MERGER);
549 }
550 }
551
552 for( int y = 2; y < world.h-2; y ++ )
553 for( int x = 2; x < world.w-2; x ++ )
554 {
555 // R,D,L,- 1110 (splitter, 1 drop created)
556
557 // R,-,L,U - 1011 (merger, 2 drop created)
558
559 u8 config = pcell((v2i){x,y})->config;
560
561 if( config == 0x7 ) // splitter
562 {
563 world.data[y*world.w+x ].state |= (FLAG_SPLIT | FLAG_DROP_L | FLAG_DROP_R);
564 }
565 else if( config == 0xD )
566 {
567 world.data[y*world.w+x-1].state |= FLAG_DROP_R;
568 world.data[y*world.w+x+1].state |= FLAG_DROP_L;
569 world.data[y*world.w+x].state |= FLAG_MERGER;
570 }
571 }
572
573 // Fish ticks
574 if( world.simulating )
575 {
576 while( world.sim_frame < (int)((vg_time-world.sim_start)*2.0f) )
577 {
578 vg_info( "frame: %u\n", world.sim_frame );
579
580 for( int i = 0; i < arrlen( world.io ); i ++ )
581 {
582 struct cell_terminal *term = &world.io[ i ];
583 int posx = term->id % world.w;
584 int posy = (term->id - posx)/world.w;
585 int is_input = world.data[ term->id ].state & FLAG_INPUT;
586
587 if( is_input )
588 {
589 if( world.sim_frame < arrlen( term->conditions ) )
590 {
591 struct fish *fish = &world.fishes[world.num_fishes++];
592 fish->pos[0] = posx;
593 fish->pos[1] = posy;
594 fish->alive = 1;
595 fish->payload = term->conditions[world.sim_frame];
596
597 int can_spawn = 0;
598
599 v2i dirs[] = {{1,0},{-1,0},{0,-1}};
600 for( int j = 0; j < vg_list_size(dirs); j ++ )
601 {
602 v2i target;
603 if( pcell( (v2i){ posx+dirs[j][0], posy+dirs[j][1] } )->state & FLAG_CANAL )
604 {
605 fish->dir[0] = dirs[j][0];
606 fish->dir[1] = dirs[j][1];
607 can_spawn = 1;
608 break;
609 }
610 }
611
612 if( !can_spawn )
613 world.num_fishes--;
614 }
615 }
616 }
617
618 for( int i = 0; i < world.num_fishes; i ++ )
619 {
620 struct fish *fish = &world.fishes[i];
621 struct cell *cell_current = pcell( fish->pos );
622
623 if( !fish->alive )
624 continue;
625
626 // Apply to output
627 if( cell_current->state & FLAG_OUTPUT )
628 {
629 for( int j = 0; j < arrlen( world.io ); j ++ )
630 {
631 struct cell_terminal *term = &world.io[j];
632
633 if( term->id == fish->pos[1]*world.w + fish->pos[0] )
634 {
635 term->recv[ term->recv_count ++ ] = fish->payload;
636 break;
637 }
638 }
639
640 fish->alive = 0;
641 continue;
642 }
643
644 if( !(cell_current->state & (FLAG_INPUT|FLAG_CANAL)) )
645 {
646 fish->alive = 0;
647 }
648 else
649 {
650 if( cell_current->state & FLAG_SPLIT )
651 {
652 // Flip flop L/R
653 fish->dir[0] = cell_current->state&FLAG_FLIP_FLOP?1:-1;
654 fish->dir[1] = 0;
655
656 cell_current->state ^= FLAG_FLIP_FLOP;
657 }
658 else if( cell_current->state & FLAG_MERGER )
659 {
660 // Can only move up
661 fish->dir[0] = 0;
662 fish->dir[1] = -1;
663 }
664 else
665 {
666 struct cell *cell_next = pcell( (v2i){ fish->pos[0]+fish->dir[0], fish->pos[1]+fish->dir[1] } );
667 if( !(cell_next->state & FLAG_CANAL) )
668 {
669 // Try other directions for valid, so down, left, right..
670 v2i dirs[] = {{1,0},{-1,0},{0,-1}};
671 vg_info( "Trying some other directions...\n" );
672
673 for( int j = 0; j < vg_list_size(dirs); j ++ )
674 {
675 if( (dirs[j][0] == -fish->dir[0]) && (dirs[j][1] == -fish->dir[1]) )
676 continue;
677
678 if( pcell( (v2i){ fish->pos[0]+dirs[j][0], fish->pos[1]+dirs[j][1] } )->state & FLAG_CANAL )
679 {
680 fish->dir[0] = dirs[j][0];
681 fish->dir[1] = dirs[j][1];
682 }
683 }
684 }
685 }
686
687 fish->pos[0] += fish->dir[0];
688 fish->pos[1] += fish->dir[1];
689 }
690 }
691
692 world.sim_frame ++;
693 }
694 }
695 }
696
697 void vg_render(void)
698 {
699 glViewport( 0,0, vg_window_x, vg_window_y );
700
701 glDisable( GL_DEPTH_TEST );
702 glClearColor( 0.8f, 0.8f, 0.8f, 1.0f );
703 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
704
705 use_mesh( &world.tile );
706 SHADER_USE( shader_tile_colour );
707 glUniformMatrix3fv( SHADER_UNIFORM( shader_tile_colour, "uPv" ), 1, GL_FALSE, (float *)vg_pv );
708
709 // Shadow layer
710 glUniform4f( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 0.5f, 0.5f, 0.5f, 1.0f );
711 for( int y = 0; y < world.h; y ++ )
712 for( int x = 0; x < world.w; x ++ )
713 {
714 struct cell *cell = pcell((v2i){x,y});
715
716 if( cell->state & FLAG_CANAL )
717 {
718 continue;
719 }
720
721 glUniform3f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), (float)x - 0.2f, (float)y - 0.15f, 1.0f );
722 draw_mesh( 0, 2 );
723 }
724
725 for( int y = 0; y < world.h; y ++ )
726 {
727 for( int x = 0; x < world.w; x ++ )
728 {
729 struct cell *cell = pcell((v2i){x,y});
730 int selected = world.selected == y*world.w + x;
731
732 if( cell->state & FLAG_CANAL && !selected )
733 continue;
734
735 glUniform3f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), (float)x, (float)y, 1.0f );
736
737 v4f colour;
738
739 if( cell->state & FLAG_WALL ) { v4_copy( (v4f){ 0.2f, 0.2f, 0.2f, 1.0f }, colour ); }
740 else if( cell->state & FLAG_CANAL ) { v4_copy( (v4f){ 0.6f, 0.6f, 0.6f, 1.0f }, colour ); }
741 else if( cell->state & FLAG_INPUT ) { v4_copy( (v4f){ 0.5f, 0.5f, 0.5f, 1.0f }, colour ); }
742 else if( cell->state & FLAG_OUTPUT ) { v4_copy( (v4f){ 0.2f, 0.7f, 0.3f, 1.0f }, colour ); }
743 else v4_copy( (v4f){ 0.9f, 0.9f, 0.9f, 1.0f }, colour );
744
745 //if( cell->water[world.frame&0x1] )
746 // v4_copy( (v4f){ 0.2f, 0.3f, 0.7f * (float)(cell->water[world.frame&0x1]) * (1.0f/16.0f), 1.0f }, colour );
747
748 if( selected )
749 v3_muls( colour, sinf( vg_time )*0.25f + 0.5f, colour );
750
751 //if( cell->state & (FLAG_SPLIT) )
752 // v4_copy( (v4f){ 0.75f, 0.75f, 0.02f, 1.0f }, colour );
753 //if( cell->state & (FLAG_MERGER) )
754 // v4_copy( (v4f){ 0.75f, 0.02f, 0.75f, 1.0f }, colour );
755
756 glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1, colour );
757
758 draw_mesh( 0, 2 );
759 }
760 }
761
762 use_mesh( &world.circle );
763
764 // Draw i/o arrays
765 for( int i = 0; i < arrlen( world.io ); i ++ )
766 {
767 struct cell_terminal *term = &world.io[ i ];
768 int posx = term->id % world.w;
769 int posy = (term->id - posx)/world.w;
770 int is_input = world.data[ term->id ].state & FLAG_INPUT;
771
772 int const filled_start = 0;
773 int const filled_count = 32;
774 int const empty_start = 32;
775 int const empty_count = 32*2;
776
777 v4f dot_colour = { 0.0f, 0.0f, 0.0f, 1.0f };
778
779 for( int j = 0; j < arrlen( term->conditions ); j ++ )
780 {
781 glUniform3f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), (float)posx + 0.2f + 0.2f * (float)j, (float)posy + 0.2f, 0.1f );
782
783 if( is_input )
784 {
785 colour_code_v3( term->conditions[j], dot_colour );
786 glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1, dot_colour );
787
788 // Draw filled if tick not passed, draw empty if empty
789 if( world.sim_frame > j )
790 draw_mesh( empty_start, empty_count );
791 else
792 draw_mesh( filled_start, filled_count );
793 }
794 else
795 {
796 if( term->recv_count > j )
797 {
798 colour_code_v3( term->recv[j], dot_colour );
799 v3_muls( dot_colour, 0.8f, dot_colour );
800 glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1, dot_colour );
801
802 draw_mesh( filled_start, filled_count );
803 }
804
805 colour_code_v3( term->conditions[j], dot_colour );
806 glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1, dot_colour );
807
808 draw_mesh( empty_start, empty_count );
809 }
810 }
811 }
812
813 // Draw 'fish'
814 if( world.simulating )
815 {
816 float scaled_time = (vg_time-world.sim_start)*2.0f;
817 float lerp = 1.0f-(scaled_time - (float)world.sim_frame);
818
819 v4f dot_colour = { 0.0f, 0.0f, 0.0f, 1.0f };
820
821 for( int i = 0; i < world.num_fishes; i ++ )
822 {
823 struct fish *fish = &world.fishes[i];
824
825 if( !fish->alive )
826 continue;
827
828 colour_code_v3( fish->payload, dot_colour );
829 glUniform4fv( SHADER_UNIFORM( shader_tile_colour, "uColour" ), 1, dot_colour );
830
831 glUniform3f( SHADER_UNIFORM( shader_tile_colour, "uOffset" ), (float)fish->pos[0] + 0.5f - (float)fish->dir[0]*lerp, (float)fish->pos[1] + 0.25f - (float)fish->dir[1]*lerp, 0.25f );
832 draw_mesh( 0, 32 );
833 }
834 }
835 }
836
837 void vg_ui(void){}