diff options
author | Treeki <treeki@gmail.com> | 2011-05-19 03:42:25 +0200 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2011-05-19 03:42:25 +0200 |
commit | 23fbdd37ecbff448f6e2b62f35752698f8711de5 (patch) | |
tree | 2ef2b2639198700b7aa1ecdba514d8347f22a286 /src/worldmap.cpp | |
parent | 416140a5f7a04df3edf8653a20ac6abc4c0398e5 (diff) | |
download | kamek-23fbdd37ecbff448f6e2b62f35752698f8711de5.tar.gz kamek-23fbdd37ecbff448f6e2b62f35752698f8711de5.zip |
world map code refactoring and cleanup: dWMPathManager_c added
Diffstat (limited to 'src/worldmap.cpp')
-rw-r--r-- | src/worldmap.cpp | 187 |
1 files changed, 17 insertions, 170 deletions
diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 33bda60..288d2bb 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -174,24 +174,20 @@ bool WMInit_SetupExtra(void *ptr) { }
// since we've got all the resources, set up the path data too
- wm->pathData.load(wm->resMng['PATH']);
-
- SaveBlock *save = GetSaveFile()->GetBlock(-1);
- if (save->current_path_node >= wm->pathData.pointCount()) {
- wm->currentPoint = wm->pathData.getPath(0)->startPoint;
- } else {
- wm->currentPoint = wm->pathData.getPoint(save->current_path_node);
- }
+ wm->pathManager->setup();
// and now Player setup
wm->player = (daWMPlayer_c*)CreateParentedObject(WM_PLAYER, wm, 0, 2);
wm->player->modelHandler->mdlClass->setPowerup(2);
wm->player->modelHandler->mdlClass->startAnimation(0, 1.2f, 10.0f, 0.0f);
- wm->player->pos = wm->currentPoint->position;
+ wm->player->pos = wm->pathManager->currentPoint->position;
// is last param correct? must check :/
wm->map = (dWMMap_c*)CreateParentedObject(WM_MAP, wm, 0, 0);
wm->hud = (dWMHud_c*)CreateParentedObject(WM_HUD, wm, 0, 0);
+ // note: world_camera and wm_path_manager are not created here
+ // because we require them earlier
+ // they are created in dScNewerWorldMap_c::onCreate
return true;
}
@@ -246,7 +242,7 @@ bool WMInit_SetupWipe(void *ptr) { #define STATE_SAVE_ERROR 27
-void dScNewerWorldMap_c::StartLevel(LevelInfo::Entry *entry) {
+void dScNewerWorldMap_c::startLevel(LevelInfo::Entry *entry) {
for (int i = 0; i < 4; i++) {
bool isThere = QueryPlayerAvailability(i);
int id = Player_ID[i];
@@ -340,6 +336,8 @@ int dScNewerWorldMap_c::onCreate() { SpammyReport("world camera\n");
CreateParentedObject(WORLD_CAMERA, this, 0, 0);
+ pathManager = (dWMPathManager_c*)CreateParentedObject(WM_PATH_MANAGER, this, 0, 0);
+
SpammyReport("setting NewerMapDrawFunc\n");
*CurrentDrawFunc = NewerMapDrawFunc;
@@ -367,11 +365,16 @@ int dScNewerWorldMap_c::onDelete() { return true;
}
-int dScNewerWorldMap_c::onExecute() {
+bool dScNewerWorldMap_c::canDoStuff() {
+ if (QueryGlobal5758(0xFFFFFFFF)) return false;
+ if (CheckIfWeCantDoStuff()) return false;
+ if (this->state == STATE_LIMBO) return false;
+ return true;
+}
+
- if (QueryGlobal5758(0xFFFFFFFF)) return true;
- if (CheckIfWeCantDoStuff()) return true;
- if (this->state == STATE_LIMBO) return true;
+int dScNewerWorldMap_c::onExecute() {
+ if (!canDoStuff()) return true;
/**************************************************************************/
// Read Wiimote Buttons
@@ -406,8 +409,6 @@ int dScNewerWorldMap_c::onExecute() { // STATE_NORMAL : Nothing related to the menu is going on
case STATE_NORMAL: {
- HandleMovement();
-
if (nowPressed & WPAD_ONE) {
STKI_SHOW(this->stockItem) = true;
this->state = STATE_POWERUPS_WAIT;
@@ -805,160 +806,6 @@ int dScNewerWorldMap_c::onExecute() { -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;
- }
-
- 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 = pathData.getPointID(this->currentPoint);
-
- dWMHud_c::instance->updateText();
- } 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);
-
- 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 = this->levelInfo.search(w, l);
- StartLevel(level);
- }
-}
-
void NewerMapDrawFunc() {
int keepCamera = GetCurrentCameraID();
|