-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
EFX spawnarg for location entities #2
base: trunk
Are you sure you want to change the base?
Changes from 6 commits
c5b3c98
4f25156
d6fad86
2d0e04d
b843b61
5f6d3cc
770c514
2425cf8
756a142
9acbcaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup /> | ||
</Project> | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ static inline ALfloat _mB_to_gain(ALfloat millibels, ALfloat min, ALfloat max) { | |
} | ||
|
||
idSoundEffect::idSoundEffect() : | ||
effect(0) { | ||
effect(0) { | ||
} | ||
|
||
idSoundEffect::~idSoundEffect() { | ||
|
@@ -104,6 +104,19 @@ bool idEFXFile::FindEffect(idStr &name, ALuint *effect) { | |
return false; | ||
} | ||
|
||
bool idEFXFile::GetEffect(idStr& name, idSoundEffect *soundEffect) { | ||
int i; | ||
|
||
for (i = 0; i < effects.Num(); i++) { | ||
if (effects[i]->name.Icmp(name) == 0) { | ||
*soundEffect = *effects[i]; | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
#define efxi(param, value) \ | ||
do { \ | ||
ALint _v = value; \ | ||
|
@@ -252,6 +265,96 @@ bool idEFXFile::ReadEffectLegacy(idLexer &src, idSoundEffect *effect) { | |
return true; | ||
} | ||
|
||
bool idEFXFile::AddOrUpdatePreset(idStr areaName, idStr efxPreset, ALuint* effect) { | ||
|
||
idSoundEffect* soundEffect = new idSoundEffect; | ||
|
||
//ALuint effect = AL_EFFECTSLOT_NULL; | ||
const bool found = GetEffect(areaName, soundEffect); | ||
ALenum err{}; | ||
bool ok; | ||
|
||
if (!found) { | ||
|
||
// we need to add this preset | ||
|
||
if (!soundEffect->alloc()) { | ||
delete soundEffect; | ||
Clear(); | ||
return false; | ||
} | ||
|
||
soundEffect->name = areaName; | ||
|
||
//ALenum err{}; | ||
bool ok; | ||
ok = AddPreset(efxPreset, soundEffect, err); | ||
|
||
if (!ok) { | ||
return false; | ||
} | ||
|
||
effects.Append(soundEffect); | ||
} | ||
else { | ||
ok = AddPreset(efxPreset, soundEffect, err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why both cases call AddPreset. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Presets can be used by either the EFX file or the spawnarg, so instead of duplicating the code I refactored it into a new function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry ignore my last comment - I understand what you mean now. I've gone back and refactored it, it should look better now. |
||
|
||
if (!ok) { | ||
return false; | ||
} | ||
} | ||
|
||
*effect = soundEffect->effect; | ||
return true; | ||
} | ||
|
||
bool idEFXFile::AddPreset(idStr preset, idSoundEffect* effect, ALenum err) { | ||
|
||
const EFXEAXREVERBPROPERTIES* props = NULL; | ||
int k = 0; | ||
for (k = 0; efxPresets[k].name[0]; k++) | ||
if (efxPresets[k].name == preset) { | ||
props = &efxPresets[k].props; | ||
break; | ||
} | ||
|
||
// Reference the preset by index instead of name. | ||
if (!props && idStr::IsNumeric(preset)) { | ||
int idx = atoi(preset); | ||
if (idx >= 0 && idx < k) | ||
props = &efxPresets[idx].props; | ||
} | ||
if (!props) { | ||
//src.Error("idEFXFile::ReadEffect: Unknown preset name %s", token.c_str()); | ||
return false; | ||
} | ||
|
||
efxf(AL_EAXREVERB_DENSITY, props->flDensity); | ||
efxf(AL_EAXREVERB_DIFFUSION, props->flDiffusion); | ||
efxf(AL_EAXREVERB_GAIN, props->flGain); | ||
efxf(AL_EAXREVERB_GAINHF, props->flGainHF); | ||
efxf(AL_EAXREVERB_GAINLF, props->flGainLF); | ||
efxf(AL_EAXREVERB_DECAY_TIME, props->flDecayTime); | ||
efxf(AL_EAXREVERB_DECAY_HFRATIO, props->flDecayHFRatio); | ||
efxf(AL_EAXREVERB_DECAY_LFRATIO, props->flDecayLFRatio); | ||
efxf(AL_EAXREVERB_REFLECTIONS_GAIN, props->flReflectionsGain); | ||
efxf(AL_EAXREVERB_REFLECTIONS_DELAY, props->flReflectionsDelay); | ||
efxfv(AL_EAXREVERB_REFLECTIONS_PAN, props->flReflectionsPan[0], props->flReflectionsPan[1], props->flReflectionsPan[2]); | ||
efxf(AL_EAXREVERB_LATE_REVERB_GAIN, props->flLateReverbGain); | ||
efxf(AL_EAXREVERB_LATE_REVERB_DELAY, props->flLateReverbDelay); | ||
efxfv(AL_EAXREVERB_LATE_REVERB_PAN, props->flLateReverbPan[0], props->flLateReverbPan[1], props->flLateReverbPan[2]); | ||
efxf(AL_EAXREVERB_ECHO_TIME, props->flEchoTime); | ||
efxf(AL_EAXREVERB_ECHO_DEPTH, props->flEchoDepth); | ||
efxf(AL_EAXREVERB_MODULATION_TIME, props->flModulationTime); | ||
efxf(AL_EAXREVERB_MODULATION_DEPTH, props->flModulationDepth); | ||
efxf(AL_EAXREVERB_AIR_ABSORPTION_GAINHF, props->flAirAbsorptionGainHF); | ||
efxf(AL_EAXREVERB_HFREFERENCE, props->flHFReference); | ||
efxf(AL_EAXREVERB_LFREFERENCE, props->flLFReference); | ||
efxf(AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, props->flRoomRolloffFactor); | ||
efxi(AL_EAXREVERB_DECAY_HFLIMIT, props->iDecayHFLimit); | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like missing return. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
|
||
bool idEFXFile::ReadEffectOpenAL(idLexer &src, idSoundEffect *effect) { | ||
idToken token; | ||
|
||
|
@@ -267,7 +370,7 @@ bool idEFXFile::ReadEffectOpenAL(idLexer &src, idSoundEffect *effect) { | |
if (!src.ExpectTokenString("{")) | ||
return false; | ||
|
||
ALenum err; | ||
ALenum err{}; | ||
alGetError(); | ||
common->Printf("Loading EFX effect for location '%s' (#%u)\n", name.c_str(), effect->effect); | ||
|
||
|
@@ -288,47 +391,9 @@ bool idEFXFile::ReadEffectOpenAL(idLexer &src, idSoundEffect *effect) { | |
return false; | ||
token.ToUpper(); | ||
|
||
const EFXEAXREVERBPROPERTIES *props = NULL; | ||
int k = 0; | ||
for (k = 0; efxPresets[k].name[0]; k++) | ||
if (efxPresets[k].name == token) { | ||
props = &efxPresets[k].props; | ||
break; | ||
} | ||
if (!props && (token.type == TT_NUMBER)) { | ||
int idx = token.GetIntValue(); | ||
if (idx >= 0 && idx < k) | ||
props = &efxPresets[idx].props; | ||
} | ||
if (!props) { | ||
src.Error("idEFXFile::ReadEffect: Unknown preset name %s", token.c_str()); | ||
if (!AddPreset(token, effect, err)) { | ||
return false; | ||
} | ||
|
||
efxf(AL_EAXREVERB_DENSITY, props->flDensity); | ||
efxf(AL_EAXREVERB_DIFFUSION, props->flDiffusion); | ||
efxf(AL_EAXREVERB_GAIN, props->flGain); | ||
efxf(AL_EAXREVERB_GAINHF, props->flGainHF); | ||
efxf(AL_EAXREVERB_GAINLF, props->flGainLF); | ||
efxf(AL_EAXREVERB_DECAY_TIME, props->flDecayTime); | ||
efxf(AL_EAXREVERB_DECAY_HFRATIO, props->flDecayHFRatio); | ||
efxf(AL_EAXREVERB_DECAY_LFRATIO, props->flDecayLFRatio); | ||
efxf(AL_EAXREVERB_REFLECTIONS_GAIN, props->flReflectionsGain); | ||
efxf(AL_EAXREVERB_REFLECTIONS_DELAY, props->flReflectionsDelay); | ||
efxfv(AL_EAXREVERB_REFLECTIONS_PAN, props->flReflectionsPan[0], props->flReflectionsPan[1], props->flReflectionsPan[2]); | ||
efxf(AL_EAXREVERB_LATE_REVERB_GAIN, props->flLateReverbGain); | ||
efxf(AL_EAXREVERB_LATE_REVERB_DELAY, props->flLateReverbDelay); | ||
efxfv(AL_EAXREVERB_LATE_REVERB_PAN, props->flLateReverbPan[0], props->flLateReverbPan[1], props->flLateReverbPan[2]); | ||
efxf(AL_EAXREVERB_ECHO_TIME, props->flEchoTime); | ||
efxf(AL_EAXREVERB_ECHO_DEPTH, props->flEchoDepth); | ||
efxf(AL_EAXREVERB_MODULATION_TIME, props->flModulationTime); | ||
efxf(AL_EAXREVERB_MODULATION_DEPTH, props->flModulationDepth); | ||
efxf(AL_EAXREVERB_AIR_ABSORPTION_GAINHF, props->flAirAbsorptionGainHF); | ||
efxf(AL_EAXREVERB_HFREFERENCE, props->flHFReference); | ||
efxf(AL_EAXREVERB_LFREFERENCE, props->flLFReference); | ||
efxf(AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, props->flRoomRolloffFactor); | ||
efxi(AL_EAXREVERB_DECAY_HFLIMIT, props->iDecayHFLimit); | ||
|
||
} else if ( token == "DENSITY" ) { | ||
efxf(AL_EAXREVERB_DENSITY, src.ParseFloat()); | ||
} else if ( token == "DIFFUSION" ) { | ||
|
@@ -398,7 +463,9 @@ bool idEFXFile::LoadFile( const char *filename/*, bool OSPath*/ ) { | |
efxFilename = filename; | ||
src.LoadFile( filename/*, OSPath*/ ); | ||
if ( !src.IsLoaded() ) { | ||
return false; | ||
|
||
// Just return true if file doesn't exist, as EFX can now be specified on location entities | ||
return true; | ||
} | ||
|
||
if ( !src.ExpectTokenString( "Version" ) ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should not be added to VCS I suppose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed from PR