Pārlūkot izejas kodu

base: make the safe enums slightly safer. :-)

undefined
Sam Hocevar pirms 10 gadiem
vecāks
revīzija
7e769d6c79
19 mainītis faili ar 358 papildinājumiem un 324 dzēšanām
  1. +1
    -0
      src/Makefile.am
  2. +7
    -4
      src/commandstack.h
  3. +14
    -14
      src/easymesh/easymesh.cpp
  4. +34
    -25
      src/easymesh/easymesh.h
  5. +92
    -71
      src/easymesh/easymeshbuild.h
  6. +11
    -8
      src/easymesh/easymeshrender.h
  7. +1
    -1
      src/gpu/shader.cpp
  8. +1
    -0
      src/lol/base/all.h
  9. +121
    -0
      src/lol/base/enum.h
  10. +0
    -155
      src/lol/base/types.h
  11. +7
    -2
      src/lol/gpu/shader.h
  12. +10
    -4
      src/lol/math/geometry.h
  13. +22
    -16
      src/lol/sys/file.h
  14. +18
    -12
      src/lol/sys/thread.h
  15. +2
    -1
      src/lolcore.vcxproj
  16. +4
    -1
      src/lolcore.vcxproj.filters
  17. +6
    -6
      src/messageservice.cpp
  18. +6
    -3
      src/messageservice.h
  19. +1
    -1
      src/sys/file.cpp

+ 1
- 0
src/Makefile.am Parādīt failu

@@ -35,6 +35,7 @@ liblolcore_headers = \
lol/base/all.h \
lol/base/log.h lol/base/array.h lol/base/types.h lol/base/array.h \
lol/base/assert.h lol/base/string.h lol/base/hash.h lol/base/map.h \
lol/base/enum.h \
\
lol/math/all.h \
lol/math/functions.h lol/math/vector.h lol/math/half.h lol/math/real.h \


+ 7
- 4
src/commandstack.h Parādīt failu

@@ -56,7 +56,7 @@ public:
inline ivec3 IV3() { ivec3 v(IV2(), 0); v.z = I(); return v; }
inline ivec4 IV4() { ivec4 v(IV3(), 0); v.w = I(); return v; }

//Alternate getters
// Alternate getters
inline void GetValue(float &f) { f = F(); }
inline void GetValue(int &i) { i = I(); }
inline void GetValue(bool &b) { b = B(); }
@@ -66,9 +66,9 @@ public:
inline void GetValue(ivec2 &iv2) { iv2 = IV2(); }
inline void GetValue(ivec3 &iv3) { iv3 = IV3(); }
inline void GetValue(ivec4 &iv4) { iv4 = IV4(); }
//For Safe Enum
template< class T > inline
void GetValue(T &i) { i = T((typename T::Value)I()); }
// For Safe Enum
template<class DEF> inline
void GetValue(SafeEnum<DEF> &i) { i = typename DEF::Type(I()); }

//SETTER
CommandStack &operator<<(int i) { m_ints << i; return *this; }
@@ -80,6 +80,9 @@ public:
CommandStack &operator<<(ivec2 iv) { return (*this << iv.x << iv.y); }
CommandStack &operator<<(ivec3 iv) { return (*this << iv.xy << iv.z); }
CommandStack &operator<<(ivec4 iv) { return (*this << iv.xyz << iv.w); }
// For Safe Enum
template<class DEF> inline
CommandStack &operator<<(SafeEnum<DEF> &i) { return *this << i.ToScalar(); }
};

} /* namespace lol */


+ 14
- 14
src/easymesh/easymesh.cpp Parādīt failu

