From 1a4ec6dba125ff405c8bf342e822accd9c26b7ef Mon Sep 17 00:00:00 2001 From: James Turk Date: Tue, 19 Jul 2005 18:35:20 +0000 Subject: [PATCH] audio:: and AudioTest revised --- CHANGELOG.txt | 6 +- CREDITS.txt | 6 +- photon.mm | 145 +++++++++++++++++++++++------- src/AppCore.cpp | 13 ++- src/Application.cpp | 3 +- src/audio/AudioCore.cpp | 10 ++- test/Audio_test.cpp | 193 ++++++++++++++++++++++------------------ 7 files changed, 242 insertions(+), 134 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5261c7e..92ac0f2 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,5 @@ Changelog for Photon -$Id: CHANGELOG.txt,v 1.1 2005/07/17 22:41:03 cozman Exp $ +$Id: CHANGELOG.txt,v 1.2 2005/07/19 18:35:20 cozman Exp $ 0.1.0 (Massachusetts) - Initial Release @@ -11,6 +11,8 @@ $Id: CHANGELOG.txt,v 1.1 2005/07/17 22:41:03 cozman Exp $ * A wide variety of helper utilities for tasks such as filesystem navigation, FileBuffer capable of reading from archives, random number generation, versioning, and timing + * Powerful input system allowing for direct access to keyboard/mouse status + or passive listeners which are notified of events when they occur. * Resource Management system including the ability to load resources from specified directories or archives. * Variety of math classes including Circle, Rectangle, and Vector classes @@ -31,5 +33,5 @@ $Id: CHANGELOG.txt,v 1.1 2005/07/17 22:41:03 cozman Exp $ * Entire library is built in a highly-modular fashion with extensibility in mind. Use of modern programming techniques like templates and exceptions contributes to ease of use and ease of development. - * 13 demo programs showing features and ease of use + * 13 demo programs showing features and ease of use of various components. diff --git a/CREDITS.txt b/CREDITS.txt index 881c482..b928353 100644 --- a/CREDITS.txt +++ b/CREDITS.txt @@ -3,6 +3,7 @@ The following people have contributed code to photon: ..yeah this list is too short right now, so help out ;) In addition, I'd like to thank: + * Sourceforge.net - Providing hosting for the project and CVS. * Sean and Gamer Tazar from the old CoZ team, where ZEngine was born * Everyone who contributed to, used, or downloaded ZEngine * Sam Lantinga and the rest of the SDL crew (without SDL, no ZEngine, @@ -13,5 +14,8 @@ In addition, I'd like to thank: * Jesse Maurais and DevMaster.net for the OpenAL tutorials * Everyone responsible for FreeMind (http://freemind.sf.net) * The Ubuntu Team (http://ubuntulinux.com) + * Makoto Matsumoto and Takuji Nishimura for authoring the Mersenne Twister + algorithm, and making it freely available. + http://www.math.keio.ac.jp/~matumoto/emt.html -$Id: CREDITS.txt,v 1.1 2005/07/17 22:41:03 cozman Exp $ +$Id: CREDITS.txt,v 1.2 2005/07/19 18:35:20 cozman Exp $ diff --git a/photon.mm b/photon.mm index ba3d38c..5a3c3ef 100644 --- a/photon.mm +++ b/photon.mm @@ -5,45 +5,126 @@ - - - - - - + + + + + - - - - - - - - - - - - - - + + - - - + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/AppCore.cpp b/src/AppCore.cpp index ff3b28d..3321662 100644 --- a/src/AppCore.cpp +++ b/src/AppCore.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: AppCore.cpp,v 1.11 2005/07/19 05:45:23 cozman Exp $ +// $Id: AppCore.cpp,v 1.12 2005/07/19 18:35:20 cozman Exp $ #include "AppCore.hpp" @@ -35,8 +35,13 @@ AppCore::AppCore() : AppCore::~AppCore() { - video::VideoCore::destroy(); // destroy videocore - glfwCloseWindow(); //close GLFW window + + if(dispWidth_ && dispHeight_) + { + video::VideoCore::destroy(); // destroy videocore + glfwCloseWindow(); //close GLFW window + } + glfwTerminate(); //shutdown GLFW } @@ -136,7 +141,7 @@ void AppCore::addInputListener(InputListener *listener) { throw ArgumentException("Null pointer in AppCore::addInputListener"); } - + // add the listener listeners_.push_back(listener); } diff --git a/src/Application.cpp b/src/Application.cpp index a55e467..2d29f3c 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Application.cpp,v 1.12 2005/07/19 01:31:38 cozman Exp $ +// $Id: Application.cpp,v 1.13 2005/07/19 18:35:20 cozman Exp $ #include "Application.hpp" @@ -43,7 +43,6 @@ Application::~Application() // destroy the singletons AppCore::destroy(); - //audio::AudioCore::destroy(); Kernel::destroy(); } diff --git a/src/audio/AudioCore.cpp b/src/audio/AudioCore.cpp index aade8b0..2576b21 100644 --- a/src/audio/AudioCore.cpp +++ b/src/audio/AudioCore.cpp @@ -5,7 +5,7 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: AudioCore.cpp,v 1.9 2005/07/19 05:56:08 cozman Exp $ +// $Id: AudioCore.cpp,v 1.10 2005/07/19 18:35:20 cozman Exp $ #ifdef PHOTON_USE_OPENAL @@ -33,12 +33,12 @@ AudioCore::~AudioCore() ALCcontext* context( alcGetCurrentContext() ); ALCdevice* device( alcGetContextsDevice(context) ); - // set current context to null - alcMakeContextCurrent(0); - // destroy context & device alcDestroyContext(context); alcCloseDevice(device); + + // set current context to null + alcMakeContextCurrent(0); } std::string AudioCore::getAudioDeviceName() const @@ -139,6 +139,8 @@ util::VersionInfo AudioCore::initOpenAL(const std::string& deviceName) #else #warning OpenAL only built on Windows/Linux, find out version on OSX #endif + + throwOpenALError("AudioCore::initOpenAL"); return util::VersionInfo(major,minor,patch); } diff --git a/test/Audio_test.cpp b/test/Audio_test.cpp index a60a198..8a1ac93 100644 --- a/test/Audio_test.cpp +++ b/test/Audio_test.cpp @@ -5,17 +5,19 @@ // James Turk (jpt2433@rit.edu) // // Version: -// $Id: Audio_test.cpp,v 1.4 2005/07/19 05:57:58 cozman Exp $ +// $Id: Audio_test.cpp,v 1.5 2005/07/19 18:35:20 cozman Exp $ #include "photon.hpp" using namespace photon; #include +// actual test is only compiled if OpenAL is in use #ifdef PHOTON_USE_OPENAL using namespace photon::audio; -class MainTask : public Task +// sole task of AudioTest +class MainTask : public Task , public InputListener { public: @@ -24,14 +26,13 @@ public: app(AppCore::getInstance()), video(video::VideoCore::getInstance()) { - LogSinkPtr csp( new ConsoleSink("console") ); - log.addSink(csp); - - video.setOrthoView(800,600); + video.setOrthoView(800,600); // setup view + // load a font video::Font::addResource("font","data/FreeMono.ttf",20); font.open("font"); + // load the 6 sound effects Sample::addResource("chimes","data/chimes.wav"); Sample::addResource("ocean","data/ocean.wav"); Sample::addResource("rain","data/rain.wav"); @@ -39,6 +40,7 @@ public: Sample::addResource("thunder","data/thunder.wav"); Sample::addResource("waterdrop","data/waterdrop.wav"); + // open the sounds chimes.open("chimes"); ocean.open("ocean"); rain.open("rain"); @@ -46,115 +48,120 @@ public: thunder.open("thunder"); waterdrop.open("waterdrop"); + // make all sounds looping chimes.setLooping(true); ocean.setLooping(true); rain.setLooping(true); stream.setLooping(true); thunder.setLooping(true); + // test Sample::isLooping via assertions assert(!waterdrop.isLooping()); waterdrop.setLooping(true); assert(waterdrop.isLooping()); + // status holds strings describing playing status for nice output for(int i=0; i < 6; ++i) status[i] = "NOT "; } - void checkKeys() + // executes the checking of the keys, when a key is pressed + // the state is toggled + void onKeyPress(int key) { static const std::string NOT_PLAYING = "NOT "; - static scalar lastCheck = 0; - if(app.getTime() - lastCheck > 0.1) + switch(key) { - lastCheck = app.getTime(); + + case KEY_C: + if(!chimes.isPlaying()) + { + chimes.play(); + status[0] = ""; + } + else + { + chimes.stop(); + status[0] = NOT_PLAYING; + } + break; - if(app.keyPressed(KEY_C)) + case KEY_O: + if(!ocean.isPlaying()) { - if(!chimes.isPlaying()) - { - chimes.play(); - status[0] = ""; - } - else - { - chimes.stop(); - status[0] = NOT_PLAYING; - } + ocean.play(); + status[1] = ""; } - if(app.keyPressed(KEY_O)) + else { - if(!ocean.isPlaying()) - { - ocean.play(); - status[1] = ""; - } - else - { - ocean.stop(); - status[1] = NOT_PLAYING; - } + ocean.stop(); + status[1] = NOT_PLAYING; } - if(app.keyPressed(KEY_R)) + break; + + case KEY_R: + if(!rain.isPlaying()) { - if(!rain.isPlaying()) - { - rain.play(); - status[2] = ""; - } - else - { - rain.stop(); - status[2] = NOT_PLAYING; - } + rain.play(); + status[2] = ""; } - if(app.keyPressed(KEY_S)) + else { - if(!stream.isPlaying()) - { - stream.play(); - status[3] = ""; - } - else - { - stream.stop(); - status[3] = NOT_PLAYING; - } + rain.stop(); + status[2] = NOT_PLAYING; } - if(app.keyPressed(KEY_T)) + break; + + case KEY_S: + if(!stream.isPlaying()) { - if(!thunder.isPlaying()) - { - thunder.play(); - status[4] = ""; - } - else - { - thunder.stop(); - status[4] = NOT_PLAYING; - } + stream.play(); + status[3] = ""; } - if(app.keyPressed(KEY_W)) + else { - if(!waterdrop.isPlaying()) - { - waterdrop.play(); - status[5] = ""; - } - else - { - waterdrop.stop(); - status[5] = NOT_PLAYING; - } + stream.stop(); + status[3] = NOT_PLAYING; } + break; + + case KEY_T: + if(!thunder.isPlaying()) + { + thunder.play(); + status[4] = ""; + } + else + { + thunder.stop(); + status[4] = NOT_PLAYING; + } + break; + + case KEY_W: + if(!waterdrop.isPlaying()) + { + waterdrop.play(); + status[5] = ""; + } + else + { + waterdrop.stop(); + status[5] = NOT_PLAYING; + } + break; + + default: + break; } } + // called once per frame void update() { - static const photon::uint fontHeight(font.getHeight()); + // used to measure FPS and display it in the title bar static double t=0; - if(app.getTime() - t > 1.0) { app.setTitle("FPS: " + @@ -162,10 +169,12 @@ public: t = app.getTime(); } - checkKeys(); + // used for calculating draw position + static const photon::uint fontHeight(font.getHeight()); - video.clear(); + video.clear(); // clear display before drawing + // draw the status of all 6 sounds font.beginDraw(0, 0*fontHeight) << "(C)himes is " << status[0] << "playing" << font.endDraw(); font.beginDraw(0, 1*fontHeight) << "(O)cean is " << status[1] << @@ -185,8 +194,8 @@ private: video::Font font; audio::Sample chimes, ocean, rain, stream, thunder, waterdrop; std::string status[6]; - - Log log; + + // references to singleton cores AppCore& app; video::VideoCore& video; }; @@ -197,23 +206,29 @@ public: int main(const StrVec& args) { + // create window AppCore::getInstance().createDisplay(800,600,32,0,0,false); - - AudioCore::initAudioDevice("OSS"); - + // create sound device + AudioCore::initAudioDevice("OSS"); + + // add the task to the Kernel Kernel::getInstance().addTask(TaskPtr(new MainTask())); - - Kernel::getInstance().run(); + // run Kernel until task finishes + Kernel::getInstance().run(); + + // destroy AudioCore, shuts down audio system + AudioCore::destroy(); return 0; } }; -ENTRYPOINT(AudioTest) +ENTRYPOINT(AudioTest) // make AudioTest the entrypoint class #else -#include +// alternate application if OpenAL was not available +#include int main() { std::cerr << "Photon compiled without OpenAL support.\n";