implemented CutsceneObject; little fixes

This commit is contained in:
aap 2019-06-12 21:17:02 +02:00
parent a9517c01af
commit 9703ef9b59
12 changed files with 137 additions and 12 deletions

View File

@ -289,7 +289,7 @@ CTimeCycle::Update(void)
TheCamera.SetMotionBlur(m_fCurrentBlurRed, m_fCurrentBlurGreen, m_fCurrentBlurBlue, m_fCurrentBlurAlpha, MBLUR_NORMAL);
if(m_FogReduction != 0)
m_fCurrentFarClip = max(m_fCurrentFarClip, m_FogReduction/64 * 650.0f);
m_fCurrentFarClip = max(m_fCurrentFarClip, m_FogReduction/64.0f * 650.0f);
m_nCurrentFogColourRed = (m_nCurrentSkyTopRed + 2*m_nCurrentSkyBottomRed) / 3;
m_nCurrentFogColourGreen = (m_nCurrentSkyTopGreen + 2*m_nCurrentSkyBottomGreen) / 3;
m_nCurrentFogColourBlue = (m_nCurrentSkyTopBlue + 2*m_nCurrentSkyBottomBlue) / 3;

View File

@ -9,7 +9,7 @@
CAnimBlendClumpData::CAnimBlendClumpData(void)
{
numFrames = 0;
pedPosition = nil;
velocity = nil;
frames = nil;
link.Init();
}

View File

@ -38,7 +38,7 @@ public:
#ifdef PED_SKIN
int32 modelNumber; // doesn't seem to be used
#endif
CVector *pedPosition;
CVector *velocity;
// order of frames is determined by RW hierarchy
AnimBlendFrameData *frames;

View File

