DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
opening.cpp
1#ifdef PAL
2#pragma argument_flag 0
3#pragma argument_flag_ones 47, 54, 61, 64, 66, 159, 160, 162, 168, 1204
4#pragma argument_flag_ones 1205, 1206, 1209, 1210, 1211, 1473, 1493, 1494, 1580, 1582
5#pragma argument_flag_ones 1583, 1585, 1599
6#else
7#pragma argument_flag 0
8#pragma argument_flag_ones 47, 54, 61, 64, 66, 159, 160, 162, 168, 334
9#pragma argument_flag_ones 339, 344, 349, 354, 359, 364, 428, 430, 1138, 1139
10#pragma argument_flag_ones 1140, 1143, 1144, 1145, 1407, 1427, 1428, 1514, 1516, 1517
11#pragma argument_flag_ones 1519, 1533
12#endif
13
14#include "common.h"
15
16#include <cstdlib>
17#include <cstring>
18
19#include "camera.hpp"
20#include "camerafollow.hpp"
21#include "character.hpp"
22#include "clsmes.hpp"
23#include "dataalloc.hpp"
24#include "dataread.hpp"
25#include "frame.hpp"
26#include "framevu1.hpp"
27#include "gamepad.hpp"
28#include "gameutil.hpp"
29#include "main.hpp"
30#include "mainselect.hpp"
31#include "mds.hpp"
32#include "mglib.hpp"
33#include "snd.hpp"
34#include "sound.hpp"
35#include "texture.hpp"
36#include "title/dispfade.hpp"
37#include "title/op_a.hpp"
38#include "title/opening.hpp"
39#include "title/script.hpp"
40#include "vector.hpp"
41#include "vutext.hpp"
42
46// clang-format off
47enum SceneReadStep {
48 SCENE_READ_START = 0,
49 SCENE_READ_WAIT = 1,
50 SCENE_READ_IDLE = 2,
51};
52
53// clang-format on
54
55/* The rectangle every 2D draw takes, declared here rather than reached through rect.h for the
56 reason title.cpp declares its own: the rectangles this file builds are temporaries whose four
57 stores come out ascending, and the constructor rect.h states assigns them in the other order. */
58template <class T>
59class CRect {
60public:
61 T x;
62 T y;
63 T w;
64 T h;
66 CRect() {}
67
68 CRect(T left, T top, T width, T height) {
69 x = left;
70 y = top;
71 w = width;
72 h = height;
73 }
74} __attribute__((aligned(16)));
75
76void MGSetViewMatrix(sceVu0FMATRIX view);
77void MGFillBox(const CRect<int> &rect, u_char r, u_char g, u_char b, u_char a);
78
79void wait_now_loading_vsync();
80void InitializeDataBuffer();
81void set2DSprite(sceVif1Packet *packet, CTexture *texture, const CRect<int> &dst, const CRect<int> &src, u_char alpha);
82void set2DSprite(sceVif1Packet *packet, CTexture *texture, const CRect<int> &dst, const CRect<int> &src, u_char r, u_char g, u_char b, u_char a);
83
84void OpB_InitProcess();
85void OpB_InitProcess2();
86void OpB_LoadDataBG();
87void OpB_LoadDataBG2();
88void OpB_MotionProcess();
89void OpB_SoundProcess();
90void OpB_DrawProcess();
91void OpC_InitProcess();
92void OpC_InitProcess2();
93void OpC_InitProcess3();
94void OpC_InitProcess4();
95void OpC_InitProcess5();
96void OpC_LoadDataBG();
97void OpC_LoadDataBG2();
98void OpC_LoadDataBG3();
99void OpC_LoadDataBG4();
100void OpC_LoadDataBG5();
101void OpC_MotionProcess();
102void OpC_SoundProcess();
103void OpC_DrawProcess();
104void OpD_InitProcess();
105void OpD_InitProcess2();
106void OpD_LoadDataBG();
107void OpD_LoadDataBG2();
108void OpD_MotionProcess();
109void OpD_SoundProcess();
110void OpD_DrawProcess();
111
112static void LoadMessage();
113static void LoadScene();
114static void SceneChange();
115static void PauseProcess();
116static void SoundStop();
117static void WaitKeyProcess();
118static void MotionProcess();
119static void SoundProcess();
120static void DrawProcess();
121static void DrawMess();
122
123CDataAlloc2<1> CharaDataBuffer__2[7];
124CDataAlloc2<1> DummyBuffer(-1);
125CDataAlloc2<1> PassDataBuffer[3];
126CDataAlloc2<1> MapDataBuffer(-1);
127CDataAlloc2<1> WaterBuffer__2(-1);
128CDataAlloc2<1> testBuffer(-1);
129
130CCharacter Chara__3[23];
131char CharaTex__2[23];
132
133/* Nothing calls this and nothing reads the table it fills: the link this file was built by removed
134 both. They are here because the compiler carries state from one definition to the next, and the
135 camera below is constructed with its arguments evaluated in an order no declaration that emits
136 nothing reaches. */
137static int OpeningWork[9];
138
139static void OpeningWorkInit() {
140 OpeningWork[0] = 1;
141 OpeningWork[1] = 2;
142 OpeningWork[2] = 3;
143 OpeningWork[3] = 4;
144 OpeningWork[4] = 5;
145 OpeningWork[5] = 6;
146 OpeningWork[6] = 7;
147 OpeningWork[7] = 8;
148 OpeningWork[8] = 9;
149}
150
151/* Nothing reads this pointer and the link removes it. Together with the exact folded constant
152 below, it preserves the camera initializer's argument order without adding retained data. */
153
154CCameraFollow OP_MainCamera(60.0f + 0.0f + 0.0f + 0.0f + 0.0f + 0.0f + 0.0f, 20.0f, 0.0f, 4.0f);
155
156CCharacter Cam__2[3];
157MOTION_INFO Op_MotionInfo;
158static ClsMes Mes1;
159static CDispFade DispFade;
160
161u_char *PassReadBuffer;
162u_char *MesBuffer;
163int OpBgmSqPort;
164static tagFRAME_INF *frame_info_cam;
165int SceneNp__2;
166int Pause;
167static int CameraMode;
168static int SceneRp;
169static int SceneCnt;
170static int SceneFlg;
171static int SceneSw;
172static float PauseFrame;
173static u_char End;
174static int EndCnt;
175static int BgmOff;
176static int BgmVol;
177static int BgmNo;
178
179void OpeningInit() {
180 wait_now_loading_vsync();
181 InitializeDataBuffer();
182 SetDataBuffer(&VisualData, 7500);
183 MesBuffer = VisualData.Alloc(4312);
184 SetDataBuffer(&CharaDataBuffer__2[0], 253000);
185 SetDataBuffer(&CharaDataBuffer__2[4], 65000);
186 SetDataBuffer(&CharaDataBuffer__2[6], 327000);
187 SetDataBuffer(&PassDataBuffer[0], 15000);
188 SetDataBuffer(&PassDataBuffer[1], 15000);
189 SetDataBuffer(&PassDataBuffer[2], 15000);
190 SetDataBuffer(&testBuffer, 15000);
191 PassReadBuffer = testBuffer.Alloc(15000);
192 SetDataBuffer(&MapDataBuffer, 159500);
193 SetDataBuffer(&WaterBuffer__2, 30000);
194#ifdef PAL
195 SetDataBuffer(&TextureData, 365000);
196#else
197 SetDataBuffer(&TextureData, 355000);
198#endif
199 SetPacketReadBuffer(40000, 273000);
200 OP_MainCamera.SetRef(0, 0.0f, 0.0f, 0.0f);
201 OP_MainCamera.SetPos(0, 0.0f, 0.0f, 0.0f);
202 OP_MainCamera.SetDistance(80.0f);
203 OP_MainCamera.SetHeight(0.0f);
204 OP_MainCamera.SetFollow(0.0f, 0.0f, 0.0f);
205 OP_MainCamera.Step(0);
206 OP_MainCamera.SetSpeed(0.0f);
207 MGSetRenderInfo(800.0f, 6.0f, 65535);
208 wait_now_loading_vsync();
209#ifdef PAL
210 CScript__2.Load("opdat/opening.pal");
211#else
212 CScript__2.Load("opdat/opening.scr");
213#endif
214 wait_now_loading_vsync();
215 LoadMessage();
216 wait_now_loading_vsync();
217 LoadScene();
218 wait_now_loading_vsync();
219 OpA_InitProcess();
220 CameraMode = 0;
221 SceneNp__2 = 0;
222 SceneRp = 0;
223 SceneCnt = 3;
224 SceneFlg = SCENE_READ_IDLE;
225 SceneSw = 0;
226 Pause = 0;
227 End = 0;
228 EndCnt = 0;
229 BgmOff = 0;
230 BgmNo = 0;
231 BgmVol = 127;
232 DispFade.FadeInit(128.0f);
233 DispFade.FadeOutStart(128.0f, 0);
234}
235
244static void LoadMessage() {
245 Mes1.Preset(MES_PRESET_AUTO_PAGE);
246 Mes1.text_x = 90;
247 Mes1.text_y = 350;
248 Mes1.text_rate = 1.0f;
249 Mes1.text_rate_set = 1.0f;
250 Mes1.end_mark = false;
251 Mes1.tex_block = 26;
252 Mes1.tex_buff = MesWinTexBuff_01;
253 Mes1.tail_to_x = 320;
254 Mes1.tail_to_y = 234;
255 Mes1.tail_half_width = 8;
256 Mes1.tail_length = 64;
257 Mes1.grow_x = 310;
258 Mes1.grow_y = 210;
259
260#ifdef PAL
261 switch (LanguageCode) {
262 case LANG_JAPANESE:
263 LoadFile("opdat/optext_0.mes", MesBuffer, 0);
264 break;
265 case LANG_ENGLISH_US:
266 LoadFile("opdat/optext_1.mes", MesBuffer, 0);
267 break;
268 case LANG_ENGLISH_UK:
269 LoadFile("opdat/optext_2.mes", MesBuffer, 0);
270 break;
271 case LANG_FRENCH:
272 LoadFile("opdat/optext_3.mes", MesBuffer, 0);
273 break;
274 case LANG_GERMAN:
275 LoadFile("opdat/optext_4.mes", MesBuffer, 0);
276 break;
277 case LANG_ITALIAN:
278 LoadFile("opdat/optext_5.mes", MesBuffer, 0);
279 break;
280 case LANG_SPANISH:
281 LoadFile("opdat/optext_6.mes", MesBuffer, 0);
282 break;
283 }
284#else
285 switch (LanguageCode) {
286 case LANG_JAPANESE:
287 LoadFile("opdat/fconv.bin", MesBuffer, 0);
288 break;
289 case LANG_ENGLISH_US:
290 LoadFile("opdat/usa/fconv.bin", MesBuffer, 0);
291 break;
292 case LANG_ENGLISH_UK:
293 LoadFile("opdat/usa/fconv.bin", MesBuffer, 0);
294 break;
295 case LANG_FRENCH:
296 LoadFile("opdat/optext_3.mes", MesBuffer, 0);
297 break;
298 case LANG_GERMAN:
299 LoadFile("opdat/optext_4.mes", MesBuffer, 0);
300 break;
301 case LANG_ITALIAN:
302 LoadFile("opdat/optext_5.mes", MesBuffer, 0);
303 break;
304 case LANG_SPANISH:
305 LoadFile("opdat/usa/fconv.bin", MesBuffer, 0);
306 break;
307 }
308#endif
309
310 Mes1.buff = (short *) MesBuffer;
311 Mes1.text = (char *) MesBuffer;
312 Mes1.text += *(short *) (MesBuffer + 2);
313}
314
323static void LoadScene() {
324 char *files[3][2] = {
325 {"opdat/scene/0101acp.sne", "0101acp.cfg"},
326 {"opdat/scene/0101bcp.sne", "0101bcp.cfg"},
327 {"opdat/scene/0104cp.sne", "0104cp.cfg" },
328 };
329 int i;
330
331 for (i = 0; i < 3; i++) {
332 LoadFile(files[i][0], (void *) read_buffer, 0);
333 Cam__2[i].LoadPackData(read_buffer, files[i][1], &PassDataBuffer[i], 0);
334 Cam__2[i].motion_type.state.time = 1.0f;
335 Cam__2[i].motion_type.state.blend_step = 1.0f;
336 Cam__2[i].motion_type.state.motion_no = 0;
337 Cam__2[i].motion_type.state.playing_no = 0;
338 Cam__2[i].motion_type.state.camera = &OP_MainCamera;
339 }
340}
341
342void LoadSceneBG() {
343 CDataAlloc2<1> *buffer;
344 int slot;
345 char *files[126][2] = {
346 {"opdat/scene/0101acp.sne", "0101acp.cfg" },
347 {"opdat/scene/0101bcp.sne", "0101bcp.cfg" },
348 {"opdat/scene/0104cp.sne", "0104cp.cfg" },
349 {"opdat/scene/0104bcp.sne", "0104bcp.cfg" },
350 {"opdat/scene/0105cp.sne", "0105cp.cfg" },
351 {"opdat/scene/0107cp.sne", "0107cp.cfg" },
352 {"opdat/scene/0108cp.sne", "0108cp.cfg" },
353 {"opdat/scene/0109cp.sne", "0109cp.cfg" },
354 {"opdat/scene/0110cp.sne", "0110cp.cfg" },
355 {"opdat/scene/0111cp.sne", "0111cp.cfg" },
356 {"opdat/scene/0112cp.sne", "0112cp.cfg" },
357 {"opdat/scene/0113cp.sne", "0113cp.cfg" },
358 {"opdat/scene/0114acp.sne", "0114acp.cfg" },
359 {"opdat/scene/0114bcp.sne", "0114bcp.cfg" },
360 {"opdat/scene/0114ccp.sne", "0114ccp.cfg" },
361 {"opdat/scene/0114dcp.sne", "0114dcp.cfg" },
362 {"opdat/scene/0114ecp.sne", "0114ecp.cfg" },
363 {"opdat/scene/0114gcp.sne", "0114gcp.cfg" },
364 {"opdat/scene/0114hcp.sne", "0114hcp.cfg" },
365 {"opdat/scene/0114icp.sne", "0114icp.cfg" },
366 {"opdat/scene/0114jcp.sne", "0114jcp.cfg" },
367 {"opdat/scene/0114kcp.sne", "0114kcp.cfg" },
368 {"opdat/scene/0114f1cp.sne", "0114f1cp.cfg"},
369 {"opdat/scene/0114f2cp.sne", "0114f2cp.cfg"},
370 {"opdat/scene/0115cp.sne", "0115cp.cfg" },
371 {"opdat/scene/0116cp.sne", "0116cp.cfg" },
372 {"opdat/scene/0117cp.sne", "0117cp.cfg" },
373 {"opdat/scene/0118cp.sne", "0118cp.cfg" },
374 {"opdat/scene/0119cp.sne", "0119cp.cfg" },
375 {"opdat/scene/0119bcp.sne", "0119bcp.cfg" },
376 {"opdat/scene/0120cp.sne", "0120cp.cfg" },
377 {"opdat/scene/0121cp.sne", "0121cp.cfg" },
378 {"opdat/scene/0122cp.sne", "0122cp.cfg" },
379 {"opdat/scene/0123cp.sne", "0123cp.cfg" },
380 {"opdat/scene/0124cp.sne", "0124cp.cfg" },
381 {"opdat/scene/0125cp.sne", "0125cp.cfg" },
382 {"opdat/scene/0126cp.sne", "0126cp.cfg" },
383 {"opdat/scene/0120cp.sne", "0120cp.cfg" },
384 {"opdat/scene/0128cp.sne", "0128cp.cfg" },
385 {"opdat/scene/0129cp.sne", "0129cp.cfg" },
386 {"opdat/scene/0126cp.sne", "0126cp.cfg" },
387 {"opdat/scene/0130cp.sne", "0130cp.cfg" },
388 {"opdat/scene/0126cp.sne", "0126cp.cfg" },
389 {"opdat/scene/0132cp.sne", "0132cp.cfg" },
390 {"opdat/scene/0132bcp.sne", "0132bcp.cfg" },
391 {"opdat/scene/0132ccp.sne", "0132ccp.cfg" },
392 {"opdat/scene/0133cp.sne", "0133cp.cfg" },
393 {"opdat/scene/0134cp.sne", "0134cp.cfg" },
394 {"opdat/scene/0135cp.sne", "0135cp.cfg" },
395 {"opdat/scene/0136cp.sne", "0136cp.cfg" },
396 {"opdat/scene/0301cp.sne", "0301cp.cfg" },
397 {"opdat/scene/0302cp.sne", "0302cp.cfg" },
398 {"opdat/scene/0303cp.sne", "0303cp.cfg" },
399 {"opdat/scene/0304cp.sne", "0304cp.cfg" },
400 {"opdat/scene/0305cp.sne", "0305cp.cfg" },
401 {"opdat/scene/0306cp.sne", "0306cp.cfg" },
402 {"opdat/scene/0307cp.sne", "0307cp.cfg" },
403 {"opdat/scene/0308cp.sne", "0308cp.cfg" },
404 {"opdat/scene/0401cp.sne", "0401cp.cfg" },
405 {"opdat/scene/0402cp.sne", "0402cp.cfg" },
406 {"opdat/scene/0403cp.sne", "0403cp.cfg" },
407 {"opdat/scene/0404cp.sne", "0404cp.cfg" },
408 {"opdat/scene/0405cp.sne", "0405cp.cfg" },
409 {"opdat/scene/0406cp.sne", "0406cp.cfg" },
410 {"opdat/scene/0407cp.sne", "0407cp.cfg" },
411 {"opdat/scene/0408cp.sne", "0408cp.cfg" },
412 {"opdat/scene/0409cp.sne", "0409cp.cfg" },
413 {"opdat/scene/0410cp.sne", "0410cp.cfg" },
414 {"opdat/scene/0411cp.sne", "0411cp.cfg" },
415 {"opdat/scene/0412cp.sne", "0412cp.cfg" },
416 {"opdat/scene/0413cp.sne", "0413cp.cfg" },
417 {"opdat/scene/0414cp.sne", "0414cp.cfg" },
418 {"opdat/scene/0415cp.sne", "0415cp.cfg" },
419 {"opdat/scene/0416cp.sne", "0416cp.cfg" },
420 {"opdat/scene/0417cp.sne", "0417cp.cfg" },
421 {"opdat/scene/0418cp.sne", "0418cp.cfg" },
422 {"opdat/scene/0419cp.sne", "0419cp.cfg" },
423 {"opdat/scene/0420cp.sne", "0420cp.cfg" },
424 {"opdat/scene/0421cp.sne", "0421cp.cfg" },
425 {"opdat/scene/0423cp.sne", "0423cp.cfg" },
426 {"opdat/scene/0425cp.sne", "0425cp.cfg" },
427 {"opdat/scene/0426cp.sne", "0426cp.cfg" },
428 {"opdat/scene/0427cp.sne", "0427cp.cfg" },
429 {"opdat/scene/0428cp.sne", "0428cp.cfg" },
430 {"opdat/scene/0429cp.sne", "0429cp.cfg" },
431 {"opdat/scene/0430cp.sne", "0430cp.cfg" },
432 {"opdat/scene/0431cp.sne", "0431cp.cfg" },
433 {"opdat/scene/0432cp.sne", "0432cp.cfg" },
434 {"opdat/scene/0433cp.sne", "0433cp.cfg" },
435 {"opdat/scene/0434cp.sne", "0434cp.cfg" },
436 {"opdat/scene/0435cp.sne", "0435cp.cfg" },
437 {"opdat/scene/0436cp.sne", "0436cp.cfg" },
438 {"opdat/scene/0437cp.sne", "0437cp.cfg" },
439 {"opdat/scene/0438cp.sne", "0438cp.cfg" },
440 {"opdat/scene/0439cp.sne", "0439cp.cfg" },
441 {"opdat/scene/0440cp.sne", "0440cp.cfg" },
442 {"opdat/scene/0441cp.sne", "0441cp.cfg" },
443 {"opdat/scene/0442cp.sne", "0442cp.cfg" },
444 {"opdat/scene/0443cp.sne", "0443cp.cfg" },
445 {"opdat/scene/0501cp.sne", "0501cp.cfg" },
446 {"opdat/scene/0502cp.sne", "0502cp.cfg" },
447 {"opdat/scene/0503cp.sne", "0503cp.cfg" },
448 {"opdat/scene/0504cp.sne", "0504cp.cfg" },
449 {"opdat/scene/0505cp.sne", "0505cp.cfg" },
450 {"opdat/scene/0506cp.sne", "0506cp.cfg" },
451 {"opdat/scene/0510cp.sne", "0510cp.cfg" },
452 {"opdat/scene/0511cp.sne", "0511cp.cfg" },
453 {"opdat/scene/0512cp.sne", "0512cp.cfg" },
454 {"opdat/scene/0513cp.sne", "0513cp.cfg" },
455 {"opdat/scene/0514cp.sne", "0514cp.cfg" },
456 {"opdat/scene/0515cp.sne", "0515cp.cfg" },
457 {"opdat/scene/0515bcp.sne", "0515bcp.cfg" },
458 {"opdat/scene/0516cp.sne", "0516cp.cfg" },
459 {"opdat/scene/0517cp.sne", "0517cp.cfg" },
460 {"opdat/scene/0518cp.sne", "0518cp.cfg" },
461 {"opdat/scene/0520cp.sne", "0520cp.cfg" },
462 {"opdat/scene/0521cp.sne", "0521cp.cfg" },
463 {"opdat/scene/0522cp.sne", "0522cp.cfg" },
464 {"opdat/scene/0523cp.sne", "0523cp.cfg" },
465 {"opdat/scene/0524cp.sne", "0524cp.cfg" },
466 {"opdat/scene/0525cp.sne", "0525cp.cfg" },
467 {"opdat/scene/0526cp.sne", "0526cp.cfg" },
468 {"opdat/scene/0527cp.sne", "0527cp.cfg" },
469 {"opdat/scene/0528cp.sne", "0528cp.cfg" },
470 {"opdat/scene/0529cp.sne", "0529cp.cfg" },
471 {"-1", "-1" },
472 };
473
474 if (files[SceneCnt][0] == "-1") {
475 return;
476 }
477
478 switch (SceneFlg) {
479 case SCENE_READ_START:
480 while (ReadBGSync())
481 ;
482
483 if (SceneCnt % 5 == 0) {
484 StartReadBG();
485 }
486
487 LoadFileBG(files[SceneCnt][0], (u_long128 *) PassReadBuffer, 0);
488 SceneFlg = SCENE_READ_WAIT;
489 break;
490 case SCENE_READ_WAIT:
491 if (ReadBGSync()) {
492 break;
493 }
494
495 slot = SceneRp;
496 buffer = &PassDataBuffer[slot];
497 buffer->used = 0;
498 Cam__2[slot].LoadPackData((u_int *) PassReadBuffer, files[SceneCnt][1], buffer, 0);
499 SceneCnt++;
500 SceneRp++;
501
502 if (SceneRp > 2) {
503 SceneRp = 0;
504 }
505
506 SceneFlg = SCENE_READ_IDLE;
507 break;
508 case SCENE_READ_IDLE:
509 break;
510 }
511}
512
513int OpeningLoop() {
514 ReadBG();
515 PauseProcess();
516
517 if (Pause == 0) {
518 CScript__2.Step();
519 WaitKeyProcess();
520 SceneChange();
521 }
522
523 MotionProcess();
524 SoundProcess();
525 DrawProcess();
526
527 if (End) {
528 if (EndCnt < 128) {
529 EndCnt++;
530 } else {
531 SoundStop();
532 MGSetBGColor(0.0f, 0.0f, 0.0f, 128.0f);
533 FadeCansel();
534 return 1;
535 }
536 }
537
538 /* These type-only names preserve the second exit's background-colour argument state. */
539 typedef float ExitState0, ExitState1;
540
541 if (CScript__2.end) {
542 MGSetBGColor(0.0f, 0.0f, 0.0f, 128.0f);
543 FadeCansel();
544 return 1;
545 }
546
547 CSnd.Step();
548 return 0;
549}
550
559static void SceneChange() {
560 switch (CScript__2.load_no) {
561 case OP_SCENE_NORUNE:
562 OpB_LoadDataBG();
563 break;
564 case OP_SCENE_TOAN_HOUSE:
565 OpB_LoadDataBG2();
566 break;
567 case OP_SCENE_NORUNE_NIGHT:
568 OpC_LoadDataBG();
569 break;
570 case OP_SCENE_DANCE:
571 OpC_LoadDataBG2();
572 break;
573 case OP_SCENE_MAJIN:
574 OpC_LoadDataBG3();
575 break;
576 case OP_SCENE_NORUNE_RUINED:
577 OpC_LoadDataBG4();
578 break;
579 case OP_SCENE_NORUNE_BURNING:
580 OpC_LoadDataBG5();
581 break;
582 case OP_SCENE_SEIREI_KING:
583 OpD_LoadDataBG();
584 break;
585 case OP_SCENE_MEADOW:
586 OpD_LoadDataBG2();
587 break;
588 }
589
590 switch (CScript__2.init_no) {
591 case OP_SCENE_NORUNE:
592 SoundStop();
593 OpB_InitProcess();
594 break;
595 case OP_SCENE_TOAN_HOUSE:
596 OpB_InitProcess2();
597 break;
598 case OP_SCENE_NORUNE_NIGHT:
599 SoundStop();
600 OpC_InitProcess();
601 break;
602 case OP_SCENE_DANCE:
603 OpC_InitProcess2();
604 break;
605 case OP_SCENE_MAJIN:
606 SoundStop();
607 OpC_InitProcess3();
608 break;
609 case OP_SCENE_NORUNE_RUINED:
610 OpC_InitProcess4();
611 break;
612 case OP_SCENE_NORUNE_BURNING:
613 OpC_InitProcess5();
614 break;
615 case OP_SCENE_SEIREI_KING:
616 SoundStop();
617 OpD_InitProcess();
618 break;
619 case OP_SCENE_MEADOW:
620 SoundStop();
621 OpD_InitProcess2();
622 break;
623 }
624}
625
634static void PauseProcess() {
635 static int endflg = 0;
636
637 if (DispFade.GetRate() != 0.0) {
638 return;
639 }
640
641 if (!endflg) {
642 if (End) {
643 return;
644 }
645
646 if (Pause == 0) {
647 if (!GamePad.Down(PAD_START)) {
648 return;
649 }
650
651 CSnd.Stop(MIDI_PORT_BGM);
652
653 if (CScript__2.scene) {
654 CSnd.Stop(MIDI_PORT_AMBIENT);
655 }
656
657 CSnd.SetVol(MIDI_PORT_SE_TITLE, 0);
658 CSnd.SetVol(MIDI_PORT_SE_DEFAULT, 0);
659 CSnd.SetVol(MIDI_PORT_UNK_D, 0);
660 CSnd.SetVol(MIDI_PORT_SE_SPECIAL, 0);
661 Pause = 1;
662 endflg = 0;
663 PauseFrame = Cam__2[SceneNp__2].motion_type.state.time;
664 } else if (Pause == 1) {
665 if (GamePad.Down(PAD_CIRCLE)) {
666 endflg = 1;
667 CSnd.SetVol(MIDI_PORT_SE_TITLE, 256);
668 CSnd.SetVol(MIDI_PORT_SE_DEFAULT, 256);
669 CSnd.SetVol(MIDI_PORT_UNK_D, 256);
670 CSnd.SetVol(MIDI_PORT_SE_SPECIAL, 256);
671
672 if (CScript__2.scene) {
673 CSnd.SQ_RePlay(MIDI_PORT_AMBIENT);
674 }
675
676 if (OpBgmSqPort != -1) {
677 CSnd.SQ_RePlay(MIDI_PORT_BGM);
678 }
679 } else if (GamePad.Down(PAD_CROSS)) {
680 while (ReadBGSync())
681 ;
682
683 End = 1;
684 DispFade.FadeOutStart(1.0f, 0);
685 }
686 }
687 } else {
688 endflg = 0;
689 Pause = 0;
690 }
691}
692
701static void SoundStop() {
702 SndStopAllSe();
703 CSnd.Stop(MIDI_PORT_BGM);
704 CSnd.StopVoice(0);
705}
706
715static void WaitKeyProcess() {
716 static int flg = 0;
717 static int cnt = 0;
718
719 if (CScript__2.mes_wait) {
720 if (!flg) {
721 PauseFrame = Cam__2[SceneNp__2].motion_type.state.time;
722 flg = 1;
723 }
724
725 if (Pause) {
726 return;
727 }
728
729 if (GamePad.Down(PAD_CIRCLE) || GamePad.Down(PAD_CROSS)) {
730 if (Mes1.State() == CLSMES_PAGE_WAIT) {
731 Mes1.text_rate = 1.0f;
732 Mes1.text_rate_set = 1.0f;
733 Mes1.GoNextPage();
734 } else if (Mes1.State() == CLSMES_SHOWN) {
735 CScript__2.mes_wait = false;
736 flg = 0;
737 } else {
738 Mes1.text_rate = 0;
739 Mes1.text_rate_set = 0;
740 }
741 }
742 } else {
743 flg = 0;
744 cnt = 0;
745 Mes1.text_rate = 1.0f;
746 Mes1.text_rate_set = 1.0f;
747 }
748}
749
758static void MotionProcess() {
759 // PAL runs at 50 frames a second, so its fade speeds are raised by a fifth.
760 switch (CScript__2.fade) {
761 case TSFADE_IN_BLACK:
762#ifdef PAL_TIMING
763 DispFade.FadeInStart(1.2f * CScript__2.fade_speed, 0);
764#else
765 DispFade.FadeInStart(CScript__2.fade_speed, 0);
766#endif
767 CScript__2.fade = TSFADE_NONE;
768 break;
769 case TSFADE_OUT_BLACK:
770#ifdef PAL_TIMING
771 DispFade.FadeOutStart(1.2f * CScript__2.fade_speed, 0);
772#else
773 DispFade.FadeOutStart(CScript__2.fade_speed, 0);
774#endif
775 CScript__2.fade = TSFADE_NONE;
776 break;
777 case TSFADE_IN_WHITE:
778#ifdef PAL_TIMING
779 DispFade.FadeInStart(1.2f * CScript__2.fade_speed, 1);
780#else
781 DispFade.FadeInStart(CScript__2.fade_speed, 1);
782#endif
783 CScript__2.fade = TSFADE_NONE;
784 break;
785 case TSFADE_OUT_WHITE:
786#ifdef PAL_TIMING
787 DispFade.FadeOutStart(1.2f * CScript__2.fade_speed, 1);
788#else
789 DispFade.FadeOutStart(CScript__2.fade_speed, 1);
790#endif
791 CScript__2.fade = TSFADE_NONE;
792 break;
793 }
794
795 if (CScript__2.motion_req) {
796 if (!ReadBGSync()) {
797 Op_MotionInfo.start = CScript__2.motion_start;
798 Op_MotionInfo.end = CScript__2.motion_end;
799 Op_MotionInfo.speed = CScript__2.motion_step;
800 CScript__2.motion_req = false;
801
802 if (SceneSw == 1) {
803 SceneNp__2++;
804
805 if (SceneNp__2 > 2) {
806 SceneNp__2 = 0;
807 }
808
809 SceneFlg = SCENE_READ_START;
810 }
811
812 SceneSw = 1;
813 Cam__2[SceneNp__2].motion_type.state.time = (float) CScript__2.motion_start;
814 } else {
815 while (ReadBGSync())
816 ;
817 }
818 }
819
820 if (Cam__2[SceneNp__2].motion_type.state.time > (float) (CScript__2.motion_end - 1)) {
821 Cam__2[SceneNp__2].motion_type.state.time = (float) (CScript__2.motion_end - 1);
822 }
823
824 if (CameraMode == 0) {
825 Cam__2[SceneNp__2].motion_type.state.camera = &OP_MainCamera;
826
827 if (PauseFrame > (float) (CScript__2.motion_end - 1)) {
828 PauseFrame = (float) (CScript__2.motion_end - 1);
829 }
830
831 if (Pause) {
832 Cam__2[SceneNp__2].motion_type.state.time = PauseFrame - CScript__2.motion_step;
833 }
834
835 if (CScript__2.mes_wait == 1) {
836 Cam__2[SceneNp__2].motion_type.state.time = PauseFrame - CScript__2.motion_step;
837 }
838
839 SetMotionEX(Cam__2[SceneNp__2].frame, &Cam__2[SceneNp__2].motion_type, &Op_MotionInfo, &Cam__2[SceneNp__2].motion_type.state, frame_info_cam);
840 LoadSceneBG();
841 }
842
843 if (!Pause) {
844 switch (CScript__2.scene) {
845 case OP_SCENE_DUNGEON_SQUARE:
846 OpA_MotionProcess();
847 break;
848 case OP_SCENE_NORUNE:
849 OpB_MotionProcess();
850 break;
851 case OP_SCENE_TOAN_HOUSE:
852 OpB_MotionProcess();
853 break;
854 case OP_SCENE_NORUNE_NIGHT:
855 OpC_MotionProcess();
856 break;
857 case OP_SCENE_DANCE:
858 OpC_MotionProcess();
859 break;
860 case OP_SCENE_MAJIN:
861 OpC_MotionProcess();
862 break;
863 case OP_SCENE_NORUNE_RUINED:
864 OpC_MotionProcess();
865 break;
866 case OP_SCENE_NORUNE_BURNING:
867 OpC_MotionProcess();
868 break;
869 case OP_SCENE_SEIREI_KING:
870 OpD_MotionProcess();
871 break;
872 case OP_SCENE_MEADOW:
873 OpD_MotionProcess();
874 break;
875 }
876 }
877}
878
887static void SoundProcess() {
888 if (CScript__2.se_stop == 0) {
889 if (CScript__2.se_voice != 0) {
890 switch (CScript__2.se_kind) {
891 case TSSE_EFFECT:
892 OpPlayVolSE(MIDI_PORT_SE_DEFAULT, CScript__2.se_no, CScript__2.se_voice, 1.0f);
893 break;
894 case TSSE_SPECIAL:
895 OpPlayVolSE(MIDI_PORT_SE_SPECIAL, CScript__2.se_no, CScript__2.se_voice, 1.0f);
896 break;
897 }
898
899 CScript__2.se_voice = 0;
900 }
901 } else {
902 switch (CScript__2.se_kind) {
903 case TSSE_EFFECT:
904 CSnd.SE_Stop(MIDI_PORT_SE_DEFAULT, CScript__2.se_no, CScript__2.se_voice, 0);
905 break;
906 case TSSE_SPECIAL:
907 CSnd.SE_Stop(MIDI_PORT_SE_SPECIAL, CScript__2.se_no, CScript__2.se_voice, 0);
908 break;
909 }
910
911 CScript__2.se_stop = false;
912 }
913
914 if (CScript__2.bgm_fade != 0) {
915 switch (CScript__2.se_kind) {
916 case TSSE_ALL:
917#ifdef PAL_TIMING
918 CScript__2.bgm_fade = 1.2f * CScript__2.bgm_fade;
919#endif
920 CSnd.Fade(MIDI_PORT_BGM, (float) CScript__2.bgm_fade / 2.0f, CScript__2.se_fade_time);
921 CSnd.Fade(MIDI_PORT_AMBIENT, (float) CScript__2.bgm_fade, CScript__2.se_fade_time);
922 CSnd.Fade(MIDI_PORT_UNK_2, (float) CScript__2.bgm_fade, CScript__2.se_fade_time);
923 CSnd.Fade(MIDI_PORT_SE_TITLE, (float) CScript__2.bgm_fade, CScript__2.se_fade_time);
924 CSnd.Fade(MIDI_PORT_SE_DEFAULT, (float) CScript__2.bgm_fade, CScript__2.se_fade_time);
925 CSnd.Fade(MIDI_PORT_UNK_D, (float) CScript__2.bgm_fade, CScript__2.se_fade_time);
926 CSnd.Fade(MIDI_PORT_SE_SPECIAL, (float) CScript__2.bgm_fade, CScript__2.se_fade_time);
927 break;
928 }
929
930 CScript__2.bgm_fade = 0;
931 }
932
933 switch (CScript__2.scene) {
934 case OP_SCENE_DUNGEON_SQUARE:
935 OpA_SoundProcess();
936 break;
937 case OP_SCENE_NORUNE:
938 OpB_SoundProcess();
939 break;
940 case OP_SCENE_TOAN_HOUSE:
941 OpB_SoundProcess();
942 break;
943 case OP_SCENE_NORUNE_NIGHT:
944 OpC_SoundProcess();
945 break;
946 case OP_SCENE_DANCE:
947 OpC_SoundProcess();
948 break;
949 case OP_SCENE_MAJIN:
950 OpC_SoundProcess();
951 break;
952 case OP_SCENE_NORUNE_RUINED:
953 OpC_SoundProcess();
954 break;
955 case OP_SCENE_NORUNE_BURNING:
956 OpC_SoundProcess();
957 break;
958 case OP_SCENE_SEIREI_KING:
959 OpD_SoundProcess();
960 break;
961 case OP_SCENE_MEADOW:
962 OpD_SoundProcess();
963 break;
964 }
965}
966
975static void DrawProcess() {
976 sceVu0FVECTOR position;
977 sceVu0FMATRIX camera;
978 sceVu0FMATRIX view;
979 sceVu0FMATRIX unit;
980 sceGsTex0 tex0;
981
982 OP_MainCamera.GetPos(position);
983 SndSetCamera(&OP_MainCamera);
984 OP_MainCamera.GetCameraMatrix(camera);
985
986 if (CScript__2.scene == OP_SCENE_MAJIN || CScript__2.scene == OP_SCENE_SEIREI_KING) {
987 OP_MainCamera.Step(1);
988 }
989
990 sceVu0UnitMatrix(unit);
991 sceVu0MulMatrix(view, unit, camera);
992
993 if (CScript__2.scene != OP_SCENE_NORUNE) {
994 MGSetViewMatrix(view, position);
995 } else {
996 MGSetViewMatrix(view);
997 }
998
999 sceVif1PkCall(Vif1Packet, (u_long128 *) Vu_prog0f, 0);
1000 sceVif1PkTerminate(Vif1Packet);
1001
1002 switch (CScript__2.scene) {
1003 case OP_SCENE_DUNGEON_SQUARE:
1004 OpA_DrawProcess();
1005 break;
1006 case OP_SCENE_NORUNE:
1007 OpB_DrawProcess();
1008 break;
1009 case OP_SCENE_TOAN_HOUSE:
1010 OpB_DrawProcess();
1011 break;
1012 case OP_SCENE_NORUNE_NIGHT:
1013 OpC_DrawProcess();
1014 break;
1015 case OP_SCENE_DANCE:
1016 OpC_DrawProcess();
1017 break;
1018 case OP_SCENE_MAJIN:
1019 OpC_DrawProcess();
1020 break;
1021 case OP_SCENE_NORUNE_RUINED:
1022 OpC_DrawProcess();
1023 break;
1024 case OP_SCENE_NORUNE_BURNING:
1025 OpC_DrawProcess();
1026 break;
1027 case OP_SCENE_SEIREI_KING:
1028 OpD_DrawProcess();
1029 break;
1030 case OP_SCENE_MEADOW:
1031 OpD_DrawProcess();
1032 break;
1033 }
1034
1035 DrawMess();
1036
1037 if (Pause == 1) {
1038 setbilinear(0);
1039 MGFillBox(CRect<int>(0, 0, 10240, SCREEN_HEIGHT * 8), 0, 0, 0, 64);
1040 TexManager.ReloadTexture(Vif1Packet, 19);
1041
1042#ifdef PAL
1043 switch (LanguageCode) {
1044 case LANG_JAPANESE:
1045 set2DSprite(GetVif1Packet(), TexManager.GetTexture("pause", -1), CRect<int>(256, 160, 128, 128), CRect<int>(0, 0, 128, 128), 128);
1046 break;
1047 case LANG_ENGLISH_US:
1048 set2DSprite(GetVif1Packet(), TexManager.GetTexture("pause_e", -1), CRect<int>(256, 160, 128, 128), CRect<int>(0, 0, 128, 128), 128);
1049 break;
1050 case LANG_ENGLISH_UK:
1051 set2DSprite(GetVif1Packet(), TexManager.GetTexture("pause_e", -1), CRect<int>(256, 160, 128, 128), CRect<int>(0, 0, 128, 128), 128);
1052 break;
1053 case LANG_FRENCH:
1054 set2DSprite(GetVif1Packet(), TexManager.GetTexture("pause_f", -1), CRect<int>(256, 160, 128, 128), CRect<int>(0, 0, 128, 128), 128);
1055 break;
1056 case LANG_GERMAN:
1057 set2DSprite(GetVif1Packet(), TexManager.GetTexture("pause_g", -1), CRect<int>(256, 160, 128, 128), CRect<int>(0, 0, 128, 128), 128);
1058 break;
1059 case LANG_ITALIAN:
1060 set2DSprite(GetVif1Packet(), TexManager.GetTexture("pause_i", -1), CRect<int>(256, 160, 128, 128), CRect<int>(0, 0, 128, 128), 128);
1061 break;
1062 case LANG_SPANISH:
1063 set2DSprite(GetVif1Packet(), TexManager.GetTexture("pause_s", -1), CRect<int>(256, 160, 128, 128), CRect<int>(0, 0, 128, 128), 128);
1064 break;
1065 }
1066
1067#else
1068 set2DSprite(GetVif1Packet(), TexManager.GetTexture("pause_e", -1), CRect<int>(256, 160, 128, 128), CRect<int>(0, 0, 128, 128), 128);
1069#endif
1070 setbilinear(1);
1071 }
1072
1073 MGGetFBuffBackTex(&tex0);
1074
1075 CTexture texture;
1076
1077 texture.tex0 = *(u_long *) &tex0;
1078#ifdef PAL
1079 set2DSprite(Vif1Packet, &texture, CRect<int>(0, 0, 640, SCREEN_HEIGHT), CRect<int>(0, 0, 640, SCREEN_HALF_HEIGHT), 128, 128, 128, 40);
1080#else
1081 set2DSprite(Vif1Packet, &texture, CRect<int>(0, 0, 640, 448), CRect<int>(0, 0, 640, 224), 128, 128, 128, 35);
1082#endif
1083 DispFade.FadeIn(Vif1Packet);
1084 DispFade.FadeOut(Vif1Packet);
1085}
1086
1095static void DrawMess() {
1096 int offset;
1097 int center;
1098
1099 if (CScript__2.scene > OP_SCENE_NORUNE_RUINED) {
1100 Mes1.auto_page = false;
1101 }
1102
1103 if (CScript__2.mes_no == 0) {
1104 return;
1105 }
1106
1107 TexManager.ReloadTexture(Vif1Packet, Mes1.tex_block);
1108
1109 static int no = 0;
1110
1111 if (CScript__2.mes_no != no) {
1112 no = CScript__2.mes_no;
1113 Mes1MakeFlg = 1;
1114 } else {
1115 if (!Pause) {
1116 if (CScript__2.mes_timer > CScript__2.motion_step) {
1117 CScript__2.mes_timer -= CScript__2.motion_step;
1118 } else {
1119 CScript__2.mes_no = 0;
1120 }
1121 }
1122
1123 Mes1.end_mark = false;
1124
1125 if (CScript__2.mes_wait) {
1126 CScript__2.mes_timer = 2.0f * CScript__2.motion_step;
1127
1128 if (Mes1.State() == CLSMES_SHOWN || (Mes1.auto_page == 0 && Mes1.State() == CLSMES_PAGE_WAIT)) {
1129 static int cnt = 0;
1130
1131 if (cnt < 16) {
1132 Mes1.end_mark = true;
1133 } else {
1134 Mes1.end_mark = false;
1135 }
1136
1137 cnt++;
1138
1139 if (cnt > 31) {
1140 cnt = 0;
1141 }
1142 } else {
1143 Mes1.end_mark = false;
1144 }
1145 }
1146 }
1147
1148 Mes1.auto_page_wait = CScript__2.mes_page_wait;
1149 Mes1.text_x = CScript__2.mes_x;
1150 Mes1.text_y = CScript__2.mes_y;
1151
1152 if (CScript__2.mes_tail_x == 0) {
1153 Mes1.tail_length = 0;
1154 Mes1.grow_x = CScript__2.mes_x;
1155 Mes1.grow_y = CScript__2.mes_y;
1156 } else {
1157 Mes1.tail_length = 64;
1158 Mes1.tail_to_x = CScript__2.mes_tail_x;
1159 Mes1.tail_to_y = CScript__2.mes_tail_y;
1160 Mes1.grow_x = CScript__2.mes_x;
1161 Mes1.grow_y = CScript__2.mes_y;
1162 }
1163
1164 center = Mes1.win_x + (Mes1.win_width >> 1);
1165 offset = (center - Mes1.tail_to_x) >> 2;
1166 Mes1.tail_x = center - offset;
1167
1168 if (CScript__2.mes_tail_x != 0) {
1169 if (offset > 0) {
1170 Mes1.tail_length += offset / 3;
1171 } else {
1172 Mes1.tail_length -= offset / 3;
1173 }
1174 }
1175
1176 if (Mes1.grow_y > Mes1.tail_to_y) {
1177 Mes1.tail_y = Mes1.win_y + 20;
1178 } else {
1179 Mes1.tail_y = Mes1.win_y + Mes1.win_height - 20;
1180 }
1181
1182 Mes1.fade_speed = 0.1f;
1183
1184 if (Mes1MakeFlg) {
1185 Mes1MakeFlg = Mes1.MakeMesWin(CScript__2.mes_no);
1186 }
1187
1188 Mes1.Step();
1189 Mes1.AbsFukidashiIn();
1190 Mes1.DrawMesWin();
1191}
1192
1193void OpBgmPlay() {
1194 int volumes[8] = {82, 106, 64, 69, 91, 92, 95, 108};
1195
1196 if (BgmOff == 0) {
1197 CSnd.SQ_Play(MIDI_PORT_BGM, 0);
1198 } else {
1199 CSnd.SQ_Play(MIDI_PORT_BGM, 0, 0);
1200 }
1201
1202 BgmVol = volumes[BgmNo];
1203 BgmNo++;
1204}
1205
1206void OpPlayVolPanSE(float *position, float near_dist, float far_dist, int group, int no, int voice) {
1207 float volume;
1208 float pan;
1209 short *se_info;
1210 short base_volume;
1211 int level;
1212 int se_index;
1213 int pan_level;
1214
1215 SndGetVolPan(&volume, &pan, position, near_dist, far_dist);
1216
1217 if (pan < -1.0f) {
1218 pan = -1.0f;
1219 }
1220
1221 if (pan > 1.0f) {
1222 pan = 1.0f;
1223 }
1224
1225 pan_level = (int) (63.0f * pan) + 64;
1226 se_index = CSnd.GetSeNo(no, voice);
1227 se_info = CSnd.GetSeInfTbl();
1228 base_volume = se_info[se_index * 2 + 1];
1229 level = (int) ((float) base_volume * volume);
1230
1231 if (level < 0) {
1232 level = 0;
1233 }
1234
1235 if (level > 127) {
1236 level = 127;
1237 }
1238
1239 CSnd.SE_Play(group, no, voice, pan_level, 127, level, 0);
1240}
1241
1242void OpSetVolPanSE(float *position, float near_dist, float far_dist, int group, int no, int voice) {
1243 float volume;
1244 float pan;
1245 short *se_info;
1246 short base_volume;
1247 int level;
1248 int se_index;
1249 int pan_level;
1250
1251 SndGetVolPan(&volume, &pan, position, near_dist, far_dist);
1252
1253 if (pan < -1.0f) {
1254 pan = -1.0f;
1255 }
1256
1257 if (pan > 1.0f) {
1258 pan = 1.0f;
1259 }
1260
1261 pan_level = (int) (63.0f * pan) + 64;
1262 CSnd.SE_SetPan(group, no, voice, pan_level, 0);
1263 se_index = CSnd.GetSeNo(no, voice);
1264 se_info = CSnd.GetSeInfTbl();
1265 base_volume = se_info[se_index * 2 + 1];
1266 level = (int) ((float) base_volume * volume);
1267
1268 if (level < 0) {
1269 level = 0;
1270 }
1271
1272 if (level > 127) {
1273 level = 127;
1274 }
1275
1276 CSnd.SE_SetVol(group, no, voice, level, 0);
1277}
1278
1279void OpPlayVolSE(int group, int no, int voice, float volume) {
1280 short *se_info;
1281 short base_volume;
1282 int se_index;
1283 int level;
1284
1285 se_index = CSnd.GetSeNo(no, voice);
1286 se_info = CSnd.GetSeInfTbl();
1287 base_volume = se_info[se_index * 2 + 1];
1288 level = (int) ((float) base_volume * volume);
1289
1290 if (level < 0) {
1291 level = 0;
1292 }
1293
1294 if (level > 127) {
1295 level = 127;
1296 }
1297
1298 CSnd.SE_Play(group, no, voice, 64, 127, level, 0);
1299}
1300
1301int OpGetVolSQ(int no) {
1302 switch (no) {
1303 case 0:
1304 return CSnd.GetMidiState()->port[0].sequence[0]->volume;
1305 case 1:
1306 return CSnd.GetMidiState()->port[0].sequence[0]->volume;
1307 }
1308 PORT_RETURN(0);
1309}
1310
1311void FadeCansel() {
1312 MIDI_STATE *state;
1313
1314 state = CSnd.GetMidiState();
1315 state->port[0].fade[0].active = false;
1316 state->port[2].fade[0].active = false;
1317 state->port[1].fade[1].active = false;
1318 state->port[4].fade[1].active = false;
1319 state->port[5].fade[1].active = false;
1320 state->port[6].fade[1].active = false;
1321 CSnd.SetVol(MIDI_PORT_SE_TITLE, 256);
1322 CSnd.SetVol(MIDI_PORT_SE_DEFAULT, 256);
1323 CSnd.SetVol(MIDI_PORT_UNK_D, 256);
1324 CSnd.SetVol(MIDI_PORT_SE_SPECIAL, 256);
1325 CSnd.Step();
1326}
1327
1328/* The classes the loader places in the world, declared here rather than reached through headers of
1329 their own because each is another unit's to type. Only the members this file touches are named;
1330 the extents are the sizes the executable gives the objects below. */
1331
1332/* A frame parented to an object, which is what lets the world transform drive a model. */
1333class CObjectFrame : public CObject {
1334public:
1335 CFrameVu1 *frame[4];
1336 s32 rotation_changed;
1337 s32 draw_on;
1339 virtual void FrameObjectOnOff(char *name, int on);
1340 virtual void Draw();
1341
1342 void SetFrame(CFrameVu1 *frame, int level);
1343};
1344
1345/* One piece of scenery. A map holds a table of them, hands each its model, and drives them through
1346 the object dispatch like anything else in the world. */
1347class CMapObject : public CObjectFrame {
1348public:
1350 CFrameVu1 *unk_D4;
1353 float unk_E0;
1354 int unk_34;
1355 int handle;
1356 char unk_EC[4];
1357
1358 virtual void Draw();
1359
1360 void Initialize();
1361 void DrawShadow(int fast);
1362};
1363
1364/* One row of the table a map sorts its scenery by. The loader writes row one and no other, and
1365 what it writes there are the four distances a level-of-detail object changes model at. */
1366class CategoryAttr {
1367public:
1368 float lod[4];
1369 int lowest;
1370 int highest;
1371};
1372
1373/* A run of frames the world draws as one. */
1374class CMap {
1375public:
1377 char unk_180[2416];
1378
1379 CMapObject *SetObject(CFrameVu1 *frame, int category_no, int handle);
1380 CMapObject *SetObject(int no, CFrameVu1 *frame, int category_no, int handle);
1381 CMapObject *GetObject(int no);
1382};
1383
1384/* One looping object animation a definition file registers: a frame is found by name and then
1385 driven between two motion numbers at a rate, with a scale of its own. */
1386class OBJ_ANIME_SEQ {
1387public:
1388 char name[16];
1389 int type;
1391 char unk_18[8];
1392 sceVu0FVECTOR start;
1393 sceVu0FVECTOR unk_30;
1394 float step_x;
1395 float step_y;
1396 float step_z;
1397 char unk_4C[60];
1398
1399 void Initialize();
1400};
1401
1402void InitObjAnime(CFrame *frame, OBJ_ANIME_SEQ *sequence);
1403
1404/* How far the scene's fog reaches and what colour it is. The four rates are the near and far
1405 planes and the two densities the renderer takes; the editor's own pair below shadows them and is
1406 never handed to the renderer here. */
1407float op_fogRate[4] = {1000.0f, 3500.0f, 0.0f, 255.0f};
1408u_char op_fogColor[3] = {96, 160, 239};
1409
1410static int debugModeFlag = 1;
1411static float run_speed = 1.0f;
1412
1413/* The water plane a definition file may place. The four corners are built from one width and one
1414 depth, so the quad is always centred on the position and always axis-aligned; everything after
1415 them is what the simulation reads. */
1416static sceVu0FVECTOR WaterV1;
1417static sceVu0FVECTOR WaterV2;
1418static sceVu0FVECTOR WaterV3;
1419static sceVu0FVECTOR WaterV4;
1420static sceVu0FVECTOR WaterPos;
1421static u_char WaterR;
1422static u_char WaterG;
1423static u_char WaterB;
1424static int WaterFlag;
1425static int WaterMeshW;
1426static int WaterMeshH;
1427static float WaterShake;
1428static float WaterCourant;
1429static float WaterDecline;
1430static float WaterAmplitude;
1431static float WaterRefraction;
1432
1433/* The two lists the loader appends to as it goes: the shapes a scene is asked collision questions
1434 against, and the models that cast its shadows. */
1435static CFrameVu1 *ColModel[64];
1436static int ColModelCount;
1437static CFrameVu1 *ShadowModel[64];
1438static int shadowModelCount;
1439
1440static int animeSpeed1;
1441static int animeSpeed2;
1442
1443/* One command of the definition language: the number the loader knows it by, how many arguments it
1444 takes, and one type per argument. A type-0 argument is a quoted string, a type-1 one a number
1445 behind a comma and a type-2 one a number standing on its own. The rows are read as plain `int`
1446 because that is how the reader takes them. */
1447static int TEIGI_GRD_IMG[] = {0, 2, TSARG_STRING, TSARG_COMMA_VALUE};
1448static int TEIGI_BLD_IMG[] = {1, 2, TSARG_STRING, TSARG_COMMA_VALUE};
1449static int TEIGI_SKY_IMG[] = {2, 2, TSARG_STRING, TSARG_COMMA_VALUE};
1450static int TEIGI_FIRE_IMG[] = {31, 1, TSARG_STRING};
1451static int TEIGI_GRD[] = {3, 7, TSARG_STRING, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1452static int TEIGI_BLD[] = {4, 8, TSARG_STRING, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1453static int TEIGI_LOD[] = {5, 1, TSARG_STRING};
1454static int TEIGI_CRD[] = {6, 1, TSARG_STRING};
1455static int TEIGI_SKY[] = {7, 2, TSARG_STRING, TSARG_COMMA_VALUE};
1456static int TEIGI_FOG[] = {8, 7, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1457static int TEIGI_AMBIENT[] = {9, 3, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1458static int TEIGI_LIGHT_COL[] = {10, 7, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1459static int TEIGI_FARCLIP[] = {11, 1, TSARG_VALUE};
1460static int TEIGI_BG_COL2[] = {12, 3, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1461static int TEIGI_BG_COL[] = {12, 3, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1462static int TEIGI_NORMALCLIP_OFF[] = {13, 1, TSARG_VALUE};
1463static int TEIGI_RUN_SPEED[] = {14, 1, TSARG_VALUE};
1464static int TEIGI_EDIT_FOG[] = {16, 7, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1465static int TEIGI_WATER_SET[] = {17, 5, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1466static int TEIGI_WATER_RGB[] = {18, 3, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1467static int TEIGI_WATER_PARAM[] = {19, 7, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1468static int TEIGI_LEVEL_FAR[] = {21, 4, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1469static int TEIGI_DebugFlag[] = {22, 1, TSARG_VALUE};
1470static int TEIGI_AnimeSpeed[] = {23, 2, TSARG_VALUE, TSARG_COMMA_VALUE};
1471static int TEIGI_UPER[] = {24, 8, TSARG_STRING, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1472static int TEIGI_UPR_IMG[] = {25, 2, TSARG_STRING, TSARG_COMMA_VALUE};
1473static int TEIGI_PLIGHT[] = {26, 9, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1474static int TEIGI_ADD_CRD[] = {27, 7, TSARG_STRING, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1475static int TEIGI_DEF_PATS[] = {50, 0};
1476static int TEIGI_DEF_ENDS[] = {51, 0};
1477static int TEIGI_S_VOLUME[] = {28, 7, TSARG_STRING, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1478static int TEIGI_PROJECTION[] = {29, 1, TSARG_VALUE};
1479static int TEIGI_OBJ_ROT[] = {30, 7, TSARG_STRING, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1480static int TEIGI_FIRE[] = {32, 5, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1481static int TEIGI_MAPINFO[] = {80, 1, TSARG_STRING};
1482static int TEIGI_PT_BASE[] = {52, 2, TSARG_STRING, TSARG_COMMA_VALUE};
1483static int TEIGI_PT_COLS[] = {54, 1, TSARG_STRING};
1484static int TEIGI_MAPD[] = {53, 32, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1485static int TEIGI_PT_FIRE[] = {55, 3, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1486static int TEIGI_PT_WATER[] = {56, 9, TSARG_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE, TSARG_COMMA_VALUE};
1487
1488/* The projection the scene is drawn with, and the editor's own fog beside the renderer's. */
1489static float Projection = 800.0f;
1490static u_char editFogColor[3] = {96, 160, 239};
1491static float editFogRate[4] = {1000.0f, 3500.0f, 0.0f, 255.0f};
1492
1493/* The four distances a level-of-detail object changes model at, which every such object in a scene
1494 shares because the loader copies them into the map's own row rather than into the object. */
1495static float levelOfDitialZ[4] = {200.0f, 400.0f, 800.0f, 1600.0f};
1496
1497/* One of the ninety-six lights a definition file may place. The first word is what the file has
1498 asked for and everything after it is what it asked for it to be, which is why the parser clears
1499 only that word and the loader writes the rest. */
1501 int used;
1502 float x;
1503 float y;
1504 float z;
1505 u_char r;
1506 u_char g;
1507 u_char b;
1508 char unk_13[1];
1509 u_int arg7;
1510 u_int arg8;
1511 float arg9;
1512};
1513
1514static POINT_LIGHT pointLight[96];
1515static int pointLightStack;
1516
1517/* The parse state the two readers share. `argLevel` is the nesting the caller has reached, which
1518 is what gives each level of a definition its own row of the two argument buffers; the file size
1519 is read once by the loader and then bounds every walk over the text. */
1520static int argLevel;
1521static int teigiFileSize;
1522
1523/* The definition file is read straight into this one off the disc, and the drive transfers by
1524 DMA into whole cache lines. */
1525static char teigiBuff[4096] __attribute__((aligned(64)));
1526static char argStrBuff[128][64];
1527static float argValBuff[128][64];
1528
1529/* The four model names one level-of-detail object is built from, as the loader hands them to the
1530 loader below it: a null entry is a level the file left out. */
1531static char *LODNameBuff[4];
1532
1533static int nowObjCnt;
1534static int nowObjCnt2;
1535static int nowPartsCnt;
1536
1537static int skipSpace(char *buf, int pos);
1538static int checkArg(char *buf, int pos, int *command);
1539
1540/* Read one definition file and turn it into rows of arguments the loader can walk. Every line
1541 ending becomes a pair of NULs first, so the rest of the file is one long run of tokens with no
1542 line structure left in it; each command the text names is then matched by its keyword, its
1543 arguments are checked into the buffers at the next level, and the level moves on. A line naming
1544 no command at all is fatal, because a definition file the loader half-understands would place
1545 half a scene. */
1546void OPAnalyz(char *name) {
1547 char *buffer;
1548 int i;
1549 int position;
1550 int matched;
1551
1552 argLevel = 0;
1553 buffer = teigiBuff;
1554
1555 if (LoadFile(name, teigiBuff, &teigiFileSize) == 0) {
1556 return;
1557 }
1558
1559 for (i = 0; i < teigiFileSize; i++) {
1560 if (buffer[i] == 13 && buffer[i + 1] == 10) {
1561 buffer[i + 1] = 0;
1562 buffer[i] = 0;
1563 }
1564 }
1565
1566 for (i = 0; i < 96; i++) {
1567 pointLight[i].used = 0;
1568 }
1569
1570 pointLightStack = 0;
1571
1572 position = 0;
1573
1574 while (position < teigiFileSize) {
1575 matched = 0;
1576
1577 position = skipSpace(buffer, position);
1578
1579 if (memcmp(&buffer[position], "GRD_IMG", 7) == 0) {
1580 position = skipSpace(buffer, position + 7);
1581 position = checkArg(buffer, position, TEIGI_GRD_IMG);
1582
1583 if (position != -1) {
1584 matched = 1;
1585 }
1586
1587 position = skipSpace(buffer, position);
1588 argLevel++;
1589 }
1590
1591 if (memcmp(&buffer[position], "BLD_IMG", 7) == 0) {
1592 position = skipSpace(buffer, position + 7);
1593 position = checkArg(buffer, position, TEIGI_BLD_IMG);
1594
1595 if (position != -1) {
1596 matched = 1;
1597 }
1598
1599 position = skipSpace(buffer, position);
1600 argLevel++;
1601 }
1602
1603 if (memcmp(&buffer[position], "SKY_IMG", 7) == 0) {
1604 position = skipSpace(buffer, position + 7);
1605 position = checkArg(buffer, position, TEIGI_SKY_IMG);
1606
1607 if (position != -1) {
1608 matched = 1;
1609 }
1610
1611 position = skipSpace(buffer, position);
1612 argLevel++;
1613 }
1614
1615 if (memcmp(&buffer[position], "GND", 3) == 0) {
1616 position = skipSpace(buffer, position + 3);
1617 position = checkArg(buffer, position, TEIGI_GRD);
1618
1619 if (position != -1) {
1620 matched = 1;
1621 }
1622
1623 position = skipSpace(buffer, position);
1624 argLevel++;
1625 }
1626
1627 if (memcmp(&buffer[position], "BLD", 3) == 0 && memcmp(&buffer[position], "BLD_IMG", 7) != 0) {
1628 position = skipSpace(buffer, position + 3);
1629 position = checkArg(buffer, position, TEIGI_BLD);
1630
1631 if (position != -1) {
1632 matched = 1;
1633 }
1634
1635 position = skipSpace(buffer, position);
1636 argLevel++;
1637 }
1638
1639 if (memcmp(&buffer[position], "LOD", 3) == 0) {
1640 position = skipSpace(buffer, position + 3);
1641 position = checkArg(buffer, position, TEIGI_LOD);
1642
1643 if (position != -1) {
1644 matched = 1;
1645 }
1646
1647 position = skipSpace(buffer, position);
1648 argLevel++;
1649 }
1650
1651 if (memcmp(&buffer[position], "SKY", 3) == 0) {
1652 position = skipSpace(buffer, position + 3);
1653 position = checkArg(buffer, position, TEIGI_SKY);
1654
1655 if (position != -1) {
1656 matched = 1;
1657 }
1658
1659 position = skipSpace(buffer, position);
1660 argLevel++;
1661 }
1662
1663 if (memcmp(&buffer[position], "FOG", 3) == 0) {
1664 position = skipSpace(buffer, position + 3);
1665 position = checkArg(buffer, position, TEIGI_FOG);
1666
1667 if (position != -1) {
1668 matched = 1;
1669 }
1670
1671 position = skipSpace(buffer, position);
1672 argLevel++;
1673 }
1674
1675 if (memcmp(&buffer[position], "CRD", 3) == 0) {
1676 position = skipSpace(buffer, position + 3);
1677 position = checkArg(buffer, position, TEIGI_CRD);
1678
1679 if (position != -1) {
1680 matched = 1;
1681 }
1682
1683 position = skipSpace(buffer, position);
1684 argLevel++;
1685 }
1686
1687 if (memcmp(&buffer[position], "AMBIENT", 7) == 0) {
1688 position = skipSpace(buffer, position + 7);
1689 position = checkArg(buffer, position, TEIGI_AMBIENT);
1690
1691 if (position != -1) {
1692 matched = 1;
1693 }
1694
1695 position = skipSpace(buffer, position);
1696 argLevel++;
1697 }
1698
1699 if (memcmp(&buffer[position], "LIGHT_C", 7) == 0) {
1700 position = skipSpace(buffer, position + 7);
1701 position = checkArg(buffer, position, TEIGI_LIGHT_COL);
1702
1703 if (position != -1) {
1704 matched = 1;
1705 }
1706
1707 position = skipSpace(buffer, position);
1708 argLevel++;
1709 }
1710
1711 if (memcmp(&buffer[position], "FARCLIP", 7) == 0) {
1712 position = skipSpace(buffer, position + 7);
1713 position = checkArg(buffer, position, TEIGI_FARCLIP);
1714
1715 if (position != -1) {
1716 matched = 1;
1717 }
1718
1719 position = skipSpace(buffer, position);
1720 argLevel++;
1721 }
1722
1723 /* Six where the keyword is seven, which is the original's own step: the `2` is left
1724 standing, and a digit is not a separator, so it is the argument reader that meets it. */
1725 if (memcmp(&buffer[position], "BG_COL2", 7) == 0) {
1726 position = skipSpace(buffer, position + 6);
1727 position = checkArg(buffer, position, TEIGI_BG_COL2);
1728
1729 if (position != -1) {
1730 matched = 1;
1731 }
1732
1733 position = skipSpace(buffer, position);
1734 argLevel++;
1735 }
1736
1737 if (memcmp(&buffer[position], "BG_COL", 6) == 0) {
1738 position = skipSpace(buffer, position + 6);
1739 position = checkArg(buffer, position, TEIGI_BG_COL);
1740
1741 if (position != -1) {
1742 matched = 1;
1743 }
1744
1745 position = skipSpace(buffer, position);
1746 argLevel++;
1747 }
1748
1749 if (memcmp(&buffer[position], "NORMALCLIP_OFF", 14) == 0) {
1750 position = skipSpace(buffer, position + 14);
1751 position = checkArg(buffer, position, TEIGI_NORMALCLIP_OFF);
1752
1753 if (position != -1) {
1754 matched = 1;
1755 }
1756
1757 position = skipSpace(buffer, position);
1758 argLevel++;
1759 }
1760
1761 if (memcmp(&buffer[position], "RUN_SPEED", 9) == 0) {
1762 position = skipSpace(buffer, position + 9);
1763 position = checkArg(buffer, position, TEIGI_RUN_SPEED);
1764
1765 if (position != -1) {
1766 matched = 1;
1767 }
1768
1769 position = skipSpace(buffer, position);
1770 argLevel++;
1771 }
1772
1773 if (memcmp(&buffer[position], "EDIT_FOG", 8) == 0) {
1774 position = skipSpace(buffer, position + 8);
1775 position = checkArg(buffer, position, TEIGI_EDIT_FOG);
1776
1777 if (position != -1) {
1778 matched = 1;
1779 }
1780
1781 position = skipSpace(buffer, position);
1782 argLevel++;
1783 }
1784
1785 if (memcmp(&buffer[position], "WATER_SET", 9) == 0) {
1786 position = skipSpace(buffer, position + 9);
1787 position = checkArg(buffer, position, TEIGI_WATER_SET);
1788
1789 if (position != -1) {
1790 matched = 1;
1791 }
1792
1793 position = skipSpace(buffer, position);
1794 argLevel++;
1795 }
1796
1797 if (memcmp(&buffer[position], "WATER_RGB", 9) == 0) {
1798 position = skipSpace(buffer, position + 9);
1799 position = checkArg(buffer, position, TEIGI_WATER_RGB);
1800
1801 if (position != -1) {
1802 matched = 1;
1803 }
1804
1805 position = skipSpace(buffer, position);
1806 argLevel++;
1807 }
1808
1809 if (memcmp(&buffer[position], "WATER_PARAM", 11) == 0) {
1810 position = skipSpace(buffer, position + 11);
1811 position = checkArg(buffer, position, TEIGI_WATER_PARAM);
1812
1813 if (position != -1) {
1814 matched = 1;
1815 }
1816
1817 position = skipSpace(buffer, position);
1818 argLevel++;
1819 }
1820
1821 if (memcmp(&buffer[position], "LEVEL_FAR", 9) == 0) {
1822 position = skipSpace(buffer, position + 9);
1823 position = checkArg(buffer, position, TEIGI_LEVEL_FAR);
1824
1825 if (position != -1) {
1826 matched = 1;
1827 }
1828
1829 position = skipSpace(buffer, position);
1830 argLevel++;
1831 }
1832
1833 if (memcmp(&buffer[position], "DebugFlag", 9) == 0) {
1834 position = skipSpace(buffer, position + 9);
1835 position = checkArg(buffer, position, TEIGI_DebugFlag);
1836
1837 if (position != -1) {
1838 matched = 1;
1839 }
1840
1841 position = skipSpace(buffer, position);
1842 argLevel++;
1843 }
1844
1845 if (memcmp(&buffer[position], "AnimeSpeed", 10) == 0) {
1846 position = skipSpace(buffer, position + 10);
1847 position = checkArg(buffer, position, TEIGI_AnimeSpeed);
1848
1849 if (position != -1) {
1850 matched = 1;
1851 }
1852
1853 position = skipSpace(buffer, position);
1854 argLevel++;
1855 }
1856
1857 if (memcmp(&buffer[position], "UPER", 4) == 0) {
1858 position = skipSpace(buffer, position + 4);
1859 position = checkArg(buffer, position, TEIGI_UPER);
1860
1861 if (position != -1) {
1862 matched = 1;
1863 }
1864
1865 position = skipSpace(buffer, position);
1866 argLevel++;
1867 }
1868
1869 if (memcmp(&buffer[position], "UPR_IMG", 7) == 0) {
1870 position = skipSpace(buffer, position + 7);
1871 position = checkArg(buffer, position, TEIGI_UPR_IMG);
1872
1873 if (position != -1) {
1874 matched = 1;
1875 }
1876
1877 position = skipSpace(buffer, position);
1878 argLevel++;
1879 }
1880
1881 if (memcmp(&buffer[position], "PLIGHT", 6) == 0) {
1882 position = skipSpace(buffer, position + 6);
1883 position = checkArg(buffer, position, TEIGI_PLIGHT);
1884
1885 if (position != -1) {
1886 matched = 1;
1887 }
1888
1889 position = skipSpace(buffer, position);
1890 argLevel++;
1891 }
1892
1893 if (memcmp(&buffer[position], "ADD_CRD", 7) == 0) {
1894 position = skipSpace(buffer, position + 7);
1895 position = checkArg(buffer, position, TEIGI_ADD_CRD);
1896
1897 if (position != -1) {
1898 matched = 1;
1899 }
1900
1901 position = skipSpace(buffer, position);
1902 argLevel++;
1903 }
1904
1905 if (memcmp(&buffer[position], "DEF_PATS", 8) == 0) {
1906 position = skipSpace(buffer, position + 8);
1907 argValBuff[argLevel][0] = (float) TEIGI_DEF_PATS[0];
1908 matched = 1;
1909 argLevel++;
1910 }
1911
1912 if (memcmp(&buffer[position], "DEF_ENDS", 8) == 0) {
1913 position = skipSpace(buffer, position + 8);
1914 argValBuff[argLevel][0] = (float) TEIGI_DEF_ENDS[0];
1915 matched = 1;
1916 argLevel++;
1917 }
1918
1919 if (memcmp(&buffer[position], "PT_BASE", 7) == 0) {
1920 position = skipSpace(buffer, position + 7);
1921 position = checkArg(buffer, position, TEIGI_PT_BASE);
1922
1923 if (position != -1) {
1924 matched = 1;
1925 }
1926
1927 position = skipSpace(buffer, position);
1928 argLevel++;
1929 }
1930
1931 if (memcmp(&buffer[position], "MAPD", 4) == 0) {
1932 position = skipSpace(buffer, position + 4);
1933 position = checkArg(buffer, position, TEIGI_MAPD);
1934
1935 if (position != -1) {
1936 matched = 1;
1937 }
1938
1939 position = skipSpace(buffer, position);
1940 argLevel++;
1941 }
1942
1943 if (memcmp(&buffer[position], "PT_COLS", 7) == 0) {
1944 position = skipSpace(buffer, position + 7);
1945 position = checkArg(buffer, position, TEIGI_PT_COLS);
1946
1947 if (position != -1) {
1948 matched = 1;
1949 }
1950
1951 position = skipSpace(buffer, position);
1952 argLevel++;
1953 }
1954
1955 if (memcmp(&buffer[position], "PT_FIRE", 7) == 0) {
1956 position = skipSpace(buffer, position + 7);
1957 position = checkArg(buffer, position, TEIGI_PT_FIRE);
1958
1959 if (position != -1) {
1960 matched = 1;
1961 }
1962
1963 position = skipSpace(buffer, position);
1964 argLevel++;
1965 }
1966
1967 if (memcmp(&buffer[position], "PT_WATER", 8) == 0) {
1968 position = skipSpace(buffer, position + 8);
1969 position = checkArg(buffer, position, TEIGI_PT_WATER);
1970
1971 if (position != -1) {
1972 matched = 1;
1973 }
1974
1975 position = skipSpace(buffer, position);
1976 argLevel++;
1977 }
1978
1979 if (memcmp(&buffer[position], "S_VOLUME", 8) == 0) {
1980 position = skipSpace(buffer, position + 8);
1981 position = checkArg(buffer, position, TEIGI_S_VOLUME);
1982
1983 if (position != -1) {
1984 matched = 1;
1985 }
1986
1987 position = skipSpace(buffer, position);
1988 argLevel++;
1989 }
1990
1991 if (memcmp(&buffer[position], "PROJECTION", 10) == 0) {
1992 position = skipSpace(buffer, position + 10);
1993 position = checkArg(buffer, position, TEIGI_PROJECTION);
1994
1995 if (position != -1) {
1996 matched = 1;
1997 }
1998
1999 position = skipSpace(buffer, position);
2000 argLevel++;
2001 }
2002
2003 if (memcmp(&buffer[position], "OBJ_ROT", 7) == 0) {
2004 position = skipSpace(buffer, position + 7);
2005 position = checkArg(buffer, position, TEIGI_OBJ_ROT);
2006
2007 if (position != -1) {
2008 matched = 1;
2009 }
2010
2011 position = skipSpace(buffer, position);
2012 argLevel++;
2013 }
2014
2015 if (memcmp(&buffer[position], "MAPINFO", 7) == 0) {
2016 position = skipSpace(buffer, position + 7);
2017 position = checkArg(buffer, position, TEIGI_MAPINFO);
2018
2019 if (position != -1) {
2020 matched = 1;
2021 }
2022
2023 position = skipSpace(buffer, position);
2024 argLevel++;
2025 }
2026
2027 if (memcmp(&buffer[position], "FIRE_IMG", 8) == 0) {
2028 position = skipSpace(buffer, position + 8);
2029 position = checkArg(buffer, position, TEIGI_FIRE_IMG);
2030
2031 if (position != -1) {
2032 matched = 1;
2033 }
2034
2035 position = skipSpace(buffer, position);
2036 argLevel++;
2037 }
2038
2039 if (memcmp(&buffer[position], "FIRE", 4) == 0) {
2040 position = skipSpace(buffer, position + 4);
2041 position = checkArg(buffer, position, TEIGI_FIRE);
2042
2043 if (position != -1) {
2044 matched = 1;
2045 }
2046
2047 position = skipSpace(buffer, position);
2048 argLevel++;
2049 }
2050
2051 if (!matched) {
2052 exit__2(-1);
2053 }
2054
2055 position = skipSpace(buffer, position);
2056 }
2057}
2058
2059/* Walk the levels the reader left behind and do what each one asks. A level's number stands in
2060 slot 0 of its row and every command is tested against every level, so a file may repeat a
2061 command as often as it likes and the last one to run wins. The frame attribute the loader builds
2062 as it goes is what every model it places is given, which is why the two commands that place a
2063 whole building save it and put it back: what they set is theirs alone. */
2064void OPMdsLoad() {
2065 CFrameAttr saved_attr;
2066 CFrameAttr attr;
2067 char path[4][128];
2068 CFrameVu1 *lod_frames[4];
2069 sceVu0FVECTOR light_dir;
2070 int i;
2071 int j;
2072 int k;
2073 int light_no;
2074 int light_slot;
2075 CFrameVu1 *frame;
2076 CFrameVu1 *rot_frame;
2077 CMapObject *object;
2078 CFrame *shadow;
2079 float rx;
2080 float ry;
2081 float rz;
2082 float light_x;
2083
2084 attr.clip_depth = 20.0f;
2085 attr.clip_enable = true;
2086 attr.program_option = 0;
2087
2088 nowObjCnt = 0;
2089 nowObjCnt2 = 0;
2090
2091 for (i = 0; i < argLevel; i++) {
2092 if (TEIGI_AnimeSpeed[0] == (int) argValBuff[i][0]) {
2093 animeSpeed1 = (int) argValBuff[i][1];
2094 animeSpeed2 = (int) argValBuff[i][2];
2095 }
2096
2097 if (TEIGI_DebugFlag[0] == (int) argValBuff[i][0]) {
2098 debugModeFlag = (int) argValBuff[i][1];
2099 }
2100
2101 if (TEIGI_LEVEL_FAR[0] == (int) argValBuff[i][0]) {
2102 levelOfDitialZ[0] = argValBuff[i][1];
2103 levelOfDitialZ[1] = argValBuff[i][2];
2104 levelOfDitialZ[2] = argValBuff[i][3];
2105 levelOfDitialZ[3] = argValBuff[i][4];
2106 }
2107
2108 if (TEIGI_WATER_PARAM[0] == (int) argValBuff[i][0]) {
2109 WaterMeshW = (int) argValBuff[i][1];
2110 WaterMeshH = (int) argValBuff[i][2];
2111 WaterShake = argValBuff[i][3];
2112 WaterCourant = argValBuff[i][4];
2113 WaterDecline = argValBuff[i][5];
2114 WaterAmplitude = argValBuff[i][6];
2115 WaterRefraction = argValBuff[i][7];
2116 }
2117
2118 if (TEIGI_WATER_SET[0] == (int) argValBuff[i][0]) {
2119 float half_width = argValBuff[i][1] / 2.0f;
2120 float half_depth = argValBuff[i][2] / 2.0f;
2121
2122 WaterV1[0] = -half_width;
2123 WaterV1[2] = -half_depth;
2124 WaterV2[0] = half_width;
2125 WaterV2[2] = -half_depth;
2126 WaterV3[0] = -half_width;
2127 WaterV3[2] = half_depth;
2128 WaterV4[0] = half_width;
2129 WaterV4[2] = half_depth;
2130 WaterPos[0] = argValBuff[i][3];
2131 WaterPos[1] = argValBuff[i][4];
2132 WaterPos[2] = argValBuff[i][5];
2133 WaterFlag = 1;
2134 }
2135
2136 if (TEIGI_WATER_RGB[0] == (int) argValBuff[i][0]) {
2137 WaterR = argValBuff[i][1];
2138 WaterG = argValBuff[i][2];
2139 WaterB = argValBuff[i][3];
2140 }
2141
2142 if (TEIGI_RUN_SPEED[0] == (int) argValBuff[i][0]) {
2143 run_speed = argValBuff[i][1];
2144 }
2145
2146 if (TEIGI_NORMALCLIP_OFF[0] == (int) argValBuff[i][0]) {
2147 if (argValBuff[i][1] == 0.0f) {
2148 attr.program_option = 0;
2149 } else {
2150 attr.program_option = 1;
2151 }
2152 }
2153
2154 if (TEIGI_BG_COL2[0] == (int) argValBuff[i][0]) {
2155 MGSetBGColor((float) (u_int) argValBuff[i][1], (float) (u_int) argValBuff[i][2], (float) (u_int) argValBuff[i][3], 128.0f);
2156 }
2157
2158 if (TEIGI_BG_COL[0] == (int) argValBuff[i][0]) {
2159 MGSetBGColor((float) (u_int) argValBuff[i][1], (float) (u_int) argValBuff[i][2], (float) (u_int) argValBuff[i][3], 128.0f);
2160 }
2161
2162 if (TEIGI_FARCLIP[0] == (int) argValBuff[i][0]) {
2163 attr.far_clip_enable = true;
2164 attr.far_clip = argValBuff[i][1];
2165 }
2166
2167 if (TEIGI_LIGHT_COL[0] == (int) argValBuff[i][0]) {
2168 light_no = (int) argValBuff[i][7];
2169 light_dir[0] = argValBuff[i][1];
2170 light_dir[1] = argValBuff[i][2];
2171 light_dir[2] = argValBuff[i][3];
2172 sceVu0Normalize(light_dir, light_dir);
2173 /* The row's index is materialised between the first component's load and its store,
2174 and an assignment's right-hand side is emitted before the subscript it is stored
2175 through, so the component has to already be in a register when the statement that
2176 computes the index runs. */
2177 light_x = light_dir[0];
2178 light_slot = light_no - 1;
2179 light[0][light_slot] = light_x;
2180 light[1][light_slot] = light_dir[1];
2181 light[2][light_slot] = light_dir[2];
2182 lightcolor[light_slot][0] = argValBuff[i][4];
2183 lightcolor[light_slot][1] = argValBuff[i][5];
2184 lightcolor[light_slot][2] = argValBuff[i][6];
2185 MGSetPLight(light, lightcolor);
2186 }
2187
2188 if (TEIGI_AMBIENT[0] == (int) argValBuff[i][0]) {
2189 ambientlight[0] = argValBuff[i][1];
2190 ambientlight[1] = argValBuff[i][2];
2191 ambientlight[2] = argValBuff[i][3];
2192 MGSetAmbient(ambientlight);
2193 }
2194
2195 if (TEIGI_CRD[0] == (int) argValBuff[i][0]) {
2196 strcpy(path[0], "sim:");
2197 strcat(path[0], argStrBuff[i]);
2198 LoadFile(path[0], (void *) read_buffer, 0);
2199 OP_GroundCol = LoadCollisionFile(read_buffer);
2200 }
2201
2202 if (TEIGI_FOG[0] == (int) argValBuff[i][0]) {
2203 op_fogRate[0] = argValBuff[i][1];
2204 op_fogRate[1] = argValBuff[i][2];
2205 op_fogRate[2] = argValBuff[i][6];
2206 op_fogRate[3] = argValBuff[i][7];
2207 op_fogColor[0] = argValBuff[i][3];
2208 op_fogColor[1] = argValBuff[i][4];
2209 op_fogColor[2] = argValBuff[i][5];
2210 MGSetFogParm(op_fogRate[0], op_fogRate[1], op_fogColor[0], op_fogColor[1], op_fogColor[2], op_fogRate[2], op_fogRate[3]);
2211 attr.fog_enable = true;
2212 }
2213
2214 if (TEIGI_EDIT_FOG[0] == (int) argValBuff[i][0]) {
2215 editFogRate[0] = argValBuff[i][1];
2216 editFogRate[1] = argValBuff[i][2];
2217 editFogRate[2] = argValBuff[i][6];
2218 editFogRate[3] = argValBuff[i][7];
2219 editFogColor[0] = argValBuff[i][3];
2220 editFogColor[1] = argValBuff[i][4];
2221 editFogColor[2] = argValBuff[i][5];
2222 attr.fog_enable = true;
2223 }
2224
2225 if (TEIGI_PLIGHT[0] == (int) argValBuff[i][0]) {
2226 pointLight[pointLightStack].used = 1;
2227 pointLight[pointLightStack].x = 10.0f * argValBuff[i][1];
2228 pointLight[pointLightStack].y = 10.0f * argValBuff[i][2];
2229 pointLight[pointLightStack].z = 10.0f * argValBuff[i][3];
2230 pointLight[pointLightStack].r = argValBuff[i][4];
2231 pointLight[pointLightStack].g = argValBuff[i][5];
2232 pointLight[pointLightStack].b = argValBuff[i][6];
2233 pointLight[pointLightStack].arg7 = argValBuff[i][7];
2234 pointLight[pointLightStack].arg8 = argValBuff[i][8];
2235 pointLight[pointLightStack].arg9 = argValBuff[i][9];
2236 pointLightStack++;
2237 }
2238
2239 if (TEIGI_GRD[0] == (int) argValBuff[i][0]) {
2240 strcpy(path[0], "sim:");
2241 strcat(path[0], argStrBuff[i]);
2242 LoadFile(path[0], (void *) read_buffer, 0);
2243 frame = LoadMDSFile(read_buffer, &MapDataBuffer, 2, 0, 0);
2244 rot_frame = frame;
2245 frame->SetAttr(attr, 1, 64);
2246 SetFrameAttr(frame, 1);
2247 object = OP_GroundMap.SetObject(frame, 0, 0);
2248 CVector3_f_ position(10.0f * argValBuff[i][2], 10.0f * argValBuff[i][3], 10.0f * argValBuff[i][4]);
2249 object->SetPosition(position);
2250 rx = PI * argValBuff[i][5] / 180.0f;
2251 ry = PI * argValBuff[i][6] / 180.0f;
2252 rz = PI * argValBuff[i][7] / 180.0f;
2253 CVector3_f_ rotation(rx, ry, rz);
2254 object->SetRotation(rotation);
2255 }
2256
2257 if (TEIGI_SKY[0] == (int) argValBuff[i][0]) {
2258 strcpy(path[0], "sim:");
2259 strcat(path[0], argStrBuff[i]);
2260 LoadFile(path[0], (void *) read_buffer, 0);
2261 OP_SkyFrame = LoadMDSFile(read_buffer, &MapDataBuffer, 2, 0, 0);
2262
2263 if (argValBuff[i][2] == 1.0f) {
2264 OP_SkyFrame->SetAttr(attr, 1, 64);
2265 }
2266 }
2267
2268 if (TEIGI_BLD[0] == (int) argValBuff[i][0]) {
2269 saved_attr = attr;
2270
2271 if (argValBuff[i][8] == 0.0f) {
2272 strcpy(path[0], "sim:");
2273 strcat(path[0], argStrBuff[i]);
2274 LoadFile(path[0], (void *) read_buffer, 0);
2275 frame = LoadMDSFile(read_buffer, &MapDataBuffer, 2, 0, 0);
2276 rot_frame = frame;
2277 frame->SetAttr(attr, 1, 64);
2278 SetFrameAttr(frame, 1);
2279 object = OP_BuildingMap.SetObject(nowObjCnt++, frame, 0, 0);
2280 object->handle = 1;
2281 object->unk_34 = 5;
2282 CVector3_f_ position(10.0f * argValBuff[i][2], 10.0f * argValBuff[i][3], 10.0f * argValBuff[i][4]);
2283 object->SetPosition(position);
2284 rx = PI * argValBuff[i][5] / 180.0f;
2285 ry = PI * argValBuff[i][6] / 180.0f;
2286 rz = PI * argValBuff[i][7] / 180.0f;
2287 CVector3_f_ rotation(rx, ry, rz);
2288 object->SetRotation(rotation);
2289 } else {
2290 for (j = 0; j < 4; j++) {
2291 if (argStrBuff[i + j][0] != 0) {
2292 strcpy(path[j], "sim:");
2293 strcat(path[j], argStrBuff[i + j]);
2294 LODNameBuff[j] = path[j];
2295 } else {
2296 LODNameBuff[j] = 0;
2297 }
2298 }
2299
2300 LoadLODData(lod_frames, LODNameBuff, read_buffer, 0);
2301
2302 object = OP_BuildingMap.GetObject(nowObjCnt++);
2303 object->handle = 1;
2304 object->unk_34 = 1;
2305
2306 CategoryAttr *category = &OP_BuildingMap.category[1];
2307
2308 for (k = 0; k < 4; k++) {
2309 category->lod[k] = levelOfDitialZ[k];
2310 }
2311
2312 category->lowest = 0;
2313 category->highest = 3;
2314
2315 for (j = 0; j < 4; j++) {
2316 object->SetFrame(lod_frames[j], j);
2317
2318 if (lod_frames[j] != 0) {
2319 lod_frames[j]->SetAttr(attr, 1, 64);
2320 SetFrameAttr(lod_frames[j], 1);
2321 shadow = frame->SearchFrame("shadow");
2322
2323 if (shadow != 0) {
2324 attr.alpha_ref = 1;
2325 shadow->SetAttr(attr, 1, 64);
2326 SetFrameAttr(shadow, 1);
2327 }
2328 }
2329 }
2330
2331 CVector3_f_ position(10.0f * argValBuff[i][2], 10.0f * argValBuff[i][3], 10.0f * argValBuff[i][4]);
2332 object->SetPosition(position);
2333 rx = PI * argValBuff[i][5] / 180.0f;
2334 ry = PI * argValBuff[i][6] / 180.0f;
2335 rz = PI * argValBuff[i][7] / 180.0f;
2336 CVector3_f_ rotation(rx, ry, rz);
2337 object->SetRotation(rotation);
2338 }
2339
2340 attr = saved_attr;
2341 }
2342
2343 if (TEIGI_UPER[0] == (int) argValBuff[i][0]) {
2344 saved_attr = attr;
2345
2346 if (argValBuff[i][8] == 0.0f) {
2347 strcpy(path[0], "sim:");
2348 strcat(path[0], argStrBuff[i]);
2349 LoadFile(path[0], (void *) read_buffer, 0);
2350 frame = LoadMDSFile(read_buffer, &MapDataBuffer, 2, 0, 0);
2351 frame->SetAttr(attr, 1, 64);
2352 SetFrameAttr(frame, 1);
2353 object = OP_BuildingMap2.SetObject(nowObjCnt2++, frame, 0, 0);
2354 object->handle = 1;
2355 object->unk_34 = 5;
2356 CVector3_f_ position(10.0f * argValBuff[i][2], 10.0f * argValBuff[i][3], 10.0f * argValBuff[i][4]);
2357 object->SetPosition(position);
2358 rx = PI * argValBuff[i][5] / 180.0f;
2359 ry = PI * argValBuff[i][6] / 180.0f;
2360 rz = PI * argValBuff[i][7] / 180.0f;
2361 CVector3_f_ rotation(rx, ry, rz);
2362 object->SetRotation(rotation);
2363 } else {
2364 for (j = 0; j < 4; j++) {
2365 if (argStrBuff[i + j][0] != 0) {
2366 strcpy(path[j], "sim:");
2367 strcat(path[j], argStrBuff[i + j]);
2368 LODNameBuff[j] = path[j];
2369 } else {
2370 LODNameBuff[j] = 0;
2371 }
2372 }
2373
2374 LoadLODData(lod_frames, LODNameBuff, read_buffer, 0);
2375
2376 object = OP_BuildingMap2.GetObject(nowObjCnt++);
2377 object->handle = 1;
2378 object->unk_34 = 1;
2379
2380 CategoryAttr *category = &OP_BuildingMap2.category[1];
2381
2382 for (k = 0; k < 4; k++) {
2383 category->lod[k] = levelOfDitialZ[k];
2384 }
2385
2386 category->lowest = 0;
2387 category->highest = 3;
2388
2389 for (j = 0; j < 4; j++) {
2390 object->SetFrame(lod_frames[j], j);
2391
2392 if (lod_frames[j] != 0) {
2393 lod_frames[j]->SetAttr(attr, 1, 64);
2394 SetFrameAttr(lod_frames[j], 1);
2395 shadow = frame->SearchFrame("shadow");
2396
2397 if (shadow != 0) {
2398 attr.alpha_ref = 1;
2399 shadow->SetAttr(attr, 1, 64);
2400 SetFrameAttr(shadow, 1);
2401 }
2402 }
2403 }
2404
2405 CVector3_f_ position(10.0f * argValBuff[i][2], 10.0f * argValBuff[i][3], 10.0f * argValBuff[i][4]);
2406 object->SetPosition(position);
2407 rx = PI * argValBuff[i][5] / 180.0f;
2408 ry = PI * argValBuff[i][6] / 180.0f;
2409 rz = PI * argValBuff[i][7] / 180.0f;
2410 CVector3_f_ rotation(rx, ry, rz);
2411 object->SetRotation(rotation);
2412 }
2413
2414 attr = saved_attr;
2415 }
2416
2417 if (TEIGI_S_VOLUME[0] == (int) argValBuff[i][0]) {
2418 strcpy(path[0], "sim:");
2419 strcat(path[0], argStrBuff[i]);
2420 LoadFile(path[0], (void *) read_buffer, 0);
2421 ShadowModel[shadowModelCount] = LoadMDSFile(read_buffer, 14, 0);
2422 ShadowModel[shadowModelCount]->SetPosition(10.0f * argValBuff[i][2], 10.0f * argValBuff[i][3], 10.0f * argValBuff[i][4]);
2423 rx = PI * argValBuff[i][5] / 180.0f;
2424 ry = PI * argValBuff[i][6] / 180.0f;
2425 rz = PI * argValBuff[i][7] / 180.0f;
2426 ShadowModel[shadowModelCount]->SetRotation(rx, ry, rz);
2427 shadowModelCount++;
2428 }
2429
2430 if (TEIGI_ADD_CRD[0] == (int) argValBuff[i][0]) {
2431 strcpy(path[0], "sim:");
2432 strcat(path[0], argStrBuff[i]);
2433 LoadFile(path[0], (void *) read_buffer, 0);
2434 ColModel[ColModelCount] = LoadCollisionFile(read_buffer);
2435 ColModel[ColModelCount]->SetPosition(10.0f * argValBuff[i][2], 10.0f * argValBuff[i][3], 10.0f * argValBuff[i][4]);
2436 rx = PI * argValBuff[i][5] / 180.0f;
2437 ry = PI * argValBuff[i][6] / 180.0f;
2438 rz = PI * argValBuff[i][7] / 180.0f;
2439 ColModel[ColModelCount]->SetRotation(rx, ry, rz);
2440 ColModelCount++;
2441 }
2442
2443 if (TEIGI_PROJECTION[0] == (int) argValBuff[i][0]) {
2444 Projection = argValBuff[i][1];
2445 }
2446
2447 if (TEIGI_OBJ_ROT[0] == (int) argValBuff[i][0]) {
2448 OP_AnimeSeq[OP_AnimeSeqRot].Initialize();
2449 OP_AnimeSeq[OP_AnimeSeqRot].type = 0;
2450 OP_AnimeSeq[OP_AnimeSeqRot].number = 0;
2451 OP_AnimeSeq[OP_AnimeSeqRot].start[0] = argValBuff[i][2];
2452 OP_AnimeSeq[OP_AnimeSeqRot].start[1] = argValBuff[i][3];
2453 OP_AnimeSeq[OP_AnimeSeqRot].start[2] = argValBuff[i][4];
2454 OP_AnimeSeq[OP_AnimeSeqRot].step_x = argValBuff[i][5];
2455 OP_AnimeSeq[OP_AnimeSeqRot].step_y = argValBuff[i][6];
2456 OP_AnimeSeq[OP_AnimeSeqRot].step_z = argValBuff[i][7];
2457 strcpy(OP_AnimeSeq[OP_AnimeSeqRot].name, argStrBuff[i]);
2458 InitObjAnime(rot_frame, &OP_AnimeSeq[OP_AnimeSeqRot]);
2459 OP_AnimeSeqRot++;
2460 }
2461
2462 if (TEIGI_FIRE[0] == (int) argValBuff[i][0]) {
2463 OP_FirePosition[OP_FireList][0] = argValBuff[i][1];
2464 OP_FirePosition[OP_FireList][1] = argValBuff[i][2];
2465 OP_FirePosition[OP_FireList][2] = argValBuff[i][3];
2466 OP_FireScale[OP_FireList] = argValBuff[i][4];
2467 OP_FireFlg[OP_FireList] = (int) argValBuff[i][5];
2468 OP_FireList++;
2469 }
2470
2471 if (TEIGI_DEF_ENDS[0] == (int) argValBuff[i][0]) {
2472 nowPartsCnt++;
2473 }
2474 }
2475}
2476
2488static int skipSpace(char *buffer, int position) {
2489 int skipped;
2490
2491 while (position < teigiFileSize) {
2492 skipped = 0;
2493
2494 if (memcmp(&buffer[position], "\x81\x40", 2) == 0) {
2495 position++;
2496 skipped = 1;
2497 }
2498
2499 if (buffer[position] == ' ') {
2500 skipped = 1;
2501 }
2502
2503 if (buffer[position] == '\t') {
2504 skipped = 1;
2505 }
2506
2507 if (buffer[position] == '\0') {
2508 position++;
2509 skipped = 1;
2510 }
2511
2512 if (memcmp(&buffer[position], "//", 2) == 0) {
2513 while (buffer[position] != '\0') {
2514 position++;
2515 }
2516
2517 position++;
2518 skipped = 1;
2519 }
2520
2521 if (!skipped) {
2522 return position;
2523 }
2524
2525 position++;
2526 }
2527
2528 return teigiFileSize;
2529}
2530
2543static int checkArg(char *buffer, int position, int *command) {
2544 int i;
2545 int cursor;
2546 int char_count;
2547 int accepted;
2548
2549 cursor = position;
2550
2551 if (command[1] == 0) {
2552 return position;
2553 }
2554
2555 for (i = 0; i < command[1]; i++) {
2556 argValBuff[argLevel][0] = (float) command[0];
2557
2558 switch (command[2 + i]) {
2559 case TSARG_STRING:
2560 if (buffer[cursor] != '"') {
2561 return -1;
2562 }
2563
2564 cursor++;
2565
2566 for (char_count = 0; char_count < 64; char_count++) {
2567 if (buffer[cursor] == '"') {
2568 argStrBuff[argLevel][char_count] = '\0';
2569 cursor++;
2570 break;
2571 }
2572
2573 argStrBuff[argLevel][char_count] = buffer[cursor];
2574 cursor++;
2575 }
2576
2577 if (char_count == 64) {
2578 return -1;
2579 }
2580
2581 cursor = skipSpace(buffer, cursor);
2582 break;
2583
2584 case TSARG_COMMA_VALUE:
2585 if (buffer[cursor] != ',') {
2586 return -1;
2587 }
2588
2589 cursor = skipSpace(buffer, cursor + 1);
2590
2591 if (memcmp(&buffer[cursor], "ON", 2) == 0) {
2592 argValBuff[argLevel][1 + i] = 1.0f;
2593 cursor += 2;
2594 } else if (memcmp(&buffer[cursor], "OFF", 3) == 0) {
2595 argValBuff[argLevel][1 + i] = 0;
2596 cursor += 3;
2597 } else {
2598 accepted = 0;
2599
2600 if (buffer[cursor] == '-') {
2601 accepted = 1;
2602 }
2603
2604 if (buffer[cursor] >= '0' && buffer[cursor] <= '9') {
2605 accepted = 1;
2606 }
2607
2608 if (!accepted) {
2609 return -1;
2610 }
2611
2612 argValBuff[argLevel][1 + i] = (float) atof(&buffer[cursor]);
2613
2614 for (char_count = 0; char_count < 32; char_count++) {
2615 accepted = 0;
2616
2617 if (buffer[cursor] == '-') {
2618 cursor++;
2619 accepted = 1;
2620 }
2621
2622 if (buffer[cursor] >= '0' && buffer[cursor] <= '9') {
2623 cursor++;
2624 accepted = 1;
2625 }
2626
2627 if (buffer[cursor] == '.') {
2628 cursor++;
2629 accepted = 1;
2630 }
2631
2632 if (!accepted) {
2633 break;
2634 }
2635 }
2636
2637 if (char_count == 32) {
2638 return -1;
2639 }
2640 }
2641
2642 cursor = skipSpace(buffer, cursor);
2643 break;
2644
2645 case TSARG_VALUE:
2646 if (memcmp(&buffer[cursor], "ON", 2) == 0) {
2647 argValBuff[argLevel][1 + i] = 1.0f;
2648 cursor += 2;
2649 } else if (memcmp(&buffer[cursor], "OFF", 3) == 0) {
2650 argValBuff[argLevel][1 + i] = 0;
2651 cursor += 3;
2652 } else {
2653 accepted = 0;
2654
2655 if (buffer[cursor] == '-') {
2656 accepted = 1;
2657 }
2658
2659 if (buffer[cursor] >= '0' && buffer[cursor] <= '9') {
2660 accepted = 1;
2661 }
2662
2663 if (!accepted) {
2664 return -1;
2665 }
2666
2667 argValBuff[argLevel][1 + i] = (float) atof(&buffer[cursor]);
2668
2669 for (char_count = 0; char_count < 32; char_count++) {
2670 accepted = 0;
2671
2672 if (buffer[cursor] == '-') {
2673 cursor++;
2674 accepted = 1;
2675 }
2676
2677 if (buffer[cursor] >= '0' && buffer[cursor] <= '9') {
2678 cursor++;
2679 accepted = 1;
2680 }
2681
2682 if (buffer[cursor] == '.') {
2683 cursor++;
2684 accepted = 1;
2685 }
2686
2687 if (!accepted) {
2688 break;
2689 }
2690 }
2691
2692 if (char_count == 32) {
2693 return -1;
2694 }
2695 }
2696
2697 cursor = skipSpace(buffer, cursor);
2698 break;
2699 }
2700 }
2701
2702 return cursor;
2703}
void SetHeight(float height)
void SetFollow(float x, float y, float z)
void SetDistance(float distance)
virtual void Step(int steps)
void GetCameraMatrix(float(*matrix)[4])
Definition camera.cpp:153
void SetRef(CFrame *parent, float x, float y, float z)
Definition camera.cpp:124
void SetPos(CFrame *parent, float x, float y, float z)
Definition camera.cpp:103
void SetSpeed(float speed)
Definition camera.cpp:222
void GetPos(float *pos)
Definition camera.cpp:230
virtual void LoadPackData(unsigned int *pack, char *name, CDataAlloc2< 1 > *model_alloc, CDataAlloc2< 1 > *texture_alloc)
tagMOTION_TYPE motion_type
void FadeOutStart(float speed, int colour)
Definition dispfade.cpp:9
float GetRate()
Definition dispfade.cpp:27
float FadeOut(sceVif1Packet *packet)
Definition dispfade.cpp:31
float FadeIn(sceVif1Packet *packet)
Definition dispfade.cpp:92
void FadeInit(float initial_rate)
Definition dispfade.cpp:21
void FadeInStart(float speed, int colour)
Definition dispfade.cpp:15
char clip_enable
Definition frame.hpp:29
short alpha_ref
Definition frame.hpp:43
float clip_depth
Definition frame.hpp:28
char program_option
Definition frame.hpp:32
float far_clip
Definition frame.hpp:37
char fog_enable
Definition frame.hpp:33
char far_clip_enable
Definition frame.hpp:34
int Down(int mask)
Definition gamepad.cpp:583
CFrameVu1 * collision_frame
Definition op_b.cpp:90
int handle
Definition op_b.cpp:96
int unk_34
Definition op_b.cpp:95
CFrameVu1 * shade_frame
Definition op_b.cpp:92
CFrameVu1 * camera_frame
Definition op_b.cpp:93
Definition op_a.cpp:90
CategoryAttr category[16]
Definition op_a.cpp:92
s32 rotation_changed
Definition op_b.cpp:77
CFrameVu1 * frame[4]
Definition op_b.cpp:76
s32 draw_on
Definition op_b.cpp:78
Definition op_a.cpp:55
T h
Definition op_a.cpp:60
T y
Definition op_a.cpp:58
T x
Definition op_a.cpp:57
T w
Definition op_a.cpp:59
int mes_y
Definition script.hpp:158
int mes_tail_y
Definition script.hpp:161
int bgm_fade
Definition script.hpp:180
int mes_page_wait
Definition script.hpp:162
float motion_step
Definition script.hpp:152
int load_no
Definition script.hpp:143
void Load(const char *name)
Definition script.cpp:51
int mes_x
Definition script.hpp:157
int mes_tail_x
Definition script.hpp:160
int se_no
Definition script.hpp:176
int fade
Definition script.hpp:137
int scene
Definition script.hpp:142
int motion_end
Definition script.hpp:151
int motion_start
Definition script.hpp:150
u8 motion_req
Definition script.hpp:153
int se_kind
Definition script.hpp:175
float mes_timer
Definition script.hpp:156
int se_voice
Definition script.hpp:177
int mes_no
Definition script.hpp:155
int mes_wait
Definition script.hpp:145
float fade_speed
Definition script.hpp:138
int se_fade_time
Definition script.hpp:178
int se_stop
Definition script.hpp:179
int init_no
Definition script.hpp:144
void Step()
Definition script.cpp:103
void StopVoice(int core)
Definition sound.cpp:69
void SE_Play(int port, int bank, int program, int pan, int velocity, int volume, int voice)
Definition sound.cpp:579
void SE_SetPan(int port, int bank, int program, int pan, int voice)
Definition sound.cpp:679
void Step()
Definition sound.cpp:814
void SetVol(int port, int volume)
Definition sound.cpp:983
void SE_SetVol(int port, int bank, int program, int volume, int voice)
Definition sound.cpp:643
void Fade(int port, float step, int volume)
Definition sound.cpp:755
void SQ_RePlay(int port)
Definition sound.cpp:574
void Stop(int port)
Definition sound.cpp:978
short * GetSeInfTbl()
Definition sound.cpp:49
void SE_Stop(int port, int bank, int program, int voice)
Definition sound.cpp:719
void SQ_Play(int port, int seq_no)
Definition sound.cpp:495
int GetSeNo(int bank, int program)
Definition sound.cpp:53
MIDI_STATE * GetMidiState()
Definition sound.cpp:45
u_long tex0
Definition texture.hpp:57
float lod[4]
Definition main.cpp:70
int lowest
Definition main.cpp:71
int highest
Definition main.cpp:72
s32 text_y
Definition clsmes.hpp:152
s32 text_x
Definition clsmes.hpp:151
short * buff
Definition clsmes.hpp:229
s32 grow_y
Definition clsmes.hpp:167
float text_rate_set
Definition clsmes.hpp:193
void DrawMesWin()
Definition clsmes.cpp:2619
s32 tail_to_y
Definition clsmes.hpp:175
void Step()
Definition clsmes.cpp:575
float fade_speed
Definition clsmes.hpp:186
s32 end_mark
Definition clsmes.hpp:210
s32 tail_y
Definition clsmes.hpp:177
void AbsFukidashiIn()
Definition clsmes.cpp:339
char * text
Definition clsmes.hpp:231
s32 win_y
Definition clsmes.hpp:169
s32 tail_length
Definition clsmes.hpp:179
s32 win_x
Definition clsmes.hpp:168
s32 win_width
Definition clsmes.hpp:170
s32 auto_page_wait
Definition clsmes.hpp:206
s32 tail_to_x
Definition clsmes.hpp:174
void GoNextPage()
Definition clsmes.cpp:663
s32 tail_x
Definition clsmes.hpp:176
s32 tail_half_width
Definition clsmes.hpp:178
void * tex_buff
Definition clsmes.hpp:233
s32 win_height
Definition clsmes.hpp:171
s32 grow_x
Definition clsmes.hpp:166
s32 tex_block
Definition clsmes.hpp:227
float text_rate
Definition clsmes.hpp:192
int MakeMesWin(int mes_no)
Definition clsmes.cpp:1669
int State()
Definition clsmes.cpp:637
void Preset(int style)
Definition clsmes.cpp:468
s32 auto_page
Definition clsmes.hpp:195
float step_y
Definition op_a.cpp:205
sceVu0FVECTOR start
Definition opening.cpp:1392
void Initialize()
Definition objanime.cpp:33
char name[16]
Definition op_a.cpp:198
float step_z
Definition op_a.cpp:206
float step_x
Definition op_a.cpp:204
s32 active
Definition sound.hpp:46
MIDI_FADE fade[2]
Definition sound.hpp:64
MIDI_SEQUENCE * sequence[10]
Definition sound.hpp:62
MIDI_PORT port[8]
Definition sound.hpp:74
CCamera * camera
Definition gameutil.hpp:196
float blend_step
Definition gameutil.hpp:190
MOTION_STATE state
Definition gameutil.hpp:273