summaryrefslogtreecommitdiffstats
path: root/src/rw/RwHelper.cpp
diff options
context:
space:
mode:
authorSergeanur <s.anureev@yandex.ua>2020-04-26 21:03:15 +0200
committerSergeanur <s.anureev@yandex.ua>2020-04-26 21:03:15 +0200
commitf0890b11122291a22d6a65f349281cf1aed49bd0 (patch)
tree3b418b522c5fd097abac916693e59808ea4f5b4f /src/rw/RwHelper.cpp
parentMore japanese (diff)
parentRemove little hack (diff)
downloadre3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar
re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.gz
re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.bz2
re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.lz
re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.xz
re3-f0890b11122291a22d6a65f349281cf1aed49bd0.tar.zst
re3-f0890b11122291a22d6a65f349281cf1aed49bd0.zip
Diffstat (limited to 'src/rw/RwHelper.cpp')
-rw-r--r--src/rw/RwHelper.cpp233
1 files changed, 215 insertions, 18 deletions
diff --git a/src/rw/RwHelper.cpp b/src/rw/RwHelper.cpp
index 44ca3a0a..ed618dd8 100644
--- a/src/rw/RwHelper.cpp
+++ b/src/rw/RwHelper.cpp
@@ -1,43 +1,55 @@
+#if defined RW_D3D9 || defined RWLIBS
#define WITHD3D
+#endif
#include "common.h"
-#include "patcher.h"
+
#include "Timecycle.h"
#include "skeleton.h"
-#if defined(RWLIBS) && !defined(FINAL)
+#include "Debug.h"
+#ifndef FINAL
#include "rtcharse.h"
-#pragma comment( lib, "rtcharse.lib" )
-
RtCharset *debugCharset;
#endif
+bool gPS2alphaTest = 1;
+
+static bool charsetOpen;
+void OpenCharsetSafe()
+{
+ if(!charsetOpen)
+ RtCharsetOpen();
+ charsetOpen = true;
+}
+
void CreateDebugFont()
{
-#if defined(RWLIBS) && !defined(FINAL)
+#ifndef FINAL
RwRGBA color = { 255, 255, 128, 255 };
RwRGBA colorbg = { 0, 0, 0, 0 };
- RtCharsetOpen();
+ OpenCharsetSafe();
debugCharset = RtCharsetCreate(&color, &colorbg);
#endif
}
void DestroyDebugFont()
{
-#if defined(RWLIBS) && !defined(FINAL)
+#ifndef FINAL
RtCharsetDestroy(debugCharset);
RtCharsetClose();
+ charsetOpen = false;
#endif
}
void ObrsPrintfString(const char *str, short x, short y)
{
-#if defined(RWLIBS) && !defined(FINAL)
- RtCharsetPrintBuffered(debugCharset, str, x, y, true);
+#ifndef FINAL
+ RtCharsetPrintBuffered(debugCharset, str, x*8, y*16, true);
#endif
}
void FlushObrsPrintfs()
{
-#if defined(RWLIBS) && !defined(FINAL)
+#ifndef FINAL
RtCharsetBufferFlush();
#endif
}
@@ -90,9 +102,16 @@ DefinedState(void)
RwRenderStateSet(rwRENDERSTATEFOGTYPE, (void*)rwFOGTYPELINEAR);
RwRenderStateSet(rwRENDERSTATECULLMODE, (void*)rwCULLMODECULLNONE);
+#ifdef LIBRW
+ rw::SetRenderState(rw::ALPHATESTFUNC, rw::ALPHAGREATEREQUAL);
+ rw::SetRenderState(rw::ALPHATESTREF, 3);
+
+ rw::SetRenderState(rw::GSALPHATEST, gPS2alphaTest);
+#else
// D3D stuff
RwD3D8SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
RwD3D8SetRenderState(D3DRS_ALPHAREF, 2);
+#endif
}
RwFrame*
@@ -163,6 +182,190 @@ GetFirstTexture(RwTexDictionary *txd)
return tex;
}
+#ifdef PED_SKIN
+static RpAtomic*
+isSkinnedCb(RpAtomic *atomic, void *data)
+{
+ RpAtomic **pAtomic = (RpAtomic**)data;
+ if(*pAtomic)
+ return nil; // already found one
+ if(RpSkinGeometryGetSkin(atomic->geometry))
+ *pAtomic = atomic; // we could just return nil here directly...
+ return atomic;
+}
+
+RpAtomic*
+IsClumpSkinned(RpClump *clump)
+{
+ RpAtomic *atomic = nil;
+ RpClumpForAllAtomics(clump, isSkinnedCb, &atomic);
+ return atomic;
+}
+
+static RpAtomic*
+GetAnimHierarchyCallback(RpAtomic *atomic, void *data)
+{
+ *(RpHAnimHierarchy**)data = RpSkinAtomicGetHAnimHierarchy(atomic);
+ return nil;
+}
+
+RpHAnimHierarchy*
+GetAnimHierarchyFromSkinClump(RpClump *clump)
+{
+ RpHAnimHierarchy *hier = nil;
+ RpClumpForAllAtomics(clump, GetAnimHierarchyCallback, &hier);
+ return hier;
+}
+
+static RwFrame*
+GetAnimHierarchyFromClumpCB(RwFrame *frame, void *data)
+{
+ RpHAnimHierarchy *hier = RpHAnimFrameGetHierarchy(frame);
+ if(hier){
+ *(RpHAnimHierarchy**)data = hier;
+ return nil;
+ }
+ RwFrameForAllChildren(frame, GetAnimHierarchyFromClumpCB, data);
+ return frame;
+}
+
+RpHAnimHierarchy*
+GetAnimHierarchyFromClump(RpClump *clump)
+{
+ RpHAnimHierarchy *hier = nil;
+ RwFrameForAllChildren(RpClumpGetFrame(clump), GetAnimHierarchyFromClumpCB, &hier);
+ return hier;
+}
+
+RwFrame*
+GetHierarchyFromChildNodesCB(RwFrame *frame, void *data)
+{
+ RpHAnimHierarchy **pHier = (RpHAnimHierarchy**)data;
+ RpHAnimHierarchy *hier = RpHAnimFrameGetHierarchy(frame);
+ if(hier == nil)
+ RwFrameForAllChildren(frame, GetHierarchyFromChildNodesCB, &hier);
+ *pHier = hier;
+ return nil;
+}
+
+void
+SkinGetBonePositionsToTable(RpClump *clump, RwV3d *boneTable)
+{
+ int i, parent;
+ RpAtomic *atomic;
+ RpSkin *skin;
+ RpHAnimHierarchy *hier;
+ int numBones;
+ RwMatrix m, invmat;
+ int stack[32];
+ int sp;
+
+ if(boneTable == nil)
+ return;
+
+// atomic = GetFirstAtomic(clump); // mobile, also VC
+ atomic = IsClumpSkinned(clump); // xbox, seems safer
+ assert(atomic);
+ skin = RpSkinGeometryGetSkin(RpAtomicGetGeometry(atomic));
+ assert(skin);
+ hier = GetAnimHierarchyFromSkinClump(clump);
+ assert(hier);
+ boneTable[0].x = 0.0f;
+ boneTable[0].y = 0.0f;
+ boneTable[0].z = 0.0f;
+ numBones = RpSkinGetNumBones(skin);
+ parent = 0;
+ sp = 0;
+#ifdef FIX_BUGS
+ stack[0] = 0; // i think this is ok
+#endif
+ for(i = 1; i < numBones; i++){
+ RwMatrixCopy(&m, &RpSkinGetSkinToBoneMatrices(skin)[i]);
+ RwMatrixInvert(&invmat, &m);
+ const RwMatrix *x = RpSkinGetSkinToBoneMatrices(skin);
+ RwV3dTransformPoints(&boneTable[i], &invmat.pos, 1, &x[parent]);
+ if(HIERNODEINFO(hier)[i].flags & rpHANIMPUSHPARENTMATRIX)
+ stack[++sp] = parent;
+ if(HIERNODEINFO(hier)[i].flags & rpHANIMPOPPARENTMATRIX)
+ parent = stack[sp--];
+ else
+ parent = i;
+ assert(parent >= 0 && parent < numBones);
+ }
+}
+
+RpHAnimAnimation*
+HAnimAnimationCreateForHierarchy(RpHAnimHierarchy *hier)
+{
+ int i;
+#ifdef FIX_BUGS
+ int numNodes = hier->numNodes*2; // you're supposed to have at least two KFs per node
+#else
+ int numNodes = hier->numNodes;
+#endif
+ RpHAnimAnimation *anim = RpHAnimAnimationCreate(rpHANIMSTDKEYFRAMETYPEID, numNodes, 0, 0.0f);
+ if(anim == nil)
+ return nil;
+ RpHAnimStdKeyFrame *frame = (RpHAnimStdKeyFrame*)HANIMFRAMES(anim);
+ for(i = 0; i < numNodes; i++){
+ frame->q.real = 1.0f;
+ frame->q.imag.x = frame->q.imag.y = frame->q.imag.z = 0.0f;
+ frame->t.x = frame->t.y = frame->t.z = 0.0f;
+ frame->time = 0.0f;
+ frame->prevFrame = nil;
+ frame++;
+ }
+ return anim;
+}
+
+RpAtomic*
+AtomicRemoveAnimFromSkinCB(RpAtomic *atomic, void *data)
+{
+ if(RpSkinGeometryGetSkin(RpAtomicGetGeometry(atomic))){
+ RpHAnimHierarchy *hier = RpSkinAtomicGetHAnimHierarchy(atomic);
+#ifdef LIBRW
+ if(hier && hier->interpolator->currentAnim){
+ RpHAnimAnimationDestroy(hier->interpolator->currentAnim);
+ hier->interpolator->currentAnim = nil;
+ }
+#else
+ if(hier && hier->pCurrentAnim){
+ RpHAnimAnimationDestroy(hier->pCurrentAnim);
+ hier->pCurrentAnim = nil;
+ }
+#endif
+ }
+ return atomic;
+}
+
+void
+RenderSkeleton(RpHAnimHierarchy *hier)
+{
+ int i;
+ int sp;
+ int stack[32];
+ int par;
+ CVector p1, p2;
+ int numNodes = hier->numNodes;
+ RwMatrix *mats = RpHAnimHierarchyGetMatrixArray(hier);
+ p1 = mats[0].pos;
+
+ par = 0;
+ sp = 0;
+ stack[sp++] = par;
+ for(i = 1; i < numNodes; i++){
+ p1 = mats[par].pos;
+ p2 = mats[i].pos;
+ CDebug::AddLine(p1, p2, 0xFFFFFFFF, 0xFFFFFFFF);
+ if(HIERNODEINFO(hier)[i].flags & rpHANIMPUSHPARENTMATRIX)
+ stack[sp++] = par;
+ par = i;
+ if(HIERNODEINFO(hier)[i].flags & rpHANIMPOPPARENTMATRIX)
+ par = stack[--sp];
+ }
+}
+#endif
+
void
CameraSize(RwCamera * camera, RwRect * rect,
RwReal viewWindow, RwReal aspectRatio)
@@ -385,13 +588,7 @@ CameraCreate(RwInt32 width, RwInt32 height, RwBool zBuffer)
return (nil);
}
+#ifdef USE_TEXTURE_POOL
WRAPPER void _TexturePoolsInitialise() { EAXJMP(0x598B10); }
WRAPPER void _TexturePoolsShutdown() { EAXJMP(0x598B30); }
-
-STARTPATCHES
- //InjectHook(0x526450, GetFirstObjectCallback, PATCH_JUMP);
- InjectHook(0x526460, GetFirstObject, PATCH_JUMP);
- InjectHook(0x527170, CameraSize, PATCH_JUMP);
- InjectHook(0x527340, CameraDestroy, PATCH_JUMP);
- InjectHook(0x5273B0, CameraCreate, PATCH_JUMP);
-ENDPATCHES
+#endif