meshnode.h

00001 /*--License:
00002         Lilith 3D Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2002-2004
00004         www.grinninglizard.com/lilith
00005 
00006         This program is free software; you can redistribute it and/or
00007         modify it under the terms of the GNU General Public License
00008         as published by the Free Software Foundation; either version 2
00009         of the License, or (at your option) any later version.
00010 
00011         This program 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 this program; if not, write to the Free Software
00018         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020         The full text of the license can be found in license.txt
00021 */
00022 
00023 #ifndef MESHNODE_INCLUDED
00024 #define MESHNODE_INCLUDED
00025 
00026 #include "../grinliz/gldebug.h"
00027 
00028 namespace lilith3d
00029 {
00030 
00031 // The parent of an Mesh - and never anything else! Backcasting
00032 // is used extensively.
00033 class MeshNode
00034 {
00035   public:
00036                 
00037         MeshNode() : next(0), prev(0)   {} 
00038         virtual ~MeshNode()
00039         {
00040                 // Make sure to take ourselves out of the container.
00041                 if ( InList() ) ListRemove();
00042         }
00043         
00044         // The mesh is in a doubly linked list of things that might be drawn:
00045         MeshNode* next;                 
00046         MeshNode* prev;
00047 
00048         bool InList()           {       GLASSERT( !prev || (prev&&next) );
00049                                                         GLASSERT( !next || (prev&&next) );
00050                                                         return next != 0;
00051                                                 }
00052 
00053         void ListRemove()       {       GLASSERT( prev );
00054                                                         GLASSERT( next );
00055                                                         prev->next = next;
00056                                                         next->prev = prev;
00057                                                         prev = next = 0;
00058                                                 }
00059         void ListAddAfter( MeshNode* add )
00060                                                 {
00061                                                         GLASSERT( add->next == 0 );
00062                                                         GLASSERT( add->prev == 0 );
00063                                                         if ( next )
00064                                                         {
00065                                                                 next->prev = add;
00066                                                                 add->next = next;
00067                                                         }
00068                                                         next = add;
00069                                                         add->prev = this;
00070                                                 }
00071 };
00072 
00073 };
00074 
00075 #endif

Generated on Fri Mar 23 19:36:22 2007 for Lilith3D by  doxygen 1.5.1-p1