From 7f612915fb609cabad71d3f17b3c3fda31b2e346 Mon Sep 17 00:00:00 2001 From: Treeki Date: Sun, 13 Mar 2011 00:25:36 +0100 Subject: durr I forgot to "git add ." after I had finished editing code :( --- src/worldmap.cpp | 345 +------------------------------------------------------ src/worldmap.h | 149 ------------------------ 2 files changed, 1 insertion(+), 493 deletions(-) (limited to 'src') diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 2db382a..cf40166 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -121,15 +121,12 @@ const char *group13 = "G_opt12"; const char *group14 = "G_opt13"; const char *group15 = "G_opt14"; -//void *EGG__Heap__alloc(unsigned long size, int unk, void *heap); -#ifdef LEVEL_MENU void dScNewerWorldMap_c::StartLevel() { LevelInfo_Entry *level = LevelInfo_GetLevels(this->levelInfo, this->currentPage); level += this->selections[this->currentPage]; StartLevel(level); } -#endif void dScNewerWorldMap_c::StartLevel(LevelInfo_Entry *entry) { for (int i = 0; i < 4; i++) { @@ -159,7 +156,6 @@ void dScNewerWorldMap_c::StartLevel(LevelInfo_Entry *entry) { DoStartLevel(GetGameMgr(), &sl); } -#ifdef LEVEL_MENU void dScNewerWorldMap_c::SetTitle(const char *text) { unsigned short conv_buf[0x1FF]; int length = strlen(text); @@ -220,13 +216,11 @@ void dScNewerWorldMap_c::GenText() { } } } -#endif int dScNewerWorldMap_c::onCreate() { LoadMapScene(); GameSetup__LoadScene(0); // lol, stolen from GAME_SETUP - #ifdef LEVEL_MENU this->layout = (Layout*)AllocFromGameHeap1(sizeof(Layout)); if (!this->layout) { OSReport("memalloc fail\n"); @@ -262,7 +256,6 @@ int dScNewerWorldMap_c::onCreate() { for (int i = 0; i < 15; i++) { EmbeddedLayout_ResetAnimToInitialState(this->layout, i, false); } - #endif this->selectCursor = CreateParentedObject(SELECT_CURSOR, this, 0, 0); @@ -290,15 +283,9 @@ int dScNewerWorldMap_c::onCreate() { this->easyPairing = CreateParentedObject(EASY_PAIRING, this, 0, 0); - //this->player = (daWMPlayer_c*)CreateParentedObject(WM_PLAYER, this, 0, 2); - - CreateParentedObject(WORLD_CAMERA, this, 0, 0); - this->state = STATE_START_DVD; - #ifdef LEVEL_MENU this->layout->drawOrder = 0; - #endif *CurrentDrawFunc = NewerMapDrawFunc; @@ -309,7 +296,6 @@ int dScNewerWorldMap_c::onCreate() { // load the menu info SaveBlock *save = GetSaveFile()->GetBlock(-1); - #ifdef LEVEL_MENU this->currentPage = save->current_world; // bounds check @@ -327,37 +313,19 @@ int dScNewerWorldMap_c::onCreate() { // show button anim EmbeddedLayout_EnableNonLoopAnim(this->layout, save->current_path_node, false); - #endif - - LoadModel(); - - wmData.load("/NewerRes/TestMap.wm"); - - WMDataHeader *hdr = (WMDataHeader*)wmData.fh.filePtr; - if (save->current_path_node >= hdr->pointCount) { - this->currentPoint = wmData.getPath(0)->startPoint; - } else { - this->currentPoint = hdr->pointList[save->current_path_node]; - } - - #ifdef LEVEL_MENU this->GenText(); - #endif - return true; } int dScNewerWorldMap_c::onDelete() { - #ifdef LEVEL_MENU EmbeddedLayout_FreeArc(this->layout); EmbeddedLayout_Free(this->layout); EmbeddedLayout_dtor(this->layout, false); FreeFromGameHeap1(this->layout); FreeFromGameHeap1(this->selections); - #endif FreeFile(&this->levelInfoFH); @@ -464,20 +432,8 @@ int dScNewerWorldMap_c::onExecute() { CONT_UNK2(this->continueObj) = true; CONT_UNK3(this->continueObj) = false; } else { - #ifdef LEVEL_MENU this->state = STATE_OPT_CHANGE_WAIT; - #else - this->state = STATE_NORMAL; - #endif } - - // and now Player setup - #ifndef LEVEL_MENU - this->player = (daWMPlayer_c*)CreateParentedObject(WM_PLAYER, this, 0, 2); - this->player->modelHandler->mdlClass->setPowerup(2); - this->player->modelHandler->mdlClass->startAnimation(0, 1.2f, 10.0f, 0.0f); - this->player->pos = this->currentPoint->position; - #endif } } break; @@ -505,11 +461,6 @@ int dScNewerWorldMap_c::onExecute() { // STATE_NORMAL : Nothing related to the menu is going on case STATE_NORMAL: { - #ifndef LEVEL_MENU - HandleMovement(); - #endif - -#ifdef LEVEL_MENU int currentPage = this->currentPage; int currentSelection = this->selections[currentPage]; int newPage = currentPage; @@ -569,29 +520,23 @@ int dScNewerWorldMap_c::onExecute() { save->current_world = newPage; save->current_path_node = newSelection; } -#endif // Enter the current level -#ifndef MARIO_OPTIONS -#ifdef LEVEL_MENU if (Wiimote_TestButtons(GetActiveWiimote(), WPAD_A | WPAD_TWO)) { this->StartLevel(); this->state = STATE_LIMBO; // just in case } -#endif if (nowPressed & WPAD_ONE) { STKI_SHOW(this->stockItem) = true; this->state = STATE_POWERUPS_WAIT; } -#endif } break; /**********************************************************************/ // STATE_OPT_CHANGE_WAIT : Waiting for the option change animation to // finish playing - #ifdef LEVEL_MENU case STATE_OPT_CHANGE_WAIT: if (!EmbeddedLayout_CheckIfAnimationIsOn(this->layout, -1)) { @@ -599,7 +544,6 @@ int dScNewerWorldMap_c::onExecute() { } break; - #endif /**********************************************************************/ // STATE_CSMENU : The course select menu is currently being shown case STATE_CSMENU: @@ -985,313 +929,25 @@ int dScNewerWorldMap_c::onExecute() { } - #ifdef LEVEL_MENU if (this->state >= STATE_NORMAL) { EmbeddedLayout_Process(this->layout); EmbeddedLayout_UpdateMatrix(this->layout); } - #endif return true; } int dScNewerWorldMap_c::onDraw() { -#ifdef LEVEL_MENU EmbeddedLayout_AddToDrawList(this->layout); -#endif - -#ifndef LEVEL_MENU - this->model.scheduleForDrawing(); - - //Mtx matrix; - //MTXIdentity(matrix); - - //this->testModel.addToDrawList(matrix); -#endif return true; } -#ifndef LEVEL_MENU -// Todo: move to .LZ files and dDvd::loader_c - -void dScNewerWorldMap_c::LoadModel() { - OSReport("Loading Goldwood model...\n"); - modelFile.openCompressed("/NewerRes/Maps/SMGoldwood.brres"); - - //LoadFile(&this->modelFH, "/Object/GoldwoodBase.arc"); - //LoadFile(&this->modelFH, "/WorldMap/CS_W1.arc"); - - /*ARCHandle arc; - ARCFileInfo keyinfo; - ARCInitHandle(this->modelFH.filePtr, &arc); - ARCOpen(&arc, "g3d/GoldwoodBase.brres", &keyinfo); - //ARCOpen(&arc, "g3d/model.brres", &keyinfo); - - nw4r::g3d::ResFile resfile(ARCGetStartAddrInMem(&keyinfo));*/ - - nw4r::g3d::ResFile resfile(modelFile.ptr()); - - if (!resfile.CheckRevision()) - OSReport("Warning: Revision check failed!\n"); - - resfile.Init(); - - if (!resfile.Bind(resfile)) - OSReport("Warning: ResFile bind failed!\n"); - - void *mdl = resfile.GetResMdl("GoldwoodBase"); - //void *mdl = resfile.GetResMdl("CS_W1"); - OSReport("Obtained ResMdl: %p\n", mdl); - - OSReport(this->allocator.link(-1, GameHeaps[0], 0, 0x20) ? "Success\n" : "Fail\n"); - OSReport(this->model.setup(&mdl, &this->allocator, 0, 1, 0) ? "Success\n" : "Fail\n"); - - SetupTextures_Map(&model, 1); - - //this->nw4rMdl.sub_80064BF0(); - //this->nw4rMdl.oneSetupType(); - - this->allocator.unlink(); - OSReport("Done loading model!\n"); - - Mtx asdf; - //MTXScale(asdf, 0.1, 0.1, 0.1); - MTXIdentity(asdf); - this->model.setDrawMatrix(asdf); - - //ARCClose(&keyinfo); -} - - -void dScNewerWorldMap_c::HandleMovement() { - int heldButtons = Remocon_GetButtons(GetActiveRemocon()); - int nowPressed = Remocon_GetPressed(GetActiveRemocon()); - - if (isMoving) { - MoveThroughPath(); - } else { - if (nowPressed & WPAD_LEFT && currentPoint->exits.asDirection.left.isValid()) - StartMovementTo(LEFT); - else if (nowPressed & WPAD_RIGHT && currentPoint->exits.asDirection.right.isValid()) - StartMovementTo(RIGHT); - else if (nowPressed & WPAD_UP && currentPoint->exits.asDirection.up.isValid()) - StartMovementTo(UP); - else if (nowPressed & WPAD_DOWN && currentPoint->exits.asDirection.down.isValid()) - StartMovementTo(DOWN); - - if (nowPressed & WPAD_TWO) - ActivatePoint(); - } -} - -void dScNewerWorldMap_c::MoveThroughPath() { - // figure out how much to move on each step - Vec from, to; - if (this->reverseThroughPath) { - from = this->currentSegment->end; - to = this->currentSegment->start; - } else { - from = this->currentSegment->start; - to = this->currentSegment->end; - } - - //float xMove = this->currentSegment->stepsPerFrame * cos(this->movementAngle); - //float zMove = this->currentSegment->stepsPerFrame * sin(this->movementAngle); - Vec move; - move.x = to.x - from.x; - move.y = to.y - from.y; - move.z = to.z - from.z; - - VECNormalize(&move, &move); - VECScale(&move, &move, this->currentSegment->stepsPerFrame); - - this->player->pos.x += move.x; - this->player->pos.y += move.y; - this->player->pos.z += move.z; - - // have we reached the end? - bool xAtEnd = false; - bool yAtEnd = false; - bool zAtEnd = false; - - if (move.x > 0) { - xAtEnd = (this->player->pos.x >= to.x); - } else { - xAtEnd = (this->player->pos.x <= to.x); - } - - if (move.y > 0) { - yAtEnd = (this->player->pos.y >= to.y); - } else { - yAtEnd = (this->player->pos.y <= to.y); - } - - if (move.z > 0) { - zAtEnd = (this->player->pos.z >= to.z); - } else { - zAtEnd = (this->player->pos.z <= to.z); - } - - if (xAtEnd && yAtEnd && zAtEnd) { - MapReport("reached end of segment %d\n", this->currentSegmentID); - - int nextSegment = this->currentSegmentID + (this->reverseThroughPath ? -1 : 1); - if (nextSegment == -1 || nextSegment == this->currentPath->segCount) { - MapReport("reached end of path\n"); - this->currentPoint = this->nextPoint; - this->player->pos = this->currentPoint->position; - this->player->startAnimation(0, 1.2, 10.0, 0.0); - this->isMoving = false; - - SaveBlock *save = GetSaveFile()->GetBlock(-1); - //save->current_world = newPage; ? - save->current_path_node = wmData.getPointID(this->currentPoint); - } else { - this->MoveToSegment(nextSegment); - } - } -} - -void dScNewerWorldMap_c::StartMovementTo(WMDirection direction) { - this->isMoving = true; - - WMPathEntrance *thisExit = ¤tPoint->exits.asArray[direction]; - MapReport("Using an exit in direction %d\n", direction); - - this->currentPath = thisExit->path; - if (thisExit->isEndSide) { - this->nextPoint = thisExit->path->startPoint; - this->reverseThroughPath = true; - this->MoveToSegment(thisExit->path->segCount - 1); - } else { - this->nextPoint = thisExit->path->endPoint; - this->reverseThroughPath = false; - this->MoveToSegment(0); - } -} - -void dScNewerWorldMap_c::MoveToSegment(int id) { - MapReport("Moving to segment %d\n", id); - - this->currentSegmentID = id; - this->currentSegment = this->currentPath->segments[id]; - - // calculate rotation - Vec from, to; - if (this->reverseThroughPath) { - from = this->currentSegment->end; - to = this->currentSegment->start; - } else { - from = this->currentSegment->start; - to = this->currentSegment->end; - } - - MapReport("From: %f,%f,%f To: %f,%f,%f\n", from.x, from.y, from.z, to.x, to.y, to.z); - - /*float xDiff = to.x - from.x; - float zDiff = to.z - from.z; - this->movementAngle = atan2(zDiff, xDiff); - float rotValue = ((int)(90.0f - MTXRadToDeg(this->movementAngle)) % 360); - - MapReport("Calculated rotation value: %f\n", rotValue);*/ - - this->player->pos = from; - - // update rotation - if (!this->currentSegment->useLastDir) { - this->player->rot.x = 0; - this->player->rot.y = this->currentSegment->direction; - this->player->rot.z = 0; - - if (this->reverseThroughPath && !this->currentSegment->alwaysSameDir) { - this->player->rot.y = ((this->currentSegment->direction) + 0x8000) & 0xFFFF; - } - } - - this->player->startAnimation(this->currentSegment->animationType, this->currentSegment->animationSpeed, 10.0, 0.0); -} - -void dScNewerWorldMap_c::ActivatePoint() { - MapReport("Point activated!\n"); - this->player->startAnimation(170, 1.2, 10.0, 0.0); - - if (this->currentPoint->type == WMPathPoint::LEVEL_TYPE) { - int w = this->currentPoint->params[0] - 1; - int l = this->currentPoint->params[1] - 1; - LevelInfo_Entry *level = LevelInfo_Search(this->levelInfo, w, l); - StartLevel(level); - } -} -#endif - - void NewerMapDrawFunc() { int keepCamera = GetCurrentCameraID(); - /*// Based off WorldMapDrawFunc. - - LinkScene(1); - SceneCalcWorld(1); - SceneCameraStuff(1); - ChangeAlphaUpdate(false); - DrawOpa(); - DrawXlu(); - UnlinkScene(0); - - SetupLYTDrawing(); - DrawAllLayoutsBeforeX(129); - RenderEffects(0, 3); - RenderEffects(0, 2); - GXDrawDone(); - - RemoveAllFromScnRoot(); - Reset3DState(); - SetCurrentCameraID(1); - DoSpecialDrawing1(); - LinkScene(1); - SceneCalcWorld(1); - SceneCameraStuff(1); - CalcMaterial(); - DrawOpa(); - DrawXlu(); - UnlinkScene(1); - GXDrawDone(); - - RemoveAllFromScnRoot(); - Reset3DState(); - GXSetZMode(0, GX_ALWAYS, 0); - DrawAllLayoutsAfterXandBeforeY(128, 146); - SetCurrentCameraID(1); - DoSpecialDrawing2(); - LinkScene(1); - SceneCalcWorld(1); - SceneCameraStuff(1); - CalcMaterial(); - DrawOpa(); - DrawXlu(); - UnlinkScene(1); - - if (GAMEMGR_GET_AFC(GameMgr)) { - for (int i = 0; i < 4; i++) { - RenderEffects(0, 11+i); - } - - for (int i = 0; i < 4; i++) { - RenderEffects(0, 7+i); - } - } - - GXDrawDone(); - RemoveAllFromScnRoot(); - Reset3DState(); - DrawAllLayoutsAfterX(145); - ClearLayoutDrawList(); - SetCurrentCameraID(0);*/ - - // All drawing uses scene 1, since that's the only one loaded by GAME_SETUP. // Todo: Newer-specific scenes? @@ -1326,6 +982,7 @@ void NewerMapDrawFunc() { RemoveAllFromScnRoot(); Reset3DState(); SetCurrentCameraID(1); + DoSpecialDrawing1(); LinkScene(1); SceneCalcWorld(1); diff --git a/src/worldmap.h b/src/worldmap.h index 1f8a9a3..5966352 100644 --- a/src/worldmap.h +++ b/src/worldmap.h @@ -8,29 +8,14 @@ // TODO: add Save Error state -//#define MARIO_OPTIONS //#define WM_DEBUGGING -//#define LEVEL_MENU #include #include -#ifdef LEVEL_MENU #include "layoutlib.h" -#endif - #include "fileload.h" #include "levelinfo.h" -#include "3dlib/treeki3d.h" -#include "worldmapdata.h" -#include - -enum WMDirection { - LEFT, - RIGHT, - UP, - DOWN -}; #ifdef WM_DEBUGGING #define MapReport OSReport @@ -41,114 +26,12 @@ inline void MapReport(const char *str, ...) { } void NewerMapDrawFunc(); -struct WMResSetEntry { - u32 key; - u32 offset; -}; - -struct WMResSetHeader { - u32 magic; - u32 count; - WMResSetEntry entries[1]; // dynamic size - - char *getName(int index) { - return (char*)((u32)this + entries[index].offset); - } -}; - -class dWMResourceMng_c { -private: - bool hasSetPath; - bool isSetLoaded; - bool isLoadingComplete; - - char setPath[0x40]; - dDvdLoader_c setLoader; - dDvdLoader_c *resLoaders; - - WMResSetHeader *setData; - -public: - dWMResourceMng_c(); - ~dWMResourceMng_c(); - - bool loadSet(const char *setName); - void *operator[](u32 key); - - bool isLoaded(); - - - u32 resCount() { - return setData->count; - } - - u32 keyForIndex(u32 index) { - return setData->entries[index].key; - } - - void *dataForIndex(u32 index) { - return resLoaders[index].buffer; - } -}; - - -class dWMMap_c : public dBase_c { -public: - int onCreate(); - int onDelete(); - int onExecute(); - int onDraw(); - - static dWMMap_c *build(); - static dWMMap_c *instance; -}; - - -class dWorldCamera_c : public dBase_c { -public: - int onCreate(); - int onDelete(); - int onExecute(); - int onDraw(); - - Point3d camPos; - Vec camRotate; - - static dWorldCamera_c *build(); - static dWorldCamera_c *instance; -}; - - -class daWMPlayer_c : public dActor_c { -public: - dPlayerModelHandler_c *modelHandler; - - int onCreate(); - int onDelete(); - int onExecute(); - int onDraw(); - - int current_param; - - int currentAnim; - float currentFrame; - float currentUnk; - float currentUpdateRate; - - void startAnimation(int id, float frame, float unk, float updateRate); - - static daWMPlayer_c *build(); - static daWMPlayer_c *instance; -}; - // WORLD MAP CLASS LAYOUT class dScNewerWorldMap_c : public dScene_c { public: - #ifdef LEVEL_MENU Layout *layout; int currentPage; int *selections; - #endif int state; void *csMenu; void *selectCursor; @@ -162,43 +45,11 @@ public: void *levelInfo; FileHandle levelInfoFH; - #ifndef LEVEL_MENU - mHeapAllocator_c allocator; - File modelFile; - m3d::mdl_c model; - - void LoadModel(); - - daWMPlayer_c *player; - - WorldMapData wmData; - - bool isMoving; - WMPathPoint *currentPoint; - WMPathPoint *nextPoint; - - WMPathDef *currentPath; - WMPathSegment *currentSegment; - int currentSegmentID; - bool reverseThroughPath; // direction we are going through the path - - void HandleMovement(); - - void StartMovementTo(WMDirection direction); - void MoveToSegment(int id); - - void MoveThroughPath(); - - void ActivatePoint(); - #endif - void StartLevel(LevelInfo_Entry *entry); - #ifdef LEVEL_MENU void StartLevel(); void GenText(); void SetTitle(const char *text); - #endif int onCreate(); int onDelete(); -- cgit v1.2.3