OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
StdSubMeshInstance Class Reference

#include <StdMesh.h>

Collaboration diagram for StdSubMeshInstance:
[legend]

Classes

struct  Pass
 
struct  TexUnit
 

Public Types

enum  FaceOrdering { FO_Fixed, FO_FarthestToNearest, FO_NearestToFarthest }
 

Public Member Functions

 StdSubMeshInstance (class StdMeshInstance &instance, const StdSubMesh &submesh, float completion)
 
void LoadFacesForCompletion (class StdMeshInstance &instance, const StdSubMesh &submesh, float completion)
 
void CompileFunc (StdCompiler *pComp)
 
const StdMeshFaceGetFaces () const
 
size_t GetNumFaces () const
 
const StdSubMeshGetSubMesh () const
 
unsigned int GetTexturePhase (size_t pass, size_t texunit) const
 
double GetTexturePosition (size_t pass, size_t texunit) const
 
const StdMeshMaterialGetMaterial () const
 
FaceOrdering GetFaceOrdering () const
 

Protected Member Functions

void SetMaterial (const StdMeshMaterial &material)
 
void SetFaceOrdering (class StdMeshInstance &instance, const StdSubMesh &submesh, FaceOrdering ordering)
 
void SetFaceOrderingForClrModulation (class StdMeshInstance &instance, const StdSubMesh &submesh, uint32_t clrmod)
 

Protected Attributes

const StdSubMeshbase
 
std::vector< StdMeshFaceFaces
 
const StdMeshMaterialMaterial
 
std::vector< PassPassData
 
FaceOrdering CurrentFaceOrdering
 

Friends

class StdMeshInstance
 
class StdMeshMaterialUpdate
 

Detailed Description

Definition at line 244 of file StdMesh.h.


Class Documentation

struct StdSubMeshInstance::Pass

Definition at line 297 of file StdMesh.h.

Class Members
vector< TexUnit > TexUnits
struct StdSubMeshInstance::TexUnit

Definition at line 286 of file StdMesh.h.

Class Members
unsigned int Phase
float PhaseDelay
double Position

Member Enumeration Documentation

Enumerator
FO_Fixed 
FO_FarthestToNearest 
FO_NearestToFarthest 

Definition at line 250 of file StdMesh.h.

Constructor & Destructor Documentation

StdSubMeshInstance::StdSubMeshInstance ( class StdMeshInstance instance,
const StdSubMesh submesh,
float  completion 
)

Definition at line 668 of file StdMesh.cpp.

References StdSubMesh::GetMaterial(), LoadFacesForCompletion(), and SetMaterial().

668  :
669  base(&submesh), Material(nullptr), CurrentFaceOrdering(FO_Fixed)
670 {
671 #ifndef USE_CONSOLE
672  LoadFacesForCompletion(instance, submesh, completion);
673 #endif
674 
675  SetMaterial(submesh.GetMaterial());
676 }
FaceOrdering CurrentFaceOrdering
Definition: StdMesh.h:303
const StdMeshMaterial & GetMaterial() const
Definition: StdMesh.h:172
void LoadFacesForCompletion(class StdMeshInstance &instance, const StdSubMesh &submesh, float completion)
Definition: StdMesh.cpp:678
const StdMeshMaterial * Material
Definition: StdMesh.h:284
const StdSubMesh * base
Definition: StdMesh.h:280
void SetMaterial(const StdMeshMaterial &material)
Definition: StdMesh.cpp:706

Here is the call graph for this function:

Member Function Documentation

void StdSubMeshInstance::CompileFunc ( StdCompiler pComp)

Definition at line 763 of file StdMesh.cpp.

References StdCompiler::excCorrupt(), StdStrBuf::Format(), StdStrBuf::getData(), StdMeshMatManager::GetMaterial(), StdCompiler::isDeserializer(), Material, MeshMaterialManager, mkNamingAdapt(), StdMeshMaterial::Name, SetMaterial(), and StdCompiler::Value().

764 {
765  // TODO: We should also serialize the texture animation positions
766  if(pComp->isDeserializer())
767  {
768  StdCopyStrBuf material_name;
769  pComp->Value(mkNamingAdapt(material_name, "Material"));
770  if(material_name != Material->Name)
771  {
772  const StdMeshMaterial* material = ::MeshMaterialManager.GetMaterial(material_name.getData());
773  if(!material)
774  {
775  StdStrBuf buf;
776  buf.Format("There is no such material with name \"%s\"", material_name.getData());
777  pComp->excCorrupt(buf.getData());
778  }
779 
780  SetMaterial(*material);
781  }
782  }
783  else
784  {
785  StdCopyStrBuf material_name = Material->Name;
786  pComp->Value(mkNamingAdapt(material_name, "Material"));
787  }
788 }
const char * getData() const
Definition: StdBuf.h:450
const StdMeshMaterial * Material
Definition: StdMesh.h:284
void excCorrupt(const char *szMessage,...)
Definition: StdCompiler.h:259
void Format(const char *szFmt,...) GNUC_FORMAT_ATTRIBUTE_O
Definition: StdBuf.cpp:181
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63
void SetMaterial(const StdMeshMaterial &material)
Definition: StdMesh.cpp:706
StdCopyStrBuf Name
const StdMeshMaterial * GetMaterial(const char *material_name) const
StdMeshMatManager MeshMaterialManager

