sound volumes are now read from and saved to config.rc + bugfix

- fixed calling of IMGUIClear() when the view state changed (was previously
	called only when the game state changed)
main
Martin Felis (berta) 2010-11-28 01:13:45 +01:00
parent 33683e817d
commit b8f0ed31e3
9 changed files with 48 additions and 22 deletions

View File

@ -10,6 +10,7 @@ Makefile
start
runtests
run_asteroids
config.rc
./doc/html/*

View File

@ -10,7 +10,7 @@ BEGIN_ENUM(Event)
DECL_ENUM_ELEMENT(EventAccelerateStart),
DECL_ENUM_ELEMENT(EventAccelerateStop),
DECL_ENUM_ELEMENT(EventLevelComplete),
DECL_ENUM_ELEMENT(EventChangeGameState),
DECL_ENUM_ELEMENT(EventChangeViewState),
DECL_ENUM_ELEMENT(EventGameOver),
DECL_ENUM_ELEMENT(EventShipExplode),
DECL_ENUM_ELEMENT(EventPlayerDied),

View File

@ -17,13 +17,13 @@ int Controller::OnInit (int argc, char *argv[]) {
mBindings[SDLK_F8] = "toggleconsole";
mBindings[SDLK_F9] = "set playerspeed 5.0";
Engine::RegisterListener (this, EventChangeGameState);
Engine::RegisterListener (this, EventChangeViewState);
return 0;
}
bool Controller::OnReceiveEvent (const Engine::EventBasePtr &event) {
if (event->mEventType == EventChangeGameState) {
if (event->mEventType == EventChangeViewState) {
IMGUIClear();
}
return false;

View File

@ -374,11 +374,6 @@ void Model::ProceedToNextLevel () {
void Model::SetGameState (const unsigned int &state) {
mLastGameState = mGameState;
Engine::EventBasePtr changegamestate_event (new Engine::EventBase());
changegamestate_event->mEventType = EventChangeGameState;
QueueEvent (changegamestate_event);
mGameState = state;
}

View File

@ -663,22 +663,19 @@ void View::DrawUiHighscore() {
void View::DrawUiOptions() {
DrawPageTitle ("Options");
SelectFont ("console.ttf size=23");
// Enter your name
std::string player_name = GetModel()->GetPlayerName();
Engine::GUI::Label (1, "Effects Volume: ", screen_right * 0.5 - 150, 240);
Engine::GUI::Label (10, "Effects Volume: ", screen_right * 0.5 - 150, 240);
float effects_volume = Engine::GetEffectsVolume();
if (Engine::GUI::VerticalSlider (2, screen_right * 0.5 - 100, 250, 250, 16, 0., 1., effects_volume)) {
if (Engine::GUI::VerticalSlider (1, screen_right * 0.5 - 100, 250, 250, 16, 0., 1., effects_volume)) {
Engine::LogDebug ("Setting effects volume to: %f", effects_volume);
Engine::SetEffectsVolume(effects_volume);
}
Engine::GUI::Label (3, "Music Volume: ", screen_right * 0.5 - 150, 300);
Engine::GUI::Label (11, "Music Volume: ", screen_right * 0.5 - 150, 300);
float music_volume = Engine::GetMusicVolume();
if (Engine::GUI::VerticalSlider (4, screen_right * 0.5 - 100, 310, 250, 16, 0., 1., music_volume)) {
if (Engine::GUI::VerticalSlider (2, screen_right * 0.5 - 100, 310, 250, 16, 0., 1., music_volume)) {
Engine::LogDebug ("Setting music volume to: %f", music_volume);
Engine::SetMusicVolume(music_volume);
}

View File

@ -75,6 +75,11 @@ class View : public Engine::ViewBase {
void PushViewState (const ViewState state) {
Engine::LogDebug ("Pushing ViewState %s", GetStringViewState(state));
mViewStateStack.push(state);
// Fire the view state change event to properly clear the IMGUI state
Engine::EventBasePtr changeviewstate_event (new Engine::EventBase());
changeviewstate_event->mEventType = EventChangeViewState;
QueueEvent (changeviewstate_event);
}
/** \brief Returns the current ViewState */
ViewState GetViewState () {
@ -92,12 +97,22 @@ class View : public Engine::ViewBase {
current_name = GetStringViewState(mViewStateStack.top());
Engine::LogDebug("Popped ViewState: %s current %s remaining: %u", popped_name.c_str(), current_name.c_str(), mViewStateStack.size());
// Fire the view state change event to properly clear the IMGUI state
Engine::EventBasePtr changeviewstate_event (new Engine::EventBase());
changeviewstate_event->mEventType = EventChangeViewState;
QueueEvent (changeviewstate_event);
}
/** \brief Removes all elements of the ViewState stack */
void ResetViewState() {
Engine::LogDebug ("Resetting ViewState stack");
while (mViewStateStack.size())
mViewStateStack.pop();
// Fire the view state change event to properly clear the IMGUI state
Engine::EventBasePtr changeviewstate_event (new Engine::EventBase());
changeviewstate_event->mEventType = EventChangeViewState;
QueueEvent (changeviewstate_event);
}
// \todo [high] add Resource Manager!

View File

@ -44,14 +44,18 @@ int main (int argc, char* argv[]) {
engine.GetView()->SetGridSize (8,8);
dynamic_cast<asteroids::Physics*>(engine.GetPhysics())->SetWorldSize (28, 20);
// run the default commands and load the configuration
Engine::RunCommand ("exec asteroids.rc");
Engine::LogMessage("Warning: muting sound!");
Engine::SetEffectsVolume(0.);
Engine::SetMusicVolume(0.);
Engine::RunCommand ("exec config.rc");
engine.MainLoop ();
// save the configuration
std::ofstream config_file ("config.rc");
config_file << "set effects_volume " << Engine::GetEffectsVolume() << std::endl;
config_file << "set music_volume " << Engine::GetMusicVolume() << std::endl;
config_file.close();
SDL_WM_SetIcon(NULL,NULL);
SDL_FreeSurface (image);

View File

@ -1,4 +1,5 @@
#include "Variables.h"
#include "SoundBaseGlobal.h"
namespace Engine {
@ -8,6 +9,19 @@ bool Cmd_Set (const std::vector<std::string> args) {
return false;
}
// special variable sound_volume
if (args[0] == "effects_volume") {
SetEffectsVolume(atof(args[1].c_str()));
return true;
}
// special variable music_volume
if (args[0] == "music_volume") {
SetMusicVolume(atof(args[1].c_str()));
return true;
}
Variable *test = GetVariable (args[0]);
if (test) {
test->SetStringValue (args[1]);

View File

@ -72,7 +72,6 @@
* todos within the code have a look at the \ref todo.
*
* \todo [high] Create a simple racing or asteroids game
* \todo [high] Enable saving of music and effects volume
* \todo [med] Use shared_ptr instead of raw pointers for the Entities
* \todo [med] Clear all references of EntityVisualState and EntityGameState
* \todo [med] Clarify functionalities of CreateEntity, KillEntity, RegisterEntity, UnregisterEntity (which frees memory, which does only change the state of the Model?)
@ -88,9 +87,10 @@
* Engine::Module::Init()
*
* Done:
* \todo [high] (28-11-2010) Enable saving of music and effects volume
* \todo [high] (28-11-2010) Allow transitions when player dies
* \todo [high] (11-09-2010) Since introduction of the IMGUI pressing 'space' in the menu crashes the game
* - [high] In Physics remove dependancy on the Model to pass on collision
* \todo [high] (11-09-2010) Since introduction of the IMGUI pressing 'space' in the menu crashes the game
* - [high] In Physics remove dependancy on the Model to pass on collision
* events
* - [high] Fix Physics bug when two actors collide actively (i.e. velocity
* towards each other)