Skip to content

Commit fe02e9b

Browse files
committed
Work on town LCS
1 parent f8364da commit fe02e9b

File tree

18 files changed

+441
-91
lines changed

18 files changed

+441
-91
lines changed

AzelLib/3dEngine_flush.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -901,17 +901,22 @@ float* getViewMatrix()
901901
return fViewMatrix;
902902
}
903903

904+
float fov = 40.f;
905+
void RendererSetFov(float fovInDegree)
906+
{
907+
fov = fovInDegree;
908+
}
909+
904910
float* getProjectionMatrix()
905911
{
906912
static float fEarlyProjectionMatrix[4 * 4];
907913

908914
float zNear = 0.1f;
909915
float zFar = 1000.f;
910-
/*
911-
s32 const1 = 229;
912-
s32 const2 = 195;
913916

914-
float fEarlyProjectionMatrix[4 * 4];
917+
#if 0
918+
s32 const1 = graphicEngineStatus.m405C.m18_widthScale; //229;
919+
s32 const2 = graphicEngineStatus.m405C.m1C_heightScale; //195;
915920

916921
fEarlyProjectionMatrix[0] = const1 / (352.f / 2.f);
917922
fEarlyProjectionMatrix[1] = 0;
@@ -934,7 +939,7 @@ float* getProjectionMatrix()
934939
fEarlyProjectionMatrix[15] = 0;
935940

936941
transposeMatrix(fEarlyProjectionMatrix);
937-
*/
942+
#else
938943

939944
glm::mat4 testProj = glm::perspectiveFov(glm::radians(50.f), 352.f, 224.f, zNear, zFar);
940945
for (int i = 0; i < 4; i++)
@@ -944,7 +949,7 @@ float* getProjectionMatrix()
944949
fEarlyProjectionMatrix[i * 4 + j] = testProj[i][j];
945950
}
946951
}
947-
952+
#endif
948953
return fEarlyProjectionMatrix;
949954
}
950955

AzelLib/PDS.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ s32 sqrt_I(s32 r4)
150150

