Enhancement to weapon sound effects
This commit is contained in:
parent
a1712628d1
commit
7a14c39911
@ -126,14 +126,14 @@ GCC 4.9 / Clang 3.2 or later is recommended because OpenSpades relies on C++11 f
|
||||
9. To get audio working, download a [Windows release of OpenSpades](https://github.com/yvt/openspades/releases), extract it, and copy the following dlls to the build output directory:
|
||||
* For OpenAL audio: `openal32.dll`
|
||||
* For YSR audio: `YSRSpades.dll`, `libgcc_s_dw2-1.dll`, `libstdc++-6.dll`, `pthreadGC2.dll`
|
||||
10. Download the [Non-free pak](https://github.com/yvt/openspades-paks/releases/download/r32/OpenSpadesDevPackage-r32.zip) and copy it to the `Resources` folder inside your build output directory, which is probably `E:/Projects/openspades/openspades.msvc/bin/BUILD_TYPE/Resources`. You can also copy the paks contained in `Official Mods/` folder of OpenSpades 0.0.12b to add more fonts and improve localization support of your build.
|
||||
10. Download the [Non-free pak](https://github.com/yvt/openspades-paks/releases/download/r33/OpenSpadesDevPackage-r33.zip) and copy it to the `Resources` folder inside your build output directory, which is probably `E:/Projects/openspades/openspades.msvc/bin/BUILD_TYPE/Resources`. You can also copy the paks contained in `Official Mods/` folder of OpenSpades 0.0.12b to add more fonts and improve localization support of your build.
|
||||
|
||||
### On Mac OS X (with Xcode)
|
||||
1. Get the latest version of Xcode and OpenSpades source.
|
||||
2. Get (pre-compiled) copies of libraries, and place them in `Sources/Externals`
|
||||
* See the file `Sources/Externals/readme.txt` for details
|
||||
4. Download [OS X release of OpenSpades](https://github.com/yvt/openspades/releases), show the package contents, and copy `libysrspades.dylib` to `Sources/Externals/lib`.
|
||||
5. Download and extract the [Non-free pak](https://github.com/yvt/openspades-paks/releases/download/r32/OpenSpadesDevPackage-r32.zip). After that, copy `pak000-Nonfree.pak` and `font-unifont.pak` to `Resources/`.
|
||||
5. Download and extract the [Non-free pak](https://github.com/yvt/openspades-paks/releases/download/r33/OpenSpadesDevPackage-r33.zip). After that, copy `pak000-Nonfree.pak` and `font-unifont.pak` to `Resources/`.
|
||||
6. Open `OpenSpades.xcodeproj` and build.
|
||||
|
||||
## Troubleshooting
|
||||
|
@ -3,7 +3,7 @@
|
||||
External Game Assets
|
||||
--------------------
|
||||
|
||||
https://github.com/yvt/openspades-paks/releases/download/r32/OpenSpadesDevPackage-r32.zip
|
||||
https://github.com/yvt/openspades-paks/releases/download/r33/OpenSpadesDevPackage-r33.zip
|
||||
|
||||
This package provides following paks:
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
namespace spades {
|
||||
class BasicViewWeapon:
|
||||
IToolSkin, IViewToolSkin, IWeaponSkin {
|
||||
IToolSkin, IViewToolSkin, IWeaponSkin, IWeaponSkin2 {
|
||||
// IToolSkin
|
||||
protected float sprintState;
|
||||
protected float raiseState;
|
||||
@ -131,6 +131,15 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
// IWeaponSkin2
|
||||
protected float ambienceRoom;
|
||||
protected float ambienceSize;
|
||||
|
||||
void SetSoundAmbience(float room, float size, float distance) {
|
||||
ambienceRoom = room;
|
||||
ambienceSize = size;
|
||||
}
|
||||
|
||||
protected Renderer@ renderer;
|
||||
protected Image@ sightImage;
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
namespace spades {
|
||||
class ThirdPersonRifleSkin:
|
||||
IToolSkin, IThirdPersonToolSkin, IWeaponSkin {
|
||||
IToolSkin, IThirdPersonToolSkin, IWeaponSkin, IWeaponSkin2 {
|
||||
private float sprintState;
|
||||
private float raiseState;
|
||||
private Vector3 teamColor;
|
||||
@ -32,6 +32,10 @@
|
||||
private float reloadProgress;
|
||||
private int ammo, clipSize;
|
||||
|
||||
private float ambienceRoom;
|
||||
private float ambienceSize;
|
||||
private float ambienceDistance;
|
||||
|
||||
float SprintState {
|
||||
set { sprintState = value; }
|
||||
}
|
||||
@ -77,12 +81,21 @@
|
||||
set { readyState = value; }
|
||||
}
|
||||
|
||||
// IWeaponSkin2
|
||||
void SetSoundAmbience(float room, float size, float distance) {
|
||||
ambienceRoom = room;
|
||||
ambienceSize = size;
|
||||
ambienceDistance = distance;
|
||||
}
|
||||
|
||||
private Renderer@ renderer;
|
||||
private AudioDevice@ audioDevice;
|
||||
private Model@ model;
|
||||
private AudioChunk@[] fireSounds(3);
|
||||
private AudioChunk@ fireFarSound;
|
||||
private AudioChunk@ fireStereoSound;
|
||||
private AudioChunk@ fireSmallReverbSound;
|
||||
private AudioChunk@ fireLargeReverbSound;
|
||||
private AudioChunk@ reloadSound;
|
||||
|
||||
ThirdPersonRifleSkin(Renderer@ r, AudioDevice@ dev) {
|
||||
@ -103,6 +116,11 @@
|
||||
("Sounds/Weapons/Rifle/FireStereo.opus");
|
||||
@reloadSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Rifle/Reload.opus");
|
||||
|
||||
@fireSmallReverbSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Rifle/V2AmbienceSmall.opus");
|
||||
@fireLargeReverbSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Rifle/V2AmbienceLarge.opus");
|
||||
}
|
||||
|
||||
void Update(float dt) {
|
||||
@ -115,6 +133,13 @@
|
||||
param.volume = 20.f;
|
||||
audioDevice.Play(fireSounds[GetRandom(fireSounds.length)], origin, param);
|
||||
|
||||
param.volume = 20.f * ambienceRoom;
|
||||
if (ambienceSize < 0.5f) {
|
||||
audioDevice.Play(fireSmallReverbSound, origin, param);
|
||||
} else {
|
||||
audioDevice.Play(fireLargeReverbSound, origin, param);
|
||||
}
|
||||
|
||||
param.volume = 1.f;
|
||||
param.referenceDistance = 26.f;
|
||||
audioDevice.Play(fireFarSound, origin, param);
|
||||
|
@ -30,6 +30,8 @@
|
||||
private AudioChunk@ fireSound;
|
||||
private AudioChunk@ fireFarSound;
|
||||
private AudioChunk@ fireStereoSound;
|
||||
private AudioChunk@ fireSmallReverbSound;
|
||||
private AudioChunk@ fireLargeReverbSound;
|
||||
private AudioChunk@ reloadSound;
|
||||
private Model@ sightModel1;
|
||||
private Model@ sightModel2;
|
||||
@ -54,6 +56,11 @@
|
||||
("Sounds/Weapons/Rifle/FireStereo.opus");
|
||||
@reloadSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Rifle/ReloadLocal.opus");
|
||||
|
||||
@fireSmallReverbSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Rifle/V2AmbienceSmall.opus");
|
||||
@fireLargeReverbSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Rifle/V2AmbienceLarge.opus");
|
||||
}
|
||||
|
||||
void Update(float dt) {
|
||||
@ -69,6 +76,13 @@
|
||||
param.volume = 8.f;
|
||||
audioDevice.PlayLocal(fireSound, origin, param);
|
||||
|
||||
param.volume = 8.f * ambienceRoom;
|
||||
if (ambienceSize < 0.5f) {
|
||||
audioDevice.PlayLocal(fireSmallReverbSound, origin, param);
|
||||
} else {
|
||||
audioDevice.PlayLocal(fireLargeReverbSound, origin, param);
|
||||
}
|
||||
|
||||
param.referenceDistance = 4.f;
|
||||
param.volume = 1.f;
|
||||
audioDevice.PlayLocal(fireFarSound, origin, param);
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
namespace spades {
|
||||
class ThirdPersonSMGSkin:
|
||||
IToolSkin, IThirdPersonToolSkin, IWeaponSkin {
|
||||
IToolSkin, IThirdPersonToolSkin, IWeaponSkin, IWeaponSkin2 {
|
||||
private float sprintState;
|
||||
private float raiseState;
|
||||
private Vector3 teamColor;
|
||||
@ -32,6 +32,10 @@
|
||||
private float reloadProgress;
|
||||
private int ammo, clipSize;
|
||||
|
||||
private float ambienceRoom;
|
||||
private float ambienceSize;
|
||||
private float ambienceDistance;
|
||||
|
||||
float SprintState {
|
||||
set { sprintState = value; }
|
||||
}
|
||||
@ -77,15 +81,22 @@
|
||||
set { readyState = value; }
|
||||
}
|
||||
|
||||
// IWeaponSkin2
|
||||
void SetSoundAmbience(float room, float size, float distance) {
|
||||
ambienceRoom = room;
|
||||
ambienceSize = size;
|
||||
ambienceDistance = distance;
|
||||
}
|
||||
|
||||
private Renderer@ renderer;
|
||||
private AudioDevice@ audioDevice;
|
||||
private Model@ model;
|
||||
|
||||
private AudioChunk@[] fireSounds(4);
|
||||
private AudioChunk@[] fireMediumSounds(4);
|
||||
private AudioChunk@ fireFarSound;
|
||||
private AudioChunk@ fireStereoSound;
|
||||
private AudioChunk@[] fireMechSounds(4);
|
||||
private AudioChunk@[] fireSmallReverbSounds(4);
|
||||
private AudioChunk@[] fireLargeReverbSounds(4);
|
||||
private AudioChunk@ reloadSound;
|
||||
|
||||
ThirdPersonSMGSkin(Renderer@ r, AudioDevice@ dev) {
|
||||
@ -95,22 +106,33 @@
|
||||
("Models/Weapons/SMG/Weapon.kv6");
|
||||
|
||||
|
||||
@fireSounds[0] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/Fire1.opus");
|
||||
@fireSounds[1] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/Fire2.opus");
|
||||
@fireSounds[2] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/Fire3.opus");
|
||||
@fireSounds[3] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/Fire4.opus");
|
||||
@fireMediumSounds[0] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/FireMedium1.opus");
|
||||
("Sounds/Weapons/SMG/V2Third1.opus");
|
||||
@fireMediumSounds[1] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/FireMedium2.opus");
|
||||
("Sounds/Weapons/SMG/V2Third2.opus");
|
||||
@fireMediumSounds[2] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/FireMedium3.opus");
|
||||
("Sounds/Weapons/SMG/V2Third3.opus");
|
||||
@fireMediumSounds[3] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/FireMedium4.opus");
|
||||
("Sounds/Weapons/SMG/V2Third4.opus");
|
||||
|
||||
@fireSmallReverbSounds[0] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceSmall1.opus");
|
||||
@fireSmallReverbSounds[1] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceSmall2.opus");
|
||||
@fireSmallReverbSounds[2] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceSmall3.opus");
|
||||
@fireSmallReverbSounds[3] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceSmall4.opus");
|
||||
|
||||
@fireLargeReverbSounds[0] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceLarge1.opus");
|
||||
@fireLargeReverbSounds[1] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceLarge2.opus");
|
||||
@fireLargeReverbSounds[2] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceLarge3.opus");
|
||||
@fireLargeReverbSounds[3] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceLarge4.opus");
|
||||
|
||||
@fireFarSound = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/FireFar.opus");
|
||||
@fireStereoSound = dev.RegisterSound
|
||||
@ -130,8 +152,16 @@
|
||||
param.volume = 9.f;
|
||||
audioDevice.Play(fireMediumSounds[GetRandom(fireMediumSounds.length)], origin, param);
|
||||
|
||||
param.volume = 8.f * ambienceRoom;
|
||||
param.referenceDistance = 10.f;
|
||||
if (ambienceSize < 0.5f) {
|
||||
audioDevice.Play(fireSmallReverbSounds[GetRandom(fireSmallReverbSounds.length)], origin, param);
|
||||
} else {
|
||||
audioDevice.Play(fireLargeReverbSounds[GetRandom(fireLargeReverbSounds.length)], origin, param);
|
||||
}
|
||||
|
||||
param.volume = .4f;
|
||||
param.referenceDistance = 5.f;
|
||||
param.referenceDistance = 10.f;
|
||||
audioDevice.Play(fireFarSound, origin, param);
|
||||
param.referenceDistance = 1.f;
|
||||
audioDevice.Play(fireStereoSound, origin, param);
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
namespace spades {
|
||||
class ViewSMGSkin:
|
||||
IToolSkin, IViewToolSkin, IWeaponSkin,
|
||||
IToolSkin, IViewToolSkin, IWeaponSkin, IWeaponSkin2,
|
||||
BasicViewWeapon {
|
||||
|
||||
private AudioDevice@ audioDevice;
|
||||
@ -33,6 +33,8 @@
|
||||
private AudioChunk@[] fireSounds(4);
|
||||
private AudioChunk@ fireFarSound;
|
||||
private AudioChunk@ fireStereoSound;
|
||||
private AudioChunk@[] fireSmallReverbSounds(4);
|
||||
private AudioChunk@[] fireLargeReverbSounds(4);
|
||||
private AudioChunk@ reloadSound;
|
||||
|
||||
ViewSMGSkin(Renderer@ r, AudioDevice@ dev){
|
||||
@ -49,14 +51,32 @@
|
||||
@sightModel3 = renderer.RegisterModel
|
||||
("Models/Weapons/SMG/Sight3.kv6");
|
||||
|
||||
@fireSmallReverbSounds[0] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceSmall1.opus");
|
||||
@fireSmallReverbSounds[1] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceSmall2.opus");
|
||||
@fireSmallReverbSounds[2] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceSmall3.opus");
|
||||
@fireSmallReverbSounds[3] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceSmall4.opus");
|
||||
|
||||
@fireLargeReverbSounds[0] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceLarge1.opus");
|
||||
@fireLargeReverbSounds[1] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceLarge2.opus");
|
||||
@fireLargeReverbSounds[2] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceLarge3.opus");
|
||||
@fireLargeReverbSounds[3] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/V2AmbienceLarge4.opus");
|
||||
|
||||
@fireSounds[0] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/FireLocal1.opus");
|
||||
("Sounds/Weapons/SMG/V2Local1.opus");
|
||||
@fireSounds[1] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/FireLocal2.opus");
|
||||
("Sounds/Weapons/SMG/V2Local2.opus");
|
||||
@fireSounds[2] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/FireLocal3.opus");
|
||||
("Sounds/Weapons/SMG/V2Local3.opus");
|
||||
@fireSounds[3] = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/FireLocal4.opus");
|
||||
("Sounds/Weapons/SMG/V2Local4.opus");
|
||||
@fireFarSound = dev.RegisterSound
|
||||
("Sounds/Weapons/SMG/FireFar.opus");
|
||||
@fireStereoSound = dev.RegisterSound
|
||||
@ -79,11 +99,12 @@
|
||||
param.volume = 8.f;
|
||||
audioDevice.PlayLocal(fireSounds[GetRandom(fireSounds.length)], origin, param);
|
||||
|
||||
param.volume = 4.f;
|
||||
audioDevice.PlayLocal(fireFarSound, origin, param);
|
||||
param.volume = 1.f;
|
||||
audioDevice.PlayLocal(fireStereoSound, origin, param);
|
||||
|
||||
param.volume = 8.f * ambienceRoom;
|
||||
if (ambienceSize < 0.5f) {
|
||||
audioDevice.PlayLocal(fireSmallReverbSounds[GetRandom(fireSmallReverbSounds.length)], origin, param);
|
||||
} else {
|
||||
audioDevice.PlayLocal(fireLargeReverbSounds[GetRandom(fireLargeReverbSounds.length)], origin, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
namespace spades {
|
||||
class ThirdPersonShotgunSkin:
|
||||
IToolSkin, IThirdPersonToolSkin, IWeaponSkin {
|
||||
IToolSkin, IThirdPersonToolSkin, IWeaponSkin, IWeaponSkin2 {
|
||||
private float sprintState;
|
||||
private float raiseState;
|
||||
private Vector3 teamColor;
|
||||
@ -32,6 +32,10 @@
|
||||
private float reloadProgress;
|
||||
private int ammo, clipSize;
|
||||
|
||||
private float ambienceRoom;
|
||||
private float ambienceSize;
|
||||
private float ambienceDistance;
|
||||
|
||||
float SprintState {
|
||||
set { sprintState = value; }
|
||||
}
|
||||
@ -77,6 +81,13 @@
|
||||
set { readyState = value; }
|
||||
}
|
||||
|
||||
// IWeaponSkin2
|
||||
void SetSoundAmbience(float room, float size, float distance) {
|
||||
ambienceRoom = room;
|
||||
ambienceSize = size;
|
||||
ambienceDistance = distance;
|
||||
}
|
||||
|
||||
private Renderer@ renderer;
|
||||
private AudioDevice@ audioDevice;
|
||||
private Model@ model;
|
||||
@ -84,6 +95,8 @@
|
||||
private AudioChunk@ fireSound;
|
||||
private AudioChunk@ fireFarSound;
|
||||
private AudioChunk@ fireStereoSound;
|
||||
private AudioChunk@ fireSmallReverbSound;
|
||||
private AudioChunk@ fireLargeReverbSound;
|
||||
private AudioChunk@ reloadSound;
|
||||
private AudioChunk@ cockSound;
|
||||
|
||||
@ -103,6 +116,11 @@
|
||||
("Sounds/Weapons/Shotgun/Reload.opus");
|
||||
@cockSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Shotgun/Cock.opus");
|
||||
|
||||
@fireSmallReverbSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Shotgun/V2AmbienceSmall.opus");
|
||||
@fireLargeReverbSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Shotgun/V2AmbienceLarge.opus");
|
||||
}
|
||||
|
||||
void Update(float dt) {
|
||||
@ -115,11 +133,19 @@
|
||||
param.volume = 8.f;
|
||||
audioDevice.Play(fireSound, origin, param);
|
||||
|
||||
param.volume = 8.f * ambienceRoom;
|
||||
if (ambienceSize < 0.5f) {
|
||||
audioDevice.Play(fireSmallReverbSound, origin, param);
|
||||
} else {
|
||||
audioDevice.Play(fireLargeReverbSound, origin, param);
|
||||
}
|
||||
|
||||
param.volume = 2.f;
|
||||
param.referenceDistance = 4.f;
|
||||
audioDevice.Play(fireFarSound, origin, param);
|
||||
param.referenceDistance = 1.f;
|
||||
audioDevice.Play(fireStereoSound, origin, param);
|
||||
|
||||
}
|
||||
}
|
||||
void ReloadingWeapon() {
|
||||
|
@ -32,6 +32,8 @@
|
||||
private AudioChunk@ fireSound;
|
||||
private AudioChunk@ fireFarSound;
|
||||
private AudioChunk@ fireStereoSound;
|
||||
private AudioChunk@ fireSmallReverbSound;
|
||||
private AudioChunk@ fireLargeReverbSound;
|
||||
private AudioChunk@ reloadSound;
|
||||
private AudioChunk@ cockSound;
|
||||
|
||||
@ -47,7 +49,6 @@
|
||||
@sightModel2 = renderer.RegisterModel
|
||||
("Models/Weapons/Shotgun/Sight2.kv6");
|
||||
|
||||
|
||||
@fireSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Shotgun/FireLocal.opus");
|
||||
@fireFarSound = dev.RegisterSound
|
||||
@ -58,6 +59,11 @@
|
||||
("Sounds/Weapons/Shotgun/ReloadLocal.opus");
|
||||
@cockSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Shotgun/CockLocal.opus");
|
||||
|
||||
@fireSmallReverbSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Shotgun/V2AmbienceSmall.opus");
|
||||
@fireLargeReverbSound = dev.RegisterSound
|
||||
("Sounds/Weapons/Shotgun/V2AmbienceLarge.opus");
|
||||
}
|
||||
|
||||
void Update(float dt) {
|
||||
@ -73,6 +79,13 @@
|
||||
param.volume = 8.f;
|
||||
audioDevice.PlayLocal(fireSound, origin, param);
|
||||
|
||||
param.volume = 8.f * ambienceRoom;
|
||||
if (ambienceSize < 0.5f) {
|
||||
audioDevice.PlayLocal(fireSmallReverbSound, origin, param);
|
||||
} else {
|
||||
audioDevice.PlayLocal(fireLargeReverbSound, origin, param);
|
||||
}
|
||||
|
||||
param.volume = 2.f;
|
||||
audioDevice.PlayLocal(fireFarSound, origin, param);
|
||||
audioDevice.PlayLocal(fireStereoSound, origin, param);
|
||||
|
@ -18,11 +18,13 @@
|
||||
|
||||
*/
|
||||
|
||||
#include <array>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "CTFGameMode.h"
|
||||
#include "Client.h"
|
||||
#include "ClientPlayer.h"
|
||||
#include "GameMap.h"
|
||||
#include "GunCasing.h"
|
||||
#include "GunCasing.h"
|
||||
#include "IAudioChunk.h"
|
||||
@ -360,12 +362,12 @@ namespace spades {
|
||||
Handle<IAudioChunk> c;
|
||||
switch (player->GetTool()) {
|
||||
case Player::ToolSpade:
|
||||
c =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Spade/RaiseLocal.opus");
|
||||
c = audioDevice->RegisterSound(
|
||||
"Sounds/Weapons/Spade/RaiseLocal.opus");
|
||||
break;
|
||||
case Player::ToolBlock:
|
||||
c =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Block/RaiseLocal.opus");
|
||||
c = audioDevice->RegisterSound(
|
||||
"Sounds/Weapons/Block/RaiseLocal.opus");
|
||||
break;
|
||||
case Player::ToolWeapon:
|
||||
switch (player->GetWeapon()->GetWeaponType()) {
|
||||
@ -1034,6 +1036,91 @@ namespace spades {
|
||||
return client->ShouldRenderInThirdPersonView();
|
||||
}
|
||||
|
||||
struct ClientPlayer::AmbienceInfo {
|
||||
float room;
|
||||
float size;
|
||||
float distance;
|
||||
};
|
||||
|
||||
ClientPlayer::AmbienceInfo ClientPlayer::ComputeAmbience() {
|
||||
float maxDistance = 40.f;
|
||||
GameMap *map = client->map;
|
||||
SPAssert(map);
|
||||
|
||||
// do raycast
|
||||
Vector3 rayFrom = player->GetEye();
|
||||
Vector3 rayTo;
|
||||
std::array<float, 32> distances;
|
||||
std::array<float, 32> feedbacknesses;
|
||||
|
||||
std::fill(feedbacknesses.begin(), feedbacknesses.end(), 0.0f);
|
||||
|
||||
for (std::size_t i = 0; i < distances.size(); ++i) {
|
||||
float &distance = distances[i];
|
||||
float &feedbackness = feedbacknesses[i];
|
||||
|
||||
rayTo.x = GetRandom() - GetRandom();
|
||||
rayTo.y = GetRandom() - GetRandom();
|
||||
rayTo.z = GetRandom() - GetRandom();
|
||||
rayTo = rayTo.Normalize();
|
||||
|
||||
IntVector3 hitPos;
|
||||
bool hit = map->CastRay(rayFrom, rayTo, maxDistance, hitPos);
|
||||
if (hit) {
|
||||
Vector3 hitPosf = {(float)hitPos.x, (float)hitPos.y, (float)hitPos.z};
|
||||
distance = (hitPosf - rayFrom).GetLength();
|
||||
} else {
|
||||
distance = maxDistance * 2.f;
|
||||
}
|
||||
|
||||
if (hit) {
|
||||
bool hit2 = map->CastRay(rayFrom, -rayTo, maxDistance, hitPos);
|
||||
if (hit2)
|
||||
feedbackness = 1.f;
|
||||
else
|
||||
feedbackness = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
// monte-carlo integration
|
||||
unsigned int rayHitCount = 0;
|
||||
float roomSize = 0.f;
|
||||
float feedbackness = 0.f;
|
||||
|
||||
for (float dist : distances) {
|
||||
if (dist < maxDistance) {
|
||||
rayHitCount++;
|
||||
roomSize += dist;
|
||||
}
|
||||
}
|
||||
for (float fb : feedbacknesses) {
|
||||
feedbackness += fb;
|
||||
}
|
||||
|
||||
float reflections;
|
||||
if (rayHitCount > distances.size() / 4) {
|
||||
roomSize /= (float)rayHitCount;
|
||||
reflections = (float)rayHitCount / (float)distances.size();
|
||||
} else {
|
||||
reflections = 0.1f;
|
||||
roomSize = 100.f;
|
||||
}
|
||||
|
||||
feedbackness /= (float)distances.size();
|
||||
feedbackness = std::min(std::max(0.0f, feedbackness - 0.2f) / 0.6f, 1.0f);
|
||||
|
||||
const SceneDefinition &lastSceneDef = client->GetLastSceneDef();
|
||||
|
||||
AmbienceInfo result;
|
||||
result.room = reflections * feedbackness;
|
||||
result.distance = (lastSceneDef.viewOrigin - player->GetEye()).GetLength();
|
||||
result.size = std::max(std::min(roomSize / 15.0f, 1.0f), 0.0f);
|
||||
result.room *= std::max(0.0f, std::min((result.size - 0.1f) * 4.0f, 1.0f));
|
||||
result.room *= 1.0f - result.size * 0.3f;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void ClientPlayer::FiredWeapon() {
|
||||
World *world = player->GetWorld();
|
||||
Vector3 muzzle;
|
||||
@ -1067,7 +1154,8 @@ namespace spades {
|
||||
snd =
|
||||
(mt_engine_client() & 0x1000)
|
||||
? audioDevice->RegisterSound("Sounds/Weapons/Rifle/ShellDrop1.opus")
|
||||
: audioDevice->RegisterSound("Sounds/Weapons/Rifle/ShellDrop2.opus");
|
||||
: audioDevice->RegisterSound(
|
||||
"Sounds/Weapons/Rifle/ShellDrop2.opus");
|
||||
snd2 =
|
||||
audioDevice->RegisterSound("Sounds/Weapons/Rifle/ShellWater.opus");
|
||||
break;
|
||||
@ -1104,6 +1192,9 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
// sound ambience estimation
|
||||
auto ambience = ComputeAmbience();
|
||||
|
||||
asIScriptObject *skin;
|
||||
// FIXME: what if current tool isn't weapon?
|
||||
if (ShouldRenderInThirdPersonView()) {
|
||||
@ -1112,6 +1203,13 @@ namespace spades {
|
||||
skin = weaponViewSkin;
|
||||
}
|
||||
|
||||
{
|
||||
ScriptIWeaponSkin2 interface(skin);
|
||||
if (interface.ImplementsInterface()) {
|
||||
interface.SetSoundAmbience(ambience.room, ambience.size, ambience.distance);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ScriptIWeaponSkin interface(skin);
|
||||
interface.WeaponFired();
|
||||
|
@ -72,6 +72,9 @@ namespace spades {
|
||||
void SetSkinParameterForTool(Player::ToolType, asIScriptObject *);
|
||||
void SetCommonSkinParameter(asIScriptObject *);
|
||||
|
||||
struct AmbienceInfo;
|
||||
AmbienceInfo ComputeAmbience();
|
||||
|
||||
float GetLocalFireVibration();
|
||||
|
||||
bool ShouldRenderInThirdPersonView();
|
||||
|
@ -25,7 +25,15 @@
|
||||
namespace spades{
|
||||
namespace client {
|
||||
ScriptIWeaponSkin::ScriptIWeaponSkin(asIScriptObject *obj):
|
||||
obj(obj){}
|
||||
obj(obj) {
|
||||
SPAssert(obj);
|
||||
SPAssert(obj->GetObjectType());
|
||||
}
|
||||
|
||||
bool ScriptIWeaponSkin::ImplementsInterface()
|
||||
{
|
||||
return obj->GetObjectType()->Implements(obj->GetEngine()->GetTypeInfoByName("IWeaponSkin"));
|
||||
}
|
||||
|
||||
void ScriptIWeaponSkin::SetReadyState(float v) {
|
||||
SPADES_MARK_FUNCTION_DEBUG();
|
||||
@ -137,7 +145,35 @@ namespace spades{
|
||||
ScriptManager::CheckError(r);
|
||||
ctx.ExecuteChecked();
|
||||
}
|
||||
|
||||
|
||||
ScriptIWeaponSkin2::ScriptIWeaponSkin2(asIScriptObject *obj):
|
||||
obj(obj) {
|
||||
SPAssert(obj);
|
||||
SPAssert(obj->GetObjectType());
|
||||
}
|
||||
|
||||
bool ScriptIWeaponSkin2::ImplementsInterface()
|
||||
{
|
||||
return obj->GetObjectType()->Implements(obj->GetEngine()->GetTypeInfoByName("IWeaponSkin2"));
|
||||
}
|
||||
|
||||
void ScriptIWeaponSkin2::SetSoundAmbience(float room, float size, float distance) {
|
||||
SPADES_MARK_FUNCTION_DEBUG();
|
||||
static ScriptFunction func("IWeaponSkin2",
|
||||
"void SetSoundAmbience(float, float, float)");
|
||||
ScriptContextHandle ctx = func.Prepare();
|
||||
int r;
|
||||
r = ctx->SetObject((void *)obj);
|
||||
ScriptManager::CheckError(r);
|
||||
r = ctx->SetArgFloat(0, room);
|
||||
ScriptManager::CheckError(r);
|
||||
r = ctx->SetArgFloat(1, size);
|
||||
ScriptManager::CheckError(r);
|
||||
r = ctx->SetArgFloat(2, distance);
|
||||
ScriptManager::CheckError(r);
|
||||
ctx.ExecuteChecked();
|
||||
}
|
||||
|
||||
class IWeaponSkinRegistrar: public ScriptObjectRegistrar {
|
||||
public:
|
||||
IWeaponSkinRegistrar():
|
||||
@ -152,6 +188,8 @@ namespace spades{
|
||||
case PhaseObjectType:
|
||||
r = eng->RegisterInterface("IWeaponSkin");
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterInterface("IWeaponSkin2");
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
case PhaseObjectMember:
|
||||
r = eng->RegisterInterfaceMethod("IWeaponSkin",
|
||||
@ -181,9 +219,12 @@ namespace spades{
|
||||
r = eng->RegisterInterfaceMethod("IWeaponSkin",
|
||||
"void ReloadedWeapon()");
|
||||
manager->CheckError(r);
|
||||
|
||||
r = eng->RegisterInterfaceMethod("IWeaponSkin2",
|
||||
"void SetSoundAmbience(float, float, float)");
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ namespace spades {
|
||||
asIScriptObject *obj;
|
||||
public:
|
||||
ScriptIWeaponSkin(asIScriptObject *obj);
|
||||
bool ImplementsInterface();
|
||||
void SetReadyState(float);
|
||||
void SetAimDownSightState(float);
|
||||
void SetReloading(bool);
|
||||
@ -40,5 +41,13 @@ namespace spades {
|
||||
void ReloadingWeapon();
|
||||
void ReloadedWeapon();
|
||||
};
|
||||
|
||||
class ScriptIWeaponSkin2 {
|
||||
asIScriptObject *obj;
|
||||
public:
|
||||
ScriptIWeaponSkin2(asIScriptObject *obj);
|
||||
bool ImplementsInterface();
|
||||
void SetSoundAmbience(float room, float size, float distance);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user