2016-07-29 17:00:23 +00:00
|
|
|
#include "CMappableObject.hpp"
|
2016-07-31 01:43:34 +00:00
|
|
|
#include "GameGlobalObjects.hpp"
|
2017-04-22 06:42:32 +00:00
|
|
|
#include "CMapWorldInfo.hpp"
|
|
|
|
#include "CSimplePool.hpp"
|
|
|
|
#include "CToken.hpp"
|
|
|
|
#include "Graphics/CTexture.hpp"
|
2016-07-29 17:00:23 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
const zeus::CVector3f CMappableObject::skDoorVerts[8] = {};
|
|
|
|
|
2017-04-22 06:42:32 +00:00
|
|
|
static const u32 DoorIndices[] =
|
|
|
|
{
|
|
|
|
6, 4, 2, 0,
|
|
|
|
3, 1, 7, 5,
|
|
|
|
1, 0, 5, 4,
|
|
|
|
7, 6, 3, 2,
|
|
|
|
3, 2, 1, 0,
|
|
|
|
5, 4, 7, 6
|
|
|
|
};
|
|
|
|
|
|
|
|
CMappableObject::CMappableObject(const void* buf)
|
|
|
|
{
|
|
|
|
athena::io::MemoryReader r(buf, 64);
|
|
|
|
x0_type = EMappableObjectType(r.readUint32Big());
|
2017-04-22 21:46:18 +00:00
|
|
|
x4_visibilityMode = EVisMode(r.readUint32Big());
|
2017-04-22 06:42:32 +00:00
|
|
|
x8_objId = r.readUint32Big();
|
|
|
|
xc_ = r.readUint32Big();
|
|
|
|
x10_transform.read34RowMajor(r);
|
|
|
|
}
|
|
|
|
|
2016-07-31 01:43:34 +00:00
|
|
|
zeus::CTransform CMappableObject::AdjustTransformForType()
|
|
|
|
{
|
2016-08-02 06:19:52 +00:00
|
|
|
const float doorCenterX = g_tweakAutoMapper->GetDoorCenter().x;
|
|
|
|
const float doorCenterZ = g_tweakAutoMapper->GetDoorCenter().z;
|
|
|
|
if (x0_type == EMappableObjectType::BigDoor1)
|
2016-07-31 01:43:34 +00:00
|
|
|
{
|
2016-07-31 19:29:07 +00:00
|
|
|
zeus::CTransform orientation;
|
2016-08-01 04:35:42 +00:00
|
|
|
orientation.origin = {-1.4f*doorCenterX, 0.0f, 0.0f};
|
2016-07-31 19:29:07 +00:00
|
|
|
orientation.rotateLocalZ(zeus::degToRad(90.0f));
|
2017-04-22 06:42:32 +00:00
|
|
|
return (x10_transform * orientation) * zeus::CTransform::Scale(zeus::CVector3f{1.5f});
|
2016-07-31 01:43:34 +00:00
|
|
|
}
|
2016-08-02 06:19:52 +00:00
|
|
|
else if (x0_type == EMappableObjectType::BigDoor2)
|
2016-07-31 01:43:34 +00:00
|
|
|
{
|
2016-08-02 06:19:52 +00:00
|
|
|
zeus::CTransform orientation;
|
|
|
|
orientation.origin = {0.f, -2.0f * doorCenterZ, -1.4f * doorCenterX};
|
|
|
|
orientation.rotateLocalZ(zeus::degToRad(-90.f));
|
|
|
|
return (x10_transform * orientation) * zeus::CTransform::Scale(zeus::CVector3f{1.5f});
|
|
|
|
}
|
|
|
|
else if (x0_type == EMappableObjectType::IceDoorCeiling || x0_type == EMappableObjectType::WaveDoorCeiling
|
|
|
|
|| x0_type == EMappableObjectType::PlasmaDoorCeiling)
|
|
|
|
{
|
|
|
|
zeus::CTransform orientation;
|
2016-08-03 23:16:31 +00:00
|
|
|
orientation.origin = {-1.65f * doorCenterX, 0.f, -1.5f * doorCenterZ};
|
2016-08-02 06:19:52 +00:00
|
|
|
orientation.rotateLocalY(zeus::degToRad(90.f));
|
|
|
|
return x10_transform * orientation;
|
2016-07-31 01:43:34 +00:00
|
|
|
}
|
2016-08-02 06:19:52 +00:00
|
|
|
else if (x0_type == EMappableObjectType::IceDoorFloor || x0_type == EMappableObjectType::WaveDoorFloor
|
|
|
|
|| x0_type == EMappableObjectType::PlasmaDoorFloor)
|
2016-07-31 01:43:34 +00:00
|
|
|
{
|
2016-08-02 06:19:52 +00:00
|
|
|
zeus::CTransform orientation;
|
2016-08-03 23:16:31 +00:00
|
|
|
orientation.origin = {-1.65f * doorCenterX, 0.f, -1.f * doorCenterZ};
|
2016-08-02 06:19:52 +00:00
|
|
|
orientation.rotateLocalY(zeus::degToRad(90.f));
|
|
|
|
return x10_transform * orientation;
|
2016-07-31 01:43:34 +00:00
|
|
|
}
|
2016-08-02 06:19:52 +00:00
|
|
|
else if ((u32(x0_type) - u32(EMappableObjectType::IceDoorFloor2)) <= u32(EMappableObjectType::ShieldDoor)
|
2017-04-22 06:42:32 +00:00
|
|
|
|| x0_type == EMappableObjectType::PlasmaDoorFloor2)
|
2016-07-31 01:43:34 +00:00
|
|
|
{
|
2016-08-02 06:19:52 +00:00
|
|
|
zeus::CTransform orientation;
|
2016-08-03 23:16:31 +00:00
|
|
|
orientation.origin = {-0.49f * doorCenterX, 0.f, -1.f * doorCenterZ};
|
2016-08-02 06:19:52 +00:00
|
|
|
orientation.rotateLocalY(zeus::degToRad(90.f));
|
|
|
|
return x10_transform * orientation;
|
2016-07-31 01:43:34 +00:00
|
|
|
}
|
2017-04-22 06:42:32 +00:00
|
|
|
else if (x0_type >= EMappableObjectType::BlueDoor || x0_type <= EMappableObjectType::PlasmaDoorFloor2)
|
2016-07-31 01:43:34 +00:00
|
|
|
{
|
2016-08-02 06:19:52 +00:00
|
|
|
zeus::CMatrix4f tmp = x10_transform.toMatrix4f().transposed();
|
|
|
|
return zeus::CTransform::Translate(tmp.m[1][0], tmp.m[2][1], tmp[3][2]);
|
2016-07-31 01:43:34 +00:00
|
|
|
}
|
2016-08-02 06:19:52 +00:00
|
|
|
return x10_transform;
|
2016-07-31 01:43:34 +00:00
|
|
|
}
|
|
|
|
|
2017-04-22 06:42:32 +00:00
|
|
|
std::pair<zeus::CColor, zeus::CColor>
|
|
|
|
CMappableObject::GetDoorColors(int curAreaId, const CMapWorldInfo& mwInfo, float alpha) const
|
2016-07-31 01:43:34 +00:00
|
|
|
{
|
2017-04-22 06:42:32 +00:00
|
|
|
zeus::CColor color = {1.f, 0.f, 1.f, 1.f};
|
|
|
|
if (x8_objId.AreaNum() == curAreaId)
|
2016-07-31 01:43:34 +00:00
|
|
|
{
|
2017-04-22 06:42:32 +00:00
|
|
|
if (mwInfo.IsDoorVisited(x8_objId) && x0_type == EMappableObjectType::ShieldDoor)
|
|
|
|
{
|
|
|
|
color = g_tweakAutoMapper->GetDoorColor(0);
|
|
|
|
}
|
|
|
|
else
|
2016-07-31 01:43:34 +00:00
|
|
|
{
|
2017-04-22 06:42:32 +00:00
|
|
|
int colorIdx = 0;
|
|
|
|
switch (x0_type)
|
|
|
|
{
|
|
|
|
case EMappableObjectType::ShieldDoor:
|
|
|
|
colorIdx = 1;
|
|
|
|
break;
|
|
|
|
case EMappableObjectType::IceDoor:
|
|
|
|
case EMappableObjectType::IceDoorCeiling:
|
|
|
|
case EMappableObjectType::IceDoorFloor:
|
|
|
|
case EMappableObjectType::IceDoorFloor2:
|
|
|
|
colorIdx = 2;
|
|
|
|
break;
|
|
|
|
case EMappableObjectType::WaveDoor:
|
|
|
|
case EMappableObjectType::WaveDoorCeiling:
|
|
|
|
case EMappableObjectType::WaveDoorFloor:
|
|
|
|
case EMappableObjectType::WaveDoorFloor2:
|
|
|
|
colorIdx = 3;
|
|
|
|
break;
|
|
|
|
case EMappableObjectType::PlasmaDoor:
|
|
|
|
case EMappableObjectType::PlasmaDoorCeiling:
|
|
|
|
case EMappableObjectType::PlasmaDoorFloor:
|
|
|
|
case EMappableObjectType::PlasmaDoorFloor2:
|
|
|
|
colorIdx = 4;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
color = g_tweakAutoMapper->GetDoorColor(colorIdx);
|
2016-07-31 01:43:34 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-22 06:42:32 +00:00
|
|
|
else if (mwInfo.IsDoorVisited(x8_objId))
|
|
|
|
{
|
|
|
|
color = g_tweakAutoMapper->GetOpenDoorColor();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
color = zeus::CColor::skClear;
|
|
|
|
}
|
|
|
|
|
|
|
|
color.a *= alpha;
|
|
|
|
return {color, zeus::CColor(std::min(1.4f * color.r, 1.f),
|
|
|
|
std::min(1.4f * color.g, 1.f),
|
|
|
|
std::min(1.4f * color.b, 1.f),
|
|
|
|
std::min(1.4f * color.a, 1.f))};
|
|
|
|
}
|
2016-07-31 01:43:34 +00:00
|
|
|
|
2017-04-22 06:42:32 +00:00
|
|
|
void CMappableObject::PostConstruct(const void *)
|
|
|
|
{
|
2016-08-02 06:19:52 +00:00
|
|
|
x10_transform = AdjustTransformForType();
|
|
|
|
}
|
|
|
|
|
2017-04-22 06:42:32 +00:00
|
|
|
void CMappableObject::Draw(int curArea, const CMapWorldInfo& mwInfo,
|
|
|
|
float alpha, bool needsVtxLoad) const
|
2016-08-02 06:19:52 +00:00
|
|
|
{
|
2017-04-22 06:42:32 +00:00
|
|
|
if (IsDoorType(x0_type))
|
|
|
|
{
|
|
|
|
std::pair<zeus::CColor, zeus::CColor> colors = GetDoorColors(curArea, mwInfo, alpha);
|
|
|
|
for (int s=0 ; s<6 ; ++s)
|
|
|
|
{
|
|
|
|
DoorSurface& ds = const_cast<DoorSurface&>(*m_doorSurface);
|
|
|
|
ds.m_surface.draw(colors.first, s * 4, 4);
|
|
|
|
CLineRenderer& line = ds.m_outline;
|
|
|
|
const u32* baseIdx = &DoorIndices[s * 4];
|
|
|
|
line.Reset();
|
|
|
|
line.AddVertex(skDoorVerts[baseIdx[0]], colors.second, 1.f);
|
|
|
|
line.AddVertex(skDoorVerts[baseIdx[1]], colors.second, 1.f);
|
|
|
|
line.AddVertex(skDoorVerts[baseIdx[2]], colors.second, 1.f);
|
|
|
|
line.AddVertex(skDoorVerts[baseIdx[3]], colors.second, 1.f);
|
|
|
|
line.Render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ResId iconRes;
|
|
|
|
zeus::CColor iconColor = zeus::CColor::skWhite;
|
|
|
|
switch (x0_type)
|
|
|
|
{
|
|
|
|
case EMappableObjectType::DownArrowYellow:
|
|
|
|
iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon;
|
|
|
|
iconColor = zeus::CColor{1.f, 1.f, 0.588f, 1.f};
|
|
|
|
break;
|
|
|
|
case EMappableObjectType::UpArrowYellow:
|
|
|
|
iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon;
|
|
|
|
iconColor = zeus::CColor{1.f, 1.f, 0.588f, 1.f};
|
|
|
|
break;
|
|
|
|
case EMappableObjectType::DownArrowGreen:
|
|
|
|
iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon;
|
|
|
|
iconColor = zeus::CColor{0.392f, 1.f, 0.588f, 1.f};
|
|
|
|
break;
|
|
|
|
case EMappableObjectType::UpArrowGreen:
|
|
|
|
iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon;
|
|
|
|
iconColor = zeus::CColor{0.392f, 1.f, 0.588f, 1.f};
|
|
|
|
break;
|
|
|
|
case EMappableObjectType::DownArrowRed:
|
|
|
|
iconRes = g_tweakPlayerRes->x10_minesBreakFirstTopIcon;
|
|
|
|
iconColor = zeus::CColor{1.f, 0.392f, 0.588f, 1.f};
|
|
|
|
break;
|
|
|
|
case EMappableObjectType::UpArrowRed:
|
|
|
|
iconRes = g_tweakPlayerRes->x14_minesBreakFirstBottomIcon;
|
|
|
|
iconColor = zeus::CColor{1.f, 0.392f, 0.588f, 1.f};
|
|
|
|
break;
|
|
|
|
case EMappableObjectType::SaveStation:
|
|
|
|
iconRes = g_tweakPlayerRes->x4_saveStationIcon;
|
|
|
|
break;
|
|
|
|
case EMappableObjectType::MissileStation:
|
|
|
|
iconRes = g_tweakPlayerRes->x8_missileStationIcon;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
iconRes = g_tweakPlayerRes->xc_elevatorIcon;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
iconColor.a *= alpha;
|
|
|
|
|
|
|
|
TLockedToken<CTexture> tex = g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), iconRes});
|
|
|
|
if (!m_texQuadFilter || m_texQuadFilter->GetTex().GetObj() != tex.GetObj())
|
2017-06-01 05:34:24 +00:00
|
|
|
const_cast<CMappableObject*>(this)->m_texQuadFilter.emplace(EFilterType::Blend, tex);
|
2017-04-22 06:42:32 +00:00
|
|
|
|
|
|
|
CTexturedQuadFilter::Vert verts[4] =
|
|
|
|
{
|
|
|
|
{{-2.6f, 0.f, 2.6f}, {0.f, 1.f}},
|
|
|
|
{{-2.6f, 0.f, -2.6f}, {0.f, 0.f}},
|
|
|
|
{{2.6f, 0.f, 2.6f}, {1.f, 1.f}},
|
|
|
|
{{2.6f, 0.f, -2.6f}, {1.f, 0.f}}
|
|
|
|
};
|
|
|
|
const_cast<CMappableObject*>(this)->m_texQuadFilter->drawVerts(iconColor, verts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMappableObject::DrawDoorSurface(int curArea, const CMapWorldInfo& mwInfo,
|
|
|
|
float alpha, int surfIdx, bool needsVtxLoad) const
|
|
|
|
{
|
|
|
|
std::pair<zeus::CColor, zeus::CColor> colors = GetDoorColors(curArea, mwInfo, alpha);
|
|
|
|
DoorSurface& ds = const_cast<DoorSurface&>(*m_doorSurface);
|
|
|
|
ds.m_surface.draw(colors.first, surfIdx * 4, 4);
|
|
|
|
CLineRenderer& line = ds.m_outline;
|
|
|
|
const u32* baseIdx = &DoorIndices[surfIdx * 4];
|
|
|
|
line.Reset();
|
|
|
|
line.AddVertex(skDoorVerts[baseIdx[0]], colors.second, 1.f);
|
|
|
|
line.AddVertex(skDoorVerts[baseIdx[1]], colors.second, 1.f);
|
|
|
|
line.AddVertex(skDoorVerts[baseIdx[2]], colors.second, 1.f);
|
|
|
|
line.AddVertex(skDoorVerts[baseIdx[3]], colors.second, 1.f);
|
|
|
|
line.Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CVector3f CMappableObject::BuildSurfaceCenterPoint(int surfIdx) const
|
|
|
|
{
|
|
|
|
const zeus::CVector3f& doorCenter = g_tweakAutoMapper->GetDoorCenter();
|
|
|
|
|
|
|
|
switch (surfIdx)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return x10_transform * zeus::CVector3f::skZero;
|
|
|
|
case 1:
|
|
|
|
return x10_transform * zeus::CVector3f{0.f, 0.f, 2.f * doorCenter.x};
|
|
|
|
case 2:
|
|
|
|
return x10_transform * zeus::CVector3f{0.f, -doorCenter.y, 0.f};
|
|
|
|
case 3:
|
|
|
|
return x10_transform * zeus::CVector3f{0.f, doorCenter.y, 0.f};
|
|
|
|
case 4:
|
|
|
|
return x10_transform * zeus::CVector3f{-doorCenter.x, 0.f, 0.f};
|
|
|
|
case 5:
|
|
|
|
return x10_transform * zeus::CVector3f{doorCenter.x, 0.f, 0.f};
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2016-08-02 06:19:52 +00:00
|
|
|
return {};
|
2016-07-31 01:43:34 +00:00
|
|
|
}
|
|
|
|
|
2017-04-22 21:46:18 +00:00
|
|
|
bool CMappableObject::IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& mwInfo) const
|
|
|
|
{
|
|
|
|
bool areaVis = mwInfo.IsAreaVisible(x8_objId.AreaNum());
|
|
|
|
switch (x4_visibilityMode)
|
|
|
|
{
|
|
|
|
case EVisMode::Always:
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
case EVisMode::MapStationOrVisit:
|
|
|
|
case EVisMode::MapStationOrVisit2:
|
|
|
|
return worldVis || areaVis;
|
|
|
|
case EVisMode::Visit:
|
|
|
|
if (IsDoorType(x0_type))
|
|
|
|
return mwInfo.IsDoorVisited(x8_objId);
|
|
|
|
return areaVis;
|
|
|
|
case EVisMode::Never:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-22 06:42:32 +00:00
|
|
|
boo::GraphicsDataToken CMappableObject::g_gfxToken = {};
|
|
|
|
boo::IGraphicsBufferS* CMappableObject::g_doorVbo;
|
|
|
|
boo::IGraphicsBufferS* CMappableObject::g_doorIbo;
|
|
|
|
|
2016-07-29 17:00:23 +00:00
|
|
|
void CMappableObject::ReadAutoMapperTweaks(const ITweakAutoMapper& tweaks)
|
|
|
|
{
|
|
|
|
const zeus::CVector3f& center = tweaks.GetDoorCenter();
|
2016-07-31 01:43:34 +00:00
|
|
|
zeus::CVector3f* doorVerts = const_cast<zeus::CVector3f*>(&CMappableObject::skDoorVerts[0]);
|
2016-07-29 17:00:23 +00:00
|
|
|
/* Wrap door verts around -Z to build surface */
|
|
|
|
doorVerts[0].assign( -center.z, -center.y, 0.f);
|
|
|
|
doorVerts[1].assign( -center.z, -center.y, 2.f * center.x);
|
|
|
|
doorVerts[2].assign( -center.z, center.y, 0.f);
|
|
|
|
doorVerts[3].assign( -center.z, center.y, 2.f * center.x);
|
|
|
|
doorVerts[4].assign(.2f * -center.z, -center.y, 0.f);
|
|
|
|
doorVerts[5].assign(.2f * -center.z, -center.y, 2.f * center.x);
|
|
|
|
doorVerts[6].assign(.2f * -center.z, center.y, 0.f);
|
|
|
|
doorVerts[7].assign(.2f * -center.z, center.y, 2.f * center.x);
|
2017-04-22 06:42:32 +00:00
|
|
|
|
|
|
|
g_gfxToken = CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx)
|
|
|
|
{
|
|
|
|
g_doorVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, skDoorVerts, 16, 8);
|
|
|
|
g_doorIbo = ctx.newStaticBuffer(boo::BufferUse::Index, DoorIndices, 4, 24);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMappableObject::Shutdown()
|
|
|
|
{
|
|
|
|
g_gfxToken.doDestroy();
|
2016-07-29 17:00:23 +00:00
|
|
|
}
|
|
|
|
}
|