Bug fixes and more CStateManager imps

This commit is contained in:
Jack Andersen 2017-02-13 18:27:20 -10:00
parent ac5f28eeff
commit 59406a069b
18 changed files with 194 additions and 43 deletions

View File

@ -47,6 +47,22 @@ void CObjectList::RemoveObject(TUniqueId uid)
--x200a_count;
}
const CEntity* CObjectList::operator[](size_t i) const
{
const SObjectListEntry& ent = x0_list[i];
if (ent.entity->x30_26_scriptingBlocked)
return nullptr;
return ent.entity;
}
CEntity* CObjectList::operator[](size_t i)
{
SObjectListEntry& ent = x0_list[i];
if (ent.entity->x30_26_scriptingBlocked)
return nullptr;
return ent.entity;
}
const CEntity* CObjectList::GetObjectById(TUniqueId uid) const
{
if (!uid)

View File

@ -53,6 +53,8 @@ public:
void AddObject(CEntity& entity);
void RemoveObject(TUniqueId uid);
const CEntity* operator[](size_t i) const;
CEntity* operator[](size_t i);
const CEntity* GetObjectById(TUniqueId uid) const;
const CEntity* GetObjectByIndex(s32 index) const { return x0_list[index].entity; }
CEntity* GetObjectById(TUniqueId uid);

View File

@ -389,13 +389,73 @@ void CStateManager::SendScriptMsg(TUniqueId src, TEditorId dest, EScriptObjectMe
}
}
void CStateManager::FreeScriptObjects(TAreaId) {}
void CStateManager::FreeScriptObjects(TAreaId aid)
{
for (const auto& p : x890_scriptIdMap)
if (p.first.AreaNum() == aid)
FreeScriptObject(p.second);
void CStateManager::GetBuildForScript(TEditorId) const {}
for (auto it = x8a4_loadedScriptObjects.begin() ; it != x8a4_loadedScriptObjects.end() ;)
{
if (it->first.AreaNum() == aid)
{
it = x8a4_loadedScriptObjects.erase(it);
continue;
}
++it;
}
TEditorId CStateManager::GetEditorIdForUniqueId(TUniqueId) const { return 0; }
CGameArea* area = x850_world->GetGameAreas()[aid].get();
if (area->IsPostConstructed())
{
const CGameArea::CPostConstructed* pc = area->GetPostConstructed();
for (CEntity* ent : *pc->x10c0_areaObjs)
if (ent && !ent->IsInUse())
FreeScriptObject(ent->GetUniqueId());
}
}
TUniqueId CStateManager::GetIdForScript(TEditorId) const { return kInvalidUniqueId; }
void CStateManager::FreeScriptObject(TUniqueId id)
{
CEntity* ent = ObjectById(id);
if (!ent || ent->IsInGraveyard())
return;
ent->SetIsInGraveyard(true);
x858_objectGraveyard.push_back(id);
ent->AcceptScriptMsg(EScriptObjectMessage::Deleted, kInvalidUniqueId, *this);
ent->SetIsScriptingBlocked(true);
if (TCastToPtr<CActor> act = ent)
{
x874_sortedListManager->Remove(act.GetPtr());
act->SetUseInSortedLists(false);
}
}
std::pair<const SScriptObjectStream*, TEditorId> CStateManager::GetBuildForScript(TEditorId id) const
{
auto search = x8a4_loadedScriptObjects.find(id);
if (search == x8a4_loadedScriptObjects.cend())
return {nullptr, kInvalidEditorId};
return {&search->second, search->first};
}
TEditorId CStateManager::GetEditorIdForUniqueId(TUniqueId id) const
{
const CEntity* ent = GetObjectById(id);
if (ent)
return ent->GetEditorId();
return kInvalidEditorId;
}
TUniqueId CStateManager::GetIdForScript(TEditorId id) const
{
auto search = x890_scriptIdMap.find(id);
if (search == x890_scriptIdMap.cend())
return kInvalidUniqueId;
return search->second;
}
std::pair<std::multimap<TEditorId, TUniqueId>::const_iterator, std::multimap<TEditorId, TUniqueId>::const_iterator>
CStateManager::GetIdListForScript(TEditorId id) const
@ -403,9 +463,77 @@ CStateManager::GetIdListForScript(TEditorId id) const
return x890_scriptIdMap.equal_range(id);
}
void CStateManager::LoadScriptObjects(TAreaId aid, CInputStream& in, std::vector<TEditorId>& idsOut) {}
void CStateManager::LoadScriptObjects(TAreaId aid, CInputStream& in, std::vector<TEditorId>& idsOut)
{
in.readUByte();
int objCount = in.readUint32Big();
idsOut.reserve(idsOut.size() + objCount);
for (int i=0 ; i<objCount ; ++i)
{
EScriptObjectType objType = EScriptObjectType(in.readUByte());
u32 objSize = in.readUint32Big();
u32 pos = in.position();
auto id = LoadScriptObject(aid, objType, objSize, in);
if (id.first == kInvalidEditorId)
continue;
auto build = GetBuildForScript(id.first);
if (build.first)
continue;
x8a4_loadedScriptObjects[id.first] = SScriptObjectStream{objType, pos, objSize};
idsOut.push_back(id.first);
}
}
void CStateManager::LoadScriptObject(TAreaId, EScriptObjectType, u32, CInputStream& in) {}
std::pair<TEditorId, TUniqueId> CStateManager::LoadScriptObject(TAreaId aid, EScriptObjectType type,
u32 length, CInputStream& in)
{
TEditorId id = in.readUint32Big();
u32 connCount = in.readUint32Big();
length -= 8;
std::vector<SConnection> conns;
conns.reserve(connCount);
for (int i=0 ; i<connCount ; ++i)
{
EScriptObjectState state = EScriptObjectState(in.readUint32Big());
EScriptObjectMessage msg = EScriptObjectMessage(in.readUint32Big());
TEditorId target = in.readUint32Big();
length -= 12;
conns.push_back(SConnection{state, msg, target});
}
u32 propCount = in.readUint32Big();
length -= 4;
auto startPos = in.position();
bool error = false;
FScriptLoader loader = {};
if (type < EScriptObjectType::ScriptObjectTypeMAX && type >= EScriptObjectType::Actor)
loader = x90c_loaderFuncs[int(type)];
CEntity* ent = nullptr;
if (loader)
{
CEntityInfo info(aid, conns, id);
ent = loader(*this, in, propCount, info);
}
else
{
error = true;
}
if (ent)
AddObject(ent);
else
error = true;
u32 leftover = length - (in.position() - startPos);
for (u32 i=0 ; i<leftover ; ++i)
in.readByte();
if (error || ent == nullptr)
return {kInvalidEditorId, kInvalidUniqueId};
else
return {id, ent->GetUniqueId()};
}
std::pair<TEditorId, TUniqueId> CStateManager::GenerateObject(TEditorId)
{
@ -589,8 +717,11 @@ void CStateManager::CreateStandardGameObjects()
zeus::CAABox pBounds = {{-xyHe, -xyHe, 0.f}, {xyHe, xyHe, height}};
auto q = zeus::CQuaternion::fromAxisAngle(zeus::CVector3f{0.f, 0.f, 1.f}, zeus::degToRad(129.6f));
x84c_player.reset(new CPlayer(
AllocateUniqueId(), zeus::CTransform(q), pBounds, 0, zeus::CVector3f{1.65f, 1.65f, 1.65f}, 200.f, unk1, unk2,
unk3, CMaterialList(EMaterialTypes::Player, EMaterialTypes::Solid, EMaterialTypes::GroundCollider)));
AllocateUniqueId(), zeus::CTransform(q), pBounds,
g_tweakPlayerRes->xc4_ballTransitionsANCS,
zeus::CVector3f{1.65f, 1.65f, 1.65f}, 200.f, unk1, unk2,
unk3, CMaterialList(EMaterialTypes::Player,
EMaterialTypes::Solid, EMaterialTypes::GroundCollider)));
AddObject(*x84c_player);
}
@ -643,14 +774,13 @@ void CStateManager::DeleteObjectRequest(TUniqueId id)
entity->SetIsInGraveyard(true);
x858_objectGraveyard.push_back(entity->GetUniqueId());
entity->AcceptScriptMsg(EScriptObjectMessage::InternalMessage12, kInvalidUniqueId, *this);
entity->AcceptScriptMsg(EScriptObjectMessage::Deleted, kInvalidUniqueId, *this);
entity->SetIsScriptingBlocked(true);
CActor* actor = static_cast<CActor*>(entity);
if (actor)
if (TCastToPtr<CActor> actor = entity)
{
x874_sortedListManager->Remove(actor);
actor->SetUseInSortedList(false);
actor->SetUseInSortedLists(false);
}
}
@ -706,21 +836,21 @@ void CStateManager::UpdateObjectInLists(CEntity&) {}
TUniqueId CStateManager::AllocateUniqueId()
{
const s16 lastIndex = x0_nextFreeIndex;
s16 ourIndex = 0;
s16 ourIndex;
do
{
ourIndex = x0_nextFreeIndex;
x0_nextFreeIndex = (x0_nextFreeIndex + 1) & 0x3ff;
if (ourIndex == lastIndex)
if (x0_nextFreeIndex == lastIndex)
LogModule.report(logvisor::Fatal, "Object List Full!");
}
while (x80c_allObjs->GetObjectByIndex(ourIndex) != nullptr);
x8_idArr[ourIndex]++;
x8_idArr[ourIndex] = (x8_idArr[ourIndex] + 1) & 0x3f;
if (((ourIndex | ((x8_idArr[ourIndex]) << 10)) & 0xFFFF) == kInvalidUniqueId)
x8_idArr[0] = 0;
return ((ourIndex | ((x8_idArr[ourIndex]) << 10)) & 0xFFFF);
return ((ourIndex | ((x8_idArr[ourIndex]) << 10)) & 0xFFFF);
}
std::pair<u32, u32> CStateManager::CalculateScanCompletionRate() const

