1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-25 20:02:40 +01:00

Add city.wav

This commit is contained in:
Daniel Evans 2015-02-04 17:16:46 +00:00
parent 441109bc99
commit 538d0c02f9
8 changed files with 117 additions and 7 deletions

View File

@ -0,0 +1,28 @@
#pragma once
#include <vector>
#include <SFML/Audio.hpp>
class SoundManager
{
public:
SoundManager();
void playSound(const std::string& fileName);
bool playBackground(const std::string& fileName);
void pause(bool p);
private:
struct PlayingSound
{
sf::Sound sound;
sf::SoundBuffer buffer;
};
std::vector<PlayingSound> sounds;
sf::SoundStream* backgroundNoise;
};

View File

@ -87,6 +87,14 @@ public:
return "PC";
}
/**
* Returns the game data path
*/
const std::string& getDataPath() const
{
return datpath;
}
/**
* Loads the data contained in the given file
*/

View File

@ -8,6 +8,7 @@
#include <ai/AIGraphNode.hpp>
#include <ai/AIGraph.hpp>
#include <audio/SoundManager.hpp>
class WorkContext;
@ -179,6 +180,11 @@ public:
*/
GameState state;
/**
* State of playing sounds
*/
SoundManager sound;
/**
* Object Definitions
*/
@ -281,6 +287,9 @@ public:
void clearTickData();
void setPaused(bool pause);
bool isPaused() const;
private:
/**
@ -289,6 +298,11 @@ private:
std::queue<GameObject*> deletionQueue;
std::vector<AreaIndicatorInfo> areaIndicators;
/**
* Flag for pausing the simulation
*/
bool paused;
};
#endif

View File

@ -0,0 +1,41 @@
#include <audio/SoundManager.hpp>
#include <audio/MADStream.hpp>
SoundManager::SoundManager()
: backgroundNoise(nullptr)
{
}
bool SoundManager::playBackground(const std::string& fileName)
{
if( backgroundNoise )
{
delete backgroundNoise;
}
sf::Music* bg = new sf::Music;
if( bg->openFromFile( fileName ) )
{
backgroundNoise = bg;
backgroundNoise->setLoop(true);
bg->play();
return true;
}
delete bg;
return false;
}
void SoundManager::pause(bool p)
{
if( p )
{
backgroundNoise->pause();
}
else
{
backgroundNoise->play();
}
}

View File

@ -76,7 +76,8 @@ public:
GameWorld::GameWorld(const std::string& path)
: gameTime(0.f), gameData(path), renderer(this), randomEngine(rand()),
_work( new WorkContext( this ) ), script(nullptr), cutsceneAudio(nullptr), missionAudio(nullptr)
_work( new WorkContext( this ) ), script(nullptr), cutsceneAudio(nullptr), missionAudio(nullptr),
paused(false)
{
gameData.engine = this;
}
@ -807,4 +808,14 @@ void GameWorld::clearTickData()
areaIndicators.clear();
}
void GameWorld::setPaused(bool pause)
{
paused = pause;
sound.pause(pause);
}
bool GameWorld::isPaused() const
{
return paused;
}

View File

@ -125,9 +125,13 @@ int RWGame::run()
while ( accum >= GAME_TIMESTEP ) {
StateManager::get().tick(GAME_TIMESTEP);
if( ! getWorld()->isPaused() )
{
StateManager::get().tick(GAME_TIMESTEP);
tick(GAME_TIMESTEP);
}
tick(GAME_TIMESTEP);
accum -= GAME_TIMESTEP;
}
@ -253,7 +257,7 @@ void RWGame::render(float alpha)
if ( engine->state.isCinematic )
{
float cinematicAspect = 19.f/10.f;
viewCam.frustum.fov *= cinematicAspect / viewCam.frustum.aspectRatio;
viewCam.frustum.fov *= viewCam.frustum.aspectRatio;
}
glEnable(GL_DEPTH_TEST);

View File

@ -9,7 +9,7 @@
#include <objects/ItemPickup.hpp>
#include <render/Model.hpp>
#include <items/WeaponItem.hpp>
#include <boost/concept_check.hpp>
#include <engine/GameWorld.hpp>
#define AUTOLOOK_TIME 2.f
@ -22,6 +22,10 @@ IngameState::IngameState(RWGame* game, bool test)
else {
getWorld()->runScript("data/main.scm");
}
// Start playing city.wav
getWorld()->sound.playBackground( getWorld()->gameData.getDataPath() + "/audio/City.wav" );
}
void IngameState::startTest()

View File

@ -16,12 +16,12 @@ PauseState::PauseState(RWGame* game)
void PauseState::enter()
{
getWorld()->setPaused(true);
}
void PauseState::exit()
{
getWorld()->setPaused(false);
}
void PauseState::tick(float dt)