Browse Source

misc: lots of compilation fixes for Visual Studio (related to mediocre

support for enable_if and other template metaprogramming techniques),
for Clang (related to static const template class member initialisation)
and for GCC (related to forward declaration of non-int enum classes).
undefined
Sam Hocevar 9 years ago
parent
commit
f791b672ed
13 changed files with 214 additions and 148 deletions
  1. +1
    -1
      src/Makefile.am
  2. +11
    -9
      src/lol/algorithm/aabb_tree.h
  3. +10
    -8
      src/lol/algorithm/portal.h
  4. +0
    -6
      src/lol/algorithm/sort.h
  5. +11
    -1
      src/lol/base/array.h
  6. +21
    -9
      src/lol/math/bigint.h
  7. +20
    -7
      src/lol/math/matrix.h
  8. +75
    -37
      src/lol/math/vector.h
  9. +1
    -0
      src/lolcore.vcxproj
  10. +3
    -0
      src/lolcore.vcxproj.filters
  11. +10
    -64
      src/math/constants.cpp
  12. +42
    -0
      src/sys/hacks.cpp
  13. +9
    -6
      tools/lolunit/lolunit.h

+ 1
- 1
src/Makefile.am View File

@@ -100,7 +100,7 @@ liblolcore_sources = \
mesh/mesh.cpp mesh/mesh.h \ mesh/mesh.cpp mesh/mesh.h \
mesh/primitive.cpp mesh/primitive.h \ mesh/primitive.cpp mesh/primitive.h \
\ \
sys/init.cpp sys/timer.cpp sys/file.cpp \
sys/init.cpp sys/timer.cpp sys/file.cpp sys/hacks.cpp \
sys/thread.cpp sys/threadbase.h \ sys/thread.cpp sys/threadbase.h \
\ \
image/image.cpp image/image-private.h image/kernel.cpp image/pixel.cpp \ image/image.cpp image/image-private.h image/kernel.cpp image/pixel.cpp \


+ 11
- 9
src/lol/algorithm/aabb_tree.h View File

@@ -1,12 +1,14 @@
// //
// Lol Engine
// Lol Engine
// //
// Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net>
// (c) 2013-2014 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// 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.
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// © 2013—2015 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
//
// This library is free software. It comes without any warranty, to
// the extent permitted by applicable law. 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 the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
// //


#pragma once #pragma once
@@ -66,7 +68,7 @@ void DrawInner(TREE *tree, array<TBB, vec4> &boxes,
} }


