Fixed loading resources by name
Also added a basic path function for animations Added a TAISEI_NOSCAN environment variable, set to 1 to disable autoloading resources on startup. They will then be loaded as they are needed, which may cause the game to stutter when that happens.
This commit is contained in:
parent
2057a49d47
commit
ffd623f1a5
6 changed files with 30 additions and 8 deletions
|
@ -102,7 +102,7 @@ void audio_backend_set_bgm_volume(float gain) {
|
|||
|
||||
char* audio_mixer_sound_path(const char *name) {
|
||||
for(const char **ext = mixer_audio_exts; *ext; ++ext) {
|
||||
char *p = strjoin(get_prefix(), SFX_PATH_PREFIX, name, *ext, NULL);
|
||||
char *p = strjoin(SFX_PATH_PREFIX, name, *ext, NULL);
|
||||
struct stat statbuf;
|
||||
|
||||
if(!stat(p, &statbuf)) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
|
||||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include "animation.h"
|
||||
#include "texture.h"
|
||||
#include "global.h"
|
||||
|
@ -14,9 +15,27 @@
|
|||
#include "taisei_err.h"
|
||||
|
||||
char* animation_path(const char *name) {
|
||||
// stub
|
||||
// we could scan the gfx/ directory and find the first matching animation here
|
||||
// ...or we could describe animations with simple text files instead of encoding them in texture file names
|
||||
DIR *dir = opendir("gfx/");
|
||||
if(dir == NULL)
|
||||
return NULL;
|
||||
|
||||
struct dirent *dp;
|
||||
|
||||
while((dp = readdir(dir)) != NULL) {
|
||||
char *filepath = strjoin("gfx/", dp->d_name, NULL);
|
||||
char *tmpname = NULL;
|
||||
|
||||
if(check_animation_path(filepath)) {
|
||||
if(!strcmp(tmpname = animation_name(filepath), name)) {
|
||||
free(tmpname);
|
||||
return filepath;
|
||||
}
|
||||
}
|
||||
|
||||
free(filepath);
|
||||
free(tmpname);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ static void parse_obj(const char *filename, ObjFileData *data);
|
|||
static void free_obj(ObjFileData *data);
|
||||
|
||||
char* model_path(const char *name) {
|
||||
return strjoin(get_prefix(), MDL_PATH_PREFIX, name, MDL_EXTENSION, NULL);
|
||||
return strjoin(MDL_PATH_PREFIX, name, MDL_EXTENSION, NULL);
|
||||
}
|
||||
|
||||
bool check_model_path(const char *path) {
|
||||
|
|
|
@ -277,7 +277,10 @@ static void scan_resources(void) {
|
|||
}
|
||||
|
||||
void load_resources(void) {
|
||||
scan_resources();
|
||||
if(!getenvint("TAISEI_NOSCAN")) {
|
||||
scan_resources();
|
||||
}
|
||||
|
||||
init_fonts();
|
||||
|
||||
if(glext.draw_instanced) {
|
||||
|
|
|
@ -30,7 +30,7 @@ static char snippet_header_gl31[] =
|
|||
;
|
||||
|
||||
char* shader_path(const char *name) {
|
||||
return strjoin(get_prefix(), SHA_PATH_PREFIX, name, SHA_EXTENSION, NULL);
|
||||
return strjoin(SHA_PATH_PREFIX, name, SHA_EXTENSION, NULL);
|
||||
}
|
||||
|
||||
bool check_shader_path(const char *path) {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
static SDL_Surface* load_png(const char *filename);
|
||||
|
||||
char* texture_path(const char *name) {
|
||||
return strjoin(get_prefix(), TEX_PATH_PREFIX, name, TEX_EXTENSION, NULL);
|
||||
return strjoin(TEX_PATH_PREFIX, name, TEX_EXTENSION, NULL);
|
||||
}
|
||||
|
||||
bool check_texture_path(const char *path) {
|
||||
|
|
Loading…
Reference in a new issue