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

Merge branch 'lua-env' into rendering-2

Conflicts:
	src/ResourceManager.cpp
Daniele Bartolini 12 лет назад
Родитель
Сommit
326399dc2a

+ 3 - 0
CMakeLists.txt

@@ -31,6 +31,7 @@ set (INCLUDES
 	${CMAKE_SOURCE_DIR}/src/network
 
 	${CMAKE_SOURCE_DIR}/game
+	${CMAKE_SOURCE_DIR}/lua
 )
 
 # always debug mode for now
@@ -104,3 +105,5 @@ if (CROWN_BUILD_TESTS)
 	add_subdirectory(tests)
 endif (CROWN_BUILD_TESTS)
 
+add_subdirectory(lua)
+

+ 41 - 0
game/Game.cpp

@@ -0,0 +1,41 @@
+#include "lua.hpp"
+#include "Device.h"
+#include "Game.h"
+
+
+namespace crown
+{
+
+lua_State* state;
+
+void init()
+{
+	state = luaL_newstate();
+	luaL_openlibs(state);
+
+	luaL_loadfile(state, "lua/lua/game.lua.script");
+
+	lua_getglobal(state, "init");
+
+	lua_pcall(state, 0, 0, 0);
+}
+
+void shutdown()
+{
+	lua_getglobal(state, "shutdown");
+
+	lua_pcall(state, 0, 0, 0);
+
+	lua_close(state);
+}
+
+void frame(float dt)
+{
+	lua_getglobal(state, "frame");
+
+	lua_pushnumber(state, dt);
+
+	lua_pcall(state, 1, 0, 0);
+}
+
+}

+ 33 - 0
lua/AccelerometerBinds.cpp

@@ -0,0 +1,33 @@
+#include "LuaStack.h"
+#include "Device.h"
+#include "LuaEnvironment.h"
+#include "Accelerometer.h"
+
+namespace crown
+{
+
+extern "C"
+{
+
+//-----------------------------------------------------------------------------
+int32_t accelerometer_orientation(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* orientation = next_vec3();
+	*orientation = device()->accelerometer()->orientation();
+
+	stack.push_vec3(orientation);
+
+	return 1;
+}
+
+} // extern "C"
+
+//-----------------------------------------------------------------------------
+void load_accelerometer(LuaEnvironment& env)
+{
+	env.load_module_function("Accelerometer", "orientation", accelerometer_orientation);
+}
+
+} // namespace crown

+ 31 - 0
lua/CMakeLists.txt

@@ -0,0 +1,31 @@
+cmake_minimum_required(VERSION 2.8)
+
+project(crown-lua)
+
+set(LUA_SRC
+	LuaStack.cpp
+	LuaEnvironment.cpp
+	Vec2Binds.cpp
+	Vec3Binds.cpp
+	Mat4Binds.cpp
+	QuatBinds.cpp
+	MathBinds.cpp
+
+	MouseBinds.cpp
+	KeyboardBinds.cpp
+	AccelerometerBinds.cpp
+)
+
+set(LUA_HEADERS
+	LuaStack.h
+	LuaEnvironment.h
+)
+
+add_definitions(-Wl,-E)
+add_library(crownlua SHARED ${LUA_SRC})
+target_link_libraries(crownlua crown)
+
+install (TARGETS crownlua DESTINATION lib/${CMAKE_PROJECT_NAME})
+
+install (FILES ${LUA_HEADERS} DESTINATION include/${CMAKE_PROJECT_NAME}/lua)
+

+ 156 - 0
lua/CameraBinds.cpp

@@ -0,0 +1,156 @@
+#include "Camera.h"
+
+namespace crown
+{
+
+extern "C"
+{
+
+Camera*				camera(const Vec3& position, float fov, float aspect);
+
+const Vec3&			camera_position(Camera* self);
+
+void				camera_set_position(Camera* self, const Vec3& position);
+
+const Vec3&			camera_look_at(Camera* self);
+
+void				camera_set_look_at(Camera* self, const Vec3& lookat);
+
+void				camera_set_rotation(Camera* self, const float x, const float y);
+
+const Vec3&			camera_up(Camera* self);
+
+float				camera_fov(Camera* self);
+
+void				camera_set_fov(Camera* self, float fov);
+
+float				camera_aspect(Camera* self);
+
+void				camera_set_aspect(Camera* self, float aspect);
+
+float				camera_near_clip_distance(Camera* self);
+
+void				camera_set_near_clip_distance(Camera* self, float near);
+
+float				camera_far_clip_distance(Camera* self);
+
+void				camera_set_far_clip_distance(Camera* self, float far);
+
+const Mat4&			camera_projection_matrix(Camera* self);
+
+const Mat4&			camera_view_matrix(Camera* self);
+
+void				camera_move_forward(Camera* self, float meters);
+
+void				camera_move_backward(Camera* self, float meters);
+
+void				camera_strafe_left(Camera* self, float meters);
+
+void				camera_strafe_right(Camera* self, float meters);
+}
+
+Camera* camera(const Vec3& position, float fov, float aspect)
+{
+	return new Camera(position, fov, aspect);
+}
+
+const Vec3& camera_position(Camera* self)
+{
+	return self->position();
+}
+
+void camera_set_position(Camera* self, const Vec3& position)
+{
+	self->set_position(position);
+}
+
+const Vec3& camera_look_at(Camera* self)
+{
+	return self->look_at();
+}
+
+void camera_set_look_at(Camera* self, const Vec3& lookat)
+{
+	self->set_look_at(lookat);
+}
+
+void camera_set_rotation(Camera* self, const float x, const float y)
+{
+	self->set_rotation(x, y);
+}
+
+const Vec3& camera_up(Camera* self)
+{
+	return self->up();
+}
+
+float camera_fov(Camera* self)
+{
+	return self->fov();
+}
+
+void camera_set_fov(Camera* self, float fov)
+{
+	self->set_fov(fov);
+}
+
+float camera_aspect(Camera* self)
+{
+	return self->aspect();
+}
+
+void camera_set_aspect(Camera* self, float aspect)
+{
+	self->set_aspect(aspect);
+}
+
+float camera_near_clip_distance(Camera* self)
+{
+	return self->near_clip_distance();
+}
+
+void camera_set_near_clip_distance(Camera* self, float near)
+{
+	self->set_near_clip_distance(near);
+}
+
+float camera_far_clip_distance(Camera* self)
+{
+	return self->far_clip_distance();
+}
+
+void camera_set_far_clip_distance(Camera* self, float far)
+{
+	self->set_far_clip_distance(far);
+}
+
+const Mat4& camera_projection_matrix(Camera* self)
+{
+	return self->projection_matrix();
+}
+
+const Mat4& camera_view_matrix(Camera* self)
+{
+	return self->view_matrix();
+}
+
+void camera_move_forward(Camera* self, float meters)
+{
+	self->move_forward(meters);
+}
+
+void camera_move_backward(Camera* self, float meters)
+{
+	self->move_backward(meters);
+}
+
+void camera_strafe_left(Camera* self, float meters)
+{
+	self->strafe_left(meters);
+}
+
+void camera_strafe_right(Camera* self, float meters)
+{
+	self->strafe_right(meters);
+}
+} // namespace crown

+ 54 - 0
lua/KeyboardBinds.cpp

@@ -0,0 +1,54 @@
+#include "LuaStack.h"
+#include "Device.h"
+#include "LuaEnvironment.h"
+#include "Keyboard.h"
+
+namespace crown
+{
+
+extern "C"
+{
+
+int32_t keyboard_modifier_pressed(lua_State* L)
+{
+	LuaStack stack(L);
+
+	int32_t modifier = stack.get_int(1);
+
+	stack.push_bool(device()->keyboard()->modifier_pressed((ModifierKey) modifier));
+
+	return 1;
+}
+
+int32_t keyboard_key_pressed(lua_State* L)
+{
+	LuaStack stack(L);
+
+	int32_t key = stack.get_int(1);
+
+	stack.push_bool(device()->keyboard()->key_pressed((KeyCode) key));
+
+	return 1;
+}
+
+int32_t keyboard_key_released(lua_State* L)
+{
+	LuaStack stack(L);
+
+	int32_t key = stack.get_int(1);
+
+	stack.push_bool(device()->keyboard()->key_released((KeyCode) key));
+
+	return 1;
+}
+
+} // extern "C"
+
+void load_keyboard(LuaEnvironment& env)
+{
+	env.load_module_function("Keyboard", "modifier_pressed",	keyboard_modifier_pressed);
+	env.load_module_function("Keyboard", "key_pressed",			keyboard_key_pressed);
+	env.load_module_function("Keyboard", "key_released",		keyboard_key_released);
+}
+
+} // namespace crown

+ 46 - 0
lua/LuaEnvironment.cpp

