ClientReloadAdaptor.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D 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 Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <client/ClientReloadAdaptor.h>
00022 #include <client/ClientNewGameHandler.h>
00023 #include <client/ScorchedClient.h>
00024 #include <server/ServerNewGameState.h>
00025 #include <server/ScorchedServer.h>
00026 #include <landscape/LandscapeSoundManager.h>
00027 #include <landscape/LandscapeMusicManager.h>
00028 #include <landscapemap/LandscapeMaps.h>
00029 #include <landscapedef/LandscapeDefinitions.h>
00030 #include <tank/TankContainer.h>
00031 #include <target/TargetLife.h>
00032 #include <tankgraph/TargetRendererImplTank.h>
00033 #include <console/ConsoleRuleMethodIAdapter.h>
00034 #include <common/Logger.h>
00035 
00036 ClientReloadAdaptor *ClientReloadAdaptor::instance_ = 0;
00037 
00038 ClientReloadAdaptor *ClientReloadAdaptor::instance()
00039 {
00040         if (!instance_)
00041         {
00042           instance_ = new ClientReloadAdaptor();
00043         }
00044 
00045         return instance_;
00046 }
00047 
00048 ClientReloadAdaptor::ClientReloadAdaptor()
00049 {
00050         new ConsoleRuleMethodIAdapter<ClientReloadAdaptor>(
00051                 this, &ClientReloadAdaptor::reloadLandscapeObjects, "ReloadLandscapeObjects");
00052         new ConsoleRuleMethodIAdapter<ClientReloadAdaptor>(
00053                 this, &ClientReloadAdaptor::showLandscapeInfo, "ShowLandscapeInfo");
00054         new ConsoleRuleMethodIAdapter<ClientReloadAdaptor>(
00055                 this, &ClientReloadAdaptor::showLandscapeAimInfo, "ShowLandscapeAimInfo");
00056 }
00057 
00058 ClientReloadAdaptor::~ClientReloadAdaptor()
00059 {
00060 
00061 }
00062 
00063 void ClientReloadAdaptor::reloadLandscapeObjects()
00064 {
00065         // Remove any old targets
00066         ServerNewGameState::removeTargets();
00067         ClientNewGameHandler::instance()->removeTargets();
00068 
00069         LandscapeDefinitionCache &serverDefinitions =
00070                 ScorchedServer::instance()->getLandscapeMaps().getDefinitions();
00071         LandscapeDefinitionCache &clientDefinitions =
00072                 ScorchedClient::instance()->getLandscapeMaps().getDefinitions();
00073 
00074         // Re-read landscape defs
00075         ScorchedServer::instance()->getLandscapes().readLandscapeDefinitions();
00076         ScorchedClient::instance()->getLandscapes().readLandscapeDefinitions();
00077         serverDefinitions.setDefinition(ScorchedServer::instance()->getContext(),
00078                 serverDefinitions.getDefinition());
00079         clientDefinitions.setDefinition(ScorchedClient::instance()->getContext(),
00080                 serverDefinitions.getDefinition());
00081 
00082         // Re-generate landscape
00083         std::list<FixedVector> tankPositions;
00084         ScorchedServer::instance()->getLandscapeMaps().generateMaps(
00085                 ScorchedServer::instance()->getContext(), 
00086                 serverDefinitions.getDefinition());
00087         ScorchedClient::instance()->getLandscapeMaps().generateMaps(
00088                 ScorchedClient::instance()->getContext(),
00089                 serverDefinitions.getDefinition());
00090 
00091         // Classes that store refs to defns and texs
00092         LandscapeSoundManager::instance()->addSounds();
00093         LandscapeMusicManager::instance()->addMusics();
00094 }
00095 
00096 void ClientReloadAdaptor::showLandscapeInfo()
00097 {
00098         LandscapeDefinitionCache &serverDefinitions =
00099                 ScorchedServer::instance()->getLandscapeMaps().getDefinitions();
00100 
00101         Logger::log(S3D::formatStringBuffer("Name : %s\nTex : %s\nDefn %s\n", 
00102                 serverDefinitions.getDefinition().getName(),
00103                 serverDefinitions.getDefinition().getTex(),
00104                 serverDefinitions.getDefinition().getDefn()));
00105 }
00106 
00107 void ClientReloadAdaptor::showLandscapeAimInfo()
00108 {
00109         if (!ScorchedClient::instance()->getOptionsGame().getDebugFeatures())
00110         {
00111                 Logger::log("Debug features must be enabled to view aim position");
00112                 return;
00113         }
00114 
00115         Logger::log(S3D::formatStringBuffer("Aim Position : %.4f,%.4f,%.4f\n", 
00116                 TargetRendererImplTankAIM::aimPosition_[0],
00117                 TargetRendererImplTankAIM::aimPosition_[1],
00118                 TargetRendererImplTankAIM::aimPosition_[2]));
00119 }

Generated on Mon Feb 16 15:14:36 2009 for Scorched3D by  doxygen 1.5.3