View File

@ -52,10 +52,10 @@ class CMFGameLoader;
struct SScriptObjectStream
{
CEntity* x0_obj;
EScriptObjectType x4_type;
u32 x8_position;
u32 xc_length;
//CEntity* x0_obj;
EScriptObjectType x0_type;
u32 x4_position;
u32 x8_length;
};
struct SOnScreenTex
@ -142,7 +142,7 @@ class CStateManager
LoadWorld,
LoadFirstArea,
Done
} xb3c_initPhase;
} xb3c_initPhase = InitPhase::LoadWorld;
CFinalInput xb54_finalInput;
CCameraFilterPass xb84_camFilterPasses[9];
@ -267,14 +267,15 @@ public:
EScriptObjectMessage msg, EScriptObjectState state);
void SendScriptMsgAlways(TUniqueId dest, TUniqueId src, EScriptObjectMessage);
void FreeScriptObjects(TAreaId);
void GetBuildForScript(TEditorId) const;
void FreeScriptObject(TUniqueId);
std::pair<const SScriptObjectStream*, TEditorId> GetBuildForScript(TEditorId) const;
TEditorId GetEditorIdForUniqueId(TUniqueId) const;
TUniqueId GetIdForScript(TEditorId) const;
std::pair<std::multimap<TEditorId, TUniqueId>::const_iterator,
std::multimap<TEditorId, TUniqueId>::const_iterator>
GetIdListForScript(TEditorId) const;
void LoadScriptObjects(TAreaId, CInputStream& in, std::vector<TEditorId>& idsOut);
void LoadScriptObject(TAreaId, EScriptObjectType, u32, CInputStream& in);
std::pair<TEditorId, TUniqueId> LoadScriptObject(TAreaId, EScriptObjectType, u32, CInputStream& in);
std::pair<TEditorId, TUniqueId> GenerateObject(TEditorId);
void InitScriptObjects(std::vector<TEditorId>& ids);
void InformListeners(const zeus::CVector3f&, EListenNoiseType);