@@ -1201,41 +1201,41 @@ void EasyMesh::DoMeshTransform(MeshTransform ct, Axis axis0, Axis axis1, float n

for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++)
{
switch (ct)
switch (ct.ToScalar())
{
case MeshTransform::Taper:
{
float value = m_vert[i].m_coord[axis0];
float value = m_vert[i].m_coord[axis0.ToScalar()];
if (absolute) value = abs(value);
m_vert[i].m_coord[(axis0 + 1) % 3] *= max(0.f, 1.f + (n0 * value + noff));
m_vert[i].m_coord[(axis0 + 2) % 3] *= max(0.f, 1.f + (n1 * value + noff));
m_vert[i].m_coord[(axis0.ToScalar() + 1) % 3] *= max(0.f, 1.f + (n0 * value + noff));
m_vert[i].m_coord[(axis0.ToScalar() + 2) % 3] *= max(0.f, 1.f + (n1 * value + noff));
break;
}
case MeshTransform::Twist:
{
vec3 rotaxis = vec3(1.f); rotaxis[(axis0 + 1) % 3] = .0f; rotaxis[(axis0 + 2) % 3] = .0f;
m_vert[i].m_coord = mat3::rotate(m_vert[i].m_coord[axis0] * n0 + noff, rotaxis) * m_vert[i].m_coord;
vec3 rotaxis = vec3(1.f); rotaxis[(axis0.ToScalar() + 1) % 3] = .0f; rotaxis[(axis0.ToScalar() + 2) % 3] = .0f;
m_vert[i].m_coord = mat3::rotate(m_vert[i].m_coord[axis0.ToScalar()] * n0 + noff, rotaxis) * m_vert[i].m_coord;
break;
}
case MeshTransform::Shear:
{
float value = m_vert[i].m_coord[axis0];
float value = m_vert[i].m_coord[axis0.ToScalar()];
if (absolute) value = abs(value);
m_vert[i].m_coord[(axis0 + 1) % 3] += (n0 * value + noff);
m_vert[i].m_coord[(axis0 + 2) % 3] += (n1 * value + noff);
m_vert[i].m_coord[(axis0.ToScalar() + 1) % 3] += (n0 * value + noff);
m_vert[i].m_coord[(axis0.ToScalar() + 2) % 3] += (n1 * value + noff);
break;
}
case MeshTransform::Stretch:
{
//float value = abs(m_vert[i].m1[axis0]);
//m_vert[i].m1[(axis0 + 1) % 3] += (lol::pow(value, n0) + noff);
//m_vert[i].m1[(axis0 + 2) % 3] += (lol::pow(value, n1) + noff);
//float value = abs(m_vert[i].m1[axis0.ToScalar()]);
//m_vert[i].m1[(axis0.ToScalar() + 1) % 3] += (lol::pow(value, n0) + noff);
//m_vert[i].m1[(axis0.ToScalar() + 2) % 3] += (lol::pow(value, n1) + noff);
break;
}
case MeshTransform::Bend:
{
vec3 rotaxis = vec3(1.f); rotaxis[(axis1 + 1) % 3] = .0f; rotaxis[(axis1 + 2) % 3] = .0f;
m_vert[i].m_coord = mat3::rotate(m_vert[i].m_coord[axis0] * n0 + noff, rotaxis) * m_vert[i].m_coord;
vec3 rotaxis = vec3(1.f); rotaxis[(axis1.ToScalar() + 1) % 3] = .0f; rotaxis[(axis1.ToScalar() + 2) % 3] = .0f;
m_vert[i].m_coord = mat3::rotate(m_vert[i].m_coord[axis0.ToScalar()] * n0 + noff, rotaxis) * m_vert[i].m_coord;
break;
}
}


+ 34
- 25
src/easymesh/easymesh.h Parādīt failu

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

/* A safe enum for MeshCSG operations. */
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)
struct CSGUsageDef
{
enum Type
{
Union,
Substract,
SubstractLoss, //will remove B from A, but not add inverted B
And,
Xor,
};
};
typedef SafeEnum<CSGUsageDef> CSGUsage;

DEF_ENUM(Axis)
DEF_VALUE
ADD_VALUE(X)
ADD_VALUE(Y)
ADD_VALUE(Z)
END_E_VALUE
END_ENUM(Axis)
struct AxisDef
{
enum Type
{
X,
Y,
Z,
};
};
typedef SafeEnum<AxisDef> 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)
struct MeshTransformDef
{
enum Type
{
Taper,
Twist,
Bend,
Stretch,
Shear,
};
};
typedef SafeEnum<MeshTransformDef> MeshTransform;

class EasyMesh
{


+ 92
- 71
src/easymesh/easymeshbuild.h Parādīt failu

@@ -21,7 +21,8 @@
namespace lol
{

DEF_ENUM(MeshBuildOperation)
struct MeshBuildOperation
{
DEF_VALUE
//When this flag is up, negative scaling will not invert faces.
ADD_VALUE_SET(ScaleWinding , (1 << 0))
@@ -34,9 +35,12 @@ DEF_ENUM(MeshBuildOperation)

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

DEF_ENUM(EasyMeshCmdType)
LOL_DECLARE_ENUM_METHODS(MeshBuildOperation)
};

struct EasyMeshCmdType
{
DEF_VALUE
ADD_VALUE(MeshCsg)

@@ -78,26 +82,32 @@ DEF_ENUM(EasyMeshCmdType)
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)
LOL_DECLARE_ENUM_METHODS(EasyMeshCmdType)
};

DEF_ENUM(TexCoordBuildType)
struct MeshTypeDef
{
enum Type
{
Triangle,
Quad,
Box,
Sphere,
Capsule,
Torus,
Cylinder,
Disc,
Star,
ExpandedStar,
Cog,
MAX,
};
};
typedef SafeEnum<MeshTypeDef> MeshType;

struct TexCoordBuildType
{
DEF_VALUE
ADD_VALUE_SET(TriangleDefault , 0)
ADD_VALUE_SET(QuadDefault , 0)
@@ -114,31 +124,37 @@ DEF_ENUM(TexCoordBuildType)
//NEVER FORGET TO INCREMENT THIS WHEN ADDING A VALUE
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)
LOL_DECLARE_ENUM_METHODS(TexCoordBuildType)
};

//NEVER FORGET TO INCREMENT THIS WHEN ADDING A VALUE
ADD_VALUE_SET(Max , 6)
END_E_VALUE
END_ENUM(MeshFaceType)
struct MeshFaceTypeDef
{
enum Type
{
BoxFront = 0,
QuadDefault = 0,
BoxLeft = 1,
BoxBack = 2,
BoxRight = 3,
BoxTop = 4,
BoxBottom = 5,
Max,
};
};
typedef SafeEnum<MeshFaceTypeDef> 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)
struct TexCoordPosDef
{
enum Type
{
BL, //BottomLeft
BR, //BottomRight
TL, //TopLeft
TR, //TopRight
};
};
typedef SafeEnum<TexCoordPosDef> TexCoordPos;

class EasyMeshBuildData
{
@@ -173,10 +189,10 @@ public:
inline vec2 &TexCoordScale2() { return m_texcoord_scale2; }

//UV1
void SetTexCoordBuildType(MeshType mt, TexCoordBuildType tcbt) { m_texcoord_build_type[mt] = (1 << (tcbt + 1)) | (m_texcoord_build_type[mt] & 1); }
void SetTexCoordBuildType(MeshType mt, TexCoordBuildType tcbt) { m_texcoord_build_type[mt.ToScalar()] = (1 << (tcbt + 1)) | (m_texcoord_build_type[mt.ToScalar()] & 1); }
TexCoordBuildType GetTexCoordBuildType(MeshType mt)
{
uint32_t flag = (uint32_t)((m_texcoord_build_type[mt] & ~(1)) >> 1);
uint32_t flag = (uint32_t)((m_texcoord_build_type[mt.ToScalar()] & ~(1)) >> 1);
int i = 0;
while (flag >>= 1)
i++;
@@ -184,22 +200,23 @@ public:
}
void SetTexCoordCustomBuild(MeshType mt, MeshFaceType face, vec2 BL, vec2 TR)
{
if (face >= m_texcoord_custom_build[mt].Count())
m_texcoord_custom_build[mt].Resize(face + 1);
m_texcoord_custom_build[mt][face].m1 = BL;
m_texcoord_custom_build[mt][face].m2 = TR;
m_texcoord_build_type[mt] |= 1;
if (face.ToScalar() >= m_texcoord_custom_build[mt.ToScalar()].Count())
m_texcoord_custom_build[mt.ToScalar()].Resize(face.ToScalar() + 1);
m_texcoord_custom_build[mt.ToScalar()][face.ToScalar()].m1 = BL;
m_texcoord_custom_build[mt.ToScalar()][face.ToScalar()].m2 = TR;
m_texcoord_build_type[mt.ToScalar()] |= 1;
}
void ClearTexCoordCustomBuild(MeshType mt) { m_texcoord_build_type[mt] &= ~1; }
void ClearTexCoordCustomBuild(MeshType mt) { m_texcoord_build_type[mt.ToScalar()] &= ~1; }
/* FIXME : Do something better ? */
vec2 TexCoord(MeshType mt, TexCoordPos tcp, MeshFaceType face)
{
vec2 BL = vec2(0.f);
vec2 TR = vec2(0.f);
if (m_texcoord_build_type[mt] & 1 && face < m_texcoord_custom_build[mt].Count())
if (m_texcoord_build_type[mt.ToScalar()] & 1
&& face.ToScalar() < m_texcoord_custom_build[mt.ToScalar()].Count())
{
BL = m_texcoord_custom_build[mt][face].m1;
TR = m_texcoord_custom_build[mt][face].m2;
BL = m_texcoord_custom_build[mt.ToScalar()][face.ToScalar()].m1;
TR = m_texcoord_custom_build[mt.ToScalar()][face.ToScalar()].m2;
}
else
{
@@ -225,8 +242,8 @@ public:
{ vec2(0.f, .5f), vec2(.5f, 1.f) },
{ vec2(.5f, .5f), vec2(1.f, 1.f) }
};
BL = data[face][0]; //[tcbt]
TR = data[face][1]; //[tcbt]
BL = data[face.ToScalar()][0]; //[tcbt]
TR = data[face.ToScalar()][1]; //[tcbt]
}
else if (mt == MeshType::Sphere)
mt = mt;
@@ -260,10 +277,10 @@ public:
}

