utils: add FindDataFilePath, which just returns NULL on failure

This commit is contained in:
Sebastian Krzyszkowiak 2019-03-29 20:53:45 +01:00
parent 993e9884e6
commit db0d8da708
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 18 additions and 6 deletions

View file

@ -23,6 +23,8 @@
// TODO: split to separate files
ALLEGRO_DEBUG_CHANNEL("libsuperderpy")
SYMBOL_EXPORT void DrawVerticalGradientRect(float x, float y, float w, float h, ALLEGRO_COLOR top, ALLEGRO_COLOR bottom) {
ALLEGRO_VERTEX v[] = {
{.x = x, .y = y, .z = 0, .color = top},
@ -369,7 +371,7 @@ static char* TestDataFilePath(struct Game* game, const char* filename) {
return NULL;
}
SYMBOL_EXPORT char* GetDataFilePath(struct Game* game, const char* filename) {
SYMBOL_EXPORT const char* FindDataFilePath(struct Game* game, const char* filename) {
char* result = 0;
#ifdef ALLEGRO_ANDROID
@ -477,6 +479,16 @@ SYMBOL_EXPORT char* GetDataFilePath(struct Game* game, const char* filename) {
return AddGarbage(game, result);
}
return NULL;
}
SYMBOL_EXPORT const char* GetDataFilePath(struct Game* game, const char* filename) {
const char* result = FindDataFilePath(game, filename);
if (result) {
return result;
}
FatalError(game, true, "Could not find data file: %s!", filename);
#ifdef __EMSCRIPTEN__
emscripten_exit_with_live_runtime();
@ -484,8 +496,6 @@ SYMBOL_EXPORT char* GetDataFilePath(struct Game* game, const char* filename) {
exit(1);
}
ALLEGRO_DEBUG_CHANNEL("libsuperderpy")
SYMBOL_EXPORT void PrintConsoleWithContext(struct Game* game, int line, const char* file, const char* func, char* format, ...) {
al_lock_mutex(game->_priv.mutex);
va_list vl;
@ -640,7 +650,7 @@ SYMBOL_EXPORT char* PunchNumber(struct Game* game, char* text, char ch, int numb
*tmp = '0' + (int)floorf(number / (float)num) % 10;
num *= 10;
}
};
}
return AddGarbage(game, txt);
}

View file

@ -52,8 +52,10 @@ void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height);
/*! \brief Loads bitmap into memory and scales it with software linear filtering. */
ALLEGRO_BITMAP* LoadScaledBitmap(struct Game* game, char* filename, int width, int height);
/*! \brief Finds path for data file. */
char* GetDataFilePath(struct Game* game, const char* filename);
/*! \brief Finds the path for data file. Returns NULL when the file can't be found. */
const char* FindDataFilePath(struct Game* game, const char* filename);
/*! \brief Finds the path for data file. Triggers BSOD and quits when the file can't be found. */
const char* GetDataFilePath(struct Game* game, const char* filename);
__attribute__((__format__(__printf__, 5, 6))) void PrintConsoleWithContext(struct Game* game, int line, const char* file, const char* func, char* format, ...);
/*! \brief Print some message on game console.