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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#include "Headers/InputInterface.h"
#include "Core/Headers/ParamHandler.h"
EffectManager::EffectManager(JoystickInterface* pJoystickInterface, U32 nUpdateFreq) : _pJoystickInterface(pJoystickInterface),
                                                                                       _nUpdateFreq(nUpdateFreq),
                                                                                       _nCurrEffectInd(-1)
{
    OIS::Effect* pEffect;
    MapVariables mapVars;
    OIS::ConstantEffect* pConstForce;
    OIS::PeriodicEffect* pPeriodForce;

    pEffect = new OIS::Effect(OIS::Effect::ConstantForce, OIS::Effect::Constant);
    pEffect->direction = OIS::Effect::North;
    pEffect->trigger_button = 0;
    pEffect->trigger_interval = 0;
    pEffect->replay_length = OIS::Effect::OIS_INFINITE; // Linux/Win32: Same behaviour as 0.
    pEffect->replay_delay = 0;
    pEffect->setNumAxes(1);
    pConstForce = dynamic_cast<OIS::ConstantEffect*>(pEffect->getForceEffect());
    pConstForce->level = 5000;  //-10K to +10k
    pConstForce->envelope.attackLength = 0;
    pConstForce->envelope.attackLevel = (unsigned short)pConstForce->level;
    pConstForce->envelope.fadeLength = 0;
    pConstForce->envelope.fadeLevel = (unsigned short)pConstForce->level;

    mapVars.clear();
    mapVars["Force"] =
        new TriangleVariable(0.0, // F0
        4 * 10000 / _nUpdateFreq / 20.0, // dF for a 20s-period triangle
        -10000.0, // Fmin
        10000.0); // Fmax
    mapVars["AttackFactor"] = new Constant(1.0);

    _vecEffects.push_back(new VariableEffect("Constant force on 1 axis with 20s-period triangle oscillations "
        "of its signed amplitude in [-10K, +10K]",
        pEffect, mapVars, forceVariableApplier));

    pEffect = new OIS::Effect(OIS::Effect::ConstantForce, OIS::Effect::Constant);
    pEffect->direction = OIS::Effect::North;
    pEffect->trigger_button = 0;
    pEffect->trigger_interval = 0;
    pEffect->replay_length = OIS::Effect::OIS_INFINITE; //(U32)(1000000.0/_nUpdateFreq); // Linux: Does not work.
    pEffect->replay_delay = 0;
    pEffect->setNumAxes(1);
    pConstForce = dynamic_cast<OIS::ConstantEffect*>(pEffect->getForceEffect());
    pConstForce->level = 5000;  //-10K to +10k
    pConstForce->envelope.attackLength = (U32)(1000000.0 / _nUpdateFreq / 2);
    pConstForce->envelope.attackLevel = (U16)(pConstForce->level*0.1);
    pConstForce->envelope.fadeLength = 0; // Never reached, actually.
    pConstForce->envelope.fadeLevel = (U16)pConstForce->level; // Idem

    mapVars.clear();
    mapVars["Force"] =
        new TriangleVariable(0.0, // F0
        4 * 10000 / _nUpdateFreq / 20.0, // dF for a 20s-period triangle
        -10000.0, // Fmin
        10000.0); // Fmax
    mapVars["AttackFactor"] = new Constant(0.1);

    _vecEffects.push_back(new VariableEffect("Constant force on 1 axis with noticeable attack (app update period / 2)"
        "and 20s-period triangle oscillations of its signed amplitude in [-10K, +10K]",
        pEffect, mapVars, forceVariableApplier));

    pEffect = new OIS::Effect(OIS::Effect::PeriodicForce, OIS::Effect::Triangle);
    pEffect->direction = OIS::Effect::North;
    pEffect->trigger_button = 0;
    pEffect->trigger_interval = 0;
    pEffect->replay_length = OIS::Effect::OIS_INFINITE;
    pEffect->replay_delay = 0;
    pEffect->setNumAxes(1);
    pPeriodForce = dynamic_cast<OIS::PeriodicEffect*>(pEffect->getForceEffect());
    pPeriodForce->magnitude = 10000;  // 0 to +10k
    pPeriodForce->offset = 0;
    pPeriodForce->phase = 0;  // 0 to 35599
    pPeriodForce->period = 10000;  // Micro-seconds
    pPeriodForce->envelope.attackLength = 0;
    pPeriodForce->envelope.attackLevel = (unsigned short)pPeriodForce->magnitude;
    pPeriodForce->envelope.fadeLength = 0;
    pPeriodForce->envelope.fadeLevel = (unsigned short)pPeriodForce->magnitude;

    mapVars.clear();
    mapVars["Period"] =
        new TriangleVariable(1 * 1000.0, // P0
        4 * (400 - 10)*1000.0 / _nUpdateFreq / 40.0, // dP for a 40s-period triangle
        10 * 1000.0, // Pmin
        400 * 1000.0); // Pmax
    _vecEffects.push_back(new VariableEffect("Periodic force on 1 axis with 40s-period triangle oscillations "
        "of its period in [10, 400] ms, and constant amplitude",
        pEffect, mapVars, periodVariableApplier));
}

