Преглед изворни кода

Merge branch 'master' of github.com:taylor001/crown

Daniele Bartolini пре 10 година
родитељ
комит
542516de31

+ 25 - 19
docs/lua_api.txt

@@ -7,7 +7,7 @@ Vector3
 -------
 
 	**Vector3** (x, y, z) : Vector3
-		Constructor.
+		Returns a new vector from individual components.
 
 	**x** (v) : float
 		Returns the x value of the vector.
@@ -110,14 +110,14 @@ Vector3
 Vector3Box
 ----------
 
-	**Vector3Box** ()
-		Creates a new Vector3Box.
+	**Vector3Box** () : Vector3Box
+		Returns a new Vector3Box.
 
-	**Vector3Box** (v)
-		Creates a new Vector3Box from the Vector3 *v*.
+	**Vector3Box** (v) : Vector3Box
+		Returns a new Vector3Box from the Vector3 *v*.
 
-	**Vector3Box** (x, y, z)
-		Creates a new Vector3Box from components.
+	**Vector3Box** (x, y, z) : Vector3Box
+		Returns a new Vector3Box from components.
 
 	**store** (v)
 		Stores the Vector3 *v* in the box.
@@ -131,8 +131,8 @@ Vector3Box
 Quaternion
 ----------
 
-	**Quaternion** (v, w) : Quaternion
-		Constructor.
+	**Quaternion** (axis, angle) : Quaternion
+		Returns a new quaternion from *axis* and *angle*.
 
 	**negate** (q) : Quaternion
 		Negates the quaternion *q* and returns the result.
@@ -183,14 +183,14 @@ Quaternion
 QuaternionBox
 -------------
 
-	**QuaternionBox** ()
-		Creates a new QuaternionBox.
+	**QuaternionBox** () : QuaternionBox
+		Returns a new QuaternionBox.
 
-	**QuaternionBox** (q)
-		Creates a new QuaternionBox from the Quaternion *q*.
+	**QuaternionBox** (q) : QuaternionBox
+		Returns a new QuaternionBox from the Quaternion *q*.
 
-	**QuaternionBox** (x, y, z, w)
-		Creates a new QuaternionBox from elements.
+	**QuaternionBox** (x, y, z, w) : QuaternionBox
+		Returns a new QuaternionBox from elements.
 
 	**store(q)** ()
 		Stores the Quaternion *q* in the box.
@@ -204,8 +204,8 @@ QuaternionBox
 Matrix4x4
 ---------
 
-	**Matrix4x4** (m0, m1, ..., m15) : Matrix4x4
-		Constructor.
+	**Matrix4x4** (xx, xy, xz, xw, yx, yy, yz, yw, zx, zy, zz, zw, tx, ty, tz, tw) : Matrix4x4
+		Returns a new matrix from individual components.
 
 	**from_quaternion** (q) : Matrix4x4
 		Returns a new matrix from *q*.
@@ -282,8 +282,8 @@ Matrix4x4
 Matrix4x4Box
 ------------
 
-	**Matrix4x4Box** (m)
-		Creates a new Matrix4x4Box from the Matrix4x4 *m*.
+	**Matrix4x4Box** (m) : Matrix4x4Box
+		Returns a new Matrix4x4Box from the Matrix4x4 *m*.
 
 	**store** (m)
 		Stores the Matrix4x4 *m* in the box.
@@ -291,6 +291,12 @@ Matrix4x4Box
 	**unbox** () : Matrix4x4
 		Returns the stored matrix from the box.
 
+Color4
+------
+
+	**Color4** (r, g, b, a) : Color4
+		Returns a new Color4 from individual components.
+
 Math
 ----
 

+ 13 - 8
src/core/error/error.cpp

@@ -5,24 +5,29 @@
 
 #include "error.h"
 #include "stacktrace.h"
+#include "log.h"
 #include <stdlib.h>
