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

View File

@ -5,23 +5,19 @@
// James Turk (jpt2433@rit.edu)
//
// 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"
using namespace photon;
#include "FPSDisplayTask.hpp" // used to display FPS in title bar
class MainTask : public Task
class MainState : public State
{
public:
MainTask() :
Task("MainTask"),
app(Application::getAppCore()),
video(Application::getVideoCore())
MainState() :
app(Application::getInstance())
{
video.setOrthoView(800,600);
// add archive to search path
util::filesys::addToSearchPath("data/fonts.zip");
@ -33,8 +29,8 @@ public:
font2.open("font2");
}
void update()
{
void render()
{
// draw the three strings to the screen
font.setColor(video::Color(0,128,128));
font.drawText(0, 0, "Photon");
@ -48,27 +44,22 @@ private:
video::Font font;
video::Font font2;
AppCore& app;
video::VideoCore& video;
Application& app;
};
// standard application, creates window, registers task and runs
class FontTest : public Application
int PhotonMain(const StrVec& args)
{
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
Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
// be sure to add FPSDisplayTask
Application::getKernel().addTask(TaskPtr(new FPSDisplayTask()));
Application::getKernel().addTask(TaskPtr(new MainTask()));
// set current state
Application::getInstance().setCurrentState<MainState>();
Application::getKernel().run();
return 0;
}
};
ENTRYPOINT(FontTest)
// run until finished
Kernel::getInstance().run();
return 0;
}

View File

@ -5,7 +5,7 @@
// James Turk (jpt2433@rit.edu)
//
// 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"
using namespace photon;
@ -19,9 +19,6 @@ class MainState : public State
public:
MainState() :
app(Application::getInstance())
{ }
void enterState()
{
// load the images
video::Image::addResource("data/icon.png");
@ -40,10 +37,6 @@ public:
img[2].flip(true,true);
}
void update()
{
}
void render()
{
// draw in top left corner
@ -67,14 +60,16 @@ private:
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
Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
Application::getInstance().registerState<MainState>("main");
Application::getInstance().setCurrentState("main");
// set current state
Application::getInstance().setCurrentState<MainState>();
// run until finished
Kernel::getInstance().run();
return 0;

View File

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

View File

@ -5,30 +5,26 @@
// James Turk (jpt2433@rit.edu)
//
// 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"
using namespace photon;
#include "FPSDisplayTask.hpp" // used to display FPS in title bar
class MainTask : public Task
class MainState : public State
{
public:
MainTask() :
Task("MainTask"),
app(Application::getAppCore()),
video(Application::getVideoCore())
MainState() :
app(Application::getInstance())
{
video.setOrthoView(800,600);
// initialize three pens, red, blue and green
r.setColor(255, 0, 0);
g.setColor(0, 255, 0);
b.setColor(0, 0, 255);
}
void update()
void render()
{
static const math::Point2 center(400, 300); // used for clock
@ -72,27 +68,22 @@ public:
private:
video::Pen r,g,b;
AppCore& app;
video::VideoCore& video;
Application& app;
};
// standard application, creates window, registers task and runs
class PenTest : public Application
int PhotonMain(const StrVec& args)
{
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
Kernel::getInstance().addTask(TaskPtr(new FPSDisplayTask()));
// be sure to add FPSDisplayTask
Application::getKernel().addTask(TaskPtr(new FPSDisplayTask()));
Application::getKernel().addTask(TaskPtr(new MainTask()));
// set current state
Application::getInstance().setCurrentState<MainState>();
Application::getKernel().run();
return 0;
}
};
ENTRYPOINT(PenTest)
// run until finished
Kernel::getInstance().run();
return 0;
}

View File

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