Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

spark.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
00002    this file is part of rcssserver3D
00003    Fri May 9 2003
00004    Copyright (C) 2003 Koblenz University
00005    $Id: spark.cpp,v 1.4 2004/12/31 11:27:05 rollmark Exp $
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; version 2 of the License.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 #include "spark.h"
00022 #include <zeitgeist/zeitgeist.h>
00023 
00024 //#include <SDL/SDL.h>
00025 using namespace spark;
00026 using namespace kerosin;
00027 using namespace oxygen;
00028 using namespace zeitgeist;
00029 using namespace salt;
00030 using namespace std;
00031 using namespace boost;
00032 
00033 
00034 Spark::Spark(const string& relPathPrefix) :
00035     mZeitgeist("." PACKAGE_NAME, relPathPrefix),
00036     mOxygen(mZeitgeist),
00037     mKerosin(mZeitgeist)
00038 {
00039 }
00040 
00041 Spark::~Spark()
00042 {
00043     // reset shared ptr to objects in the zeitgeist hierarchy before
00044     // the zeitgeist core is shutdown
00045     mLogServer.reset();
00046     mScriptServer.reset();
00047     mSceneServer.reset();
00048     mSimulationServer.reset();
00049 }
00050 
00051 bool Spark::Init(int argc, char** argv)
00052 {
00053     mLogServer = mZeitgeist.GetCore()->GetLogServer();
00054     if (mLogServer.get() == 0)
00055         {
00056             cout << "(Spark) ERROR: LogServer not found\n";
00057             return false;
00058         }
00059 
00060     mScriptServer = mZeitgeist.GetCore()->GetScriptServer();
00061     if (mScriptServer.get() == 0)
00062         {
00063             mLogServer->Error()
00064                 << "(Spark) ERROR: ScriptServer not found\n";
00065             return false;
00066         }
00067 
00068     // run the spark init script
00069     mZeitgeist.GetCore()->GetRoot()->GetScript()->RunInitScript
00070         (
00071          "spark.rb",
00072          "lib/spark",
00073          ScriptServer::IS_COMMON
00074          );
00075 
00076     mSceneServer = shared_dynamic_cast<SceneServer>
00077         (mZeitgeist.GetCore()->Get("/sys/server/scene"));
00078 
00079     if (mSceneServer.get() == 0)
00080         {
00081             mLogServer->Error() << "(Spark) ERROR: SceneServer not found\n";
00082             return false;
00083         }
00084 
00085     mSimulationServer = shared_dynamic_cast<SimulationServer>
00086         (mZeitgeist.GetCore()->Get("/sys/server/simulation"));
00087 
00088     if (mSimulationServer.get() == 0)
00089         {
00090             mLogServer->Error() << "(Spark) ERROR: SimulationServer not found\n";
00091             return false;
00092         }
00093 
00094     // run the app defined init
00095     return InitApp(argc,argv);
00096 }
00097 
00098 bool Spark::InitApp(int /*argc*/, char** /*argv*/)
00099 {
00100     return true;
00101 }
00102 
00103 Zeitgeist& Spark::GetZeitgeist()
00104 {
00105     return mZeitgeist;
00106 }
00107 
00108 shared_ptr<Core> Spark::GetCore()
00109 {
00110     return mZeitgeist.GetCore();
00111 }
00112 
00113 shared_ptr<zeitgeist::LogServer> Spark::GetLog()
00114 {
00115     return mZeitgeist.GetCore()->GetLogServer();
00116 }
00117 
00118 shared_ptr<SceneServer> Spark::GetSceneServer()
00119 {
00120     return mSceneServer;
00121 }
00122 
00123 shared_ptr<SimulationServer> Spark::GetSimulationServer()
00124 {
00125     return mSimulationServer;
00126 }
00127 
00128 shared_ptr<InputControl> Spark::GetInputControl()
00129 {
00130     if (mSimulationServer.get() == 0)
00131         {
00132             return shared_ptr<InputControl>();
00133         }
00134 
00135     return shared_dynamic_cast<InputControl>
00136         (mSimulationServer->GetControlNode("kerosin/InputControl"));
00137 }
00138 
00139 shared_ptr<RenderControl> Spark::GetRenderControl()
00140 {
00141     if (mSimulationServer.get() == 0)
00142         {
00143             return shared_ptr<RenderControl>();
00144         }
00145 
00146     return shared_dynamic_cast<RenderControl>
00147         (mSimulationServer->GetControlNode("kerosin/RenderControl"));
00148 }
00149 
00150 
00151 shared_ptr<ScriptServer> Spark::GetScriptServer()
00152 {
00153     return mScriptServer;
00154 }
00155 
00156 shared_ptr<Scene> Spark::GetActiveScene()
00157 {
00158     shared_ptr<Scene> scene = mSceneServer->GetActiveScene();
00159 
00160     if (scene.get() == 0)
00161         {
00162             mLogServer->Warning()
00163                 << "(Spark) Warning: no active scene registered\n";
00164         }
00165 
00166     return scene;
00167 }
00168 

Generated on Thu Apr 6 15:25:40 2006 for rcssserver3d by  doxygen 1.4.4