| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/main/D3ForceFeedback.cpp $ |
| 21 | * $Revision: 19 $ |
| 22 | * $Date: 5/10/99 9:25p $ |
| 23 | * $Author: Jeff $ |
| 24 | * |
| 25 | * High level force-feedback implementation |
| 26 | * |
| 27 | * $Log: /DescentIII/main/D3ForceFeedback.cpp $ |
| 28 | * |
| 29 | * 19 5/10/99 9:25p Jeff |
| 30 | * first phase of Rock 'n' Ride support added |
| 31 | * |
| 32 | * 18 4/24/99 7:45p Jeff |
| 33 | * fixed recoil |
| 34 | * |
| 35 | * 17 4/21/99 11:05a Kevin |
| 36 | * new ps_rand and ps_srand to replace rand & srand |
| 37 | * |
| 38 | * 16 4/15/99 1:38a Jeff |
| 39 | * changes for linux compile |
| 40 | * |
| 41 | * 15 4/12/99 1:06p Jeff |
| 42 | * hooked force feedback into recoil of weapon struct |
| 43 | * |
| 44 | * 14 3/28/99 5:53p Jeff |
| 45 | * fixed iforce crashes |
| 46 | * |
| 47 | * 13 2/09/99 3:32p Jeff |
| 48 | * table file parser takes quotes strings for force keywords |
| 49 | * |
| 50 | * 12 2/05/99 7:04p Jeff |
| 51 | * table file parsing macros put in |
| 52 | * |
| 53 | * 11 1/30/99 11:27p Jeff |
| 54 | * added immersion support |
| 55 | * |
| 56 | * 10 1/28/99 12:09p Jeff |
| 57 | * added force feedback to player shake...fixed spelling error in define |
| 58 | * for forcefeedback |
| 59 | * |
| 60 | * 9 1/25/99 7:28p Jeff |
| 61 | * fixed alt-tab bug (finally)...wasn't releasing effects on alt-tab out, |
| 62 | * and re-creating them on restart |
| 63 | * |
| 64 | * 8 11/18/98 5:50p Jeff |
| 65 | * added some cheap recoil effects for ForceFeedback...not fully |
| 66 | * implemented |
| 67 | * |
| 68 | * 7 11/10/98 5:16p Jeff |
| 69 | * updated forcefeedback system...pretty complete now |
| 70 | * |
| 71 | * 6 11/06/98 7:00p Jeff |
| 72 | * first round of new force feedback installed |
| 73 | * |
| 74 | * 5 11/03/98 6:43p Jeff |
| 75 | * new low-level & high level Force Feedback system implemented, handles |
| 76 | * window losing focus, etc. |
| 77 | * |
| 78 | * 4 10/12/98 3:49p Jeff |
| 79 | * struct changes |
| 80 | * |
| 81 | * 3 9/21/98 11:09a Jeff |
| 82 | * general update, new low level, small high level implementation |
| 83 | * |
| 84 | * 2 9/18/98 7:38p Jeff |
| 85 | * creation of low-level forcefeedback and beginning of high-level |
| 86 | * forcefeedback |
| 87 | * |
| 88 | * $NoKeywords: $ |
| 89 | */ |
| 90 | |
| 91 | #include <stdlib.h> |
| 92 | |
| 93 | #include "forcefeedback.h" |
| 94 | #include "D3ForceFeedback.h" |
| 95 | #include "pserror.h" |
| 96 | #include "mono.h" |
| 97 | #include "weapon.h" |
| 98 | #include "ddio.h" |
| 99 | #include "psrand.h" |
| 100 | #include "descent.h" |
| 101 | |
| 102 | extern float Gametime; |
| 103 | |
| 104 | // D3Force_init |
| 105 | // true if ForceInit() has been called, meaning hi-level ForceFeedback has been initialized |
| 106 | // and any of the Hi-Level ForceFeedback commands can be called. |
| 107 | bool D3Force_init = false; |
| 108 | |
| 109 | // D3Force_pause |
| 110 | // true if the ForceFeedback effects are currently being paused. ForceContinue() must be called |
| 111 | // before any other ForceFeedback functions are called. |
| 112 | bool D3Force_pause = false; |
| 113 | |
| 114 | // D3Force_auto_center |
| 115 | // true if the user wants his joystick to be autocentered (if available) |
| 116 | bool D3Force_auto_center = false; |
| 117 | |
| 118 | // D3Force_gain |
| 119 | // the gain setting of the ForceFeedback system |
| 120 | float D3Force_gain = 1.0f; |
| 121 | |
| 122 | // D3Use_force_feedback |
| 123 | // true if the user wants force feedback during play (if available) |
| 124 | bool D3Use_force_feedback = true; |
| 125 | |
| 126 | int Force_hi_to_low_map[DDIO_FF_MAXEFFECTS]; |
| 127 | |
| 128 | // ----------------------------------------------------------------- |
| 129 | // ForceInit |
| 130 | // Purpose: |
| 131 | // Initializes the Hi-Level Force Feedback system, creating all |
| 132 | // of the effects so they are ready to be used. |
| 133 | // ----------------------------------------------------------------- |
| 134 | void ForceInit(void) { |
| 135 | static bool first_call = true; |
| 136 | |
| 137 | ASSERT(!D3Force_init); |
| 138 | |
| 139 | bool dd_found, dd_enabled; |
| 140 | ddio_ff_GetInfo(&dd_found, &dd_enabled); |
| 141 | |
| 142 | if (dd_found) { |
| 143 | D3Force_init = true; |
| 144 | D3Force_pause = false; |
| 145 | |
| 146 | mprintf(0, "Force: High Level Force Feedback system initialized\n"); |
| 147 | } else { |
| 148 | D3Force_init = false; |
| 149 | D3Force_pause = false; |
| 150 | |
| 151 | mprintf(0, "Force: Force Feedback System Not Found\n"); |
| 152 | } |
| 153 | |
| 154 | for (int i = 0; i < DDIO_FF_MAXEFFECTS; i++) { |
| 155 | Force_hi_to_low_map[i] = -1; |
| 156 | } |
| 157 | |
| 158 | ForceEffectsInit(); |
| 159 | |
| 160 | if (D3Force_init) { |
| 161 | // Enable/Disable the force feedback |
| 162 | // --------------------------------- |
| 163 | if (D3Use_force_feedback) |
| 164 | ForceEnable(); |
| 165 | else |
| 166 | ForceDisable(); |
| 167 | |
| 168 | // Enable/Disable AutoCentering |
| 169 | // ---------------------------- |
| 170 | if (D3Force_auto_center) |
| 171 | ForceEnableAutoCenter(); |
| 172 | else |
| 173 | ForceDisableAutoCenter(); |
| 174 | |
| 175 | // Set ForceFeedback Gain |
| 176 | // ---------------------- |
| 177 | ForceSetGain(D3Force_gain); |
| 178 | } |
| 179 | |
| 180 | if (first_call) { |
| 181 | first_call = false; |
| 182 | atexit(ForceClose); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // ----------------------------------------------------------------- |
| 187 | // ForceClose |
| 188 | // Purpose: |
| 189 | // Shutsdown the Hi-Level Force Feedback system |
| 190 | // ----------------------------------------------------------------- |
| 191 | void ForceClose(void) { |
| 192 | if (!D3Force_init) |
| 193 | return; |
| 194 | |
| 195 | D3Force_pause = false; |
| 196 | D3Force_init = false; |
| 197 | |
| 198 | mprintf(0, "Force: Shutting down high level force feedback\n"); |
| 199 | ForceEffectsClose(); |
| 200 | |
| 201 | for (int i = 0; i < DDIO_FF_MAXEFFECTS; i++) { |
| 202 | Force_hi_to_low_map[i] = -1; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | // ----------------------------------------------------------------- |
| 207 | // ForceShutdown |
| 208 | // Purpose: |
| 209 | // Puts the Force Feedback system on pause while the application |
| 210 | // is doing other things (like it lost focus) |
| 211 | // ----------------------------------------------------------------- |
| 212 | void ForceShutdown(void) { |
| 213 | D3Force_pause = true; |
| 214 | |
| 215 | ForceClose(); |
| 216 | if (D3Force_init) { |
| 217 | mprintf(0, "Force: Shutting down Force Feedback System\n"); |
| 218 | ddio_ffb_Pause(kJoy1); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // ------------------------------------------------------------------ |
| 223 | // ForceRestart |
| 224 | // Purpose: |
| 225 | // Restores the Force Feedback system that has been put on pause |
| 226 | // from ForceShutdown. |
| 227 | // ------------------------------------------------------------------ |
| 228 | void ForceRestart(void) { |
| 229 | D3Force_pause = false; |
| 230 | |
| 231 | if (D3Force_init) { |
| 232 | mprintf(0, "Force: Restarting Force Feedback System\n"); |
| 233 | ddio_ff_Acquire(kJoy1); |
| 234 | ddio_ffb_Continue(kJoy1); |
| 235 | |
| 236 | // Enable/Disable the force feedback |
| 237 | // --------------------------------- |
| 238 | if (D3Use_force_feedback) |
| 239 | ForceEnable(); |
| 240 | else |
| 241 | ForceDisable(); |
| 242 | |
| 243 | // Enable/Disable AutoCentering |
| 244 | // ---------------------------- |
| 245 | if (D3Force_auto_center) |
| 246 | ForceEnableAutoCenter(); |
| 247 | else |
| 248 | ForceDisableAutoCenter(); |
| 249 | |
| 250 | // Set ForceFeedback Gain |
| 251 | // ---------------------- |
| 252 | ForceSetGain(D3Force_gain); |
| 253 | } |
| 254 | |
| 255 | ForceInit(); |
| 256 | } |
| 257 | |
| 258 | // ------------------------------------------------------------------ |
| 259 | // ForceDisable |
| 260 | // Purpose: |
| 261 | // Disables Force Feedback on a Force Feedback system |
| 262 | // ------------------------------------------------------------------ |
| 263 | void ForceDisable(void) { |
| 264 | if (D3Force_init) { |
| 265 | mprintf(0, "Force: Disabling Force Feedback System\n"); |
| 266 | //@@ddio_ffb_Disable(kJoy1); |
| 267 | D3Use_force_feedback = false; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // ------------------------------------------------------------------ |
| 272 | // ForceEnable |
| 273 | // Purpose: |
| 274 | // Enables Force Feedback that has been previously disabled |
| 275 | // ------------------------------------------------------------------ |
| 276 | void ForceEnable(void) { |
| 277 | if (D3Force_init) { |
| 278 | mprintf(0, "Force: Enabling Force Feedback System\n"); |
| 279 | //@@ddio_ffb_Enable(kJoy1); |
| 280 | D3Use_force_feedback = true; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | // ------------------------------------------------------------------ |
| 285 | // ForceDisableAutoCenter |
| 286 | // Purpose: |
| 287 | // Disables autocentering on the joystick |
| 288 | // ------------------------------------------------------------------ |
| 289 | void ForceDisableAutoCenter(void) { |
| 290 | if (D3Force_init) { |
| 291 | D3Force_auto_center = false; |
| 292 | |
| 293 | ddio_ffjoy_EnableAutoCenter(kJoy1, false); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | // ------------------------------------------------------------------ |
| 298 | // ForceEnableAutoCenter |
| 299 | // Purpose: |
| 300 | // Enables autocentering on the joystick |
| 301 | // ------------------------------------------------------------------ |
| 302 | void ForceEnableAutoCenter(void) { |
| 303 | if (D3Force_init) { |
| 304 | D3Force_auto_center = true; |
| 305 | |
| 306 | ddio_ffjoy_EnableAutoCenter(kJoy1, true); |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | // ------------------------------------------------------------------ |
| 311 | // ForceIsEnabled |
| 312 | // Purpose: |
| 313 | // Returns true if Force Feedback is enabled on the system |
| 314 | // ------------------------------------------------------------------ |
| 315 | bool ForceIsEnabled(void) { return D3Use_force_feedback; } |
| 316 | |
| 317 | // ------------------------------------------------------------------ |
| 318 | // ForceIsAutoCenter |
| 319 | // Purpose: |
| 320 | // Returns true if Force Feedback joystick is autocentering |
| 321 | // ------------------------------------------------------------------ |
| 322 | bool ForceIsAutoCenter(void) { return D3Force_auto_center; } |
| 323 | |
| 324 | // ------------------------------------------------------------------ |
| 325 | // ForceSetGain |
| 326 | // Purpose: |
| 327 | // Sets the gain of the ForceFeedback system (0 -> 1) |
| 328 | // ------------------------------------------------------------------ |
| 329 | void ForceSetGain(float val) { |
| 330 | if (val < 0.0f) |
| 331 | val = 0.0f; |
| 332 | if (val > 1.0f) |
| 333 | val = 1.0f; |
| 334 | |
| 335 | D3Force_gain = val; |
| 336 | ddio_ffjoy_SetGain(kJoy1, D3Force_gain); |
| 337 | } |
| 338 | |
| 339 | // ------------------------------------------------------------------ |
| 340 | // ForceGetGain |
| 341 | // Purpose: |
| 342 | // Returns the current gain setting of the ForceFeedback system (0-1) |
| 343 | // ------------------------------------------------------------------ |
| 344 | float ForceGetGain(void) { return D3Force_gain; } |
| 345 | |
| 346 | /* |
| 347 | ============================================================================= |
| 348 | */ |
| 349 | |
| 350 | // ----------------------------------------------------------------- |
| 351 | // ForceEffectsClose |
| 352 | // Purpose: |
| 353 | // Destroys all the effects created |
| 354 | // ----------------------------------------------------------------- |
| 355 | void ForceEffectsClose(void) { ddio_ffb_DestroyAll(); } |
| 356 | |
| 357 | // ----------------------------------------------------------------- |
| 358 | // ForceEffectsPlay |
| 359 | // Purpose: |
| 360 | // Plays an effect |
| 361 | // ----------------------------------------------------------------- |
| 362 | void ForceEffectsPlay(int id, float *scale, int *direction) { |
| 363 | if (!D3Force_init || !D3Use_force_feedback) |
| 364 | return; |
| 365 | |
| 366 | if (id < 0 || id >= DDIO_FF_MAXEFFECTS) |
| 367 | return; |
| 368 | |
| 369 | int low_id = Force_hi_to_low_map[id]; |
| 370 | if (low_id == -1) |
| 371 | return; |
| 372 | |
| 373 | if (scale || direction) { |
| 374 | uint32_t *ns = NULL; |
| 375 | uint32_t new_gain; |
| 376 | |
| 377 | if (scale) { |
| 378 | new_gain = (uint32_t)(10000.0f * (*scale)); |
| 379 | ns = &new_gain; |
| 380 | } |
| 381 | |
| 382 | ddio_ffb_effectModify(low_id, direction, NULL, ns, NULL, NULL, NULL); |
| 383 | } |
| 384 | |
| 385 | ddio_ffb_effectPlay(low_id); |
| 386 | } |
| 387 | void ForceEffectsPlay(int id, float *scale, vector *direction) { |
| 388 | if (!D3Force_init || !D3Use_force_feedback) |
| 389 | return; |
| 390 | |
| 391 | if (id < 0 || id >= DDIO_FF_MAXEFFECTS) |
| 392 | return; |
| 393 | |
| 394 | int low_id = Force_hi_to_low_map[id]; |
| 395 | if (low_id == -1) |
| 396 | return; |
| 397 | |
| 398 | int new_dir = -1; |
| 399 | |
| 400 | if (direction) { |
| 401 | matrix mat = Identity_matrix; |
| 402 | angvec ag; |
| 403 | |
| 404 | vm_VectorToMatrix(&mat, direction); |
| 405 | vm_ExtractAnglesFromMatrix(&ag, &mat); |
| 406 | |
| 407 | new_dir = ((((float)ag.h) / 65535.0f) * 360.0f); |
| 408 | |
| 409 | new_dir = (new_dir)*FF_DEGREES; |
| 410 | } |
| 411 | |
| 412 | if (scale || direction) { |
| 413 | int *d = NULL; |
| 414 | uint32_t *ns = NULL; |
| 415 | uint32_t new_gain; |
| 416 | |
| 417 | if (direction) |
| 418 | d = &new_dir; |
| 419 | |
| 420 | if (scale) { |
| 421 | new_gain = (uint32_t)(10000.0f * (*scale)); |
| 422 | ns = &new_gain; |
| 423 | } |
| 424 | |
| 425 | ddio_ffb_effectModify(low_id, d, NULL, ns, NULL, NULL, NULL); |
| 426 | } |
| 427 | |
| 428 | ddio_ffb_effectPlay(low_id); |
| 429 | } |
| 430 | |
| 431 | void DoForceForWeapon(object *me_obj, object *it_obj, vector *force_vec) { |
| 432 | if (it_obj->id < 0 || it_obj->id >= MAX_WEAPONS) |
| 433 | return; |
| 434 | |
| 435 | weapon *weap = &Weapons[it_obj->id]; |
| 436 | |
| 437 | if (weap->flags & WF_MICROWAVE) { |
| 438 | vector local_norm, v; |
| 439 | float scale = 1.00f; |
| 440 | v.x = ps_rand() % 10; |
| 441 | v.y = 0; |
| 442 | v.z = ps_rand() % 10; |
| 443 | vm_NormalizeVector(&v); |
| 444 | vm_MatrixMulVector(&local_norm, &v, &me_obj->orient); |
| 445 | |
| 446 | local_norm *= -1.0f; |
| 447 | |
| 448 | ForceEffectsPlay(FORCE_MICROWAVE, &scale, &local_norm); |
| 449 | return; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | void DoForceForWall(object *playerobj, float hitspeed, int hitseg, int hitwall, vector *wall_normal) { |
| 454 | vector local_norm; |
| 455 | float scale = 1.00f; |
| 456 | |
| 457 | if (hitspeed < 20) |
| 458 | return; |
| 459 | |
| 460 | scale = hitspeed / 80.0f; |
| 461 | if (scale < 0.0f) |
| 462 | scale = 0.0f; |
| 463 | if (scale > 1.0f) |
| 464 | scale = 1.0f; |
| 465 | |
| 466 | vm_MatrixMulVector(&local_norm, wall_normal, &playerobj->orient); |
| 467 | local_norm *= -1.0f; |
| 468 | |
| 469 | ForceEffectsPlay(FORCE_WALLHIT, &scale, &local_norm); |
| 470 | } |
| 471 | |
| 472 | void DoForceForRecoil(object *playerobj, object *weap) { |
| 473 | weapon *w_ptr = &Weapons[weap->id]; |
| 474 | |
| 475 | vector local_norm; |
| 476 | float scale; |
| 477 | #define MIN_RECOIL 1000.0f |
| 478 | #define MAX_RECOIL 5000.0f |
| 479 | #define RECOIL_THRESHOLD 1100.0f |
| 480 | |
| 481 | if (w_ptr->recoil_force < RECOIL_THRESHOLD) |
| 482 | return; |
| 483 | |
| 484 | vector offset = weap->pos - playerobj->pos; |
| 485 | vm_MatrixMulVector(&local_norm, &offset, &playerobj->orient); |
| 486 | |
| 487 | if (weap->movement_type != MT_PHYSICS) |
| 488 | return; |
| 489 | |
| 490 | ASSERT(w_ptr->recoil_force >= MIN_RECOIL && w_ptr->recoil_force <= MAX_RECOIL); |
| 491 | scale = (w_ptr->recoil_force - MIN_RECOIL) / (MAX_RECOIL - MIN_RECOIL); |
| 492 | |
| 493 | ForceEffectsPlay(FORCE_WEAPON_RECOIL, &scale, &local_norm); |
| 494 | } |
| 495 | |
| 496 | float Force_time_since_last_shake; |
| 497 | #define SHAKE_TIME 0.2f |
| 498 | void DoForceForShake(float magnitude) { |
| 499 | if (Force_time_since_last_shake + SHAKE_TIME > Gametime) { |
| 500 | if (Force_time_since_last_shake < Gametime) { |
| 501 | return; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | Force_time_since_last_shake = Gametime; |
| 506 | |
| 507 | vector local_norm; |
| 508 | |
| 509 | if (magnitude < 0.0f) |
| 510 | magnitude = 0.0f; |
| 511 | if (magnitude > 1.0f) |
| 512 | magnitude = 1.0f; |
| 513 | |
| 514 | local_norm.x = (ps_rand() % 5); |
| 515 | local_norm.y = (ps_rand() % 5); |
| 516 | local_norm.z = (ps_rand() % 5); |
| 517 | vm_NormalizeVector(&local_norm); |
| 518 | |
| 519 | ForceEffectsPlay(FORCE_SHIPSHAKE, &magnitude, &local_norm); |
| 520 | } |
| 521 | |
| 522 | //************************************************************************ |
| 523 | |
| 524 | void FFECreate_Test(tFFB_Effect *ef) { |
| 525 | memset(ef, 0, sizeof(tFFB_Effect)); |
| 526 | |
| 527 | ef->Type = kConstant; |
| 528 | ef->TypeInfo.Constant.Mag = FF_NOMINALMAX; |
| 529 | ef->Duration = 0.1 * FF_SECONDS; |
| 530 | ef->Gain = FF_NOMINALMAX; |
| 531 | ef->Period = 0; |
| 532 | ef->Axis = kBothAxes; |
| 533 | ef->Trigger = kNoButton; |
| 534 | ef->Direction = 0; |
| 535 | } |
| 536 | |
| 537 | void FFECreate_Microwave(tFFB_Effect *ef) { |
| 538 | memset(ef, 0, sizeof(tFFB_Effect)); |
| 539 | |
| 540 | ef->Flags = FF_USEENVELOPE; |
| 541 | ef->Type = kWave_Sine; |
| 542 | ef->TypeInfo.Wave.Mag = FF_NOMINALMAX; |
| 543 | ef->TypeInfo.Wave.Offset = 0; |
| 544 | ef->TypeInfo.Wave.Phase = 0; |
| 545 | ef->TypeInfo.Wave.Period = 0.2 * FF_SECONDS; |
| 546 | |
| 547 | ef->Duration = 0.6 * FF_SECONDS; |
| 548 | ef->Gain = FF_NOMINALMAX; |
| 549 | ef->Period = 0; |
| 550 | ef->Axis = kBothAxes; |
| 551 | ef->Trigger = kNoButton; |
| 552 | ef->Direction = 0; |
| 553 | |
| 554 | ef->Envelope.AttackLevel = FF_NOMINALMAX * 0.5f; |
| 555 | ef->Envelope.AttackTime = 0; |
| 556 | ef->Envelope.FadeLevel = FF_NOMINALMAX * 0.1f; |
| 557 | ef->Envelope.FadeTime = 0.6 * FF_SECONDS; |
| 558 | } |
| 559 | |
| 560 | void FFECreate_Wallhit(tFFB_Effect *ef) { |
| 561 | memset(ef, 0, sizeof(tFFB_Effect)); |
| 562 | |
| 563 | ef->Type = kConstant; |
| 564 | ef->TypeInfo.Constant.Mag = FF_NOMINALMAX; |
| 565 | ef->Duration = 0.1 * FF_SECONDS; |
| 566 | ef->Gain = FF_NOMINALMAX; |
| 567 | ef->Period = 0; |
| 568 | ef->Axis = kBothAxes; |
| 569 | ef->Trigger = kNoButton; |
| 570 | ef->Direction = 0; |
| 571 | } |
| 572 | |
| 573 | void FFECreate_WeaponRecoil(tFFB_Effect *ef) { |
| 574 | memset(ef, 0, sizeof(tFFB_Effect)); |
| 575 | |
| 576 | ef->Type = kConstant; |
| 577 | ef->TypeInfo.Constant.Mag = FF_NOMINALMAX; |
| 578 | ef->Duration = 0.1 * FF_SECONDS; |
| 579 | ef->Gain = FF_NOMINALMAX; |
| 580 | ef->Period = 0; |
| 581 | ef->Axis = kBothAxes; |
| 582 | ef->Trigger = kNoButton; |
| 583 | ef->Direction = 0; |
| 584 | } |
| 585 | |
| 586 | void FFECreate_VaussRecoil(tFFB_Effect *ef) { |
| 587 | memset(ef, 0, sizeof(tFFB_Effect)); |
| 588 | |
| 589 | ef->Type = kWave_Square; |
| 590 | ef->TypeInfo.Wave.Mag = FF_NOMINALMAX; |
| 591 | ef->TypeInfo.Wave.Offset = 0; |
| 592 | ef->TypeInfo.Wave.Phase = 0; |
| 593 | ef->TypeInfo.Wave.Period = 0.05 * FF_SECONDS; |
| 594 | |
| 595 | ef->Duration = 0.2 * FF_SECONDS; |
| 596 | ef->Gain = FF_NOMINALMAX; |
| 597 | ef->Period = 0; |
| 598 | ef->Axis = kBothAxes; |
| 599 | ef->Trigger = kNoButton; |
| 600 | ef->Direction = 0; |
| 601 | } |
| 602 | |
| 603 | void FFECreate_Afterburner(tFFB_Effect *ef) { |
| 604 | memset(ef, 0, sizeof(tFFB_Effect)); |
| 605 | |
| 606 | ef->Type = kWave_Square; |
| 607 | ef->TypeInfo.Wave.Mag = FF_NOMINALMAX; |
| 608 | ef->TypeInfo.Wave.Offset = 0; |
| 609 | ef->TypeInfo.Wave.Phase = 0; |
| 610 | ef->TypeInfo.Wave.Period = 0.05 * FF_SECONDS; |
| 611 | |
| 612 | ef->Duration = 0.2 * FF_SECONDS; |
| 613 | ef->Gain = FF_NOMINALMAX; |
| 614 | ef->Period = 0; |
| 615 | ef->Axis = kBothAxes; |
| 616 | ef->Trigger = kNoButton; |
| 617 | ef->Direction = 0; |
| 618 | } |
| 619 | |
| 620 | void FFECreate_ShipShake(tFFB_Effect *ef) { |
| 621 | memset(ef, 0, sizeof(tFFB_Effect)); |
| 622 | |
| 623 | ef->Type = kWave_Sine; |
| 624 | ef->TypeInfo.Wave.Mag = (FF_NOMINALMAX / 3); |
| 625 | ef->TypeInfo.Wave.Offset = 0; |
| 626 | ef->TypeInfo.Wave.Phase = 0; |
| 627 | ef->TypeInfo.Wave.Period = (SHAKE_TIME / 2) * FF_SECONDS; |
| 628 | |
| 629 | ef->Duration = SHAKE_TIME * FF_SECONDS; |
| 630 | ef->Gain = FF_NOMINALMAX; |
| 631 | ef->Period = 0; |
| 632 | ef->Axis = kBothAxes; |
| 633 | ef->Trigger = kNoButton; |
| 634 | ef->Direction = 0; |
| 635 | } |
| 636 | |
| 637 | //************************************************************* |
| 638 | // ------------------------------------------------------------------ |
| 639 | // ForceEffectsInit |
| 640 | // Purpose: |
| 641 | // Initializes the force feedback effects for Descent 3 |
| 642 | // ------------------------------------------------------------------ |
| 643 | void ForceEffectsInit(void) { |
| 644 | tFFB_Effect eff; |
| 645 | int lowid; |
| 646 | Force_time_since_last_shake = 0; |
| 647 | FORCEPROJECT prj; |
| 648 | char path[_MAX_PATH]; |
| 649 | |
| 650 | if (cfexist("D3Force.ifr")) { |
| 651 | ddio_MakePath(path, Descent3_temp_directory, "D3Force.ifr", NULL); |
| 652 | cf_CopyFile(path, "D3Force.ifr", 0); |
| 653 | prj = ddio_ForceLoadProject(IGNORE_TABLE(path), kJoy1); |
| 654 | } else { |
| 655 | prj = NULL; |
| 656 | } |
| 657 | /* |
| 658 | $$TABLE_GAMEFILE "D3Force.ifr" |
| 659 | */ |
| 660 | lowid = ddio_CreateForceFromProject(prj, "Test"); |
| 661 | if (lowid == -1) { |
| 662 | FFECreate_Test(&eff); |
| 663 | lowid = ddio_ffb_effectCreate(kJoy1, &eff); |
| 664 | } |
| 665 | Force_hi_to_low_map[FORCE_TEST_FORCE] = lowid; |
| 666 | |
| 667 | lowid = ddio_CreateForceFromProject(prj, "Microwave"); |
| 668 | if (lowid == -1) { |
| 669 | FFECreate_Microwave(&eff); |
| 670 | lowid = ddio_ffb_effectCreate(kJoy1, &eff); |
| 671 | } |
| 672 | Force_hi_to_low_map[FORCE_MICROWAVE] = lowid; |
| 673 | |
| 674 | lowid = ddio_CreateForceFromProject(prj, "WallHit"); |
| 675 | if (lowid == -1) { |
| 676 | FFECreate_Wallhit(&eff); |
| 677 | lowid = ddio_ffb_effectCreate(kJoy1, &eff); |
| 678 | } |
| 679 | Force_hi_to_low_map[FORCE_WALLHIT] = lowid; |
| 680 | |
| 681 | lowid = ddio_CreateForceFromProject(prj, "Recoil"); |
| 682 | if (lowid == -1) { |
| 683 | FFECreate_WeaponRecoil(&eff); |
| 684 | lowid = ddio_ffb_effectCreate(kJoy1, &eff); |
| 685 | } |
| 686 | Force_hi_to_low_map[FORCE_WEAPON_RECOIL] = lowid; |
| 687 | |
| 688 | lowid = ddio_CreateForceFromProject(prj, "VaussRecoil"); |
| 689 | if (lowid == -1) { |
| 690 | FFECreate_VaussRecoil(&eff); |
| 691 | lowid = ddio_ffb_effectCreate(kJoy1, &eff); |
| 692 | } |
| 693 | Force_hi_to_low_map[FORCE_VAUSS_RECOIL] = lowid; |
| 694 | |
| 695 | lowid = ddio_CreateForceFromProject(prj, "Afterburner"); |
| 696 | if (lowid == -1) { |
| 697 | FFECreate_Afterburner(&eff); |
| 698 | lowid = ddio_ffb_effectCreate(kJoy1, &eff); |
| 699 | } |
| 700 | Force_hi_to_low_map[FORCE_AFTERBURNER] = lowid; |
| 701 | |
| 702 | lowid = ddio_CreateForceFromProject(prj, "ShipShake"); |
| 703 | if (lowid == -1) { |
| 704 | FFECreate_ShipShake(&eff); |
| 705 | lowid = ddio_ffb_effectCreate(kJoy1, &eff); |
| 706 | } |
| 707 | Force_hi_to_low_map[FORCE_SHIPSHAKE] = lowid; |
| 708 | |
| 709 | ddio_ForceUnloadProject(prj); |
| 710 | if (cfexist(path)) { |
| 711 | ddio_DeleteFile(path); |
| 712 | } |
| 713 | } |