Implemented TFlags for easy, type-safe bitflags

This commit is contained in:
parax0
2016-01-05 11:50:10 -07:00
parent ee5d5fae0a
commit 5375f34c19
63 changed files with 207 additions and 329 deletions

View File

@@ -29,7 +29,7 @@ CMaterial::CMaterial()
mpIndirectTexture = nullptr;
}
CMaterial::CMaterial(EGame version, EVertexDescription vtxDesc)
CMaterial::CMaterial(EGame version, FVertexDescription vtxDesc)
{
mpShader = nullptr;
mShaderStatus = eNoShader;
@@ -87,7 +87,7 @@ void CMaterial::GenerateShader()
else mShaderStatus = eShaderExists;
}
bool CMaterial::SetCurrent(ERenderOptions Options)
bool CMaterial::SetCurrent(FRenderOptions Options)
{
// Bind textures
const char *skpSamplers[8] = {
@@ -226,12 +226,12 @@ EGame CMaterial::Version() const
return mVersion;
}
CMaterial::EMaterialOptions CMaterial::Options() const
CMaterial::FMaterialOptions CMaterial::Options() const
{
return mOptions;
}
EVertexDescription CMaterial::VtxDesc() const
FVertexDescription CMaterial::VtxDesc() const
{
return mVtxDesc;
}
@@ -287,13 +287,13 @@ void CMaterial::SetName(const TString& name)
mName = name;
}
void CMaterial::SetOptions(EMaterialOptions Options)
void CMaterial::SetOptions(FMaterialOptions Options)
{
mOptions = Options;
mRecalcHash = true;
}
void CMaterial::SetVertexDescription(EVertexDescription desc)
void CMaterial::SetVertexDescription(FVertexDescription desc)
{
mVtxDesc = desc;
mRecalcHash = true;

View File

@@ -5,12 +5,12 @@
#include "CTexture.h"
#include "EGame.h"
#include "TResPtr.h"
#include "Core/Resource/Model/EVertexDescription.h"
#include "Core/Render/ERenderOptions.h"
#include "Core/Resource/Model/EVertexAttribute.h"
#include "Core/Render/FRenderOptions.h"
#include "Core/OpenGL/CShader.h"
#include <Common/CColor.h>
#include <Common/EnumUtil.h>
#include <Common/Flags.h>
#include <Common/types.h>
#include <FileIO/IInputStream.h>
@@ -23,7 +23,7 @@ public:
friend class CMaterialCooker;
// Enums
enum EMaterialOptions
enum EMaterialOption
{
eNoSettings = 0,
eKonst = 0x8,
@@ -38,6 +38,7 @@ public:
eShortTexCoord = 0x2000,
eAllSettings = 0x2FF8
};
DECLARE_FLAGS(EMaterialOption, FMaterialOptions)
private:
enum EShaderStatus
@@ -58,8 +59,8 @@ private:
bool mEnableBloom; // Bool that toggles bloom on or off. On by default on MP3 materials, off by default on MP1 materials.
EGame mVersion;
EMaterialOptions mOptions; // See the EMaterialOptions enum above
EVertexDescription mVtxDesc; // Descriptor of vertex attributes used by this material
FMaterialOptions mOptions; // See the EMaterialOptions enum above
FVertexDescription mVtxDesc; // Descriptor of vertex attributes used by this material
CColor mKonstColors[4]; // Konst color values for TEV
GLenum mBlendSrcFac; // Source blend factor
GLenum mBlendDstFac; // Dest blend factor
@@ -72,19 +73,19 @@ private:
public:
CMaterial();
CMaterial(EGame version, EVertexDescription vtxDesc);
CMaterial(EGame version, FVertexDescription vtxDesc);
~CMaterial();
CMaterial* Clone();
void GenerateShader();
bool SetCurrent(ERenderOptions Options);
bool SetCurrent(FRenderOptions Options);
u64 HashParameters();
void Update();
// Getters
TString Name() const;
EGame Version() const;
EMaterialOptions Options() const;
EVertexDescription VtxDesc() const;
FMaterialOptions Options() const;
FVertexDescription VtxDesc() const;
GLenum BlendSrcFac() const;
GLenum BlendDstFac() const;
CColor Konst(u32 KIndex) const;
@@ -97,8 +98,8 @@ public:
// Setters
void SetName(const TString& name);
void SetOptions(EMaterialOptions Options);
void SetVertexDescription(EVertexDescription desc);
void SetOptions(FMaterialOptions Options);
void SetVertexDescription(FVertexDescription desc);
void SetBlendMode(GLenum SrcFac, GLenum DstFac);
void SetKonst(CColor& Konst, u32 KIndex);
void SetIndTexture(CTexture *pTex);
@@ -108,6 +109,5 @@ public:
// Static
static void KillCachedMaterial();
};
DEFINE_ENUM_FLAGS(CMaterial::EMaterialOptions)
#endif // MATERIAL_H