151151
void initVDP1Projection(fixedPoint r4, u32 mode)
152152
{
153+
{
154+
float fValueInRad = r4.toFloat() * ((glm::pi<float>() / 2.f) / 1024.f);
155+
float fValueInDegree = glm::degrees<float>(fValueInRad);
156+
RendererSetFov(fValueInDegree);
157+
}
153158
u32 angle = r4.getInteger();
154159

155160
fixedPoint sin = getSin(angle);
@@ -162,16 +167,16 @@ void initVDP1Projection(fixedPoint r4, u32 mode)
162167
switch (mode)
163168
{
164169
case 0:
165-
graphicEngineStatus.m405C.m18 = FP_Mul(r0, fixedPoint(0x11999)); // 1.0999908447265625 = 352 / 320
166-
graphicEngineStatus.m405C.m1C = FP_Mul(r0, fixedPoint(0xEEEE)); // 0.93331909179687500 = 224 / 240
170+
graphicEngineStatus.m405C.m18_widthScale = FP_Mul(r0, fixedPoint(0x11999)); // 1.0999908447265625 = 352 / 320
171+
graphicEngineStatus.m405C.m1C_heightScale = FP_Mul(r0, fixedPoint(0xEEEE)); // 0.93331909179687500 = 224 / 240
167172
break;
168173
case 1:
169-
graphicEngineStatus.m405C.m18 = FP_Mul(r0, fixedPoint(0xD333)); //0.82499694824218750 = 264 / 320
170-
graphicEngineStatus.m405C.m1C = FP_Mul(r0, fixedPoint(0xEEEE)); //0.93331909179687500 = 224 / 240
174+
graphicEngineStatus.m405C.m18_widthScale = FP_Mul(r0, fixedPoint(0xD333)); //0.82499694824218750 = 264 / 320
175+
graphicEngineStatus.m405C.m1C_heightScale = FP_Mul(r0, fixedPoint(0xEEEE)); //0.93331909179687500 = 224 / 240
171176
break;
172177
case 2:
173-
graphicEngineStatus.m405C.m18 = FP_Mul(r0, fixedPoint(0xD333)); //0.82499694824218750 = 264 / 320
174-
graphicEngineStatus.m405C.m1C = FP_Mul(r0, fixedPoint(0xB333)); //0.69999694824218750 = 168 / 240
178+
graphicEngineStatus.m405C.m18_widthScale = FP_Mul(r0, fixedPoint(0xD333)); //0.82499694824218750 = 264 / 320
179+
graphicEngineStatus.m405C.m1C_heightScale = FP_Mul(r0, fixedPoint(0xB333)); //0.69999694824218750 = 168 / 240
175180
break;
176181
default:
177182
assert(0);
@@ -181,20 +186,20 @@ void initVDP1Projection(fixedPoint r4, u32 mode)
181186
s32 array[2];
182187

183188
array[0] = 352 / 2;
184-
array[1] = graphicEngineStatus.m405C.m18;
189+
array[1] = graphicEngineStatus.m405C.m18_widthScale;
185190
graphicEngineStatus.m405C.m2C_widthRatio = FP_Div(array[0], array[1]);
186191
graphicEngineStatus.m405C.m28_widthRatio2 = FP_Div(sqrt_I(MTH_Product2d(array, array)), array[1]);
187192

188193
array[0] = 224 / 2;
189-
array[1] = graphicEngineStatus.m405C.m1C;
194+
array[1] = graphicEngineStatus.m405C.m1C_heightScale;
190195
graphicEngineStatus.m405C.m24_heightRatio = FP_Div(array[0], array[1]);
191196
graphicEngineStatus.m405C.m20_heightRatio2 = FP_Div(sqrt_I(MTH_Product2d(array, array)), array[1]);
192197
}
193198

194199
void getVdp1ProjectionParams(s16* r4, s16* r5)
195200
{
196-
*r4 = graphicEngineStatus.m405C.m18;
197-
*r5 = graphicEngineStatus.m405C.m1C;
201+
*r4 = graphicEngineStatus.m405C.m18_widthScale;
202+
*r5 = graphicEngineStatus.m405C.m1C_heightScale;
198203
}
199204

200205
void initVDP1()

AzelLib/PDS.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
#define PDS_TOOL
88

9-
//#define SHIPPING_BUILD
9+
#ifndef _DEBUG
10+
#define SHIPPING_BUILD
11+
#endif
1012

1113
#ifdef WIN32
1214
#define _CRT_SECURE_NO_WARNINGS
@@ -138,6 +140,13 @@ struct sSaturnPtr
138140
return *this;
139141
}
140142

