فهرست منبع

Initial input management rewrite

Daniele Bartolini 13 سال پیش
والد
کامیت
388a339949

+ 4 - 6
src/CMakeLists.txt

@@ -2,7 +2,6 @@ set (SRC
 	Camera.cpp
 	Camera.cpp
 	Device.cpp
 	Device.cpp
 	EventBuffer.cpp
 	EventBuffer.cpp
-	EventLoop.cpp
 	Filesystem.cpp
 	Filesystem.cpp
 	Font.cpp
 	Font.cpp
 	FontManager.cpp
 	FontManager.cpp
@@ -31,7 +30,6 @@ set (HEADERS
 	Data.h
 	Data.h
 	Device.h
 	Device.h
 	EventBuffer.h
 	EventBuffer.h
-	EventLoop.h
 	Filesystem.h
 	Filesystem.h
 	Font.h
 	Font.h
 	FontManager.h
 	FontManager.h
@@ -160,12 +158,15 @@ set (STREAMS_HEADERS
 
 
 set (MEM_SRC
 set (MEM_SRC
 	core/mem/GarbageBin.cpp
 	core/mem/GarbageBin.cpp
+	#core/mem/MallocAllocator.cpp
 )
 )
 
 
 set (MEM_HEADERS
 set (MEM_HEADERS
 	core/mem/Auto.h
 	core/mem/Auto.h
 	core/mem/GarbageBin.h
 	core/mem/GarbageBin.h
 	core/mem/Shared.h
 	core/mem/Shared.h
+	#core/mem/Allocator.h
+	#core/mem/MallocAllocator.h
 )
 )
 
 
 set (INPUT_SRC
 set (INPUT_SRC
@@ -225,15 +226,12 @@ set (LINUX_SRC
 	os/linux/GLXRenderWindow.cpp
 	os/linux/GLXRenderWindow.cpp
 	os/linux/LinuxOS.cpp
 	os/linux/LinuxOS.cpp
 	os/linux/LinuxTimer.cpp
 	os/linux/LinuxTimer.cpp
-	os/linux/X11Keyboard.cpp
-	os/linux/X11Mouse.cpp
+	os/linux/Input.cpp
 )
 )
 
 
 set (LINUX_HEADERS
 set (LINUX_HEADERS
 #	os/linux/EGLRenderWindow.h
 #	os/linux/EGLRenderWindow.h
 	os/linux/LinuxTimer.h
 	os/linux/LinuxTimer.h
-	os/linux/X11Keyboard.h
-	os/linux/X11Mouse.h
 )
 )
 
 
 set (SOURCES
 set (SOURCES

+ 0 - 2
src/Crown.h

@@ -95,8 +95,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "MeshManager.h"
 #include "MeshManager.h"
 #include "MovableCamera.h"
 #include "MovableCamera.h"
 #include "OcclusionQuery.h"
 #include "OcclusionQuery.h"
-#include "ParticleEmitter.h"
-#include "ParticleManager.h"
 #include "Pixel.h"
 #include "Pixel.h"
 #include "Renderer.h"
 #include "Renderer.h"
 #include "ResourceManager.h"
 #include "ResourceManager.h"

+ 3 - 62
src/Device.cpp

@@ -54,9 +54,7 @@ Device::Device() :
 	mPreferredUserPath(Str::EMPTY),
 	mPreferredUserPath(Str::EMPTY),
 	mIsInit(false),
 	mIsInit(false),
 	mIsRunning(false),
 	mIsRunning(false),
-	mInputManager(NULL),
-	mRenderer(NULL),
-	mGarbageBin(NULL)
+	mRenderer(NULL)
 {
 {
 }
 }
 
 
@@ -93,9 +91,6 @@ bool Device::Init(int argc, char** argv)
 	}
 	}
 	Log::D("Window created.");
 	Log::D("Window created.");
 
 
-	// Creates the garbage bin
-	mGarbageBin = new GarbageBin();
-
 	// Creates the renderer
 	// Creates the renderer
 	if (!mRenderer)
 	if (!mRenderer)
 	{
 	{
@@ -103,34 +98,7 @@ bool Device::Init(int argc, char** argv)
 	}
 	}
 	Log::D("Renderer created.");
 	Log::D("Renderer created.");
 
 
-	
-//	// Creates the input manager
-//	mInputManager = GetInputManager();
-
-//	Mouse* mouse = NULL;
-//	Keyboard* keyboard = NULL;
-//	Touch* touch = NULL;
-
-//	if (mInputManager)
-//	{
-//		keyboard = mInputManager->GetKeyboard();
-//		mouse = mInputManager->GetMouse();
-//		touch = mInputManager->GetTouch();
-//	}
-
-//	if (mouse)
-//	{
-//		mouse->SetListener(mInputManager->GetEventDispatcher());
-//	}
-//	if (keyboard)
-//	{
-//		keyboard->SetListener(mInputManager->GetEventDispatcher());
-//	}
-//	if (touch)
-//	{
-//		touch->SetListener(mInputManager->GetEventDispatcher());
-//	}
-	Log::D("InputManager created.");
+	os::init_input();
 
 
 	mIsInit = true;
 	mIsInit = true;
 
 
@@ -142,12 +110,6 @@ bool Device::Init(int argc, char** argv)
 	return true;
 	return true;
 }
 }
 
 
-//-----------------------------------------------------------------------------
-InputManager* Device::GetInputManager()
-{
-	return mInputManager;
-}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void Device::Shutdown()
 void Device::Shutdown()
 {
 {
@@ -157,13 +119,6 @@ void Device::Shutdown()
 		return;
 		return;
 	}
 	}
 
 
-	Log::I("Releasing GarbageBin...");
-
-	if (mGarbageBin)
-	{
-		delete mGarbageBin;
-	}
-
 	Log::I("Releasing Renderer...");
 	Log::I("Releasing Renderer...");
 
 
 	if (mRenderer)
 	if (mRenderer)
@@ -171,12 +126,6 @@ void Device::Shutdown()
 		Renderer::DestroyRenderer(mRenderer);
 		Renderer::DestroyRenderer(mRenderer);
 	}
 	}
 
 
