Enforced G3D enum type safety

This commit is contained in:
mathusummut
2018-10-03 23:08:44 +02:00
parent 4da0c7bc73
commit 8efc78ebe7
3 changed files with 75 additions and 18 deletions

View File

@@ -76,7 +76,7 @@ namespace Shared {
bool glow; bool glow;
uint8 factionColorOpacity; uint8 factionColorOpacity;
uint32 textureFlags; MeshTexture textureFlags;
InterpolationData *interpolationData; InterpolationData *interpolationData;
TextureManager *textureManager; TextureManager *textureManager;

View File

@@ -40,22 +40,64 @@ namespace Shared {
mtMorphMesh mtMorphMesh
}; };
enum MeshPropertyFlag { enum MeshPropertyFlag : uint32 {
mpfNone = 0, mpfNone = 0,
mpfCustomColor = 1, mpfCustomColor = 1,
mpfTwoSided = 2, mpfTwoSided = 2,
mpfNoSelect = 4, mpfNoSelect = 4,
mpfGlow = 8 mpfGlow = 8
}; };
inline MeshPropertyFlag operator~ (MeshPropertyFlag a) {
return (MeshPropertyFlag) ~(uint32) a;
}
inline MeshPropertyFlag operator| (MeshPropertyFlag a, MeshPropertyFlag b) {
return (MeshPropertyFlag) ((uint32) a | (uint32) b);
}
inline MeshPropertyFlag operator& (MeshPropertyFlag a, MeshPropertyFlag b) {
return (MeshPropertyFlag) ((uint32) a & (uint32) b);
}
inline MeshPropertyFlag operator^ (MeshPropertyFlag a, MeshPropertyFlag b) {
return (MeshPropertyFlag) ((uint32) a ^ (uint32) b);
}
inline MeshPropertyFlag& operator|= (MeshPropertyFlag& a, MeshPropertyFlag b) {
return (MeshPropertyFlag&) ((uint32&) a |= (uint32) b);
}
inline MeshPropertyFlag& operator&= (MeshPropertyFlag& a, MeshPropertyFlag b) {
return (MeshPropertyFlag&) ((uint32&) a &= (uint32) b);
}
inline MeshPropertyFlag& operator^= (MeshPropertyFlag& a, MeshPropertyFlag b) {
return (MeshPropertyFlag&) ((uint32&) a ^= (uint32) b);
}
static const int MESH_TEXTURE_COUNT = 3; static const int MESH_TEXTURE_COUNT = 3;
enum MeshTexture { enum MeshTexture : uint32 {
mtNone = 0, mtNone = 0,
mtDiffuse = 1, mtDiffuse = 1,
mtSpecular = 2, mtSpecular = 2,
mtNormal = 4 mtNormal = 4
}; };
inline MeshTexture operator~ (MeshTexture a) {
return (MeshTexture) ~(uint32) a;
}
inline MeshTexture operator| (MeshTexture a, MeshTexture b) {
return (MeshTexture) ((uint32) a | (uint32) b);
}
inline MeshTexture operator& (MeshTexture a, MeshTexture b) {
return (MeshTexture) ((uint32) a & (uint32) b);
}
inline MeshTexture operator^ (MeshTexture a, MeshTexture b) {
return (MeshTexture) ((uint32) a ^ (uint32) b);
}
inline MeshTexture& operator|= (MeshTexture& a, MeshTexture b) {
return (MeshTexture&) ((uint32&) a |= (uint32) b);
}
inline MeshTexture& operator&= (MeshTexture& a, MeshTexture b) {
return (MeshTexture&) ((uint32&) a &= (uint32) b);
}
inline MeshTexture& operator^= (MeshTexture& a, MeshTexture b) {
return (MeshTexture&) ((uint32&) a ^= (uint32) b);
}
const int meshTextureChannelCount[] = { 4, 1, 3 }; const int meshTextureChannelCount[] = { 4, 1, 3 };
@@ -71,8 +113,8 @@ namespace Shared {
float32 specularColor[3]; float32 specularColor[3];
float32 specularPower; float32 specularPower;
float32 opacity; float32 opacity;
uint32 properties; MeshPropertyFlag properties;
uint32 textures; MeshTexture textures;
}; };
#pragma pack(pop) #pragma pack(pop)
@@ -84,12 +126,33 @@ namespace Shared {
uint32 meshCount; uint32 meshCount;
}; };
enum MeshPropertyV3 { enum MeshPropertyV3 : uint32 {
mp3None = 0, mp3None = 0,
mp3NoTexture = 1, mp3NoTexture = 1,
mp3TwoSided = 2, mp3TwoSided = 2,
mp3CustomColor = 4 mp3CustomColor = 4
}; };
inline MeshPropertyV3 operator~ (MeshPropertyV3 a) {
return (MeshPropertyV3) ~(uint32) a;
}
inline MeshPropertyV3 operator| (MeshPropertyV3 a, MeshPropertyV3 b) {
return (MeshPropertyV3) ((uint32) a | (uint32) b);
}
inline MeshPropertyV3 operator& (MeshPropertyV3 a, MeshPropertyV3 b) {
return (MeshPropertyV3) ((uint32) a & (uint32) b);
}
inline MeshPropertyV3 operator^ (MeshPropertyV3 a, MeshPropertyV3 b) {
return (MeshPropertyV3) ((uint32) a ^ (uint32) b);
}
inline MeshPropertyV3& operator|= (MeshPropertyV3& a, MeshPropertyV3 b) {
return (MeshPropertyV3&) ((uint32&) a |= (uint32) b);
}
inline MeshPropertyV3& operator&= (MeshPropertyV3& a, MeshPropertyV3 b) {
return (MeshPropertyV3&) ((uint32&) a &= (uint32) b);
}
inline MeshPropertyV3& operator^= (MeshPropertyV3& a, MeshPropertyV3 b) {
return (MeshPropertyV3&) ((uint32&) a ^= (uint32) b);
}
struct MeshHeaderV3 { struct MeshHeaderV3 {
uint32 vertexFrameCount; uint32 vertexFrameCount;
@@ -98,7 +161,7 @@ namespace Shared {
uint32 colorFrameCount; uint32 colorFrameCount;
uint32 pointCount; uint32 pointCount;
uint32 indexCount; uint32 indexCount;
uint32 properties; MeshPropertyV3 properties;
uint8 texName[64]; uint8 texName[64];
}; };

View File

@@ -228,7 +228,7 @@ namespace Shared {
glow = false; glow = false;
factionColorOpacity = 255; factionColorOpacity = 255;
textureFlags = 0; textureFlags = mtNone;
hasBuiltVBOs = false; hasBuiltVBOs = false;
// Vertex Buffer Object Names // Vertex Buffer Object Names
@@ -447,10 +447,7 @@ namespace Shared {
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("Load v2, this = %p Found meshHeader.hasTexture = %d, texName [%s] mtDiffuse = %d meshIndex = %d modelFile [%s]\n", this, meshHeader.hasTexture, toLower(reinterpret_cast<char*>(meshHeader.texName)).c_str(), mtDiffuse, meshIndex, modelFile.c_str()); if (SystemFlags::VERBOSE_MODE_ENABLED) printf("Load v2, this = %p Found meshHeader.hasTexture = %d, texName [%s] mtDiffuse = %d meshIndex = %d modelFile [%s]\n", this, meshHeader.hasTexture, toLower(reinterpret_cast<char*>(meshHeader.texName)).c_str(), mtDiffuse, meshIndex, modelFile.c_str());
textureFlags = 0; textureFlags = meshHeader.hasTexture ? mtDiffuse : mtNone;
if (meshHeader.hasTexture) {
textureFlags = 1;
}
//texture //texture
if (meshHeader.hasTexture && textureManager != NULL) { if (meshHeader.hasTexture && textureManager != NULL) {
@@ -586,10 +583,7 @@ namespace Shared {
noSelect = false; noSelect = false;
glow = false; glow = false;
textureFlags = 0; textureFlags = ((meshHeader.properties & mp3NoTexture) == mp3NoTexture) ? mtNone : mtDiffuse;
if ((meshHeader.properties & mp3NoTexture) != mp3NoTexture) {
textureFlags = 1;
}
if (SystemFlags::VERBOSE_MODE_ENABLED) printf("Load v3, this = %p Found meshHeader.properties = %d, textureFlags = %d, texName [%s] mtDiffuse = %d meshIndex = %d modelFile [%s]\n", this, meshHeader.properties, textureFlags, toLower(reinterpret_cast<char*>(meshHeader.texName)).c_str(), mtDiffuse, meshIndex, modelFile.c_str()); if (SystemFlags::VERBOSE_MODE_ENABLED) printf("Load v3, this = %p Found meshHeader.properties = %d, textureFlags = %d, texName [%s] mtDiffuse = %d meshIndex = %d modelFile [%s]\n", this, meshHeader.properties, textureFlags, toLower(reinterpret_cast<char*>(meshHeader.texName)).c_str(), mtDiffuse, meshIndex, modelFile.c_str());
@@ -888,9 +882,9 @@ namespace Shared {
meshHeader.opacity = opacity; meshHeader.opacity = opacity;
//properties //properties
meshHeader.properties = 0; meshHeader.properties = mpfNone;
if (customColor) { if (customColor) {
meshHeader.properties |= (255 - (factionColorOpacity << 24)) | mpfCustomColor; meshHeader.properties |= static_cast<MeshPropertyFlag>(255 - (factionColorOpacity << 24)) | mpfCustomColor;
} }
if (twoSided) { if (twoSided) {
meshHeader.properties |= mpfTwoSided; meshHeader.properties |= mpfTwoSided;