@@ -0,0 +1,46 @@
+#include "LuaEnvironment.h"
+
+namespace crown
+{
+
+LuaEnvironment::LuaEnvironment(lua_State* L) :
+	m_state(L)
+{
+
+}
+
+//-----------------------------------------------------------
+void LuaEnvironment::load_module_function(const char* module, const char* name, const lua_CFunction func)
+{
+	luaL_Reg entry[2];
+
+	entry[0].name = name;
+	entry[0].func = func;
+
+	entry[1].name = NULL;
+	entry[1].func = NULL;
+
+	luaL_register(m_state, module, entry);
+}
+
+extern "C"
+{
+	int32_t luaopen_libcrownlua(lua_State* L)
+	{
+		LuaEnvironment env(L);
+
+		load_vec2(env);
+		load_vec3(env);
+		load_mat4(env);
+		load_quat(env);
+		load_math(env);
+
+		load_mouse(env);
+		load_keyboard(env);
+		load_accelerometer(env);
+
+		return 1;
+	}
+}
+
+} // namespace crown

+ 44 - 0
lua/LuaEnvironment.h

@@ -0,0 +1,44 @@
+#pragma once
+
+#include "lua.hpp"
+#include "Types.h"
+
+namespace crown
+{
+
+class LuaEnvironment
+{
+
+public:
+	/// Constructor
+					LuaEnvironment(lua_State* L);
+	/// Load a function to proper module
+	void			load_module_function(const char* module, const char* name, const lua_CFunction func);
+	/// Create library based on each module which will be opened by luaopen_*
+	void			create_module_library();
+
+private:
+
+	lua_State*		m_state;
+};
+
+extern "C"
+{
+	int32_t luaopen_libcrownlua(lua_State* L);
+}
+
+void load_vec2(LuaEnvironment& env);
+void load_vec3(LuaEnvironment& env);
+void load_mat4(LuaEnvironment& env);
+void load_quat(LuaEnvironment& env);
+void load_math(LuaEnvironment& env);
+
+void load_mouse(LuaEnvironment& env);
+void load_keyboard(LuaEnvironment& env);
+void load_touch(LuaEnvironment& env);
+void load_accelerometer(LuaEnvironment& env);
+
+void load_camera(LuaEnvironment& env);
+
+
+} // namespace crown

+ 189 - 0
lua/LuaStack.cpp

@@ -0,0 +1,189 @@
+#include "LuaStack.h"
+#include "Assert.h"
+
+namespace crown
+{
+
+static const int32_t 	LUA_VEC2_BUFFER_SIZE = 4096;
+static Vec2 			vec2_buffer[LUA_VEC2_BUFFER_SIZE];
+static uint32_t 		vec2_used = 0;
+
+static const int32_t 	LUA_VEC3_BUFFER_SIZE = 4096;
+static Vec3 			vec3_buffer[LUA_VEC3_BUFFER_SIZE];
+static uint32_t 		vec3_used = 0;
+
+static const int32_t 	LUA_MAT4_BUFFER_SIZE = 4096;
+static Mat4 			mat4_buffer[LUA_MAT4_BUFFER_SIZE];
+static uint32_t 		mat4_used = 0;
+
+static const int32_t 	LUA_QUAT_BUFFER_SIZE = 4096;
+static Quat 			quat_buffer[LUA_QUAT_BUFFER_SIZE];
+static uint32_t 		quat_used = 0;
+
+//-----------------------------------------------------------------------------
+Vec2* next_vec2()
+{
+	ce_assert(vec2_used < LUA_VEC2_BUFFER_SIZE, "Maximum number of Vec2 reached");
+
+	return &vec2_buffer[vec2_used++];
+}
+
+//-----------------------------------------------------------------------------
+Vec3* next_vec3()
+{
+	ce_assert(vec3_used < LUA_VEC3_BUFFER_SIZE, "Maximum number of Vec3 reached");
+
+	return &vec3_buffer[vec3_used++];
+}
+
+//-----------------------------------------------------------------------------
+Mat4* next_mat4()
+{
+	ce_assert(mat4_used < LUA_MAT4_BUFFER_SIZE, "Maximum number of Mat4 reached");
+
+	return &mat4_buffer[mat4_used++];
+}
+
+//-----------------------------------------------------------------------------
+Quat* next_quat()
+{
+	ce_assert(quat_used < LUA_QUAT_BUFFER_SIZE, "Maximum number of Quat reached");
+
+	return &quat_buffer[quat_used++];
+}
+
+//-----------------------------------------------------------------------------	
+LuaStack::LuaStack(lua_State* L)
+{
+	m_state = L;
+}
+
+//-----------------------------------------------------------------------------
+void LuaStack::push_bool(bool value)
+{
+	lua_pushboolean(m_state, value);
+}
+
+//-----------------------------------------------------------------------------
+void LuaStack::push_int(int32_t value)
+{
+	lua_pushinteger(m_state, value);
+}
+
+//-----------------------------------------------------------------------------
+void LuaStack::push_float(float value)
+{
+	lua_pushnumber(m_state, value);
+}
+
+//-----------------------------------------------------------------------------
+void LuaStack::push_string(const char* str, size_t len)
+{
+	lua_pushlstring(m_state, str, len);
+}
+
+//-----------------------------------------------------------------------------
+void LuaStack::push_vec2(Vec2* v)
+{
+	ce_assert(v >= &vec2_buffer[0] && v <= &vec2_buffer[LUA_VEC2_BUFFER_SIZE-1], "Vec2 type error");
+
+	lua_pushlightuserdata(m_state, v);
+}
+
+//-----------------------------------------------------------------------------
+void LuaStack::push_vec3(Vec3* v)
+{
+	ce_assert(v >= &vec3_buffer[0] && v <= &vec3_buffer[LUA_VEC3_BUFFER_SIZE-1], "Vec3 type error");
+
+	lua_pushlightuserdata(m_state, v);
+}
+
+//-----------------------------------------------------------------------------
+void LuaStack::push_mat4(Mat4* m)
+{
+	ce_assert(m >= &mat4_buffer[0] && m <= &mat4_buffer[LUA_MAT4_BUFFER_SIZE-1], "Mat4 type error");
+
+	lua_pushlightuserdata(m_state, m);
+}
+
+//-----------------------------------------------------------------------------
+void LuaStack::push_quat(Quat* q)
+{
+	ce_assert(q >= &quat_buffer[0] && q <= &quat_buffer[LUA_MAT4_BUFFER_SIZE-1], "Quat type error");
+
+	lua_pushlightuserdata(m_state, q);
+}
+
+//-----------------------------------------------------------------------------
+bool LuaStack::get_bool(int32_t index)
+{
+	return (bool) luaL_checkinteger(m_state, index);
+}
+
+//-----------------------------------------------------------------------------
+int32_t LuaStack::get_int(int32_t index)
+{
+	return luaL_checkinteger(m_state, index);
+}
+
+//-----------------------------------------------------------------------------
+float LuaStack::get_float(int32_t index)
+{
+	return luaL_checknumber(m_state, index);
+}
+
+//-----------------------------------------------------------------------------
+const char* LuaStack::get_string(int32_t index)
+{
+	return luaL_checkstring(m_state, index);
+}
+
+//-----------------------------------------------------------------------------
+Vec2* LuaStack::get_vec2(int32_t index)
+{
+	ce_assert(lua_islightuserdata(m_state, index), "Not a lightuserdata object");
+
+	Vec2* v = (Vec2*)lua_touserdata(m_state, index);
+
+	ce_assert(v >= &vec2_buffer[0] && v <= &vec2_buffer[LUA_VEC2_BUFFER_SIZE-1], "Vec2 type error");
+
+	return v;
+}
+
+//-----------------------------------------------------------------------------
+Vec3* LuaStack::get_vec3(int32_t index)
+{
+	ce_assert(lua_islightuserdata(m_state, index), "Not a lightuserdata object");
+
+	Vec3* v = (Vec3*)lua_touserdata(m_state, index);
+
+	ce_assert(v >= &vec3_buffer[0] && v <= &vec3_buffer[LUA_VEC3_BUFFER_SIZE-1], "Vec3 type error");
+
+	return v;
+}
+
+//-----------------------------------------------------------------------------
+Mat4* LuaStack::get_mat4(int32_t index)
+{
+	ce_assert(lua_islightuserdata(m_state, index), "Not a lightuserdata object");
+
+	Mat4* m = (Mat4*)lua_touserdata(m_state, index);
+
+	ce_assert(m >= &mat4_buffer[0] && m <= &mat4_buffer[LUA_MAT4_BUFFER_SIZE-1], "Mat4 type error");
+
+	return m;
+}
+
+//-----------------------------------------------------------------------------
+Quat* LuaStack::get_quat(int32_t index)
+{
+	ce_assert(lua_islightuserdata(m_state, index), "Not a lightuserdata object");
+
+	Quat* q = (Quat*)lua_touserdata(m_state, index);
+
+	ce_assert(q >= &quat_buffer[0] && q <= &quat_buffer[LUA_QUAT_BUFFER_SIZE-1], "Quat type error");
+
+	return q;
+}
+
+} // namespace crown

+ 62 - 0
lua/LuaStack.h