//UV2
void SetTexCoordBuildType2(MeshType mt, TexCoordBuildType tcbt) { m_texcoord_build_type2[mt] = (1 << (tcbt + 1)) | (m_texcoord_build_type2[mt] & 1); }
void SetTexCoordBuildType2(MeshType mt, TexCoordBuildType tcbt) { m_texcoord_build_type2[mt.ToScalar()] = (1 << (tcbt + 1)) | (m_texcoord_build_type2[mt.ToScalar()] & 1); }
TexCoordBuildType GetTexCoordBuildType2(MeshType mt)
{
uint32_t flag = ((m_texcoord_build_type2[mt] & ~(1)) >> 1);
uint32_t flag = ((m_texcoord_build_type2[mt.ToScalar()] & ~(1)) >> 1);
int i = 0;
while (flag >>= 1)
i++;
@@ -271,21 +288,22 @@ public:
}
void SetTexCoordCustomBuild2(MeshType mt, MeshFaceType face, vec2 BL, vec2 TR)
{
if (face >= m_texcoord_custom_build2[mt].Count())
m_texcoord_custom_build2[mt].Resize(face + 1);
m_texcoord_custom_build2[mt][face].m1 = BL;
m_texcoord_custom_build2[mt][face].m2 = TR;
m_texcoord_build_type2[mt] |= 1;
if (face.ToScalar() >= m_texcoord_custom_build2[mt.ToScalar()].Count())
m_texcoord_custom_build2[mt.ToScalar()].Resize(face.ToScalar() + 1);
m_texcoord_custom_build2[mt.ToScalar()][face.ToScalar()].m1 = BL;
m_texcoord_custom_build2[mt.ToScalar()][face.ToScalar()].m2 = TR;
m_texcoord_build_type2[mt.ToScalar()] |= 1;
}
void ClearTexCoordCustomBuild2(MeshType mt) { m_texcoord_build_type2[mt] &= ~1; }
void ClearTexCoordCustomBuild2(MeshType mt) { m_texcoord_build_type2[mt.ToScalar()] &= ~1; }
vec2 TexCoord2(MeshType mt, TexCoordPos tcp, MeshFaceType face)
{
vec2 BL = vec2(0.f);
vec2 TR = vec2(0.f);
if (m_texcoord_build_type2[mt] & 1 && face < m_texcoord_custom_build2[mt].Count())
if (m_texcoord_build_type2[mt.ToScalar()] & 1
&& face.ToScalar() < m_texcoord_custom_build2[mt.ToScalar()].Count())
{
BL = m_texcoord_custom_build2[mt][face].m1;
TR = m_texcoord_custom_build2[mt][face].m2;
BL = m_texcoord_custom_build2[mt.ToScalar()][face.ToScalar()].m1;
TR = m_texcoord_custom_build2[mt.ToScalar()][face.ToScalar()].m2;
}
else
{
@@ -310,8 +328,8 @@ public:
{ vec2(0.f, .5f), vec2(.5f, 1.f) },
{ vec2(.5f, .5f), vec2(1.f, 1.f) }
};
BL = data[face][0]; //[tcbt]
TR = data[face][1]; //[tcbt]
BL = data[face.ToScalar()][0]; //[tcbt]
TR = data[face.ToScalar()][1]; //[tcbt]
}
else if (mt == MeshType::Sphere)
mt = mt;
@@ -369,13 +387,16 @@ public:
};

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