//-- //--
template <typename TE>
template <typename TE, typename TV = void>
void Draw(Quadtree<TE>* tree, vec4 color) void Draw(Quadtree<TE>* tree, vec4 color)
{ {
array<box2, vec4> boxes; array<box2, vec4> boxes;
@@ -97,7 +99,7 @@ void Draw(Quadtree<TE>* tree, vec4 color)
} }
} }
//-- //--
template <typename TE>
template <typename TE, typename TV = void>
void Draw(Octree<TE>* tree, vec4 color) void Draw(Octree<TE>* tree, vec4 color)
{ {
array<box3, vec4> boxes; array<box3, vec4> boxes;


+ 10
- 8
src/lol/algorithm/portal.h View File

@@ -1,12 +1,14 @@
// //
// Lol Engine
// Lol Engine
// //
// Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net>
// (c) 2013-2014 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
// 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.
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// © 2013—2015 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
//
// This library is free software. It comes without any warranty, to
// the extent permitted by applicable law. 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 the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
// //


#pragma once #pragma once
@@ -27,7 +29,7 @@ template <typename TE> class PortalSet;


//-- //--
namespace Debug { namespace Debug {
template <typename TE>
template <typename TE, typename TV = void>
void Draw(PortalDoor<TE>& port, vec4 color) void Draw(PortalDoor<TE>& port, vec4 color)
{ {
vec3 points[4]; port.GetPoints(points); vec3 points[4]; port.GetPoints(points);


+ 0
- 6
src/lol/algorithm/sort.h View File

@@ -18,12 +18,6 @@
namespace lol namespace lol
{ {


enum class SortAlgorithm : uint8_t
{
QuickSwap,
Bubble,
};

template<typename T, typename ARRAY> template<typename T, typename ARRAY>
void array_base<T, ARRAY>::Shuffle() void array_base<T, ARRAY>::Shuffle()
{ {


+ 11
- 1
src/lol/base/array.h View File

@@ -33,6 +33,16 @@ namespace lol


static ptrdiff_t const INDEX_NONE = -1; static ptrdiff_t const INDEX_NONE = -1;


/*
* Sorting algorithm list
*/

enum class SortAlgorithm : uint8_t
{
QuickSwap,
Bubble,
};

/* /*
* The base array type. * The base array type.
* *
@@ -383,7 +393,7 @@ public:
} }


void Shuffle(); void Shuffle();
void Sort(enum class SortAlgorithm : uint8_t);
void Sort(SortAlgorithm algorithm);
void SortQuickSwap(ptrdiff_t start, ptrdiff_t stop); void SortQuickSwap(ptrdiff_t start, ptrdiff_t stop);


/* TODO: remove these legacy functions one day */ /* TODO: remove these legacy functions one day */


+ 21
- 9
src/lol/math/bigint.h View File

@@ -31,6 +31,20 @@ namespace lol
/* Avoid issues with NaCl headers */ /* Avoid issues with NaCl headers */
#undef log2 #undef log2


template<unsigned int N, typename T>
class bigint_digits
{
protected:
T m_digits[N];
};

template<typename T>
class bigint_digits<0, T>
{
protected:
static T const m_digits[1];
};

/* /*
* A bigint stores its digits in an array of integers. The MSB of the * A bigint stores its digits in an array of integers. The MSB of the
* integers are unused. The highest used bit is the sign bit. * integers are unused. The highest used bit is the sign bit.
@@ -39,7 +53,7 @@ namespace lol
*/ */


template<unsigned int N = 16, typename T = uint32_t> template<unsigned int N = 16, typename T = uint32_t>
class bigint
class bigint : public bigint_digits<N, T>
{ {
static int const bits_per_digit = sizeof(T) * 8 - 1; static int const bits_per_digit = sizeof(T) * 8 - 1;
static T const digit_mask = ~((T)1 << bits_per_digit); static T const digit_mask = ~((T)1 << bits_per_digit);
@@ -190,9 +204,9 @@ public:
* and pad missing digits if one of the two operands is shorter. * and pad missing digits if one of the two operands is shorter.
*/ */
template<unsigned int M> template<unsigned int M>
bigint<(N > M) ? N : M, T> operator +(bigint<M,T> const &x) const
bigint<((N > M) ? N : M), T> operator +(bigint<M,T> const &x) const
{ {
bigint<(N > M) ? N : M, T> ret;
bigint<((N > M) ? N : M), T> ret;
T padding = is_negative() ? digit_mask : (T)0; T padding = is_negative() ? digit_mask : (T)0;
T x_padding = x.is_negative() ? digit_mask : (T)0; T x_padding = x.is_negative() ? digit_mask : (T)0;
T carry(0); T carry(0);
@@ -213,7 +227,7 @@ public:
* FIXME: this could be factored with operator+(). * FIXME: this could be factored with operator+().
*/ */
template<unsigned int M> template<unsigned int M>
bigint<(N > M) ? N : M, T> operator -(bigint<M,T> const &x) const
bigint<((N > M) ? N : M), T> operator -(bigint<M,T> const &x) const
{ {
bigint<(N > M) ? N : M, T> ret; bigint<(N > M) ? N : M, T> ret;
T padding = is_negative() ? digit_mask : (T)0; T padding = is_negative() ? digit_mask : (T)0;
@@ -359,7 +373,7 @@ private:
} }


template<unsigned int M> template<unsigned int M>
typename std::enable_if<(N == M && N >= 64), bigint<N + M, T>>
typename std::enable_if<(N == M) && (N >= 64), bigint<N + M, T>>
::type inline multiply(bigint<M,T> const &b) const ::type inline multiply(bigint<M,T> const &b) const
{ {
bigint<2 * N, T> ret, tmp(0); bigint<2 * N, T> ret, tmp(0);
@@ -379,8 +393,8 @@ private:
return ret + tmp; return ret + tmp;
} }


template<unsigned int M>
typename std::enable_if<(N == M && N == 1), bigint<N + M, T>>
template<unsigned int M, int = 0>
typename std::enable_if<(N == M) && (N == 1), bigint<N + M, T>>
::type inline multiply(bigint<M,T> const &b) const ::type inline multiply(bigint<M,T> const &b) const
{ {
bigint<2, T> ret; bigint<2, T> ret;
@@ -404,8 +418,6 @@ private:
ret |= m_digits[digit_index + 1] << (bits_per_digit - bit_index); ret |= m_digits[digit_index + 1] << (bits_per_digit - bit_index);
return ret; return ret;
} }

T m_digits[N];
}; };


/* /*


+ 20
- 7
src/lol/math/matrix.h View File

@@ -1,11 +1,13 @@
// //
// Lol Engine
// Lol Engine
// //
// Copyright: (c) 2010-2014 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.
// Copyright © 2010-2015 Sam Hocevar <sam@hocevar.net>
//
// This library is free software. It comes without any warranty, to
// the extent permitted by applicable law. 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 the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
// //


#pragma once #pragma once
@@ -531,7 +533,7 @@ void lu_decomposition(mat_t<T, N, N> const &m, mat_t<T, N, N> & L, mat_t<T, N, N
} }
else /* if (i >= j) */ else /* if (i >= j) */
{ {
L[i][j] = i == j ? 1 : 0;
L[i][j] = i == j ? T(1) : T(0);
U[i][j] = (m[i][j] - sum) / L[j][j]; U[i][j] = (m[i][j] - sum) / L[j][j];
} }
} }
@@ -697,6 +699,17 @@ outer(mat_t<T, COLS1, ROWS1> const &a, mat_t<T, COLS2, ROWS2> const &b)
return ret; return ret;
} }


/*
* Constants
*/

template<typename T>
mat_t<T,2,2> const mat_t<T,2,2>::identity = mat_t<T,2,2>((T)1);
template<typename T>
mat_t<T,3,3> const mat_t<T,3,3>::identity = mat_t<T,3,3>((T)1);
template<typename T>
mat_t<T,4,4> const mat_t<T,4,4>::identity = mat_t<T,4,4>((T)1);

#if !LOL_FEATURE_CXX11_CONSTEXPR #if !LOL_FEATURE_CXX11_CONSTEXPR
#undef constexpr #undef constexpr
#endif #endif


+ 75
- 37
src/lol/math/vector.h View File

@@ -1,11 +1,13 @@
// //
// Lol Engine
// Lol Engine
// //
// Copyright: (c) 2010-2014 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.
// Copyright © 2010-2015 Sam Hocevar <sam@hocevar.net>
//
// This library is free software. It comes without any warranty, to
// the extent permitted by applicable law. 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 the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
// //


#pragma once #pragma once
@@ -123,10 +125,17 @@ struct vec_t<T, N, FULL_SWIZZLE>


/* Explicit constructor that takes exactly N arguments thanks to SFINAE. */ /* Explicit constructor that takes exactly N arguments thanks to SFINAE. */
template<typename... ARGS> template<typename... ARGS>
explicit inline vec_t(typename std::enable_if<sizeof...(ARGS) == N - 1, T>
::type const &x, ARGS... args)
explicit inline vec_t(typename std::enable_if<(sizeof...(ARGS) == N - 1) && (N > 1), T>
::type const &X, ARGS... args)
{
internal_init(m_data, X, args...);
}

/* Various explicit constructors */
explicit inline vec_t(T const &X)
{ {
internal_init(m_data, x, args...);
for (auto &value : m_data)
value = X;
} }


/* Explicit constructor for type conversion */ /* Explicit constructor for type conversion */
@@ -134,7 +143,7 @@ struct vec_t<T, N, FULL_SWIZZLE>
explicit inline vec_t(vec_t<U, N> const &v) explicit inline vec_t(vec_t<U, N> const &v)
{ {
for (int i = 0; i < N; ++i) for (int i = 0; i < N; ++i)
m_data[i] = (T)v[i];
m_data[i] = T(v[i]);
} }


/* Factory for base axis vectors, e.g. [1,0,0,…,0] */ /* Factory for base axis vectors, e.g. [1,0,0,…,0] */
@@ -142,8 +151,8 @@ struct vec_t<T, N, FULL_SWIZZLE>
{ {
ASSERT(i >= 0); ASSERT(i >= 0);
ASSERT(i < N); ASSERT(i < N);
vec_t<T, N> ret((T)0);
ret[i] = (T)1;
vec_t<T, N> ret(T(0));
ret[i] = T(1);
return ret; return ret;
} }


@@ -154,20 +163,15 @@ struct vec_t<T, N, FULL_SWIZZLE>
auto l = list.begin(); auto l = list.begin();
for (int i = 0; i < count && l != list.end(); ++i, ++l) for (int i = 0; i < count && l != list.end(); ++i, ++l)
m_data[i] = *l; m_data[i] = *l;
for (int i = list.size(); i < count; ++i)
m_data[i] = (T)0;
}

/* Various explicit constructors */
explicit inline vec_t(T X)
{
for (int i = 0; i < N; ++i)
m_data[i] = X;
for (int i = (int)list.size(); i < count; ++i)
m_data[i] = T(0);
} }


inline T& operator[](size_t n) { return m_data[n]; } inline T& operator[](size_t n) { return m_data[n]; }
inline T const& operator[](size_t n) const { return m_data[n]; } inline T const& operator[](size_t n) const { return m_data[n]; }


static const vec_t<T,N> zero;

private: private:
template<typename... ARGS> template<typename... ARGS>
static inline void internal_init(T *data, T const &x, ARGS... args) static inline void internal_init(T *data, T const &x, ARGS... args)
@@ -228,7 +232,7 @@ struct vec_t<T,2>
/* Explicit constructor for type conversion */ /* Explicit constructor for type conversion */
template<typename U, int SWIZZLE> template<typename U, int SWIZZLE>
explicit inline constexpr vec_t(vec_t<U, 2, SWIZZLE> const &v) explicit inline constexpr vec_t(vec_t<U, 2, SWIZZLE> const &v)
: x(v[0]), y(v[1]) {}
: x(T(v[0])), y(T(v[1])) {}


/* Constructor for initializer_list. We need these ugly /* Constructor for initializer_list. We need these ugly
* loops until C++ lets us initialize m_data directly. */ * loops until C++ lets us initialize m_data directly. */
@@ -237,8 +241,8 @@ struct vec_t<T,2>
auto l = list.begin(); auto l = list.begin();
for (int i = 0; i < count && l != list.end(); ++i, ++l) for (int i = 0; i < count && l != list.end(); ++i, ++l)
m_data[i] = *l; m_data[i] = *l;
for (int i = list.size(); i < count; ++i)
m_data[i] = (T)0;
for (int i = (int)list.size(); i < count; ++i)
m_data[i] = T(0);
} }


/* Various explicit constructors */ /* Various explicit constructors */
@@ -252,7 +256,7 @@ struct vec_t<T,2>
{ {
ASSERT(i >= 0); ASSERT(i >= 0);
ASSERT(i < 2); ASSERT(i < 2);
return vec_t<T,2>((T)(i == 0), (T)(i == 1));
return vec_t<T,2>(T(i == 0), T(i == 1));
} }


LOL_COMMON_MEMBER_OPS(x) LOL_COMMON_MEMBER_OPS(x)
@@ -343,7 +347,7 @@ struct vec_t<T,3>
/* Explicit constructor for type conversion */ /* Explicit constructor for type conversion */
template<typename U, int SWIZZLE> template<typename U, int SWIZZLE>
explicit inline constexpr vec_t(vec_t<U, 3, SWIZZLE> const &v) explicit inline constexpr vec_t(vec_t<U, 3, SWIZZLE> const &v)
: x(v[0]), y(v[1]), z(v[2]) {}
: x(T(v[0])), y(T(v[1])), z(T(v[2])) {}


/* Constructor for initializer_list. We need these ugly /* Constructor for initializer_list. We need these ugly
* loops until C++ lets us initialize m_data directly. */ * loops until C++ lets us initialize m_data directly. */
@@ -352,8 +356,8 @@ struct vec_t<T,3>
auto l = list.begin(); auto l = list.begin();
for (int i = 0; i < count && l != list.end(); ++i, ++l) for (int i = 0; i < count && l != list.end(); ++i, ++l)
m_data[i] = *l; m_data[i] = *l;
for (int i = list.size(); i < count; ++i)
m_data[i] = (T)0;
for (int i = (int)list.size(); i < count; ++i)
m_data[i] = T(0);
} }


/* Various explicit constructors */ /* Various explicit constructors */
@@ -371,7 +375,7 @@ struct vec_t<T,3>
{ {
ASSERT(i >= 0); ASSERT(i >= 0);
ASSERT(i < 3); ASSERT(i < 3);
return vec_t<T,3>((T)(i == 0), (T)(i == 1), (T)(i == 2));
return vec_t<T,3>(T(i == 0), T(i == 1), T(i == 2));
} }


LOL_COMMON_MEMBER_OPS(x) LOL_COMMON_MEMBER_OPS(x)
@@ -402,8 +406,8 @@ struct vec_t<T,3>
friend inline type orthogonal(type const &a) friend inline type orthogonal(type const &a)
{ {
return lol::abs(a.x) > lol::abs(a.z) return lol::abs(a.x) > lol::abs(a.z)
? type(-a.y, a.x, (T)0)
: type((T)0, -a.z, a.y);
? type(-a.y, a.x, T(0))
: type(T(0), -a.z, a.y);
} }


/* Return a vector that is orthonormal to “a” */ /* Return a vector that is orthonormal to “a” */
@@ -589,7 +593,7 @@ struct vec_t<T,4>
/* Explicit constructor for type conversion */ /* Explicit constructor for type conversion */
template<typename U, int SWIZZLE> template<typename U, int SWIZZLE>
explicit inline constexpr vec_t(vec_t<U, 4, SWIZZLE> const &v) explicit inline constexpr vec_t(vec_t<U, 4, SWIZZLE> const &v)
: x(v[0]), y(v[1]), z(v[2]), w(v[3]) {}
: x(T(v[0])), y(T(v[1])), z(T(v[2])), w(T(v[3])) {}


/* Constructor for initializer_list. We need these ugly /* Constructor for initializer_list. We need these ugly
* loops until C++ lets us initialize m_data directly. */ * loops until C++ lets us initialize m_data directly. */
@@ -598,8 +602,8 @@ struct vec_t<T,4>
auto l = list.begin(); auto l = list.begin();
for (int i = 0; i < count && l != list.end(); ++i, ++l) for (int i = 0; i < count && l != list.end(); ++i, ++l)
m_data[i] = *l; m_data[i] = *l;
for (int i = list.size(); i < count; ++i)
m_data[i] = (T)0;
for (int i = (int)list.size(); i < count; ++i)
m_data[i] = T(0);
} }


