Skip to content

Commit

Permalink
Renames before type changes:
Browse files Browse the repository at this point in the history
ScopedMatricesMemAlloc -> ScopedTransformMemAlloc
MatricesMemStorage -> TransformsMemStorage
also rename their variables
  • Loading branch information
lhog committed Dec 14, 2024
1 parent 2c1b21f commit c5c9589
Show file tree
Hide file tree
Showing 13 changed files with 94 additions and 94 deletions.
6 changes: 3 additions & 3 deletions rts/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ void CGame::PreLoadRendering()
geometricObjects = new CGeometricObjects();

// load components that need to exist before PostLoadSimulation
matrixUploader.Init();
transformsUploader.Init();
modelsUniformsUploader.Init();
worldDrawer.InitPre();
}
Expand Down Expand Up @@ -997,7 +997,7 @@ void CGame::KillRendering()
icon::iconHandler.Kill();
spring::SafeDelete(geometricObjects);
worldDrawer.Kill();
matrixUploader.Kill();
transformsUploader.Kill();
modelsUniformsUploader.Kill();
}

Expand Down Expand Up @@ -1470,7 +1470,7 @@ bool CGame::UpdateUnsynced(const spring_time currentTime)
shadowHandler.Update();
{
worldDrawer.Update(newSimFrame);
matrixUploader.Update();
transformsUploader.Update();
modelsUniformsUploader.Update();
}

