Просмотр исходного кода

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

Daniele Bartolini 10 лет назад
Родитель
Сommit
7e0a8a247d

+ 6 - 0
docs/lua_api.txt

@@ -78,6 +78,12 @@ Vector3
 	**angle** (a, b) : float
 		Returns the angle between the vectors *a* and *b*.
 
+	**max** (a, b) : Vector3
+		Returns a vector that contains the largest value for each component from *a* and *b*.
+
+	**min** (a, b) : Vector3
+		Returns a vector that contains the smallest value for each component from *a* and *b*.
+
 	**forward** () : Vector3
 
 	**backward** () : Vector3

+ 0 - 2
src/compilers/compile_options.h

@@ -11,8 +11,6 @@
 namespace crown
 {
 
-typedef Array<char> Buffer;
-
 struct CompileOptions
 {
 	CompileOptions(Filesystem& fs, File* out, const char* platform)

+ 1 - 1
src/core/containers/array.h

@@ -9,7 +9,7 @@
 #include "error.h"
 #include "macros.h"
 #include "allocator.h"
-#include <cstring> // memcpy
+#include <string.h> // memcpy
 
 namespace crown
 {

+ 2 - 0
src/core/containers/container_types.h

@@ -44,6 +44,8 @@ struct Array
 	ALLOCATOR_AWARE;
 };
 
+typedef Array<char> Buffer;
+
 /// Dynamic array of objects.
 /// @note
 /// Calls constructors and destructors, not suitable for performance-critical stuff.

+ 1 - 2
src/core/containers/queue.h

@@ -8,7 +8,7 @@
 #include "container_types.h"
 #include "array.h"
 #include "error.h"
-#include <cstring> // memcpy
+#include <string.h> // memcpy
 
 namespace crown
 {
@@ -136,7 +136,6 @@ namespace queue
 	inline void pop_back(Queue<T>& q)
 	{
 		CE_ASSERT(q._size > 0, "The queue is empty");
-
 		q._size--;
 	}
 

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

@@ -176,7 +176,6 @@ public:
 	/// Reads the JSON document from file @a f.
 	JSONParser(File& f);
 
-	typedef Array<char> Buffer;
 	JSONParser(Buffer& b);
 
 	~JSONParser();

+ 1 - 1
src/core/log.h

@@ -6,7 +6,7 @@
 #pragma once
 
 #include "config.h"
-#include <cstdarg>
+#include <stdarg.h>
 
 namespace crown
 {

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

@@ -149,6 +149,24 @@ inline float angle(const Vector2& a, const Vector2& b)
 	return acos(dot(a, b) / (length(a) * length(b)));
 }
 
+/// Returns a vector that contains the largest value for each component from @a a and @a b.
+inline Vector2 max(const Vector2& a, const Vector2& b)
+{
+	Vector2 v;
+	v.x = fmax(a.x, b.x);
+	v.y = fmax(a.y, b.y);
+	return v;
+}
+
+/// Returns a vector that contains the smallest value for each component from @a a and @a b.
+inline Vector2 min(const Vector2& a, const Vector2& b)
+{
+	Vector2 v;
+	v.x = fmin(a.x, b.x);
+	v.y = fmin(a.y, b.y);
+	return v;
+}
+
 /// Returns the pointer to the data of @a a.
 inline float* to_float_ptr(Vector2& a)
 {

+ 24 - 2
src/core/math/vector3.h

@@ -7,7 +7,6 @@
 
 #include "math_types.h"
 #include "math_utils.h"
-#include "vector2.h"
 #include "error.h"
 
 namespace crown
@@ -164,6 +163,26 @@ inline float angle(const Vector3& a, const Vector3& b)
 	return acos(dot(a, b) / (length(a) * length(b)));
 }
 
+/// Returns a vector that contains the largest value for each component from @a a and @a b.
+inline Vector3 max(const Vector3& a, const Vector3& b)
+{
+	Vector3 v;
+	v.x = fmax(a.x, b.x);
+	v.y = fmax(a.y, b.y);
+	v.z = fmax(a.z, b.z);
+	return v;
+}
+
+/// Returns a vector that contains the smallest value for each component from @a a and @a b.
+inline Vector3 min(const Vector3& a, const Vector3& b)
+{
+	Vector3 v;
+	v.x = fmin(a.x, b.x);
+	v.y = fmin(a.y, b.y);
+	v.z = fmin(a.z, b.z);
+	return v;
+}
+
 /// Returns the pointer to the data of @a a.
 inline float* to_float_ptr(Vector3& a)
 {
@@ -179,7 +198,10 @@ inline const float* to_float_ptr(const Vector3& a)
 /// Returns the Vector2 portion of @a a. (i.e. truncates z)
 inline Vector2 to_vector2(const Vector3& a)
 {
-	return vector2(a.x, a.y);
+	Vector2 v;
+	v.x = a.x;
+	v.y = a.y;
+	return v;
 }
 
 /// @}

+ 27 - 2
src/core/math/vector4.h

@@ -7,7 +7,6 @@
 
 #include "math_types.h"
 #include "math_utils.h"
-#include "vector3.h"
 #include "error.h"
 
 namespace crown
@@ -182,6 +181,28 @@ inline float angle(const Vector4& a, const Vector4& b)
 	return acos(dot(a, b) / (length(a) * length(b)));
 }
 
+/// Returns a vector that contains the largest value for each component from @a a and @a b.
+inline Vector4 max(const Vector4& a, const Vector4& b)
+{
+	Vector4 v;
+	v.x = fmax(a.x, b.x);
+	v.y = fmax(a.y, b.y);
+	v.z = fmax(a.z, b.z);
+	v.w = fmax(a.w, b.w);
+	return v;
+}
+
+/// Returns a vector that contains the smallest value for each component from @a a and @a b.
+inline Vector4 min(const Vector4& a, const Vector4& b)
+{
+	Vector4 v;
+	v.x = fmin(a.x, b.x);
+	v.y = fmin(a.y, b.y);
+	v.z = fmin(a.z, b.z);
+	v.w = fmin(a.w, b.w);
+	return v;
+}
+
 /// Returns the pointer to the data of @a a.
 inline float* to_float_ptr(Vector4& a)
 {
@@ -196,7 +217,11 @@ inline const float* to_float_ptr(const Vector4& a)
 
 inline Vector3 to_vector3(const Vector4& a)
 {
-	return vector3(a.x, a.y, a.z);
+	Vector3 v;
+	v.x = a.x;
+	v.y = a.y;
+	v.z = a.z;
+	return v;
 }
 
 /// @}

+ 0 - 1
src/core/profiler.cpp

@@ -14,7 +14,6 @@ namespace crown
 {
 namespace profiler_globals
 {
-	typedef Array<char> Buffer;
 	char _mem[sizeof(Buffer)];
 	Buffer* _buffer = NULL;
 

+ 1 - 1
src/core/strings/dynamic_string.h

@@ -11,8 +11,8 @@
 #include "array.h"
 #include "string_utils.h"
 #include "string_id.h"
+#include <string.h> // memmove
 #include <algorithm>
-#include <cstring>
 
 namespace crown
 {

+ 16 - 0
src/lua/lua_math.cpp

@@ -183,6 +183,20 @@ static int vector3_angle(lua_State* L)
 	return 1;
 }
 
+static int vector3_max(lua_State* L)
+{
+	LuaStack stack(L);
+	stack.push_vector3(max(stack.get_vector3(1), stack.get_vector3(2)));
+	return 1;
+}
+
+static int vector3_min(lua_State* L)
+{
+	LuaStack stack(L);
+	stack.push_vector3(min(stack.get_vector3(1), stack.get_vector3(2)));
+	return 1;
+}
+
 static int vector3_forward(lua_State* L)
 {
 	LuaStack stack(L);
@@ -852,6 +866,8 @@ void load_math(LuaEnvironment& env)
 	env.load_module_function("Vector3", "normalize",      vector3_normalize);
 	env.load_module_function("Vector3", "distance",       vector3_distance);
 	env.load_module_function("Vector3", "angle",          vector3_angle);
+	env.load_module_function("Vector3", "max",            vector3_max);
+	env.load_module_function("Vector3", "min",            vector3_min);
 	env.load_module_function("Vector3", "forward",        vector3_forward);
 	env.load_module_function("Vector3", "backward",       vector3_backward);
 	env.load_module_function("Vector3", "left",           vector3_left);

+ 4 - 3
src/resource/mesh_resource.cpp

@@ -12,6 +12,7 @@
 #include "vector3.h"
 #include "resource_manager.h"
 #include "compile_options.h"
+#include "vector2.h"
 
 namespace crown
 {
@@ -25,9 +26,9 @@ namespace mesh_resource
 
 		bool operator==(const MeshVertex& other)
 		{
-			return position == other.position &&
-					normal == other.normal &&
-					texcoord == other.texcoord;
+			return position == other.position
+				&& normal == other.normal
+				&& texcoord == other.texcoord;
 		}
 	};
 

+ 0 - 4
src/resource/sprite_resource.cpp

@@ -16,10 +16,6 @@
 #include "vector4.h"
 #include "resource_manager.h"
 #include "compile_options.h"
-#include <cfloat>
-#include <cstring>
-#include <inttypes.h>
-
 
 namespace crown
 {