Skip to content

Commit

Permalink
zParCmd equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
SquareMan committed Jul 2, 2024
1 parent f05e183 commit 9a9f825
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 58 deletions.
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def Rel(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
Object(Equivalent, "SB/Game/zMenu.cpp"),
Object(NonMatching, "SB/Game/zMovePoint.cpp"),
Object(NonMatching, "SB/Game/zMusic.cpp"),
Object(NonMatching, "SB/Game/zParCmd.cpp"),
Object(Equivalent, "SB/Game/zParCmd.cpp"),
Object(Matching, "SB/Game/zParEmitter.cpp"),
Object(NonMatching, "SB/Game/zPendulum.cpp"),
Object(Matching, "SB/Game/zPickupTable.cpp"),
Expand Down
13 changes: 12 additions & 1 deletion src/SB/Core/x/xParCmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ struct xParCmdRandomVelocityPar : xParCmdAsset

// XPARCMD_TYPE_CUSTOM
void xParCmdCustom_Update(xParCmd* c, xParGroup* ps, float32 dt);

struct xParCmdCustom : xParCmdAsset // not in dwarf
{
uint32 unknown;
};

void xParCmdCustom_Grass_Update(xParCmd* c, xParGroup* ps, float32 dt);

// XPARCMD_TYPE_KILLDISTANCE
Expand Down Expand Up @@ -291,6 +297,11 @@ void xParCmdClipVolumes_Update(xParCmd* c, xParGroup* ps, float32 dt);
// XPARCMD_TYPE_ANIMALMAGENTISM
void xParCmdAnimalMagentism_Update(xParCmd* c, xParGroup* ps, float32 dt);

struct xParCmdAnimalMagnetism : xParCmdAsset // not in dwarf
{
float32 unknown;
};

// XPARCMD_TYPE_DAMAGEPLAYER
void xParCmdDamagePlayer_Update(xParCmd* c, xParGroup* ps, float32 dt);

Expand Down Expand Up @@ -352,4 +363,4 @@ struct xParCmdCollideFallSticky : xParCmdCollideFall
float32 sticky;
};

#endif
#endif
242 changes: 186 additions & 56 deletions src/SB/Game/zParCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,23 @@ void xParCmdPlayerCollision_Update(xParCmd* c, xParGroup* ps, float32 dt)
return;
}

// This function looks like it was written with math operations on the vector types but
// that ends up calling the math operator functions.
void xParCmdAnimalMagentism_Update(xParCmd* c, xParGroup* ps, float dt)
{
xPar* p = ps->m_root;
xParCmdAnimalMagnetism* cmd = (xParCmdAnimalMagnetism*)c->tasset;

xVec3 pos = *xEntGetPos(&globals.player.ent);
pos.y += 1.0f;

float32 mul = dt * -p->m_lifetime;
float32 mul = dt * -cmd->unknown;
for (; p != NULL; p = p->m_next)
{
// xVec3 vec = p->m_pos - pos;
xVec3 vec;
vec.x = p->m_pos.x - pos.x;
vec.y = p->m_pos.y - pos.y;
vec.z = p->m_pos.z - pos.z;
float32 dist = xVec3Normalize(&vec, &vec);

// p->m_vel += vec * mul;
p->m_vel.x += vec.x * mul;
p->m_vel.y += vec.y * mul;
p->m_vel.z += vec.z * mul;
Expand All @@ -127,25 +124,21 @@ void xParCmdAnimalMagentism_Update(xParCmd* c, xParGroup* ps, float dt)
}
else if (dist < 2.0f)
{
// p->m_vel *= dist * 0.5f;
p->m_vel.x *= dist * 0.5f;
p->m_vel.y *= dist * 0.5f;
p->m_vel.z *= dist * 0.5f;
dist *= 0.49f;
p->m_vel.x *= dist;
p->m_vel.y *= dist;
p->m_vel.z *= dist;
}
}
}