/* Various explicit constructors */ /* Various explicit constructors */
@@ -625,7 +629,7 @@ struct vec_t<T,4>
{ {
ASSERT(i >= 0); ASSERT(i >= 0);
ASSERT(i < 4); ASSERT(i < 4);
return vec_t<T,4>((T)(i == 0), (T)(i == 1), (T)(i == 2), (T)(i == 3));
return vec_t<T,4>(T(i == 0), T(i == 1), T(i == 2), T(i == 3));
} }


LOL_COMMON_MEMBER_OPS(x) LOL_COMMON_MEMBER_OPS(x)
@@ -1142,7 +1146,7 @@ template<typename T, int N, int SWIZZLE>
static inline T length(vec_t<T,N,SWIZZLE> const &a) static inline T length(vec_t<T,N,SWIZZLE> const &a)
{ {
/* FIXME: this is not very nice */ /* FIXME: this is not very nice */
return (T)sqrt((double)sqlength(a));
return T(sqrt((double)sqlength(a)));
} }


template<typename T, int N, int SWIZZLE1, int SWIZZLE2> template<typename T, int N, int SWIZZLE1, int SWIZZLE2>
@@ -1184,7 +1188,7 @@ static inline vec_t<T,N> saturate(vec_t<T,N,SWIZZLE> const &a)
template<typename T, int N, int SWIZZLE> template<typename T, int N, int SWIZZLE>
static inline vec_t<T,N> normalize(vec_t<T,N,SWIZZLE> const &a) static inline vec_t<T,N> normalize(vec_t<T,N,SWIZZLE> const &a)
{ {
T norm = (T)length(a);
T norm = T(length(a));
return norm ? a / norm : vec_t<T,N>(T(0)); return norm ? a / norm : vec_t<T,N>(T(0));
} }


