summaryrefslogtreecommitdiff
path: root/src/game/assets.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/assets.cpp')
-rw-r--r--src/game/assets.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/game/assets.cpp b/src/game/assets.cpp
new file mode 100644
index 0000000..7d755c0
--- /dev/null
+++ b/src/game/assets.cpp
@@ -0,0 +1,78 @@
+#include "assets.h"
+
+#include "../game.h"
+#include "../render/gl_2d_font.h"
+
+void assets_init( GAME_DATA *game ) {
+ game->assets.test = gl_texture_create( game->gl, "assets/test.png" );
+ game->assets.fonts_init = 0;
+}
+
+void assets_create_fonts( struct GAME_DATA *game ) {
+ dlog( "creating fonts\n" );
+
+ game->gl->fonts.each( fn( GL_FONT** font ) {
+ gl_font_destroy( game->gl, *font );
+ });
+
+ game->gl->fonts.clear();
+ GAME_ASSETS* a = &game->assets;
+ a->font = gl_font_create( game->gl, "cour.ttf", 16 );
+ a->jpn12 = gl_font_create( game->gl, "jpn12.ttf", 12 );
+ a->jpn16 = gl_font_create( game->gl, "jpn16.ttf", 16 );
+}
+
+U8 assets_on_frame( struct GAME_DATA *game ) {
+ thread_mutex_lock( &font_mutex );
+ if( !game->assets.fonts_init ) {
+ assets_create_fonts( game );
+ game->assets.fonts_init = 1;
+ thread_mutex_unlock( &font_mutex );
+ return 0;
+ }
+
+ thread_mutex_unlock( &font_mutex );
+ return 1;
+}
+
+LIST<FILE_ENTRY> assets_get_files_by_ext_dir( const char** extensions, const char* dirname ) {
+ LIST<FILE_ENTRY> ret;
+ LIST<FILE_ENTRY> dir = dir_get_entries( dirname );
+
+ dir.each( fn( FILE_ENTRY* e ) {
+ char fullpath[256];
+ sprintf( fullpath, "%s/%s", dirname, e->name );
+ if( e->dir ) {
+ LIST<FILE_ENTRY> subdir = assets_get_files_by_ext_dir( extensions, fullpath );
+ subdir.each( fn( FILE_ENTRY* se ) { ret.push( *se ); } );
+ return;
+ }
+
+ U32 len = strlen( e->name );
+ for( U32 i = 0; !!extensions[i]; ++i ) {
+ const char* ext = extensions[i];
+ U32 extlen = strlen( ext );
+
+ if( extlen < len && e->name[len - extlen - 1] == '.' ) {
+ if( !strcmp( e->name + len - extlen, ext ) ) {
+ FILE_ENTRY ne{ .dir = 0 };
+ strcpy( ne.name, fullpath );
+ ret.push( ne );
+ }
+ }
+ }
+ } );
+
+ return ret;
+}
+
+LIST<FILE_ENTRY> assets_get_files_by_ext( const char** extensions ) {
+ return assets_get_files_by_ext_dir( extensions, "../assets" );
+}
+
+const char* assets_abspath( const char* filename ) {
+ while( !strncmp( filename, "../assets/", 10 ) )
+ filename += 10;
+
+ return filename;
+}