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

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

Daniele Bartolini 10 лет назад
Родитель
Сommit
46a11e686d
7 измененных файлов с 68 добавлено и 27 удалено
  1. 3 0
      docs/lua_api.txt
  2. 4 4
      src/core/math/vector2.h
  3. 10 6
      src/core/math/vector3.h
  4. 8 7
      src/core/math/vector4.h
  5. 35 9
      src/core/os.h
  6. 0 1
      src/device.cpp
  7. 8 0
      src/lua/lua_math.cpp

+ 3 - 0
docs/lua_api.txt

@@ -146,6 +146,9 @@ Quaternion
 	**multiply_by_scalar** (a, k) : Quaternion
 		Multiplies the quaternion *a* by the scalar *k*.
 
+	**dot** (a, b) : float
+		Returns the dot product between quaternions *a* and *b*.
+
 	**length** (q) : float
 		Returns the length of *q*.
 

+ 4 - 4
src/core/math/vector2.h

@@ -45,10 +45,10 @@ inline Vector2& operator*=(Vector2& a, float k)
 /// Negates @a a and returns the result.
 inline Vector2 operator-(const Vector2& a)
 {
-	Vector2 res;
-	res.x = -a.x;
-	res.y = -a.y;
-	return res;
+	Vector2 v;
+	v.x = -a.x;
+	v.y = -a.y;
+	return v;
 }
 
 /// Adds the vector @a a to @a b and returns the result.

+ 10 - 6
src/core/math/vector3.h

@@ -49,11 +49,11 @@ inline Vector3& operator*=(Vector3& a, float k)
 /// Negates @a a and returns the result.
 inline Vector3 operator-(const Vector3& a)
 {
-	Vector3 res;
-	res.x = -a.x;
-	res.y = -a.y;
-	res.z = -a.z;
-	return res;
+	Vector3 v;
+	v.x = -a.x;
+	v.y = -a.y;
+	v.z = -a.z;
+	return v;
 }
 
 /// Adds the vector @a a to @a b and returns the result.
@@ -99,7 +99,11 @@ inline float dot(const Vector3& a, const Vector3& b)
 /// Returns the cross product between the vectors @a a and @a b.
 inline Vector3 cross(const Vector3& a, const Vector3& b)
 {
-	return vector3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
+	Vector3 v;
+	v.x = a.y * b.z - a.z * b.y;
+	v.y = a.z * b.x - a.x * b.z;
+	v.z = a.x * b.y - a.y * b.x;
+	return v;
 }
 
 /// Returns the squared length of @a a.

+ 8 - 7
src/core/math/vector4.h

@@ -63,12 +63,12 @@ inline Vector4& operator*=(Vector4& a, float k)
 /// Negates @a a and returns the result.
 inline Vector4 operator-(const Vector4& a)
 {
-	Vector4 res;
-	res.x = -a.x;
-	res.y = -a.y;
-	res.z = -a.z;
-	res.w = -a.w;
-	return res;
+	Vector4 v;
+	v.x = -a.x;
+	v.y = -a.y;
+	v.z = -a.z;
+	v.w = -a.w;
+	return v;
 }
 
 /// Adds the vector @a a to @a b and returns the result.
@@ -105,7 +105,8 @@ inline bool operator==(const Vector4& a, const Vector4& b)
 	return fequal(a.x, b.x)
 		&& fequal(a.y, b.y)
 		&& fequal(a.z, b.z)
-		&& fequal(a.w, b.w);
+		&& fequal(a.w, b.w)
+		;
 }
 
 /// Returns the dot product between the vectors @a a and @a b.

+ 35 - 9
src/core/os.h

@@ -86,6 +86,35 @@ namespace os
 #endif
 	}
 
+	/// Returns the last modification time of @a path.
+	inline uint64_t mtime(const char* path)
+	{
+#if CROWN_PLATFORM_POSIX
+		struct stat info;
+		memset(&info, 0, sizeof(struct stat));
+		int err = lstat(path, &info);
+		CE_ASSERT(err == 0, "lstat: errno = %d", errno);
+		CE_UNUSED(err);
+		return info.st_mtime;
+#elif CROWN_PLATFORM_WINDOWS
+		HANDLE hfile = CreateFile(path
+			, GENERIC_READ
+			, FILE_SHARE_READ
+			, NULL
+			, OPEN_EXISTING
+			, 0
+			, NULL
+			);
+		CE_ASSERT(hfile != INVALID_HANDLE_VALUE, "CreateFile: GetLastError = %d", GetLastError());
+		FILETIME ftwrite;
+		BOOL err = GetFileTime(hfile, NULL, NULL, &ftwrite);
+		CE_ASSERT(err != 0, "GetFileTime: GetLastError = %d", GetLastError());
+		CE_UNUSED(err);
+		CloseHandle(hfile);
+		return (uint64_t)((ftwrite.dwHighDateTime << 32) | ftwrite.dwLowDateTime);
+#endif
+	}
+
 	/// Creates a regular file.
 	inline void create_file(const char* path)
 	{
@@ -155,21 +184,18 @@ namespace os
 		struct dirent *entry;
 
 		if (!(dir = opendir(path)))
-		{
 			return;
-		}
 
 		while ((entry = readdir(dir)))
 		{
-			if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
-			{
-				continue;
-			}
+			const char* dname = entry->d_name;
 
-			DynamicString filename(default_allocator());
+			if (!strcmp(dname, ".") || !strcmp(dname, ".."))
+				continue;
 
-			filename = entry->d_name;
-			vector::push_back(files, filename);
+			TempAllocator512 ta;
+			DynamicString fname(dname, ta);
+			vector::push_back(files, fname);
 		}
 
 		closedir(dir);

+ 0 - 1
src/device.cpp

@@ -27,7 +27,6 @@
 #include "profiler.h"
 #include "console_server.h"
 #include "input_device.h"
-#include "profiler.h"
 
 #if CROWN_PLATFORM_ANDROID
 	#include "apk_filesystem.h"

+ 8 - 0
src/lua/lua_math.cpp

@@ -648,6 +648,13 @@ static int quaternion_identity(lua_State* L)
 	return 1;
 }
 
+static int quaternion_dot(lua_State* L)
+{
+	LuaStack stack(L);
+	stack.push_float(dot(stack.get_quaternion(1), stack.get_quaternion(2)));
+	return 1;
+}
+
 static int quaternion_length(lua_State* L)
 {
 	LuaStack stack(L);
@@ -973,6 +980,7 @@ void load_math(LuaEnvironment& env)
 	env.load_module_function("Quaternion", "identity",           quaternion_identity);
 	env.load_module_function("Quaternion", "multiply",           quaternion_multiply);
 	env.load_module_function("Quaternion", "multiply_by_scalar", quaternion_multiply_by_scalar);
+	env.load_module_function("Quaternion", "dot",                quaternion_dot);
 	env.load_module_function("Quaternion", "length",             quaternion_length);
 	env.load_module_function("Quaternion", "normalize",          quaternion_normalize);
 	env.load_module_function("Quaternion", "conjugate",          quaternion_conjugate);