Various bug fixes

This commit is contained in:
Jack Andersen 2018-05-26 18:22:38 -10:00
parent 92ed463051
commit cc6d79e280
25 changed files with 182 additions and 46 deletions

View File

@ -1838,8 +1838,8 @@ void CStateManager::SetGameState(EGameState state)
if (x904_gameState == state)
return;
if (state == EGameState::SoftPaused)
x850_world->SetPauseState(false);
if (x904_gameState == EGameState::SoftPaused)
x850_world->SetLoadPauseState(false);
switch (state)
{
@ -1850,7 +1850,7 @@ void CStateManager::SetGameState(EGameState state)
case EGameState::SoftPaused:
if (!x88c_rumbleManager->IsDisabled())
x88c_rumbleManager->SetDisabled(true);
x850_world->SetPauseState(true);
x850_world->SetLoadPauseState(true);
default: break;
}
@ -2620,7 +2620,7 @@ void CStateManager::DeferStateTransition(EStateManagerTransition t)
{
if (xf90_deferredTransition != EStateManagerTransition::InGame)
{
x850_world->SetPauseState(false);
x850_world->SetLoadPauseState(false);
xf90_deferredTransition = EStateManagerTransition::InGame;
}
}
@ -2628,7 +2628,7 @@ void CStateManager::DeferStateTransition(EStateManagerTransition t)
{
if (xf90_deferredTransition == EStateManagerTransition::InGame)
{
x850_world->SetPauseState(true);
x850_world->SetLoadPauseState(true);
xf90_deferredTransition = t;
}
}

View File

@ -1,4 +1,5 @@
#include "CAABoxFilter.hpp"
#include "CollisionUtil.hpp"
namespace urde
{
@ -10,7 +11,26 @@ void CAABoxFilter::Filter(const CCollisionInfoList& in, CCollisionInfoList& out)
void CAABoxFilter::FilterBoxFloorCollisions(const CCollisionInfoList& in, CCollisionInfoList& out)
{
/* TODO: finish */
float minZ = 10000.f;
for (const CCollisionInfo& info : in)
{
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Wall) && info.GetPoint().z < minZ)
minZ = info.GetPoint().z;
}
CCollisionInfoList temp;
for (const CCollisionInfo& info : in)
{
if (info.GetMaterialLeft().HasMaterial(EMaterialTypes::Floor))
{
if (info.GetPoint().z < minZ)
temp.Add(info, false);
}
else
{
temp.Add(info, false);
}
}
CollisionUtil::AddAverageToFront(temp, out);
}
}

View File

@ -47,9 +47,9 @@ public:
const CMaterialList& GetMaterialRight() const { return x40_materialRight; }
zeus::CVector3f GetExtreme() const;
void Swap();
zeus::CVector3f GetNormalLeft() const { return x48_normalLeft; }
zeus::CVector3f GetNormalRight() const { return x54_normalRight; }
zeus::CVector3f GetPoint() const { return x0_point; }
const zeus::CVector3f& GetNormalLeft() const { return x48_normalLeft; }
const zeus::CVector3f& GetNormalRight() const { return x54_normalRight; }
const zeus::CVector3f& GetPoint() const { return x0_point; }
};
}

View File

@ -19,7 +19,7 @@ namespace urde
static float CollisionImpulseFiniteVsInfinite(float mass, float velNormDot, float restitution)
{
return mass * ((1.f / restitution) * velNormDot);
return mass * -(1.f + restitution) * velNormDot;
}
static float CollisionImpulseFiniteVsFinite(float mass0, float mass1, float velNormDot, float restitution)

View File

@ -1237,6 +1237,25 @@ bool AABox_AABox_Moving(const zeus::CAABox& aabb0, const zeus::CAABox& aabb1, co
void AddAverageToFront(const CCollisionInfoList& in, CCollisionInfoList& out)
{
if (in.GetCount() > 1)
{
zeus::CVector3f pointAccum, normAccum;
for (const CCollisionInfo& info : in)
{
pointAccum += info.GetPoint();
normAccum += info.GetNormalLeft();
}
if (normAccum.canBeNormalized())
{
out.Add(CCollisionInfo(pointAccum / float(in.GetCount()),
in.GetItem(0).GetMaterialRight(), in.GetItem(0).GetMaterialLeft(),
normAccum.normalized()), false);
}
}
for (const CCollisionInfo& info : in)
out.Add(info, false);
}
}

