Finish CMapWorld and CMapUniverse rendering

This commit is contained in:
Jack Andersen 2017-04-24 15:11:31 -10:00
parent 72cac044d3
commit 53c01af8e9
10 changed files with 278 additions and 78 deletions

View File

@ -24,6 +24,8 @@ struct ITweakAutoMapper : public ITweak
virtual const zeus::CColor& GetOutlineUnvisitedColor() const=0;
virtual const zeus::CColor& GetSurfaceSelectVisitedColor() const=0;
virtual const zeus::CColor& GetOutlineSelectVisitedColor() const=0;
virtual float GetMapSurfaceNormColorLinear() const=0;
virtual float GetMapSurfaceNormColorConstant() const=0;
virtual float GetOpenMapScreenTime() const=0;
virtual float GetCloseMapScreenTime() const=0;
virtual float GetHintPanTime() const=0;

View File

@ -33,8 +33,8 @@ struct CTweakAutoMapper : public ITweakAutoMapper
DNAColor x48_outlineColorUnvisited;
DNAColor x4c_surfaceSelectColorVisited;
DNAColor x50_outlineSelectColorVisited;
Value<float> x54_;
Value<float> x58_;
Value<float> x54_mapSurfaceNormColorLinear;
Value<float> x58_mapSurfaceNormColorConstant;
Value<float> x5c_;
float x60_ = 0.4f;
Value<float> x64_openMapScreenTime;
@ -99,6 +99,8 @@ struct CTweakAutoMapper : public ITweakAutoMapper
const zeus::CColor& GetOutlineUnvisitedColor() const { return x48_outlineColorUnvisited; }
const zeus::CColor& GetSurfaceSelectVisitedColor() const { return x4c_surfaceSelectColorVisited; }
const zeus::CColor& GetOutlineSelectVisitedColor() const { return x50_outlineSelectColorVisited; }
float GetMapSurfaceNormColorLinear() const { return x54_mapSurfaceNormColorLinear; }
float GetMapSurfaceNormColorConstant() const { return x58_mapSurfaceNormColorConstant; }
float GetOpenMapScreenTime() const { return x64_openMapScreenTime; }
float GetCloseMapScreenTime() const { return x68_closeMapScreenTime; }
float GetHintPanTime() const { return x6c_hintPanTime; }

View File

