Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 330 vs 331 for /trunk/Source Code/Hardware/Input/EffectManager.cpp

Diff revisions: vs.
  @@ -12,7 +12,7 @@
12 12 OIS::ConstantEffect* pConstForce;
13 13 OIS::PeriodicEffect* pPeriodForce;
14 14
15 - pEffect = New OIS::Effect(OIS::Effect::ConstantForce, OIS::Effect::Constant);
15 + pEffect = MemoryManager_NEW OIS::Effect(OIS::Effect::ConstantForce, OIS::Effect::Constant);
16 16 pEffect->direction = OIS::Effect::North;
17 17 pEffect->trigger_button = 0;
18 18 pEffect->trigger_interval = 0;
  @@ -28,17 +28,18 @@
28 28
29 29 mapVars.clear();
30 30 mapVars["Force"] =
31 - New TriangleVariable(0.0, // F0
31 + MemoryManager_NEW TriangleVariable(0.0, // F0
32 32 4 * 10000 / _nUpdateFreq / 20.0, // dF for a 20s-period triangle
33 33 -10000.0, // Fmin
34 34 10000.0); // Fmax
35 - mapVars["AttackFactor"] = New Constant(1.0);
35 + mapVars["AttackFactor"] = MemoryManager_NEW Constant(1.0);
36 36
37 - _vecEffects.push_back(New VariableEffect("Constant force on 1 axis with 20s-period triangle oscillations "
38 - "of its signed amplitude in [-10K, +10K]",
39 - pEffect, mapVars, forceVariableApplier));
37 + _vecEffects.push_back(MemoryManager_NEW
38 + VariableEffect("Constant force on 1 axis with 20s-period triangle oscillations "
39 + "of its signed amplitude in [-10K, +10K]",
40 + pEffect, mapVars, forceVariableApplier));
40 41
41 - pEffect = New OIS::Effect(OIS::Effect::ConstantForce, OIS::Effect::Constant);
42 + pEffect = MemoryManager_NEW OIS::Effect(OIS::Effect::ConstantForce, OIS::Effect::Constant);
42 43 pEffect->direction = OIS::Effect::North;
43 44 pEffect->trigger_button = 0;
44 45 pEffect->trigger_interval = 0;
  @@ -54,17 +55,18 @@
54 55
55 56 mapVars.clear();
56 57 mapVars["Force"] =
57 - New TriangleVariable(0.0, // F0
58 + MemoryManager_NEW TriangleVariable(0.0, // F0
58 59 4 * 10000 / _nUpdateFreq / 20.0, // dF for a 20s-period triangle
59 60 -10000.0, // Fmin
60 61 10000.0); // Fmax
61 - mapVars["AttackFactor"] = New Constant(0.1);
62 + mapVars["AttackFactor"] = MemoryManager_NEW Constant(0.1);
62 63
63 - _vecEffects.push_back(New VariableEffect("Constant force on 1 axis with noticeable attack (app update period / 2)"
64 - "and 20s-period triangle oscillations of its signed amplitude in [-10K, +10K]",
65 - pEffect, mapVars, forceVariableApplier));
64 + _vecEffects.push_back(MemoryManager_NEW
65 + VariableEffect("Constant force on 1 axis with noticeable attack (app update period / 2)"
66 + "and 20s-period triangle oscillations of its signed amplitude in [-10K, +10K]",
67 + pEffect, mapVars, forceVariableApplier));
66 68
67 - pEffect = New OIS::Effect(OIS::Effect::PeriodicForce, OIS::Effect::Triangle);
69 + pEffect = MemoryManager_NEW OIS::Effect(OIS::Effect::PeriodicForce, OIS::Effect::Triangle);
68 70 pEffect->direction = OIS::Effect::North;
69 71 pEffect->trigger_button = 0;
70 72 pEffect->trigger_interval = 0;
  @@ -83,55 +85,55 @@
83 85
84 86 mapVars.clear();
85 87 mapVars["Period"] =
86 - New TriangleVariable(1 * 1000.0, // P0
88 + MemoryManager_NEW TriangleVariable(1 * 1000.0, // P0
87 89 4 * (400 - 10)*1000.0 / _nUpdateFreq / 40.0, // dP for a 40s-period triangle
88 90 10 * 1000.0, // Pmin
89 91 400 * 1000.0); // Pmax
90 - _vecEffects.push_back(New VariableEffect("Periodic force on 1 axis with 40s-period triangle oscillations "
91 - "of its period in [10, 400] ms, and constant amplitude",
92 - pEffect, mapVars, periodVariableApplier));
92 + _vecEffects.push_back(MemoryManager_NEW
93 + VariableEffect("Periodic force on 1 axis with 40s-period triangle oscillations "
94 + "of its period in [10, 400] ms, and constant amplitude",
95 + pEffect, mapVars, periodVariableApplier));
93 96 }
94 97
95 98 EffectManager::~EffectManager()
96 99 {
97 - for ( VariableEffect* iterEffs : _vecEffects ) {
98 - MemoryManager::SAFE_DELETE( iterEffs );
99 - }
100 - _vecEffects.clear();
100 + MemoryManager::DELETE_VECTOR(_vecEffects);
101 101 }
102 102
103 103 void EffectManager::updateActiveEffects() {
104 -
105 - for (vectorImpl<VariableEffect*>::iterator iterEffs = _vecEffects.begin();
106 - iterEffs != _vecEffects.end();
107 - ++iterEffs)
108 - if ((*iterEffs)->isActive()){
109 - (*iterEffs)->update();
110 - _pJoystickInterface->getCurrentFFDevice()->modify((*iterEffs)->getFFEffect());
104 + vectorImpl<VariableEffect*>::iterator iterEffs;;
105 + for (iterEffs = _vecEffects.begin(); iterEffs != _vecEffects.end(); ++iterEffs) {
106 + if ((*iterEffs)->isActive()){
107 + (*iterEffs)->update();
108 + _pJoystickInterface->getCurrentFFDevice()->modify((*iterEffs)->getFFEffect());
109 + }
111 110 }
112 111 }
113 112
114 113 void EffectManager::checkPlayableEffects() {
115 114 // Nothing to do if no joystick currently selected
116 - if (!_pJoystickInterface->getCurrentFFDevice()) return;
115 + if (!_pJoystickInterface->getCurrentFFDevice()) {
116 + return;
117 + }
117 118
118 119 // Get the list of indices of effects that the selected device can play
119 120 _vecPlayableEffectInd.clear();
120 121 for (vectorAlg::vecSize nEffInd = 0; nEffInd < _vecEffects.size(); ++nEffInd) {
121 122 const OIS::Effect::EForce& eForce = _vecEffects[nEffInd]->getFFEffect()->force;
122 123 const OIS::Effect::EType& eType = _vecEffects[nEffInd]->getFFEffect()->type;
123 - if (_pJoystickInterface->getCurrentFFDevice()->supportsEffect(eForce, eType))
124 + if (_pJoystickInterface->getCurrentFFDevice()->supportsEffect(eForce, eType)) {
124 125 _vecPlayableEffectInd.push_back(nEffInd);
126 + }
125 127 }
126 128
127 129 // Print details about playable effects
128 130 if (_vecPlayableEffectInd.empty()) {
129 131 D_ERROR_FN(Locale::get("INPUT_EFFECT_TEST_FAIL"));
130 - }
131 - else {
132 + } else {
132 133 PRINT_FN(Locale::get("INPUT_DEVICE_EFFECT_SUPPORT"));
133 134
134 - for (vectorAlg::vecSize nEffIndInd = 0; nEffIndInd < _vecPlayableEffectInd.size(); ++nEffIndInd) {
135 + vectorAlg::vecSize nEffIndInd = 0;
136 + for (; nEffIndInd < _vecPlayableEffectInd.size(); ++nEffIndInd) {
135 137 printEffect(_vecPlayableEffectInd[nEffIndInd]);
136 138 }
137 139
  @@ -153,24 +155,29 @@
153 155 }
154 156
155 157 // If no effect selected, and next or previous requested, select the first one.
156 - if (eWhich != eNone && _nCurrEffectInd < 0)
158 + if (eWhich != eNone && _nCurrEffectInd < 0) {
157 159 _nCurrEffectInd = 0;
158 160 // Otherwise, remove the current one from the device and then select the requested one if any.
159 - else if (_nCurrEffectInd >= 0) {
160 - _pJoystickInterface->getCurrentFFDevice()->remove(_vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect());
161 + } else if (_nCurrEffectInd >= 0) {
162 + OIS::Effect* effect = _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect();
163 + _pJoystickInterface->getCurrentFFDevice()->remove(effect);
164 +
161 165 _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->setActive(false);
162 166 _nCurrEffectInd += eWhich;
163 - if (_nCurrEffectInd < -1 || _nCurrEffectInd >= (I16)_vecPlayableEffectInd.size())
167 + if (_nCurrEffectInd < -1 || _nCurrEffectInd >= (I16)_vecPlayableEffectInd.size()) {
164 168 _nCurrEffectInd = -1;
169 + }
165 170 }
166 171
167 172 // If no effect must be selected, reset the selection index
168 - if (eWhich == eNone)
173 + if (eWhich == eNone) {
169 174 _nCurrEffectInd = -1;
170 175 // Otherwise, upload the new selected effect to the device if any.
171 - else if (_nCurrEffectInd >= 0) {
176 + } else if (_nCurrEffectInd >= 0) {
172 177 _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->setActive(true);
173 - _pJoystickInterface->getCurrentFFDevice()->upload(_vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect());
178 +
179 + OIS::Effect* effect = _vecEffects[_vecPlayableEffectInd[_nCurrEffectInd]]->getFFEffect();
180 + _pJoystickInterface->getCurrentFFDevice()->upload(effect);
174 181 }
175 182 }
176 183