diff --git a/src/input/input.cpp b/src/input/input.cpp index 5637b28d..13d40eec 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -31,6 +31,8 @@ namespace lol * Input implementation class */ +Array Input::InputAssocationList; + static class InputData { friend class Input; @@ -113,6 +115,102 @@ int Input::GetButtonState(int button) #endif } +//-- + +//--- +//Internal : Updates the action status & timers +void Input::UpdateActionStatus(float seconds) +{ + for (int i = 0; i < InputAssocationList.Count(); i++) + { + ButtonSetting &CurIT = InputAssocationList[i]; + + CurIT.PrevStatus = CurIT.CurStatus; + CurIT.CurStatus = Input::GetButtonState(CurIT.RawButtonId); + + for (int j = 0; j < CurIT.AssociatedActionList.Count(); j++) + { + ActionSetting &CurAS = CurIT.AssociatedActionList[j]; + + if (CurAS.BufferedSince <= CurAS.BufferingTime) + CurAS.BufferedSince += seconds; + + if (CurIT.CurStatus && CurAS.BufferingTime >= .0f) + CurAS.BufferedSince = .0f; + } + } + +} + +//Helps link a software input Action-Id to an hardware input Button-Id. +void Input::LinkActionIdToButtonId(int ActionId, int ButtonId) +{ + int ITIdx = GetButtonSettingIdx(ButtonId); + if (ITIdx == -1) + { + ITIdx = InputAssocationList.Count(); + InputAssocationList << ButtonSetting(ButtonId); + } + + ButtonSetting &CurIT = InputAssocationList[ITIdx]; + + int ASIdx = CurIT.GetActionSettingIdx(ActionId); + if (ASIdx == -1) + { + ASIdx = CurIT.AssociatedActionList.Count(); + CurIT.AssociatedActionList << ActionSetting(ActionId); + } +} + +//Helps unlink a software input Action-Id to an hardware input Button-Id. +void Input::UnlinkActionId(int ActionId) +{ + for (int i = 0; i < InputAssocationList.Count(); i++) + { + ButtonSetting &CurIT = InputAssocationList[i]; + int ASIdx = CurIT.GetActionSettingIdx(ActionId); + if (ASIdx != -1) + CurIT.AssociatedActionList.Remove(ASIdx); + } +} + +//Returns the current status of a given action +int Input::GetActionStatus(int ActionId) +{ + for (int i = 0; i < InputAssocationList.Count(); i++) + { + ButtonSetting &CurIT = InputAssocationList[i]; + int ASIdx = CurIT.GetActionSettingIdx(ActionId); + if (ASIdx != -1) + { + ActionSetting &CurAS = CurIT.AssociatedActionList[ASIdx]; + + if (CurAS.BufferingTime >= .0f && CurAS.BufferedSince <= CurAS.BufferingTime) + return 1; + return 0; + } + } + return 0; +} + +//Returns TRUE if action status when from Active to Inactive this frame +bool Input::WasActionJustReleased(int ActionId) +{ + for (int i = 0; i < InputAssocationList.Count(); i++) + { + ButtonSetting &CurIT = InputAssocationList[i]; + int ASIdx = CurIT.GetActionSettingIdx(ActionId); + if (ASIdx != -1) + { + if (!CurIT.CurStatus && CurIT.PrevStatus) + return TRUE; + return FALSE; + } + } + return FALSE; +} + +//-- void Input::TrackMouse(WorldEntity *e) { if (data->nentities >= InputData::MAX_ENTITIES) diff --git a/src/input/input.h b/src/input/input.h index 79b879db..fc036136 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -24,15 +24,146 @@ namespace lol class WorldEntity; +//Partial Key reap-off of the SDLK enum +#define LOLK_UNKNOWN = 0; + +#define LOLK_RETURN = '\r'; +#define LOLK_ESCAPE = '\033'; +#define LOLK_BACKSPACE = '\b'; +#define LOLK_TAB = '\t'; +#define LOLK_SPACE = ' '; +#define LOLK_EXCLAIM = '!'; +#define LOLK_QUOTEDBL = '"'; +#define LOLK_HASH = '#'; +#define LOLK_PERCENT = '%'; +#define LOLK_DOLLAR = '$'; +#define LOLK_AMPERSAND = '&'; +#define LOLK_QUOTE = '\''; +#define LOLK_LEFTPAREN = '('; +#define LOLK_RIGHTPAREN = ')'; +#define LOLK_ASTERISK = '*'; +#define LOLK_PLUS = '+'; +#define LOLK_COMMA = ';'; +#define LOLK_MINUS = '-'; +#define LOLK_PERIOD = '.'; +#define LOLK_SLASH = '/'; +#define LOLK_0 = '0'; +#define LOLK_1 = '1'; +#define LOLK_2 = '2'; +#define LOLK_3 = '3'; +#define LOLK_4 = '4'; +#define LOLK_5 = '5'; +#define LOLK_6 = '6'; +#define LOLK_7 = '7'; +#define LOLK_8 = '8'; +#define LOLK_9 = '9'; +#define LOLK_COLON = ':'; +#define LOLK_SEMICOLON = ';'; +#define LOLK_LESS = '<'; +#define LOLK_EQUALS = '='; +#define LOLK_GREATER = '>'; +#define LOLK_QUESTION = '?'; +#define LOLK_AT = '@'; +/* + Skip uppercase letters + */ +#define LOLK_LEFTBRACKET = '['; +#define LOLK_BACKSLASH = '\\'; +#define LOLK_RIGHTBRACKET = ']'; +#define LOLK_CARET = '^'; +#define LOLK_UNDERSCORE = '_'; +#define LOLK_BACKQUOTE = '`'; +#define LOLK_a = 'a'; +#define LOLK_b = 'b'; +#define LOLK_c = 'c'; +#define LOLK_d = 'd'; +#define LOLK_e = 'e'; +#define LOLK_f = 'f'; +#define LOLK_g = 'g'; +#define LOLK_h = 'h'; +#define LOLK_i = 'i'; +#define LOLK_j = 'j'; +#define LOLK_k = 'k'; +#define LOLK_l = 'l'; +#define LOLK_m = 'm'; +#define LOLK_n = 'n'; +#define LOLK_o = 'o'; +#define LOLK_p = 'p'; +#define LOLK_q = 'q'; +#define LOLK_r = 'r'; +#define LOLK_s = 's'; +#define LOLK_t = 't'; +#define LOLK_u = 'u'; +#define LOLK_v = 'v'; +#define LOLK_w = 'w'; +#define LOLK_x = 'x'; +#define LOLK_y = 'y'; +#define LOLK_z = 'z'; + +struct ActionSetting +{ + int ActionId; + float BufferingTime; + float BufferedSince; + + ActionSetting(int NewActionId) + { + memset(this, 0, sizeof(ActionSetting)); + ActionId = NewActionId; + } +}; + +struct ButtonSetting +{ + int RawButtonId; + int CurStatus; + int PrevStatus; + Array AssociatedActionList; + + ButtonSetting(int NewRawButtonId) + { + memset(this, 0, sizeof(ButtonSetting)); + RawButtonId = NewRawButtonId; + } + int GetActionSettingIdx(int ActionId) + { + for (int i = 0; i < AssociatedActionList.Count(); i++) + if (AssociatedActionList[i].ActionId == ActionId) + return i; + return -1; + } +}; + class Input { +private: + static Array InputAssocationList; + + static int GetButtonSettingIdx(int ButtonId) + { + for (int i = 0; i < InputAssocationList.Count(); i++) + if (InputAssocationList[i].RawButtonId == ButtonId) + return i; + return -1; + } + + static void UpdateActionStatus(float seconds); + public: + /* These methods are general queries */ static ivec2 GetMousePos(); static ivec3 GetMouseButtons(); - //BH : Added this, is a v0.1 Alpha version. + + //BH : Shouldn't use this static int GetButtonState(int button); + //Action management + static void LinkActionIdToButtonId(int ActionId, int ButtonId); + static void UnlinkActionId(int ActionId); + static int GetActionStatus(int ActionId); + static bool WasActionJustReleased(int ActionId); + /* Entities can subscribe to events */ static void TrackMouse(WorldEntity *e); static void UntrackMouse(WorldEntity *e); diff --git a/test/Physics/Src/EasyPhysics.cpp b/test/Physics/Src/EasyPhysics.cpp index 077a048a..0ac4c33e 100644 --- a/test/Physics/Src/EasyPhysics.cpp +++ b/test/Physics/Src/EasyPhysics.cpp @@ -156,6 +156,7 @@ void EasyPhysic::InitBodyToRigid(bool SetToKinematic) btRigidBody::btRigidBodyConstructionInfo NewInfos(m_mass, m_motion_state, m_collision_shape, m_local_inertia); m_rigid_body = new btRigidBody(NewInfos); m_collision_object = m_rigid_body; + m_collision_object->setUserPointer(this); if (m_mass == .0f) { @@ -184,12 +185,53 @@ void EasyPhysic::InitBodyToGhost() m_ghost_object = GetGhostObject(); m_ghost_object->setCollisionShape(m_collision_shape); m_collision_object = m_ghost_object; + m_collision_object->setUserPointer(this); SetTransform(m_local_to_world.v3.xyz, lol::quat(m_local_to_world)); m_ghost_object->setCollisionFlags(m_ghost_object->getCollisionFlags()); } +//------------- +//Touch logic +//------------- + // btManifoldArray manifoldArray; + // btBroadphasePairArray& pairArray = ghostObject->getOverlappingPairCache()->getOverlappingPairArray(); + // int numPairs = pairArray.size(); + + // for (int i=0;igetPairCache()->findPair(pair.m_pProxy0,pair.m_pProxy1); + // if (!collisionPair) + // continue; + + // if (collisionPair->m_algorithm) + // collisionPair->m_algorithm->getAllContactManifolds(manifoldArray); + + // for (int j=0;jgetBody0() == m_ghostObject ? btScalar(-1.0) : btScalar(1.0); + // for (int p=0;pgetNumContacts();p++) + // { + // const btManifoldPoint&pt = manifold->getContactPoint(p); + // if (pt.getDistance()<0.f) + //{ + // const btVector3& ptA = pt.getPositionWorldOnA(); + // const btVector3& ptB = pt.getPositionWorldOnB(); + // const btVector3& normalOnB = pt.m_normalWorldOnB; + // /// work here + //} + // } + // } + // } + + //Add Physic object to the simulation void EasyPhysic::AddToSimulation(class Simulation* current_simulation) {