(Hopefully) fixes #577
This commit is contained in:
parent
aa1a23477c
commit
8e8f2a8772
@ -47,8 +47,6 @@ namespace spades {
|
||||
get { return muted; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
// IWeaponSkin
|
||||
|
||||
protected float aimDownSightState;
|
||||
@ -139,6 +137,10 @@ namespace spades {
|
||||
environmentRoom = room;
|
||||
environmentSize = size;
|
||||
}
|
||||
// set_SoundOrigin is not called for first-person skin scripts
|
||||
Vector3 SoundOrigin {
|
||||
set { }
|
||||
}
|
||||
|
||||
protected Renderer@ renderer;
|
||||
protected Image@ sightImage;
|
||||
|
@ -35,6 +35,7 @@
|
||||
private float environmentRoom;
|
||||
private float environmentSize;
|
||||
private float environmentDistance;
|
||||
private Vector3 soundOrigin;
|
||||
|
||||
float SprintState {
|
||||
set { sprintState = value; }
|
||||
@ -87,6 +88,9 @@
|
||||
environmentSize = size;
|
||||
environmentDistance = distance;
|
||||
}
|
||||
Vector3 SoundOrigin {
|
||||
set { soundOrigin = value; }
|
||||
}
|
||||
|
||||
private Renderer@ renderer;
|
||||
private AudioDevice@ audioDevice;
|
||||
@ -128,7 +132,7 @@
|
||||
|
||||
void WeaponFired(){
|
||||
if(!muted){
|
||||
Vector3 origin = originMatrix * Vector3(0.f, 0.f, 0.f);
|
||||
Vector3 origin = soundOrigin;
|
||||
AudioParam param;
|
||||
param.volume = 20.f;
|
||||
audioDevice.Play(fireSounds[GetRandom(fireSounds.length)], origin, param);
|
||||
@ -151,7 +155,7 @@
|
||||
|
||||
void ReloadingWeapon() {
|
||||
if(!muted){
|
||||
Vector3 origin = originMatrix * Vector3(0.f, 0.f, 0.f);
|
||||
Vector3 origin = soundOrigin;
|
||||
AudioParam param;
|
||||
param.volume = 0.2f;
|
||||
audioDevice.Play(reloadSound, origin, param);
|
||||
|
@ -35,6 +35,7 @@
|
||||
private float environmentRoom;
|
||||
private float environmentSize;
|
||||
private float environmentDistance;
|
||||
private Vector3 soundOrigin;
|
||||
|
||||
float SprintState {
|
||||
set { sprintState = value; }
|
||||
@ -87,6 +88,9 @@
|
||||
environmentSize = size;
|
||||
environmentDistance = distance;
|
||||
}
|
||||
Vector3 SoundOrigin {
|
||||
set { soundOrigin = value; }
|
||||
}
|
||||
|
||||
private Renderer@ renderer;
|
||||
private AudioDevice@ audioDevice;
|
||||
@ -147,7 +151,7 @@
|
||||
|
||||
void WeaponFired(){
|
||||
if(!muted){
|
||||
Vector3 origin = originMatrix * Vector3(0.f, 0.f, 0.f);
|
||||
Vector3 origin = soundOrigin;
|
||||
AudioParam param;
|
||||
param.volume = 9.f;
|
||||
audioDevice.Play(fireMediumSounds[GetRandom(fireMediumSounds.length)], origin, param);
|
||||
@ -170,7 +174,7 @@
|
||||
}
|
||||
void ReloadingWeapon() {
|
||||
if(!muted){
|
||||
Vector3 origin = originMatrix * Vector3(0.f, 0.f, 0.f);
|
||||
Vector3 origin = soundOrigin;
|
||||
AudioParam param;
|
||||
param.volume = 0.2f;
|
||||
audioDevice.Play(reloadSound, origin, param);
|
||||
|
@ -35,6 +35,7 @@
|
||||
private float environmentRoom;
|
||||
private float environmentSize;
|
||||
private float environmentDistance;
|
||||
private Vector3 soundOrigin;
|
||||
|
||||
float SprintState {
|
||||
set { sprintState = value; }
|
||||
@ -87,6 +88,9 @@
|
||||
environmentSize = size;
|
||||
environmentDistance = distance;
|
||||
}
|
||||
Vector3 SoundOrigin {
|
||||
set { soundOrigin = value; }
|
||||
}
|
||||
|
||||
private Renderer@ renderer;
|
||||
private AudioDevice@ audioDevice;
|
||||
@ -128,7 +132,7 @@
|
||||
|
||||
void WeaponFired(){
|
||||
if(!muted){
|
||||
Vector3 origin = originMatrix * Vector3(0.f, 0.f, 0.f);
|
||||
Vector3 origin = soundOrigin;
|
||||
AudioParam param;
|
||||
param.volume = 8.f;
|
||||
audioDevice.Play(fireSound, origin, param);
|
||||
@ -150,7 +154,7 @@
|
||||
}
|
||||
void ReloadingWeapon() {
|
||||
if(!muted){
|
||||
Vector3 origin = originMatrix * Vector3(0.f, 0.f, 0.f);
|
||||
Vector3 origin = soundOrigin;
|
||||
AudioParam param;
|
||||
param.volume = 0.2f;
|
||||
audioDevice.Play(reloadSound, origin, param);
|
||||
|
@ -211,7 +211,7 @@ namespace spades {
|
||||
|
||||
al::qalSourcef(handle, AL_PITCH, param.pitch);
|
||||
ALCheckErrorPrecise();
|
||||
al::qalSourcef(handle, AL_GAIN, param.volume * (float)s_gain);
|
||||
al::qalSourcef(handle, AL_GAIN, param.volume * std::max<float>(std::min<float>(s_gain, 4.0f), 0.0f));
|
||||
ALCheckErrorPrecise();
|
||||
al::qalSourcef(handle, AL_REFERENCE_DISTANCE, param.referenceDistance);
|
||||
|
||||
|
@ -555,7 +555,7 @@ namespace spades {
|
||||
YsrContext::PlayParam param;
|
||||
param.pitch = base.pitch;
|
||||
param.referenceDistance = base.referenceDistance;
|
||||
param.volume = base.volume * (float)s_gain;
|
||||
param.volume = base.volume * std::max<float>(std::min<float>(s_gain, 4.0f), 0.0f);
|
||||
return param;
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ namespace spades {
|
||||
float ScreenHeight() { return base->ScreenHeight(); }
|
||||
};
|
||||
|
||||
ClientPlayer::ClientPlayer(Player *p, Client *c) : player(p), client(c) {
|
||||
ClientPlayer::ClientPlayer(Player *p, Client *c) : player(p), client(c), hasValidOriginMatrix(false) {
|
||||
SPADES_MARK_FUNCTION();
|
||||
|
||||
sprintState = 0.f;
|
||||
@ -951,6 +951,8 @@ namespace spades {
|
||||
interface.AddToScene();
|
||||
}
|
||||
|
||||
hasValidOriginMatrix = true;
|
||||
|
||||
// draw intel in ctf
|
||||
IGameMode *mode = world->GetMode();
|
||||
if (mode && IGameMode::m_CTF == mode->ModeType()) {
|
||||
@ -984,6 +986,8 @@ namespace spades {
|
||||
Player *p = player;
|
||||
const SceneDefinition &lastSceneDef = client->GetLastSceneDef();
|
||||
|
||||
hasValidOriginMatrix = false;
|
||||
|
||||
if (p->GetTeamId() >= 2) {
|
||||
// spectator, or dummy player
|
||||
return;
|
||||
@ -1237,6 +1241,11 @@ namespace spades {
|
||||
ScriptIWeaponSkin2 interface(skin);
|
||||
if (interface.ImplementsInterface()) {
|
||||
interface.SetSoundEnvironment(ambience.room, ambience.size, ambience.distance);
|
||||
interface.SetSoundOrigin(player->GetEye());
|
||||
} else if (ShouldRenderInThirdPersonView() && !hasValidOriginMatrix) {
|
||||
// Legacy skin scripts rely on OriginMatrix which is only updated when
|
||||
// the player's location is within the fog range.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1255,6 +1264,21 @@ namespace spades {
|
||||
skin = weaponViewSkin;
|
||||
}
|
||||
|
||||
// sound ambience estimation
|
||||
auto ambience = ComputeAmbience();
|
||||
|
||||
{
|
||||
ScriptIWeaponSkin2 interface(skin);
|
||||
if (interface.ImplementsInterface()) {
|
||||
interface.SetSoundEnvironment(ambience.room, ambience.size, ambience.distance);
|
||||
interface.SetSoundOrigin(player->GetEye());
|
||||
} else if (ShouldRenderInThirdPersonView() && !hasValidOriginMatrix) {
|
||||
// Legacy skin scripts rely on OriginMatrix which is only updated when
|
||||
// the player's location is within the fog range.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ScriptIWeaponSkin interface(skin);
|
||||
interface.ReloadingWeapon();
|
||||
|
@ -50,6 +50,12 @@ namespace spades {
|
||||
float localFireVibrationTime;
|
||||
float time;
|
||||
|
||||
/**
|
||||
* Indicates whether the third-person weapon skin script has the latest
|
||||
* value of `OriginMatrix`.
|
||||
*/
|
||||
bool hasValidOriginMatrix;
|
||||
|
||||
Vector3 viewWeaponOffset;
|
||||
|
||||
Vector3 lastFront;
|
||||
|
@ -174,6 +174,19 @@ namespace spades{
|
||||
ctx.ExecuteChecked();
|
||||
}
|
||||
|
||||
void ScriptIWeaponSkin2::SetSoundOrigin(Vector3 origin) {
|
||||
SPADES_MARK_FUNCTION_DEBUG();
|
||||
static ScriptFunction func("IWeaponSkin2",
|
||||
"void set_SoundOrigin(Vector3)");
|
||||
ScriptContextHandle ctx = func.Prepare();
|
||||
int r;
|
||||
r = ctx->SetObject((void *)obj);
|
||||
ScriptManager::CheckError(r);
|
||||
r = ctx->SetArgObject(0, &origin);
|
||||
ScriptManager::CheckError(r);
|
||||
ctx.ExecuteChecked();
|
||||
}
|
||||
|
||||
class IWeaponSkinRegistrar: public ScriptObjectRegistrar {
|
||||
public:
|
||||
IWeaponSkinRegistrar():
|
||||
@ -222,6 +235,8 @@ namespace spades{
|
||||
|
||||
r = eng->RegisterInterfaceMethod("IWeaponSkin2",
|
||||
"void SetSoundEnvironment(float, float, float)");
|
||||
r = eng->RegisterInterfaceMethod("IWeaponSkin2",
|
||||
"void set_SoundOrigin(Vector3)");
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
default:
|
||||
|
@ -48,6 +48,7 @@ namespace spades {
|
||||
ScriptIWeaponSkin2(asIScriptObject *obj);
|
||||
bool ImplementsInterface();
|
||||
void SetSoundEnvironment(float room, float size, float distance);
|
||||
void SetSoundOrigin(Vector3);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user