@ -23,7 +23,7 @@ FrameUpdateCallBack(AnimBlendFrameData *frame, void *arg)
AnimBlendFrameUpdateData *updateData = (AnimBlendFrameUpdateData*)arg;
if(frame->flag & AnimBlendFrameData::VELOCITY_EXTRACTION &&
gpAnimBlendClump->pedPosition){
gpAnimBlendClump->velocity){
if(frame->flag & AnimBlendFrameData::VELOCITY_EXTRACTION_3D)
FrameUpdateCallBackWith3dVelocityExtraction(frame, arg);
else
@ -132,11 +132,11 @@ FrameUpdateCallBackWithVelocityExtraction(AnimBlendFrameData *frame, void *arg)
}
if((frame->flag & AnimBlendFrameData::IGNORE_TRANSLATION) == 0){
gpAnimBlendClump->pedPosition->x = transx - curx;
gpAnimBlendClump->pedPosition->y = transy - cury;
gpAnimBlendClump->velocity->x = transx - curx;
gpAnimBlendClump->velocity->y = transy - cury;
if(looped){
gpAnimBlendClump->pedPosition->x += endx;
gpAnimBlendClump->pedPosition->y += endy;
gpAnimBlendClump->velocity->x += endx;
gpAnimBlendClump->velocity->y += endy;
}
mat->pos.x = pos.x - transx;
mat->pos.y = pos.y - transy;
@ -211,9 +211,9 @@ FrameUpdateCallBackWith3dVelocityExtraction(AnimBlendFrameData *frame, void *arg
}
if((frame->flag & AnimBlendFrameData::IGNORE_TRANSLATION) == 0){
*gpAnimBlendClump->pedPosition = trans - cur;
*gpAnimBlendClump->velocity = trans - cur;
if(looped)
*gpAnimBlendClump->pedPosition += end;
*gpAnimBlendClump->velocity += end;
mat->pos.x = (pos - trans).x + frame->resetPos.x;
mat->pos.y = (pos - trans).y + frame->resetPos.y;
mat->pos.z = (pos - trans).z + frame->resetPos.z;

View File

@ -1,4 +1,13 @@
#include "common.h"
#include "patcher.h"
#include "lights.h"
#include "PointLights.h"
#include "RpAnimBlend.h"
#include "AnimBlendClumpData.h"
#include "Renderer.h"
#include "ModelIndices.h"
#include "Shadows.h"
#include "TimeCycle.h"
#include "CutsceneObject.h"
CCutsceneObject::CCutsceneObject(void)
@ -10,3 +19,80 @@ CCutsceneObject::CCutsceneObject(void)
m_fMass = 1.0f;
m_fTurnMass = 1.0f;
}
void
CCutsceneObject::SetModelIndex(uint32 id)
{
CEntity::SetModelIndex(id);
assert(RwObjectGetType(m_rwObject) == rpCLUMP);
RpAnimBlendClumpInit((RpClump*)m_rwObject);
(*RPANIMBLENDCLUMPDATA(m_rwObject))->velocity = &m_vecMoveSpeed;
(*RPANIMBLENDCLUMPDATA(m_rwObject))->frames[0].flag |= AnimBlendFrameData::VELOCITY_EXTRACTION_3D;
}
void
CCutsceneObject::ProcessControl(void)
{
CPhysical::ProcessControl();
if(CTimer::GetTimeStep() < 1/100.0f)
m_vecMoveSpeed *= 100.0f;
else
m_vecMoveSpeed *= 1.0f/CTimer::GetTimeStep();
ApplyMoveSpeed();
}
void
CCutsceneObject::PreRender(void)
{
if(IsPedModel(GetModelIndex()))
CShadows::StoreShadowForPedObject(this,
CTimeCycle::m_fShadowDisplacementX[CTimeCycle::m_CurrentStoredValue],
CTimeCycle::m_fShadowDisplacementY[CTimeCycle::m_CurrentStoredValue],
CTimeCycle::m_fShadowFrontX[CTimeCycle::m_CurrentStoredValue],
CTimeCycle::m_fShadowFrontY[CTimeCycle::m_CurrentStoredValue],
CTimeCycle::m_fShadowSideX[CTimeCycle::m_CurrentStoredValue],
CTimeCycle::m_fShadowSideY[CTimeCycle::m_CurrentStoredValue]);
}
void
CCutsceneObject::Render(void)
{
CObject::Render();
}
bool
CCutsceneObject::SetupLighting(void)
{
ActivateDirectional();
SetAmbientColoursForPedsCarsAndObjects();
if(bRenderScorched){
WorldReplaceNormalLightsWithScorched(Scene.world, 0.1f);
}else{
CVector coors = GetPosition();
float lighting = CPointLights::GenerateLightsAffectingObject(&coors);
if(!m_flagB20 && lighting != 1.0f){
SetAmbientAndDirectionalColours(lighting);
return true;
}
}
return false;
}
void
CCutsceneObject::RemoveLighting(bool reset)
{
CRenderer::RemoveVehiclePedLights(this, reset);
}
STARTPATCHES
InjectHook(0x4BA980, &CCutsceneObject::SetModelIndex_, PATCH_JUMP);
InjectHook(0x4BA9C0, &CCutsceneObject::ProcessControl_, PATCH_JUMP);
InjectHook(0x4BAA40, &CCutsceneObject::PreRender_, PATCH_JUMP);
InjectHook(0x4BAAA0, &CCutsceneObject::Render_, PATCH_JUMP);
InjectHook(0x4A7E70, &CCutsceneObject::SetupLighting_, PATCH_JUMP);
InjectHook(0x4A7F00, &CCutsceneObject::RemoveLighting_, PATCH_JUMP);
ENDPATCHES

View File

@ -6,5 +6,20 @@ class CCutsceneObject : public CObject
{
public:
CCutsceneObject(void);
void SetModelIndex(uint32 id);
void ProcessControl(void);
void PreRender(void);
void Render(void);
bool SetupLighting(void);
void RemoveLighting(bool reset);
void SetModelIndex_(uint32 id) { CCutsceneObject::SetModelIndex(id); }
void ProcessControl_(void) { CCutsceneObject::ProcessControl(); }
void PreRender_(void) { CCutsceneObject::PreRender(); }
void Render_(void) { CCutsceneObject::Render(); }
bool SetupLighting_(void) { return CCutsceneObject::SetupLighting(); }
void RemoveLighting_(bool reset) { CCutsceneObject::RemoveLighting(reset); }
};
static_assert(sizeof(CCutsceneObject) == 0x198, "CCutsceneObject: error");

View File

@ -264,3 +264,9 @@ IsBoatModel(int16 id)
id == MI_SPEEDER ||
id == MI_GHOST;
}
inline bool
IsPedModel(int16 id)
{
return id >= 0 && id <= 89;
}

