Skip to content

Commit

Permalink
zParPTank nearly equivalent. (#280)
Browse files Browse the repository at this point in the history
* Start decomping zParPTank.cpp

* zParPTank nearly 100% equivalent.

Game crashes after leaving the main menu.
  • Loading branch information
SquareMan authored Jun 27, 2024
1 parent 89958ff commit 6fea765
Show file tree
Hide file tree
Showing 13 changed files with 1,195 additions and 36 deletions.
253 changes: 240 additions & 13 deletions include/rwsdk/rpptank.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,147 @@ struct RpPTankData
RwMatrix cMatrix;
};

typedef void* (*RpPTankAllocCallBack)(RpPTankData* ptankGlobal, RwInt32 maxPCount,
RwUInt32 dataFlags, RwUInt32 platFlags);
typedef RwBool (*RpPTankCreateCallBack)(RpAtomic* atomic, RpPTankData* ptankGlobal,
RwInt32 maxPCount, RwUInt32 dataFlags, RwUInt32 platFlags);
typedef RwBool (*RpPTankInstanceCallBack)(RpAtomic* atomic, RpPTankData* ptankGlobal,
RwInt32 actPCount, RwUInt32 instFlags);
typedef RwBool (*RpPTankRenderCallBack)(RpAtomic* atomic, RpPTankData* ptankGlobal,
RwInt32 actPCount);

/* data piece size */
extern const RwInt32 datasize[];

#define RPPTANKSIZEPOSITION 0
#define RPPTANKSIZEMATRIX 1
#define RPPTANKSIZENORMAL 2
#define RPPTANKSIZESIZE 3
#define RPPTANKSIZECOLOR 4
#define RPPTANKSIZEVTXCOLOR 5
#define RPPTANKSIZE2DROTATE 6
#define RPPTANKSIZEVTX2TEXCOORDS 7
#define RPPTANKSIZEVTX4TEXCOORDS 8


/**
* \ingroup rpptank
* \ref RpPTankAllocCallBack
*
* ...
*/
typedef void *(* RpPTankAllocCallBack)(RpPTankData *ptankGlobal,
RwInt32 maxPCount,
RwUInt32 dataFlags,
RwUInt32 platFlags);

/**
* \ingroup rpptank
* \ref RpPTankCreateCallBack
*
* ...
*/
typedef RwBool (* RpPTankCreateCallBack)(RpAtomic *atomic,
RpPTankData *ptankGlobal,
RwInt32 maxPCount,
RwUInt32 dataFlags,
RwUInt32 platFlags);

/**
* \ingroup rpptank
* \ref RpPTankInstanceCallBack
* ...
*/
typedef RwBool (* RpPTankInstanceCallBack)(RpAtomic *atomic,
RpPTankData *ptankGlobal,
RwInt32 actPCount,
RwUInt32 instFlags);

/**
* \ingroup rpptank
* \ref RpPTankRenderCallBack
* ...
*/
typedef RwBool (* RpPTankRenderCallBack)(RpAtomic *atomic,
RpPTankData *ptankGlobal,
RwInt32 actPCount);

typedef struct RpPTankCallBacks RpPTankCallBacks;

struct RpPTankCallBacks
{
RpPTankAllocCallBack alloc;
RpPTankCreateCallBack create;
RpPTankInstanceCallBack instance;
RpPTankRenderCallBack render;
RpPTankAllocCallBack alloc;
RpPTankCreateCallBack create;
RpPTankInstanceCallBack instance;
RpPTankRenderCallBack render;
};

/* private typedefs */
typedef struct RpPTANKInstanceSetupData RpPTANKInstanceSetupData;

struct RpPTANKInstanceSetupData
{
RwBool instancePositions;
RwBool instanceUVs;
RwBool instanceColors;
RwBool instanceNormals;

RpPTankLockStruct positionOut;
RpPTankLockStruct UVOut;
RpPTankLockStruct colorsOut;
RpPTankLockStruct normalsOut;

RwV3d right;
RwV3d up;

};

typedef void (* RpPTankGENInstancePosCallback)(
RpPTankLockStruct *dstCluster,
RwV3d *right,
RwV3d *up,
RwInt32 pCount,
RpPTankData *ptankGlobal);

typedef void (* RpPTankGENInstanceCallback)(
RpPTankLockStruct *dstCluster,
RwInt32 pCount,
RpPTankData *ptankGlobal);

typedef void (* RpPTankGENInstanceSetupCallback)(
RpPTANKInstanceSetupData *data,
RpAtomic *atomic,
RpPTankData *ptankGlobal,
RwInt32 actPCount,
RwUInt32 instFlags);

typedef void (* RpPTankGENInstanceEndingCallback)(
RpPTANKInstanceSetupData *data,
RpAtomic *atomic,
RpPTankData *ptankGlobal,
RwInt32 actPCount,
RwUInt32 instFlags);