Expand Down
6 changes: 3 additions & 3 deletions rts/Lua/LuaVBOImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ SInstanceData LuaVBOImpl::InstanceDataFromGetData(int id, int attrID, uint8_t de
uint32_t teamID = defTeamID;

const TObj* obj = LuaUtils::SolIdToObject<TObj>(id, __func__);
const uint32_t matOffset = static_cast<uint32_t>(matrixUploader.GetElemOffset(obj));
const uint32_t matOffset = static_cast<uint32_t>(transformsUploader.GetElemOffset(obj));
const uint32_t uniIndex = static_cast<uint32_t>(modelsUniformsStorage.GetObjOffset(obj)); //doesn't need to exist for defs and model. Don't check for validity

if (matOffset == ~0u) {
Expand All @@ -1003,11 +1003,11 @@ SInstanceData LuaVBOImpl::InstanceDataFromGetData(int id, int attrID, uint8_t de
size_t bposeIndex = 0;
if constexpr (std::is_same<TObj, S3DModel>::value) {
numPieces = static_cast<uint8_t>(obj->numPieces);
bposeIndex = matrixUploader.GetElemOffset(obj);
bposeIndex = transformsUploader.GetElemOffset(obj);
}
else {
numPieces = static_cast<uint8_t>(obj->model->numPieces);
bposeIndex = matrixUploader.GetElemOffset(obj->model);
bposeIndex = transformsUploader.GetElemOffset(obj->model);
}

return SInstanceData(matOffset, teamID, drawFlags, numPieces, uniIndex, bposeIndex);
Expand Down
4 changes: 2 additions & 2 deletions rts/Rendering/Common/ModelDrawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace GL { struct GeometryBuffer; }
template<typename T> class ScopedModelDrawerImpl;
class ScopedMatricesMemAlloc;
class ScopedTransformMemAlloc;


static constexpr const char* ModelDrawerNames[ModelDrawerTypes::MODEL_DRAWER_CNT] = {
Expand Down Expand Up @@ -110,7 +110,7 @@ class CModelDrawerBase : public CModelDrawerConcept {
static bool CanDrawDeferred() { return modelDrawerState->CanDrawDeferred(); }
static bool SetTeamColor(int team, const float alpha = 1.0f) { return modelDrawerState->SetTeamColor(team, alpha); }
static void SetNanoColor(const float4& color) { modelDrawerState->SetNanoColor(color); }
static const ScopedMatricesMemAlloc& GetMatricesMemAlloc(const ObjType* o) { return const_cast<const TDrawerData*>(modelDrawerData)->GetObjectMatricesMemAlloc(o); }
static const ScopedTransformMemAlloc& GetMatricesMemAlloc(const ObjType* o) { return const_cast<const TDrawerData*>(modelDrawerData)->GetObjectTransformMemAlloc(o); }
public:
virtual void Update() const = 0;
// Draw*
Expand Down
14 changes: 7 additions & 7 deletions rts/Rendering/Common/ModelDrawerData.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ class CModelDrawerDataBase : public CModelDrawerDataConcept

void ClearPreviousDrawFlags() { for (auto object : unsortedObjects) object->previousDrawFlag = 0; }

const ScopedMatricesMemAlloc& GetObjectMatricesMemAlloc(const T* o) const {
const ScopedTransformMemAlloc& GetObjectTransformMemAlloc(const T* o) const {
const auto it = matricesMemAllocs.find(const_cast<T*>(o));
return (it != matricesMemAllocs.end()) ? it->second : ScopedMatricesMemAlloc::Dummy();
return (it != matricesMemAllocs.end()) ? it->second : ScopedTransformMemAlloc::Dummy();
}
ScopedMatricesMemAlloc& GetObjectMatricesMemAlloc(const T* o) { return matricesMemAllocs[const_cast<T*>(o)]; }
ScopedTransformMemAlloc& GetObjectTransformMemAlloc(const T* o) { return matricesMemAllocs[const_cast<T*>(o)]; }
private:
static constexpr int MMA_SIZE0 = 2 << 16;
protected:
std::array<ModelRenderContainer<T>, MODELTYPE_CNT> modelRenderers;

std::vector<T*> unsortedObjects;
std::unordered_map<T*, ScopedMatricesMemAlloc> matricesMemAllocs;
std::unordered_map<T*, ScopedTransformMemAlloc> matricesMemAllocs;

bool& mtModelDrawer;
};
Expand Down Expand Up @@ -126,7 +126,7 @@ inline void CModelDrawerDataBase<T>::AddObject(const T* co, bool add)
unsortedObjects.emplace_back(o);

const uint32_t numMatrices = (o->model ? o->model->numPieces : 0) + 1u;
matricesMemAllocs.emplace(o, ScopedMatricesMemAlloc(numMatrices));
matricesMemAllocs.emplace(o, ScopedTransformMemAlloc(numMatrices));

modelsUniformsStorage.GetObjOffset(co);
}
Expand Down Expand Up @@ -157,10 +157,10 @@ inline void CModelDrawerDataBase<T>::UpdateObject(const T* co, bool init)
template<typename T>
inline void CModelDrawerDataBase<T>::UpdateObjectSMMA(const T* o)
{
ScopedMatricesMemAlloc& smma = GetObjectMatricesMemAlloc(o);
ScopedTransformMemAlloc& smma = GetObjectTransformMemAlloc(o);

const auto tmNew = o->GetTransformMatrix();
const auto& tmOld = const_cast<const ScopedMatricesMemAlloc&>(smma)[0];
const auto& tmOld = const_cast<const ScopedTransformMemAlloc&>(smma)[0];

// from one point it doesn't worth the comparison, cause units usually move
// but having not updated smma[0] allows for longer solid no-update areas in ModelsUniformsUploader::UpdateDerived()
Expand Down
4 changes: 2 additions & 2 deletions rts/Rendering/Models/3DModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,13 +763,13 @@ void S3DModel::SetPieceMatrices()
// use this occasion and copy bpose matrices
for (size_t i = 0; i < pieceObjects.size(); ++i) {
const auto* po = pieceObjects[i];
matAlloc[0 + i] = po->bposeTransform.ToMatrix();
traAlloc[0 + i] = po->bposeTransform.ToMatrix();
}

// use this occasion and copy inverse bpose matrices
// store them right after all bind pose matrices
for (size_t i = 0; i < pieceObjects.size(); ++i) {
const auto* po = pieceObjects[i];
matAlloc[numPieces + i] = po->bposeInvTransform.ToMatrix();
traAlloc[numPieces + i] = po->bposeInvTransform.ToMatrix();
}
}
10 changes: 5 additions & 5 deletions rts/Rendering/Models/3DModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ struct S3DModel
, loadStatus(NOTLOADED)
, uploaded(false)

, matAlloc(ScopedMatricesMemAlloc())
, traAlloc(ScopedTransformMemAlloc())
{}

S3DModel(const S3DModel& m) = delete;
Expand Down Expand Up @@ -307,7 +307,7 @@ struct S3DModel
loadStatus = m.loadStatus;
uploaded = m.uploaded;

std::swap(matAlloc, m.matAlloc);
std::swap(traAlloc, m.traAlloc);

return *this;
}
Expand Down Expand Up @@ -342,7 +342,7 @@ struct S3DModel

// force mutex just in case this is called from modelLoader.ProcessVertices()
// TODO: pass to S3DModel if it is created from LoadModel(ST) or from ProcessVertices(MT)
matAlloc = ScopedMatricesMemAlloc(2 * numPieces);
traAlloc = ScopedTransformMemAlloc(2 * numPieces);

std::vector<S3DModelPiece*> stack = { root };

Expand All @@ -368,7 +368,7 @@ struct S3DModel
float3 CalcDrawMidPos() const { return ((maxs + mins) * 0.5f); }
float3 GetDrawMidPos() const { return relMidPos; }

const ScopedMatricesMemAlloc& GetMatAlloc() const { return matAlloc; }
const ScopedTransformMemAlloc& GetMatAlloc() const { return traAlloc; }
public:
std::string name;
std::array<std::string, NUM_MODEL_TEXTURES> texs;
Expand All @@ -395,7 +395,7 @@ struct S3DModel
LoadStatus loadStatus;
bool uploaded;
private:
ScopedMatricesMemAlloc matAlloc;
ScopedTransformMemAlloc traAlloc;
};


Expand Down
18 changes: 9 additions & 9 deletions rts/Rendering/Models/3DModelVAO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ template<typename TObj>
bool S3DModelVAO::AddToSubmissionImpl(const TObj* obj, uint32_t indexStart, uint32_t indexCount, uint8_t teamID, uint8_t drawFlags)
{
RECOIL_DETAILED_TRACY_ZONE;
const auto matIndex = matrixUploader.GetElemOffset(obj);
if (matIndex == MatricesMemStorage::INVALID_INDEX)
const auto matIndex = transformsUploader.GetElemOffset(obj);
if (matIndex == TransformsMemStorage::INVALID_INDEX)
return false;

const auto uniIndex = modelsUniformsStorage.GetObjOffset(obj); //doesn't need to exist for defs and models. Don't check for validity
Expand All @@ -297,14 +297,14 @@ bool S3DModelVAO::AddToSubmissionImpl(const TObj* obj, uint32_t indexStart, uint
size_t bposeIndex = 0;
if constexpr (std::is_same<TObj, S3DModel>::value) {
numPieces = static_cast<uint8_t>(obj->numPieces);
bposeIndex = matrixUploader.GetElemOffset(obj);
bposeIndex = transformsUploader.GetElemOffset(obj);
}
else {
numPieces = static_cast<uint8_t>(obj->model->numPieces);
bposeIndex = matrixUploader.GetElemOffset(obj->model);
bposeIndex = transformsUploader.GetElemOffset(obj->model);
}

if (bposeIndex == MatricesMemStorage::INVALID_INDEX)
if (bposeIndex == TransformsMemStorage::INVALID_INDEX)
return false;

auto& modelInstanceData = modelDataToInstance[SIndexAndCount{ indexStart, indexCount }];
Expand Down Expand Up @@ -414,8 +414,8 @@ template<typename TObj>
bool S3DModelVAO::SubmitImmediatelyImpl(const TObj* obj, uint32_t indexStart, uint32_t indexCount, uint8_t teamID, uint8_t drawFlags, GLenum mode, bool bindUnbind)
{
RECOIL_DETAILED_TRACY_ZONE;
std::size_t matIndex = matrixUploader.GetElemOffset(obj);
if (matIndex == MatricesMemStorage::INVALID_INDEX)
std::size_t matIndex = transformsUploader.GetElemOffset(obj);
if (matIndex == TransformsMemStorage::INVALID_INDEX)
return false;

const auto uniIndex = modelsUniformsStorage.GetObjOffset(obj); //doesn't need to exist for defs. Don't check for validity
Expand All @@ -424,11 +424,11 @@ bool S3DModelVAO::SubmitImmediatelyImpl(const TObj* obj, uint32_t indexStart, ui
size_t bposeIndex = 0;
if constexpr (std::is_same<TObj, S3DModel>::value) {
numPieces = static_cast<uint8_t>(obj->numPieces);
bposeIndex = matrixUploader.GetElemOffset(obj);
bposeIndex = transformsUploader.GetElemOffset(obj);
}
else {
numPieces = static_cast<uint8_t>(obj->model->numPieces);
bposeIndex = matrixUploader.GetElemOffset(obj->model);
bposeIndex = transformsUploader.GetElemOffset(obj->model);
}

SInstanceData instanceData(static_cast<uint32_t>(matIndex), teamID, drawFlags, numPieces, uniIndex, bposeIndex);
Expand Down
2 changes: 1 addition & 1 deletion rts/Rendering/Models/IModelParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void LoadDummyModel(S3DModel& model)
model.numPieces = 1;
// give it one empty piece
model.AddPiece(g3DOParser.AllocPiece());
model.FlattenPieceTree(model.GetRootPiece()); //useless except for setting up matAlloc
model.FlattenPieceTree(model.GetRootPiece()); //useless except for setting up traAlloc
model.GetRootPiece()->SetCollisionVolume(CollisionVolume('b', 'z', -UpVector, ZeroVector));
model.loadStatus = S3DModel::LoadStatus::LOADED;
}
Expand Down
4 changes: 2 additions & 2 deletions rts/Rendering/Models/ModelsMemStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "System/Misc/TracyDefs.h"

MatricesMemStorage matricesMemStorage;
TransformsMemStorage transformsMemStorage;
ModelsUniformsStorage modelsUniformsStorage;

ModelsUniformsStorage::ModelsUniformsStorage()
Expand Down Expand Up @@ -49,7 +49,7 @@ ModelUniformData& ModelsUniformsStorage::GetObjUniformsArray(const CWorldObject*
return storage[offset];
}

void MatricesMemStorage::SetAllDirty()
void TransformsMemStorage::SetAllDirty()
{
RECOIL_DETAILED_TRACY_ZONE;
assert(Threading::IsMainThread());
Expand Down
46 changes: 23 additions & 23 deletions rts/Rendering/Models/ModelsMemStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#include "Sim/Misc/GlobalConstants.h"
#include "Sim/Objects/SolidObjectDef.h"

class MatricesMemStorage : public StablePosAllocator<CMatrix44f> {
class TransformsMemStorage : public StablePosAllocator<CMatrix44f> {
public:
explicit MatricesMemStorage()
explicit TransformsMemStorage()
: StablePosAllocator<CMatrix44f>(INIT_NUM_ELEMS)
, dirtyMap(INIT_NUM_ELEMS, BUFFERING)
{}
Expand Down Expand Up @@ -68,40 +68,40 @@ class MatricesMemStorage : public StablePosAllocator<CMatrix44f> {
static constexpr int INIT_NUM_ELEMS = 1 << 16u;
};

extern MatricesMemStorage matricesMemStorage;
extern TransformsMemStorage transformsMemStorage;


////////////////////////////////////////////////////////////////////

class ScopedMatricesMemAlloc {
class ScopedTransformMemAlloc {
public:
ScopedMatricesMemAlloc() : ScopedMatricesMemAlloc(0u) {};
ScopedMatricesMemAlloc(std::size_t numElems_)
ScopedTransformMemAlloc() : ScopedTransformMemAlloc(0u) {};
ScopedTransformMemAlloc(std::size_t numElems_)
: numElems{numElems_}
{
firstElem = matricesMemStorage.Allocate(numElems);
firstElem = transformsMemStorage.Allocate(numElems);
}

ScopedMatricesMemAlloc(const ScopedMatricesMemAlloc&) = delete;
ScopedMatricesMemAlloc(ScopedMatricesMemAlloc&& smma) noexcept { *this = std::move(smma); }
ScopedTransformMemAlloc(const ScopedTransformMemAlloc&) = delete;
ScopedTransformMemAlloc(ScopedTransformMemAlloc&& smma) noexcept { *this = std::move(smma); }

~ScopedMatricesMemAlloc() {
if (firstElem == MatricesMemStorage::INVALID_INDEX)
~ScopedTransformMemAlloc() {
if (firstElem == TransformsMemStorage::INVALID_INDEX)
return;

matricesMemStorage.Free(firstElem, numElems, &CMatrix44f::Zero());
transformsMemStorage.Free(firstElem, numElems, &CMatrix44f::Zero());
}

bool Valid() const { return firstElem != MatricesMemStorage::INVALID_INDEX; }
bool Valid() const { return firstElem != TransformsMemStorage::INVALID_INDEX; }
std::size_t GetOffset(bool assertInvalid = true) const {
if (assertInvalid)
assert(Valid());

return firstElem;
}

ScopedMatricesMemAlloc& operator= (const ScopedMatricesMemAlloc&) = delete;
ScopedMatricesMemAlloc& operator= (ScopedMatricesMemAlloc&& smma) noexcept {
ScopedTransformMemAlloc& operator= (const ScopedTransformMemAlloc&) = delete;
ScopedTransformMemAlloc& operator= (ScopedTransformMemAlloc&& smma) noexcept {
//swap to prevent dealloc on dying object, yet enable destructor to do its thing on valid object
std::swap(firstElem, smma.firstElem);
std::swap(numElems , smma.numElems );
Expand All @@ -110,26 +110,26 @@ class ScopedMatricesMemAlloc {
}

const CMatrix44f& operator[](std::size_t offset) const {
assert(firstElem != MatricesMemStorage::INVALID_INDEX);
assert(firstElem != TransformsMemStorage::INVALID_INDEX);
assert(offset >= 0 && offset < numElems);

return matricesMemStorage[firstElem + offset];
return transformsMemStorage[firstElem + offset];
}
CMatrix44f& operator[](std::size_t offset) {
assert(firstElem != MatricesMemStorage::INVALID_INDEX);
assert(firstElem != TransformsMemStorage::INVALID_INDEX);
assert(offset >= 0 && offset < numElems);

matricesMemStorage.GetDirtyMap().at(firstElem + offset) = MatricesMemStorage::BUFFERING;
return matricesMemStorage[firstElem + offset];
transformsMemStorage.GetDirtyMap().at(firstElem + offset) = TransformsMemStorage::BUFFERING;
return transformsMemStorage[firstElem + offset];
}
public:
static const ScopedMatricesMemAlloc& Dummy() {
static ScopedMatricesMemAlloc dummy;
static const ScopedTransformMemAlloc& Dummy() {
static ScopedTransformMemAlloc dummy;

return dummy;
};
private:
std::size_t firstElem = MatricesMemStorage::INVALID_INDEX;
std::size_t firstElem = TransformsMemStorage::INVALID_INDEX;
std::size_t numElems = 0u;
};

Expand Down
Loading

0 comments on commit c5c9589

Please sign in to comment.