Changeset 2810


Ignore:
Timestamp:
Jul 23, 2013, 5:42:32 PM (4 years ago)
Author:
benlitz
Message:

Completely reworked input system. Unified device interface, button, axis and cursor support, controller and binding system, mouse capture. Tutorial 07_input provided. Require to compile lolcore with LOL_INPUT_V2 to be activated (also needed app-side before including core.h)

Location:
trunk
Files:
9 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/build/vs2010/Lol.sln

    r2804 r2810  
    152152EndProject
    153153Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lol.js", "Lol.js", "{F7D4A671-612F-4FF4-883F-2097697694B7}"
     154EndProject
     155Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "07_input", "..\..\demos\tutorial\07_input.vcxproj", "{572E5B9C-7E19-489C-BD8A-E8401CFBBC47}"
     156EndProject
     157Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "06_sprite", "..\..\demos\tutorial\06_sprite.vcxproj", "{E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}"
    154158EndProject
    155159Global
     
    942946                {AA376B9B-484B-4DC4-982F-6CFA645E441E}.Release|Xbox 360.Build.0 = Release|Xbox 360
    943947                {AA376B9B-484B-4DC4-982F-6CFA645E441E}.Release|Xbox 360.Deploy.0 = Release|Xbox 360
     948                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Debug|Any CPU.ActiveCfg = Debug|x64
     949                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
     950                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Debug|Mixed Platforms.Build.0 = Debug|Win32
     951                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Debug|ORBIS.ActiveCfg = Debug|x64
     952                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Debug|PS3.ActiveCfg = Debug|x64
     953                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Debug|Win32.ActiveCfg = Debug|Win32
     954                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Debug|Win32.Build.0 = Debug|Win32
     955                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Debug|x64.ActiveCfg = Debug|x64
     956                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Debug|x64.Build.0 = Debug|x64
     957                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Debug|Xbox 360.ActiveCfg = Debug|x64
     958                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Release|Any CPU.ActiveCfg = Release|x64
     959                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Release|Mixed Platforms.ActiveCfg = Release|Win32
     960                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Release|Mixed Platforms.Build.0 = Release|Win32
     961                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Release|ORBIS.ActiveCfg = Release|x64
     962                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Release|PS3.ActiveCfg = Release|x64
     963                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Release|Win32.ActiveCfg = Release|Win32
     964                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Release|Win32.Build.0 = Release|Win32
     965                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Release|x64.ActiveCfg = Release|x64
     966                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Release|x64.Build.0 = Release|x64
     967                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47}.Release|Xbox 360.ActiveCfg = Release|x64
     968                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Debug|Any CPU.ActiveCfg = Debug|x64
     969                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Debug|Mixed Platforms.ActiveCfg = Debug|x64
     970                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Debug|Mixed Platforms.Build.0 = Debug|x64
     971                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Debug|ORBIS.ActiveCfg = Debug|x64
     972                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Debug|PS3.ActiveCfg = Debug|x64
     973                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Debug|Win32.ActiveCfg = Debug|Win32
     974                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Debug|Win32.Build.0 = Debug|Win32
     975                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Debug|x64.ActiveCfg = Debug|x64
     976                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Debug|x64.Build.0 = Debug|x64
     977                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Debug|Xbox 360.ActiveCfg = Debug|x64
     978                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Release|Any CPU.ActiveCfg = Release|x64
     979                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Release|Mixed Platforms.ActiveCfg = Release|x64
     980                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Release|Mixed Platforms.Build.0 = Release|x64
     981                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Release|ORBIS.ActiveCfg = Release|x64
     982                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Release|PS3.ActiveCfg = Release|x64
     983                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Release|Win32.ActiveCfg = Release|Win32
     984                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Release|Win32.Build.0 = Release|Win32
     985                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Release|x64.ActiveCfg = Release|x64
     986                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Release|x64.Build.0 = Release|x64
     987                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}.Release|Xbox 360.ActiveCfg = Release|x64
    944988        EndGlobalSection
    945989        GlobalSection(SolutionProperties) = preSolution
     
    9661010                {EE203B88-44CF-4859-9D42-7A1F43FECB52} = {E0491194-35E3-4513-9D31-608EA3165ECF}
    9671011                {7CE9FE12-E4AB-4A22-90D4-2C15F0C30D4E} = {E0491194-35E3-4513-9D31-608EA3165ECF}
    968                 {B92ABADC-45BE-4CC5-B724-9426053123A1} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04}
     1012                {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} = {E5C5E320-C077-4362-9A3F-3920C6447601}
     1013                {F7D4A671-612F-4FF4-883F-2097697694B7} = {E5C5E320-C077-4362-9A3F-3920C6447601}
    9691014                {7B083DA2-FE08-4F6D-BFDD-195D5C2783EB} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04}
    9701015                {1C5B8702-290C-42DA-AA9E-671348F5B747} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04}
     
    9741019                {834852DB-EDB6-4FD0-BCF9-45CD01126962} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04}
    9751020                {6BF81B39-EDC2-4227-9982-C2D8ABEA95AF} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04}
     1021                {B92ABADC-45BE-4CC5-B724-9426053123A1} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04}
     1022                {572E5B9C-7E19-489C-BD8A-E8401CFBBC47} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04}
     1023                {E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF} = {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04}
    9761024                {32F3F8CF-D22E-45E4-BEB8-AD909E8C5515} = {33704AA4-F2B5-4138-A40D-E3E77F89ED46}
    9771025                {EE203B88-44CF-4859-9D42-7A5F40FECB52} = {8C77EAA8-1077-4EF7-AE53-97C6C60A3601}
     
    9871035                {58922993-9830-4A40-B462-0326342F69ED} = {9CC50C06-DF5E-41A7-AD90-04F05386E081}
    9881036                {FAF82AD2-D9F4-4694-9A01-103BC5B771B4} = {B583BBFF-BE97-4F4E-BA1E-1F978A31EAB0}
    989                 {E74CF679-CA2A-47E9-B1F4-3779D6AC6B04} = {E5C5E320-C077-4362-9A3F-3920C6447601}
    990                 {F7D4A671-612F-4FF4-883F-2097697694B7} = {E5C5E320-C077-4362-9A3F-3920C6447601}
    9911037                {AA376B9B-484B-4DC4-982F-6CFA645E441E} = {F7D4A671-612F-4FF4-883F-2097697694B7}
    9921038        EndGlobalSection
  • trunk/demos/tutorial/06_sprite.vcxproj

    r2788 r2810  
    1 <?xml version="1.0" encoding="utf-8"?>
     1<?xml version="1.0" encoding="utf-8"?>
    22<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    33  <ItemGroup Label="ProjectConfigurations">
     
    5050  </ItemGroup>
    5151  <PropertyGroup Label="Globals">
    52     <ProjectGuid>{1c5b8702-290c-42da-aa9e-671348f5b747}</ProjectGuid>
     52    <ProjectGuid>{E05E23A5-67DE-42B5-98A3-E63CCE0CC0AF}</ProjectGuid>
    5353    <ConfigurationType>Application</ConfigurationType>
    5454    <Keyword>Win32Proj</Keyword>
  • trunk/demos/tutorial/11_fractal.cpp

    r2675 r2810  
    121121        m_bbox[0] = m_position;
    122122        m_bbox[1] = ivec3(m_window_size, 0);
    123         Input::TrackMouse(this);
     123        //Input::TrackMouse(this);
    124124
    125125#if LOL_FEATURE_THREADS
     
    143143#endif
    144144
    145         Input::UntrackMouse(this);
     145        //Input::UntrackMouse(this);
    146146#if !defined __native_client__
    147147        Ticker::Unref(m_centertext);
     
    176176        rcmplx worldmouse = m_center + rcmplx(ScreenToWorldOffset(m_mousepos));
    177177
    178         uint32_t buttons = Input::GetMouseButtons();
     178                uint32_t buttons = 0;
     179        //uint32_t buttons = Input::GetMouseButtons();
    179180#if !defined __CELLOS_LV2__ && !defined _XBOX
    180181        if (buttons & 0x2)
  • trunk/demos/tutorial/Makefile.am

    r2660 r2810  
    3434endif
    3535
     3607_input_SOURCES = 07_input.cpp 07_input.lolfx
     3707_input_CPPFLAGS = $(AM_CPPFLAGS)
     3807_input_DEPENDENCIES = @LOL_DEPS@
     39
    364008_fbo_SOURCES = 08_fbo.cpp 08_fbo.lolfx
    374108_fbo_CPPFLAGS = $(AM_CPPFLAGS)
  • trunk/src/core.h

    r2762 r2810  
    130130#include "profiler.h"
    131131
     132// Input (v2)
     133#include "input/input.h"
     134#include "input/inputdevice.h"
     135#include "input/controller.h"
     136
    132137// Entities
    133138#include "entity.h"
  • trunk/src/input/input.cpp

    r2645 r2810  
    99//
    1010
     11#ifndef LOL_INPUT_V2
     12
    1113#if defined HAVE_CONFIG_H
    1214#   include "config.h"
     
    479481} /* namespace lol */
    480482
     483#endif // !LOL_INPUT_V2
  • trunk/src/input/input.h

    r2645 r2810  
    1616#if !defined __LOL_INPUT_INPUT_H__
    1717#define __LOL_INPUT_INPUT_H__
     18
     19#ifndef LOL_INPUT_V2
    1820
    1921#include <cstring>
     
    457459} /* namespace lol */
    458460
     461#endif // !LOL_INPUT_V2
     462
    459463#endif // __LOL_INPUT_INPUT_H__
    460464
  • trunk/src/input/keyboard.cpp

    r2216 r2810  
    88//   http://www.wtfpl.net/ for more details.
    99//
     10
     11#ifndef LOL_INPUT_V2
    1012
    1113#if defined HAVE_CONFIG_H
     
    6769} /* namespace lol */
    6870
     71#endif // !LOL_INPUT_V2
  • trunk/src/input/keyboard.h

    r2216 r2810  
    1616#if !defined __LOL_INPUT_KEYBOARD_H__
    1717#define __LOL_INPUT_KEYBOARD_H__
     18
     19#ifndef LOL_INPUT_V2
    1820
    1921#include "entity.h"
     
    4042} /* namespace lol */
    4143
     44#endif // !LOL_INPUT_V2
     45
    4246#endif // __LOL_INPUT_KEYBOARD_H__
    4347
  • trunk/src/input/stick.cpp

    r2183 r2810  
    88//   http://www.wtfpl.net/ for more details.
    99//
     10
     11#ifndef LOL_INPUT_V2
    1012
    1113#if defined HAVE_CONFIG_H
     
    108110} /* namespace lol */
    109111
     112#endif // !LOL_INPUT_V2
  • trunk/src/input/stick.h

    r2216 r2810  
    1616#if !defined __LOL_INPUT_STICK_H__
    1717#define __LOL_INPUT_STICK_H__
     18
     19#ifndef LOL_INPUT_V2
    1820
    1921#include "entity.h"
     
    4951} /* namespace lol */
    5052
     53#endif // !LOL_INPUT_V2
     54
    5155#endif // __LOL_INPUT_STICK_H__
    5256
  • trunk/src/lolcore.vcxproj

    r2785 r2810  
    145145    <ClCompile Include="image\color\cie1931.cpp" />
    146146    <ClCompile Include="image\image.cpp" />
     147    <ClCompile Include="input\controller.cpp" />
    147148    <ClCompile Include="input\input.cpp" />
     149    <ClCompile Include="input\inputdevice.cpp" />
    148150    <ClCompile Include="input\keyboard.cpp" />
    149151    <ClCompile Include="input\stick.cpp" />
     
    206208    <ClInclude Include="gradient.h" />
    207209    <ClInclude Include="image\image-private.h" />
     210    <ClInclude Include="input\controller.h" />
    208211    <ClInclude Include="input\input.h" />
     212    <ClInclude Include="input\inputdevice.h" />
     213    <ClInclude Include="input\inputdevice_internal.h" />
    209214    <ClInclude Include="input\keyboard.h" />
     215    <ClInclude Include="input\keys.h" />
    210216    <ClInclude Include="input\stick.h" />
    211217    <ClInclude Include="layer.h" />
  • trunk/src/lolcore.vcxproj.filters

    r2777 r2810  
    313313      <Filter>debug</Filter>
    314314    </ClCompile>
     315    <ClCompile Include="input\controller.cpp">
     316      <Filter>input</Filter>
     317    </ClCompile>
     318    <ClCompile Include="input\inputdevice.cpp">
     319      <Filter>input</Filter>
     320    </ClCompile>
    315321  </ItemGroup>
    316322  <ItemGroup>
     
    609615      <Filter>lol\image</Filter>
    610616    </ClInclude>
     617    <ClInclude Include="input\inputdevice.h">
     618      <Filter>input</Filter>
     619    </ClInclude>
     620    <ClInclude Include="input\keys.h">
     621      <Filter>input</Filter>
     622    </ClInclude>
     623    <ClInclude Include="input\inputdevice_internal.h">
     624      <Filter>input</Filter>
     625    </ClInclude>
     626    <ClInclude Include="input\controller.h">
     627      <Filter>input</Filter>
     628    </ClInclude>
    611629  </ItemGroup>
    612630  <ItemGroup>
  • trunk/src/platform/d3d9/d3d9input.cpp

    r2216 r2810  
    2121#include "d3d9input.h"
    2222
     23#ifdef LOL_INPUT_V2
     24#include "input/inputdevice_internal.h"
     25#endif // LOL_INPUT_V2
     26
    2327namespace lol
    2428{
     
    3438private:
    3539#if defined USE_XINPUT
     40#if defined LOL_INPUT_V2
     41    Array<int, InputDeviceInternal*> m_joysticks;
     42#else
    3643    Array<int, Stick *> m_joysticks;
    37 #endif
     44#endif // LOL_INPUT_V2
     45#endif // USE_XINPUT
    3846};
    3947
     
    5159        if (XInputGetState(i, &state) != ERROR_SUCCESS)
    5260            continue;
     61#if defined LOL_INPUT_V2
     62                // TODO: we can put more friendly name here, such as LeftAxisX, ButtonX...
     63                InputDeviceInternal* stick = new InputDeviceInternal(String::Printf("Joystick%d", i+1).C());
     64                for (int j = 0; j < 4; ++j)
     65                        stick->AddAxis(String::Printf("Axis%d", j+1).C());
     66                for (int j = 0; j < 16; ++j)
     67                        stick->AddKey(String::Printf("Button%d", j+1).C());
    5368
     69                m_data->m_joysticks.Push(i, stick);
     70#else
    5471        Stick *stick = Input::CreateStick();
    5572        stick->SetAxisCount(4);
    5673        stick->SetButtonCount(16);
    5774        m_data->m_joysticks.Push(i, stick);
     75#endif // LOL_INPUT_V2
    5876    }
    5977#endif
     
    6886    while (m_data->m_joysticks.Count())
    6987    {
    70         Input::DestroyStick(m_data->m_joysticks[0].m2);
    71         m_data->m_joysticks.Remove(0);
     88#if defined LOL_INPUT_V2
     89                delete m_data->m_joysticks[0].m2;
     90#else
     91                Input::DestroyStick(m_data->m_joysticks[0].m2);
     92#endif // LOL_INPUT_V2
     93                m_data->m_joysticks.Remove(0);
    7294    }
    7395#endif
     
    97119
    98120        for (int b = 0; b < 16; b++)
    99             m_data->m_joysticks[i].m2->SetButton(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1);
    100     }
     121#if defined LOL_INPUT_V2
     122                        m_data->m_joysticks[i].m2->SetKey(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1);
     123#else
     124                        m_data->m_joysticks[i].m2->SetButton(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1);
     125#endif // LOL_INPUT_V2
     126        }
    101127#endif
    102128}
  • trunk/src/platform/sdl/sdlapp.cpp

    r2770 r2810  
    6767    }
    6868
     69#   ifdef LOL_INPUT_V2
     70        const SDL_VideoInfo* vidinfo = SDL_GetVideoInfo();
     71        int screen_w = vidinfo->current_w;
     72        int screen_h = vidinfo->current_h;
     73#   endif
     74
    6975#   if defined USE_D3D9
    7076    SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 16, 0);
     
    7884    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    7985    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
     86#   ifdef LOL_INPUT_V2
     87        // TODO: when implementing fullscreen, be sure to overwrite screen_w and screen_h with the value of vidinfo after the call to SDL_SetVideoMode
     88#   endif
    8089    SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 0, SDL_OPENGL);
    8190#   endif
     
    101110#   endif
    102111
    103     new SdlInput();
     112#   ifdef LOL_INPUT_V2
     113    new SdlInput(video->w, video->h, screen_w, screen_h);
     114#   else
     115        new SdlInput();
     116#   endif
    104117#endif
    105118}
  • trunk/src/platform/sdl/sdlinput.cpp

    r2646 r2810  
    2424#include "sdlinput.h"
    2525
     26#ifdef LOL_INPUT_V2
     27#include "input/inputdevice_internal.h"
     28#endif // LOL_INPUT_V2
     29
    2630/* We force joystick polling because no events are received when
    2731 * there is no SDL display (eg. on the Raspberry Pi). */
     
    4347
    4448    static ivec2 GetMousePos();
     49    static void SetMousePos(ivec2 position);
     50
    4551#if USE_SDL
     52# ifdef LOL_INPUT_V2
     53    SdlInputData(int app_w, int app_h, int screen_w, int screen_h) :
     54        m_prevmouse(ivec2(0)),
     55        m_app_w((float)app_w),
     56        m_app_h((float)app_h),
     57        m_screen_w((float)screen_w),
     58        m_screen_h((float)screen_h)
     59    { }
     60
     61    Array<SDL_Joystick*, InputDeviceInternal*> m_joysticks;
     62    InputDeviceInternal* m_mouse;
     63    InputDeviceInternal* m_keyboard;
     64    ivec2 m_prevmouse;
     65    float m_app_w;
     66    float m_app_h;
     67    float m_screen_w;
     68    float m_screen_h;
     69    bool m_mousecapture;
     70# else
    4671    Array<SDL_Joystick *, Stick *> m_joysticks;
    47 #endif
     72# endif // LOL_INPUT_V2
     73#endif // USE_SDL
    4874};
    4975
     
    5278 */
    5379
     80#ifdef LOL_INPUT_V2
     81SdlInput::SdlInput(int app_w, int app_h, int screen_w, int screen_h)
     82  : m_data(new SdlInputData(app_w, app_h, screen_w, screen_h))
     83#else
    5484SdlInput::SdlInput()
    5585  : m_data(new SdlInputData())
     86#endif
    5687{
    5788#if USE_SDL
     
    6798    SDL_JoystickEventState(SDL_ENABLE);
    6899#       endif
     100
     101#ifdef LOL_INPUT_V2
     102    m_data->m_keyboard = InputDeviceInternal::CreateStandardKeyboard();
     103    m_data->m_mouse = InputDeviceInternal::CreateStandardMouse();
     104#endif
    69105
    70106    /* Register all the joysticks we can find, and let the input
     
    89125        }
    90126
     127#       ifdef LOL_INPUT_V2
     128        InputDeviceInternal* stick = new InputDeviceInternal(String::Printf("Joystick%d", i+1).C());
     129        for (int i = 0; i < SDL_JoystickNumAxes(sdlstick); ++i)
     130            stick->AddAxis(String::Printf("Axis%d", i+1).C());
     131        for (int i = 0; i < SDL_JoystickNumButtons(sdlstick); ++i)
     132            stick->AddKey(String::Printf("Button%d", i+1).C());
     133
     134        m_data->m_joysticks.Push(sdlstick, stick);
     135#       else // !LOL_INPUT_V2
    91136        Stick *stick = Input::CreateStick();
    92137        stick->SetAxisCount(SDL_JoystickNumAxes(sdlstick));
     
    98143
    99144        m_data->m_joysticks.Push(sdlstick, stick);
     145#       endif
    100146    }
    101147#   endif
     
    112158    {
    113159        SDL_JoystickClose(m_data->m_joysticks[0].m1);
     160#       ifdef LOL_INPUT_V2
     161        delete m_data->m_joysticks[0].m2;
     162#       else
    114163        Input::DestroyStick(m_data->m_joysticks[0].m2);
     164#       endif
    115165        m_data->m_joysticks.Remove(0);
    116166    }
     
    140190{
    141191#if USE_SDL
    142     /* Handle mouse input */
    143     ivec2 mouse = SdlInputData::GetMousePos();;
    144     Input::SetMousePos(mouse);
    145 
    146192    /* Pump all joystick events because no event is coming to us. */
    147193#   if SDL_FORCE_POLL_JOYSTICK && !EMSCRIPTEN
     
    149195    for (int j = 0; j < m_joysticks.Count(); j++)
    150196    {
     197#       ifdef LOL_INPUT_V2
     198        for (int i = 0; i < SDL_JoystickNumButtons(m_joysticks[j].m1); i++)
     199            m_joysticks[j].m2->SetKey(i, SDL_JoystickGetButton(m_joysticks[j].m1, i) != 0);
     200        for (int i = 0; i < SDL_JoystickNumAxes(m_joysticks[j].m1); i++)
     201            m_joysticks[j].m2->SetAxis(i, (float)SDL_JoystickGetAxis(m_joysticks[j].m1, i) / 32768.f);
     202#       else // !LOL_INPUT_V2
    151203        for (int i = 0; i < SDL_JoystickNumButtons(m_joysticks[j].m1); i++)
    152204            m_joysticks[j].m2->SetButton(i, SDL_JoystickGetButton(m_joysticks[j].m1, i));
    153205        for (int i = 0; i < SDL_JoystickNumAxes(m_joysticks[j].m1); i++)
    154206            m_joysticks[j].m2->SetAxis(i, (float)SDL_JoystickGetAxis(m_joysticks[j].m1, i) / 32768.f);
     207
     208#       endif
    155209    }
    156210#   endif
     
    174228        case SDL_MOUSEBUTTONUP:
    175229        {
    176             ivec2 newmouse = SdlInputData::GetMousePos();
    177             if (newmouse != mouse)
    178                 Input::SetMousePos(mouse = newmouse);
     230#ifdef LOL_INPUT_V2
     231            m_mouse->SetKey(event.button.button - 1, event.type == SDL_MOUSEBUTTONDOWN);
     232#else // !LOL_INPUT_V2
    179233            if (event.type == SDL_MOUSEBUTTONDOWN)
    180234                Input::SetMouseButton(event.button.button - 1);
    181235            else
    182236                Input::UnsetMouseButton(event.button.button - 1);
     237#endif // LOL_INPUT_V2
    183238            break;
    184239        }
    185240
    186241#   if !SDL_FORCE_POLL_JOYSTICK
     242#        ifdef LOL_INPUT_V2
     243        case SDL_JOYAXISMOTION:
     244            m_joysticks[event.jaxis.which].m2->SetAxis(event.jaxis.axis, (float)event.jaxis.value / 32768.f);
     245            break;
     246
     247        case SDL_JOYBUTTONUP:
     248        case SDL_JOYBUTTONDOWN:
     249            m_joysticks[event.jbutton.which].m2->SetKey(event.jbutton.button, event.jbutton.state);
     250            break;
     251#        else // !LOL_INPUT_V2
    187252        case SDL_JOYAXISMOTION:
    188253            m_joysticks[event.jaxis.which].m2->SetAxis(event.jaxis.axis, (float)event.jaxis.value / 32768.f);
     
    193258            m_joysticks[event.jbutton.which].m2->SetButton(event.jbutton.button, event.jbutton.state);
    194259            break;
     260#        endif // LOL_INPUT_V2
    195261#   endif
    196262        }
    197263    }
    198264
    199     /* Send the whole keyboard state to the input system */
    200     Array<uint8_t> &lolstate = Input::GetKeyboardState();
     265    /* Handle mouse input */
     266    ivec2 mouse = SdlInputData::GetMousePos();
     267#   ifdef LOL_INPUT_V2
     268    if (InputDeviceInternal::GetMouseCapture() != m_mousecapture)
     269    {
     270        m_mousecapture = InputDeviceInternal::GetMouseCapture();
     271        SDL_WM_GrabInput(m_mousecapture ? SDL_GRAB_ON : SDL_GRAB_OFF);
     272        //SDL_ShowCursor(m_mousecapture ? SDL_DISABLE : SDL_ENABLE);
     273    }
     274
     275    if (mouse.x >= 0 && mouse.x < m_app_w && mouse.y >= 0 && mouse.y < m_app_h)
     276    {
     277        m_mouse->SetCursor(0, vec2((float)(mouse.x) / m_app_w, (float)(mouse.y) / m_app_h), mouse);
     278        // Note: 100.0f is an arbitrary value that makes it feel about the same than an xbox controller joystick
     279        m_mouse->SetAxis(0, (float)(mouse.x - m_prevmouse.x) * 100.0f / m_screen_w);
     280        m_mouse->SetAxis(1, (float)(mouse.y - m_prevmouse.y) * 100.0f / m_screen_h);
     281    }
     282
     283    if (m_mousecapture)
     284    {
     285        mouse = ivec2((int)m_app_w / 2, (int)m_app_h / 2);
     286        SdlInputData::SetMousePos(mouse);
     287    }
     288
     289    m_prevmouse = mouse;
     290
     291#   else // !LOL_INPUT_V2
     292    Input::SetMousePos(mouse);
     293#       endif // LOL_INPUT_V2
    201294
    202295#   if SDL_VERSION_ATLEAST(1,3,0)
     
    205298    Uint8 *sdlstate = SDL_GetKeyState(nullptr);
    206299#   endif
     300
     301    int keyindex = 0;
     302#       ifdef LOL_INPUT_V2
     303#       define KEY_FUNC(name, index) m_keyboard->SetKey(keyindex++, sdlstate[index] != 0);
     304#       if !defined SDLK_WORLD_0
     305#        define KEY_DISABLE_WORLD
     306#   endif // !SDLK_WORLD_0
     307#       include "input/keys.h"
     308#       undef KEY_FUNC
     309#       else // !LOL_INPUT_V2
     310
     311    /* Send the whole keyboard state to the input system */
     312    Array<uint8_t> &lolstate = Input::GetKeyboardState();
    207313
    208314    lolstate[Key::Unknown] = sdlstate[SDLK_UNKNOWN];
     
    377483    lolstate[Key::World94] = sdlstate[SDLK_WORLD_94];
    378484    lolstate[Key::World95] = sdlstate[SDLK_WORLD_95];
    379 #endif
     485#endif // SDLK_WORLD_0
    380486
    381487    lolstate[Key::KP0] = sdlstate[SDLK_KP0];
     
    449555
    450556    UNUSED(seconds);
    451 #endif
     557#       endif // LOL_INPUT_V2
     558
     559#endif // USE_SDL
    452560}
    453561
     
    468576}
    469577
     578void SdlInputData::SetMousePos(ivec2 position)
     579{
     580    SDL_WarpMouse((uint16_t)position.x, (uint16_t)position.y);
     581}
     582
    470583} /* namespace lol */
    471584
  • trunk/src/platform/sdl/sdlinput.h

    r2216 r2810  
    2727{
    2828public:
     29#ifdef LOL_INPUT_V2
     30    /** passing the screen resolution (note: not the windowed app resolution!) allows to make the mouse axis resolution-independent */
     31    SdlInput(int app_w, int app_h, int screen_w, int screen_h);
     32#else
    2933    SdlInput();
     34#endif
    3035    virtual ~SdlInput();
     36    void SetScreenResolution();
    3137
    3238protected:
Note: See TracChangeset for help on using the changeset viewer.