143+
bool isNull()
144+
{
145+
if (m_offset == 0)
146+
return true;
147+
return false;
148+
}
149+
141150
static sSaturnPtr& getNull()
142151
{
143152
static sSaturnPtr temp;
@@ -413,3 +422,7 @@ struct sProcessed3dModel
413422

414423
extern p_workArea(*gFieldOverlayFunction)(p_workArea workArea, u32 arg);
415424
fixedPoint distanceSquareBetween2Points(const sVec3_FP& r4_vertice0, const sVec3_FP& r5_vertice1);
425+
426+
void RendererSetFov(float fovInDegree);
427+
s32 MTH_Product2d(s32(&r4)[2], s32(&r5)[2]);
428+
fixedPoint MulVec2(const sVec2_FP& r4, const sVec2_FP& r5);

AzelLib/PDS_Logger.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#include "PDS.h"
22

3+
#ifndef SHIPPING_BUILD
34
sPDS_Logger PDS_Logger[eLogCategories::log_max];
5+
#endif

AzelLib/PDS_Logger.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
2-
2+
3+
#ifndef SHIPPING_BUILD
34
struct sPDS_Logger
45
{
56
ImGuiTextBuffer Buf;
@@ -10,7 +11,7 @@ struct sPDS_Logger
1011
void Clear() { Buf.clear(); LineOffsets.clear(); }
1112

1213
void AddLog(const char* fmt, ...)
13-
{
14+
{
1415
{
1516
va_list args;
1617
va_start (args, fmt);
@@ -82,8 +83,16 @@ enum eLogCategories
8283
log_max
8384
};
8485
extern sPDS_Logger PDS_Logger[eLogCategories::log_max];
86+
#endif
8587

88+
#ifdef SHIPPING_BUILD
89+
#define PDS_Log(string, ...)
90+
#define PDS_CategorizedLog(logCategory, string, ...)
91+
#define PDS_unimplemented(name)
92+
#define PDS_warningOnce(name)
93+
#else
8694
#define PDS_Log(string, ...) {PDS_Logger[log_default].AddLog(string, __VA_ARGS__);}
8795
#define PDS_CategorizedLog(logCategory, string, ...) {PDS_Logger[logCategory].AddLog(string, __VA_ARGS__);}
8896
#define PDS_unimplemented(name) { static bool printed = false; if(!printed) {printed = true; PDS_Logger[log_unimlemented].AddLog("Unimplemented: %s\n", name);}}
89-
#define PDS_warningOnce(name) { static bool printed = false; if(!printed) {printed = true; PDS_Logger[log_warning].AddLog("Warning: %s\n", name);}}
97+
#define PDS_warningOnce(name) { static bool printed = false; if(!printed) {printed = true; PDS_Logger[log_warning].AddLog("Warning: %s\n", name);}}
98+
#endif

AzelLib/common.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ struct sVec2_FP
209209
}
210210
};
211211

212+
void Imgui_FP(const char* label, fixedPoint* pFP);
213+
void Imgui_FP_Angle(const char* name, fixedPoint* pFP);
214+
void Imgui_Vec3FP(sVec3_FP* pVector);
215+
void Imgui_Vec3FP(const char* name, sVec3_FP* pVector);
216+
217+
212218
#include "kernel/fade.h"
213219

214220
struct sInterpolator_FP
@@ -670,8 +676,8 @@ struct s_graphicEngineStatus_405C
670676

671677
fixedPoint m10;
672678
fixedPoint m14_farClipDistance; // max distance for drawing laser?
673-
fixedPoint m18;
674-
fixedPoint m1C;
679+
fixedPoint m18_widthScale;
680+
fixedPoint m1C_heightScale;
675681
fixedPoint m20_heightRatio2;
676682
fixedPoint m24_heightRatio;
677683
fixedPoint m28_widthRatio2;

AzelLib/field.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ struct s_dragonTaskWorkArea : s_workAreaTemplateWithArg<s_dragonTaskWorkArea, s3
474474

475475
u32 m_1C4;
476476

477-
fixedPoint m1CC;
477+
fixedPoint m1CC_fieldOfView;
478478
s_cameraScript* m1D0_cameraScript;
479479
s_cutsceneData* m1D4_cutsceneData;
480480
s_cutsceneTask* m1D8_cutscene;
@@ -917,8 +917,11 @@ struct s_fieldSub0Task : public s_workAreaTemplate<s_fieldSub0Task>
917917
fieldTaskVar0 = nullptr;
918918

919919
//FIX:
920-
assert(gExitMenuTaskSub1Task->m8 == pThis);
921-
gExitMenuTaskSub1Task->m8 = nullptr;
920+
if(gExitMenuTaskSub1Task)
921+
{
922+
assert(gExitMenuTaskSub1Task->m8 == pThis);
923+
gExitMenuTaskSub1Task->m8 = nullptr;
924+
}
922925
}
923926
};
924927

AzelLib/field/field_a3/a3_background_layer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ struct s_A3_BackgroundLayer : public s_workAreaTemplate<s_A3_BackgroundLayer>
5959
s32 r2 = atan2(r4, 0x80000);
6060
s16 var0 = cameraProperties2.mC_rotation[0] + r2;
6161
s32 var4 = var0 & 0xFFF;
62-
pThis->mC = pThis->m10 - MTH_Mul(graphicEngineStatus.m405C.m1C ,FP_Div(getSin(var4), getCos(var4)));
63-
pThis->m8 = -80 + performModulo(80, MTH_Mul(graphicEngineStatus.m405C.m18, MTH_Mul(cameraProperties2.mC_rotation[1], 0x3243F) << 5));
62+
pThis->mC = pThis->m10 - MTH_Mul(graphicEngineStatus.m405C.m1C_heightScale ,FP_Div(getSin(var4), getCos(var4)));
63+
pThis->m8 = -80 + performModulo(80, MTH_Mul(graphicEngineStatus.m405C.m18_widthScale, MTH_Mul(cameraProperties2.mC_rotation[1], 0x3243F) << 5));
6464
}
6565

