Use CMake option for asset dir instead of command-line flag
This commit is contained in:
@@ -7,6 +7,7 @@ else()
|
||||
target_link_libraries(game PRIVATE engine)
|
||||
endif()
|
||||
set_default_target_options(game)
|
||||
target_compile_definitions(game PRIVATE ASSET_DIR="${ASSET_DIR}")
|
||||
target_include_directories(game PUBLIC include)
|
||||
|
||||
target_link_libraries(game PRIVATE
|
||||
|
||||
40
game/main.c
40
game/main.c
@@ -140,7 +140,6 @@ typedef struct {
|
||||
typedef unsigned map_t[MAPNLAYERS][MAPWIDTH][MAPHEIGHT];
|
||||
|
||||
typedef struct {
|
||||
const char *assetdir;
|
||||
map_t map;
|
||||
SDL_Texture *tstex, *pidle, *pwalk;
|
||||
input_state_t input;
|
||||
@@ -251,8 +250,8 @@ static unsigned load_objtype(
|
||||
xmlNodePtr sprites)
|
||||
{
|
||||
static char buf[MAX_PATH_LEN];
|
||||
assert(strlen(state->assetdir) + strlen(templ) + 1 < MAX_PATH_LEN);
|
||||
strcpy(buf, state->assetdir);
|
||||
assert(strlen(ASSET_DIR) + strlen(templ) + 1 < MAX_PATH_LEN);
|
||||
strcpy(buf, ASSET_DIR);
|
||||
strcat(buf, "/");
|
||||
strcat(buf, templ);
|
||||
|
||||
@@ -340,9 +339,9 @@ static unsigned load_objtype(
|
||||
state->objtypes[id].animframes = atoi((const char *)val);
|
||||
} else if (xmlStrcmp(key, (const xmlChar *)"assetpath") == 0) {
|
||||
assert(
|
||||
strlen(state->assetdir) + strlen((const char *)val)
|
||||
strlen(ASSET_DIR) + strlen((const char *)val)
|
||||
< MAX_PATH_LEN);
|
||||
strcpy(buf, state->assetdir);
|
||||
strcpy(buf, ASSET_DIR);
|
||||
strcat(buf, (const char *)val);
|
||||
state->objtypes[id].tex = IMG_LoadTexture(renderer, buf);
|
||||
assert(NULL != state->objtypes[id].tex);
|
||||
@@ -362,9 +361,8 @@ static void
|
||||
load_objects(gamestate_t *state, xmlNodePtr node, SDL_Renderer *renderer)
|
||||
{
|
||||
char path[MAX_PATH_LEN];
|
||||
assert(strlen(state->assetdir) + strlen(OBJSPRITES) < MAX_PATH_LEN);
|
||||
strcpy(path, state->assetdir);
|
||||
strcat(path, OBJSPRITES);
|
||||
assert(strlen(ASSET_DIR OBJSPRITES) < MAX_PATH_LEN);
|
||||
strcpy(path, ASSET_DIR OBJSPRITES);
|
||||
xmlDocPtr spritesdoc = xmlParseFile(path);
|
||||
xmlNodePtr sprites = xmlDocGetRootElement(spritesdoc);
|
||||
|
||||
@@ -496,34 +494,30 @@ void init_drawlist(gamestate_t *state)
|
||||
|
||||
void game_init(int argc, char *argv[], void *mem, SDL_Renderer *renderer)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
char path[MAX_PATH_LEN];
|
||||
gamestate_t *state = (gamestate_t *)mem;
|
||||
|
||||
assert(2 == argc);
|
||||
state->assetdir = argv[1];
|
||||
|
||||
// Load map
|
||||
assert(strlen(state->assetdir) + strlen(MAP_ASSET) < MAX_PATH_LEN);
|
||||
strcpy(path, state->assetdir);
|
||||
strcat(path, MAP_ASSET);
|
||||
assert(strlen(ASSET_DIR MAP_ASSET) < MAX_PATH_LEN);
|
||||
strcpy(path, ASSET_DIR MAP_ASSET);
|
||||
load_map(state, path, renderer);
|
||||
|
||||
// Load tileset
|
||||
assert(strlen(state->assetdir) + strlen(TSASSET) < MAX_PATH_LEN);
|
||||
strcpy(path, state->assetdir);
|
||||
strcat(path, TSASSET);
|
||||
assert(strlen(ASSET_DIR TSASSET) < MAX_PATH_LEN);
|
||||
strcpy(path, ASSET_DIR TSASSET);
|
||||
state->tstex = IMG_LoadTexture(renderer, path);
|
||||
assert(NULL != state->tstex);
|
||||
|
||||
// Load player spritesheets and initialize texture
|
||||
assert(strlen(state->assetdir) + strlen(PIDLE_ASSET) < MAX_PATH_LEN);
|
||||
strcpy(path, state->assetdir);
|
||||
strcat(path, PIDLE_ASSET);
|
||||
assert(strlen(ASSET_DIR PIDLE_ASSET) < MAX_PATH_LEN);
|
||||
strcpy(path, ASSET_DIR PIDLE_ASSET);
|
||||
state->pidle = IMG_LoadTexture(renderer, path);
|
||||
assert(NULL != state->pidle);
|
||||
assert(strlen(state->assetdir) + strlen(PWALK_ASSET) < MAX_PATH_LEN);
|
||||
strcpy(path, state->assetdir);
|
||||
strcat(path, PWALK_ASSET);
|
||||
assert(strlen(ASSET_DIR PWALK_ASSET) < MAX_PATH_LEN);
|
||||
strcpy(path, ASSET_DIR PWALK_ASSET);
|
||||
state->pwalk = IMG_LoadTexture(renderer, path);
|
||||
assert(NULL != state->pwalk);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user