@ -38,11 +38,12 @@ void CMapArea::PostConstruct()
}
u8* tmp = x3c_vertexStart;
for (u32 i = 0 ; i<(x2c_vertexCount*3) ; ++i)
m_verts.reserve(x2c_vertexCount);
for (u32 i = 0 ; i<x2c_vertexCount ; ++i)
{
float* fl = reinterpret_cast<float*>(tmp);
*fl = hecl::SBig(*fl);
tmp += 4;
m_verts.emplace_back(hecl::SBig(fl[0]), hecl::SBig(fl[1]), hecl::SBig(fl[2]));
tmp += 12;
}
std::vector<u32> index;
@ -57,8 +58,38 @@ void CMapArea::PostConstruct()
{
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, x3c_vertexStart, 12, x2c_vertexCount);
m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, index.data(), 4, index.size());
/* Only the map universe specifies Always; it draws a maximum of 133 instances */
size_t instCount = (xc_visibilityMode == EVisMode::Always) ? 133 : 1;
for (u32 i = 0 ; i<x30_surfaceCount ; ++i)
m_surfaces[i].m_surfacePrims.emplace(ctx, m_vbo, m_ibo);
{
CMapAreaSurface& surf = m_surfaces[i];
surf.m_instances.reserve(instCount);
for (u32 inst = 0 ; inst < instCount ; ++inst)
{
surf.m_instances.emplace_back(ctx, m_vbo, m_ibo);
CMapAreaSurface::Instance& instance = surf.m_instances.back();
athena::io::MemoryReader r(surf.x1c_outlineOffset, INT_MAX);
u32 outlineCount = r.readUint32Big();
std::vector<CLineRenderer>& linePrims = instance.m_linePrims;
linePrims.reserve(outlineCount * 2);
for (u32 j=0 ; j<2 ; ++j)
{
r.seek(4, athena::SeekOrigin::Begin);
for (u32 i=0 ; i<outlineCount ; ++i)
{
u32 count = r.readUint32Big();
r.seek(count);
r.seekAlign4();
linePrims.emplace_back(ctx, CLineRenderer::EPrimitiveMode::LineStrip, count, nullptr, false);
}
}
}
}
for (u32 i = 0 ; i<x28_mappableObjCount ; ++i)
{
CMappableObject& mapObj = m_mappableObjects[i];
@ -251,42 +282,20 @@ void CMapArea::CMapAreaSurface::PostConstruct(const u8* buf, std::vector<u32>& i
}
void CMapArea::CMapAreaSurface::Draw(const zeus::CVector3f* verts, const zeus::CColor& surfColor,
const zeus::CColor& lineColor, float lineWidth) const
const zeus::CColor& lineColor, float lineWidth, int instIdx) const
{
Instance& instance = const_cast<Instance&>(m_instances[instIdx]);
if (surfColor.a)
const_cast<CMapSurfaceShader&>(*m_surfacePrims).draw(surfColor, m_primStart, m_primCount);
instance.m_surfacePrims.draw(surfColor, m_primStart, m_primCount);
if (lineColor.a)
{
bool draw2 = lineWidth > 1.f;
int totalPrims = draw2 + 1;
athena::io::MemoryReader r(x1c_outlineOffset, INT_MAX);
u32 outlineCount = r.readUint32Big();
totalPrims *= outlineCount;
std::vector<CLineRenderer>& linePrims = const_cast<std::vector<CLineRenderer>&>(m_linePrims);
if (linePrims.size() < totalPrims)
{
linePrims.clear();
linePrims.reserve(totalPrims);
const_cast<CMapAreaSurface*>(this)->m_lineToken =
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx)
{
for (u32 j=0 ; j<=draw2 ; ++j)
{
r.seek(4, athena::SeekOrigin::Begin);
for (u32 i=0 ; i<outlineCount ; ++i)
{
u32 count = r.readUint32Big();
r.seek(count);
r.seekAlign4();
linePrims.emplace_back(ctx, CLineRenderer::EPrimitiveMode::LineStrip, count, nullptr, false);
}
}
return true;
});
}
std::vector<CLineRenderer>& linePrims = instance.m_linePrims;
zeus::CColor color = lineColor;
if (draw2)
color.a *= 0.5f;

View File

