re3/src/core/AnimViewer.cpp

439 lines
12 KiB
C++
Raw Normal View History

2019-08-15 14:51:39 +00:00
#include "common.h"
2020-04-17 13:31:11 +00:00
2019-08-15 14:51:39 +00:00
#include "Font.h"
#include "Pad.h"
#include "Text.h"
#include "main.h"
#include "Timer.h"
#include "DMAudio.h"
#include "FileMgr.h"
#include "Streaming.h"
#include "TxdStore.h"
#include "General.h"
#include "Camera.h"
#include "Vehicle.h"
#include "Bike.h"
2019-08-15 14:51:39 +00:00
#include "PlayerSkin.h"
#include "PlayerInfo.h"
#include "World.h"
#include "Renderer.h"
#include "AnimManager.h"
2020-12-03 02:22:58 +00:00
#include "AnimBlendAssocGroup.h"
2019-08-15 14:51:39 +00:00
#include "AnimViewer.h"
#include "PlayerPed.h"
#include "Pools.h"
#include "References.h"
#include "PathFind.h"
#include "HandlingMgr.h"
#include "TempColModels.h"
#include "Particle.h"
#include "CdStream.h"
#include "Messages.h"
#include "CarCtrl.h"
#include "FileLoader.h"
#include "ModelIndices.h"
#include "Clock.h"
#include "Timecycle.h"
#include "RpAnimBlend.h"
2020-03-28 14:47:52 +00:00
#include "AnimBlendAssociation.h"
2019-08-15 14:51:39 +00:00
#include "Shadows.h"
#include "Radar.h"
#include "Hud.h"
2020-04-24 11:27:02 +00:00
#include "debugmenu.h"
2019-08-15 14:51:39 +00:00
int CAnimViewer::animTxdSlot = 0;
CEntity *CAnimViewer::pTarget = nil;
void
CAnimViewer::Render(void) {
2019-08-15 15:59:09 +00:00
if (pTarget) {
2019-08-15 14:51:39 +00:00
// pTarget->GetPosition() = CVector(0.0f, 0.0f, 0.0f);
2019-08-15 15:59:09 +00:00
if (pTarget) {
#ifdef FIX_BUGS
if(pTarget->IsPed())
((CPed*)pTarget)->UpdateRpHAnim();
#endif
2019-08-15 14:51:39 +00:00
pTarget->Render();
CRenderer::RenderOneNonRoad(pTarget);
}
}
}
void
CAnimViewer::Initialise(void) {
2020-12-03 02:22:58 +00:00
// we need messages, messages needs hud, hud needs those
2019-08-15 14:51:39 +00:00
int hudSlot = CTxdStore::AddTxdSlot("hud");
CTxdStore::LoadTxd(hudSlot, "MODELS/HUD.TXD");
2020-12-03 02:22:58 +00:00
CHud::m_Wants_To_Draw_Hud = false;
animTxdSlot = CTxdStore::AddTxdSlot("generic");
CTxdStore::Create(animTxdSlot);
2019-08-15 14:51:39 +00:00
int particleSlot = CTxdStore::AddTxdSlot("particle");
CTxdStore::LoadTxd(particleSlot, "MODELS/PARTICLE.TXD");
CTxdStore::SetCurrentTxd(animTxdSlot);
CPools::Initialise();
CReferences::Init();
TheCamera.Init();
TheCamera.SetRwCamera(Scene.camera);
TheCamera.Cams[TheCamera.ActiveCam].Distance = 5.0f;
2019-08-15 14:51:39 +00:00
ThePaths.Init();
ThePaths.AllocatePathFindInfoMem(4500);
CCollision::Init();
CWorld::Initialise();
mod_HandlingManager.Initialise();
CTempColModels::Initialise();
CAnimManager::Initialise();
CModelInfo::Initialise();
CParticle::Initialise();
CCarCtrl::Init();
CPedStats::Initialise();
CMessages::Init();
CdStreamAddImage("MODELS\\GTA3.IMG");
CFileLoader::LoadLevel("DATA\\DEFAULT.DAT");
2019-08-15 14:51:39 +00:00
CFileLoader::LoadLevel("DATA\\ANIMVIEWER.DAT");
CStreaming::Init();
for(int i = 0; i < MODELINFOSIZE; i++)
if(CModelInfo::GetModelInfo(i))
CModelInfo::GetModelInfo(i)->ConvertAnimFileIndex();
2019-08-15 14:51:39 +00:00
CStreaming::LoadInitialPeds();
CStreaming::RequestSpecialModel(MI_PLAYER, "player", STREAMFLAGS_DONT_REMOVE);
CStreaming::LoadAllRequestedModels(false);
CRenderer::Init();
CVehicleModelInfo::LoadVehicleColours();
2020-12-03 10:30:46 +00:00
#ifdef FIX_BUGS
CVehicleModelInfo::LoadEnvironmentMaps();
#endif
2019-08-15 14:51:39 +00:00
CAnimManager::LoadAnimFiles();
CWorld::PlayerInFocus = 0;
CWeapon::InitialiseWeapons();
CPed::Initialise();
CTimer::Initialise();
CClock::Initialise(60000);
CTimeCycle::Initialise();
CCarCtrl::Init();
CPlayerPed *player = new CPlayerPed();
2020-05-05 01:45:18 +00:00
player->SetPosition(0.0f, 0.0f, 0.0f);
2019-08-15 14:51:39 +00:00
CWorld::Players[0].m_pPed = player;
CDraw::SetFOV(120.0f);
CDraw::ms_fLODDistance = 500.0f;
int fd = CFileMgr::OpenFile("DATA\\SPECIAL.TXT", "r");
char animGroup[32], modelName[32];
2019-08-15 15:59:09 +00:00
if (fd) {
2019-08-15 14:51:39 +00:00
for (int lineId = 0; lineId < NUM_OF_SPECIAL_CHARS; lineId++) {
if (!CFileMgr::ReadLine(fd, gString, 255))
break;
2020-05-11 23:24:57 +00:00
sscanf(gString, "%s %s", modelName, animGroup);
2019-08-15 14:51:39 +00:00
int groupId;
2019-08-15 15:59:09 +00:00
for (groupId = 0; groupId < NUM_ANIM_ASSOC_GROUPS; groupId++) {
2019-08-15 14:51:39 +00:00
if (!strcmp(animGroup, CAnimManager::GetAnimGroupName((AssocGroupId)groupId)))
break;
}
if (groupId != NUM_ANIM_ASSOC_GROUPS)
((CPedModelInfo*)CModelInfo::GetModelInfo(MI_SPECIAL01 + lineId))->m_animGroup = groupId;
CStreaming::RequestSpecialChar(lineId, modelName, STREAMFLAGS_DONT_REMOVE);
}
CFileMgr::CloseFile(fd);
} else {
// TODO? maybe request some special models here so the thing doesn't crash
2019-08-15 14:51:39 +00:00
}
2020-12-03 02:22:58 +00:00
// From LCS. idk if needed
int vanBlock = CAnimManager::GetAnimationBlockIndex("van");
int bikesBlock = CAnimManager::GetAnimationBlockIndex("bikes");
int bikevBlock = CAnimManager::GetAnimationBlockIndex("bikev");
int bikehBlock = CAnimManager::GetAnimationBlockIndex("bikeh");
int bikedBlock = CAnimManager::GetAnimationBlockIndex("biked");
CStreaming::FlushRequestList();
CStreaming::RequestAnim(vanBlock, STREAMFLAGS_DEPENDENCY);
CStreaming::RequestAnim(bikesBlock, STREAMFLAGS_DEPENDENCY);
CStreaming::RequestAnim(bikevBlock, STREAMFLAGS_DEPENDENCY);
CStreaming::RequestAnim(bikehBlock, STREAMFLAGS_DEPENDENCY);
CStreaming::RequestAnim(bikedBlock, STREAMFLAGS_DEPENDENCY);
CStreaming::LoadAllRequestedModels(false);
CAnimManager::AddAnimBlockRef(vanBlock);
CAnimManager::AddAnimBlockRef(bikesBlock);
CAnimManager::AddAnimBlockRef(bikevBlock);
CAnimManager::AddAnimBlockRef(bikehBlock);
CAnimManager::AddAnimBlockRef(bikedBlock);
2019-08-15 14:51:39 +00:00
}
int
LastPedModelId(int modelId)
{
CBaseModelInfo *model;
for(;;){
assert(modelId < MODELINFOSIZE);
model = CModelInfo::GetModelInfo(modelId);
if (model && model->GetModelType() == MITYPE_PED)
break;
modelId--;
2019-08-15 14:51:39 +00:00
}
return modelId;
}
int
FirstCarModelId(int modelId)
2019-08-15 14:51:39 +00:00
{
CBaseModelInfo *model;
for(;;){
assert(modelId < MODELINFOSIZE);
model = CModelInfo::GetModelInfo(modelId);
if (model && model->GetModelType() == MITYPE_VEHICLE)
break;
modelId++;
2019-08-15 14:51:39 +00:00
}
return modelId;
}
int
NextModelId(int modelId, int wantedChange)
2019-08-15 14:51:39 +00:00
{
// Max. 2 trials wasn't here, it's me that added it.
int tryCount = 2;
int ogModelId = modelId;
2019-08-15 15:59:09 +00:00
while(tryCount != 0) {
2019-08-15 14:51:39 +00:00
modelId += wantedChange;
2019-08-15 15:59:09 +00:00
if (modelId < 0 || modelId >= MODELINFOSIZE) {
2019-08-15 14:51:39 +00:00
tryCount--;
wantedChange = -wantedChange;
2019-08-15 15:59:09 +00:00
} else if (modelId != 5 && modelId != 6 && modelId != 405) {
2019-08-15 14:51:39 +00:00
CBaseModelInfo *model = CModelInfo::GetModelInfo(modelId);
if (model)
{
//int type = model->m_type;
return modelId;
}
}
}
return ogModelId;
}
void
PlayAnimation(RpClump *clump, AssocGroupId animGroup, AnimationId anim)
{
CAnimBlendAssociation *currentAssoc = RpAnimBlendClumpGetAssociation(clump, anim);
if (currentAssoc && currentAssoc->IsPartial())
delete currentAssoc;
RpAnimBlendClumpSetBlendDeltas(clump, ASSOC_PARTIAL, -8.0f);
CAnimBlendAssociation *animAssoc = CAnimManager::BlendAnimation(clump, animGroup, anim, 8.0f);
animAssoc->flags |= ASSOC_DELETEFADEDOUT;
animAssoc->SetCurrentTime(0.0f);
animAssoc->SetRun();
}
void
CAnimViewer::Update(void)
{
static int modelId = 0;
2020-06-08 11:23:08 +00:00
static int animId = 0;
2020-12-03 02:22:58 +00:00
static bool reloadIFP = false;
2019-08-15 14:51:39 +00:00
AssocGroupId animGroup = ASSOCGRP_STD;
int nextModelId = modelId;
CBaseModelInfo *modelInfo = CModelInfo::GetModelInfo(modelId);
2020-05-05 12:06:55 +00:00
if (modelInfo->GetModelType() == MITYPE_PED) {
2019-08-15 14:51:39 +00:00
int animGroup = ((CPedModelInfo*)modelInfo)->m_animGroup;
if (animId > ANIM_IDLE_STANCE)
animGroup = ASSOCGRP_STD;
2019-08-15 15:59:09 +00:00
if (reloadIFP) {
if (pTarget) {
2019-08-15 14:51:39 +00:00
CWorld::Remove(pTarget);
if (pTarget)
delete pTarget;
}
pTarget = nil;
// These calls were inside of LoadIFP function.
CAnimManager::Shutdown();
CAnimManager::Initialise();
CAnimManager::LoadAnimFiles();
2020-12-03 02:22:58 +00:00
reloadIFP = false;
2019-08-15 14:51:39 +00:00
}
2019-08-15 15:59:09 +00:00
} else {
2019-08-15 14:51:39 +00:00
animGroup = ASSOCGRP_STD;
}
CPad::UpdatePads();
CPad* pad = CPad::GetPad(0);
2020-05-09 13:06:13 +00:00
#ifdef DEBUGMENU
2020-03-28 14:47:52 +00:00
DebugMenuProcess();
2020-05-09 13:06:13 +00:00
#endif
2020-03-28 14:47:52 +00:00
2019-08-15 14:51:39 +00:00
CStreaming::UpdateForAnimViewer();
CStreaming::RequestModel(modelId, 0);
2019-08-15 15:59:09 +00:00
if (CStreaming::HasModelLoaded(modelId)) {
if (!pTarget) {
2020-05-05 12:06:55 +00:00
if (modelInfo->GetModelType() == MITYPE_VEHICLE) {
2019-08-15 15:59:09 +00:00
2019-08-15 14:51:39 +00:00
CVehicleModelInfo* veh = (CVehicleModelInfo*)modelInfo;
if (veh->m_vehicleType == VEHICLE_TYPE_CAR) {
pTarget = new CAutomobile(modelId, RANDOM_VEHICLE);
} else if (veh->m_vehicleType == VEHICLE_TYPE_BOAT) {
pTarget = new CBoat(modelId, RANDOM_VEHICLE);
} else if (veh->m_vehicleType == VEHICLE_TYPE_BIKE) {
pTarget = new CBike(modelId, RANDOM_VEHICLE);
2019-08-15 15:59:09 +00:00
} else {
pTarget = new CObject(modelId, true);
if (!modelInfo->GetColModel()) {
modelInfo->SetColModel(&CTempColModels::ms_colModelWheel1);
}
2019-08-15 14:51:39 +00:00
}
pTarget->SetStatus(STATUS_ABANDONED);
2020-05-05 12:06:55 +00:00
} else if (modelInfo->GetModelType() == MITYPE_PED) {
pTarget = new CPed(PEDTYPE_CIVMALE);
pTarget->SetModelIndex(modelId);
2019-08-15 15:59:09 +00:00
} else {
pTarget = new CObject(modelId, true);
2019-08-15 14:51:39 +00:00
if (!modelInfo->GetColModel())
{
modelInfo->SetColModel(&CTempColModels::ms_colModelWheel1);
}
pTarget->SetStatus(STATUS_ABANDONED);
2019-08-15 14:51:39 +00:00
}
pTarget->SetPosition(0.0f, 0.0f, 0.0f);
CWorld::Add(pTarget);
2020-04-02 10:48:01 +00:00
TheCamera.TakeControl(pTarget, CCam::MODE_MODELVIEW, JUMP_CUT, CAMCONTROL_SCRIPT);
2019-08-15 14:51:39 +00:00
}
if (pTarget->IsVehicle() || pTarget->IsPed() || pTarget->IsObject()) {
2019-08-15 15:59:09 +00:00
((CPhysical*)pTarget)->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
2019-08-15 14:51:39 +00:00
}
2020-12-03 10:30:46 +00:00
#ifdef FIX_BUGS
// so we don't end up in the water
pTarget->GetMatrix().GetPosition().z = 10.0f;
#else
2020-05-05 01:45:18 +00:00
pTarget->GetMatrix().GetPosition().z = 0.0f;
2020-12-03 10:30:46 +00:00
#endif
2019-08-15 14:51:39 +00:00
if (modelInfo->GetModelType() == MITYPE_PED) {
2019-08-15 14:51:39 +00:00
((CPed*)pTarget)->bKindaStayInSamePlace = true;
// Triangle in mobile
if (pad->GetSquareJustDown()) {
2020-12-03 02:22:58 +00:00
reloadIFP = true;
AsciiToUnicode("IFP reloaded", gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 15:59:09 +00:00
} else if (pad->GetCrossJustDown()) {
2019-08-15 14:51:39 +00:00
PlayAnimation(pTarget->GetClump(), animGroup, (AnimationId)animId);
AsciiToUnicode("Animation restarted", gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 15:59:09 +00:00
} else if (pad->GetCircleJustDown()) {
2019-08-15 14:51:39 +00:00
PlayAnimation(pTarget->GetClump(), animGroup, ANIM_IDLE_STANCE);
AsciiToUnicode("Idle animation playing", gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 15:59:09 +00:00
} else if (pad->GetDPadUpJustDown()) {
2019-08-15 14:51:39 +00:00
animId--;
2019-08-15 15:59:09 +00:00
if (animId < 0) {
2020-12-03 02:22:58 +00:00
animId = NUM_STD_ANIMS - 1;
2019-08-15 14:51:39 +00:00
}
PlayAnimation(pTarget->GetClump(), animGroup, (AnimationId)animId);
2019-08-15 15:59:09 +00:00
sprintf(gString, "Current anim: %d", animId);
AsciiToUnicode(gString, gUString);
CMessages::AddMessage(gUString, 1000, 0);
} else if (pad->GetDPadDownJustDown()) {
2020-12-03 02:22:58 +00:00
animId = (animId == (NUM_STD_ANIMS - 1) ? 0 : animId + 1);
2019-08-15 14:51:39 +00:00
PlayAnimation(pTarget->GetClump(), animGroup, (AnimationId)animId);
2019-08-15 15:59:09 +00:00
sprintf(gString, "Current anim: %d", animId);
AsciiToUnicode(gString, gUString);
CMessages::AddMessage(gUString, 1000, 0);
} else if (pad->GetStartJustDown()) {
2019-08-15 14:51:39 +00:00
} else if (pad->GetLeftShoulder1JustDown()) {
nextModelId = FirstCarModelId(modelId);
AsciiToUnicode("Switched to vehicles", gUString);
CMessages::AddMessage(gUString, 1000, 0);
// Originally it was GetPad(1)->LeftShoulder2
} else if (pad->NewState.Triangle) {
((CPedModelInfo *)CModelInfo::GetModelInfo(pTarget->GetModelIndex()))->AnimatePedColModelSkinned(pTarget->GetClump());
AsciiToUnicode("Ped Col model will be animated as long as you hold the button", gUString);
CMessages::AddMessage(gUString, 100, 0);
}
2020-12-03 02:22:58 +00:00
// From LCS
if (CAnimManager::GetAnimAssocGroups()[animGroup].numAssociations <= animId)
animId = 0;
} else if (modelInfo->GetModelType() == MITYPE_VEHICLE) {
if (pad->GetLeftShoulder1JustDown()) {
nextModelId = LastPedModelId(modelId);
AsciiToUnicode("Switched to peds", gUString);
CMessages::AddMessage(gUString, 1000, 0);
// Start in mobile
} else if (pad->GetSquareJustDown()) {
CVehicleModelInfo::LoadVehicleColours();
AsciiToUnicode("Carcols.dat reloaded", gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 14:51:39 +00:00
}
}
}
if (pad->GetDPadLeftJustDown()) {
nextModelId = NextModelId(modelId, -1);
sprintf(gString, "Current model ID: %d", nextModelId);
AsciiToUnicode(gString, gUString);
CMessages::AddMessage(gUString, 1000, 0);
} else if (pad->GetDPadRightJustDown()) {
nextModelId = NextModelId(modelId, 1);
sprintf(gString, "Current model ID: %d", nextModelId);
AsciiToUnicode(gString, gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 14:51:39 +00:00
}
2019-08-15 15:59:09 +00:00
// There were extra codes here to let us change model id by 50, but xbox CPad struct is different, so I couldn't port.
2019-08-15 14:51:39 +00:00
2019-08-15 15:59:09 +00:00
if (nextModelId != modelId) {
2019-08-15 14:51:39 +00:00
modelId = nextModelId;
2019-08-15 15:59:09 +00:00
if (pTarget) {
2019-08-15 14:51:39 +00:00
CWorld::Remove(pTarget);
if (pTarget)
delete pTarget;
}
pTarget = nil;
return;
}
CTimeCycle::Update();
CWorld::Process();
if (pTarget)
TheCamera.Process();
}
void
CAnimViewer::Shutdown(void)
{
if (CWorld::Players[0].m_pPed)
delete CWorld::Players[0].m_pPed;
CWorld::ShutDown();
CModelInfo::ShutDown();
CAnimManager::Shutdown();
CTimer::Shutdown();
CStreaming::Shutdown();
CTxdStore::RemoveTxdSlot(animTxdSlot);
2020-05-11 23:24:57 +00:00
}