diff --git a/docs/progress.svg b/docs/progress.svg
index 3ff5e1236..3b5eced9b 100644
--- a/docs/progress.svg
+++ b/docs/progress.svg
@@ -15,7 +15,7 @@
S_InsertRoom
calc_object_vertices
calc_vertice_light
-calc_roomvert
+calc_roomvert
phd_RotateLight
phd_InitPolyList
phd_SortPolyList
@@ -770,7 +770,7 @@
DoDetailOptionHW
HWR_SetHardwareVideoMode
LoadLevel
-calc_roomvert
+calc_roomvert
sub_405F90
BearControl
WolfControl
@@ -1431,10 +1431,10 @@
SampleLoader
KeyGet
S_CDVolume
-Functions decompiled (count): 93.01%
-Functions decompiled (bytesize): 88.73%
-Functions not decompiled, but with known names (count): 4.48%
-Functions not decompiled, but with known names (bytesize): 4.51%
+Functions decompiled (count): 93.15%
+Functions decompiled (bytesize): 89.16%
+Functions not decompiled, but with known names (count): 4.34%
+Functions not decompiled, but with known names (bytesize): 4.08%
Functions not decompiled, with unknown names (count): 2.52%
Functions not decompiled, with unknown names (bytesize): 6.76%
diff --git a/docs/progress.txt b/docs/progress.txt
index c80f7f488..9c7960a1b 100644
--- a/docs/progress.txt
+++ b/docs/progress.txt
@@ -24,7 +24,7 @@ phd_PutPolygons 0x00401AD0 0x000000F3 *
S_InsertRoom 0x00401BD0 0x0000006E *
calc_object_vertices 0x00401C40 0x000001B6 +
calc_vertice_light 0x00401E00 0x00000165 +
-calc_roomvert 0x00401F70 0x00000428 -
+calc_roomvert 0x00401F70 0x00000428 +
phd_RotateLight 0x004023A0 0x000000CF +
phd_PointLight ---------- ---------- x
phd_InitPolyList 0x00402470 0x0000002D *
diff --git a/src/3dsystem/3d_gen.c b/src/3dsystem/3d_gen.c
index db7246329..8029ce8bf 100644
--- a/src/3dsystem/3d_gen.c
+++ b/src/3dsystem/3d_gen.c
@@ -533,6 +533,91 @@ int16_t *calc_vertice_light(int16_t *obj_ptr)
return obj_ptr;
}
+int16_t *calc_roomvert(int16_t *obj_ptr)
+{
+ int32_t vertex_count = *obj_ptr++;
+
+ for (int i = 0; i < vertex_count; i++) {
+ int32_t xv = PhdMatrixPtr->_00 * obj_ptr[0]
+ + PhdMatrixPtr->_01 * obj_ptr[1] + PhdMatrixPtr->_02 * obj_ptr[2]
+ + PhdMatrixPtr->_03;
+ int32_t yv = PhdMatrixPtr->_10 * obj_ptr[0]
+ + PhdMatrixPtr->_11 * obj_ptr[1] + PhdMatrixPtr->_12 * obj_ptr[2]
+ + PhdMatrixPtr->_13;
+ int32_t zv = PhdMatrixPtr->_20 * obj_ptr[0]
+ + PhdMatrixPtr->_21 * obj_ptr[1] + PhdMatrixPtr->_22 * obj_ptr[2]
+ + PhdMatrixPtr->_23;
+ PhdVBuf[i].xv = xv;
+ PhdVBuf[i].yv = yv;
+ PhdVBuf[i].zv = zv;
+
+ if (zv < PhdNearZ) {
+ PhdVBuf[i].clip = 0x8000;
+ PhdVBuf[i].g = obj_ptr[3];
+ } else {
+ int16_t clip_flags = 0;
+ int32_t depth = zv >> W2V_SHIFT;
+ if (depth > DEPTH_Q_END) {
+ PhdVBuf[i].g = 0x1FFF;
+ clip_flags |= 16;
+ } else if (depth <= DEPTH_Q_START) {
+ PhdVBuf[i].g = obj_ptr[3];
+ } else {
+ PhdVBuf[i].g = obj_ptr[3] + depth - DEPTH_Q_START;
+ if (!IsWaterEffect) {
+ CLAMPG(PhdVBuf[i].g, 0x1FFF);
+ }
+ }
+
+ int32_t xs = PhdCenterX + xv / (zv / PhdPersp);
+ int32_t ys = PhdCenterY + yv / (zv / PhdPersp);
+ if (IsWibbleEffect) {
+ xs += WibbleTable[(ys + WibbleOffset) & 0x1F];
+ ys += WibbleTable[(xs + WibbleOffset) & 0x1F];
+ }
+
+ if (xs < PhdLeft) {
+ if (xs < -32760) {
+ xs = -32760;
+ }
+ clip_flags |= 1;
+ } else if (xs > PhdRight) {
+ if (xs > 32760) {
+ xs = 32760;
+ }
+ clip_flags |= 2;
+ }
+
+ if (ys < PhdTop) {
+ if (ys < -32760) {
+ ys = -32760;
+ }
+ clip_flags |= 4;
+ } else if (ys > PhdBottom) {
+ if (ys > 32760) {
+ ys = 32760;
+ }
+ clip_flags |= 8;
+ }
+
+ if (IsWaterEffect) {
+ PhdVBuf[i].g += ShadeTable
+ [(((uint8_t)WibbleOffset
+ + (uint8_t)RandTable[(vertex_count - i) % WIBBLE_SIZE])
+ % WIBBLE_SIZE)];
+ CLAMP(PhdVBuf[i].g, 0, 0x1FFF);
+ }
+
+ PhdVBuf[i].xs = xs;
+ PhdVBuf[i].ys = ys;
+ PhdVBuf[i].clip = clip_flags;
+ }
+ obj_ptr += 4;
+ }
+
+ return obj_ptr;
+}
+
void T1MInject3DSystem3DGen()
{
INJECT(0x00401000, phd_GenerateW2V);
@@ -548,6 +633,7 @@ void T1MInject3DSystem3DGen()
INJECT(0x00401A20, visible_zclip);
INJECT(0x00401C40, calc_object_vertices);
INJECT(0x00401E00, calc_vertice_light);
+ INJECT(0x00401F70, calc_roomvert);
INJECT(0x004023A0, phd_RotateLight);
INJECT(0x004025D0, phd_InitWindow);
INJECT(0x004026D0, AlterFOV);
diff --git a/src/3dsystem/3d_gen.h b/src/3dsystem/3d_gen.h
index 455c29685..6bf7c018f 100644
--- a/src/3dsystem/3d_gen.h
+++ b/src/3dsystem/3d_gen.h
@@ -37,6 +37,7 @@ void phd_PopMatrix();
int16_t *calc_object_vertices(int16_t *obj_ptr);
int16_t *calc_vertice_light(int16_t *obj_ptr);
+int16_t *calc_roomvert(int16_t *obj_ptr);
void T1MInject3DSystem3DGen();
diff --git a/src/global/const.h b/src/global/const.h
index 0a1ca4376..726cee874 100644
--- a/src/global/const.h
+++ b/src/global/const.h
@@ -4,6 +4,7 @@
#define MALLOC_SIZE 0x1000000 // 16 MB
#define PHD_ONE 0x10000
#define PHD_DEGREE (PHD_ONE / 360) // = 182
+#define PHD_360 (PHD_ONE) // = 65536 = 0x10000
#define PHD_180 (PHD_ONE / 2) // = 32768 = 0x8000
#define PHD_90 (PHD_ONE / 4) // = 16384 = 0x4000
#define PHD_45 (PHD_ONE / 8) // = 8192 = 0x2000
diff --git a/src/specific/init.c b/src/specific/init.c
index 0aafc9065..bb642c684 100644
--- a/src/specific/init.c
+++ b/src/specific/init.c
@@ -152,10 +152,10 @@ void game_free(int32_t free_size, int32_t type)
void CalculateWibbleTable()
{
for (int i = 0; i < WIBBLE_SIZE; i++) {
- PHD_ANGLE angle = (i * 65536) / WIBBLE_SIZE;
+ PHD_ANGLE angle = (i * PHD_360) / WIBBLE_SIZE;
WibbleTable[i] = phd_sin(angle) * MAX_WIBBLE >> W2V_SHIFT;
ShadeTable[i] = phd_sin(angle) * MAX_SHADE >> W2V_SHIFT;
- RandTable[i] = (GetRandomDraw() >> 5) - 0x01ff;
+ RandTable[i] = (GetRandomDraw() >> 5) - 0x01FF;
}
}