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
collideTrees Struct Reference

#include <unit_collide.h>

Public Member Functions

bool usingColTree () const
 
csOPCODECollidercolTree (Unit *un, const Vector &othervelocity)
 
 collideTrees (const std::string &hk, csOPCODECollider *cT, csOPCODECollider *cS)
 
void Inc ()
 
void Dec ()
 

Static Public Member Functions

static collideTreesGet (const std::string &hash_key)
 

Public Attributes

std::string hash_key
 
csOPCODEColliderrapidColliders [collideTreesMaxTrees]
 
csOPCODECollidercolShield
 
int refcount
 

Detailed Description

Definition at line 274 of file unit_collide.h.

Constructor & Destructor Documentation

collideTrees::collideTrees ( const std::string &  hk,
csOPCODECollider cT,
csOPCODECollider cS 
)

Definition at line 19 of file collide.cpp.

References collideTreesMaxTrees, hash_key, i, Hashtable< KEY, VALUE, SIZ >::Put(), rapidColliders, and refcount.

20  : hash_key( hk )
21  , colShield( cS )
22 {
23  for (unsigned int i = 0; i < collideTreesMaxTrees; ++i)
24  rapidColliders[i] = NULL;
25  rapidColliders[0] = cT;
26 
27  refcount = 1;
28  unitColliders.Put( hash_key, this );
29 }

Member Function Documentation

csOPCODECollider * collideTrees::colTree ( Unit un,
const Vector othervelocity 
)

Definition at line 32 of file collide.cpp.

References collideTreesMaxTrees, Unit::getCollideTree(), VegaConfig::getVariable(), Unit::GetVelocity(), XMLSupport::parse_int(), rapidColliders, Unit::rSize(), SIMULATION_ATOM, Vector, and vs_config.

Referenced by ContinuousTerrain::Collide(), Unit::Collide(), Unit::InsideCollideTree(), and Unit::rayCollide().

33 {
34  const float const_factor = 1;
35  float magsqr = un->GetVelocity().MagnitudeSquared();
36  float newmagsqr = (un->GetVelocity()-othervelocity).MagnitudeSquared();
37  float speedsquared = const_factor*const_factor*(magsqr > newmagsqr ? newmagsqr : magsqr);
38  static unsigned int max_collide_trees = static_cast<unsigned int>(XMLSupport::parse_int( vs_config->getVariable( "physics", "max_collide_trees", "16384" ) ));
39  if (un->rSize()*un->rSize() > SIMULATION_ATOM*SIMULATION_ATOM*speedsquared || max_collide_trees == 1)
40  return rapidColliders[0];
41  if (rapidColliders[0] == NULL)
42  return NULL;
43  if (un->rSize() <= 0.) //Shouldn't happen bug I've seen this for asteroid fields...
44  return NULL;
45  //Force pow to 0 in order to avoid nan problems...
46  unsigned int pow = 0;
47  if (pow >= collideTreesMaxTrees || pow >= max_collide_trees)
48  pow = collideTreesMaxTrees-1;
49  int val = 1<<pow;
50  if (rapidColliders[pow] == NULL)
51  rapidColliders[pow] = un->getCollideTree( Vector( 1, 1, val ) );
52  return rapidColliders[pow];
53 }
void collideTrees::Dec ( )

Definition at line 60 of file collide.cpp.

References collideTreesMaxTrees, colShield, Hashtable< KEY, VALUE, SIZ >::Delete(), hash_key, i, rapidColliders, and refcount.

61 {
62  refcount--;
63  if (refcount == 0) {
64  unitColliders.Delete( hash_key );
65  for (unsigned int i = 0; i < collideTreesMaxTrees; ++i)
66  if (rapidColliders[i])
67  delete rapidColliders[i];
68  if (colShield)
69  delete colShield;
70  delete this;
71  return;
72  }
73 }
collideTrees * collideTrees::Get ( const std::string &  hash_key)
static

Definition at line 55 of file collide.cpp.

References Hashtable< KEY, VALUE, SIZ >::Get().

Referenced by Unit::LoadRow().

56 {
57  return unitColliders.Get( hash_key );
58 }
void collideTrees::Inc ( )
inline

Definition at line 293 of file unit_collide.h.

References refcount.

Referenced by Unit::LoadRow().

294  {
295  refcount++;
296  }
bool collideTrees::usingColTree ( ) const
inline

Definition at line 280 of file unit_collide.h.

References rapidColliders.

Referenced by Unit::InsideCollideTree(), and LaunchOneParticle().

281  {
282  return rapidColliders[0] != NULL;
283  }

Member Data Documentation

csOPCODECollider* collideTrees::colShield

Definition at line 289 of file unit_collide.h.

Referenced by Dec().

std::string collideTrees::hash_key

Definition at line 276 of file unit_collide.h.

Referenced by collideTrees(), and Dec().

csOPCODECollider* collideTrees::rapidColliders[collideTreesMaxTrees]
int collideTrees::refcount

Definition at line 291 of file unit_collide.h.

Referenced by collideTrees(), Dec(), and Inc().


The documentation for this struct was generated from the following files: