From 9c08082263ab2519bfa66e19212235d1960c3ad8 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 1 Feb 2011 19:23:49 +0000 Subject: [PATCH] Minor updates to the mouse tracking architecture. --- src/input.cpp | 51 ++++++++++++++++++++++++++++++++++++++--------- src/input.h | 4 ++-- src/worldentity.h | 3 +++ 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index 25d4a5a0..6e3585e1 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -31,11 +31,17 @@ static class InputData public: InputData() : mouse(-1, -1), - buttons(0, 0, 0) + buttons(0, 0, 0), + nentities(0) { } +private: int2 mouse; int3 buttons; + + static int const MAX_ENTITIES = 100; + WorldEntity *entities[MAX_ENTITIES]; + int nentities; } inputdata; @@ -62,28 +68,55 @@ float2 Input::GetAxis(int axis) return f; } -void Input::SetMousePos(int2 coord) +int2 Input::GetMousePos() { - data->mouse = coord; + return data->mouse; } -int2 Input::GetMousePos() +int3 Input::GetMouseButtons() { - return data->mouse; + return data->buttons; +} + +void Input::TrackMouse(WorldEntity *e) +{ + if (data->nentities >= InputData::MAX_ENTITIES) + return; + data->entities[data->nentities] = e; + data->nentities++; +} + +void Input::UntrackMouse(WorldEntity *e) +{ + for (int n = 0; n < data->nentities; n++) + { + if (data->entities[n] != e) + continue; + + data->entities[n] = data->entities[data->nentities - 1]; + data->nentities--; + n--; + } +} + +void Input::SetMousePos(int2 coord) +{ + data->mouse = coord; + + /* FIXME: parse all subscribed entities and update them */ } void Input::SetMouseButton(int index) { data->buttons[index] = 1; + + /* FIXME: parse all subscribed entities and update them */ } void Input::UnsetMouseButton(int index) { data->buttons[index] = 0; -} -int3 Input::GetMouseButtons() -{ - return data->buttons; + /* FIXME: parse all subscribed entities and update them */ } diff --git a/src/input.h b/src/input.h index e33b9aa3..6cfac64a 100644 --- a/src/input.h +++ b/src/input.h @@ -29,8 +29,8 @@ public: static int3 GetMouseButtons(); /* Entities can subscribe to events */ - static void ListenMouse(WorldEntity *e); - static void UnlistenMouse(WorldEntity *e); + static void TrackMouse(WorldEntity *e); + static void UntrackMouse(WorldEntity *e); /* These methods are called by the underlying input listeners */ static void SetMousePos(int2 coord); diff --git a/src/worldentity.h b/src/worldentity.h index 324d5213..d70c7372 100644 --- a/src/worldentity.h +++ b/src/worldentity.h @@ -26,6 +26,9 @@ public: float3 velocity; float3 bbox[2]; + int2 mousepos; + int3 mousebuttons; + protected: WorldEntity(); virtual ~WorldEntity();