From 1cc1afe0f971121f7aed34460305e835de90e984 Mon Sep 17 00:00:00 2001 From: Treeki Date: Sun, 14 Aug 2011 00:39:47 +0200 Subject: merged random tiles into level-select --- src/randtiles.cpp | 218 ++++++++++++++++++++++++++++++++++++++++++++++++------ src/randtiles.h | 63 ---------------- 2 files changed, 196 insertions(+), 85 deletions(-) delete mode 100644 src/randtiles.h (limited to 'src') diff --git a/src/randtiles.cpp b/src/randtiles.cpp index 0bc2ede..34e2daf 100644 --- a/src/randtiles.cpp +++ b/src/randtiles.cpp @@ -1,22 +1,196 @@ -#include "randtiles.h" - -u32 djb2(u8 *str) { - u32 hash = 5381; - int c; - - while (c = *str++) - hash = ((hash << 5) + hash) + c; - - return hash; -} - -RandTiles_Section *RandTiles_Search(void *file, u32 nameHash) { - for (int i = 0; i < RandTiles_GetSectionCount(file); i++) { - RandTiles_Section *sect = RandTiles_GetSection(file, i); - - if (sect->nameHash == nameHash) - return sect; - } - - return 0; -} +#include + +class RandomTileData { +public: + enum Type { + CHECK_NONE = 0, + CHECK_HORZ = 1, + CHECK_VERT = 2, + CHECK_BOTH = 3 + }; + + enum Special { + SP_NONE = 0, + SP_VDOUBLE_TOP = 1, + SP_VDOUBLE_BOTTOM = 2 + }; + + class NameList { + public: + u32 count; + u32 offsets[1]; // variable size + + const char *getName(int index) { + return ((char*)this) + offsets[index]; + } + + bool contains(const char *name) { + OSReport("NameList[%p] with %d names being compared against %s\n", this, count, name); + for (int i = 0; i < count; i++) { + OSReport("Checking %s\n", getName(i)); + if (strcmp(name, getName(i)) == 0) + return true; + OSReport("Did not pass\n"); + } + + return false; + } + }; + + class Entry { + public: + u8 lowerBound, upperBound; + u8 count, type; + u32 tileNumOffset; + + u8 *getTileNums() { + return ((u8*)this) + tileNumOffset; + } + }; + + class Section { + public: + u32 nameListOffset; + u32 entryCount; + Entry entries[1]; // variable size + + NameList *getNameList() { + return (NameList*)(((u32)this) + nameListOffset); + } + }; + + u32 magic; + u32 sectionCount; + u32 offsets[1]; // variable size + + Section *getSection(int id) { + return (Section*)(((char*)this) + offsets[id]); + } + + Section *getSection(const char *name); + + static RandomTileData *instance; +}; + +class RTilemapClass : public TilemapClass { +public: + // NEWER ADDITIONS + RandomTileData::Section *sections[4]; +}; + +RandomTileData::Section *RandomTileData::getSection(const char *name) { + for (int i = 0; i < sectionCount; i++) { + RandomTileData::Section *sect = getSection(i); + + if (sect->getNameList()->contains(name)) + return sect; + } + + return 0; +} + + +// Real tile handling code + +RandomTileData *RandomTileData::instance = 0; + +dDvdLoader_c RandTileLoader; + +extern "C" bool RandTileLoadHook() { + OSReport("Trying to load..."); + void *buf = RandTileLoader.load("/NewerRes/RandTiles.bin"); + if (buf == 0) { + OSReport("Failed.\n"); + return false; + } else { + OSReport("Successfully loaded RandTiles.bin [%p].\n", buf); + RandomTileData::instance = (RandomTileData*)buf; + return true; + } +} + + +extern "C" void IdentifyTilesets(RTilemapClass *self) { + self->_C0C = 0xFFFFFFFF; + + for (int i = 0; i < 4; i++) { + const char *tilesetName = BGDatClass::instance->getTilesetName(self->areaID, i); + + self->sections[i] = RandomTileData::instance->getSection(tilesetName); + OSReport("[%d] Chose %p for %s\n", i, self->sections[i], tilesetName); + } +} + +extern "C" void TryAndRandomise(RTilemapClass *self, BGRender *bgr) { + int fullTile = bgr->tileToPlace & 0x3FF; + int tile = fullTile & 0xFF; + int tileset = fullTile >> 8; + + RandomTileData::Section *rtSect = self->sections[tileset]; + if (rtSect == 0) + return; + + for (int i = 0; i < rtSect->entryCount; i++) { + RandomTileData::Entry *entry = &rtSect->entries[i]; + + if (tile >= entry->lowerBound && tile <= entry->upperBound) { + // Found it!! + // Try to make one until we meet the conditions + u8 type = entry->type & 3; + u8 special = entry->type >> 2; + + u8 *tileNums = entry->getTileNums(); + u16 chosen = 0xFF; + + // If it's the top special, then ignore this tile, we'll place that one + // once we choose the bottom one + if (special == RandomTileData::SP_VDOUBLE_TOP) + break; + + u16 *top = 0, *left = 0, *right = 0, *bottom = 0; + if (type == RandomTileData::CHECK_HORZ || type == RandomTileData::CHECK_BOTH) { + left = self->getPointerToTile(bgr->curX - 1, bgr->curY); + right = self->getPointerToTile(bgr->curX + 1, bgr->curY); + } + + if (type == RandomTileData::CHECK_VERT || type == RandomTileData::CHECK_BOTH) { + top = self->getPointerToTile(bgr->curX, bgr->curY - 1); + bottom = self->getPointerToTile(bgr->curX, bgr->curY + 1); + } + + int attempts = 0; + while (true) { + // is there even a point to using that special random function? + chosen = (tileset << 8) | tileNums[MakeRandomNumberForTiles(entry->count)]; + + // avoid infinite loops + attempts++; + if (attempts > 5) + break; + + if (top != 0 && *top == chosen) + continue; + if (bottom != 0 && *bottom == chosen) + continue; + if (left != 0 && *left == chosen) + continue; + if (right != 0 && *right == chosen) + continue; + break; + } + + bgr->tileToPlace = chosen; + + if (special == RandomTileData::SP_VDOUBLE_BOTTOM) { + if (top == 0) + top = self->getPointerToTile(bgr->curX, bgr->curY - 1); + + *top = (chosen - 0x10); + } + + return; + } + } +} + + diff --git a/src/randtiles.h b/src/randtiles.h deleted file mode 100644 index 14355da..0000000 --- a/src/randtiles.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef __NEWER_RANDTILES_H -#define __NEWER_RANDTILES_H - -#include -#include "fileload.h" - -#define RAND_CHECK_HORZ -#define RAND_CHECK_VERT -#define RAND_CHECK_BOTH - -struct RandTiles_Header { - u32 magic; - u32 sectionCount; -}; - -struct RandTiles_Section { - u32 nameHash; - u32 entryCount; -}; - -struct RandTiles_Entry { - u16 startTile; - u16 endTile; - u8 count; - u8 type; - u16 reserved; - u32 dataOffset; -}; - -inline u32 RandTiles_GetSectionCount(void *file) { - return ((RandTiles_Header*)file)->sectionCount; -} - -inline u32 *RandTiles_GetOffsets(void *file) { - return (u32*)(((RandTiles_Header*)file)+1); -} - -inline RandTiles_Section *RandTiles_GetSection(void *file, int id) { - u32 offs = RandTiles_GetOffsets(file)[id]; - return (RandTiles_Section*)(((char*)file)+offs); -}; - -inline RandTiles_Entry *RandTiles_GetTiles(void *file, RandTiles_Section *section) { - return (RandTiles_Entry*)(section+1); -} - -inline RandTiles_Entry *RandTiles_GetTiles(void *file, int sectionID) { - return (RandTiles_Entry*)(RandTiles_GetSection(file, sectionID)+1); -} - -inline char *RandTiles_GetName(void *file, RandTiles_Section *section) { - return ((char*)file)+section->nameOffset; -} - -inline u16 *RandTiles_GetData(void *file, RandTiles_Entry *entry) { - return (u16*)(((char*)file)+entry->dataOffset); -} - -u32 djb2(u8 *str); -RandTiles_Section *RandTiles_Search(void *file, u32 nameHash); - - -#endif -- cgit v1.2.3 From 15a45c3a765692d164df913d83dbaaedf760edb0 Mon Sep 17 00:00:00 2001 From: Treeki Date: Sun, 14 Aug 2011 01:05:32 +0200 Subject: forgot to remove this debug code --- src/randtiles.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'src') diff --git a/src/randtiles.cpp b/src/randtiles.cpp index 34e2daf..f4853d4 100644 --- a/src/randtiles.cpp +++ b/src/randtiles.cpp @@ -25,12 +25,9 @@ public: } bool contains(const char *name) { - OSReport("NameList[%p] with %d names being compared against %s\n", this, count, name); for (int i = 0; i < count; i++) { - OSReport("Checking %s\n", getName(i)); if (strcmp(name, getName(i)) == 0) return true; - OSReport("Did not pass\n"); } return false; -- cgit v1.2.3 From df2a6c031daa43c948eaebd5c53c1434d48851b6 Mon Sep 17 00:00:00 2001 From: Treeki Date: Sun, 14 Aug 2011 13:54:14 +0200 Subject: random tile engine is fixed once and for all! --- src/randtiles.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/randtiles.cpp b/src/randtiles.cpp index f4853d4..1508200 100644 --- a/src/randtiles.cpp +++ b/src/randtiles.cpp @@ -146,13 +146,13 @@ extern "C" void TryAndRandomise(RTilemapClass *self, BGRender *bgr) { u16 *top = 0, *left = 0, *right = 0, *bottom = 0; if (type == RandomTileData::CHECK_HORZ || type == RandomTileData::CHECK_BOTH) { - left = self->getPointerToTile(bgr->curX - 1, bgr->curY); - right = self->getPointerToTile(bgr->curX + 1, bgr->curY); + left = self->getPointerToTile((bgr->curX - 1) * 16, bgr->curY * 16); + right = self->getPointerToTile((bgr->curX + 1) * 16, bgr->curY * 16); } if (type == RandomTileData::CHECK_VERT || type == RandomTileData::CHECK_BOTH) { - top = self->getPointerToTile(bgr->curX, bgr->curY - 1); - bottom = self->getPointerToTile(bgr->curX, bgr->curY + 1); + top = self->getPointerToTile(bgr->curX * 16, (bgr->curY - 1) * 16); + bottom = self->getPointerToTile(bgr->curX * 16, (bgr->curY + 1) * 16); } int attempts = 0; @@ -180,7 +180,7 @@ extern "C" void TryAndRandomise(RTilemapClass *self, BGRender *bgr) { if (special == RandomTileData::SP_VDOUBLE_BOTTOM) { if (top == 0) - top = self->getPointerToTile(bgr->curX, bgr->curY - 1); + top = self->getPointerToTile(bgr->curX * 16, (bgr->curY - 1) * 16); *top = (chosen - 0x10); } -- cgit v1.2.3 From 4d482b80241de4512b68bc160dfc29b7e521134d Mon Sep 17 00:00:00 2001 From: Treeki Date: Sun, 14 Aug 2011 14:44:23 +0200 Subject: fixed powerup sound --- src/poweruphax.S | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/poweruphax.S b/src/poweruphax.S index 9274b78..e028eb9 100644 --- a/src/poweruphax.S +++ b/src/poweruphax.S @@ -16,6 +16,7 @@ .extern continuePlumberSetPowerupTexture .extern doneSettingThePowerupTexture .extern doneSettingThePowerupTexture2 +.extern returnFromPowerupSoundChange #ifndef __MWERKS__ .set r0,0; .set r1,1; .set r2,2; .set r3,3; .set r4,4 @@ -391,16 +392,30 @@ _not19: .global FixPowerupSound FixPowerupSound: - # WARNING! This is a bad, bad, bad hack. - # I was too lazy to add anything to the linker script, so... - - # We branch at 80141334, so our LR is 80141338 - # We need to jump to 80141384 - mflr r3 - addi r3, r3, 0x4C - mtlr r3 + #lis r3, DBString@h + #ori r3, r3, DBString@l + #lwz r4, 0x1090(r29) + #crclr 4*cr1+eq + #bl OSReport + + lwz r5, 0x14DC(r29) # Original powerup + lwz r0, 0x1090(r29) # New powerup + # if NEW is 1 (big) and OLD is not 0 or 3, then play 273 (powerdown) + cmpwi r0, 1 + bne dontConsiderPowerdown + + cmpwi r5, 0 + beq dontConsiderPowerdown + cmpwi r5, 3 + beq dontConsiderPowerdown + # If the player is here, he was downgraded from a higher powerup to Big Mario + # So play the powerdown sound + mr r3, r29 + li r4, 273 + li r5, 0 + b returnFromPowerupSoundChange - lwz r0, 0x1090(r29) +dontConsiderPowerdown: lis r3, PowerupSounds@h ori r3, r3, PowerupSounds@l slwi r4, r0, 2 @@ -408,7 +423,7 @@ FixPowerupSound: mr r3, r29 li r5, 0 - blr + b returnFromPowerupSoundChange .global WeirdAnimLoadHack @@ -719,6 +734,9 @@ I_hammerModelName: PowerupTexDebugStr: .string "Plumber::SetPowerupTexture() called on class %p with texnum %d lr=%p\n" +DBString: + .string "PW:%d\n" + #.global BrosModelFilename #BrosModelFilename: # .string "g3d/bros.brres" -- cgit v1.2.3