Parcourir la source

Praise the Safe-Enum.

Implemented Safe-Enum for everyone.
Now the power is in the Safe-Enum for all.
undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> il y a 10 ans
Parent
révision
1e4af19a89
12 fichiers modifiés avec 422 ajouts et 451 suppressions
  1. +27
    -50
      src/easymesh/easymesh.h
  2. +125
    -175
      src/easymesh/easymeshbuild.h
  3. +8
    -17
      src/easymesh/easymeshrender.h
  4. +3
    -3
      src/gpu/shader.cpp
  5. +151
    -27
      src/lol/base/types.h
  6. +38
    -49
      src/lol/gpu/shader.h
  7. +16
    -36
      src/lol/math/geometry.h
  8. +16
    -29
      src/lol/sys/file.h
  9. +18
    -36
      src/lol/sys/thread.h
  10. +2
    -2
      src/mesh/mesh.cpp
  11. +1
    -1
      src/messageservice.cpp
  12. +17
    -26
      src/messageservice.h

+ 27
- 50
src/easymesh/easymesh.h Voir le fichier

@@ -26,40 +26,33 @@ namespace lol
{

/* A safe enum for MeshCSG operations. */
struct CSGUsage
{
enum Value
{
Union = 0,
Substract,
SubstractLoss, //will remove B from A, but not add inverted B
And,
Xor,

Max
}
m_value;

inline CSGUsage() : m_value(Union) {}
inline CSGUsage(Value v) : m_value(v) {}
inline CSGUsage(int v) : m_value((Value)v) {}
inline operator Value() { return m_value; }
};

struct Axis
{
enum Value
{
X,
Y,
Z
}
m_value;

inline Axis() : m_value(X) {}
inline Axis(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};
DEF_ENUM(CSGUsage)
DEF_VALUE
ADD_VALUE(Union)
ADD_VALUE(Substract)
ADD_VALUE(SubstractLoss) //will remove B from A, but not add inverted B
ADD_VALUE(And)
ADD_VALUE(Xor)
END_E_VALUE
END_ENUM(CSGUsage)

DEF_ENUM(Axis)
DEF_VALUE
ADD_VALUE(X)
ADD_VALUE(Y)
ADD_VALUE(Z)
END_E_VALUE
END_ENUM(Axis)

DEF_ENUM(MeshTransform)
DEF_VALUE
ADD_VALUE(Taper)
ADD_VALUE(Twist)
ADD_VALUE(Bend)
ADD_VALUE(Stretch)
ADD_VALUE(Shear)
END_E_VALUE
END_ENUM(MeshTransform)

class EasyMesh
{
@@ -245,22 +238,6 @@ public:
/* [cmd:bdzy] Same as BendXY, with Z & Y */
void BendZY(float t, float toff=0.f);
private:
struct MeshTransform
{
enum Value
{
Taper,
Twist,
Bend,
Stretch,
Shear
}
m_value;

inline MeshTransform() : m_value(Taper) {}
inline MeshTransform(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};
void DoMeshTransform(MeshTransform ct, Axis axis0, Axis axis1, float n0, float n1, float noff, bool absolute=false);
public:
/* [cmd:s/sx/sy/sz] Scale vertices


+ 125
- 175
src/easymesh/easymeshbuild.h Voir le fichier

@@ -21,168 +21,124 @@
namespace lol
{

struct MeshBuildOperation
{
enum Value
{
DEF_ENUM(MeshBuildOperation)
DEF_VALUE
//When this flag is up, negative scaling will not invert faces.
ScaleWinding = (1 << 0),
CommandRecording = (1 << 1),
CommandExecution = (1 << 2),
QuadWeighting = (1 << 3),
IgnoreQuadWeighting = (1 << 4),
PostBuildComputeNormals = (1 << 5),
PreventVertCleanup = (1 << 6),

All = 0xffffffff
}
m_value;

inline MeshBuildOperation(Value v) : m_value(v) {}
inline MeshBuildOperation(uint64_t i) : m_value((Value)i) {}
inline operator Value() { return m_value; }
};

struct EasyMeshCmdType
{
enum Value
{
MeshCsg = 0,

LoopStart,
LoopEnd,
OpenBrace,
CloseBrace,

ScaleWinding,
QuadWeighting,
PostBuildNormal,
PreventVertCleanup,
SetColorA,
SetColorB,
SetVertColor,

VerticesMerge,
VerticesSeparate,

Translate,
Rotate,
RadialJitter,
MeshTranform,
Scale,
DupAndScale,
Chamfer,

SplitTriangles,
SmoothMesh,

AppendCylinder,
AppendCapsule,
AppendTorus,
AppendBox,
AppendStar,
AppendExpandedStar,
AppendDisc,
AppendSimpleTriangle,
AppendSimpleQuad,
AppendCog,

Max
}
m_value;

inline EasyMeshCmdType(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
inline int Value() { return m_value; }
};

struct MeshType
{
enum Value
{
Triangle = 0,
Quad,
Box,
Sphere,
Capsule,
Torus,
Cylinder,
Disc,
Star,
ExpandedStar,
Cog,

Max
}
m_value;

inline MeshType(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};

//TODO : Add other Build type
struct TexCoordBuildType
{
enum Value
{
TriangleDefault = 0,
QuadDefault = 0,
BoxDefault = 0,
SphereDefault = 0,
CapsuleDefault = 0,
TorusDefault = 0,
CylinderDefault = 0,
DiscDefault = 0,
StarDefault = 0,
ExpandedStarDefault = 0,
CogDefault = 0,
ADD_VALUE_SET(ScaleWinding , (1 << 0))
ADD_VALUE_SET(CommandRecording , (1 << 1))
ADD_VALUE_SET(CommandExecution , (1 << 2))
ADD_VALUE_SET(QuadWeighting , (1 << 3))
ADD_VALUE_SET(IgnoreQuadWeighting , (1 << 4))
ADD_VALUE_SET(PostBuildComputeNormals , (1 << 5))
ADD_VALUE_SET(PreventVertCleanup , (1 << 6))

ADD_VALUE_SET(All , 0xffffffff)
END_E_VALUE
END_ENUM(MeshBuildOperation)

DEF_ENUM(EasyMeshCmdType)
DEF_VALUE
ADD_VALUE(MeshCsg)

ADD_VALUE(LoopStart)
ADD_VALUE(LoopEnd)
ADD_VALUE(OpenBrace)
ADD_VALUE(CloseBrace)

ADD_VALUE(ScaleWinding)
ADD_VALUE(QuadWeighting)
ADD_VALUE(PostBuildNormal)
ADD_VALUE(PreventVertCleanup)
ADD_VALUE(SetColorA)
ADD_VALUE(SetColorB)
ADD_VALUE(SetVertColor)

ADD_VALUE(VerticesMerge)
ADD_VALUE(VerticesSeparate)

ADD_VALUE(Translate)
ADD_VALUE(Rotate)
ADD_VALUE(RadialJitter)
ADD_VALUE(MeshTranform)
ADD_VALUE(Scale)
ADD_VALUE(DupAndScale)
ADD_VALUE(Chamfer)

ADD_VALUE(SplitTriangles)
ADD_VALUE(SmoothMesh)

ADD_VALUE(AppendCylinder)
ADD_VALUE(AppendCapsule)
ADD_VALUE(AppendTorus)
ADD_VALUE(AppendBox)
ADD_VALUE(AppendStar)
ADD_VALUE(AppendExpandedStar)
ADD_VALUE(AppendDisc)
ADD_VALUE(AppendSimpleTriangle)
ADD_VALUE(AppendSimpleQuad)
ADD_VALUE(AppendCog)
END_E_VALUE
END_ENUM(EasyMeshCmdType)

DEF_ENUM(MeshType)
DEF_VALUE
ADD_VALUE(Triangle)
ADD_VALUE(Quad)
ADD_VALUE(Box)
ADD_VALUE(Sphere)
ADD_VALUE(Capsule)
ADD_VALUE(Torus)
ADD_VALUE(Cylinder)
ADD_VALUE(Disc)
ADD_VALUE(Star)
ADD_VALUE(ExpandedStar)
ADD_VALUE(Cog)
ADD_VALUE(NEW_VALUE)
END_E_VALUE
END_ENUM(MeshType)

DEF_ENUM(TexCoordBuildType)
DEF_VALUE
ADD_VALUE_SET(TriangleDefault , 0)
ADD_VALUE_SET(QuadDefault , 0)
ADD_VALUE_SET(BoxDefault , 0)
ADD_VALUE_SET(SphereDefault , 0)
ADD_VALUE_SET(CapsuleDefault , 0)
ADD_VALUE_SET(TorusDefault , 0)
ADD_VALUE_SET(CylinderDefault , 0)
ADD_VALUE_SET(DiscDefault , 0)
ADD_VALUE_SET(StarDefault , 0)
ADD_VALUE_SET(ExpandedStarDefault , 0)
ADD_VALUE_SET(CogDefault , 0)

//NEVER FORGET TO INCREMENT THIS WHEN ADDING A VALUE
Max = 1
}
m_value;

inline TexCoordBuildType() : m_value(TriangleDefault) {}
inline TexCoordBuildType(Value v) : m_value(v) {}
inline TexCoordBuildType(int v) : m_value((Value)v) {}
inline operator Value() { return m_value; }
};

struct MeshFaceType
{
enum Value
{
BoxFront = 0,
BoxLeft = 1,
BoxBack = 2,
BoxRight = 3,
BoxTop = 4,
BoxBottom = 5,
QuadDefault = 0,
ADD_VALUE_SET(Max , 1)
END_E_VALUE
END_ENUM(TexCoordBuildType)

DEF_ENUM(MeshFaceType)
DEF_VALUE
ADD_VALUE_SET(BoxFront , 0)
ADD_VALUE_SET(BoxLeft , 1)
ADD_VALUE_SET(BoxBack , 2)
ADD_VALUE_SET(BoxRight , 3)
ADD_VALUE_SET(BoxTop , 4)
ADD_VALUE_SET(BoxBottom , 5)
ADD_VALUE_SET(QuadDefault , 0)

//NEVER FORGET TO INCREMENT THIS WHEN ADDING A VALUE
Max = 6
}
m_value;

inline MeshFaceType(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};

struct TexCoordPos
{
enum Value
{
BL, //BottomLeft
BR, //BottomRight
TL, //TopLeft
TR //TopRight
}
m_value;

inline TexCoordPos(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};
ADD_VALUE_SET(Max , 6)
END_E_VALUE
END_ENUM(MeshFaceType)

DEF_ENUM(TexCoordPos)
DEF_VALUE
ADD_VALUE(BL) //BottomLeft
ADD_VALUE(BR) //BottomRight
ADD_VALUE(TL) //TopLeft
ADD_VALUE(TR) //TopRight
END_E_VALUE
END_ENUM(TexCoordPos)

class EasyMeshBuildData
{
@@ -198,7 +154,7 @@ public:
m_build_flags = 0;
m_i_cmd = 0;
m_exec_nb = -1;
for (int i = 0; i < MeshType::Max; ++i)
for (int i = 0; i < MeshType::MAX; ++i)
{
m_texcoord_build_type[i] = TexCoordBuildType::TriangleDefault;
m_texcoord_build_type2[i] = TexCoordBuildType::TriangleDefault;
@@ -405,27 +361,21 @@ public:
vec2 m_texcoord_offset2;
vec2 m_texcoord_scale;
vec2 m_texcoord_scale2;
Array<vec2, vec2> m_texcoord_custom_build[MeshType::Max];
Array<vec2, vec2> m_texcoord_custom_build2[MeshType::Max];
uint32_t m_texcoord_build_type[MeshType::Max];
uint32_t m_texcoord_build_type2[MeshType::Max];
Array<vec2, vec2> m_texcoord_custom_build[MeshType::MAX];
Array<vec2, vec2> m_texcoord_custom_build2[MeshType::MAX];
uint32_t m_texcoord_build_type[MeshType::MAX];
uint32_t m_texcoord_build_type2[MeshType::MAX];
uint32_t m_build_flags;
};

/* A safe enum for VertexDictionnary operations. */
struct VDictType
{
enum Value
{
DoesNotExist=-3,
Alone=-2,
Master=-1
}
m_value;

inline VDictType(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};
DEF_ENUM(VDictType)
DEF_VALUE
ADD_VALUE_SET(DoesNotExist , -3)
ADD_VALUE_SET(Alone , -2)
ADD_VALUE_SET(Master , -1)
END_E_VALUE
END_ENUM(VDictType)

/* TODO : replace VDict by a proper Half-edge system */
//a class whose goal is to keep a list of the adjacent vertices for mesh operations purposes


+ 8
- 17
src/easymesh/easymeshrender.h Voir le fichier

@@ -22,23 +22,14 @@ namespace lol
{

//Utility enum for renderers
struct MeshRender
{
enum Value
{
NeedData = 0,
NeedConvert,
CanRender,
IgnoreRender,

Max
}
m_value;

inline MeshRender(Value v) : m_value(v) {}
inline MeshRender() : m_value(NeedData) {}
inline operator Value() { return m_value; }
};
DEF_ENUM(MeshRender)
DEF_VALUE
ADD_VALUE(NeedData)
ADD_VALUE(NeedConvert)
ADD_VALUE(CanRender)
ADD_VALUE(IgnoreRender)
END_E_VALUE
END_ENUM(MeshRender)

//Vertex datas for easymesh vertex list.
//TODO : <COORD, NORM, COLOR, UV>


+ 3
- 3
src/gpu/shader.cpp Voir le fichier

@@ -390,8 +390,8 @@ Shader::Shader(char const *vert, char const *frag)

String name(name_buffer);
int index = -1;
VertexUsage usage = VertexUsage::Max;
for (int j = 0; j < VertexUsage::Max; ++j)
VertexUsage usage = VertexUsage::MAX;
for (int j = 0; j < VertexUsage::MAX; ++j)
{
if (name.StartsWith(attribute_names[j]))
{
@@ -402,7 +402,7 @@ Shader::Shader(char const *vert, char const *frag)
}
}

if (usage == VertexUsage::Max || index == -1)
if (usage == VertexUsage::MAX || index == -1)
{
Log::Error("unable to parse attribute semantic from name: %s",
name_buffer);


+ 151
- 27
src/lol/base/types.h Voir le fichier

@@ -28,36 +28,160 @@ typedef Real<16> real;
/* The “half” type used for 16-bit floating point numbers. */
class half;

#define DEFINE_ENUM(NEW_ENUM) struct NEW_ENUM {
//-- STRUCT TEMPLATE:
//DEF_ENUM(NEW_ENUM)
// DEF_VALUE
// ADD_VALUE(NEW_VALUE)
// ADD_VALUE_SET(NEW_VALUE, VALUE_SET)
// END_E_VALUE
// DEF_TEXT
// ADD_TEXT(NEW_VALUE)
// END_TEXT
//END_ENUM(NEW_ENUM)

#define START_VALUE enum Value {
#define ADD_VALUE(NEW_VALUE) E##NEW_VALUE,
#define END_VALUE MAX } m_value;
#define DEF_ENUM(NEW_ENUM) struct NEW_ENUM {
#define END_ENUM(NEW_ENUM) \
inline NEW_ENUM() : m_value(MAX) {} \
inline NEW_ENUM(Value v) : m_value(v) {} \
inline NEW_ENUM(const int8_t & v) : m_value((Value)v) {} \
inline NEW_ENUM(const int16_t & v) : m_value((Value)v) {} \
inline NEW_ENUM(const int32_t & v) : m_value((Value)v) {} \
inline NEW_ENUM(const int64_t & v) : m_value((Value)v) {} \
inline NEW_ENUM(const uint8_t & v) : m_value((Value)v) {} \
inline NEW_ENUM(const uint16_t & v) : m_value((Value)v) {} \
inline NEW_ENUM(const uint32_t & v) : m_value((Value)v) {} \
inline NEW_ENUM(const uint64_t & v) : m_value((Value)v) {} \
inline NEW_ENUM(const float & v) : m_value((Value)(int)v) {} \
inline NEW_ENUM(const double & v) : m_value((Value)(int)v) {} \
inline operator Value() { return m_value; } \
inline int32_t I() { return (int32_t ) m_value; } \
inline int8_t I8() { return (int8_t ) m_value; } \
inline int16_t I16() { return (int16_t ) m_value; } \
inline int32_t I32() { return (int32_t ) m_value; } \
inline int64_t I64() { return (int64_t ) m_value; } \
inline uint32_t UI() { return (uint32_t) m_value; } \
inline uint8_t UI8() { return (uint8_t ) m_value; } \
inline uint16_t UI16() { return (uint16_t) m_value; } \
inline uint32_t UI32() { return (uint32_t) m_value; } \
inline uint64_t UI64() { return (uint64_t) m_value; } \
inline float F() { return (float ) m_value; } \
inline double D() { return (double ) m_value; } \
bool operator==(const NEW_ENUM & v) { return m_value == v.m_value; } \
bool operator==(const Value & v) { return m_value == v; } \
bool operator==(const int8_t & v) { return m_value == NEW_ENUM(v); } \
bool operator==(const int16_t & v) { return m_value == NEW_ENUM(v); } \
bool operator==(const int32_t & v) { return m_value == NEW_ENUM(v); } \
bool operator==(const int64_t & v) { return m_value == NEW_ENUM(v); } \
bool operator==(const uint8_t & v) { return m_value == NEW_ENUM(v); } \
bool operator==(const uint16_t & v) { return m_value == NEW_ENUM(v); } \
bool operator==(const uint32_t & v) { return m_value == NEW_ENUM(v); } \
bool operator==(const uint64_t & v) { return m_value == NEW_ENUM(v); } \
bool operator==(const float & v) { return m_value == NEW_ENUM(v); } \
bool operator==(const double & v) { return m_value == NEW_ENUM(v); } \
bool operator!=(const NEW_ENUM & v) { return m_value != v.m_value; } \
bool operator!=(const Value & v) { return m_value != v; } \
bool operator!=(const int8_t & v) { return m_value != NEW_ENUM(v); } \
bool operator!=(const int16_t & v) { return m_value != NEW_ENUM(v); } \
bool operator!=(const int32_t & v) { return m_value != NEW_ENUM(v); } \
bool operator!=(const int64_t & v) { return m_value != NEW_ENUM(v); } \
bool operator!=(const uint8_t & v) { return m_value != NEW_ENUM(v); } \
bool operator!=(const uint16_t & v) { return m_value != NEW_ENUM(v); } \
bool operator!=(const uint32_t & v) { return m_value != NEW_ENUM(v); } \
bool operator!=(const uint64_t & v) { return m_value != NEW_ENUM(v); } \
bool operator!=(const float & v) { return m_value != NEW_ENUM(v); } \
bool operator!=(const double & v) { return m_value != NEW_ENUM(v); } \
bool operator<(const NEW_ENUM & v) { return m_value < v.m_value; } \
bool operator<(const Value & v) { return m_value < v; } \
bool operator<(const int8_t & v) { return m_value < NEW_ENUM(v); } \
bool operator<(const int16_t & v) { return m_value < NEW_ENUM(v); } \
bool operator<(const int32_t & v) { return m_value < NEW_ENUM(v); } \
bool operator<(const int64_t & v) { return m_value < NEW_ENUM(v); } \
bool operator<(const uint8_t & v) { return m_value < NEW_ENUM(v); } \
bool operator<(const uint16_t & v) { return m_value < NEW_ENUM(v); } \
bool operator<(const uint32_t & v) { return m_value < NEW_ENUM(v); } \
bool operator<(const uint64_t & v) { return m_value < NEW_ENUM(v); } \
bool operator<(const float & v) { return m_value < NEW_ENUM(v); } \
bool operator<(const double & v) { return m_value < NEW_ENUM(v); } \
bool operator>(const NEW_ENUM & v) { return m_value > v.m_value; } \
bool operator>(const Value & v) { return m_value > v; } \
bool operator>(const int8_t & v) { return m_value > NEW_ENUM(v); } \
bool operator>(const int16_t & v) { return m_value > NEW_ENUM(v); } \
bool operator>(const int32_t & v) { return m_value > NEW_ENUM(v); } \
bool operator>(const int64_t & v) { return m_value > NEW_ENUM(v); } \
bool operator>(const uint8_t & v) { return m_value > NEW_ENUM(v); } \
bool operator>(const uint16_t & v) { return m_value > NEW_ENUM(v); } \
bool operator>(const uint32_t & v) { return m_value > NEW_ENUM(v); } \
bool operator>(const uint64_t & v) { return m_value > NEW_ENUM(v); } \
bool operator>(const float & v) { return m_value > NEW_ENUM(v); } \
bool operator>(const double & v) { return m_value > NEW_ENUM(v); } \
bool operator<=(const NEW_ENUM & v) { return m_value <= v.m_value; } \
bool operator<=(const Value & v) { return m_value <= v; } \
bool operator<=(const int8_t & v) { return m_value <= NEW_ENUM(v); } \
bool operator<=(const int16_t & v) { return m_value <= NEW_ENUM(v); } \
bool operator<=(const int32_t & v) { return m_value <= NEW_ENUM(v); } \
bool operator<=(const int64_t & v) { return m_value <= NEW_ENUM(v); } \
bool operator<=(const uint8_t & v) { return m_value <= NEW_ENUM(v); } \
bool operator<=(const uint16_t & v) { return m_value <= NEW_ENUM(v); } \
bool operator<=(const uint32_t & v) { return m_value <= NEW_ENUM(v); } \
bool operator<=(const uint64_t & v) { return m_value <= NEW_ENUM(v); } \
bool operator<=(const float & v) { return m_value <= NEW_ENUM(v); } \
bool operator<=(const double & v) { return m_value <= NEW_ENUM(v); } \
bool operator>=(const NEW_ENUM & v) { return m_value >= v.m_value; } \
bool operator>=(const Value & v) { return m_value >= v; } \
bool operator>=(const int8_t & v) { return m_value >= NEW_ENUM(v); } \
bool operator>=(const int16_t & v) { return m_value >= NEW_ENUM(v); } \
bool operator>=(const int32_t & v) { return m_value >= NEW_ENUM(v); } \
bool operator>=(const int64_t & v) { return m_value >= NEW_ENUM(v); } \
bool operator>=(const uint8_t & v) { return m_value >= NEW_ENUM(v); } \
bool operator>=(const uint16_t & v) { return m_value >= NEW_ENUM(v); } \
bool operator>=(const uint32_t & v) { return m_value >= NEW_ENUM(v); } \
bool operator>=(const uint64_t & v) { return m_value >= NEW_ENUM(v); } \
bool operator>=(const float & v) { return m_value >= NEW_ENUM(v); } \
bool operator>=(const double & v) { return m_value >= NEW_ENUM(v); } \
};
/*
bool operator== (NEW_ENUM::Value& e1, NEW_ENUM& e2) { return (e2 == e1); }
bool operator== (int& e1, NEW_ENUM& e2) { return (e2 == e1); }
bool operator== (uint32_t& e1, NEW_ENUM& e2) { return (e2 == e1); }
bool operator== (float& e1, NEW_ENUM& e2) { return (e2 == e1); }
bool operator!= (NEW_ENUM::Value& e1, NEW_ENUM& e2) { return (e2 != e1); }
bool operator!= (int& e1, NEW_ENUM& e2) { return (e2 != e1); }
bool operator!= (uint32_t& e1, NEW_ENUM& e2) { return (e2 != e1); }
bool operator!= (float& e1, NEW_ENUM& e2) { return (e2 != e1); }
bool operator< (NEW_ENUM::Value& e1, NEW_ENUM& e2) { return (e2 < e1); }
bool operator< (int& e1, NEW_ENUM& e2) { return (e2 < e1); }
bool operator< (uint32_t& e1, NEW_ENUM& e2) { return (e2 < e1); }
bool operator< (float& e1, NEW_ENUM& e2) { return (e2 < e1); }
bool operator> (NEW_ENUM::Value& e1, NEW_ENUM& e2) { return (e2 > e1); }
bool operator> (int& e1, NEW_ENUM& e2) { return (e2 > e1); }
bool operator> (uint32_t& e1, NEW_ENUM& e2) { return (e2 > e1); }
bool operator> (float& e1, NEW_ENUM& e2) { return (e2 > e1); }
bool operator<= (NEW_ENUM::Value& e1, NEW_ENUM& e2) { return (e2 <= e1); }
bool operator<= (int& e1, NEW_ENUM& e2) { return (e2 <= e1); }
bool operator<= (uint32_t& e1, NEW_ENUM& e2) { return (e2 <= e1); }
bool operator<= (float& e1, NEW_ENUM& e2) { return (e2 <= e1); }
bool operator>= (NEW_ENUM::Value& e1, NEW_ENUM& e2) { return (e2 >= e1); }
bool operator>= (int& e1, NEW_ENUM& e2) { return (e2 >= e1); }
bool operator>= (uint32_t& e1, NEW_ENUM& e2) { return (e2 >= e1); }
bool operator>= (float& e1, NEW_ENUM& e2) { return (e2 >= e1); }
*/

#define START_TEXT \
inline String C() \
{ \
static String text[] = {
#define ADD_TEXT(NEW_TEXT) #NEW_TEXT,
#define END_TEXT \
}; \
if (m_value >= MAX) \
return "INVALID"; \
return text[m_value]; \
}; \
#define DEF_VALUE enum Value { INVALID = -1,
#define ADD_VALUE(NEW_VALUE) NEW_VALUE,
#define ADD_VALUE_SET(NEW_VALUE, VALUE_SET) NEW_VALUE = VALUE_SET,
#define END_E_VALUE MAX } m_value;

#define END_ENUM(NEW_ENUM) \
inline NEW_ENUM() : m_value(MAX) {} \
inline NEW_ENUM(Value v) : m_value(v) {} \
inline NEW_ENUM(int v) : m_value((Value)v) {} \
inline NEW_ENUM(float v) : m_value((Value)(int)v) {} \
bool operator==(const NEW_ENUM& v) { return m_value == v.m_value; } \
bool operator==(const int& v) { return m_value == NEW_ENUM(v); } \
bool operator==(const float& v) { return m_value == NEW_ENUM(v); } \
inline operator Value() { return m_value; } \
}; \
bool operator== (int e1, NEW_ENUM& e2) { return (e2 == e1); } \
bool operator== (float e1, NEW_ENUM& e2){ return (e2 == e1); }
#define DEF_TEXT \
inline String C() \
{ \
static const String text[] = {
#define ADD_TEXT(NEW_TEXT) String(#NEW_TEXT),
#define ADD_TEXT_PADDING String(""),
#define END_TEXT }; \
if (m_value < 0 || m_value >= MAX) \
return "INVALID"; \
return text[m_value]; \
};

} /* namespace lol */



+ 38
- 49
src/lol/gpu/shader.h Voir le fichier

@@ -25,54 +25,47 @@ namespace lol
* now there is only TexCoord and not TexCoord0 TexCoord1 etc. because
* we can always reorganise the vertex declaration for the indices to
* match. If the need arises these enums will be added. */
struct VertexUsage
{
enum Value
{
Position = 0,
BlendWeight,
BlendIndices,
Normal,
PointSize,
TexCoord,
TexCoordExt,
Tangent,
Binormal,
TessFactor,
PositionT,
Color,
Fog,
Depth,
Sample,

Max
}
m_value;

DEF_ENUM(VertexUsage)
DEF_VALUE
ADD_VALUE(Position)
ADD_VALUE(BlendWeight)
ADD_VALUE(BlendIndices)
ADD_VALUE(Normal)
ADD_VALUE(PointSize)
ADD_VALUE(TexCoord)
ADD_VALUE(TexCoordExt)
ADD_VALUE(Tangent)
ADD_VALUE(Binormal)
ADD_VALUE(TessFactor)
ADD_VALUE(PositionT)
ADD_VALUE(Color)
ADD_VALUE(Fog)
ADD_VALUE(Depth)
ADD_VALUE(Sample)
END_E_VALUE
DEF_TEXT
ADD_TEXT(Position)
ADD_TEXT(BlendWeight)
ADD_TEXT(BlendIndices)
ADD_TEXT(Normal)
ADD_TEXT(PointSize)
ADD_TEXT(TexCoord)
ADD_TEXT(TexCoordExt)
ADD_TEXT(Tangent)
ADD_TEXT(Binormal)
ADD_TEXT(TessFactor)
ADD_TEXT(PositionT)
ADD_TEXT(Color)
ADD_TEXT(Fog)
ADD_TEXT(Depth)
ADD_TEXT(Sample)
END_TEXT
private:
static String GetName(Value v, bool use_simple)
{
String tmp = String("");
if (!use_simple) tmp += "<";
switch (v)
{
case Position: { tmp += "Position"; break; }
case BlendWeight: { tmp += "BlendWeight"; break; }
case BlendIndices: { tmp += "BlendIndices";break; }
case Normal: { tmp += "Normal"; break; }
case PointSize: { tmp += "PointSize"; break; }
case TexCoord: { tmp += "TexCoord"; break; }
case TexCoordExt: { tmp += "TexCoordExt"; break; }
case Tangent: { tmp += "Tangent"; break; }
case Binormal: { tmp += "Binormal"; break; }
case TessFactor: { tmp += "TessFactor"; break; }
case PositionT: { tmp += "PositionT"; break; }
case Color: { tmp += "Color"; break; }
case Fog: { tmp += "Fog"; break; }
case Depth: { tmp += "Depth"; break; }
case Sample: { tmp += "Sample"; break; }
default: { tmp += "UNDEFINED"; break; }
}
tmp += VertexUsage(v).C();
if (!use_simple) tmp += ">";
return tmp;
}
@@ -87,7 +80,7 @@ public:
{
String tmp = String("<");
int nb = 0;
for (int i = 0; i < Max; ++i)
for (int i = 0; i < MAX; ++i)
{
if (v & (1<<i))
{
@@ -99,11 +92,7 @@ public:
}
return tmp + ">";
}

inline VertexUsage(Value v) : m_value(v) {}
inline VertexUsage(int v) : m_value((Value)v) {}
inline operator Value() { return m_value; }
};
END_ENUM(VertexUsage)

struct ShaderUniform
{


+ 16
- 36
src/lol/math/geometry.h Voir le fichier

@@ -238,25 +238,16 @@ bool TestRayVsTriangle(vec3 const &ray_point, vec3 const &ray_dir,
vec3 const &tri_p0, vec3 const &tri_p1, vec3 const &tri_p2,
vec3 &vi);

struct RayIntersect
{
enum Value
{
Nothing = 0,
All,
None,
P0,
P1,

MAX
}
m_value;
DEF_ENUM(RayIntersect)
DEF_VALUE
ADD_VALUE(Nothing)
ADD_VALUE(All)
ADD_VALUE(None)
ADD_VALUE(P0)
ADD_VALUE(P1)
END_E_VALUE
END_ENUM(RayIntersect)

inline RayIntersect() : m_value(Nothing) {}
inline RayIntersect(Value v) : m_value(v) {}
inline RayIntersect(int v) : m_value((Value)v) {}
inline operator Value() { return m_value; }
};
#define RAY_ISECT_NOTHING 0
#define RAY_ISECT_ALL 1
#define RAY_ISECT_NONE 2
@@ -302,24 +293,13 @@ bool TestRayVsPlane(const TV &ray_p0, const TV &ray_p1,
}

/* A safe enum for Primitive edge face. */
struct PlaneIntersection
{
enum Value
{
Invalid=-1,
Back,
Front,
Plane,

MAX
}
m_value;

inline PlaneIntersection() : m_value(Invalid) {}
inline PlaneIntersection(Value v) : m_value(v) {}
inline PlaneIntersection(int v) : m_value((Value)v) {}
inline operator Value() { return m_value; }
};
DEF_ENUM(PlaneIntersection)
DEF_VALUE
ADD_VALUE(Back)
ADD_VALUE(Front)
ADD_VALUE(Plane)
END_E_VALUE
END_ENUM(PlaneIntersection)

//Point/Plane : Normal must be given normalized.
template <typename TV>


+ 16
- 29
src/lol/sys/file.h Voir le fichier

@@ -21,35 +21,22 @@
namespace lol
{

struct FileAccess
{
enum Value
{
Read = 0,
Write,
}
m_value;

inline FileAccess(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
};

struct StreamType
{
enum Value
{
StdIn = 0,
StdOut,
StdErr,
File,
FileBinary
}
m_value;

inline StreamType(Value v) : m_value(v) {}
inline operator Value() { return m_value; }
inline int Value() { return m_value; }
};
DEF_ENUM(FileAccess)
DEF_VALUE
ADD_VALUE(Read)
ADD_VALUE(Write)
END_E_VALUE
END_ENUM(FileAccess)

DEF_ENUM(StreamType)
DEF_VALUE
ADD_VALUE(StdIn)
ADD_VALUE(StdOut)
ADD_VALUE(StdErr)
ADD_VALUE(File)
ADD_VALUE(FileBinary)
END_E_VALUE
END_ENUM(StreamType)

class File
{


+ 18
- 36
src/lol/sys/thread.h Voir le fichier

@@ -47,42 +47,24 @@ public:
virtual ~Thread() {}
};

struct ThreadStatus
{
enum Value
{
NOTHING = 0,
THREAD_STARTED,
THREAD_STOPPED,

MAX
}
m_value;

inline ThreadStatus() : m_value(ThreadStatus::NOTHING) {}
inline ThreadStatus(Value v) : m_value(v) {}
bool operator==(const ThreadStatus& v) { return m_value == v.m_value; }
};

struct ThreadJobType
{
enum Value
{
NONE = 0,
WORK_TODO,
WORK_DONE,
WORK_FAILED,
WORK_FETCHED,
THREAD_STOP,

MAX
}
m_value;

inline ThreadJobType() : m_value(ThreadJobType::MAX) {}
inline ThreadJobType(Value v) : m_value(v) {}
bool operator==(const ThreadJobType& o) { return m_value == o.m_value; }
};
DEF_ENUM(ThreadStatus)
DEF_VALUE
ADD_VALUE(NOTHING)
ADD_VALUE(THREAD_STARTED)
ADD_VALUE(THREAD_STOPPED)
END_E_VALUE
END_ENUM(ThreadStatus)

DEF_ENUM(ThreadJobType)
DEF_VALUE
ADD_VALUE(NONE)
ADD_VALUE(WORK_TODO)
ADD_VALUE(WORK_DONE)
ADD_VALUE(WORK_FAILED)
ADD_VALUE(WORK_FETCHED)
ADD_VALUE(THREAD_STOP)
END_E_VALUE
END_ENUM(ThreadJobType)

class ThreadJob
{


+ 2
- 2
src/mesh/mesh.cpp Voir le fichier

@@ -85,8 +85,8 @@ void SubMesh::Render(Shader* shader)
return;
}

int indices[VertexUsage::Max];
memset(indices, 0, sizeof(int) * VertexUsage::Max);
int indices[VertexUsage::MAX];
memset(indices, 0, sizeof(int) * VertexUsage::MAX);

VertexStreamBase stream = m_vdecl->GetStream(i);
for (int j = 0; j < stream.GetStreamCount(); ++j)


+ 1
- 1
src/messageservice.cpp Voir le fichier

@@ -53,7 +53,7 @@ MessageService::~MessageService()
void MessageService::Setup()
{
g_messageservice = new MessageService();
g_messageservice->m_bucket.Resize(MessageBucket::Max);
g_messageservice->m_bucket.Resize(MessageBucket::MAX);
}

void MessageService::Destroy()


+ 17
- 26
src/messageservice.h Voir le fichier

@@ -21,32 +21,23 @@ namespace lol
{

//Utility enum for message service
struct MessageBucket
{
enum Value
{
AppIn = 0,
AppOut,

Bckt0,
Bckt1,
Bckt2,
Bckt3,
Bckt4,
Bckt5,
Bckt6,
Bckt7,
Bckt8,
Bckt9,

Max
}
m_value;

inline MessageBucket(Value v) : m_value(v) {}
inline MessageBucket() : m_value(AppIn) {}
inline operator Value() { return m_value; }
};
DEF_ENUM(MessageBucket)
DEF_VALUE
ADD_VALUE(AppIn)
ADD_VALUE(AppOut)

ADD_VALUE(Bckt0)
ADD_VALUE(Bckt1)
ADD_VALUE(Bckt2)
ADD_VALUE(Bckt3)
ADD_VALUE(Bckt4)
ADD_VALUE(Bckt5)
ADD_VALUE(Bckt6)
ADD_VALUE(Bckt7)
ADD_VALUE(Bckt8)
ADD_VALUE(Bckt9)
END_E_VALUE
END_ENUM(MessageBucket)

//Message list container with time in it
struct MessageList


Chargement…
Annuler
Enregistrer