6666
static void Draw(s_A3_BackgroundLayer* pThis)

AzelLib/field/field_a3/o_fld_a3.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4264,7 +4264,7 @@ void dragonFieldTaskInitSub2(s_dragonTaskWorkArea* pWorkArea)
42644264

42654265
dragonFieldTaskInitSub2Sub4(&pWorkArea->m48);
42664266

4267-
pWorkArea->m1CC = 0x38E38E3; // field of view
4267+
pWorkArea->m1CC_fieldOfView = 0x38E38E3; // field of view
42684268
pWorkArea->m234 = 0;
42694269

42704270
pWorkArea->m21C_DragonSpeedValues[0] = 0;
@@ -6264,9 +6264,15 @@ void dragonFieldTaskDrawSub1(s_dragonTaskWorkArea* pTypedWorkArea)
62646264
setupLight(lightLocation[0], lightLocation[1], lightLocation[2], pColor->toU32());
62656265
generateLightFalloffMap(pTypedWorkArea->mCB_falloffColor0.toU32(), pTypedWorkArea->mCE_falloffColor1.toU32(), pTypedWorkArea->mD1_falloffColor2.toU32());
62666266
}
6267+
6268+
if (ImGui::Begin("Field"))
6269+
{
6270+
Imgui_FP_Angle("Field of view", &pTypedWorkArea->m1CC_fieldOfView);
6271+
}
6272+
ImGui::End();
62676273

62686274
//0607416C
6269-
initVDP1Projection((pTypedWorkArea->m1CC + (pTypedWorkArea->m1CC < 0)) / 2, 0);
6275+
initVDP1Projection(pTypedWorkArea->m1CC_fieldOfView / 2, 0);
62706276
printMainDebugStats(pTypedWorkArea);
62716277
}
62726278

