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
#include "Headers/Scene.h"

#include "Core/Headers/ParamHandler.h"
#include "Rendering/PostFX/Headers/PostFX.h"
#include "Managers/Headers/SceneManager.h"

namespace Divide {

void Scene::onLostFocus() {
   state().resetMovement();
#ifndef _DEBUG
   _paramHandler.setParam("freezeLoopTime", true);
#endif
}

namespace {
    struct selectionQueueDistanceFrontToBack {
        selectionQueueDistanceFrontToBack(const vec3<F32>& eyePos) : _eyePos(eyePos) {}

        bool operator()(SceneGraphNode* const a, SceneGraphNode* const b) const {
            F32 dist_a = a->getBoundingBoxConst().nearestDistanceFromPointSquared(_eyePos);
            F32 dist_b = b->getBoundingBoxConst().nearestDistanceFromPointSquared(_eyePos);
            return dist_a > dist_b;
        }
    private:
        vec3<F32> _eyePos;
    };
    static vectorImpl<SceneGraphNode* > _sceneSelectionCandidates;
}

void Scene::findSelection(F32 mouseX, F32 mouseY) {
    mouseY = renderState().cachedResolution().height - mouseY - 1;
    vec3<F32> startRay = renderState().getCameraConst().unProject(vec3<F32>(mouseX, mouseY, 0.0f));
    vec3<F32> endRay   = renderState().getCameraConst().unProject(vec3<F32>(mouseX, mouseY, 1.0f));
    const vec2<F32>& zPlanes = renderState().getCameraConst().getZPlanes();

    // deselect old node
    if (_currentSelection) {
        _currentSelection->setSelected(false);
    }

    _currentSelection = nullptr;

    // see if we select another one
    _sceneSelectionCandidates.clear();
    // Cast the picking ray and find items between the nearPlane (with an offset) and limit the range to half of the far plane
    _sceneGraph->Intersect(Ray(startRay, startRay.direction(endRay)), 
                           zPlanes.x + 0.5f, 
                           zPlanes.y * 0.5f, 
                           _sceneSelectionCandidates); 

    if(!_sceneSelectionCandidates.empty()){
        std::sort(_sceneSelectionCandidates.begin(), _sceneSelectionCandidates.end(), 
                  selectionQueueDistanceFrontToBack(renderState().getCameraConst().getEye()));
        _currentSelection = _sceneSelectionCandidates[0];
        // set it's state to selected
        _currentSelection->setSelected(true);
#ifdef _DEBUG
        _lines[DEBUG_LINE_RAY_PICK].push_back(Line(startRay, endRay, vec4<U8>(0, 255, 0, 255)));
#endif
    }

    for(DELEGATE_CBK<>& cbk : _selectionChangeCallbacks) {
        cbk();
    }
}

bool Scene::mouseButtonPressed(const Input::MouseEvent& key, Input::MouseButton button){
    _mousePressed[button] = true;
    switch (button){
        default:       return false;

        case Input::MouseButton::MB_Left:    break;
        case Input::MouseButton::MB_Right:   break;
        case Input::MouseButton::MB_Middle:  break;
        case Input::MouseButton::MB_Button3: break;
        case Input::MouseButton::MB_Button4: break;
        case Input::MouseButton::MB_Button5: break;
        case Input::MouseButton::MB_Button6: break;
        case Input::MouseButton::MB_Button7: break;
    }
    return true;
}

bool Scene::mouseButtonReleased(const Input::MouseEvent& key, Input::MouseButton button){
    _mousePressed[button] = false;
    switch (button){
        default:       return false;

        case Input::MouseButton::MB_Left:    {
            findSelection(key.state.X.abs, key.state.Y.abs);
        }break;
        case Input::MouseButton::MB_Right:   {
            state()._angleLR = 0;
            state()._angleUD = 0;
        }break;
        case Input::MouseButton::MB_Middle:  break;
        case Input::MouseButton::MB_Button3: break;
        case Input::MouseButton::MB_Button4: break;
        case Input::MouseButton::MB_Button5: break;
        case Input::MouseButton::MB_Button6: break;
        case Input::MouseButton::MB_Button7: break;
    }
    return true;
}
  
bool Scene::mouseMoved(const Input::MouseEvent& key){ 
    state()._mouseXDelta = _previousMousePos.x - key.state.X.abs;
    state()._mouseYDelta = _previousMousePos.y - key.state.Y.abs;
    _previousMousePos.set(key.state.X.abs, key.state.Y.abs);
    if (_mousePressed[Input::MouseButton::MB_Right]) {
        state()._angleLR = -state()._mouseXDelta;
        state()._angleUD = -state()._mouseYDelta;
    }
    return true;
}

using namespace Input;
bool Scene::onKeyDown(const Input::KeyEvent& key){
    switch(key._key){
        default:  return false;
        case KeyCode::KC_END : {
            deleteSelection();  
        } break;
        case KeyCode::KC_ADD : {
            Camera& cam = renderState().getCamera();
            F32 currentCamMoveSpeedFactor = cam.getMoveSpeedFactor();
            if (currentCamMoveSpeedFactor < 50){
                cam.setMoveSpeedFactor( currentCamMoveSpeedFactor + 1.0f);
                cam.setTurnSpeedFactor( cam.getTurnSpeedFactor()  + 1.0f);
            }
        } break;
        case KeyCode::KC_SUBTRACT :    {
            Camera& cam = renderState().getCamera();
            F32 currentCamMoveSpeedFactor = cam.getMoveSpeedFactor();
            if (currentCamMoveSpeedFactor > 1.0f){
                cam.setMoveSpeedFactor( currentCamMoveSpeedFactor - 1.0f);
                cam.setTurnSpeedFactor( cam.getTurnSpeedFactor() - 1.0f);
            }
        } break;
        case KeyCode::KC_W: {
            state()._moveFB = 1;
        } break;
        case KeyCode::KC_S: {
            state()._moveFB = -1;
        } break;
        case KeyCode::KC_A: {
            state()._moveLR = -1;
        } break;
        case KeyCode::KC_D: {
            state()._moveLR = 1;
        } break;
        case KeyCode::KC_Q: {
            state()._roll = 1;
        } break;
        case KeyCode::KC_E: {
            state()._roll = -1;
        } break;
        case KeyCode::KC_RIGHT: {
            state()._angleLR = 1;
        }break;
        case KeyCode::KC_LEFT: {
            state()._angleLR = -1;
        } break;
        case KeyCode::KC_UP: {
            state()._angleUD = -1;
        } break;
        case KeyCode::KC_DOWN: {
            state()._angleUD = 1;
        } break;
    }
    return true;
}

bool Scene::onKeyUp(const Input::KeyEvent& key){
    switch( key._key ) {
        case KeyCode::KC_P: {
            _paramHandler.setParam("freezeLoopTime", 
                                   !_paramHandler.getParam("freezeLoopTime", false));
        } break;
        case KeyCode::KC_F2: {
            renderState().toggleSkeletons();
        } break;
        case KeyCode::KC_F3: {
            _paramHandler.setParam("postProcessing.enableDepthOfField", 
                                   !_paramHandler.getParam<bool>("postProcessing.enableDepthOfField"));
        } break;
        case KeyCode::KC_F4: {
            _paramHandler.setParam("postProcessing.enableBloom", 
                                   !_paramHandler.getParam<bool>("postProcessing.enableBloom"));
        } break;
        case KeyCode::KC_F5: {
            renderState().toggleAxisLines();
        } break;
        case KeyCode::KC_B: {
            renderState().toggleBoundingBoxes();
        } break;
        case KeyCode::KC_F8: {
            renderState().drawDebugLines(!renderState()._debugDrawLines);
        } break;
#        ifdef _DEBUG
            case KeyCode::KC_F9: {
                for (U8 i = 0; i < DEBUG_LINE_PLACEHOLDER; ++i) {
                    _lines[i].clear();
                }
            } break;
#        endif
        case KeyCode::KC_F10: {
            ParamHandler& param = ParamHandler::getInstance();
            LightManager::getInstance().togglePreviewShadowMaps();
            param.setParam<bool>("rendering.previewDepthBuffer", 
                                 !param.getParam<bool>("rendering.previewDepthBuffer", false));
        } break;
        case KeyCode::KC_F7: {
            GFX_DEVICE.Screenshot("screenshot_");
        } break;
        case KeyCode::KC_W: 
        case KeyCode::KC_S: {
            state()._moveFB = 0;
        } break;
        case KeyCode::KC_A: 
        case KeyCode::KC_D: {
            state()._moveLR = 0;
        } break;
        case KeyCode::KC_Q: 
        case KeyCode::KC_E: {
            state()._roll = 0;
        } break;
        case KeyCode::KC_RIGHT:
        case KeyCode::KC_LEFT: {
            state()._angleLR = 0;
        } break;
        case KeyCode::KC_UP: 
        case KeyCode::KC_DOWN: {
            state()._angleUD = 0;
        } break;
        default: return false;
    }
    return true;
}

static I32 axisDeadZone = 256;

bool Scene::joystickAxisMoved(const Input::JoystickEvent& key,I8 axis) {
    STUBBED("ToDo: Store input from multiple joysticks in scene state! - Ionut");
    if (key.device->getID() != Input::JOYSTICK_1) {
        return false;
    }
    I32 axisABS = key.state.mAxes[axis].abs;
    
    switch (axis) {
        case 0 : {
            if (axisABS > axisDeadZone) {
                state()._angleUD = 1;
            } else if (axisABS < -axisDeadZone) {
                state()._angleUD = -1;
            } else {
                state()._angleUD = 0;
            }
        } break;
        case 1 : {
            if (axisABS > axisDeadZone) {
                state()._angleLR = 1;
            } else if(axisABS < -axisDeadZone) {
                state()._angleLR = -1;
            } else {
                state()._angleLR = 0;
            }
        } break;
    
        case 2 : {
            if (axisABS < -axisDeadZone) {
                state()._moveFB = 1;
            } else if (axisABS > axisDeadZone) {
                state()._moveFB = -1;
            } else {
                state()._moveFB = 0;
            }
        } break;
        case 3 : {
            if (axisABS < -axisDeadZone) {
                state()._moveLR = -1;
            } else if(axisABS > axisDeadZone) {
                state()._moveLR = 1;
            } else {
                state()._moveLR = 0;
            }
        } break;
    }
    return true;
}

bool Scene::joystickPovMoved(const Input::JoystickEvent& key, I8 pov){
    if (key.state.mPOV[pov].direction & OIS::Pov::North) { //Going up
        state()._moveFB = 1;
    } else if (key.state.mPOV[pov].direction & OIS::Pov::South) {//Going down
        state()._moveFB = -1;
    } else if (key.state.mPOV[pov].direction & OIS::Pov::East) {//Going right
        state()._moveLR = 1;
    } else if (key.state.mPOV[pov].direction & OIS::Pov::West) {//Going left
        state()._moveLR = -1;
    } else /*if (key.state.mPOV[pov].direction == OIS::Pov::Centered)*/ { //stopped/centered out
        state()._moveLR = 0;
        state()._moveFB = 0;
    }
    return true;
}

};

Commits for Divide-Framework/trunk/Source Code/Scenes/SceneInput.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)

331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

323 Diff Diff IonutCava picture IonutCava Thu 11 Sep, 2014 20:58:50 +0000

[Ionut]
- Reworked GFXDevice API initialization system
- Added a separate map for boolean values in ParamHandler
- More cleanups in GFXDevice class
- Fixed an infinite loop issue in Task class

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

320 Diff Diff IonutCava picture IonutCava Sun 31 Aug, 2014 21:45:33 +0000

[Ionut]
- More AI work (entity captures flag and returns it to base)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

315 Diff Diff IonutCava picture IonutCava Mon 25 Aug, 2014 15:23:33 +0000

[Ionut]
- Update ReCast to the latest version available on GitHub
- Improved nav mesh target point selection
- Added basic “go to enemy flag” logic for the WarScene teams

314 Diff Diff IonutCava picture IonutCava Sun 24 Aug, 2014 19:54:33 +0000

[Ionut]
- More AI work
- Added some needed audio dlls

309 IonutCava picture IonutCava Sat 16 Aug, 2014 22:57:33 +0000

[Ionut]
- Added an InputAggregator interface to standardize input event handling