From c1c9c1d2b2affd11b139aaa21ef23a141a8fce0e Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Tue, 19 Mar 2013 05:26:06 +0200 Subject: [PATCH] input.joyset: Preserve and invert user input --- manual.lyx | 14 +++++++++++++- manual.txt | 8 +++++++- src/lua/input.cpp | 20 ++++++++++++++------ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/manual.lyx b/manual.lyx index 2a59db8d..9ca31164 100644 --- a/manual.lyx +++ b/manual.lyx @@ -3185,6 +3185,18 @@ Set the the state of specified controller to values specified in specified table. \end_layout +\begin_layout Itemize +nil does not change value +\end_layout + +\begin_layout Itemize +true/false (buttons) and integers (axes) force value. +\end_layout + +\begin_layout Itemize +string (button) inverts the input. +\end_layout + \begin_layout Subsubsection input.lcid_to_pcid(number controller) \end_layout @@ -3464,7 +3476,7 @@ Count number of subframes in specified frame (frame numbers are 1-based) \end_layout \begin_layout Subsubsection -movie.read_subframe(number frame, number subframe) +movie.read_subframes(number frame, number subframe) \end_layout \begin_layout Standard diff --git a/manual.txt b/manual.txt index d59021a5..e673e6b5 100644 --- a/manual.txt +++ b/manual.txt @@ -1587,6 +1587,12 @@ names of fields vary by controller type. Set the the state of specified controller to values specified in specified table. +• nil does not change value + +• true/false (buttons) and integers (axes) force value. + +• string (button) inverts the input. + 8.4.17 input.lcid_to_pcid(number controller) Return the physical index, physical port and controller number in @@ -1737,7 +1743,7 @@ Set readwrite mode (does not cause on_readwrite callback). Count number of subframes in specified frame (frame numbers are 1-based) and return that. -8.7.7 movie.read_subframe(number frame, number subframe) +8.7.7 movie.read_subframes(number frame, number subframe) Read specifed subframe in specified frame and return data as array (100 elements, numbered 0-99 currently). diff --git a/src/lua/input.cpp b/src/lua/input.cpp index 48b37516..fdcbd682 100644 --- a/src/lua/input.cpp +++ b/src/lua/input.cpp @@ -174,20 +174,28 @@ namespace continue; lua_pushstring(LS, n.c_str()); lua_gettable(LS, 2); - int s = lua_toboolean(LS, -1) ? 1 : 0; - lua_input_controllerdata->axis(pcid, y, s); + if(lua_type(LS, -1) == LUA_TBOOLEAN) { + int s = lua_toboolean(LS, -1) ? 1 : 0; + lua_input_controllerdata->axis(pcid, y, s); + } else if(lua_type(LS, -1) == LUA_TSTRING) { + lua_input_controllerdata->axis(pcid, y, lua_input_controllerdata->axis(pcid, y) ^ 1); + } lua_pop(LS, 1); } if(lua_input_controllerdata->is_analog(pcid)) { lua_pushstring(LS, "xaxis"); lua_gettable(LS, 2); - int s = lua_tonumber(LS, -1); - lua_input_controllerdata->axis(pcid, 0, s); + if(lua_type(LS, -1) != LUA_TNIL) { + int s = lua_tonumber(LS, -1); + lua_input_controllerdata->axis(pcid, 0, s); + } lua_pop(LS, 1); lua_pushstring(LS, "yaxis"); lua_gettable(LS, 2); - s = lua_tonumber(LS, -1); - lua_input_controllerdata->axis(pcid, 1, s); + if(lua_type(LS, -1) != LUA_TNIL) { + int s = lua_tonumber(LS, -1); + lua_input_controllerdata->axis(pcid, 1, s); + } lua_pop(LS, 1); } return 0;