@@ -0,0 +1,62 @@
+#pragma once
+
+#include "lua.hpp"
+#include "Types.h"
+#include "Vec2.h"
+#include "Vec3.h"
+#include "Mat4.h"
+#include "Quat.h"
+
+namespace crown
+{
+
+Vec2* next_vec2();
+Vec3* next_vec3();
+
+Mat4* next_mat4();
+Quat* next_quat();
+
+class LuaStack
+{
+public:
+
+							LuaStack(lua_State* L);
+
+	void					push_bool(bool value);
+
+	void					push_int(int32_t value);
+
+	void 					push_float(float value);
+
+	void 					push_string(const char* str, size_t len);
+
+	void					push_vec2(Vec2* v);
+
+	void					push_vec3(Vec3* v);
+
+	void					push_mat4(Mat4* m);
+
+	void					push_quat(Quat* q);
+
+	bool 					get_bool(int32_t index);
+
+	int32_t					get_int(int32_t index);
+
+	float 					get_float(int32_t index);
+
+	const char*				get_string(int32_t index);
+
+	Vec2*					get_vec2(int32_t index);
+
+	Vec3*					get_vec3(int32_t index);
+
+	Mat4*					get_mat4(int32_t index);
+
+	Quat*					get_quat(int32_t index);
+
+private:
+
+	lua_State* 				m_state;
+};
+
+} // namespace crown

+ 444 - 0
lua/Mat4Binds.cpp

@@ -0,0 +1,444 @@
+#include "Mat4.h"
+#include "Vec3.h"
+#include "LuaStack.h"
+#include "LuaEnvironment.h"
+#include "OS.h"
+
+namespace crown
+{
+
+extern "C"
+{
+
+int32_t mat4(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float m0 = stack.get_float(1);
+	float m1 = stack.get_float(2);
+	float m2 = stack.get_float(3);
+	float m4 = stack.get_float(4);	
+	float m5 = stack.get_float(5);
+	float m6 = stack.get_float(6);	
+	float m8 = stack.get_float(7);
+	float m9 = stack.get_float(8);
+	float m10 = stack.get_float(9);
+
+	Mat4* mat = next_mat4();
+
+	mat->m[0] = m0;
+	mat->m[1] = m1;
+	mat->m[2] = m2;
+	mat->m[4] = m4;
+	mat->m[5] = m5;
+	mat->m[6] = m6;
+	mat->m[8] = m8;
+	mat->m[9] = m9;
+	mat->m[10] = m10;
+
+	stack.push_mat4(mat);
+
+	return 1;
+}
+					
+int32_t mat4_add(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	Mat4* b = stack.get_mat4(2);
+
+	*a += *b;
+
+	stack.push_mat4(a);
+
+	return 1;
+}
+
+int32_t mat4_subtract(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = (Mat4*)stack.get_mat4(1);
+	Mat4* b = (Mat4*)stack.get_mat4(2);
+
+	*a -= *b;
+
+	stack.push_mat4(a);
+
+	return 1;
+}
+
+int32_t mat4_multiply(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	Mat4* b = stack.get_mat4(2);
+
+	*a *= *b;
+
+	stack.push_mat4(a);
+
+	return 1;
+}	
+
+int32_t mat4_multiply_by_scalar(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = (Mat4*)stack.get_mat4(1);
+	float k = stack.get_float(2);
+
+	*a *= k;
+
+	stack.push_mat4(a);
+
+	return 1;
+}
+
+int32_t mat4_divide_by_scalar(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = (Mat4*)stack.get_mat4(1);
+	float k = stack.get_float(2);
+
+	*a /= k;
+
+	stack.push_mat4(a);
+
+	return 1;
+}
+
+int32_t mat4_build_rotation_x(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = (Mat4*)stack.get_mat4(1);
+	float k = stack.get_float(2);
+
+	a->build_rotation_x(k);
+
+	return 0;
+}
+
+int32_t mat4_build_rotation_y(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	float k = stack.get_float(2);
+
+	a->build_rotation_y(k);
+
+	return 0;
+}
+
+int32_t mat4_build_rotation_z(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = (Mat4*)stack.get_mat4(1);
+	float k = stack.get_float(2);
+
+	a->build_rotation_z(k);
+
+	return 0;
+}
+
+int32_t mat4_build_rotation(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = (Mat4*)stack.get_mat4(1);
+	Vec3* d = (Vec3*)stack.get_vec3(2);
+	float k = stack.get_float(3);
+
+	a->build_rotation(*d, k);
+
+	return 0;
+}
+
+int32_t mat4_build_projection_perspective_rh(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	float fovy = stack.get_float(2);
+	float aspect = stack.get_float(3);
+	float near = stack.get_float(4);
+	float far = stack.get_float(5);
+
+	a->build_projection_perspective_rh(fovy, aspect, near, far);
+
+	return 0;
+}
+
+int32_t mat4_build_projection_perspective_lh(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	float fovy = stack.get_float(2);
+	float aspect = stack.get_float(3);
+	float near = stack.get_float(4);
+	float far = stack.get_float(5);
+
+	a->build_projection_perspective_lh(fovy, aspect, near, far);
+
+	return 0;
+}
+
+int32_t mat4_build_projection_ortho_rh(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	float width = stack.get_float(2);
+	float height = stack.get_float(3);
+	float near = stack.get_float(4);
+	float far = stack.get_float(5);
+
+	a->build_projection_ortho_rh(width, height, near, far);
+
+	return 0;
+}
+
+int32_t mat4_build_projection_ortho_lh(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	float width = stack.get_float(2);
+	float height = stack.get_float(3);
+	float near = stack.get_float(4);
+	float far = stack.get_float(5);
+
+	a->build_projection_ortho_lh(width, height, near, far);
+
+	return 0;
+}
+
+int32_t mat4_build_projection_ortho_2d_rh(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	float width = stack.get_float(2);
+	float height = stack.get_float(3);
+	float near = stack.get_float(4);
+	float far = stack.get_float(5);
+
+	a->build_projection_ortho_2d_rh(width, height, near, far);
+
+	return 0;
+}
+
+int32_t mat4_build_look_at_rh(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	Vec3* pos = stack.get_vec3(2);
+	Vec3* target = stack.get_vec3(3);
+	Vec3* up = stack.get_vec3(4);
+
+	a->build_look_at_rh(*pos, *target, *up);
+
+	return 0;
+}
+
+int32_t mat4_build_look_at_lh(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	Vec3* pos = stack.get_vec3(2);
+	Vec3* target = stack.get_vec3(3);
+	Vec3* up = stack.get_vec3(4);
+
+	a->build_look_at_lh(*pos, *target, *up);
+
+	return 0;
+}
+
+int32_t mat4_build_viewpoint_billboard(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	Vec3* pos = stack.get_vec3(2);
+	Vec3* target = stack.get_vec3(3);
+	Vec3* up = stack.get_vec3(4);
+
+	a->build_viewpoint_billboard(*pos, *target, *up);
+
+	return 0;
+}
+
+int32_t mat4_build_axis_billboard(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	Vec3* pos = stack.get_vec3(2);
+	Vec3* target = stack.get_vec3(3);
+	Vec3* up = stack.get_vec3(4);
+
+	a->build_axis_billboard(*pos, *target, *up);
+
+	return 0;
+}
+
+int32_t mat4_transpose(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+
+	a->transpose();
+
+	stack.push_mat4(a);
+
+	return 1;
+}
+
+int32_t mat4_determinant(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+
+	stack.push_float(a->get_determinant());
+
+	return 1;
+}
+
+int32_t mat4_invert(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+
+	a->invert();
+
+	stack.push_mat4(a);
+
+	return 1;
+}
+
+int32_t mat4_load_identity(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+
+	a->load_identity();
+
+	return 0;
+}
+
+int32_t mat4_get_translation(lua_State* L)
+{	
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+
+	Vec3* translation = next_vec3();
+	*translation = a->get_translation();
+
+	stack.push_vec3(translation);
+
+	return 1;
+}
+
+int32_t mat4_set_translation(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	Vec3* trans = stack.get_vec3(2);
+
+	a->set_translation(*trans);
+
+	return 0;
+}
+
+int32_t mat4_get_scale(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+
+	Vec3* scale = next_vec3();
+	*scale = a->get_scale();
+
+	stack.push_vec3(scale);
+
+	return 1;
+}
+
+int32_t mat4_set_scale(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+	Vec3* scale = stack.get_vec3(2);
+
+	a->set_scale(*scale);
+
+	return 0;
+}
+
+int32_t mat4_print(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Mat4* a = stack.get_mat4(1);
+
+	os::printf("|%.1f|%.1f|%.1f|%.1f|\n", a->m[0], a->m[4], a->m[8], a->m[12]);
+	os::printf("|%.1f|%.1f|%.1f|%.1f|\n", a->m[1], a->m[5], a->m[9], a->m[13]);
+	os::printf("|%.1f|%.1f|%.1f|%.1f|\n", a->m[2], a->m[6], a->m[10], a->m[14]);
+	os::printf("|%.1f|%.1f|%.1f|%.1f|\n", a->m[3], a->m[7], a->m[11], a->m[15]);
+
+	return 0;
+}
+
+} //extern "C"
+
+void load_mat4(LuaEnvironment& env)
+{
+	env.load_module_function("Mat4", "new", 							mat4);
+	env.load_module_function("Mat4", "add", 							mat4_add);
+	env.load_module_function("Mat4", "sub", 							mat4_subtract);
+	env.load_module_function("Mat4", "mul", 							mat4_multiply);
+	env.load_module_function("Mat4", "muls", 							mat4_multiply_by_scalar);
+	env.load_module_function("Mat4", "divs", 							mat4_divide_by_scalar);
+	env.load_module_function("Mat4", "build_rotation_x", 				mat4_build_rotation_x);
+	env.load_module_function("Mat4", "build_rotation_y", 				mat4_build_rotation_y);
+	env.load_module_function("Mat4", "build_rotation_z", 				mat4_build_rotation_z);
+	env.load_module_function("Mat4", "build_rotation", 					mat4_build_rotation);
+	env.load_module_function("Mat4", "build_projection_perspective_rh", mat4_build_projection_perspective_rh);
+	env.load_module_function("Mat4", "build_projection_perspective_lh", mat4_build_projection_perspective_lh);
+	env.load_module_function("Mat4", "build_projection_ortho_rh", 		mat4_build_projection_ortho_rh);
+	env.load_module_function("Mat4", "build_projection_ortho_lh", 		mat4_build_projection_ortho_lh);
+	env.load_module_function("Mat4", "build_projection_ortho_2d_rh", 	mat4_build_projection_ortho_2d_rh);
+	env.load_module_function("Mat4", "build_look_at_rh", 				mat4_build_look_at_rh);
+	env.load_module_function("Mat4", "build_look_at_lh", 				mat4_build_look_at_rh);
+	env.load_module_function("Mat4", "build_viewpoint_billboard", 		mat4_build_viewpoint_billboard);
+	env.load_module_function("Mat4", "build_axis_billboard", 			mat4_build_axis_billboard);
+	env.load_module_function("Mat4", "transpose", 						mat4_transpose);
+	env.load_module_function("Mat4", "determinant", 					mat4_determinant);
+	env.load_module_function("Mat4", "invert", 							mat4_invert);
+	env.load_module_function("Mat4", "load_identity", 					mat4_load_identity);
+	env.load_module_function("Mat4", "get_translation", 				mat4_get_translation);
+	env.load_module_function("Mat4", "set_translation", 				mat4_set_translation);
+	env.load_module_function("Mat4", "get_scale", 						mat4_get_scale);
+	env.load_module_function("Mat4", "set_scale", 						mat4_set_scale);
+	env.load_module_function("Mat4", "print", 							mat4_print);
+
+}
+
+
+} //namespace crown

