Skip to content

Commit

Permalink
objects sound play gain
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Dec 17, 2024
1 parent 9d8b054 commit 79acf9e
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 28 deletions.
2 changes: 1 addition & 1 deletion config/presets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ common: sc - "short scenery name" (name color)
<o o="crate_anomaly" s="hud/chkwrong" />
<o o="crate" s="hud/chk" />

<o o="fuel_can" s="mud1" />
<o o="fuel_can" s="water1" />
<o o="garbage_bag_01" s="hud/chk" />
<o o="garbage_bag_02" s="hud/chk" />
<o o="garbage_bin" s="water3" />
Expand Down
6 changes: 4 additions & 2 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ WIP means work in progress, unfinished, still being developed.
- **Effects**, all require (Water) Refractions on, to work
- **SSAO** (ambient occlusion, on Effects tab)
- lens flare (sun glow in camera)
- sunbeams (rays)
- sunbeams (rays), most visible on sunset tracks
- Compositor rewrite, created in code
- SplitScreen uses RTTs, smaller Hud fonts
- Refractions work, SSAO too
Expand All @@ -16,8 +16,10 @@ WIP means work in progress, unfinished, still being developed.
Global Illumination ([GI methods](https://ogrecave.github.io/ogre-next/api/latest/_gi_methods.html): IFD+VCT),
on new Gui tab Advanced after Effects, has also debug visuals.
- Sounds
- New vehicle sounds for: cars WIP, hovercrafts, drones, hovercars
- New turbo sound and gear shift
- WIP ambient track sound (rain, etc)
- WIP dynamic object hit sounds
- WIP dynamic objects hit sounds
- Game
- Setup - Paints tab new *filter* slider, to show paints only from filter rating and above.
But editing paints list must be done w/o filter, on highest value.
Expand Down
5 changes: 4 additions & 1 deletion src/common/data/SceneClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ class Object // 📦 Object - mesh (static🪨) or prop (dynamic)
bool stat = false; // force static, if has .bullet
bool shadow = true;

bool playSound =0; // play
bool playSound =0; // to play ▶️ info
float playGain = 0.f; // to play
bool playing =0; // when playing
float playingGain = 0.f;
std::string sound; // hit 🔉 from presets.xml

Ogre::SceneNode* nd = 0; // 🟢 ogre
Expand Down
8 changes: 5 additions & 3 deletions src/game/Update_Poses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,13 @@ void App::updatePoses(float time)
o.rot[0] = q.x(); o.rot[1] = q.y(); o.rot[2] = q.z(); o.rot[3] = q.w();
o.SetFromBlt();

if (o.playSound) // obj hit snd 🔉
if (o.playSound && // obj hit snd 🔉
(!o.playing || o.playGain > o.playingGain)) // quiet or louder
{ o.playSound =0;
if (pSet->s.snd_dynamic && !o.sound.empty())
pGame->snd->CreateDynamic(o.sound, o.nd);
}
{
pGame->snd->CreateDynamic(o.sound, o.nd, &o, o.playGain);
} }
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/sound/SoundBaseMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
#include "SoundBase.h"
#include "SoundBaseMgr.h"
#include "SoundDynamic.h"
#include "SoundReverbSets.h"
#include "SceneClasses.h"
#include "settings.h"

#include <AL/alc.h>
#include <AL/alext.h>
#include <AL/efx.h>
#include "SoundReverbSets.h"
#include "settings.h"
#include <vector>
using namespace Ogre;
using namespace std;
Expand Down Expand Up @@ -475,6 +477,9 @@ void SoundBaseMgr::Update(float dt)
{
if (!(*it)->isPlaying())
{
if ((*it)->pObj)
(*it)->pObj->playing = 0; // mark object as quiet

// (*it)->stop();
(*it)->Destroy();
it = dynamics.erase(it);
Expand Down
2 changes: 1 addition & 1 deletion src/sound/SoundBaseMgrUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ SoundBase* SoundBaseMgr::createSound(String file, String name)
bool SoundBaseMgr::loadWAVFile(String file, ALuint buffer, int& outSamples)
{
outSamples = 0;
LogO("@ Loading WAV: "+file);
// LogO("@ Loading WAV: "+file);

// create the Stream
std::string path = PATHS::Sounds()+"/"+file;
Expand Down
7 changes: 3 additions & 4 deletions src/sound/SoundDynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void SoundDynamic::seek(float pos) // [0..1)

// 🔉🆕 Create Dynamic Sound
//......................................................................................................
bool SoundDynamic::Create(string file, bool loop1, bool is2d, SceneNode* nd)
bool SoundDynamic::Create(string file, bool loop1, bool is2d, SceneNode* nd, Object* obj)
{
if (enabled)
return false; // already
Expand Down Expand Up @@ -134,9 +134,8 @@ bool SoundDynamic::Create(string file, bool loop1, bool is2d, SceneNode* nd)
}

// setup ----
loop = loop1;
is2D = is2d;
node = nd;
loop = loop1; is2D = is2d;
node = nd; pObj = obj;

if (!is2D)
{
Expand Down
5 changes: 3 additions & 2 deletions src/sound/SoundDynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <OgreString.h>
#include <string>

class SoundBaseMgr;
class SoundBaseMgr; class Object;
namespace Ogre
{ class SceneNode; }

Expand All @@ -19,7 +19,7 @@ class SoundDynamic

public:
SoundDynamic(SoundBaseMgr* sound_mgr1);
bool Create(std::string file, bool loop1=1, bool is2d=1, Ogre::SceneNode* nd=0);
bool Create(std::string file, bool loop1=1, bool is2d=1, Ogre::SceneNode* nd=0, Object* obj=0);
void Destroy();

void Update(float dt);
Expand Down Expand Up @@ -60,5 +60,6 @@ class SoundDynamic
Ogre::Vector3 posOld{0,0,0};
// Ogre::Vector3 vel{0,0,0};

Object* pObj =0;
SoundBaseMgr* sound_mgr =0;
};
5 changes: 3 additions & 2 deletions src/sound/SoundMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include <map>

namespace Ogre { class FileStreamDataStream; class SceneNode; }
class SoundBase; class SoundBaseMgr; class SETTINGS;
class SoundBase; class SoundBaseMgr; class SoundDynamic;
class SETTINGS; class Object;

const int MAX_SOUNDS_PER_SCRIPT = 12; // per 1 template, todo? vector<

Expand Down Expand Up @@ -96,7 +97,7 @@ class SoundMgr
void CreateAmbient(Ogre::String templ);
void DestroyAmbient();

void CreateDynamic(Ogre::String templ, Ogre::SceneNode* node);
SoundDynamic* CreateDynamic(Ogre::String templ, Ogre::SceneNode* node, Object* obj, float gain);


void setPaused(bool mute);
Expand Down
17 changes: 11 additions & 6 deletions src/sound/SoundMgr_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "SoundDynamic.h"
#include "SoundBaseMgr.h"
#include "settings.h"
#include "SceneClasses.h"
#include <OgreDataStream.h>
#include <OgreException.h>
using namespace Ogre;
Expand Down Expand Up @@ -276,27 +277,31 @@ void SoundMgr::DestroyAmbient()
}


// 🆕 New Dynamic 🛢️📦
void SoundMgr::CreateDynamic(String name, Ogre::SceneNode* node)
// 🆕 New Dynamic 🛢️📦 🔉
SoundDynamic* SoundMgr::CreateDynamic(String name, Ogre::SceneNode* node, Object* obj, float gain)
{
// search template
if (templates.find(name) == templates.end())
{
LogO("@ sound dynamic, template not found in .cfg: "+name);
return;
return 0;
}
// LogO("@ sound dynamic create: "+name);

SoundTemplate* templ = templates[name];

auto* dyn = new SoundDynamic(sound_mgr);
bool ok = dyn->Create(templ->start_name, false, false, node);
bool ok = dyn->Create(templ->start_name, false, false, node, obj);
if (!ok)
delete dyn;
{ delete dyn; dyn = 0; }
else
{
dyn->setGain(pSet->s.vol_dynamic);
obj->playing = 1; // mark object
obj->playingGain = gain;

dyn->setGain(pSet->s.vol_dynamic * gain);
dyn->play();
sound_mgr->dynamics.push_back(dyn);
}
return dyn;
}
10 changes: 6 additions & 4 deletions src/vdrift/collision_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ void IntTickCallback(btDynamicsWorld* world, btScalar timeStep)
for (int j=0; j < num; ++j)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
btScalar f = pt.getAppliedImpulse() * timeStep;
if (f > 3.f) // par.. 6` 2-
btScalar frc = pt.getAppliedImpulse() * timeStep;
float gain = std::min(1.f, frc / 4.f); // todo: div by obj mass?..
if (gain > 0.1f) // par <,^
{
sdObj->pObj->playSound =1; // play
LogO("obj hit: "+toStr(i)+" "+toStr(j)+" "+fToStr(f,2,4));
sdObj->pObj->playSound =1; // play if louder
sdObj->pObj->playGain = gain;
// LogO("obj hit: "+toStr(i)+" "+toStr(j)+" "+fToStr(frc,2,4));
} }
}

Expand Down

0 comments on commit 79acf9e

Please sign in to comment.