mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 10:22:52 +01:00
Add city.wav
This commit is contained in:
parent
441109bc99
commit
538d0c02f9
28
rwengine/include/audio/SoundManager.hpp
Normal file
28
rwengine/include/audio/SoundManager.hpp
Normal 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;
|
||||
|
||||
};
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
@ -280,6 +286,9 @@ public:
|
||||
const std::vector<AreaIndicatorInfo>& getAreaIndicators() const { return areaIndicators; }
|
||||
|
||||
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
|
||||
|
41
rwengine/src/audio/SoundManager.cpp
Normal file
41
rwengine/src/audio/SoundManager.cpp
Normal 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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user