diff --git a/src/common/Data.h b/src/common/Data.h index 4d9f1fff3..9ceea9441 100644 --- a/src/common/Data.h +++ b/src/common/Data.h @@ -1,56 +1,56 @@ -/** -* Copyright (c) 2006-2011 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#ifndef LOVE_DATA_H -#define LOVE_DATA_H - -// LOVE -#include "config.h" -#include "Object.h" - -namespace love -{ - /** - * This class is a simple abstraction over all objects which contain data. - **/ - class Data : public Object - { - public: - - /** - * Destructor. - **/ - virtual ~Data() {}; - - /** - * Gets a pointer to the data. This pointer will obviously not - * be valid if the Data object is destroyed. - **/ - virtual void * getData() const = 0 ; - - /** - * Gets the size of the Data in bytes. - **/ - virtual int getSize() const = 0; - - }; // Data -} // love - -#endif // LOVE_DATA_H +/** +* Copyright (c) 2006-2011 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#ifndef LOVE_DATA_H +#define LOVE_DATA_H + +// LOVE +#include "config.h" +#include "Object.h" + +namespace love +{ + /** + * This class is a simple abstraction over all objects which contain data. + **/ + class Data : public Object + { + public: + + /** + * Destructor. + **/ + virtual ~Data() {}; + + /** + * Gets a pointer to the data. This pointer will obviously not + * be valid if the Data object is destroyed. + **/ + virtual void * getData() const = 0 ; + + /** + * Gets the size of the Data in bytes. + **/ + virtual int getSize() const = 0; + + }; // Data +} // love + +#endif // LOVE_DATA_H diff --git a/src/common/EnumMap.h b/src/common/EnumMap.h index c86f9fe33..9c3f104b5 100644 --- a/src/common/EnumMap.h +++ b/src/common/EnumMap.h @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2011 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -41,7 +41,7 @@ namespace love Value values_u[PEAK]; public: - + struct Entry { T t; @@ -52,27 +52,27 @@ namespace love { unsigned n = size/sizeof(Entry); - for(unsigned i = 0; i -#include -using namespace std; - -namespace love -{ - Exception::Exception(const char * fmt, ...) - { - va_list args; - int size_buffer = 256, size_out; - char * buffer; - while (true) { - buffer = new char[size_buffer]; - memset(buffer, 0, size_buffer); - - va_start(args, fmt); - size_out = vsnprintf(buffer, size_buffer, fmt, args); - va_end(args); - - // see http://perfec.to/vsnprintf/pasprintf.c - // if size_out ... - // == -1 --> output was truncated - // == size_buffer --> output was truncated - // == size_buffer-1 --> ambiguous, /may/ have been truncated - // > size_buffer --> output was truncated, and size_out - // bytes would have been written - if (size_out == size_buffer || size_out == -1 || size_out == size_buffer-1) - size_buffer *= 2; - else if (size_out > size_buffer) - size_buffer = size_out + 2; // to avoid the ambiguous case - else - break; - - delete[] buffer; - } - message = std::string(buffer); - delete[] buffer; - } - -} +/** +* Copyright (c) 2006-2011 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#include "Exception.h" +#include +#include +using namespace std; + +namespace love +{ + Exception::Exception(const char * fmt, ...) + { + va_list args; + int size_buffer = 256, size_out; + char * buffer; + while (true) + { + buffer = new char[size_buffer]; + memset(buffer, 0, size_buffer); + + va_start(args, fmt); + size_out = vsnprintf(buffer, size_buffer, fmt, args); + va_end(args); + + // see http://perfec.to/vsnprintf/pasprintf.c + // if size_out ... + // == -1 --> output was truncated + // == size_buffer --> output was truncated + // == size_buffer-1 --> ambiguous, /may/ have been truncated + // > size_buffer --> output was truncated, and size_out + // bytes would have been written + if (size_out == size_buffer || size_out == -1 || size_out == size_buffer-1) + size_buffer *= 2; + else if (size_out > size_buffer) + size_buffer = size_out + 2; // to avoid the ambiguous case + else + break; + + delete[] buffer; + } + message = std::string(buffer); + delete[] buffer; + } + +} diff --git a/src/common/Exception.h b/src/common/Exception.h index c02a00eae..9101f40af 100644 --- a/src/common/Exception.h +++ b/src/common/Exception.h @@ -1,64 +1,64 @@ -/** -* Copyright (c) 2006-2011 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#ifndef LOVE_EXCEPTION_H -#define LOVE_EXCEPTION_H - -#include -#include // vararg -#include // vsnprintf -#include // strncpy -#include - -namespace love -{ - /** - * A convenient vararg-enabled exception class. - **/ - class Exception : public std::exception - { - private: - - std::string message; - - public: - - /** - * Creates a new Exception according to printf-rules. - * - * See: http://www.cplusplus.com/reference/clibrary/cstdio/printf/ - * - * @param fmt The format string (see printf). - **/ - Exception(const char * fmt, ...); - virtual ~Exception() throw() {} - - /** - * Returns a string containing reason for the exception. - * @return A description of the exception. - **/ - inline virtual const char * what() const throw() - { return message.c_str(); } - - }; // class - -} // love - -#endif // LOVE_EXCEPTION_H +/** +* Copyright (c) 2006-2011 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#ifndef LOVE_EXCEPTION_H +#define LOVE_EXCEPTION_H + +#include +#include // vararg +#include // vsnprintf +#include // strncpy +#include + +namespace love +{ + /** + * A convenient vararg-enabled exception class. + **/ + class Exception : public std::exception + { + private: + + std::string message; + + public: + + /** + * Creates a new Exception according to printf-rules. + * + * See: http://www.cplusplus.com/reference/clibrary/cstdio/printf/ + * + * @param fmt The format string (see printf). + **/ + Exception(const char * fmt, ...); + virtual ~Exception() throw() {} + + /** + * Returns a string containing reason for the exception. + * @return A description of the exception. + **/ + inline virtual const char * what() const throw() + { return message.c_str(); } + + }; // class + +} // love + +#endif // LOVE_EXCEPTION_H diff --git a/src/common/Matrix.cpp b/src/common/Matrix.cpp index e173fface..eef350325 100644 --- a/src/common/Matrix.cpp +++ b/src/common/Matrix.cpp @@ -1,196 +1,196 @@ -/** -* Copyright (c) 2006-2011 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#include "Matrix.h" - -// STD -#include // memcpy -#include - -namespace love -{ - - // | e0 e4 e8 e12 | - // | e1 e5 e9 e13 | - // | e2 e6 e10 e14 | - // | e3 e7 e11 e15 | - - Matrix::Matrix() - { - setIdentity(); - } - - Matrix::~Matrix() - { - } - - // | e0 e4 e8 e12 | - // | e1 e5 e9 e13 | - // | e2 e6 e10 e14 | - // | e3 e7 e11 e15 | - // | e0 e4 e8 e12 | - // | e1 e5 e9 e13 | - // | e2 e6 e10 e14 | - // | e3 e7 e11 e15 | - - Matrix Matrix::operator * (const Matrix & m) const - { - Matrix t; - - t.e[0] = (e[0]*m.e[0]) + (e[4]*m.e[1]) + (e[8]*m.e[2]) + (e[12]*m.e[3]); - t.e[4] = (e[0]*m.e[4]) + (e[4]*m.e[5]) + (e[8]*m.e[6]) + (e[12]*m.e[7]); - t.e[8] = (e[0]*m.e[8]) + (e[4]*m.e[9]) + (e[8]*m.e[10]) + (e[12]*m.e[11]); - t.e[12] = (e[0]*m.e[12]) + (e[4]*m.e[13]) + (e[8]*m.e[14]) + (e[12]*m.e[15]); - - t.e[1] = (e[1]*m.e[0]) + (e[5]*m.e[1]) + (e[9]*m.e[2]) + (e[13]*m.e[3]); - t.e[5] = (e[1]*m.e[4]) + (e[5]*m.e[5]) + (e[9]*m.e[6]) + (e[13]*m.e[7]); - t.e[9] = (e[1]*m.e[8]) + (e[5]*m.e[9]) + (e[9]*m.e[10]) + (e[13]*m.e[11]); - t.e[13] = (e[1]*m.e[12]) + (e[5]*m.e[13]) + (e[9]*m.e[14]) + (e[13]*m.e[15]); - - t.e[2] = (e[2]*m.e[0]) + (e[6]*m.e[1]) + (e[10]*m.e[2]) + (e[14]*m.e[3]); - t.e[6] = (e[2]*m.e[4]) + (e[6]*m.e[5]) + (e[10]*m.e[6]) + (e[14]*m.e[7]); - t.e[10] = (e[2]*m.e[8]) + (e[6]*m.e[9]) + (e[10]*m.e[10]) + (e[14]*m.e[11]); - t.e[14] = (e[2]*m.e[12]) + (e[6]*m.e[13]) + (e[10]*m.e[14]) + (e[14]*m.e[15]); - - t.e[3] = (e[3]*m.e[0]) + (e[7]*m.e[1]) + (e[11]*m.e[2]) + (e[15]*m.e[3]); - t.e[7] = (e[3]*m.e[4]) + (e[7]*m.e[5]) + (e[11]*m.e[6]) + (e[15]*m.e[7]); - t.e[11] = (e[3]*m.e[8]) + (e[7]*m.e[9]) + (e[11]*m.e[10]) + (e[15]*m.e[11]); - t.e[15] = (e[3]*m.e[12]) + (e[7]*m.e[13]) + (e[11]*m.e[14]) + (e[15]*m.e[15]); - - return t; - } - - void Matrix::operator *= (const Matrix & m) - { - Matrix t = (*this) * m; - memcpy((void*)this->e, (void*)t.e, sizeof(float)*16); - } - - const float * Matrix::getElements() const - { - return e; - } - - void Matrix::setIdentity() - { - memset(e, 0, sizeof(float)*16); - e[0] = e[5] = e[10] = e[15] = 1; - } - - void Matrix::setTranslation(float x, float y) - { - setIdentity(); - e[12] = x; - e[13] = y; - } - - void Matrix::setRotation(float rad) - { - setIdentity(); - float c = cos(rad), s = sin(rad); - e[0] = c; e[4] = -s; - e[1] = s; e[5] = c; - } - - void Matrix::setScale(float sx, float sy) - { - setIdentity(); - e[0] = sx; - e[5] = sy; - } - - void Matrix::setShear(float kx, float ky) - { - setIdentity(); - e[1] = ky; - e[4] = kx; - } - - void Matrix::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) - { - memset(e, 0, sizeof(float)*16); // zero out matrix - float c = cos(angle), s = sin(angle); - // matrix multiplication carried out on paper: - // |1 x| |c -s | |sx | | 1 ky | |1 -ox| - // | 1 y| |s c | | sy | |kx 1 | | 1 -oy| - // | 1 | | 1 | | 1 | | 1 | | 1 | - // | 1| | 1| | 1| | 1| | 1 | - // move rotate scale skew origin - e[10] = e[15] = 1.0f; - e[0] = c * sx - ky * s * sy; // = a - e[1] = s * sx + ky * c * sy; // = b - e[4] = kx * c * sx - s * sy; // = c - e[5] = kx * s * sx + c * sy; // = d - e[12] = x - ox * e[0] - oy * e[4]; - e[13] = y - ox * e[1] - oy * e[5]; - } - - void Matrix::translate(float x, float y) - { - Matrix t; - t.setTranslation(x, y); - this->operator *=(t); - } - - void Matrix::rotate(float rad) - { - Matrix t; - t.setRotation(rad); - this->operator *=(t); - } - - void Matrix::scale(float sx, float sy) - { - Matrix t; - t.setScale(sx, sy); - this->operator *=(t); - } - - void Matrix::shear(float kx, float ky) - { - Matrix t; - t.setShear(kx,ky); - this->operator *=(t); - } - - // | x | - // | y | - // | 0 | - // | 1 | - // | e0 e4 e8 e12 | - // | e1 e5 e9 e13 | - // | e2 e6 e10 e14 | - // | e3 e7 e11 e15 | - - void Matrix::transform(vertex * dst, const vertex * src, int size) const - { - for(int i = 0;i // memcpy +#include + +namespace love +{ + + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + + Matrix::Matrix() + { + setIdentity(); + } + + Matrix::~Matrix() + { + } + + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + + Matrix Matrix::operator * (const Matrix & m) const + { + Matrix t; + + t.e[0] = (e[0]*m.e[0]) + (e[4]*m.e[1]) + (e[8]*m.e[2]) + (e[12]*m.e[3]); + t.e[4] = (e[0]*m.e[4]) + (e[4]*m.e[5]) + (e[8]*m.e[6]) + (e[12]*m.e[7]); + t.e[8] = (e[0]*m.e[8]) + (e[4]*m.e[9]) + (e[8]*m.e[10]) + (e[12]*m.e[11]); + t.e[12] = (e[0]*m.e[12]) + (e[4]*m.e[13]) + (e[8]*m.e[14]) + (e[12]*m.e[15]); + + t.e[1] = (e[1]*m.e[0]) + (e[5]*m.e[1]) + (e[9]*m.e[2]) + (e[13]*m.e[3]); + t.e[5] = (e[1]*m.e[4]) + (e[5]*m.e[5]) + (e[9]*m.e[6]) + (e[13]*m.e[7]); + t.e[9] = (e[1]*m.e[8]) + (e[5]*m.e[9]) + (e[9]*m.e[10]) + (e[13]*m.e[11]); + t.e[13] = (e[1]*m.e[12]) + (e[5]*m.e[13]) + (e[9]*m.e[14]) + (e[13]*m.e[15]); + + t.e[2] = (e[2]*m.e[0]) + (e[6]*m.e[1]) + (e[10]*m.e[2]) + (e[14]*m.e[3]); + t.e[6] = (e[2]*m.e[4]) + (e[6]*m.e[5]) + (e[10]*m.e[6]) + (e[14]*m.e[7]); + t.e[10] = (e[2]*m.e[8]) + (e[6]*m.e[9]) + (e[10]*m.e[10]) + (e[14]*m.e[11]); + t.e[14] = (e[2]*m.e[12]) + (e[6]*m.e[13]) + (e[10]*m.e[14]) + (e[14]*m.e[15]); + + t.e[3] = (e[3]*m.e[0]) + (e[7]*m.e[1]) + (e[11]*m.e[2]) + (e[15]*m.e[3]); + t.e[7] = (e[3]*m.e[4]) + (e[7]*m.e[5]) + (e[11]*m.e[6]) + (e[15]*m.e[7]); + t.e[11] = (e[3]*m.e[8]) + (e[7]*m.e[9]) + (e[11]*m.e[10]) + (e[15]*m.e[11]); + t.e[15] = (e[3]*m.e[12]) + (e[7]*m.e[13]) + (e[11]*m.e[14]) + (e[15]*m.e[15]); + + return t; + } + + void Matrix::operator *= (const Matrix & m) + { + Matrix t = (*this) * m; + memcpy((void*)this->e, (void*)t.e, sizeof(float)*16); + } + + const float * Matrix::getElements() const + { + return e; + } + + void Matrix::setIdentity() + { + memset(e, 0, sizeof(float)*16); + e[0] = e[5] = e[10] = e[15] = 1; + } + + void Matrix::setTranslation(float x, float y) + { + setIdentity(); + e[12] = x; + e[13] = y; + } + + void Matrix::setRotation(float rad) + { + setIdentity(); + float c = cos(rad), s = sin(rad); + e[0] = c; e[4] = -s; + e[1] = s; e[5] = c; + } + + void Matrix::setScale(float sx, float sy) + { + setIdentity(); + e[0] = sx; + e[5] = sy; + } + + void Matrix::setShear(float kx, float ky) + { + setIdentity(); + e[1] = ky; + e[4] = kx; + } + + void Matrix::setTransformation(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) + { + memset(e, 0, sizeof(float)*16); // zero out matrix + float c = cos(angle), s = sin(angle); + // matrix multiplication carried out on paper: + // |1 x| |c -s | |sx | | 1 ky | |1 -ox| + // | 1 y| |s c | | sy | |kx 1 | | 1 -oy| + // | 1 | | 1 | | 1 | | 1 | | 1 | + // | 1| | 1| | 1| | 1| | 1 | + // move rotate scale skew origin + e[10] = e[15] = 1.0f; + e[0] = c * sx - ky * s * sy; // = a + e[1] = s * sx + ky * c * sy; // = b + e[4] = kx * c * sx - s * sy; // = c + e[5] = kx * s * sx + c * sy; // = d + e[12] = x - ox * e[0] - oy * e[4]; + e[13] = y - ox * e[1] - oy * e[5]; + } + + void Matrix::translate(float x, float y) + { + Matrix t; + t.setTranslation(x, y); + this->operator *=(t); + } + + void Matrix::rotate(float rad) + { + Matrix t; + t.setRotation(rad); + this->operator *=(t); + } + + void Matrix::scale(float sx, float sy) + { + Matrix t; + t.setScale(sx, sy); + this->operator *=(t); + } + + void Matrix::shear(float kx, float ky) + { + Matrix t; + t.setShear(kx,ky); + this->operator *=(t); + } + + // | x | + // | y | + // | 0 | + // | 1 | + // | e0 e4 e8 e12 | + // | e1 e5 e9 e13 | + // | e2 e6 e10 e14 | + // | e3 e7 e11 e15 | + + void Matrix::transform(vertex * dst, const vertex * src, int size) const + { + for (int i = 0;iL = L; - idx = luaL_ref(L, LUA_GLOBALSINDEX); - } - - void Reference::unref() - { - if(idx != LUA_REFNIL) - { - luaL_unref(L, LUA_GLOBALSINDEX, idx); - idx = LUA_REFNIL; - } - } - - void Reference::push() - { - if(idx != LUA_REFNIL) - lua_rawgeti(L, LUA_GLOBALSINDEX, idx); - else - lua_pushnil(L); - } - - lua_State * Reference::getL() - { - return L; - } - -} // love +/** +* Copyright (c) 2006-2011 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#include "Reference.h" + +namespace love +{ + Reference::Reference() + : L(0), idx(LUA_REFNIL) + { + } + + Reference::Reference(lua_State * L) + : L(0), idx(LUA_REFNIL) + { + ref(L); + } + + Reference::~Reference() + { + unref(); + } + + void Reference::ref(lua_State * L) + { + unref(); // Just to be safe. + this->L = L; + idx = luaL_ref(L, LUA_GLOBALSINDEX); + } + + void Reference::unref() + { + if (idx != LUA_REFNIL) + { + luaL_unref(L, LUA_GLOBALSINDEX, idx); + idx = LUA_REFNIL; + } + } + + void Reference::push() + { + if (idx != LUA_REFNIL) + lua_rawgeti(L, LUA_GLOBALSINDEX, idx); + else + lua_pushnil(L); + } + + lua_State * Reference::getL() + { + return L; + } + +} // love diff --git a/src/common/Reference.h b/src/common/Reference.h index 132e48aa3..acb704f1b 100644 --- a/src/common/Reference.h +++ b/src/common/Reference.h @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2011 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -49,7 +49,7 @@ namespace love Reference(); /** - * Creates the object and a reference to the value + * Creates the object and a reference to the value * on the top of the stack. **/ Reference(lua_State * L); @@ -58,11 +58,11 @@ namespace love * Deletes the reference, if any. **/ virtual ~Reference(); - + /** * Creates a reference to the value on the * top of the stack. - **/ + **/ void ref(lua_State * L); /** diff --git a/src/common/StringMap.h b/src/common/StringMap.h index ff3f9e8a0..895fcf541 100644 --- a/src/common/StringMap.h +++ b/src/common/StringMap.h @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2011 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -54,12 +54,12 @@ namespace love StringMap(Entry * entries, unsigned num) { - for(unsigned i = 0; i < SIZE; ++i) + for (unsigned i = 0; i < SIZE; ++i) reverse[i] = 0; unsigned n = num/sizeof(Entry); - for(unsigned i = 0; i < n; ++i) + for (unsigned i = 0; i < n; ++i) { add(entries[i].key, entries[i].value); } @@ -67,9 +67,9 @@ namespace love bool streq(const char * a, const char * b) { - while(*a != 0 && *b != 0) + while (*a != 0 && *b != 0) { - if(*a != *b) + if (*a != *b) return false; ++a; ++b; @@ -82,11 +82,11 @@ namespace love { //unsigned str_hash = djb2(key); - for(unsigned i = 0; i < MAX; ++i) + for (unsigned i = 0; i < MAX; ++i) { //unsigned str_i = (str_hash + i) % MAX; //this isn't used, is this intentional? - if(records[i].set && streq(records[i].key, key)) + if (records[i].set && streq(records[i].key, key)) { t = records[i].value; return true; @@ -100,10 +100,10 @@ namespace love { unsigned index = (unsigned)key; - if(index >= SIZE) + if (index >= SIZE) return false; - - if(reverse[index] != 0) + + if (reverse[index] != 0) { str = reverse[index]; return true; @@ -118,12 +118,12 @@ namespace love { unsigned str_hash = djb2(key); bool inserted = false; - - for(unsigned i = 0; i < MAX; ++i) + + for (unsigned i = 0; i < MAX; ++i) { unsigned str_i = (str_hash + i) % MAX; - if(!records[str_i].set) + if (!records[str_i].set) { inserted = true; records[str_i].set = true; @@ -135,7 +135,7 @@ namespace love unsigned index = (unsigned)value; - if(index >= SIZE) + if (index >= SIZE) { printf("\nConstant %s out of bounds with %i!\n", key, index); return false; diff --git a/src/common/Vector.cpp b/src/common/Vector.cpp index c2bce3558..20682d0f8 100644 --- a/src/common/Vector.cpp +++ b/src/common/Vector.cpp @@ -1,26 +1,26 @@ -/** -* Copyright (c) 2006-2011 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#include "Vector.h" - -namespace love -{ - // Implementation in header. +/** +* Copyright (c) 2006-2011 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#include "Vector.h" + +namespace love +{ + // Implementation in header. } \ No newline at end of file diff --git a/src/common/Vector.h b/src/common/Vector.h index 6638e5d3a..7d1d8adbb 100644 --- a/src/common/Vector.h +++ b/src/common/Vector.h @@ -1,310 +1,310 @@ -/** -* Copyright (c) 2006-2011 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#ifndef LOVE_VECTOR_H -#define LOVE_VECTOR_H - -// STD -#include - -// LOVE -#include "Matrix.h" - -namespace love -{ - /** - * 2D Vector class. - * - * @author Anders Ruud - * @date 2006-05-13 - **/ - class Vector - { - public: - - // The components. - float x, y; - - /** - * Creates a new (1,1) Vector. - **/ - Vector(); - - /** - * Creates a new Vector. - * @param x The x position/dimension. - * @param y The y position/dimension. - **/ - Vector(float x, float y); - - /** - * Gets the length of the Vector. - * @return The length of the Vector. - * - * This method requires sqrt() and should be used - * carefully. - **/ - float getLength() const; - - /** - * Normalizes the Vector. - * @return The old length of the Vector. - **/ - float normalize(); - - /** - * Gets a normal to the Vector. - * @return A normal to the Vector. - **/ - - Vector getNormal() const; - - /** - * Adds a Vector to this Vector. - * @param v The Vector we want to add to this Vector. - * @return The resulting Vector. - **/ - Vector operator + (const Vector & v) const; - - /** - * Substracts a Vector to this Vector. - * @param v The Vector we want to subtract to this Vector. - * @return The resulting Vector. - **/ - Vector operator - (const Vector & v) const; - - /** - * Resizes a Vector by a scalar. - * @param s The scalar with which to resize the Vector. - * @return The resulting Vector. - **/ - Vector operator * (float s) const; - - /** - * Resizes a Vector by a scalar. - * @param s The scalar with which to resize the Vector. - * @return The resulting Vector. - **/ - Vector operator / (float s) const; - - /** - * Reverses the Vector. - * @return The reversed Vector. - **/ - Vector operator - () const; - - /** - * Adds a Vector to this Vector, and also saves changes in the first Vector. - * @param v The Vector we want to add to this Vector. - **/ - void operator += (const Vector & v); - - /** - * Subtracts a Vector to this Vector, and also saves changes in the first Vector. - * @param v The Vector we want to subtract to this Vector. - **/ - void operator -= (const Vector & v); - - /** - * Resizes the Vector, and also saves changes in the first Vector. - * @param s The scalar by which we want to resize the Vector. - **/ - void operator *= (float s); - - /** - * Resizes the Vector, and also saves changes in the first Vector. - * @param s The scalar by which we want to resize the Vector. - **/ - void operator /= (float s); - - /** - * Calculates the dot product of two Vectors. - * @return The dot product of the two Vectors. - **/ - float operator * (const Vector & v) const; - - /** - * Calculates the cross product of two Vectors. - * @return The cross product of the two Vectors. - **/ - float operator ^ (const Vector & v) const; - - bool operator == (const Vector & v) const; - - bool operator < (const Vector & v) const; - /** - * Gets the x value of the Vector. - * @return The x value of the Vector. - **/ - float getX() const; - - /** - * Gets the x value of the Vector. - * @return The x value of the Vector. - **/ - float getY() const; - - /** - * Sets the x value of the Vector. - * @param The x value of the Vector. - **/ - void setX(float x); - - /** - * Sets the x value of the Vector. - * @param The x value of the Vector. - **/ - void setY(float y); - - }; - - inline float Vector::getLength() const - { - return sqrt(x*x + y*y); - } - - inline Vector Vector::getNormal() const - { - return Vector(-y, x); - } - - inline float Vector::normalize() - { - - float len = getLength(); - - if(len > 0) - (*this) /= len; - - return len; - } - - /** - * Inline methods must have body in header. - **/ - - inline Vector::Vector() - { - x = 1; - y = 1; - } - - inline Vector::Vector(float x, float y) - { - this->x = x; - this->y = y; - } - - inline Vector Vector::operator + (const Vector & v) const - { - return Vector(x + v.x, y + v.y); - } - - inline Vector Vector::operator - (const Vector & v) const - { - return Vector(x - v.getX(), y - v.getY()); - } - - inline Vector Vector::operator * (float s) const - { - return Vector(x*s, y*s); - } - - inline Vector Vector::operator / (float s) const - { - return Vector(x/s, y/s); - } - - inline Vector Vector::operator - () const - { - return Vector(-x, -y); - } - - inline void Vector::operator += (const Vector & v) - { - x += v.getX(); - y += v.getY(); - } - - inline void Vector::operator -= (const Vector & v) - { - x -= v.getX(); - y -= v.getY(); - } - - inline void Vector::operator *= (float s) - { - x *= s; - y *= s; - } - - inline void Vector::operator /= (float s) - { - x /= s; - y /= s; - } - - inline float Vector::operator * (const Vector & v) const - { - return x * v.getX() + y * v.getY(); - } - - inline float Vector::operator ^ (const Vector & v) const - { - return x * v.getY() - y * v.getX(); - } - - inline bool Vector::operator == (const Vector & v) const - { - return getLength() == v.getLength(); - } - - inline bool Vector::operator < (const Vector & v) const - { - return getLength() < v.getLength(); - } - - /** - * Accessor methods - **/ - - inline float Vector::getX() const - { - return x; - } - - inline float Vector::getY() const - { - return y; - } - - inline void Vector::setX(float x) - { - this->x = x; - } - - inline void Vector::setY(float y) - { - this->y = y; - } - -} //love - -#endif// LOVE_VECTOR_H +/** +* Copyright (c) 2006-2011 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#ifndef LOVE_VECTOR_H +#define LOVE_VECTOR_H + +// STD +#include + +// LOVE +#include "Matrix.h" + +namespace love +{ + /** + * 2D Vector class. + * + * @author Anders Ruud + * @date 2006-05-13 + **/ + class Vector + { + public: + + // The components. + float x, y; + + /** + * Creates a new (1,1) Vector. + **/ + Vector(); + + /** + * Creates a new Vector. + * @param x The x position/dimension. + * @param y The y position/dimension. + **/ + Vector(float x, float y); + + /** + * Gets the length of the Vector. + * @return The length of the Vector. + * + * This method requires sqrt() and should be used + * carefully. + **/ + float getLength() const; + + /** + * Normalizes the Vector. + * @return The old length of the Vector. + **/ + float normalize(); + + /** + * Gets a normal to the Vector. + * @return A normal to the Vector. + **/ + + Vector getNormal() const; + + /** + * Adds a Vector to this Vector. + * @param v The Vector we want to add to this Vector. + * @return The resulting Vector. + **/ + Vector operator + (const Vector & v) const; + + /** + * Substracts a Vector to this Vector. + * @param v The Vector we want to subtract to this Vector. + * @return The resulting Vector. + **/ + Vector operator - (const Vector & v) const; + + /** + * Resizes a Vector by a scalar. + * @param s The scalar with which to resize the Vector. + * @return The resulting Vector. + **/ + Vector operator * (float s) const; + + /** + * Resizes a Vector by a scalar. + * @param s The scalar with which to resize the Vector. + * @return The resulting Vector. + **/ + Vector operator / (float s) const; + + /** + * Reverses the Vector. + * @return The reversed Vector. + **/ + Vector operator - () const; + + /** + * Adds a Vector to this Vector, and also saves changes in the first Vector. + * @param v The Vector we want to add to this Vector. + **/ + void operator += (const Vector & v); + + /** + * Subtracts a Vector to this Vector, and also saves changes in the first Vector. + * @param v The Vector we want to subtract to this Vector. + **/ + void operator -= (const Vector & v); + + /** + * Resizes the Vector, and also saves changes in the first Vector. + * @param s The scalar by which we want to resize the Vector. + **/ + void operator *= (float s); + + /** + * Resizes the Vector, and also saves changes in the first Vector. + * @param s The scalar by which we want to resize the Vector. + **/ + void operator /= (float s); + + /** + * Calculates the dot product of two Vectors. + * @return The dot product of the two Vectors. + **/ + float operator * (const Vector & v) const; + + /** + * Calculates the cross product of two Vectors. + * @return The cross product of the two Vectors. + **/ + float operator ^ (const Vector & v) const; + + bool operator == (const Vector & v) const; + + bool operator < (const Vector & v) const; + /** + * Gets the x value of the Vector. + * @return The x value of the Vector. + **/ + float getX() const; + + /** + * Gets the x value of the Vector. + * @return The x value of the Vector. + **/ + float getY() const; + + /** + * Sets the x value of the Vector. + * @param The x value of the Vector. + **/ + void setX(float x); + + /** + * Sets the x value of the Vector. + * @param The x value of the Vector. + **/ + void setY(float y); + + }; + + inline float Vector::getLength() const + { + return sqrt(x*x + y*y); + } + + inline Vector Vector::getNormal() const + { + return Vector(-y, x); + } + + inline float Vector::normalize() + { + + float len = getLength(); + + if (len > 0) + (*this) /= len; + + return len; + } + + /** + * Inline methods must have body in header. + **/ + + inline Vector::Vector() + { + x = 1; + y = 1; + } + + inline Vector::Vector(float x, float y) + { + this->x = x; + this->y = y; + } + + inline Vector Vector::operator + (const Vector & v) const + { + return Vector(x + v.x, y + v.y); + } + + inline Vector Vector::operator - (const Vector & v) const + { + return Vector(x - v.getX(), y - v.getY()); + } + + inline Vector Vector::operator * (float s) const + { + return Vector(x*s, y*s); + } + + inline Vector Vector::operator / (float s) const + { + return Vector(x/s, y/s); + } + + inline Vector Vector::operator - () const + { + return Vector(-x, -y); + } + + inline void Vector::operator += (const Vector & v) + { + x += v.getX(); + y += v.getY(); + } + + inline void Vector::operator -= (const Vector & v) + { + x -= v.getX(); + y -= v.getY(); + } + + inline void Vector::operator *= (float s) + { + x *= s; + y *= s; + } + + inline void Vector::operator /= (float s) + { + x /= s; + y /= s; + } + + inline float Vector::operator * (const Vector & v) const + { + return x * v.getX() + y * v.getY(); + } + + inline float Vector::operator ^ (const Vector & v) const + { + return x * v.getY() - y * v.getX(); + } + + inline bool Vector::operator == (const Vector & v) const + { + return getLength() == v.getLength(); + } + + inline bool Vector::operator < (const Vector & v) const + { + return getLength() < v.getLength(); + } + + /** + * Accessor methods + **/ + + inline float Vector::getX() const + { + return x; + } + + inline float Vector::getY() const + { + return y; + } + + inline void Vector::setX(float x) + { + this->x = x; + } + + inline void Vector::setY(float y) + { + this->y = y; + } + +} //love + +#endif// LOVE_VECTOR_H diff --git a/src/common/b64.cpp b/src/common/b64.cpp index bf1dba11b..dadac9573 100644 --- a/src/common/b64.cpp +++ b/src/common/b64.cpp @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2011 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -25,7 +25,7 @@ namespace love static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq"; void b64_decode_block(char in[4], char out[3]) - { + { out[0] = (char)(in[0] << 2 | in[1] >> 4); out[1] = (char)(in[1] << 4 | in[2] >> 2); out[2] = (char)(((in[2] << 6) & 0xc0) | in[3]); @@ -41,33 +41,34 @@ namespace love char in[4], out[3], v; int i, len, pos = 0; - while(pos <= slen) + while (pos <= slen) { - for(len = 0, i = 0; i < 4 && pos <= slen; i++ ) + for (len = 0, i = 0; i < 4 && pos <= slen; i++ ) { v = 0; - while(pos <= slen && v == 0 ) + while (pos <= slen && v == 0 ) { v = src[pos++]; v = (char)((v < 43 || v > 122) ? 0 : cd64[v - 43]); - if(v) + if (v) v = (char)((v == '$') ? 0 : v - 61); } - if(pos <= slen) + if (pos <= slen) { len++; - if(v) + if (v) in[i] = (char)(v - 1); } else in[i] = 0; } - if(len) { + if (len) + { b64_decode_block(in, out); - for(i = 0; i < len - 1; i++) + for (i = 0; i < len - 1; i++) *(d++) = out[i]; } } diff --git a/src/common/b64.h b/src/common/b64.h index 7ccd8c049..3c47fdf38 100644 --- a/src/common/b64.h +++ b/src/common/b64.h @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2011 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be diff --git a/src/common/config.h b/src/common/config.h index ae35a6069..afb2d92ca 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2011 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be diff --git a/src/common/math.h b/src/common/math.h index 2ec22db5c..217d9cc48 100644 --- a/src/common/math.h +++ b/src/common/math.h @@ -1,85 +1,85 @@ -/** -* Copyright (c) 2006-2011 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#ifndef LOVE_MATH_H -#define LOVE_MATH_H - -#include // for CHAR_BIT - -/* Definitions of useful mathematical constants - * M_E - e - * M_LOG2E - log2(e) - * M_LOG10E - log10(e) - * M_LN2 - ln(2) - * M_LN10 - ln(10) - * M_PI - pi - * M_PI_2 - pi/2 - * M_PI_4 - pi/4 - * M_1_PI - 1/pi - * M_2_PI - 2/pi - * M_2_SQRTPI - 2/sqrt(pi) - * M_SQRT2 - sqrt(2) - * M_SQRT1_2 - 1/sqrt(2) - */ - -#define LOVE_M_E 2.71828182845904523536 -#define LOVE_M_LOG2E 1.44269504088896340736 -#define LOVE_M_LOG10E 0.434294481903251827651 -#define LOVE_M_LN2 0.693147180559945309417 -#define LOVE_M_LN10 2.30258509299404568402 -#define LOVE_M_PI 3.14159265358979323846 -#define LOVE_M_PI_2 1.57079632679489661923 -#define LOVE_M_PI_4 0.785398163397448309616 -#define LOVE_M_1_PI 0.318309886183790671538 -#define LOVE_M_2_PI 0.636619772367581343076 -#define LOVE_M_2_SQRTPI 1.12837916709551257390 -#define LOVE_M_SQRT2 1.41421356237309504880 -#define LOVE_M_SQRT1_2 0.707106781186547524401 -#define LOVE_M_TORAD (float)(LOVE_M_PI/180.0) -#define LOVE_M_TODEG (float)(180.0/LOVE_M_PI) -#define LOVE_TORAD(x) (float)(x*LOVE_M_TORAD) -#define LOVE_TODEG(x) (float)(x*LOVE_M_TODEG) - -namespace love -{ - -struct vertex -{ - unsigned char r, g, b, a; - float x, y; - float s, t; -}; - -inline int next_p2(int x) -{ - x += (x == 0); - x--; - for (unsigned int i = 1; i < sizeof(int)*CHAR_BIT; i <<= 1) x |= x >> i; - return ++x; -} - -inline float next_p2(float x) -{ - return static_cast(next_p2(static_cast(x))); -} - -} // love - -#endif // LOVE_MATH_H +/** +* Copyright (c) 2006-2011 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#ifndef LOVE_MATH_H +#define LOVE_MATH_H + +#include // for CHAR_BIT + +/* Definitions of useful mathematical constants + * M_E - e + * M_LOG2E - log2(e) + * M_LOG10E - log10(e) + * M_LN2 - ln(2) + * M_LN10 - ln(10) + * M_PI - pi + * M_PI_2 - pi/2 + * M_PI_4 - pi/4 + * M_1_PI - 1/pi + * M_2_PI - 2/pi + * M_2_SQRTPI - 2/sqrt(pi) + * M_SQRT2 - sqrt(2) + * M_SQRT1_2 - 1/sqrt(2) + */ + +#define LOVE_M_E 2.71828182845904523536 +#define LOVE_M_LOG2E 1.44269504088896340736 +#define LOVE_M_LOG10E 0.434294481903251827651 +#define LOVE_M_LN2 0.693147180559945309417 +#define LOVE_M_LN10 2.30258509299404568402 +#define LOVE_M_PI 3.14159265358979323846 +#define LOVE_M_PI_2 1.57079632679489661923 +#define LOVE_M_PI_4 0.785398163397448309616 +#define LOVE_M_1_PI 0.318309886183790671538 +#define LOVE_M_2_PI 0.636619772367581343076 +#define LOVE_M_2_SQRTPI 1.12837916709551257390 +#define LOVE_M_SQRT2 1.41421356237309504880 +#define LOVE_M_SQRT1_2 0.707106781186547524401 +#define LOVE_M_TORAD (float)(LOVE_M_PI/180.0) +#define LOVE_M_TODEG (float)(180.0/LOVE_M_PI) +#define LOVE_TORAD(x) (float)(x*LOVE_M_TORAD) +#define LOVE_TODEG(x) (float)(x*LOVE_M_TODEG) + +namespace love +{ + +struct vertex +{ + unsigned char r, g, b, a; + float x, y; + float s, t; +}; + +inline int next_p2(int x) +{ + x += (x == 0); + x--; + for (unsigned int i = 1; i < sizeof(int)*CHAR_BIT; i <<= 1) x |= x >> i; + return ++x; +} + +inline float next_p2(float x) +{ + return static_cast(next_p2(static_cast(x))); +} + +} // love + +#endif // LOVE_MATH_H diff --git a/src/common/runtime.cpp b/src/common/runtime.cpp index 11838ea45..3bb7f29c6 100644 --- a/src/common/runtime.cpp +++ b/src/common/runtime.cpp @@ -1,474 +1,475 @@ -/** -* Copyright (c) 2006-2011 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#include "runtime.h" - -// LOVE -#include "Module.h" -#include "Object.h" -#include "Reference.h" -#include "StringMap.h" -#include - -// STD -#include - - -namespace love -{ - static thread::Mutex *gcmutex = 0; - void *_gcmutex = 0; - unsigned int _gcthread = 0; - /** - * Called when an object is collected. The object is released - * once in this function, possibly deleting it. - **/ - static int w__gc(lua_State * L) - { - if (!gcmutex) - { - gcmutex = new thread::Mutex(); - _gcmutex = (void*) gcmutex; - } - Proxy * p = (Proxy *)lua_touserdata(L, 1); - Object * t = (Object *)p->data; - if(p->own) - { - thread::Lock lock(gcmutex); - _gcthread = thread::ThreadBase::threadId(); - t->release(); - } - return 0; - } - - static int w__tostring(lua_State * L) - { - lua_pushvalue(L, lua_upvalueindex(1)); - return 1; - } - - static int w__typeOf(lua_State * L) - { - Proxy * p = (Proxy *)lua_touserdata(L, 1); - Type t = luax_type(L, 2); - luax_pushboolean(L, p->flags[t]); - return 1; - } - - static int w__eq(lua_State * L) - { - Proxy * p1 = (Proxy *)lua_touserdata(L, 1); - Proxy * p2 = (Proxy *)lua_touserdata(L, 2); - luax_pushboolean(L, p1->data == p2->data); - return 1; - } - - Reference * luax_refif(lua_State * L, int type) - { - Reference * r = 0; - - // Create a reference only if the test succeeds. - if(lua_type(L, -1) == type) - r = new Reference(L); - else // Pop the value even if it fails (but also if it succeeds). - lua_pop(L, 1); - - return r; - } - - void luax_printstack(lua_State * L) - { - for(int i = 1;i<=lua_gettop(L);i++) - { - std::cout << i << " - " << luaL_typename(L, i) << std::endl; - } - } - - bool luax_toboolean(lua_State * L, int idx) - { - return (lua_toboolean(L, idx) != 0); - } - - void luax_pushboolean(lua_State * L, bool b) - { - lua_pushboolean(L, b ? 1 : 0); - } - - bool luax_optboolean(lua_State * L, int idx, bool b) - { - if(lua_isboolean(L, idx) == 1) - return (lua_toboolean(L, idx) == 1 ? true : false); - return b; - } - - std::string luax_checkstring(lua_State * L, int idx) - { - size_t len; - const char * str = luaL_checklstring(L, idx, &len); - return std::string(str, len); - } - - void luax_pushstring(lua_State * L, std::string str) - { - lua_pushlstring(L, str.data(), str.size()); - } - - int luax_assert_argc(lua_State * L, int min) - { - int argc = lua_gettop(L); - if( argc < min ) - return luaL_error(L, "Incorrect number of arguments. Got [%d], expected at least [%d]", argc, min); - return 0; - } - - int luax_assert_argc(lua_State * L, int min, int max) - { - int argc = lua_gettop(L); - if( argc < min || argc > max) - return luaL_error(L, "Incorrect number of arguments. Got [%d], expected [%d-%d]", argc, min, max); - return 0; - } - - int luax_assert_function(lua_State * L, int n) - { - if(!lua_isfunction(L, n)) - return luaL_error(L, "Argument must be of type \"function\"."); - return 0; - } - - int luax_register_module(lua_State * L, const WrappedModule & m) - { - // Put a reference to the C++ module in Lua. - luax_getregistry(L, REGISTRY_MODULES); - - Proxy * p = (Proxy *)lua_newuserdata(L, sizeof(Proxy)); - p->own = true; - p->data = m.module; - p->flags = m.flags; - - luaL_newmetatable(L, m.module->getName()); - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - lua_pushcfunction(L, w__gc); - lua_setfield(L, -2, "__gc"); - - lua_setmetatable(L, -2); - lua_setfield(L, -2, m.name); // _modules[name] = proxy - lua_pop(L, 1); - - // Gets the love table. - luax_insistglobal(L, "love"); - - // Create new table for module. - lua_newtable(L); - - // Register all the functions. - luaL_register(L, 0, m.functions); - - // Register types. - if(m.types != 0) - for(const lua_CFunction * t = m.types; *t != 0; t++) - (*t)(L); - - lua_setfield(L, -2, m.name); // love.graphics = table - lua_pop(L, 1); // love - - return 0; - } - - int luax_preload(lua_State * L, lua_CFunction f, const char * name) - { - lua_getglobal(L, "package"); - lua_getfield(L, -1, "preload"); - lua_pushcfunction(L, f); - lua_setfield(L, -2, name); - lua_pop(L, 2); - return 0; - } - - int luax_register_type(lua_State * L, const char * tname, const luaL_Reg * f) - { - luaL_newmetatable(L, tname); - - // m.__index = m - lua_pushvalue(L, -1); - lua_setfield(L, -2, "__index"); - - // setup gc - lua_pushcfunction(L, w__gc); - lua_setfield(L, -2, "__gc"); - - // Add equality - lua_pushcfunction(L, w__eq); - lua_setfield(L, -2, "__eq"); - - // Add tostring function. - lua_pushstring(L, tname); - lua_pushcclosure(L, w__tostring, 1); - lua_setfield(L, -2, "__tostring"); - - // Add tostring to as type() as well. - lua_pushstring(L, tname); - lua_pushcclosure(L, w__tostring, 1); - lua_setfield(L, -2, "type"); - - // Add typeOf - lua_pushcfunction(L, w__typeOf); - lua_setfield(L, -2, "typeOf"); - - if(f != 0) - luaL_register(L, 0, f); - - lua_pop(L, 1); // Pops metatable. - return 0; - } - - int luax_table_insert(lua_State * L, int tindex, int vindex, int pos) - { - if (tindex < 0) - tindex = lua_gettop(L)+1+tindex; - if (vindex < 0) - vindex = lua_gettop(L)+1+vindex; - if (pos == -1) - { - lua_pushvalue(L, vindex); - lua_rawseti(L, tindex, lua_objlen(L, tindex)+1); - return 0; - } - else if (pos < 0) - pos = lua_objlen(L, tindex)+1+pos; - for (int i = lua_objlen(L, tindex)+1; i > pos; i--) - { - lua_rawgeti(L, tindex, i-1); - lua_rawseti(L, tindex, i); - } - lua_pushvalue(L, vindex); - lua_rawseti(L, tindex, pos); - return 0; - } - - int luax_register_searcher(lua_State * L, lua_CFunction f, int pos) - { - // Add the package loader to the package.loaders table. - lua_getglobal(L, "package"); - - if(lua_isnil(L, -1)) - return luaL_error(L, "Can't register searcher: package table does not exist."); - - lua_getfield(L, -1, "loaders"); - - if(lua_isnil(L, -1)) - return luaL_error(L, "Can't register searcher: package.loaders table does not exist."); - - lua_pushcfunction(L, f); - luax_table_insert(L, -2, -1, pos); - lua_pop(L, 3); - return 0; - } - - void luax_newtype(lua_State * L, const char * name, bits flags, void * data, bool own) - { - Proxy * u = (Proxy *)lua_newuserdata(L, sizeof(Proxy)); - - u->data = data; - u->flags = flags; - u->own = own; - - luaL_newmetatable(L, name); - lua_setmetatable(L, -2); - } - - bool luax_istype(lua_State * L, int idx, love::bits type) - { - if(lua_isuserdata(L, idx) == 0) - return false; - - return ((((Proxy *)lua_touserdata(L, idx))->flags & type) == type); - } - - int luax_getfunction(lua_State * L, const char * mod, const char * fn) - { - lua_getglobal(L, "love"); - if(lua_isnil(L, -1)) return luaL_error(L, "Could not find global love!"); - lua_getfield(L, -1, mod); - if(lua_isnil(L, -1)) return luaL_error(L, "Could not find love.%s!", mod); - lua_getfield(L, -1, fn); - if(lua_isnil(L, -1)) return luaL_error(L, "Could not find love.%s.%s!", mod, fn); - - lua_remove(L, -2); // remove mod - lua_remove(L, -2); // remove fn - return 0; - } - - int luax_convobj(lua_State * L, int idx, const char * mod, const char * fn) - { - // Convert string to a file. - luax_getfunction(L, mod, fn); - lua_pushvalue(L, idx); // The initial argument. - lua_call(L, 1, 1); // Call the function, one arg, one return value. - lua_replace(L, idx); // Replace the initial argument with the new object. - return 0; - } - - int luax_convobj(lua_State * L, int idxs[], int n, const char * mod, const char * fn) - { - luax_getfunction(L, mod, fn); - for (int i = 0; i < n; i++) { - lua_pushvalue(L, idxs[i]); // The arguments. - } - lua_call(L, n, 1); // Call the function, n args, one return value. - lua_replace(L, idxs[0]); // Replace the initial argument with the new object. - return 0; - } - - int luax_strtofile(lua_State * L, int idx) - { - return luax_convobj(L, idx, "filesystem", "newFile"); - } - - int luax_filetodata(lua_State * L, int idx) - { - return luax_convobj(L, idx, "filesystem", "read"); - } - - int luax_insist(lua_State * L, int idx, const char * k) - { - lua_getfield(L, idx, k); - - // Create if necessary. - if(!lua_istable(L, -1)) - { - lua_pop(L, 1); // Pop the non-table. - lua_newtable(L); - lua_pushvalue(L, -1); // Duplicate the table to leave on top. - lua_setfield(L, -3, k); // k[idx] = table - } - - return 1; - } - - int luax_insistglobal(lua_State * L, const char * k) - { - lua_getglobal(L, k); - - if(!lua_istable(L, -1)) - { - lua_pop(L, 1); // Pop the non-table. - lua_newtable(L); - lua_pushvalue(L, -1); - lua_setglobal(L, k); - } - - return 1; - } - - int luax_insistlove(lua_State * L, const char * k) - { - luax_insistglobal(L, "love"); - luax_insist(L, -1, k); - - // The love table should be replaced with the top stack - // item. Only the reqested table should remain on the stack. - lua_replace(L, -2); - - return 1; - } - - int luax_getregistry(lua_State * L, Registry r) - { - switch(r) - { - case REGISTRY_GC: - return luax_insistlove(L, "_gc"); - case REGISTRY_MODULES: - return luax_insistlove(L, "_modules"); - default: - return luaL_error(L, "Attempted to use invalid registry."); - } - } - - StringMap::Entry typeEntries[] = - { - {"Invalid", INVALID_ID}, - - {"Object", OBJECT_ID}, - {"Data", DATA_ID}, - {"Module", MODULE_ID}, - - // Filesystem - {"File", FILESYSTEM_FILE_ID}, - {"FileData", FILESYSTEM_FILE_DATA_ID}, - - // Font - {"GlyphData", FONT_GLYPH_DATA_ID}, - {"Rasterizer", FONT_RASTERIZER_ID}, - - // Graphics - {"Drawable", GRAPHICS_DRAWABLE_ID}, - {"Image", GRAPHICS_IMAGE_ID}, - {"Quad", GRAPHICS_QUAD_ID}, - {"Font", GRAPHICS_FONT_ID}, - {"ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_ID}, - {"SpriteBatch", GRAPHICS_SPRITE_BATCH_ID}, - {"Canvas", GRAPHICS_CANVAS_ID}, - - // Image - {"ImageData", IMAGE_IMAGE_DATA_ID}, - - // Audio - {"Source", AUDIO_SOURCE_ID}, - - // Sound - {"SoundData", SOUND_SOUND_DATA_ID}, - {"Decoder", SOUND_DECODER_ID}, - - // Physics - {"World", PHYSICS_WORLD_ID}, - {"Contact", PHYSICS_CONTACT_ID}, - {"Body", PHYSICS_BODY_ID}, - {"Shape", PHYSICS_SHAPE_ID}, - {"CircleShape", PHYSICS_CIRCLE_SHAPE_ID}, - {"PolygonShape", PHYSICS_POLYGON_SHAPE_ID}, - {"Joint", PHYSICS_JOINT_ID}, - {"MouseJoint", PHYSICS_MOUSE_JOINT_ID}, - {"DistanceJoint", PHYSICS_DISTANCE_JOINT_ID}, - {"PrismaticJoint", PHYSICS_PRISMATIC_JOINT_ID}, - {"RevoluteJoint", PHYSICS_REVOLUTE_JOINT_ID}, - {"PulleyJoint", PHYSICS_PULLEY_JOINT_ID}, - {"GearJoint", PHYSICS_GEAR_JOINT_ID}, - - // Thread - {"Thread", THREAD_THREAD_ID}, - - // The modules themselves. Only add abstracted modules here. - {"filesystem", MODULE_FILESYSTEM_ID}, - {"image", MODULE_IMAGE_ID}, - {"sound", MODULE_SOUND_ID}, - }; - - StringMap types(typeEntries, sizeof(typeEntries)); - - Type luax_type(lua_State * L, int idx) - { - Type t = INVALID_ID; - types.find(luaL_checkstring(L, idx), t); - return t; - } -} // love +/** +* Copyright (c) 2006-2011 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#include "runtime.h" + +// LOVE +#include "Module.h" +#include "Object.h" +#include "Reference.h" +#include "StringMap.h" +#include + +// STD +#include + + +namespace love +{ + static thread::Mutex *gcmutex = 0; + void *_gcmutex = 0; + unsigned int _gcthread = 0; + /** + * Called when an object is collected. The object is released + * once in this function, possibly deleting it. + **/ + static int w__gc(lua_State * L) + { + if (!gcmutex) + { + gcmutex = new thread::Mutex(); + _gcmutex = (void*) gcmutex; + } + Proxy * p = (Proxy *)lua_touserdata(L, 1); + Object * t = (Object *)p->data; + if (p->own) + { + thread::Lock lock(gcmutex); + _gcthread = thread::ThreadBase::threadId(); + t->release(); + } + return 0; + } + + static int w__tostring(lua_State * L) + { + lua_pushvalue(L, lua_upvalueindex(1)); + return 1; + } + + static int w__typeOf(lua_State * L) + { + Proxy * p = (Proxy *)lua_touserdata(L, 1); + Type t = luax_type(L, 2); + luax_pushboolean(L, p->flags[t]); + return 1; + } + + static int w__eq(lua_State * L) + { + Proxy * p1 = (Proxy *)lua_touserdata(L, 1); + Proxy * p2 = (Proxy *)lua_touserdata(L, 2); + luax_pushboolean(L, p1->data == p2->data); + return 1; + } + + Reference * luax_refif(lua_State * L, int type) + { + Reference * r = 0; + + // Create a reference only if the test succeeds. + if (lua_type(L, -1) == type) + r = new Reference(L); + else // Pop the value even if it fails (but also if it succeeds). + lua_pop(L, 1); + + return r; + } + + void luax_printstack(lua_State * L) + { + for (int i = 1;i<=lua_gettop(L);i++) + { + std::cout << i << " - " << luaL_typename(L, i) << std::endl; + } + } + + bool luax_toboolean(lua_State * L, int idx) + { + return (lua_toboolean(L, idx) != 0); + } + + void luax_pushboolean(lua_State * L, bool b) + { + lua_pushboolean(L, b ? 1 : 0); + } + + bool luax_optboolean(lua_State * L, int idx, bool b) + { + if (lua_isboolean(L, idx) == 1) + return (lua_toboolean(L, idx) == 1 ? true : false); + return b; + } + + std::string luax_checkstring(lua_State * L, int idx) + { + size_t len; + const char * str = luaL_checklstring(L, idx, &len); + return std::string(str, len); + } + + void luax_pushstring(lua_State * L, std::string str) + { + lua_pushlstring(L, str.data(), str.size()); + } + + int luax_assert_argc(lua_State * L, int min) + { + int argc = lua_gettop(L); + if ( argc < min ) + return luaL_error(L, "Incorrect number of arguments. Got [%d], expected at least [%d]", argc, min); + return 0; + } + + int luax_assert_argc(lua_State * L, int min, int max) + { + int argc = lua_gettop(L); + if ( argc < min || argc > max) + return luaL_error(L, "Incorrect number of arguments. Got [%d], expected [%d-%d]", argc, min, max); + return 0; + } + + int luax_assert_function(lua_State * L, int n) + { + if (!lua_isfunction(L, n)) + return luaL_error(L, "Argument must be of type \"function\"."); + return 0; + } + + int luax_register_module(lua_State * L, const WrappedModule & m) + { + // Put a reference to the C++ module in Lua. + luax_getregistry(L, REGISTRY_MODULES); + + Proxy * p = (Proxy *)lua_newuserdata(L, sizeof(Proxy)); + p->own = true; + p->data = m.module; + p->flags = m.flags; + + luaL_newmetatable(L, m.module->getName()); + lua_pushvalue(L, -1); + lua_setfield(L, -2, "__index"); + lua_pushcfunction(L, w__gc); + lua_setfield(L, -2, "__gc"); + + lua_setmetatable(L, -2); + lua_setfield(L, -2, m.name); // _modules[name] = proxy + lua_pop(L, 1); + + // Gets the love table. + luax_insistglobal(L, "love"); + + // Create new table for module. + lua_newtable(L); + + // Register all the functions. + luaL_register(L, 0, m.functions); + + // Register types. + if (m.types != 0) + for (const lua_CFunction * t = m.types; *t != 0; t++) + (*t)(L); + + lua_setfield(L, -2, m.name); // love.graphics = table + lua_pop(L, 1); // love + + return 0; + } + + int luax_preload(lua_State * L, lua_CFunction f, const char * name) + { + lua_getglobal(L, "package"); + lua_getfield(L, -1, "preload"); + lua_pushcfunction(L, f); + lua_setfield(L, -2, name); + lua_pop(L, 2); + return 0; + } + + int luax_register_type(lua_State * L, const char * tname, const luaL_Reg * f) + { + luaL_newmetatable(L, tname); + + // m.__index = m + lua_pushvalue(L, -1); + lua_setfield(L, -2, "__index"); + + // setup gc + lua_pushcfunction(L, w__gc); + lua_setfield(L, -2, "__gc"); + + // Add equality + lua_pushcfunction(L, w__eq); + lua_setfield(L, -2, "__eq"); + + // Add tostring function. + lua_pushstring(L, tname); + lua_pushcclosure(L, w__tostring, 1); + lua_setfield(L, -2, "__tostring"); + + // Add tostring to as type() as well. + lua_pushstring(L, tname); + lua_pushcclosure(L, w__tostring, 1); + lua_setfield(L, -2, "type"); + + // Add typeOf + lua_pushcfunction(L, w__typeOf); + lua_setfield(L, -2, "typeOf"); + + if (f != 0) + luaL_register(L, 0, f); + + lua_pop(L, 1); // Pops metatable. + return 0; + } + + int luax_table_insert(lua_State * L, int tindex, int vindex, int pos) + { + if (tindex < 0) + tindex = lua_gettop(L)+1+tindex; + if (vindex < 0) + vindex = lua_gettop(L)+1+vindex; + if (pos == -1) + { + lua_pushvalue(L, vindex); + lua_rawseti(L, tindex, lua_objlen(L, tindex)+1); + return 0; + } + else if (pos < 0) + pos = lua_objlen(L, tindex)+1+pos; + for (int i = lua_objlen(L, tindex)+1; i > pos; i--) + { + lua_rawgeti(L, tindex, i-1); + lua_rawseti(L, tindex, i); + } + lua_pushvalue(L, vindex); + lua_rawseti(L, tindex, pos); + return 0; + } + + int luax_register_searcher(lua_State * L, lua_CFunction f, int pos) + { + // Add the package loader to the package.loaders table. + lua_getglobal(L, "package"); + + if (lua_isnil(L, -1)) + return luaL_error(L, "Can't register searcher: package table does not exist."); + + lua_getfield(L, -1, "loaders"); + + if (lua_isnil(L, -1)) + return luaL_error(L, "Can't register searcher: package.loaders table does not exist."); + + lua_pushcfunction(L, f); + luax_table_insert(L, -2, -1, pos); + lua_pop(L, 3); + return 0; + } + + void luax_newtype(lua_State * L, const char * name, bits flags, void * data, bool own) + { + Proxy * u = (Proxy *)lua_newuserdata(L, sizeof(Proxy)); + + u->data = data; + u->flags = flags; + u->own = own; + + luaL_newmetatable(L, name); + lua_setmetatable(L, -2); + } + + bool luax_istype(lua_State * L, int idx, love::bits type) + { + if (lua_isuserdata(L, idx) == 0) + return false; + + return ((((Proxy *)lua_touserdata(L, idx))->flags & type) == type); + } + + int luax_getfunction(lua_State * L, const char * mod, const char * fn) + { + lua_getglobal(L, "love"); + if (lua_isnil(L, -1)) return luaL_error(L, "Could not find global love!"); + lua_getfield(L, -1, mod); + if (lua_isnil(L, -1)) return luaL_error(L, "Could not find love.%s!", mod); + lua_getfield(L, -1, fn); + if (lua_isnil(L, -1)) return luaL_error(L, "Could not find love.%s.%s!", mod, fn); + + lua_remove(L, -2); // remove mod + lua_remove(L, -2); // remove fn + return 0; + } + + int luax_convobj(lua_State * L, int idx, const char * mod, const char * fn) + { + // Convert string to a file. + luax_getfunction(L, mod, fn); + lua_pushvalue(L, idx); // The initial argument. + lua_call(L, 1, 1); // Call the function, one arg, one return value. + lua_replace(L, idx); // Replace the initial argument with the new object. + return 0; + } + + int luax_convobj(lua_State * L, int idxs[], int n, const char * mod, const char * fn) + { + luax_getfunction(L, mod, fn); + for (int i = 0; i < n; i++) + { + lua_pushvalue(L, idxs[i]); // The arguments. + } + lua_call(L, n, 1); // Call the function, n args, one return value. + lua_replace(L, idxs[0]); // Replace the initial argument with the new object. + return 0; + } + + int luax_strtofile(lua_State * L, int idx) + { + return luax_convobj(L, idx, "filesystem", "newFile"); + } + + int luax_filetodata(lua_State * L, int idx) + { + return luax_convobj(L, idx, "filesystem", "read"); + } + + int luax_insist(lua_State * L, int idx, const char * k) + { + lua_getfield(L, idx, k); + + // Create if necessary. + if (!lua_istable(L, -1)) + { + lua_pop(L, 1); // Pop the non-table. + lua_newtable(L); + lua_pushvalue(L, -1); // Duplicate the table to leave on top. + lua_setfield(L, -3, k); // k[idx] = table + } + + return 1; + } + + int luax_insistglobal(lua_State * L, const char * k) + { + lua_getglobal(L, k); + + if (!lua_istable(L, -1)) + { + lua_pop(L, 1); // Pop the non-table. + lua_newtable(L); + lua_pushvalue(L, -1); + lua_setglobal(L, k); + } + + return 1; + } + + int luax_insistlove(lua_State * L, const char * k) + { + luax_insistglobal(L, "love"); + luax_insist(L, -1, k); + + // The love table should be replaced with the top stack + // item. Only the reqested table should remain on the stack. + lua_replace(L, -2); + + return 1; + } + + int luax_getregistry(lua_State * L, Registry r) + { + switch(r) + { + case REGISTRY_GC: + return luax_insistlove(L, "_gc"); + case REGISTRY_MODULES: + return luax_insistlove(L, "_modules"); + default: + return luaL_error(L, "Attempted to use invalid registry."); + } + } + + StringMap::Entry typeEntries[] = + { + {"Invalid", INVALID_ID}, + + {"Object", OBJECT_ID}, + {"Data", DATA_ID}, + {"Module", MODULE_ID}, + + // Filesystem + {"File", FILESYSTEM_FILE_ID}, + {"FileData", FILESYSTEM_FILE_DATA_ID}, + + // Font + {"GlyphData", FONT_GLYPH_DATA_ID}, + {"Rasterizer", FONT_RASTERIZER_ID}, + + // Graphics + {"Drawable", GRAPHICS_DRAWABLE_ID}, + {"Image", GRAPHICS_IMAGE_ID}, + {"Quad", GRAPHICS_QUAD_ID}, + {"Font", GRAPHICS_FONT_ID}, + {"ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_ID}, + {"SpriteBatch", GRAPHICS_SPRITE_BATCH_ID}, + {"Canvas", GRAPHICS_CANVAS_ID}, + + // Image + {"ImageData", IMAGE_IMAGE_DATA_ID}, + + // Audio + {"Source", AUDIO_SOURCE_ID}, + + // Sound + {"SoundData", SOUND_SOUND_DATA_ID}, + {"Decoder", SOUND_DECODER_ID}, + + // Physics + {"World", PHYSICS_WORLD_ID}, + {"Contact", PHYSICS_CONTACT_ID}, + {"Body", PHYSICS_BODY_ID}, + {"Shape", PHYSICS_SHAPE_ID}, + {"CircleShape", PHYSICS_CIRCLE_SHAPE_ID}, + {"PolygonShape", PHYSICS_POLYGON_SHAPE_ID}, + {"Joint", PHYSICS_JOINT_ID}, + {"MouseJoint", PHYSICS_MOUSE_JOINT_ID}, + {"DistanceJoint", PHYSICS_DISTANCE_JOINT_ID}, + {"PrismaticJoint", PHYSICS_PRISMATIC_JOINT_ID}, + {"RevoluteJoint", PHYSICS_REVOLUTE_JOINT_ID}, + {"PulleyJoint", PHYSICS_PULLEY_JOINT_ID}, + {"GearJoint", PHYSICS_GEAR_JOINT_ID}, + + // Thread + {"Thread", THREAD_THREAD_ID}, + + // The modules themselves. Only add abstracted modules here. + {"filesystem", MODULE_FILESYSTEM_ID}, + {"image", MODULE_IMAGE_ID}, + {"sound", MODULE_SOUND_ID}, + }; + + StringMap types(typeEntries, sizeof(typeEntries)); + + Type luax_type(lua_State * L, int idx) + { + Type t = INVALID_ID; + types.find(luaL_checkstring(L, idx), t); + return t; + } +} // love diff --git a/src/common/runtime.h b/src/common/runtime.h index 837943349..33dcb9bdb 100644 --- a/src/common/runtime.h +++ b/src/common/runtime.h @@ -147,7 +147,7 @@ namespace love * @param str The string to push. **/ void luax_pushstring(lua_State * L, std::string str); - + /** * Require at least 'min' number of items on the stack. * @param L The Lua state. @@ -348,12 +348,12 @@ namespace love template T * luax_checktype(lua_State * L, int idx, const char * name, love::bits type) { - if(lua_isuserdata(L, idx) == 0) + if (lua_isuserdata(L, idx) == 0) luaL_error(L, "Incorrect parameter type: expected userdata."); Proxy * u = (Proxy *)lua_touserdata(L, idx); - if((u->flags & type) != type) + if ((u->flags & type) != type) luaL_error(L, "Incorrect parameter type: expected %s", name); return (T *)u->data; @@ -365,12 +365,12 @@ namespace love luax_getregistry(L, REGISTRY_MODULES); lua_getfield(L, -1, k); - if(!lua_isuserdata(L, -1)) + if (!lua_isuserdata(L, -1)) luaL_error(L, "Tried to get nonexisting module %s.", k); Proxy * u = (Proxy *)lua_touserdata(L, -1); - if((u->flags & type) != type) + if ((u->flags & type) != type) luaL_error(L, "Incorrect module %s", k); lua_pop(L, 2); diff --git a/src/common/types.h b/src/common/types.h index 446a0d5cb..208497c9d 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -1,173 +1,173 @@ -/** -* Copyright (c) 2006-2011 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#ifndef LOVE_TYPES_H -#define LOVE_TYPES_H - -// STD -#include - -namespace love -{ - enum Type - { - INVALID_ID = 0, - // Cross-module types. - OBJECT_ID, - DATA_ID, - MODULE_ID, - - // Filesystem. - FILESYSTEM_FILE_ID, - FILESYSTEM_FILE_DATA_ID, - - // Font - FONT_GLYPH_DATA_ID, - FONT_RASTERIZER_ID, - - // Graphics - GRAPHICS_DRAWABLE_ID, - GRAPHICS_DRAWQABLE_ID, - GRAPHICS_IMAGE_ID, - GRAPHICS_QUAD_ID, - GRAPHICS_FONT_ID, - GRAPHICS_PARTICLE_SYSTEM_ID, - GRAPHICS_SPRITE_BATCH_ID, - GRAPHICS_CANVAS_ID, - GRAPHICS_PIXELEFFECT_ID, - - // Image - IMAGE_IMAGE_DATA_ID, - IMAGE_ENCODED_IMAGE_DATA_ID, - - // Audio - AUDIO_SOURCE_ID, - - // Sound - SOUND_SOUND_DATA_ID, - SOUND_DECODER_ID, - - // Physics - PHYSICS_WORLD_ID, - PHYSICS_CONTACT_ID, - PHYSICS_BODY_ID, - PHYSICS_FIXTURE_ID, - PHYSICS_SHAPE_ID, - PHYSICS_CIRCLE_SHAPE_ID, - PHYSICS_POLYGON_SHAPE_ID, - PHYSICS_EDGE_SHAPE_ID, - PHYSICS_CHAIN_SHAPE_ID, - PHYSICS_JOINT_ID, - PHYSICS_MOUSE_JOINT_ID, - PHYSICS_DISTANCE_JOINT_ID, - PHYSICS_PRISMATIC_JOINT_ID, - PHYSICS_REVOLUTE_JOINT_ID, - PHYSICS_PULLEY_JOINT_ID, - PHYSICS_GEAR_JOINT_ID, - PHYSICS_FRICTION_JOINT_ID, - PHYSICS_WELD_JOINT_ID, - PHYSICS_ROPE_JOINT_ID, - PHYSICS_WHEEL_JOINT_ID, - - // Thread - THREAD_THREAD_ID, - - // The modules themselves. Only add abstracted modules here. - MODULE_FILESYSTEM_ID, - MODULE_IMAGE_ID, - MODULE_SOUND_ID, - - // Count the number of bits needed. - TYPE_MAX_ENUM - }; - - typedef std::bitset bits; - - const bits INVALID_T = bits(1) << INVALID_ID; - - const bits OBJECT_T = bits(1) << OBJECT_ID; - const bits DATA_T = (bits(1) << DATA_ID) | OBJECT_T; - const bits MODULE_T = (bits(1) << MODULE_ID) | OBJECT_T; - - // Filesystem. - const bits FILESYSTEM_FILE_T = (bits(1) << FILESYSTEM_FILE_ID) | OBJECT_T; - const bits FILESYSTEM_FILE_DATA_T = (bits(1) << FILESYSTEM_FILE_DATA_ID) | DATA_T; - - const bits FONT_GLYPH_DATA_T = (bits(1) << FONT_GLYPH_DATA_ID) | DATA_T; - const bits FONT_RASTERIZER_T = (bits(1) << FONT_RASTERIZER_ID) | OBJECT_T; - - // Graphics. - const bits GRAPHICS_DRAWABLE_T = (bits(1) << GRAPHICS_DRAWABLE_ID) | OBJECT_T; - const bits GRAPHICS_DRAWQABLE_T = (bits(1) << GRAPHICS_DRAWQABLE_ID) | GRAPHICS_DRAWABLE_T; - const bits GRAPHICS_IMAGE_T = (bits(1) << GRAPHICS_IMAGE_ID) | GRAPHICS_DRAWQABLE_T; - const bits GRAPHICS_QUAD_T = (bits(1) << GRAPHICS_QUAD_ID) | OBJECT_T; - const bits GRAPHICS_FONT_T = (bits(1) << GRAPHICS_FONT_ID) | OBJECT_T; - const bits GRAPHICS_PARTICLE_SYSTEM_T = (bits(1) << GRAPHICS_PARTICLE_SYSTEM_ID) | GRAPHICS_DRAWABLE_T; - const bits GRAPHICS_SPRITE_BATCH_T = (bits(1) << GRAPHICS_SPRITE_BATCH_ID) | GRAPHICS_DRAWABLE_T; - const bits GRAPHICS_CANVAS_T = (bits(1) << GRAPHICS_CANVAS_ID) | GRAPHICS_DRAWQABLE_T; - const bits GRAPHICS_PIXELEFFECT_T = (bits(1) << GRAPHICS_PIXELEFFECT_ID) | OBJECT_T; - - // Image. - const bits IMAGE_IMAGE_DATA_T = (bits(1) << IMAGE_IMAGE_DATA_ID) | DATA_T; - const bits IMAGE_ENCODED_IMAGE_DATA_T = (bits(1) << IMAGE_ENCODED_IMAGE_DATA_ID) | DATA_T; - - // Audio. - const bits AUDIO_SOURCE_T = (bits(1) << AUDIO_SOURCE_ID) | OBJECT_T; - - // Sound. - const bits SOUND_SOUND_DATA_T = (bits(1) << SOUND_SOUND_DATA_ID) | DATA_T; - const bits SOUND_DECODER_T = bits(1) << SOUND_DECODER_ID; - - // Physics. - const bits PHYSICS_WORLD_T = (bits(1) << PHYSICS_WORLD_ID) | OBJECT_T; - const bits PHYSICS_CONTACT_T = (bits(1) << PHYSICS_CONTACT_ID) | OBJECT_T; - const bits PHYSICS_BODY_T = (bits(1) << PHYSICS_BODY_ID) | OBJECT_T; - const bits PHYSICS_FIXTURE_T = (bits(1) << PHYSICS_FIXTURE_ID) | OBJECT_T; - const bits PHYSICS_SHAPE_T = (bits(1) << PHYSICS_SHAPE_ID) | OBJECT_T; - const bits PHYSICS_CIRCLE_SHAPE_T = (bits(1) << PHYSICS_CIRCLE_SHAPE_ID) | PHYSICS_SHAPE_T; - const bits PHYSICS_POLYGON_SHAPE_T = (bits(1) << PHYSICS_POLYGON_SHAPE_ID) | PHYSICS_SHAPE_T; - const bits PHYSICS_EDGE_SHAPE_T = (bits(1) << PHYSICS_EDGE_SHAPE_ID) | PHYSICS_SHAPE_T; - const bits PHYSICS_CHAIN_SHAPE_T = (bits(1) << PHYSICS_CHAIN_SHAPE_ID) | PHYSICS_SHAPE_T; - const bits PHYSICS_JOINT_T = (bits(1) << PHYSICS_JOINT_ID) | OBJECT_T; - const bits PHYSICS_MOUSE_JOINT_T = (bits(1) << PHYSICS_MOUSE_JOINT_ID) | PHYSICS_JOINT_T; - const bits PHYSICS_DISTANCE_JOINT_T = (bits(1) << PHYSICS_DISTANCE_JOINT_ID) | PHYSICS_JOINT_T; - const bits PHYSICS_PRISMATIC_JOINT_T = (bits(1) << PHYSICS_PRISMATIC_JOINT_ID) | PHYSICS_JOINT_T; - const bits PHYSICS_REVOLUTE_JOINT_T = (bits(1) << PHYSICS_REVOLUTE_JOINT_ID) | PHYSICS_JOINT_T; - const bits PHYSICS_PULLEY_JOINT_T = (bits(1) << PHYSICS_PULLEY_JOINT_ID) | PHYSICS_JOINT_T; - const bits PHYSICS_GEAR_JOINT_T = (bits(1) << PHYSICS_GEAR_JOINT_ID) | PHYSICS_JOINT_T; - const bits PHYSICS_FRICTION_JOINT_T = (bits(1) << PHYSICS_FRICTION_JOINT_ID) | PHYSICS_JOINT_T; - const bits PHYSICS_WELD_JOINT_T = (bits(1) << PHYSICS_WELD_JOINT_ID) | PHYSICS_JOINT_T; - const bits PHYSICS_ROPE_JOINT_T = (bits(1) << PHYSICS_ROPE_JOINT_ID) | PHYSICS_JOINT_T; - const bits PHYSICS_WHEEL_JOINT_T = (bits(1) << PHYSICS_WHEEL_JOINT_ID) | PHYSICS_JOINT_T; - - // Thread. - const bits THREAD_THREAD_T = (bits(1) << THREAD_THREAD_ID) | OBJECT_T; - - // Modules. - const bits MODULE_FILESYSTEM_T = (bits(1) << MODULE_FILESYSTEM_ID) | MODULE_T; - const bits MODULE_IMAGE_T = (bits(1) << MODULE_IMAGE_ID) | MODULE_T; - const bits MODULE_SOUND_T = (bits(1) << MODULE_SOUND_ID) | MODULE_T; - - bool getType(const char * in, Type & out); - bool getType(Type in, const char *& out); - -} // love - -#endif // LOVE_TYPES_H +/** +* Copyright (c) 2006-2011 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#ifndef LOVE_TYPES_H +#define LOVE_TYPES_H + +// STD +#include + +namespace love +{ + enum Type + { + INVALID_ID = 0, + // Cross-module types. + OBJECT_ID, + DATA_ID, + MODULE_ID, + + // Filesystem. + FILESYSTEM_FILE_ID, + FILESYSTEM_FILE_DATA_ID, + + // Font + FONT_GLYPH_DATA_ID, + FONT_RASTERIZER_ID, + + // Graphics + GRAPHICS_DRAWABLE_ID, + GRAPHICS_DRAWQABLE_ID, + GRAPHICS_IMAGE_ID, + GRAPHICS_QUAD_ID, + GRAPHICS_FONT_ID, + GRAPHICS_PARTICLE_SYSTEM_ID, + GRAPHICS_SPRITE_BATCH_ID, + GRAPHICS_CANVAS_ID, + GRAPHICS_PIXELEFFECT_ID, + + // Image + IMAGE_IMAGE_DATA_ID, + IMAGE_ENCODED_IMAGE_DATA_ID, + + // Audio + AUDIO_SOURCE_ID, + + // Sound + SOUND_SOUND_DATA_ID, + SOUND_DECODER_ID, + + // Physics + PHYSICS_WORLD_ID, + PHYSICS_CONTACT_ID, + PHYSICS_BODY_ID, + PHYSICS_FIXTURE_ID, + PHYSICS_SHAPE_ID, + PHYSICS_CIRCLE_SHAPE_ID, + PHYSICS_POLYGON_SHAPE_ID, + PHYSICS_EDGE_SHAPE_ID, + PHYSICS_CHAIN_SHAPE_ID, + PHYSICS_JOINT_ID, + PHYSICS_MOUSE_JOINT_ID, + PHYSICS_DISTANCE_JOINT_ID, + PHYSICS_PRISMATIC_JOINT_ID, + PHYSICS_REVOLUTE_JOINT_ID, + PHYSICS_PULLEY_JOINT_ID, + PHYSICS_GEAR_JOINT_ID, + PHYSICS_FRICTION_JOINT_ID, + PHYSICS_WELD_JOINT_ID, + PHYSICS_ROPE_JOINT_ID, + PHYSICS_WHEEL_JOINT_ID, + + // Thread + THREAD_THREAD_ID, + + // The modules themselves. Only add abstracted modules here. + MODULE_FILESYSTEM_ID, + MODULE_IMAGE_ID, + MODULE_SOUND_ID, + + // Count the number of bits needed. + TYPE_MAX_ENUM + }; + + typedef std::bitset bits; + + const bits INVALID_T = bits(1) << INVALID_ID; + + const bits OBJECT_T = bits(1) << OBJECT_ID; + const bits DATA_T = (bits(1) << DATA_ID) | OBJECT_T; + const bits MODULE_T = (bits(1) << MODULE_ID) | OBJECT_T; + + // Filesystem. + const bits FILESYSTEM_FILE_T = (bits(1) << FILESYSTEM_FILE_ID) | OBJECT_T; + const bits FILESYSTEM_FILE_DATA_T = (bits(1) << FILESYSTEM_FILE_DATA_ID) | DATA_T; + + const bits FONT_GLYPH_DATA_T = (bits(1) << FONT_GLYPH_DATA_ID) | DATA_T; + const bits FONT_RASTERIZER_T = (bits(1) << FONT_RASTERIZER_ID) | OBJECT_T; + + // Graphics. + const bits GRAPHICS_DRAWABLE_T = (bits(1) << GRAPHICS_DRAWABLE_ID) | OBJECT_T; + const bits GRAPHICS_DRAWQABLE_T = (bits(1) << GRAPHICS_DRAWQABLE_ID) | GRAPHICS_DRAWABLE_T; + const bits GRAPHICS_IMAGE_T = (bits(1) << GRAPHICS_IMAGE_ID) | GRAPHICS_DRAWQABLE_T; + const bits GRAPHICS_QUAD_T = (bits(1) << GRAPHICS_QUAD_ID) | OBJECT_T; + const bits GRAPHICS_FONT_T = (bits(1) << GRAPHICS_FONT_ID) | OBJECT_T; + const bits GRAPHICS_PARTICLE_SYSTEM_T = (bits(1) << GRAPHICS_PARTICLE_SYSTEM_ID) | GRAPHICS_DRAWABLE_T; + const bits GRAPHICS_SPRITE_BATCH_T = (bits(1) << GRAPHICS_SPRITE_BATCH_ID) | GRAPHICS_DRAWABLE_T; + const bits GRAPHICS_CANVAS_T = (bits(1) << GRAPHICS_CANVAS_ID) | GRAPHICS_DRAWQABLE_T; + const bits GRAPHICS_PIXELEFFECT_T = (bits(1) << GRAPHICS_PIXELEFFECT_ID) | OBJECT_T; + + // Image. + const bits IMAGE_IMAGE_DATA_T = (bits(1) << IMAGE_IMAGE_DATA_ID) | DATA_T; + const bits IMAGE_ENCODED_IMAGE_DATA_T = (bits(1) << IMAGE_ENCODED_IMAGE_DATA_ID) | DATA_T; + + // Audio. + const bits AUDIO_SOURCE_T = (bits(1) << AUDIO_SOURCE_ID) | OBJECT_T; + + // Sound. + const bits SOUND_SOUND_DATA_T = (bits(1) << SOUND_SOUND_DATA_ID) | DATA_T; + const bits SOUND_DECODER_T = bits(1) << SOUND_DECODER_ID; + + // Physics. + const bits PHYSICS_WORLD_T = (bits(1) << PHYSICS_WORLD_ID) | OBJECT_T; + const bits PHYSICS_CONTACT_T = (bits(1) << PHYSICS_CONTACT_ID) | OBJECT_T; + const bits PHYSICS_BODY_T = (bits(1) << PHYSICS_BODY_ID) | OBJECT_T; + const bits PHYSICS_FIXTURE_T = (bits(1) << PHYSICS_FIXTURE_ID) | OBJECT_T; + const bits PHYSICS_SHAPE_T = (bits(1) << PHYSICS_SHAPE_ID) | OBJECT_T; + const bits PHYSICS_CIRCLE_SHAPE_T = (bits(1) << PHYSICS_CIRCLE_SHAPE_ID) | PHYSICS_SHAPE_T; + const bits PHYSICS_POLYGON_SHAPE_T = (bits(1) << PHYSICS_POLYGON_SHAPE_ID) | PHYSICS_SHAPE_T; + const bits PHYSICS_EDGE_SHAPE_T = (bits(1) << PHYSICS_EDGE_SHAPE_ID) | PHYSICS_SHAPE_T; + const bits PHYSICS_CHAIN_SHAPE_T = (bits(1) << PHYSICS_CHAIN_SHAPE_ID) | PHYSICS_SHAPE_T; + const bits PHYSICS_JOINT_T = (bits(1) << PHYSICS_JOINT_ID) | OBJECT_T; + const bits PHYSICS_MOUSE_JOINT_T = (bits(1) << PHYSICS_MOUSE_JOINT_ID) | PHYSICS_JOINT_T; + const bits PHYSICS_DISTANCE_JOINT_T = (bits(1) << PHYSICS_DISTANCE_JOINT_ID) | PHYSICS_JOINT_T; + const bits PHYSICS_PRISMATIC_JOINT_T = (bits(1) << PHYSICS_PRISMATIC_JOINT_ID) | PHYSICS_JOINT_T; + const bits PHYSICS_REVOLUTE_JOINT_T = (bits(1) << PHYSICS_REVOLUTE_JOINT_ID) | PHYSICS_JOINT_T; + const bits PHYSICS_PULLEY_JOINT_T = (bits(1) << PHYSICS_PULLEY_JOINT_ID) | PHYSICS_JOINT_T; + const bits PHYSICS_GEAR_JOINT_T = (bits(1) << PHYSICS_GEAR_JOINT_ID) | PHYSICS_JOINT_T; + const bits PHYSICS_FRICTION_JOINT_T = (bits(1) << PHYSICS_FRICTION_JOINT_ID) | PHYSICS_JOINT_T; + const bits PHYSICS_WELD_JOINT_T = (bits(1) << PHYSICS_WELD_JOINT_ID) | PHYSICS_JOINT_T; + const bits PHYSICS_ROPE_JOINT_T = (bits(1) << PHYSICS_ROPE_JOINT_ID) | PHYSICS_JOINT_T; + const bits PHYSICS_WHEEL_JOINT_T = (bits(1) << PHYSICS_WHEEL_JOINT_ID) | PHYSICS_JOINT_T; + + // Thread. + const bits THREAD_THREAD_T = (bits(1) << THREAD_THREAD_ID) | OBJECT_T; + + // Modules. + const bits MODULE_FILESYSTEM_T = (bits(1) << MODULE_FILESYSTEM_ID) | MODULE_T; + const bits MODULE_IMAGE_T = (bits(1) << MODULE_IMAGE_ID) | MODULE_T; + const bits MODULE_SOUND_T = (bits(1) << MODULE_SOUND_ID) | MODULE_T; + + bool getType(const char * in, Type & out); + bool getType(Type in, const char *& out); + +} // love + +#endif // LOVE_TYPES_H diff --git a/src/common/utf8.cpp b/src/common/utf8.cpp index 6bd0220cb..8067195a2 100644 --- a/src/common/utf8.cpp +++ b/src/common/utf8.cpp @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2011 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -48,9 +48,9 @@ namespace love { int length = str.length(); - for(int i = 0; i 1 && strcmp(argv[1],"--version") == 0) { + if (argc > 1 && strcmp(argv[1],"--version") == 0) + { printf("LOVE %s (%s)\n", love::VERSION, love::VERSION_CODENAME); return 0; } @@ -259,7 +260,7 @@ int main(int argc, char ** argv) { lua_newtable(L); - if(argc > 0) + if (argc > 0) { lua_pushstring(L, argv[0]); lua_rawseti(L, -2, -2); @@ -268,7 +269,7 @@ int main(int argc, char ** argv) lua_pushstring(L, "embedded boot.lua"); lua_rawseti(L, -2, -1); - for(int i = 1; i -#include "Source.h" - -namespace love -{ -namespace sound -{ - class Decoder; - class SoundData; -} -namespace audio -{ - /** - * The Audio module is responsible for playing back raw sound samples. - **/ - class Audio : public Module - { - public: - - /** - * Destructor. - **/ - virtual ~Audio(){}; - - virtual Source * newSource(love::sound::Decoder * decoder) = 0; - virtual Source * newSource(love::sound::SoundData * soundData) = 0; - - /** - * Gets the current number of simultaneous playing sources. - * @return The current number of simultaneous playing sources. - **/ - virtual int getNumSources() const = 0; - - /** - * Gets the maximum supported number of simultaneous playing sources. - * @return The maximum supported number of simultaneous playing sources. - **/ - virtual int getMaxSources() const = 0; - - /** - * Play the specified Source. - * @param source The Source to play. - **/ - virtual void play(Source * source) = 0; - - /** - * Stops playback on the specified source. - * @param source The source on which to stop the playback. - **/ - virtual void stop(Source * source) = 0; - - /** - * Stops all playing audio. - **/ - virtual void stop() = 0; - - /** - * Pauses playback on the specified source. - * @param source The source on which to pause the playback. - **/ - virtual void pause(Source * source) = 0; - - /** - * Pauses all audio. - **/ - virtual void pause() = 0; - - /** - * Resumes playback on the specified source. - * @param source The source on which to resume the playback. - **/ - virtual void resume(Source * source) = 0; - - /** - * Resumes all audio. - **/ - virtual void resume() = 0; - - /** - * Rewinds the specified source. Whatever is playing on this - * source gets rewound to the start. - * @param source The source to rewind. - **/ - virtual void rewind(Source * source) = 0; - - /** - * Rewinds all playing audio. - **/ - virtual void rewind() = 0; - - /** - * Sets the master volume, where 0.0f is min (off) and 1.0f is max. - * @param volume The new master volume. - **/ - virtual void setVolume(float volume) = 0; - - /** - * Gets the master volume. - * @return The current master volume. - **/ - virtual float getVolume() const = 0; - - /** - * Gets the position of the listener. - * @param v A float array of size 3 containing (x,y,z) in that order. - **/ - virtual void getPosition(float * v) const = 0; - - /** - * Sets the position of the listener. - * @param v A float array of size 3 containing [x,y,z] in that order. - **/ - virtual void setPosition(float * v) = 0; - - /** - * Gets the orientation of the listener. - * @param v A float array of size 6 containing [x,y,z] for the forward - * vector, followed by [x,y,z] for the up vector. - **/ - virtual void getOrientation(float * v) const = 0; - - /** - * Sets the orientation of the listener. - * @param v A float array of size 6 containing [x,y,z] for the forward - * vector, followed by [x,y,z] for the up vector. - **/ - virtual void setOrientation(float * v) = 0; - - /** - * Gets the velocity of the listener. - * @param v A float array of size 3 containing [x,y,z] in that order. - **/ - virtual void getVelocity(float * v) const = 0; - - /** - * Sets the velocity of the listener. - * @param v A float array of size 3 containing [x,y,z] in that order. - **/ - virtual void setVelocity(float * v) = 0; - - /** - * Begins recording audio input from the microphone. - **/ - virtual void record() = 0; - - /** - * Gets a section of recorded audio. - * Per OpenAL, the measurement begins from the start of the - * audio data in memory, which is after the last time this function - * was called. If this function has not been called yet this recording - * session, it just grabs from the beginning. - * @return All the recorded SoundData thus far. - **/ - virtual love::sound::SoundData * getRecordedData() = 0; - - /** - * Stops recording and, if passed true, returns all the recorded audio - * not already gotten by getRecordedData. - * @param returnData Whether to return recorded audio. - * @return if returnData, all the recorded audio yet to be gotten, - * otherwise NULL. - **/ - virtual love::sound::SoundData * stopRecording(bool returnData) = 0; - - /** - * Checks whether LOVE is able to record audio input. - * @return hasMic Whether LOVE has a microphone enabled. - **/ - virtual bool canRecord() = 0; - - }; // Audio - -} // audio -} // love - -#endif // LOVE_AUDIO_AUDIO_H +/** +* Copyright (c) 2006-2011 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented = 0; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#ifndef LOVE_AUDIO_AUDIO_H +#define LOVE_AUDIO_AUDIO_H + +#include +#include "Source.h" + +namespace love +{ +namespace sound +{ + class Decoder; + class SoundData; +} +namespace audio +{ + /** + * The Audio module is responsible for playing back raw sound samples. + **/ + class Audio : public Module + { + public: + + /** + * Destructor. + **/ + virtual ~Audio(){}; + + virtual Source * newSource(love::sound::Decoder * decoder) = 0; + virtual Source * newSource(love::sound::SoundData * soundData) = 0; + + /** + * Gets the current number of simultaneous playing sources. + * @return The current number of simultaneous playing sources. + **/ + virtual int getNumSources() const = 0; + + /** + * Gets the maximum supported number of simultaneous playing sources. + * @return The maximum supported number of simultaneous playing sources. + **/ + virtual int getMaxSources() const = 0; + + /** + * Play the specified Source. + * @param source The Source to play. + **/ + virtual void play(Source * source) = 0; + + /** + * Stops playback on the specified source. + * @param source The source on which to stop the playback. + **/ + virtual void stop(Source * source) = 0; + + /** + * Stops all playing audio. + **/ + virtual void stop() = 0; + + /** + * Pauses playback on the specified source. + * @param source The source on which to pause the playback. + **/ + virtual void pause(Source * source) = 0; + + /** + * Pauses all audio. + **/ + virtual void pause() = 0; + + /** + * Resumes playback on the specified source. + * @param source The source on which to resume the playback. + **/ + virtual void resume(Source * source) = 0; + + /** + * Resumes all audio. + **/ + virtual void resume() = 0; + + /** + * Rewinds the specified source. Whatever is playing on this + * source gets rewound to the start. + * @param source The source to rewind. + **/ + virtual void rewind(Source * source) = 0; + + /** + * Rewinds all playing audio. + **/ + virtual void rewind() = 0; + + /** + * Sets the master volume, where 0.0f is min (off) and 1.0f is max. + * @param volume The new master volume. + **/ + virtual void setVolume(float volume) = 0; + + /** + * Gets the master volume. + * @return The current master volume. + **/ + virtual float getVolume() const = 0; + + /** + * Gets the position of the listener. + * @param v A float array of size 3 containing (x,y,z) in that order. + **/ + virtual void getPosition(float * v) const = 0; + + /** + * Sets the position of the listener. + * @param v A float array of size 3 containing [x,y,z] in that order. + **/ + virtual void setPosition(float * v) = 0; + + /** + * Gets the orientation of the listener. + * @param v A float array of size 6 containing [x,y,z] for the forward + * vector, followed by [x,y,z] for the up vector. + **/ + virtual void getOrientation(float * v) const = 0; + + /** + * Sets the orientation of the listener. + * @param v A float array of size 6 containing [x,y,z] for the forward + * vector, followed by [x,y,z] for the up vector. + **/ + virtual void setOrientation(float * v) = 0; + + /** + * Gets the velocity of the listener. + * @param v A float array of size 3 containing [x,y,z] in that order. + **/ + virtual void getVelocity(float * v) const = 0; + + /** + * Sets the velocity of the listener. + * @param v A float array of size 3 containing [x,y,z] in that order. + **/ + virtual void setVelocity(float * v) = 0; + + /** + * Begins recording audio input from the microphone. + **/ + virtual void record() = 0; + + /** + * Gets a section of recorded audio. + * Per OpenAL, the measurement begins from the start of the + * audio data in memory, which is after the last time this function + * was called. If this function has not been called yet this recording + * session, it just grabs from the beginning. + * @return All the recorded SoundData thus far. + **/ + virtual love::sound::SoundData * getRecordedData() = 0; + + /** + * Stops recording and, if passed true, returns all the recorded audio + * not already gotten by getRecordedData. + * @param returnData Whether to return recorded audio. + * @return if returnData, all the recorded audio yet to be gotten, + * otherwise NULL. + **/ + virtual love::sound::SoundData * stopRecording(bool returnData) = 0; + + /** + * Checks whether LOVE is able to record audio input. + * @return hasMic Whether LOVE has a microphone enabled. + **/ + virtual bool canRecord() = 0; + + }; // Audio + +} // audio +} // love + +#endif // LOVE_AUDIO_AUDIO_H diff --git a/src/modules/audio/Source.cpp b/src/modules/audio/Source.cpp index 34bac0785..3dab230a4 100644 --- a/src/modules/audio/Source.cpp +++ b/src/modules/audio/Source.cpp @@ -1,73 +1,73 @@ -/** -* Copyright (c) 2006-2011 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#include "Source.h" - -namespace love -{ -namespace audio -{ - Source::Source(Type type) - : type(type) - { - } - - Source::~Source() - { - } - - bool Source::getConstant(const char * in, Type & out) - { - return types.find(in, out); - } - - bool Source::getConstant(Type in, const char *& out) - { - return types.find(in, out); - } - - bool Source::getConstant(const char * in, Unit & out) - { - return units.find(in, out); - } - - bool Source::getConstant(Unit in, const char *& out) - { - return units.find(in, out); - } - - StringMap::Entry Source::typeEntries[] = - { - {"static", Source::TYPE_STATIC}, - {"stream", Source::TYPE_STREAM}, - }; - - StringMap Source::types(Source::typeEntries, sizeof(Source::typeEntries)); - - StringMap::Entry Source::unitEntries[] = - { - {"seconds", Source::UNIT_SECONDS}, - {"samples", Source::UNIT_SAMPLES}, - }; - - StringMap Source::units(Source::unitEntries, sizeof(Source::unitEntries)); - -} // audio -} // love +/** +* Copyright (c) 2006-2011 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#include "Source.h" + +namespace love +{ +namespace audio +{ + Source::Source(Type type) + : type(type) + { + } + + Source::~Source() + { + } + + bool Source::getConstant(const char * in, Type & out) + { + return types.find(in, out); + } + + bool Source::getConstant(Type in, const char *& out) + { + return types.find(in, out); + } + + bool Source::getConstant(const char * in, Unit & out) + { + return units.find(in, out); + } + + bool Source::getConstant(Unit in, const char *& out) + { + return units.find(in, out); + } + + StringMap::Entry Source::typeEntries[] = + { + {"static", Source::TYPE_STATIC}, + {"stream", Source::TYPE_STREAM}, + }; + + StringMap Source::types(Source::typeEntries, sizeof(Source::typeEntries)); + + StringMap::Entry Source::unitEntries[] = + { + {"seconds", Source::UNIT_SECONDS}, + {"samples", Source::UNIT_SAMPLES}, + }; + + StringMap Source::units(Source::unitEntries, sizeof(Source::unitEntries)); + +} // audio +} // love diff --git a/src/modules/audio/Source.h b/src/modules/audio/Source.h index 45bc359d6..e03bc5212 100644 --- a/src/modules/audio/Source.h +++ b/src/modules/audio/Source.h @@ -1,107 +1,107 @@ -/** -* Copyright (c) 2006-2011 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#ifndef LOVE_AUDIO_SOURCE_H -#define LOVE_AUDIO_SOURCE_H - -// LOVE -#include -#include - -namespace love -{ -namespace audio -{ - class Source : public Object - { - public: - - enum Type - { - TYPE_STATIC = 1, - TYPE_STREAM, - TYPE_MAX_ENUM - }; // Type - - enum Unit - { - UNIT_SECONDS = 1, - UNIT_SAMPLES, - UNIT_MAX_ENUM - }; - - protected: - Type type; - public: - - Source(Type type); - virtual ~Source(); - - virtual Source * copy() = 0; - - virtual void play() = 0; - virtual void stop() = 0; - virtual void pause() = 0; - virtual void resume() = 0; - virtual void rewind() = 0; - virtual bool isStopped() const = 0; - virtual bool isPaused() const = 0; - virtual bool isFinished() const = 0; - virtual bool update() = 0; - - virtual void setPitch(float pitch) = 0; - virtual float getPitch() const = 0; - - virtual void setVolume(float volume) = 0; - virtual float getVolume() const = 0; - - virtual void seek(float offset, Unit unit) = 0; - virtual float tell(Unit unit) = 0; - - // all float * v must be of size 3 - virtual void setPosition(float * v) = 0; - virtual void getPosition(float * v) const = 0; - virtual void setVelocity(float * v) = 0; - virtual void getVelocity(float * v) const = 0; - virtual void setDirection(float * v) = 0; - virtual void getDirection(float * v) const = 0; - - virtual void setLooping(bool looping) = 0; - virtual bool isLooping() const = 0; - virtual bool isStatic() const = 0; - - static bool getConstant(const char * in, Type & out); - static bool getConstant(Type in, const char *& out); - static bool getConstant(const char * in, Unit & out); - static bool getConstant(Unit in, const char *& out); - - private: - - static StringMap::Entry typeEntries[]; - static StringMap types; - static StringMap::Entry unitEntries[]; - static StringMap units; - - }; // Source - -} // audio -} // love - -#endif // LOVE_AUDIO_SOURCE_H +/** +* Copyright (c) 2006-2011 LOVE Development Team +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +**/ + +#ifndef LOVE_AUDIO_SOURCE_H +#define LOVE_AUDIO_SOURCE_H + +// LOVE +#include +#include + +namespace love +{ +namespace audio +{ + class Source : public Object + { + public: + + enum Type + { + TYPE_STATIC = 1, + TYPE_STREAM, + TYPE_MAX_ENUM + }; // Type + + enum Unit + { + UNIT_SECONDS = 1, + UNIT_SAMPLES, + UNIT_MAX_ENUM + }; + + protected: + Type type; + public: + + Source(Type type); + virtual ~Source(); + + virtual Source * copy() = 0; + + virtual void play() = 0; + virtual void stop() = 0; + virtual void pause() = 0; + virtual void resume() = 0; + virtual void rewind() = 0; + virtual bool isStopped() const = 0; + virtual bool isPaused() const = 0; + virtual bool isFinished() const = 0; + virtual bool update() = 0; + + virtual void setPitch(float pitch) = 0; + virtual float getPitch() const = 0; + + virtual void setVolume(float volume) = 0; + virtual float getVolume() const = 0; + + virtual void seek(float offset, Unit unit) = 0; + virtual float tell(Unit unit) = 0; + + // all float * v must be of size 3 + virtual void setPosition(float * v) = 0; + virtual void getPosition(float * v) const = 0; + virtual void setVelocity(float * v) = 0; + virtual void getVelocity(float * v) const = 0; + virtual void setDirection(float * v) = 0; + virtual void getDirection(float * v) const = 0; + + virtual void setLooping(bool looping) = 0; + virtual bool isLooping() const = 0; + virtual bool isStatic() const = 0; + + static bool getConstant(const char * in, Type & out); + static bool getConstant(Type in, const char *& out); + static bool getConstant(const char * in, Unit & out); + static bool getConstant(Unit in, const char *& out); + + private: + + static StringMap::Entry typeEntries[]; + static StringMap types; + static StringMap::Entry unitEntries[]; + static StringMap units; + + }; // Source + +} // audio +} // love + +#endif // LOVE_AUDIO_SOURCE_H diff --git a/src/modules/audio/null/Audio.cpp b/src/modules/audio/null/Audio.cpp index 6e4805846..f14d3f1da 100644 --- a/src/modules/audio/null/Audio.cpp +++ b/src/modules/audio/null/Audio.cpp @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2011 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -132,21 +132,21 @@ namespace null void Audio::setVelocity(float *) { } - + void Audio::record() { } - + love::sound::SoundData * Audio::getRecordedData() { return NULL; } - + love::sound::SoundData * Audio::stopRecording(bool) { return NULL; } - + bool Audio::canRecord() { return false; diff --git a/src/modules/audio/null/Audio.h b/src/modules/audio/null/Audio.h index 663d9029e..3ccc75689 100644 --- a/src/modules/audio/null/Audio.h +++ b/src/modules/audio/null/Audio.h @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2011 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -68,7 +68,7 @@ namespace null void setOrientation(float * v); void getVelocity(float * v) const; void setVelocity(float * v); - + void record(); love::sound::SoundData * getRecordedData(); love::sound::SoundData * stopRecording(bool returnData); diff --git a/src/modules/audio/null/Source.cpp b/src/modules/audio/null/Source.cpp index e2ea14a2c..731262bc2 100644 --- a/src/modules/audio/null/Source.cpp +++ b/src/modules/audio/null/Source.cpp @@ -101,11 +101,11 @@ namespace null { return volume; } - + void Source::seek(float, Source::Unit) { } - + float Source::tell(Source::Unit) { return 0.0f; diff --git a/src/modules/audio/null/Source.h b/src/modules/audio/null/Source.h index 51e0f9cd8..e8ec211a1 100644 --- a/src/modules/audio/null/Source.h +++ b/src/modules/audio/null/Source.h @@ -1,78 +1,78 @@ -/** -* Copyright (c) 2006-2011 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#ifndef LOVE_AUDIO_NULL_SOURCE_H -#define LOVE_AUDIO_NULL_SOURCE_H - -// LOVE -#include -#include