re3-wiiu/src/core/AnimViewer.cpp

420 lines
12 KiB
C++
Raw Normal View History

2019-08-15 16:51:39 +02:00
#include "common.h"
#include "patcher.h"
#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 "PlayerSkin.h"
#include "PlayerInfo.h"
#include "World.h"
#include "Renderer.h"
#include "AnimManager.h"
#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"
#include "Shadows.h"
#include "Radar.h"
#include "Hud.h"
2019-08-15 16:51:39 +02:00
int CAnimViewer::animTxdSlot = 0;
CEntity *CAnimViewer::pTarget = nil;
void
CAnimViewer::Render(void) {
2019-08-15 17:59:09 +02:00
if (pTarget) {
2019-08-15 16:51:39 +02:00
// pTarget->GetPosition() = CVector(0.0f, 0.0f, 0.0f);
2019-08-15 17:59:09 +02:00
if (pTarget) {
2019-08-15 16:51:39 +02:00
pTarget->Render();
CRenderer::RenderOneNonRoad(pTarget);
}
}
}
void
CAnimViewer::Initialise(void) {
LoadingScreen("Loading the ModelViewer", "", GetRandomSplashScreen());
animTxdSlot = CTxdStore::AddTxdSlot("generic");
CTxdStore::Create(animTxdSlot);
int hudSlot = CTxdStore::AddTxdSlot("hud");
CTxdStore::LoadTxd(hudSlot, "MODELS/HUD.TXD");
int particleSlot = CTxdStore::AddTxdSlot("particle");
CTxdStore::LoadTxd(particleSlot, "MODELS/PARTICLE.TXD");
CTxdStore::SetCurrentTxd(animTxdSlot);
CPools::Initialise();
CReferences::Init();
TheCamera.Init();
TheCamera.SetRwCamera(Scene.camera);
// I didn't get which camera og code selects.
for (int i = 0; i < 3; i++) {
TheCamera.Cams[i].Distance = 5.0f;
}
gbModelViewer = true;
CHud::m_Wants_To_Draw_Hud = false;
2019-08-15 16:51:39 +02: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\\ANIMVIEWER.DAT");
CStreaming::Init();
CStreaming::LoadInitialPeds();
CStreaming::RequestSpecialModel(MI_PLAYER, "player", STREAMFLAGS_DONT_REMOVE);
CStreaming::LoadAllRequestedModels(false);
CRenderer::Init();
CRadar::Initialise();
CRadar::LoadTextures();
2019-08-15 16:51:39 +02:00
CVehicleModelInfo::LoadVehicleColours();
CAnimManager::LoadAnimFiles();
CWorld::PlayerInFocus = 0;
CWeapon::InitialiseWeapons();
CShadows::Init();
CPed::Initialise();
CTimer::Initialise();
CClock::Initialise(60000);
CTimeCycle::Initialise();
CCarCtrl::Init();
CPlayerPed *player = new CPlayerPed();
player->GetPosition() = CVector(0.0f, 0.0f, 0.0f);
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 17:59:09 +02:00
if (fd) {
2019-08-15 16:51:39 +02:00
for (int lineId = 0; lineId < NUM_OF_SPECIAL_CHARS; lineId++) {
if (!CFileMgr::ReadLine(fd, gString, 255))
break;
sscanf(gString, "%s %s", &modelName, &animGroup);
int groupId;
2019-08-15 17:59:09 +02:00
for (groupId = 0; groupId < NUM_ANIM_ASSOC_GROUPS; groupId++) {
2019-08-15 16:51:39 +02: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 {
// From xbox
CStreaming::RequestSpecialChar(0, "luigi", STREAMFLAGS_DONT_REMOVE);
CStreaming::RequestSpecialChar(1, "joey", STREAMFLAGS_DONT_REMOVE);
CStreaming::RequestSpecialChar(2, "tony", STREAMFLAGS_DONT_REMOVE);
CStreaming::RequestSpecialChar(3, "curly", STREAMFLAGS_DONT_REMOVE);
}
}
int
LastPedModelId(int modelId)
{
CBaseModelInfo *model;
for (int i = modelId; i >= 0; i--) {
model = CModelInfo::GetModelInfo(i);
if (model->m_type == MITYPE_PED)
return i;
}
return modelId;
}
int
LastVehicleModelId(int modelId)
{
CBaseModelInfo* model;
for (int i = modelId; i >= 0; i--) {
model = CModelInfo::GetModelInfo(i);
if (model->m_type == MITYPE_VEHICLE)
return i;
}
return modelId;
}
// It's me that named this.
int
FindMeAModelID(int modelId, int wantedChange)
{
// Max. 2 trials wasn't here, it's me that added it.
int tryCount = 2;
int ogModelId = modelId;
2019-08-15 17:59:09 +02:00
while(tryCount != 0) {
2019-08-15 16:51:39 +02:00
modelId += wantedChange;
2019-08-15 17:59:09 +02:00
if (modelId < 0 || modelId >= MODELINFOSIZE) {
2019-08-15 16:51:39 +02:00
tryCount--;
wantedChange = -wantedChange;
2019-08-15 17:59:09 +02:00
} else if (modelId != 5 && modelId != 6 && modelId != 405) {
2019-08-15 16:51:39 +02: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;
static int animId = 0;
// Please don't make this bool, static bool's are problematic on my side.
static int reloadIFP = 0;
AssocGroupId animGroup = ASSOCGRP_STD;
int nextModelId = modelId;
CBaseModelInfo *modelInfo = CModelInfo::GetModelInfo(modelId);
2019-08-16 18:25:02 +02:00
CEntity *newEntity = nil;
2019-08-15 16:51:39 +02:00
2019-08-15 17:59:09 +02:00
if (modelInfo->m_type == MITYPE_PED) {
2019-08-15 16:51:39 +02:00
int animGroup = ((CPedModelInfo*)modelInfo)->m_animGroup;
if (animId > ANIM_IDLE_STANCE)
animGroup = ASSOCGRP_STD;
2019-08-15 17:59:09 +02:00
if (reloadIFP) {
if (pTarget) {
2019-08-15 16:51:39 +02:00
CWorld::Remove(pTarget);
if (pTarget)
delete pTarget;
}
pTarget = nil;
// These calls were inside of LoadIFP function.
CAnimManager::Shutdown();
CAnimManager::Initialise();
CAnimManager::LoadAnimFiles();
reloadIFP = 0;
}
2019-08-15 17:59:09 +02:00
} else {
2019-08-15 16:51:39 +02:00
animGroup = ASSOCGRP_STD;
}
CPad::UpdatePads();
CPad* pad = CPad::GetPad(0);
CStreaming::UpdateForAnimViewer();
CStreaming::RequestModel(modelId, 0);
2019-08-15 17:59:09 +02:00
if (CStreaming::HasModelLoaded(modelId)) {
if (!pTarget) {
if (modelInfo->m_type == MITYPE_VEHICLE) {
2019-08-15 16:51:39 +02:00
CVehicleModelInfo* veh = (CVehicleModelInfo*)modelInfo;
2019-09-24 13:33:16 +02:00
if (veh->m_vehicleType != VEHICLE_TYPE_AUTOMOBILE) {
2019-08-15 16:51:39 +02:00
// Not ready yet
/* if (veh->m_vehicleType == VEHICLE_TYPE_BOAT)
{
v33 = (CBoat*)CVehicle::operator new((CVehicle*)0x488, v6);
CBoat::CBoat(v33, modelId, 1u);
2019-08-16 18:25:02 +02:00
newEntity = (int)v33;
2019-08-15 16:51:39 +02:00
pTarget = (int)v33;
}
else
{
2019-08-16 18:25:02 +02:00
*/ newEntity = pTarget = new CObject(modelId, true);
2019-08-15 17:59:09 +02:00
if (!modelInfo->GetColModel()) {
2019-08-15 16:51:39 +02:00
modelInfo->SetColModel(&CTempColModels::ms_colModelWheel1);
}
// }
2019-08-15 17:59:09 +02:00
} else {
2019-08-16 18:25:02 +02:00
newEntity = pTarget = new CAutomobile(modelId, RANDOM_VEHICLE);
newEntity->m_status = STATUS_ABANDONED;
2019-08-15 16:51:39 +02:00
}
2019-08-16 18:25:02 +02:00
newEntity->bIsStuck = true;
2019-08-15 17:59:09 +02:00
} else if (modelInfo->m_type == MITYPE_PED) {
2019-08-16 18:25:02 +02:00
pTarget = newEntity = new CPed(PEDTYPE_CIVMALE);
newEntity->SetModelIndex(modelId);
2019-08-15 17:59:09 +02:00
} else {
2019-08-16 18:25:02 +02:00
newEntity = pTarget = new CObject(modelId, true);
2019-08-15 16:51:39 +02:00
if (!modelInfo->GetColModel())
{
modelInfo->SetColModel(&CTempColModels::ms_colModelWheel1);
}
2019-08-16 18:25:02 +02:00
newEntity->bIsStuck = true;
2019-08-15 16:51:39 +02:00
}
2019-08-16 18:25:02 +02:00
newEntity->GetPosition() = CVector(0.0f, 0.0f, 0.0f);
CWorld::Add(newEntity);
2019-08-15 16:51:39 +02:00
TheCamera.TakeControl(pTarget, 9, 2, 1);
}
2019-08-15 17:59:09 +02:00
if (pTarget->m_type == ENTITY_TYPE_VEHICLE || pTarget->m_type == ENTITY_TYPE_PED || pTarget->m_type == ENTITY_TYPE_OBJECT) {
((CPhysical*)pTarget)->m_vecMoveSpeed = CVector(0.0f, 0.0f, 0.0f);
2019-08-15 16:51:39 +02:00
}
pTarget->GetPosition().z = 0.0f;
2019-08-15 17:59:09 +02:00
if (modelInfo->m_type != MITYPE_PED) {
if (modelInfo->m_type == MITYPE_VEHICLE) {
if (pad->NewState.LeftShoulder1 && !pad->OldState.LeftShoulder1) {
2019-08-15 16:51:39 +02:00
nextModelId = LastPedModelId(modelId);
AsciiToUnicode("Switched to peds", gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 17:59:09 +02:00
} else {
2019-08-15 16:51:39 +02:00
// Start in mobile
if (pad->NewState.Square && !pad->OldState.Square) {
2019-08-15 16:51:39 +02:00
CVehicleModelInfo::LoadVehicleColours();
AsciiToUnicode("Carcols.dat reloaded", gUString);
CMessages::AddMessage(gUString, 1000, 0);
}
2019-08-15 16:51:39 +02:00
}
}
2019-08-15 17:59:09 +02:00
} else {
2019-08-15 16:51:39 +02:00
((CPed*)pTarget)->bKindaStayInSamePlace = true;
// Triangle in mobile
if (pad->NewState.Square && !pad->OldState.Square) {
reloadIFP = 1;
AsciiToUnicode("IFP reloaded", gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 17:59:09 +02:00
} else if (pad->NewState.Cross && !pad->OldState.Cross) {
2019-08-15 16:51:39 +02:00
PlayAnimation(pTarget->GetClump(), animGroup, (AnimationId)animId);
AsciiToUnicode("Animation restarted", gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 17:59:09 +02:00
} else if (pad->NewState.Circle && !pad->OldState.Circle) {
2019-08-15 16:51:39 +02:00
PlayAnimation(pTarget->GetClump(), animGroup, ANIM_IDLE_STANCE);
AsciiToUnicode("Idle animation playing", gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 17:59:09 +02:00
} else if (pad->NewState.DPadUp && pad->OldState.DPadUp == 0) {
2019-08-15 16:51:39 +02:00
animId--;
2019-08-15 17:59:09 +02:00
if (animId < 0) {
2019-08-15 16:51:39 +02:00
animId = NUM_ANIMS - 1;
}
PlayAnimation(pTarget->GetClump(), animGroup, (AnimationId)animId);
2019-08-15 17:59:09 +02:00
sprintf(gString, "Current anim: %d", animId);
AsciiToUnicode(gString, gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 17:59:09 +02:00
} else if (pad->NewState.DPadDown && !pad->OldState.DPadDown) {
2019-08-15 16:51:39 +02:00
animId = (animId == (NUM_ANIMS - 1) ? 0 : animId + 1);
PlayAnimation(pTarget->GetClump(), animGroup, (AnimationId)animId);
2019-08-15 17:59:09 +02:00
sprintf(gString, "Current anim: %d", animId);
AsciiToUnicode(gString, gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 17:59:09 +02:00
} else {
if (pad->NewState.Start && !pad->OldState.Start) {
2019-08-15 16:51:39 +02:00
} else {
if (pad->NewState.LeftShoulder1 && !pad->OldState.LeftShoulder1) {
nextModelId = LastVehicleModelId(modelId);
AsciiToUnicode("Switched to vehicles", gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 16:51:39 +02:00
} else {
// Originally it was GetPad(1)->LeftShoulder2
if (pad->NewState.Triangle) {
CPedModelInfo::AnimatePedColModel(((CPedModelInfo*)CModelInfo::GetModelInfo(pTarget->m_modelIndex))->GetHitColModel(), RpClumpGetFrame(pTarget->GetClump()));
AsciiToUnicode("Ped Col model will be animated as long as you hold the button", gUString);
CMessages::AddMessage(gUString, 100, 0);
}
2019-08-15 16:51:39 +02:00
}
}
}
}
}
2019-08-15 17:59:09 +02:00
if (pad->NewState.DPadLeft && pad->OldState.DPadLeft == 0) {
2019-08-15 16:51:39 +02:00
nextModelId = FindMeAModelID(modelId, -1);
sprintf(gString, "Current model ID: %d", nextModelId);
AsciiToUnicode(gString, gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 17:59:09 +02:00
} else if (pad->NewState.DPadRight && pad->OldState.DPadRight == 0) {
2019-08-15 16:51:39 +02:00
nextModelId = FindMeAModelID(modelId, 1);
sprintf(gString, "Current model ID: %d", nextModelId);
AsciiToUnicode(gString, gUString);
CMessages::AddMessage(gUString, 1000, 0);
2019-08-15 16:51:39 +02:00
}
2019-08-15 17:59:09 +02: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 16:51:39 +02:00
2019-08-15 17:59:09 +02:00
if (nextModelId != modelId) {
2019-08-15 16:51:39 +02:00
modelId = nextModelId;
2019-08-15 17:59:09 +02:00
if (pTarget) {
2019-08-15 16:51:39 +02: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);
}