-#include <stdio.h>
 #include <stdarg.h>
 
 namespace crown
 {
 namespace error
 {
-	void abort(const char* file, int line, const char* message, ...)
+	static void abort(const char* file, int line, const char* format, va_list args)
 	{
-		va_list ap;
-		va_start(ap, message);
-		vprintf(message, ap);
-		va_end(ap);
-		printf("\tIn: %s:%d\n", file, line);
-		printf("Stacktrace:\n");
+		CE_LOGEV(format, args);
+		CE_LOGE("\tIn: %s:%d", file, line);
+		CE_LOGE("Stacktrace:");
 		print_callstack();
 		exit(EXIT_FAILURE);
 	}
+
+	void abort(const char* file, int line, const char* format, ...)
+	{
+		va_list args;
+		va_start(args, format);
+		abort(file, line, format, args);
+		va_end(args);
+	}
 } // namespace error
 } // namespace crown

+ 1 - 1
src/core/error/error.h

@@ -13,7 +13,7 @@ namespace error
 {
 	/// Aborts the program execution logging an error message and the stacktrace if
 	/// the platform supports it.
-	void abort(const char* file, int line, const char* message, ...);
+	void abort(const char* file, int line, const char* format, ...);
 } // namespace error
 } // namespace crown
 

+ 3 - 3
src/core/error/stacktrace_linux.cpp

@@ -9,7 +9,7 @@
 
 #include "macros.h"
 #include "string_utils.h"
-#include <stdio.h>
+#include "log.h"
 #include <stdlib.h>
 #include <cxxabi.h>
 #include <execinfo.h>
@@ -64,7 +64,7 @@ void print_callstack()
 			char line[256];
 			memset(line, 0, sizeof(line));
 