View File

@ -23,7 +23,9 @@ CTextColor CTextParser::ParseColor(const char16_t* str, int len)
u8 a = 0xff;
if (len == 9)
a = GetColorValue(str + 7);
return CTextColor(r, g, b, a);
CTextColor ret;
ret.fromRGBA8(r, g, b, a);
return ret;
}
u8 CTextParser::GetColorValue(const char16_t* str)

View File

@ -2007,6 +2007,8 @@ CFrontEndUI::CFrontEndUI()
m_touchBar = NewFrontEndUITouchBar();
m_touchBar->SetPhase(CFrontEndUITouchBar::EPhase::None);
x14_phase = EPhase::ExitFrontEnd;
}
void CFrontEndUI::StartSlideShow(CArchitectureQueue& queue)

View File

@ -103,15 +103,11 @@ CIOWin::EMessageReturn CMFGameLoader::OnMessage(const CArchitectureMessage& msg,
return EMessageReturn::Exit;
}
u32 loadingCount = 0;
std::vector<const SObjectTag*> unloaded;
for (CToken& tok : x1c_loadList)
{
tok.Lock();
if (!tok.IsLoaded())
{
unloaded.push_back(tok.GetObjectTag());
++loadingCount;
}
}
wtMgr->Update(dt);
if (loadingCount)

