Main Page   Class Hierarchy   Compound List   File List   Compound Members  

glgraph.h

00001 /*--License:
00002         Kyra Sprite Engine
00003         Copyright Lee Thomason (Grinning Lizard Software) 2001-2002
00004         www.grinninglizard.com/kyra
00005         www.sourceforge.net/projects/kyra
00006 
00007         Kyra is provided under 2 licenses:
00008 
00009         - The GPL, with no additional restrictions.
00010         - The LGPL, provided you display the Kyra splash screen, described below.
00011 
00012 
00013 --- GPL License --
00014         This program is free software; you can redistribute it and/or
00015         modify it under the terms of the GNU General Public License
00016         as published by the Free Software Foundation; either version 2
00017         of the License, or (at your option) any later version.
00018 
00019         This program is distributed in the hope that it will be useful,
00020         but WITHOUT ANY WARRANTY; without even the implied warranty of
00021         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022         GNU General Public License for more details.
00023 
00024         You should have received a copy of the GNU General Public License
00025         along with this program; if not, write to the Free Software
00026         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028         The full text of the license can be found in license.txt
00029 
00030 
00031 --- LGPL License --
00032   **Provided you kindly display the Kyra splash screen (details below), 
00033         you     may use the LGPL license:**
00034 
00035     This library is free software; you can redistribute it and/or
00036     modify it under the terms of the GNU Lesser General Public
00037     License as published by the Free Software Foundation; either
00038     version 2.1 of the License, or (at your option) any later version.
00039 
00040     This library is distributed in the hope that it will be useful,
00041     but WITHOUT ANY WARRANTY; without even the implied warranty of
00042     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00043     Lesser General Public License for more details.
00044 
00045     You should have received a copy of the GNU Lesser General Public
00046     License along with this library; if not, write to the Free Software
00047     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00048 
00049         The full text of the license can be found in lgpl.txt
00050 
00051 
00052 --- Kyra Splash Screen.
00053 
00054         It would be appreciate if you display the Kyra splash screen when using
00055         either license, however it is only required for the LGPL. All the
00056         resources for the splash are compiled into the library, and it can be
00057         accessed through the following API:
00058 
00059                 KrEngine::StartSplash
00060                 KrEngine::UpdateSplash
00061                 KrEngine::EndSplash
00062 
00063         Full documentation is provided with the KrEngine class. The splash screen
00064         should be displayed for 2 seconds.
00065 
00066         Thank you.
00067 */
00068 
00069 #ifndef GLGRAPH_INCLUDED
00070 #define GLGRAPH_INCLUDED
00071 
00072 #include "gllist.h"
00073 #include "gldynarray.h"
00074 #include "glinsidelist.h"
00075 #include "glcirclelist.h"
00076 
00077 
00078 /*      A class to solve a graph algorith. Vertices and edges, which have a travel cost, in
00079         a connected system.
00080 */
00081 class GlGraph
00082 {
00083   public:
00084 
00085         GlGraph( int numVertex );
00086         ~GlGraph();
00087 
00091         void AddBiEdge( int source, int dest, int length );
00092 
00096         void AddBiEdge( int source, int dest, int lengthSourceToDest, int lengthDestToSource );
00097 
00101         void AddEdge( int source, int dest, int length );
00102 
00108         void GetPath( int source, int dest, int *nextVertex, int* length, int *distance );
00109 
00110         #ifdef DEBUG
00111                 void DumpVertex();
00112         #endif
00113 
00114   private:
00115         struct DataPoint
00116         {
00117                 int             distance;       // from the DataPoint to the destination
00118                 int             vertex;         // the vertex to take
00119         };
00120 
00121         struct Edge
00122         {
00123                 int lengthTo;   // how long the edge is, from the source vertex to 'toVertex'
00124                 int lengthFrom; // how long the edge is, from the 'toVertex' back to the source
00125                 int toVertex;   // which vertex this edge goes to
00126 
00127                 bool operator==( const Edge& rhs )      { return lengthTo == rhs.lengthTo && lengthFrom == rhs.lengthFrom && toVertex == rhs.toVertex; }
00128         };
00129 
00130         struct Vertex
00131         {
00132                 Vertex() : destinationCalculated( false ) {}
00133 
00134                 bool                    destinationCalculated;
00135                 GlSList< Edge > edgeList;
00136         };
00137         
00138         void LowerAddEdge( int v0, int v1, int length0to1, int length1to0 );
00139         void ShortestPathCalc( int destVertex );
00140         DataPoint* GetDataPoint( int source, int dest ) { return ( dataPoint + dest * numVertex + source ); }
00141         int FindCheapest( GlCircleList<int>* set, int dest );
00142 
00143         enum {
00144                 GL_INFINITE = 0x1000000
00145         };
00146 
00147         int                                     numVertex;
00148         Vertex                          *vertex;
00149         DataPoint                       *dataPoint;
00150 };
00151 
00152 
00153 #endif
00154 
00155 

Generated on Fri Feb 7 20:44:20 2003 for Kyra by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001