ComsLevelMessage.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 <landscapedef/LandscapeDefinition.h>
00022 #include <coms/ComsLevelMessage.h>
00023 #include <common/Defines.h>
00024 
00025 ComsLevelMessage::ComsLevelMessage() :
00026         ComsMessage("ComsLevelMessage")
00027 {
00028 
00029 }
00030 
00031 ComsLevelMessage::~ComsLevelMessage()
00032 {
00033 }
00034 
00035 void ComsLevelMessage::createMessage(LandscapeDefinition &hdef)
00036 {
00037         hdef_ = hdef;
00038 }
00039 
00040 LandscapeDefinition &ComsLevelMessage::getGroundMapsDefn()
00041 { 
00042         return hdef_; 
00043 }
00044 
00045 bool ComsLevelMessage::writeMessage(NetBuffer &buffer)
00046 {
00047         if (!hdef_.writeMessage(buffer)) return false;
00048         buffer.addToBuffer(newTargets_);
00049         buffer.addToBuffer(oldTargets_);
00050 
00051         buffer.addToBuffer((int) deformInfos_.size());
00052         {
00053                 std::vector<DeformLandscape::DeformInfo>::iterator itor;
00054                 for (itor = deformInfos_.begin();
00055                         itor != deformInfos_.end();
00056                         itor++)
00057                 {
00058                         DeformLandscape::DeformInfo &info = *itor;
00059                         buffer.addToBuffer(info.type);
00060                         buffer.addToBuffer(info.pos);
00061                         buffer.addToBuffer(info.radius);
00062                 }
00063         }       
00064 
00065         buffer.addToBuffer((int) targetIds_.size());
00066         {
00067                 std::set<unsigned int>::iterator itor;
00068                 for (itor = targetIds_.begin();
00069                         itor != targetIds_.end();
00070                         itor++)
00071                 {
00072                         buffer.addToBuffer(*itor);
00073                 }
00074         }
00075 
00076         return true;
00077 }
00078 
00079 bool ComsLevelMessage::readMessage(NetBufferReader &reader)
00080 {
00081         if (!hdef_.readMessage(reader)) return false;
00082         if (!reader.getFromBuffer(newTargets_)) return false;
00083         if (!reader.getFromBuffer(oldTargets_)) return false;
00084 
00085         int infosSize = 0;
00086         if (!reader.getFromBuffer(infosSize)) return false;
00087         for (int i=0; i<infosSize; i++)
00088         {
00089                 DeformLandscape::DeformInfo info;
00090                 if (!reader.getFromBuffer(info.type)) return false;
00091                 if (!reader.getFromBuffer(info.pos)) return false;
00092                 if (!reader.getFromBuffer(info.radius)) return false;
00093                 deformInfos_.push_back(info);
00094         }
00095 
00096         int targetIdSize = 0;
00097         if (!reader.getFromBuffer(targetIdSize)) return false;
00098         for (int i=0; i<targetIdSize; i++)
00099         {
00100                 unsigned int targetId = 0;
00101                 if (!reader.getFromBuffer(targetId)) return false;
00102                 targetIds_.insert(targetId);
00103         }
00104 
00105         return true;
00106 }
00107 

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