Skip to content

Commit

Permalink
Work on zParCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
SquareMan committed Jul 2, 2024
1 parent 9131fee commit f05e183
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/SB/Core/x/xBound.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void xBoundUpdate(xBound* b);
void xBoundHitsBound(const xBound* a, const xBound* b, xCollis* c);
void xRayHitsBound(const xRay3* r, const xBound* b, xCollis* c);
void xSphereHitsBound(const xSphere* o, const xBound* b, xCollis* c);
void xVecHitsBound(const xVec3* v, const xBound* b, xCollis* c);
float32 xsqrt(float32 x);

#endif
#endif
1 change: 1 addition & 0 deletions src/SB/Game/zEntPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ extern _CurrentPlayer gCurrentPlayer;
void zEntPlayer_Load(xEnt*, xSerial*);

int32 zEntPlayer_Damage(xBase* src, uint32 damage);
int32 zEntPlayer_Damage(xBase* src, uint32 damage, const xVec3* knockback);

uint32 WalkCheck(xAnimTransition* tran, xAnimSingle* anim, void* param_3);
uint32 RunCheck(xAnimTransition* tran, xAnimSingle* anim, void* param_3);
Expand Down
193 changes: 183 additions & 10 deletions src/SB/Game/zParCmd.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#include "zParCmd.h"
#include "zScene.h"
#include "zVolume.h"
#include "xParCmd.h"
#include "xString.h"

#include <types.h>
#include <string.h>
#include <stdio.h>

extern zVolume* sClipVolume[32];
extern int32 sClipVolumeTotal;
#include "xParCmd.h"
#include "xMath.h"
#include "xString.h"

#include "zGlobals.h"
#include "zScene.h"
#include "zVolume.h"

extern char* zParCmd_strings;
static zVolume* sClipVolume[32];
static int32 sClipVolumeTotal;

void zParCmdInit()
{
Expand All @@ -26,8 +28,6 @@ void zParCmdInit()
xParCmdRegister(0x11, 0x10, xParCmdKillDistance_Update);
}

#ifdef NON_MATCHING

void zParCmdFindClipVolumes()
{
char findname[64];
Expand All @@ -44,9 +44,182 @@ void zParCmdFindClipVolumes()
sClipVolume[sClipVolumeTotal] = vol;
}
}
#endif

void xParCmdKillDistance_Update(xParCmd* c, xParGroup* ps, float)
{
xPar* p = ps->m_root;
xParCmdKillDistance* cmd = (xParCmdKillDistance*)c->tasset;
xVec3* camera_pos = &globals.camera.mat.pos;
xVec3 out;

if (cmd->kill_greater_than)
{
for (; p != NULL; p = p->m_next)
{
xVec3Sub(&out, &p->m_pos, camera_pos);
if (xVec3Length2(&out) > cmd->dSqr)
{
p->m_lifetime = -1.0f;
}
}
}
else
{
for (; p != NULL; p = p->m_next)
{
xVec3Sub(&out, &p->m_pos, camera_pos);
if (xVec3Length2(&out) < cmd->dSqr)
{
p->m_lifetime = -1.0f;
}
}
}
}

// Equivalent. The original function mixes the sClipVolume load into the prologue
void xParCmdClipVolumes_Update(xParCmd* c, xParGroup* ps, float)
{
for (xPar* p = ps->m_root; p != NULL; p = p->m_next)
{
for (int32 i = 0; i < sClipVolumeTotal; i++)
{
xCollis collis;
xVecHitsBound(&p->m_pos, &sClipVolume[i]->asset->bound, &collis);
if (collis.flags & 1)
{
p->m_lifetime = -1.0f;
}
}
}
}

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;

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

float32 mul = dt * -p->m_lifetime;
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;
if (dist < 0.25f)
{
p->m_lifetime = -1.0f;
}
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;
}
}
}

// WIP
#if 0
void xParCmdDamagePlayer_Update(xParCmd* c, xParGroup* ps, float dt)
{
xParCmdDamagePlayer* cmd = (xParCmdDamagePlayer*)c->tasset;
xPar* p;
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)
{
p = p->m_next;
}

static xCollis collis;
static xBound bnd_fake;

memset(&collis, 0, sizeof(xCollis));
memset(&bnd_fake, 0, sizeof(xBound));
bnd_fake.type = XBOUND_TYPE_SPHERE;

while (p != NULL && last_idx > 0)
{
// for (; last_idx < 1 && p != NULL;)
// while (cmd->granular <= 0)
{
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)
{
zEntPlayer_Damage(NULL, 1, NULL);
break;
}

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

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

void xParCmdJet_Update(xParCmd*, xParGroup*, float)
{
}

void xParCmdCustom_Grass_Update(xParCmd*, xParGroup*, float)
{
}

void xParCmdApplyCamMat_Update(xParCmd*, xParGroup*, float)
{
}

void xParCmdCustom_Update(xParCmd*, xParGroup*, float)
{
}

0 comments on commit f05e183

Please sign in to comment.