@@ -1272,6 +1276,40 @@ inline vec_const_iter<T,N,SWIZZLE> end(vec_t<T,N,SWIZZLE> const &a)
return vec_const_iter<T,N,SWIZZLE>(a, N); return vec_const_iter<T,N,SWIZZLE>(a, N);
} }


/*
* Constants
*/

template<typename T, int N>
vec_t<T,N> const vec_t<T,N>::zero = vec_t<T,N>(T(0));
template<typename T>
vec_t<T,2> const vec_t<T,2>::zero = vec_t<T,2>(T(0));
template<typename T>
vec_t<T,3> const vec_t<T,3>::zero = vec_t<T,3>(T(0));
template<typename T>
vec_t<T,4> const vec_t<T,4>::zero = vec_t<T,4>(T(0));

template<typename T>
vec_t<T,2> const vec_t<T,2>::axis_x = vec_t<T,2>(T(1), T(0));
template<typename T>
vec_t<T,2> const vec_t<T,2>::axis_y = vec_t<T,2>(T(0), T(1));

template<typename T>
vec_t<T,3> const vec_t<T,3>::axis_x = vec_t<T,3>(T(1), T(0), T(0));
template<typename T>
vec_t<T,3> const vec_t<T,3>::axis_y = vec_t<T,3>(T(0), T(1), T(0));
template<typename T>
vec_t<T,3> const vec_t<T,3>::axis_z = vec_t<T,3>(T(0), T(0), T(1));

