Procházet zdrojové kódy

Merge branch 'master' into cross-compilation

mikymod před 12 roky
rodič
revize
4e9f6e2444

+ 1 - 1
game/Game.h

@@ -37,7 +37,7 @@ public:
 
 	virtual void	init() = 0;
 	virtual void	shutdown() = 0;
-	virtual void	update() = 0;
+	virtual void	update(float dt) = 0;
 };
 
 typedef Game* create_game_t();

+ 30 - 33
samples/terrain/terrain.cpp

@@ -59,14 +59,6 @@ public:
 		{		
 			terrain.PlotCircle(8, 8, 8, 2);
 		}
-
-		if (event.key == KC_SPACE)
-		{
-			if (cam)
-			{
-				cam->SetActive(!cam->IsActive());
-			}
-		}
 	}
 
 	void button_pressed(const MouseEvent& event)
@@ -129,16 +121,9 @@ public:
 		Vec3 start = Vec3(0.0f, 10.0f, 0.0f);
 
 		// Add a movable camera
-		cam = new MovableCamera(/*Vec3::ZERO*/start, true, 90.0f, 1.6f, true, 0.1, 2.5);
+		cam = new Camera(start, 90.0f, 1.6f);
 
-		if (cam)
-		{
-			cam->SetActive(true);
-			cam->SetSpeed(0.1);
-			cam->SetFarClipDistance(1000.0f);
-		}
-
-		system = new FPSSystem(cam);
+		system = new FPSSystem(cam, 10.0f, 2.5f);
 
 		// Add a skybox
 		skybox = new Skybox(Vec3::ZERO, true);
@@ -155,8 +140,14 @@ public:
 
 		terrain.CreateTerrain(64, 64, 1, 0.0f);
 
-		//grass = GetTextureManager()->Load("res/grass.tga");
-		//grass->SetFilter(TF_TRILINEAR);
+		device()->resource_manager()->load("textures/red_north.tga");
+		device()->resource_manager()->load("textures/red_south.tga");
+		device()->resource_manager()->load("textures/red_east.tga");
+		device()->resource_manager()->load("textures/red_west.tga");
+		device()->resource_manager()->load("textures/red_up.tga");
+		device()->resource_manager()->load("textures/red_down.tga");
+
+		grass = device()->resource_manager()->load("textures/grass.tga");
 
 		terrain.PlotCircle(4, 4, 4, 2);
 
@@ -164,12 +155,12 @@ public:
 		terrain.UpdateVertexBuffer(true);
 	}
 
-	void render()
+	void render(float dt)
 	{
 		Renderer* renderer = device()->renderer();
 		
 		system->set_view_by_cursor();
-		system->camera_render();
+		system->update(dt);
 
 		renderer->set_lighting(false);
 		renderer->set_texturing(0, false);
@@ -179,11 +170,8 @@ public:
 			skybox->Render();
 		}
 
-		if (cam->IsActive())
-		{
-			ray.set_origin(cam->GetPosition());
-			ray.set_direction(cam->GetLookAt());
-		}
+		ray.set_origin(cam->position());
+		ray.set_direction(cam->look_at());
 
 		/* Render the terrain */
 		renderer->set_ambient_light(Color4(0.5f, 0.5f, 0.5f, 1.0f));
@@ -197,10 +185,19 @@ public:
 		renderer->set_material_params(Color4(0.3f, 0.3f, 0.3f), Color4(0.8f, 0.8f, 0.8f), Color4::BLACK, Color4::BLACK, 0);
 
 		renderer->set_matrix(MT_MODEL, Mat4::IDENTITY);
-		// Texture disabled because of last updates not in sync... :(
-		//renderer->set_texturing(0, true);
-		//renderer->set_texture(0, grass);
-		renderer->set_lighting(true);
+
+		if (device()->resource_manager()->is_loaded(grass))
+		{
+			TextureResource* grass_tex = (TextureResource*)device()->resource_manager()->data(grass);
+			if (grass_tex)
+			{
+				TextureId grass_id = grass_tex->m_render_texture;
+				renderer->set_texturing(0, true);
+				renderer->set_texture(0, grass_id);
+				renderer->set_lighting(true);
+			}
+		}
+
 		
 		//glColor3f(1, 1, 1);
 
@@ -230,7 +227,7 @@ public:
 private:
 
 	FPSSystem* system;
-	MovableCamera* cam;
+	Camera* cam;
 	Skybox* skybox;
 	Mat4 ortho;
 	Terrain terrain;
@@ -260,9 +257,9 @@ public:
 	{
 	}
 
-	void update()
+	void update(float dt)
 	{
-		m_scene.render();
+		m_scene.render(dt);
 	}
 
 private:

+ 0 - 173
src/Android.mk