EffectManager::~EffectManager()
{
    for (vectorImpl<VariableEffect*>::iterator iterEffs = _vecEffects.begin();
        iterEffs != _vecEffects.end();
        ++iterEffs)
        SAFE_DELETE(*iterEffs);
}

void EffectManager::updateActiveEffects() {

    for (vectorImpl<VariableEffect*>::iterator iterEffs = _vecEffects.begin();
        iterEffs != _vecEffects.end();
        ++iterEffs)
    if ((*iterEffs)->isActive()){
        (*iterEffs)->update();
        _pJoystickInterface->getCurrentFFDevice()->modify((*iterEffs)->getFFEffect());
    }
}

void EffectManager::checkPlayableEffects() {
    // Nothing to do if no joystick currently selected
    if (!_pJoystickInterface->getCurrentFFDevice()) return;

    // Get the list of indices of effects that the selected device can play
    _vecPlayableEffectInd.clear();
    for (size_t nEffInd = 0; nEffInd < _vecEffects.size(); ++nEffInd) {
        const OIS::Effect::EForce& eForce = _vecEffects[nEffInd]->getFFEffect()->force;
        const OIS::Effect::EType& eType = _vecEffects[nEffInd]->getFFEffect()->type;
        if (_pJoystickInterface->getCurrentFFDevice()->supportsEffect(eForce, eType))
            _vecPlayableEffectInd.push_back(nEffInd);
    }

    // Print details about playable effects
    if (_vecPlayableEffectInd.empty()) {
        D_ERROR_FN(Locale::get("INPUT_EFFECT_TEST_FAIL"));
    }
    else {
        PRINT_FN(Locale::get("INPUT_DEVICE_EFFECT_SUPPORT"));

        for (size_t nEffIndInd = 0; nEffIndInd < _vecPlayableEffectInd.size(); ++nEffIndInd)
            printEffect(_vecPlayableEffectInd[nEffIndInd]);

        PRINT_FN("");
    }
}

void EffectManager::selectEffect(EWhichEffect eWhich) {
    // Nothing to do if no joystick currently selected
    if (!_pJoystickInterface->getCurrentFFDevice()) {
        D_PRINT_FN(Locale::get("INPUT_NO_JOYSTICK_SELECTED"));
        return;
    }

    // Nothing to do if joystick cannot play any effect
    if (_vecPlayableEffectInd.empty()) {
        D_PRINT_FN(Locale::get("INPUT_NO_PLAYABLE_EFFECTS"));
        return;
    }

    // If no effect selected, and next or previous requested, select the first one.
    if (eWhich != eNone && _nCurrEffectInd < 0)
        _nCurrEffectInd = 0;
    // Otherwise, remove the current one from the device and then select the requested one if any.
    else if (_nCurrEffectInd >= 0) {
        _pJoystickInterface->getCurrentFFDevice()->remove(_vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect());
        _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->setActive(false);
        _nCurrEffectInd += eWhich;
        if (_nCurrEffectInd < -1 || _nCurrEffectInd >= (I16)_vecPlayableEffectInd.size())
            _nCurrEffectInd = -1;
    }

    // If no effect must be selected, reset the selection index
    if (eWhich == eNone)
        _nCurrEffectInd = -1;
    // Otherwise, upload the new selected effect to the device if any.
    else if (_nCurrEffectInd >= 0) {
        _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->setActive(true);
        _pJoystickInterface->getCurrentFFDevice()->upload(_vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect());
    }
}

U8 InputInterface::init(Kernel* const kernel, const std::string& 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<std::string>("appTitle").c_str());
    // Create OIS input manager
    pl.insert(std::make_pair(std::string("WINDOW"), Util::toString(hwnd)));
    pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
    pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
    pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND")));
    pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE")));
#elif defined OIS_LINUX_PLATFORM
    pl.insert(std::make_pair(std::string("x11_mouse_grab"), std::string("false")));
    pl.insert(std::make_pair(std::string("x11_mouse_hide"), std::string("false")));
    pl.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("false")));
    pl.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("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 = New EventHandler(this, kernel);
    DIVIDE_ASSERT(_pEventHdlr != nullptr, "InputInterface error: EventHandler allocation failed!");

    try{
        // Create a simple keyboard
        _pKeyboard = (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
    U32 numJoysticks = std::min(_pInputInterface->getNumberOfDevices(OIS::OISJoyStick), MAX_ALLOWED_JOYSTICKS);

    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 = New JoystickInterface(_pInputInterface, _pEventHdlr);
        if (!_pJoystickInterface->wasFFDetected())	{
            PRINT_FN(Locale::get("WARN_INPUT_NO_FORCE_FEEDBACK"));
            SAFE_DELETE(_pJoystickInterface);
        }
        else{
            // Create force feedback effect manager.
            _pEffectMgr = new EffectManager(_pJoystickInterface, _nEffectUpdateFreq);
            // Initialize the event handler.
            _pEventHdlr->initialize(_pJoystickInterface, _pEffectMgr);
        }
    }

    try{
        _pMouse = (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;
}

U8 InputInterface::update(const U64 deltaTime) {

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

    if (!_bIsInitialized)
        return _nStatus;

    if (_bMustStop){
        terminate();
        return 0;
    }

    try {
        // 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--;
            }
        }
    }
    catch (...) {}

    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();
            SAFE_DELETE(_pJoystickInterface);
        }

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

    SAFE_DELETE(_pEffectMgr);
    SAFE_DELETE(_pEventHdlr);

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

}

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