template<typename T>
vec_t<T,4> const vec_t<T,4>::axis_x = vec_t<T,4>(T(1), T(0), T(0), T(0));
template<typename T>
vec_t<T,4> const vec_t<T,4>::axis_y = vec_t<T,4>(T(0), T(1), T(0), T(0));
template<typename T>
vec_t<T,4> const vec_t<T,4>::axis_z = vec_t<T,4>(T(0), T(0), T(1), T(0));
template<typename T>
vec_t<T,4> const vec_t<T,4>::axis_w = vec_t<T,4>(T(0), T(0), T(0), T(1));

#if !LOL_FEATURE_CXX11_CONSTEXPR #if !LOL_FEATURE_CXX11_CONSTEXPR
#undef constexpr #undef constexpr
#endif #endif


+ 1
- 0
src/lolcore.vcxproj View File

@@ -212,6 +212,7 @@
<ClCompile Include="scene.cpp" /> <ClCompile Include="scene.cpp" />
<ClCompile Include="sprite.cpp" /> <ClCompile Include="sprite.cpp" />
<ClCompile Include="sys\file.cpp" /> <ClCompile Include="sys\file.cpp" />
<ClCompile Include="sys\hacks.cpp" />
<ClCompile Include="sys\init.cpp" /> <ClCompile Include="sys\init.cpp" />
<ClCompile Include="sys\thread.cpp" /> <ClCompile Include="sys\thread.cpp" />
<ClCompile Include="sys\timer.cpp" /> <ClCompile Include="sys\timer.cpp" />


