1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-12-25 06:05:45 +00:00

More compile fixes for gcc 2.95

This commit is contained in:
fgenesis 2012-09-23 05:30:47 +02:00
parent 1fdae0c128
commit 31930051d5
5 changed files with 96 additions and 55 deletions

View file

@ -359,6 +359,7 @@ static void scriptError(lua_State *L, const std::string& msg)
// memory location, be sure this is the case before running into undefined behavior later. // memory location, be sure this is the case before running into undefined behavior later.
// - The C++ standard allows offsetof() only on POD-types. Oh well, it probably works anyways. // - The C++ standard allows offsetof() only on POD-types. Oh well, it probably works anyways.
// If it does not compile for some reason, comment it out, hope for the best, and go ahead. // If it does not compile for some reason, comment it out, hope for the best, and go ahead.
#if !(defined(__GNUC__) && __GNUC__ <= 2)
void compile_time_assertions() void compile_time_assertions()
{ {
#define oo(cls) offsetof(cls, _objtype) #define oo(cls) offsetof(cls, _objtype)
@ -377,6 +378,7 @@ void compile_time_assertions()
compile_assert(oo(Path) == oo(BaseText)); compile_assert(oo(Path) == oo(BaseText));
#undef oo #undef oo
} }
#endif
template <typename T> template <typename T>
static void ensureType(lua_State *L, T *& ptr, ScriptObjectType ty) static void ensureType(lua_State *L, T *& ptr, ScriptObjectType ty)

View file

@ -232,7 +232,7 @@ void stringToLowerUserData(std::string &s)
const size_t len = userdata.length(); const size_t len = userdata.length();
const bool match = (s.length() > len) && const bool match = (s.length() > len) &&
((s[len] == '/') || (s[len] == '\\')) && ((s[len] == '/') || (s[len] == '\\')) &&
(userdata.compare(0, len, s, 0, len) == 0); !strncmp(userdata.c_str(), s.c_str(), len);
if (!match) if (!match)
stringToLower(s); stringToLower(s);
else else

View file