@@ -7424,11 +7430,11 @@ void Laser1DrawSub0Sub0(std::array<sVec3_FP, 2>&r4, s32 r5, sVec2_S16& r6, sVec2
74247430
var_30[1] = var_2C[1] + MTH_Mul(r10, var_30[1] - var_2C[1]);
74257431
var_30[2] = maxDistance;
74267432

7427-
r6[0] = setDividend(r12.m18, r4[1][0], r4[1][2]);
7428-
r6[1] = setDividend(r12.m1C, r4[1][1], r4[1][2]);
7433+
r6[0] = setDividend(r12.m18_widthScale, r4[1][0], r4[1][2]);
7434+
r6[1] = setDividend(r12.m1C_heightScale, r4[1][1], r4[1][2]);
74297435

7430-
r7[0] = setDividend(r12.m18, r5, maxDistance);
7431-
r7[1] = setDividend(r12.m1C, r5, maxDistance);
7436+
r7[0] = setDividend(r12.m18_widthScale, r5, maxDistance);
7437+
r7[1] = setDividend(r12.m1C_heightScale, r5, maxDistance);
74327438

74337439
if (r7[0] >= 80)
74347440
{
@@ -7708,10 +7714,10 @@ void s_LCSTask340Sub::Laser1DrawSub0(std::array<sVec3_FP, 8>& input_r5, s32 r6,
77087714

77097715
transformAndAddVecByCurrentMatrix(&input_r5[0], &stack70[0]);
77107716

7711-
stack5C[0][0] = setDividend(r14.m18, stack70[0][0], stack70[0][2]);
7712-
stack5C[0][1] = setDividend(r14.m1C, stack70[0][1], stack70[0][2]);
7713-
stack68[0][0] = setDividend(r14.m18, readSaturnS32(r7), stack70[0][2]);
7714-
stack68[0][1] = setDividend(r14.m1C, readSaturnS32(r7), stack70[0][2]);
7717+
stack5C[0][0] = setDividend(r14.m18_widthScale, stack70[0][0], stack70[0][2]);
7718+
stack5C[0][1] = setDividend(r14.m1C_heightScale, stack70[0][1], stack70[0][2]);
7719+
stack68[0][0] = setDividend(r14.m18_widthScale, readSaturnS32(r7), stack70[0][2]);
7720+
stack68[0][1] = setDividend(r14.m1C_heightScale, readSaturnS32(r7), stack70[0][2]);
77157721

77167722
auto r4 = stack88.begin();
77177723
if (stack70[0][2] < 0x3000)
@@ -7737,13 +7743,13 @@ void s_LCSTask340Sub::Laser1DrawSub0(std::array<sVec3_FP, 8>& input_r5, s32 r6,
77377743
while (r11 < stack24)
77387744
{
77397745
transformAndAddVecByCurrentMatrix(&stack1C[r11 + 1], &stack70[1]);
7740-
stack58[0] = r9[0] = setDividend(r14.m18, stack70[1][0], stack70[1][2]);
7741-
stack58[1] = r9[1] = setDividend(r14.m1C, stack70[1][1], stack70[1][2]);
7746+
stack58[0] = r9[0] = setDividend(r14.m18_widthScale, stack70[1][0], stack70[1][2]);
7747+
stack58[1] = r9[1] = setDividend(r14.m1C_heightScale, stack70[1][1], stack70[1][2]);
77427748

77437749
auto stack18 = stack10 + r11 * 4;
77447750
auto stack0 = stack18 + 4;
7745-
stack64[0] = stack68[1][0] = setDividend(r14.m18, readSaturnS32(stack0), stack70[1][2]);
7746-
stack64[1] = stack68[1][1] = setDividend(r14.m1C, readSaturnS32(stack0), stack70[1][2]);
7751+
stack64[0] = stack68[1][0] = setDividend(r14.m18_widthScale, readSaturnS32(stack0), stack70[1][2]);
7752+
stack64[1] = stack68[1][1] = setDividend(r14.m1C_heightScale, readSaturnS32(stack0), stack70[1][2]);
77477753

77487754
if (stack70[1][2] < 0x3000)
77497755
{

AzelLib/fixedPoint.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,43 @@ s32 atan2_FP(s32 y, s32 x)
297297
}
298298
}
299299

300+
void Imgui_FP(const char* label, fixedPoint* pFP)
301+
{
302+
float fValue = pFP->toFloat();
303+
if (ImGui::InputFloat(label, &fValue, 0.01, 0.1))
304+
{
305+
pFP->m_value = fValue * 0x10000;
306+
}
307+
}
308+
309+
void Imgui_FP_Angle(const char* label, fixedPoint* pFP)
310+
{
311+
// 1 = sin(1024)
312+
// 1024 = pi/2
313+
// conversion is (pi/2)/1024
314+
float fValueInRad = pFP->toFloat() * ((glm::pi<float>() / 2.f) / 1024.f);
315+
float fValueInDegree = glm::degrees<float>(fValueInRad);
316+
if (ImGui::InputFloat(label, &fValueInDegree, 0.01, 0.1))
317+
{
318+
fValueInRad = glm::radians<float>(fValueInDegree);
319+
320+
pFP->m_value = (fValueInRad / ((glm::pi<float>() / 2.f) / 1024.f)) * 0x10000;
321+
}
322+
}
323+
324+
void Imgui_Vec3FP(sVec3_FP* pVector)
325+
{
326+
ImGui::PushItemWidth(100);
327+
Imgui_FP("x", &pVector->m_value[0]); ImGui::SameLine();
328+
Imgui_FP("y", &pVector->m_value[1]); ImGui::SameLine();
329+
Imgui_FP("z", &pVector->m_value[2]);
330+
ImGui::PopItemWidth();
331+
}
332+
333+
void Imgui_Vec3FP(const char* name, sVec3_FP* pVector)
334+
{
335+
ImGui::Text(name); ImGui::SameLine();
336+
ImGui::PushID(name);
337+
Imgui_Vec3FP(pVector);
338+
ImGui::PopID();
339+
}

0 commit comments

Comments
 (0)