+ 211 - 0
lua/MathBinds.cpp

@@ -0,0 +1,211 @@
+#include "MathUtils.h"
+#include "LuaStack.h"
+#include "LuaEnvironment.h"
+
+namespace crown
+{
+
+extern "C"
+{
+
+int32_t math_deg_to_rad(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float deg = stack.get_float(1);
+
+	stack.push_float(math::deg_to_rad(deg));
+
+	return 1;
+}
+
+int32_t math_rad_to_deg(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float rad = stack.get_float(1);
+
+	stack.push_float(math::rad_to_deg(rad));
+
+	return 1;
+}
+
+int32_t math_next_pow_2(lua_State* L)
+{
+	LuaStack stack(L);
+
+	uint32_t x = stack.get_int(1);
+
+	stack.push_int(math::next_pow_2(x));
+
+	return 1;
+}
+
+int32_t math_is_pow_2(lua_State* L)
+{
+	LuaStack stack(L);
+
+	uint32_t x = stack.get_int(1);
+
+	stack.push_bool(math::is_pow_2(x));
+
+	return 1;
+}
+
+int32_t math_ceil(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+
+	stack.push_float(math::ceil(x));
+
+	return 1;
+}
+
+int32_t math_floor(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+
+	stack.push_float(math::floor(x));
+
+	return 1;
+}
+
+int32_t math_sqrt(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+
+	stack.push_float(math::sqrt(x));
+
+	return 1;
+}
+
+int32_t math_inv_sqrt(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+
+	stack.push_float(math::inv_sqrt(x));
+
+	return 1;
+}
+
+int32_t math_sin(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+
+	stack.push_float(math::sin(x));
+
+	return 1;
+}
+
+int32_t math_cos(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+
+	stack.push_float(math::cos(x));
+
+	return 1;
+}
+
+int32_t math_asin(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+
+	stack.push_float(math::asin(x));
+
+	return 1;
+}
+
+int32_t math_acos(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+
+	stack.push_float(math::acos(x));
+
+	return 1;
+}
+
+int32_t math_tan(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+
+	stack.push_float(math::tan(x));
+
+	return 1;
+}
+
+int32_t math_atan2(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+	float y = stack.get_float(2);
+
+	stack.push_float(math::atan2(x, y));
+
+	return 1;
+}
+
+int32_t math_abs(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+
+	stack.push_float(math::abs(x));
+
+	return 1;
+}
+
+int32_t math_fmod(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+	float y = stack.get_float(2);
+
+	stack.push_float(math::fmod(x, y));
+
+	return 1;
+}
+
+} // extern "C"
+
+void load_math(LuaEnvironment& env)
+{
+	env.load_module_function("Math", "deg_to_rad", 	math_deg_to_rad);
+	env.load_module_function("Math", "rad_to_deg", 	math_rad_to_deg);
+	env.load_module_function("Math", "next_pow_2", 	math_next_pow_2);
+	env.load_module_function("Math", "is_pow_2", 	math_is_pow_2);
+	env.load_module_function("Math", "ceil", 		math_ceil);
+	env.load_module_function("Math", "floor", 		math_floor);
+	env.load_module_function("Math", "sqrt", 		math_sqrt);
+	env.load_module_function("Math", "inv_sqrt", 	math_inv_sqrt);
+	env.load_module_function("Math", "sin", 		math_sin);
+	env.load_module_function("Math", "cos", 		math_cos);
+	env.load_module_function("Math", "asin",	 	math_asin);
+	env.load_module_function("Math", "acos", 		math_acos);
+	env.load_module_function("Math", "tan", 		math_tan);
+	env.load_module_function("Math", "atan2", 		math_atan2);
+	env.load_module_function("Math", "abs", 		math_abs);
+	env.load_module_function("Math", "fmod", 		math_fmod);
+}
+
+} // namespace crown

+ 101 - 0
lua/MouseBinds.cpp