@@ -1,173 +0,0 @@
-# Copyright (C) 2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-LOCAL_MODULE    := crown
-LOCAL_SRC_FILES :=\
-	core/bv/Circle.cpp\
-	core/bv/Frustum.cpp\
-	core/bv/Rectangle.cpp\
-	core/containers/Generic.cpp\
-	core/containers/StringUtils.cpp\
-	core/math/Angles.cpp\
-	core/math/Color4.cpp\
-	core/math/Mat3.cpp\
-	core/math/Mat4.cpp\
-	core/math/MathUtils.cpp\
-	core/math/Plane.cpp\
-	core/math/Quat.cpp\
-	core/math/Shape.cpp\
-	core/math/Vec2.cpp\
-	core/math/Vec3.cpp\
-	core/math/Vec4.cpp\
-	core/mem/GarbageBin.cpp\
-	core/mem/ManagedObject.cpp\
-	core/Object.cpp\
-	core/Observable.cpp\
-	core/streams/FileStream.cpp\
-	core/streams/MemoryStream.cpp\
-	core/streams/Stream.cpp\
-\
-	input/android/AndroidInputManager.cpp\
-	input/android/AndroidTouch.cpp\
-	input/EventDispatcher.cpp\
-	input/InputManager.cpp\
-\
-	loaders/BMPImageLoader.cpp\
-	loaders/CRWDecoder.cpp\
-	loaders/TGAImageLoader.cpp\
-\
-	Filesystem.cpp\
-\
-	renderers/gles/egl/EGLRenderWindow.cpp\
-	renderers/gles/GLESIndexBuffer.cpp\
-	renderers/gles/GLESRenderer.cpp\
-	renderers/gles/GLESSupport.cpp\
-	renderers/gles/GLESTextRenderer.cpp\
-	renderers/gles/GLESTexture.cpp\
-	renderers/gles/GLESTextureManager.cpp\
-	renderers/gles/GLESVertexBuffer.cpp\
-\
-	App.cpp\
-	Camera.cpp\
-	Device.cpp\
-	Entity.cpp\
-	Font.cpp\
-	FontManager.cpp\
-	Frame.cpp\
-	Image.cpp\
-	ImageLoader.cpp\
-	Light.cpp\
-	Log.cpp\
-	LogManager.cpp\
-	Material.cpp\
-	MaterialManager.cpp\
-	MeshChunk.cpp\
-	Mesh.cpp\
-	MeshManager.cpp\
-	MovableCamera.cpp\
-	PhysicNode.cpp\
-	PhysicsManager.cpp\
-	Pixel.cpp\
-	Renderer.cpp\
-	RenderWindow.cpp\
-	ResourceManager.cpp\
-	Scene.cpp\
-	SceneManager.cpp\
-	SceneNode.cpp\
-	Skybox.cpp\
-	SpriteAnimator.cpp\
-	Sprite.cpp\
-	Timer.cpp\
-\
-
-LOCAL_C_INCLUDES	:=\
-	$(LOCAL_PATH)/core\
-	$(LOCAL_PATH)/core/math\
-	$(LOCAL_PATH)/core/containers\
-	$(LOCAL_PATH)/core/bv\
-	$(LOCAL_PATH)/core/mem\
-	$(LOCAL_PATH)/core/streams\
-	$(LOCAL_PATH)/loaders\
-	$(LOCAL_PATH)/renderers\
-	$(LOCAL_PATH)/things\
-	$(LOCAL_PATH)/filesystem\
-	$(LOCAL_PATH)/gui\
-	$(LOCAL_PATH)/windowing\
-	$(LOCAL_PATH)/windowing/themes\
-	$(LOCAL_PATH)/windowing/layouts\
-	$(LOCAL_PATH)/windowing/templates\
-	$(LOCAL_PATH)/windowing/toolbox\
-	$(LOCAL_PATH)/renderers/gl\
-	$(LOCAL_PATH)/renderers/gl/glx\
-	$(LOCAL_PATH)/renderers/gl/wgl\
-	$(LOCAL_PATH)/renderers/gles\
-	$(LOCAL_PATH)/renderers/gles/egl\
-	$(LOCAL_PATH)/input\
-	$(LOCAL_PATH)/input/android
-
-LOCAL_CPPFLAGS	:= -g -fexceptions
-LOCAL_LDLIBS	:= -llog -landroid -lEGL -lGLESv1_CM
-LOCAL_STATIC_LIBRARIES := android_native_app_glue
-include $(BUILD_STATIC_LIBRARY)
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE    := simple
-LOCAL_SRC_FILES :=	tests/chainsawbuffet/maain.cpp\
-					tests/chainsawbuffet/Globals.cpp\
-					tests/chainsawbuffet/entities/Pg.cpp\
-					tests/chainsawbuffet/entities/Zombie.cpp\
-					tests/chainsawbuffet/entities/SolidSceneNode.cpp\
-					tests/chainsawbuffet/entities/Joystick.cpp\
-					tests/chainsawbuffet/scenes/ArenaScene.cpp\
-					tests/chainsawbuffet/entities/Bullet.cpp
-LOCAL_SHARED_LIBRARIES := crown
-LOCAL_C_INCLUDES	:=\
-	$(LOCAL_PATH)/core\
-	$(LOCAL_PATH)/core/math\
-	$(LOCAL_PATH)/core/containers\
-	$(LOCAL_PATH)/core/bv\
-	$(LOCAL_PATH)/core/mem\
-	$(LOCAL_PATH)/core/streams\
-	$(LOCAL_PATH)/loaders\
-	$(LOCAL_PATH)/renderers\
-	$(LOCAL_PATH)/things\
-	$(LOCAL_PATH)/filesystem\
-	$(LOCAL_PATH)/gui\
-	$(LOCAL_PATH)/windowing\
-	$(LOCAL_PATH)/windowing/themes\
-	$(LOCAL_PATH)/windowing/layouts\
-	$(LOCAL_PATH)/windowing/templates\
-	$(LOCAL_PATH)/windowing/toolbox\
-	$(LOCAL_PATH)/renderers/gl\
-	$(LOCAL_PATH)/renderers/gl/glx\
-	$(LOCAL_PATH)/renderers/gl/wgl\
-	$(LOCAL_PATH)/renderers/gles\
-	$(LOCAL_PATH)/renderers/gles/egl\
-	$(LOCAL_PATH)/input\
-	$(LOCAL_PATH)/input/android\
-	$(LOCAL_PATH)/tests\
-	$(LOCAL_PATH)/tests/chainsawbuffet\
-	$(LOCAL_PATH)/tests/chainsawbuffet/entities\
-	$(LOCAL_PATH)/tests/chainsawbuffet/scenes\
-
-LOCAL_CPPFLAGS	:= -g -fexceptions
-LOCAL_LDLIBS	:= -llog -landroid -lEGL -lGLESv1_CM -lz
-LOCAL_STATIC_LIBRARIES := android_native_app_glue
-include $(BUILD_SHARED_LIBRARY)
-$(call import-module,android/native_app_glue)
-

+ 0 - 2
src/Application.mk

@@ -1,2 +0,0 @@
-APP_PLATFORM := android-9
-APP_STL := gnustl_static

+ 4 - 4
src/CMakeLists.txt

