Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Thumbs.db
ehthumbs.db

# RAD Debugger files
*.rdi

# Visual Studio folder
.vs
*.pdb
Expand Down
10 changes: 10 additions & 0 deletions include/constants/sa2/characters.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef GUARD_CONSTANTS_CHARACTERS_H
#define GUARD_CONSTANTS_CHARACTERS_H

#if 01
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

typedef enum {
CHARACTER_SONIC,
#if (GAME >= GAME_SA2)
Expand All @@ -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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw since we have constants/sa2 split out from constants/sa1 I think we can remove the enum for now?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, moving it to a different file would be unintuitive...

But overall it's definitely better to have an enum than #defines

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree enum is better, but atm we have both lol

// 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_<something> before NUM_CHARACTERS confuses it.
Expand Down
4 changes: 2 additions & 2 deletions tools/BriBaSA_ex/src/drawing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions tools/BriBaSA_ex/src/file_paths.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
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};

info.gameRoot = gameDir;
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 */
Expand Down
2 changes: 1 addition & 1 deletion tools/BriBaSA_ex/src/file_paths.h
Original file line number Diff line number Diff line change
@@ -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
59 changes: 41 additions & 18 deletions tools/BriBaSA_ex/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ 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);
}

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);
Expand Down Expand Up @@ -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;
}
}
}
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tools/BriBaSA_ex/src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
23 changes: 17 additions & 6 deletions tools/BriBaSA_ex/src/parsing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++;

Expand Down
46 changes: 23 additions & 23 deletions tools/BriBaSA_ex/src/texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

2 changes: 1 addition & 1 deletion tools/BriBaSA_ex/src/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading