소스 검색

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> 10 년 전
부모
커밋
1e4af19a89
12개의 변경된 파일422개의 추가작업 그리고 451개의 파일을 삭제
  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 파일 보기

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


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

DEF_ENUM(Axis)
Max DEF_VALUE
} ADD_VALUE(X)
m_value; ADD_VALUE(Y)

ADD_VALUE(Z)
inline CSGUsage() : m_value(Union) {} END_E_VALUE
inline CSGUsage(Value v) : m_value(v) {} END_ENUM(Axis)
inline CSGUsage(int v) : m_value((Value)v) {} DEF_ENUM(MeshTransform)
inline operator Value() { return m_value; } DEF_VALUE
}; ADD_VALUE(Taper)

ADD_VALUE(Twist)
struct Axis ADD_VALUE(Bend)
{ ADD_VALUE(Stretch)
enum Value ADD_VALUE(Shear)
{ END_E_VALUE
X, END_ENUM(MeshTransform)
Y,
Z
}
m_value;

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


class EasyMesh class EasyMesh
{ {
@@ -245,22 +238,6 @@ public:
/* [cmd:bdzy] Same as BendXY, with Z & Y */ /* [cmd:bdzy] Same as BendXY, with Z & Y */
void BendZY(float t, float toff=0.f); void BendZY(float t, float toff=0.f);
private: 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); void DoMeshTransform(MeshTransform ct, Axis axis0, Axis axis1, float n0, float n1, float noff, bool absolute=false);
public: public:
/* [cmd:s/sx/sy/sz] Scale vertices /* [cmd:s/sx/sy/sz] Scale vertices


+ 125
- 175
src/easymesh/easymeshbuild.h 파일 보기

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


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

ADD_VALUE_SET(All , 0xffffffff)
All = 0xffffffff END_E_VALUE
} END_ENUM(MeshBuildOperation)
m_value; DEF_ENUM(EasyMeshCmdType)

DEF_VALUE
inline MeshBuildOperation(Value v) : m_value(v) {} ADD_VALUE(MeshCsg)
inline MeshBuildOperation(uint64_t i) : m_value((Value)i) {} ADD_VALUE(LoopStart)
inline operator Value() { return m_value; } ADD_VALUE(LoopEnd)
}; ADD_VALUE(OpenBrace)

ADD_VALUE(CloseBrace)
struct EasyMeshCmdType ADD_VALUE(ScaleWinding)
{ ADD_VALUE(QuadWeighting)
enum Value ADD_VALUE(PostBuildNormal)
{ ADD_VALUE(PreventVertCleanup)
MeshCsg = 0, ADD_VALUE(SetColorA)

ADD_VALUE(SetColorB)
LoopStart, ADD_VALUE(SetVertColor)
LoopEnd, ADD_VALUE(VerticesMerge)
OpenBrace, ADD_VALUE(VerticesSeparate)
CloseBrace, ADD_VALUE(Translate)

ADD_VALUE(Rotate)
ScaleWinding, ADD_VALUE(RadialJitter)
QuadWeighting, ADD_VALUE(MeshTranform)
PostBuildNormal, ADD_VALUE(Scale)
PreventVertCleanup, ADD_VALUE(DupAndScale)
SetColorA, ADD_VALUE(Chamfer)
SetColorB, ADD_VALUE(SplitTriangles)
SetVertColor, ADD_VALUE(SmoothMesh)

ADD_VALUE(AppendCylinder)
VerticesMerge, ADD_VALUE(AppendCapsule)
VerticesSeparate, ADD_VALUE(AppendTorus)

ADD_VALUE(AppendBox)
Translate, ADD_VALUE(AppendStar)
Rotate, ADD_VALUE(AppendExpandedStar)
RadialJitter, ADD_VALUE(AppendDisc)
MeshTranform, ADD_VALUE(AppendSimpleTriangle)
Scale, ADD_VALUE(AppendSimpleQuad)
DupAndScale, ADD_VALUE(AppendCog)
Chamfer, END_E_VALUE

END_ENUM(EasyMeshCmdType)
SplitTriangles, DEF_ENUM(MeshType)
SmoothMesh, DEF_VALUE

ADD_VALUE(Triangle)
AppendCylinder, ADD_VALUE(Quad)
AppendCapsule, ADD_VALUE(Box)
AppendTorus, ADD_VALUE(Sphere)
AppendBox, ADD_VALUE(Capsule)
AppendStar, ADD_VALUE(Torus)
AppendExpandedStar, ADD_VALUE(Cylinder)
AppendDisc, ADD_VALUE(Disc)
AppendSimpleTriangle, ADD_VALUE(Star)
AppendSimpleQuad, ADD_VALUE(ExpandedStar)
AppendCog, ADD_VALUE(Cog)

ADD_VALUE(NEW_VALUE)
Max END_E_VALUE
} END_ENUM(MeshType)
m_value; DEF_ENUM(TexCoordBuildType)

DEF_VALUE
inline EasyMeshCmdType(Value v) : m_value(v) {} ADD_VALUE_SET(TriangleDefault , 0)
inline operator Value() { return m_value; } ADD_VALUE_SET(QuadDefault , 0)
inline int Value() { return m_value; } ADD_VALUE_SET(BoxDefault , 0)
}; ADD_VALUE_SET(SphereDefault , 0)

ADD_VALUE_SET(CapsuleDefault , 0)
struct MeshType ADD_VALUE_SET(TorusDefault , 0)
{ ADD_VALUE_SET(CylinderDefault , 0)
enum Value ADD_VALUE_SET(DiscDefault , 0)
{ ADD_VALUE_SET(StarDefault , 0)
Triangle = 0, ADD_VALUE_SET(ExpandedStarDefault , 0)
Quad, ADD_VALUE_SET(CogDefault , 0)
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,


//NEVER FORGET TO INCREMENT THIS WHEN ADDING A VALUE //NEVER FORGET TO INCREMENT THIS WHEN ADDING A VALUE
Max = 1 ADD_VALUE_SET(Max , 1)
} END_E_VALUE
m_value; END_ENUM(TexCoordBuildType)

DEF_ENUM(MeshFaceType)
inline TexCoordBuildType() : m_value(TriangleDefault) {} DEF_VALUE
inline TexCoordBuildType(Value v) : m_value(v) {} ADD_VALUE_SET(BoxFront , 0)
inline TexCoordBuildType(int v) : m_value((Value)v) {} ADD_VALUE_SET(BoxLeft , 1)
inline operator Value() { return m_value; } ADD_VALUE_SET(BoxBack , 2)
}; ADD_VALUE_SET(BoxRight , 3)

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


//NEVER FORGET TO INCREMENT THIS WHEN ADDING A VALUE //NEVER FORGET TO INCREMENT THIS WHEN ADDING A VALUE
Max = 6 ADD_VALUE_SET(Max , 6)
} END_E_VALUE
m_value; END_ENUM(MeshFaceType)

DEF_ENUM(TexCoordPos)
inline MeshFaceType(Value v) : m_value(v) {} DEF_VALUE
inline operator Value() { return m_value; } ADD_VALUE(BL) //BottomLeft
}; ADD_VALUE(BR) //BottomRight

ADD_VALUE(TL) //TopLeft
struct TexCoordPos ADD_VALUE(TR) //TopRight
{ END_E_VALUE
enum Value END_ENUM(TexCoordPos)
{
BL, //BottomLeft
BR, //BottomRight
TL, //TopLeft
TR //TopRight
}
m_value;

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


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


/* A safe enum for VertexDictionnary operations. */ /* A safe enum for VertexDictionnary operations. */
struct VDictType DEF_ENUM(VDictType)
{ DEF_VALUE
enum Value ADD_VALUE_SET(DoesNotExist , -3)
{ ADD_VALUE_SET(Alone , -2)
DoesNotExist=-3, ADD_VALUE_SET(Master , -1)
Alone=-2, END_E_VALUE
Master=-1 END_ENUM(VDictType)
}
m_value;

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


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


+ 8
- 17
src/easymesh/easymeshrender.h 파일 보기

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


//Utility enum for renderers //Utility enum for renderers
struct MeshRender DEF_ENUM(MeshRender)
{ DEF_VALUE
enum Value ADD_VALUE(NeedData)
{ ADD_VALUE(NeedConvert)
NeedData = 0, ADD_VALUE(CanRender)
NeedConvert, ADD_VALUE(IgnoreRender)
CanRender, END_E_VALUE
IgnoreRender, END_ENUM(MeshRender)

Max
}
m_value;

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


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


+ 3
- 3
src/gpu/shader.cpp 파일 보기

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


String name(name_buffer); String name(name_buffer);
int index = -1; int index = -1;
VertexUsage usage = VertexUsage::Max; VertexUsage usage = VertexUsage::MAX;
for (int j = 0; j < VertexUsage::Max; ++j) for (int j = 0; j < VertexUsage::MAX; ++j)
{ {
if (name.StartsWith(attribute_names[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", Log::Error("unable to parse attribute semantic from name: %s",
name_buffer); name_buffer);


+ 151
- 27
src/lol/base/types.h 파일 보기

@@ -28,36 +28,160 @@ typedef Real<16> real;
/* The “half” type used for 16-bit floating point numbers. */ /* The “half” type used for 16-bit floating point numbers. */
class half; 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 DEF_ENUM(NEW_ENUM) struct NEW_ENUM {
#define ADD_VALUE(NEW_VALUE) E##NEW_VALUE, #define END_ENUM(NEW_ENUM) \
#define END_VALUE MAX } m_value; 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 \ #define DEF_VALUE enum Value { INVALID = -1,
inline String C() \ #define ADD_VALUE(NEW_VALUE) NEW_VALUE,
{ \ #define ADD_VALUE_SET(NEW_VALUE, VALUE_SET) NEW_VALUE = VALUE_SET,
static String text[] = { #define END_E_VALUE MAX } m_value;
#define ADD_TEXT(NEW_TEXT) #NEW_TEXT,
#define END_TEXT \
}; \
if (m_value >= MAX) \
return "INVALID"; \
return text[m_value]; \
}; \


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


} /* namespace lol */ } /* namespace lol */




+ 38
- 49
src/lol/gpu/shader.h 파일 보기

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

ADD_TEXT(Position)
Max ADD_TEXT(BlendWeight)
} ADD_TEXT(BlendIndices)
m_value; 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: private:
static String GetName(Value v, bool use_simple) static String GetName(Value v, bool use_simple)
{ {
String tmp = String(""); String tmp = String("");
if (!use_simple) tmp += "<"; if (!use_simple) tmp += "<";
switch (v) tmp += VertexUsage(v).C();
{
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; }
}
if (!use_simple) tmp += ">"; if (!use_simple) tmp += ">";
return tmp; return tmp;
} }
@@ -87,7 +80,7 @@ public:
{ {
String tmp = String("<"); String tmp = String("<");
int nb = 0; int nb = 0;
for (int i = 0; i < Max; ++i) for (int i = 0; i < MAX; ++i)
{ {
if (v & (1<<i)) if (v & (1<<i))
{ {
@@ -99,11 +92,7 @@ public:
} }
return tmp + ">"; return tmp + ">";
} }

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


struct ShaderUniform struct ShaderUniform
{ {


+ 16
- 36
src/lol/math/geometry.h 파일 보기

@@ -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 const &tri_p0, vec3 const &tri_p1, vec3 const &tri_p2,
vec3 &vi); vec3 &vi);


struct RayIntersect DEF_ENUM(RayIntersect)
{ DEF_VALUE
enum Value ADD_VALUE(Nothing)
{ ADD_VALUE(All)
Nothing = 0, ADD_VALUE(None)
All, ADD_VALUE(P0)
None, ADD_VALUE(P1)
P0, END_E_VALUE
P1, END_ENUM(RayIntersect)

MAX
}
m_value;


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_NOTHING 0
#define RAY_ISECT_ALL 1 #define RAY_ISECT_ALL 1
#define RAY_ISECT_NONE 2 #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. */ /* A safe enum for Primitive edge face. */
struct PlaneIntersection DEF_ENUM(PlaneIntersection)
{ DEF_VALUE
enum Value ADD_VALUE(Back)
{ ADD_VALUE(Front)
Invalid=-1, ADD_VALUE(Plane)
Back, END_E_VALUE
Front, END_ENUM(PlaneIntersection)
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; }
};


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


+ 16
- 29
src/lol/sys/file.h 파일 보기

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


struct FileAccess DEF_ENUM(FileAccess)
{ DEF_VALUE
enum Value ADD_VALUE(Read)
{ ADD_VALUE(Write)
Read = 0, END_E_VALUE
Write, END_ENUM(FileAccess)
} DEF_ENUM(StreamType)
m_value; DEF_VALUE

ADD_VALUE(StdIn)
inline FileAccess(Value v) : m_value(v) {} ADD_VALUE(StdOut)
inline operator Value() { return m_value; } ADD_VALUE(StdErr)
}; ADD_VALUE(File)

ADD_VALUE(FileBinary)
struct StreamType END_E_VALUE
{ END_ENUM(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; }
};


class File class File
{ {


+ 18
- 36
src/lol/sys/thread.h 파일 보기

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


struct ThreadStatus DEF_ENUM(ThreadStatus)
{ DEF_VALUE
enum Value ADD_VALUE(NOTHING)
{ ADD_VALUE(THREAD_STARTED)
NOTHING = 0, ADD_VALUE(THREAD_STOPPED)
THREAD_STARTED, END_E_VALUE
THREAD_STOPPED, END_ENUM(ThreadStatus)

DEF_ENUM(ThreadJobType)
MAX DEF_VALUE
} ADD_VALUE(NONE)
m_value; ADD_VALUE(WORK_TODO)

ADD_VALUE(WORK_DONE)
inline ThreadStatus() : m_value(ThreadStatus::NOTHING) {} ADD_VALUE(WORK_FAILED)
inline ThreadStatus(Value v) : m_value(v) {} ADD_VALUE(WORK_FETCHED)
bool operator==(const ThreadStatus& v) { return m_value == v.m_value; } ADD_VALUE(THREAD_STOP)
}; END_E_VALUE

END_ENUM(ThreadJobType)
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; }
};


class ThreadJob class ThreadJob
{ {


+ 2
- 2
src/mesh/mesh.cpp 파일 보기

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


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


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


+ 1
- 1
src/messageservice.cpp 파일 보기

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


void MessageService::Destroy() void MessageService::Destroy()


+ 17
- 26
src/messageservice.h 파일 보기

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


//Utility enum for message service //Utility enum for message service
struct MessageBucket DEF_ENUM(MessageBucket)
{ DEF_VALUE
enum Value ADD_VALUE(AppIn)
{ ADD_VALUE(AppOut)
AppIn = 0, ADD_VALUE(Bckt0)
AppOut, ADD_VALUE(Bckt1)

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

Max
}
m_value;

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


//Message list container with time in it //Message list container with time in it
struct MessageList struct MessageList


||||||
x
 
000:0
불러오는 중...
취소
저장