@ -25,15 +25,20 @@ public:
const u8* x1c_outlineOffset;
u32 m_primStart;
u32 m_primCount;
std::experimental::optional<CMapSurfaceShader> m_surfacePrims;
std::vector<CLineRenderer> m_linePrims;
boo::GraphicsDataToken m_lineToken;
struct Instance
{
CMapSurfaceShader m_surfacePrims;
std::vector<CLineRenderer> m_linePrims;
Instance(boo::IGraphicsDataFactory::Context& ctx, boo::IGraphicsBufferS* vbo, boo::IGraphicsBufferS* ibo)
: m_surfacePrims(ctx, vbo, ibo) {}
};
std::vector<Instance> m_instances;
public:
CMapAreaSurface(const void* surfBuf);
CMapAreaSurface(CMapAreaSurface&&) = default;
void PostConstruct(const u8* buf, std::vector<u32>& index);
void Draw(const zeus::CVector3f* verts, const zeus::CColor& surfColor,
const zeus::CColor& lineColor, float lineWidth) const;
const zeus::CColor& lineColor, float lineWidth, int instIdx=0) const;
const zeus::CVector3f& GetNormal() const { return x0_normal; }
const zeus::CVector3f& GetCenterPosition() const { return xc_centroid; }
};
@ -58,6 +63,7 @@ private:
u8* x38_moStart;
std::vector<CMappableObject> m_mappableObjects;
u8* x3c_vertexStart;
std::vector<zeus::CVector3f> m_verts;
u8* x40_surfaceStart;
std::vector<CMapAreaSurface> m_surfaces;
std::unique_ptr<u8[]> x44_buf;
@ -77,6 +83,7 @@ public:
u32 GetNumSurfaces() const { return m_surfaces.size(); }
zeus::CTransform GetAreaPostTransform(const IWorld& world, TAreaId aid) const;
static const zeus::CVector3f& GetAreaPostTranslate(const IWorld& world, TAreaId aid);
const zeus::CVector3f* GetVertices() const { return m_verts.data(); }
};
CFactoryFnReturn FMapAreaFactory(const SObjectTag& objTag, CInputStream& in, const CVParamTransfer&,

View File

@ -1,6 +1,7 @@
#include "CMapUniverse.hpp"
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp"
#include "CGameState.hpp"
namespace urde
{
@ -29,13 +30,13 @@ CMapUniverse::CMapWorldData::CMapWorldData(CInputStream& in, u32 version)
}
if (version != 0)
x54_.readRGBABig(in);
x54_surfColorSelected.readRGBABig(in);
else
x54_.fromRGBA32(255 | (x10_worldAssetId & 0xFFFFFF00));
x54_surfColorSelected.fromRGBA32(255 | (x10_worldAssetId & 0xFFFFFF00));
x58_ = zeus::CColor::lerp(zeus::CColor::skWhite, x54_, 0.5f);
x5c_ = zeus::CColor::lerp(zeus::CColor::skBlack, x54_, 0.5f);
x60_ = zeus::CColor::lerp(zeus::CColor::skWhite, x5c_, 0.5f);
x58_outlineColorSelected = zeus::CColor::lerp(zeus::CColor::skWhite, x54_surfColorSelected, 0.5f);
x5c_surfColorUnselected = zeus::CColor::lerp(zeus::CColor::skBlack, x54_surfColorSelected, 0.5f);
x60_outlineColorUnselected = zeus::CColor::lerp(zeus::CColor::skWhite, x5c_surfColorUnselected, 0.5f);
for (const zeus::CTransform& xf : x44_hexagonXfs)
x64_centerPoint += xf.origin;
@ -45,7 +46,88 @@ CMapUniverse::CMapWorldData::CMapWorldData(CInputStream& in, u32 version)
void CMapUniverse::Draw(const CMapUniverseDrawParms& parms, const zeus::CVector3f&, float, float) const
{
if (!x4_hexagonToken.IsLoaded())
return;
u32 totalSurfaceCount = 0;
for (const CMapWorldData& data : x10_worldDatas)
totalSurfaceCount += data.GetNumMapAreaDatas() * x4_hexagonToken->GetNumSurfaces();
std::vector<CMapObjectSortInfo> sortInfos;
sortInfos.reserve(totalSurfaceCount);
for (int w=0 ; w<x10_worldDatas.size() ; ++w)
{
const CMapWorldData& data = x10_worldDatas[w];
const CMapWorldInfo& mwInfo = *g_GameState->StateForWorld(data.GetWorldAssetId()).MapWorldInfo();
if (!mwInfo.IsAnythingSet())
continue;
zeus::CColor surfColor, outlineColor;
if (w == parms.GetFocusWorldIndex())
{
surfColor = data.GetSurfaceColorSelected();
surfColor.a *= parms.GetAlpha();
outlineColor = data.GetOutlineColorSelected();
outlineColor.a *= parms.GetAlpha();
}
else
{
surfColor = data.GetSurfaceColorUnselected();
surfColor.a *= parms.GetAlpha();
outlineColor = data.GetSurfaceColorUnselected();
outlineColor.a *= parms.GetAlpha();
}
for (int h=0 ; h<data.GetNumMapAreaDatas() ; ++h)
{
zeus::CTransform hexXf = parms.GetCameraTransform().inverse() * data.GetMapAreaData(h);
for (int s=0 ; s<x4_hexagonToken->GetNumSurfaces() ; ++s)
{
const CMapArea::CMapAreaSurface& surf = x4_hexagonToken->GetSurface(s);
zeus::CVector3f centerPos = hexXf * surf.GetCenterPosition();
sortInfos.emplace_back(centerPos.y, w, h, s, surfColor, outlineColor);
}
}
}
std::sort(sortInfos.begin(), sortInfos.end(),
[](const CMapObjectSortInfo& a, const CMapObjectSortInfo& b)
{
return a.GetZDistance() < b.GetZDistance();
});
int lastWldIdx = -1;
int lastHexIdx = -1;
int instIdx = 0;
for (const CMapObjectSortInfo& info : sortInfos)
{
const CMapWorldData& mwData = x10_worldDatas[info.GetWorldIndex()];
zeus::CColor surfColor = info.GetSurfaceColor();
zeus::CColor outlineColor = info.GetOutlineColor();
if (parms.GetWorldAssetId() == mwData.GetWorldAssetId() && parms.GetClosestArea() == info.GetAreaIndex())
{
surfColor = zeus::CColor::lerp(g_tweakAutoMapper->GetSurfaceSelectVisitedColor(),
g_tweakAutoMapper->GetAreaFlashPulseColor(),
parms.GetFlashPulse());
surfColor.a = info.GetSurfaceColor().a;
outlineColor = zeus::CColor::lerp(g_tweakAutoMapper->GetOutlineSelectVisitedColor(),
g_tweakAutoMapper->GetAreaFlashPulseColor(),
parms.GetFlashPulse());
outlineColor.a = info.GetOutlineColor().a;
}
zeus::CTransform hexXf = mwData.GetMapAreaData(info.GetAreaIndex());
hexXf.orthonormalize();
const CMapArea::CMapAreaSurface& surf = x4_hexagonToken->GetSurface(info.GetObjectIndex());
zeus::CColor color(std::max(0.f, (-parms.GetCameraTransform().basis[1]).dot(hexXf.rotate(surf.GetNormal()))) *
g_tweakAutoMapper->GetMapSurfaceNormColorLinear() + g_tweakAutoMapper->GetMapSurfaceNormColorConstant());
surfColor *= color;
if (info.GetAreaIndex() != lastHexIdx || info.GetWorldIndex() != lastWldIdx)
CGraphics::SetModelMatrix(parms.GetPaneProjectionTransform() * mwData.GetMapAreaData(info.GetAreaIndex()));
surf.Draw(x4_hexagonToken->GetVertices(), surfColor, outlineColor, 2.f, instIdx++);
}
}
CFactoryFnReturn FMapUniverseFactory(const SObjectTag&, CInputStream& in, const CVParamTransfer&,

View File

@ -42,18 +42,30 @@ public:
const zeus::CTransform& GetCameraTransform() const { return x1c_view; }
const zeus::CTransform& GetPaneProjectionTransform() const { return x18_model; }
float GetAlpha() const { return x0_alpha; }
ResId GetWorldAssetId() const { return x8_wldRes; }
int GetClosestArea() const { return xc_closestHex; }
float GetFlashPulse() const { return x10_flashPulse; }
};
class CMapObjectSortInfo
{
float x0_zDist;
int x4_wldIdx;
int x8_hexIdx;
int xc_surfIdx;
zeus::CColor x10_surfColor;
zeus::CColor x14_outlineColor;
public:
CMapObjectSortInfo(float, int, int, int, const zeus::CColor&, const zeus::CColor&);
zeus::CColor GetOutlineColor() const;
zeus::CColor GetSurfaceColor() const;
s32 GetObjectIndex() const;
s32 GetAreaIndex() const;
s32 GetWorldIndex() const;
float GetZDistance() const;
CMapObjectSortInfo(float zDist, int wldIdx, int hexIdx, int surfIdx,
const zeus::CColor& surf, const zeus::CColor& outline)
: x0_zDist(zDist), x4_wldIdx(wldIdx), x8_hexIdx(hexIdx), xc_surfIdx(surfIdx),
x10_surfColor(surf), x14_outlineColor(outline) {}
const zeus::CColor& GetOutlineColor() const { return x14_outlineColor; }
const zeus::CColor& GetSurfaceColor() const { return x10_surfColor; }
int GetObjectIndex() const { return xc_surfIdx; }
int GetAreaIndex() const { return x8_hexIdx; }
int GetWorldIndex() const { return x4_wldIdx; }
float GetZDistance() const { return x0_zDist; }
};
class CMapWorldData
@ -62,10 +74,10 @@ public:
ResId x10_worldAssetId;
zeus::CTransform x14_transform;
std::vector<zeus::CTransform> x44_hexagonXfs;
zeus::CColor x54_;
zeus::CColor x58_ = zeus::CColor(1.0f, 0.0f, 1.0f);
zeus::CColor x5c_ = zeus::CColor(1.0f, 0.0f, 1.0f);
zeus::CColor x60_ = zeus::CColor(1.0f, 0.0f, 1.0f);
zeus::CColor x54_surfColorSelected;
zeus::CColor x58_outlineColorSelected = zeus::CColor(1.0f, 0.0f, 1.0f);
zeus::CColor x5c_surfColorUnselected = zeus::CColor(1.0f, 0.0f, 1.0f);
zeus::CColor x60_outlineColorUnselected = zeus::CColor(1.0f, 0.0f, 1.0f);
zeus::CVector3f x64_centerPoint = zeus::CVector3f::skZero;
public:
CMapWorldData(CInputStream& in, u32 version);
@ -75,10 +87,10 @@ public:
const zeus::CTransform& GetWorldTransform() const { return x14_transform; }
const zeus::CTransform& GetMapAreaData(s32 idx) const { return x44_hexagonXfs[idx]; }
u32 GetNumMapAreaDatas() const { return x44_hexagonXfs.size(); }
zeus::CColor GetOutlineColorUnselected() const;
zeus::CColor GetOutlineColorSelected() const;
zeus::CColor GetSurfaceColorUnselected() const;
zeus::CColor GetSurfaceColorSelected() const;
const zeus::CColor& GetOutlineColorUnselected() const { return x60_outlineColorUnselected; }
const zeus::CColor& GetOutlineColorSelected() const { return x58_outlineColorSelected; }
const zeus::CColor& GetSurfaceColorUnselected() const { return x5c_surfColorUnselected; }
const zeus::CColor& GetSurfaceColorSelected() const { return x54_surfColorSelected; }
};
private:

