瀏覽代碼

refactoring Input class

dmuratshin 9 年之前
父節點
當前提交
9bb3b35c97
共有 5 個文件被更改,包括 8 次插入62 次删除
  1. 2 3
      oxygine/src/Input.cpp
  2. 1 1
      oxygine/src/Input.h
  3. 3 54
      oxygine/src/PointerState.cpp
  4. 2 2
      oxygine/src/PointerState.h
  5. 0 2
      oxygine/src/core/oxygine.cpp

+ 2 - 3
oxygine/src/Input.cpp

@@ -25,9 +25,9 @@ namespace oxygine
         me.pressure = pressure;
         me.pressure = pressure;
 
 
         if (type == TouchEvent::TOUCH_DOWN)
         if (type == TouchEvent::TOUCH_DOWN)
-            ps->_isPressed[button] = true;
+            ps->_pressed |= 1 << button;
         else if (type == TouchEvent::TOUCH_UP)
         else if (type == TouchEvent::TOUCH_UP)
-            ps->_isPressed[button] = false;
+            ps->_pressed &= ~(1 << button);
 
 
         ps->_position = p;
         ps->_position = p;
 
 
@@ -65,7 +65,6 @@ namespace oxygine
 
 
     Input::Input()
     Input::Input()
     {
     {
-        addRef();
         _pointerMouse.init(MAX_TOUCHES + 1);
         _pointerMouse.init(MAX_TOUCHES + 1);
         for (int i = 0; i < MAX_TOUCHES; ++i)
         for (int i = 0; i < MAX_TOUCHES; ++i)
             _pointers[i].init(i + 1);
             _pointers[i].init(i + 1);

+ 1 - 1
oxygine/src/Input.h

@@ -12,7 +12,7 @@ namespace oxygine
 
 
     const int MAX_TOUCHES = 17;
     const int MAX_TOUCHES = 17;
 
 
-    class Input: public Object
+    class Input
     {
     {
     public:
     public:
         static Input instance;
         static Input instance;

+ 3 - 54
oxygine/src/PointerState.cpp

@@ -10,63 +10,12 @@ namespace oxygine
     void PointerState::init(int pointerIndex)
     void PointerState::init(int pointerIndex)
     {
     {
         _index = pointerIndex;
         _index = pointerIndex;
-        for (int i = 0; i < MouseButton_Count; ++i)
-            _isPressed[i] = false;
+        _pressed = 0;
         _position.setZero();
         _position.setZero();
     }
     }
 
 
-    bool isFriend22(Actor* actor, Actor* max_parent, Actor* checkParent)
+    bool PointerState::isPressed(MouseButton mb) const
     {
     {
-        if (!max_parent)
-            max_parent = actor;
-
-        Actor* parent = actor;
-        while (parent)
-        {
-            if (parent == checkParent)
-                return true;
-            Actor* copy = parent;
-            parent = parent->getParent();
-
-            if (copy == max_parent)
-                break;
-        }
-        return false;
-    }
-    /*
-    bool checkParent(spEventHandler eh, Actor *checkIsItChild)
-    {
-        Actor *parent = eh->getFriendActor();
-        if (!parent)
-        {
-            if (eh->getClient() == checkIsItChild)
-                return true;
-            return false;
-        }
-        while (checkIsItChild)
-        {
-            if (checkIsItChild == parent)
-                return true;
-            checkIsItChild = checkIsItChild->getParent();
-        }
-        return false;
-    }
-    */
-
-    Vector2 global2local(Actor* actor, const Vector2& globalPos)
-    {
-        Vector2 pos = globalPos;
-        if (!actor)
-            return pos;
-        Actor* parent = actor->getParent();
-        if (parent)
-        {
-            pos = global2local(parent, globalPos);
-        }
-
-        pos = actor->global2local(pos);
-
-        return pos;
+        return (_pressed & (1 << mb)) != 0;
     }
     }
-
 }
 }

+ 2 - 2
oxygine/src/PointerState.h

@@ -24,7 +24,7 @@ namespace oxygine
 
 
         void init(int pointerIndex);
         void init(int pointerIndex);
 
 
-        bool            isPressed(MouseButton mb = MouseButton_Touch) const {return _isPressed[mb];}
+        bool            isPressed(MouseButton mb = MouseButton_Touch) const;
         int             getIndex() const {return _index;}
         int             getIndex() const {return _index;}
         const Vector2&  getPosition() const {return _position;}
         const Vector2&  getPosition() const {return _position;}
 
 
@@ -32,7 +32,7 @@ namespace oxygine
         friend class Input;
         friend class Input;
 
 
         int _index;
         int _index;
-        bool _isPressed[MouseButton_Count];
+        int _pressed;
         Vector2 _position;
         Vector2 _position;
     };
     };
 }
 }

+ 0 - 2
oxygine/src/core/oxygine.cpp

@@ -232,8 +232,6 @@ namespace oxygine
 
 
         void init(init_desc* desc_ptr)
         void init(init_desc* desc_ptr)
         {
         {
-            Input::instance.__removeFromDebugList();
-
             std::string t;
             std::string t;
 
 
 #ifdef OX_DEBUG
 #ifdef OX_DEBUG