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

namespace Divide {
    namespace Input {

EffectManager::EffectManager(JoystickInterface* pJoystickInterface, U32 nUpdateFreq) : _pJoystickInterface(pJoystickInterface),
                                                                                       _nUpdateFreq(nUpdateFreq),
                                                                                       _nCurrEffectInd(-1)
{
    OIS::Effect* pEffect;
    MapVariables mapVars;
    OIS::ConstantEffect* pConstForce;
    OIS::PeriodicEffect* pPeriodForce;

    pEffect = MemoryManager_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"] =
        MemoryManager_NEW TriangleVariable(0.0, // F0
        4 * 10000 / _nUpdateFreq / 20.0, // dF for a 20s-period triangle
        -10000.0, // Fmin
        10000.0); // Fmax
    mapVars["AttackFactor"] = MemoryManager_NEW Constant(1.0);

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

    pEffect = MemoryManager_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"] =
        MemoryManager_NEW TriangleVariable(0.0, // F0
        4 * 10000 / _nUpdateFreq / 20.0, // dF for a 20s-period triangle
        -10000.0, // Fmin
        10000.0); // Fmax
    mapVars["AttackFactor"] = MemoryManager_NEW Constant(0.1);

    _vecEffects.push_back(MemoryManager_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 = MemoryManager_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"] =
        MemoryManager_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(MemoryManager_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()
{
    MemoryManager::DELETE_VECTOR(_vecEffects);
}

void EffectManager::updateActiveEffects() {
    vectorImpl<VariableEffect*>::iterator iterEffs;;
    for (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 (vectorAlg::vecSize 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"));

        vectorAlg::vecSize nEffIndInd = 0;
        for (; 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) {
        OIS::Effect* effect = _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect();
        _pJoystickInterface->getCurrentFFDevice()->remove(effect);

        _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);

        OIS::Effect* effect = _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect();
        _pJoystickInterface->getCurrentFFDevice()->upload(effect);
    }
}

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

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

Diff revisions: vs.
Revision Author Commited Message
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)

325 Diff Diff IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)

324 Diff Diff IonutCava picture IonutCava Sun 14 Sep, 2014 14:01:39 +0000

[Ionut]
- New memory management system (no custom allocators in this commit)
— Memory tracer to detect memory leaks on shutdown (from: https://www.relisoft.com/book/tech/9new.html)
— SAFE_DELETE_XYZ are now inline template functions not macros
— ASSERTION system now supports logging and message boxes and continue on error configurable for each build type
— Fixed a lot of memory leaks detected by the new system (some still remain)

- Added SRGB support (part 1)
— Albedo textures are loaded as SRGB (make sure resources are SRGB)
— Shaders output gamma corrected colors
— Moved terrain textures back to 2 array system (albedo and normal maps, albedo maps using a SRGB sampler)

- Sky is now loaded via the ResourceCache system
- Added include safeguards in shader atoms

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)

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)

303 IonutCava picture IonutCava Sat 09 Aug, 2014 19:12:32 +0000

[Ionut]
- Fixed mouse movement (change resolution callback properly informs inputInterface of the new window’s width and height)
- Fixed immediate mode emulation rendering (destroyed index buffers for some reason)
- Added axis gizmos for Scene / Scene + Selected Object / Scene + All object cycled via the F5 key in debug