View File

@ -56,7 +56,7 @@ void CActor::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateMana
}
}
break;
case EScriptObjectMessage::InternalMessage12: // 34
case EScriptObjectMessage::Deleted: // 34
{
RemoveEmitter();
#if 0
@ -235,7 +235,7 @@ void CActor::SetCallTouch(bool callTouch) { xe5_28_callTouch = callTouch; }
bool CActor::GetCallTouch() const { return xe5_28_callTouch; }
void CActor::SetUseInSortedList(bool use) { xe5_27_useInSortedLists = use; }
void CActor::SetUseInSortedLists(bool use) { xe5_27_useInSortedLists = use; }
bool CActor::GetUseInSortedLists() const { return xe5_27_useInSortedLists; }

View File

@ -138,7 +138,7 @@ public:
void CreateShadow(bool);
void SetCallTouch(bool callTouch);
bool GetCallTouch() const;
void SetUseInSortedList(bool use);
void SetUseInSortedLists(bool use);
bool GetUseInSortedLists() const;
const CMaterialFilter& GetMaterialFilter() const { return x70_materialFilter; }
void SetMaterialFilter(const CMaterialFilter& filter) { x70_materialFilter = filter; }

View File

@ -28,7 +28,7 @@ protected:
bool x30_24_active : 1;
bool x30_25_inGraveyard : 1;
bool x30_26_scriptingBlocked : 1;
bool x30_27_ : 1;
bool x30_27_inUse : 1;
};
u8 _dummy = 0;
};
@ -53,14 +53,16 @@ public:
void SetIsInGraveyard(bool in) { x30_25_inGraveyard = in; }
bool IsScriptingBlocked() const { return x30_26_scriptingBlocked; }
void SetIsScriptingBlocked(bool blocked) { x30_26_scriptingBlocked = blocked; }
bool IsInUse() const { return x30_27_inUse; }
TAreaId GetAreaId() const
{
if (x30_27_)
if (x30_27_inUse)
return x4_areaId;
return kInvalidAreaId;
}
TUniqueId GetUniqueId() const {return x8_uid;}
TEditorId GetEditorId() const {return xc_editorId;}
void SendScriptMsgs(EScriptObjectState state, CStateManager& stateMgr, EScriptObjectMessage msg);
};

View File