View File

@@ -81,7 +81,7 @@ void CMaterialPass::LoadTexture(u32 PassIndex)
mpTexture->Bind(PassIndex);
}
void CMaterialPass::SetAnimCurrent(ERenderOptions Options, u32 PassIndex)
void CMaterialPass::SetAnimCurrent(FRenderOptions Options, u32 PassIndex)
{
if (mAnimMode == eNoUVAnim) return;

View File

@@ -4,7 +4,7 @@
#include "TResPtr.h"
#include "CTexture.h"
#include "ETevEnums.h"
#include "Core/Render/ERenderOptions.h"
#include "Core/Render/FRenderOptions.h"
#include <Common/CFourCC.h>
#include <Common/CHashFNV1A.h>
@@ -47,7 +47,7 @@ public:
CMaterialPass* Clone(CMaterial *pParent);
void HashParameters(CHashFNV1A& Hash);
void LoadTexture(u32 PassIndex);
void SetAnimCurrent(ERenderOptions Options, u32 PassIndex);
void SetAnimCurrent(FRenderOptions Options, u32 PassIndex);
// Setters
void SetType(CFourCC Type);

View File

@@ -141,7 +141,7 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& Out)
else
Flags = 0x4002;
Flags |= (HasKonst << 3) | mpMat->Options() | (TexFlags << 16);
Flags |= (HasKonst ? 0x8 : 0x0) | mpMat->Options() | (TexFlags << 16);
Out.WriteLong(Flags);
@@ -151,10 +151,10 @@ void CMaterialCooker::WriteMaterialPrime(IOutputStream& Out)
Out.WriteLong(TexIndices[iTex]);
// Vertex description
EVertexDescription Desc = mpMat->VtxDesc();
FVertexDescription Desc = mpMat->VtxDesc();
if (mVersion < eEchoes)
Desc = (EVertexDescription) (Desc & 0x00FFFFFF);
Desc &= 0x00FFFFFF;
Out.WriteLong(Desc);

View File

@@ -164,7 +164,7 @@ void CModelCooker::WriteModelPrime(IOutputStream& Out)
Out.WriteToBoundary(32, 0);
u32 PrimTableStart = Out.Tell();
EVertexDescription MatAttribs = mpModel->GetMaterialBySurface(0, iSurf)->VtxDesc();
FVertexDescription MatAttribs = mpModel->GetMaterialBySurface(0, iSurf)->VtxDesc();
for (u32 iPrim = 0; iPrim < pSurface->Primitives.size(); iPrim++)
{

View File

@@ -14,7 +14,7 @@ class CModelCooker
u32 mNumVertices;
u8 mVertexFormat;
std::vector<CVertex> mVertices;
EVertexDescription mVtxAttribs;
FVertexDescription mVtxAttribs;
CModelCooker();
void GenerateSurfaceData();

View File

@@ -50,7 +50,7 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
pMat->mEnableBloom = false;
// Flags
pMat->mOptions = (CMaterial::EMaterialOptions) (mpFile->ReadLong() & CMaterial::eAllSettings);
pMat->mOptions = (mpFile->ReadLong() & CMaterial::eAllSettings);
// Textures
u32 NumTextures = mpFile->ReadLong();
@@ -63,7 +63,7 @@ CMaterial* CMaterialLoader::ReadPrimeMaterial()
}
// Vertex description
pMat->mVtxDesc = (EVertexDescription) mpFile->ReadLong();
pMat->mVtxDesc = (FVertexDescription) mpFile->ReadLong();
// Unknowns
if (mVersion >= eEchoesDemo)
@@ -266,7 +266,7 @@ CMaterial* CMaterialLoader::ReadCorruptionMaterial()
mHas0x400 = ((Flags & 0x400) != 0);
mpFile->Seek(0x8, SEEK_CUR); // Don't know what any of this is
pMat->mVtxDesc = (EVertexDescription) mpFile->ReadLong();
pMat->mVtxDesc = (FVertexDescription) mpFile->ReadLong();
mpFile->Seek(0xC, SEEK_CUR);
// Initialize all KColors to white

