summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2013-02-22 00:24:16 +0100
committerTreeki <treeki@gmail.com>2013-02-22 00:24:16 +0100
commit1aa3c19834f16d5153fba34c7ef9dc5a66be9466 (patch)
tree5a6e5a3b248a4f53f6f39aae615ffc689134113c
parent47c6a8826430eb0836cb0ef811f7492cae76e91c (diff)
downloadkamek-1aa3c19834f16d5153fba34c7ef9dc5a66be9466.tar.gz
kamek-1aa3c19834f16d5153fba34c7ef9dc5a66be9466.zip
add swimming support for maps, FINALLY
-rw-r--r--src/koopatlas/core.cpp2
-rw-r--r--src/koopatlas/player.cpp59
-rw-r--r--src/koopatlas/player.h4
3 files changed, 61 insertions, 4 deletions
diff --git a/src/koopatlas/core.cpp b/src/koopatlas/core.cpp
index 9a24f82..d4130c4 100644
--- a/src/koopatlas/core.cpp
+++ b/src/koopatlas/core.cpp
@@ -247,6 +247,7 @@ bool WMInit_SetupExtra(void *ptr) {
SpammyReport("creating player\n");
wm->player = (daWMPlayer_c*)CreateParentedObject(WM_PLAYER, wm, 0, 2);
wm->player->modelHandler->mdlClass->setPowerup(Player_Powerup[0]);
+ wm->player->bindPats();
wm->player->modelHandler->mdlClass->startAnimation(0, 1.2f, 10.0f, 0.0f);
// since we've got all the resources, set up the path data too
@@ -724,6 +725,7 @@ void dScKoopatlas_c::executeState_PowerupsWait() {
if (!stockItem->show) {
player->modelHandler->mdlClass->setPowerup(Player_Powerup[0]);
+ player->bindPats();
state.setState(&StateID_Normal);
hud->unhideAll();
diff --git a/src/koopatlas/player.cpp b/src/koopatlas/player.cpp
index e549871..3edb202 100644
--- a/src/koopatlas/player.cpp
+++ b/src/koopatlas/player.cpp
@@ -1,16 +1,37 @@
#include "koopatlas/player.h"
daWMPlayer_c *daWMPlayer_c::instance;
+static const char *mdlNames[] = {"MB_model", "SMB_model", "PLMB_model", "PMB_model"};
+static const char *patNames[] = {"PB_switch_swim", "PB_switch_swim", "PLMB_switch_swim", "PLB_switch_swim"};
int daWMPlayer_c::onCreate() {
this->modelHandler = new dPlayerModelHandler_c(0);
// loadModel(u8 player_id, int powerup_id, int unk);
// Unk is some kind of mode: 0=in-game, 1=map, 2=2D
- this->modelHandler->loadModel(0, 3, 1);
- this->modelHandler->mdlClass->startAnimation(0, 1.2, 10.0, 0.0);
- this->modelHandler->setSRT((Vec){0.0,100.0,-100.0}, (S16Vec){0,0,0}, (Vec){2.0,2.0,2.0});
- this->modelHandler->draw();
+
+ // Here we do a bit of a hack
+ //this->modelHandler->loadModel(0, 3, 1);
+ dPlayerModel_c *pm = (dPlayerModel_c*)modelHandler->mdlClass;
+
+ pm->mode_maybe = 1;
+ pm->player_id_1 = 0;
+ pm->allocator.link(0xC000, GameHeaps[0], 0, 0x20);
+ pm->prepare();
+
+ for (int i = 0; i < 4; i++) {
+ nw4r::g3d::ResMdl mdl = pm->modelResFile.GetResMdl(mdlNames[i]);
+ nw4r::g3d::ResAnmTexPat pat = pm->modelResFile.GetResAnmTexPat(patNames[i]);
+
+ pats[i].setup(mdl, pat, &pm->allocator, 0, 1);
+ }
+
+ pm->allocator.unlink();
+ pm->setPowerup(3);
+ pm->finaliseModel();
+
+ pm->startAnimation(0, 1.2, 10.0, 0.0);
+ modelHandler->setSRT((Vec){0.0,100.0,-100.0}, (S16Vec){0,0,0}, (Vec){2.0,2.0,2.0});
hammerSuit.setup(this->modelHandler);
@@ -26,6 +47,10 @@ int daWMPlayer_c::onCreate() {
timer = 0;
jumpOffset = 0.0;
+ // -1 or 0xC000? normally we use -1 but Player uses 0xC000....
+ //allocator.link(0xC000, GameHeaps[0], 0, 0x20);
+ //allocator.unlink();
+
return true;
}
@@ -49,6 +74,7 @@ int daWMPlayer_c::onExecute() {
dScKoopatlas_c::instance->pathManager.execute();
this->modelHandler->update();
+ pats[((dPlayerModel_c*)modelHandler->mdlClass)->currentPlayerModelID].process();
mMtx myMatrix;
myMatrix.scale(scale.x, scale.y, scale.z);
@@ -95,13 +121,38 @@ void daWMPlayer_c::startAnimation(int id, float frame, float unk, float updateRa
if (id == currentAnim && frame == currentFrame && unk == currentUnk && updateRate == currentUpdateRate)
return;
+ bool isOldSwimming = (currentAnim == swim_wait);
+ bool isNewSwimming = (id == swim_wait);
+
currentAnim = id;
currentFrame = frame;
currentUnk = unk;
currentUpdateRate = updateRate;
this->modelHandler->mdlClass->startAnimation(id, frame, unk, updateRate);
+
+ if (isOldSwimming != isNewSwimming)
+ bindPats();
}
+void daWMPlayer_c::bindPats() {
+ dPlayerModel_c *pm = (dPlayerModel_c*)modelHandler->mdlClass;
+ int id = pm->currentPlayerModelID;
+
+ static const float frames[] = {0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 2.0f, 3.0f};
+ float frame = frames[pm->powerup_id];
+ if (currentAnim == swim_wait)
+ frame += (pm->powerup_id == 4 || pm->powerup_id == 5) ? 1.0f : 4.0f;
+
+ nw4r::g3d::ResAnmTexPat pat = pm->modelResFile.GetResAnmTexPat(patNames[id]);
+ pats[id].bindEntry(
+ &pm->models[id].body,
+ &pat,
+ 0, 4);
+ pats[id].setUpdateRateForEntry(0.0f, 0);
+ pats[id].setFrameForEntry(frame, 0);
+
+ pm->models[id].body.bindAnim(&pats[id]);
+}
daWMPlayer_c *daWMPlayer_c::build() {
diff --git a/src/koopatlas/player.h b/src/koopatlas/player.h
index db9b16a..074c72d 100644
--- a/src/koopatlas/player.h
+++ b/src/koopatlas/player.h
@@ -33,6 +33,10 @@ class daWMPlayer_c : public dActor_c {
mEf::es2 effect;
dHammerSuitRenderer_c hammerSuit;
+ mHeapAllocator_c allocator;
+ m3d::anmTexPat_c pats[4];
+ void bindPats();
+
void startAnimation(int id, float frame, float unk, float updateRate);
static daWMPlayer_c *build();