@ -39,7 +39,7 @@ void CScriptAreaAttributes::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId
area->SetAreaAttributes(this);
stateMgr.GetEnvFxManager()->SetFxDensity(500, x3c_envFxDensity);
}
else if (msg >= EScriptObjectMessage::InternalMessage12)
else if (msg >= EScriptObjectMessage::Deleted)
{
CGameArea* area = stateMgr.WorldNC()->GetArea(x4_areaId);

View File

@ -54,7 +54,7 @@ void CScriptBeam::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CSt
EMaterialTypes::Projectile, x138_damageInfo, x8_uid, x4_areaId,
x154_projectileId, 8, false, 2));
}
else if (msg == EScriptObjectMessage::InternalMessage12)
else if (msg == EScriptObjectMessage::Deleted)
{
}

View File

@ -100,7 +100,7 @@ void CScriptDock::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStat
dock->SetReferenceCount(x258_dockReferenceCount);
}
break;
case EScriptObjectMessage::InternalMessage12:
case EScriptObjectMessage::Deleted:
CleanUp();
break;
case EScriptObjectMessage::InternalMessage13:

View File

@ -18,7 +18,7 @@ void CScriptRelay::Accept(IVisitor& visitor)
void CScriptRelay::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId objId, CStateManager &stateMgr)
{
CEntity::AcceptScriptMsg(msg, objId, stateMgr);
if (msg == EScriptObjectMessage::InternalMessage12)
if (msg == EScriptObjectMessage::Deleted)
{
UpdateObjectRef(stateMgr);
}

View File

@ -73,7 +73,7 @@ void CScriptSound::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSta
{
}
break;
case EScriptObjectMessage::InternalMessage12:
case EScriptObjectMessage::Deleted:
{
}
break;

View File

@ -39,7 +39,7 @@ void CScriptTrigger::Think(float dt, CStateManager& mgr)
void CScriptTrigger::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CStateManager& mgr)
{
if (GetActive() && (msg == EScriptObjectMessage::Deactivate || msg == EScriptObjectMessage::InternalMessage12))
if (GetActive() && (msg == EScriptObjectMessage::Deactivate || msg == EScriptObjectMessage::Deleted))
{
if (msg == EScriptObjectMessage::Deactivate)
{
@ -62,7 +62,6 @@ void CScriptTrigger::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CS
}
CEntity::AcceptScriptMsg(msg, uid, mgr);
;
}
CScriptTrigger::CObjectTracker* CScriptTrigger::FindObject(TUniqueId id)

View File

@ -183,8 +183,9 @@ std::string CDummyWorld::IGetDefaultAudioTrack() const { return {}; }
int CDummyWorld::IGetAreaCount() const { return x18_areas.size(); }
CWorld::CWorld(IObjectStore& objStore, IFactory& resFactory, ResId mlvlId)
: x60_objectStore(objStore), x64_resFactory(resFactory)
: x8_mlvlId(mlvlId), x60_objectStore(objStore), x64_resFactory(resFactory)
{
x70_24_ = true;
SObjectTag tag{FOURCC('MLVL'), mlvlId};
static_cast<ProjectResourceFactoryBase&>(resFactory).LoadResourceAsync(tag, x40_loadBuf);
}
@ -263,7 +264,7 @@ bool CWorld::CheckWorldComplete(CStateManager* mgr, TAreaId id, ResId mreaId)
{
if (!x40_loadBuf)
return false;
athena::io::MemoryReader r(x40_loadBuf.get(), UINT32_MAX, false);
athena::io::MemoryReader r(x40_loadBuf.get(), UINT32_MAX);
r.readUint32Big();
int version = r.readUint32Big();
xc_strgId = r.readUint32Big();

View File

@ -211,7 +211,7 @@ enum class EScriptObjectMessage
InternalMessage09 = 31,
InternalMessage10 = 32,
InternalMessage11 = 33,
InternalMessage12 = 34,
Deleted = 34,
InternalMessage13 = 35,
InternalMessage14 = 36,
InternalMessage15 = 37,