View File

@ -70,17 +70,32 @@ void CGraphics::SetAmbientColor(const zeus::CColor& col)
void CGraphics::SetFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color)
{
if (mode == ERglFogMode::None)
g_Fog.m_mode = mode > ERglFogMode::PerspRevExp2 ? ERglFogMode(int(mode) - 8) : mode;
switch (g_Fog.m_mode)
{
case ERglFogMode::None:
{
g_Fog.m_start = 4096.f;
g_Fog.m_rangeScale = 0.f;
break;
}
else
case ERglFogMode::PerspRevExp:
case ERglFogMode::PerspRevExp2:
{
float userRange = endz - startz;
g_Fog.m_color = color;
g_Fog.m_start = endz;
g_Fog.m_rangeScale = 1.f / userRange;
break;
}
default:
{
float userRange = endz - startz;
g_Fog.m_color = color;
g_Fog.m_start = startz;
g_Fog.m_rangeScale = 1.f / userRange;
break;
}
}
}

View File

@ -122,7 +122,7 @@ enum class ERglAlphaOp
XNor = 3
};
enum class ERglFogMode
enum class ERglFogMode : uint32_t
{
None = 0x00,
@ -232,6 +232,7 @@ public:
struct CFogState
{
ERglFogMode m_mode;
zeus::CColor m_color;
float m_rangeScale = 0.f;
float m_start = 4096.f;

View File

@ -59,6 +59,7 @@ BOO_GLSL_BINDING_HEAD
"};\n"
"struct Fog\n" // Reappropriated for indirect texture scaling
"{\n"
" uint mode;\n"
" vec4 color;\n"
" float indScale;\n"
" float start;\n"
@ -129,6 +130,7 @@ BOO_GLSL_BINDING_HEAD
"};\n"
"struct Fog\n" // Reappropriated for indirect texture scaling
"{\n"
" uint mode;\n"
" vec4 color;\n"
" float indScale;\n"
" float start;\n"

View File

@ -61,6 +61,7 @@ static const char* FS =
"};\n"
"struct Fog\n" // Reappropriated for indirect texture scaling
"{\n"
" uint mode;\n"
" float4 color;\n"
" float indScale;\n"
" float start;\n"
@ -130,6 +131,7 @@ static const char* FSDoor =
"};\n"
"struct Fog\n" // Reappropriated for indirect texture scaling
"{\n"
" uint mode;\n"
" float4 color;\n"
" float indScale;\n"
" float start;\n"

View File

@ -73,6 +73,7 @@ static const char* FS =
"};\n"
"struct Fog\n" // Reappropriated for indirect texture scaling
"{\n"
" uint mode;\n"
" float4 color;\n"
" float indScale;\n"
" float start;\n"
@ -151,6 +152,7 @@ static const char* FSDoor =
"};\n"
"struct Fog\n" // Reappropriated for indirect texture scaling
"{\n"
" uint mode;\n"
" float4 color;\n"
" float indScale;\n"
" float start;\n"

View File

@ -15,6 +15,7 @@ static const char* LightingGLSL =
"};\n"
"struct Fog\n"
"{\n"
" uint mode;\n"
" vec4 color;\n"
" float rangeScale;\n"
" float start;\n"
@ -63,6 +64,7 @@ static const char* LightingShadowGLSL =
"};\n"
"struct Fog\n"
"{\n"
" uint mode;\n"
" vec4 color;\n"
" float rangeScale;\n"
" float start;\n"
@ -118,8 +120,31 @@ static const char* LightingShadowGLSL =
static const char* MainPostGLSL =
"vec4 MainPostFunc(vec4 colorIn)\n"
"{\n"
" float fogZ = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
" return mix(fog.color, colorIn, clamp(exp2(-8.0 * fogZ), 0.0, 1.0));\n"
" float fogZ, temp;\n"
" switch (fog.mode)\n"
" {\n"
" case 2:\n"
" fogZ = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
" break;\n"
" case 4:\n"
" fogZ = 1.0 - exp2(-8.0 * (-vtf.mvPos.z - fog.start) * fog.rangeScale);\n"
" break;\n"
" case 5:\n"
" temp = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
" fogZ = 1.0 - exp2(-8.0 * temp * temp);\n"
" break;\n"
" case 6:\n"
" fogZ = exp2(-8.0 * (fog.start + vtf.mvPos.z) * fog.rangeScale);\n"
" break;\n"
" case 7:\n"
" temp = (fog.start + vtf.mvPos.z) * fog.rangeScale;\n"
" fogZ = exp2(-8.0 * temp * temp);\n"
" break;\n"
" default:\n"
" fogZ = 0.0;\n"
" break;\n"
" }\n"
" return mix(colorIn, fog.color, clamp(fogZ, 0.0, 1.0));\n"
"}\n"
"\n";

View File

@ -14,6 +14,7 @@ static const char* LightingHLSL =
"};\n"
"struct Fog\n"
"{\n"
" uint mode;\n"
" float4 color;\n"
" float rangeScale;\n"
" float start;\n"
@ -62,6 +63,7 @@ static const char* LightingShadowHLSL =
"};\n"
"struct Fog\n"
"{\n"
" uint mode;\n"
" float4 color;\n"
" float rangeScale;\n"
" float start;\n"
@ -114,8 +116,31 @@ static const char* LightingShadowHLSL =
static const char* MainPostHLSL =
"static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn)\n"
"{\n"
" float fogZ = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
" return lerp(fog.color, colorIn, saturate(exp2(-8.0 * fogZ)));\n"
" float fogZ, temp;\n"
" switch (fog.mode)\n"
" {\n"
" case 2:\n"
" fogZ = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
" break;\n"
" case 4:\n"
" fogZ = 1.0 - exp2(-8.0 * (-vtf.mvPos.z - fog.start) * fog.rangeScale);\n"
" break;\n"
" case 5:\n"
" temp = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
" fogZ = 1.0 - exp2(-8.0 * temp * temp);\n"
" break;\n"
" case 6:\n"
" fogZ = exp2(-8.0 * (fog.start + vtf.mvPos.z) * fog.rangeScale);\n"
" break;\n"
" case 7:\n"
" temp = (fog.start + vtf.mvPos.z) * fog.rangeScale;\n"
" fogZ = exp2(-8.0 * temp * temp);\n"
" break;\n"
" default:\n"
" fogZ = 0.0;\n"
" break;\n"
" }\n"
" return lerp(colorIn, fog.color, saturate(fogZ));\n"
"}\n"
"\n";

View File

@ -14,6 +14,7 @@ static const char* LightingMetal =
"};\n"
"struct Fog\n"
"{\n"
" uint mode;\n"
" float4 color;\n"
" float rangeScale;\n"
" float start;\n"
@ -62,6 +63,7 @@ static const char* LightingShadowMetal =
"};\n"
"struct Fog\n"
"{\n"
" uint mode;\n"
" float4 color;\n"
" float rangeScale;\n"
" float start;\n"
@ -115,8 +117,31 @@ static const char* LightingShadowMetal =
static const char* MainPostMetal =
"float4 MainPostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colorIn)\n"
"{\n"
" float fogZ = (-vtf.mvPos.z - lu.fog.start) * lu.fog.rangeScale;\n"
" return mix(lu.fog.color, colorIn, saturate(exp2(-8.0 * fogZ)));\n"
" float fogZ, temp;\n"
" switch (lu.fog.mode)\n"
" {\n"
" case 2:\n"
" fogZ = (-vtf.mvPos.z - lu.fog.start) * lu.fog.rangeScale;\n"
" break;\n"
" case 4:\n"
" fogZ = 1.0 - exp2(-8.0 * (-vtf.mvPos.z - lu.fog.start) * lu.fog.rangeScale);\n"
" break;\n"
" case 5:\n"
" temp = (-vtf.mvPos.z - lu.fog.start) * lu.fog.rangeScale;\n"
" fogZ = 1.0 - exp2(-8.0 * temp * temp);\n"
" break;\n"
" case 6:\n"
" fogZ = exp2(-8.0 * (lu.fog.start + vtf.mvPos.z) * lu.fog.rangeScale);\n"
" break;\n"
" case 7:\n"
" temp = (lu.fog.start + vtf.mvPos.z) * lu.fog.rangeScale;\n"
" fogZ = exp2(-8.0 * temp * temp);\n"
" break;\n"
" default:\n"
" fogZ = 0.0;\n"
" break;\n"
" }\n"
" return mix(colorIn, lu.fog.color, saturate(fogZ));\n"
"}\n"
"\n";

View File

@ -2006,7 +2006,7 @@ CFrontEndUI::CFrontEndUI()
m->ResetGameState();
g_GameState->SetCurrentWorldId(g_ResFactory->TranslateOriginalToNew(g_DefaultWorldTag.id));
g_GameState->CurrentWorldState().SetAreaId(1);
g_GameState->CurrentWorldState().SetAreaId(0);
g_GameState->GameOptions().ResetToDefaults();
g_GameState->WriteBackupBuf();

View File

@ -224,7 +224,7 @@ CElementGen::CElementGen(const TToken<CGenDescription>& gen,
tex = texr->GetValueTexture(0).GetObj()->GetBooTexture();
int maxVerts = (x90_MAXP == 0 ? 256 : x90_MAXP);
m_lineRenderer.reset(new CLineRenderer(CLineRenderer::EPrimitiveMode::Lines,
maxVerts * 2, tex, x26c_26_AAPH));
maxVerts * 2, tex, x26c_26_AAPH, x26c_28_zTest));
}
else
{

View File

@ -419,7 +419,7 @@ CGameArea::CGameArea(CInputStream& in, int idx, int mlvlVersion)
xf0_24_postConstructed = false;
xf0_25_active = true;
xf0_26_tokensReady = false;
xf0_27_paused = false;
xf0_27_loadPaused = false;
xf0_28_validated = false;
x8_nameSTRG = in.readUint32Big();
xc_transform.read34RowMajor(in);
@ -470,7 +470,7 @@ CGameArea::CGameArea(CAssetId mreaId)
xf0_24_postConstructed = false;
xf0_25_active = false;
xf0_26_tokensReady = false;
xf0_27_paused = false;
xf0_27_loadPaused = false;
xf0_28_validated = false;
while (StartStreamingMainArea())
@ -552,11 +552,11 @@ const zeus::CTransform& CGameArea::IGetTM() const
return xc_transform;
}
void CGameArea::SetPauseState(bool paused)
void CGameArea::SetLoadPauseState(bool paused)
{
if (xf0_26_tokensReady)
return;
xf0_27_paused = paused;
xf0_27_loadPaused = paused;
if (!paused)
return;
@ -982,7 +982,7 @@ void CGameArea::CullDeadAreaRequests()
void CGameArea::StartStreamIn(CStateManager& mgr)
{
if (xf0_24_postConstructed || xf0_27_paused)
if (xf0_24_postConstructed || xf0_27_loadPaused)
return;
VerifyTokenList(mgr);

View File

@ -120,7 +120,7 @@ class CGameArea final : public IGameArea
bool xf0_24_postConstructed : 1;
bool xf0_25_active : 1;
bool xf0_26_tokensReady : 1;
bool xf0_27_paused : 1;
bool xf0_27_loadPaused : 1;
bool xf0_28_validated : 1;
enum class EPhase
@ -285,7 +285,7 @@ public:
bool IsFinishedOccluding() const;
void ReadDependencyList();
void SetPauseState(bool paused);
void SetLoadPauseState(bool paused);
std::pair<std::unique_ptr<u8[]>, s32> IGetScriptingMemoryAlways() const;
TAreaId GetAreaId() const { return x4_selfIdx; }

View File

@ -142,7 +142,7 @@ void CPhysicsActor::SetMass(float mass)
tensor = 1.0f / mass;
xec_massRecip = tensor;
SetInertiaTensorScalar(mass * tensor);
SetInertiaTensorScalar(mass / 6.f);
}
void CPhysicsActor::SetAngularVelocityOR(const zeus::CAxisAngle& angVel)

View File

@ -130,7 +130,7 @@ void CScriptPlayerActor::PumpBeamModel(CStateManager& mgr)
return;
BuildBeamModelData();
x314_beamModelData->Touch(mgr, 0);
mgr.WorldNC()->CyclePauseState();
mgr.WorldNC()->CycleLoadPauseState();
x31c_beamModel = TLockedToken<CModel>();
x354_27_beamModelLoading = false;
}
@ -148,7 +148,7 @@ void CScriptPlayerActor::PumpSuitModel(CStateManager& mgr)
return;
x320_suitModel->Touch(0);
mgr.WorldNC()->CyclePauseState();
mgr.WorldNC()->CycleLoadPauseState();
bool didSetup = false;
if (x354_26_deferOfflineModelData)