View File

@ -16,6 +16,7 @@
#include "ModelIndices.h"
#include "Streaming.h"
#include "Shadows.h"
#include "PointLights.h"
#include "Renderer.h"
bool gbShowPedRoadGroups;
@ -1153,6 +1154,16 @@ CRenderer::IsVehicleCullZoneVisible(CEntity *ent)
return true;
}
void
CRenderer::RemoveVehiclePedLights(CEntity *ent, bool reset)
{
if(ent->bRenderScorched)
WorldReplaceScorchedLightsWithNormal(Scene.world);
CPointLights::RemoveLightsAffectingObject();
if(reset)
ReSetAmbientAndDirectionalColours();
}
STARTPATCHES
InjectHook(0x4A7680, CRenderer::Init, PATCH_JUMP);
@ -1185,4 +1196,6 @@ STARTPATCHES
InjectHook(0x4A9840, CRenderer::ShouldModelBeStreamed, PATCH_JUMP);
InjectHook(0x4AAA00, CRenderer::IsEntityCullZoneVisible, PATCH_JUMP);
InjectHook(0x4AAAA0, CRenderer::IsVehicleCullZoneVisible, PATCH_JUMP);
InjectHook(0x4A7CF0, CRenderer::RemoveVehiclePedLights, PATCH_JUMP);
ENDPATCHES

View File

@ -56,4 +56,6 @@ public:
static bool ShouldModelBeStreamed(CEntity *ent);
static bool IsEntityCullZoneVisible(CEntity *ent);
static bool IsVehicleCullZoneVisible(CEntity *ent);
static void RemoveVehiclePedLights(CEntity *ent, bool reset);
};

View File

@ -6,4 +6,5 @@ WRAPPER void CShadows::AddPermanentShadow(unsigned char ShadowType, RwTexture* p
WRAPPER void CShadows::RenderStaticShadows(void) { EAXJMP(0x5145F0); }
WRAPPER void CShadows::RenderStoredShadows(void) { EAXJMP(0x514010); }
WRAPPER void CShadows::RenderExtraPlayerShadows(void) { EAXJMP(0x516F90); }
WRAPPER void CShadows::CalcPedShadowValues(CVector light, float *frontX, float *frontY, float *sideX, float *sideY, float *dispX, float *dispY) { EAXJMP(0x516EB0); }
WRAPPER void CShadows::CalcPedShadowValues(CVector light, float *frontX, float *frontY, float *sideX, float *sideY, float *dispX, float *dispY) { EAXJMP(0x516EB0); }
WRAPPER void CShadows::StoreShadowForPedObject(CEntity *ent, float dispX, float dispY, float frontX, float frontY, float sideX, float sideY) { EAXJMP(0x513CB0); }

View File

@ -1,6 +1,7 @@
#pragma once
struct RwTexture;
class CEntity;
class CShadows
{
@ -10,4 +11,5 @@ public:
static void RenderStoredShadows(void);
static void RenderExtraPlayerShadows(void);
static void CalcPedShadowValues(CVector light, float *frontX, float *frontY, float *sideX, float *sideY, float *dispX, float *dispY);
static void StoreShadowForPedObject(CEntity *ent, float dispX, float dispY, float frontX, float frontY, float sideX, float sideY);
};

View File

@ -145,7 +145,7 @@ CSprite2d::Draw(const CRect &rect, const CRGBA &c0, const CRGBA &c1, const CRGBA
void
CSprite2d::Draw(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const CRGBA &col)
{
SetVertices(x1, y2, x2, y2, x3, y3, x4, y4, col, col, col, col);
SetVertices(x1, y1, x2, y2, x3, y3, x4, y4, col, col, col, col);
SetRenderState();
RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4);
}