VPS
Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "Headers/InputInterface.h"
#include "Core/Headers/ParamHandler.h"

namespace Divide {
    namespace Input {

U8 InputInterface::init(Kernel* const kernel, const stringImpl& windowTitle) {
    if (_bIsInitialized) {
        return NO_ERR;
    }

    PRINT_FN(Locale::get("INPUT_CREATE_START"));

    OIS::ParamList pl;
#   if defined OIS_WIN32_PLATFORM
        U32 hwnd = (U32)FindWindow(nullptr, ParamHandler::getInstance().getParam<stringImpl>("appTitle", "Divide").c_str());
        // Create OIS input manager
        pl.insert(std::make_pair("WINDOW", stringAlg::fromBase(Util::toString(hwnd))));
        pl.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND"));
        pl.insert(std::make_pair("w32_mouse", "DISCL_NONEXCLUSIVE"));
        pl.insert(std::make_pair("w32_keyboard", "DISCL_FOREGROUND"));
        pl.insert(std::make_pair("w32_keyboard", "DISCL_NONEXCLUSIVE"));
#   elif defined OIS_LINUX_PLATFORM
        pl.insert(std::make_pair("x11_mouse_grab", "false"));
        pl.insert(std::make_pair("x11_mouse_hide", "false"));
        pl.insert(std::make_pair("x11_keyboard_grab", "false"));
        pl.insert(std::make_pair("XAutoRepeatOn", "true"));
#   endif

    _pInputInterface = OIS::InputManager::createInputSystem(pl);
    DIVIDE_ASSERT(_pInputInterface != nullptr, "InputInterface error: Could not create OIS Input Interface");

    PRINT_FN(Locale::get("INPUT_CREATE_OK"), _pInputInterface->inputSystemName().c_str());

    // Create the event handler.
    _pEventHdlr = MemoryManager_NEW EventHandler(this, kernel);
    DIVIDE_ASSERT(_pEventHdlr != nullptr, "InputInterface error: EventHandler allocation failed!");

    try {
        // Create a simple keyboard
        _pKeyboard = static_cast<OIS::Keyboard*>(_pInputInterface->createInputObject(OIS::OISKeyboard, true));
        _pKeyboard->setEventCallback(_pEventHdlr);
    } catch (OIS::Exception &ex) {
        PRINT_FN(Locale::get("ERROR_INPUT_CREATE_KB"), ex.eText);
    }

    // Limit max joysticks to MAX_ALLOWED_JOYSTICKS
    I32 numJoysticks = std::min(_pInputInterface->getNumberOfDevices(OIS::OISJoyStick), static_cast<I32>(Joystick_PLACEHOLDER));

    if (numJoysticks > 0) {
        _pJoysticks.resize(numJoysticks);
        try {
            for (vectorImpl<OIS::JoyStick* >::iterator it = _pJoysticks.begin(); it != _pJoysticks.end(); ++it) {
                (*it) = static_cast<OIS::JoyStick*>(_pInputInterface->createInputObject(OIS::OISJoyStick, true));
                (*it)->setEventCallback(_pEventHdlr);
            }
        } catch (OIS::Exception &ex) {
            PRINT_FN(Locale::get("ERROR_INPUT_CREATE_JOYSTICK"), ex.eText);
        }

        // Create the joystick manager.
        _pJoystickInterface = MemoryManager_NEW JoystickInterface(_pInputInterface, _pEventHdlr);
        if (!_pJoystickInterface->wasFFDetected())    {
            PRINT_FN(Locale::get("WARN_INPUT_NO_FORCE_FEEDBACK"));
            MemoryManager::DELETE( _pJoystickInterface );
        } else{
            // Create force feedback effect manager.
            _pEffectMgr = MemoryManager_NEW EffectManager(_pJoystickInterface, _nEffectUpdateFreq);
            // Initialize the event handler.
            _pEventHdlr->initialize(_pJoystickInterface, _pEffectMgr);
        }
    }

    try {
        _pMouse = static_cast<OIS::Mouse*>(_pInputInterface->createInputObject(OIS::OISMouse, true));
        _pMouse->setEventCallback(_pEventHdlr);
        const OIS::MouseState &ms = _pMouse->getMouseState(); //width and height are mutable
        ms.width = Application::getInstance().getResolution().width;
        ms.height = Application::getInstance().getResolution().height;
    } catch (OIS::Exception &ex) {
        PRINT_FN(Locale::get("ERROR_INPUT_CREATE_MOUSE"), ex.eText);
    }

    _bIsInitialized = true;

    return _nStatus;
}

void InputInterface::updateResolution(U16 w,U16 h) {
    if (!_bIsInitialized) {
        return;
    }
    // width and height are mutable
    const OIS::MouseState &ms = _pMouse->getMouseState(); 
    ms.width = w;
    ms.height = h;
}

U8 InputInterface::update(const U64 deltaTime) {

    const U8 nMaxEffectUpdateCnt = _nHartBeatFreq / _nEffectUpdateFreq;
    U8 nEffectUpdateCnt = 0;

    if (!_bIsInitialized) {
        return _nStatus;
    }
    if (_bMustStop) {
        terminate();
        return 0;
    }

    // This fires off buffered events for keyboards
    if (_pKeyboard != nullptr) {
        _pKeyboard->capture();
    }
    if (_pMouse != nullptr) {
        _pMouse->capture();
    }
    if (_pJoysticks.size() > 0) {
        for (vectorImpl<OIS::JoyStick* >::iterator it = _pJoysticks.begin(); it != _pJoysticks.end(); ++it) {
            (*it)->capture();
        }

        // This fires off buffered events for each joystick we have
        if (_pJoystickInterface != nullptr)  {
            _pJoystickInterface->captureEvents();
            // Update currently selected effects if time has come to.
            if (!nEffectUpdateCnt) {
                _pEffectMgr->updateActiveEffects();
                nEffectUpdateCnt = nMaxEffectUpdateCnt;
            } else {
                nEffectUpdateCnt--;
            }
        }
    }

    return _nStatus;
}

void InputInterface::terminate() {
    if (_pInputInterface) {
        _pInputInterface->destroyInputObject(_pKeyboard);
        _pKeyboard = nullptr;

        _pInputInterface->destroyInputObject(_pMouse);    
        _pMouse = nullptr;

        if (_pJoysticks.size() > 0) {
            for (vectorImpl<OIS::JoyStick* >::iterator it = _pJoysticks.begin(); it != _pJoysticks.end(); ++it) {
                _pInputInterface->destroyInputObject(*it);
            }
            _pJoysticks.clear();
            MemoryManager::DELETE( _pJoystickInterface );
        }

        OIS::InputManager::destroyInputSystem(_pInputInterface);
        _pInputInterface = nullptr;
    }

    MemoryManager::DELETE( _pEffectMgr );
    MemoryManager::DELETE( _pEventHdlr );

#if defined OIS_LINUX_PLATFORM
    // Be nice to X and clean up the x window
    XDestroyWindow(_pXDisp, _xWin);
    XCloseDisplay(_pXDisp);
#endif
}

    }; //namespace Input
}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Platform/Input/InputInterface.cpp

Diff revisions: vs.
Revision Author Commited Message
337 Diff Diff IonutCava picture IonutCava Wed 17 Dec, 2014 17:25:16 +0000

[Ionut]
- Replaced all tabs with 4 spaces (some spacing may be off now. no way to check all the files.)
- Moved implementation details for ParamHandler, BoundingBox, BoundingSphere and ProfileTimer to proper .inl and .cpp files. (more to follow)
- Update all forward declared enums with the required storage type (as requested by the C++11 standard)

334 IonutCava picture IonutCava Wed 10 Dec, 2014 17:21:22 +0000

[Ionut]
- Reorganized the Hardware project and renamed to "Platform"
- Reorganized the Server project