summaryrefslogtreecommitdiff
path: root/src/wm_player.cpp
blob: 39dc0a5cc06c1b92aaf459cd819d7ae5e1f9cfaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "worldmap.h"

daWMPlayer_c *daWMPlayer_c::instance;

int daWMPlayer_c::onCreate() {
	OSReport("* dWMPlayer_c created\n");

	OSReport("Init handler...\n");
	this->modelHandler = new dPlayerModelHandler_c(0);
	this->modelHandler->loadModel(0, 3, 2);
	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();
	OSReport("Init done!\n");

	pos = (Vec){0.0f,0.0f,0.0f};
	rot = (S16Vec){0,0,0};
	scale = (Vec){1.5f,1.5f,1.5f};

	current_param = 0;

	/*//#define BRRES_NAME "fruits_kusa_gake"
	//#define MODEL_NAME "fruits_kusa_gake_S"

	#define BRRES_NAME "bgB_4502"
	#define MODEL_NAME BRRES_NAME

	OSReport("Loading nw4r model\n");
	//LoadFile(&this->nw4rMdlFH, "/Object/" BRRES_NAME ".arc");
	LoadFile(&this->nw4rMdlFH, "/Object/CrapMap.arc");
	OSReport("Loaded. Reading arc\n");
	ARCHandle arc;
	ARCFileInfo keyinfo;
	ARCInitHandle(this->nw4rMdlFH.filePtr, &arc);
	//bool arcres = ARCOpen(&arc, "g3d/" BRRES_NAME ".brres", &keyinfo);
	bool arcres = ARCOpen(&arc, "g3d/model.brres", &keyinfo);
	OSReport(arcres ? "Success\n" : "Fail\n");

	OSReport("Getting nw4r model\n");
	//void *brres = DVD_GetFile(GetDVDClass2(), "fruits_kusa_gake", "g3d/fruits_kusa_gake.brres");

	OSReport("Done. Constructing model\n");
	void *brres = ARCGetStartAddrInMem(&keyinfo);
	OSReport("brres @ %p\n", brres);
	nw4r::g3d::ResFile resfile(brres);
	OSReport(resfile.CheckRevision() ? "Success\n" : "Fail\n");
	resfile.Init();
	OSReport(resfile.Bind(resfile) ? "Success\n" : "Fail\n");
	//void *mdl = resfile.GetResMdl(MODEL_NAME);
	void *mdl = resfile.GetResMdl("CrapMap");
	OSReport("MDL @ %p, %d\n", mdl, 1099);
	//this->nw4rMdlTest = nw4r::g3d::ConstructScnMdl(mdl, 0x20, 1);
	//this->nw4rMdlTest = nw4r::g3d::ConstructScnMdlSimple(mdl, 1);
	OSReport(this->allocator.link(-1, GameHeaps[0], 0, 0x20) ? "Success\n" : "Fail\n");
	OSReport(this->nw4rMdl.setup(&mdl, &this->allocator, 0, 1, 0) ? "Success\n" : "Fail\n");
	//this->nw4rMdl.sub_80064BF0();
	//this->nw4rMdl.oneSetupType();
	OSReport("Unlink returned %d\n", this->allocator.unlink());
	OSReport("Done!\n");

	Mtx asdf;
	MTXIdentity(asdf);
	this->nw4rMdl.setDrawMatrix(asdf);

	ARCClose(&keyinfo);*/

	return true;
}

int daWMPlayer_c::onDelete() {
	delete modelHandler;
	OSReport("* dWMPlayer_c deleted\n");

	return true;
}


int daWMPlayer_c::onExecute() {
	this->modelHandler->update();
	this->modelHandler->setSRT(this->pos, this->rot, this->scale);

#ifdef MARIO_OPTIONS
	// Before we leave, do the debug movement stuff
	int heldButtons = Remocon_GetButtons(GetActiveRemocon());
	int nowPressed = Remocon_GetPressed(GetActiveRemocon());
	char buf[100];
	bool updated = false;

	if (nowPressed & WPAD_LEFT) {
		current_param--;
		updated = true;
	}

	if (nowPressed & WPAD_RIGHT) {
		current_param++;
		updated = true;
	}

	if (current_param < 0)
		current_param = 8;

	if (current_param > 8)
		current_param = 0;

	float pos_mod = 0.0f;
	short rot_mod = 0.0f;
	float scale_mod = 0.0f;
	if (nowPressed & WPAD_ONE) {
		pos_mod -= 5.0f;
		rot_mod -= 0x1000;
		scale_mod -= 0.1f;
		updated = true;
	} else if (nowPressed & WPAD_TWO) {
		pos_mod += 5.0f;
		rot_mod += 0x1000;
		scale_mod += 0.1f;
		updated = true;
	}

	if (!updated) return true;

	if (current_param == 0) {
		pos.x += pos_mod;
		sprintf(buf, "X position: %f", pos.x);
	} else if (current_param == 1) {
		pos.y += pos_mod;
		sprintf(buf, "Y position: %f", pos.y);
	} else if (current_param == 2) {
		pos.z += pos_mod;
		sprintf(buf, "Z position: %f", pos.z);
	} else if (current_param == 3) {
		rot.x += rot_mod;
		sprintf(buf, "X rotation: 0x%04x", rot.x);
	} else if (current_param == 4) {
		rot.y += rot_mod;
		sprintf(buf, "Y rotation: 0x%04x", rot.y);
	} else if (current_param == 5) {
		rot.z += rot_mod;
		sprintf(buf, "Z rotation: 0x%04x", rot.z);
	} else if (current_param == 6) {
		scale.x += scale_mod;
		sprintf(buf, "X scale: %f", scale.x);
	} else if (current_param == 7) {
		scale.y += scale_mod;
		sprintf(buf, "Y scale: %f", scale.y);
	} else if (current_param == 8) {
		scale.z += scale_mod;
		sprintf(buf, "Z scale: %f", scale.z);
	}

	dScNewerWorldMap_c::instance->SetTitle(buf);
#endif

	return true;
}

int daWMPlayer_c::onDraw() {
	this->modelHandler->draw();

	//OSReport("Adding to scene\n");
	//this->nw4rMdl.scheduleForDrawing();
	//OSReport("done\n");

	return true;
}


void daWMPlayer_c::startAnimation(int id, float frame, float unk, float updateRate) {
	if (id == currentAnim && frame == currentFrame && unk == currentUnk && updateRate == currentUpdateRate)
		return;

	currentAnim = id;
	currentFrame = frame;
	currentUnk = unk;
	currentUpdateRate = updateRate;
	this->modelHandler->mdlClass->startAnimation(id, frame, unk, updateRate);
}



daWMPlayer_c *daWMPlayer_c::build() {
	OSReport("Creating WMPlayer\n");

	void *buffer = AllocFromGameHeap1(sizeof(daWMPlayer_c));
	daWMPlayer_c *c = new(buffer) daWMPlayer_c;

	OSReport("Created WMPlayer @ %p\n", c);

	instance = c;
	return c;
}