typedef struct RpPTankAtomicExtPrv RpPTankAtomicExtPrv;

struct RpPTankAtomicExtPrv
{
RwInt32 maxPCount; /* max number of particles */
RwInt32 actPCount; /* number of actives particles */

RwBool isAStructure; /* is in a structure of array form */
void *rawdata; /* unaligned pointer to the PI data */

/* Rendering callback */
RpAtomicCallBackRender defaultRenderCB;

RpPTankCallBacks ptankCallBacks;

/* Instancing CallBacks */
RpPTankGENInstanceSetupCallback insSetupCB;
RpPTankGENInstancePosCallback insPosCB;
RpPTankGENInstanceCallback insUVCB;
RpPTankGENInstanceCallback insColorsCB;
RpPTankGENInstanceCallback insNormalsCB;
RpPTankGENInstanceEndingCallback insEndingCB;

RwUInt32 lockFlags;
RwUInt32 instFlags;
RwUInt32 platFlags;

RpPTankData publicData;
};

enum RpPTankLockFlags
Expand All @@ -58,10 +184,111 @@ enum RpPTankLockFlags
rpPTANKLOCKREAD = ((int)0x80000000)
};

enum RpPTankInstanceFlags
{
rpPTANKIFLAGNONE = ((int)0x00000000),
rpPTANKIFLAGPOSITION = ((int)0x00000001), /**<Particles position changed*/
rpPTANKIFLAGCOLOR = ((int)0x00000002), /**<Particles color changed*/
rpPTANKIFLAGSIZE = ((int)0x00000004), /**<Particles size changed*/
rpPTANKIFLAGMATRIX = ((int)0x00000008), /**<Particles matrix changed*/
rpPTANKIFLAGNORMAL = ((int)0x00000010), /**<Particles normal changed*/
rpPTANKIFLAG2DROTATE = ((int)0x00000020), /**<Particles 2D rotation changed*/
rpPTANKIFLAGVTXCOLOR = ((int)0x00000040), /**<Vertex color changed*/
rpPTANKIFLAGVTX2TEXCOORDS = ((int)0x00000080), /**<Vertex 2 Texture coordinates changed*/
rpPTANKIFLAGVTX4TEXCOORDS = ((int)0x00000100), /**<Vertex 4 Texture coordinates changed*/
/* free = ((int)0x00000200), */
/* free = ((int)0x00000400), */
/* free = ((int)0x00000800), */
/* free = ((int)0x00001000), */
rpPTANKIFLAGCNSCOLOR = ((int)0x00002000), /**<Constant color changed*/
rpPTANKIFLAGCNSSIZE = ((int)0x00004000), /**<Constant size changed*/
rpPTANKIFLAGCNSMATRIX = ((int)0x00008000), /**<Constant matrix changed*/
rpPTANKIFLAGCNSNORMAL = ((int)0x00010000), /**<Constant normal changed*/
rpPTANKIFLAGCNS2DROTATE = ((int)0x00020000), /**<Constant 2D rotation changed*/
rpPTANKIFLAGCNSVTXCOLOR = ((int)0x00040000), /**<Constant vertex color changed*/
rpPTANKIFLAGCNSVTX2TEXCOORDS = ((int)0x00080000), /**<Constant vertex 2 Texture coordinates changed*/
rpPTANKIFLAGCNSVTX4TEXCOORDS = ((int)0x00100000), /**<Constant vertex 4 Texture coordinates changed*/
/* free = ((int)0x00200000), */
/* free = ((int)0x00400000), */
rpPTANKIFLAGACTNUMCHG = ((int)0x00800000), /**<Number of active particle changed*/
rpPTANKIFLAGCENTER = ((int)0x01000000), /**<Center position changed*/
/* free = ((int)0x04000000), */
/* free = ((int)0x08000000), */
rpPTANKIFLAGALPHABLENDING = ((int)0x10000000), /**<Internal Use*/
rpPTANKIFLAGALL = ((int)0xFFFFFFFF),

RPPTANKINSTANCEFLAGSFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
};

