Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gl_vertex_list.cpp File Reference
#include "gfxlib_struct.h"
#include "vegastrike.h"
#include "vs_globals.h"
#include "vsfilesystem.h"
#include <assert.h>
#include "gl_globals.h"
#include "gnuhash.h"
#include <map>

Go to the source code of this file.

Classes

struct  VertexCompare
 

Functions

void GFXOptimizeList (GFXVertex *old, int numV, GFXVertex **nw, int *nnewV, unsigned int **ind)
 Optimizes a list to reuse repeated vertices! More...
 

Variables

GFXVertexListnext
 

Function Documentation

void GFXOptimizeList ( GFXVertex old,
int  numV,
GFXVertex **  nw,
int nnewV,
unsigned int **  ind 
)

Optimizes a list to reuse repeated vertices!

Definition at line 68 of file gl_vertex_list.cpp.

References i, VsnetOSS::memcpy(), and VSFileSystem::vs_dprintf().

Referenced by Mesh::PostProcessLoading().

69 {
70  std::map< GFXVertex*, int, VertexCompare >vtxcache;
71 
72  *ind = (unsigned int*) malloc( sizeof (unsigned int)*numV );
73  *nw = (GFXVertex*) malloc( numV*sizeof (GFXVertex) );
74  int _nnewV = *nnewV = 0;
75  int i;
76  bool quickpath = true;
77  for (i = 0; i < numV; i++) {
78  std::map< GFXVertex*, int, VertexCompare >::const_iterator it = vtxcache.find( old+i );
79  if ( it != vtxcache.end() ) {
80  if (quickpath && i > 0) {
81  quickpath = false;
82  memcpy( *nw, old, sizeof(GFXVertex)*size_t(i) );
83  }
84  (*ind)[i] = it->second;
85  } else {
86  if (!quickpath)
87  memcpy( (*nw)+_nnewV, old+i, sizeof (GFXVertex) );
88  vtxcache[old+i] = ( (*ind)[i] ) = _nnewV;
89  ++_nnewV;
90  }
91  }
92  if (quickpath && i > 0)
93  memcpy( *nw, old, sizeof(GFXVertex)*size_t(i) );
94  *nnewV = _nnewV;
95 
96  VSFileSystem::vs_dprintf(3, "Optimized vertex list - vertices: %d -> %d\n", numV, *nnewV);
97 }

Variable Documentation

Definition at line 41 of file gl_vertex_list.cpp.

Referenced by commandI::fexecute(), and NavigationSystem::ParseFile().