LOL_DECLARE_ENUM_METHODS(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


+ 11
- 8
src/easymesh/easymeshrender.h Parādīt failu

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

//Utility enum for renderers
DEF_ENUM(MeshRender)
DEF_VALUE
ADD_VALUE(NeedData)
ADD_VALUE(NeedConvert)
ADD_VALUE(CanRender)
ADD_VALUE(IgnoreRender)
END_E_VALUE
END_ENUM(MeshRender)
struct MeshRenderDef
{
enum Type
{
NeedData,
NeedConvert,
CanRender,
IgnoreRender,
};
};
typedef SafeEnum<MeshRenderDef> MeshRender;

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


+ 1
- 1
src/gpu/shader.cpp Parādīt failu

@@ -402,7 +402,7 @@ Shader::Shader(char const *vert, char const *frag)
}
}

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


+ 1
- 0
src/lol/base/all.h Parādīt failu

@@ -12,6 +12,7 @@
#define __LOL_BASE_ALL_H__

#include <lol/base/types.h>
#include <lol/base/enum.h>
#include <lol/base/log.h>
#include <lol/base/assert.h>
#include <lol/base/array.h>


+ 121
- 0
src/lol/base/enum.h Parādīt failu

@@ -0,0 +1,121 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://www.wtfpl.net/ for more details.
//

#if !defined __LOL_BASE_ENUM_H__
#define __LOL_BASE_ENUM_H__