View File

@ -210,7 +210,7 @@ void CScriptSound::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSta
void CScriptSound::PlaySound(CStateManager& mgr)
{
if ((x11d_24_allowDuplicates || !xec_sfxHandle) && !x11d_25_processedThisFrame)
if ((x11d_24_allowDuplicates || !xec_sfxHandle || !xec_sfxHandle->IsPlaying()) && !x11d_25_processedThisFrame)
{
x11d_25_processedThisFrame = true;
if (x11c_26_nonEmitter)

View File

@ -93,7 +93,7 @@ void CScriptWorldTeleporter::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId
case EScriptObjectMessage::SetToZero:
{
const auto& world = mgr.WorldNC();
world->SetPauseState(true);
world->SetLoadPauseState(true);
CAssetId currentWorld = g_GameState->CurrentWorldAssetId();
if (g_ResFactory->GetResourceTypeById(currentWorld) == SBIG('MLVL'))

View File

@ -557,25 +557,25 @@ void CWorld::TravelToArea(TAreaId aid, CStateManager& mgr, bool skipLoadOther)
++toStreamCount;
}
if (!toStreamCount && otherLoadArea && !x70_25_paused)
if (!toStreamCount && otherLoadArea && !x70_25_loadPaused)
otherLoadArea->StartStreamIn(mgr);
x28_mapWorld->SetWhichMapAreasLoaded(*this, aid, 3);
}
void CWorld::SetPauseState(bool paused)
void CWorld::SetLoadPauseState(bool paused)
{
for (auto it = GetChainHead(EChain::Loading) ; it != AliveAreasEnd() ; ++it)
it->SetPauseState(paused);
x70_25_paused = paused;
it->SetLoadPauseState(paused);
x70_25_loadPaused = paused;
}
void CWorld::CyclePauseState()
void CWorld::CycleLoadPauseState()
{
if (!x70_25_paused)
if (!x70_25_loadPaused)
{
SetPauseState(true);
SetPauseState(false);
SetLoadPauseState(true);
SetLoadPauseState(false);
}
}

View File

@ -137,7 +137,7 @@ private:
struct
{
bool x70_24_currentAreaNeedsAllocation : 1;
bool x70_25_paused : 1;
bool x70_25_loadPaused : 1;
bool x70_26_skyboxActive : 1;
bool x70_27_skyboxVisible : 1;
};
@ -169,8 +169,8 @@ public:
CGameArea::CConstChainIterator end() const { return GetAliveAreasEnd(); }
bool ScheduleAreaToLoad(CGameArea* area, CStateManager& mgr);
void TravelToArea(TAreaId aid, CStateManager& mgr, bool);
void SetPauseState(bool paused);
void CyclePauseState();
void SetLoadPauseState(bool paused);
void CycleLoadPauseState();
CWorld(IObjectStore& objStore, IFactory& resFactory, CAssetId mlvlId);
~CWorld();

2
hecl

@ -1 +1 @@
Subproject commit 2255856884b53bbc126d5dfc70723f4be193613d
Subproject commit 419a51e5cd341bbf109c0431737c7f89e27ac129

2
nod

@ -1 +1 @@
Subproject commit d5f5db440cc266700bd59397b3a3b4a4596b87aa
Subproject commit 4d9071bad75f0f8de94777052cec6bfd5e1e585c