View File

@ -23,7 +23,8 @@ CMapWorld::CMapWorld(CInputStream& in)
for (u32 i=0 ; i<areaCount ; ++i)
{
ResId mapaId = in.readUint32Big();
x0_areas.emplace_back(mapaId, EMapAreaList::Unloaded, x0_areas.empty() ? nullptr : &x0_areas.back());
x0_areas.emplace_back(mapaId, EMapAreaList::Unloaded,
x0_areas.empty() ? nullptr : &x0_areas.back());
}
x10_listHeads[2] = &x0_areas.back();
}
@ -174,7 +175,8 @@ void CMapWorld::Draw(const CMapWorld::CMapWorldDrawParms& parms, int curArea, in
DrawAreas(parms, curArea, bfsInfos, inMapScreen);
}
void CMapWorld::DoBFS(const IWorld& wld, int startArea, int areaCount, float surfDepth, float outlineDepth,
void CMapWorld::DoBFS(const IWorld& wld, int startArea, int areaCount,
float surfDepth, float outlineDepth,
bool checkLoad, std::vector<CMapAreaBFSInfo>& bfsInfos) const
{
if (areaCount <= 0 || !IsMapAreaValid(wld, startArea, checkLoad))
@ -240,7 +242,8 @@ void CMapWorld::DrawAreas(const CMapWorld::CMapWorldDrawParms& parms, int selAre
{
int thisArea = bfsInfo.GetAreaIndex();
const CMapArea* mapa = GetMapArea(thisArea);
if (!mapa->GetIsVisibleToAutoMapper(mwInfo.IsWorldVisible(thisArea), mwInfo.IsAreaVisible(thisArea)))
if (!mapa->GetIsVisibleToAutoMapper(mwInfo.IsWorldVisible(thisArea),
mwInfo.IsAreaVisible(thisArea)))
continue;
float surfDepth = bfsInfo.GetSurfaceDrawDepth();
@ -286,7 +289,8 @@ void CMapWorld::DrawAreas(const CMapWorld::CMapWorldDrawParms& parms, int selAre
}
zeus::CColor hintFlashColor =
zeus::CColor::lerp(zeus::CColor::skClear, zeus::CColor{1.f, 1.f, 1.f, 0.f}, parms.GetHintAreaFlashIntensity());
zeus::CColor::lerp(zeus::CColor::skClear, zeus::CColor{1.f, 1.f, 1.f, 0.f},
parms.GetHintAreaFlashIntensity());
zeus::CColor finalSurfColor, finalOutlineColor;
if (thisArea == selArea && inMapScreen)
@ -339,7 +343,8 @@ void CMapWorld::DrawAreas(const CMapWorld::CMapWorldDrawParms& parms, int selAre
for (int s=0 ; s<6 ; ++s)
{
zeus::CVector3f center = obj.BuildSurfaceCenterPoint(s);
zeus::CVector3f pos = modelView * (CMapArea::GetAreaPostTranslate(parms.GetWorld(), thisArea) + center);
zeus::CVector3f pos = modelView *
(CMapArea::GetAreaPostTranslate(parms.GetWorld(), thisArea) + center);
sortInfos.emplace_back(pos.y, thisArea, CMapObjectSortInfo::EObjectCode::DoorSurface, si+s,
zeus::CColor{1.f, 0.f, 1.f, 1.f}, zeus::CColor{1.f, 0.f, 1.f, 1.f});
}
@ -347,17 +352,69 @@ void CMapWorld::DrawAreas(const CMapWorld::CMapWorldDrawParms& parms, int selAre
}
}
zeus::CVector3f pos = modelView * (obj.GetTransform().origin + CMapArea::GetAreaPostTranslate(parms.GetWorld(), thisArea));
zeus::CVector3f pos = modelView * (obj.GetTransform().origin +
CMapArea::GetAreaPostTranslate(parms.GetWorld(), thisArea));
sortInfos.emplace_back(pos.y, thisArea, doorType ? CMapObjectSortInfo::EObjectCode::Door :
CMapObjectSortInfo::EObjectCode::Object,
i, zeus::CColor{1.f, 0.f, 1.f, 1.f}, zeus::CColor{1.f, 0.f, 1.f, 1.f});
}
}
if (sortInfos.empty())
return;
std::sort(sortInfos.begin(), sortInfos.end(),
[](const CMapObjectSortInfo& a, const CMapObjectSortInfo& b)
{
return a.GetZDistance() < b.GetZDistance();
});
/* TODO: Finish */
int lastAreaIdx = -1;
CMapObjectSortInfo::EObjectCode lastType = CMapObjectSortInfo::EObjectCode::Invalid;
for (const CMapObjectSortInfo& info : sortInfos)
{
const CMapArea* mapa = GetMapArea(info.GetAreaIndex());
zeus::CTransform areaPostXf = mapa->GetAreaPostTransform(parms.GetWorld(), info.GetAreaIndex());
if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Surface)
{
const CMapArea::CMapAreaSurface& surf = mapa->GetSurface(info.GetLocalObjectIndex());
zeus::CColor color(std::max(0.f, (-parms.GetCameraTransform().basis[1]).dot(
areaPostXf.rotate(surf.GetNormal()))) * g_tweakAutoMapper->GetMapSurfaceNormColorLinear() +
g_tweakAutoMapper->GetMapSurfaceNormColorConstant());
color *= info.GetSurfaceColor();
if (lastAreaIdx != info.GetAreaIndex() || lastType != CMapObjectSortInfo::EObjectCode::Surface)
CGraphics::SetModelMatrix(parms.GetPlaneProjectionTransform() * areaPostXf);
surf.Draw(mapa->GetVertices(), color, info.GetOutlineColor(), parms.GetOutlineWidthScale());
}
else if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Door ||
info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Object)
{
const CMappableObject& mapObj = mapa->GetMappableObject(info.GetLocalObjectIndex());
zeus::CTransform objXf =
zeus::CTransform::Translate(CMapArea::GetAreaPostTranslate(parms.GetWorld(), info.GetAreaIndex())) *
mapObj.GetTransform();
if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Door)
{
CGraphics::SetModelMatrix(parms.GetPlaneProjectionTransform() * objXf);
}
else
{
CGraphics::SetModelMatrix(parms.GetPlaneProjectionTransform() * objXf *
zeus::CTransform(parms.GetCameraTransform().buildMatrix3f() *
zeus::CMatrix3f(parms.GetObjectScale())));
}
mapObj.Draw(selArea, mwInfo, parms.GetAlpha(), lastType != info.GetObjectCode());
}
else if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::DoorSurface)
{
const CMappableObject& mapObj = mapa->GetMappableObject(info.GetLocalObjectIndex() / 6);
zeus::CTransform objXf = parms.GetPlaneProjectionTransform() *
zeus::CTransform::Translate(CMapArea::GetAreaPostTranslate(
parms.GetWorld(), info.GetAreaIndex())) * mapObj.GetTransform();
CGraphics::SetModelMatrix(objXf);
mapObj.DrawDoorSurface(selArea, mwInfo, parms.GetAlpha(), info.GetLocalObjectIndex() % 6,
lastType != info.GetObjectCode());
}
lastAreaIdx = info.GetAreaIndex();
lastType = info.GetObjectCode();
}
}
struct Support
@ -696,14 +753,40 @@ void CMapWorld::RecalculateWorldSphere(const CMapWorldInfo& mwInfo, const IWorld
}
Circle circle = MinCircle(coords);
const_cast<CMapWorld*>(this)->x3c_ = circle.x8_radius;
const_cast<CMapWorld*>(this)->x30_ = zeus::CVector3f(circle.x0_point.x, circle.x0_point.y, (zMin + zMax) * 0.5f);
const_cast<CMapWorld*>(this)->x40_ = (zMax - zMin) * 0.5f;
const_cast<CMapWorld*>(this)->x3c_worldSphereRadius = circle.x8_radius;
const_cast<CMapWorld*>(this)->x30_worldSpherePoint =
zeus::CVector3f(circle.x0_point.x, circle.x0_point.y, (zMin + zMax) * 0.5f);
const_cast<CMapWorld*>(this)->x40_worldSphereHalfDepth = (zMax - zMin) * 0.5f;
}
zeus::CVector3f CMapWorld::ConstrainToWorldVolume(const zeus::CVector3f&, const zeus::CVector3f&) const
zeus::CVector3f CMapWorld::ConstrainToWorldVolume(const zeus::CVector3f& point, const zeus::CVector3f& lookVec) const
{
return {};
zeus::CVector3f ret = point;
if (std::fabs(lookVec.z) > FLT_EPSILON)
{
float f2 = point.z - (x40_worldSphereHalfDepth + x30_worldSpherePoint.z);
float f1 = point.z - (x30_worldSpherePoint.z - x40_worldSphereHalfDepth);
if (f2 > 0.f)
ret = point + lookVec * (-f2 / lookVec.z);
else if (f1 < 0.f)
ret = point + lookVec * (-f1 / lookVec.z);
}
else
{
ret.z = zeus::clamp(x30_worldSpherePoint.z - x40_worldSphereHalfDepth, ret.z,
x40_worldSphereHalfDepth + x30_worldSpherePoint.z);
}
zeus::CVector2f tmp(x30_worldSpherePoint.x, x30_worldSpherePoint.y);
zeus::CVector2f vec2 = zeus::CVector2f(point.x, point.y) - tmp;
if (vec2.magnitude() > x3c_worldSphereRadius)
{
tmp += vec2.normalized() * x3c_worldSphereRadius;
ret.x = tmp.x;
ret.y = tmp.y;
}
return ret;
}
void CMapWorld::ClearTraversedFlags() const

