src/engine/eGrid.cpp File Reference

#include "eGrid.h"
#include "eTess2.h"
#include "rTexture.h"
#include "tEventQueue.h"
#include "eTimer.h"
#include "eWall.h"
#include "eGameObject.h"
#include "eCamera.h"
#include "tMath.h"
#include "nConfig.h"
#include "tRecorder.h"
#include <vector>
#include <set>

Include dependency graph for eGrid.cpp:

Go to the source code of this file.

Classes

class  eReplacementStorage
struct  eFaceReplacementArgument

Defines

#define SMALL_FLOAT   1E-30
#define SIMPLIFY

Typedefs

typedef std::vector
< tJUST_CONTROLLED_PTR< eFace > > 
eReplacementStorageBase
typedef std::pair< eFace *, REALeFaceScorePair
typedef std::set< const eFace * > eFaceVisitedSet

Functions

 tDEFINE_REFOBJ (ePoint) tDEFINE_REFOBJ(eHalfEdge) tDEFINE_REFOBJ(eFace) REAL se_EstimatedRangeOfMult(const eCoord &a
void se_LinkFaces (tControlledPTR< eFace > &old, eFace *replacement)
eFaceScorePair se_FindBestReplacement (const eFace *old, eFaceReplacementArgument &arg)
bool Movable (const ePoint *p)
void ClampMovement (const ePoint *p, eCoord &dir, const eHalfEdge *e)
void ClampMovement (const ePoint *p, eCoord &dir)
const eCoord se_zeroCoord (0, 0)
static void ProcessWallsRecursive (eGrid::WallProcessor *proc, const eCoord &pos, REAL range, eFace *start, eFace *from, int depthLeft)

Variables

const REAL se_maxGridSize = 1E+15
int se_debugExt = 0
static int se_simplifyEdges = 0
static const int se_simplifyEdgesSuccess = 20
static const int se_simplifyEdgesNew = 2
static nSettingItem< short > se_bugRipNet ("BUG_RIP", se_bugRip)
static eHalfEdgeleakEdge = NULL
static ePointleakPoint = NULL
static int se_drawLineTimeout = 10000
static tSettingItem< int > se_drawLineTimeoutConf ("DRAWLINE_TIMEOUT", se_drawLineTimeout)
eGridcurrentGrid = NULL
static REAL s_rangeSquared
static eFaces_start = NULL
static eFaces_processed = NULL


Define Documentation

#define SIMPLIFY

Definition at line 1664 of file eGrid.cpp.

#define SMALL_FLOAT   1E-30

Definition at line 50 of file eGrid.cpp.


Typedef Documentation

typedef std::pair< eFace*, REAL > eFaceScorePair

Definition at line 349 of file eGrid.cpp.

typedef std::set< const eFace* > eFaceVisitedSet

Definition at line 350 of file eGrid.cpp.

typedef std::vector< tJUST_CONTROLLED_PTR<eFace> > eReplacementStorageBase

Definition at line 331 of file eGrid.cpp.


Function Documentation

void ClampMovement ( const ePoint p,
eCoord &  dir 
)

Definition at line 1732 of file eGrid.cpp.

References ClampMovement(), eDual::Edge(), eHalfEdge::Next(), and eHalfEdge::Other().

01733 {
01734     eHalfEdge* run = p->Edge();
01735     eHalfEdge* stop =run;
01736 
01737     // run through all edges from this point
01738     do
01739     {
01740         // get the max mobility of the edge
01741         ClampMovement( p, dir, run );
01742 
01743         // advance to next edge from this point
01744         run = run->Other();
01745         if ( run )
01746             run = run->Next();
01747     }
01748     while ( run && stop != run );
01749 }

Here is the call graph for this function:

void ClampMovement ( const ePoint p,
eCoord &  dir,
const eHalfEdge e 
)

Definition at line 1694 of file eGrid.cpp.

References eCoord, eHalfEdge::Next(), eHalfEdge::next, REAL, tASSERT, and eHalfEdge::Vec().

Referenced by ClampMovement(), and eFace::CorrectArea().

01695 {
01696     eHalfEdge* next = e->Next();
01697     // get two of the side vectors of the face
01698     eCoord oppositeEdge = next->Vec();
01699     eCoord adjacentEdge = e->Vec();
01700 
01701     // calculate current surface area
01702     REAL area = oppositeEdge * adjacentEdge;
01703 
01704     // calculate the influence of the proposed movement on the surface area
01705     REAL areaChange = dir * oppositeEdge;
01706 
01707     // allow it if the change increases the area
01708     if ( areaChange >= 0 )
01709         return;
01710 
01711     // allow it if the change keeps the area positive
01712     if ( area + areaChange >= 0 )
01713         return;
01714 
01715     // if the current surface area is already negative, forbid the change
01716     if ( area < 0 )
01717     {
01718         dir = eCoord(0,0);
01719         return;
01720     }
01721 
01722     // clamp the desired movement
01723     REAL clampFactor = - area / areaChange;
01724     tASSERT( clampFactor >=0 && clampFactor <= 1 );
01725 
01726     // clamp
01727     dir = dir * clampFactor;
01728 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool Movable ( const ePoint p  ) 

Definition at line 1668 of file eGrid.cpp.

References eDual::Edge(), eHalfEdge::Movable(), eHalfEdge::Next(), and eHalfEdge::Other().

Referenced by eFace::CorrectArea().

01669 {
01670     eHalfEdge* run = p->Edge();
01671     eHalfEdge* stop =run;
01672 
01673     // run through all edges from this point
01674     do
01675     {
01676         // one of the edges contains a wall, abort:
01677         if ( !run->Movable() )
01678             return false;
01679 
01680         // advance to next edge from this point
01681         run = run->Other();
01682         if ( run )
01683             run = run->Next();
01684     }
01685     while ( run && stop != run );
01686 
01687     // no obstacles found.
01688     return true;
01689 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void ProcessWallsRecursive ( eGrid::WallProcessor *  proc,
const eCoord &  pos,
REAL  range,
eFace start,
eFace from,
int  depthLeft 
) [static]

Definition at line 2703 of file eGrid.cpp.

References eCoord, eDual::Edge(), eHalfEdge::Face(), eWallHolder::GetWall(), eHalfEdge::Next(), eFace::nextProcessed, NULL, eHalfEdge::Other(), eHalfEdge::Point(), REAL, tASSERT, and eHalfEdge::Vec().

Referenced by eGrid::ProcessWallsInRange().

02709 {
02710     tASSERT( start );
02711 
02712     if ( depthLeft < 0 )
02713         return;
02714 
02715     if ( start->nextProcessed )
02716         return;
02717 
02718     start->nextProcessed = s_processed;
02719     s_processed = start;
02720 
02721 
02722     eHalfEdge* leave = start->Edge();
02723     for ( int i = 2; i>=0; --i )
02724     {
02725         if ( leave->Other() && leave->Other()->Face() )
02726         {
02727             eCoord normal = leave->Vec().Conj();
02728             REAL normalLen = normal.Norm();
02729             if ( normalLen <= 0 )
02730                 continue;
02731             normal *= 1/ normalLen;
02732 
02733             eCoord Pos1 = normal.Turn( *leave->Point() - pos );
02734             eCoord Pos2 = normal.Turn( *leave->Other()->Point() - pos );
02735 
02736             tASSERT( fabs( Pos1.y - Pos2.y ) <= fabs( Pos1.y ) + fabs ( Pos2.y ) + .1f * .1f );
02737 
02738             // start test: the line through the edge "leave" must come closer than "range" to "pos"
02739             // and we have to be on the correct side
02740             if ( Pos1.y > -range && Pos1.y <= range*.01f )
02741             {
02742                 // check for real hit
02743                 if ( Pos1.x * Pos2.x < 0 ||
02744                         Pos1.NormSquared() < s_rangeSquared ||
02745                         Pos2.NormSquared() < s_rangeSquared )
02746                 {
02747                     // recurse
02748                     if ( NULL == leave->Other()->Face()->nextProcessed )
02749                         ProcessWallsRecursive( proc, pos, range, leave->Other()->Face(), start , depthLeft - 1 );
02750 
02751                     // process this wall
02752                     if ( leave->GetWall() )
02753                         (*proc) ( leave->GetWall() );
02754                     if ( leave->Other()->GetWall() )
02755                         (*proc) ( leave->Other()->GetWall() );
02756                 }
02757             }
02758         }
02759         leave = leave->Next();
02760     }
02761 }

Here is the call graph for this function:

Here is the caller graph for this function:

eFaceScorePair se_FindBestReplacement ( const eFace old,
eFaceReplacementArgument arg 
)

Definition at line 358 of file eGrid.cpp.

References eFaceReplacementArgument::coord, eFaceReplacementArgument::direction, eFace::GetReplacementStorage(), eFace::Insideness(), eDual::IsInGrid(), eFaceReplacementArgument::lastDirection, se_maxGridSize, and eFaceReplacementArgument::visited.

Referenced by eFace::FindReplacement().

00359 {
00360     // return invalid return if the face was already visited
00361     if ( arg.visited.find( old ) != arg.visited.end() )
00362         return eFaceScorePair( 0, -se_maxGridSize );
00363 
00364     // register face as visited
00365     arg.visited.insert( old );
00366 
00367     // find entry in replacement map
00368 
00369     {
00370         // real work starts here
00371         // get the vector of replacements
00372         const eReplacementStorage& storage = old->GetReplacementStorage();
00373 
00374         // iterate it
00375 
00376         // the currently best face/insideness pair
00377         std::pair< eFace*, REAL > best( 0, -100000 );
00378         for( eReplacementStorage::const_iterator i = storage.begin(); i != storage.end(); ++i )
00379         {
00380             // the current face/insideness pair
00381             eFaceScorePair current; // ( 0, -100000 );
00382 
00383             // the current face
00384             eFace* face = *i;
00385 
00386             // is it inside the grid?
00387             if ( face->IsInGrid() )
00388             {
00389                 // enter it directly
00390                 current.first = face;
00391                 current.second = face->Insideness( arg.coord, arg.direction, arg.lastDirection );
00392             }
00393             else
00394             {
00395                 // no, we have to look for a replacement recursively
00396                 current = se_FindBestReplacement( face, arg );
00397             }
00398 
00399             if ( current.second > best.second && current.first )
00400                 best = current;
00401         }
00402 
00403         return best;
00404     }
00405 }

Here is the call graph for this function:

Here is the caller graph for this function:

void se_LinkFaces ( tControlledPTR< eFace > &  old,
eFace replacement 
)

Definition at line 336 of file eGrid.cpp.

References tASSERT.

Referenced by eGrid::DrawLine(), eFace::eFace(), and eHalfEdge::Simplify().

00337 {
00338     tASSERT( old != replacement );
00339 
00340     // we only need to store an eFace if it is referenced by something different than
00341     // the pointer we got it by
00342     if ( old->GetRefcount() > 1 )
00343     {
00344         eReplacementStorage& storage = old->GetReplacementStorage();
00345         storage.push_back( replacement );
00346     }
00347 }

Here is the caller graph for this function:

const eCoord se_zeroCoord ( ,
 
)

tDEFINE_REFOBJ ( ePoint   )  const


Variable Documentation

eGrid* currentGrid = NULL

Definition at line 2067 of file eGrid.cpp.

eHalfEdge* leakEdge = NULL [static]

Definition at line 714 of file eGrid.cpp.

ePoint* leakPoint = NULL [static]

Definition at line 715 of file eGrid.cpp.

eFace* s_processed = NULL [static]

Definition at line 2700 of file eGrid.cpp.

REAL s_rangeSquared [static]

Definition at line 2698 of file eGrid.cpp.

eFace* s_start = NULL [static]

Definition at line 2699 of file eGrid.cpp.

nSettingItem<short> se_bugRipNet("BUG_RIP", se_bugRip) [static]

int se_debugExt = 0

Definition at line 55 of file eGrid.cpp.

int se_drawLineTimeout = 10000 [static]

Definition at line 717 of file eGrid.cpp.

tSettingItem<int> se_drawLineTimeoutConf("DRAWLINE_TIMEOUT", se_drawLineTimeout) [static]

const REAL se_maxGridSize = 1E+15

Definition at line 51 of file eGrid.cpp.

Referenced by eFace::Create(), eGrid::DrawLine(), eGrid::Grow(), eGrid::Range(), and se_FindBestReplacement().

int se_simplifyEdges = 0 [static]

Definition at line 58 of file eGrid.cpp.

Referenced by eGrid::DrawLine(), eGrid::SimplifyAll(), and eGrid::SimplifyNum().

const int se_simplifyEdgesNew = 2 [static]

Definition at line 65 of file eGrid.cpp.

Referenced by eGrid::DrawLine().

const int se_simplifyEdgesSuccess = 20 [static]

Definition at line 62 of file eGrid.cpp.

Referenced by eGrid::SimplifyNum().


Generated on Sat Mar 15 22:57:22 2008 for Armagetron Advanced by  doxygen 1.5.4