Skip to content

Commit

Permalink
#368 GBA osLoadLevel and osLoadScreen by level id
Browse files Browse the repository at this point in the history
  • Loading branch information
XProger committed May 28, 2022
1 parent 4ec68f1 commit 18566e1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/fixed/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ EWRAM_DATA ExtraInfoLara playersExtra[MAX_PLAYERS];
#include "LEVEL1_PKD.h"
#include "LEVEL2_PKD.h"

#define LEVEL_INFO(name, title, track, secrets) { #name, name##_PKD, title, track, secrets }
#define LEVEL_INFO(data, title, track, secrets) { data##_PKD, title, track, secrets }
#else
#define LEVEL_INFO(name, title, track, secrets) { #name, NULL, title, track, secrets }
#define LEVEL_INFO(data, title, track, secrets) { #data, title, track, secrets }
#endif

EWRAM_DATA LevelID gLevelID = LVL_TR1_TITLE;
Expand Down
26 changes: 13 additions & 13 deletions src/fixed/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,6 @@ X_INLINE int32 abs(int32 x) {
extern uint16 fb[VRAM_WIDTH * FRAME_HEIGHT];
#endif

// system
extern int32 osGetSystemTimeMS();
extern bool osSaveSettings();
extern bool osLoadSettings();
extern bool osCheckSave();
extern bool osSaveGame();
extern bool osLoadGame();
extern void osJoyVibrate(int32 index, int32 L, int32 R);
extern void osSetPalette(const uint16* palette);
extern void* osLoadLevel(const char* name);

#ifdef PROFILING
#define PROFILE_FRAME\
CNT_UPDATE,\
Expand Down Expand Up @@ -2592,7 +2581,6 @@ enum TrackID

struct LevelInfo
{
const char* name;
const void* data;
StringID title;
TrackID track;
Expand Down Expand Up @@ -2938,7 +2926,7 @@ bool useSwitch(ItemObj* item, int32 timer);
bool useKey(ItemObj* item, ItemObj* lara);
bool usePickup(ItemObj* item);

void startLevel(const char* name);
void startLevel(LevelID id);
void nextLevel(LevelID next);
bool gameSave();
bool gameLoad();
Expand All @@ -2964,4 +2952,16 @@ void updateFading(int32 frames);
void dmaFill(void* dst, uint8 value, uint32 count);
void dmaCopy(const void* src, void* dst, uint32 size);

// system
int32 osGetSystemTimeMS();
bool osSaveSettings();
bool osLoadSettings();
bool osCheckSave();
bool osSaveGame();
bool osLoadGame();
void osJoyVibrate(int32 index, int32 L, int32 R);
void osSetPalette(const uint16* palette);
const void* osLoadScreen(LevelID id);
const void* osLoadLevel(LevelID id);

#endif
12 changes: 6 additions & 6 deletions src/fixed/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool gameLoad()

SaveGame tmp = gSaveGame;
gLevelID = (LevelID)gSaveGame.level;
startLevel(gLevelInfo[gLevelID].name);
startLevel(gLevelID);
gSaveGame = tmp;

inventory.setSlots(gSaveGame.invSlots);
Expand Down Expand Up @@ -83,7 +83,7 @@ bool gameLoad()
return true;
}

void gameInit(const char* name)
void gameInit()
{
drawInit();

Expand All @@ -101,7 +101,7 @@ void gameInit(const char* name)

inventory.init();

startLevel(name);
startLevel(gLevelID);
}

void gameFree()
Expand Down Expand Up @@ -227,15 +227,15 @@ void gameLoadLevel(const void* data)
drawLevelInit();
}

void startLevel(const char* name)
void startLevel(LevelID id)
{
gRandSeedLogic = osGetSystemTimeMS() * 3;
gRandSeedDraw = osGetSystemTimeMS() * 7;

sndStop();
sndFreeSamples();

void* data = osLoadLevel(name);
const void* data = osLoadLevel(id);
gameLoadLevel(data);

sndInitSamples();
Expand Down Expand Up @@ -311,7 +311,7 @@ void gameUpdate(int32 frames)
if (gLevelID == LVL_LOAD) {
gameLoad();
} else {
startLevel(gLevelInfo[gLevelID].name);
startLevel(gLevelID);
}
gameUpdate(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/fixed/inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ struct Inventory
this->lara = lara;

if (page == INV_PAGE_TITLE) {
background = TITLE_SCR;
background = osLoadScreen(LVL_TR1_TITLE);
} else {
background = copyBackground();
}
Expand Down
27 changes: 15 additions & 12 deletions src/platform/gba/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,19 @@ LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
return 0;
}

void* osLoadLevel(const char* name)
const void* osLoadScreen(LevelID id)
{
return TITLE_SCR;
}

const void* osLoadLevel(LevelID id)
{
// level1
char buf[32];

delete[] levelData;

sprintf(buf, "data/%s.PKD", name);
sprintf(buf, "data/%s.PKD", gLevelInfo[id].data);

FILE *f = fopen(buf, "rb");

Expand Down Expand Up @@ -279,7 +284,7 @@ int main(void)

soundInit();

gameInit(gLevelInfo[gLevelID].name);
gameInit();

MSG msg;

Expand Down Expand Up @@ -550,16 +555,14 @@ void boostEWRAM()
}
}

void* osLoadLevel(const char* name)
const void* osLoadScreen(LevelID id)
{
for (int32 i = 0; i < LVL_MAX; i++)
{
if (strcmp(name, gLevelInfo[i].name) == 0)
return (void*)gLevelInfo[i].data;
}
return TITLE_SCR;
}

gLevelID = LVL_TR1_TITLE;
return (void*)gLevelInfo[gLevelID].data;
const void* osLoadLevel(LevelID id)
{
return gLevelInfo[id].data;
}

int main(void)
Expand All @@ -577,7 +580,7 @@ int main(void)
rumbleInit();
soundInit();

gameInit(gLevelInfo[gLevelID].name);
gameInit();

uint16 mode = DCNT_BG2 | DCNT_PAGE | DCNT_MODE4;

Expand Down

0 comments on commit 18566e1

Please sign in to comment.