projects
/
fishladder.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
world text (old style) & optimisations
[fishladder.git]
/
fishladder.c
diff --git
a/fishladder.c
b/fishladder.c
index 11d65b0b5c1dae488b02073d1d414cdb0e9c22d6..aca4e406459415dd19ea0edba5a49d063a8807de 100644
(file)
--- a/
fishladder.c
+++ b/
fishladder.c
@@
-86,6
+86,8
@@
enum e_game_state
#define FLAG_FLIP_ROTATING 0x400
#define FLAG_TARGETED 0x800
#define FLAG_FLIP_ROTATING 0x400
#define FLAG_TARGETED 0x800
+#define FLAG_INPUT_NICE 0x1000
+
/*
0000 0 | 0001 1 | 0010 2 | 0011 3
| | | | |
/*
0000 0 | 0001 1 | 0010 2 | 0011 3
| | | | |
@@
-206,6
+208,7
@@
static struct world
float lvl_load_time;
float world_transition;
float lvl_load_time;
float world_transition;
+ ui_ctx world_text;
}
st;
}
st;
@@
-626,7
+629,7
@@
static void map_reclassify( v2i start, v2i end, int update_texbuffer )
if( cell->state & FLAG_WALL )
height = 0xFF-0x3F + hash21i( (v2i){x,y}, 0x3F );
if( cell->state & FLAG_WALL )
height = 0xFF-0x3F + hash21i( (v2i){x,y}, 0x3F );
- config = 0xF;
+ config =
cell->state & FLAG_INPUT_NICE? 0xB:
0xF;
}
pcell((v2i){x,y})->config = config;
}
pcell((v2i){x,y})->config = config;
@@
-757,6
+760,31
@@
static void gen_level_text( struct cmp_level *pLevel )
{
text_buffers.title_count = gen_text_buffer( pLevel->title, &font_Ubuntu, (v2f){ -5.0f, -0.6f }, 0.6f, text_buffers.title_start );
text_buffers.desc_count = gen_text_buffer( pLevel->description, &font_Ubuntu, (v2f){ -5.0, -0.9f }, 0.25f, text_buffers.desc_start );
{
text_buffers.title_count = gen_text_buffer( pLevel->title, &font_Ubuntu, (v2f){ -5.0f, -0.6f }, 0.6f, text_buffers.title_start );
text_buffers.desc_count = gen_text_buffer( pLevel->description, &font_Ubuntu, (v2f){ -5.0, -0.9f }, 0.25f, text_buffers.desc_start );
+
+ // Old style UI.
+ ui_px const unit_scale_px = 4*UI_GLYPH_SPACING_X; // 4 char per unit
+ ui_begin( &world.st.world_text, world.w*unit_scale_px, world.h*unit_scale_px );
+
+ for( int i = 0; i < vg_list_size( pLevel->strings ); i ++ )
+ {
+ struct world_string *wstr = &pLevel->strings[i];
+
+ if( wstr->str )
+ {
+ ui_px pos[2];
+
+ pos[0] = -UI_GLYPH_SPACING_X/2;
+
+ if( wstr->placement == k_placement_bottom )
+ pos[1] = 2*-unit_scale_px;
+ else
+ pos[1] = (world.h-1)*-unit_scale_px -6;
+
+ ui_text( &world.st.world_text, pos, wstr->str, 1, k_text_align_left );
+ }
+ }
+
+ ui_resolve( &world.st.world_text );
}
static int map_load( const char *str, const char *name )
}
static int map_load( const char *str, const char *name )
@@
-948,6
+976,7
@@
static int map_load( const char *str, const char *name )
reg_end ++;
}
reg_end ++;
}
+ else if( *c == '.' ) cell->state = FLAG_INPUT_NICE;
else if( *c == '#' ) cell->state = FLAG_WALL;
else if( ((u32)*c >= (u32)'A') && ((u32)*c <= (u32)'A'+0xf) )
{
else if( *c == '#' ) cell->state = FLAG_WALL;
else if( ((u32)*c >= (u32)'A') && ((u32)*c <= (u32)'A'+0xf) )
{
@@
-1182,6
+1211,7
@@
static void map_serialize( FILE *stream )
struct cell *cell = pcell( (v2i){ x, y } );
if( cell->state & FLAG_WALL ) fputc( '#', stream );
struct cell *cell = pcell( (v2i){ x, y } );
if( cell->state & FLAG_WALL ) fputc( '#', stream );
+ else if( cell->state & FLAG_INPUT_NICE ) fputc( '.', stream );
else if( cell->state & FLAG_INPUT ) fputc( '+', stream );
else if( cell->state & FLAG_OUTPUT ) fputc( '-', stream );
else if( cell->state & FLAG_EMITTER ) fputc( '*', stream );
else if( cell->state & FLAG_INPUT ) fputc( '+', stream );
else if( cell->state & FLAG_OUTPUT ) fputc( '-', stream );
else if( cell->state & FLAG_EMITTER ) fputc( '*', stream );
@@
-2380,19
+2410,10
@@
static void vg_update(void)
static void render_tile( v2i pos, struct cell *ptr, v4f const regular_colour, v4f const selected_colour )
{
int selected = world.selected == pos[1]*world.w + pos[0];
static void render_tile( v2i pos, struct cell *ptr, v4f const regular_colour, v4f const selected_colour )
{
int selected = world.selected == pos[1]*world.w + pos[0];
-
- int tile_offsets[][2] =
- {
- {2, 0}, {0, 3}, {0, 2}, {2, 2},
- {1, 0}, {2, 3}, {3, 2}, {1, 3},
- {3, 1}, {0, 1}, {1, 2}, {2, 1},
- {1, 1}, {3, 3}, {2, 1}, {2, 1}
- };
-
int uv[2];
int uv[2];
- uv[0] =
tile_offsets[ ptr->config ][0]
;
- uv[1] =
tile_offsets[ ptr->config ][1]
;
+ uv[0] =
ptr->config & 0x3
;
+ uv[1] =
ptr->config >> 2
;
glUniform4f( SHADER_UNIFORM( shader_tile_main, "uOffset" ),
(float)pos[0],
glUniform4f( SHADER_UNIFORM( shader_tile_main, "uOffset" ),
(float)pos[0],
@@
-2622,11
+2643,14
@@
void vg_render(void)
{
struct cell *cell = pcell((v2i){x,y});
{
struct cell *cell = pcell((v2i){x,y});
- if( cell->state & (FLAG_CANAL|FLAG_INPUT|FLAG_OUTPUT|FLAG_EMITTER) )
+ if( cell->state & (FLAG_CANAL|FLAG_INPUT|FLAG_OUTPUT|FLAG_EMITTER
|FLAG_INPUT_NICE
) )
{
struct render_cmd *cmd;
{
struct render_cmd *cmd;
- if( cell->config == k_cell_type_split || (cell->state & FLAG_EMITTER || cell->state & FLAG_IS_TRIGGER) )
+ if(
+ (cell->config == k_cell_type_split && (cell->state & FLAG_CANAL))
+ || (cell->state & (FLAG_EMITTER|FLAG_IS_TRIGGER))
+ )
cmd = &world.cmd_buf_tiles[ world.max_commands - (++ world.tile_special_count) ];
else
cmd = &world.cmd_buf_tiles[ world.tile_count ++ ];
cmd = &world.cmd_buf_tiles[ world.max_commands - (++ world.tile_special_count) ];
else
cmd = &world.cmd_buf_tiles[ world.tile_count ++ ];
@@
-2781,8
+2805,8
@@
void vg_render(void)
glUniform4f( SHADER_UNIFORM( shader_tile_main, "uOffset" ),
(float)cmd->pos[0],
(float)cmd->pos[1] + 0.125f,
glUniform4f( SHADER_UNIFORM( shader_tile_main, "uOffset" ),
(float)cmd->pos[0],
(float)cmd->pos[1] + 0.125f,
- cell->state & FLAG_TARGETED? 3.0f:
0
.0f,
-
0
.0f
+ cell->state & FLAG_TARGETED? 3.0f:
2
.0f,
+
3
.0f
);
draw_mesh( 0, 2 );
}
);
draw_mesh( 0, 2 );
}
@@
-3061,9
+3085,21
@@
void vg_render(void)
glUniform4f( SHADER_UNIFORM( shader_sdf, "uColour" ), 1.0f, 1.0f, 1.0f, 0.17f );
glDrawElements( GL_TRIANGLES, text_buffers.grid_count*6, GL_UNSIGNED_SHORT, (void*)( text_buffers.grid_start*6*sizeof(u16) ) );
glUniform4f( SHADER_UNIFORM( shader_sdf, "uColour" ), 1.0f, 1.0f, 1.0f, 0.17f );
glDrawElements( GL_TRIANGLES, text_buffers.grid_count*6, GL_UNSIGNED_SHORT, (void*)( text_buffers.grid_start*6*sizeof(u16) ) );
+ // Old style
+ m3x3f mvp_text;
+ m3x3_identity( mvp_text );
+ m3x3_scale( mvp_text, (v3f){
+ 1.0f/ ((float)UI_GLYPH_SPACING_X*4.0f),
+ 1.0f/ -((float)UI_GLYPH_SPACING_X*4.0f),
+ 1.0f
+ });
+
+ m3x3_mul( vg_pv, mvp_text, mvp_text );
+ ui_draw( &world.st.world_text, mvp_text );
+
// WIRES
// ========================================================================================================
// WIRES
// ========================================================================================================
-
//glDis
able(GL_BLEND);
+
glEn
able(GL_BLEND);
SHADER_USE( shader_wire );
glBindVertexArray( world.wire.vao );
SHADER_USE( shader_wire );
glBindVertexArray( world.wire.vao );
@@
-3787,6
+3823,11
@@
void vg_start(void)
resource_load_main();
resource_load_main();
+ // Init world text
+ {
+ ui_init_context( &world.st.world_text, 15000 );
+ }
+
// Create text buffers
{
// Work out the counts for each 'segment'
// Create text buffers
{
// Work out the counts for each 'segment'
@@
-3933,6
+3974,8
@@
void vg_free(void)
free_mesh( &world.shapes );
free_mesh( &world.shapes );
+ ui_context_free( &world.st.world_text );
+
map_free();
}
map_free();
}