namespace lol
{

template<typename DEF, typename T = typename DEF::Type>
class SafeEnum : public DEF
{
typedef T Type;
Type m_value;

public:
inline SafeEnum() : m_value() {}
inline SafeEnum(Type v) : m_value(v) {}

/* Allow conversion from/to int */
inline Type ToScalar() const { return m_value; }

/* Safe comparisons between enums of the same type */
friend bool operator == (SafeEnum const &a, SafeEnum const &b)
{
return a.m_value == b.m_value;
}
friend bool operator != (SafeEnum const &a, SafeEnum const &b)
{
return a.m_value != b.m_value;
}
friend bool operator < (SafeEnum const &a, SafeEnum const &b)
{
return a.m_value < b.m_value;
}
friend bool operator > (SafeEnum const &a, SafeEnum const &b)
{
return a.m_value > b.m_value;
}
friend bool operator <= (SafeEnum const &a, SafeEnum const &b)
{
return a.m_value <= b.m_value;
}
friend bool operator >= (SafeEnum const &a, SafeEnum const &b)
{
return a.m_value >= b.m_value;
}
};

//-- STRUCT TEMPLATE:
// enum E {
// DEF_VALUE
// ADD_VALUE(NEW_VALUE)
// ADD_VALUE_SET(NEW_VALUE, VALUE_SET)
// END_E_VALUE
// DEF_TEXT
// ADD_TEXT(NEW_VALUE)
// END_TEXT
// LOL_DECLARE_ENUM_METHODS(E)
// };

#define LOL_DECLARE_ENUM_METHODS(E) \
inline E() : m_value(MAX) {} \
inline E(Value v) : m_value(v) {} \
inline E(const int8_t & v) : m_value((Value)v) {} \
inline E(const int16_t & v) : m_value((Value)v) {} \
inline E(const int32_t & v) : m_value((Value)v) {} \
inline E(const int64_t & v) : m_value((Value)v) {} \
inline E(const uint8_t & v) : m_value((Value)v) {} \
inline E(const uint16_t & v) : m_value((Value)v) {} \
inline E(const uint32_t & v) : m_value((Value)v) {} \
inline E(const uint64_t & v) : m_value((Value)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; } \
bool operator==(const E & v) { return m_value == v.m_value; } \
bool operator!=(const E & v) { return m_value != v.m_value; } \
bool operator<(const E & v) { return m_value < v.m_value; } \
bool operator>(const E & v) { return m_value > v.m_value; } \
bool operator<=(const E & v) { return m_value <= v.m_value; } \
bool operator>=(const E & v) { return m_value >= v.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 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 */

#endif // __LOL_BASE_ENUM_H__


+ 0
- 155
src/lol/base/types.h Parādīt failu

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

//-- 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 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 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 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 */

#endif // __LOL_BASE_TYPES_H__


+ 7
- 2
src/lol/gpu/shader.h Parādīt failu

@@ -25,7 +25,8 @@ 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. */
DEF_ENUM(VertexUsage)
struct VertexUsage
{
DEF_VALUE
ADD_VALUE(Position)
ADD_VALUE(BlendWeight)
@@ -43,6 +44,7 @@ DEF_ENUM(VertexUsage)
ADD_VALUE(Depth)
ADD_VALUE(Sample)
END_E_VALUE

DEF_TEXT
ADD_TEXT(Position)
ADD_TEXT(BlendWeight)
@@ -60,6 +62,9 @@ DEF_ENUM(VertexUsage)
ADD_TEXT(Depth)
ADD_TEXT(Sample)
END_TEXT

LOL_DECLARE_ENUM_METHODS(VertexUsage);

private:
static String GetName(Value v, bool use_simple)
{
@@ -92,7 +97,7 @@ public:
}
return tmp + ">";
}
END_ENUM(VertexUsage)
};

struct ShaderUniform
{


+ 10
- 4
src/lol/math/geometry.h Parādīt failu

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

DEF_ENUM(RayIntersect)
struct RayIntersect
{
DEF_VALUE
ADD_VALUE(Nothing)
ADD_VALUE(All)
@@ -246,7 +247,9 @@ DEF_ENUM(RayIntersect)
ADD_VALUE(P0)
ADD_VALUE(P1)
END_E_VALUE
END_ENUM(RayIntersect)

LOL_DECLARE_ENUM_METHODS(RayIntersect)
};

#define RAY_ISECT_NOTHING 0
#define RAY_ISECT_ALL 1
@@ -293,13 +296,16 @@ bool TestRayVsPlane(const TV &ray_p0, const TV &ray_p1,
}

/* A safe enum for Primitive edge face. */
DEF_ENUM(PlaneIntersection)
struct PlaneIntersection
{
DEF_VALUE
ADD_VALUE(Back)
ADD_VALUE(Front)
ADD_VALUE(Plane)
END_E_VALUE
END_ENUM(PlaneIntersection)

LOL_DECLARE_ENUM_METHODS(PlaneIntersection)
};

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


+ 22
- 16
src/lol/sys/file.h Parādīt failu

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

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)
struct FileAccessDef
{
enum Type
{
Read = 0,
Write,
};
};
typedef SafeEnum<FileAccessDef> FileAccess;

struct StreamTypeDef
{
enum Type
{
StdIn,
StdOut,
StdErr,
File,
FileBinary,
};
};
typedef SafeEnum<StreamTypeDef> StreamType;

class File
{


+ 18
- 12
src/lol/sys/thread.h Parādīt failu

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

DEF_ENUM(ThreadStatus)
struct 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)
LOL_DECLARE_ENUM_METHODS(ThreadStatus)
};

struct ThreadJobTypeDef
{
enum Type
{
NONE,
WORK_TODO,
WORK_DONE,
WORK_FAILED,
WORK_FETCHED,
THREAD_STOP,
};
};
typedef SafeEnum<ThreadJobTypeDef> ThreadJobType;

