PhotonMain, done for 0.0.1

This commit is contained in:
James Turk 2005-08-08 06:37:10 +00:00
parent 8bd0e0ec0a
commit 4596737916
6 changed files with 99 additions and 153 deletions

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Audio_test.cpp,v 1.9 2005/08/07 07:12:48 cozman Exp $ // $Id: Audio_test.cpp,v 1.10 2005/08/08 06:37:10 cozman Exp $
#include "photon.hpp" #include "photon.hpp"
using namespace photon; using namespace photon;
@ -17,16 +17,12 @@ using namespace photon;
using namespace photon::audio; using namespace photon::audio;
// sole task of AudioTest // sole task of AudioTest
class MainTask : public Task , public InputListener class MainState : public State , public InputListener
{ {
public: public:
MainTask() : MainState()
Task("MainTask"),
video(Application::getVideoCore())
{ {
video.setOrthoView(800,600); // setup view
// add archives to search path // add archives to search path
util::filesys::addToSearchPath("data/fonts.zip"); util::filesys::addToSearchPath("data/fonts.zip");
util::filesys::addToSearchPath("data/wavdata.zip"); util::filesys::addToSearchPath("data/wavdata.zip");
@ -160,8 +156,7 @@ public:
} }
} }
// called once per frame void render()
void update()
{ {
// used for calculating draw position // used for calculating draw position
static const photon::uint fontHeight(font.getHeight()); static const photon::uint fontHeight(font.getHeight());
@ -179,46 +174,38 @@ public:
"playing" << font.endDraw(); "playing" << font.endDraw();
font.beginDraw(0, 5*fontHeight) << "(W)aterdrop is " << status[5] << font.beginDraw(0, 5*fontHeight) << "(W)aterdrop is " << status[5] <<
"playing" << font.endDraw(); "playing" << font.endDraw();
} }
private: private:
video::Font font; video::Font font;
audio::Sample chimes, ocean, rain, stream, thunder, waterdrop; audio::Sample chimes, ocean, rain, stream, thunder, waterdrop;
std::string status[6]; std::string status[6];
video::VideoCore& video;
}; };
class AudioTest : public Application int PhotonMain(const StrVec& args)
{ {
public:
int main(const StrVec& args)
{
// create window // create window
Application::getAppCore().createDisplay(800,600,32,0,0,false); Application::getInstance().createDisplay(800,600,32,0,0,false);
// create sound device // initialize audio core
Application::initAudioCore("OSS"); Application::getInstance().initAudioCore("OSS");
// be sure to add FPSDisplayTask // be sure to add FPSDisplayTask
Application::getKernel().addTask(TaskPtr(new FPSDisplayTask())); Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
// add the main task to the Kernel
Application::getKernel().addTask(TaskPtr(new MainTask())); // register state and make active
// run Kernel until task finishes Application::getInstance().setCurrentState<MainState>();
Application::getKernel().run();
// run until finished
Kernel::getInstance().run();
return 0; return 0;
} }
};
ENTRYPOINT(AudioTest) // make AudioTest the entrypoint class
#else #else
// alternate application if OpenAL was not available // alternate application if OpenAL was not available
#include <iostream> #include <iostream>
int main() int PhotonMain(const StrVec& args)
{ {
std::cerr << "Photon compiled without OpenAL support.\n"; std::cerr << "Photon compiled without OpenAL support.\n";
} }

View File