Diff revisions: vs.
Revision Author Commited Message
286 Diff Diff IonutCava picture IonutCava Fri 18 Jul, 2014 16:32:03 +0000

[Ionut] [[BR]]

    • very buggy commit ** [[BR]]

- New rendering pipeline: [[BR]]
— Bumped OpenGL version to 4.4 [[BR]]
— Command based rendering. GFXDevice dispatches rendering commands to their respective buffers [[BR]]
— State changing is exclusively controlled by the GFXDevice class [[BR]]
— Material properties and transform matrices are stored in shader storage buffers that are updated after culling and uploaded once per RenderPass. Objects use drawIDs to index data in shaders [[BR]]
— Removed all custom matrices and other, per shader, bind data [[BR]]
— Removed per node light data. Light culling and shader buffers will replace the old light management system [[BR]]
— Framebuffers now use the Texture class for attachments [[BR]]
— Sampler objects now work like RenderStateBlocks. GL_API handles them and stores them in a hash indexed map [[BR]]
— Removed “prepareMaterial” calls. Pre-draw material setup is now only limited to texture binding [[BR]]
— Moved immediate mode emulation and primitive rendering from API level to GFXDevice level [[BR]]
— Framebuffer rendering must be completed with a call to end() to ensure proper MSAA resolve (asserts, otherwise) [[BR]]
- Fixed hash code generation for RenderStateBlock (and now, glSamplerObject) using boost::hash_combine [[BR]]
- Temporarily disabled XML caching for materials [[BR]]

273 Diff Diff IonutCava picture IonutCava Wed 11 Jun, 2014 20:34:00 +0000

[Ionut] [[BR]]
- Improved batching part2: [[BR]]
— Moved all bone transformation matrices upload from uniform functions in SceneNode to Shader Storage Buffers in AnimationController class with updates controlled by SceneGraphNode’s AnimationComponent [[BR]]
-— No double-buffering or efficient mapping of data yet. Just raw buffer updates [[BR]]
— Replaced all RenderStateBlock* pointers with I64 hash values [[BR]]
-— Will be used later in draw commands as per-shader state hash [[BR]]
— Moved getShaderProgram from Material to Material::ShaderInfo [[BR]]
-— Improved redundant uniform checks [[BR]]
— Improved texture unit changing in case of redundant texture bind case (i.e. skip changing the texture unit) [[BR]]
[[BR]]
- Improved float and double comparison functions using algorithms described in http://randomascii.wordpress.com/2012/02/13/dont-store-that-in-a-float/ [[BR]]
- Added a new utility function, DIVIDE_ASSERT, to more easily bind an assert check with a specific message [[BR]]
- Added missing files from Forward+ renderer’s initial code [[BR]]

259 k1ngp1n picture k1ngp1n Sun 27 Apr, 2014 18:24:52 +0000

[Ionut][[BR]]
- Implemented Exponential Stable Cascaded Shadow Maps for directional lights (still buggy, but basically working) [[BR]]
— CSM settings (resolution, number of splits, etc) are part of the scene render state [[BR]]
- SGN can skip rendering for the current frame if they are not ready (e.g. OnDraw can now return false or materials can fail to bind) [[BR]]
- Frustum class is now using the Plane class [[BR]]
- Removed Math SIMD implementation as the compiler generated code will always be faster and safer [[BR]]
- Added a “STUBBED” macro for outputing to the error stream of important messages (instead of using #pragma message) [[BR]]
- Added “freeze time” logic to pause/resume updates with or without freezing the GUI too [[BR]]
- Added “processGUI” method the every Scene class to separate time-sensitive GUI updates from game logic loop [[BR]]
- GLSL <-> Vertex Buffer bind locations are automatically set for every vertex shader [[BR]]
- Added basic support for compute shaders [[BR]]
- Removed most OS define checks to make porting to a new platform easier [[BR]]
- Texture transparency check per-pixel is now using OpenMP [[BR]]
- Texture samplers can now set a border color for CLAMP_TO_BORDER wrap mode [[BR]]
- Removed “Object” suffix from GFX Classes (pixel buffer, vertex buffer, frame buffer, etc) [[BR]]
- Stop processing scene input when application looses focus [[BR]]
- SceneGraphNode class is now responsible for updating SGNComponents on draw and calling its _node’s OnDraw method [[BR]]
- UBOs can now list all of the active uniforms inside a block with info such as type and offset [[BR]]
- Removed deprecated ‘GLCheck’ macro [[BR]]
- A lot of bug fixes and performance improvements in various places [[BR]]