Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

vertexes.cpp

Go to the documentation of this file.
00001 // libdoomwad: manipulates Doom wad files.
00002 // Copyright (C) 2005  John Gaughan
00003 //
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 //
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 //
00018 // This library is distributed with the full text of the LGPL. Please see
00019 // the accompanying file named COPYING.
00020 // 
00021 // You may contact the author at john@johngaughan.net
00022 
00028 // C++ required.
00029 #if !defined __cplusplus
00030 #error C++ compiler required
00031 #endif
00032 
00033 // C++ headers
00034 #include <exception>
00035 #include <sstream>
00036 #include <stdexcept>
00037 #include <string>
00038 
00039 // Doom headers
00040 #include "global.hpp"
00041 #include "lump.hpp"
00042 #include "vertexes.hpp"
00043 #include "wadentry.hpp"
00044 
00045 using namespace Doomwad;
00046 
00047 const size_t Vertex::LENGTH        = 0x00000004;
00048 const size_t GLVertex::LENGTH      = 0x00000008;
00049 const size_t GLVertexes::V2_MARKER = 0x674E6432;
00050 
00051 const std::string Vertexes::NAME   = "VERTEXES";
00052 const std::string GLVertexes::NAME = "GL_VERT";
00053 
00062 Vertex::Vertex (int16 _x, int16 _y) throw () : x (_x), y (_y)
00063 {
00064 }
00065 
00069 Vertex::~Vertex (void) throw ()
00070 {
00071 }
00072 
00073 size_t Vertex::getLength (void) const throw ()
00074 {
00075   return LENGTH;
00076 }
00077 
00078 bool Vertex::write (Lump &lump, Lump::size_type i) const throw ()
00079 {
00080   try
00081   {
00082     lump.setInt16 (this->x, i);
00083     lump.setInt16 (this->y, i + 2);
00084   }
00085   catch (std::range_error &e)
00086   {
00087     return false;
00088   }
00089   return true;
00090 }
00091 
00092 bool Vertex::read (const Lump &lump, Lump::size_type i) throw ()
00093 {
00094   try
00095   {
00096     this->x = lump.getInt16 (i);
00097     this->y = lump.getInt16 (i + 2);
00098   }
00099   catch (std::range_error &e)
00100   {
00101     return false;
00102   }
00103   return true;
00104 }
00105 
00106 std::string Vertex::toString (void) const throw ()
00107 {
00108   std::ostringstream str;
00109   str << '(' << this->x << ',' << this->y << ')';
00110   return str.str ();
00111 }
00112 
00121 GLVertex::GLVertex (int32 _x, int32 _y) throw () : x (_x), y (_y)
00122 {
00123   return;
00124 }
00125 
00129 GLVertex::~GLVertex (void) throw ()
00130 {
00131   return;
00132 }
00133 
00144 bool GLVertex::writeV1 (Lump &lump, Lump::size_type i) const throw ()
00145 {
00146   try
00147   {
00148     lump.setInt16 (this->x, i);
00149     lump.setInt16 (this->y, i + 2);
00150   }
00151   catch (std::range_error &e)
00152   {
00153     return false;
00154   }
00155   return true;
00156 }
00157 
00168 bool GLVertex::readV1 (const Lump &lump, Lump::size_type i) throw ()
00169 {
00170   try
00171   {
00172     this->x = lump.getInt16 (i);
00173     this->y = lump.getInt16 (i + 2);
00174   }
00175   catch (std::range_error &e)
00176   {
00177     return false;
00178   }
00179   return true;
00180 }
00181 
00182 size_t GLVertex::getLength (void) const throw ()
00183 {
00184   return LENGTH;
00185 }
00186 
00187 bool GLVertex::write (Lump &lump, Lump::size_type i) const throw ()
00188 {
00189   try
00190   {
00191     lump.setInt32 (this->x, i);
00192     lump.setInt32 (this->y, i + 4);
00193   }
00194   catch (std::range_error &e)
00195   {
00196     return false;
00197   }
00198   return true;
00199 }
00200 
00201 bool GLVertex::read (const Lump &lump, Lump::size_type i) throw ()
00202 {
00203   try
00204   {
00205     this->x = lump.getInt32 (i);
00206     this->y = lump.getInt32 (i + 4);
00207   }
00208   catch (std::range_error &e)
00209   {
00210     return false;
00211   }
00212   return true;
00213 }
00214 
00215 std::string GLVertex::toString (void) const throw ()
00216 {
00217   std::ostringstream str;
00218   str << '(' << this->x << ',' << this->y << ')';
00219   return str.str ();
00220 }
00221 
00225 Vertexes::Vertexes (void) throw ()
00226 {
00227   return;
00228 }
00229 
00239 Vertexes::Vertexes (const Lump &lump) throw ()
00240 {
00241   this->setFromLump (lump);
00242   return;
00243 }
00244 
00250 Vertexes::~Vertexes (void) throw ()
00251 {
00252   return;
00253 }
00254 
00255 bool Vertexes::setFromLump (const Lump &lump) throw ()
00256 {
00257 
00258   // Vertexes lumps must be multiples of 4 bytes
00259   if (lump.size () % Vertex::LENGTH != 0) return false;
00260 
00261   size_t q = lump.size ();
00262   Vertex v;
00263 
00264   this->clear ();
00265 
00266   for (size_t i = 0; i < q; i += Vertex::LENGTH)
00267   {
00268     v.read (lump, i);
00269     this->push_back (v);
00270   }
00271 
00272   return true;
00273 }
00274 
00275 Lump Vertexes::toLump (void) const throw ()
00276 {
00277   Lump lump (NAME, this->size () * Vertex::LENGTH);
00278   const_iterator iter = this->begin ();
00279   for (size_t i = 0; iter != this->end (); i += Vertex::LENGTH, ++iter)
00280   {
00281     iter->write (lump, i);
00282   }
00283   return lump;
00284 }
00285 
00286 std::string Vertexes::toString (void) const throw ()
00287 {
00288   std::ostringstream str;
00289   for (const_iterator iter = this->begin (); iter != this->end (); ++iter)
00290     str << iter->toString () << '\n';
00291   return str.str ();
00292 }
00293 
00299 GLVertexes::GLVertexes (void) throw ()
00300 {
00301   return;
00302 }
00303 
00312 GLVertexes::GLVertexes (const Lump &lump) throw ()
00313 {
00314   this->setFromLump (lump);
00315   return;
00316 }
00317 
00323 GLVertexes::~GLVertexes (void) throw ()
00324 {
00325   return;
00326 }
00327 
00328 bool GLVertexes::setFromLump (const Lump &lump) throw ()
00329 {
00330   // TODO: implement
00331   lump.size ();
00332   return true;
00333 }
00334 
00335 Lump GLVertexes::toLump (void) const throw ()
00336 {
00337   // TODO: implement
00338   Lump lump (NAME, this->size () * GLVertex::LENGTH);
00339   return lump;
00340 }
00341 
00349 Lump GLVertexes::toLumpV1 (void) const throw ()
00350 {
00351   // TODO: implement
00352   Lump lump (NAME, this->size () * GLVertex::LENGTH / 2);
00353   return lump;
00354 }
00355 
00356 std::string GLVertexes::toString (void) const throw ()
00357 {
00358   std::ostringstream str;
00359   for (GLVertexes::const_iterator i = this->begin (); i != this->end (); ++i)
00360     str << i->toString ();
00361   return str.str ();
00362 }

Generated on Fri Jun 10 19:38:51 2005 for libdoomwad by  doxygen 1.4.0