Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvesound #93

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add the position of the sound source while triggering all the sounds.…
… This is more realistic and also consumes better the available resources.
  • Loading branch information
faturita committed Oct 4, 2023
commit a7245f874bc718bb5d9d66e8014b464afe1f9f7a
4 changes: 2 additions & 2 deletions src/carrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void drawHUD()
static int coun=0;
if (int((enemy).magnitude()) <= coun++ )
{
radarbeep();
radarbeep(v->getPos());
coun=0;
}

Expand Down Expand Up @@ -1238,8 +1238,8 @@ void update(int value)

if (entities[i]->getType() != VehicleTypes::WEAPON)
{
explosion();
Vec3f loc = entities[i]->getPos();
explosion(loc);

Explosion* b1 = new Explosion();
b1->init();
Expand Down
10 changes: 5 additions & 5 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,8 @@ void waterexplosion(Vehicle* v, dWorldID world, dSpaceID space)
{
if (dGeomIsEnabled(v->getGeom()))
{
splash();
Vec3f loc = v->getPos();
splash(loc);

Explosion* b1 = new Explosion();
b1->init();
Expand All @@ -583,8 +583,8 @@ void groundexplosion(Vehicle* v, dWorldID world, dSpaceID space)
{
if (dGeomIsEnabled(v->getGeom()))
{
explosion();
Vec3f loc = v->getPos();
explosion(loc);

Explosion* b1 = new Explosion();
b1->init();
Expand Down Expand Up @@ -1504,7 +1504,7 @@ void defendIsland(unsigned long timer, dSpaceID space, dWorldID world)
if (action != NULL)
{
size_t l = entities.push_at_the_back(action,action->getGeom());
gunshot();
gunshot(lb->getPos());

action->goTo(target->getPos());
action->enableAuto();
Expand Down Expand Up @@ -1950,7 +1950,7 @@ Manta* launchManta(Vehicle *v)
sprintf(msg, "%s has been launched.", m->getName().c_str());
mg.msg = std::string(msg);
messages.insert(messages.begin(), mg);
takeoff();
takeoff(m->getPos());
}
return m;
} else if (v->getType() == LANDINGABLE)
Expand All @@ -1972,7 +1972,7 @@ Manta* launchManta(Vehicle *v)
sprintf(msg, "%s is departing from %s.", m->getName().c_str(), is->getName().c_str());
mg.msg = std::string(msg);
messages.insert(messages.begin(), mg);
takeoff();
takeoff(m->getPos());
}
return m;
}
Expand Down
3 changes: 3 additions & 0 deletions src/math/yamathutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
#include <math.h>
#include "vec3f.h"

#ifndef PI
#define PI 3.1415926536
#endif


#ifndef M_PI
#define M_PI (3.14159265358979323846)
Expand Down
208 changes: 74 additions & 134 deletions src/sounds/sounds.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "sounds.h"

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Expand All @@ -9,6 +7,12 @@

#include "soundtexture.h"

#include "sounds.h"

#include "../camera.h"


extern Camera Camera;
extern bool mute;

//std::unordered_map<std::string, SoundTexture*> soundtextures;
Expand Down Expand Up @@ -39,12 +43,19 @@ void playsound(char *filename)
system(temp);
}

void bullethit()

void playthissound(char fl[256])
{
try {
if (!mute && s.done) {
if (!mute) {
while (!s.done)
{
s.interrupt = true;
Stk::sleep( 1 );
}
//static SoundTexture s;
s.init("sounds/bullethit.wav");
s.init(fl);
s.amplitude = 1.0;
s.play();
}
} catch (StkError) {
Expand All @@ -53,179 +64,108 @@ void bullethit()

}

void playthissound(Vec3f source, char fl[256])
{
try {
if (!mute) {
Vec3f dist = source - Camera.pos;
if (dist.magnitude()<1000.0)
{
StkFloat amplitude = 1000.0-dist.magnitude() / 1000.0;
amplitude = 1.0;
while (!s.done)
{
s.interrupt = true;
Stk::sleep( 1 );
}
//static SoundTexture s;
s.init(fl);
s.amplitude = amplitude;
s.play();
}
}
} catch (StkError) {

}

}




void firesound(int times)
{
for(int i=0;i<times;i++)
printf ("%c", 7);

}

void smallenginestart()
void bullethit(Vec3f source)
{
try {
if (!mute && s.done) {
//static SoundTexture s;
s.init("sounds/boozing.wav");
s.play();
}
} catch (StkError) {

}
playthissound(source,"sounds/bullethit.wav");
}

void enginestart()
void smallenginestart(Vec3f source)
{
try {
if (!mute && s.done) {
//static SoundTexture s;
s.init("sounds/cruise.wav");
s.play();
}
} catch (StkError) {

}
playthissound(source,"sounds/boozing.wav");
}

void takeoff()
void enginestart(Vec3f source)
{
try {
if (!mute && s.done)
{
//static SoundTexture s;
s.init("sounds/takeoff.wav");
s.play();
}
} catch (StkError) {

}
playthissound(source,"sounds/cruise.wav");
}

void explosion()
void takeoff(Vec3f source)
{
try {
if (!mute && s.done) {
//static SoundTexture s;
s.init("sounds/explosion.wav");
s.play();
}
} catch (StkError) {

}
playthissound(source,"sounds/takeoff.wav");
}

void radarbeep()
void explosion(Vec3f source)
{
try {
if (!mute && s.done) {
//static SoundTexture s;
s.init("sounds/radarbeep.wav");
s.play();
}
} catch (StkError) {

}
playthissound(source,"sounds/explosion.wav");
}

void splash()
void radarbeep(Vec3f source)
{
try {
if (!mute && s.done) {
//static SoundTexture s;
s.init("sounds/splash.wav");
s.play();
}
} catch (StkError) {

}
playthissound(source,"sounds/radarbeep.wav");
}

void coast()
void splash(Vec3f source)
{
try {
if (!mute && s.done) {
//static SoundTexture s;
s.init("sounds/coast.wav");
s.play();
}
} catch (StkError) {

}
playthissound(source,"sounds/splash.wav");
}

void honk()
void coast(Vec3f source)
{
try {
if (!mute && s.done) {
//static SoundTexture s;
s.init("sounds/boathonk.wav");
s.play();
}
} catch (StkError) {

}
playthissound(source,"sounds/coast.wav");
}

void soaring()
void honk(Vec3f source)
{
try {
if (!mute && s.done) {
//static SoundTexture s;
s.init("sounds/soaring.wav");
s.play();
}
} catch (StkError) {

}
playthissound(source,"sounds/boathonk.wav");
}

void gunshot()
void soaring(Vec3f source)
{
try {
if (!mute && s.done) {
//static SoundTexture s;
s.init("sounds/gunshot.wav");
s.play();
}
} catch (StkError) {

}
playthissound(source,"sounds/soaring.wav");
}

void artilleryshot()
void gunshot(Vec3f source)
{
try {
if (!mute && s.done) {
//static SoundTexture s;
s.init("sounds/artillery.wav");
s.play();
}
} catch (StkError) {

}
playthissound(source,"sounds/gunshot.wav");
}

void droneflying()
void artilleryshot(Vec3f source)
{
try {
if (!mute && s.done) {
//static SoundTexture s;
s.init("sounds/cephalopod.wav");
s.play();
}
} catch (StkError) {
playthissound(source,"sounds/artillery.wav");
}

}
void droneflying(Vec3f source)
{
playthissound(source,"sounds/cephalopod.wav");
}

void intro()
{
try {
if (!mute && s.done) {
//static SoundTexture s;
s.init("sounds/intro.wav");
s.play();
}
} catch (StkError) {

}
playthissound( "sounds/intro.wav");
}
28 changes: 15 additions & 13 deletions src/sounds/sounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@
#include <GLUT/glut.h>
#endif

#include "../math/yamathutil.h"


void initSound();
void clearSound();

void firesound(int times);
void enginestart();
void takeoff();
void explosion();
void splash();
void honk();
void gunshot();
void artilleryshot();
void smallenginestart();
void soaring();
void bullethit();
void droneflying();

void radarbeep();
void enginestart(Vec3f source);
void takeoff(Vec3f source);
void explosion(Vec3f source);
void splash(Vec3f source);
void honk(Vec3f source);
void gunshot(Vec3f source);
void artilleryshot(Vec3f source);
void smallenginestart(Vec3f source);
void soaring(Vec3f source);
void bullethit(Vec3f source);
void droneflying(Vec3f source);

void radarbeep(Vec3f source);

void intro();

Expand Down
Loading