Skip to content

Commit

Permalink
port calc_roomvert
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Oct 14, 2021
1 parent 4248c60 commit d248024
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 9 deletions.
12 changes: 6 additions & 6 deletions docs/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
86 changes: 86 additions & 0 deletions src/3dsystem/3d_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/3dsystem/3d_gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions src/global/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/specific/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit d248024

Please sign in to comment.