diff --git a/configure.py b/configure.py index c385f046f..0b1cf79d4 100644 --- a/configure.py +++ b/configure.py @@ -204,6 +204,8 @@ "-i src/dolphin/include", "-i src/dolphin/src", "-i src", + "-i src/rwsdk", + "-i include/rwsdk", f"-i build/{config.version}/include", f"-DBUILD_VERSION={version_num}", f"-DVERSION_{config.version}", diff --git a/include/rwsdk/rphanim.h b/include/rwsdk/rphanim.h index 320605f7d..5a2ad3951 100644 --- a/include/rwsdk/rphanim.h +++ b/include/rwsdk/rphanim.h @@ -3,6 +3,10 @@ #include "rwcore.h" #include "rtanim.h" +#include "rtquat.h" + +#define rpHANIMDEFAULTFRAMEID -1 +#define rpHANIMSTREAMCURRENTVERSION 0x100 struct RpHAnimNodeInfo { @@ -12,6 +16,9 @@ struct RpHAnimNodeInfo RwFrame* pFrame; }; +typedef struct RpHAnimNodeInfo RpHAnimNodeInfo; +typedef struct RpHAnimHierarchy RpHAnimHierarchy; + struct RpHAnimHierarchy { RwInt32 flags; @@ -34,6 +41,43 @@ enum RpHAnimHierarchyFlag rpHANIMHIERARCHYLOCALSPACEMATRICES = 0x4000, rpHANIMHIERARCHYFLAGFORCEENUMSIZEINT = RWFORCEENUMSIZEINT }; +typedef enum RpHAnimHierarchyFlag RpHAnimHierarchyFlag; + +typedef struct RpHAnimAtomicGlobalVars RpHAnimAtomicGlobalVars; + +struct RpHAnimAtomicGlobalVars +{ + RwInt32 engineOffset; + RwFreeList* HAnimFreeList; +}; + +typedef struct RpHAnimFrameExtension RpHAnimFrameExtension; + +struct RpHAnimFrameExtension +{ + RwInt32 id; + RpHAnimHierarchy* hierarchy; +}; + +typedef struct RpHAnimInterpFrame RpHAnimInterpFrame; + +typedef struct RpHAnimKeyFrame RpHAnimKeyFrame; + +struct RpHAnimKeyFrame +{ + RpHAnimKeyFrame* prevFrame; + RwReal time; + RtQuat q; + RwV3d t; +}; + +struct RpHAnimInterpFrame +{ + RpHAnimKeyFrame* keyFrame1; + RpHAnimKeyFrame* keyFrame2; + RtQuat q; + RwV3d t; +}; #ifdef __cplusplus extern "C" { @@ -60,4 +104,4 @@ extern RpHAnimHierarchy* RpHAnimFrameGetHierarchy(RwFrame* frame); } #endif -#endif \ No newline at end of file +#endif diff --git a/include/rwsdk/rpmatfx.h b/include/rwsdk/rpmatfx.h index f9601fba3..92bd684c7 100644 --- a/include/rwsdk/rpmatfx.h +++ b/include/rwsdk/rpmatfx.h @@ -31,10 +31,15 @@ enum RpMatFXMaterialFlags extern "C" { #endif +typedef struct RxPipeline RxPipeline; +typedef enum RpMatFXGameCubePipeline RpMatFXGameCubePipeline; + extern RxPipeline* RpMatFXGetGameCubePipeline(RpMatFXGameCubePipeline gamecubePipeline); extern RwBool RpMatFXPluginAttach(void); extern RpAtomic* RpMatFXAtomicEnableEffects(RpAtomic* atomic); extern RpWorldSector* RpMatFXWorldSectorEnableEffects(RpWorldSector* worldSector); +typedef enum RpMatFXMaterialFlags RpMatFXMaterialFlags; + extern RpMaterial* RpMatFXMaterialSetEffects(RpMaterial* material, RpMatFXMaterialFlags flags); extern RpMaterial* RpMatFXMaterialSetupBumpMap(RpMaterial* material, RwTexture* texture, RwFrame* frame, RwReal coef); @@ -75,4 +80,4 @@ extern const RpMaterial* RpMatFXMaterialGetUVTransformMatrices(const RpMaterial* } #endif -#endif \ No newline at end of file +#endif diff --git a/include/rwsdk/rpskin.h b/include/rwsdk/rpskin.h index 68eb7623e..3d2051aa5 100644 --- a/include/rwsdk/rpskin.h +++ b/include/rwsdk/rpskin.h @@ -5,7 +5,7 @@ #include "rpworld.h" #include "rphanim.h" -typedef struct RpSkin; +typedef struct RpSkin RpSkin; struct RwMatrixWeights { @@ -34,13 +34,18 @@ extern RpSkin* RpSkinGeometryGetSkin(RpGeometry* geometry); extern RpGeometry* RpSkinGeometrySetSkin(RpGeometry* geometry, RpSkin* skin); extern RpSkin* RpSkinDestroy(RpSkin* skin); extern RwUInt32 RpSkinGetNumBones(RpSkin* skin); +typedef struct RwMatrixWeights RwMatrixWeights; + extern const RwMatrixWeights* RpSkinGetVertexBoneWeights(RpSkin* skin); extern const RwUInt32* RpSkinGetVertexBoneIndices(RpSkin* skin); extern const RwMatrix* RpSkinGetSkinToBoneMatrices(RpSkin* skin); +typedef struct RpAtomic RpAtomic; +typedef enum RpSkinType RpSkinType; + extern RpAtomic* RpSkinAtomicSetType(RpAtomic* atomic, RpSkinType type); #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif diff --git a/include/rwsdk/rpworld.h b/include/rwsdk/rpworld.h index b621b4b25..b6fc8c3df 100644 --- a/include/rwsdk/rpworld.h +++ b/include/rwsdk/rpworld.h @@ -2,8 +2,11 @@ #define RPWORLD_H #include +#include "rpworld.h" -typedef struct RpLight; +typedef struct RpLight RpLight; +typedef struct RwSurfaceProperties RwSurfaceProperties; +typedef struct RpMaterial RpMaterial; struct RpMaterial { @@ -81,6 +84,8 @@ struct RpBuildMeshTriangle RwUInt16 pipelineIndex; }; +typedef struct RpBuildMeshTriangle RpBuildMeshTriangle; + struct RpBuildMesh { RwUInt32 triangleBufferSize; @@ -88,6 +93,8 @@ struct RpBuildMesh RpBuildMeshTriangle* meshTriangles; }; +typedef struct RpMesh RpMesh; + struct RpMesh { RxVertexIndex* indices; @@ -95,6 +102,7 @@ struct RpMesh RpMaterial* material; }; +typedef struct RpMeshHeader RpMeshHeader; struct RpMeshHeader { RwUInt32 flags; @@ -106,7 +114,7 @@ struct RpMeshHeader typedef RpMesh* (*RpMeshCallBack)(RpMesh* mesh, RpMeshHeader* meshHeader, void* pData); -typedef struct RpGeometry; +typedef struct RpGeometry RpGeometry; struct RpMorphTarget { @@ -116,6 +124,11 @@ struct RpMorphTarget RwV3d* normals; }; +typedef struct RpMaterialList RpMaterialList; +typedef struct RpTriangle RpTriangle; +typedef struct RwTexCoords RwTexCoords; +typedef struct RpMorphTarget RpMorphTarget; + struct RpGeometry { RwObject object; @@ -150,7 +163,7 @@ enum RpAtomicFlag rpATOMICFLAGFORCEENUMSIZEINT = RWFORCEENUMSIZEINT }; -typedef struct RpClump; +typedef struct RpClump RpClump; typedef RpClump* (*RpClumpCallBack)(RpClump* clump, void* data); @@ -174,7 +187,7 @@ struct RpInterpolator RwReal position; }; -typedef struct RpAtomic; +typedef struct RpAtomic RpAtomic; typedef RpAtomic* (*RpAtomicCallBackRender)(RpAtomic* atomic); @@ -318,6 +331,8 @@ typedef RpAtomic* (*RpAtomicCallBackRender)(RpAtomic* atomic); #define RpAtomicSetPipeline RpAtomicSetPipelineMacro #define RpAtomicGetPipeline RpAtomicGetPipelineMacro +typedef struct RpInterpolator RpInterpolator; + struct RpAtomic { RwObjectHasFrame object; @@ -351,6 +366,10 @@ struct RpPolygon RwUInt16 vertIndex[3]; }; +typedef struct RpPolygon RpPolygon; +typedef struct RpVertexNormal RpVertexNormal; +typedef struct RpWorldSector RpWorldSector; + struct RpWorldSector { RwInt32 type; @@ -453,6 +472,9 @@ enum RpWorldRenderOrder typedef RpWorldSector* (*RpWorldSectorCallBackRender)(RpWorldSector* worldSector); +typedef enum RpWorldRenderOrder RpWorldRenderOrder; +typedef struct RpSector RpSector; + struct RpWorld { RwObject object; @@ -542,6 +564,8 @@ typedef RpLight* (*RpLightCallBack)(RpLight* light, void* data); extern "C" { #endif +typedef struct RpWorld RpWorld; + extern RpWorld* RpWorldStreamRead(RwStream* stream); extern RpAtomic* AtomicDefaultRenderCallBack(RpAtomic* atomic); extern void _rpAtomicResyncInterpolatedSphere(RpAtomic* atomic); @@ -654,6 +678,7 @@ extern RpMaterialList* _rpMaterialListStreamRead(RwStream* stream, RpMaterialLis extern RpMeshHeader* _rpMeshHeaderCreate(RwUInt32 size); extern void* _rpMeshClose(void* instance, RwInt32 offset, RwInt32 size); extern void* _rpMeshOpen(void* instance, RwInt32 offset, RwInt32 size); +typedef struct RpBuildMesh RpBuildMesh; extern RpBuildMesh* _rpBuildMeshCreate(RwUInt32 bufferSize); extern RwBool _rpBuildMeshDestroy(RpBuildMesh* mesh); extern RwBool _rpMeshDestroy(RpMeshHeader* mesh); @@ -725,4 +750,4 @@ extern RxNodeDefinition* RxNodeDefinitionGetGameCubeWorldSectorAllInOne(void); } #endif -#endif \ No newline at end of file +#endif diff --git a/include/rwsdk/rtanim.h b/include/rwsdk/rtanim.h index bca0b2e20..13c13f8de 100644 --- a/include/rwsdk/rtanim.h +++ b/include/rwsdk/rtanim.h @@ -3,7 +3,7 @@ #include "rwcore.h" -typedef struct RtAnimAnimation; +typedef struct RtAnimAnimation RtAnimAnimation; typedef void (*RtAnimKeyFrameApplyCallBack)(void* result, void* voidIFrame); typedef void (*RtAnimKeyFrameBlendCallBack)(void* voidOut, void* voidIn1, void* voidIn2, @@ -17,6 +17,8 @@ typedef RtAnimAnimation* (*RtAnimKeyFrameStreamReadCallBack)(RwStream* stream, typedef RwBool (*RtAnimKeyFrameStreamWriteCallBack)(RtAnimAnimation* animation, RwStream* stream); typedef RwInt32 (*RtAnimKeyFrameStreamGetSizeCallBack)(RtAnimAnimation* animation); +typedef struct RtAnimInterpolatorInfo RtAnimInterpolatorInfo; + struct RtAnimInterpolatorInfo { RwInt32 typeID; @@ -43,7 +45,7 @@ struct RtAnimAnimation void* customData; }; -typedef struct RtAnimInterpolator; +typedef struct RtAnimInterpolator RtAnimInterpolator; typedef RtAnimInterpolator* (*RtAnimCallBack)(RtAnimInterpolator* animInstance, void* data); @@ -83,4 +85,4 @@ extern void RtAnimInterpolatorDestroy(RtAnimInterpolator* anim); } #endif -#endif \ No newline at end of file +#endif diff --git a/include/rwsdk/rtquat.h b/include/rwsdk/rtquat.h index ff402d361..e92fdf4df 100644 --- a/include/rwsdk/rtquat.h +++ b/include/rwsdk/rtquat.h @@ -1,64 +1,18 @@ #ifndef RTQUAT_H #define RTQUAT_H -/** - * \defgroup rtquat RtQuat - * \ingroup mathtools - * - * Quaternion Toolkit for RenderWare. - * - * See also http://www.gamasutra.com/features/19980703/quaternions_01.htm - */ - -/* - * See http://www-groups.dcs.st-and.ac.uk/~history/Mathematicians/Hamilton.html - * On 16 October 1843 (a Monday) Hamilton was walking in along the Royal - * Canal with his wife to preside at a Council meeting of the Royal Irish - * Academy. - * - * Although his wife talked to him now and again Hamilton hardly - * heard, for the discovery of the quaternions, the first noncommutative - * algebra to be studied, was taking shape in his mind:- - * - * "And here there dawned on me the notion that we must admit, in - * some sense, a fourth dimension of space for the purpose of calculating - * with triples ... An electric circuit seemed to close, and a spark - * flashed forth." - */ - -/**************************************************************************** - Includes - */ - #include -/* renderware */ -//#include "rwplcore.h" - -//#include "rtquat.rpe" /* automatically generated header file */ +#include "rwcore.h" #define RW_TOL_ORTHONORMAL ((RwReal)0.01) -/**************************************************************************** - Global Types - */ - typedef struct RtQuat RtQuat; -/** - * \ingroup rtquat - * \struct RtQuat - * A structure describing a Quaternion - * -*/ struct RtQuat { - RwV3d imag; /**< The imaginary part(s) */ - RwReal real; /**< The real part */ + RwV3d imag; + RwReal real; }; -/**************************************************************************** - Defines - */ - #define RtQuatInitMacro(result, _x, _y, _z, _w) \ MACRO_START \ { \ @@ -71,7 +25,7 @@ struct RtQuat #if (!defined(RtQuatAssignMacro)) #define RtQuatAssignMacro(_target, _source) (*(_target) = *(_source)) -#endif /* (!defined(RtQuatAssignMacro)) */ +#endif #define RtQuatAddMacro(result, q1, q2) \ MACRO_START \ @@ -159,9 +113,6 @@ struct RtQuat #define RtQuatMultiplyMacro(result, q1, q2) \ MACRO_START \ { \ - /* \ - * Assumes q1 != result != q2 \ - */ \ (result)->real = (q1)->real * (q2)->real - RwV3dDotProductMacro(&(q1)->imag, &(q2)->imag); \ RwV3dCrossProductMacro(&(result)->imag, &(q1)->imag, &(q2)->imag); \ RwV3dIncrementScaledMacro(&(result)->imag, &(q2)->imag, (q1)->real); \ @@ -172,9 +123,6 @@ struct RtQuat #define RtQuatReciprocalMacro(result, q) \ MACRO_START \ { \ - /* \ - * Assumes result != q \ - */ \ RwReal val = RtQuatModulusSquaredMacro(q); \ \ if (val > (RwReal)0) \ @@ -190,9 +138,6 @@ struct RtQuat #define RtQuatSquareMacro(result, q) \ MACRO_START \ { \ - /* \ - * Assumes result != q \ - */ \ RwReal val = ((RwReal)2) * (q)->real; \ \ (result)->real = (q)->real * (q)->real - RwV3dDotProductMacro(&(q)->imag, &(q)->imag); \ @@ -467,14 +412,11 @@ struct RtQuat #define RtQuatUnitConvertToMatrix(qpQuat, mpMatrix) RtQuatUnitConvertToMatrixMacro(qpQuat, mpMatrix) -#endif /* (! ( defined(RWDEBUG) || defined(RWSUPPRESSINLINE) )) */ +#endif -/**************************************************************************** - Function prototypes - */ #ifdef __cplusplus extern "C" { -#endif /* __cplusplus */ +#endif extern RwBool RtQuatConvertFromMatrix(RtQuat* const qpQuat, const RwMatrix* const mpMatrix); @@ -536,15 +478,11 @@ extern void RtQuatConvertToMatrix(const RtQuat* const qpQuat, RwMatrix* const mp extern void RtQuatUnitConvertToMatrix(const RtQuat* const qpQuat, RwMatrix* const mpMatrix); -#endif /* ( defined(RWDEBUG) || defined(RWSUPPRESSINLINE) ) */ +#endif #ifdef __cplusplus } -#endif /* __cplusplus */ - -/* - * Backwards compatibility code - */ +#endif typedef RtQuat RpQuat; @@ -552,4 +490,4 @@ typedef RtQuat RpQuat; #define RpAnimQuatConvertToMatrix(qpQuat, mpMatrix) RtQuatUnitConvertToMatrix(qpQuat, mpMatrix) -#endif /* RTQUAT_H */ +#endif diff --git a/include/rwsdk/rwcore.h b/include/rwsdk/rwcore.h index 311d8bfc1..025d83f93 100644 --- a/include/rwsdk/rwcore.h +++ b/include/rwsdk/rwcore.h @@ -16,6 +16,9 @@ union RxColorUnion // However, currently decomped functions seem to pack the struct // in this particular way so it's like this for now. // See: zActionLIne.cpp + +typedef union RxColorUnion RxColorUnion; + struct _RxObjSpace3DVertex { RwV3d objVertex; @@ -33,12 +36,16 @@ typedef struct rxHeapSuperBlockDescriptor; typedef struct RxHeap; typedef struct rxHeapBlockHeader; +typedef struct rxHeapBlockHeader rxHeapBlockHeader; + struct rxHeapFreeBlock { RwUInt32 size; rxHeapBlockHeader* ptr; }; +typedef struct rxHeapSuperBlockDescriptor rxHeapSuperBlockDescriptor; + struct rxHeapSuperBlockDescriptor { void* start; @@ -46,6 +53,8 @@ struct rxHeapSuperBlockDescriptor rxHeapSuperBlockDescriptor* next; }; +typedef struct rxHeapFreeBlock rxHeapFreeBlock; + struct RxHeap { RwUInt32 superBlockSize; @@ -57,6 +66,8 @@ struct RxHeap RwBool dirty; }; +typedef struct rxHeapFreeBlock rxHeapFreeBlock; + struct rxHeapBlockHeader { rxHeapBlockHeader *prev, *next; @@ -95,6 +106,8 @@ struct RxClusterDefinition const RwChar* attributeSet; }; +typedef enum RxClusterValid RxClusterValid; + struct RxOutputSpec { RwChar* name; @@ -109,6 +122,9 @@ enum RxClusterForcePresent rxCLUSTERFORCEPRESENTFORCEENUMSIZEINT = RWFORCEENUMSIZEINT }; +typedef struct RxClusterDefinition RxClusterDefinition; +typedef enum RxClusterForcePresent RxClusterForcePresent; + struct RxClusterRef { RxClusterDefinition* clusterDef; @@ -116,6 +132,10 @@ struct RxClusterRef RwUInt32 reserved; }; +typedef struct RxClusterRef RxClusterRef; +typedef enum RxClusterValidityReq RxClusterValidityReq; +typedef struct RxOutputSpec RxOutputSpec; + struct RxIoSpec { RwUInt32 numClustersOfInterest; @@ -125,6 +145,11 @@ struct RxIoSpec RxOutputSpec* outputs; }; +typedef struct RxPipelineNode RxPipelineNode; +typedef struct RxPipelineNodeParam RxPipelineNodeParam; +typedef struct RxNodeDefinition RxNodeDefinition; +typedef struct RxPipeline RxPipeline; + typedef RwBool (*RxNodeBodyFn)(RxPipelineNode* self, const RxPipelineNodeParam* params); typedef RwBool (*RxNodeInitFn)(RxNodeDefinition* self); typedef void (*RxNodeTermFn)(RxNodeDefinition* self); @@ -152,6 +177,10 @@ enum RxNodeDefEditable rxNODEDEFEDITABLEFORCEENUMSIZEINT = RWFORCEENUMSIZEINT }; +typedef struct RxNodeMethods RxNodeMethods; +typedef struct RxIoSpec RxIoSpec; +typedef enum RxNodeDefEditable RxNodeDefEditable; + struct RxNodeDefinition { RwChar* name; @@ -168,6 +197,8 @@ struct RxPipelineCluster RwUInt32 creationAttributes; }; +typedef struct RxPipelineCluster RxPipelineCluster; + struct RxCluster { RwUInt16 flags; @@ -180,6 +211,9 @@ struct RxCluster RwUInt32 attributes; }; +typedef struct RxPipelineCluster RxPipelineCluster; +typedef struct RxCluster RxCluster; + struct RxPacket { RwUInt16 flags; @@ -191,6 +225,8 @@ struct RxPacket RxCluster clusters[1]; }; +typedef struct RxPipelineNodeTopSortData RxPipelineNodeTopSortData; + struct RxPipelineNode { RxNodeDefinition* nodeDef; @@ -205,7 +241,7 @@ struct RxPipelineNode RwUInt32 initializationDataSize; }; -typedef struct rxReq; +typedef struct rxReq rxReq; struct RxPipelineNodeTopSortData { @@ -214,6 +250,8 @@ struct RxPipelineNodeTopSortData rxReq* req; }; +typedef struct RxHeap RxHeap; + struct RxPipelineNodeParam { void* dataParam; @@ -236,6 +274,10 @@ struct RxPipelineRequiresCluster RwUInt32 slotIndex; }; +typedef enum rxEmbeddedPacketState rxEmbeddedPacketState; +typedef struct RxPacket RxPacket; +typedef struct RxPipelineRequiresCluster RxPipelineRequiresCluster; + struct RxPipeline { RwBool locked; @@ -324,6 +366,8 @@ enum RwRasterPrivateFlag #define rwRASTERPALETTELOCKED (rwRASTERPALETTELOCKEDREAD | rwRASTERPALETTELOCKEDWRITE) #define rwRASTERLOCKED (rwRASTERPIXELLOCKED | rwRASTERPALETTELOCKED) +typedef struct RwRaster RwRaster; + struct RwRaster { RwRaster* parent; @@ -356,6 +400,12 @@ struct RwRaster #define RwRasterGetParent(_raster) ((_raster)->parent) +typedef enum RwShadeMode RwShadeMode; +typedef enum RwBlendFunction RwBlendFunction; +typedef enum RwTextureAddressMode RwTextureAddressMode; +typedef enum RwTextureFilterMode RwTextureFilterMode; +typedef enum RwFogType RwFogType; + struct RxRenderStateVector { RwUInt32 Flags; @@ -425,6 +475,8 @@ struct RwTexDictionary RwLLLink lInInstance; }; +typedef struct RwTexDictionary RwTexDictionary; + struct RwTexture { RwRaster* raster; @@ -436,6 +488,8 @@ struct RwTexture RwInt32 refCount; }; +typedef struct RwTexture RwTexture; + typedef RwTexture* (*RwTextureCallBackRead)(const RwChar* name, const RwChar* maskName); typedef RwTexture* (*RwTextureCallBack)(RwTexture* texture, void* pData); @@ -531,12 +585,16 @@ struct RwFrame struct RwFrame* root; }; +typedef struct RwFrame RwFrame; + typedef RwFrame* (*RwFrameCallBack)(RwFrame* frame, void* data); #define RwFrameGetParent(_f) ((RwFrame*)rwObjectGetParent(_f)) #define RwFrameGetMatrix(_f) (&(_f)->modelling) +typedef struct RwObjectHasFrame RwObjectHasFrame; + typedef struct RwObjectHasFrame; typedef RwObjectHasFrame* (*RwObjectHasFrameSyncFunction)(RwObjectHasFrame* object); @@ -586,6 +644,8 @@ enum RwFrustumTestResult rwFRUSTUMTESTRESULTFORCEENUMSIZEINT = RWFORCEENUMSIZEINT }; +typedef struct RwPlane RwPlane; + struct RwFrustumPlane { RwPlane plane; @@ -597,9 +657,16 @@ struct RwFrustumPlane typedef struct RwCamera; +typedef struct RwCamera RwCamera; + typedef RwCamera* (*RwCameraBeginUpdateFunc)(RwCamera* camera); typedef RwCamera* (*RwCameraEndUpdateFunc)(RwCamera* camera); +typedef enum RwCameraProjection RwCameraProjection; +typedef struct RwV2d RwV2d; +typedef struct RwFrustumPlane RwFrustumPlane; +typedef struct RwBBox RwBBox; + struct RwCamera { RwObjectHasFrame object; @@ -668,6 +735,8 @@ extern RwCamera* RwCameraStreamRead(RwStream* stream); extern RwInt32 RwFrameRegisterPluginStream(RwUInt32 pluginID, RwPluginDataChunkReadCallBack readCB, RwPluginDataChunkWriteCallBack writeCB, RwPluginDataChunkGetSizeCallBack getSizeCB); +typedef struct rwFrameList rwFrameList; + extern RwBool _rwFrameListFindFrame(const rwFrameList* frameList, const RwFrame* frame, RwInt32* npIndex); extern rwFrameList* _rwFrameListDeinitialize(rwFrameList* frameList); @@ -685,6 +754,9 @@ extern RwCamera* RwCameraBeginUpdate(RwCamera* camera); extern RwCamera* RwCameraSetViewOffset(RwCamera* camera, const RwV2d* offset); extern RwCamera* RwCameraSetNearClipPlane(RwCamera* camera, RwReal nearClip); extern RwCamera* RwCameraSetFarClipPlane(RwCamera* camera, RwReal farClip); +typedef enum RwFrustumTestResult RwFrustumTestResult; +typedef struct RwSphere RwSphere; + extern RwFrustumTestResult RwCameraFrustumTestSphere(const RwCamera* camera, const RwSphere* sphere); extern RwCamera* RwCameraClear(RwCamera* camera, RwRGBA* colour, RwInt32 clearMode); @@ -716,6 +788,8 @@ extern RwInt32 RwFrameRegisterPlugin(RwInt32 size, RwUInt32 pluginID, RwPluginObjectConstructor constructCB, RwPluginObjectDestructor destructCB, RwPluginObjectCopy copyCB); +typedef struct RwImage RwImage; + extern RwImage* RwImageCreate(RwInt32 width, RwInt32 height, RwInt32 depth); extern RwBool RwImageDestroy(RwImage* image); extern RwImage* RwImageAllocatePixels(RwImage* image); @@ -802,6 +876,8 @@ extern void RxHeapFree(RxHeap* heap, void* block); extern RwBool _rxHeapReset(RxHeap* heap); extern void RxHeapDestroy(RxHeap* heap); extern RxHeap* RxHeapCreate(RwUInt32 size); +typedef struct RxRenderStateVector RxRenderStateVector; + extern RxRenderStateVector* RxRenderStateVectorSetDefaultRenderStateVector(RxRenderStateVector* rsvp); extern RxRenderStateVector* RxRenderStateVectorLoadDriverState(RxRenderStateVector* rsvp); @@ -811,4 +887,4 @@ extern void RwGameCubeCameraTextureFlush(RwRaster* ras, RwUInt32 param); } #endif -#endif \ No newline at end of file +#endif diff --git a/include/rwsdk/rwplcore.h b/include/rwsdk/rwplcore.h index 80c5eba6d..5501bb1dc 100644 --- a/include/rwsdk/rwplcore.h +++ b/include/rwsdk/rwplcore.h @@ -31,12 +31,14 @@ struct RwInt64 RwUInt32 bottom; }; +typedef struct RwUInt64 RwUInt64; struct RwUInt128 { RwUInt64 top; RwUInt64 bottom; }; +typedef struct RwInt64 RwInt64; struct RwInt128 { RwInt64 top; @@ -54,6 +56,16 @@ struct RwInt128 #define RwUInt16MAXVAL 0xFFFF #define RwUInt16MINVAL 0x0000 +#define RWALIGN(type, x) type __attribute__((aligned(x))) +#define rwMATRIXALIGNMENT sizeof(RwUInt32) +#define rwFRAMEALIGNMENT sizeof(RwUInt32) +#define rwV4DALIGNMENT sizeof(RwUInt32) + +#define rwMALLOCALIGNMENT 32 + +/* We define texture names to be a maximum of 16 ISO chars */ +#define rwTEXTUREBASENAMELENGTH 32 + #include #define _RW_C1 ((float)4.1666667908e-02) @@ -140,6 +152,8 @@ union RwSplitBits volatile RwUInt32 nUInt; }; +typedef struct RwSplitFixed RwSplitFixed; + struct RwSplitFixed { RwInt16 integral; @@ -183,6 +197,8 @@ struct RwRect RwInt32 h; }; +typedef struct RwV3d RwV3d; + struct RwSphere { RwV3d center; @@ -213,12 +229,16 @@ enum RwTextureCoordinateIndex rwTEXTURECOORDINATEINDEXFORCEENUMSIZEINT = RWFORCEENUMSIZEINT }; +typedef struct RwTexCoords RwTexCoords; + struct RwTexCoords { RwReal u; RwReal v; }; +typedef struct RwSLLink RwSLLink; + struct RwSLLink { RwSLLink* next; @@ -242,6 +262,8 @@ struct RwSingleList #define rwSingleListGetFirstSLLink(list) ((list)->link.next) #define rwSingleListGetTerminator(list) (NULL) +typedef struct RwLLLink RwLLLink; + struct RwLLLink { RwLLLink* next; @@ -378,6 +400,7 @@ enum RwPlatformID rwID_GAMECUBE, rwID_SOFTRAS, rwID_PCD3D8, + rwID_PCD3D9, rwPLATFROMIDFORCEENUMSIZEINT = RWFORCEENUMSIZEINT }; @@ -389,6 +412,7 @@ struct RwObject RwUInt8 privateFlags; void* parent; }; +typedef struct RwObject RwObject; typedef RwObject* (*RwObjectCallBack)(RwObject* object, void* data); @@ -497,6 +521,8 @@ struct RwMemoryFunctions void* (*rwcalloc)(size_t numObj, size_t sizeObj); }; +typedef struct RwLinkList RwLinkList; + struct RwFreeList { RwUInt32 entrySize; @@ -508,6 +534,8 @@ struct RwFreeList RwLLLink link; }; +typedef struct RwFreeList RwFreeList; + typedef void (*RwFreeListCallBack)(void* pMem, void* pData); typedef void* (*RwMemoryAllocFn)(RwFreeList* fl); typedef RwFreeList* (*RwMemoryFreeFn)(RwFreeList* fl, void* pData); @@ -558,6 +586,10 @@ struct RwStreamCustom void* data; }; +typedef struct RwStreamMemory RwStreamMemory; +typedef union RwStreamFile RwStreamFile; +typedef struct RwStreamCustom RwStreamCustom; + union RwStreamUnion { RwStreamMemory memory; @@ -565,6 +597,10 @@ union RwStreamUnion RwStreamCustom custom; }; +typedef enum RwStreamType RwStreamType; +typedef enum RwStreamAccessType RwStreamAccessType; +typedef union RwStreamUnion RwStreamUnion; + struct RwStream { RwStreamType type; @@ -580,6 +616,8 @@ typedef void* (*RwPluginObjectDestructor)(void* object, RwInt32 offsetInObject, RwInt32 sizeInObject); typedef void* (*RwPluginObjectCopy)(void* dstObject, const void* srcObject, RwInt32 offsetInObject, RwInt32 sizeInObject); +typedef struct RwStream RwStream; + typedef RwStream* (*RwPluginDataChunkReadCallBack)(RwStream* stream, RwInt32 binaryLength, void* object, RwInt32 offsetInObject, RwInt32 sizeInObject); @@ -595,6 +633,8 @@ typedef RwBool (*RwPluginDataChunkRightsCallBack)(void* object, RwInt32 offsetIn typedef struct RwPluginRegEntry; +typedef struct RwPluginRegEntry RwPluginRegEntry; + struct RwPluginRegistry { RwInt32 sizeOfStruct; @@ -607,6 +647,8 @@ struct RwPluginRegistry typedef void* (*RwPluginErrorStrCallBack)(void*); +typedef struct RwPluginRegistry RwPluginRegistry; + struct RwPluginRegEntry { RwInt32 offset; @@ -781,6 +823,8 @@ struct RwRGBA #define RwRGBAAssign(_target, _source) (*(_target) = *(_source)) +typedef struct RwRGBA RwRGBA; + struct rwGameCube2DVertex { RwReal x; @@ -790,6 +834,7 @@ struct rwGameCube2DVertex RwReal u; RwReal v; }; +typedef struct rwGameCube2DVertex rwGameCube2DVertex; typedef rwGameCube2DVertex RwIm2DVertex; typedef RwUInt16 RxVertexIndex; @@ -1080,11 +1125,14 @@ struct RwEngineOpenParams void* displayID; }; +typedef struct RwGameCubeDeviceConfig RwGameCubeDeviceConfig; struct RwGameCubeDeviceConfig { - /* unknown */ + s32 temppad; // stops a compiler issue }; +typedef enum RwRenderState RwRenderState; + typedef RwBool (*RwSystemFunc)(RwInt32 nOption, void* pOut, void* pInOut, RwInt32 nIn); typedef RwBool (*RwRenderStateSetFunction)(RwRenderState nState, void* pParam); typedef RwBool (*RwRenderStateGetFunction)(RwRenderState nState, void* pParam); @@ -1092,6 +1140,8 @@ typedef RwBool (*RwIm2DRenderLineFunction)(RwIm2DVertex* vertices, RwInt32 numVe RwInt32 vert1, RwInt32 vert2); typedef RwBool (*RwIm2DRenderTriangleFunction)(RwIm2DVertex* vertices, RwInt32 numVertices, RwInt32 vert1, RwInt32 vert2, RwInt32 vert3); +typedef enum RwPrimitiveType RwPrimitiveType; + typedef RwBool (*RwIm2DRenderPrimitiveFunction)(RwPrimitiveType primType, RwIm2DVertex* vertices, RwInt32 numVertices); typedef RwBool (*RwIm2DRenderIndexedPrimitiveFunction)(RwPrimitiveType primType, @@ -1148,6 +1198,8 @@ enum RwVideoModeFlag rwVIDEOMODEFLAGFORCEENUMSIZEINT = RWFORCEENUMSIZEINT }; +typedef enum RwVideoModeFlag RwVideoModeFlag; + struct RwVideoMode { RwInt32 width; @@ -1176,6 +1228,13 @@ enum RwEngineStatus rwENGINESTATUSFORCEENUMSIZEINT = RWFORCEENUMSIZEINT }; +typedef struct RwDevice RwDevice; +typedef struct RwFileFunctions RwFileFunctions; +typedef struct RwStringFunctions RwStringFunctions; +typedef struct RwMemoryFunctions RwMemoryFunctions; +typedef struct RwMetrics RwMetrics; +typedef enum RwEngineStatus RwEngineStatus; + struct RwGlobals { void* curCamera; @@ -1198,8 +1257,10 @@ struct RwGlobals typedef struct RwResEntry; +typedef struct RwResEntry RwResEntry; typedef void (*RwResEntryDestroyNotify)(RwResEntry* resEntry); +typedef struct RwResEntry RwResEntry; struct RwResEntry { RwLLLink link; @@ -1220,6 +1281,8 @@ struct RwChunkHeaderInfo RwBool isComplex; /**< Internal Use */ }; +typedef struct RwRGBAReal RwRGBAReal; + struct RwSky2DVertexFields { RwV3d scrVertex; @@ -1233,6 +1296,8 @@ struct RwSky2DVertexFields RwReal pad2; }; +typedef struct RwSky2DVertexFields RwSky2DVertexFields; + struct RwSky2DVertexAlignmentOverlay { union @@ -1242,15 +1307,38 @@ struct RwSky2DVertexAlignmentOverlay }; }; +typedef struct RwSky2DVertexAlignmentOverlay RwSky2DVertexAlignmentOverlay; + struct RwSky2DVertex { RwSky2DVertexAlignmentOverlay u; }; +typedef struct RwModuleInfo RwModuleInfo; +struct RwModuleInfo +{ + RwInt32 globalsOffset; + RwInt32 numInstances; +}; + +enum RwMemoryHintDuration +{ + rwMEMHINTDUR_NADURATION = 0x00000000, + rwMEMHINTDUR_FUNCTION = 0x00010000, + rwMEMHINTDUR_FRAME = 0x00020000, + rwMEMHINTDUR_EVENT = 0x00030000, + rwMEMHINTDUR_GLOBAL = 0x00040000, + rwMEMHINTDUR_MASK = 0x00FF0000, + rwMEMHINTDURFORCEENUMSIZEINT = RWFORCEENUMSIZEINT +}; +typedef enum RwMemoryHintDuration RwMemoryHintDuration; + #ifdef __cplusplus extern "C" { #endif +typedef struct RwGlobals RwGlobals; + extern RwGlobals* RwEngineInstance; extern RwStream* _rwStreamWriteVersionedChunkHeader(RwStream* stream, RwInt32 type, RwInt32 size, @@ -1265,6 +1353,9 @@ extern RwStream* RwStreamWriteReal(RwStream* stream, const RwReal* reals, RwUInt extern RwStream* RwStreamWriteInt32(RwStream* stream, const RwInt32* ints, RwUInt32 numBytes); extern RwStream* RwStreamReadReal(RwStream* stream, RwReal* reals, RwUInt32 numBytes); extern RwStream* RwStreamReadInt32(RwStream* stream, RwInt32* ints, RwUInt32 numBytes); +typedef struct RwChunkHeaderInfo RwChunkHeaderInfo; +typedef struct RwError RwError; + extern RwStream* RwStreamReadChunkHeaderInfo(RwStream* stream, RwChunkHeaderInfo* chunkHeaderInfo); extern RwError* RwErrorSet(RwError* code); extern RwError* RwErrorGet(RwError* code); @@ -1290,6 +1381,8 @@ extern RwMatrix* RwMatrixUpdate(RwMatrix* matrix); extern RwMatrix* RwMatrixMultiply(RwMatrix* matrixOut, const RwMatrix* MatrixIn1, const RwMatrix* matrixIn2); extern RwMatrix* RwMatrixOrthoNormalize(RwMatrix* matrixOut, const RwMatrix* matrixIn); +typedef enum RwOpCombineType RwOpCombineType; + extern RwMatrix* RwMatrixRotateOneMinusCosineSine(RwMatrix* matrix, const RwV3d* unitAxis, RwReal oneMinusCosine, RwReal sine, RwOpCombineType combineOp); @@ -1360,6 +1453,9 @@ extern RwInt32 RwEngineRegisterPlugin(RwInt32 size, RwUInt32 pluginID, RwPluginObjectConstructor initCB, RwPluginObjectDestructor termCB); extern RwInt32 RwEngineGetPluginOffset(RwUInt32 pluginID); +typedef struct RwVideoMode RwVideoMode; +typedef struct RwEngineOpenParams RwEngineOpenParams; + extern RwVideoMode* RwEngineGetVideoModeInfo(RwVideoMode* modeinfo, RwInt32 modeIndex); extern RwInt32 RwEngineGetCurrentVideoMode(void); extern RwBool RwEngineStop(void); diff --git a/src/rwsdk/driver/common/palquant.c b/src/rwsdk/driver/common/palquant.c new file mode 100644 index 000000000..319b542b6 --- /dev/null +++ b/src/rwsdk/driver/common/palquant.c @@ -0,0 +1,53 @@ +#include "rwplcore.h" +#include "rwcore.h" + +typedef struct _rwPalQuantRGBABox _rwPalQuantRGBABox; +typedef struct _rwPalQuantOctNode _rwPalQuantOctNode; +typedef struct _rwPalQuantLeafNode _rwPalQuantLeafNode; +typedef struct _rwPalQuantBranchNode _rwPalQuantBranchNode; + +extern RwGlobals* RwEngineInstance; + +struct _rwPalQuantLeafNode +{ + RwReal weight; + RwRGBAReal ac; + RwReal var; + RwUInt8 palIndex; +}; + +struct _rwPalQuantBranchNode +{ + _rwPalQuantOctNode* dir[16]; +}; + +struct _rwPalQuantOctNode +{ + _rwPalQuantLeafNode Leaf; + _rwPalQuantBranchNode Branch; +}; + +void InitLeaf(_rwPalQuantLeafNode* Leaf) +{ + // What the hell is going on here? + Leaf->palIndex = 0xff; + Leaf->weight = 0; + Leaf->ac.red = 0; + Leaf->ac.green = 0; + Leaf->ac.blue = 0; + Leaf->ac.alpha = 0; + Leaf->var = 0; +} + +void InitBranch(_rwPalQuantBranchNode* Branch) +{ + int x; + for (x = 0; x < 16; ++x) + { + Branch->dir[x] = (_rwPalQuantOctNode*)NULL; + } +} + +void CreateCube() +{ +} diff --git a/src/rwsdk/driver/gcn/dl2drend.c b/src/rwsdk/driver/gcn/dl2drend.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/driver/gcn/dlconvrt.c b/src/rwsdk/driver/gcn/dlconvrt.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/driver/gcn/dldevice.c b/src/rwsdk/driver/gcn/dldevice.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/driver/gcn/dlraster.c b/src/rwsdk/driver/gcn/dlraster.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/driver/gcn/dlrendst.c b/src/rwsdk/driver/gcn/dlrendst.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/driver/gcn/dlsprite.c b/src/rwsdk/driver/gcn/dlsprite.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/driver/gcn/dltexdic.c b/src/rwsdk/driver/gcn/dltexdic.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/driver/gcn/dltextur.c b/src/rwsdk/driver/gcn/dltextur.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/driver/gcn/dltoken.c b/src/rwsdk/driver/gcn/dltoken.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/os/gcn/osintf.c b/src/rwsdk/os/gcn/osintf.c new file mode 100644 index 000000000..519afb04d --- /dev/null +++ b/src/rwsdk/os/gcn/osintf.c @@ -0,0 +1,6 @@ +#include "rwplcore.h" +#include "rwcore.h" + +RwInt32 _rwpathisabsolute() +{ +} diff --git a/src/rwsdk/plugin/collis/ctbsp.c b/src/rwsdk/plugin/collis/ctbsp.c index ef70eb772..c344b8e8a 100644 --- a/src/rwsdk/plugin/collis/ctbsp.c +++ b/src/rwsdk/plugin/collis/ctbsp.c @@ -1,8 +1,57 @@ -// #include +#include "rwplcore.h" +#include "rwcore.h" // #include // #include // #include -void _rpCollBSPTreeInit() +struct nodeInfo { -} \ No newline at end of file + u32 type; + u32 index; +}; + +typedef struct RpCollBSPTree RpCollBSPTree; + +struct RpCollBSPTree +// Blocks +/* anonymous block */ { + // Range: 0x1C9BE0 -> 0x1CA540 + s32 nStack; // r20 + struct nodeInfo nodeStack[33]; // r29+0x420 + struct RwLine lineStack[33]; // r29+0x100 + struct RwLine currLine; // r29+0xE0 + struct RpCollBSPLeafNode* leaf; // r2 + struct RpCollBSPBranchNode* branch; // r9 + u32 branch_type; // r5 + u32 branch_leftType; // r6 + u32 branch_rightType; // r4 + u32 branch_leftNode; // r3 + u32 branch_rightNode; // r2 + union RwSplitBits lStart; // r29+0x53C + union RwSplitBits lEnd; // r29+0x538 + union RwSplitBits rStart; // r29+0x534 + union RwSplitBits rEnd; // r29+0x530 + f32 delta; // r5 + //f32 delta; // r5 + //f32 delta; // r6 + //f32 delta; // r5 +}; + +RpCollBSPTree* _rpCollBSPTreeInit(RpCollBSPTree* tree, s32 numLeafNodes) +{ + // Something similar to this? + // Not quite sure yet + tree = (RpCollBSPTree*)numLeafNodes; + if (numLeafNodes + -1 > 0) + { + tree = (tree + 4); + tree = tree + (numLeafNodes + -1) * 0x10; + return; + } + tree = 0; + tree = (tree + 4); +} + +s32 _rpCollBSPTreeMemGetSize(s32 numLeafNodes) +{ +} diff --git a/src/rwsdk/plugin/collis/ctgeom.c b/src/rwsdk/plugin/collis/ctgeom.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/collis/ctworld.c b/src/rwsdk/plugin/collis/ctworld.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/collis/rpcollis.c b/src/rwsdk/plugin/collis/rpcollis.c new file mode 100644 index 000000000..b0b3086a6 --- /dev/null +++ b/src/rwsdk/plugin/collis/rpcollis.c @@ -0,0 +1,60 @@ +#include "rwplcore.h" +#include "rwcore.h" + +RwInt32 _rpCollisionNumInstances = 0; +RwInt32 _rpCollisionGlobalsOffset = 0; +RwInt32 _rpCollisionAtomicDataOffset = 0; +RwInt32 _rpCollisionGeometryDataOffset = 0; +RwInt32 _rpCollisionWorldSectorDataOffset = 0; + +struct RpCollisionData +{ + struct RpCollTree* tree; +}; + +typedef struct RpCollisionData RpCollisionData; + +// Not the correct params? +static void* CollisionOpen(void* instance, RwInt32 offset, RwInt32 size) +{ + _rpCollisionNumInstances++; +} + +// Not the correct params? +static void* CollisionClose(void* instance, RwInt32 offset, RwInt32 size) +{ + _rpCollisionNumInstances--; +} + +void* CollisionDataDestroy(void* object, s32 offset) +{ + RpCollisionData** extData; +} + +// params unknown, probably offset and size tho +void CollisionDataCreate(RwInt32 offset, RwInt32 size) +{ + *(RwInt32*)(offset + size) = 0; +} + +// param could be wrong +void CollisionAtomicInit(RwInt32 size) +{ + *(RwInt32*)(size + _rpCollisionAtomicDataOffset) = 0; +} + +static RwStream* CollisionDataStreamWrite(RwStream* stream, const void* object, RwInt32 offset) +{ +} + +RwStream* CollisionDataStreamRead(RwStream* stream, s32 binaryLength, void* object, s32 offset) +{ +} + +s32 CollisionDataStreamGetSize(void* object, s32 offsetInObject) +{ +} + +RwBool RpCollisionPluginAttach() +{ +} diff --git a/src/rwsdk/plugin/hanim/rphanim.c b/src/rwsdk/plugin/hanim/rphanim.c new file mode 100644 index 000000000..c08e47315 --- /dev/null +++ b/src/rwsdk/plugin/hanim/rphanim.c @@ -0,0 +1,231 @@ +#include "rwplcore.h" +#include "rwcore.h" +#include "rphanim.h" + +extern RpHAnimAtomicGlobalVars RpHAnimAtomicGlobals; + +static void* HAnimClose(void* instance, RwInt32 offset, RwInt32 size) +{ + if (NULL != RpHAnimAtomicGlobals.HAnimFreeList) + { + RwFreeListDestroy(RpHAnimAtomicGlobals.HAnimFreeList); + RpHAnimAtomicGlobals.HAnimFreeList = (RwFreeList*)NULL; + } + return instance; +} + +static void* HAnimConstructor(void* object, RwInt32 offset, RwInt32 size) +{ + RpHAnimFrameExtension* frameExt = 0; + + frameExt = (object); + frameExt->hierarchy = (RpHAnimHierarchy*)NULL; + frameExt->id = rpHANIMDEFAULTFRAMEID; + + return (object); +} + +static void* HAnimDestructor(void* object, RwInt32 offset, RwInt32 size) +{ + RpHAnimFrameExtension* frameExt; + + frameExt = (RpHAnimFrameExtension*)RPHANIMFRAMEGETDATA(object); + if (frameExt->hierarchy) + { + RpHAnimHierarchy* pHierarchy = frameExt->hierarchy; + RwInt32 frameNum; + /* run through all the frames this hierarchy + points at since they also point back at the + hierarchy. Set the pointers to NULL and then + destroy the hierarchy */ + for (frameNum = 0; frameNum < pHierarchy->numNodes; frameNum++) + { + if (pHierarchy->pNodeInfo[frameNum].pFrame) + { + /* TODO: + In here we ultimately check if this pointer is a sub-hierarchy + root, if so destroy the sub-hierarchy */ + } + + pHierarchy->pNodeInfo[frameNum].pFrame = (RwFrame*)NULL; + } + + if (pHierarchy->parentFrame == (RwFrame*)object) + { + RpHAnimHierarchyDestroy(pHierarchy); + } + + frameExt->hierarchy = (RpHAnimHierarchy*)NULL; + } + frameExt->id = rpHANIMDEFAULTFRAMEID; + + return object; +} + +static void* HAnimCopy(void* dstObject, const void* srcObject, RwInt32 offset, RwInt32 size) +{ + const RpHAnimFrameExtension* srcFrameExt; + RpHAnimFrameExtension* dstFrameExt; + + srcFrameExt = (const RpHAnimFrameExtension*)RPHANIMFRAMEGETCONSTDATA(srcObject); + dstFrameExt = (RpHAnimFrameExtension*)RPHANIMFRAMEGETDATA(dstObject); + + dstFrameExt->id = srcFrameExt->id; + if (srcFrameExt->hierarchy) + { + RpHAnimHierarchy* srcHierarchy = srcFrameExt->hierarchy; + if (!(srcHierarchy->flags & rpHANIMHIERARCHYSUBHIERARCHY)) + { + RpHAnimHierarchy* dstHierarchy; + RwInt32 i; + + dstHierarchy = + RpHAnimHierarchyCreate(srcHierarchy->numNodes, (RwUInt32*)NULL, (RwInt32*)NULL, + (RpHAnimHierarchyFlag)srcHierarchy->flags, + srcHierarchy->currentAnim->maxInterpKeyFrameSize); + + for (i = 0; i < dstHierarchy->numNodes; i++) + { + dstHierarchy->pNodeInfo[i].pFrame = (RwFrame*)NULL; + dstHierarchy->pNodeInfo[i].flags = srcHierarchy->pNodeInfo[i].flags; + dstHierarchy->pNodeInfo[i].nodeIndex = srcHierarchy->pNodeInfo[i].nodeIndex; + dstHierarchy->pNodeInfo[i].nodeID = srcHierarchy->pNodeInfo[i].nodeID; + } + + dstFrameExt->hierarchy = dstHierarchy; + dstHierarchy->parentFrame = (RwFrame*)dstObject; + } + } + + return dstObject; +} + +static RwStream* HAnimWrite(RwStream* stream, RwInt32 binaryLength, const void* object, + RwInt32 offsetInObject, RwInt32 sizeInObject) +{ + RwInt32 i; + const RpHAnimFrameExtension* frameExt; + RpHAnimNodeInfo* pNodeInfo; + RpHAnimHierarchy* animHierarchy; + RwInt32 streamVersion = rpHANIMSTREAMCURRENTVERSION; + + if (!RwStreamWriteInt32(stream, (RwInt32*)&streamVersion, sizeof(RwInt32))) + { + return NULL; + } + + frameExt = (const RpHAnimFrameExtension*)RPHANIMFRAMEGETCONSTDATA(object); + + if (!RwStreamWriteInt32(stream, (const RwInt32*)&frameExt->id, sizeof(RwInt32))) + { + return NULL; + } + + animHierarchy = frameExt->hierarchy; + + if (animHierarchy && !(animHierarchy->flags & rpHANIMHIERARCHYSUBHIERARCHY)) + { + if (!RwStreamWriteInt32(stream, (const RwInt32*)&animHierarchy->numNodes, sizeof(RwInt32))) + { + return NULL; + } + if (!RwStreamWriteInt32(stream, (const RwInt32*)&animHierarchy->flags, sizeof(RwInt32))) + { + return NULL; + } + if (!RwStreamWriteInt32(stream, + (const RwInt32*)&animHierarchy->currentAnim->maxInterpKeyFrameSize, + sizeof(RwInt32))) + { + return NULL; + } + + pNodeInfo = animHierarchy->pNodeInfo; + + for (i = 0; i < animHierarchy->numNodes; i++) + { + if (!RwStreamWriteInt32(stream, (RwInt32*)&pNodeInfo->nodeID, sizeof(RwInt32))) + { + return NULL; + } + + if (!RwStreamWriteInt32(stream, (RwInt32*)&pNodeInfo->nodeIndex, sizeof(RwInt32))) + { + return NULL; + } + + if (!RwStreamWriteInt32(stream, (RwInt32*)&pNodeInfo->flags, sizeof(RwInt32))) + { + return NULL; + } + + pNodeInfo++; + } + } + else + { + RwInt32 numNodes = 0; + + if (!RwStreamWriteInt32(stream, (const RwInt32*)&numNodes, sizeof(RwInt32))) + { + return NULL; + } + } + + return stream; +} + +static RwInt32 HAnimSize(const void* object, RwInt32 offsetInObject, RwInt32 sizeInObject) +{ + RwBool needToStream; + + const RpHAnimFrameExtension* frameExt = + (const RpHAnimFrameExtension*)RPHANIMFRAMEGETCONSTDATA(object); + + needToStream = (rpHANIMDEFAULTFRAMEID != frameExt->id) || (frameExt->hierarchy); + + if (needToStream) + { + RwInt32 size; + + size = sizeof(RwInt32); + size += sizeof(RwInt32); + size += sizeof(RwInt32); + + if (frameExt->hierarchy && !(frameExt->hierarchy->flags & rpHANIMHIERARCHYSUBHIERARCHY)) + { + size += sizeof(RwInt32); + size += sizeof(RwInt32); + size += frameExt->hierarchy->numNodes * (sizeof(RwInt32) * 3); + } + + return size; + } + + return 0; +} + +RwBool RpHAnimFrameSetHierarchy(RwFrame* frame, RpHAnimHierarchy* hierarchy) +{ + // Seems to be the correct idea but the RPHANIMFRAMEGETDATA call + // adds in too much to the asm. Needs re-written + RpHAnimFrameExtension* frameExt; + + frameExt = (RpHAnimFrameExtension*)RPHANIMFRAMEGETDATA(frame); + + if (frameExt->hierarchy) + { + frameExt->hierarchy->parentFrame = (RwFrame*)NULL; + } + frameExt->hierarchy = hierarchy; + if (hierarchy) + { + hierarchy->parentFrame = frame; + } + + return TRUE; +} + +RpHAnimHierarchy* RpHAnimFrameGetHierarchy(RwFrame* frame) +{ +} diff --git a/src/rwsdk/plugin/hanim/stdkey.c b/src/rwsdk/plugin/hanim/stdkey.c new file mode 100644 index 000000000..f81dca3d9 --- /dev/null +++ b/src/rwsdk/plugin/hanim/stdkey.c @@ -0,0 +1,95 @@ +#include "rwplcore.h" +#include "rwcore.h" +#include "rphanim.h" + +#define RpHAnimKeyFrameToMatrixMacro(_matrix, _voidIFrame) \ + MACRO_START \ + { \ + RpHAnimInterpFrame* iFrame = (RpHAnimInterpFrame*)(_voidIFrame); \ + \ + RtQuatUnitConvertToMatrix(&iFrame->q, (_matrix)); \ + \ + (_matrix)->pos.x = iFrame->t.x; \ + (_matrix)->pos.y = iFrame->t.y; \ + (_matrix)->pos.z = iFrame->t.z; \ + } \ + MACRO_STOP + +#define _EPSILON ((RwReal)(0.001)) +#define _TOL_COS_ZERO (((RwReal)1) - _EPSILON) + +void RpHAnimKeyFrameApply(void* pMatrix, void* pVoidIFrame) +{ + // Correct idea, but executed wwrong? + RpHAnimKeyFrameToMatrixMacro((RwMatrix*)pMatrix, pVoidIFrame); + return; +} + +void RpHAnimKeyFrameInterpolate(void* pVoidOut, void* pVoidIn1, void* pVoidIn2, RwReal time, + void* customData) +{ + // End of the function is correct, first 80% is horribly wrong. + RpHAnimInterpFrame* pOut = (RpHAnimInterpFrame*)pVoidOut; + RpHAnimKeyFrame* pIn1 = (RpHAnimKeyFrame*)pVoidIn1; + RpHAnimKeyFrame* pIn2 = (RpHAnimKeyFrame*)pVoidIn2; + + RwReal fCosTheta = + (RwV3dDotProduct(&pIn1->q.imag, &pIn2->q.imag) + pIn1->q.real * pIn2->q.real); + RwReal fAlpha = ((time - pIn1->time) / + + (pIn2->time - pIn1->time)); + RwReal fBeta; + RwBool bObtuseTheta; + RwBool bNearlyZeroTheta = 0; + + RpHAnimKeyFrameTransInterpolate(&pOut->t, &pIn1->t, fAlpha, &pIn2->t); + + bObtuseTheta = (fCosTheta < ((RwReal)0)); + + if (bObtuseTheta) + { + fCosTheta = -fCosTheta; + RwV3dNegate(&pIn2->q.imag, &pIn2->q.imag); + pIn2->q.real = -pIn2->q.real; + } + + fBeta = ((RwReal)1) - fAlpha; + + bNearlyZeroTheta = (fCosTheta >= _TOL_COS_ZERO); + + if (!bNearlyZeroTheta) + { + RwReal fTheta = 0; + RwReal fCosecTheta = 0; + + RwIEEEACosfMacro(fTheta, fCosTheta); + RwCosecMinusPiToPiMacro(fCosecTheta, fTheta); + + fBeta *= fTheta; + RwSinMinusPiToPiMacro(fBeta, fBeta); + fBeta *= fCosecTheta; + + fAlpha *= fTheta; + RwSinMinusPiToPiMacro(fAlpha, fAlpha); + fAlpha *= fCosecTheta; + } + + pOut->q.imag.x = fBeta * pIn1->q.imag.x + fAlpha * pIn2->q.imag.x; + pOut->q.imag.y = fBeta * pIn1->q.imag.y + fAlpha * pIn2->q.imag.y; + pOut->q.imag.z = fBeta * pIn1->q.imag.z + fAlpha * pIn2->q.imag.z; + pOut->q.real = fBeta * pIn1->q.real + fAlpha * pIn2->q.real; + +#if (0) + /* Assert no worse than 5% error in length^2 of + * spherically interpolated quaternion */ + + RWASSERT(bNearlyZeroTheta || (((0.95) < RtQuatModulusSquaredMacro(&pOut->q)) && + (RtQuatModulusSquaredMacro(&pOut->q) < (1 / 0.95)))); +#endif + + return; +} + +// Not continuing with this file for now +// Seems to need the macros rewritten, along with a good portion of the functions +// -Colin diff --git a/src/rwsdk/plugin/matfx/gcn/effectPipesGcn.c b/src/rwsdk/plugin/matfx/gcn/effectPipesGcn.c new file mode 100644 index 000000000..16f1dece5 --- /dev/null +++ b/src/rwsdk/plugin/matfx/gcn/effectPipesGcn.c @@ -0,0 +1,24 @@ +#include "rwplcore.h" +#include "rwcore.h" +#include "rpmatfx.h" + +RwTexture* _rpMatFXTextureMaskCreate(); +RpWorldSector* _RpMatFXWorldSectorPipe; + +typedef struct MatFXDualData MatFXDualData; + +extern RpWorldSector* _rpMatFXPipelineWorldSectorSetup(RpWorldSector* worldSector) +{ + _RpMatFXWorldSectorPipe = worldSector; +} + +extern RwBool _rpMatFXSetupDualRenderState(MatFXDualData* dualData, RwRenderState nState) +{ + return TRUE; +} + +extern RwTexture* _rpMatFXSetupBumpMapTexture(const RwTexture* baseTexture, + const RwTexture* effectTexture) +{ + _rpMatFXTextureMaskCreate(); +} diff --git a/src/rwsdk/plugin/matfx/gcn/multiTexGcn.c b/src/rwsdk/plugin/matfx/gcn/multiTexGcn.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/matfx/gcn/multiTexGcnData.c b/src/rwsdk/plugin/matfx/gcn/multiTexGcnData.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/matfx/gcn/multiTexGcnPipe.c b/src/rwsdk/plugin/matfx/gcn/multiTexGcnPipe.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/matfx/matfx.h b/src/rwsdk/plugin/matfx/matfx.h new file mode 100644 index 000000000..62aa25244 --- /dev/null +++ b/src/rwsdk/plugin/matfx/matfx.h @@ -0,0 +1,106 @@ +#ifndef RPMATFX_MATFX_H +#define RPMATFX_MATFX_H + +#include "rwcore.h" +#include "rpworld.h" + +typedef enum RpMatFXMaterialFlags RpMatFXMaterialFlags; +typedef struct RwMatFXInfo RwMatFXInfo; +typedef struct RwModuleInfo RwModuleInfo; + +struct RwMatFXInfo +{ + RwModuleInfo Module; + RwFreeList* MaterialData; +}; + +extern RwMatFXInfo MatFXInfo; + +#ifdef __cplusplus +extern "C" { +#endif + +extern void RpMatFXMaterialDataSetFreeListCreateParams(RwInt32 blockSize, + RwInt32 numBlocksToPrealloc); + +extern RwBool RpMatFXPluginAttach(void); +extern RpAtomic* RpMatFXAtomicEnableEffects(RpAtomic* atomic); +extern RwBool RpMatFXAtomicQueryEffects(RpAtomic* atomic); +extern RpWorldSector* RpMatFXWorldSectorEnableEffects(RpWorldSector* worldSector); +extern RwBool RpMatFXWorldSectorQueryEffects(RpWorldSector* worldSector); +extern RpMaterial* RpMatFXMaterialSetEffects(RpMaterial* material, RpMatFXMaterialFlags flags); + +extern RpMaterial* RpMatFXMaterialSetupBumpMap(RpMaterial* material, RwTexture* texture, + RwFrame* frame, RwReal coef); + +extern RpMaterial* RpMatFXMaterialSetupEnvMap(RpMaterial* material, RwTexture* texture, + RwFrame* frame, RwBool useFrameBufferAlpha, + RwReal coef); + +extern RpMaterial* RpMatFXMaterialSetupDualTexture(RpMaterial* material, RwTexture* texture, + RwBlendFunction srcBlendMode, + RwBlendFunction dstBlendMode); + +extern RpMatFXMaterialFlags RpMatFXMaterialGetEffects(const RpMaterial* material); + +extern RpMaterial* RpMatFXMaterialSetBumpMapTexture(RpMaterial* material, RwTexture* texture); + +extern RpMaterial* RpMatFXMaterialSetBumpMapFrame(RpMaterial* material, RwFrame* frame); + +extern RpMaterial* RpMatFXMaterialSetBumpMapCoefficient(RpMaterial* material, RwReal coef); +extern RwTexture* RpMatFXMaterialGetBumpMapTexture(const RpMaterial* material); + +extern RwTexture* RpMatFXMaterialGetBumpMapBumpedTexture(const RpMaterial* material); + +extern RwFrame* RpMatFXMaterialGetBumpMapFrame(const RpMaterial* material); + +extern RwReal RpMatFXMaterialGetBumpMapCoefficient(const RpMaterial* material); + +extern RpMaterial* RpMatFXMaterialSetEnvMapTexture(RpMaterial* material, RwTexture* texture); + +extern RpMaterial* RpMatFXMaterialSetEnvMapFrame(RpMaterial* material, RwFrame* frame); + +extern RpMaterial* RpMatFXMaterialSetEnvMapFrameBufferAlpha(RpMaterial* material, + RwBool useFrameBufferAlpha); + +extern RpMaterial* RpMatFXMaterialSetEnvMapCoefficient(RpMaterial* material, RwReal coef); + +extern RwTexture* RpMatFXMaterialGetEnvMapTexture(const RpMaterial* material); + +extern RwFrame* RpMatFXMaterialGetEnvMapFrame(const RpMaterial* material); + +extern RwBool RpMatFXMaterialGetEnvMapFrameBufferAlpha(const RpMaterial* material); + +extern RwReal RpMatFXMaterialGetEnvMapCoefficient(const RpMaterial* material); + +extern RpMaterial* RpMatFXMaterialSetDualTexture(RpMaterial* material, RwTexture* texture); + +extern RpMaterial* RpMatFXMaterialSetDualBlendModes(RpMaterial* material, + RwBlendFunction srcBlendMode, + RwBlendFunction dstBlendMode); + +extern RwTexture* RpMatFXMaterialGetDualTexture(const RpMaterial* material); + +extern const RpMaterial* RpMatFXMaterialGetDualBlendModes(const RpMaterial* material, + RwBlendFunction* srcBlendMode, + RwBlendFunction* dstBlendMode); + +extern RpMaterial* RpMatFXMaterialSetUVTransformMatrices(RpMaterial* material, + RwMatrix* baseTransform, + RwMatrix* dualTransform); + +extern const RpMaterial* RpMatFXMaterialGetUVTransformMatrices(const RpMaterial* material, + RwMatrix** baseTransform, + RwMatrix** dualTransform); + +#ifdef __cplusplus +} +#endif + +extern RwStream* _rpMatFXStreamWriteTexture(RwStream* stream, const RwTexture* texture); + +extern RwStream* _rpMatFXStreamReadTexture(RwStream* stream, RwTexture** texture); + +extern RwUInt32 _rpMatFXStreamSizeTexture(const RwTexture* texture); + +#endif diff --git a/src/rwsdk/plugin/matfx/multiTex.c b/src/rwsdk/plugin/matfx/multiTex.c new file mode 100644 index 000000000..3ff67142d --- /dev/null +++ b/src/rwsdk/plugin/matfx/multiTex.c @@ -0,0 +1,230 @@ +#include "rwplcore.h" +#include "rwcore.h" +#include "rpmatfx.h" +#include + +#define MAXPLATFORMID (rwID_PCD3D9) + +#ifndef rwCHUNKHEADERSIZE +#define rwCHUNKHEADERSIZE (sizeof(RwUInt32) * 3) +#endif + +#define rwMAXTEXTURECOORDS 8 + +#define rwID_MULTITEXPLUGIN MAKECHUNKID(rwVENDORID_CRITERIONTK, 0x2c) +#define rwID_CHAINPLUGIN MAKECHUNKID(rwVENDORID_CRITERIONTK, 0x2d) + +typedef struct _MultiTextureExt +{ + RpMultiTexture* multiTexture; + +} MultiTextureExt; + +typedef enum _MultiTextureStreamFlag +{ + MULTITEXTURESTREAMEFFECT = 0x01 + +} MultiTextureStreamFlag; + +typedef struct _MultiTextureStreamHdr +{ + RwUInt8 platformID; + RwUInt8 numTextures; + RwUInt8 flags; + RwUInt8 pad; + +} MultiTextureStreamHdr; + +rpMultiTextureRegEntry RegEntries[MAXPLATFORMID + 1]; + +RwModuleInfo _rpMultiTextureModule = { 0, 0 }; + +static void* MultiTextureOpen(void* object, RwInt32 offsetInObject, RwInt32 sizeInObject) +{ + _rpMultiTextureModule.numInstances++; + _rpMTEffectOpen(); + return object; +} + +static void* MultiTextureClose(void* object, RwInt32 offsetInObject, RwInt32 sizeInObject) +{ + _rpMTEffectClose(); + _rpMultiTextureModule.numInstances--; + return object; +} + +static void* MultiTextureConstructor(void* object, RwInt32 offset, RwInt32 size) +{ + *(RwInt32*)((RwInt32)object + offset) = 0; +} + +static void* MultiTextureDestructor(void* object, RwInt32 offset, RwInt32 size) +{ + MultiTextureExt* ext = (MultiTextureExt*)GetMultiTextureExtMacro(object, offset); + + if (ext->multiTexture) + { + MultiTextureDestroy(ext->multiTexture); + ext->multiTexture = (RpMultiTexture*)NULL; + } + + return object; +} + +static void* MultiTextureCopy(void* dstObject, const void* srcObject, RwInt32 offset, RwInt32 size) +{ + RpMultiTexture const* srcMT; + RpMultiTexture* dstMT; + RwUInt32 i; + + srcMT = 0; + if (!srcMT) + { + RWRETURN(dstObject); + } + + dstMT = (RpMultiTexture*)MultiTextureCreate(srcMT->regEntry, srcMT->numTextures); + if (!dstMT) + { + return NULL; + } + + for (i = 0; i < srcMT->numTextures; i++) + { + RpMultiTextureSetTexture(dstMT, i, RpMultiTextureGetTexture(srcMT, i)); + RpMultiTextureSetCoords(dstMT, i, RpMultiTextureGetCoords(srcMT, i)); + } + + RpMultiTextureSetEffect(dstMT, RpMultiTextureGetEffect(srcMT)); + + return dstObject; +} + +static RwInt32 MultiTextureStreamGetSize(const void* object, RwInt32 offset, RwInt32 sizeInObj) +{ +} + +static RwStream* MultiTextureStreamWrite(RwStream* stream, RwInt32 length, const void* object, + RwInt32 offset, RwInt32 sizeInObj) +{ +} + +static RwStream* MultiTextureStreamRead(RwStream* stream, RwInt32 length, void* object, + RwInt32 offset, RwInt32 sizeInObj) +{ +} + +RwBool _rpMultiTexturePluginAttach() +{ + if (!_rpMTEffectSystemInit()) + { + return FALSE; + } + + memset(RegEntries, 0, sizeof(RegEntries)); + + _rpMultiTextureModule.globalsOffset = RwEngineRegisterPlugin( + sizeof(rpMultiTextureGlobals), rwID_MULTITEXPLUGIN, MultiTextureOpen, MultiTextureClose); + + if (_rpMultiTextureModule.globalsOffset < 0) + { + return (FALSE); + } + + return TRUE; +} + +RwBool _rpMaterialRegisterMultiTexturePlugin(RwPlatformID platformID, RwUInt32 pluginID, + RwUInt32 extensionSize) +{ + RwInt32 offset; + rpMultiTextureRegEntry* regEntry; + + offset = RpMaterialRegisterPlugin(sizeof(MultiTextureExt), pluginID, MultiTextureConstructor, + MultiTextureDestructor, MultiTextureCopy); + if (offset < 0) + { + return FALSE; + } + regEntry = &RegEntries[platformID]; + regEntry->materialOffset = offset; + offset = RpMaterialRegisterPluginStream(pluginID, MultiTextureStreamRead, + MultiTextureStreamWrite, MultiTextureStreamGetSize); + if (offset < 0) + { + return FALSE; + } + + regEntry->platformID = platformID; + regEntry->pluginID = pluginID; + regEntry->extensionSize = extensionSize; + + return TRUE; +} + +RpMultiTexture* RpMultiTextureSetEffect(RpMultiTexture* multiTexture, RpMTEffect* effect) +{ + if (multiTexture->effect) + { + RpMTEffectDestroy(multiTexture->effect); + } + multiTexture->effect = effect; + if (effect) + { + RpMTEffectAddRef(multiTexture->effect); + } + return multiTexture; +} + +RpMTEffect* RpMultiTextureGetEffect(const RpMultiTexture* multiTexture) +{ + return multiTexture->effect; +} + +RpMultiTexture* RpMultiTextureSetTexture(RpMultiTexture* multiTexture, RwUInt32 index, + RwTexture* texture) +{ + if (multiTexture->textures[index]) + { + RwTextureDestroy(multiTexture->textures[index]); + } + + multiTexture->textures[index] = texture; + if (texture) + { + RwTextureAddRef(texture); + } + + return multiTexture; +} + +RwTexture* RpMultiTextureGetTexture(const RpMultiTexture* multiTexture, RwUInt32 index) +{ + return multiTexture->textures[index]; +} + +RpMultiTexture* RpMultiTextureSetCoords(RpMultiTexture* multiTexture, RwUInt32 index, + RwUInt32 texCoordIndex) +{ + multiTexture->coordMap[index] = (RwUInt8)texCoordIndex; + return multiTexture; +} + +RwUInt32 RpMultiTextureGetCoords(const RpMultiTexture* multiTexture, RwUInt32 index) +{ + return multiTexture->coordMap[index]; +} + +RpMultiTexture* RpMaterialGetMultiTexture(const RpMaterial* material, RwPlatformID platformID) +{ + rpMultiTextureRegEntry* regEntry; + + regEntry = &RegEntries[platformID]; + if (regEntry->pluginID) + { + const MultiTextureExt* ext; + ext = 0; + return (ext->multiTexture); + } + return (RpMultiTexture*)NULL; +} diff --git a/src/rwsdk/plugin/matfx/multiTex.h b/src/rwsdk/plugin/matfx/multiTex.h new file mode 100644 index 000000000..f5d2dc339 --- /dev/null +++ b/src/rwsdk/plugin/matfx/multiTex.h @@ -0,0 +1,88 @@ +#ifndef RPMATFX_MULTITEX_H +#define RPMATFX_MULTITEX_H + +#include "rwcore.h" +#include "rpworld.h" + +#include + +#define rpMAXMULTITEXTURES 8 + +struct rpMultiTextureRegEntry +{ + RwPlatformID platformID; + RwUInt32 pluginID; + RwUInt32 materialOffset; + RwUInt32 extensionSize; +}; +typedef struct rpMultiTextureRegEntry rpMultiTextureRegEntry; + +struct RpMultiTexture +{ + rpMultiTextureRegEntry* regEntry; + + RwUInt32 numTextures; + RwTexture* textures[rpMAXMULTITEXTURES]; + RwUInt8 coordMap[rpMAXMULTITEXTURES]; + + RpMTEffect* effect; + + void* extension; +}; + +typedef struct RpMultiTexture RpMultiTexture; + +typedef struct _rpMultiTextureGlobals +{ + rpMTEffectGlobals effect; + +} rpMultiTextureGlobals; + +extern RwModuleInfo _rpMultiTextureModule; + +#define RPMULTITEXTUREGLOBAL(var) \ + (RWPLUGINOFFSET(rpMultiTextureGlobals, RwEngineInstance, _rpMultiTextureModule.globalsOffset) \ + ->var) + +#ifdef __cplusplus +extern "C" { +#endif + +extern RwUInt32 RpMultiTextureGetNumTextures(const RpMultiTexture* multiTexture); + +extern RpMultiTexture* RpMultiTextureSetTexture(RpMultiTexture* multiTexture, RwUInt32 index, + RwTexture* texture); + +extern RwTexture* RpMultiTextureGetTexture(const RpMultiTexture* multiTexture, RwUInt32 index); + +extern RpMultiTexture* RpMultiTextureSetCoords(RpMultiTexture* multiTexture, RwUInt32 index, + RwUInt32 texCoordIndex); + +extern RwUInt32 RpMultiTextureGetCoords(const RpMultiTexture* multiTexture, RwUInt32 index); + +extern RpMultiTexture* RpMultiTextureSetEffect(RpMultiTexture* multiTexture, RpMTEffect* effect); + +extern RpMTEffect* RpMultiTextureGetEffect(const RpMultiTexture* multiTexture); + +extern RpMaterial* RpMaterialCreateMultiTexture(RpMaterial* material, RwPlatformID platformID, + RwUInt32 numTextures); + +extern RpMaterial* RpMaterialDestroyMultiTexture(RpMaterial* material, RwPlatformID platformID); + +extern RpMultiTexture* RpMaterialGetMultiTexture(const RpMaterial* material, + RwPlatformID platformID); + +extern RwBool RpMaterialQueryMultiTexturePlatform(RwPlatformID platformID); + +extern RwBool _rpMultiTexturePluginAttach(void); + +extern RwBool _rpMaterialRegisterMultiTexturePlugin(RwPlatformID platformID, RwUInt32 pluginID, + RwUInt32 extensionSize); + +extern RwBool _rpMultiTexturePlatformPluginsAttach(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/rwsdk/plugin/matfx/multiTexEffect.c b/src/rwsdk/plugin/matfx/multiTexEffect.c new file mode 100644 index 000000000..e5a965502 --- /dev/null +++ b/src/rwsdk/plugin/matfx/multiTexEffect.c @@ -0,0 +1,164 @@ +#include "rwplcore.h" +#include "rwcore.h" +#include "rpmatfx.h" +#include + +#define MAXPLATFORMID (rwID_PCD3D9) +#define DEFAULTPATHSIZE 256 +#define rwID_MULTITEXPLUGIN MAKECHUNKID(rwVENDORID_CRITERIONTK, 0x2c) + +typedef union RpPtrMTEffect RpPtrMTEffect; +union RpPtrMTEffect +{ + RpMTEffect* ptrMTEffect; + const RpMTEffect* constptrMTEffect; +}; + +typedef union RpPtrMTEffectDict RpPtrMTEffectDict; +union RpPtrMTEffectDict +{ + RpMTEffectDict* ptrMTEffectDict; + const RpMTEffectDict* constptrMTEffectDict; +}; + +typedef struct EffectRegEntry EffectRegEntry; +struct EffectRegEntry +{ + RwPlatformID platformID; + + rpMTEffectDestroyCallBack destroy; + rpMTEffectStreamReadCallBack streamRead; + rpMTEffectStreamWriteCallBack streamWrite; + rpMTEffectStreamGetSizeCallBack streamGetSize; +}; + +typedef struct BinaryEffectDict BinaryEffectDict; +struct BinaryEffectDict +{ + RwUInt32 numEffects; +}; + +typedef struct BinaryEffect BinaryEffect; +struct BinaryEffect +{ + RwUInt32 platformID; +}; + +typedef struct Iterator Iterator; +struct Iterator +{ + const RwLLLink* cur; + const RwLLLink* end; +}; + +static EffectRegEntry EffectRegEntries[MAXPLATFORMID + 1]; + +static RpMTEffectDict* DummyDict = (RpMTEffectDict*)NULL; + +RwBool _rpMTEffectSystemInit() +{ + memset(EffectRegEntries, 0, sizeof(EffectRegEntries)); + return TRUE; +} + +RwBool _rpMTEffectRegisterPlatform(RwPlatformID platformID, rpMTEffectStreamReadCallBack streamRead, + rpMTEffectStreamWriteCallBack streamWrite, + rpMTEffectStreamGetSizeCallBack streamGetSize, + rpMTEffectDestroyCallBack destroy) +{ + EffectRegEntry* regEntry; + + regEntry = &EffectRegEntries[platformID]; + regEntry->platformID = platformID; + regEntry->streamRead = streamRead; + regEntry->streamWrite = streamWrite; + regEntry->streamGetSize = streamGetSize; + regEntry->destroy = destroy; + + return TRUE; +} + +RwBool _rpMTEffectOpen() +{ +} + +RwBool _rpMTEffectClose() +{ +} + +RpMTEffect* _rpMTEffectInit(RpMTEffect* effect, RwPlatformID platformID) +{ + memset(effect, 0, sizeof(RpMTEffect)); + + effect->platformID = platformID; + effect->refCount = 1; + rwLLLinkInitialize(&effect->dictLink); + + // if (platformID && RPMULTITEXTUREGLOBAL(effect.currentDict)) + // { + // RpMTEffectDictAddEffect(RPMULTITEXTUREGLOBAL(effect.currentDict), effect); + // } + + return (effect); +} + +RpMTEffectDict* RpMTEffectDictCreate(void) +{ + // What? + RpMTEffectDict* dict; + RwUInt32 size; + + size = sizeof(RpMTEffectDict); + dict = (RpMTEffectDict*)RwMalloc(size); + if (!dict) + { + RwErrorSet(NULL); + return ((RpMTEffectDict*)NULL); + } + + rwLinkListInitialize(&dict->effectList); + + return dict; +} + +RpMTEffectDict* RpMTEffectDictAddEffect(RpMTEffectDict* dict, RpMTEffect* effect) +{ + if (effect->dictLink.next) + { + rwLinkListRemoveLLLink(&effect->dictLink); + RpMTEffectDestroy(effect); + } + rwLinkListAddLLLink(&dict->effectList, &effect->dictLink); + RpMTEffectAddRef(effect); + + return dict; +} + +RpMTEffect* RpMTEffectDictRemoveEffect(RpMTEffect* effect) +{ + if (effect->dictLink.next) + { + rwLinkListRemoveLLLink(&effect->dictLink); + RpMTEffectDestroy(effect); + } + + return effect; +} + +RpMTEffect* RpMTEffectCreateDummy(void) +{ +} + +RpMTEffect* RpMTEffectSetName(RpMTEffect* effect, RwChar* name) +{ + rwstrncpy(effect->name, name, rpMTEFFECTNAMELENGTH - 1); + + return effect; +} + +RpMTEffect* RpMTEffectAddRef(RpMTEffect* effect) +{ + effect->refCount++; + + return effect; +} diff --git a/src/rwsdk/plugin/matfx/multiTexEffect.h b/src/rwsdk/plugin/matfx/multiTexEffect.h new file mode 100644 index 000000000..b2a5ba24a --- /dev/null +++ b/src/rwsdk/plugin/matfx/multiTexEffect.h @@ -0,0 +1,125 @@ +#ifndef RPMATFX_MULTITEXEFFECT_H +#define RPMATFX_MULTITEXEFFECT_H + +#include "rwcore.h" +#include "rpworld.h" + +#define rpMTEFFECTNAMELENGTH 32 + +typedef struct RpMTEffect RpMTEffect; + +typedef struct RpMTEffectDict RpMTEffectDict; + +typedef RpMTEffect* (*RpMTEffectCallBack)(RpMTEffect* effect, void* data); + +typedef RpMTEffectDict* (*RpMTEffectDictCallBack)(RpMTEffectDict* dict, void* data); + +struct RpMTEffectDict +{ + RwLinkList effectList; + RwLLLink dictListLink; +}; + +typedef struct rpMTEffectGlobals rpMTEffectGlobals; +struct rpMTEffectGlobals +{ + RwLinkList dictList; + RpMTEffectDict* currentDict; + RwInt32 pathSize; + RwChar* path; + RwChar* scratchMem; +}; + +#if (!defined(DOXYGEN)) + +typedef enum RwPlatformID RwPlatformID; + +struct RpMTEffect +{ + RwPlatformID platformID; + RwUInt32 refCount; + RwChar name[rpMTEFFECTNAMELENGTH]; + RwLLLink dictLink; +}; +#endif + +typedef void (*rpMTEffectDestroyCallBack)(RpMTEffect* effect); +typedef RwInt32 (*rpMTEffectStreamGetSizeCallBack)(const RpMTEffect* effect); +typedef RpMTEffect* (*rpMTEffectStreamReadCallBack)(RwStream* stream, RwPlatformID platformID, + RwUInt32 version, RwUInt32 length); +typedef const RpMTEffect* (*rpMTEffectStreamWriteCallBack)(const RpMTEffect* effect, + RwStream* stream); + +#ifdef __cplusplus +extern "C" { +#endif + +extern RpMTEffectDict* RpMTEffectDictCreate(void); + +extern void RpMTEffectDictDestroy(RpMTEffectDict* dict); + +extern RpMTEffectDict* RpMTEffectDictAddEffect(RpMTEffectDict* dict, RpMTEffect* effect); + +extern RpMTEffect* RpMTEffectDictRemoveEffect(RpMTEffect* effect); + +extern RpMTEffect* RpMTEffectDictFindNamedEffect(const RpMTEffectDict* dict, const RwChar* name); + +extern RpMTEffectDict* RpMTEffectDictSetCurrent(RpMTEffectDict* dict); + +extern RpMTEffectDict* RpMTEffectDictGetCurrent(void); + +extern RwUInt32 RpMTEffectDictStreamGetSize(const RpMTEffectDict* dict); + +extern const RpMTEffectDict* RpMTEffectDictStreamWrite(const RpMTEffectDict* dict, + RwStream* stream); + +extern RpMTEffectDict* RpMTEffectDictStreamRead(RwStream* stream); + +extern RwBool RpMTEffectDictForAllDictionaries(RpMTEffectDictCallBack callBack, void* data); + +extern const RpMTEffectDict* RpMTEffectDictForAllEffects(const RpMTEffectDict* dict, + RpMTEffectCallBack callBack, void* data); + +extern const RwChar* RpMTEffectSetPath(const RwChar* path); + +extern RwChar* RpMTEffectGetPath(void); + +extern RpMTEffect* RpMTEffectCreateDummy(void); + +extern void RpMTEffectDestroy(RpMTEffect* effect); + +extern RwUInt32 RpMTEffectStreamGetSize(const RpMTEffect* effect); + +extern const RpMTEffect* RpMTEffectStreamWrite(const RpMTEffect* effect, RwStream* stream); + +extern RpMTEffect* RpMTEffectStreamRead(RwStream* stream); + +extern RpMTEffect* RpMTEffectFind(RwChar* name); + +extern const RpMTEffect* RpMTEffectWrite(const RpMTEffect* effect); + +extern RpMTEffect* RpMTEffectSetName(RpMTEffect* effect, RwChar* name); + +extern RwChar* RpMTEffectGetName(RpMTEffect* effect); + +extern RpMTEffect* RpMTEffectAddRef(RpMTEffect* effect); + +extern RwBool _rpMTEffectSystemInit(void); + +extern RwBool _rpMTEffectRegisterPlatform(RwPlatformID platformID, + rpMTEffectStreamReadCallBack streamRead, + rpMTEffectStreamWriteCallBack streamWrite, + rpMTEffectStreamGetSizeCallBack streamGetSize, + rpMTEffectDestroyCallBack destroy); + +extern RwBool _rpMTEffectOpen(void); + +extern RwBool _rpMTEffectClose(void); + +extern RpMTEffect* _rpMTEffectInit(RpMTEffect* effect, RwPlatformID platformID); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/rwsdk/plugin/matfx/rpmatfx.c b/src/rwsdk/plugin/matfx/rpmatfx.c new file mode 100644 index 000000000..be261e8ad --- /dev/null +++ b/src/rwsdk/plugin/matfx/rpmatfx.c @@ -0,0 +1,1303 @@ +#include "rwplcore.h" +#include "rwcore.h" +#include "rpmatfx.h" +#include + +#define MATFXBUMPTEXTURENAMEEXTENSION "_B" + +#ifndef _rpMatFXMaterialPlatformInitialize +#define _rpMatFXMaterialPlatformInitialize(material) +#endif +#ifndef _rpMatFXMaterialPlatformEnvMapSetBlend +#define _rpMatFXMaterialPlatformEnvMapSetBlend(material) +#endif +#ifndef _rpMatFXMaterialPlatformDualSetBlend +#define _rpMatFXMaterialPlatformDualSetBlend(material) +#endif + +#define rpMATFXENTRIESPERBLOCK 128 + +#define rpMATFXALIGNMENT rwFRAMEALIGNMENT + +#define RPMATFXALIGNMENT(_x) (!(((rpMATFXALIGNMENT)-1) & ((RwUInt32)(_x)))) + +#define MATFXMATERIALGETDATA(material) \ + ((rpMatFXMaterialData**)(((RwUInt8*)material) + MatFXMaterialDataOffset)) + +#define MATFXMATERIALGETCONSTDATA(material) \ + ((const rpMatFXMaterialData* const*)(((const RwUInt8*)material) + MatFXMaterialDataOffset)) + +#define MATFXATOMICGETDATA(atomic) ((MatFXAtomicData*)(((RwUInt8*)atomic) + MatFXAtomicDataOffset)) + +#define MATFXATOMICGETCONSTDATA(atomic) \ + ((const MatFXAtomicData*)(((const RwUInt8*)atomic) + MatFXAtomicDataOffset)) + +#define MATFXWORLDSECTORGETDATA(worldSector) \ + ((MatFXWorldSectorData*)(((RwUInt8*)worldSector) + MatFXWorldSectorDataOffset)) + +#define MATFXWORLDSECTORGETCONSTDATA(worldSector) \ + ((const MatFXWorldSectorData*)(((const RwUInt8*)worldSector) + MatFXWorldSectorDataOffset)) + +#define MATFXMATERIALGETDATA(material) \ + ((rpMatFXMaterialData**)(((RwUInt8*)material) + MatFXMaterialDataOffset)) + +#define MATFXMATERIALGETCONSTDATA(material) \ + ((const rpMatFXMaterialData* const*)(((const RwUInt8*)material) + MatFXMaterialDataOffset)) + +typedef struct MatFXWorldSectorData MatFXWorldSectorData; +struct MatFXWorldSectorData +{ + RwBool enabled; +}; + +typedef struct MatFXAtomicData MatFXAtomicData; +struct MatFXAtomicData +{ + RwBool enabled; +}; + +#if (defined(RWDEBUG)) +long rpMatFXStackDepth = 0; +#endif /* (defined(RWDEBUG)) */ + +RwInt32 MatFXMaterialDataOffset = 0; + +RwMatFXInfo MatFXInfo = { { 0, 0 }, (RwFreeList*)NULL }; + +static RwInt32 MatFXAtomicDataOffset = 0; +static RwInt32 MatFXWorldSectorDataOffset = 0; + +RwTexture* _rpMatFXTextureMaskCreate(); + +static void* MatFXClose(void* instance, RwInt32 offset, RwInt32 size) +{ + MatFXInfo.Module.numInstances--; + if (MatFXInfo.Module.numInstances == 0) + { + _rpMatFXPipelinesDestroy(); + } + if (MatFXInfo.MaterialData) + { + RwFreeListDestroy(MatFXInfo.MaterialData); + MatFXInfo.MaterialData = (RwFreeList*)NULL; + } + + return instance; +} + +static RwInt32 _rpMatFXMaterialDataFreeListBlockSize = rpMATFXENTRIESPERBLOCK, + _rpMatFXMaterialDataFreeListPreallocBlocks = 1; +static RwFreeList _rpMatFXMaterialDataFreeList; + +static void* MatFXOpen(void* instance, RwInt32 offset, RwInt32 size) +{ + if (MatFXInfo.Module.numInstances == 0) + { + // Instruction below this is kinda fucked. + + // MatFXInfo.MaterialData = RwFreeListCreateAndPreallocateSpace( + // sizeof(rpMatFXMaterialData), _rpMatFXMaterialDataFreeListBlockSize, rpMATFXALIGNMENT, + // _rpMatFXMaterialDataFreeListPreallocBlocks, &_rpMatFXMaterialDataFreeList, + // rwID_MATERIALEFFECTSPLUGIN | rwMEMHINTDUR_GLOBAL); + + if (MatFXInfo.MaterialData == NULL) + { + instance = NULL; + return instance; + } + + if (FALSE == _rpMatFXPipelinesCreate()) + { + instance = NULL; + return instance; + } + } + MatFXInfo.Module.numInstances++; + + return instance; +} +typedef struct rpMatFXMaterialData rpMatFXMaterialData; +static void* MatFXMaterialConstructor(void* object, RwInt32 offset, RwInt32 size) +{ + *MATFXMATERIALGETDATA(object) = (rpMatFXMaterialData*)NULL; + + return object; +} + +enum MatFXPass +{ + rpSECONDPASS = 0, + rpTHIRDPASS = 1, + rpMAXPASS = 2 +}; + +typedef enum MatFXPass MatFXPass; +// typedef struct MatFXUVAnimData RWALIGN(MatFXUVAnimData, rpMATFXALIGNMENT); +// typedef struct MatFXBumpMapData RWALIGN(MatFXBumpMapData, rpMATFXALIGNMENT); +// typedef struct MatFXDualData RWALIGN(MatFXDualData, rpMATFXALIGNMENT); +// typedef union MatFXEffectUnion RWALIGN(MatFXEffectUnion, rpMATFXALIGNMENT); + +typedef struct MatFXBumpMapData MatFXBumpMapData; + +struct MatFXBumpMapData +{ + RwFrame* frame; + RwTexture* texture; + RwTexture* bumpTexture; + RwReal coef; + RwReal invBumpWidth; +}; +typedef struct MatFXDualData MatFXDualData; + +struct MatFXDualData +{ + RwTexture* texture; + RwBlendFunction srcBlendMode; + RwBlendFunction dstBlendMode; + + // device specific +}; +typedef struct MatFXEnvMapData RWALIGN(MatFXEnvMapData, rpMATFXALIGNMENT); +struct MatFXEnvMapData +{ + RwFrame* frame; + RwTexture* texture; + RwReal coef; + RwBool useFrameBufferAlpha; +}; + +typedef struct MatFXUVAnimData MatFXUVAnimData; + +struct MatFXUVAnimData +{ + RwMatrix* baseTransform; + RwMatrix* dualTransform; +}; + +typedef union MatFXEffectUnion MatFXEffectUnion; + +union MatFXEffectUnion +{ + MatFXBumpMapData bumpMap; + MatFXEnvMapData envMap; + MatFXDualData dual; + MatFXUVAnimData uvAnim; + +#if (defined(MULTITEXD3D8_H)) + MatFXD3D8Material d3d8Mat; +#endif +}; + +typedef struct MatFXEffectData RWALIGN(MatFXEffectData, rpMATFXALIGNMENT); +struct MatFXEffectData +{ + MatFXEffectUnion data; + RpMatFXMaterialFlags flag; + +#if (defined(SKY2_DRVMODEL_H)) + MatFXSkyMaterial skyMat; +#endif +}; +struct rpMatFXMaterialData +{ + MatFXEffectData data[rpMAXPASS]; + RpMatFXMaterialFlags flags; +}; + +static void* MatFXMaterialCopy(void* dstObject, const void* srcObject, RwInt32 offset, RwInt32 size) +{ + const RpMaterial* srcMaterial; + const rpMatFXMaterialData* srcMaterialData; + + RpMaterial* dstMaterial; + rpMatFXMaterialData* dstMaterialData; + + RpMaterial* ret; + + RwUInt8 pass; + + srcMaterial = (const RpMaterial*)srcObject; + dstMaterial = (RpMaterial*)dstObject; + + srcMaterialData = (const rpMatFXMaterialData*)*MATFXMATERIALGETCONSTDATA(srcMaterial); + + if ((rpMatFXMaterialData*)NULL == srcMaterialData) + { + return NULL; + } + + dstMaterialData = (rpMatFXMaterialData*)MatFXMaterialGetData(dstMaterial); + + if (NULL == dstMaterialData) + { + return NULL; + } + ret = RpMatFXMaterialSetEffects(dstMaterial, srcMaterialData->flags); + for (pass = 0; pass < rpMAXPASS; pass++) + { + RpMatFXMaterialFlags effect; + effect = srcMaterialData->data[pass].flag; + + switch (effect) + { + case rpMATFXEFFECTNULL: + { + break; + } + case rpMATFXEFFECTBUMPMAP: + { + const MatFXBumpMapData* srcBumpMapData; + MatFXBumpMapData* dstBumpMapData; + + RwFrame* frame; + RwReal coef; + + srcBumpMapData = &(srcMaterialData->data[pass].data.bumpMap); + dstBumpMapData = &(dstMaterialData->data[pass].data.bumpMap); + + frame = RpMatFXMaterialGetBumpMapFrame(srcMaterial); + coef = RpMatFXMaterialGetBumpMapCoefficient(srcMaterial); + ret = RpMatFXMaterialSetBumpMapFrame(dstMaterial, frame); + ret = RpMatFXMaterialSetBumpMapCoefficient(dstMaterial, coef); + + dstBumpMapData->texture = srcBumpMapData->texture; + dstBumpMapData->bumpTexture = srcBumpMapData->bumpTexture; + + if (NULL != dstBumpMapData->texture) + { + (void)RwTextureAddRef(dstBumpMapData->texture); + } + + if (NULL != dstBumpMapData->bumpTexture) + { + (void)RwTextureAddRef(dstBumpMapData->bumpTexture); + } + + break; + } + case rpMATFXEFFECTENVMAP: + { + RwTexture* texture; + RwFrame* frame; + RwReal coef; + RwBool useFrameBufferAlpha; + + texture = RpMatFXMaterialGetEnvMapTexture(srcMaterial); + frame = RpMatFXMaterialGetEnvMapFrame(srcMaterial); + coef = RpMatFXMaterialGetEnvMapCoefficient(srcMaterial); + useFrameBufferAlpha = RpMatFXMaterialGetEnvMapFrameBufferAlpha(srcMaterial); + + if (NULL != texture) + { + ret = RpMatFXMaterialSetEnvMapTexture(dstMaterial, texture); + } + ret = RpMatFXMaterialSetEnvMapFrame(dstMaterial, frame); + ret = RpMatFXMaterialSetEnvMapFrameBufferAlpha(dstMaterial, useFrameBufferAlpha); + ret = RpMatFXMaterialSetEnvMapCoefficient(dstMaterial, coef); + + break; + } + case rpMATFXEFFECTDUAL: + { + RwTexture* texture; + RwBlendFunction srcBlendMode; + RwBlendFunction dstBlendMode; + + texture = RpMatFXMaterialGetDualTexture(srcMaterial); + RpMatFXMaterialGetDualBlendModes(srcMaterial, &srcBlendMode, &dstBlendMode); + + if (NULL != texture) + { + ret = RpMatFXMaterialSetDualTexture(dstMaterial, texture); + } + ret = RpMatFXMaterialSetDualBlendModes(dstMaterial, srcBlendMode, dstBlendMode); + + break; + } + case rpMATFXEFFECTUVTRANSFORM: + { + RwMatrix* baseTransform; + RwMatrix* dualTransform; + + srcMaterial = + RpMatFXMaterialGetUVTransformMatrices(srcMaterial, &baseTransform, &dualTransform); + + dstMaterial = + RpMatFXMaterialSetUVTransformMatrices(dstMaterial, baseTransform, dualTransform); + + break; + } + default: + { + /* We shouldn't get here. */ + + break; + } + } + } + + return dstObject; +} + +RwStream* _rpMatFXStreamWriteTexture(RwStream* stream, const RwTexture* texture) +{ + RwBool present; + + present = (NULL != texture); + + if (!RwStreamWriteInt32(stream, (RwInt32*)&present, sizeof(RwBool))) + { + return ((RwStream*)NULL); + } + if (present) + { + if (!RwTextureStreamWrite(texture, stream)) + { + return ((RwStream*)NULL); + } + } + + return stream; +} + +RwUInt32 _rpMatFXStreamSizeTexture(const RwTexture* texture) +{ + RwUInt32 size; + + size = sizeof(RwBool); + + if (texture) + { + size += RwTextureStreamGetSize(texture); + } + + return (size); +} + +static RwStream* MatFXMaterialStreamWrite(RwStream* stream, RwInt32 binaryLength, + const void* object, RwInt32 offsetInObject, + RwInt32 sizeInObject) +{ + const RpMaterial* material = (const RpMaterial*)object; + const rpMatFXMaterialData* materialData; + RwUInt8 pass; + RwInt32 temp; + + materialData = (const rpMatFXMaterialData*)*MATFXMATERIALGETCONSTDATA(material); + + temp = materialData->flags; + if (!RwStreamWriteInt32(stream, &temp, sizeof(RwInt32))) + { + return NULL; + } + + for (pass = 0; pass < rpMAXPASS; pass++) + { + RpMatFXMaterialFlags effect; + + effect = materialData->data[pass].flag; + if (!RwStreamWriteInt32(stream, (RwInt32*)&effect, sizeof(RwInt32))) + { + return NULL; + } + + switch (effect) + { + case rpMATFXEFFECTNULL: + case rpMATFXEFFECTUVTRANSFORM: + { + break; + } + case rpMATFXEFFECTBUMPMAP: + { + const MatFXBumpMapData* bumpData; + RwReal coef; + + bumpData = &(materialData->data[pass].data.bumpMap); + coef = -bumpData->coef; + + if (!RwStreamWriteReal(stream, &coef, sizeof(RwReal))) + { + return NULL; + } + if (!_rpMatFXStreamWriteTexture(stream, bumpData->texture)) + { + return NULL; + } + if (!_rpMatFXStreamWriteTexture(stream, bumpData->bumpTexture)) + { + return NULL; + } + + break; + } + case rpMATFXEFFECTENVMAP: + { + const MatFXEnvMapData* envData; + envData = &(materialData->data[pass].data.envMap); + if (!RwStreamWriteReal(stream, &(envData->coef), sizeof(RwReal))) + { + return NULL; + } + temp = envData->useFrameBufferAlpha; + if (!RwStreamWriteInt32(stream, &temp, sizeof(RwInt32))) + { + return NULL; + } + if (!_rpMatFXStreamWriteTexture(stream, envData->texture)) + { + return NULL; + } + + break; + } + case rpMATFXEFFECTDUAL: + { + const MatFXDualData* dualData; + dualData = &(materialData->data[pass].data.dual); + + temp = dualData->srcBlendMode; + if (!RwStreamWriteInt32(stream, &temp, sizeof(RwInt32))) + { + return NULL; + } + + temp = dualData->dstBlendMode; + if (!RwStreamWriteInt32(stream, &temp, sizeof(RwInt32))) + { + return NULL; + } + + if (!_rpMatFXStreamWriteTexture(stream, dualData->texture)) + { + return NULL; + } + + break; + } + default: + { + break; + } + } + } + return stream; +} + +static RwStream* MatFXMaterialStreamRead(RwStream* stream, RwInt32 binaryLength, void* object, + RwInt32 offsetInObject, RwInt32 sizeInObject) +{ + RpMaterial* material; + rpMatFXMaterialData* materialData; + RpMatFXMaterialFlags flags; + RwUInt8 pass; + + material = (RpMaterial*)object; + materialData = (rpMatFXMaterialData*)MatFXMaterialGetData(material); + if (NULL == materialData) + { + return NULL; + } + + if (!RwStreamReadInt32(stream, (RwInt32*)&flags, sizeof(RwInt32))) + { + return NULL; + } + + RpMatFXMaterialSetEffects(material, flags); + + for (pass = 0; pass < rpMAXPASS; pass++) + { + RpMatFXMaterialFlags effect; + + if (!RwStreamReadInt32(stream, (RwInt32*)&effect, sizeof(RwInt32))) + { + return NULL; + } + switch (effect) + { + case rpMATFXEFFECTNULL: + case rpMATFXEFFECTUVTRANSFORM: + { + break; + } + case rpMATFXEFFECTBUMPMAP: + { + RwReal coef; + RwTexture* texture = NULL; + RwTexture* bumpTexture = NULL; + MatFXBumpMapData* bumpMapData; + + bumpMapData = &(materialData->data[pass].data.bumpMap); + if (!RwStreamReadReal(stream, &coef, sizeof(RwReal))) + { + return NULL; + } + if (!_rpMatFXStreamReadTexture(stream, &texture)) + { + return NULL; + } + if (!_rpMatFXStreamReadTexture(stream, &bumpTexture)) + { + if (texture) + { + RwTextureDestroy(texture); + } + + return NULL; + } + if (texture != NULL) + { + RwRaster* raster; + RwInt32 nWidth; + RwReal width; + + bumpMapData->texture = texture; + bumpMapData->bumpTexture = bumpTexture; + raster = RwTextureGetRaster(bumpMapData->texture); + nWidth = RwRasterGetWidth(raster); + width = (RwReal)nWidth; + bumpMapData->invBumpWidth = 1.0f / width; + } + else if (bumpTexture != NULL) + { + RpMatFXMaterialSetBumpMapTexture(material, bumpTexture); + RwTextureDestroy(bumpTexture); + } + else + { + bumpMapData->texture = (RwTexture*)NULL; + bumpMapData->bumpTexture = (RwTexture*)NULL; + } + + RpMatFXMaterialSetBumpMapCoefficient(material, coef); + + break; + } + case rpMATFXEFFECTENVMAP: + { + RwReal coef; + RwBool useFrameBufferAlpha; + RwTexture* texture = 0; + + if (!RwStreamReadReal(stream, &coef, sizeof(RwReal))) + { + return NULL; + } + if (!RwStreamReadInt32(stream, (RwInt32*)&useFrameBufferAlpha, sizeof(RwInt32))) + { + return NULL; + } + if (!_rpMatFXStreamReadTexture(stream, &texture)) + { + return NULL; + } + if (texture != NULL) + { + RpMatFXMaterialSetEnvMapTexture(material, texture); + RwTextureDestroy(texture); + } + + RpMatFXMaterialSetEnvMapCoefficient(material, coef); + RpMatFXMaterialSetEnvMapFrameBufferAlpha(material, useFrameBufferAlpha); + + break; + } + case rpMATFXEFFECTDUAL: + { + RwBlendFunction blendFuncs[2]; + RwTexture* texture = 0; + + if (!RwStreamReadInt32(stream, (RwInt32*)blendFuncs, sizeof(blendFuncs))) + { + return NULL; + } + if (!_rpMatFXStreamReadTexture(stream, &texture)) + { + return NULL; + } + if (texture != NULL) + { + RpMatFXMaterialSetDualTexture(material, texture); + RwTextureDestroy(texture); + } + + RpMatFXMaterialSetDualBlendModes(material, blendFuncs[0], blendFuncs[1]); + + break; + } + default: + { + break; + } + } + } + return stream; +} + +static RwInt32 MatFXMaterialStreamGetSize(const void* object, RwInt32 offsetInObject, + RwInt32 sizeInObject) +{ + const RpMaterial* material; + const rpMatFXMaterialData* materialData; + + RwInt32 size; + RwUInt8 pass; + + material = (const RpMaterial*)object; + materialData = (const rpMatFXMaterialData*)*MATFXMATERIALGETCONSTDATA(material); + + if (NULL == materialData || rpMATFXEFFECTNULL == materialData->flags) + { + return FALSE; + } + + size = sizeof(RpMatFXMaterialFlags); + + for (pass = 0; pass < rpMAXPASS; pass++) + { + RpMatFXMaterialFlags effect; + + effect = materialData->data[pass].flag; + size += sizeof(RpMatFXMaterialFlags); + switch (effect) + { + case rpMATFXEFFECTNULL: + case rpMATFXEFFECTUVTRANSFORM: + { + break; + } + case rpMATFXEFFECTBUMPMAP: + { + size += sizeof(RwReal); + size += _rpMatFXStreamSizeTexture(materialData->data[pass].data.bumpMap.texture); + size += _rpMatFXStreamSizeTexture(materialData->data[pass].data.bumpMap.bumpTexture); + break; + } + case rpMATFXEFFECTENVMAP: + { + size += sizeof(RwReal); + size += sizeof(RwBool); + size += _rpMatFXStreamSizeTexture(materialData->data[pass].data.envMap.texture); + break; + } + case rpMATFXEFFECTDUAL: + { + size += 2 * sizeof(RwBlendFunction); + size += _rpMatFXStreamSizeTexture(materialData->data[pass].data.dual.texture); + + break; + } + default: + { + break; + } + } + } + + return size; +} + +static void* MatFXAtomicConstructor(void* object, RwInt32 offset, RwInt32 size) +{ + MatFXAtomicData* atomicData; + + atomicData = (MatFXAtomicData*)MATFXATOMICGETDATA((RpAtomic*)object); + atomicData->enabled = FALSE; + + return object; +} + +static void* MatFXAtomicDestructor(void* object, RwInt32 offset, RwInt32 size) +{ + MatFXAtomicData* atomicData; + + atomicData = (MatFXAtomicData*)MATFXATOMICGETDATA((RpAtomic*)object); + atomicData->enabled = FALSE; + + return object; +} + +static void* MatFXAtomicCopy(void* dstObject, const void* srcObject, RwInt32 offset, RwInt32 size) +{ + const RpAtomic* srcAtomic; + const MatFXAtomicData* srcAtomicData; + + RpAtomic* dstAtomic; + MatFXAtomicData* dstAtomicData; + + srcAtomic = (const RpAtomic*)srcObject; + dstAtomic = (RpAtomic*)dstObject; + + srcAtomicData = (const MatFXAtomicData*)MATFXATOMICGETCONSTDATA(srcAtomic); + dstAtomicData = (MatFXAtomicData*)MATFXATOMICGETDATA(dstAtomic); + + if (srcAtomicData->enabled) + { + dstAtomicData->enabled = TRUE; + } + + return dstObject; +} + +static RwStream* MatFXAtomicStreamWrite(RwStream* stream, RwInt32 binaryLength, const void* object, + RwInt32 offsetInObject, RwInt32 sizeInObject) +{ + const MatFXAtomicData* atomicData = MATFXATOMICGETCONSTDATA(object); + RwStream* streamOut; + RwInt32 temp; + + temp = atomicData->enabled; + streamOut = RwStreamWriteInt32(stream, &temp, sizeof(RwInt32)); + + return streamOut; +} + +static RwStream* MatFXAtomicStreamRead(RwStream* stream, RwInt32 binaryLength, void* object, + RwInt32 offsetInObject, RwInt32 sizeInObject) +{ + RpAtomic* atomic = (RpAtomic*)object; + RwBool enabled; + + if (!RwStreamReadInt32(stream, (RwInt32*)&enabled, sizeof(RwInt32))) + { + return NULL; + } + if (enabled) + { + RpMatFXAtomicEnableEffects(atomic); + } + + return stream; +} + +static RwInt32 MatFXAtomicStreamGetSize(const void* object, RwInt32 offsetInObject, + RwInt32 sizeInObject) +{ + const MatFXAtomicData* atomicData = MATFXATOMICGETCONSTDATA(object); + + if (FALSE == atomicData->enabled) + { + return FALSE; + } + + return (sizeof(RwBool)); +} + +static void* MatFXWorldSectorConstructor(void* object, RwInt32 offset, RwInt32 size) +{ + MatFXWorldSectorData* worldSectorData; + + worldSectorData = (MatFXWorldSectorData*)MATFXWORLDSECTORGETDATA((RpWorldSector*)object); + worldSectorData->enabled = FALSE; + + return object; +} + +static void* MatFXWorldSectorDestructor(void* object, RwInt32 offset, RwInt32 size) +{ + MatFXWorldSectorData* worldSectorData; + + worldSectorData = (MatFXWorldSectorData*)MATFXWORLDSECTORGETDATA((RpWorldSector*)object); + worldSectorData->enabled = FALSE; + + return object; +} + +static void* MatFXWorldSectorCopy(void* dstObject, const void* srcObject, RwInt32 offset, + RwInt32 size) +{ + const RpWorldSector* srcWorldSector; + const MatFXWorldSectorData* srcWorldSectorData; + + RpWorldSector* dstWorldSector; + MatFXWorldSectorData* dstWorldSectorData; + + srcWorldSector = (const RpWorldSector*)srcObject; + dstWorldSector = (RpWorldSector*)dstObject; + + srcWorldSectorData = (const MatFXWorldSectorData*)MATFXWORLDSECTORGETCONSTDATA(srcWorldSector); + dstWorldSectorData = (MatFXWorldSectorData*)MATFXWORLDSECTORGETDATA(dstWorldSector); + + if (srcWorldSectorData->enabled) + { + dstWorldSectorData->enabled = TRUE; + } + + return dstObject; +} + +static RwStream* MatFXWorldSectorStreamWrite(RwStream* stream, RwInt32 binaryLength, + const void* object, RwInt32 offsetInObject, + RwInt32 sizeInObject) +{ + RwStream* streamOut; + RwInt32 temp; + const MatFXWorldSectorData* sectorData = MATFXWORLDSECTORGETCONSTDATA(object); + + temp = sectorData->enabled; + streamOut = RwStreamWriteInt32(stream, &temp, sizeof(RwInt32)); + + return streamOut; +} + +static RwStream* MatFXWorldSectorStreamRead(RwStream* stream, RwInt32 binaryLength, void* object, + RwInt32 offsetInObject, RwInt32 sizeInObject) +{ + RpWorldSector* worldSector = (RpWorldSector*)object; + RwBool enabled; + + if (!RwStreamReadInt32(stream, (RwInt32*)&enabled, sizeof(RwInt32))) + { + return NULL; + } + + if (enabled) + { + RpMatFXWorldSectorEnableEffects(worldSector); + } + + return stream; +} + +static RwInt32 MatFXWorldSectorStreamGetSize(const void* object, RwInt32 offsetInObject, + RwInt32 sizeInObject) +{ + const MatFXWorldSectorData* sectorData = MATFXWORLDSECTORGETCONSTDATA(object); + + if (FALSE == sectorData->enabled) + { + return FALSE; + } + + return (sizeof(RwBool)); +} + +RwTexture* _rpMatFXTextureMaskCreate(const RwTexture* baseTexture, const RwTexture* maskTexture) +{ + RwRaster* baseRaster = (RwRaster*)NULL; + RwRaster* maskRaster; + RwRaster* newRaster; + + RwInt32 maskX, maskY; + RwInt32 baseX, baseY; + + RwImage* maskImage; + RwImage* baseImage; + + RwTexture* result; + + RwTextureFilterMode filterMode; + RwTextureAddressMode addrsMode; + + maskRaster = RwTextureGetRaster(maskTexture); + maskX = RwRasterGetWidth(maskRaster); + maskY = RwRasterGetHeight(maskRaster); + maskImage = RwImageCreate(maskX, maskY, 32); + + RwImageAllocatePixels(maskImage); + RwImageSetFromRaster(maskImage, maskRaster); + + if (baseTexture) + { + baseRaster = RwTextureGetRaster(baseTexture); + baseX = RwRasterGetWidth(baseRaster); + baseY = RwRasterGetHeight(baseRaster); + baseImage = RwImageCreate(baseX, baseY, 32); + + RwImageAllocatePixels(baseImage); + RwImageSetFromRaster(baseImage, baseRaster); + } + else + { + RwInt32 x, y; + + baseX = RwRasterGetWidth(maskRaster); + baseY = RwRasterGetHeight(maskRaster); + baseImage = RwImageCreate(baseX, baseY, 32); + RwImageAllocatePixels(baseImage); + + for (y = 0; y < baseY; y++) + { + for (x = 0; x < baseX; x++) + { + *(RwUInt32*)(RwImageGetPixels(baseImage) + RwImageGetStride(baseImage) * y + + x * 4) = 0xFfFfFfFf; + } + } + } + + if ((baseX != maskX) || (baseY != maskY)) + { + RwImage* resampleImage; + + resampleImage = RwImageCreate(baseX, baseY, 32); + + RwImageAllocatePixels(resampleImage); + RwImageResample(resampleImage, maskImage); + RwImageDestroy(maskImage); + + maskImage = resampleImage; + } + + RwImageMakeMask(maskImage); + RwImageApplyMask(baseImage, maskImage); + + { + RwInt32 rasterWidth, rasterHeight; + RwInt32 rasterDepth, rasterFlags, rasterBaseFlags; + + RwImageFindRasterFormat(baseImage, rwRASTERTYPETEXTURE, &rasterWidth, &rasterHeight, + &rasterDepth, &rasterFlags); + + if (baseTexture) + { + rasterBaseFlags = RwRasterGetFormat(baseRaster); + } + else + { + rasterBaseFlags = RwRasterGetFormat(maskRaster); + } + + if (rasterBaseFlags & rwRASTERFORMATMIPMAP) + { + rasterFlags |= (rwRASTERFORMATAUTOMIPMAP | rwRASTERFORMATMIPMAP); + } + + newRaster = RwRasterCreate(rasterWidth, rasterHeight, rasterDepth, rasterFlags); + RwRasterSetFromImage(newRaster, baseImage); + } + + result = RwTextureCreate(newRaster); + + if (baseTexture) + { + filterMode = RwTextureGetFilterMode(baseTexture); + addrsMode = RwTextureGetAddressing(baseTexture); + } + else + { + filterMode = RwTextureGetFilterMode(maskTexture); + addrsMode = RwTextureGetAddressing(maskTexture); + } + + RwTextureSetAddressing(result, addrsMode); + RwTextureSetFilterMode(result, filterMode); + + RwImageDestroy(baseImage); + RwImageDestroy(maskImage); + + { + RwChar newName[rwTEXTUREBASENAMELENGTH] = { 0 }; + + GenBumpedTextureName(newName, baseTexture, maskTexture); + RwTextureSetName(result, newName); + } + + return result; +} + +RpAtomic* RpMatFXAtomicEnableEffects(RpAtomic* atomic) +{ + MatFXAtomicData* atomicData; + + atomicData = (MatFXAtomicData*)MATFXATOMICGETDATA(atomic); + + if (atomicData->enabled == FALSE) + { + if (NULL == _rpMatFXPipelineAtomicSetup(atomic)) + { + return NULL; + } + + atomicData->enabled = TRUE; + } + + return atomic; +} + +RpWorldSector* RpMatFXWorldSectorEnableEffects(RpWorldSector* worldSector) +{ + MatFXWorldSectorData* worldSectorData; + + worldSectorData = (MatFXWorldSectorData*)MATFXWORLDSECTORGETDATA(worldSector); + + if (worldSectorData->enabled == FALSE) + { + if (NULL == _rpMatFXPipelineWorldSectorSetup(worldSector)) + { + return NULL; + } + + worldSectorData->enabled = TRUE; + } + + return worldSector; +} + +RpMaterial* RpMatFXMaterialSetEffects(RpMaterial* material, RpMatFXMaterialFlags flags) +{ + rpMatFXMaterialData* materialData; + + materialData = (rpMatFXMaterialData*)MatFXMaterialGetData(material); + if (NULL == materialData) + { + return NULL; + } + + if ((flags == rpMATFXEFFECTNULL) || + ((materialData->flags != rpMATFXEFFECTNULL) && (materialData->flags != flags))) + { + MatFXMaterialDataClean(materialData); + } + + materialData->flags = flags; + + switch (materialData->flags) + { + case rpMATFXEFFECTBUMPMAP: + { + materialData->data[rpSECONDPASS].flag = rpMATFXEFFECTBUMPMAP; + + break; + } + case rpMATFXEFFECTENVMAP: + { + materialData->data[rpSECONDPASS].flag = rpMATFXEFFECTENVMAP; + + break; + } + case rpMATFXEFFECTBUMPENVMAP: + { + materialData->data[rpSECONDPASS].flag = rpMATFXEFFECTBUMPMAP; + materialData->data[rpTHIRDPASS].flag = rpMATFXEFFECTENVMAP; + + break; + } + case rpMATFXEFFECTDUAL: + { + materialData->data[rpSECONDPASS].flag = rpMATFXEFFECTDUAL; + + RpMatFXMaterialSetDualBlendModes(material, rwBLENDSRCALPHA, rwBLENDINVSRCALPHA); + + break; + } + case rpMATFXEFFECTUVTRANSFORM: + { + materialData->data[rpSECONDPASS].flag = rpMATFXEFFECTUVTRANSFORM; + + break; + } + case rpMATFXEFFECTDUALUVTRANSFORM: + { + materialData->data[rpSECONDPASS].flag = rpMATFXEFFECTUVTRANSFORM; + materialData->data[rpTHIRDPASS].flag = rpMATFXEFFECTDUAL; + + RpMatFXMaterialSetDualBlendModes(material, rwBLENDSRCALPHA, rwBLENDINVSRCALPHA); + + break; + } + case rpMATFXEFFECTNULL: + { + break; + } + default: + { + break; + } + } + + _rpMatFXMaterialPlatformInitialize(material); + + return material; +} + +RpMaterial* RpMatFXMaterialSetupBumpMap(RpMaterial* material, RwTexture* texture, RwFrame* frame, + RwReal coef) +{ + if (NULL == RpMatFXMaterialSetBumpMapTexture(material, texture)) + { + return NULL; + } + + if (NULL == RpMatFXMaterialSetBumpMapFrame(material, frame)) + { + return NULL; + } + + if (NULL == RpMatFXMaterialSetBumpMapCoefficient(material, coef)) + { + return NULL; + } + + return material; +} + +RpMaterial* RpMatFXMaterialSetupEnvMap(RpMaterial* material, RwTexture* texture, RwFrame* frame, + RwBool useFrameBufferAlpha, RwReal coef) +{ + if (NULL == RpMatFXMaterialSetEnvMapTexture(material, texture)) + { + return NULL; + } + + if (NULL == RpMatFXMaterialSetEnvMapFrame(material, frame)) + { + return NULL; + } + + if (NULL == RpMatFXMaterialSetEnvMapFrameBufferAlpha(material, useFrameBufferAlpha)) + { + return NULL; + } + + if (NULL == RpMatFXMaterialSetEnvMapCoefficient(material, coef)) + { + return NULL; + } + + return material; +} + +RpMatFXMaterialFlags RpMatFXMaterialGetEffects(const RpMaterial* material) +{ + const rpMatFXMaterialData* materialData; + + materialData = (const rpMatFXMaterialData*)*MATFXMATERIALGETCONSTDATA(material); + + if (NULL == materialData) + { + return (rpMATFXEFFECTNULL); + } + + return (materialData->flags); +} + +RpMaterial* RpMatFXMaterialSetBumpMapTexture(RpMaterial* material, RwTexture* bumpTexture) +{ + MatFXBumpMapData* bumpMapData; + + bumpMapData = (MatFXBumpMapData*)MATFXBUMPMAPGETDATA(material); + + if (NULL != bumpMapData->bumpTexture) + { + RwTextureDestroy(bumpMapData->bumpTexture); + bumpMapData->bumpTexture = (RwTexture*)NULL; + } + + if (NULL != bumpMapData->texture) + { + RwTextureDestroy(bumpMapData->texture); + + bumpMapData->texture = (RwTexture*)NULL; + bumpMapData->invBumpWidth = 0; + } + + if (bumpTexture) + { + RwBool dummyTextures; + RwRaster* bumpRaster; + RwTexture* baseTexture; + + bumpMapData->bumpTexture = bumpTexture; + (void)RwTextureAddRef(bumpMapData->bumpTexture); + bumpRaster = RwTextureGetRaster(bumpTexture); + dummyTextures = (0 == RwRasterGetWidth(bumpRaster)); + + baseTexture = RpMaterialGetTexture(material); + if (!dummyTextures && baseTexture) + { + RwRaster* baseRaster; + baseRaster = RwTextureGetRaster(baseTexture); + dummyTextures = (0 == RwRasterGetWidth(baseRaster)); + } + + if (!dummyTextures) + { + RwChar bumpedName[rwTEXTUREBASENAMELENGTH] = { 0 }; + RwTexDictionary* dict; + RwRaster* bumpedRaster; + + GenBumpedTextureName(bumpedName, baseTexture, bumpTexture); + + dict = RwTexDictionaryGetCurrent(); + bumpMapData->texture = (RwTexture*)NULL; + if (dict) + { + bumpMapData->texture = RwTexDictionaryFindNamedTexture(dict, bumpedName); + } + + if (!bumpMapData->texture) + { + bumpMapData->texture = + (RwTexture*)_rpMatFXSetupBumpMapTexture(baseTexture, bumpTexture); + if (!bumpMapData->texture) + { + return NULL; + } + + if (dict) + { + RwTexDictionaryAddTexture(dict, bumpMapData->texture); + } + } + else + { + (void)RwTextureAddRef(bumpMapData->texture); + } + + bumpedRaster = RwTextureGetRaster(bumpMapData->texture); + bumpMapData->invBumpWidth = 1.0f / ((RwReal)RwRasterGetWidth(bumpedRaster)); + } + } + else + { + RwTexture* baseTexture; + RwRaster* raster; + + baseTexture = RpMaterialGetTexture(material); + raster = RwTextureGetRaster(baseTexture); + + bumpMapData->invBumpWidth = 1.0f / ((RwReal)RwRasterGetWidth(raster)); + } + + return material; +} + +RpMaterial* RpMatFXMaterialSetBumpMapFrame(RpMaterial* material, RwFrame* frame) +{ +} + +RpMaterial* RpMatFXMaterialSetBumpMapCoefficient(RpMaterial* material, RwReal coef) +{ +} + +RwFrame* RpMatFXMaterialGetBumpMapFrame(const RpMaterial* material) +{ +} + +RwReal RpMatFXMaterialGetBumpMapCoefficient(const RpMaterial* material) +{ +} + +RpMaterial* RpMatFXMaterialSetEnvMapTexture(RpMaterial* material, RwTexture* texture) +{ + MatFXEnvMapData* envMapData; + + envMapData = (MatFXEnvMapData*)MATFXENVMAPGETDATA(material); + RwTextureAddRef(texture); + + if (NULL != envMapData->texture) + { + RwTextureDestroy(envMapData->texture); + envMapData->texture = (RwTexture*)NULL; + } + + envMapData->texture = texture; + + return material; +} + +RpMaterial* RpMatFXMaterialSetEnvMapFrame(RpMaterial* material, RwFrame* frame) +{ +} diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcn.c b/src/rwsdk/plugin/ptank/gcn/ptankgcn.c new file mode 100644 index 000000000..e29e6c088 --- /dev/null +++ b/src/rwsdk/plugin/ptank/gcn/ptankgcn.c @@ -0,0 +1,13 @@ +#include "rwplcore.h" +#include "rwcore.h" + +s32 _rxPTankGameCubeRenderPipeline; + +void PTankClose() +{ + if (_rxPTankGameCubeRenderPipeline != 0) + { + _rxPipelineDestroy((RxPipeline*)_rxPTankGameCubeRenderPipeline); + _rxPTankGameCubeRenderPipeline = 0; + } +} diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcn_cc_cs_nr.c b/src/rwsdk/plugin/ptank/gcn/ptankgcn_cc_cs_nr.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcn_cc_cs_ppr.c b/src/rwsdk/plugin/ptank/gcn/ptankgcn_cc_cs_ppr.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcn_cc_ppm.c b/src/rwsdk/plugin/ptank/gcn/ptankgcn_cc_ppm.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcn_cc_pps_nr.c b/src/rwsdk/plugin/ptank/gcn/ptankgcn_cc_pps_nr.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcn_cc_pps_ppr.c b/src/rwsdk/plugin/ptank/gcn/ptankgcn_cc_pps_ppr.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcn_nc_cs_nr.c b/src/rwsdk/plugin/ptank/gcn/ptankgcn_nc_cs_nr.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcn_nc_cs_ppr.c b/src/rwsdk/plugin/ptank/gcn/ptankgcn_nc_cs_ppr.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcn_nc_ppm.c b/src/rwsdk/plugin/ptank/gcn/ptankgcn_nc_ppm.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcn_nc_pps_nr.c b/src/rwsdk/plugin/ptank/gcn/ptankgcn_nc_pps_nr.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcn_nc_pps_ppr.c b/src/rwsdk/plugin/ptank/gcn/ptankgcn_nc_pps_ppr.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcncallbacks.c b/src/rwsdk/plugin/ptank/gcn/ptankgcncallbacks.c new file mode 100644 index 000000000..d7864bd6f --- /dev/null +++ b/src/rwsdk/plugin/ptank/gcn/ptankgcncallbacks.c @@ -0,0 +1,7 @@ +#include "rwplcore.h" +#include "rwcore.h" + +s32 _rpPTankGameCubeInstanceCallBack() +{ + return 1; +} diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcnrender.c b/src/rwsdk/plugin/ptank/gcn/ptankgcnrender.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/ptank/gcn/ptankgcntransforms.c b/src/rwsdk/plugin/ptank/gcn/ptankgcntransforms.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/ptank/rpptank.c b/src/rwsdk/plugin/ptank/rpptank.c new file mode 100644 index 000000000..1a377cd63 --- /dev/null +++ b/src/rwsdk/plugin/ptank/rpptank.c @@ -0,0 +1,37 @@ +#include "rwcore.h" +#include "rtanim.h" +#include "rtquat.h" + +RwInt32 _rpPTankAtomicDataOffset = 0; /* Offset in RpAtomic */ +RwInt32 _rpPTankGlobalsOffset = 0; /* Offset in Rwengine */ + +typedef struct RwTexCoords RxTexCoords; + +const RwInt32 datasize[] = { + sizeof(RwV3d), /*rpPTANKDFLAGPOSITION*/ + sizeof(RwMatrix), /*rpPTANKDFLAGMATRIX*/ + sizeof(RwV3d), /*rpPTANKDFLAGNORMAL*/ + sizeof(RwV2d), /*rpPTANKDFLAGSIZE*/ + sizeof(RwRGBA), /*rpPTANKDFLAGCOLOR*/ + 4 * sizeof(RwRGBA), /*rpPTANKDFLAGVTXCOLOR*/ + sizeof(RwReal), /*rpPTANKDFLAG2DROTATE*/ + 2 * sizeof(RwTexCoords), /*rpPTANKDFLAGVTX2TEXCOORDS*/ + 4 * sizeof(RwTexCoords) /*rpPTANKDFLAGVTX4TEXCOORDS*/ +}; + +#if (defined(GCN_DRVMODEL_H)) + +#define FAVORITEORGANISATIONMODE (rpPTANKDFLAGSTRUCTURE) + +#elif (defined(D3D8_DRVMODEL_H) || defined(D3D9_DRVMODEL_H) || defined(XBOX_DRVMODEL_H) || \ + defined(NULL_DRVMODEL_H) || defined(NULLGCN_DRVMODEL_H) || defined(NULLSKY_DRVMODEL_H) || \ + defined(SKY2_DRVMODEL_H) || defined(OPENGL_DRVMODEL_H) || defined(SOFTRAS_DRVMODEL_H) || \ + defined(NULLXBOX_DRVMODEL_H)) + +#define FAVORITEORGANISATIONMODE (rpPTANKDFLAGARRAY) + +#endif + +static void* PTankAtomicInit(void* object, RwInt32 offset, RwInt32 size) +{ +} diff --git a/src/rwsdk/plugin/skin2/bsplit.c b/src/rwsdk/plugin/skin2/bsplit.c new file mode 100644 index 000000000..1305637be --- /dev/null +++ b/src/rwsdk/plugin/skin2/bsplit.c @@ -0,0 +1,118 @@ +#include "rwplcore.h" +#include "rwcore.h" +#include + +RwBool _rpSkinSplitDataDestroy(RpSkin* skin) +{ + SkinSplitData* skinSplitData; + + skinSplitData = &skin->skinSplitData; + + if (skinSplitData->matrixRemapIndices != NULL) + { + RwFree(skinSplitData->matrixRemapIndices); + } + + skinSplitData->boneLimit = 0; + skinSplitData->numMeshes = 0; + skinSplitData->numRLE = 0; + + skinSplitData->matrixRemapIndices = NULL; + skinSplitData->meshRLECount = NULL; + skinSplitData->meshRLE = NULL; + + return TRUE; +} + +RwStream* _rpSkinSplitDataStreamWrite(RwStream* stream, const RpSkin* skin) +{ + RwInt32 streamSize; + const SkinSplitData* skinSplitData; + + skinSplitData = &skin->skinSplitData; + + /* Write out the counters */ + if (!RwStreamWriteInt32(stream, (const RwInt32*)&skinSplitData->boneLimit, sizeof(RwInt32))) + { + return NULL; + } + + if (!RwStreamWriteInt32(stream, (const RwInt32*)&skinSplitData->numMeshes, sizeof(RwInt32))) + { + return NULL; + } + + if (!RwStreamWriteInt32(stream, (const RwInt32*)&skinSplitData->numRLE, sizeof(RwInt32))) + { + return NULL; + } + + if (0 < skin->skinSplitData.numMeshes) + { + streamSize = SkinSplitDataSize(skin, skinSplitData); + + if (!RwStreamWrite(stream, skinSplitData->matrixRemapIndices, streamSize)) + { + return NULL; + } + } + + return stream; +} + +RwStream* _rpSkinSplitDataStreamRead(RwStream* stream, RpSkin* skin) +{ + RwInt32 numMeshes, numRLE, boneLimit, streamSize; + SkinSplitData* skinSplitData; + + skinSplitData = &skin->skinSplitData; + + if (!RwStreamReadInt32(stream, (RwInt32*)&boneLimit, sizeof(RwInt32))) + { + return NULL; + } + + if (!RwStreamReadInt32(stream, (RwInt32*)&numMeshes, sizeof(RwInt32))) + { + return NULL; + } + + if (!RwStreamReadInt32(stream, (RwInt32*)&numRLE, sizeof(RwInt32))) + { + return NULL; + } + + if (numMeshes > 0) + { + if (!_rpSkinSplitDataCreate(skin, boneLimit, skin->boneData.numBones, numMeshes, numRLE)) + { + return NULL; + } + + streamSize = SkinSplitDataSize(skin, skinSplitData); + + /* Read in the index array */ + if (!RwStreamRead(stream, skinSplitData->matrixRemapIndices, streamSize)) + { + RwFree(skinSplitData); + + return NULL; + } + } + + return stream; +} + +RwInt32 _rpSkinSplitDataStreamGetSize(const RpSkin* skin) +{ + RwUInt32 streamSize; + + streamSize = sizeof(RwUInt32) * 3; + + if (0 < skin->skinSplitData.numMeshes) + { + streamSize += SkinSplitDataSize(skin, &skin->skinSplitData); + } + + return streamSize; +} diff --git a/src/rwsdk/plugin/skin2/gcn/instance/instanceskin.c b/src/rwsdk/plugin/skin2/gcn/instance/instanceskin.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/skin2/gcn/skingcn.c b/src/rwsdk/plugin/skin2/gcn/skingcn.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/skin2/gcn/skingcnasm.c b/src/rwsdk/plugin/skin2/gcn/skingcnasm.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/skin2/gcn/skingcng.c b/src/rwsdk/plugin/skin2/gcn/skingcng.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/skin2/gcn/skinmatrixblend.c b/src/rwsdk/plugin/skin2/gcn/skinmatrixblend.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/skin2/gcn/skinstream.c b/src/rwsdk/plugin/skin2/gcn/skinstream.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/plugin/skin2/rpskin.c b/src/rwsdk/plugin/skin2/rpskin.c new file mode 100644 index 000000000..8ed1f7bbc --- /dev/null +++ b/src/rwsdk/plugin/skin2/rpskin.c @@ -0,0 +1,284 @@ +#include "rwplcore.h" +#include "rwcore.h" +#include + +#if (defined(RWDEBUG)) +long _rpSkinStackDepth = 0; +#endif /* (defined(RWDEBUG)) */ + +#define rpSKINENTRIESPERBLOCK 20 +#define rpSKINALIGNMENT sizeof(RwUInt32) + +#define ROUNDUP16(x) (((RwUInt32)(x) + 16 - 1) & ~(16 - 1)) + +#define CHECKSTREAMANDRETURN(success) \ + MACRO_START \ + { \ + if (NULL == (success)) \ + { \ + RWRETURN((RwStream*)NULL); \ + } \ + } \ + MACRO_STOP + +#define rwID_SKINPLUGIN MAKECHUNKID(rwVENDORID_CRITERIONTK, 0x16) + +static RwInt32 _rpSkinFreeListBlockSize = rpSKINENTRIESPERBLOCK, _rpSkinFreeListPreallocBlocks = 1; +static RwFreeList _rpSkinFreeList; + +static RpSkin* SkinCreate(RwUInt32 numVertices, RwUInt32 numBones, RwUInt32 numBonesUsed, + RwUInt32 maxWeights, RwMatrixWeights* vertexWeights, + RwUInt32* vertexIndices, RwMatrix* inverseMatrices) +{ + RwUInt8 usedBoneList[256]; + RpSkin* skin; + + RWFUNCTION(RWSTRING("SkinCreate")); + RWASSERT(0 < numVertices); + RWASSERT(0 < numBones); + + /* Get a new skin */ + skin = (RpSkin*)RwFreeListAlloc(_rpSkinGlobals.freeList, rwID_SKINPLUGIN | rwMEMHINTDUR_EVENT); + RWASSERT(NULL != skin); + + /* Clean the skin */ + memset(skin, 0, sizeof(RpSkin)); + + /* Find the maximum number of weights used */ + if (0 == maxWeights) + { + SkinFindMaxWeights(skin, vertexWeights, numVertices); + } + + /* Find the number of used bones */ + if (0 == numBonesUsed) + { + SkinFindNumUsedBones(skin, vertexIndices, vertexWeights, usedBoneList, &numBonesUsed, + numVertices); + } + + /* Setup the skin's bones */ + if (!SkinCreateSkinData(skin, numBones, numBonesUsed, numVertices, usedBoneList, vertexWeights, + vertexIndices, inverseMatrices)) + { + RwFreeListFree(_rpSkinGlobals.freeList, skin); + RWRETURN((RpSkin*)NULL); + } + + RWRETURN(skin); +} + +static void* SkinOpen(void* instance, RwInt32 offset, RwInt32 size) +{ +} + +static void* SkinClose(void* instance, RwInt32 offset, RwInt32 size) +{ + _rpSkinGlobals.module.numInstances--; + + if (0 == _rpSkinGlobals.module.numInstances) + { + RwBool success; + + success = _rpSkinPipelinesDestroy(); + RwFreeListDestroy(_rpSkinGlobals.freeList); + _rpSkinGlobals.freeList = (RwFreeList*)NULL; + RwFree(_rpSkinGlobals.matrixCache.unaligned); + _rpSkinGlobals.matrixCache.unaligned = NULL; + } + + return instance; +} + +static void* SkinGeometryConstructor(void* object, RwInt32 offset, RwInt32 size) +{ + *RPSKINGEOMETRYGETDATA(object) = (RpSkin*)NULL; + + return object; +} + +static void* SkinGeometryDestructor(void* object, RwInt32 offset, RwInt32 size) +{ + RpGeometry* geometry; + RpSkin* skin; + + geometry = (RpGeometry*)object; + skin = *RPSKINGEOMETRYGETDATA(geometry); + + if (NULL != skin) + { + _rpSkinDeinitialize(geometry); + *RPSKINGEOMETRYGETDATA(geometry) = RpSkinDestroy(skin); + } + + return object; +} + +static void* SkinGeometryCopy(void* dstObject, const void* srcObject, RwInt32 offset, RwInt32 size) +{ +} + +static void* SkinAtomicConstructor(void* object, RwInt32 offset, RwInt32 size) +{ + // use same var as the Destructor counterpart? +} + +static void* SkinAtomicDestructor(void* object, RwInt32 offset, RwInt32 size) +{ + RpAtomic* atomic; + SkinAtomicData* atomicData; + + atomic = (RpAtomic*)object; + atomicData = RPSKINATOMICGETDATA(atomic); + + if (NULL != atomicData->hierarchy) + { + atomicData->hierarchy = (RpHAnimHierarchy*)NULL; + } + + return object; +} + +static void* SkinAtomicCopy(void* dstObject, const void* srcObject, RwInt32 offset, RwInt32 size) +{ + // odd way to write it but ok + const RpAtomic* srcAtomic; + const SkinAtomicData* srcAtomicData; + + RpAtomic* dstAtomic; + SkinAtomicData* dstAtomicData; + + srcAtomic = (const RpAtomic*)srcObject; + dstAtomic = (RpAtomic*)dstObject; + + srcAtomicData = RPSKINATOMICGETCONSTDATA(srcAtomic); + dstAtomicData = RPSKINATOMICGETDATA(dstAtomic); + + dstAtomicData->hierarchy = srcAtomicData->hierarchy; + + return dstObject; +} + +static RwBool SkinAtomicAlways(void* object, RwInt32 offset, RwInt32 size) +{ +} + +static RwBool SkinAtomicRights(void* object, RwInt32 offset, RwInt32 size, RwUInt32 extraData) +{ +} + +static RwInt32 SkinGeometrySize(const void* object, RwInt32 offset, RwInt32 bytes) +{ +} + +static RwStream* SkinGeometryWrite(RwStream* stream, RwInt32 binaryLength, const void* object, + RwInt32 offsetInObject, RwInt32 sizeInObject) +{ +} + +static RwStream* SkinGeometryRead(RwStream* stream, RwInt32 binaryLength, void* object, + RwInt32 offsetInObject, RwInt32 sizeInObject) +{ +} + +static RwStream* SkinAtomicRead(RwStream* stream, RwInt32 binaryLength, void* object, + RwInt32 offsetInObject, RwInt32 sizeInObject) +{ +} + +static RwStream* SkinAtomicWrite(RwStream* stream, RwInt32 binaryLength, const void* object, + RwInt32 offsetInObject, RwInt32 sizeInObject) +{ + return; +} + +static RwInt32 SkinAtomicGetSize(const void* object, RwInt32 offsetInObject, RwInt32 sizeInObject) +{ + return 0; +} + +RwBool RpSkinPluginAttach(void) +{ +} + +RpAtomic* RpSkinAtomicSetHAnimHierarchy(RpAtomic* atomic, RpHAnimHierarchy* hierarchy) +{ + SkinAtomicData* atomicData; + + atomicData = RPSKINATOMICGETDATA(atomic); + atomicData->hierarchy = hierarchy; + + return atomic; +} + +RpSkin* RpSkinGeometryGetSkin(RpGeometry* geometry) +{ + RpSkin* skin; + + skin = *RPSKINGEOMETRYGETDATA(geometry); + + return skin; +} + +RpGeometry* RpSkinGeometrySetSkin(RpGeometry* geometry, RpSkin* skin) +{ + RpSkin* oldSkin; + + oldSkin = *RPSKINGEOMETRYGETDATA(geometry); + if (skin != oldSkin) + { + if (NULL != oldSkin) + { + _rpSkinDeinitialize(geometry); + } + + *RPSKINGEOMETRYGETDATA(geometry) = skin; + + if (NULL != skin) + { + if (!_rpSkinInitialize(geometry)) + { + return NULL; + } + } + } + + return geometry; +} + +RpSkin* RpSkinDestroy(RpSkin* skin) +{ + if (skin->unaligned) + { + RwFree(skin->unaligned); + } + + _rpSkinSplitDataDestroy(skin); + skin = (RpSkin*)NULL; + + return skin; +} + +RwUInt32 RpSkinGetNumBones(RpSkin* skin) +{ + return (skin->boneData.numBones); +} + +const RwMatrixWeights* RpSkinGetVertexBoneWeights(RpSkin* skin) +{ + return (skin->vertexMaps.matrixWeights); +} + +const RwUInt32* RpSkinGetVertexBoneIndices(RpSkin* skin) +{ + return (skin->vertexMaps.matrixIndices); +} + +const RwMatrix* RpSkinGetSkinToBoneMatrices(RpSkin* skin) +{ + return (skin->boneData.invBoneToSkinMat); +} + +RpAtomic* RpSkinAtomicSetType(RpAtomic* atomic, RpSkinType type) +{ +} diff --git a/src/rwsdk/plugin/skin2/skin.h b/src/rwsdk/plugin/skin2/skin.h new file mode 100644 index 000000000..dc1639345 --- /dev/null +++ b/src/rwsdk/plugin/skin2/skin.h @@ -0,0 +1,184 @@ +#ifndef _SKIN_H +#define _SKIN_H + +#include "rwcore.h" +#include "rpworld.h" + +//#include "rpplugin.h" +//#include "rpdbgerr.h" + +#include "rphanim.h" +#include "rpskin.h" + +#if (defined(SKY2_DRVMODEL_H)) +#include "sky2/skinsky.h" +#elif (defined(XBOX_DRVMODEL_H)) +#include "xbox/skinxbox.h" +#elif (defined(GCN_DRVMODEL_H)) +#include "gcn/skingcn.h" +#elif (defined(NULLGCN_DRVMODEL_H)) +#include "gcn/skingcn.h" +#elif (defined(D3D8_DRVMODEL_H)) +#include "d3d8/skind3d8.h" +#elif (defined(D3D9_DRVMODEL_H)) +#include "d3d9/skind3d9.h" +#elif (defined(OPENGL_DRVMODEL_H)) +#include "opengl/skinopengl.h" +#elif (defined(SOFTRAS_DRVMODEL_H)) +#include "softras/skinsoftras.h" +#elif (defined(NULL_DRVMODEL_H) || defined(NULLSKY_DRVMODEL_H) || defined(NULLXBOX_DRVMODEL_H)) +#include "null/skinnull.h" +#else +//#include "generic/skingeneric.h" +#endif + +enum SkinPipeline +{ + rpNASKINPIPELINE = 0, + rpSKINPIPELINESKINGENERIC = 0x01, + rpSKINPIPELINESKINMATFX = 0x02, + rpSKINPIPELINESKINTOON = 0x04, + rpSKINPIPELINEFORCEENUMSIZEINT = RWFORCEENUMSIZEINT +}; +typedef enum SkinPipeline SkinPipeline; + +typedef void* SkinUnaligned; + +typedef struct SkinPlatformData SkinPlatformData; +struct SkinPlatformData +{ + void* vertices; + void* normals; + RwUInt8* weights; + RwUInt8* indices; + RwUInt32 skinType; +}; +#if defined(SKIN_ATOMIC_PLATFORM_DATA) +typedef struct SkinAtomicPlatformData SkinAtomicPlatformData; +#endif +typedef struct SkinGlobalPlatform SkinGlobalPlatform; +struct SkinGlobalPlatform +{ + RxPipeline* pipelines[5]; +}; + +typedef struct SkinSplitData SkinSplitData; +struct SkinSplitData +{ + RwUInt32 boneLimit; + RwUInt32 numMeshes; + RwUInt32 numRLE; + RwUInt8* matrixRemapIndices; + RwUInt8* meshRLECount; + RwUInt8* meshRLE; +}; + +typedef struct SkinBoneData SkinBoneData; +struct SkinBoneData +{ + RwUInt32 numBones; + RwUInt32 numUsedBones; + RwUInt8* usedBoneList; + RwMatrix* invBoneToSkinMat; +}; + +typedef struct SkinVertexMaps SkinVertexMaps; +struct SkinVertexMaps +{ + RwUInt32 maxWeights; + RwUInt32* matrixIndices; + RwMatrixWeights* matrixWeights; +}; + +struct RpSkin +{ + SkinBoneData boneData; + SkinVertexMaps vertexMaps; + SkinPlatformData platformData; + SkinSplitData skinSplitData; + SkinUnaligned* unaligned; +}; + +typedef struct SkinAtomicData SkinAtomicData; +struct SkinAtomicData +{ + RpHAnimHierarchy* hierarchy; +#if defined(SKIN_ATOMIC_PLATFORM_DATA) + SkinAtomicPlatformData platformData; +#endif +}; + +typedef struct SkinMatrixCache SkinMatrixCache; +struct SkinMatrixCache +{ + RwMatrix* aligned; + SkinUnaligned unaligned; +}; + +typedef struct SkinGlobals SkinGlobals; +typedef struct RwModuleInfo RwModuleInfo; + +struct SkinGlobals +{ + RwInt32 engineOffset; + RwInt32 atomicOffset; + RwInt32 geometryOffset; + + SkinMatrixCache matrixCache; + RwUInt32 numMatrices; + + RwFreeList* freeList; + RwModuleInfo module; + + SkinGlobalPlatform platform; + + SkinSplitData* skinSplitData; +}; + +extern SkinGlobals _rpSkinGlobals; + +#define RPSKINENGINEGETDATA(engineInstance) \ + ((_rpSkinLinkCallBack*)(((RwUInt8*)engineInstance) + _rpSkinGlobals.engineOffset)) + +#define RPSKINENGINEGETCONSTDATA(engineInstance) \ + ((const _rpSkinLinkCallBack*)(((const RwUInt8*)engineInstance) + _rpSkinGlobals.engineOffset)) + +#define RPSKINATOMICGETDATA(atomicInstance) \ + ((SkinAtomicData*)(((RwUInt8*)atomicInstance) + _rpSkinGlobals.atomicOffset)) + +#define RPSKINATOMICGETCONSTDATA(atomicInstance) \ + ((const SkinAtomicData*)(((const RwUInt8*)atomicInstance) + _rpSkinGlobals.atomicOffset)) + +#define RPSKINGEOMETRYGETDATA(geometryInstance) \ + ((RpSkin**)(((RwUInt8*)geometryInstance) + _rpSkinGlobals.geometryOffset)) + +#define RPSKINGEOMETRYGETCONSTDATA(geometryInstance) \ + ((const RpSkin* const*)(((const RwUInt8*)geometryInstance) + _rpSkinGlobals.geometryOffset)) + +#ifdef __cplusplus +extern "C" { +#endif + +extern RwBool _rpSkinPipelinesCreate(RwUInt32 pipes); + +extern RwBool _rpSkinPipelinesDestroy(void); + +extern RpAtomic* _rpSkinPipelinesAttach(RpAtomic* atomic, RpSkinType type); + +extern RwMatrix* _rpSkinGetAlignedMatrixCache(void); + +extern RwInt32 _rpSkinGeometryNativeSize(const RpGeometry* geometry); + +extern RwStream* _rpSkinGeometryNativeWrite(RwStream* stream, const RpGeometry* geometry); + +extern RwStream* _rpSkinGeometryNativeRead(RwStream* stream, RpGeometry* geometry); + +#ifdef SKIN_ATOMIC_PLATFORM_STREAM_SIZE +extern RwInt32 _rpSkinAtomicNativeSize(const RpAtomic* atomic); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/rwsdk/plugin/userdata/rpusrdat.c b/src/rwsdk/plugin/userdata/rpusrdat.c new file mode 100644 index 000000000..0fc97b112 --- /dev/null +++ b/src/rwsdk/plugin/userdata/rpusrdat.c @@ -0,0 +1,181 @@ +#include + +static RwInt32 userDataGeometryOffset = 0; +static RwInt32 userDataGeometryStreamOffset = 0; +static RwInt32 userDataWorldSectorOffset = 0; +static RwInt32 userDataWorldSectorStreamOffset = 0; +static RwInt32 userDataFrameOffset = 0; +static RwInt32 userDataFrameStreamOffset = 0; +static RwInt32 userDataCameraOffset = 0; +static RwInt32 userDataCameraStreamOffset = 0; +static RwInt32 userDataLightOffset = 0; +static RwInt32 userDataLightStreamOffset = 0; +static RwInt32 userDataMaterialOffset = 0; +static RwInt32 userDataMaterialStreamOffset = 0; +static RwInt32 userDataTextureOffset = 0; +static RwInt32 userDataTextureStreamOffset = 0; + +RwModuleInfo userDataModule; + +#define rwPLUGIN_ID rwID_USERDATAPLUGIN +#define rwPLUGIN_ERRFUNC _rwdb_CriterionUserData +#define rwPLUGIN_ERRENUM e_rwdb_CriterionUserData +#define rwPLUGIN_ERRENUMLAST e_rwdb_CriterionUserDataLAST + +typedef struct RpUserDataList RpUserDataList; + +struct RpUserDataList +{ + RwInt32 numElements; + RpUserDataArray* userData; +}; + +// Not continuing this file because RwMalloc could be wrong +// Will return when more info is available + +static void* UserDataOpen(void* instance, RwInt32 offset, RwInt32 size) +{ + userDataModule.numInstances++; + + return instance; +} + +static void* UserDataClose(void* instance, RwInt32 offset, RwInt32 size) +{ + userDataModule.numInstances--; + + return instance; +} + +static RwStream* UserDataStreamRead(RpUserDataArray* userData, RwStream* stream) +{ + RwInt32 i, length; + RwInt32* intData; + RwReal* realData; + RwChar** charData; + + if (!RwStreamReadInt32(stream, &length, sizeof(RwInt32))) + { + return NULL; + } + + if (length > 0) + { + if (userData->name == NULL) + { + return NULL; + } + + if (!RwStreamRead(stream, userData->name, sizeof(RwChar) * length)) + { + return NULL; + } + } + + if (!RwStreamReadInt32(stream, (RwInt32*)&userData->format, sizeof(RwInt32))) + { + return NULL; + } + + if (!RwStreamReadInt32(stream, &userData->numElements, sizeof(RwInt32))) + { + return NULL; + } + + switch (userData->format) + { + case rpINTUSERDATA: + + if (userData->data == NULL) + { + return NULL; + } + + intData = (RwInt32*)userData->data; + + if (!RwStreamReadInt32(stream, intData, sizeof(RwInt32) * userData->numElements)) + { + return NULL; + } + break; + case rpREALUSERDATA: + + if (userData->data == NULL) + { + return NULL; + } + + realData = (RwReal*)userData->data; + + if (!RwStreamReadReal(stream, realData, sizeof(RwReal) * userData->numElements)) + { + return NULL; + } + break; + case rpSTRINGUSERDATA: + + if (userData->data == NULL) + { + return NULL; + } + + charData = (RwChar**)userData->data; + + for (i = 0; i < userData->numElements; i++) + { + if (!RwStreamReadInt32(stream, &length, sizeof(RwInt32))) + { + return NULL; + } + + if (length > 0) + { + if (charData[i] == NULL) + { + return NULL; + } + + if (!RwStreamRead(stream, charData[i], sizeof(RwChar) * length)) + { + return NULL; + } + } + else + { + charData[i] = (RwChar*)NULL; + } + } + break; + default: + return NULL; + break; + } + + return stream; +} + +static void* UserDataObjectConstruct(void* object, RwInt32 offset, RwInt32 size) +{ +} + +static void* UserDataObjectCopy(void* destinationObject, const void* sourceObject, RwInt32 offset, + RwInt32 size) +{ + RpUserDataList* dstUserDataList = 0; + const RpUserDataList* srcUserDataList = 0; + + UserDataListCopy(dstUserDataList, srcUserDataList); + + return destinationObject; +} + +RwInt32 RpGeometryAddUserDataArray(RpGeometry* geometry, RwChar* name, RpUserDataFormat format, + RwInt32 numElements) +{ + RwInt32 index; + RpUserDataList* userDataList = 0; + + index = UserDataListAddElement(userDataList, name, format, numElements); + + return index; +} diff --git a/src/rwsdk/plugin/userdata/rpusrdat.h b/src/rwsdk/plugin/userdata/rpusrdat.h new file mode 100644 index 000000000..ecf0bed79 --- /dev/null +++ b/src/rwsdk/plugin/userdata/rpusrdat.h @@ -0,0 +1,93 @@ +#ifndef RPUSERDATAPLUGIN_H +#define RPUSERDATAPLUGIN_H + +#include +#include + +enum RpUserDataFormat +{ + rpNAUSERDATAFORMAT = 0, + rpINTUSERDATA, + rpREALUSERDATA, + rpSTRINGUSERDATA, + rpUSERDATAFORCEENUMSIZEINT = RWFORCEENUMSIZEINT +}; +typedef enum RpUserDataFormat RpUserDataFormat; + +typedef struct RpUserDataArray RpUserDataArray; + +struct RpUserDataArray +{ + RwChar* name; + RpUserDataFormat format; + RwInt32 numElements; + void* data; +}; + +#ifdef __cplusplus +extern "C" { +#endif + +extern RwBool RpUserDataPluginAttach(void); + +extern RwInt32 RpGeometryAddUserDataArray(RpGeometry* geometry, RwChar* name, + RpUserDataFormat format, RwInt32 numElements); +extern RpGeometry* RpGeometryRemoveUserDataArray(RpGeometry* geometry, RwInt32 index); +extern RpUserDataArray* RpGeometryGetUserDataArray(const RpGeometry* geometry, RwInt32 data); +extern RwInt32 RpGeometryGetUserDataArrayCount(const RpGeometry* geometry); + +extern RwInt32 RpWorldSectorAddUserDataArray(RpWorldSector* sector, RwChar* name, + RpUserDataFormat format, RwInt32 numElements); +extern RpWorldSector* RpWorldSectorRemoveUserDataArray(RpWorldSector* sector, RwInt32 index); +extern RpUserDataArray* RpWorldSectorGetUserDataArray(const RpWorldSector* sector, RwInt32 data); +extern RwInt32 RpWorldSectorGetUserDataArrayCount(const RpWorldSector* sector); + +extern RwInt32 RwFrameAddUserDataArray(RwFrame* frame, RwChar* name, RpUserDataFormat format, + RwInt32 numElements); +extern RwFrame* RwFrameRemoveUserDataArray(RwFrame* frame, RwInt32 index); +extern RpUserDataArray* RwFrameGetUserDataArray(const RwFrame* frame, RwInt32 data); +extern RwInt32 RwFrameGetUserDataArrayCount(const RwFrame* frame); + +extern RwInt32 RwCameraAddUserDataArray(RwCamera* camera, RwChar* name, RpUserDataFormat format, + RwInt32 numElements); +extern RwCamera* RwCameraRemoveUserDataArray(RwCamera* camera, RwInt32 index); +extern RpUserDataArray* RwCameraGetUserDataArray(const RwCamera* camera, RwInt32 data); +extern RwInt32 RwCameraGetUserDataArrayCount(const RwCamera* camera); + +extern RwInt32 RpLightAddUserDataArray(RpLight* light, RwChar* name, RpUserDataFormat format, + RwInt32 numElements); +extern RpLight* RpLightRemoveUserDataArray(RpLight* light, RwInt32 index); +extern RpUserDataArray* RpLightGetUserDataArray(const RpLight* light, RwInt32 data); +extern RwInt32 RpLightGetUserDataArrayCount(const RpLight* light); + +extern RwInt32 RpMaterialAddUserDataArray(RpMaterial* material, RwChar* name, + RpUserDataFormat format, RwInt32 numElements); +extern RpMaterial* RpMaterialRemoveUserDataArray(RpMaterial* material, RwInt32 index); +extern RpUserDataArray* RpMaterialGetUserDataArray(const RpMaterial* material, RwInt32 data); +extern RwInt32 RpMaterialGetUserDataArrayCount(const RpMaterial* material); + +extern RwInt32 RwTextureAddUserDataArray(RwTexture* texture, RwChar* name, RpUserDataFormat format, + RwInt32 numElements); +extern RwTexture* RwTextureRemoveUserDataArray(RwTexture* texture, RwInt32 index); +extern RpUserDataArray* RwTextureGetUserDataArray(const RwTexture* texture, RwInt32 data); +extern RwInt32 RwTextureGetUserDataArrayCount(const RwTexture* texture); + +extern RwChar* RpUserDataArrayGetName(RpUserDataArray* userData); +extern RpUserDataFormat RpUserDataArrayGetFormat(RpUserDataArray* userData); +extern RwInt32 RpUserDataArrayGetNumElements(RpUserDataArray* userData); + +extern RwInt32 RpUserDataArrayGetInt(RpUserDataArray* userData, RwInt32 index); +extern RwReal RpUserDataArrayGetReal(RpUserDataArray* userData, RwInt32 index); +extern RwChar* RpUserDataArrayGetString(RpUserDataArray* userData, RwInt32 index); + +extern void RpUserDataArraySetInt(RpUserDataArray* userData, RwInt32 index, RwInt32 value); +extern void RpUserDataArraySetReal(RpUserDataArray* userData, RwInt32 index, RwReal value); +extern void RpUserDataArraySetString(RpUserDataArray* userData, RwInt32 index, RwChar* value); + +extern RwInt32 RpUserDataGetFormatSize(RpUserDataFormat format); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/rwsdk/src/babbox.c b/src/rwsdk/src/babbox.c new file mode 100644 index 000000000..a924ad78c --- /dev/null +++ b/src/rwsdk/src/babbox.c @@ -0,0 +1,14 @@ +#include "rwplcore.h" +#include "rwcore.h" + +RwBBox* RwBBoxCalculate(RwBBox* boundBox, const RwV3d* verts, RwInt32 numVerts) +{ +} + +RwBBox* RwBBoxInitialize(RwBBox* boundBox, const RwV3d* vertex) +{ +} + +RwBBox* RwBBoxAddPoint(RwBBox* boundBox, const RwV3d* vertex) +{ +} diff --git a/src/rwsdk/src/babincam.c b/src/rwsdk/src/babincam.c new file mode 100644 index 000000000..ee38944ef --- /dev/null +++ b/src/rwsdk/src/babincam.c @@ -0,0 +1,65 @@ +#include "rwplcore.h" +#include "rwcore.h" + +typedef struct rwStreamCamera RwCameraChunkInfo; +typedef struct rwStreamCamera rwStreamCamera; + +extern RwPluginRegistry cameraTKList; + +struct rwStreamCamera +{ + RwV2d viewWindow; + RwV2d viewOffset; + RwReal nearPlane, farPlane; + RwReal fogPlane; + RwUInt32 projection; +}; + +RwInt32 RwCameraRegisterPluginStream(RwUInt32 pluginID, RwPluginDataChunkReadCallBack readCB, + RwPluginDataChunkWriteCallBack writeCB, + RwPluginDataChunkGetSizeCallBack getSizeCB) +{ + _rwPluginRegistryAddPluginStream(&cameraTKList, pluginID, readCB, writeCB, getSizeCB); +} + +RwCamera* RwCameraStreamRead(RwStream* stream) +{ + RwCamera* camera; + rwStreamCamera cam; + RwUInt32 size, version; + + if (!RwStreamFindChunk(stream, rwID_STRUCT, &size, &version)) + { + RWRETURN((RwCamera*)NULL); + } + + if ((version >= rwLIBRARYBASEVERSION) && (version <= rwLIBRARYCURRENTVERSION)) + { + memset(&cam, 0, sizeof(cam)); + if (RwStreamRead(stream, &cam, size) != size) + { + RWRETURN((RwCamera*)NULL); + } + camera = RwCameraCreate(); + if (!camera) + { + RWRETURN((RwCamera*)NULL); + } + if (!_rwPluginRegistryReadDataChunks(&cameraTKList, stream, camera)) + { + RWRETURN((RwCamera*)NULL); + } + RwCameraSetViewWindow(camera, &cam.viewWindow); + RwCameraSetViewOffset(camera, &cam.viewOffset); + RwCameraSetNearClipPlane(camera, ((RwReal)cam.nearPlane)); + RwCameraSetFarClipPlane(camera, ((RwReal)cam.farPlane)); + RwCameraSetFogDistance(camera, ((RwReal)cam.fogPlane)); + RwCameraSetProjection(camera, (RwCameraProjection)cam.projection); + + RWRETURN(camera); + } + else + { + RWRETURN((RwCamera*)NULL); + } +} diff --git a/src/rwsdk/src/babinfrm.c b/src/rwsdk/src/babinfrm.c new file mode 100644 index 000000000..60c1170f0 --- /dev/null +++ b/src/rwsdk/src/babinfrm.c @@ -0,0 +1,34 @@ +#include "rwplcore.h" +#include "rwcore.h" + +extern RwPluginRegistry frameTKList; + +RwInt32 RwFrameRegisterPluginStream(RwUInt32 pluginID, RwPluginDataChunkReadCallBack readCB, + RwPluginDataChunkWriteCallBack writeCB, + RwPluginDataChunkGetSizeCallBack getSizeCB) +{ + _rwPluginRegistryAddPluginStream(&frameTKList, pluginID, readCB, writeCB, getSizeCB); +} + +RwBool _rwFrameListFindFrame(const rwFrameList* frameList, const RwFrame* frame, RwInt32* npIndex) +{ + // Something like this? + + int i; + for (i = 0; i < frameList->numFrames; i++) + { + if (frameList->frames[i] == frame) + { + (*npIndex) = i; + } + } +} + +rwFrameList* _rwFrameListDeinitialize(rwFrameList* frameList) +{ + if (frameList->numFrames) + { + RwFree(frameList->frames); + } + return frameList; +} diff --git a/src/rwsdk/src/babintex.c b/src/rwsdk/src/babintex.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/bacamera.c b/src/rwsdk/src/bacamera.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/badevice.c b/src/rwsdk/src/badevice.c new file mode 100644 index 000000000..3c3fe0012 --- /dev/null +++ b/src/rwsdk/src/badevice.c @@ -0,0 +1,28 @@ +#include "rwplcore.h" +#include "rwcore.h" + +extern RwPluginRegistry engineTKList; + +RwGlobals* RwEngineInstance; +RwInt32 engineInstancesOpened; + +RwInt32 _rwGetNumEngineInstances() +{ + return engineInstancesOpened; +} + +RwUInt32 RwEngineGetVersion() +{ + return 0x35000; +} + +RwInt32 RwEngineRegisterPlugin(RwInt32 size, RwUInt32 pluginID, RwPluginObjectConstructor initCB, + RwPluginObjectDestructor termCB) +{ + _rwPluginRegistryAddPlugin(&engineTKList, size, pluginID, initCB, termCB, 0x0); +} + +RwInt32 RwEngineGetPluginOffset(RwUInt32 pluginID) +{ + _rwPluginRegistryGetPluginOffset(&engineTKList, pluginID); +} diff --git a/src/rwsdk/src/baframe.c b/src/rwsdk/src/baframe.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/baimage.c b/src/rwsdk/src/baimage.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/baimras.c b/src/rwsdk/src/baimras.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/baraster.c b/src/rwsdk/src/baraster.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/baresamp.c b/src/rwsdk/src/baresamp.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/basync.c b/src/rwsdk/src/basync.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/batextur.c b/src/rwsdk/src/batextur.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/batypehf.c b/src/rwsdk/src/batypehf.c new file mode 100644 index 000000000..e3d38e5f9 --- /dev/null +++ b/src/rwsdk/src/batypehf.c @@ -0,0 +1,27 @@ +#include "rwplcore.h" +#include "rwcore.h" + +void _rwObjectHasFrameSetFrame(void* object, RwFrame* frame) +{ + RwObjectHasFrame* ohf = (RwObjectHasFrame*)object; + if (rwObjectGetParent(ohf)) + { + rwLinkListRemoveLLLink(&ohf->lFrame); + } + rwObjectSetParent(object, frame); + if (frame) + { + rwLinkListAddLLLink(&frame->objectList, &ohf->lFrame); + + RwFrameUpdateObjects(frame); + } +} + +void _rwObjectHasFrameReleaseFrame(void* object) +{ + RwObjectHasFrame* ohf = (RwObjectHasFrame*)object; + if (rwObjectGetParent(ohf)) + { + rwLinkListRemoveLLLink(&ohf->lFrame); + } +} diff --git a/src/rwsdk/src/pipe/p2/baim3d.c b/src/rwsdk/src/pipe/p2/baim3d.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/pipe/p2/bapipe.c b/src/rwsdk/src/pipe/p2/bapipe.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/pipe/p2/gcn/im3dpipe.c b/src/rwsdk/src/pipe/p2/gcn/im3dpipe.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/pipe/p2/gcn/nodeDolphinSubmitNoLight.c b/src/rwsdk/src/pipe/p2/gcn/nodeDolphinSubmitNoLight.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/pipe/p2/p2altmdl.c b/src/rwsdk/src/pipe/p2/p2altmdl.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/pipe/p2/p2core.c b/src/rwsdk/src/pipe/p2/p2core.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/pipe/p2/p2define.c b/src/rwsdk/src/pipe/p2/p2define.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/pipe/p2/p2dep.c b/src/rwsdk/src/pipe/p2/p2dep.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/pipe/p2/p2heap.c b/src/rwsdk/src/pipe/p2/p2heap.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/pipe/p2/p2renderstate.c b/src/rwsdk/src/pipe/p2/p2renderstate.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/pipe/p2/p2resort.c b/src/rwsdk/src/pipe/p2/p2resort.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/babinary.c b/src/rwsdk/src/plcore/babinary.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/bacolor.c b/src/rwsdk/src/plcore/bacolor.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/baerr.c b/src/rwsdk/src/plcore/baerr.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/bafsys.c b/src/rwsdk/src/plcore/bafsys.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/baimmedi.c b/src/rwsdk/src/plcore/baimmedi.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/bamatrix.c b/src/rwsdk/src/plcore/bamatrix.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/bamemory.c b/src/rwsdk/src/plcore/bamemory.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/baresour.c b/src/rwsdk/src/plcore/baresour.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/bastream.c b/src/rwsdk/src/plcore/bastream.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/batkbin.c b/src/rwsdk/src/plcore/batkbin.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/batkreg.c b/src/rwsdk/src/plcore/batkreg.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/bavector.c b/src/rwsdk/src/plcore/bavector.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/resmem.c b/src/rwsdk/src/plcore/resmem.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/src/plcore/rwstring.c b/src/rwsdk/src/plcore/rwstring.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/tool/anim/rtanim.c b/src/rwsdk/tool/anim/rtanim.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/tool/intsec/rtintsec.c b/src/rwsdk/tool/intsec/rtintsec.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/babinwor.c b/src/rwsdk/world/babinwor.c new file mode 100644 index 000000000..8712086cd --- /dev/null +++ b/src/rwsdk/world/babinwor.c @@ -0,0 +1,67 @@ +#include + +#if !(rwLIBRARYVERSION36002 < rwLIBRARYBASEVERSION) +typedef struct rpPolygon rpPolygon; +struct rpPolygon +{ + RwUInt16 matIndex; + RwUInt16 vertIndex[3]; +}; +#endif + +#define RWSTREAMTYPE(_type) \ + ((rwNASTREAM == (_type)) ? \ + "rwNASTREAM" : \ + ((rwSTREAMFILE == (_type)) ? \ + "rwSTREAMFILE" : \ + ((rwSTREAMFILENAME == (_type)) ? \ + "rwSTREAMFILENAME" : \ + ((rwSTREAMMEMORY == (_type)) ? "rwSTREAMMEMORY" : "Unknown")))) + +#define WorldFormatGetNumTexCoordSetsMacro(_fmt) \ + (((_fmt)&0xff0000) ? \ + (((_fmt)&0xff0000) >> 16) : \ + (((_fmt)&rpGEOMETRYTEXTURED2) ? 2 : (((_fmt)&rpGEOMETRYTEXTURED) ? 1 : 0))) + +#define WorldFormatGetFlagsMacro(_fmt) ((_fmt)&0xff) + +static RwModuleInfo binWorldModule; + +static RwUInt32 lastSeenWorldRightsPluginId; +static RwUInt32 lastSeenWorldExtraData; + +RwStream* _rpReadWorldRights(RwStream* s, RwInt32 len, void* obj, RwInt32 off, RwInt32 size) +{ + if (!RwStreamReadInt32(s, (RwInt32*)&(lastSeenWorldRightsPluginId), sizeof(RwInt32))) + { + return NULL; + } + if (len == 8) + { + if (!RwStreamReadInt32(s, (RwInt32*)&(lastSeenWorldExtraData), sizeof(RwInt32))) + { + return NULL; + } + } + return s; +} + +RwStream* _rpWriteWorldRights(RwStream* s, RwInt32 len, const void* obj, RwInt32 off, RwInt32 size) +{ + // How does this instruction order even + // become out of order like this? + const RpWorld* wrl; + + wrl = (const RpWorld*)obj; + + if (!RwStreamWriteInt32(s, (RwInt32*)&(wrl->pipeline->pluginId), sizeof(RwInt32))) + { + return NULL; + } + if (!RwStreamWriteInt32(s, (RwInt32*)&(wrl->pipeline->pluginData), sizeof(RwInt32))) + { + return NULL; + } + + return s; +} diff --git a/src/rwsdk/world/babinwor.h b/src/rwsdk/world/babinwor.h new file mode 100644 index 000000000..e2a339130 --- /dev/null +++ b/src/rwsdk/world/babinwor.h @@ -0,0 +1,119 @@ + + +#ifndef RWBINWOR_H +#define RWBINWOR_H + +#include +#include + +typedef struct RpWorldChunkInfoSector RpWorldSectorChunkInfo; +typedef struct RpWorldChunkInfoSector _rpWorldSector; + +#if (!defined(DOXYGEN)) +struct RpWorldChunkInfoSector +{ + RwInt32 matListWindowBase; + RwInt32 numTriangles; + RwInt32 numVertices; + RwV3d inf; + RwV3d sup; + RwBool collSectorPresent; + RwBool unused; +}; + +typedef struct RpPlaneSectorChunkInfo RpPlaneSectorChunkInfo; +typedef struct RpPlaneSectorChunkInfo _rpPlaneSector; + +struct RpPlaneSectorChunkInfo +{ + RwInt32 type; + RwReal value; + RwBool leftIsWorldSector; + RwBool rightIsWorldSector; + RwReal leftValue; + RwReal rightValue; +}; + +typedef struct RpWorldChunkInfo RpWorldChunkInfo; +typedef struct RpWorldChunkInfo _rpWorld; + +struct RpWorldChunkInfo +{ + RwBool rootIsWorldSector; + + RwV3d invWorldOrigin; + + RwInt32 numTriangles; + RwInt32 numVertices; + RwInt32 numPlaneSectors; + RwInt32 numWorldSectors; + RwInt32 colSectorSize; + + RwInt32 format; + + RwBBox boundingBox; +}; + +typedef struct rpWorldChunkInfo34000 rpWorldChunkInfo34000; + +struct rpWorldChunkInfo34000 +{ + RwBool rootIsWorldSector; + + RwV3d invWorldOrigin; + + RwSurfaceProperties surfaceProps; + + RwInt32 numTriangles; + RwInt32 numVertices; + RwInt32 numPlaneSectors; + RwInt32 numWorldSectors; + RwInt32 colSectorSize; + + RwInt32 format; +}; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +extern void* _rpBinaryWorldOpen(void* instance, RwInt32 offset, RwInt32 size); +extern void* _rpBinaryWorldClose(void* instance, RwInt32 offset, RwInt32 size); + +extern RwStream* _rpReadWorldRights(RwStream* s, RwInt32 len, void* obj, RwInt32 off, RwInt32 size); +extern RwStream* _rpWriteWorldRights(RwStream* s, RwInt32 len, const void* obj, RwInt32 off, + RwInt32 size); +extern RwInt32 _rpSizeWorldRights(const void* obj, RwInt32 off, RwInt32 size); + +extern RwStream* _rpReadSectRights(RwStream* s, RwInt32 len, void* obj, RwInt32 off, RwInt32 size); +extern RwStream* _rpWriteSectRights(RwStream* s, RwInt32 len, const void* obj, RwInt32 off, + RwInt32 size); +extern RwInt32 _rpSizeSectRights(const void* obj, RwInt32 off, RwInt32 size); + +extern RwUInt32 RpWorldStreamGetSize(const RpWorld* world); +extern RpWorld* RpWorldStreamRead(RwStream* stream); +extern const RpWorld* RpWorldStreamWrite(const RpWorld* world, RwStream* stream); +extern RpWorldSectorChunkInfo* +_rpWorldSectorChunkInfoRead(RwStream* stream, RpWorldSectorChunkInfo* worldSectorChunkInfo, + RwInt32* bytesRead); +extern RpPlaneSectorChunkInfo* +_rpPlaneSectorChunkInfoRead(RwStream* stream, RpPlaneSectorChunkInfo* planeSectorChunkInfo, + RwInt32* bytesRead); +extern RpWorldChunkInfo* _rpWorldChunkInfoRead(RwStream* stream, RpWorldChunkInfo* worldChunkInfo, + RwInt32* bytesRead); + +#ifdef __cplusplus +} +#endif + +#define RpWorldSectorChunkInfoRead(stream, worldSectorChunkInfo, bytesRead) \ + _rpWorldSectorChunkInfoRead(stream, worldSectorChunkInfo, bytesRead) + +#define RpPlaneSectorChunkInfoRead(stream, planeSectorChunkInfo, bytesRead) \ + _rpPlaneSectorChunkInfoRead(stream, planeSectorChunkInfo, bytesRead) + +#define RpWorldChunkInfoRead(stream, worldChunkInfo, bytesRead) \ + _rpWorldChunkInfoRead(stream, worldChunkInfo, bytesRead) + +#endif diff --git a/src/rwsdk/world/baclump.c b/src/rwsdk/world/baclump.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/bageomet.c b/src/rwsdk/world/bageomet.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/balight.c b/src/rwsdk/world/balight.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/bamateri.c b/src/rwsdk/world/bamateri.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/bamatlst.c b/src/rwsdk/world/bamatlst.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/bamesh.c b/src/rwsdk/world/bamesh.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/bameshop.c b/src/rwsdk/world/bameshop.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/basector.c b/src/rwsdk/world/basector.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/baworld.c b/src/rwsdk/world/baworld.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/baworobj.c b/src/rwsdk/world/baworobj.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/bapipew.c b/src/rwsdk/world/pipe/p2/bapipew.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/gclights.c b/src/rwsdk/world/pipe/p2/gcn/gclights.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/gcmorph.c b/src/rwsdk/world/pipe/p2/gcn/gcmorph.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/gcpipe.c b/src/rwsdk/world/pipe/p2/gcn/gcpipe.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/instance/geomcond.c b/src/rwsdk/world/pipe/p2/gcn/instance/geomcond.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/instance/geominst.c b/src/rwsdk/world/pipe/p2/gcn/instance/geominst.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/instance/ibuffer.c b/src/rwsdk/world/pipe/p2/gcn/instance/ibuffer.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/instance/instancegeom.c b/src/rwsdk/world/pipe/p2/gcn/instance/instancegeom.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/instance/instanceworld.c b/src/rwsdk/world/pipe/p2/gcn/instance/instanceworld.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/instance/itools.c b/src/rwsdk/world/pipe/p2/gcn/instance/itools.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/instance/vbuffer.c b/src/rwsdk/world/pipe/p2/gcn/instance/vbuffer.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/instance/vtools.c b/src/rwsdk/world/pipe/p2/gcn/instance/vtools.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/instance/vtxdesc.c b/src/rwsdk/world/pipe/p2/gcn/instance/vtxdesc.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/native.c b/src/rwsdk/world/pipe/p2/gcn/native.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/nodeGameCubeAtomicAllInOne.c b/src/rwsdk/world/pipe/p2/gcn/nodeGameCubeAtomicAllInOne.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/nodeGameCubeWorldSectorAllInOne.c b/src/rwsdk/world/pipe/p2/gcn/nodeGameCubeWorldSectorAllInOne.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/setup.c b/src/rwsdk/world/pipe/p2/gcn/setup.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/vtxfmt.c b/src/rwsdk/world/pipe/p2/gcn/vtxfmt.c new file mode 100644 index 000000000..e69de29bb diff --git a/src/rwsdk/world/pipe/p2/gcn/wrldpipe.c b/src/rwsdk/world/pipe/p2/gcn/wrldpipe.c new file mode 100644 index 000000000..e69de29bb