浏览代码

Simplify input folder

Daniele Bartolini 12 年之前
父节点
当前提交
03dee6d1a3

+ 0 - 44
engine/input/Accelerometer.cpp

@@ -1,44 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-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 "Accelerometer.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-Accelerometer::Accelerometer() :
-	m_orientation(0.0f, 0.0f, 0.0f)
-{
-}
-
-//-----------------------------------------------------------------------------
-const Vec3& Accelerometer::orientation() const
-{
-	return m_orientation;
-}
-
-} // namespace crown

+ 10 - 19
engine/input/Accelerometer.h

@@ -32,38 +32,29 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 namespace crown
 {
 {
 
 
-class InputManager;
-
-struct AccelerometerEvent
-{
-	float x;
-	float y;
-	float z;
-};
-
-class AccelerometerListener
-{
-public:
-
-	virtual void accelerometer_changed(const AccelerometerEvent& event) { (void)event; }
-};
-
 /// Interface for accessing accelerometer input device.
 /// Interface for accessing accelerometer input device.
 class Accelerometer
 class Accelerometer
 {
 {
 public:
 public:
 	
 	
-					Accelerometer();
+	//-----------------------------------------------------------------------------
+	Accelerometer()
+		: m_orientation(0.0f, 0.0f, 0.0f)
+	{
+	}
 
 
 	/// Returns the orientation of the accelerometer.
 	/// Returns the orientation of the accelerometer.
 	/// FIXME NEED MORE DOCUMENTATION
 	/// FIXME NEED MORE DOCUMENTATION
-	const Vec3&		orientation() const;
+	const Vec3& orientation() const
+	{
+		return m_orientation;
+	}
 
 
 private:
 private:
 
 
 	Vec3			m_orientation;
 	Vec3			m_orientation;
 
 
-	friend class	InputManager;
+	friend class	Device;
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 0 - 178
engine/input/EventDispatcher.cpp

@@ -1,178 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-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 "EventDispatcher.h"
-#include "Allocator.h"
-#include "Log.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-EventDispatcher::EventDispatcher() :
-	m_mouse_listener_list(default_allocator()),
-	m_keyboard_listener_list(default_allocator()),
-	m_touch_listener_list(default_allocator()),
-	m_acc_listener_list(default_allocator())
-{
-}
-
-//-----------------------------------------------------------------------------
-EventDispatcher::~EventDispatcher()
-{
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::add_mouse_listener(MouseListener* listener)
-{
-	CE_ASSERT(listener != NULL, "Listener must be != NULL");
-
-	m_mouse_listener_list.push_back(listener);
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::add_keyboard_listener(KeyboardListener* listener)
-{
-	CE_ASSERT(listener != NULL, "Listener must be != NULL");
-
-	m_keyboard_listener_list.push_back(listener);
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::add_touch_listener(TouchListener* listener)
-{
-	CE_ASSERT(listener != NULL, "Listener must be != NULL");
-
-	m_touch_listener_list.push_back(listener);
-}
-
-void EventDispatcher::add_accelerometer_listener(AccelerometerListener* listener)
-{
-	CE_ASSERT(listener != NULL, "Listener must be != NULL");
-	m_acc_listener_list.push_back(listener);
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::button_pressed(const MouseEvent& event)
-{
-	for (uint32_t i = 0; i < m_mouse_listener_list.size(); i++)
-	{
-		m_mouse_listener_list[i]->button_pressed(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::button_released(const MouseEvent& event)
-{
-	for (uint32_t i = 0; i < m_mouse_listener_list.size(); i++)
-	{
-		m_mouse_listener_list[i]->button_released(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::cursor_moved(const MouseEvent& event)
-{
-	for (uint32_t i = 0; i < m_mouse_listener_list.size(); i++)
-	{
-		m_mouse_listener_list[i]->cursor_moved(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::key_pressed(const KeyboardEvent& event)
-{
-	for (uint32_t i = 0; i < m_keyboard_listener_list.size(); i++)
-	{
-		m_keyboard_listener_list[i]->key_pressed(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::key_released(const KeyboardEvent& event)
-{
-	for (uint32_t i = 0; i < m_keyboard_listener_list.size(); i++)
-	{
-		m_keyboard_listener_list[i]->key_released(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::text_input(const KeyboardEvent& event)
-{
-	for (uint32_t i = 0; i < m_keyboard_listener_list.size(); i++)
-	{
-		m_keyboard_listener_list[i]->text_input(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::touch_down(const TouchEvent& event)
-{
-	for (uint32_t i = 0; i < m_touch_listener_list.size(); i++)
-	{
-		m_touch_listener_list[i]->touch_down(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::touch_up(const TouchEvent& event)
-{
-	for (uint32_t i = 0; i < m_touch_listener_list.size(); i++)
-	{
-		m_touch_listener_list[i]->touch_up(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::touch_move(const TouchEvent& event)
-{
-	for (uint32_t i = 0; i < m_touch_listener_list.size(); i++)
-	{
-		m_touch_listener_list[i]->touch_move(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::touch_cancel(const TouchEvent& event)
-{
-	for (uint32_t i = 0; i < m_touch_listener_list.size(); i++)
-	{
-		m_touch_listener_list[i]->touch_cancel(event);
-	}
-}
-
-//-----------------------------------------------------------------------------
-void EventDispatcher::accelerometer_changed(const AccelerometerEvent& event)
-{
-	for (uint32_t i = 0; i < m_acc_listener_list.size(); i++)
-	{
-		m_acc_listener_list[i]->accelerometer_changed(event);
-	}
-}
-
-} // namespace crown
-

+ 0 - 79
engine/input/EventDispatcher.h

@@ -1,79 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "List.h"
-#include "Mouse.h"
-#include "Keyboard.h"
-#include "Touch.h"
-#include "Accelerometer.h"
-
-namespace crown
-{
-
-class EventDispatcher
-{
-	typedef List<MouseListener*>			MouseListenerList;
-	typedef List<KeyboardListener*>			KeyboardListenerList;
-	typedef List<TouchListener*>			TouchListenerList;
-	typedef List<AccelerometerListener*>	AccelerometerListenerList;
-
-public:
-
-	EventDispatcher();
-	~EventDispatcher();
-
-	void add_mouse_listener(MouseListener* listener);
-	void add_keyboard_listener(KeyboardListener* listener);
-	void add_touch_listener(TouchListener* listener);
-	void add_accelerometer_listener(AccelerometerListener* listener);
-
-	void button_pressed(const MouseEvent&);
-	void button_released(const MouseEvent&);
-	void cursor_moved(const MouseEvent&);
-
-	void key_pressed(const KeyboardEvent&);
-	void key_released(const KeyboardEvent&);
-	void text_input(const KeyboardEvent&);
-
-	void touch_down(const TouchEvent& event);
-	void touch_up(const TouchEvent& event);
-	void touch_move(const TouchEvent& event);
-	void touch_cancel(const TouchEvent& event);
-
-	void accelerometer_changed(const AccelerometerEvent& event);
-
-private:
-
-	MouseListenerList			m_mouse_listener_list;
-	KeyboardListenerList		m_keyboard_listener_list;
-	TouchListenerList			m_touch_listener_list;
-	AccelerometerListenerList	m_acc_listener_list;
-};
-
-} // namespace crown
-

+ 0 - 237
engine/input/InputManager.cpp

@@ -1,237 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-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 "InputManager.h"
-#include "OS.h"
-#include "Log.h"
-#include "EventBuffer.h"
-#include "OsEvents.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-InputManager::InputManager()
-{
-}
-
-//-----------------------------------------------------------------------------
-InputManager::~InputManager()
-{
-}
-
-//-----------------------------------------------------------------------------
-Keyboard* InputManager::keyboard()
-{
-	return &m_keyboard;
-}
-
-//-----------------------------------------------------------------------------
-Mouse* InputManager::mouse()
-{
-	return &m_mouse;
-}
-
-//-----------------------------------------------------------------------------
-Touch* InputManager::touch()
-{
-	return &m_touch;
-}
-
-//-----------------------------------------------------------------------------
-Accelerometer* InputManager::accelerometer()
-{
-	return &m_accelerometer;
-}
-
-//-----------------------------------------------------------------------------
-void InputManager::register_mouse_listener(MouseListener* listener)
-{
-	m_event_dispatcher.add_mouse_listener(listener);
-}
-
-//-----------------------------------------------------------------------------
-void InputManager::register_keyboard_listener(KeyboardListener* listener)
-{
-	m_event_dispatcher.add_keyboard_listener(listener);
-}
-
-//-----------------------------------------------------------------------------
-void InputManager::register_touch_listener(TouchListener* listener)
-{
-	m_event_dispatcher.add_touch_listener(listener);
-}
-
-//-----------------------------------------------------------------------------
-void InputManager::register_accelerometer_listener(AccelerometerListener* listener)
-{
-	m_event_dispatcher.add_accelerometer_listener(listener);
-}
-
-//-----------------------------------------------------------------------------
-EventDispatcher* InputManager::get_event_dispatcher()
-{
-	return &m_event_dispatcher;
-}
-
-//-----------------------------------------------------------------------------
-void InputManager::frame(uint64_t frame_count)
-{
-	void* event;
-	uint32_t event_type;
-	size_t event_size;
-
-	// Update input devices
-	m_keyboard.m_current_frame = frame_count;
-	m_mouse.m_current_frame = frame_count;
-
-	while (1)
-	{
-		if ((event = os_event_buffer()->get_next_event(event_type, event_size)) == NULL)
-		{
-			break;
-		}
-
-		switch (event_type)
-		{
-			case OSET_NONE:
-			{
-				return;
-			}
-			case OSET_BUTTON_PRESS:
-			case OSET_BUTTON_RELEASE:
-			{
-				MouseEvent mouse_event;
-				mouse_event.x = ((OsMouseEvent*)event)->x;
-				mouse_event.y = ((OsMouseEvent*)event)->y;
-				mouse_event.button = ((OsMouseEvent*)event)->button == 0 ? MB_LEFT : ((OsMouseEvent*)event)->button == 1 ? MB_MIDDLE : MB_RIGHT;
-				mouse_event.wheel = 0.0f;
-
-				if (event_type == OSET_BUTTON_PRESS)
-				{
-					m_mouse.update(frame_count, mouse_event.button, true);
-					m_event_dispatcher.button_pressed(mouse_event);
-				}
-				else
-				{
-					m_mouse.update(frame_count, mouse_event.button, false);
-					m_event_dispatcher.button_released(mouse_event);
-				}
-
-				break;
-			}
-			case OSET_KEY_PRESS:
-			case OSET_KEY_RELEASE:
-			{
-				KeyboardEvent keyboard_event;
-				keyboard_event.key = (KeyCode) ((OsKeyboardEvent*)event)->key;
-				keyboard_event.modifier = (uint8_t) ((OsKeyboardEvent*)event)->modifier;
-
-				m_keyboard.m_modifier = keyboard_event.modifier;
-
-				if (event_type == OSET_KEY_PRESS)
-				{
-					m_keyboard.update(frame_count, keyboard_event.key, true);
-					m_event_dispatcher.key_pressed(keyboard_event);
-				}
-				else
-				{
-					m_keyboard.update(frame_count, keyboard_event.key, false);
-					m_event_dispatcher.key_released(keyboard_event);
-				}
-
-				break;
-			}
-			case OSET_TOUCH_DOWN:
-			case OSET_TOUCH_UP:
-			{
-				TouchEvent touch_event;
-				touch_event.pointer_id = ((OsTouchEvent*)event)->pointer_id;
-				touch_event.x = ((OsTouchEvent*)event)->x;
-				touch_event.y = ((OsTouchEvent*)event)->y;
-
-				m_touch.m_pointers[touch_event.pointer_id].x = touch_event.x;
-				m_touch.m_pointers[touch_event.pointer_id].y = touch_event.y;
-
-				// FIXME
-				m_touch.m_pointers[touch_event.pointer_id].relative_x = 0.0f;
-				m_touch.m_pointers[touch_event.pointer_id].relative_y = 0.0f;
-
-				if (event_type == OSET_TOUCH_DOWN)
-				{
-					m_touch.m_pointers[touch_event.pointer_id].up = false;
-					m_event_dispatcher.touch_down(touch_event);
-				}
-				else
-				{
-					m_touch.m_pointers[touch_event.pointer_id].up = true;
-					m_event_dispatcher.touch_up(touch_event);
-				}
-
-				break;
-			}
-			case OSET_TOUCH_MOVE:
-			{
-				TouchEvent touch_event;
-				touch_event.pointer_id = ((OsTouchEvent*)event)->pointer_id;
-				touch_event.x = ((OsTouchEvent*)event)->x;
-				touch_event.y = ((OsTouchEvent*)event)->y;
-
-				m_touch.m_pointers[touch_event.pointer_id].x = touch_event.x;
-				m_touch.m_pointers[touch_event.pointer_id].y = touch_event.y;
-
-				// FIXME
-				m_touch.m_pointers[touch_event.pointer_id].relative_x = 0.0f;
-				m_touch.m_pointers[touch_event.pointer_id].relative_y = 0.0f;
-
-				m_event_dispatcher.touch_move(touch_event);
-
-				break;
-			}
-			// case OSET_ACCELEROMETER:
-			// {
-			// 	AccelerometerEvent sensor_event;
-			// 	sensor_event.x = event.data_a.float_value;
-			// 	sensor_event.y = event.data_b.float_value;
-			// 	sensor_event.z = event.data_c.float_value;
-
-			// 	m_accelerometer.m_orientation.x = sensor_event.x;
-			// 	m_accelerometer.m_orientation.y = sensor_event.y;
-			// 	m_accelerometer.m_orientation.z = sensor_event.z;
-
-			// 	m_event_dispatcher.accelerometer_changed(sensor_event);
-			// 	break;
-			// }
-			default:
-			{
-				break;
-			}
-		}
-	}
-}
-
-} // namespace crown
-

+ 0 - 74
engine/input/InputManager.h

@@ -1,74 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-*/
-
-#pragma once
-
-#include "EventDispatcher.h"
-#include "Mouse.h"
-#include "Keyboard.h"
-#include "Touch.h"
-#include "Accelerometer.h"
-
-namespace crown
-{
-
-class MouseListener;
-class KeyboardListener;
-class TouchListener;
-
-class InputManager
-{
-public:
-
-						InputManager();
-						~InputManager();
-
-	Keyboard*			keyboard();
-	Mouse*				mouse();
-	Touch*				touch();
-	Accelerometer*		accelerometer();
-
-	void				register_mouse_listener(MouseListener* listener);
-	void				register_keyboard_listener(KeyboardListener* listener);
-	void				register_touch_listener(TouchListener* listener);
-	void				register_accelerometer_listener(AccelerometerListener* listener);
-
-	EventDispatcher*	get_event_dispatcher();
-
-	void				frame(uint64_t frame_count);
-
-private:
-
-	EventDispatcher		m_event_dispatcher;
-
-	Keyboard			m_keyboard;
-	Mouse				m_mouse;
-	Touch				m_touch;
-	Accelerometer		m_accelerometer;
-};
-
-} // namespace crown
-

+ 0 - 90
engine/input/Keyboard.cpp

@@ -1,90 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-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 "Keyboard.h"
-#include "Assert.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-Keyboard::Keyboard() :
-	m_modifier(0),
-	m_current_frame(0),
-	m_last_key(KC_NOKEY)
-{
-	for (uint32_t i = 0; i < MAX_KEYCODES; i++)
-	{
-		m_keys[i] = ~0;
-		m_state[i] = false;
-	}
-}
-
-//-----------------------------------------------------------------------------
-bool Keyboard::modifier_pressed(ModifierKey modifier) const
-{
-	return (m_modifier & modifier) == modifier;
-}
-
-//-----------------------------------------------------------------------------
-bool Keyboard::key_pressed(KeyCode key) const
-{
-	CE_ASSERT(key >= 0 && key < MAX_KEYCODES, "KeyCode out of range: %d", key);
-
-	return (m_state[key] == true) && (m_keys[key] == m_current_frame);
-}
-
-//-----------------------------------------------------------------------------
-bool Keyboard::key_released(KeyCode key) const
-{
-	CE_ASSERT(key >= 0 && key < MAX_KEYCODES, "KeyCode out of range: %d", key);
-
-	return (m_state[key] == false) && (m_keys[key] == m_current_frame);
-}
-
-//-----------------------------------------------------------------------------
-bool Keyboard::any_pressed() const
-{
-	return key_pressed(m_last_key);
-}
-
-//-----------------------------------------------------------------------------
-bool Keyboard::any_released() const
-{
-	return key_released(m_last_key);
-}
-
-//-----------------------------------------------------------------------------
-void Keyboard::update(uint64_t frame, KeyCode k, bool state)
-{
-	CE_ASSERT(k >= 0 && k < MAX_KEYCODES, "KeyCode out of range: %d", k);
-
-	m_last_key = k;
-	m_keys[k] = frame;
-	m_state[k] = state;
-}
-
-} // namespace crown

+ 45 - 29
engine/input/Keyboard.h

@@ -29,6 +29,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Types.h"
 #include "Types.h"
 #include "KeyCode.h"
 #include "KeyCode.h"
 #include "OS.h"
 #include "OS.h"
+#include "Assert.h"
 
 
 #undef MK_SHIFT
 #undef MK_SHIFT
 #undef MK_ALT
 #undef MK_ALT
@@ -36,9 +37,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 namespace crown
 {
 {
 
 
-class InputManager;
-
-
 /// Enumerates modifier keys.
 /// Enumerates modifier keys.
 enum ModifierKey
 enum ModifierKey
 {
 {
@@ -47,29 +45,20 @@ enum ModifierKey
 	MK_ALT		= 4
 	MK_ALT		= 4
 };
 };
 
 
-struct KeyboardEvent
-{
-	KeyCode		key;
-	uint8_t		modifier;
-	char		text[4];
-};
-
-class KeyboardListener
-{
-
-public:
-
-	virtual void key_pressed(const KeyboardEvent& event) { (void)event; }
-	virtual void key_released(const KeyboardEvent& event) { (void)event; }
-	virtual void text_input(const KeyboardEvent& event) { (void)event; }
-};
-
 /// Interface for accessing keyboard input device.
 /// Interface for accessing keyboard input device.
 class Keyboard
 class Keyboard
 {
 {
 public:
 public:
 
 
-					Keyboard();
+	Keyboard()
+		: m_modifier(0), m_current_frame(0), m_last_key(KC_NOKEY)
+	{
+		for (uint32_t i = 0; i < MAX_KEYCODES; i++)
+		{
+			m_keys[i] = ~0;
+			m_state[i] = false;
+		}
+	}
 
 
 	/// Returns whether the specified @a modifier is pressed.
 	/// Returns whether the specified @a modifier is pressed.
 	/// @note
 	/// @note
@@ -77,23 +66,51 @@ public:
 	/// 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
 	/// @note
 	/// Crown currently supports three different modifier keys: Shift, Ctrl and Alt.
 	/// Crown currently supports three different modifier keys: Shift, Ctrl and Alt.
-	bool			modifier_pressed(ModifierKey modifier) const;
+	bool modifier_pressed(ModifierKey modifier) const
+	{
+		return (m_modifier & modifier) == modifier;
+	}
 
 
 	/// Returns whether the specified @a key is pressed in the current frame.
 	/// Returns whether the specified @a key is pressed in the current frame.
-	bool			key_pressed(KeyCode key) const;
+	bool key_pressed(KeyCode key) const
+	{
+		CE_ASSERT(key >= 0 && key < MAX_KEYCODES, "KeyCode out of range: %d", key);
+
+		return (m_state[key] == true) && (m_keys[key] == m_current_frame);
+	}
 
 
 	/// Returns whether the specified @a key is released in the current frame.
 	/// Returns whether the specified @a key is released in the current frame.
-	bool			key_released(KeyCode key) const;
+	bool key_released(KeyCode key) const
+	{
+		CE_ASSERT(key >= 0 && key < MAX_KEYCODES, "KeyCode out of range: %d", key);
+
+		return (m_state[key] == false) && (m_keys[key] == m_current_frame);
+	}
 
 
 	/// Returns wheter any key is pressed in the current frame.
 	/// Returns wheter any key is pressed in the current frame.
-	bool			any_pressed() const;
+	bool any_pressed() const
+	{
+		return key_pressed(m_last_key);
+	}
 
 
 	/// Returns whether any key is released in the current frame.
 	/// Returns whether any key is released in the current frame.
-	bool			any_released() const;
+	bool any_released() const
+	{
+		return key_released(m_last_key);
+	}
 
 
 private:
 private:
 
 
-	void			update(uint64_t frame, KeyCode k, bool state);
+	void update(uint64_t frame, KeyCode k, bool state)
+	{
+		CE_ASSERT(k >= 0 && k < MAX_KEYCODES, "KeyCode out of range: %d", k);
+
+		m_last_key = k;
+		m_keys[k] = frame;
+		m_state[k] = state;
+	}
+
+private:
 
 
 	uint8_t			m_modifier;
 	uint8_t			m_modifier;
 
 
@@ -105,8 +122,7 @@ private:
 	uint64_t		m_keys[MAX_KEYCODES];
 	uint64_t		m_keys[MAX_KEYCODES];
 	bool			m_state[MAX_KEYCODES];
 	bool			m_state[MAX_KEYCODES];
 
 
-	friend class	InputManager;
+	friend class	Device;
 };
 };
 
 
 } // namespace crown
 } // namespace crown
-

+ 0 - 131
engine/input/Mouse.cpp

@@ -1,131 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-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 "Mouse.h"
-#include "Device.h"
-#include "OsWindow.h"
-
-#undef MB_RIGHT
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-Mouse::Mouse() :
-	m_current_frame(0),
-	m_last_button(MB_LEFT)
-{
-	m_buttons[MB_LEFT] = ~0;
-	m_buttons[MB_MIDDLE] = ~0;
-	m_buttons[MB_RIGHT] = ~0;
-
-	m_state[MB_LEFT] = false;
-	m_state[MB_MIDDLE] = false;
-	m_state[MB_RIGHT] = false;
-}
-
-//-----------------------------------------------------------------------------
-bool Mouse::button_pressed(MouseButton button) const
-{
-	CE_ASSERT(button >= 0 && button < MAX_MOUSE_BUTTONS, "MouseButton out of range: %d", button);
-
-	return (m_state[button] == true) && (m_buttons[button] == m_current_frame);
-}
-
-//-----------------------------------------------------------------------------
-bool Mouse::button_released(MouseButton button) const
-{
-	CE_ASSERT(button >= 0 && button < MAX_MOUSE_BUTTONS, "MouseButton out of range: %d", button);
-
-	return (m_state[button] == false) && (m_buttons[button] == m_current_frame);
-}
-
-//-----------------------------------------------------------------------------
-bool Mouse::any_pressed() const
-{
-	return button_pressed(m_last_button);
-}
-
-//-----------------------------------------------------------------------------
-bool Mouse::any_released() const
-{
-	return button_released(m_last_button);
-}
-
-//-----------------------------------------------------------------------------
-Vec2 Mouse::cursor_xy() const
-{
-	int32_t x, y;
-
-	device()->window()->get_cursor_xy(x, y);
-
-	return Vec2(x, y);
-}
-
-//-----------------------------------------------------------------------------
-void Mouse::set_cursor_xy(const Vec2& position)
-{
-	device()->window()->set_cursor_xy((int32_t) position.x, (int32_t) position.y);
-}
-
-//-----------------------------------------------------------------------------
-Vec2 Mouse::cursor_relative_xy() const
-{
-	uint32_t window_width;
-	uint32_t window_height;
-
-	device()->window()->get_size(window_width, window_height);
-
-	Vec2 pos = cursor_xy();
-
-	pos.x = pos.x / (float) window_width;
-	pos.y = pos.y / (float) window_height;
-
-	return pos;
-}
-
-//-----------------------------------------------------------------------------
-void Mouse::set_cursor_relative_xy(const Vec2& position)
-{
-	uint32_t window_width;
-	uint32_t window_height;
-
-	device()->window()->get_size(window_width, window_height);
-
-	set_cursor_xy(Vec2(position.x * (float) window_width, position.y * (float) window_height));
-}
-
-//-----------------------------------------------------------------------------
-void Mouse::update(uint64_t frame, MouseButton b, bool state)
-{
-	CE_ASSERT(b >= 0 && b < MAX_MOUSE_BUTTONS, "MouseButton out of range: %d", b);
-
-	m_last_button = b;
-	m_buttons[b] = frame;
-	m_state[b] = state;
-}
-
-} // namespace crown

+ 80 - 30
engine/input/Mouse.h

@@ -29,6 +29,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 
 #include "Types.h"
 #include "Types.h"
 #include "Vec2.h"
 #include "Vec2.h"
+#include "Device.h"
+#include "OsWindow.h"
 
 
 namespace crown
 namespace crown
 {
 {
@@ -43,58 +45,75 @@ enum MouseButton
 	MB_RIGHT	= 2
 	MB_RIGHT	= 2
 };
 };
 
 
-struct MouseEvent
-{
-	MouseButton button;
-	int32_t x;
-	int32_t y;
-	float wheel;
-};
-
-/// Interface for managing mouse input.
-class MouseListener
-{
-
-public:
-
-	virtual void button_pressed(const MouseEvent& event) { (void)event; }
-	virtual void button_released(const MouseEvent& event) { (void)event; }
-	virtual void cursor_moved(const MouseEvent& event) { (void)event; }
-};
-
 /// Interface for accessing mouse input device.
 /// Interface for accessing mouse input device.
 class Mouse
 class Mouse
 {
 {
 public:
 public:
 
 
-					Mouse();
+	//-----------------------------------------------------------------------------
+	Mouse()
+		: m_current_frame(0), m_last_button(MB_LEFT)
+	{
+		m_buttons[MB_LEFT] = ~0;
+		m_buttons[MB_MIDDLE] = ~0;
+		m_buttons[MB_RIGHT] = ~0;
 
 
+		m_state[MB_LEFT] = false;
+		m_state[MB_MIDDLE] = false;
+		m_state[MB_RIGHT] = false;
+	}
 
 
 	/// Returns whether @a button is pressed in the current frame.
 	/// Returns whether @a button is pressed in the current frame.
-	bool			button_pressed(MouseButton button) const;
+	bool button_pressed(MouseButton button) const
+	{
+		CE_ASSERT(button >= 0 && button < MAX_MOUSE_BUTTONS, "MouseButton out of range: %d", button);
+
+		return (m_state[button] == true) && (m_buttons[button] == m_current_frame);
+	}
 
 
 	/// Returns whether @a button is released in the current frame.
 	/// Returns whether @a button is released in the current frame.
-	bool			button_released(MouseButton button) const;
+	bool button_released(MouseButton button) const
+	{
+		CE_ASSERT(button >= 0 && button < MAX_MOUSE_BUTTONS, "MouseButton out of range: %d", button);
+
+		return (m_state[button] == false) && (m_buttons[button] == m_current_frame);
+	}
 
 
 	/// Returns wheter any button is pressed in the current frame.
 	/// Returns wheter any button is pressed in the current frame.
-	bool			any_pressed() const;
+	bool any_pressed() const
+	{
+		return button_pressed(m_last_button);
+	}
 
 
 	/// Returns whether any button is released in the current frame.
 	/// Returns whether any button is released in the current frame.
-	bool			any_released() const;
+	bool any_released() const
+	{
+		return button_released(m_last_button);
+	}
 
 
 	/// Returns the position of the cursor in window space.
 	/// Returns the position of the cursor in window space.
 	/// @note
 	/// @note
 	/// 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.
-	Vec2			cursor_xy() const;
+	Vec2 cursor_xy() const
+	{
+		int32_t x, y;
+
+		device()->window()->get_cursor_xy(x, y);
+
+		return Vec2(x, y);
+	}
 
 
 	/// Sets the position of the cursor in window space.
 	/// Sets the position of the cursor in window space.
 	/// @note
 	/// @note
 	/// 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.
-	void			set_cursor_xy(const Vec2& position);
+	void set_cursor_xy(const Vec2& position)
+	{
+		device()->window()->set_cursor_xy((int32_t) position.x, (int32_t) position.y);
+	}
 
 
 	/// Returns the relative position of the cursor in window space.
 	/// Returns the relative position of the cursor in window space.
 	/// @note
 	/// @note
@@ -105,7 +124,20 @@ public:
 	/// Relative coordinates are mapped to a float varying
 	/// Relative coordinates are mapped to a float 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.
-	Vec2			cursor_relative_xy() const;
+	Vec2 cursor_relative_xy() const
+	{
+		uint32_t window_width;
+		uint32_t window_height;
+
+		device()->window()->get_size(window_width, window_height);
+
+		Vec2 pos = cursor_xy();
+
+		pos.x = pos.x / (float) window_width;
+		pos.y = pos.y / (float) window_height;
+
+		return pos;
+	}
 
 
 	/// Sets the relative position of the cursor in window space.
 	/// Sets the relative position of the cursor in window space.
 	/// @note
 	/// @note
@@ -116,11 +148,29 @@ public:
 	/// Relative coordinates are mapped to a float varying
 	/// Relative coordinates are mapped to a float 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.
-	void			set_cursor_relative_xy(const Vec2& position);
+	void set_cursor_relative_xy(const Vec2& position)
+	{
+		uint32_t window_width;
+		uint32_t window_height;
+
+		device()->window()->get_size(window_width, window_height);
+
+		set_cursor_xy(Vec2(position.x * (float) window_width, position.y * (float) window_height));
+	}
 
 
 private:
 private:
 
 
-	void			update(uint64_t frame, MouseButton b, bool state);
+	//-----------------------------------------------------------------------------
+	void update(uint64_t frame, MouseButton b, bool state)
+	{
+		CE_ASSERT(b >= 0 && b < MAX_MOUSE_BUTTONS, "MouseButton out of range: %d", b);
+
+		m_last_button = b;
+		m_buttons[b] = frame;
+		m_state[b] = state;
+	}
+
+private:
 
 
 	// The current frame number
 	// The current frame number
 	uint64_t		m_current_frame;
 	uint64_t		m_current_frame;
@@ -131,7 +181,7 @@ private:
 	uint64_t		m_buttons[MAX_MOUSE_BUTTONS];
 	uint64_t		m_buttons[MAX_MOUSE_BUTTONS];
 	bool			m_state[MAX_MOUSE_BUTTONS];
 	bool			m_state[MAX_MOUSE_BUTTONS];
 
 
-	friend class	InputManager;
+	friend class	Device;
 };
 };
 
 
 } // namespace crown
 } // namespace crown

+ 0 - 66
engine/input/Touch.cpp

@@ -1,66 +0,0 @@
-/*
-Copyright (c) 2013 Daniele Bartolini, Michele Rossi
-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 "Touch.h"
-
-namespace crown
-{
-
-//-----------------------------------------------------------------------------
-Touch::Touch()
-{
-
-}
-
-//-----------------------------------------------------------------------------
-bool Touch::touch_up(uint16_t id) const
-{
-	return m_pointers[id].up == true;
-}
-
-//-----------------------------------------------------------------------------
-bool Touch::touch_down(uint16_t id) const
-{
-	return m_pointers[id].up == false;
-}
-
-//----------------------------------------------------------------------------- 
-Vec2 Touch::touch_xy(uint16_t id) const
-{
-	const PointerData& data = m_pointers[id];
-
-	return Vec2(data.x, data.y);
-}
-
-//-----------------------------------------------------------------------------
-Vec2 Touch::touch_relative_xy(uint16_t id)
-{
-	const PointerData& data = m_pointers[id];
-
-	return Vec2(data.relative_x, data.relative_y);
-}
-
-} // namespace crown

+ 21 - 26
engine/input/Touch.h

@@ -43,44 +43,34 @@ struct PointerData
 	bool		up;
 	bool		up;
 };
 };
 
 
-struct TouchEvent
-{
-	uint32_t	pointer_id;
-	uint32_t	x;
-	uint32_t	y;
-};
-
-/// Interface for managing touch input device.
-class TouchListener
-{
-
-public:
-
-	virtual void touch_down(const TouchEvent& event) { (void)event; }
-	virtual void touch_up(const TouchEvent& event) { (void)event; }
-	virtual void touch_move(const TouchEvent& event) { (void)event; }
-	virtual void touch_cancel(const TouchEvent& event) { (void)event; }
-};
-
 /// Interface for accessing touch input device.
 /// Interface for accessing touch input device.
 class Touch
 class Touch
 {
 {
 public:
 public:
 
 
-					Touch();
-
 	/// Returns whether the touch pointer @a id is up.
 	/// Returns whether the touch pointer @a id is up.
-	bool			touch_up(uint16_t id) const;
+	bool touch_up(uint16_t id) const
+	{
+		return m_pointers[id].up == true;
+	}
 
 
 	/// Returns whether the touch pointer @a id is down.
 	/// Returns whether the touch pointer @a id is down.
-	bool			touch_down(uint16_t id) const;
+	bool touch_down(uint16_t id) const
+	{
+		return m_pointers[id].up == false;
+	}
 
 
 	/// Returns the position of the pointer @a id in windows space.
 	/// Returns the position of the pointer @a id in windows space.
 	/// @note
 	/// @note
 	/// 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.
-	Vec2			touch_xy(uint16_t id) const;
+	Vec2 touch_xy(uint16_t id) const
+	{
+		const PointerData& data = m_pointers[id];
+
+		return Vec2(data.x, data.y);
+	}
 
 
 	/// Returns the relative position of the pointer @a id in window space.
 	/// Returns the relative position of the pointer @a id in window space.
 	/// @note
 	/// @note
@@ -91,13 +81,18 @@ public:
 	/// Relative coordinates are mapped to a float varying
 	/// Relative coordinates are mapped to a float 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.
-	Vec2			touch_relative_xy(uint16_t id);
+	Vec2 touch_relative_xy(uint16_t id)
+	{
+		const PointerData& data = m_pointers[id];
+
+		return Vec2(data.relative_x, data.relative_y);
+	}
 
 
 private:
 private:
 
 
 	PointerData		m_pointers[MAX_POINTER_IDS];
 	PointerData		m_pointers[MAX_POINTER_IDS];
 
 
-	friend class	InputManager;
+	friend class	Device;
 };
 };
 
 
 }
 }