-			printf("\t[%d] %s: (%s)+%s in %s\n"
+			CE_LOGE("\t[%d] %s: (%s)+%s in %s"
 				, i
 				, msg
 				, (demangle_ok == 0 ? real_name : mangled_name)
@@ -77,7 +77,7 @@ void print_callstack()
 		// otherwise, print the whole line
 		else
 		{
-			printf("\t[%d] %s\n", i, msg);
+			CE_LOGE("\t[%d] %s", i, msg);
 		}
 	}
 	free(messages);

+ 3 - 3
src/core/error/stacktrace_windows.cpp

@@ -7,9 +7,9 @@
 
 #if CROWN_PLATFORM_WINDOWS
 
+#include "log.h"
 #include <windows.h>
 #include <dbghelp.h>
-#include <stdio.h>
 
 namespace crown
 {
@@ -77,9 +77,9 @@ void print_callstack()
 		res = res && SymFromAddr(GetCurrentProcess(), stack.AddrPC.Offset, 0, sym);
 
 		if (res == TRUE)
-			printf("\t[%i] %s (%s:%d)\n", num, sym->Name, line.FileName, line.LineNumber);
+			CE_LOGE("\t[%i] %s (%s:%d)", num, sym->Name, line.FileName, line.LineNumber);
 		else
-			printf("\t[%i] 0x%p\n", num, stack.AddrPC.Offset);
+			CE_LOGE("\t[%i] 0x%p", num, stack.AddrPC.Offset);
 	}
 
 	SymCleanup(GetCurrentProcess());

+ 1 - 1
src/core/json/json.h

@@ -11,7 +11,7 @@
 namespace crown
 {
 
-/// Functions to parse JSON-encoded strings.
+/// Functions to parse JSON-encoded data.
 ///
 /// @ingroup JSON
 namespace json

+ 1 - 1
src/core/json/sjson.cpp

@@ -275,7 +275,7 @@ namespace sjson
 		return (float) parse_number(json);
 	}
 
-	void parse_array(const char* json, Array<const char*>& array)
+	void parse_array(const char* json, JsonArray& array)
 	{
 		CE_ASSERT_NOT_NULL(json);
 

+ 1 - 1
src/core/json/sjson.h

@@ -12,7 +12,7 @@
 namespace crown
 {
 
-/// Functions to parse SJSON-encoded strings.
+/// Functions to parse SJSON-encoded data.
 ///
 /// @ingroup JSON
 namespace sjson

+ 8 - 4
src/core/math/color4.h

@@ -13,6 +13,7 @@ namespace crown
 /// @addtogroup Math
 /// @{
 
+/// Returns a new color from individual components.
 inline Color4 color4(float r, float g, float b, float a)
 {
 	Color4 c;
@@ -23,7 +24,8 @@ inline Color4 color4(float r, float g, float b, float a)
 	return c;
 }
 
-inline Color4 from_rgb(int r, int g, int b)
+/// Returns a new color from individual components. Alpha is set to 255.
+inline Color4 from_rgb(uint8_t r, uint8_t g, uint8_t b)
 {
 	Color4 c;
 	c.x = 1.0f/255.0f * r;
@@ -33,7 +35,8 @@ inline Color4 from_rgb(int r, int g, int b)
 	return c;
 }
 
-inline Color4 from_rgba(int r, int g, int b, int a)
+/// Returns a new color from individual components.
+inline Color4 from_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
 {
 	Color4 c;
 	c.x = 1.0f/255.0f * r;
@@ -43,6 +46,7 @@ inline Color4 from_rgba(int r, int g, int b, int a)
 	return c;
 }
 
+/// Returns a new color from packed RGBA integer.
 inline Color4 from_rgba(uint32_t rgba)
 {
 	Color4 c;
@@ -53,7 +57,7 @@ inline Color4 from_rgba(uint32_t rgba)
 	return c;
 }
 
-/// Returns the color as a packed 32-bit integer. (RGBA order, alpha assumed = 255)
+/// Returns the color as a packed RGBA integer. Alpha is set to 255.
 inline uint32_t to_rgb(const Color4& c)
 {
 	uint32_t rgba;
@@ -64,7 +68,7 @@ inline uint32_t to_rgb(const Color4& c)
 	return rgba;
 }
 
-/// Returns the color as a packed 32-bit integer. (ABGR order, alpha assumed = 255)
+/// Returns the color as a packed ABGR integer. Alpha is set to 255.
 inline uint32_t to_bgr(const Color4& c)
 {
 	uint32_t abgr;

+ 2 - 0
src/core/math/matrix3x3.h

@@ -13,6 +13,7 @@ namespace crown
 /// @addtogroup Math
 /// @{
 
+/// Returns a new matrix from axes @a x, @a y and @a z.
 inline Matrix3x3 matrix3x3(const Vector3& x, const Vector3& y, const Vector3& z)
 {
 	Matrix3x3 m;
@@ -22,6 +23,7 @@ inline Matrix3x3 matrix3x3(const Vector3& x, const Vector3& y, const Vector3& z)
 	return m;
 }
 
+/// Returns a new matrix from rotation @a r.
 inline Matrix3x3 matrix3x3(const Quaternion& r)
 {
 	Matrix3x3 m;

+ 43 - 38
src/core/math/matrix4x4.h

@@ -15,35 +15,37 @@ namespace crown
 /// @addtogroup Math
 /// @{
 
-inline Matrix4x4 matrix4x4(float r1c1, float r2c1, float r3c1, float r4c1
-	, float r1c2, float r2c2, float r3c2, float r4c2
-	, float r1c3, float r2c3, float r3c3, float r4c3
-	, float r1c4, float r2c4, float r3c4, float r4c4
+/// Returns a new matrix from individual components.
+inline Matrix4x4 matrix4x4(float xx, float xy, float xz, float xw
+	, float yx, float yy, float yz, float yw
+	, float zx, float zy, float zz, float zw
+	, float tx, float ty, float tz, float tw
 	)
 {
 	Matrix4x4 m;
-	m.x.x = r1c1;
-	m.x.y = r1c2;
-	m.x.z = r1c3;
-	m.x.w = r1c4;
-
-	m.y.x = r2c1;
-	m.y.y = r2c2;
-	m.y.z = r2c3;
-	m.y.w = r2c4;
-
-	m.z.x = r3c1;
-	m.z.y = r3c2;
-	m.z.z = r3c3;
-	m.z.w = r3c4;
-
-	m.t.x = r4c1;
-	m.t.y = r4c2;
-	m.t.z = r4c3;
-	m.t.w = r4c4;
+	m.x.x = xx;
+	m.x.y = xy;
+	m.x.z = xz;
+	m.x.w = xw;
+
+	m.y.x = yx;
+	m.y.y = yy;
+	m.y.z = yz;
+	m.y.w = yw;
+
+	m.z.x = zx;
+	m.z.y = zy;
+	m.z.z = zz;
+	m.z.w = zw;
+
+	m.t.x = tx;
+	m.t.y = ty;
+	m.t.z = tz;
+	m.t.w = tw;
 	return m;
 }
 
+/// Returns a new matrix from individual components.
 inline Matrix4x4 matrix4x4(const float a[16])
 {
 	Matrix4x4 m;
@@ -69,6 +71,7 @@ inline Matrix4x4 matrix4x4(const float a[16])
 	return m;
 }
 
+/// Returns a new matrix from axes @a x, @a y and @a z and translation @a t.
 inline Matrix4x4 matrix4x4(const Vector3& x, const Vector3& y, const Vector3& z, const Vector3& t)
 {
 	Matrix4x4 m;
@@ -94,7 +97,8 @@ inline Matrix4x4 matrix4x4(const Vector3& x, const Vector3& y, const Vector3& z,
 	return m;
 }
 
-inline Matrix4x4 matrix4x4(const Quaternion& r, const Vector3& p)
+/// Returns a new matrix from rotation @a r and translation @a t.
+inline Matrix4x4 matrix4x4(const Quaternion& r, const Vector3& t)
 {
 	Matrix4x4 m;
 	m.x.x = 1.0f - 2.0f * r.y * r.y - 2.0f * r.z * r.z;
@@ -112,29 +116,30 @@ inline Matrix4x4 matrix4x4(const Quaternion& r, const Vector3& p)
 	m.z.z = 1.0f - 2.0f * r.x * r.x - 2.0f * r.y * r.y;
 	m.z.w = 0.0f;
 
-	m.t.x = p.x;
-	m.t.y = p.y;
-	m.t.z = p.z;
+	m.t.x = t.x;
+	m.t.y = t.y;
+	m.t.z = t.z;
 	m.t.w = 1.0f;
 	return m;
 }
 
-inline Matrix4x4 matrix4x4(const Matrix3x3& rot)
+/// Returns a new matrix from rotation matrix @a r.
+inline Matrix4x4 matrix4x4(const Matrix3x3& r)
 {
 	Matrix4x4 m;
-	m.x.x = rot.x.x;
-	m.x.y = rot.x.y;
-	m.x.z = rot.x.z;
+	m.x.x = r.x.x;
+	m.x.y = r.x.y;
+	m.x.z = r.x.z;
 	m.x.w = 0.0f;
 
-	m.y.x = rot.y.x;
-	m.y.y = rot.y.y;
-	m.y.z = rot.y.z;
+	m.y.x = r.y.x;
+	m.y.y = r.y.y;
+	m.y.z = r.y.z;
 	m.y.w = 0.0f;
 
-	m.z.x = rot.z.x;
-	m.z.y = rot.z.y;
-	m.z.z = rot.z.z;
+	m.z.x = r.z.x;
+	m.z.y = r.z.y;
+	m.z.z = r.z.z;
 	m.z.w = 0.0f;
 
 	m.t.x = 0.0f;
@@ -613,7 +618,7 @@ inline Vector3 scale(const Matrix4x4& m)
 	return v;
 }
 
-/// Sets the scale of the matrix @æ m.
+/// Sets the scale of the matrix @a m.
 inline void set_scale(Matrix4x4& m, const Vector3& s)
 {
 	Matrix3x3 rot = to_matrix3x3(m);

+ 6 - 0
src/core/math/quaternion.h

@@ -14,6 +14,7 @@ namespace crown
 /// @addtogroup Math
 /// @{
 
+/// Returns a new quaternion from individual components.
 inline Quaternion quaternion(float x, float y, float z, float w)
 {
 	Quaternion q;
@@ -24,6 +25,7 @@ inline Quaternion quaternion(float x, float y, float z, float w)
 	return q;
 }
 
+/// Returns a new quaternion from @a axis and @a angle.
 inline Quaternion quaternion(const Vector3& axis, float angle)
 {
 	const float ha = angle * 0.5f;
@@ -37,6 +39,7 @@ inline Quaternion quaternion(const Vector3& axis, float angle)
 	return q;
 }
 
+/// Returns a new quaternion from matrix @a m.
 Quaternion quaternion(const Matrix3x3& m);
 
 inline Quaternion& operator*=(Quaternion& a, const Quaternion& b)
@@ -156,18 +159,21 @@ inline Quaternion look(const Vector3& dir, const Vector3& up = VECTOR3_YAXIS)
 	return quaternion(m);
 }
 
+/// Returns the right axis of the rotation represented by @a q.
 inline Vector3 right(const Quaternion& q)
 {
 	const Matrix3x3 m = matrix3x3(q);
 	return m.x;
 }
 
+/// Returns the up axis of the rotation represented by @a q.
 inline Vector3 up(const Quaternion& q)
 {
 	const Matrix3x3 m = matrix3x3(q);
 	return m.y;
 }
 
+/// Returns the forward axis of the rotation represented by @a q.
 inline Vector3 forward(const Quaternion& q)
 {
 	const Matrix3x3 m = matrix3x3(q);

+ 5 - 4
src/core/math/sphere.h

@@ -73,12 +73,13 @@ namespace sphere
 	{
 		for (uint32_t i = 0; i < num; ++i)
 		{
-			const float dist = length_squared(spheres[i].c - s.c);
+			const Sphere si = spheres[i];
+			const float dist = length_squared(si.c - s.c);
 
-			if (dist < (spheres[i].r + s.r) * (spheres[i].r + s.r))
+			if (dist < (si.r + s.r) * (si.r + s.r))
 			{
-				if (spheres[i].r * spheres[i].r > s.r * s.r)
-					s.r = sqrtf(dist + spheres[i].r * spheres[i].r);
+				if (si.r*si.r > s.r*s.r)
+					s.r = sqrtf(dist + si.r*si.r);
 			}
 		}
 	}

+ 1 - 0
src/core/math/vector2.h

@@ -13,6 +13,7 @@ namespace crown
 /// @addtogroup Math
 /// @{
 
+/// Returns a new vector from individual components.
 inline Vector2 vector2(float x, float y)
 {
 	Vector2 v;

+ 1 - 0
src/core/math/vector3.h

@@ -13,6 +13,7 @@ namespace crown
 /// @addtogroup Math
 /// @{
 
+/// Returns a new vector from individual components.
 inline Vector3 vector3(float x, float y, float z)
 {
 	Vector3 v;

+ 1 - 10
src/core/math/vector4.h

@@ -13,6 +13,7 @@ namespace crown
 /// @addtogroup Math
 /// @{
 
+/// Returns a new vector from individual components.
 inline Vector4 vector4(float x, float y, float z, float w)
 {
 	Vector4 v;
@@ -23,16 +24,6 @@ inline Vector4 vector4(float x, float y, float z, float w)
 	return v;
 }
 
-inline Vector4 vector4(const Vector3& a, float w)
-{
-	Vector4 v;
-	v.x = a.x;
-	v.y = a.y;
-	v.z = a.z;
-	v.w = w;
-	return v;
-}
-
 inline Vector4& operator+=(Vector4& a,	const Vector4& b)
 {
 	a.x += b.x;