summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornavewindre <boneyaard@gmail.com>2025-11-27 17:19:02 +0100
committernavewindre <boneyaard@gmail.com>2025-11-27 17:21:48 +0100
commite3de3ba5162f7ddd5005911124d4333e140fd984 (patch)
treeefb2d3851940ba1b70f0105611cddb17344e7e32
parent5c8bbc3bc618068af1f7d6f2829c4346570c2ab9 (diff)
bunch o stuff
-rw-r--r--src/editor/editor.h6
-rw-r--r--src/editor/gui.cpp39
-rw-r--r--src/editor/view2d.cpp144
-rw-r--r--src/editor/view3d.cpp13
-rw-r--r--src/game/assets.cpp5
-rw-r--r--src/game/player.cpp6
-rw-r--r--src/game/world/bsp.cpp89
-rw-r--r--src/game/world/bsp.h5
-rw-r--r--src/gui/base.h1
-rw-r--r--src/render/gl.cpp17
-rw-r--r--src/render/gl_2d.cpp16
-rw-r--r--src/util/allocator.h18
-rw-r--r--src/util/input.cpp10
-rw-r--r--src/util/input.h8
14 files changed, 300 insertions, 77 deletions
diff --git a/src/editor/editor.h b/src/editor/editor.h
index 0bf2ab4..a4b1f1a 100644
--- a/src/editor/editor.h
+++ b/src/editor/editor.h
@@ -70,9 +70,13 @@ extern void editor_load_map_cb( void* );
extern void editor_new_map_cb( void* );
extern void editor_create_map_view( GAME_EDITOR* e );
+extern void editor_update_properties_column( GAME_EDITOR* e );
struct GUI_EDITORWINDOW : GUI_WINDOW {};
-struct GUI_EDITOR_3DVIEW : GUI_VIEW {};
+struct GUI_EDITOR_3DVIEW : GUI_VIEW {
+ U8 heldoutbounds;
+};
+
struct GUI_EDITOR_2DVIEW : GUI_VIEW {
F32 scale;
F32 posx, posy;
diff --git a/src/editor/gui.cpp b/src/editor/gui.cpp
index 71ce113..94967cc 100644
--- a/src/editor/gui.cpp
+++ b/src/editor/gui.cpp
@@ -121,48 +121,9 @@ void editor_create_tools_row( GAME_EDITOR* e ) {
editor_update_active_tool_label( e );
}
-void editor_update_view_settings( GAME_EDITOR* e ) {
- GAME_EDITOR::EDITOR_GUI* egui = &e->gui;
-
- sprintf( egui->gridlabel->name, "grid size: %1.2f", e->grid );
-}
-
-void editor_grid_increment_cb( void* ) {
- if( editor->grid < 16.f ) editor->grid *= 2.f;
- editor_update_view_settings( editor );
-
- if( editor->propgrid )
- editor_update_properties_column( editor );
-}
-
-void editor_grid_decrement_cb( void* ) {
- if( editor->grid > 0.25f ) editor->grid *= 0.5f;
- editor_update_view_settings( editor );
-
- if( editor->propgrid )
- editor_update_properties_column( editor );
-}
-
-void editor_grid_propgrid_cb( void* ) {
- editor_update_properties_column( editor );
-}
-
void editor_create_view_settings_row( GAME_EDITOR* e ) {
I32 x = 320, y = 426;
- gui_label( x, y, "view settings:" ); x += 95;
- editor->gui.gridlabel = gui_label( x, y, "grid size: %1.2f", e->grid );
- x += 95;
- gui_button( x, y, 20, 20, "+", editor_grid_increment_cb );
- gui_button( x + 25, y, 20, 20, "-", editor_grid_decrement_cb );
- x += 55;
- GUI_CHECKBOX* check = gui_checkbox( x, y, "properties grid", &e->propgrid );
- check->cb = editor_grid_propgrid_cb;
- x += 120;
- gui_checkbox( x, y, "wireframe", &e->wireframe );
-
- x = 320;
- y = 440;
gui_button( x, y, 100, 20, "compile bsp", pfn( void* b ) {
if( editor->map->bsp )
bsp_free( editor->map->bsp );
diff --git a/src/editor/view2d.cpp b/src/editor/view2d.cpp
index 35fd208..1445cfc 100644
--- a/src/editor/view2d.cpp
+++ b/src/editor/view2d.cpp
@@ -1,12 +1,13 @@
#include <math.h>
#include "editor.h"
#include "../render/gl_2d.h"
-
#include "../game/objlist.h"
+#include "../game/world/bsp.h"
const I32 EDITORVIEW_TITLE_OFFSET = 15;
const I32 EDITORVIEW_GUTTERS_OFFSETX = 22;
const I32 EDITORVIEW_GUTTERS_OFFSETY = 16;
+const I32 EDITORVIEW_TOOLBAR_OFFSET = 20;
F32 gui_editor_2dview_calc_scale( GUI_EDITOR_2DVIEW* view ) {
WORLD_MAP* m = editor->map;
@@ -337,13 +338,23 @@ void gui_editor_2dview_draw_fn( void* ptr ) {
U32 offx = EDITORVIEW_GUTTERS_OFFSETX;
U32 offy = EDITORVIEW_GUTTERS_OFFSETY;
- gui_draw_push_clip( x + offx, y + offy, w - offx, h - offy );
+ gui_draw_push_clip( x + offx, y + offy, w - offx, h - offy - EDITORVIEW_TOOLBAR_OFFSET );
gui_editor_2dview_draw_polygons( view, x + offx, y + offy );
gui_editor_2dview_draw_walls( view, x + offx, y + offy );
gui_editor_2dview_draw_sprites( view, x + offx, y + offy );
gui_editor_2dview_draw_player( view, x + offx, y + offy );
gui_editor_2dview_draw_origin( view, x + offx, y + offy );
gui_draw_pop_clip();
+
+ gui_draw_push_clip( x, y + 16, view->w, view->h );
+ view->children.each( fn( GUI_BASE** childptr ) {
+ GUI_BASE* child = *childptr;
+ if( !child->enabled ) return;
+
+ if( child->draw_fn ) child->draw_fn( child );
+ else dlog( "gui_view_draw_fn(): child %p no draw_fn\n", child );
+ } );
+ gui_draw_pop_clip();
}
U8 gui_editor_2dview_input_drag( GUI_EDITOR_2DVIEW* view, U8 mouse ) {
@@ -876,11 +887,91 @@ void gui_editor_2dview_input_tool_draw( GUI_EDITOR_2DVIEW* view ) {
}
}
+void gui_editor_view2d_delete_obj( GUI_EDITOR_2DVIEW* view ) {
+ void* it;
+ U8 type;
+
+ if( view->curdrag && view->dragtype ) {
+ it = view->curdrag;
+ type = view->dragtype;
+ view->curdrag = 0;
+ view->dragtype = EDITOR_SELECT_NONE;
+ } else if( editor->gui.props->curselect ) {
+ it = editor->gui.props->curselect;
+ type = editor->gui.props->seltype;
+ view->curselect = 0;
+ view->seltype = EDITOR_SELECT_NONE;
+ }
+ else return;
+
+ U8 cleared = 1;
+ switch( type ) {
+ case EDITOR_SELECT_POLY: {
+ I32 idx = editor->map->polygons.idx_of( (MAP_POLYGON*)it );
+ if( idx != -1 )
+ editor->map->polygons.erase( idx );
+ } break;
+ case EDITOR_SELECT_WALL: {
+ I32 idx = editor->map->walls.idx_of( (MAP_WALL*)it );
+ if( idx != -1 )
+ editor->map->walls.erase( idx );
+ }; break;
+ case EDITOR_SELECT_SPRITE: {
+ I32 idx = editor->map->sprites.idx_of( (MAP_SPRITE*)it );
+ if( idx != -1 )
+ editor->map->sprites.erase( idx );
+ }; break;
+ case EDITOR_SELECT_PVERTEX: {
+ I32 vidx = -1, idx = editor->map->polygons.idx_where( fn( MAP_POLYGON* p ) {
+ vidx = p->vertices.idx_where( fn( MAP_VERTEX* v ) {
+ return v == it;
+ } );
+ return vidx != -1;
+ } );
+
+ if( idx != -1 && vidx != -1 ) {
+ MAP_POLYGON* p = &editor->map->polygons[idx];
+ if( p->vertices.size <= 3 ) {
+ editor->map->polygons.erase( idx );
+ break;
+ }
+ editor->map->polygons[idx].vertices.erase( vidx );
+ }
+ }; break;
+ case EDITOR_SELECT_WVERTEX: {
+ I32 idx = editor->map->walls.idx_where( fn( MAP_WALL* w ) {
+ return &w->end == it || &w->start == it;
+ } );
+
+ if( idx != -1 )
+ editor->map->walls.erase( idx );
+ }; break;
+ default:
+ cleared = 0; break;
+ }
+
+ if( cleared && it == editor->gui.props->curselect ) {
+ gui_editor_propview_select( editor->gui.props, 0, 0 );
+ }
+}
+
+void gui_editor_2dview_key_input( GUI_EDITOR_2DVIEW* view ) {
+ static U8 del_held = 0;
+ if( kb_down( SDLK_DELETE ) && !input.mouselock ) {
+ if( !del_held )
+ gui_editor_view2d_delete_obj( view );
+
+ del_held = 1;
+ } else del_held = 0;
+}
+
void gui_editor_2dview_input_fn( void* ptr ) {
GUI_EDITOR_2DVIEW* view = (GUI_EDITOR_2DVIEW*)ptr;
if( !editor->map )
return;
+ gui_editor_2dview_key_input( view );
+
I32 x = gui_relx( view );
I32 y = gui_rely( view ) + EDITORVIEW_TITLE_OFFSET;
I32 w = view->w;
@@ -902,6 +993,10 @@ void gui_editor_2dview_input_fn( void* ptr ) {
if( view->heldoutbounds )
return;
+ gui_base_input_fn( view );
+ if( my >= y + h - 18 )
+ return;
+
switch( editor->tool ) {
case EDITOR_TOOL_SELECT: return gui_editor_2dview_input_tool_select( view );
case EDITOR_TOOL_WALL:
@@ -913,6 +1008,47 @@ void gui_editor_2dview_input_fn( void* ptr ) {
}
}
+void update_view_settings( GAME_EDITOR* e ) {
+ GAME_EDITOR::EDITOR_GUI* egui = &e->gui;
+
+ sprintf( egui->gridlabel->name, "grid: %1.2f", e->grid );
+}
+
+void grid_increment_cb( void* ) {
+ if( editor->grid < 16.f ) editor->grid *= 2.f;
+ update_view_settings( editor );
+
+ if( editor->propgrid )
+ editor_update_properties_column( editor );
+}
+
+void grid_decrement_cb( void* ) {
+ if( editor->grid > 0.25f ) editor->grid *= 0.5f;
+ update_view_settings( editor );
+
+ if( editor->propgrid )
+ editor_update_properties_column( editor );
+}
+
+void grid_propgrid_cb( void* ) {
+ editor_update_properties_column( editor );
+}
+
+void gui_editor_2dview_create_toolbar( GUI_EDITOR_2DVIEW* view ) {
+ GAME_EDITOR* e = editor;
+ I32 x = 150, y = view->h - 4;
+
+ editor->gui.gridlabel = gui_label( x, y + 1, "grid: %1.2f", e->grid );
+ x += 70;
+ gui_button( x, y, 18, 18, "+", grid_increment_cb );
+ gui_button( x + 23, y, 18, 18, "-", grid_decrement_cb );
+ x += 50;
+ GUI_CHECKBOX* check = gui_checkbox( x, y, "properties grid", &e->propgrid );
+ check->cb = grid_propgrid_cb;
+ x += 120;
+ gui_checkbox( x, y, "wireframe", &e->wireframe );
+}
+
GUI_EDITOR_2DVIEW* gui_editor_2dview( I32 x, I32 y, I32 w, I32 h ) {
GUI_EDITOR_2DVIEW* view = new GUI_EDITOR_2DVIEW;
view->x = x;
@@ -934,5 +1070,9 @@ GUI_EDITOR_2DVIEW* gui_editor_2dview( I32 x, I32 y, I32 w, I32 h ) {
parent->children.push( view );
view->parent = parent;
+ gui_set_view( view );
+ gui_editor_2dview_create_toolbar( view );
+ gui_set_view( (GUI_VIEW*)parent );
+
return view;
}
diff --git a/src/editor/view3d.cpp b/src/editor/view3d.cpp
index 61bcc3e..64cfe85 100644
--- a/src/editor/view3d.cpp
+++ b/src/editor/view3d.cpp
@@ -32,7 +32,7 @@ void gui_editor_3dview_draw_showpos( GUI_EDITOR_3DVIEW* view ) {
objl->pl->rot.x
);
- if( input.mouse_captured ) {
+ if( input.mouselock ) {
gui_draw_str(
x + 2, y + 2,
ALIGN_L,
@@ -65,7 +65,7 @@ void gui_editor_3dview_draw_fn( void* ptr ) {
bsp_draw( editor->map->bsp, editor->game, wnd, winsize );
else
world_draw( editor->game, objl->world, wnd, winsize );
-
+
gui_editor_3dview_draw_showpos( view );
}
@@ -75,14 +75,17 @@ void gui_editor_3dview_input_fn( void* ptr ) {
if( !objl->pl )
return;
- if( input.mouse.left && !input.mouse_captured ) {
+ if( input.mouse.left ) {
I32 view_x = gui_relx( view );
I32 view_y = gui_rely( view ) + EDITORVIEW_TITLE_OFFSET;
if( input.mouse.pos.x >= view_x && input.mouse.pos.x < view_x + view->w &&
input.mouse.pos.y >= view_y && input.mouse.pos.y < view_y + view->h ) {
- input_capture_mouse( true );
+ if( !input.mouselock && !view->heldoutbounds )
+ input_capture_mouse( true );
+ } else {
+ view->heldoutbounds = 1;
}
- }
+ } else view->heldoutbounds = 0;
game_on_tick( editor->game );
}
diff --git a/src/game/assets.cpp b/src/game/assets.cpp
index 7d755c0..62663a9 100644
--- a/src/game/assets.cpp
+++ b/src/game/assets.cpp
@@ -3,8 +3,11 @@
#include "../game.h"
#include "../render/gl_2d_font.h"
+#include "../util/stb_image.h"
+#include "../util/anim.h"
+
void assets_init( GAME_DATA *game ) {
- game->assets.test = gl_texture_create( game->gl, "assets/test.png" );
+ game->assets.test = gl_texture_from_file( game->gl, "uvtest.png" );
game->assets.fonts_init = 0;
}
diff --git a/src/game/player.cpp b/src/game/player.cpp
index c4b9c9a..51d1cf8 100644
--- a/src/game/player.cpp
+++ b/src/game/player.cpp
@@ -38,9 +38,9 @@ void capture_mouse( PLAYER* p ) {
input_capture_mouse( false );
}
- if( input.mouse_captured ) {
- *yaw += input.mouse.pos_delta.x * input.mouse_sensitivity;
- *pitch -= input.mouse.pos_delta.y * input.mouse_sensitivity;
+ if( input.mouselock ) {
+ *yaw += input.mouse.pos_delta.x * input.msens;
+ *pitch -= input.mouse.pos_delta.y * input.msens;
if( *pitch > 89.f ) *pitch = 89.f;
if( *pitch < -89.f ) *pitch = -89.f;
diff --git a/src/game/world/bsp.cpp b/src/game/world/bsp.cpp
index 9aa94d7..a95a693 100644
--- a/src/game/world/bsp.cpp
+++ b/src/game/world/bsp.cpp
@@ -637,7 +637,89 @@ U8 pvs_get( BSP_BITSET* pvs, U32 count, U32 cluster, U32 seen ) {
U32 w = seen / 32, b = seen % 32;
if( base + w >= pvs->size ) return 0;
- return ( pvs->data[base + w] >> b) & 1u;
+ return (pvs->data[base + w] >> b) & 1u;
+}
+
+void bsp_build_pvs( BSP* bsp ) {
+ U32 nclusters = bsp->leaves.size;
+ bsp->pvs_bits.clear();
+ bsp->clusters.clear();
+ bsp->clusters.reserve( nclusters );
+
+ LIST<LIST<I32>> leaf_portals;
+ leaf_portals.resize( nclusters );
+
+ for( U32 i = 0; i < bsp->portals.size; ++i ) {
+ BSP_PORTAL* p = &bsp->portals.data[i];
+ I32 lf = bsp_leaf_index( p->front );
+ I32 rf = bsp_leaf_index( p->back );
+
+ leaf_portals.data[lf].push( i );
+ leaf_portals.data[rf].push( i );
+ }
+
+ for( U32 i = 0; i < nclusters; ++i ) {
+ BSP_CLUSTER* c = &bsp->clusters.data[i];
+ c->first = 0;
+ c->count = 0;
+ c->pvs_off = 0;
+ }
+
+ for( U32 from = 0; from < nclusters; ++from ) {
+ LIST<I32>* plist = &leaf_portals.data[from];
+ pvs_set( &bsp->pvs_bits, nclusters, from, from );
+
+ LIST<BSP_PORTAL_QUEUE> queue;
+ for( U32 i = 0; i < plist->size; ++i ) {
+ I32 pid = plist->data[i];
+ BSP_PORTAL* p = &bsp->portals.data[pid];
+
+ BSP_PORTAL_QUEUE it{
+ .front = (I32)from,
+ .frustum = p->w
+ };
+
+ queue.push( it ) ;
+ }
+
+ while( queue.size ) {
+ BSP_PORTAL_QUEUE it = queue.pop();
+ LIST<I32>* plist = &leaf_portals.data[it.front];
+
+ for( U32 i = 0; plist->size; ++i ) {
+ BSP_PORTAL* p = &bsp->portals.data[plist->data[i]];
+ I32 lf = bsp_leaf_index( p->front );
+ I32 lb = bsp_leaf_index( p->back );
+
+ I32 neighbor = (lf == it.front) ? lb : (lb == it.front) ? lf : -1;
+ if( neighbor < 0 )
+ continue;
+
+ BSP_WINDING next_w;
+ if( !bsp_winding_intersect_plane( &p->plane, &it.frustum, &p->w, &next_w ) )
+ continue;
+
+ if( !pvs_get( &bsp->pvs_bits, nclusters, from, (U32)neighbor ) ) {
+ pvs_set( &bsp->pvs_bits, nclusters, from, (U32)neighbor );
+
+ LIST<I32>* nbr_plist = &leaf_portals.data[neighbor];
+ for( U32 i2 = 0; i2 < nbr_plist->size; ++i2 ) {
+ BSP_PORTAL* nbr_p = &bsp->portals.data[nbr_plist->data[i2]];
+ if( nbr_p == p )
+ continue;
+
+ BSP_WINDING clipped = next_w;
+ if( bsp_winding_intersect_plane( &nbr_p->plane, &clipped, &nbr_p->w, &clipped ) ) {
+ BSP_PORTAL_QUEUE n{};
+ n.front = neighbor;
+ n.frustum = clipped;
+ queue.push( n );
+ }
+ }
+ }
+ }
+ }
+ }
}
BSP* bsp_build_map( WORLD_MAP* m ) {
@@ -647,12 +729,13 @@ BSP* bsp_build_map( WORLD_MAP* m ) {
LIST<BSP_PLANE> planes = bsp_map_get_planes( m );
bsp->root = bsp_build_nodes( bsp, planes, faces, 0 );
- U32 vertc = 0;
- m->polygons.each( fn( MAP_POLYGON* p ) { vertc += p->vertices.size; } );
for( U32 i = 0; i < bsp->faces.size; ++i ) {
bsp->faces.data[i].id = i;
}
bsp_gen_render_vertices( bsp );
+
+ bsp_build_portals( bsp );
+ bsp_build_pvs( bsp );
return bsp;
}
diff --git a/src/game/world/bsp.h b/src/game/world/bsp.h
index 439fce1..457bcb9 100644
--- a/src/game/world/bsp.h
+++ b/src/game/world/bsp.h
@@ -71,6 +71,11 @@ struct BSP_PORTAL_NODE {
BSP_WINDING w;
};
+struct BSP_PORTAL_QUEUE {
+ I32 front;
+ BSP_WINDING frustum;
+};
+
struct BSP_BITSET : public LIST<U32> {};
struct BSP {
diff --git a/src/gui/base.h b/src/gui/base.h
index 96e0fa5..7b95d34 100644
--- a/src/gui/base.h
+++ b/src/gui/base.h
@@ -115,6 +115,7 @@ typedef void( *GUI_DRAW_FN )( void* el );
typedef void( *GUI_INPUT_FN )( void* el );
extern void gui_base_input_fn( void* );
+extern void gui_view_draw_fn( void* );
struct GUI_BASE {
I32 x{}, y{};
diff --git a/src/render/gl.cpp b/src/render/gl.cpp
index 382d81e..e44a165 100644
--- a/src/render/gl.cpp
+++ b/src/render/gl.cpp
@@ -276,7 +276,7 @@ GL_TEX2D* gl_texture_from_file( GL_DATA* gl, const char* name ) {
return tex;
}
-GL_TEX2D* gl_texture_from_bitmap( GL_DATA* gl, const char* name, U8* bitmap, U32 width, U32 height ) {
+GL_TEX2D* gl_texture_from_bitmap( GL_DATA* gl, const char* name, U8* bitmap, U32 w, U32 h ) {
GL_TEX2D* tex = gl_texture_create( gl, name );
glBindTexture( GL_TEXTURE_2D, tex->id );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
@@ -284,18 +284,13 @@ GL_TEX2D* gl_texture_from_bitmap( GL_DATA* gl, const char* name, U8* bitmap, U32
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- tex->width = width;
- tex->height = height;
-
- glTexImage2D(
- GL_TEXTURE_2D,
- 0, GL_RGBA,
- (I32)width, (I32)height, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, bitmap
- );
-
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, bitmap );
+ glGenerateMipmap( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, 0 );
+ tex->width = w;
+ tex->height = h;
+
return tex;
}
diff --git a/src/render/gl_2d.cpp b/src/render/gl_2d.cpp
index 1803eb5..78af1da 100644
--- a/src/render/gl_2d.cpp
+++ b/src/render/gl_2d.cpp
@@ -104,25 +104,33 @@ void gl_2d_textured_frect( GL_SHADER_PROGRAM* gl2d, VEC2 origin, VEC2 dim, GL_TE
glBindBuffer( GL_ARRAY_BUFFER, gl2d->gl->vbuffer );
glBufferData( GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_DYNAMIC_DRAW );
+
I32 position = glGetAttribLocation( gl2d->id, "in_pos" );
+ I32 color = glGetAttribLocation( gl2d->id, "in_col" );
+ I32 texcoord = glGetAttribLocation( gl2d->id, "in_texcoord" );
+ I32 sampler = glGetAttribLocation( gl2d->id, "in_sampler" );
+
glEnableVertexAttribArray( position );
glVertexAttribPointer( position, 2, GL_FLOAT, 0, sizeof(VERTEX), 0 );
- I32 color = glGetAttribLocation( gl2d->id, "in_col" );
+
glEnableVertexAttribArray( color );
glVertexAttribPointer( color, 4, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->clr );
- I32 texcoord = glGetAttribLocation( gl2d->id, "in_texcoord" );
+
glEnableVertexAttribArray( texcoord );
glVertexAttribPointer( texcoord, 2, GL_FLOAT, 0, sizeof(VERTEX), &( (VERTEX*)nullptr)->uv );
- I32 sampler = glGetAttribLocation( gl2d->id, "in_sampler" );
+
glEnableVertexAttribArray( sampler );
glVertexAttribPointer( sampler, 1, GL_UNSIGNED_BYTE, 1, sizeof(VERTEX), &( (VERTEX*)nullptr)->sampler );
+ glActiveTexture( GL_TEXTURE0 );
+ glBindTexture( GL_TEXTURE_2D, texture->id );
+
glBindBuffer( GL_ARRAY_BUFFER, 0 );
glActiveTexture( GL_TEXTURE0 );
glBindTexture( GL_TEXTURE_2D, texture->id );
- glUniform1f( glGetUniformLocation( gl2d->id, "in_time" ), u_time() );
+ // glUniform1f( glGetUniformLocation( gl2d->id, "in_time" ), u_time() );
glDrawElements( GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, order );
glBindTexture( GL_TEXTURE_2D, 0 );
diff --git a/src/util/allocator.h b/src/util/allocator.h
index 7927b9c..27b21c0 100644
--- a/src/util/allocator.h
+++ b/src/util/allocator.h
@@ -165,8 +165,12 @@ struct LIST {
if( size > capacity )
reserve( size * 2 );
- if( size < capacity ) {
- for( U32 i = size; i < capacity; ++i )
+ if( size < capacity / 4 )
+ shrink();
+
+ if( this->size < size ) {
+ memset( &data[this->size], 0, sizeof(T) * (size - this->size) );
+ for( U32 i = this->size; i < size; ++i )
data[i] = T();
}
@@ -262,6 +266,16 @@ struct LIST {
return -1;
}
+ I32 idx_of( const T* what ) {
+ for( U32 i = 0; i < size; ++i ) {
+ if( &data[i] == what ) {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
I32 idx_where( ON_SEARCH_FN what ) {
for( U32 i = 0; i < size; ++i ) {
if( what( &data[i] ) ) {
diff --git a/src/util/input.cpp b/src/util/input.cpp
index 225b696..284ebfe 100644
--- a/src/util/input.cpp
+++ b/src/util/input.cpp
@@ -27,8 +27,8 @@ void input_on_event( SDL_Event* e ) {
case SDL_MOUSEMOTION: {
input.mouse.pos.x = (F32)e->motion.x;
input.mouse.pos.y = (F32)e->motion.y;
- input.mouse.pos_delta.x += (F32)e->motion.xrel;
- input.mouse.pos_delta.y += (F32)e->motion.yrel;
+ input.mouse.pos_delta.x += (F32)e->motion.xrel * input.mpitch;
+ input.mouse.pos_delta.y += (F32)e->motion.yrel * input.myaw;
} break;
case SDL_KEYDOWN: {
input.keys[e->key.keysym.sym & 0xff] = 1;
@@ -79,8 +79,12 @@ void input_frame_end() {
input.mouse.wheel = 0;
}
+U8 input_is_key_down( U32 key ) {
+ return input.keys[key];
+}
+
void input_capture_mouse( bool capture ) {
input_reset_mouse_accumulator();
- input.mouse_captured = capture;
+ input.mouselock = capture;
SDL_SetRelativeMouseMode( capture ? SDL_TRUE : SDL_FALSE );
}
diff --git a/src/util/input.h b/src/util/input.h
index ec901ab..86d715c 100644
--- a/src/util/input.h
+++ b/src/util/input.h
@@ -38,8 +38,10 @@ using ON_INPUT_FN = std::function<void( SDL_Event* )>;
struct INPUT_DATA {
MOUSE_DATA mouse;
U8 keys[0xff];
- bool mouse_captured;
- F32 mouse_sensitivity = .3f;
+ bool mouselock;
+ F32 msens = .3f;
+ F32 myaw = 1.f;
+ F32 mpitch = 1.f;
INPUT_KEYBINDS binds;
LIST<ON_INPUT_FN> on_input;
@@ -51,7 +53,7 @@ extern INPUT_DATA input;
extern void input_frame_end();
extern void input_on_event( SDL_Event* e );
extern void input_on_mouse( I32 type, I32 x, I32 y );
-extern void input_is_key_down( U32 key );
+extern U8 input_is_key_down( U32 key );
extern void input_capture_mouse( bool capture );
extern void input_reset_mouse_accumulator();