-	Log::I("Releasing InputManager...");
-	if (mInputManager)
-	{
-		// do nothing
-	}
-
 	Log::I("Releasing Render Window...");
 	Log::I("Releasing Render Window...");
 	os::destroy_render_window();
 	os::destroy_render_window();
 
 
@@ -195,12 +144,6 @@ Renderer* Device::GetRenderer()
 	return mRenderer;
 	return mRenderer;
 }
 }
 
 
-//-----------------------------------------------------------------------------
-GarbageBin* Device::GetGarbageBin()
-{
-	return mGarbageBin;
-}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void Device::StartRunning()
 void Device::StartRunning()
 {
 {
@@ -234,14 +177,12 @@ void Device::Frame()
 {
 {
 	os::event_loop();
 	os::event_loop();
 
 
-	mInputManager->EventLoop();
+	GetInputManager()->EventLoop();
 
 
 		mRenderer->_BeginFrame();
 		mRenderer->_BeginFrame();
 		mRenderer->_EndFrame();
 		mRenderer->_EndFrame();
 
 
 	os::swap_buffers();
 	os::swap_buffers();
-
-	mGarbageBin->Empty();
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------

+ 0 - 8
src/Device.h

@@ -36,7 +36,6 @@ namespace crown
 
 
 class Renderer;
 class Renderer;
 class InputManager;
 class InputManager;
-class GarbageBin;
 
 
 /**
 /**
 	Device.
 	Device.
@@ -49,9 +48,7 @@ public:
 							Device();
 							Device();
 							~Device();
 							~Device();
 
 
-	InputManager*			GetInputManager();
 	Renderer*				GetRenderer();
 	Renderer*				GetRenderer();
-	GarbageBin*				GetGarbageBin();
 
 
 	void					StartRunning();
 	void					StartRunning();
 	void					StopRunning();
 	void					StopRunning();
@@ -79,14 +76,9 @@ private:
 	bool					mIsInit		: 1;
 	bool					mIsInit		: 1;
 	bool					mIsRunning	: 1;
 	bool					mIsRunning	: 1;
 
 
-	InputManager*			mInputManager;
 	Renderer*				mRenderer;
 	Renderer*				mRenderer;
-
-	GarbageBin*				mGarbageBin;
 	Timer					mTimer;
 	Timer					mTimer;
 
 
-	EventLoop				_event_loop;
-
 	// Disable copying
 	// Disable copying
 	Device(const Device&);
 	Device(const Device&);
 	Device& operator=(const Device&);
 	Device& operator=(const Device&);

+ 4 - 4
src/MovableCamera.cpp

@@ -42,13 +42,13 @@ MovableCamera::MovableCamera(const Vec3& position, const Angles& axis,
 	mDownPressed(false),
 	mDownPressed(false),
 	mLeftPressed(false)
 	mLeftPressed(false)
 {
 {
-	GetDevice()->GetInputManager()->RegisterKeyboardListener(this);
+	GetInputManager()->RegisterKeyboardListener(this);
 
 
 	mRotFactor = Vec2(0.0f, 0.0f);
 	mRotFactor = Vec2(0.0f, 0.0f);
 	mAngleX = 0.0f;
 	mAngleX = 0.0f;
 	mAngleY = 0.0f;
 	mAngleY = 0.0f;
 
 
-	//GetDevice()->GetInputManager()->GetMouse()->SetCursorRelativeXY(Vec2(0.5f, 0.5f));
+	//GetInputManager()->GetMouse()->SetCursorRelativeXY(Vec2(0.5f, 0.5f));
 }
 }
 
 
 MovableCamera::~MovableCamera()
 MovableCamera::~MovableCamera()
@@ -63,7 +63,7 @@ float MovableCamera::GetMouseSensibility() const
 void MovableCamera::SetActive(bool active)
 void MovableCamera::SetActive(bool active)
 {
 {
 	Camera::SetActive(active);
 	Camera::SetActive(active);
-	//GetDevice()->GetInputManager()->GetMouse()->SetCursorRelativeXY(Vec2(0.5f, 0.5f));
+	//GetInputManager()->GetMouse()->SetCursorRelativeXY(Vec2(0.5f, 0.5f));
 }
 }
 
 
 void MovableCamera::SetMouseSensibility(float sensibility)
 void MovableCamera::SetMouseSensibility(float sensibility)
@@ -205,7 +205,7 @@ void MovableCamera::StrafeRight()
 
 
 void MovableCamera::SetViewByMouse()
 void MovableCamera::SetViewByMouse()
 {
 {
-	//Mouse* mouse = GetDevice()->GetInputManager()->GetMouse();
+	//Mouse* mouse = GetInputManager()->GetMouse();
 
 
 	static Vec2 lastPos = Vec2::ZERO;//mouse->GetCursorRelativeXY();
 	static Vec2 lastPos = Vec2::ZERO;//mouse->GetCursorRelativeXY();
 	Vec2 currentPos = Vec2::ZERO;//mouse->GetCursorRelativeXY();
 	Vec2 currentPos = Vec2::ZERO;//mouse->GetCursorRelativeXY();

+ 1 - 1
src/core/mem/GarbageBin.cpp

@@ -32,7 +32,7 @@ namespace crown
 
 
 void IGarbageable::Trash()
 void IGarbageable::Trash()
 {
 {
-	GetDevice()->GetGarbageBin()->Trash(this);
+	//GetDevice()->GetGarbageBin()->Trash(this);
 }
 }
 
 
 GarbageBin::GarbageBin()
 GarbageBin::GarbageBin()

+ 17 - 41
src/input/EventDispatcher.h

@@ -33,63 +33,39 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 namespace crown
 {
 {
 
 
-class EventDispatcher : public MouseListener, public KeyboardListener, public TouchListener
+class EventDispatcher
 {
 {
-	typedef List<MouseListener*> MouseListenerList;
-	typedef List<KeyboardListener*> KeyboardListenerList;
-	typedef List<TouchListener*> TouchListenerList;
+	typedef List<MouseListener*>		MouseListenerList;
+	typedef List<KeyboardListener*>		KeyboardListenerList;
+	typedef List<TouchListener*>		TouchListenerList;
 
 
 public:
 public:
 
 
-	/**
-		Constructor.
-	*/
 	EventDispatcher() {}
 	EventDispatcher() {}
-
-	/**
-		Destructor.	
-	*/
 	~EventDispatcher() {}
 	~EventDispatcher() {}
 
 
-	/**
-		Adds a MouseListener.
-	@param listener
-		The listener
-	*/
 	void AddMouseListener(MouseListener* listener);
 	void AddMouseListener(MouseListener* listener);
-
-	/**
-		Adds a KeyboardListener.
-	@param listener
-		The listener
-	*/
 	void AddKeyboardListener(KeyboardListener* listener);
 	void AddKeyboardListener(KeyboardListener* listener);
-
-	/**
-		Adds a TouchListener.
-	@param listener
-		The listener
-	*/
 	void AddTouchListener(TouchListener* listener);
 	void AddTouchListener(TouchListener* listener);
 
 
-	virtual void ButtonPressed(const MouseEvent&);
-	virtual void ButtonReleased(const MouseEvent&);
-	virtual void CursorMoved(const MouseEvent&);
+	void ButtonPressed(const MouseEvent&);
+	void ButtonReleased(const MouseEvent&);
+	void CursorMoved(const MouseEvent&);
 
 
-	virtual void KeyPressed(const KeyboardEvent&);
-	virtual void KeyReleased(const KeyboardEvent&);
-	virtual void TextInput(const KeyboardEvent&);
+	void KeyPressed(const KeyboardEvent&);
+	void KeyReleased(const KeyboardEvent&);
+	void TextInput(const KeyboardEvent&);
 
 
-	virtual void TouchDown(const TouchEvent& event);
-	virtual void TouchUp(const TouchEvent& event);
-	virtual void TouchMove(const TouchEvent& event);
-	virtual void TouchCancel(const TouchEvent& event);
+	void TouchDown(const TouchEvent& event);
+	void TouchUp(const TouchEvent& event);
+	void TouchMove(const TouchEvent& event);
+	void TouchCancel(const TouchEvent& event);
 
 
 private:
 private:
 
 
-	MouseListenerList mMouseListenerList;
-	KeyboardListenerList mKeyboardListenerList;
-	TouchListenerList mTouchListenerList;
+	MouseListenerList		mMouseListenerList;
+	KeyboardListenerList	mKeyboardListenerList;
+	TouchListenerList		mTouchListenerList;
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 73 - 1
src/input/InputManager.cpp

@@ -29,11 +29,83 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 namespace crown
 {
 {
 
 
+//-----------------------------------------------------------------------------
+InputManager::InputManager()
+{
+//	mMouse = new Mouse();
+//	mKeyboard = new Keyboard();
+//	mTouch = new Touch();
+}
+
+//-----------------------------------------------------------------------------
+InputManager::~InputManager()
+{
+}
+
+//-----------------------------------------------------------------------------
 void InputManager::EventLoop()
 void InputManager::EventLoop()
 {
 {
-	//TODO do the hard job here...
+	os::OSEvent event;
+
+	while (1)
+	{
+		event = os::pop_event();
+
+		if (event.type == os::OSET_NONE)
+		{
+			return;
+		}
+
+		os::printf("OS Event: %d, %d, %d, %d, %d\n", event.type, event.data_a, event.data_b, event.data_c, event.data_d);
+
+		switch (event.type)
+		{
+			case os::OSET_BUTTON_PRESS:
+			case os::OSET_BUTTON_RELEASE:
+			{
+				MouseEvent mouse_event;
+				mouse_event.x = event.data_a;
+				mouse_event.y = event.data_b;
+				mouse_event.button = event.data_c == 0 ? MB_LEFT : event.data_c == 1 ? MB_MIDDLE : MB_RIGHT;
+				mouse_event.wheel = 0.0f;
+
+				if (event.type == os::OSET_BUTTON_PRESS)
+				{
+					mEventDispatcher.ButtonPressed(mouse_event);
+				}
+				else
+				{
+					mEventDispatcher.ButtonReleased(mouse_event);
+				}
+
+				break;
+			}
+			case os::OSET_KEY_PRESS:
+			case os::OSET_KEY_RELEASE:
+			{
+				KeyboardEvent keyboard_event;
+				keyboard_event.key = event.data_a;
+
+				if (event.type == os::OSET_KEY_PRESS)
+				{
+					mEventDispatcher.KeyPressed(keyboard_event);
+				}
+				else
+				{
+					mEventDispatcher.KeyReleased(keyboard_event);
+				}
+
+				break;
+			}
+			default:
+			{
+				break;
+			}
+		}
+	}
 }
 }
 
 
+//-----------------------------------------------------------------------------
 InputManager inputManager;
 InputManager inputManager;
 InputManager* GetInputManager()
 InputManager* GetInputManager()
 {
 {

+ 12 - 25
src/input/InputManager.h

@@ -37,6 +37,7 @@ class MouseListener;
 class KeyboardListener;
 class KeyboardListener;
 class TouchListener;
 class TouchListener;
 
 
+
 class InputManager
 class InputManager
 {
 {
 
 
@@ -45,14 +46,12 @@ public:
 	/**
 	/**
 		Constructor.
 		Constructor.
 	*/
 	*/
-	InputManager() : mMouse(NULL), mKeyboard(NULL), mTouch(NULL)
-	{
-	}
+	InputManager();
 
 
 	/**
 	/**
 		Destructor.
 		Destructor.
 	*/
 	*/
-	~InputManager() {}
+	~InputManager();
 
 
 	/**
 	/**
 		Initializes the input manager.
 		Initializes the input manager.
@@ -61,68 +60,56 @@ public:
 
 
 	/**
 	/**
 		Returns whether the mouse is available.
 		Returns whether the mouse is available.
-	@return
-		True if available, false otherwise
 	*/
 	*/
 	bool IsMouseAvailable() {}
 	bool IsMouseAvailable() {}
 
 
 	/**
 	/**
 		Returns whether the keyboard is available.
 		Returns whether the keyboard is available.
-	@return
-		True if available, false otherwise
 	*/
 	*/
 	bool IsKeyboardAvailable() {}
 	bool IsKeyboardAvailable() {}
 
 
 	/**
 	/**
 		Returns whether the touch is available.
 		Returns whether the touch is available.
-	@return
-		True if available, false otherwise
 	*/
 	*/
 	bool IsTouchAvailable() {}
 	bool IsTouchAvailable() {}
 
 
 	/**
 	/**
 		Returns the handle to the mouse input device.
 		Returns the handle to the mouse input device.
-	@return
-		The mouse input device or NULL
 	*/
 	*/
 	inline Mouse* GetMouse()
 	inline Mouse* GetMouse()
 	{
 	{
-		return mMouse;
+		//return mMouse;
 	}
 	}
 
 
 	/**
 	/**
 		Returns the handle to the keyboard input device.
 		Returns the handle to the keyboard input device.
-	@return
-		The keyboard input device or NULL
 	*/
 	*/
 	inline Keyboard* GetKeyboard()
 	inline Keyboard* GetKeyboard()
 	{
 	{
-		return mKeyboard;
+		//return mKeyboard;
 	}
 	}
 
 
 	/**
 	/**
 		Return the handle to the touch input device.
 		Return the handle to the touch input device.
-	@return
-		The touch input device or NULL
 	*/
 	*/
 	inline Touch* GetTouch()
 	inline Touch* GetTouch()
 	{
 	{
-		return mTouch;
+		//return mTouch;
 	}
 	}
 
 
 	inline void RegisterMouseListener(MouseListener* listener)
 	inline void RegisterMouseListener(MouseListener* listener)
 	{
 	{
-		//mEventDispatcher.AddMouseListener(listener);
+		mEventDispatcher.AddMouseListener(listener);
 	}
 	}
 
 
 	inline void RegisterKeyboardListener(KeyboardListener* listener)
 	inline void RegisterKeyboardListener(KeyboardListener* listener)
 	{
 	{
-		//mEventDispatcher.AddKeyboardListener(listener);
+		mEventDispatcher.AddKeyboardListener(listener);
 	}
 	}
 
 
 	inline void RegisterTouchListener(TouchListener* listener)
 	inline void RegisterTouchListener(TouchListener* listener)
 	{
 	{
-		//mEventDispatcher.AddTouchListener(listener);
+		mEventDispatcher.AddTouchListener(listener);
 	}
 	}
 
 
 	inline EventDispatcher* GetEventDispatcher()
 	inline EventDispatcher* GetEventDispatcher()
@@ -136,9 +123,9 @@ protected:
 
 
 	EventDispatcher		mEventDispatcher;
 	EventDispatcher		mEventDispatcher;
 
 
-	Mouse*				mMouse;
-	Keyboard*			mKeyboard;
-	Touch*				mTouch;
+//	Mouse*				mMouse;
+//	Keyboard*			mKeyboard;
+//	Touch*				mTouch;
 };
 };
 
 
 InputManager* GetInputManager();
 InputManager* GetInputManager();

+ 1 - 22
src/input/Keyboard.h

@@ -72,7 +72,7 @@ public:
 	/**
 	/**
 		Constructor.
 		Constructor.
 	*/
 	*/
-	Keyboard(InputManager* creator) : mCreator(creator), mListener(0) {}
+	Keyboard() : mListener(NULL) {}
 
 
 	/**
 	/**
 		Destructor.
 		Destructor.
@@ -84,48 +84,27 @@ public:
 	@note
 	@note
 		A modifier is a special key that modifies the normal action
 		A modifier is a special key that modifies the normal action
 		of another key when the two are pressed in combination. (Thanks wikipedia.)
 		of another key when the two are pressed in combination. (Thanks wikipedia.)
-	@note
 		Crown currently supports three different modifier keys: Shift, Ctrl and Alt.
 		Crown currently supports three different modifier keys: Shift, Ctrl and Alt.
-	@param modifier
-		The modifier
-	@return True if pressed, false otherwise
 	*/
 	*/
 	virtual bool IsModifierPressed(ModifierKey modifier) const = 0;
 	virtual bool IsModifierPressed(ModifierKey modifier) const = 0;
 
 
 	/**
 	/**
 		Returns whether the specified key is pressed.
 		Returns whether the specified key is pressed.
-	@param key
-		The key
-	@return
-		True if pressed, false otherwise
 	*/
 	*/
 	virtual bool IsKeyPressed(KeyCode key) const = 0;
 	virtual bool IsKeyPressed(KeyCode key) const = 0;
 
 
 	/**
 	/**
 		Returns whether the specified key is released.
 		Returns whether the specified key is released.
-	@param key
-		The key
-	@return
-		True if released, false otherwise
 	*/
 	*/
 	virtual bool IsKeyReleased(KeyCode key) const = 0;
 	virtual bool IsKeyReleased(KeyCode key) const = 0;
 
 
-	/**
-		Captures and reports keyboard-related events.
-	*/
-	virtual void EventLoop() = 0;
-
 	/**
 	/**
 		Sets the listener for this device.
 		Sets the listener for this device.
-	@param listener
-		The listener
 	*/
 	*/
 	inline void SetListener(KeyboardListener* listener) { mListener = listener; }
 	inline void SetListener(KeyboardListener* listener) { mListener = listener; }
 
 
 protected:
 protected:
 
 
-	// The InputManager which created the istance
-	InputManager* mCreator;
 	KeyboardListener* mListener;
 	KeyboardListener* mListener;
 };
 };
 
 

+ 1 - 22
src/input/Mouse.h

@@ -72,7 +72,7 @@ public:
 	/**
 	/**
 		Constructor.
 		Constructor.
 	*/
 	*/
-	Mouse(InputManager* creator) : mCreator(creator), mListener(0) {}
+	Mouse() : mListener(NULL) {}
 
 
 	/**
 	/**
 		Destructor.
 		Destructor.
@@ -81,15 +81,11 @@ public:
 
 
 	/**
 	/**
 		Returns whether the cursor is visible.
 		Returns whether the cursor is visible.
-	@return
-		True if visible, false otherwise
 	*/
 	*/
 	virtual bool IsCursorVisible() const = 0;
 	virtual bool IsCursorVisible() const = 0;
 
 
 	/**
 	/**
 		Sets whether the cursor is visible.
 		Sets whether the cursor is visible.
-	@param visible
-		Whether the cursor is visible
 	*/
 	*/
 	virtual void SetCursorVisible(bool visible) = 0;
 	virtual void SetCursorVisible(bool visible) = 0;
 
 
@@ -99,8 +95,6 @@ public:
 		Coordinates in window space have the origin at the
 		Coordinates in window space have the origin at the
 		upper-left corner of the window. +X extends from left
 		upper-left corner of the window. +X extends from left
 		to right and +Y extends from top to bottom.
 		to right and +Y extends from top to bottom.
-	@return
-		The position of the cursor in window space
 	*/
 	*/
 	virtual Point2 GetCursorXY() const = 0;
 	virtual Point2 GetCursorXY() const = 0;
 
 
@@ -110,8 +104,6 @@ public:
 		Coordinates in window space have the origin at the
 		Coordinates in window space have the origin at the
 		upper-left corner of the window. +X extends from left
 		upper-left corner of the window. +X extends from left
 		to right and +Y extends from top to bottom.
 		to right and +Y extends from top to bottom.
-	@param position
-		The position of the cursor in window space
 	*/
 	*/
 	virtual void SetCursorXY(const Point2& position) = 0;
 	virtual void SetCursorXY(const Point2& position) = 0;
 
 
@@ -125,8 +117,6 @@ public:
 		Relative coordinates are mapped to a real varying
 		Relative coordinates are mapped to a real varying
 		from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
 		from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
 		maximum extent of the cosidered axis.
 		maximum extent of the cosidered axis.
-	@return
-		The relative position of the cursor in window space
 	*/
 	*/
 	virtual Vec2 GetCursorRelativeXY() const = 0;
 	virtual Vec2 GetCursorRelativeXY() const = 0;
 
 
@@ -140,27 +130,16 @@ public:
 		Relative coordinates are mapped to a real varying
 		Relative coordinates are mapped to a real varying
 		from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
 		from 0.0 to 1.0 where 0.0 is the origin and 1.0 the
 		maximum extent of the cosidered axis.
 		maximum extent of the cosidered axis.
-	@param position
-		The relative position of the cursor in window space
 	*/
 	*/
 	virtual void SetCursorRelativeXY(const Vec2& position) = 0;
 	virtual void SetCursorRelativeXY(const Vec2& position) = 0;
 
 
-	/**
-		Captures and reports mouse-related events.
-	*/
-	virtual void EventLoop() = 0;
-
 	/**
 	/**
 		Sets the listener for this device.
 		Sets the listener for this device.
-	@param listener
-		The listener
 	*/
 	*/
 	inline void SetListener(MouseListener* listener) { mListener = listener; }
 	inline void SetListener(MouseListener* listener) { mListener = listener; }
 
 
 protected:
 protected:
 
 
-	// The InputManager which created the istance
-	InputManager* mCreator;
 	MouseListener* mListener;
 	MouseListener* mListener;
 };
 };
 
 

+ 1 - 8
src/input/Touch.h

@@ -59,18 +59,13 @@ public:
 	/**
 	/**
 		Constructor.
 		Constructor.
 	*/
 	*/
-	Touch(InputManager* creator) : mCreator(creator), mListener(0) {}
+	Touch() : mListener(NULL) {}
 
 
 	/**
 	/**
 		Destructor.
 		Destructor.
 	*/
 	*/
 	virtual ~Touch() {}
 	virtual ~Touch() {}
 
 
-	/**
-		Captures and reports touch-related events.
-	*/
-	virtual void EventLoop() = 0;
-
 	/**
 	/**
 		Sets the listener for this device.
 		Sets the listener for this device.
 	@param listener
 	@param listener
@@ -80,8 +75,6 @@ public:
 
 
 protected:
 protected:
 
 
-	// The InputManager which created the istance
-	InputManager* mCreator;
 	TouchListener* mListener;
 	TouchListener* mListener;
 };
 };
 
 

+ 14 - 12
src/os/OS.cpp

@@ -6,18 +6,21 @@ namespace crown
 namespace os
 namespace os
 {
 {
 
 
-#define				MAX_OS_EVENTS 256
-
-static int			event_queue_count = 0;
 static OSEvent		event_queue[MAX_OS_EVENTS];
 static OSEvent		event_queue[MAX_OS_EVENTS];
+static int			event_queue_head = 0;
+static int			event_queue_tail = 0;
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void push_event(OSEventType type, int data_a, int data_b, int data_c, int data_d)
 void push_event(OSEventType type, int data_a, int data_b, int data_c, int data_d)
 {
 {
-	// The queue wraps silently when MAX_OS_EVENTS reached
-	OSEvent* event = &event_queue[event_queue_count % MAX_OS_EVENTS];
+	if ((event_queue_tail + 1) % MAX_OS_EVENTS == event_queue_head)
+	{
+		os::printf("OS event queue full!\n");
+		return;
+	}
 
 
-	event_queue_count++;
+	OSEvent* event = &event_queue[event_queue_tail];
+	event_queue_tail = (event_queue_tail + 1) % MAX_OS_EVENTS;
 
 
 	event->type = type;
 	event->type = type;
 	event->data_a = data_a;
 	event->data_a = data_a;
@@ -29,17 +32,16 @@ void push_event(OSEventType type, int data_a, int data_b, int data_c, int data_d
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 OSEvent& pop_event()
 OSEvent& pop_event()
 {
 {
-	OSEvent event;
+	static OSEvent event;
 
 
-	if (event_queue_count > 0)
+	if (event_queue_head == event_queue_tail)
 	{
 	{
-		event = event_queue[event_queue_count - 1 % MAX_OS_EVENTS];
-		event_queue_count--;
-
+		event.type = OSET_NONE;
 		return event;
 		return event;
 	}
 	}
 
 
-	event.type = OSET_NONE;
+	event = event_queue[event_queue_head];
+	event_queue_head = (event_queue_head + 1) % MAX_OS_EVENTS;
 
 
 	return event;
 	return event;
 }
 }

+ 12 - 17
src/os/OS.h

@@ -42,11 +42,15 @@ namespace os
 #ifdef LINUX
 #ifdef LINUX
 const size_t	MAX_OS_PATH_LENGTH = 1024;
 const size_t	MAX_OS_PATH_LENGTH = 1024;
 const char		PATH_SEPARATOR = '/';
 const char		PATH_SEPARATOR = '/';
+
+const size_t	MAX_OS_EVENTS = 512;
 #endif
 #endif
 
 
 #ifdef WINDOWS
 #ifdef WINDOWS
 const size_t	MAX_OS_PATH_LENGTH = 1024;
 const size_t	MAX_OS_PATH_LENGTH = 1024;
 const char		PATH_SEPARATOR = '\\';
 const char		PATH_SEPARATOR = '\\';
+
+const size_t	MAX_OS_EVENTS = 512;
 #endif
 #endif
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -83,9 +87,7 @@ void			swap_buffers();
 
 
 void			event_loop();
 void			event_loop();
 
 
-void			init_keyboard();
-void			init_mouse();
-void			init_touch();
+void			init_input();
 
 
 void			hide_cursor();
 void			hide_cursor();
 void			show_cursor();
 void			show_cursor();
@@ -93,21 +95,14 @@ void			show_cursor();
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 enum OSEventType
 enum OSEventType
 {
 {
-	OSET_NONE		= 0,
-	OSET_KEYBOARD	= 1,
-	OSET_MOUSE		= 2,
-	OSET_TOUCH		= 3
-};
+	OSET_NONE				= 0,
 
 
-enum OSMouseEventType
-{
-	OSMET_LEFT_PRESSED		= 0,
-	OSMET_MIDDLE_PRESSED	= 1,
-	OSMET_RIGHT_PRESSED		= 2,
-	OSMET_LEFT_RELEASED		= 3,
-	OSMET_MIDDLE_RELEASED	= 4,
-	OSMET_RIGHT_RELEASED	= 5,
-	OSMET_CURSOR_MOVED		= 6
+	OSET_KEY_PRESS			= 1,
+	OSET_KEY_RELEASE		= 2,
+
+	OSET_BUTTON_PRESS		= 3,
+	OSET_BUTTON_RELEASE		= 4,
+	OSET_MOTION_NOTIFY		= 5,
 };
 };
 
 
 struct OSEvent
 struct OSEvent

+ 35 - 180
src/os/linux/GLXRenderWindow.cpp

@@ -37,25 +37,25 @@ namespace crown
 namespace os
 namespace os
 {
 {
 
 
-Display*		mXDisplay = NULL;
-Window			mXWindow = None;
-GLXContext		mGLXContext = NULL;
-GLXDrawable		mGLXWindow = None;
+Display*		display = NULL;
+Window			window = None;
+GLXContext		glx_context = NULL;
+GLXDrawable		glx_window = None;
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 bool create_render_window(uint x, uint y, uint width, uint height, bool fullscreen)
 bool create_render_window(uint x, uint y, uint width, uint height, bool fullscreen)
 {
 {
 	assert(width != 0 && height != 0);
 	assert(width != 0 && height != 0);
 
 
-	mXDisplay = XOpenDisplay(NULL);
+	display = XOpenDisplay(NULL);
 
 
-	if (mXDisplay == NULL)
+	if (display == NULL)
 	{
 	{
 		Log::E("Unable to open a display");
 		Log::E("Unable to open a display");
 		return false;
 		return false;
 	}
 	}
 
 
-	Window defRoot = DefaultRootWindow(mXDisplay);
+	Window defRoot = DefaultRootWindow(display);
 
 
 	// Color index buffer not supported - deprecated
 	// Color index buffer not supported - deprecated
 	int fbAttribs[] =
 	int fbAttribs[] =
@@ -80,7 +80,7 @@ bool create_render_window(uint x, uint y, uint width, uint height, bool fullscre
 	};
 	};
 
 
 	int fbCount;
 	int fbCount;
-	GLXFBConfig* fbConfig = glXChooseFBConfig(mXDisplay, XDefaultScreen(mXDisplay), fbAttribs, &fbCount);
+	GLXFBConfig* fbConfig = glXChooseFBConfig(display, XDefaultScreen(display), fbAttribs, &fbCount);
 
 
 	if (!fbConfig)
 	if (!fbConfig)
 	{
 	{
@@ -88,7 +88,7 @@ bool create_render_window(uint x, uint y, uint width, uint height, bool fullscre
 		return false;
 		return false;
 	}
 	}
 
 
-	XVisualInfo* visualInfo = glXGetVisualFromFBConfig(mXDisplay, fbConfig[0]);
+	XVisualInfo* visualInfo = glXGetVisualFromFBConfig(display, fbConfig[0]);
 
 
 	if (!visualInfo)
 	if (!visualInfo)
 	{
 	{
@@ -98,13 +98,13 @@ bool create_render_window(uint x, uint y, uint width, uint height, bool fullscre
 	}
 	}
 
 
 	Colormap cmap;
 	Colormap cmap;
-	cmap = XCreateColormap(mXDisplay, defRoot, visualInfo->visual, AllocNone);
+	cmap = XCreateColormap(display, defRoot, visualInfo->visual, AllocNone);
 	XSetWindowAttributes winAttribs;
 	XSetWindowAttributes winAttribs;
 	winAttribs.colormap = cmap;
 	winAttribs.colormap = cmap;
 	winAttribs.event_mask = FocusChangeMask | StructureNotifyMask;
 	winAttribs.event_mask = FocusChangeMask | StructureNotifyMask;
 
 
-	mXWindow = XCreateWindow(
-				   mXDisplay,
+	window = XCreateWindow(
+				   display,
 				   defRoot,
 				   defRoot,
 				   x, y,
 				   x, y,
 				   width, height,
 				   width, height,
@@ -116,22 +116,22 @@ bool create_render_window(uint x, uint y, uint width, uint height, bool fullscre
 				   &winAttribs
 				   &winAttribs
 			   );
 			   );
 
 
-	if (!mXWindow)
+	if (!window)
 	{
 	{
 		Log::E("Unable to create the X Window.");
 		Log::E("Unable to create the X Window.");
 		return false;
 		return false;
 	}
 	}
 
 
-	XMapRaised(mXDisplay, mXWindow);
-	mGLXWindow = glXCreateWindow(mXDisplay, fbConfig[0], mXWindow, 0);
+	XMapRaised(display, window);
+	glx_window = glXCreateWindow(display, fbConfig[0], window, 0);
 
 
-	mGLXContext = glXCreateNewContext(mXDisplay, fbConfig[0], GLX_RGBA_TYPE, NULL, True);
-	glXMakeContextCurrent(mXDisplay, mGLXWindow, mGLXWindow, mGLXContext);
+	glx_context = glXCreateNewContext(display, fbConfig[0], GLX_RGBA_TYPE, NULL, True);
+	glXMakeContextCurrent(display, glx_window, glx_window, glx_context);
 
 
-	XFreeColormap(mXDisplay, cmap);
+	XFreeColormap(display, cmap);
 	XFree(visualInfo);
 	XFree(visualInfo);
 	XFree(fbConfig);
 	XFree(fbConfig);
-	XFlush(mXDisplay);
+	XFlush(display);
 
 
 	return true;
 	return true;
 }
 }
@@ -139,177 +139,32 @@ bool create_render_window(uint x, uint y, uint width, uint height, bool fullscre
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 bool destroy_render_window()
 bool destroy_render_window()
 {
 {
-	if (mXDisplay)
+	if (display)
 	{
 	{
-		if (mGLXWindow)
+		if (glx_window)
 		{
 		{
-			glXDestroyWindow(mXDisplay, mGLXWindow);
+			glXDestroyWindow(display, glx_window);
 		}
 		}
 
 
-		if (mGLXContext)
+		if (glx_context)
 		{
 		{
-			glXMakeContextCurrent(mXDisplay, None, None, NULL);
-			glXDestroyContext(mXDisplay, mGLXContext);
+			glXMakeContextCurrent(display, None, None, NULL);
+			glXDestroyContext(display, glx_context);
 		}
 		}
 
 
-		if (mXWindow)
+		if (window)
 		{
 		{
-			XDestroyWindow(mXDisplay, mXWindow);
+			XDestroyWindow(display, window);
 		}
 		}
 
 
-		XCloseDisplay(mXDisplay);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void event_loop()
-{
-	XEvent event;
-
-	while (XPending(mXDisplay))
-	{
-		XNextEvent(mXDisplay, &event);
-
-		switch (event.type)
-		{
-//			case ConfigureNotify:
-//			{
-//				_NotifyMetricsChange(event.xconfigure.x, event.xconfigure.y,
-//										event.xconfigure.width, event.xconfigure.height);
-//				break;
-//			}
-			case ButtonPress:
-			{
-				switch (event.xbutton.button)
-				{
-					case Button1:
-					{
-						push_event(os::OSET_MOUSE, os::OSMET_LEFT_PRESSED, event.xbutton.x, event.xbutton.y, 0);
-						break;
-					}
-					case Button2:
-					{
-						push_event(os::OSET_MOUSE, os::OSMET_MIDDLE_PRESSED, event.xbutton.x, event.xbutton.y, 0);
-						break;
-					}
-					case Button3:
-					{
-						push_event(os::OSET_MOUSE, os::OSMET_RIGHT_PRESSED, event.xbutton.x, event.xbutton.y, 0);
-						break;
-					}
-				}
-
-				break;
-			}
-			case ButtonRelease:
-			{
-				switch (event.xbutton.button)
-				{
-					case Button1:
-					{
-						push_event(os::OSET_MOUSE, os::OSMET_LEFT_PRESSED, event.xbutton.x, event.xbutton.y, 0);
-						break;
-					}
-					case Button2:
-					{
-						push_event(os::OSET_MOUSE, os::OSMET_MIDDLE_PRESSED, event.xbutton.x, event.xbutton.y, 0);
-						break;
-					}
-					case Button3:
-					{
-						push_event(os::OSET_MOUSE, os::OSMET_RIGHT_PRESSED, event.xbutton.x, event.xbutton.y, 0);
-						break;
-					}
-				}
-
-				break;
-			}
-			case MotionNotify:
-			{
-				push_event(os::OSET_MOUSE, os::OSMET_CURSOR_MOVED, event.xbutton.x, event.xbutton.y, 0);
-				break;
-			}
-//			case KeyPress:
-//			case KeyRelease:
-//			{
-//				char string[4] = {0, 0, 0, 0};
-//				int len = -1;
-//				KeySym key;
-
-//				len = XLookupString(&event.xkey, string, 4, &key, NULL);
-
-//				Key kc = TranslateKey(key);
-
-//				// Check if any modifier key is pressed or released
-//				if (kc == KC_LSHIFT || kc == KC_RSHIFT)
-//				{
-//					(event.type == KeyPress) ? mModifierMask |= MK_SHIFT : mModifierMask &= ~MK_SHIFT;
-//				}
-//				else if (kc == KC_LCONTROL || kc == KC_RCONTROL)
-//				{
-//					(event.type == KeyPress) ? mModifierMask |= MK_CTRL : mModifierMask &= ~MK_CTRL;
-//				}
-//				else if (kc == KC_LALT || kc == KC_RALT)
-//				{
-//					(event.type == KeyPress) ? mModifierMask |= MK_ALT : mModifierMask &= ~MK_ALT;
-//				}
-
-//				mKeyState[kc] = (event.type == KeyPress) ? true : false;
-//				keyboardEvent.key = kc;
-
-//				if (mListener)
-//				{
-//					if (event.type == KeyPress)
-//					{
-//						mListener->KeyPressed(keyboardEvent);
-//					}
-//					else if (event.type == KeyRelease)
-//					{
-//						mListener->KeyReleased(keyboardEvent);
-//					}
-//				}
-
-//				if (event.type == KeyPress)
-//				{
-//					push_event(os::OSET_KEYBOARD, 1, 2, 3, 4);
-//				}
-//				else if (event.type == KeyRelease)
-//				{
-//					push_event(os::OSET_KEYBOARD, 55, 2, 3, 4);
-//				}
-
-//				// Text input part
-//				if (event.type == KeyPress && len > 0)
-//				{
-//					//crownEvent.event_type = ET_TEXT;
-//					//crownEvent.text.type = TET_TEXT_INPUT;
-//					strncpy(keyboardEvent.text, string, 4);
-
-//					if (mListener)
-//					{
-//						mListener->TextInput(keyboardEvent);
-//					}
-//				}
-
-//				break;
-//			}
-			case KeymapNotify:
-			{
-				XRefreshKeyboardMapping(&event.xmapping);
-				break;
-			}
-			default:
-			{
-				break;
-			}
-		}
+		XCloseDisplay(display);
 	}
 	}
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void swap_buffers()
 void swap_buffers()
 {
 {
-	glXSwapBuffers(mXDisplay, mGLXWindow);
+	glXSwapBuffers(display, glx_window);
 }
 }
 
 
 ////-----------------------------------------------------------------------------
 ////-----------------------------------------------------------------------------
@@ -320,7 +175,7 @@ void swap_buffers()
 //		return;
 //		return;
 //	}
 //	}
 
 
-//	XMoveWindow(mXDisplay, mXWindow, x, y);
+//	XMoveWindow(display, window, x, y);
 //}
 //}
 
 
 ////-----------------------------------------------------------------------------
 ////-----------------------------------------------------------------------------
@@ -336,7 +191,7 @@ void swap_buffers()
 //		return;
 //		return;
 //	}
 //	}
 
 
-//	XResizeWindow(mXDisplay, mXWindow, width, height);
+//	XResizeWindow(display, window, width, height);
 //}
 //}
 
 
 ////-----------------------------------------------------------------------------
 ////-----------------------------------------------------------------------------
@@ -344,16 +199,16 @@ void swap_buffers()
 //{
 //{
 //	mFull = full;
 //	mFull = full;
 //	XEvent xEvent;
 //	XEvent xEvent;
-//	Atom wmState = XInternAtom(mXDisplay, "_NET_WM_STATE", False);
-//	Atom fullscreen = XInternAtom(mXDisplay, "_NET_WM_STATE_FULLSCREEN", False);
+//	Atom wmState = XInternAtom(display, "_NET_WM_STATE", False);
+//	Atom fullscreen = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", False);
 //	xEvent.type = ClientMessage;
 //	xEvent.type = ClientMessage;
-//	xEvent.xclient.window = mXWindow;
+//	xEvent.xclient.window = window;
 //	xEvent.xclient.message_type = wmState;
 //	xEvent.xclient.message_type = wmState;
 //	xEvent.xclient.format = 32;
 //	xEvent.xclient.format = 32;
 //	xEvent.xclient.data.l[0] = (mFull ? 1 : 0);
 //	xEvent.xclient.data.l[0] = (mFull ? 1 : 0);
 //	xEvent.xclient.data.l[1] = fullscreen;
 //	xEvent.xclient.data.l[1] = fullscreen;
 //	xEvent.xclient.data.l[2] = 0;
 //	xEvent.xclient.data.l[2] = 0;
-//	XSendEvent(mXDisplay, DefaultRootWindow(mXDisplay), False, SubstructureNotifyMask, &xEvent);
+//	XSendEvent(display, DefaultRootWindow(display), False, SubstructureNotifyMask, &xEvent);
 //}
 //}
 
 
 } // namespace os
 } // namespace os

+ 0 - 1
src/os/linux/LinuxOS.cpp

@@ -202,7 +202,6 @@ bool ls(const char* path, List<Str>& fileList)
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 void init_os()
 void init_os()
 {
 {
-
 }
 }
 
 
 } // namespace os
 } // namespace os