@ -18,7 +18,8 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#pragma once #ifndef BBGE_VECTOR_H
#define BBGE_VECTOR_H
#include <math.h> #include <math.h>
#include <float.h> #include <float.h>
@ -64,13 +65,13 @@ public:
} }
// vecector equality // vecector equality
const bool operator==(const Vector &vec) const bool operator==(const Vector &vec) const
{ {
return ((x == vec.x) && (y == vec.y) && (z == vec.z)); return ((x == vec.x) && (y == vec.y) && (z == vec.z));
} }
// vecector inequality // vecector inequality
const bool operator!=(const Vector &vec) const bool operator!=(const Vector &vec) const
{ {
return !(*this == vec); return !(*this == vec);
} }
@ -106,10 +107,6 @@ public:
{ {
return Vector(-x, -y, -z); return Vector(-x, -y, -z);
} }
bool isZero()
{
return x == 0 && y == 0 && z == 0;
}
// vector decrement // vector decrement
const Vector &operator-=(const Vector& vec) const Vector &operator-=(const Vector& vec)
@ -201,12 +198,12 @@ public:
return Vector(y*vec.z - z*vec.y, z*vec.x - x*vec.z, x*vec.y - y*vec.x); return Vector(y*vec.z - z*vec.y, z*vec.x - x*vec.z, x*vec.y - y*vec.x);
} }
Vector inline getPerpendicularLeft() inline Vector getPerpendicularLeft()
{ {
return Vector(-y, x); return Vector(-y, x);
} }
Vector inline getPerpendicularRight() inline Vector getPerpendicularRight()
{ {
return Vector(y, -x); return Vector(y, -x);
} }
@ -218,41 +215,41 @@ public:
} }
// dot product // dot product
const scalar_t inline dot(const Vector &vec) const inline scalar_t dot(const Vector &vec) const
{ {
return x*vec.x + y*vec.y + z*vec.z; return x*vec.x + y*vec.y + z*vec.z;
} }
const scalar_t inline dot2D(const Vector &vec) const inline scalar_t dot2D(const Vector &vec) const
{ {
return x*vec.x + y*vec.y; return x*vec.x + y*vec.y;
} }
// dot product // dot product
const scalar_t operator%(const Vector &vec) const scalar_t operator%(const Vector &vec) const
{ {
return x*vec.x + y*vec.x + z*vec.z; return x*vec.x + y*vec.x + z*vec.z;
} }
// length of vector // length of vector
const scalar_t inline getLength3D() const inline scalar_t getLength3D() const
{ {
return (scalar_t)sqrtf(x*x + y*y + z*z); return (scalar_t)sqrtf(x*x + y*y + z*z);
} }
const scalar_t inline getLength2D() const inline scalar_t getLength2D() const
{ {
return (scalar_t)sqrtf(x*x + y*y); return (scalar_t)sqrtf(x*x + y*y);
} }
// return the unit vector // return the unit vector
const Vector inline unitVector3D() const inline const Vector unitVector3D() const
{ {
return (*this) * (1/getLength3D()); return (*this) * (1/getLength3D());
} }
// normalize this vector // normalize this vector
void inline normalize3D() inline void normalize3D()
{ {
if (x == 0 && y == 0 && z == 0) if (x == 0 && y == 0 && z == 0)
{ {
@ -264,7 +261,7 @@ public:
(*this) *= 1/getLength3D(); (*this) *= 1/getLength3D();
} }
} }
void inline normalize2D() inline void normalize2D()
{ {
if (x == 0 && y == 0) if (x == 0 && y == 0)
{ {
@ -277,7 +274,7 @@ public:
} }
} }
const scalar_t operator!() const scalar_t operator!() const
{ {
return sqrtf(x*x + y*y + z*z); return sqrtf(x*x + y*y + z*z);
} }
@ -297,7 +294,7 @@ public:
} }
*/ */
void inline setLength3D(const float l) inline void setLength3D(const float l)
{ {
// IGNORE !! // IGNORE !!
if (l == 0) if (l == 0)
@ -312,7 +309,7 @@ public:
this->z *= (l/len); this->z *= (l/len);
} }
} }
void inline setLength2D(const float l) inline void setLength2D(const float l)
{ {
float len = getLength2D(); float len = getLength2D();
if (len == 0) if (len == 0)
@ -328,24 +325,24 @@ public:
} }
// return angle between two vectors // return angle between two vectors
const float inline Angle(const Vector& normal) const inline scalar_t Angle(const Vector& normal) const
{ {
return acosf(*this % normal); return acosf(*this % normal);
} }
/* /*
const scalar_t inline cheatLen() const inline scalar_t cheatLen() const
{ {
return (x*x + y*y + z*z); return (x*x + y*y + z*z);
} }
const scalar_t inline cheatLen2D() const inline scalar_t cheatLen2D() const
{ {
return (x*x + y*y); return (x*x + y*y);
} }
const scalar_t inline getCheatLength3D() const; inline scalar_t getCheatLength3D() const;
*/ */
const bool inline isLength2DIn(float radius) const inline bool isLength2DIn(float radius) const
{ {
return (x*x + y*y) <= (radius*radius); return (x*x + y*y) <= (radius*radius);
} }
@ -359,20 +356,20 @@ public:
} }
*/ */
const void inline setZero() inline void setZero()
{ {
this->x = this->y = this->z = 0; this->x = this->y = this->z = 0;
} }
const float inline getSquaredLength2D() const inline scalar_t getSquaredLength2D() const
{ {
return (x*x) + (y*y); return (x*x) + (y*y);
} }
const bool inline isZero() const inline bool isZero() const
{ {
return x==0 && y==0 && z==0; return x==0 && y==0 && z==0;
} }
const bool inline isNan() const inline bool isNan() const
{ {
#ifdef BBGE_BUILD_WINDOWS #ifdef BBGE_BUILD_WINDOWS
return _isnan(x) || _isnan(y) || _isnan(z); return _isnan(x) || _isnan(y) || _isnan(z);
@ -383,11 +380,11 @@ public:
#endif #endif
} }
void inline capLength2D(const float l) inline void capLength2D(const float l)
{ {
if (!isLength2DIn(l)) setLength2D(l); if (!isLength2DIn(l)) setLength2D(l);
} }
void inline capRotZ360() inline void capRotZ360()
{ {
while (z > 360) while (z > 360)
z -= 360; z -= 360;
@ -573,3 +570,5 @@ public:
Vector getRotatedVector(const Vector &vec, float rot); Vector getRotatedVector(const Vector &vec, float rot);
Vector lerp(const Vector &v1, const Vector &v2, float dt, int lerpType); Vector lerp(const Vector &v1, const Vector &v2, float dt, int lerpType);
#endif // BBGE_VECTOR_H

View file

@ -6,6 +6,12 @@
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>
#if defined(__GNUC__) && __GNUC__ <= 2
# define BB_OLD_GNUC
# include <algorithm>
#endif
// ** compatibility stuff for BBGE .... ** // ** compatibility stuff for BBGE .... **
@ -26,7 +32,7 @@
namespace ByteBufferTools namespace ByteBufferTools
{ {
template<size_t T> inline void convert(char *val) template<int T> inline void convert(char *val)
{ {
std::swap(*val, *(val + T - 1)); std::swap(*val, *(val + T - 1));
convert<T - 2>(val + 1); convert<T - 2>(val + 1);
@ -39,12 +45,21 @@ namespace ByteBufferTools
convert<sizeof(T)>((char *)(val)); convert<sizeof(T)>((char *)(val));
} }
inline void EndianConvertRT(char *p, unsigned int size)
{
std::reverse(p, p + size);
}
#if BB_IS_BIG_ENDIAN #if BB_IS_BIG_ENDIAN
template<typename T> inline void ToLittleEndian(T& val) { EndianConvert<T>(&val); } template<typename T> inline void ToLittleEndian(T& val) { EndianConvert<T>(&val); }
inline void ToLittleEndianRT(void *p, unsigned int size) { EndianConvertRT((char*)p, size); }
template<typename T> inline void ToBigEndian(T&) { } template<typename T> inline void ToBigEndian(T&) { }
inline void ToBigEndianRT(void *p, unsigned int size) { }
#else #else
template<typename T> inline void ToLittleEndian(T&) { } template<typename T> inline void ToLittleEndian(T&) { }
inline void ToLittleEndianRT(void *p, unsigned int size) { }
template<typename T> inline void ToBigEndian(T& val) { EndianConvert<T>(&val); } template<typename T> inline void ToBigEndian(T& val) { EndianConvert<T>(&val); }
inline void ToBigEndianRT(void *p, unsigned int size) { EndianConvertRT((char*)p, size); }
#endif #endif
template<typename T> void ToLittleEndian(T*); // will generate link error template<typename T> void ToLittleEndian(T*); // will generate link error
@ -52,8 +67,13 @@ namespace ByteBufferTools
}; };
#define BB_MAKE_WRITE_OP(T) inline ByteBuffer& operator<<(T val) { append<T>(val); return *this; } #ifdef BB_OLD_GNUC
#define BB_MAKE_READ_OP(T) inline ByteBuffer& operator>>(T &val) { val = read<T>(); return *this; } # define BB_MAKE_WRITE_OP(T) inline ByteBuffer& operator<<(T val) { appendT(&val, sizeof(T)); return *this; }
# define BB_MAKE_READ_OP(T) inline ByteBuffer& operator>>(T &val) { readT(&val, sizeof(T)); return *this; }
#else
# define BB_MAKE_WRITE_OP(T) inline ByteBuffer& operator<<(T val) { append<T>(val); return *this; }
# define BB_MAKE_READ_OP(T) inline ByteBuffer& operator>>(T &val) { val = read<T>(); return *this; }
#endif
class ByteBuffer class ByteBuffer
{ {
@ -241,23 +261,17 @@ public:
BB_MAKE_WRITE_OP(float); BB_MAKE_WRITE_OP(float);
BB_MAKE_WRITE_OP(double); BB_MAKE_WRITE_OP(double);
ByteBuffer &operator<<(bool value)
{
append<char>((char)value);
return *this;
}
ByteBuffer &operator<<(const char *str) ByteBuffer &operator<<(const char *str)
{ {
append((uint8 *)str, str ? strlen(str) : 0); append((uint8 *)str, str ? strlen(str) : 0);
append((uint8)0); appendByte(0);
return *this; return *this;
} }
ByteBuffer &operator<<(const std::string &value) ByteBuffer &operator<<(const std::string &value)
{ {
append((uint8 *)value.c_str(), value.length()); append((uint8 *)value.c_str(), value.length());
append((uint8)0); appendByte(0);
return *this; return *this;
} }
@ -271,22 +285,18 @@ public:
BB_MAKE_READ_OP(float); BB_MAKE_READ_OP(float);
BB_MAKE_READ_OP(double); BB_MAKE_READ_OP(double);
ByteBuffer &operator>>(bool &value) inline uint8 operator[](uint32 pos) const
{ {
value = read<char>() > 0 ? true : false; if(pos >= size())
return *this; BYTEBUFFER_EXCEPT(this, "operator[]", 1);
} return _buf[pos];
uint8 operator[](uint32 pos)
{
return read<uint8>(pos);
} }
ByteBuffer &operator>>(std::string& value) ByteBuffer &operator>>(std::string& value)
{ {
value.clear(); value.clear();
char c; char c;
while(readable() && (c = read<char>())) while(readable() && (c = readByte()))
value += c; value += c;
return *this; return *this;
} }
@ -313,6 +323,7 @@ public:
_rpos += sizeof(T); _rpos += sizeof(T);
return r; return r;
} }
template <typename T> T read(uint32 pos) const template <typename T> T read(uint32 pos) const
{ {
if(pos + sizeof(T) > size()) if(pos + sizeof(T) > size())
@ -322,6 +333,20 @@ public:
return val; return val;
} }
inline uint8 readByte()
{
if (_rpos < size())
return _buf[_rpos++];
BYTEBUFFER_EXCEPT(this, "readByte", 1);
return 0;
}
void readT(void *dest, uint32 len)
{
read(dest, len);
ByteBufferTools::ToLittleEndianRT(dest, len);
}
void read(void *dest, uint32 len) void read(void *dest, uint32 len)
{ {
if (_rpos + len <= size()) if (_rpos + len <= size())
@ -352,7 +377,7 @@ public:
inline uint32 readable(void) const { return size() - rpos(); } inline uint32 readable(void) const { return size() - rpos(); }
inline uint32 writable(void) const { return size() - wpos(); } // free space left before realloc will occur inline uint32 writable(void) const { return size() - wpos(); } // free space left before realloc will occur
template <typename T> void append(T value) template <typename T> inline void append(T value)
{ {
ByteBufferTools::ToLittleEndian<T>(value); ByteBufferTools::ToLittleEndian<T>(value);
_enlargeIfReq(_wpos + sizeof(T)); _enlargeIfReq(_wpos + sizeof(T));
@ -362,6 +387,21 @@ public:
_size = _wpos; _size = _wpos;
} }
inline void appendByte(uint8 value)
{
_enlargeIfReq(_wpos + 1);
_buf[_wpos++] = value;
if(_size < _wpos)
_size = _wpos;
}
// GCC 2.95 fails with an internal error in the template function above
void appendT(const void *src, uint32 bytes)
{
append(src, bytes);
ByteBufferTools::ToLittleEndianRT(_buf + (_wpos - bytes), bytes);
}
void append(const void *src, uint32 bytes) void append(const void *src, uint32 bytes)
{ {
if (!bytes) return; if (!bytes) return;
@ -382,7 +422,7 @@ public:
memcpy(_buf + pos, src, bytes); memcpy(_buf + pos, src, bytes);
} }
template <typename T> void put(uint32 pos, T value) template <typename T> void put(uint32 pos, const T& value)
{ {
if(pos >= size()) if(pos >= size())
BYTEBUFFER_EXCEPT(this, "put", sizeof(T)); BYTEBUFFER_EXCEPT(this, "put", sizeof(T));

View file

@ -118,7 +118,7 @@ bool InStream::open(const char *fn)
vf->dropBuf(true); vf->dropBuf(true);
return true; return true;
} }
setstate(std::ios_base::failbit); setstate(std::ios::failbit);
return false; return false;
} }