// WIP
#if 0
void xParCmdDamagePlayer_Update(xParCmd* c, xParGroup* ps, float dt)
{
xParCmdDamagePlayer* cmd = (xParCmdDamagePlayer*)c->tasset;
xPar* p;
xParCmdDamagePlayer* cmd = (xParCmdDamagePlayer*)c->tasset;
xBound* pbound = &globals.player.ent.bound;
int32 last_idx = 10 - (xrand() & 1);

// int32 i = 0;
// for (; p != NULL, last_idx > 0; last_idx--)
p = ps->m_root;
while (p != NULL && last_idx-- > 0)
{
Expand All @@ -159,67 +152,204 @@ void xParCmdDamagePlayer_Update(xParCmd* c, xParGroup* ps, float dt)
memset(&bnd_fake, 0, sizeof(xBound));
bnd_fake.type = XBOUND_TYPE_SPHERE;

while (p != NULL && last_idx > 0)
while (p != NULL)
{
// for (; last_idx < 1 && p != NULL;)
// while (cmd->granular <= 0)
if (p->m_lifetime > 0.1f)
{
if (p->m_lifetime > 0.1f)
collis.flags = 0;
if (p->m_size > 1.0f)
{
bnd_fake.sph.r = 0.5f * p->m_size;
xVec3Copy(&bnd_fake.sph.center, &p->m_pos);
xQuickCullForBound(&bnd_fake.qcd, &bnd_fake);
xBoundHitsBound(&bnd_fake, pbound, &collis);
}
else
{
xVecHitsBound(&p->m_pos, pbound, &collis);
}

if (collis.flags & 1)
{
collis.flags = 0;
if (p->m_size > 1.0f)
{
bnd_fake.sph.r = 0.5f * p->m_size;
xVec3Copy(&bnd_fake.sph.center, &p->m_pos);
xQuickCullForBound(&bnd_fake.qcd, &bnd_fake);
xBoundHitsBound(&bnd_fake, pbound, &collis);
}
else
{
xVecHitsBound(&p->m_pos, pbound, &collis);
}

if (collis.flags & 1)
{
zEntPlayer_Damage(NULL, 1, NULL);
break;
}

// if (cmd->granular <= 0)
// {
// last_idx = cmd->granular;
// continue;
// }
zEntPlayer_Damage(NULL, 1, NULL);
}
}

// for()
if(cmd->granular)
for (int32 i = 0; i < cmd->granular; i++)
{
if (p == NULL)
{
return;
break;
}
p = p->m_next;
}
// for (; !last_idx != 0;)
// while (cmd->granular != 0)
// while(p != NULL)
// {
// p = p->m_next;
// }
}
}
#endif

void xParCmdJet_Update(xParCmd*, xParGroup*, float)
void xParCmdJet_Update(xParCmd* c, xParGroup* ps, float dt)
{
xPar* p;
xParCmdJet* cmd = (xParCmdJet*)c->tasset;
float32 mdt = cmd->gravity * dt;

xVec3 center;
if (cmd->mode == 0)
{
center.x = globals.player.ent.model->Mat->pos.x;
center.y = globals.player.ent.model->Mat->pos.y;
center.z = globals.player.ent.model->Mat->pos.z;
}
else
{
center = cmd->center;
}

for (p = ps->m_root; p != NULL; p = p->m_next)
{
xVec3 r;
xVec3Sub(&r, &center, &p->m_pos);

float32 rSqr = r.x * r.x + r.y * r.y + r.z * r.z;
if (!(rSqr < cmd->radiusSqr))
{
continue;
}

float32 oorSqr = mdt / xsqrt(rSqr + cmd->epsilon);
r.x = r.x < 0.0f ? 1.0f : -1.0f;
r.z = r.z < 0.0f ? 1.0f : -1.0f;

p->m_vel.x = cmd->acc.x * oorSqr * r.x + p->m_vel.x;
p->m_vel.y = cmd->acc.y * oorSqr + p->m_vel.y;
p->m_vel.z = cmd->acc.z * oorSqr * r.z + p->m_vel.z;
}
}

void xParCmdCustom_Grass_Update(xParCmd*, xParGroup*, float)
// Extremely different float regalloc and scheduling, but looks equivalent
void xParCmdCustom_Grass_Update(xParCmd* c, xParGroup* ps, float dt)
{
xPar* p;

xVec3 pos;
pos.x = globals.player.ent.model->Mat->pos.x;
pos.y = globals.player.ent.model->Mat->pos.y;
pos.z = globals.player.ent.model->Mat->pos.z;

for (p = ps->m_root; p != NULL; p = p->m_next)
{
xVec3 r;
xVec3Sub(&r, &pos, &p->m_pos);

float32 rSqr = r.x * r.x + r.y * r.y + r.z * r.z;
if (rSqr < 2.0f)
{
p->m_size = p->m_size - 4.0f * dt;

if (p->m_size < 0.1f)
{
p->m_size = 0.1f;
}
}
else
{
p->m_size = p->m_size + .01f * dt;
if (p->m_size > 1.0f)
{
p->m_size = 1.0f;
}
}
}
}

void xParCmdApplyCamMat_Update(xParCmd*, xParGroup*, float)
void xParCmdApplyCamMat_Update(xParCmd* c, xParGroup* ps, float dt)
{
xPar* p;
xParCmdApplyCamMat* cmd = (xParCmdApplyCamMat*)c->tasset;
xMat4x3* mat = &globals.camera.mat;
float32 mul;

if (cmd->apply.x != 0.0f)
{
mul = dt * cmd->apply.x;
for (p = ps->m_root; p != NULL; p = p->m_next)
{
p->m_vel.x += mat->right.x * mul;
p->m_vel.y += mat->right.y * mul;
p->m_vel.z += mat->right.z * mul;
}
}

if (cmd->apply.y != 0.0f)
{
mul = dt * cmd->apply.y;
for (p = ps->m_root; p != NULL; p = p->m_next)
{
p->m_vel.x += mat->up.x * mul;
p->m_vel.y += mat->up.y * mul;
p->m_vel.z += mat->up.z * mul;
}
}

if (cmd->apply.z != 0.0f)
{
mul = dt * cmd->apply.z;
for (p = ps->m_root; p != NULL; p = p->m_next)
{
p->m_vel.x += mat->at.x * mul;
p->m_vel.y += mat->at.y * mul;
p->m_vel.z += mat->at.z * mul;
}
}
}

void xParCmdCustom_Update(xParCmd*, xParGroup*, float)
void xParCmdCustom_Update(xParCmd* c, xParGroup* ps, float dt)
{
xPar* p = ps->m_root;
xParCmdCustom* cmd = (xParCmdCustom*)c->tasset;

switch (cmd->unknown)
{
case 0:
float32 mdt = 4.0f * dt;
xVec3 pos;
pos.x = globals.player.ent.model->Mat->pos.x;
pos.y = globals.player.ent.model->Mat->pos.y;
pos.z = globals.player.ent.model->Mat->pos.z;

for (; p != NULL; p = p->m_next)
{
xVec3 r;
xVec3Sub(&r, &pos, &p->m_pos);
float32 rSqr = r.x * r.x + r.y * r.y + r.z * r.z;
if (!(rSqr < 16.0f))
{
continue;
}

float32 oorSqr = xsqrt(rSqr + 0.001f);
r.x = r.x < 0.0f ? 1.0f : -1.0f;
r.z = r.z < 0.0f ? 1.0f : -1.0f;

p->m_size = 1.0f / (10.0f * (mdt / oorSqr) * (r.x + r.z));
}
break;
case 2:
for (; p != NULL; p = p->m_next)
{
p->m_vel.x = 0.0f;
p->m_vel.y = 0.0f;
p->m_vel.z = 0.0f;
}
break;
case 10:
xParCmdCustom_Grass_Update(c, ps, dt);
break;
case 11:
for (; p != NULL; p = p->m_next)
{
xVec3Length2(&p->m_vel); // ?? Why did they do this
xVec3SMulBy(&p->m_vel, 0.98f);
}
break;
}
}

0 comments on commit 9a9f825

Please sign in to comment.