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/ClientShotState.h> 00022 #include <client/ClientState.h> 00023 #include <client/ScorchedClient.h> 00024 #include <client/ClientWaitState.h> 00025 #include <client/ClientParams.h> 00026 #include <engine/ActionController.h> 00027 #include <engine/ViewPoints.h> 00028 #include <common/Logger.h> 00029 #include <coms/ComsPlayMovesMessage.h> 00030 #include <landscape/Landscape.h> 00031 00032 ClientShotState *ClientShotState::instance_ = 0; 00033 00034 ClientShotState *ClientShotState::instance() 00035 { 00036 if (!instance_) 00037 { 00038 instance_ = new ClientShotState; 00039 } 00040 return instance_; 00041 } 00042 00043 ClientShotState::ClientShotState() : 00044 GameStateI("ClientShotState"), 00045 playShots_(), 00046 shotState_(ScorchedClient::instance()->getContext(), playShots_) 00047 { 00048 ScorchedClient::instance()->getComsMessageHandler().addHandler( 00049 "ComsPlayMovesMessage", 00050 this); 00051 } 00052 00053 ClientShotState::~ClientShotState() 00054 { 00055 } 00056 00057 bool ClientShotState::processMessage( 00058 NetMessage &message, 00059 const char *messageType, 00060 NetBufferReader &reader) 00061 { 00062 // Reset graphics 00063 Landscape::instance()->restoreLandscapeTexture(); 00064 ScorchedClient::instance()->getContext().getViewPoints().reset(); 00065 00066 // Read the new shots into the action controller 00067 ComsPlayMovesMessage playMovesMessage; 00068 if (!playMovesMessage.readMessage(reader)) return false; 00069 00070 // Read the moves from the message 00071 playShots_.readMessage(playMovesMessage); 00072 00073 // Play the shots 00074 ScorchedClient::instance()->getActionController(). 00075 getRandom().seed(playMovesMessage.getSeed()); 00076 shotState_.setup(); 00077 00078 // Ensure and move to the shot state 00079 ScorchedClient::instance()->getGameState().stimulate(ClientState::StimWait); 00080 ScorchedClient::instance()->getGameState().checkStimulate(); 00081 ScorchedClient::instance()->getGameState().stimulate(ClientState::StimShot); 00082 return true; 00083 } 00084 00085 void ClientShotState::enterState(const unsigned state) 00086 { 00087 // Not needed as setup is done above 00088 } 00089 00090 bool ClientShotState::acceptStateChange(const unsigned state, 00091 const unsigned nextState, 00092 float frameTime) 00093 { 00094 // All the shots have finished, move to finished 00095 if (shotState_.run(frameTime)) 00096 { 00097 // Tell the server we have finished processing the landscape 00098 // This will stimulate us into the wait state 00099 ClientWaitState::instance()->sendClientReady(); 00100 return false; // This is done by the send ready 00101 } 00102 00103 return false; 00104 }
1.5.3