@ -5,23 +5,19 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Font_test.cpp,v 1.9 2005/08/02 23:07:53 cozman Exp $ // $Id: Font_test.cpp,v 1.10 2005/08/08 06:37:10 cozman Exp $
#include "photon.hpp" #include "photon.hpp"
using namespace photon; using namespace photon;
#include "FPSDisplayTask.hpp" // used to display FPS in title bar #include "FPSDisplayTask.hpp" // used to display FPS in title bar
class MainTask : public Task class MainState : public State
{ {
public: public:
MainTask() : MainState() :
Task("MainTask"), app(Application::getInstance())
app(Application::getAppCore()),
video(Application::getVideoCore())
{ {
video.setOrthoView(800,600);
// add archive to search path // add archive to search path
util::filesys::addToSearchPath("data/fonts.zip"); util::filesys::addToSearchPath("data/fonts.zip");
@ -33,7 +29,7 @@ public:
font2.open("font2"); font2.open("font2");
} }
void update() void render()
{ {
// draw the three strings to the screen // draw the three strings to the screen
font.setColor(video::Color(0,128,128)); font.setColor(video::Color(0,128,128));
@ -48,27 +44,22 @@ private:
video::Font font; video::Font font;
video::Font font2; video::Font font2;
AppCore& app; Application& app;
video::VideoCore& video;
}; };
// standard application, creates window, registers task and runs int PhotonMain(const StrVec& args)
class FontTest : public Application
{ {
public: // create window
Application::getInstance().createDisplay(800,600,32,0,0,false);
int main(const StrVec& args)
{
Application::getAppCore().createDisplay(800,600,32,0,0,false);
// be sure to add FPSDisplayTask // be sure to add FPSDisplayTask
Application::getKernel().addTask(TaskPtr(new FPSDisplayTask())); Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
Application::getKernel().addTask(TaskPtr(new MainTask()));
Application::getKernel().run(); // set current state
Application::getInstance().setCurrentState<MainState>();
// run until finished
Kernel::getInstance().run();
return 0; return 0;
} }
};
ENTRYPOINT(FontTest)

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Image_test.cpp,v 1.9 2005/08/07 07:12:48 cozman Exp $ // $Id: Image_test.cpp,v 1.10 2005/08/08 06:37:10 cozman Exp $
#include "photon.hpp" #include "photon.hpp"
using namespace photon; using namespace photon;
@ -19,9 +19,6 @@ class MainState : public State
public: public:
MainState() : MainState() :
app(Application::getInstance()) app(Application::getInstance())
{ }
void enterState()
{ {
// load the images // load the images
video::Image::addResource("data/icon.png"); video::Image::addResource("data/icon.png");
@ -40,10 +37,6 @@ public:
img[2].flip(true,true); img[2].flip(true,true);
} }
void update()
{
}
void render() void render()
{ {
// draw in top left corner // draw in top left corner
@ -67,14 +60,16 @@ private:
int PhotonMain(const StrVec& args) int PhotonMain(const StrVec& args)
{ {
Application::getInstance().createDisplay(800,600,32,0,0,true); // create window
Application::getInstance().createDisplay(800,600,32,0,0,false);
// be sure to add FPSDisplayTask // be sure to add FPSDisplayTask
Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask())); Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
Application::getInstance().registerState<MainState>("main"); // set current state
Application::getInstance().setCurrentState("main"); Application::getInstance().setCurrentState<MainState>();
// run until finished
Kernel::getInstance().run(); Kernel::getInstance().run();
return 0; return 0;

View File

@ -5,23 +5,19 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Input_test.cpp,v 1.6 2005/08/02 23:07:53 cozman Exp $ // $Id: Input_test.cpp,v 1.7 2005/08/08 06:37:10 cozman Exp $
#include "photon.hpp" #include "photon.hpp"
using namespace photon; using namespace photon;
#include "FPSDisplayTask.hpp" // used to display FPS in title bar #include "FPSDisplayTask.hpp" // used to display FPS in title bar
class MainTask : public Task, public InputListener class MainState : public State, public InputListener
{ {
public: public:
MainTask() : MainState() :
Task("MainTask"), app(Application::getInstance())
app(Application::getAppCore()),
video(Application::getVideoCore())
{ {
video.setOrthoView(800,600);
// add archives to search path // add archives to search path
util::filesys::addToSearchPath("data/fonts.zip"); util::filesys::addToSearchPath("data/fonts.zip");
@ -59,7 +55,7 @@ public:
lastEvent = "mouse moved to " + boost::lexical_cast<std::string>(pos); lastEvent = "mouse moved to " + boost::lexical_cast<std::string>(pos);
} }
void update() void render()
{ {
// used for spacing text vertically // used for spacing text vertically
static const photon::uint fontHeight(font.getHeight()); static const photon::uint fontHeight(font.getHeight());
@ -112,27 +108,22 @@ private:
video::Font font; video::Font font;
std::string lastEvent; std::string lastEvent;
AppCore& app; Application& app;
video::VideoCore& video;
}; };
// standard application, creates window, registers task and runs int PhotonMain(const StrVec& args)
class InputTest : public Application
{ {
public: // create window
Application::getInstance().createDisplay(800,600,32,0,0,false);
int main(const StrVec& args)
{
Application::getAppCore().createDisplay(800,600,32,0,0,false);
// be sure to add FPSDisplayTask // be sure to add FPSDisplayTask
Application::getKernel().addTask(TaskPtr(new FPSDisplayTask())); Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
Application::getKernel().addTask(TaskPtr(new MainTask()));
Application::getKernel().run(); // set current state
Application::getInstance().setCurrentState<MainState>();
// run until finished
Kernel::getInstance().run();
return 0; return 0;
} }
};
ENTRYPOINT(InputTest)

View File

@ -5,30 +5,26 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Pen_test.cpp,v 1.6 2005/08/02 23:07:53 cozman Exp $ // $Id: Pen_test.cpp,v 1.7 2005/08/08 06:37:10 cozman Exp $
#include "photon.hpp" #include "photon.hpp"
using namespace photon; using namespace photon;
#include "FPSDisplayTask.hpp" // used to display FPS in title bar #include "FPSDisplayTask.hpp" // used to display FPS in title bar
class MainTask : public Task class MainState : public State
{ {
public: public:
MainTask() : MainState() :
Task("MainTask"), app(Application::getInstance())
app(Application::getAppCore()),
video(Application::getVideoCore())
{ {
video.setOrthoView(800,600);
// initialize three pens, red, blue and green // initialize three pens, red, blue and green
r.setColor(255, 0, 0); r.setColor(255, 0, 0);
g.setColor(0, 255, 0); g.setColor(0, 255, 0);
b.setColor(0, 0, 255); b.setColor(0, 0, 255);
} }
void update() void render()
{ {
static const math::Point2 center(400, 300); // used for clock static const math::Point2 center(400, 300); // used for clock
@ -72,27 +68,22 @@ public:
private: private:
video::Pen r,g,b; video::Pen r,g,b;
AppCore& app; Application& app;
video::VideoCore& video;
}; };
// standard application, creates window, registers task and runs int PhotonMain(const StrVec& args)
class PenTest : public Application
{ {
public: // create window
Application::getInstance().createDisplay(800,600,32,0,0,false);
int main(const StrVec& args)
{
Application::getAppCore().createDisplay(800,600,32,0,0,false);
// be sure to add FPSDisplayTask // be sure to add FPSDisplayTask
Application::getKernel().addTask(TaskPtr(new FPSDisplayTask())); Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
Application::getKernel().addTask(TaskPtr(new MainTask()));
Application::getKernel().run(); // set current state
Application::getInstance().setCurrentState<MainState>();
// run until finished
Kernel::getInstance().run();
return 0; return 0;
} }
};
ENTRYPOINT(PenTest)

View File

@ -5,23 +5,19 @@
// James Turk (jpt2433@rit.edu) // James Turk (jpt2433@rit.edu)
// //
// Version: // Version:
// $Id: Texture_test.cpp,v 1.7 2005/08/02 23:07:53 cozman Exp $ // $Id: Texture_test.cpp,v 1.8 2005/08/08 06:37:10 cozman Exp $
#include "photon.hpp" #include "photon.hpp"
using namespace photon; using namespace photon;
#include "FPSDisplayTask.hpp" // used to display FPS in title bar #include "FPSDisplayTask.hpp" // used to display FPS in title bar
class MainTask : public Task class MainState : public State
{ {
public: public:
MainTask() : MainState() :
Task("MainTask"), app(Application::getInstance())
app(Application::getAppCore()),
video(Application::getVideoCore())
{ {
video.setOrthoView(800,600);
video::Texture::addResource("data/icon.png"); video::Texture::addResource("data/icon.png");
video::Texture::addResource("robo","data/robo.png"); video::Texture::addResource("robo","data/robo.png");
@ -36,7 +32,7 @@ public:
} }
void update() void render()
{ {
// draw first texture at actual size // draw first texture at actual size
tex[0].bind(); tex[0].bind();
@ -72,27 +68,22 @@ public:
private: private:
video::Texture tex[3]; video::Texture tex[3];
AppCore& app; Application& app;
video::VideoCore& video;
}; };
// standard application, creates window, registers task and runs int PhotonMain(const StrVec& args)
class TextureTest : public Application
{ {
public: // create window
Application::getInstance().createDisplay(800,600,32,0,0,false);
int main(const StrVec& args)
{
Application::getAppCore().createDisplay(800,600,32,0,0,false);
// be sure to add FPSDisplayTask // be sure to add FPSDisplayTask
Application::getKernel().addTask(TaskPtr(new FPSDisplayTask())); Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
Application::getKernel().addTask(TaskPtr(new MainTask()));
Application::getKernel().run(); // set current state
Application::getInstance().setCurrentState<MainState>();
// run until finished
Kernel::getInstance().run();
return 0; return 0;
} }
};
ENTRYPOINT(TextureTest)