Skip to content

Commit

Permalink
UPBGE: Use slot to store information around display arrays in RAS_Def…
Browse files Browse the repository at this point in the history
…ormer.

Previously the display array and display array bucket tracked by deformers
were stored in two separated listes, m_displayArrayList and
m_displayArrayBucketList. But futur feature will request to store more
information related to the display arrays. To fix this inconvenient a slot
struct is introduced: DisplayArraySlot stored under list m_slots.
This struct contains the new DA and DAB but also the original DA for update
listening and the original mesh material for replication.
  • Loading branch information
panzergame committed Dec 6, 2017
1 parent 86cf416 commit 404070c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 27 deletions.
9 changes: 6 additions & 3 deletions source/gameengine/Converter/BL_MeshDeformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ void BL_MeshDeformer::Apply(RAS_MeshMaterial *UNUSED(meshmat), RAS_IDisplayArray
// only apply once per frame if the mesh is actually modified
if (m_lastDeformUpdate != m_gameobj->GetLastFrame()) {
// For each display array
for (RAS_IDisplayArray *array: m_displayArrayList) {
for (const DisplayArraySlot& slot : m_slots) {
RAS_IDisplayArray *array = slot.m_displayArray;
if (array->GetModifiedFlag() == RAS_IDisplayArray::NONE_MODIFIED) {
continue;
}
Expand Down Expand Up @@ -120,7 +121,8 @@ void BL_MeshDeformer::RecalcNormals()
normal = {{0.0f, 0.0f, 0.0f}};
}

for (RAS_IDisplayArray *array : m_displayArrayList) {
for (const DisplayArraySlot& slot : m_slots) {
RAS_IDisplayArray *array = slot.m_displayArray;
for (unsigned int i = 0, size = array->GetTriangleIndexCount(); i < size; i += 3) {
const float *co[3];
bool flat = false;
Expand Down Expand Up @@ -154,7 +156,8 @@ void BL_MeshDeformer::RecalcNormals()
}

// Assign smooth vertex normals.
for (RAS_IDisplayArray *array: m_displayArrayList) {
for (const DisplayArraySlot& slot : m_slots) {
RAS_IDisplayArray *array = slot.m_displayArray;
for (unsigned int i = 0, size = array->GetVertexCount(); i < size; ++i) {
RAS_Vertex v = array->GetVertex(i);
const RAS_VertexInfo& vinfo = array->GetVertexInfo(i);
Expand Down
10 changes: 6 additions & 4 deletions source/gameengine/Converter/BL_ModifierDeformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,13 @@ void BL_ModifierDeformer::UpdateTransverts()
return;
}

const unsigned short nummat = m_mesh->GetNumMaterials();
const unsigned short nummat = m_slots.size();
std::vector<BL_MeshMaterial> mats(nummat);

for (unsigned short i = 0; i < nummat; ++i) {
RAS_MeshMaterial *meshmat = m_mesh->GetMeshMaterial(i);
RAS_IDisplayArray *array = m_displayArrayList[i];
const DisplayArraySlot& slot = m_slots[i];
RAS_MeshMaterial *meshmat = slot.m_meshMaterial;
RAS_IDisplayArray *array = slot.m_displayArray;
array->Clear();

RAS_IPolyMaterial *mat = meshmat->GetBucket()->GetPolyMaterial();
Expand All @@ -203,7 +204,8 @@ void BL_ModifierDeformer::UpdateTransverts()

BL_ConvertDerivedMeshToArray(m_dm, m_bmesh, mats, m_mesh->GetLayersInfo());

for (RAS_IDisplayArray *array : m_displayArrayList) {
for (const DisplayArraySlot& slot : m_slots) {
RAS_IDisplayArray *array = slot.m_displayArray;
array->AppendModifiedFlag(RAS_IDisplayArray::SIZE_MODIFIED);
array->UpdateCache();
}
Expand Down
3 changes: 2 additions & 1 deletion source/gameengine/Converter/BL_SkinDeformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ void BL_SkinDeformer::UpdateTransverts()
// the vertex cache is unique to this deformer, no need to update it
// if it wasn't updated! We must update all the materials at once
// because we will not get here again for the other material
for (RAS_IDisplayArray *array: m_displayArrayList) {
for (const DisplayArraySlot& slot : m_slots) {
RAS_IDisplayArray *array = slot.m_displayArray;
// for each vertex
// copy the untransformed data from the original mvert
for (unsigned int i = 0, size = array->GetVertexCount(); i < size; ++i) {
Expand Down
27 changes: 12 additions & 15 deletions source/gameengine/Rasterizer/RAS_Deformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,35 @@ RAS_Deformer::RAS_Deformer(RAS_MeshObject *mesh)

RAS_Deformer::~RAS_Deformer()
{
for (RAS_DisplayArrayBucket *arrayBucket : m_displayArrayBucketList) {
delete arrayBucket;
}

for (RAS_IDisplayArray *array : m_displayArrayList) {
delete array;
for (const DisplayArraySlot& slot : m_slots) {
delete slot.m_displayArray;
delete slot.m_displayArrayBucket;
}
}

void RAS_Deformer::InitializeDisplayArrays()
{
for (RAS_MeshMaterial *meshmat : m_mesh->GetMeshMaterialList()) {
RAS_IDisplayArray *origArray = meshmat->GetDisplayArray();
/* Duplicate the display array bucket and the display array if needed to store
* the mesh slot on a unique list (= display array bucket) and use an unique vertex
* array (=display array). */
RAS_IDisplayArray *array = meshmat->GetDisplayArray()->GetReplica();
RAS_IDisplayArray *array = origArray->GetReplica();

RAS_DisplayArrayBucket *arrayBucket = new RAS_DisplayArrayBucket(meshmat->GetBucket(), array, m_mesh, meshmat, this);

m_displayArrayList.push_back(array);
m_displayArrayBucketList.push_back(arrayBucket);
m_slots.push_back({array, origArray, meshmat, arrayBucket});
}
}

void RAS_Deformer::ProcessReplica()
{
m_boundingBox = m_boundingBox->GetReplica();

for (unsigned short i = 0, size = m_displayArrayList.size(); i < size; ++i) {
RAS_IDisplayArray *array = m_displayArrayList[i] = m_displayArrayList[i]->GetReplica();
RAS_MeshMaterial *meshmat = m_displayArrayBucketList[i]->GetMeshMaterial();
m_displayArrayBucketList[i] = new RAS_DisplayArrayBucket(meshmat->GetBucket(), array, m_mesh, meshmat, this);
for (DisplayArraySlot& slot : m_slots) {
RAS_IDisplayArray *array = slot.m_displayArray = slot.m_displayArray->GetReplica();
RAS_MeshMaterial *meshmat = slot.m_meshMaterial;
slot.m_displayArrayBucket = new RAS_DisplayArrayBucket(meshmat->GetBucket(), array, m_mesh, meshmat, this);
}
}

Expand All @@ -74,10 +71,10 @@ RAS_MeshObject *RAS_Deformer::GetMesh() const

RAS_IDisplayArray *RAS_Deformer::GetDisplayArray(unsigned short index) const
{
return m_displayArrayList[index];
return m_slots[index].m_displayArray;
}

RAS_DisplayArrayBucket *RAS_Deformer::GetDisplayArrayBucket(unsigned short index) const
{
return m_displayArrayBucketList[index];
return m_slots[index].m_displayArrayBucket;
}
22 changes: 18 additions & 4 deletions source/gameengine/Rasterizer/RAS_Deformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@

#include <map>

struct DerivedMesh;
class RAS_MeshObject;
class RAS_IPolyMaterial;
class RAS_MeshMaterial;

class SCA_IObject;

struct DerivedMesh;

class RAS_Deformer
{
public:
Expand Down Expand Up @@ -85,12 +87,24 @@ class RAS_Deformer
RAS_DisplayArrayBucket *GetDisplayArrayBucket(unsigned short index) const;

protected:
/// Struct wrapping display arrays owned/used by the deformer.
struct DisplayArraySlot
{
/// The unique display array owned by the deformer.
RAS_IDisplayArray *m_displayArray;
/// The original display array used by the deformer to duplicate data.
RAS_IDisplayArray *m_origDisplayArray;
/// The mesh material of the owning the original display array.
RAS_MeshMaterial *m_meshMaterial;
/// The unique display array bucket using the display array of this deformer.
RAS_DisplayArrayBucket *m_displayArrayBucket;
};

std::vector<DisplayArraySlot> m_slots;

RAS_MeshObject *m_mesh;
bool m_bDynamic;

RAS_IDisplayArrayList m_displayArrayList;
RAS_DisplayArrayBucketList m_displayArrayBucketList;

/// Deformer bounding box.
RAS_BoundingBox *m_boundingBox;
};
Expand Down

0 comments on commit 404070c

Please sign in to comment.