diff --git a/.gitignore b/.gitignore index 5d022f364..a79bb4304 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,9 @@ Thumbs.db ehthumbs.db +# RAD Debugger files +*.rdi + # Visual Studio folder .vs *.pdb diff --git a/include/constants/sa2/characters.h b/include/constants/sa2/characters.h index afcd2cdb2..14cefa555 100644 --- a/include/constants/sa2/characters.h +++ b/include/constants/sa2/characters.h @@ -1,6 +1,7 @@ #ifndef GUARD_CONSTANTS_CHARACTERS_H #define GUARD_CONSTANTS_CHARACTERS_H +#if 01 typedef enum { CHARACTER_SONIC, #if (GAME >= GAME_SA2) @@ -12,6 +13,15 @@ typedef enum { NUM_CHARACTERS } ECharacters; +#else +// TODO: Right now these have to be defined like this for BriBaSA_ex to work. +// Obviously this shall change! +#define CHARACTER_SONIC 0 +#define CHARACTER_TAILS 1 +#define CHARACTER_KNUCKLES 2 +#define CHARACTER_AMY 3 +#define NUM_CHARACTERS 4 +#endif // NOTE: Put this after NUM_CHARACTERS, to allow BriBaSA_ex to parse this file properly. // Naming it CHARACTER_ before NUM_CHARACTERS confuses it. diff --git a/tools/BriBaSA_ex/src/drawing.c b/tools/BriBaSA_ex/src/drawing.c index 2dfef656d..c64b17242 100644 --- a/tools/BriBaSA_ex/src/drawing.c +++ b/tools/BriBaSA_ex/src/drawing.c @@ -1019,8 +1019,8 @@ DrawMap(AppState *state, Rectangle recMap, Texture2D txMtAtlas, Texture2D txMap) ); } - int mtIndexBack = GetMetatileIndex(&state->map, &state->paths.map, LAYER_BACK, mtX, mtY); - int mtIndexFront = GetMetatileIndex(&state->map, &state->paths.map, LAYER_FRONT, mtX, mtY); + int mtIndexBack = GetMetatileIndex(state->game, &state->map, &state->paths.map, LAYER_BACK, mtX, mtY); + int mtIndexFront = GetMetatileIndex(state->game, &state->map, &state->paths.map, LAYER_FRONT, mtX, mtY); bool iterateAgain = false; do { diff --git a/tools/BriBaSA_ex/src/file_paths.c b/tools/BriBaSA_ex/src/file_paths.c index c95ea813f..95763c536 100644 --- a/tools/BriBaSA_ex/src/file_paths.c +++ b/tools/BriBaSA_ex/src/file_paths.c @@ -12,7 +12,7 @@ static void SetupTilemapPaths(Tilemap *out, char *directory); void -InitFilePaths(FileInfo *outInfo, char *gameDir, char *mapDir) +InitFilePaths(Game game, FileInfo *outInfo, char *gameDir, char *mapDir) { FileInfo info = {0}; @@ -20,11 +20,11 @@ InitFilePaths(FileInfo *outInfo, char *gameDir, char *mapDir) info.mapRoot = mapDir; /* Global C Headers */ - info.characters_h = allocPath(gameDir, "include/constants/characters.h"); - info.animations_h = allocPath(gameDir, "include/constants/animations.h"); - info.enemies_h = allocPath(gameDir, "include/constants/enemies.h"); - info.interactables_h = allocPath(gameDir, "include/constants/interactables.h"); - info.items_h = allocPath(gameDir, "include/constants/items.h"); + info.characters_h = allocPath(gameDir, TextFormat("include/constants/sa%d/characters.h", game)); + info.animations_h = allocPath(gameDir, TextFormat("include/constants/sa%d/animations.h", game)); + info.enemies_h = allocPath(gameDir, TextFormat("include/constants/sa%d/enemies.h", game)); + info.interactables_h = allocPath(gameDir, TextFormat("include/constants/sa%d/interactables.h", game)); + info.items_h = allocPath(gameDir, TextFormat("include/constants/sa%d/items.h", game)); /* Map-specific */ diff --git a/tools/BriBaSA_ex/src/file_paths.h b/tools/BriBaSA_ex/src/file_paths.h index ad4dd4c3a..715e11519 100644 --- a/tools/BriBaSA_ex/src/file_paths.h +++ b/tools/BriBaSA_ex/src/file_paths.h @@ -1,7 +1,7 @@ #ifndef GUARD_BRIBASA_EX_FILE_PATHS_H #define GUARD_BRIBASA_EX_FILE_PATHS_H -extern void InitFilePaths(FileInfo *outInfo, char *gameDir, char *mapDir); +extern void InitFilePaths(Game game, FileInfo *outInfo, char *gameDir, char *mapDir); extern char *allocPath(char *folder, char *fileName); #endif // GUARD_BRIBASA_EX_FILE_PATHS_H diff --git a/tools/BriBaSA_ex/src/main.c b/tools/BriBaSA_ex/src/main.c index 88950cbcc..207ea661f 100644 --- a/tools/BriBaSA_ex/src/main.c +++ b/tools/BriBaSA_ex/src/main.c @@ -114,7 +114,7 @@ int main(void) exit(-1); } - const char *mapsRoot = TextFormat("%s/data/maps/", rootDir); + const char *mapsRoot = TextFormat("%s/data/sa%d/maps/", rootDir, state.game); if(!DirectoryExists(mapsRoot)) { printf("ERROR: '%s' could not be found. Closing...\n", mapsRoot); exit(-2); @@ -122,10 +122,10 @@ int main(void) char *mapDir = GetMapDirectory(mapsRoot); - InitFilePaths(&state.paths, (char*)rootDir, (char*)mapDir); + InitFilePaths(state.game, &state.paths, (char*)rootDir, (char*)mapDir); LoadEntityNamesAndIDs(&state); - LoadAllEntityTextures(state.paths.gameRoot, &state.paths); + LoadAllEntityTextures(state.game, state.paths.gameRoot, &state.paths); LoadEntityDataFromCSVs(&state); InitUiHeaderWidgets(&state.uiHeader); @@ -545,22 +545,40 @@ SetNewMetatiles(AppState *state, int x, int y) StageMap *map = &state->map; short targetIndex = y * map->width + x; - if(targetIndex < (state->paths.map.tilemap.dataSize / sizeof(short))) { + if(targetIndex < (state->paths.map.tilemap.dataSize / ((state->game == GAME_SA1) ? sizeof(unsigned char) : sizeof(short)) )) { if(map->flags & MAP_FLAG_SHOW_BACK_LAYER) { - unsigned short *layoutBack = state->paths.map.layers[LAYER_BACK].data; + if(state->game == GAME_SA1) { + unsigned char *layoutBack = state->paths.map.layers[LAYER_BACK].data; - if(layoutBack[targetIndex] != map->selectedMetatileIndexBack) { - layoutBack[targetIndex] = map->selectedMetatileIndexBack; - state->unsavedChangesExist = true; + if(layoutBack[targetIndex] != map->selectedMetatileIndexBack) { + layoutBack[targetIndex] = map->selectedMetatileIndexBack; + state->unsavedChangesExist = true; + } + } else { + unsigned short *layoutBack = state->paths.map.layers[LAYER_BACK].data; + + if(layoutBack[targetIndex] != map->selectedMetatileIndexBack) { + layoutBack[targetIndex] = map->selectedMetatileIndexBack; + state->unsavedChangesExist = true; + } } } if(map->flags & MAP_FLAG_SHOW_FRONT_LAYER) { - unsigned short *layoutFront = state->paths.map.layers[LAYER_FRONT].data; + if(state->game == GAME_SA1) { + unsigned char *layoutFront = state->paths.map.layers[LAYER_FRONT].data; + + if(layoutFront[targetIndex] != map->selectedMetatileIndexFront) { + layoutFront[targetIndex] = map->selectedMetatileIndexFront; + state->unsavedChangesExist = true; + } + } else { + unsigned short *layoutFront = state->paths.map.layers[LAYER_FRONT].data; - if(layoutFront[targetIndex] != map->selectedMetatileIndexFront) { - layoutFront[targetIndex] = map->selectedMetatileIndexFront; - state->unsavedChangesExist = true; + if(layoutFront[targetIndex] != map->selectedMetatileIndexFront) { + layoutFront[targetIndex] = map->selectedMetatileIndexFront; + state->unsavedChangesExist = true; + } } } } @@ -577,14 +595,19 @@ GetMousePositionInRec(Rectangle rec) { } inline int -GetMetatileIndex(StageMap *map, Tilemap* tilemap, MetatileLayer layer, int x, int y) +GetMetatileIndex(Game game, StageMap *map, Tilemap* tilemap, MetatileLayer layer, int x, int y) { ///assert(layer < LAYER_COUNT); if(x >= 0 && y >= 0 - && x < map->width && y < map->height) { - uint16_t *mtIndices = tilemap->layers[layer].data; - return mtIndices[y * map->width + x]; + && x < map->width && y < map->height) { + if(game == GAME_SA1) { + uint8_t *mtIndices = tilemap->layers[layer].data; + return mtIndices[y * map->width + x]; + } else { + uint16_t *mtIndices = tilemap->layers[layer].data; + return mtIndices[y * map->width + x]; + } } else { return 0; } @@ -638,8 +661,8 @@ HandleMouseInput(AppState *state, Rectangle recMap) map->selectedMetatile.x = mtMouse.x; map->selectedMetatile.y = mtMouse.y; - int mtIndexFront = GetMetatileIndex(&state->map, &state->paths.map, LAYER_FRONT, state->map.selectedMetatile.x, state->map.selectedMetatile.y); - int mtIndexBack = GetMetatileIndex(&state->map, &state->paths.map, LAYER_BACK , state->map.selectedMetatile.x, state->map.selectedMetatile.y); + int mtIndexFront = GetMetatileIndex(state->game, &state->map, &state->paths.map, LAYER_FRONT, state->map.selectedMetatile.x, state->map.selectedMetatile.y); + int mtIndexBack = GetMetatileIndex(state->game, &state->map, &state->paths.map, LAYER_BACK , state->map.selectedMetatile.x, state->map.selectedMetatile.y); state->map.selectedMetatileIndexFront = mtIndexFront; state->map.selectedMetatileIndexBack = mtIndexBack; diff --git a/tools/BriBaSA_ex/src/map.h b/tools/BriBaSA_ex/src/map.h index 671ffd71b..9233feb46 100644 --- a/tools/BriBaSA_ex/src/map.h +++ b/tools/BriBaSA_ex/src/map.h @@ -2,7 +2,7 @@ #define GUARD_BRIBASA_EX_MAP_H extern Texture2D CreateMetatileAtlas(AppState *state, int numMetatiles); -extern int GetMetatileIndex(StageMap *map, Tilemap* tilemap, MetatileLayer layer, int x, int y); +extern int GetMetatileIndex(Game game, StageMap *map, Tilemap* tilemap, MetatileLayer layer, int x, int y); extern Vector2i GetMetatilePointBelowMouse(StageMap *map, Rectangle recMap); extern bool IsMouseOnSpawn(StageMap *map, CharacterList *chars); diff --git a/tools/BriBaSA_ex/src/parsing.c b/tools/BriBaSA_ex/src/parsing.c index 64622b255..de4144d2e 100644 --- a/tools/BriBaSA_ex/src/parsing.c +++ b/tools/BriBaSA_ex/src/parsing.c @@ -166,19 +166,28 @@ LoadEntityNamesAndIDs(AppState *state) } if(TextIsEqual(tokenName->text, TextFormat("SA%d_ANIM_ITEMBOX", state->game))) { - items->animItembox = TextToInteger(tokenID->text); + if(items->animItembox == 0) { + items->animItembox = TextToInteger(tokenID->text); + } } else if(TextIsEqual(tokenName->text, TextFormat("SA%d_ANIM_ITEMBOX_TYPE", state->game))) { - items->animItemType = TextToInteger(tokenID->text); + if(items->animItemType == 0) + { + items->animItemType = TextToInteger(tokenID->text); + } } else if(TextIsEqual(tokenName->text, TextFormat("SA%d_ANIM_RING", state->game))) { - ring->anim = TextToInteger(tokenID->text); + if(ring->anim == 0) { + ring->anim = TextToInteger(tokenID->text); + } } else if(foundEnemyAnims < enemies->count) { for(int ei = 0; ei < enemies->count; ei++) { unsigned short id = enemies->elements[ei].id; EntityMeta *enemy = &enemies->elements[id]; const char *format = TextFormat("SA%d_ANIM_%s", state->game, enemy->name); - if(TextIsEqual((char *)tokenName->text, format)) { - enemy->anim = TextToInteger(tokenID->text); + if(TextIsEqual((char *)tokenName->text, format)) { + if(enemy->anim == 0) { + enemy->anim = TextToInteger(tokenID->text); + } foundEnemyAnims++; break; @@ -192,7 +201,9 @@ LoadEntityNamesAndIDs(AppState *state) if(TextIsEqual((char *)tokenName->text, format)) { do { - ia->anim = TextToInteger(tokenID->text); + if(ia->anim == 0) { + ia->anim = TextToInteger(tokenID->text); + } foundIAAnims++; diff --git a/tools/BriBaSA_ex/src/texture.c b/tools/BriBaSA_ex/src/texture.c index 149096ec6..7c152c42e 100644 --- a/tools/BriBaSA_ex/src/texture.c +++ b/tools/BriBaSA_ex/src/texture.c @@ -49,65 +49,65 @@ GetEntityTextureById(AppState *state, EntityType etype, unsigned char id) } static inline void -LoadCharacterTextures(char *gameRoot, CharacterList *chars) +LoadCharacterTextures(Game game, char *gameRoot, CharacterList *chars) { for(int c = 0; c < chars->count; c++) { Character *character = &chars->elements[c]; int frame = 0; - const char *animPath = TextFormat("%s/graphics/obj_tiles/4bpp/anim_%04d/f%03d.png", - gameRoot, character->animIdle, frame); + const char *animPath = TextFormat("%s/graphics/sa%d/obj_tiles/4bpp/anim_%04d/f%03d.png", + gameRoot, game, character->animIdle, frame); character->texture = LoadTexture(animPath); } } static inline void -LoadEntityTextures(char *gameRoot, EntityMetaList *ents) +LoadEntityTextures(Game game, char *gameRoot, EntityMetaList *ents) { for(int c = 0; c < ents->count; c++) { EntityMeta *ent = &ents->elements[c]; int frame = 0; - const char *animPath = TextFormat("%s/graphics/obj_tiles/4bpp/anim_%04d/f%03d.png", - gameRoot, ent->anim, frame); + const char *animPath = TextFormat("%s/graphics/sa%d/obj_tiles/4bpp/anim_%04d/f%03d.png", + gameRoot, game, ent->anim, frame); ent->texture = LoadTexture(animPath); } } static inline void -LoadInteractableTextures(char *gameRoot, InteractableMetaList *ias) +LoadInteractableTextures(Game game, char *gameRoot, InteractableMetaList *ias) { for(int c = 0; c < ias->count; c++) { InteractableMeta *ia = &ias->elements[c]; int frame = 0; - const char *animPath = TextFormat("%s/graphics/obj_tiles/4bpp/anim_%04d/f%03d.png", - gameRoot, ia->anim, frame); + const char *animPath = TextFormat("%s/graphics/sa%d/obj_tiles/4bpp/anim_%04d/f%03d.png", + gameRoot, game, ia->anim, frame); ia->texture = LoadTexture(animPath); } } static inline void -LoadRingTexture(char *gameRoot, EntityMeta *ring) +LoadRingTexture(Game game, char *gameRoot, EntityMeta *ring) { int frame = 0; - const char *animPath = TextFormat("%s/graphics/obj_tiles/4bpp/anim_%04d/f%03d.png", - gameRoot, ring->anim, frame); + const char *animPath = TextFormat("%s/graphics/sa%d/obj_tiles/4bpp/anim_%04d/f%03d.png", + gameRoot, game, ring->anim, frame); ring->texture = LoadTexture(animPath); } static inline void -LoadItemTextures(char *gameRoot, ItemMetaList *items, short numCharacters) +LoadItemTextures(Game game, char *gameRoot, ItemMetaList *items, short numCharacters) { - const char *pathFormat = "%s/graphics/obj_tiles/4bpp/anim_%04d/f%03d.png"; + const char *pathFormat = "%s/graphics/sa%d/obj_tiles/4bpp/anim_%04d/f%03d.png"; // Itembox unsigned short animId = items->animItembox; - const char *itemboxPath = TextFormat(pathFormat, gameRoot, animId, 0); + const char *itemboxPath = TextFormat(pathFormat, gameRoot, game, animId, 0); items->txItembox = LoadTexture(itemboxPath); // 1-Up icons for(int c = 0; c < numCharacters; c++) { unsigned short animId = items->animItemType; - const char *iconPath = TextFormat(pathFormat, gameRoot, animId, c); + const char *iconPath = TextFormat(pathFormat, gameRoot, game, animId, c); Texture tx1Up = LoadTexture(iconPath); da_append(&items->oneUpIcons, &tx1Up); @@ -122,19 +122,19 @@ LoadItemTextures(char *gameRoot, ItemMetaList *items, short numCharacters) ent->texture = items->oneUpIcons.elements[0]; } } else { - const char *animPath = TextFormat(pathFormat, gameRoot, items->animItemType, (i - 1) + numCharacters); + const char *animPath = TextFormat(pathFormat, gameRoot, game, items->animItemType, (i - 1) + numCharacters); ent->texture = LoadTexture(animPath); } } } void -LoadAllEntityTextures(char *gamePath, FileInfo *paths) +LoadAllEntityTextures(Game game, char *gamePath, FileInfo *paths) { - LoadCharacterTextures(gamePath, &paths->characters); - LoadInteractableTextures(gamePath, &paths->interactables); - LoadEntityTextures(gamePath, &paths->enemies); - LoadItemTextures(gamePath, &paths->items, paths->characters.count); - LoadRingTexture(gamePath, &paths->ring); + LoadCharacterTextures(game, gamePath, &paths->characters); + LoadInteractableTextures(game, gamePath, &paths->interactables); + LoadEntityTextures(game, gamePath, &paths->enemies); + LoadItemTextures(game, gamePath, &paths->items, paths->characters.count); + LoadRingTexture(game, gamePath, &paths->ring); } diff --git a/tools/BriBaSA_ex/src/texture.h b/tools/BriBaSA_ex/src/texture.h index 290871813..beef6145f 100644 --- a/tools/BriBaSA_ex/src/texture.h +++ b/tools/BriBaSA_ex/src/texture.h @@ -3,6 +3,6 @@ extern Texture2D GetEntityTextureById(AppState *state, EntityType etype, unsigned char id); -extern void LoadAllEntityTextures(char *gamePath, FileInfo *paths); +extern void LoadAllEntityTextures(Game game, char *gamePath, FileInfo *paths); #endif // GUARD_BRISABA_EX_TEXTURE_H