Lots of bug fixes

This commit is contained in:
Jack Andersen 2018-05-09 21:25:26 -10:00
parent b58ebc1af5
commit 12430610f1
23 changed files with 129 additions and 43 deletions

View File

@ -245,29 +245,28 @@ void CRSM<IDType>::_write(athena::io::IStreamWriter& w) const
w.writeBytes("CRSM", 4);
for (const auto& pair : x0_generators)
{
if (pair.second)
{
w.writeBytes(pair.first.toString().c_str(), 4);
pair.second.write(w);
}
w.writeBytes(pair.first.getChars(), 4);
pair.second.write(w);
}
for (const auto& pair : x10_sfx)
{
w.writeBytes(pair.first.getChars(), 4);
if (pair.second != ~0)
{
w.writeBytes(pair.first.toString().c_str(), 4);
w.writeBytes("CNST", 4);
w.writeUint32Big(pair.second);
}
else
{
w.writeBytes("NONE", 4);
}
}
for (const auto& pair : x20_decals)
{
if (pair.second)
{
w.writeBytes(pair.first.toString().c_str(), 4);
pair.second.write(w);
}
w.writeBytes(pair.first.getChars(), 4);
pair.second.write(w);
}
if (x30_RNGE != 50.f)

View File

@ -301,6 +301,8 @@ bool ViewManager::proc()
g_ResFactory->AsyncIdle();
if (!m_skipWait || !hecl::com_developer->toBoolean())
m_mainWindow->waitForRetrace(m_voiceEngine.get());
else
m_voiceEngine->pumpAndMixVoices();
CBooModel::ClearModelUniformCounters();
CGraphics::TickRenderTimings();
++logvisor::FrameIndex;

View File

@ -1,5 +1,7 @@
#include "CSortedLists.hpp"
#include "World/CActor.hpp"
#include "Weapon/CEnergyProjectile.hpp"
#include "TCastTo.hpp"
namespace urde
{
@ -75,8 +77,10 @@ void CSortedListManager::MoveInList(ESortedList list, s16 idx)
if (AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx + 1)).x4_box[int(list)] >=
AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx)).x4_box[int(list)])
return;
AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx + 1)).x1c_selfIdxs[int(list)] = idx + 1;
AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx + 1)).x1c_selfIdxs[int(list)] = idx;
AccessElement(x0_nodes, AccessElement(sl.x0_ids, idx)).x1c_selfIdxs[int(list)] = idx + 1;
std::swap(AccessElement(sl.x0_ids, idx), AccessElement(sl.x0_ids, idx + 1));
++idx;
}
}
}
@ -110,7 +114,7 @@ void CSortedListManager::InsertInList(ESortedList list, SNode& node)
/* Do insert */
AccessElement(sl.x0_ids, insIdx) = node.x0_actor->GetUniqueId().Value();
node.x1c_selfIdxs[int(list)] = insIdx;
node.x1c_selfIdxs[int(list)] = s16(insIdx);
++sl.x800_size;
}

View File