@@ -6,8 +6,6 @@ set (SRC
 	Font.cpp
 	Image.cpp
 	MaterialResource.cpp
-	MovableCamera.cpp
-	Pixel.cpp
 	ResourceManager.cpp
 	Skybox.cpp
 	Terrain.cpp
@@ -34,8 +32,6 @@ set (HEADERS
 	Glyph.h
 	Image.h
 	MaterialResource.h
-	MovableCamera.h
-	Pixel.h
 	Resource.h
 	ResourceManager.h
 	ResourceArchive.h
@@ -155,12 +151,14 @@ set (STRINGS_HEADERS
 
 set (MEM_SRC
 	core/mem/MallocAllocator.cpp
+	core/mem/ProxyAllocator.cpp
 )
 
 set (MEM_HEADERS
 	core/mem/Memory.h
 	core/mem/Allocator.h
 	core/mem/MallocAllocator.h
+	core/mem/ProxyAllocator.h
 )
 
 set (COMPRESSORS_SRC
@@ -207,6 +205,7 @@ set (INPUT_HEADERS
 
 set (RENDERERS_SRC
 	renderers/DebugRenderer.cpp
+	renderers/Pixel.cpp
 )
 
 set (RENDERERS_HEADERS
@@ -217,6 +216,7 @@ set (RENDERERS_HEADERS
 	renderers/Material.h
 	renderers/Texture.h
 	renderers/DebugRenderer.h
+	renderers/Pixel.h
 )
 
 set (OS_HEADERS

+ 123 - 69
src/Camera.cpp

@@ -24,153 +24,207 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "Camera.h"
-#include "Device.h"
 #include "Types.h"
-#include "Renderer.h"
+#include "MathUtils.h"
 
 namespace crown
 {
 
-Camera::Camera(const Vec3& position, bool visible, float fov, float aspect, bool active) :
-	mPosition(position),
-	mLookAt(0, 0, -1),
-	mUp(0, 1, 0),
-	mFOV(fov),
-	mAspect(aspect),
-	mNear(0.1f),
-	mFar(1000.0f),
-	mActive(active),
-	mAutoAspect(true)
+//-----------------------------------------------------------------------------
+Camera::Camera(const Vec3& position, float fov, float aspect) :
+	m_position(position),
+	m_look_at(0, 0, -1),
+	m_up(0, 1, 0),
+
+	m_rot_factor(0.0f, 0.0f),
+	m_angle_x(0.0f),
+	m_angle_y(0.0f),
+
+	m_FOV(fov),
+	m_aspect(aspect),
+	m_near(0.1f),
+	m_far(1000.0f)
 {
-	UpdateProjectionMatrix();
-	UpdateViewMatrix();
-	UpdateFrustum();
+	update_projection_matrix();
+	update_view_matrix();
+	update_frustum();
 }
 
-Camera::~Camera()
+//-----------------------------------------------------------------------------
+const Vec3& Camera::position() const
 {
+	return m_position;
 }
 
-void Camera::SetPosition(const Vec3& position)
+//-----------------------------------------------------------------------------
+void Camera::set_position(const Vec3& position)
 {
-	mPosition = position;
-	UpdateViewMatrix();
+	m_position = position;
+
+	update_view_matrix();
 }
 
-const Vec3& Camera::GetLookAt() const
+//-----------------------------------------------------------------------------
+const Vec3& Camera::look_at() const
 {
-	return mLookAt;
+	return m_look_at;
 }
 
-void Camera::SetLookAt(const Vec3& lookat)
+//-----------------------------------------------------------------------------
+void Camera::set_look_at(const Vec3& lookat)
 {
-	mLookAt = lookat;
-	UpdateViewMatrix();
+	m_look_at = lookat;
+
+	update_view_matrix();
 }
 
-const Vec3& Camera::GetUpVector() const
+//-----------------------------------------------------------------------
+void Camera::set_rotation(const float x, const float y)
 {
-	return mUp;
+	Vec3 right(1, 0, 0);
+	Vec3 look;
+
+	look.x = 0.0f;
+	look.y = math::sin(x);
+	look.z = -math::cos(x);
+
+	Vec3 up = right.cross(look);
+	up.normalize();
+
+	Mat3 m;
+	m.build_rotation_y(y);
+	look = m * look;
+	m_up = m * up;
+
+	set_look_at(look);
 }
 
-bool Camera::IsActive() const
+//-----------------------------------------------------------------------------
+const Vec3& Camera::up() const
 {
-	return mActive;
+	return m_up;
 }
 
-void Camera::SetActive(bool active)
+//-----------------------------------------------------------------------------
+float Camera::fov() const
 {
-	mActive = active;
+	return m_FOV;
 }
 
-float Camera::GetFOV() const
+//-----------------------------------------------------------------------------
+void Camera::set_fov(float fov)
 {
-	return mFOV;
+	m_FOV = fov;
+
+	update_projection_matrix();
 }
 
-void Camera::SetFOV(float fov)
+//-----------------------------------------------------------------------------
+float Camera::aspect() const
 {
-	mFOV = fov;
-	UpdateProjectionMatrix();
+	return m_aspect;
 }
 
-bool Camera::GetAutoAspect() const
+//-----------------------------------------------------------------------------
+void Camera::set_aspect(float aspect)
 {
-	return mAutoAspect;
+	m_aspect = aspect;
+
+	update_projection_matrix();
 }
 
-void Camera::SetAutoAspect(bool autoAspect)
+//-----------------------------------------------------------------------------
+float Camera::near_clip_distance() const
 {
-	mAutoAspect = autoAspect;
+	return m_near;
 }
 
-float Camera::GetAspect() const
+//-----------------------------------------------------------------------------
+void Camera::set_near_clip_distance(float near)
 {
-	return mAspect;
+	m_near = near;
+
+	update_projection_matrix();
 }
 
-void Camera::SetAspect(float aspect)
+//-----------------------------------------------------------------------------
+float Camera::far_clip_distance() const
 {
-	mAspect = aspect;
-	UpdateProjectionMatrix();
+	return m_far;
 }
 
-float Camera::GetNearClipDistance() const
+//-----------------------------------------------------------------------------
+void Camera::set_far_clip_distance(float far)
 {
-	return mNear;
+	m_far = far;
+
+	update_projection_matrix();
 }
 
-void Camera::SetNearClipDistance(float near)
+//-----------------------------------------------------------------------------
+const Mat4& Camera::projection_matrix() const
 {
-	mNear = near;
-	UpdateProjectionMatrix();
+	return m_projection;
 }
 
-float Camera::GetFarClipDistance() const
+//-----------------------------------------------------------------------------
+const Mat4& Camera::view_matrix() const
 {
-	return mFar;
+	return m_view;
 }
 
-void Camera::SetFarClipDistance(float far)
+//-----------------------------------------------------------------------------
+const Frustum& Camera::frustum() const
 {
-	mFar = far;
-	UpdateProjectionMatrix();
+	return m_frustum;
 }
 
-const Mat4& Camera::GetProjectionMatrix() const
+//-----------------------------------------------------------------------------
+void Camera::update_projection_matrix()
 {
-	return mProjection;
+	m_projection.build_projection_perspective_rh(m_FOV, m_aspect, m_near, m_far);
 }
 
-const Mat4& Camera::GetViewMatrix() const
+//-----------------------------------------------------------------------------
+void Camera::update_view_matrix()
 {
-	return mView;
+	m_view.build_look_at_rh(m_position, m_position + m_look_at, m_up);
 }
 
-const Frustum& Camera::GetFrustum() const
+//-----------------------------------------------------------------------------
+void Camera::update_frustum()
 {
-	return mFrustum;
+	m_frustum.from_matrix(m_projection * m_view);
 }
 
-void Camera::Render()
+//-----------------------------------------------------------------------------
+void Camera::move_forward(float meters)
 {
-	device()->renderer()->set_matrix(MT_PROJECTION, mProjection);
-	device()->renderer()->set_matrix(MT_VIEW, mView);
+	set_position(m_position + m_look_at * meters);
 }
 
-void Camera::UpdateProjectionMatrix()
+//-----------------------------------------------------------------------
+void Camera::move_backward(float meters)
 {
-	mProjection.build_projection_perspective_rh(mFOV, mAspect, mNear, mFar);
+	set_position(m_position + m_look_at * -meters);
 }
 
-void Camera::UpdateViewMatrix()
+//-----------------------------------------------------------------------
+void Camera::strafe_left(float meters)
 {
-	mView.build_look_at_rh(mPosition, mPosition + mLookAt, mUp);
+	Vec3 left = m_up.cross(m_look_at);
+	left.normalize();
+
+	set_position(m_position + left * meters);
 }
 
-void Camera::UpdateFrustum()
+//-----------------------------------------------------------------------
+void Camera::strafe_right(float meters)
 {
-	mFrustum.from_matrix(mProjection * mView);
+	Vec3 left = m_up.cross(m_look_at);
+	left.normalize();
+
+	set_position(m_position + left * -meters);
 }
 
 } // namespace crown

+ 63 - 62
src/Camera.h

@@ -28,107 +28,108 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "Frustum.h"
 #include "Mat4.h"
+#include "Mat3.h"
 #include "Vec3.h"
 
 namespace crown
 {
 
+/// Represents the point of view into the game world.
 class Camera
 {
-
 public:
 
-	//! Constructor
-	Camera(const Vec3& position, bool visible, float fov, float aspect, bool active);
-
-	//! Destructor
-	virtual ~Camera();
+	/// Construct the camera placed at the given world-space @position
+	/// with the given @fov field of view and @aspect ratio.
+					Camera(const Vec3& position, float fov, float aspect);
 
-	//! Sets the camera's position
-	void SetPosition(const Vec3& position);
+	/// Returns the world-space position of the camera 
+	const Vec3&		position() const;
 
-	//! Returns the camera's lookat-point32_t
-	const Vec3& GetLookAt() const;
+	/// Sets the world-space @position of the camera
+	void			set_position(const Vec3& position);
 
-	//! Sets the camera's lookat-point32_t
-	void SetLookAt(const Vec3& lookat);
+	/// Returns the lookat-point of the camera
+	const Vec3&		look_at() const;
 
-	//! Returns the camera's up vector
-	const Vec3& GetUpVector() const;
+	/// Sets the lookat-point of the camera
+	void			set_look_at(const Vec3& lookat);
 
-	//! Returns whether the camera is active
-	bool IsActive() const;
+	/// Sets the rotation of the camera about the world's @x axis and @y axis
+	void			set_rotation(const float x, const float y);
 
-	//! Sets whether the camera is active
-	void SetActive(bool active);
+	/// Returns the up-vector of the camera
+	const Vec3&		up() const;
 
-	//! Returns the camera's Field Of View
-	float GetFOV() const;
+	/// Returns the field of view of the camera in degrees
+	float			fov() const;
 
-	//! Sets the camera's Field Of View
-	void SetFOV(float fov);
+	/// Sets the field of view of the camera
+	void			set_fov(float fov);
 
-	//! Returns whether the camera automatically adjusts aspect ratio based on the Viewport
-	bool GetAutoAspect() const;
+	/// Returns the aspect ratio of the camera
+	float			aspect() const;
 
-	//! Sets whether the camera automatically adjusts aspect ratio based on the Viewport
-	void SetAutoAspect(bool autoAspect);
+	/// Sets the aspect ration of the camera
+	void			set_aspect(float aspect);
 
-	//! Returns the camera's aspect ratio
-	float GetAspect() const;
+	/// Returns the near clipping distance of the camera
+	float			near_clip_distance() const;
 
-	//! Sets the camera's aspect ratio
-	void SetAspect(float aspect);
+	/// Sets the near clipping distance of the camera
+	void			set_near_clip_distance(float near);
 
-	//! Returns the camera's near clipping distance
-	float GetNearClipDistance() const;
+	/// Returns the far clipping distance of the camera
+	float			far_clip_distance() const;
 
-	//! Sets the camera's near clipping distance
-	void SetNearClipDistance(float near);
+	/// Sets the far clipping distance of the camera
+	void			set_far_clip_distance(float far);
 
-	//! Returns the camera's far clipping distance
-	float GetFarClipDistance() const;
+	/// Returns the view-frustum of the camera
+	const Frustum&	frustum() const;
 
-	//! Sets the camera's far clipping distance
-	void SetFarClipDistance(float far);
+	/// Returns the renderer-independent projection matrix used by the camera
+	const Mat4&		projection_matrix() const;
 
-	//! Returns the camera's view frustum
-	const Frustum& GetFrustum() const;
+	/// Returns the renderer-independent view matrix used by the camera
+	const Mat4&		view_matrix() const;
 
-	//! Returns the projection matrix
-	const Mat4& GetProjectionMatrix() const;
+	/// Moves the camera towards look direction by @meters meters
+	void			move_forward(float meters);
 
-	//! Returns the view matrix
-	const Mat4& GetViewMatrix() const;
+	/// Moves the camera towards the opposite look direction by @meters meters
+	void			move_backward(float meters);
 
-	//! Loads the view and projection matrix
-	virtual void Render();
+	/// Moves the camera along the axis perpendicular to the look direction by @meters meters
+	void			strafe_left(float meters);
 
-	const Vec3& GetPosition() const { return mPosition; }
+	/// Moves the camera along the axis perpendicular to the look direction by @meters meters
+	void			strafe_right(float meters);
 
 protected:
 
-	void UpdateProjectionMatrix();
-	void UpdateViewMatrix();
-	void UpdateFrustum();
+	void			update_projection_matrix();
+	void			update_view_matrix();
+	void			update_frustum();
 
-	Vec3 mPosition;
-	Vec3 mLookAt;
-	Vec3 mUp;
+	Vec3			m_position;
+	Vec3			m_look_at;
+	Vec3			m_up;
 
-	Mat4 mView;
-	Mat4 mProjection;
+	Vec2			m_rot_factor;
+	float			m_angle_x;
+	float			m_angle_y;
 
-	Frustum mFrustum;
+	Mat4			m_view;
+	Mat4			m_projection;
 
-	float mFOV;
-	float mAspect;
+	Frustum			m_frustum;
 
-	float mNear;
-	float mFar;
+	float			m_FOV;
+	float			m_aspect;
 
-	bool mActive		: 1;
-	bool mAutoAspect	: 1;
+	float			m_near;
+	float			m_far;
 };
 
 } // namespace crown

+ 3 - 26
src/Crown.h

@@ -28,6 +28,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 // Core
 #include "Types.h"
 #include "Args.h"
+#include "Log.h"
 
 // Core/Math
 #include "Color4.h"
@@ -70,6 +71,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Memory.h"
 #include "Allocator.h"
 #include "MallocAllocator.h"
+#include "ProxyAllocator.h"
 
 // Core/Streams
 #include "Stream.h"
@@ -97,9 +99,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Font.h"
 #include "Glyph.h"
 #include "Image.h"
-#include "Log.h"
-#include "MovableCamera.h"
-#include "Pixel.h"
 #include "ResourceArchive.h"
 #include "ArchiveResourceArchive.h"
 #include "FileResourceArchive.h"
@@ -129,27 +128,5 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Material.h"
 #include "Texture.h"
 #include "DebugRenderer.h"
+#include "Pixel.h"
 
-//// Engine/Windowing
-//#include "Bind.h"
-//#include "Button.h"
-//#include "DragArea.h"
-//#include "ItemsSelector.h"
-//#include "ItemsWidget.h"
-//#include "ListView.h"
-//#include "Property.h"
-//#include "ScrollArea.h"
-//#include "SpecificProperties.h"
-//#include "StackLayout.h"
-//#include "TextBox.h"
-//#include "Themes.h"
-//#include "ThemeSpriteWidget.h"
-//#include "TreeView.h"
-//#include "Widget.h"
-//#include "Window.h"
-//#include "WindowContext.h"
-//#include "WindowingEventArgs.h"
-//#include "WindowsManager.h"
-
-// Engine/Windowing/Toolbox
-//#include "TextInputWindow.h"

+ 108 - 46
src/Device.cpp

@@ -64,6 +64,12 @@ Device::Device() :
 	m_is_init(false),
 	m_is_running(false),
 
+	m_frame_count(0),
+
+	m_last_time(0),
+	m_current_time(0),
+	m_last_delta_time(0.0f),
+
 	m_filesystem(NULL),
 	m_resource_manager(NULL),
 	m_input_manager(NULL),
@@ -101,54 +107,15 @@ bool Device::init(int argc, char** argv)
 	// Initialize
 	Log::i("Initializing Crown Engine %d.%d.%d...", CROWN_VERSION_MAJOR, CROWN_VERSION_MINOR, CROWN_VERSION_MICRO);
 
-	// Select current dir if no root path provided
-	if (string::strcmp(m_preferred_root_path, string::EMPTY) == 0)
-	{
-		m_filesystem = new Filesystem(os::get_cwd());
-	}
-	else
-	{
-		m_filesystem = new Filesystem(m_preferred_root_path);
-	}
+	create_filesystem();
 
-	// Select appropriate resource archive
-	if (m_preferred_mode == MODE_DEVELOPMENT)
-	{
-		m_resource_archive = new FileResourceArchive(*m_filesystem);
-	}
-	else
-	{
-		m_resource_archive = new ArchiveResourceArchive(*m_filesystem);
-	}
+	create_resource_manager();
 
-	// Create resource manager
-	m_resource_manager = new ResourceManager(*m_resource_archive, m_resource_allocator);
+	create_input_manager();
 
-	// Create input manager
-	m_input_manager = new InputManager();
+	create_renderer();
 
-	// Select appropriate renderer
-	if (m_preferred_renderer == RENDERER_GL)
-	{
-		#ifdef CROWN_BUILD_OPENGL
-		m_renderer = new GLRenderer;
-		#else
-		Log::e("Crown Engine was not built with OpenGL support.");
-		return false;
-		#endif
-	}
-	else if (m_preferred_renderer == RENDERER_GLES)
-	{
-		#ifdef CROWN_BUILD_OPENGLES
-		m_renderer = new GLESRenderer;
-		#else
-		Log::e("Crown Engine was not built with OpenGL|ES support.");
-		return false;
-		#endif
-	}
-
-	// Create debug renderer
-	m_debug_renderer = new DebugRenderer(*m_renderer);
+	create_debug_renderer();
 
 	Log::i("Crown Engine initialized.");
 
@@ -159,7 +126,7 @@ bool Device::init(int argc, char** argv)
 
 	if (m_game_library == NULL)
 	{
-		Log::e("Error while loading game library.");
+		Log::e("Unable to load the game.");
 		return false;
 	}
 
@@ -279,6 +246,8 @@ void Device::start()
 	}
 
 	m_is_running = true;
+
+	m_last_time = os::milliseconds();
 }
 
 //-----------------------------------------------------------------------------
@@ -299,18 +268,111 @@ bool Device::is_running() const
 	return m_is_running;
 }
 
+//-----------------------------------------------------------------------------
+uint64_t Device::frame_count() const
+{
+	return m_frame_count;
+}
+
+//-----------------------------------------------------------------------------
+float Device::last_delta_time() const
+{
+	return m_last_delta_time;
+}
+
 //-----------------------------------------------------------------------------
 void Device::frame()
 {
+	m_current_time = os::milliseconds();
+	m_last_delta_time = (m_current_time - m_last_time) / 1000.0f;
+	m_last_time = m_current_time;
+
+	if (frame_count() % 5 == 0)
+	{
+		m_resource_manager->flush_load_queue();
+		m_resource_manager->bring_loaded_online();
+	}
+
 	m_input_manager->event_loop();
 
 	m_renderer->begin_frame();
 
-	m_game->update();
+	m_game->update(last_delta_time());
 
 	m_debug_renderer->draw_all();
 
 	m_renderer->end_frame();
+
+	m_frame_count++;
+}
+
+//-----------------------------------------------------------------------------
+void Device::create_filesystem()
+{
+	// Select current dir if no root path provided
+	if (string::strcmp(m_preferred_root_path, string::EMPTY) == 0)
+	{
+		m_filesystem = new Filesystem(os::get_cwd());
+	}
+	else
+	{
+		m_filesystem = new Filesystem(m_preferred_root_path);
+	}
+}
+
+//-----------------------------------------------------------------------------
+void Device::create_resource_manager()
+{
+	// Select appropriate resource archive
+	if (m_preferred_mode == MODE_DEVELOPMENT)
+	{
+		m_resource_archive = new FileResourceArchive(*m_filesystem);
+	}
+	else
+	{
+		m_resource_archive = new ArchiveResourceArchive(*m_filesystem);
+	}
+
+	// Create resource manager
+	m_resource_manager = new ResourceManager(*m_resource_archive, m_resource_allocator);
+}
+
+//-----------------------------------------------------------------------------
+void Device::create_input_manager()
+{
+	// Create input manager
+	m_input_manager = new InputManager();
+}
+
+//-----------------------------------------------------------------------------
+void Device::create_renderer()
+{
+	// Select appropriate renderer
+	if (m_preferred_renderer == RENDERER_GL)
+	{
+		#ifdef CROWN_BUILD_OPENGL
+		m_renderer = new GLRenderer;
+		#else
+		Log::e("Crown Engine was not built with OpenGL support.");
+		assert(false);
+		#endif
+	}
+	else if (m_preferred_renderer == RENDERER_GLES)
+	{
+		#ifdef CROWN_BUILD_OPENGLES
+		m_renderer = new GLESRenderer;
+		#else
+		Log::e("Crown Engine was not built with OpenGL|ES support.");
+		assert(false);
+		#endif
+	}
+}
+
+//-----------------------------------------------------------------------------
+void Device::create_debug_renderer()
+{
+	// Create debug renderer
+	m_debug_renderer = new DebugRenderer(*m_renderer);
 }
 
 //-----------------------------------------------------------------------------

+ 19 - 1
src/Device.h

@@ -65,6 +65,14 @@ public:
 	/// Returns whether the engine is correctly initialized
 	bool					is_init() const;
 
+	/// Return the number of frames rendered from the first
+	/// call to Device::start()
+	uint64_t				frame_count() const;
+
+	/// Returns the time in milliseconds needed to render
+	/// the last frame
+	float					last_delta_time() const;
+
 	/// Forces the engine to actually start doing work.
 	void					start();
 
@@ -83,7 +91,11 @@ public:
 
 private:
 
-	
+	void					create_filesystem();
+	void					create_resource_manager();
+	void					create_input_manager();
+	void					create_renderer();
+	void					create_debug_renderer();
 
 	bool					parse_command_line(int argc, char** argv);
 	void					print_help_message();
@@ -103,6 +115,12 @@ private:
 	bool					m_is_init		: 1;
 	bool					m_is_running	: 1;
 
+	uint64_t				m_frame_count;
+
+	uint64_t				m_last_time;
+	uint64_t				m_current_time;
+	float					m_last_delta_time;
+
 	// Public subsystems
 	Filesystem*				m_filesystem;
 	ResourceManager*		m_resource_manager;

+ 16 - 13
src/FPSSystem.cpp

@@ -24,7 +24,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 */
 
 #include "InputManager.h"
-#include "MovableCamera.h"
+#include "Camera.h"
 #include "FPSSystem.h"
 #include "Vec2.h"
 #include "Vec3.h"
@@ -36,8 +36,10 @@ namespace crown
 {
 
 //-----------------------------------------------------------------------
-FPSSystem::FPSSystem(MovableCamera* camera) :
+FPSSystem::FPSSystem(Camera* camera, float speed, float sensibility) :
 	m_camera(camera),
+	m_camera_speed(speed),
+	m_camera_sensibility(sensibility),
 
 	m_angle_x(0),
 	m_angle_y(0),
@@ -133,41 +135,42 @@ void FPSSystem::accelerometer_changed(const AccelerometerEvent& event)
 	set_view_by_cursor();
 }
 //-----------------------------------------------------------------------
-void FPSSystem::set_camera(MovableCamera* camera)
+void FPSSystem::set_camera(Camera* camera)
 {
 	m_camera = camera;
 }
 
 //-----------------------------------------------------------------------
-MovableCamera* FPSSystem::get_camera()
+Camera* FPSSystem::camera()
 {
 	return m_camera;
 }
 
 //-----------------------------------------------------------------------
-void FPSSystem::camera_render()
+void FPSSystem::update(float dt)
 {
 	if (m_up_pressed)
 	{
-		m_camera->MoveForward();
+		m_camera->move_forward(m_camera_speed * dt);
 	}
 
 	if (m_left_pressed)
 	{
-		m_camera->StrafeLeft();
+		m_camera->strafe_left(m_camera_speed * dt);
 	}		
 
 	if (m_down_pressed)
 	{
-		m_camera->MoveBackward();
+		m_camera->move_backward(m_camera_speed * dt);
 	}
 
 	if (m_right_pressed)
 	{
-		m_camera->StrafeRight();
+		m_camera->strafe_right(m_camera_speed * dt);
 	}
 
-	m_camera->Render();
+	device()->renderer()->set_matrix(MT_VIEW, m_camera->view_matrix());
+	device()->renderer()->set_matrix(MT_PROJECTION, m_camera->projection_matrix());
 }
 
 //-----------------------------------------------------------------------	
@@ -187,13 +190,13 @@ void FPSSystem::set_view_by_cursor()
 	device()->input_manager()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
 	lastPos = device()->input_manager()->get_cursor_relative_xy();
 
-	m_angle_x += delta.y * m_camera->GetSensibility();
-	m_angle_y += delta.x * m_camera->GetSensibility();
+	m_angle_x += delta.y * m_camera_sensibility;
+	m_angle_y += delta.x * m_camera_sensibility;
 
 	m_angle_x = math::clamp_to_range(-89.999f * math::DEG_TO_RAD, 89.999f * math::DEG_TO_RAD, m_angle_x);
 	m_angle_y = math::fmod(m_angle_y, math::TWO_PI);
 
-	m_camera->SetRotation(m_angle_x, m_angle_y);
+	m_camera->set_rotation(m_angle_x, m_angle_y);
 }
 
 } // namespace crown

+ 9 - 5
src/FPSSystem.h

@@ -32,6 +32,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Keyboard.h"
 #include "Touch.h"
 #include "Accelerometer.h"
+#include "Renderer.h"
 
 namespace crown
 {
@@ -41,12 +42,12 @@ class FPSSystem : public MouseListener, public KeyboardListener, public Accelero
 public:
 
 					/// Constructor
-					FPSSystem(MovableCamera* camera);
+					FPSSystem(Camera* camera, float speed, float sensibility);
 
-	void 			set_camera(MovableCamera* camera);
-	MovableCamera*	get_camera();
+	void 			set_camera(Camera* camera);
+	Camera*			camera();
 
-	void			camera_render();
+	void			update(float dt);
 	void			set_view_by_cursor();	
 
 	virtual void 	key_pressed(const KeyboardEvent& event);
@@ -55,7 +56,10 @@ public:
 
 private:
 
-	MovableCamera*	m_camera;
+	Camera*			m_camera;
+
+	float			m_camera_speed;
+	float			m_camera_sensibility;
 
 	real 			m_angle_x;
 	real 			m_angle_y;

+ 17 - 31
src/Filesystem.cpp

@@ -58,26 +58,16 @@ const char* Filesystem::build_os_path(const char* base_path, const char* relativ
 {
 	static char os_path[os::MAX_PATH_LENGTH];
 
-	size_t i = 0;
+	string::strncpy(os_path, base_path, os::MAX_PATH_LENGTH);
 
-	while (*base_path != '\0')
-	{
-		os_path[i++] = *base_path;
-		base_path++;
-	}
+	size_t base_path_len = string::strlen(base_path);
 
-	os_path[i++] = '/';
-
-	while (*relative_path != '\0')
-	{
-		os_path[i++] = *relative_path;
-		relative_path++;
-	}
+	os_path[base_path_len] = os::PATH_SEPARATOR;
 
-	os_path[i] = '\0';
+	string::strncpy(&os_path[base_path_len + 1], relative_path, os::MAX_PATH_LENGTH);
 
-	// Replace Crown-specific path separator with OS-speficic one
-	for (size_t j = 0; j < i; j++)
+	// FIXME FIXME FIXME Replace Crown-specific path separator with OS-speficic one
+	for (size_t j = 0; j < string::strlen(os_path); j++)
 	{
 		if (os_path[j] == '/')
 		{
@@ -89,12 +79,12 @@ const char* Filesystem::build_os_path(const char* base_path, const char* relativ
 }
 
 //-----------------------------------------------------------------------------
-bool Filesystem::get_info(const char* base_path, const char* relative_path, FilesystemEntry& info)
+bool Filesystem::get_info(const char* relative_path, FilesystemEntry& info)
 {
 	// Entering OS-DEPENDENT-PATH-MODE
-	// (i.e. os_path is of the form: C:\babbeo\relative_path or /babbeo/relative_path)
+	// (i.e. os_path is of the form: C:\foo\relative_path or /foo/relative_path)
 
-	const char* os_path = build_os_path(base_path, relative_path);
+	const char* os_path = build_os_path(m_root_path, relative_path);
 	
 	string::strncpy(info.os_path, os_path, os::MAX_PATH_LENGTH);
 	string::strncpy(info.relative_path, relative_path, os::MAX_PATH_LENGTH);
@@ -104,8 +94,7 @@ bool Filesystem::get_info(const char* base_path, const char* relative_path, File
 		info.type = FilesystemEntry::FILE;
 		return true;
 	}
-
-	if (os::is_dir(os_path))
+	else if (os::is_dir(os_path))
 	{
 		info.type = FilesystemEntry::DIRECTORY;
 		return true;
@@ -121,7 +110,7 @@ bool Filesystem::exists(const char* relative_path)
 {
 	FilesystemEntry dummy;
 
-	return get_info(m_root_path, relative_path, dummy);
+	return get_info(relative_path, dummy);
 }
 
 //-----------------------------------------------------------------------------
@@ -129,7 +118,7 @@ bool Filesystem::is_file(const char* relative_path)
 {
 	FilesystemEntry info;
 
-	if (get_info(m_root_path, relative_path, info))
+	if (get_info(relative_path, info))
 	{
 		return info.type == FilesystemEntry::FILE;
 	}
@@ -142,7 +131,7 @@ bool Filesystem::is_dir(const char* relative_path)
 {
 	FilesystemEntry info;
 
-	if (get_info(m_root_path, relative_path, info))
+	if (get_info(relative_path, info))
 	{
 		return info.type == FilesystemEntry::DIRECTORY;
 	}
@@ -183,20 +172,17 @@ bool Filesystem::delete_dir(const char* relative_path)
 }
 
 //-----------------------------------------------------------------------------
-Stream* Filesystem::open(const char* relative_path, StreamOpenMode mode)
+FileStream* Filesystem::open(const char* relative_path, StreamOpenMode mode)
 {
 	FilesystemEntry info;
-	Stream* stream;
-
-	get_info(m_root_path, relative_path, info);
 
-	stream = new FileStream(mode, info.os_path);
+	assert(get_info(relative_path, info) && info.type == FilesystemEntry::FILE);
 
-	return stream;
+	return new FileStream(mode, info.os_path);
 }
 
 //-----------------------------------------------------------------------------
-void Filesystem::close(Stream* stream)
+void Filesystem::close(FileStream* stream)
 {
 	delete stream;
 }

+ 32 - 25
src/Filesystem.h

@@ -26,8 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "String.h"
-#include "Stream.h"
 #include "OS.h"
+#include "Stream.h"
 
 namespace crown
 {
@@ -49,8 +49,8 @@ struct FilesystemEntry
 	char			relative_path[os::MAX_PATH_LENGTH];	///< Relative path of the entry
 };
 
-/// Filesystem.
-///
+class FileStream;
+
 /// Provides a platform-independent way to access files and directories
 /// on the host filesystem.
 ///
@@ -71,14 +71,13 @@ struct FilesystemEntry
 ///                             // so it refers to "/home/foo/bar.txt"
 ///
 /// The filesystem will take care of the necessary path conversions.
-/// The root path can be really anything: platform-specific/absolute/relative/whatever.
-/// Examples of valid root paths.
+/// The root path must be an absolute path for the underlying operating system.
+/// Examples of valid root paths:
 ///
 /// 1) "/home/foo"
 /// 2) "C:\Users\Phil"
-/// 3) "\abc$\/..)?/"
 ///
-/// The relative paths must follow some strict rules:
+/// The relative paths, used to access files, must follow some strict rules:
 ///
 /// a) Only unix-like pathnames (i.e. case sensitive and using '/' as separator)
 ///    are allowed.
@@ -94,53 +93,61 @@ struct FilesystemEntry
 ///
 /// Examples of valid relative paths.
 ///
-/// data/textures/grass.texture
-/// grass.texture
-/// foo/bar
+/// 1) data/textures/grass.texture
+/// 2) grass.texture
+/// 3) foo/bar
 class Filesystem
 {
 public:
 
-						/// The @root_path must be absolute.
+	/// The @root_path must be absolute.
 						Filesystem(const char* root_path);
 						~Filesystem();
 
-						/// Returns the root path of the filesystem
+	/// Returns the root path of the filesystem
 	const char*			root_path() const;
 
-						/// TODO
-	bool				get_info(const char* base_path, const char* relative_path, FilesystemEntry& info);
+	/// Returns whether the @relative_path exists and fills @info with
+	/// with informations about the given @relative_path path
+	bool				get_info(const char* relative_path, FilesystemEntry& info);
 	
-						/// Returns whether the @relative_path exists on disk
+	/// Returns whether the @relative_path exists on disk
 	bool				exists(const char* relative_path);
 
-						/// Returns whether @relative_path is a regular file
+	/// Returns whether @relative_path is a regular file
 	bool				is_file(const char* relative_path);
-						/// Returns whether @relative_path if a directory
+
+	/// Returns whether @relative_path is a directory
 	bool				is_dir(const char* relative_path);
 
-						/// Creates a regular file named @relative_path
+	/// Creates a regular file named @relative_path
 	bool				create_file(const char* relative_path);
-						/// Creates a directory named @relative_path
+
+	/// Creates a directory named @relative_path
 	bool				create_dir(const char* relative_path);
 
-						/// Deletes the regular file @relative_path
+	/// Deletes the regular file @relative_path
 	bool				delete_file(const char* relative_path);
-						/// Deletes the directory @relative_path
+
+	/// Deletes the directory @relative_path
 	bool				delete_dir(const char* relative_path);
 
-	Stream*				open(const char* relative_path, StreamOpenMode mode);
-	void				close(Stream* stream);
+	/// Opens the file @relative_path with the specified access @mode
+	FileStream*			open(const char* relative_path, StreamOpenMode mode);
+
+	/// Closes a previously opened file @stream
+	void				close(FileStream* stream);
 	
 private:
 
-	const char*			build_os_path(const char* basePath, const char* relative_path);
+	// Builds the OS-dependent path from base_path and relative_path
+	const char*			build_os_path(const char* base_path, const char* relative_path);
 	
 private:
 
 	char				m_root_path[os::MAX_PATH_LENGTH];
 
-						// Disable copying
+	// Disable copying
 						Filesystem(const Filesystem&);
 	Filesystem&			operator=(const Filesystem&);
 

+ 5 - 5
src/Image.cpp

@@ -115,14 +115,14 @@ PixelFormat Image::GetFormat() const
 	return mPixelFormat;
 }
 
-uint32_t Image::GetBitsPerPixel() const
+uint32_t Image::GetBytesPerPixel() const
 {
-	return Pixel::GetBitsPerPixel(mPixelFormat);
+	return Pixel::bytes_per_pixel(mPixelFormat);
 }
 
-uint32_t Image::GetBytesPerPixel() const
+uint32_t Image::GetBitsPerPixel() const
 {
-	return Pixel::GetBytesPerPixel(mPixelFormat);
+	return Pixel::bytes_per_pixel(mPixelFormat);
 }
 
 uint8_t* Image::GetBuffer()
@@ -215,7 +215,7 @@ void Image::SetPixel(uint32_t x, uint32_t y, Color4 color)
 		throw ArgumentException("Coordinates outside the Image");
 	}*/
 
-	int32_t bpp = 3;//GetBytesPerPixel();
+	int32_t bpp = 3;//bytes_per_pixel();
 	int32_t offset = (y * mWidth + x) * GetBytesPerPixel();
 	mBuffer[offset    ] = (uint8_t)(color.r * 255);
 	mBuffer[offset + 1] = (uint8_t)(color.g * 255);

+ 0 - 145
src/MovableCamera.cpp

@@ -1,145 +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 "Device.h"
-#include "Mat3.h"
-#include "Types.h"
-#include "MovableCamera.h"
-#include "Device.h"
-#include "InputManager.h"
-
-namespace crown
-{
-//-----------------------------------------------------------------------
-MovableCamera::MovableCamera(const Vec3& position, bool visible, float fov, float aspect, bool active, float speed, float sensibility) :
-	Camera(position, visible, fov, aspect, active),
-	mSpeed(speed),
-	mSensibility(sensibility)
-{
-	mRotFactor = Vec2(0.0f, 0.0f);
-	mAngleX = 0.0f;
-	mAngleY = 0.0f;
-}
-
-//-----------------------------------------------------------------------
-MovableCamera::~MovableCamera()
-{
-}
-
-//-----------------------------------------------------------------------
-float MovableCamera::GetSensibility() const
-{
-	return mSensibility;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::SetActive(bool active)
-{
-	Camera::SetActive(active);
-	device()->input_manager()->set_cursor_relative_xy(Vec2(0.5f, 0.5f));
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::SetSensibility(float sensibility)
-{
-	mSensibility = sensibility;
-}
-
-//-----------------------------------------------------------------------
-float MovableCamera::GetSpeed() const
-{
-	return mSpeed;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::SetSpeed(float speed)
-{
-	mSpeed = speed;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::Render()
-{
-	if (!mActive)
-	{
-		return;
-	}
-
-	UpdateViewMatrix();
-
-	Camera::Render();
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::MoveForward()
-{
-	mPosition += mLookAt * mSpeed;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::MoveBackward()
-{
-	mPosition -= mLookAt * mSpeed;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::StrafeLeft()
-{
-	Vec3 left = mUp.cross(mLookAt);
-	left.normalize();
-	mPosition += left * mSpeed;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::StrafeRight()
-{
-	Vec3 left = mUp.cross(mLookAt);
-	left.normalize();
-	mPosition -= left * mSpeed;
-}
-
-//-----------------------------------------------------------------------
-void MovableCamera::SetRotation(const float x, const float y)
-{
-	Vec3 right(1, 0, 0);
-	Vec3 look;
-
-	look.x = 0.0f;
-	look.y = math::sin(x);
-	look.z = -math::cos(x);
-
-	Vec3 up = right.cross(look);
-	up.normalize();
-
-	Mat3 m;
-	m.build_rotation_y(y);
-	look = m * look;
-	mUp = m * up;
-
-	Camera::SetLookAt(look);
-}
-
-} // namespace crown
-

+ 1 - 1
src/Terrain.cpp

@@ -278,7 +278,7 @@ void Terrain::Render()
 {
 	Renderer* renderer = device()->renderer();
 
-	renderer->render_triangles(
+	renderer->draw_triangles(
 				mVertices[0].to_float_ptr(),
 				mNormals[0].to_float_ptr(),
 				mTexCoords[0].to_float_ptr(),

+ 1 - 1
src/TextureResource.cpp

@@ -23,7 +23,7 @@ void* TextureResource::load(Allocator& allocator, ResourceArchive& archive, Reso
 		stream->read(&resource->m_width, sizeof(uint16_t));
 		stream->read(&resource->m_height, sizeof(uint16_t));
 	
-		size_t size = resource->m_width * resource->m_height * Pixel::GetBytesPerPixel(resource->m_format);
+		size_t size = resource->m_width * resource->m_height * Pixel::bytes_per_pixel(resource->m_format);
 
 		resource->m_data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
 

+ 58 - 0
src/core/mem/ProxyAllocator.cpp

@@ -0,0 +1,58 @@
+/*
+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 "ProxyAllocator.h"
+#include "Allocator.h"
+
+namespace crown
+{
+
+//-----------------------------------------------------------------------------
+ProxyAllocator::ProxyAllocator(Allocator& allocator, const char* name) :
+	m_allocator(allocator),
+	m_name(name)
+{
+	assert(name != NULL);
+}
+
+//-----------------------------------------------------------------------------
+void* ProxyAllocator::allocate(size_t size, size_t align)
+{
+	return m_allocator.allocate(size, align);
+}
+
+//-----------------------------------------------------------------------------
+void ProxyAllocator::deallocate(void* data)
+{
+	m_allocator.deallocate(data);
+}
+
+//-----------------------------------------------------------------------------
+const char* ProxyAllocator::name() const
+{
+	return m_name;
+}
+
+} // namespace crown

+ 16 - 41
src/MovableCamera.h → src/core/mem/ProxyAllocator.h

@@ -26,59 +26,34 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 #include "Types.h"
-#include "Camera.h"
-#include "Vec2.h"
-#include "Mouse.h"
-#include "Keyboard.h"
+#include "Memory.h"
 
 namespace crown
 {
 
-class MovableCamera : public Camera
-{
+class Allocator;
 
+/// Offers the facility to tag allocations by a string identifier.
+class ProxyAllocator
+{
 public:
 
-	//! Constructor
-	MovableCamera(const Vec3& position, bool visible, float fov, float aspect,
-					bool active, float speed, float sensibility);
-
-	//! Destructor
-	~MovableCamera();
-
-	//! Returns the camera's movement sensibility
-	float GetSensibility() const;
-
-	//! Sets the camera's movement sensibility
-	void SetSensibility(float sensibility);
+	/// Tag all allocations made with @allocator by the given @name
+					ProxyAllocator(Allocator& allocator, const char* name);
 
-	//! Returns the camera's speed
-	float GetSpeed() const;
+	/// @copydoc Allocator::allocate()
+	void*			allocate(size_t size, size_t align = memory::DEFAULT_ALIGN);
 
-	//! Sets the camera speed
-	void SetSpeed(float speed);
+	/// @copydoc Allocator::deallocate()
+	void			deallocate(void* data);
 
-	void SetActive(bool active);
+	/// Returns the name of the proxy allocator
+	const char*		name() const;
 
-	//! Loads the view matrix
-	virtual void Render();
-
-	void MoveForward();
-	void MoveBackward();
-	void StrafeLeft();
-	void StrafeRight();
-	void SetRotation(const real x, const real y);
-
-protected:
-
-	Vec2 mRotFactor;
-	float mAngleX;
-	float mAngleY;
-
-	float mSpeed;
-	float mSensibility;
+private:
 
+	Allocator&		m_allocator;
+	const char*		m_name;
 };
 
 } // namespace crown
-

+ 5 - 3
src/Pixel.cpp → src/renderers/Pixel.cpp

@@ -29,7 +29,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-uint32_t Pixel::GetBitsPerPixel(PixelFormat format)
+//-----------------------------------------------------------------------------
+uint32_t Pixel::bits_per_pixel(PixelFormat format)
 {
 	switch (format)
 	{
@@ -108,9 +109,10 @@ uint32_t Pixel::GetBitsPerPixel(PixelFormat format)
 	}
 }
 
-uint32_t Pixel::GetBytesPerPixel(PixelFormat format)
+//-----------------------------------------------------------------------------
+uint32_t Pixel::bytes_per_pixel(PixelFormat format)
 {
-	return GetBitsPerPixel(format) / 8;
+	return bits_per_pixel(format) / 8;
 }
 
 } // namespace crown

+ 6 - 8
src/Pixel.h → src/renderers/Pixel.h

@@ -40,9 +40,8 @@ namespace crown
 // [36 - 39]	-> 128-bit
 // 40			-> Unknown (0-bit)
 
-/**
-	Enumerates pixel formats.
-*/
+
+/// Enumerates pixel formats.
 enum PixelFormat
 {
 	PF_L_8 = 0,				//!< Luminance only, 8-bit
@@ -101,14 +100,13 @@ enum PixelFormat
 
 class Pixel
 {
-
 public:
 
-	//! Returns the format's bytes per pixel
-	static uint32_t GetBytesPerPixel(PixelFormat format);
+	/// Returns the bytes per pixel necessary to @format pixel format
+	static uint32_t bytes_per_pixel(PixelFormat format);
 
-	//! Returns the format's bits per pixel
-	static uint32_t GetBitsPerPixel(PixelFormat format);
+	/// Returns the bits per pixel necessary to @format pixel format
+	static uint32_t bits_per_pixel(PixelFormat format);
 
 private:
 

+ 3 - 12
src/renderers/Renderer.h

@@ -67,13 +67,8 @@ enum DrawMode
 
 class Renderer
 {
-
 public:
 
-	static Renderer* CreateRenderer();
-	static void	DestroyRenderer(Renderer* renderer);
-
-
 	Renderer() {}
 	virtual ~Renderer() {}
 
@@ -183,15 +178,11 @@ public:
 	//! Loads the current matrix
 	virtual void set_matrix(MatrixType type, const Mat4& matrix) = 0;
 
-	//! Selects the active matrix
-	virtual void select_matrix(MatrixType type) = 0;
-
-	virtual void render_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices) = 0;
-
-	virtual void render_point_buffer(const VertexBuffer* buffer) = 0;
+	virtual void draw_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices) = 0;
+	virtual void draw_point_buffer(const VertexBuffer* buffer) = 0;
 
 	virtual void draw_lines(const float* vertices, const float* colors, uint32_t count) = 0;
-	virtual void render_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count) = 0;
+	virtual void draw_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count) = 0;
 
 	// FIXME
 	virtual TextureId	load_texture(TextureResource* texture) = 0;

+ 3 - 26
src/renderers/gl/GLRenderer.cpp

@@ -614,30 +614,7 @@ void GLRenderer::set_matrix(MatrixType type, const Mat4& matrix)
 }
 
 //-----------------------------------------------------------------------------
-void GLRenderer::select_matrix(MatrixType type)
-{
-	switch (type)
-	{
-		case MT_VIEW:
-		case MT_MODEL:
-			glMatrixMode(GL_MODELVIEW);
-			break;
-		case MT_PROJECTION:
-			glMatrixMode(GL_PROJECTION);
-			break;
-		case MT_TEXTURE:
-			glMatrixMode(GL_TEXTURE);
-			break;
-		case MT_COLOR:
-			glMatrixMode(GL_COLOR);
-			break;
-		default:
-			break;
-	}
-}
-
-//-----------------------------------------------------------------------------
-void GLRenderer::render_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices)
+void GLRenderer::draw_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices)
 {
 	assert(vertices != NULL);
 	assert(indices != NULL);
@@ -659,7 +636,7 @@ void GLRenderer::render_vertex_index_buffer(const VertexBuffer* vertices, const
 }
 
 //-----------------------------------------------------------------------------
-void GLRenderer::render_point_buffer(const VertexBuffer* buffer)
+void GLRenderer::draw_point_buffer(const VertexBuffer* buffer)
 {
 	if (buffer == NULL)
 		return;
@@ -763,7 +740,7 @@ void GLRenderer::draw_lines(const float* vertices, const float* colors, uint32_t
 }
 
 //-----------------------------------------------------------------------------
-void GLRenderer::render_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count)
+void GLRenderer::draw_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count)
 {
 	glBindBuffer(GL_ARRAY_BUFFER, 0);
 	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

+ 3 - 5
src/renderers/gl/GLRenderer.h

@@ -111,13 +111,11 @@ public:
 	Mat4				get_matrix(MatrixType type) const;
 	void				set_matrix(MatrixType type, const Mat4& matrix);
 
-	void				select_matrix(MatrixType type);
-
-	void				render_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices);
-	void				render_point_buffer(const VertexBuffer* buffer);
+	void				draw_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices);
+	void				draw_point_buffer(const VertexBuffer* buffer);
 
 	void				draw_lines(const float* vertices, const float* colors, uint32_t count);
-	void				render_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count);
+	void				draw_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count);
 
 	TextureId			load_texture(TextureResource* texture);
 	void				unload_texture(TextureResource* texture);

+ 3 - 26
src/renderers/gles/GLESRenderer.cpp

@@ -565,30 +565,7 @@ void GLESRenderer::set_matrix(MatrixType type, const Mat4& matrix)
 }
 
 //-----------------------------------------------------------------------------
-void GLESRenderer::select_matrix(MatrixType type)
-{
-	switch (type)
-	{
-		case MT_VIEW:
-		case MT_MODEL:
-			glMatrixMode(GL_MODELVIEW);
-			break;
-		case MT_PROJECTION:
-			glMatrixMode(GL_PROJECTION);
-			break;
-		case MT_TEXTURE:
-			glMatrixMode(GL_TEXTURE);
-			break;
-		case MT_COLOR:
-			//glMatrixMode(GL_COLOR);
-			break;
-		default:
-			break;
-	}
-}
-
-//-----------------------------------------------------------------------------
-void GLESRenderer::render_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices)
+void GLESRenderer::draw_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices)
 {
 	assert(vertices != NULL);
 	assert(indices != NULL);
@@ -610,7 +587,7 @@ void GLESRenderer::render_vertex_index_buffer(const VertexBuffer* vertices, cons
 }
 
 //-----------------------------------------------------------------------------
-void GLESRenderer::render_point_buffer(const VertexBuffer* buffer)
+void GLESRenderer::draw_point_buffer(const VertexBuffer* buffer)
 {
 	if (buffer == NULL)
 		return;
@@ -711,7 +688,7 @@ void GLESRenderer::draw_lines(const float* vertices, const float* colors, uint32
 }
 
 //-----------------------------------------------------------------------------
-void GLESRenderer::render_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count)
+void GLESRenderer::draw_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count)
 {
 	glBindBuffer(GL_ARRAY_BUFFER, 0);
 	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

+ 3 - 5
src/renderers/gles/GLESRenderer.h

@@ -110,13 +110,11 @@ public:
 	Mat4				get_matrix(MatrixType type) const;
 	void				set_matrix(MatrixType type, const Mat4& matrix);
 
-	void				select_matrix(MatrixType type);
-
-	void				render_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices);
-	void				render_point_buffer(const VertexBuffer* buffer);
+	void				draw_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices);
+	void				draw_point_buffer(const VertexBuffer* buffer);
 
 	void				draw_lines(const float* vertices, const float* colors, uint32_t count);
-	void				render_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count);
+	void				draw_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count);
 
 	TextureId			load_texture(TextureResource* texture);
 	void				unload_texture(TextureResource* texture);