class ThreadJob
{


+ 2
- 1
src/lolcore.vcxproj Parādīt failu

@@ -279,6 +279,7 @@
<ClInclude Include="lol\base\all.h" />
<ClInclude Include="lol\base\array.h" />
<ClInclude Include="lol\base\assert.h" />
<ClInclude Include="lol\base\enum.h" />
<ClInclude Include="lol\base\hash.h" />
<ClInclude Include="lol\base\log.h" />
<ClInclude Include="lol\base\map.h" />
@@ -428,4 +429,4 @@
<ImportGroup Label="ExtensionTargets">
<Import Project="$(SolutionDir)\Lol.Fx.targets" />
</ImportGroup>
</Project>
</Project>

+ 4
- 1
src/lolcore.vcxproj.filters Parādīt failu

@@ -555,6 +555,9 @@
<ClInclude Include="lol\base\assert.h">
<Filter>lol\base</Filter>
</ClInclude>
<ClInclude Include="lol\base\enum.h">
<Filter>lol\base</Filter>
</ClInclude>
<ClInclude Include="lol\base\hash.h">
<Filter>lol\base</Filter>
</ClInclude>
@@ -751,4 +754,4 @@
</None>
<None Include="Makefile.am" />
</ItemGroup>
</Project>
</Project>

+ 6
- 6
src/messageservice.cpp Parādīt failu

@@ -67,7 +67,7 @@ bool MessageService::Send(MessageBucket id, const String& message)
{
if (g_messageservice)
{
ASSERT(0 <= id && id < g_messageservice->m_bucket.Count());
ASSERT(0 <= id && (int)id < g_messageservice->m_bucket.Count());
return g_messageservice->Send(id, message.C());
}
return false;
@@ -77,7 +77,7 @@ bool MessageService::Send(MessageBucket id, const char* message)
{
if (g_messageservice)
{
ASSERT(0 <= id && id < g_messageservice->m_bucket.Count());
ASSERT(0 <= id && (int)id < g_messageservice->m_bucket.Count());
MessageService& g = *g_messageservice;
Array<MessageList>& bucket = g.m_bucket[id];
bucket << MessageList(time(nullptr), String(message));
@@ -91,7 +91,7 @@ bool MessageService::FetchFirst(MessageBucket id, String& message)
{
if (g_messageservice)
{
ASSERT(0 <= id && id < g_messageservice->m_bucket.Count());
ASSERT(0 <= id && (int)id < g_messageservice->m_bucket.Count());
time_t timestamp;
return g_messageservice->FetchFirst(id, message, timestamp);
}
@@ -102,7 +102,7 @@ bool MessageService::FetchFirst(MessageBucket id, String& message, time_t& times
{
if (g_messageservice)
{
ASSERT(0 <= id && id < g_messageservice->m_bucket.Count());
ASSERT(0 <= id && (int)id < g_messageservice->m_bucket.Count());
MessageService& g = *g_messageservice;
Array<MessageList>& bucket = g.m_bucket[id];

@@ -122,7 +122,7 @@ bool MessageService::FetchAll(MessageBucket id, String& message)
{
if (g_messageservice)
{
ASSERT(0 <= id && id < g_messageservice->m_bucket.Count());
ASSERT(0 <= id && (int)id < g_messageservice->m_bucket.Count());
time_t timestamp;
return g_messageservice->FetchAll(id, message, timestamp);
}
@@ -133,7 +133,7 @@ bool MessageService::FetchAll(MessageBucket id, String& message, time_t& first_t
{
if (g_messageservice)
{
ASSERT(0 <= id && id < g_messageservice->m_bucket.Count());
ASSERT(0 <= id && (int)id < g_messageservice->m_bucket.Count());
MessageService& g = *g_messageservice;
Array<MessageList>& bucket = g.m_bucket[id];
message = String("");


+ 6
- 3
src/messageservice.h Parādīt failu

@@ -20,8 +20,9 @@
namespace lol
{

//Utility enum for message service
DEF_ENUM(MessageBucket)
// Utility enum for message service
struct MessageBucket
{
DEF_VALUE
ADD_VALUE(AppIn)
ADD_VALUE(AppOut)
@@ -37,7 +38,9 @@ DEF_ENUM(MessageBucket)
ADD_VALUE(Bckt8)
ADD_VALUE(Bckt9)
END_E_VALUE
END_ENUM(MessageBucket)

LOL_DECLARE_ENUM_METHODS(MessageBucket)
};

//Message list container with time in it
struct MessageList


+ 1
- 1
src/sys/file.cpp Parādīt failu

@@ -51,7 +51,7 @@ class FileData
m_type == StreamType::FileBinary)
return;
m_type = stream;
switch((int)stream)
switch (stream.ToScalar())
{
#if __CELLOS_LV2__
/* FIXME: no modes, no error checking, no nothing */


Notiek ielāde…
Atcelt
Saglabāt