@ -26,7 +26,6 @@ CCameraManager::CCameraManager(TUniqueId curCameraId) : x0_curCameraId(curCamera
{
CSfxManager::AddListener(CSfxManager::ESfxChannels::Game, zeus::CVector3f::skZero, zeus::CVector3f::skZero,
{1.f, 0.f, 0.f}, {0.f, 0.f, 1.f}, 50.f, 50.f, 1000.f, 1, 1.f);
sAspect = float(g_Viewport.x8_width / g_Viewport.xc_height);
sFirstPersonFOV = g_tweakGame->GetFirstPersonFOV();
}

View File

@ -153,7 +153,7 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
const CActor* act = TCastToConstPtr<CActor>(mgr.GetObjectById(player->x310_orbitTargetId));
if (act && act->GetMaterialList().HasMaterial(EMaterialTypes::Orbit))
{
zeus::CVector3f v = player->x314_orbitPoint.y - eyePos;
zeus::CVector3f v = player->x314_orbitPoint - eyePos;
if (v.canBeNormalized())
v.normalize();

View File

@ -39,9 +39,9 @@ void CSkinRules::TransformVerticesCPU(std::vector<std::pair<zeus::CVector3f, zeu
{
const zeus::CTransform& xf = pose.GetRestToAccumTransform(w.m_id);
vertex += (xf * origVertex) * w.m_weight;
normal += (xf.basis.inverted().transposed() * origVertex) * w.m_weight;
normal += (xf.basis.inverted().transposed() * origNormal) * w.m_weight;
}
vnOut[i] = std::make_pair(vertex, normal);
vnOut[i] = std::make_pair(vertex, normal.normalized());
}
}

View File

@ -320,6 +320,7 @@ public:
zeus::CVector3f GetPoolNormal(size_t idx) const;
void ApplyVerticesCPU(const boo::ObjToken<boo::IGraphicsBufferD>& vertBuf,
const std::vector<std::pair<zeus::CVector3f, zeus::CVector3f>>& vn) const;
void RestoreVerticesCPU(const boo::ObjToken<boo::IGraphicsBufferD>& vertBuf) const;
void _WarmupShaders();
static void WarmupShaders(const SObjectTag& cmdlTag);

View File

@ -281,7 +281,7 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf)
m_instances.emplace_back();
ModelInstance& newInst = m_instances.back();
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx)
{
/* Build geometry uniform buffer if shared not available */
boo::ObjToken<boo::IGraphicsBufferD> geomUniformBuf;
@ -643,24 +643,47 @@ void CBooModel::DrawSurface(const CBooSurface& surf, const CModelFlags& flags) c
extended = flags.m_noCull ? (flags.m_noZWrite ?
EExtendedShader::ForcedAdditiveNoCullNoZWrite :
EExtendedShader::ForcedAdditiveNoCull) :
EExtendedShader::ForcedAdditive;
(flags.m_noZWrite ?
EExtendedShader::ForcedAdditiveNoZWrite :
EExtendedShader::ForcedAdditive);
else if (flags.x0_blendMode > 4)
extended = flags.m_noCull ? (flags.m_noZWrite ?
EExtendedShader::ForcedAlphaNoCullNoZWrite :
EExtendedShader::ForcedAlphaNoCull) :
EExtendedShader::ForcedAlpha;
(flags.m_noZWrite ?
EExtendedShader::ForcedAlphaNoZWrite :
EExtendedShader::ForcedAlpha);
else
extended = EExtendedShader::Lighting;
extended = flags.m_noCull ? (flags.m_noZWrite ?
EExtendedShader::ForcedAlphaNoCullNoZWrite :
EExtendedShader::ForcedAlphaNoCull) :
(flags.m_noZWrite ?
EExtendedShader::ForcedAlphaNoZWrite :
EExtendedShader::Lighting);
}
else if (flags.m_noCull && flags.m_noZWrite)
{
/* Substitute no-cull,no-zwrite pipeline if available */
if (data.heclIr.m_blendDst == boo::BlendFactor::One)
extended = EExtendedShader::ForcedAdditiveNoCullNoZWrite;
else
extended = EExtendedShader::ForcedAlphaNoCullNoZWrite;
}
else if (flags.m_noCull)
{
/* Substitute no-cull pipeline if available */
if (data.heclIr.m_blendDst == boo::BlendFactor::InvSrcAlpha)
extended = EExtendedShader::ForcedAlphaNoCull;
else if (data.heclIr.m_blendDst == boo::BlendFactor::One)
if (data.heclIr.m_blendDst == boo::BlendFactor::One)
extended = EExtendedShader::ForcedAdditiveNoCull;
else
extended = EExtendedShader::Lighting;
extended = EExtendedShader::ForcedAlphaNoCull;
}
else if (flags.m_noZWrite)
{
/* Substitute no-zwrite pipeline if available */
if (data.heclIr.m_blendDst == boo::BlendFactor::One)
extended = EExtendedShader::ForcedAdditiveNoZWrite;
else
extended = EExtendedShader::ForcedAlphaNoZWrite;
}
else
{
@ -1357,7 +1380,7 @@ size_t CModel::GetPoolVertexOffset(size_t idx) const
zeus::CVector3f CModel::GetPoolVertex(size_t idx) const
{
auto* floats = reinterpret_cast<const float*>(m_dynamicVertexData.get() + GetPoolVertexOffset(idx));
return {floats[0], floats[1], floats[2]};
return {floats};
}
size_t CModel::GetPoolNormalOffset(size_t idx) const
@ -1368,7 +1391,7 @@ size_t CModel::GetPoolNormalOffset(size_t idx) const
zeus::CVector3f CModel::GetPoolNormal(size_t idx) const
{
auto* floats = reinterpret_cast<const float*>(m_dynamicVertexData.get() + GetPoolNormalOffset(idx));
return {floats[0], floats[1], floats[2]};
return {floats};
}
void CModel::ApplyVerticesCPU(const boo::ObjToken<boo::IGraphicsBufferD>& vertBuf,
@ -1389,6 +1412,14 @@ void CModel::ApplyVerticesCPU(const boo::ObjToken<boo::IGraphicsBufferD>& vertBu
vertBuf->unmap();
}
void CModel::RestoreVerticesCPU(const boo::ObjToken<boo::IGraphicsBufferD>& vertBuf) const
{
size_t size = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount;
u8* data = reinterpret_cast<u8*>(vertBuf->map(size));
memcpy(data, m_dynamicVertexData.get(), size);
vertBuf->unmap();
}
void CModel::_WarmupShaders()
{
CBooModel::SetDummyTextures(true);

View File

@ -38,7 +38,8 @@ void CSkinnedModel::Calculate(const CPoseAsTransforms& pose,
{
if (morphEffect || g_PointGenFunc)
{
if (boo::ObjToken<boo::IGraphicsBufferD> vertBuf = m_modelInst->UpdateUniformData(drawFlags, nullptr, nullptr))
if (boo::ObjToken<boo::IGraphicsBufferD> vertBuf =
m_modelInst->UpdateUniformData(drawFlags, nullptr, nullptr))
{
x10_skinRules->TransformVerticesCPU(m_vertWorkspace, pose, *x4_model);
if (morphEffect)
@ -46,11 +47,20 @@ void CSkinnedModel::Calculate(const CPoseAsTransforms& pose,
if (g_PointGenFunc)
g_PointGenFunc(g_PointGenCtx, m_vertWorkspace);
x4_model->ApplyVerticesCPU(vertBuf, m_vertWorkspace);
m_modifiedVBO = true;
}
}
else
{
m_modelInst->UpdateUniformData(drawFlags, x10_skinRules.GetObj(), &pose);
if (boo::ObjToken<boo::IGraphicsBufferD> vertBuf =
m_modelInst->UpdateUniformData(drawFlags, x10_skinRules.GetObj(), &pose))
{
if (m_modifiedVBO)
{
x4_model->RestoreVerticesCPU(vertBuf);
m_modifiedVBO = false;
}
}
}
}

View File

@ -22,6 +22,7 @@ class CSkinnedModel
TLockedToken<CSkinRules> x10_skinRules;
TLockedToken<CCharLayoutInfo> x1c_layoutInfo;
std::vector<std::pair<zeus::CVector3f, zeus::CVector3f>> m_vertWorkspace;
bool m_modifiedVBO = false;
public:
enum class EDataOwnership
{

View File

@ -29,6 +29,8 @@ enum EExtendedShader : uint8_t
WorldShadow,
ForcedAlphaNoCull,
ForcedAdditiveNoCull,
ForcedAlphaNoZWrite,
ForcedAdditiveNoZWrite,
ForcedAlphaNoCullNoZWrite,
ForcedAdditiveNoCullNoZWrite
};

View File

@ -271,6 +271,18 @@ CModelShaders::GetShaderExtensionsGLSL(boo::IGraphicsDataFactory::Platform plat)
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::None, false, false, true);
/* Forced alpha shading without Z-write */
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"},
3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::Original, true, false, true);
/* Forced additive shading without Z-write */
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"},
3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::Original, true, false, true);
/* Forced alpha shading without culling or Z-write */
ext.registerExtensionSlot({LightingGLSL, "LightingFunc"}, {MainPostGLSL, "MainPostFunc"},
3, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,

View File

@ -251,6 +251,18 @@ CModelShaders::GetShaderExtensionsHLSL(boo::IGraphicsDataFactory::Platform plat)
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::None, false, false, true);
/* Forced alpha shading without Z-write */
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::Original, true, false, true);
/* Forced additive shading without Z-write */
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::Original, true, false, true);
/* Forced alpha shading without culling or Z-write */
ext.registerExtensionSlot({LightingHLSL, "LightingFunc"}, {MainPostHLSL, "MainPostFunc"},
0, nullptr, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,

View File

@ -261,6 +261,18 @@ CModelShaders::GetShaderExtensionsMetal(boo::IGraphicsDataFactory::Platform plat
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::None, false, false, true);
/* Forced alpha shading without Z-write */
ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"},
1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::Original, true, false, true);
/* Forced additive shading without Z-write */
ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"},
1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,
hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original,
hecl::Backend::CullMode::Original, true, false, true);
/* Forced alpha shading without culling or Z-write */
ext.registerExtensionSlot({LightingMetal, "LightingFunc"}, {MainPostMetal, "MainPostFunc"},
1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha,

View File

@ -350,9 +350,9 @@ void CCompoundTargetReticle::UpdateCurrLockOnGroup(float dt, const CStateManager
IsGrappleTarget(targetId, mgr) ? g_tweakTargeting->GetGrappleMinClampScale() : 1.f, false);
x16c_currGroupDur = xf0_targetId == kInvalidUniqueId ? g_tweakTargeting->GetCurrLockOnExitDuration() :
g_tweakTargeting->GetCurrLockOnSwitchDuration();
x170_currGroupTimer = x16c_currGroupDur;
xf0_targetId = targetId;
}
x170_currGroupTimer = x16c_currGroupDur;
xf0_targetId = targetId;
}
if (x170_currGroupTimer > 0.f)
{
@ -581,7 +581,7 @@ void CCompoundTargetReticle::DrawCurrLockOnGroup(const zeus::CMatrix3f& rot, con
zeus::CMatrix3f lockBreakXf;
zeus::CColor lockBreakColor = zeus::CColor::skClear;
if (IsDamageOrbit(mgr.GetPlayer().GetOrbitRequest()) && x14c_currGroupB.GetFactor() == 0)
if (IsDamageOrbit(mgr.GetPlayer().GetOrbitRequest()) && x14c_currGroupB.GetFactor() == 0.f)
{
zeus::CMatrix3f lockBreakRM;
for (int i=0 ; i<4 ; ++i)

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

@ -53,7 +53,7 @@ public:
bool xa4_EWTR = true;
bool xa5_LWTR = true;
bool xa6_SWTR = true;
s32 xa8_PJFX;
s32 xa8_PJFX = -1;
std::unique_ptr<CRealElement> xac_RNGE;
std::unique_ptr<CRealElement> xb0_FOFF;
};

View File

@ -31,14 +31,14 @@ CEnergyProjectile::CEnergyProjectile(bool active, const TToken<CWeaponDescriptio
void CEnergyProjectile::PlayImpactSound(const zeus::CVector3f& pos, EWeaponCollisionResponseTypes type)
{
u16 sfxId = x170_projectile.GetSoundIdForCollision(type);
if (sfxId >= 0.f)
s32 sfxId = x170_projectile.GetSoundIdForCollision(type);
if (sfxId >= 0)
{
CAudioSys::C3DEmitterParmData parmData = {};
parmData.x18_maxDist = x170_projectile.GetAudibleRange();
parmData.x1c_distComp = x170_projectile.GetAudibleFallOff();
parmData.x20_flags = 0x1; // Continuous parameter update
parmData.x24_sfxId = CSfxManager::TranslateSFXID(sfxId);
parmData.x24_sfxId = CSfxManager::TranslateSFXID(u16(sfxId));
parmData.x26_maxVol = 1.f;
parmData.x27_minVol = 0.16f;
parmData.x29_prio = 0x7f;

View File

@ -168,11 +168,11 @@ CProjectileWeapon::GetDecalForCollision(EWeaponCollisionResponseTypes type) cons
return x4_weaponDesc->x94_COLR.m_res->GetDecalDescription(type);
}
u16 CProjectileWeapon::GetSoundIdForCollision(EWeaponCollisionResponseTypes type) const
s32 CProjectileWeapon::GetSoundIdForCollision(EWeaponCollisionResponseTypes type) const
{
if (!x4_weaponDesc->x94_COLR)
return 0xffff;
return u16(x4_weaponDesc->x94_COLR.m_res->GetSoundEffectId(type));
return -1;
return x4_weaponDesc->x94_COLR.m_res->GetSoundEffectId(type);
}
std::experimental::optional<TLockedToken<CGenDescription>>

View File

@ -78,7 +78,7 @@ public:
float GetAudibleRange() const;
std::experimental::optional<TLockedToken<CDecalDescription>>
GetDecalForCollision(EWeaponCollisionResponseTypes type) const;
u16 GetSoundIdForCollision(EWeaponCollisionResponseTypes type) const;
s32 GetSoundIdForCollision(EWeaponCollisionResponseTypes type) const;
std::experimental::optional<TLockedToken<CGenDescription>>
CollisionOccured(EWeaponCollisionResponseTypes type, bool deflected, bool useTarget, const zeus::CVector3f& pos,
const zeus::CVector3f& normal, const zeus::CVector3f& target);

View File

@ -723,6 +723,7 @@ void CWorld::DrawSky(const zeus::CTransform& xf) const
CGraphics::SetDepthRange(DEPTH_SKY, DEPTH_FAR);
CModelFlags flags(0, 0, 1, zeus::CColor::skWhite);
flags.m_noZWrite = true;
model->Draw(flags);
CGraphics::SetDepthRange(DEPTH_WORLD, DEPTH_FAR);

2
hecl

@ -1 +1 @@
Subproject commit 29830aacb55bd35f05e9ef79e087b9363c01c95a
Subproject commit ed2e587c3af34009200dbb2e6eb5f3e376479a4c

@ -1 +1 @@
Subproject commit e3901665c3a2984f51aad77fb4920858e87f2764
Subproject commit 498c570050df733cb7c8a97c262d76920b5aac16