View File

@@ -142,7 +142,7 @@ SSurface* CModelLoader::LoadSurface(IInputStream& Model)
for (u16 iVtx = 0; iVtx < VertexCount; iVtx++)
{
CVertex Vtx;
EVertexDescription VtxDesc = pMat->VtxDesc();
FVertexDescription VtxDesc = pMat->VtxDesc();
for (u32 iMtxAttr = 0; iMtxAttr < 8; iMtxAttr++)
if (VtxDesc & (ePosMtx << iMtxAttr)) Model.Seek(0x1, SEEK_CUR);
@@ -277,7 +277,7 @@ SSurface* CModelLoader::LoadAssimpMesh(const aiMesh *pMesh, CMaterialSet *pSet)
{
// Create vertex description and assign it to material
CMaterial *pMat = pSet->MaterialByIndex(pMesh->mMaterialIndex);
EVertexDescription desc = pMat->VtxDesc();
FVertexDescription desc = pMat->VtxDesc();
if (desc == eNoAttributes)
{

View File

@@ -6,7 +6,7 @@
#include "Core/Resource/Model/CModel.h"
#include "Core/Resource/CResCache.h"
#include "Core/Resource/EGame.h"
#include <Common/EnumUtil.h>
#include <Common/Flags.h>
#include <FileIO/FileIO.h>
#include <assimp/scene.h>
@@ -14,7 +14,7 @@
class CModelLoader
{
public:
enum EModelFlags
enum EModelFlag
{
eNoFlags = 0x0,
eShortPositions = 0x1,
@@ -22,6 +22,7 @@ public:
eHasTex1 = 0x4,
eHasVisGroups = 0x8
};
DECLARE_FLAGS(EModelFlag, FModelFlags)
private:
TResPtr<CModel> mpModel;
@@ -41,7 +42,7 @@ private:
u32 mSurfaceCount;
std::vector<u32> mSurfaceOffsets;
EModelFlags mFlags;
FModelFlags mFlags;
CModelLoader();
~CModelLoader();
@@ -62,6 +63,4 @@ public:
static EGame GetFormatVersion(u32 Version);
};
DEFINE_ENUM_FLAGS(CModelLoader::EModelFlags)
#endif // CMODELLOADER_H

View File

@@ -82,14 +82,14 @@ void CModel::ClearGLBuffer()
mBuffered = false;
}
void CModel::Draw(ERenderOptions Options, u32 MatSet)
void CModel::Draw(FRenderOptions Options, u32 MatSet)
{
if (!mBuffered) BufferGL();
for (u32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++)
DrawSurface(Options, iSurf, MatSet);
}
void CModel::DrawSurface(ERenderOptions Options, u32 Surface, u32 MatSet)
void CModel::DrawSurface(FRenderOptions Options, u32 Surface, u32 MatSet)
{
if (!mBuffered) BufferGL();
@@ -122,7 +122,7 @@ void CModel::DrawSurface(ERenderOptions Options, u32 Surface, u32 MatSet)
mVBO.Unbind();
}
void CModel::DrawWireframe(ERenderOptions Options, CColor WireColor /*= CColor::skWhite*/)
void CModel::DrawWireframe(FRenderOptions Options, CColor WireColor /*= CColor::skWhite*/)
{
if (!mBuffered) BufferGL();

View File

@@ -6,7 +6,7 @@
#include "Core/Resource/CMaterialSet.h"
#include "Core/OpenGL/CIndexBuffer.h"
#include "Core/OpenGL/GLCommon.h"
#include "Core/Render/ERenderOptions.h"
#include "Core/Render/FRenderOptions.h"
class CModel : public CBasicModel
{
@@ -24,9 +24,9 @@ public:
void BufferGL();
void ClearGLBuffer();
void Draw(ERenderOptions Options, u32 MatSet);
void DrawSurface(ERenderOptions Options, u32 Surface, u32 MatSet);
void DrawWireframe(ERenderOptions Options, CColor WireColor = CColor::skWhite);
void Draw(FRenderOptions Options, u32 MatSet);
void DrawSurface(FRenderOptions Options, u32 Surface, u32 MatSet);
void DrawWireframe(FRenderOptions Options, CColor WireColor = CColor::skWhite);
u32 GetMatSetCount();
u32 GetMatCount();

View File

@@ -97,7 +97,7 @@ void CStaticModel::ClearGLBuffer()
mBuffered = false;
}
void CStaticModel::Draw(ERenderOptions Options)
void CStaticModel::Draw(FRenderOptions Options)
{
if (!mBuffered) BufferGL();
@@ -119,7 +119,7 @@ void CStaticModel::Draw(ERenderOptions Options)
mVBO.Unbind();
}
void CStaticModel::DrawSurface(ERenderOptions Options, u32 Surface)
void CStaticModel::DrawSurface(FRenderOptions Options, u32 Surface)
{
if (!mBuffered) BufferGL();
@@ -144,7 +144,7 @@ void CStaticModel::DrawSurface(ERenderOptions Options, u32 Surface)
mVBO.Unbind();
}
void CStaticModel::DrawWireframe(ERenderOptions Options, CColor WireColor /*= CColor::skWhite*/)
void CStaticModel::DrawWireframe(FRenderOptions Options, CColor WireColor /*= CColor::skWhite*/)
{
if (!mBuffered) BufferGL();

View File

@@ -2,7 +2,7 @@
#define CSTATICMODEL_H
#include "CBasicModel.h"
#include "Core/Render/ERenderOptions.h"
#include "Core/Render/FRenderOptions.h"
#include "Core/OpenGL/CIndexBuffer.h"
/* A CStaticModel is meant for meshes that don't move. It's built specifically with terrain in mind.
@@ -23,9 +23,9 @@ public:
void BufferGL();
void ClearGLBuffer();
void Draw(ERenderOptions Options);
void DrawSurface(ERenderOptions Options, u32 Surface);
void DrawWireframe(ERenderOptions Options, CColor WireColor = CColor::skWhite);
void Draw(FRenderOptions Options);
void DrawSurface(FRenderOptions Options, u32 Surface);
void DrawWireframe(FRenderOptions Options, CColor WireColor = CColor::skWhite);
CMaterial* GetMaterial();
void SetMaterial(CMaterial *pMat);

View File

@@ -1,9 +1,9 @@
#ifndef EVERTEXDESCRIPTION
#define EVERTEXDESCRIPTION
#ifndef EVERTEXATTRIBUTE
#define EVERTEXATTRIBUTE
#include <Common/EnumUtil.h>
#include <Common/Flags.h>
enum EVertexDescription
enum EVertexAttribute
{
eNoAttributes = 0x0,
ePosition = 0x3,
@@ -27,7 +27,7 @@ enum EVertexDescription
eTex5Mtx = 0x40000000,
eTex6Mtx = 0x80000000
};
DEFINE_ENUM_FLAGS(EVertexDescription)
DECLARE_FLAGS(EVertexAttribute, FVertexDescription)
#endif // EVERTEXDESCRIPTION
#endif // EVERTEXATTRIBUTE

View File

@@ -1,130 +0,0 @@
#ifndef EOBJECTTYPE_H
#define EOBJECTTYPE_H
// dunno if this is actually needed, but here it is.
enum EObjectType
{
Actor = 0x0,
Waypoint = 0x2,
DoorArea = 0x3,
Trigger = 0x4,
Timer = 0x5,
Counter = 0x6,
Effect = 0x7,
Platform = 0x8,
Sound = 0x9,
Generator = 0xA,
Dock = 0xB,
Camera = 0xC,
CameraWaypoint = 0xD,
NewIntroBoss = 0xE,
SpawnPoint = 0xF,
CameraHint = 0x10,
Pickup = 0x11,
MemoryRelay = 0x13,
RandomRelay = 0x14,
Relay = 0x15,
Beetle = 0x16,
HUDMemo = 0x17,
CameraFilterKeyframe = 0x18,
CameraBlurKeyframe = 0x19,
DamageableTrigger = 0x1A,
Debris = 0x1B,
CameraShaker = 0x1C,
ActorKeyFrame = 0x1D,
Water = 0x20,
Warwasp = 0x21,
SpacePirate = 0x24,
FlyingPirate = 0x25,
ElitePirate = 0x26,
MetroidBeta = 0x27,
ChozoGhost = 0x28,
CoverPoint = 0x2A,
SpiderBallWaypoint = 0x2C,
BloodFlower = 0x2D,
FlickerBat = 0x2E,
PathCamera = 0x2F,
GrapplePoint = 0x30,
PuddleSpore = 0x31,
SpiderBallAttractionSurface = 0x33,
PuddleToadGamma = 0x34,
Fog = 0x35,
FireFlea = 0x36,
MetareeAlpha = 0x37,
ActorRotate = 0x39,
SpecialFunction = 0x3A,
SpankWeed = 0x3B,
Zoomer = 0x3D,
PlayerHint = 0x3E,
Ripper = 0x3F,
PickupGenerator = 0x40,
PointOfInterest = 0x42,
Drone = 0x43,
MetroidAlpha = 0x44,
DebrisExtended = 0x45,
Steam = 0x46,
Ripple = 0x47,
BallTrigger = 0x48,
TargetingPoint = 0x49,
ElectroMagneticPulse = 0x4A,
IceSheegoth = 0x4B,
PlayerActor = 0x4C,
Flaahgra = 0x4D,
AreaAttributes = 0x4E,
FishCloud = 0x4F,
FishCloudModifier = 0x50,
VisorFlare = 0x51,
VisorGoo = 0x53,
JellyZap = 0x54,
ControllerAction = 0x55,
Switch = 0x56,
PlayerStateChange = 0x57,
Thardus = 0x58,
WallCrawlerSwarm = 0x5A,
AIJumpPoint = 0x5B,
FlaahgraTentacle = 0x5C,
RoomAcoustics = 0x5D,
ColorModulate = 0x5E,
ThardusRockProjectile = 0x5F,
Midi = 0x60,
StreamedAudio = 0x61,
WorldTeleporter = 0x62,
Repulsor = 0x63,
GunTurret = 0x64,
Babygoth = 0x66,
Eyeball = 0x67,
RadialKnockback = 0x68,
CameraPitchVolume = 0x69,
EnvFxDensityController = 0x6A,
Magdolite = 0x6B,
TeamAIMgr = 0x6C,
SnakeWeedSwarm = 0x6D,
ActorContraption = 0x6E,
Oculus = 0x6F,
Geemer = 0x70,
SpindleCamera = 0x71,
AtomicAlpha = 0x72,
CameraHintTrigger = 0x73,
RumbleEffect = 0x74,
AmbientAI = 0x75,
AtomicBeta = 0x77,
Puffer = 0x79,
Tryclops = 0x7A,
Ridley = 0x7B,
Seedling = 0x7C,
ThermalHeatFader = 0x7D,
Burrower = 0x7F,
ScriptBeam = 0x81,
WorldLightFader = 0x82,
MetroidPrimeStage2 = 0x83,
MetroidPrimeRelay = 0x84,
MazeNode = 0x85,
OmegaPirate = 0x86,
PhazonPool = 0x87,
PhazonHealingNodule = 0x88,
NewCameraShaker = 0x89,
ShadowProjector = 0x8A,
BeamEnergyBall = 0x8B
};
#endif // EOBJECTTYPE_H