diff --git a/doc/angelscript/Script2Game/InputEngineClass.h b/doc/angelscript/Script2Game/InputEngineClass.h index 2ab87560e6..08a251d1a4 100644 --- a/doc/angelscript/Script2Game/InputEngineClass.h +++ b/doc/angelscript/Script2Game/InputEngineClass.h @@ -16,6 +16,12 @@ namespace Script2Game { class InputEngineClass { public: + + /** + * Set a permanent (you must also clear it!) override for an input event; Value can be between -1 and 1; Don't forget to reset back to 0! + */ + void setEventSimulatedValue(inputEvents ev, float val); + /** * @return full configuration string for given command, including the EXPL modifier. */ diff --git a/source/main/scripting/bindings/InputEngineAngelscript.cpp b/source/main/scripting/bindings/InputEngineAngelscript.cpp index 24a874440b..91ade986f4 100644 --- a/source/main/scripting/bindings/InputEngineAngelscript.cpp +++ b/source/main/scripting/bindings/InputEngineAngelscript.cpp @@ -34,7 +34,11 @@ void registerInputEngineObject(asIScriptEngine* engine) int result = 0; result = engine->RegisterObjectType("InputEngineClass", sizeof(InputEngine), asOBJ_REF | asOBJ_NOCOUNT); ROR_ASSERT(result>=0); + + // > Input processing + result = engine->RegisterObjectMethod("InputEngineClass", "void setEventSimulatedValue(inputEvents ev, float value)", asMETHOD(InputEngine,setEventSimulatedValue), asCALL_THISCALL); ROR_ASSERT(result>=0); + // > Event info result = engine->RegisterObjectMethod("InputEngineClass", "string getEventCommand(inputEvents ev)", asMETHOD(InputEngine,getEventCommand), asCALL_THISCALL); ROR_ASSERT(result>=0); result = engine->RegisterObjectMethod("InputEngineClass", "string getEventCommandTrimmed(inputEvents ev)", asMETHOD(InputEngine,getEventCommandTrimmed), asCALL_THISCALL); ROR_ASSERT(result>=0); @@ -42,6 +46,7 @@ void registerInputEngineObject(asIScriptEngine* engine) // result = engine->RegisterObjectMethod("InputEngineClass", "bool isKeyDown(int keycode)", asMETHOD(InputEngine,isKeyDown), asCALL_THISCALL); ROR_ASSERT(result>=0); // result = engine->RegisterObjectMethod("InputEngineClass", "bool isKeyDownEffective(int keycode)", asMETHOD(InputEngine,isKeyDownEffective), asCALL_THISCALL); ROR_ASSERT(result>=0); + // > Event states result = engine->RegisterObjectMethod("InputEngineClass", "bool getEventBoolValue(inputEvents ev)", asMETHOD(InputEngine,getEventBoolValue), asCALL_THISCALL); ROR_ASSERT(result>=0); result = engine->RegisterObjectMethod("InputEngineClass", "bool getEventBoolValueBounce(inputEvents ev, float time = 0.2f)", asMETHOD(InputEngine,getEventBoolValueBounce), asCALL_THISCALL); ROR_ASSERT(result>=0); } diff --git a/source/main/utils/InputEngine.cpp b/source/main/utils/InputEngine.cpp index 413769e493..b75285df05 100644 --- a/source/main/utils/InputEngine.cpp +++ b/source/main/utils/InputEngine.cpp @@ -697,6 +697,11 @@ void InputEngine::resetKeys() } } +void InputEngine::setEventSimulatedValue(RoR::events eventID, float value) +{ + event_values_simulated[eventID] = value; +} + bool InputEngine::getEventBoolValue(int eventID) { return (getEventValue(eventID) > 0.5f); @@ -900,6 +905,10 @@ bool InputEngine::isEventAnalog(int eventID) float InputEngine::getEventValue(int eventID, bool pure, InputSourceType valueSource /*= InputSourceType::IST_ANY*/) { + const float simulatedValue = event_values_simulated[eventID]; + if (simulatedValue != 0.f) + return simulatedValue; + float returnValue = 0; std::vector t_vec = events[eventID]; float value = 0; @@ -1174,6 +1183,12 @@ const char* InputEngine::getEventTypeName(eventtypes type) } void InputEngine::addEvent(int eventID, event_trigger_t& t) +{ + this->addEvent(eventID); + events[eventID].push_back(t); +} + +void InputEngine::addEvent(int eventID) { uniqueCounter++; @@ -1183,9 +1198,8 @@ void InputEngine::addEvent(int eventID, event_trigger_t& t) if (events.find(eventID) == events.end()) { events[eventID] = std::vector(); - events[eventID].clear(); + event_values_simulated[eventID] = false; } - events[eventID].push_back(t); } void InputEngine::addEventDefault(int eventID, int deviceID /*= -1*/) @@ -1495,7 +1509,7 @@ bool InputEngine::processLine(const char* line, int deviceID) if (eventID == -1) return false; // Insert event with no trigger - events.insert(std::make_pair(eventID, std::vector())); + addEvent(eventID); return true; } case ET_MouseButton: diff --git a/source/main/utils/InputEngine.h b/source/main/utils/InputEngine.h index 7ec14c463a..61b2a68a66 100644 --- a/source/main/utils/InputEngine.h +++ b/source/main/utils/InputEngine.h @@ -484,6 +484,7 @@ class InputEngine void ProcessKeyRelease(const OIS::KeyEvent& arg); void ProcessJoystickEvent(const OIS::JoyStickEvent& arg); void resetKeys(); + void setEventSimulatedValue(events eventID, float value); // Event info @@ -513,6 +514,7 @@ class InputEngine // Event management void addEvent(int eventID, event_trigger_t& t); //!< Registers new trigger for this event. + void addEvent(int eventID); //!< Registers new event without trigger. void addEventDefault(int eventID, int deviceID = -1); //!< Adds a new trigger with builtin value for this event. void updateEvent(int eventID, const event_trigger_t& t); void eraseEvent(int eventID, const event_trigger_t* t); @@ -573,6 +575,7 @@ class InputEngine // define event aliases std::map> events; + std::map event_values_simulated; std::map event_times; std::string m_loaded_configs[MAX_JOYSTICKS]; bool loadMapping(Ogre::String fileName, int deviceID);