2005-02-07 02:00:48 +00:00
|
|
|
//This file is part of Photon (http://photon.sourceforge.net)
|
|
|
|
//Copyright (C) 2004-2005 James Turk
|
|
|
|
//
|
|
|
|
// Author:
|
|
|
|
// James Turk (jpt2433@rit.edu)
|
|
|
|
//
|
|
|
|
// Version:
|
2005-08-02 23:07:51 +00:00
|
|
|
// $Id: Application.cpp,v 1.14 2005/08/02 23:07:52 cozman Exp $
|
2005-02-07 02:00:48 +00:00
|
|
|
|
2005-02-13 22:12:02 +00:00
|
|
|
#include "Application.hpp"
|
2005-02-07 02:00:48 +00:00
|
|
|
|
|
|
|
#include "physfs.h"
|
2005-04-21 19:30:19 +00:00
|
|
|
#include "GL/gl.h"
|
2005-03-15 19:21:51 +00:00
|
|
|
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include "exceptions.hpp"
|
|
|
|
#include "Log.hpp"
|
|
|
|
#include "Kernel.hpp"
|
|
|
|
#include "AppCore.hpp"
|
|
|
|
#include "video/VideoCore.hpp"
|
2005-05-15 02:50:52 +00:00
|
|
|
#include "audio/AudioCore.hpp"
|
2005-06-11 05:28:41 +00:00
|
|
|
#include "util/filesys/filesys.hpp"
|
|
|
|
|
2005-02-07 02:00:48 +00:00
|
|
|
|
|
|
|
namespace photon
|
|
|
|
{
|
|
|
|
|
2005-08-02 23:07:51 +00:00
|
|
|
Kernel Application::kernel_;
|
|
|
|
AppCore Application::appCore_;
|
|
|
|
std::auto_ptr<video::VideoCore> Application::videoCore_;
|
|
|
|
std::auto_ptr<audio::AudioCore> Application::audioCore_;
|
|
|
|
std::string Application::arg0_;
|
|
|
|
|
2005-02-16 04:26:22 +00:00
|
|
|
Application::Application() :
|
|
|
|
photonVer_(0,0,1) // this is the current version
|
2005-02-07 02:00:48 +00:00
|
|
|
{
|
2005-02-13 22:12:02 +00:00
|
|
|
util::VersionInfo physfsReq(1,0,0); // requires PhysFS 1.0.0
|
2005-05-15 02:50:52 +00:00
|
|
|
util::ensureVersion("PhysFS", initPhysFS(), physfsReq);
|
2005-08-02 23:07:51 +00:00
|
|
|
|
|
|
|
appCore_.init(); // init appcore
|
2005-02-07 02:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Application::~Application()
|
|
|
|
{
|
2005-08-02 23:07:51 +00:00
|
|
|
appCore_.shutdown(); // shutdown appcore
|
|
|
|
|
|
|
|
PHYSFS_deinit(); // shutdown PhysFS
|
|
|
|
}
|
2005-03-15 19:21:51 +00:00
|
|
|
|
2005-08-02 23:07:51 +00:00
|
|
|
Kernel& Application::getKernel()
|
|
|
|
{
|
|
|
|
return kernel_;
|
|
|
|
}
|
|
|
|
|
|
|
|
AppCore& Application::getAppCore()
|
|
|
|
{
|
|
|
|
return appCore_;
|
|
|
|
}
|
|
|
|
|
|
|
|
video::VideoCore& Application::getVideoCore()
|
|
|
|
{
|
|
|
|
// return VideoCore if it has been created
|
|
|
|
if(videoCore_.get() == 0)
|
|
|
|
{
|
|
|
|
throw PreconditionException("call to Application::getVideoCore() before"
|
|
|
|
" Application::initAudioDevice");
|
|
|
|
}
|
|
|
|
return *videoCore_;
|
|
|
|
}
|
|
|
|
|
|
|
|
audio::AudioCore& Application::getAudioCore()
|
|
|
|
{
|
|
|
|
// return AudioCore if it has been created
|
|
|
|
if(audioCore_.get() == 0)
|
|
|
|
{
|
|
|
|
throw PreconditionException("call to Application::getAudioCore() before"
|
|
|
|
" Application::initAudioDevice");
|
|
|
|
}
|
|
|
|
return *audioCore_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::initVideoCore(uint width, uint height)
|
|
|
|
{
|
|
|
|
// create VideoCore, avoid double initializaiton
|
|
|
|
if(videoCore_.get() == 0)
|
|
|
|
{
|
|
|
|
videoCore_.reset(new video::VideoCore(width, height));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw PreconditionException("Attempt to double initialize VideoCore");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Application::initAudioCore(const std::string& deviceName)
|
|
|
|
{
|
|
|
|
// create AudioCore, avoid double initializaiton
|
|
|
|
if(audioCore_.get() == 0)
|
|
|
|
{
|
|
|
|
audioCore_.reset(new audio::AudioCore(deviceName));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw PreconditionException("Attempt to double initialize AudioCore");
|
|
|
|
}
|
2005-03-15 19:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Application::setInitOptions(const char* arg0)
|
|
|
|
{
|
|
|
|
arg0_ = arg0;
|
2005-02-13 22:12:02 +00:00
|
|
|
}
|
|
|
|
|
2005-05-15 02:50:52 +00:00
|
|
|
util::VersionInfo Application::initPhysFS()
|
2005-02-13 22:12:02 +00:00
|
|
|
{
|
|
|
|
PHYSFS_Version ver;
|
2005-05-15 02:50:52 +00:00
|
|
|
PHYSFS_init(arg0_.c_str());
|
2005-06-11 05:28:41 +00:00
|
|
|
PHYSFS_addToSearchPath(PHYSFS_getBaseDir(),0);
|
2005-02-13 22:12:02 +00:00
|
|
|
PHYSFS_getLinkedVersion(&ver);
|
|
|
|
return util::VersionInfo(ver.major, ver.minor, ver.patch);
|
|
|
|
}
|
|
|
|
|
2005-02-07 02:00:48 +00:00
|
|
|
}
|