enum RpPTankDataFlags
{
rpPTANKDFLAGNONE = ((int)0x00000000),
rpPTANKDFLAGPOSITION = ((int)0x00000001), /**<Uses a position per particle*/
rpPTANKDFLAGCOLOR = ((int)0x00000002), /**<Uses a color per particle*/
rpPTANKDFLAGSIZE = ((int)0x00000004), /**<Uses a size per particle. This flag is ignored if the particle is a matrix.*/
rpPTANKDFLAGMATRIX = ((int)0x00000008), /**<Uses a matrix per particle*/
rpPTANKDFLAGNORMAL = ((int)0x00000010), /**<Uses a normal per particle*/
rpPTANKDFLAG2DROTATE = ((int)0x00000020), /**<Uses a 2D rotation per particle*/
rpPTANKDFLAGVTXCOLOR = ((int)0x00000040), /**<Uses a color per Billboard vertex*/
rpPTANKDFLAGVTX2TEXCOORDS = ((int)0x00000080), /**<Uses Top-Left and Bottom-Right Texture coordinates*/
rpPTANKDFLAGVTX4TEXCOORDS = ((int)0x00000100), /**<Uses a texture UV per vertex*/
/* free = ((int)0x00000200), */
/* free = ((int)0x00000400), */
/* free = ((int)0x00000800), */
/* free = ((int)0x00001000), */
/* free = ((int)0x00002000), */
/* free = ((int)0x00004000), */
rpPTANKDFLAGCNSMATRIX = ((int)0x00008000), /**<Uses a constant matrix*/
rpPTANKDFLAGCNSNORMAL = ((int)0x00010000), /**<Uses a constant normal*/
rpPTANKDFLAGCNS2DROTATE = ((int)0x00020000), /**<Uses a constant 2D rotation*/
rpPTANKDFLAGCNSVTXCOLOR = ((int)0x00040000), /**<Uses a constant color per Billboard vertex*/
rpPTANKDFLAGCNSVTX2TEXCOORDS = ((int)0x00080000), /**<Uses constant Top-Left and Bottom-Right Texture coordinates*/
rpPTANKDFLAGCNSVTX4TEXCOORDS = ((int)0x00100000), /**<Uses a constant texture UV per vertex*/
/* free = ((int)0x00200000), */
/* free = ((int)0x00400000), */
/* free = ((int)0x00800000), */
rpPTANKDFLAGUSECENTER = ((int)0x01000000), /**<The position of the particles are shifted*/
/* free = ((int)0x04000000), */
/* free = ((int)0x08000000), */
rpPTANKDFLAGARRAY = ((int)0x10000000), /**<Data is organized in an array */
rpPTANKDFLAGSTRUCTURE = ((int)0x20000000), /**<Data is organized in a structure */

RPPTANKDATAFLAGSFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
};

enum RpPTankDataLockFlags
{
rpPTANKLFLAGNONE = ((int)0x00000000),
rpPTANKLFLAGPOSITION = ((int)0x00000001), /**<Access the positions buffer*/
rpPTANKLFLAGCOLOR = ((int)0x00000002), /**<Access the colors buffer*/
rpPTANKLFLAGSIZE = ((int)0x00000004), /**<Access the sizes buffer*/
rpPTANKLFLAGMATRIX = ((int)0x00000008), /**<Access the matrixes buffer*/
rpPTANKLFLAGNORMAL = ((int)0x00000010), /**<Access the normals buffer*/
rpPTANKLFLAG2DROTATE = ((int)0x00000020), /**<Access the 2D rotations buffer*/
rpPTANKLFLAGVTXCOLOR = ((int)0x00000040), /**<Access the colors buffer (when using a color per vertex) */
rpPTANKLFLAGVTX2TEXCOORDS = ((int)0x00000080), /**<Access the Top-Left and Bottom-Right Texture coordinates buffer*/
rpPTANKLFLAGVTX4TEXCOORDS = ((int)0x00000100), /**<Access the texture UVs Buffer (when using a color per vertex)*/

RPPTANKLOCKFLAGSFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
};

#ifdef __cplusplus
extern "C" {
#endif


/* private globals */
extern RwInt32 _rpPTankAtomicDataOffset; /* Offset in RpAtomic */

extern RwInt32 _rpPTankGlobalsOffset; /* Offset in RwEngine */

/* Macro tools */
#define RPATOMICPTANKPLUGINDATA(atomic) \
(*RWPLUGINOFFSET(RpPTankAtomicExtPrv *, (atomic), _rpPTankAtomicDataOffset))

#define GLOBALPTANKPLUGINDATA() \
(*RWPLUGINOFFSET(void *, RwEngineInstance, _rpPTankGlobalsOffset))

extern RwBool RpPTankPluginAttach(void);
extern RpAtomic* RpPTankAtomicCreate(RwInt32 maxParticleNum, RwUInt32 dataFlags,
RwUInt32 platFlags);
Expand All @@ -76,4 +303,4 @@ extern RpAtomic* RpPTankAtomicUnlock(RpAtomic* atomic);
}
#endif

#endif
#endif
41 changes: 40 additions & 1 deletion include/rwsdk/rwplcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,8 @@ struct RwPluginRegEntry
RwPluginRegistry* parentRegistry;
};

#define RWPLUGINOFFSET(_type, _base, _offset) ((_type*)((RwUInt8*)(_base) + (_offset)))