View File

@ -49,6 +49,7 @@ public:
public:
enum class EObjectCode
{
Invalid = -1,
Object = 1 << 16,
DoorSurface = 2 << 16,
Door = 3 << 16,
@ -135,18 +136,20 @@ public:
float GetAlphaSurfaceUnvisited() const { return x8_alphaSurfUnvisited; }
float GetAlphaOutlineVisited() const { return x4_alphaOlVisited; }
float GetAlphaSurfaceVisited() const { return x0_alphaSurfVisited; }
float GetAlpha() const { return x10_alpha; }
const CMapWorldInfo& GetMapWorldInfo() const { return x28_mwInfo; }
const CStateManager& GetStateManager() const { return x18_mgr; }
bool GetIsSortDoorSurfaces() const { return x38_sortDoorSurfs; }
float GetObjectScale() const { return x34_objectScale; }
};
private:
std::vector<CMapAreaData> x0_areas;
rstl::reserved_vector<CMapAreaData*, 3> x10_listHeads;
std::vector<bool> x20_traversed;
zeus::CVector3f x30_;
float x3c_ = 0.f;
float x40_ = 0.f;
zeus::CVector3f x30_worldSpherePoint;
float x3c_worldSphereRadius = 0.f;
float x40_worldSphereHalfDepth = 0.f;
public:
CMapWorld(CInputStream&);
u32 GetNumAreas() const { return x0_areas.size(); }

View File

@ -14,9 +14,10 @@ CMapSurfaceShader::CMapSurfaceShader(boo::IGraphicsDataFactory::Context& ctx,
void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count)
{
m_uniform.mtx = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f();
m_uniform.color = color;
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
Uniform uniform = {
CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(), color
};
m_uniBuf->load(&uniform, sizeof(uniform));
CGraphics::SetShaderDataBinding(m_dataBind);
CGraphics::DrawArrayIndexed(start, count);
}

View File

@ -19,7 +19,6 @@ class CMapSurfaceShader
zeus::CColor color;
};
Uniform m_uniform;
boo::IGraphicsBufferD* m_uniBuf;
boo::IGraphicsBufferS* m_vbo;
boo::IGraphicsBufferS* m_ibo;