+ 3
- 0
src/lolcore.vcxproj.filters View File

@@ -297,6 +297,9 @@
<ClCompile Include="easymesh\csgbsp.cpp"> <ClCompile Include="easymesh\csgbsp.cpp">
<Filter>easymesh</Filter> <Filter>easymesh</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="sys\hacks.cpp">
<Filter>sys</Filter>
</ClCompile>
<ClCompile Include="sys\init.cpp"> <ClCompile Include="sys\init.cpp">
<Filter>sys</Filter> <Filter>sys</Filter>
</ClCompile> </ClCompile>


+ 10
- 64
src/math/constants.cpp View File

@@ -1,75 +1,21 @@
// //
// Lol Engine
// 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.
// Copyright © 2010-2015 Sam Hocevar <sam@hocevar.net>
//
// This library is free software. It comes without any warranty, to
// the extent permitted by applicable law. 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 the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
// //


#include <lol/engine-internal.h> #include <lol/engine-internal.h>


namespace lol { namespace lol {


#define LOL_VEC_2_CONST(T, name, a, b) \
template<> \
vec_t<T,2> const vec_t<T,2>::name = vec_t<T,2>((T)a, (T)b);

#define LOL_VEC_3_CONST(T, name, a, b, c) \
template<> \
vec_t<T,3> const vec_t<T,3>::name = vec_t<T,3>((T)a, (T)b, (T)c);

#define LOL_VEC_4_CONST(T, name, a, b, c, d) \
template<> \
vec_t<T,4> const vec_t<T,4>::name = vec_t<T,4>((T)a, (T)b, (T)c, (T)d);

#define LOL_MAT_CONST(T, name, a) \
template<> \
mat_t<T,2,2> const mat_t<T,2,2>::name = mat_t<T,2,2>((T)a); \
\
template<> \
mat_t<T,3,3> const mat_t<T,3,3>::name = mat_t<T,3,3>((T)a); \
\
template<> \
mat_t<T,4,4> const mat_t<T,4,4>::name = mat_t<T,4,4>((T)a);

#define LOL_ALL_CONST_INNER(T) \
LOL_VEC_2_CONST(T, zero, 0, 0) \
LOL_VEC_2_CONST(T, axis_x, 1, 0) \
LOL_VEC_2_CONST(T, axis_y, 0, 1) \
\
LOL_VEC_3_CONST(T, zero, 0, 0, 0) \
LOL_VEC_3_CONST(T, axis_x, 1, 0, 0) \
LOL_VEC_3_CONST(T, axis_y, 0, 1, 0) \
LOL_VEC_3_CONST(T, axis_z, 0, 0, 1) \
\
LOL_VEC_4_CONST(T, zero, 0, 0, 0, 0) \
LOL_VEC_4_CONST(T, axis_x, 1, 0, 0, 0) \
LOL_VEC_4_CONST(T, axis_y, 0, 1, 0, 0) \
LOL_VEC_4_CONST(T, axis_z, 0, 0, 1, 0) \
LOL_VEC_4_CONST(T, axis_w, 0, 0, 0, 1) \
\
LOL_MAT_CONST(T, identity, 1)

#if LOL_FEATURE_CXX11_UNRESTRICTED_UNIONS
LOL_ALL_CONST_INNER(half)
#endif
LOL_ALL_CONST_INNER(float)
LOL_ALL_CONST_INNER(double)
LOL_ALL_CONST_INNER(ldouble)
#if LOL_FEATURE_CXX11_UNRESTRICTED_UNIONS
LOL_ALL_CONST_INNER(real)
#endif

LOL_ALL_CONST_INNER(int8_t)
LOL_ALL_CONST_INNER(uint8_t)
LOL_ALL_CONST_INNER(int16_t)
LOL_ALL_CONST_INNER(uint16_t)
LOL_ALL_CONST_INNER(int32_t)
LOL_ALL_CONST_INNER(uint32_t)
LOL_ALL_CONST_INNER(int64_t)
LOL_ALL_CONST_INNER(uint64_t)
// There is nothing here for now.
extern int unused_file_constants_cpp;


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



+ 42
- 0
src/sys/hacks.cpp View File

@@ -0,0 +1,42 @@
//
// Lol Engine
//
// Copyright © 2010-2015 Sam Hocevar <sam@hocevar.net>
//
// This library is free software. It comes without any warranty, to
// the extent permitted by applicable law. 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 the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
//

#include <lol/engine-internal.h>

/*
* VS 2015 hack: the CRT was fully rewritten, and functions such
* as _iob_func() and fprintf() have disappeared. Since we link with
* libSDL which uses these versions, we need to provide them.
*/

#if _MSC_VER >= 1900
#include <cstdio>

extern "C" {

void *__imp___iob_func(void)
{
return NULL;
}

int __imp_fprintf(FILE *stream, char const *fmt, ...)
{
va_list va;
va_start(va, fmt);
int ret = vfprintf(stream, fmt, va);
va_end(va);
return ret;
}

}
#endif


+ 9
- 6
tools/lolunit/lolunit.h View File

@@ -1,11 +1,13 @@
// //
// Lol Engine
// Lol Engine
// //
// Copyright: (c) 2010-2011 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.
// Copyright © 2010-2015 Sam Hocevar <sam@hocevar.net>
//
// This library is free software. It comes without any warranty, to
// the extent permitted by applicable law. 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 the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
// //


#pragma once #pragma once
@@ -324,6 +326,7 @@ public:
public: \ public: \
lol_unit_helper_test_##N() \ lol_unit_helper_test_##N() \
{ \ { \
(void)lol_unit_helper_name(nullptr); \
AddTestCase(this, #N, \ AddTestCase(this, #N, \
(void (FixtureClass::*)()) &FixtureClass::N); \ (void (FixtureClass::*)()) &FixtureClass::N); \
} \ } \


Loading…
Cancel
Save