enum RwOpCombineType
{
rwCOMBINEREPLACE = 0,
Expand Down Expand Up @@ -686,15 +688,52 @@ struct RwMatrixTag

typedef struct RwMatrixTag RwMatrix;

#if (!defined(RwMatrixCopyMacro))
#define RwMatrixCopyMacro(_target, _source) (*(_target) = *(_source))
#endif /* (!defined(RwMatrixCopyMacro)) */

#if (!defined(RwMatrixSetIdentityMacro))
#define RwMatrixSetIdentityMacro(m) \
MACRO_START \
{ \
(m)->right.x = (m)->up.y = (m)->at.z = (RwReal)((1.0)); \
(m)->right.y = (m)->right.z = (m)->up.x = (RwReal)((0.0)); \
(m)->up.z = (m)->at.x = (m)->at.y = (RwReal)((0.0)); \
(m)->pos.x = (m)->pos.y = (m)->pos.z = (RwReal)((0.0)); \
rwMatrixSetFlags((m), rwMatrixGetFlags(m) | \
(rwMATRIXINTERNALIDENTITY | rwMATRIXTYPEORTHONORMAL)); \
} \
MACRO_STOP
#endif /* (!defined(RwMatrixSetIdentityMacro)) */

typedef void (*rwMatrixMultFn)(RwMatrix* dstMat, const RwMatrix* matA, const RwMatrix* matB);

typedef struct RwMatrixTolerance RwMatrixTolerance;

#ifndef RWADOXYGENEXTERNAL
/**
* \ingroup rwmatrix
* \struct RwMatrixTolerance
* Holds tolerances for matrix optimizations with \ref RwMatrixOptimize
*/
#endif /* RWADOXYGENEXTERNAL */
struct RwMatrixTolerance
{
RwReal Normal;
/**< Tolerance within which matrix is deemed to be normal */
RwReal Orthogonal;
/**< Tolerance within which matrix is deemed to be orthogonal */
RwReal Identity;
/**< Tolerance within which matrix is deemed to be identity */
};

#define rwMatrixSetFlags(m, flagsbit) ((m)->flags = (flagsbit))
#define rwMatrixGetFlags(m) ((m)->flags)
#define rwMatrixTestFlags(m, flagsbit) ((m)->flags & (RwInt32)(flagsbit))

#define RwMatrixCopy(dst, src) RwMatrixCopyMacro(dst, src)
#define RwMatrixSetIdentity(m) RwMatrixSetIdentityMacro(m)

#define RwMatrixGetRight(m) (&(m)->right)
#define RwMatrixGetUp(m) (&(m)->up)
#define RwMatrixGetAt(m) (&(m)->at)
Expand Down Expand Up @@ -1348,4 +1387,4 @@ extern RwBool RwEngineInit(const RwMemoryFunctions* memFuncs, RwUInt32 initFlags
}
#endif

#endif
#endif
3 changes: 1 addition & 2 deletions src/SB/Core/x/xClimate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

_tagClimate* sClimate;

float snow_life = 3.0f;

const float snow_life = 3.0f;
const xVec3 snow_vel = { 0.0f, -2.0f, 0.0f };
const xVec3 snow_dvel = { 0.1f, 0.1f, 0.1f };

Expand Down
2 changes: 2 additions & 0 deletions src/SB/Core/x/xClimate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
struct xEnvAsset;
struct zParEmitter;

extern const float snow_life;

struct _tagRain
{
int32 rain;
Expand Down
6 changes: 5 additions & 1 deletion src/SB/Core/x/xMath2.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ struct xVec2
float32 x;
float32 y;

xVec2& assign(float32 xy)
{
return assign(xy,xy);
}
xVec2& assign(float32 x, float32 y);
float32 length() const;

Expand All @@ -52,4 +56,4 @@ float32 xVec2Dist(float32 x1, float32 y1, float32 x2, float32 y2);
float32 xVec2Dot(const xVec2* a, const xVec2* b);
void xVec2Init(xVec2* v, float32 _x, float32 _y);

#endif
#endif
4 changes: 3 additions & 1 deletion src/SB/Core/x/xParEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ void xParEmitterInit(void* b, void* tasset);
void xParEmitterSetup(xParEmitter* t);
void xParEmitterDestroy();
void xParEmitterUpdate(xBase* to, xScene*, float32 dt);
xPar* xParEmitterEmitCustom(xParEmitter* p, float dt, xParEmitterCustomSettings* info);
xPar* xParEmitterEmitCustom(xParEmitter* p, float32 dt, xParEmitterCustomSettings* info);
float32 xParInterpCompute(int32 interp_mode, xParInterp* r, float32 time, int32 time_has_elapsed,
float32 last_val);

#endif
Loading

0 comments on commit 6fea765

Please sign in to comment.