Here is the call graph for this function:

FaceOrdering StdSubMeshInstance::GetFaceOrdering ( ) const
inline

Definition at line 274 of file StdMesh.h.

274 { return CurrentFaceOrdering; }
FaceOrdering CurrentFaceOrdering
Definition: StdMesh.h:303
const StdMeshFace* StdSubMeshInstance::GetFaces ( ) const
inline

Definition at line 265 of file StdMesh.h.

265 { return Faces.size() > 0 ? &Faces[0] : 0; }
std::vector< StdMeshFace > Faces
Definition: StdMesh.h:282
const StdMeshMaterial& StdSubMeshInstance::GetMaterial ( ) const
inline

Definition at line 272 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimation().

272 { return *Material; }
const StdMeshMaterial * Material
Definition: StdMesh.h:284

Here is the caller graph for this function:

size_t StdSubMeshInstance::GetNumFaces ( ) const
inline

Definition at line 266 of file StdMesh.h.

266 { return Faces.size(); }
std::vector< StdMeshFace > Faces
Definition: StdMesh.h:282
const StdSubMesh& StdSubMeshInstance::GetSubMesh ( ) const
inline

Definition at line 267 of file StdMesh.h.

Referenced by StdMeshInstance::ReorderFaces().

267 { return *base; }
const StdSubMesh * base
Definition: StdMesh.h:280

Here is the caller graph for this function:

unsigned int StdSubMeshInstance::GetTexturePhase ( size_t  pass,
size_t  texunit 
) const
inline

Definition at line 269 of file StdMesh.h.

269 { return PassData[pass].TexUnits[texunit].Phase; }
std::vector< Pass > PassData
Definition: StdMesh.h:302
double StdSubMeshInstance::GetTexturePosition ( size_t  pass,
size_t  texunit 
) const
inline

Definition at line 270 of file StdMesh.h.

270 { return PassData[pass].TexUnits[texunit].Position; }
std::vector< Pass > PassData
Definition: StdMesh.h:302
void StdSubMeshInstance::LoadFacesForCompletion ( class StdMeshInstance instance,
const StdSubMesh submesh,
float  completion 
)

Definition at line 678 of file StdMesh.cpp.

References Faces, FO_FarthestToNearest, StdSubMesh::GetFace(), StdSubMesh::GetNumFaces(), StdSubMesh::GetNumVertices(), StdMeshInstance::GetSharedVertices(), and StdSubMesh::GetVertices().

Referenced by SetFaceOrdering(), and StdSubMeshInstance().

679 {
680 #ifndef USE_CONSOLE
681  // First: Copy all faces
682  Faces.resize(submesh.GetNumFaces());
683  for (unsigned int i = 0; i < submesh.GetNumFaces(); ++i)
684  Faces[i] = submesh.GetFace(i);
685 
686  if(completion < 1.0f)
687  {
688  // Second: Order by Y position. StdMeshInstanceFaceOrderingCmpPred orders by Z position,
689  // however we can simply give an appropriate transformation matrix to the face ordering.
690  // At this point, all vertices are in the OGRE coordinate frame, and Z in OGRE equals
691  // Y in Clonk, so we are fine without additional transformation.
692  const StdMeshVertex* vertices;
693  if(submesh.GetNumVertices() > 0)
694  vertices = &submesh.GetVertices()[0];
695  else
696  vertices = &instance.GetSharedVertices()[0];
697  SortFacesArray(vertices, Faces, FO_FarthestToNearest, StdMeshMatrix::Identity());
698 
699  // Third: Only use the first few ones
700  assert(submesh.GetNumFaces() >= 1);
701  Faces.resize(Clamp<unsigned int>(static_cast<unsigned int>(completion * submesh.GetNumFaces() + 0.5), 1, submesh.GetNumFaces()));
702  }
703 #endif
704 }
size_t GetNumFaces() const
Definition: StdMesh.h:170
const StdMeshFace & GetFace(size_t i) const
Definition: StdMesh.h:169
size_t GetNumVertices() const
Definition: StdMesh.h:167
const std::vector< Vertex > & GetVertices() const
Definition: StdMesh.h:165
std::vector< StdMeshFace > Faces
Definition: StdMesh.h:282

Here is the call graph for this function:

Here is the caller graph for this function:

void StdSubMeshInstance::SetFaceOrdering ( class StdMeshInstance instance,
const StdSubMesh submesh,
FaceOrdering  ordering 
)
protected

