ClientInitializeHandler.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/ClientInitializeHandler.h>
00022 #include <client/ScorchedClient.h>
00023 #include <client/ClientState.h>
00024 #include <client/ClientWindowSetup.h>
00025 #include <sprites/ExplosionTextures.h>
00026 #include <server/ScorchedServer.h>
00027 #include <weapons/AccessoryStore.h>
00028 #include <landscapedef/LandscapeDefinitions.h>
00029 #include <common/Logger.h>
00030 #include <common/OptionsScorched.h>
00031 #include <client/ClientParams.h>
00032 #include <dialogs/ProgressDialog.h>
00033 #include <dialogs/PlayerDialog.h>
00034 #include <tank/TankModelStore.h>
00035 #include <engine/ModFiles.h>
00036 #include <graph/OptionsDisplay.h>
00037 #include <coms/ComsInitializeMessage.h>
00038 #include <coms/ComsMessageSender.h>
00039 #include <GLW/GLWWindowManager.h>
00040 #include <GLW/GLWWindowSkinManager.h>
00041 #include <GLEXT/GLLenseFlare.h>
00042 
00043 ClientInitializeHandler *ClientInitializeHandler::instance_ = 0;
00044 
00045 ClientInitializeHandler *ClientInitializeHandler::instance()
00046 {
00047         if (!instance_)
00048         {
00049                 instance_ = new ClientInitializeHandler;
00050         }
00051         return instance_;
00052 }
00053 
00054 ClientInitializeHandler::ClientInitializeHandler() :
00055         initialized_(false)
00056 {
00057         ScorchedClient::instance()->getComsMessageHandler().addHandler(
00058                 "ComsInitializeMessage",
00059                 this);
00060 }
00061 
00062 ClientInitializeHandler::~ClientInitializeHandler()
00063 {
00064 }
00065 
00066 bool ClientInitializeHandler::processMessage(
00067         NetMessage &netMessage,
00068         const char *messageType,
00069         NetBufferReader &reader)
00070 {
00071         ComsInitializeMessage message;
00072         if (!message.readMessage(reader)) return false;
00073 
00074         if (!initialized_)
00075         {
00076                 if (!initialize()) return false;
00077                 else initialized_ = true;
00078         }
00079 
00080         // Tell the server we are initialized
00081         ComsMessageSender::sendToServer(message);
00082         return true;
00083 }
00084 
00085 bool ClientInitializeHandler::initialize()
00086 {
00087         // Clear any memory used by stored mod files as they will not be required now
00088         ScorchedClient::instance()->getModFiles().clearData();
00089         if (!ClientParams::instance()->getConnectedToServer())
00090         {
00091                 ScorchedServer::instance()->getModFiles().clearData();
00092         }
00093 
00094         // Load the accessory files
00095         if (!ScorchedClient::instance()->getAccessoryStore().parseFile(
00096                 ScorchedClient::instance()->getContext(),
00097                 ProgressDialogSync::instance())) return false;
00098 
00099         // Load tank models here
00100         // This is after mods are complete but before any tanks models are used
00101         if (!ScorchedClient::instance()->getTankModels().loadTankMeshes(
00102                 ScorchedClient::instance()->getContext(), 
00103                 OptionsDisplay::instance()->getTankDetail(),
00104                 ProgressDialogSync::instance()))
00105         {
00106                 S3D::dialogMessage("Scorched 3D", "Failed to load all tank models");
00107                 return false;
00108         }
00109 
00110         // Load the landscape definitions
00111         if (!ScorchedClient::instance()->getLandscapes().readLandscapeDefinitions()) return false;
00112 
00113         // Load textures
00114         if (!ExplosionTextures::instance()->createTextures(
00115                 ProgressDialogSync::instance())) 
00116                         S3D::dialogExit("Scorched3D", "Failed to load explosion textures");
00117         GLLenseFlare::instance()->init(
00118                 ProgressDialogSync::instance());
00119                 
00120         // Load game windows
00121         ProgressDialogSync::instance()->setNewPercentage(0.0f);
00122         ProgressDialogSync::instance()->setNewOp(LANG_RESOURCE("INITIALIZING_WINDOWS", "Initializing Game Windows"));
00123         if (!GLWWindowSkinManager::modinstance()->loadWindows())
00124         {
00125                 S3D::dialogExit("Scorched3D", "Failed to load windows skins");
00126         }
00127         ClientWindowSetup::setupGameWindows(GLWWindowSkinManager::modinstance());
00128         GLWWindowManager::instance()->loadPositions();          
00129 
00130         // Move into the player setup state
00131         if (ClientParams::instance()->getSaveFile()[0])
00132         {
00133                 ScorchedClient::instance()->getGameState().stimulate(ClientState::StimLoadPlayers);
00134         }
00135         else
00136         {
00137                 ScorchedClient::instance()->getGameState().stimulate(ClientState::StimGetPlayers);
00138                 // Show player dialog
00139                 GLWWindowManager::instance()->showWindow(
00140                         PlayerDialog::instance()->getId());     
00141         }
00142         ScorchedClient::instance()->getGameState().checkStimulate();
00143         return true;
00144 }

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