@@ -0,0 +1,101 @@
+#include "LuaStack.h"
+#include "Device.h"
+#include "LuaEnvironment.h"
+#include "Mouse.h"
+#include "Log.h"
+
+namespace crown
+{
+
+extern "C"
+{
+
+//-----------------------------------------------------------------------------
+int32_t mouse_button_pressed(lua_State* L)
+{
+	LuaStack stack(L);
+
+	int32_t button = stack.get_int(1);
+
+	stack.push_bool(device()->mouse()->button_pressed((MouseButton) button));
+
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+int32_t mouse_button_released(lua_State* L)
+{
+	LuaStack stack(L);
+
+	int32_t button = stack.get_int(1);
+
+	stack.push_bool(device()->mouse()->button_released((MouseButton) button));
+
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+int32_t mouse_cursor_xy(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* xy = next_vec2();
+
+	*xy = device()->mouse()->cursor_xy();
+
+	stack.push_vec2(xy);
+
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+int32_t mouse_set_cursor_xy(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* xy = stack.get_vec2(1);
+
+	device()->mouse()->set_cursor_xy(*xy);
+
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+int32_t mouse_cursor_relative_xy(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* xy = next_vec2();
+	*xy = device()->mouse()->cursor_relative_xy();
+
+	stack.push_vec2(xy);
+
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+int32_t mouse_set_cursor_relative_xy(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* xy = (Vec2*) stack.get_vec2(1);
+
+	device()->mouse()->set_cursor_relative_xy(*xy);
+
+	return 0;
+}
+
+} // extern "C"
+
+//-----------------------------------------------------------------------------
+void load_mouse(LuaEnvironment& env)
+{
+	env.load_module_function("Mouse", "button_pressed",			mouse_button_pressed);
+	env.load_module_function("Mouse", "button_released",		mouse_button_released);
+	env.load_module_function("Mouse", "cursor_xy",				mouse_cursor_xy);
+	env.load_module_function("Mouse", "set_cursor_xy",			mouse_set_cursor_xy);
+	env.load_module_function("Mouse", "cursor_relative_xy",		mouse_cursor_relative_xy);
+	env.load_module_function("Mouse", "set_cursor_relative_xy",	mouse_set_cursor_relative_xy);
+}
+
+} // namespace crown

+ 148 - 0
lua/QuatBinds.cpp

@@ -0,0 +1,148 @@
+#include "Quat.h"
+#include "Vec3.h"
+#include "LuaStack.h"
+#include "LuaEnvironment.h"
+
+
+namespace crown
+{
+
+extern "C"
+{
+
+int32_t quat(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float w = stack.get_float(1);
+	Vec3* v = stack.get_vec3(2);
+
+	Quat* quat = next_quat();
+
+	quat->w = w;
+	quat->v = *v;
+
+	stack.push_quat(quat);
+
+	return 1;
+}
+
+int32_t quat_negate(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Quat* q = stack.get_quat(1);
+
+	q->negate();
+
+	return 0;
+}
+
+int32_t quat_load_identity(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Quat* q = stack.get_quat(1);
+
+	q->load_identity();
+
+	return 0;
+}
+
+int32_t quat_length(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Quat* q = stack.get_quat(1);
+
+	stack.push_float(q->length());
+
+	return 1;
+}
+
+int32_t quat_conjugate(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Quat* q = stack.get_quat(1);
+
+	Quat* conjugate = next_quat();
+	*conjugate = q->get_conjugate();
+
+	stack.push_quat(conjugate);
+
+	return 1;
+}
+
+int32_t quat_inverse(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Quat* q = stack.get_quat(1);
+
+	Quat* inverse = next_quat();
+	*inverse = q->get_inverse();
+
+	stack.push_quat(inverse);
+
+	return 1;
+}
+
+int32_t quat_cross(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Quat* q1 = stack.get_quat(1);
+	Quat* q2 = stack.get_quat(2);
+
+	*q1 = (*q1) * (*q2);
+
+	stack.push_quat(q1);
+
+	return 1;
+}
+
+int32_t quat_multiply(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Quat* q = stack.get_quat(1);
+	float k = stack.get_float(2);
+
+	*q = (*q) * k;
+
+	stack.push_quat(q);
+
+	return 1;
+}
+
+int32_t quat_power(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Quat* q = stack.get_quat(1);
+	float k = stack.get_float(2);
+
+	q->power(k);
+
+	stack.push_quat(q);
+
+	return 1;
+}
+
+} // extern "C"
+
+void load_quat(LuaEnvironment& env)
+{
+	env.load_module_function("Quat", "new", quat);
+	env.load_module_function("Quat", "negate", quat_negate);
+	env.load_module_function("Quat", "load_identity", quat_load_identity);
+	env.load_module_function("Quat", "length", quat_length);
+	env.load_module_function("Quat", "conjugate", quat_conjugate);
+	env.load_module_function("Quat", "inverse", quat_inverse);
+	env.load_module_function("Quat", "cross", quat_cross);
+	env.load_module_function("Quat", "mul", quat_multiply);
+	env.load_module_function("Quat", "pow", quat_power);
+}
+
+} //namespace crown

+ 0 - 0
lua/TouchBinds.cpp


+ 268 - 0
lua/Vec2Binds.cpp

@@ -0,0 +1,268 @@
+#include "Vec2.h"
+#include "LuaStack.h"
+#include "LuaEnvironment.h"
+
+
+namespace crown
+{
+
+extern "C"
+{
+
+int32_t	vec2(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+	float y = stack.get_float(2);
+
+	Vec2* vec = next_vec2();
+
+	vec->x = x;
+	vec->y = y;
+
+	stack.push_vec2(vec);
+
+	return 1;
+}
+
+int32_t vec2_values(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* a = (Vec2*)stack.get_vec2(1);
+
+	float x = a->x;
+	float y = a->y;
+
+	stack.push_float(x);
+	stack.push_float(y);
+
+	return 2;
+}
+
+
+int32_t vec2_add(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* a = (Vec2*)stack.get_vec2(1);
+	Vec2* b = (Vec2*)stack.get_vec2(2);
+
+	*a += *b;
+
+	stack.push_vec2(a);
+
+	return 1;
+}
+
+int32_t vec2_subtract(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+	Vec2* b = (Vec2*) stack.get_vec2(2);
+
+	*a -= *b;
+
+	stack.push_vec2(a);
+
+	return 1;
+}
+
+int32_t vec2_multiply(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+	float k = stack.get_float(2);
+
+	*a *= k;
+
+	stack.push_vec2(a);
+
+	return 1;
+}			
+	
+int32_t vec2_divide(lua_State* L)
+{
+	LuaStack stack(L);
+	
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+	float k = stack.get_float(2);
+
+	*a /= k;
+
+	stack.push_vec2(a);
+
+	return 1;
+}
+
+int32_t vec2_dot(lua_State* L)
+{
+	LuaStack stack(L);
+	
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+	Vec2* b = (Vec2*) stack.get_vec2(2);
+
+	stack.push_float(a->dot(*b));
+
+	return 1;
+}
+
+int32_t vec2_equals(lua_State* L)
+{
+	LuaStack stack(L);
+	
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+	Vec2* b = (Vec2*) stack.get_vec2(2);
+
+	stack.push_bool(*a == *b);
+
+	return 1;
+}
+
+int32_t vec2_lower(lua_State* L)
+{
+	LuaStack stack(L);
+	
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+	Vec2* b = (Vec2*) stack.get_vec2(2);
+
+	stack.push_bool(*a < *b);
+
+	return 1;
+}
+
+int32_t vec2_greater(lua_State* L)
+{
+	LuaStack stack(L);
+	
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+	Vec2* b = (Vec2*) stack.get_vec2(2);
+	
+	stack.push_bool(*a > *b);
+
+	return 1;
+}
+
+int32_t vec2_length(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+
+	stack.push_float(a->length());
+
+	return 1;
+}
+
+int32_t vec2_squared_length(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+
+	stack.push_float(a->squared_length());
+
+	return 1;
+}
+
+int32_t vec2_set_length(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+	float len = stack.get_float(2);
+
+	a->set_length(len);
+
+	return 0;
+}
+
+int32_t	vec2_normalize(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+
+	a->normalize();
+
+	stack.push_vec2(a);
+
+	return 1;
+}
+
+int32_t	vec2_negate(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+
+	a->negate();
+
+	stack.push_vec2(a);
+
+	return 1;
+}
+
+int32_t	vec2_get_distance_to(lua_State* L)
+{
+	LuaStack stack(L);
+	
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+	Vec2* b = (Vec2*) stack.get_vec2(2);
+
+	stack.push_float(a->get_distance_to(*b));
+
+	return 1;
+}
+
+int32_t	vec2_get_angle_between(lua_State* L)
+{
+	LuaStack stack(L);
+	
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+	Vec2* b = (Vec2*) stack.get_vec2(2);
+
+	stack.push_float(a->get_angle_between(*b));
+
+	return 1;
+}
+
+int32_t	vec2_zero(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec2* a = (Vec2*) stack.get_vec2(1);
+
+	a->zero();
+
+	return 0;
+}
+
+} // extern "C"
+
+void load_vec2(LuaEnvironment& env)
+{
+	env.load_module_function("Vec2", "new", vec2);
+	env.load_module_function("Vec2", "val", vec2_values);
+	env.load_module_function("Vec2", "add", vec2_add);
+	env.load_module_function("Vec2", "sub", vec2_subtract);
+	env.load_module_function("Vec2", "mul", vec2_multiply);
+	env.load_module_function("Vec2", "div", vec2_divide);
+	env.load_module_function("Vec2", "dot", vec2_dot);
+	env.load_module_function("Vec2", "equals", vec2_equals);
+	env.load_module_function("Vec2", "lower", vec2_lower);
+	env.load_module_function("Vec2", "greater", vec2_greater);
+	env.load_module_function("Vec2", "length", vec2_length);
+	env.load_module_function("Vec2", "squared_length", vec2_squared_length);
+	env.load_module_function("Vec2", "set_length", vec2_set_length);
+	env.load_module_function("Vec2", "normalize", vec2_normalize);
+	env.load_module_function("Vec2", "negate", vec2_negate);
+	env.load_module_function("Vec2", "get_distance_to", vec2_get_distance_to);
+	env.load_module_function("Vec2", "get_angle_between", vec2_get_angle_between);
+	env.load_module_function("Vec2", "zero", vec2_zero);
+}
+
+} // namespace crown

+ 303 - 0
lua/Vec3Binds.cpp

@@ -0,0 +1,303 @@
+#include "Vec3.h"
+#include "LuaStack.h"
+#include "LuaEnvironment.h"
+
+namespace crown
+{
+
+/// Lightweight bind for Vec3 
+
+extern "C"
+{
+
+//------------------------------------------------------------
+int32_t vec3(lua_State* L)
+{
+	LuaStack stack(L);
+
+	float x = stack.get_float(1);
+	float y = stack.get_float(2);
+	float z = stack.get_float(3);
+
+	Vec3* vec = next_vec3();
+
+	vec->x = x;
+	vec->y = y;
+	vec->z = z;
+
+	stack.push_vec3(vec);
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_values(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+
+	float x = a->x;
+	float y = a->y;
+	float z = a->z;
+
+	stack.push_float(x);
+	stack.push_float(y);
+	stack.push_float(z);
+
+	return 3;
+}
+
+//------------------------------------------------------------
+int32_t vec3_add(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+	Vec3* b = stack.get_vec3(2);
+
+	*a += *b;
+
+	stack.push_vec3(a);
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_subtract(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+	Vec3* b = stack.get_vec3(2);
+
+	*a -= *b;
+
+	stack.push_vec3(a);
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_multiply(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+	float b = stack.get_float(2);
+
+	*a *= b;
+
+	stack.push_vec3(a);
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_divide(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+	float b = stack.get_float(2);
+
+	*a /= b;
+
+	stack.push_vec3(a);
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_dot(lua_State* L)
+{
+	LuaStack stack(L);
+	
+	Vec3* a = stack.get_vec3(1);
+	Vec3* b = stack.get_vec3(2);
+
+	stack.push_float(a->dot(*b));
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_cross(lua_State* L)
+{
+	LuaStack stack(L);
+	
+	Vec3* a = stack.get_vec3(1);
+	Vec3* b = stack.get_vec3(2);
+
+	/// CHECK CHECK CHECK
+	*a = a->cross(*b);
+
+	stack.push_vec3(a);
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_equals(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+	Vec3* b = stack.get_vec3(2);
+
+	stack.push_bool(*a == *b);
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_lower(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+	Vec3* b = stack.get_vec3(2);
+
+	stack.push_bool(*a < *b);
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_greater(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+	Vec3* b = stack.get_vec3(2);
+
+	stack.push_bool(*a > *b);
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_length(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+
+	stack.push_float(a->length());
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_squared_length(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+
+	stack.push_float(a->squared_length());
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_set_length(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+	float len = stack.get_float(2);
+
+	a->set_length(len);
+
+	return 0;
+}
+
+//------------------------------------------------------------
+int32_t vec3_normalize(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+
+	a->normalize();
+
+	return 0;
+}
+
+//------------------------------------------------------------
+int32_t vec3_negate(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+
+	a->negate();
+
+	return 0;
+}
+
+//------------------------------------------------------------
+int32_t vec3_get_distance_to(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+	Vec3* b = stack.get_vec3(2);
+
+	stack.push_float(a->get_distance_to(*b));
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_get_angle_between(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+	Vec3* b = stack.get_vec3(2);
+
+	stack.push_float(a->get_angle_between(*b));
+
+	return 1;
+}
+
+//------------------------------------------------------------
+int32_t vec3_zero(lua_State* L)
+{
+	LuaStack stack(L);
+
+	Vec3* a = stack.get_vec3(1);
+
+	a->zero();
+
+	return 0;
+}	
+
+} // extern "C"
+
+void load_vec3(LuaEnvironment& env)
+{
+	env.load_module_function("Vec3", "new", 				vec3);
+	env.load_module_function("Vec3", "val", 				vec3_values);
+	env.load_module_function("Vec3", "add", 				vec3_add);
+	env.load_module_function("Vec3", "sub", 				vec3_subtract);
+	env.load_module_function("Vec3", "mul", 				vec3_multiply);
+	env.load_module_function("Vec3", "div", 				vec3_divide);
+	env.load_module_function("Vec3", "dot", 				vec3_dot);
+	env.load_module_function("Vec3", "cross", 				vec3_cross);
+	env.load_module_function("Vec3", "equals", 				vec3_equals);
+	env.load_module_function("Vec3", "lower", 				vec3_lower);
+	env.load_module_function("Vec3", "greater", 			vec3_greater);
+	env.load_module_function("Vec3", "length", 				vec3_length);
+	env.load_module_function("Vec3", "squared_length", 		vec3_squared_length);
+	env.load_module_function("Vec3", "set_length", 			vec3_set_length);
+	env.load_module_function("Vec3", "normalize", 			vec3_normalize);
+	env.load_module_function("Vec3", "negate", 				vec3_negate);
+	env.load_module_function("Vec3", "get_distance_to", 	vec3_get_distance_to);
+	env.load_module_function("Vec3", "get_angle_between", 	vec3_get_angle_between);
+	env.load_module_function("Vec3", "zero", 				vec3_zero);	
+}
+
+} // namespace crown

+ 1 - 1
proj/sublime-text/crown.proj

@@ -2,7 +2,7 @@
 	"folders":
 	[
 		{
-			"path": "/home/mikymod/repositories/crown/"
+			"path": "/home/mikymod/repositories/crown"
 		}
 	],
 	"build_systems":

+ 9 - 4
samples/lua/CMakeLists.txt

@@ -1,7 +1,12 @@
 cmake_minimum_required(VERSION 2.8)
 
-include_directories(${CROWN_THIRD}/luajit/include/luajit-2.0)
-link_directories(${CROWN_THIRD}/luajit/lib)
-add_executable(luas lua.cpp)
-target_link_libraries(luas crown luajit-5.1)
+set (SRC
+	lua.cpp
+)
+
+add_definitions(-Wl,-E)
+add_library (game SHARED ${SRC})
+target_link_libraries(game crown)
+
+install (TARGETS game DESTINATION bin/lua_sample)
 

+ 25 - 42
samples/lua/lua.cpp

@@ -1,60 +1,43 @@
-#include <iostream>
 #include "Crown.h"
-#include "lua.hpp"
-#include <unistd.h>
+#include "Game.h"
 
-using namespace crown;
 
-static void report_errors(lua_State* state, const int status)
+namespace crown
 {
-  if (status != 0)
-  {
-    std::cerr << "-- " << lua_tostring(state, -1) << std::endl;
 
-    lua_pop(state, 1);
-  }
-}
+lua_State* L;
 
-int main(int argc, char** argv)
+void init()
 {
-  lua_State* lua_state;
-
-  Filesystem fs("/home/mikymod/test/res_compiled");
-
-  FileResourceArchive archive(fs);
-
-  MallocAllocator allocator;
-
-  ResourceManager res_manager(archive, allocator);
-
-  ResourceId script = res_manager.load("lua/hello.lua");
+	L = luaL_newstate();
+	luaL_openlibs(L);
 
-  res_manager.flush();
+	if (luaL_loadfile(L, "/home/mikymod/test/res_linux/lua/game.raw") || lua_pcall(L, 0, 0, 0))
+	{
+		os::printf("error: %s", lua_tostring(L, -1));
+	}
 
-  while (1)
-  {
-    if (res_manager.is_loaded(script))
-    {
+	lua_getglobal(L, "init");
 
-      lua_state = luaL_newstate();
-      luaL_openlibs(lua_state);
+	lua_pcall(L, 0, 0, 0);
+}
 
-      ScriptResource* resource = (ScriptResource*)res_manager.data(script);
+void shutdown()
+{
+	lua_getglobal(L, "shutdown");
 
-      int s = luaL_loadbuffer(lua_state, (char*)resource->data(), 47, "");
+	lua_pcall(L, 0, 0, 0);
 
-      if (s == 0)
-      {
-        s = lua_pcall(lua_state, 0, LUA_MULTRET, 0);
-      }
+	lua_close(L);
+}
 
-      report_errors(lua_state, s);
+void frame(float dt)
+{
+	lua_getglobal(L, "frame");
 
-      break;
-    }
-  }
+	lua_pushnumber(L, dt);
 
-  lua_close(lua_state);
+	lua_pcall(L, 1, 0, 0);
+}
 
-  return 0;
 }

+ 7 - 4
samples/terrain/CMakeLists.txt

@@ -1,5 +1,7 @@
 cmake_minimum_required(VERSION 2.8)
 
+project(sample-terrain)
+
 set (SRC
 	terrain.cpp
 	Terrain.cpp
@@ -9,8 +11,9 @@ set (HEADERS
 	Terrain.h
 )
 
-add_library (game SHARED ${SRC} ${HEADERS})
-target_link_libraries(game crown)
+#add_library (game SHARED ${SRC} ${HEADERS})
+#target_link_libraries(game crown)
+
+#install (DIRECTORY terrain DESTINATION samples)
+#install (TARGETS game DESTINATION samples/terrain)
 
-install (DIRECTORY terrain DESTINATION samples)
-install (TARGETS game DESTINATION samples/terrain)

+ 3 - 0
samples/terrain/terrain.cpp

@@ -2,6 +2,7 @@
 #include "Terrain.h"
 #include "FPSSystem.h"
 #include "Game.h"
+#include "ScriptSystem.h"
 
 using namespace crown;
 
@@ -195,6 +196,8 @@ private:
 	PixelShaderId ps_id;
 	GPUProgramId gpu_program_id;
 
+	ResourceId script;
+
 	bool optShowSkybox;
 	bool optShowCrate;
 	bool optShowTerrain;

+ 5 - 3
src/CMakeLists.txt

@@ -8,7 +8,6 @@ set (SRC
 
 	TextureResource.cpp
 	TextResource.cpp
-	ScriptResource.cpp
 	FontResource.cpp
 	VertexShaderResource.cpp
 	PixelShaderResource.cpp
@@ -34,7 +33,6 @@ set (HEADERS
 
 	TextureResource.h
 	TextResource.h
-	ScriptResource.h
 	FontResource.h
 	VertexShaderResource.h
 	PixelShaderResource.h
@@ -271,9 +269,13 @@ set (CROWN_HEADERS
 	${NETWORK_HEADERS}
 
 	${OS_HEADERS}
+
+	${SCRIPT_HEADERS}
 )
 
-link_libraries(rt z)
+include_directories(${CROWN_THIRD}/luajit/include/luajit-2.0)
+link_directories(${CROWN_THIRD}/luajit/lib)
+link_libraries(rt z luajit-5.1)
 add_library(crown SHARED ${CROWN_SOURCES} ${CROWN_HEADERS})
 
 if (CROWN_BUILD_OPENGL)

+ 5 - 1
src/Crown.h

@@ -107,7 +107,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "TextResource.h"
 #include "TextureResource.h"
-#include "ScriptResource.h"
 #include "MaterialResource.h"
 #include "FontResource.h"
 #include "VertexShaderResource.h"
@@ -134,3 +133,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "PixelFormat.h"
 #include "VertexFormat.h"
 
+// Lua
+#include "LuaStack.h"
+#include "LuaEnvironment.h"
+
+

+ 0 - 13
src/ResourceManager.cpp

@@ -38,7 +38,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "FileStream.h"
 #include "TextResource.h"
 #include "TextureResource.h"
-#include "ScriptResource.h"
 #include "VertexShaderResource.h"
 #include "PixelShaderResource.h"
 
@@ -345,10 +344,6 @@ void* ResourceManager::load_by_type(ResourceId name) const
 	{
 		return TextResource::load(m_resource_allocator, m_resource_archive, name);
 	}
-	else if (name.type == SCRIPT_TYPE)
-	{
-		return ScriptResource::load(m_resource_allocator, m_resource_archive, name);
-	}
 	else if (name.type == VERTEX_SHADER_TYPE)
 	{
 		return VertexShaderResource::load(m_resource_allocator, m_resource_archive, name);
@@ -372,10 +367,6 @@ void ResourceManager::unload_by_type(ResourceId name, void* resource) const
 	{
 		TextResource::unload(m_resource_allocator, resource);
 	}
-	else if (name.type == SCRIPT_TYPE)
-	{
-		ScriptResource::unload(m_resource_allocator, resource);
-	}
 	else if (name.type == VERTEX_SHADER_TYPE)
 	{
 		VertexShaderResource::unload(m_resource_allocator, resource);
@@ -399,10 +390,6 @@ void ResourceManager::online(ResourceId name, void* resource)
 	{
 		TextResource::online(resource);
 	}
-	else if (name.type == SCRIPT_TYPE)
-	{
-		ScriptResource::online(resource);
-	}
 	else if (name.type == VERTEX_SHADER_TYPE)
 	{
 		VertexShaderResource::online(resource);

+ 0 - 56
src/ScriptResource.cpp

@@ -1,56 +0,0 @@
-#include "Assert.h"
-
-#include "ScriptResource.h"
-#include "ResourceArchive.h"
-#include "Log.h"
-#include "FileStream.h"
-#include "Allocator.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-void* ScriptResource::load(Allocator& allocator, ResourceArchive& archive, ResourceId id)
-{
-	FileStream* stream = archive.open(id);
-
-	if (stream != NULL)
-	{
-		ScriptResource* resource = (ScriptResource*)allocator.allocate(sizeof(ScriptResource));
-	
-		size_t size = stream->size() - stream->position();
-
-		resource->m_data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
-
-		stream->read(resource->m_data, size);
-
-		archive.close(stream);
-
-		return resource;
-	}
-
-	return NULL;
-}
-
-//-----------------------------------------------------------------------------
-void ScriptResource::online(void* resource)
-{
-	(void) resource;
-}
-
-//-----------------------------------------------------------------------------
-void ScriptResource::unload(Allocator& allocator, void* resource)
-{
-	ce_assert(resource != NULL, "");
-
-	allocator.deallocate(((ScriptResource*)resource)->m_data);
-	allocator.deallocate(resource);
-}
-
-//-----------------------------------------------------------------------------
-void ScriptResource::offline()
-{
-
-}
-
-} // namespace crown

+ 0 - 55
src/ScriptResource.h

@@ -1,55 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Types.h"
-#include "Resource.h"
-
-namespace crown
-{
-
-class ResourceArchive;
-class Allocator;
-
-class ScriptResource
-{
-public:
-
-	static void*		load(Allocator& allocator, ResourceArchive& archive, ResourceId id);
-	static void			online(void* script);
-	static void			unload(Allocator& allocator, void* resource);
-	static void			offline();
-
-public:
-
-	const uint8_t*		data() const { return m_data; }
-
-private:
-
-	uint8_t*			m_data;
-};
-
-} // namespace crown

+ 7 - 7
src/input/Mouse.cpp

@@ -50,17 +50,17 @@ bool Mouse::button_released(MouseButton button) const
 }
 
 //-----------------------------------------------------------------------------
-Point2 Mouse::cursor_xy() const
+Vec2 Mouse::cursor_xy() const
 {
-	Point2 xy;
+	int32_t x, y;
 
-	os::get_cursor_xy(xy.x, xy.y);
+	os::get_cursor_xy(x, y);
 
-	return xy;
+	return Vec2(x, y);
 }
 
 //-----------------------------------------------------------------------------
-void Mouse::set_cursor_xy(const Point2& position)
+void Mouse::set_cursor_xy(const Vec2& position)
 {
 	os::set_cursor_xy(position.x, position.y);
 }
@@ -73,7 +73,7 @@ Vec2 Mouse::cursor_relative_xy() const
 
 	os::get_render_window_metrics(window_width, window_height);
 
-	Vec2 pos = cursor_xy().to_vec2();
+	Vec2 pos = cursor_xy();
 
 	pos.x = pos.x / (float) window_width;
 	pos.y = pos.y / (float) window_height;
@@ -89,7 +89,7 @@ void Mouse::set_cursor_relative_xy(const Vec2& position)
 
 	os::get_render_window_metrics(window_width, window_height);
 
-	set_cursor_xy(Point2((int32_t)(position.x * (float) window_width), (int32_t)(position.y * (float) window_height)));
+	set_cursor_xy(Vec2(position.x * (float) window_width, position.y * (float) window_height));
 }
 
 } // namespace crown

+ 2 - 3
src/input/Mouse.h

@@ -27,7 +27,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "Vec2.h"
-#include "Point2.h"
 
 namespace crown
 {
@@ -80,14 +79,14 @@ public:
 	/// Coordinates in window space have the origin at the
 	/// upper-left corner of the window. +X extends from left
 	/// to right and +Y extends from top to bottom.
-	Point2	cursor_xy() const;
+	Vec2	cursor_xy() const;
 
 	/// Sets the position of the cursor in window space.
 	/// @note
 	/// Coordinates in window space have the origin at the
 	/// upper-left corner of the window. +X extends from left
 	/// to right and +Y extends from top to bottom.
-	void	set_cursor_xy(const Point2& position);
+	void	set_cursor_xy(const Vec2& position);
 
 	/// Returns the relative position of the cursor in window space.
 	/// @note

+ 2 - 2
src/input/Touch.cpp

@@ -47,11 +47,11 @@ bool Touch::touch_down(uint16_t id) const
 }
 
 //----------------------------------------------------------------------------- 
-Point2 Touch::touch_xy(uint16_t id) const
+Vec2 Touch::touch_xy(uint16_t id) const
 {
 	const PointerData& data = m_pointers[id];
 
-	return Point2(data.x, data.y);
+	return Vec2(data.x, data.y);
 }
 
 //-----------------------------------------------------------------------------

+ 1 - 2
src/input/Touch.h

@@ -27,7 +27,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "Types.h"
 #include "Vec2.h"
-#include "Point2.h"
 
 namespace crown
 {
@@ -80,7 +79,7 @@ public:
 	/// Coordinates in window space have the origin at the
 	/// upper-left corner of the window. +X extends from left
 	/// to right and +Y extends from top to bottom.
-	Point2			touch_xy(uint16_t id) const;
+	Vec2			touch_xy(uint16_t id) const;
 
 	/// Returns the relative position of the pointer @id in window space.
 	/// @note

+ 5 - 3
third/x86/CMakeLists.txt

@@ -8,7 +8,9 @@ install (FILES 	luajit/include/luajit-2.0/lua.hpp
 				luajit/include/luajit-2.0/lualib.h DESTINATION include/crown/luajit)
 				
 install (DIRECTORY luajit/lib/pkgconfig DESTINATION lib/crown)
-install (FILES luajit/lib/libluajit-5.1.so.2.0.1 DESTINATION lib/crown)
-
-install (FILES luajit/bin/luajit-2.0.1 DESTINATION bin)
+install (FILES luajit/lib/libluajit-5.1.so.2.0.1 
+			   luajit/lib/libluajit-5.1.so.2 DESTINATION lib/crown)
 
+install (PROGRAMS luajit/bin/luajit-2.0.1 DESTINATION bin)
+install (FILES luajit/bin/luajit DESTINATION bin)
+install (DIRECTORY luajit/share/luajit-2.0.1/jit DESTINATION bin)

+ 5 - 2
third/x86_64/CMakeLists.txt

@@ -8,6 +8,9 @@ install (FILES 	luajit/include/luajit-2.0/lua.hpp
 				luajit/include/luajit-2.0/lualib.h DESTINATION include/crown/luajit)
 				
 install (DIRECTORY luajit/lib/pkgconfig DESTINATION lib/crown)
-install (FILES luajit/lib/libluajit-5.1.so.2.0.1 DESTINATION lib/crown)
+install (FILES luajit/lib/libluajit-5.1.so.2.0.1 
+			   luajit/lib/libluajit-5.1.so.2 DESTINATION lib/crown)
 
-install (FILES luajit/bin/luajit-2.0.1 DESTINATION bin)
+install (PROGRAMS luajit/bin/luajit-2.0.1 DESTINATION bin)
+install (FILES luajit/bin/luajit DESTINATION bin)
+install (DIRECTORY luajit/share/luajit-2.0.1/jit DESTINATION bin)

+ 0 - 4
tools/compilers/CMakeLists.txt

@@ -2,20 +2,16 @@ cmake_minimum_required(VERSION 2.8)
 
 set (SRC
 	Compiler.cpp
-
 	tga/TGACompiler.cpp
 	txt/TXTCompiler.cpp
-	lua/LuaCompiler.cpp
 	ps/PSCompiler.cpp
 	vs/VSCompiler.cpp
 )
 
 set (HEADERS
 	Compiler.h
-
 	tga/TGACompiler.h
 	txt/TXTCompiler.h
-	lua/LuaCompiler.h
 	ps/PSCompiler.h
 	vs/VSCompiler.h
 )

+ 0 - 112
tools/compilers/lua/LuaCompiler.cpp

@@ -1,112 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#include "LuaCompiler.h"
-#include "FileStream.h"
-#include "Resource.h"
-#include "Log.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-LuaCompiler::LuaCompiler(const char* root_path, const char* dest_path) :
-	Compiler(root_path, dest_path, SCRIPT_TYPE),
-	m_file_size(0),
-	m_file_data(NULL)
-{
-}
-
-//-----------------------------------------------------------------------------
-LuaCompiler::~LuaCompiler()
-{
-	cleanup_impl();
-}
-
-//-----------------------------------------------------------------------------
-size_t LuaCompiler::read_header_impl(FileStream* in_file)
-{
-	(void) in_file;
-	return 0;
-}
-
-//-----------------------------------------------------------------------------
-size_t LuaCompiler::read_resource_impl(FileStream* in_file)
-{
-	Filesystem fs(root_path());
-
-	char tmp_resource[os::MAX_PATH_LENGTH];
-
-	string::strcpy(tmp_resource, resource_name());
-	string::strcat(tmp_resource, ".script");
-
-	if (!fs.exists(tmp_resource))
-	{
-		Log::e("'%s': resource cannot be found.");
-		return 0;
-	}
-
-	FileStream* tmp_file = (FileStream*)fs.open(tmp_resource, SOM_READ);
-
-	m_file_size = tmp_file->size();
-
-	if (m_file_size == 0)
-	{
-		Log::e("'%s': resource is empty.");
-		return 0;
-	}
-
-	m_file_data = new char[m_file_size];
-
-	// Copy the entire file into the buffer
-	tmp_file->read(m_file_data, m_file_size);
-
-	// Returns the total size of the resource
-	return m_file_size;
-}
-
-//-----------------------------------------------------------------------------
-void LuaCompiler::write_header_impl(FileStream* out_file)
-{
-	(void) out_file;
-}
-
-//-----------------------------------------------------------------------------
-void LuaCompiler::write_resource_impl(FileStream* out_file)
-{
-	out_file->write(m_file_data, m_file_size);
-}
-
-//-----------------------------------------------------------------------------
-void LuaCompiler::cleanup_impl()
-{
-	if (m_file_data)
-	{
-		delete[] m_file_data;
-		m_file_data = NULL;
-	}
-}
-
-} // namespace crown

+ 0 - 55
tools/compilers/lua/LuaCompiler.h

@@ -1,55 +0,0 @@
-/*
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "Compiler.h"
-#include "FileStream.h"
-
-namespace crown
-{
-
-class LuaCompiler : public Compiler
-{
-
-public:
-					LuaCompiler(const char* root_path, const char* dest_path);
-					~LuaCompiler();
-
-	size_t			read_header_impl(FileStream* in_file);
-	size_t			read_resource_impl(FileStream* in_file);
-
-	void			write_header_impl(FileStream* out_file);
-	void			write_resource_impl(FileStream* out_file);
-
-	void			cleanup_impl();
-
-private:
-
-	uint32_t		m_file_size;
-	char*			m_file_data;
-};
-
-} // namespace crown

+ 0 - 45
tools/compilers/lua/bytecode-generator.lua

@@ -1,45 +0,0 @@
--- Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
--- 
--- Permission is hereby granted, free of charge, to any person
--- obtaining a copy of this software and associated documentation
--- files (the "Software"), to deal in the Software without
--- restriction, including without limitation the rights to use,
--- copy, modify, merge, publish, distribute, sublicense, and/or sell
--- copies of the Software, and to permit persons to whom the
--- Software is furnished to do so, subject to the following
--- conditions:
--- 
--- The above copyright notice and this permission notice shall be
--- included in all copies or substantial portions of the Software.
--- 
--- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
--- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
--- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
--- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
--- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
--- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
--- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
--- OTHER DEALINGS IN THE SOFTWARE.
-
-local src = arg[1]
-local tmp = src .. ".script"
-
-
-local chunk = string.dump(loadfile(src), true)
-
-local f,err = io.open(tmp, "w")
-
-if not f then 
-	return print(err) 
-end
-
-f:write(chunk)
-
-f:close()
-
-
-
-
-
-
-

+ 0 - 7
tools/compilers/resource-compiler.cpp

@@ -1,7 +1,6 @@
 #include "Crown.h"
 #include "tga/TGACompiler.h"
 #include "txt/TXTCompiler.h"
-#include "lua/LuaCompiler.h"
 #include "vs/VSCompiler.h"
 #include "ps/PSCompiler.h"
 
@@ -37,7 +36,6 @@ int main(int argc, char** argv)
 
 	TGACompiler tga(root_path, dest_path);
 	TXTCompiler txt(root_path, dest_path);
-	LuaCompiler lua(root_path, dest_path);
 	VSCompiler vs(root_path, dest_path);
 	PSCompiler ps(root_path, dest_path);
 
@@ -67,11 +65,6 @@ int main(int argc, char** argv)
 				txt.compile(resource, resource_name_hash, resource_type_hash);
 				break;
 			}
-			case SCRIPT_TYPE:
-			{
-				lua.compile(resource, resource_name_hash, resource_type_hash);
-				break;
-			}
 			case VERTEX_SHADER_TYPE:
 			{
 				vs.compile(resource, resource_name_hash, resource_type_hash);

+ 21 - 10
tools/pycrown/Compiler.py

@@ -25,8 +25,8 @@
 import subprocess
 import os
 
-LUAJIT = "luajit-2.0.1"
-BC_G = "bytecode-generator.lua"
+LUAJIT = "luajit"
+OPTION = "-b"
 COMPILER_NAME = "resource-compiler"
 RES_H = "resource-hash"
 
@@ -91,8 +91,26 @@ class Compiler:
 
 	# Compiles all the script resources in the repository
 	def compile_scripts(self):
-		self.compile(self.m_repository.script_resources());
+		lua_resources = self.m_repository.script_resources()
+		root_path = self.m_repository.root_path()
+
+		for res in lua_resources:
+			path_in = os.path.normpath(root_path + "/" + res)
+			path_out = os.path.normpath(os.path.dirname(self.m_dest_path + "/" + res))
+
+			if not os.path.exists(path_out):
+				os.makedirs(path_out)
+
+			head, out_filename = os.path.split(res)
+			out_filename, ext = os.path.splitext(out_filename)
+
+			res_in = res
+			res_out = out_filename + ".raw"
 
+			print(res_out, "<=", res_in)
+
+			f = subprocess.call([LUAJIT, OPTION, path_in, path_out + "/" + res_out]);
+	
 	# Compiles all the vertex shader resources in the repository
 	def compile_vertex_shaders(self):
 		self.compile(self.m_repository.vertex_shader_resources());
@@ -124,10 +142,3 @@ class Compiler:
 		compiler_params = [COMPILER_NAME, "--root-path", root_path, "--dest-path", self.m_dest_path, "--seed", str(self.m_perfect_seed)]
 
 		p = subprocess.call(compiler_params + resource_params)
-
-		# if resource.endswith('.lua'):
-		# 	path = os.path.normpath(root_path + "/" + resource)
-		# 	f = subprocess.call([LUAJIT, BC_G, path]);
-		# 	p = subprocess.call([LUA_C, ROOT_P, root_path, DEST_P, self.m_dest_path, RES_IN, resource, SEED, str(self.m_perfect_seed)]);
-	
-