Definition at line 735 of file StdMesh.cpp.

References CurrentFaceOrdering, FO_Fixed, StdMeshInstance::GetCompletion(), and LoadFacesForCompletion().

Referenced by SetFaceOrderingForClrModulation().

736 {
737 #ifndef USE_CONSOLE
738  if (CurrentFaceOrdering != ordering)
739  {
740  CurrentFaceOrdering = ordering;
741  if (ordering == FO_Fixed)
742  {
743  LoadFacesForCompletion(instance, submesh, instance.GetCompletion());
744  }
745  }
746 #endif
747 }
FaceOrdering CurrentFaceOrdering
Definition: StdMesh.h:303
void LoadFacesForCompletion(class StdMeshInstance &instance, const StdSubMesh &submesh, float completion)
Definition: StdMesh.cpp:678

Here is the call graph for this function:

Here is the caller graph for this function:

void StdSubMeshInstance::SetFaceOrderingForClrModulation ( class StdMeshInstance instance,
const StdSubMesh submesh,
uint32_t  clrmod 
)
protected

Definition at line 749 of file StdMesh.cpp.

References FO_FarthestToNearest, FO_Fixed, FO_NearestToFarthest, StdMeshMaterial::IsOpaque(), Material, and SetFaceOrdering().

750 {
751 #ifndef USE_CONSOLE
752  bool opaque = Material->IsOpaque();
753 
754  if(!opaque)
755  SetFaceOrdering(instance, submesh, FO_FarthestToNearest);
756  else if( ((clrmod >> 24) & 0xff) != 0xff)
757  SetFaceOrdering(instance, submesh, FO_NearestToFarthest);
758  else
759  SetFaceOrdering(instance, submesh, FO_Fixed);
760 #endif
761 }
const StdMeshMaterial * Material
Definition: StdMesh.h:284
bool IsOpaque() const
void SetFaceOrdering(class StdMeshInstance &instance, const StdSubMesh &submesh, FaceOrdering ordering)
Definition: StdMesh.cpp:735

Here is the call graph for this function:

void StdSubMeshInstance::SetMaterial ( const StdMeshMaterial material)
protected

Definition at line 706 of file StdMesh.cpp.

References StdMeshMaterial::BestTechniqueIndex, Material, PassData, StdMeshMaterialTechnique::Passes, StdSubMeshInstance::TexUnit::Phase, StdSubMeshInstance::TexUnit::PhaseDelay, StdSubMeshInstance::TexUnit::Position, StdMeshMaterial::Techniques, and StdMeshMaterialPass::TextureUnits.

Referenced by CompileFunc(), StdSubMeshInstance(), and StdMeshMaterialUpdate::Update().

707 {
708  Material = &material;
709 
710 #ifndef USE_CONSOLE
711  // Setup initial texture animation data
712  assert(Material->BestTechniqueIndex >= 0);
714  PassData.resize(technique.Passes.size());
715  for (unsigned int i = 0; i < PassData.size(); ++i)
716  {
717  const StdMeshMaterialPass& pass = technique.Passes[i];
718  // Clear from previous material
719  PassData[i].TexUnits.clear();
720 
721  for (unsigned int j = 0; j < pass.TextureUnits.size(); ++j)
722  {
723  TexUnit unit;
724  unit.Phase = 0;
725  unit.PhaseDelay = 0.0f;
726  unit.Position = 0.0;
727  PassData[i].TexUnits.push_back(unit);
728  }
729  }
730 
731  // TODO: Reset face ordering
732 #endif
733 }
const StdMeshMaterial * Material
Definition: StdMesh.h:284
std::vector< Pass > PassData
Definition: StdMesh.h:302
std::vector< StdMeshMaterialPass > Passes
std::vector< StdMeshMaterialTextureUnit > TextureUnits
std::vector< StdMeshMaterialTechnique > Techniques

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class StdMeshInstance
friend

Definition at line 246 of file StdMesh.h.

friend class StdMeshMaterialUpdate
friend

Definition at line 247 of file StdMesh.h.

Member Data Documentation

const StdSubMesh* StdSubMeshInstance::base
protected

Definition at line 280 of file StdMesh.h.

FaceOrdering StdSubMeshInstance::CurrentFaceOrdering
protected

Definition at line 303 of file StdMesh.h.

Referenced by StdMeshInstance::ReorderFaces(), and SetFaceOrdering().

std::vector<StdMeshFace> StdSubMeshInstance::Faces
protected

Definition at line 282 of file StdMesh.h.

Referenced by LoadFacesForCompletion(), and StdMeshInstance::ReorderFaces().

const StdMeshMaterial* StdSubMeshInstance::Material
protected
std::vector<Pass> StdSubMeshInstance::PassData
protected

Definition at line 302 of file StdMesh.h.

Referenced by StdMeshInstance::ExecuteAnimation(), and SetMaterial().


The documentation for this class was generated from the following files: