OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ValueProviderDist Class Reference

#include <C4MeshAnimation.h>

Inheritance diagram for C4ValueProviderDist:
[legend]
Collaboration diagram for C4ValueProviderDist:
[legend]

Public Member Functions

 C4ValueProviderDist ()
 
 C4ValueProviderDist (C4Object *object, C4Real pos, C4Real begin, C4Real end, int32_t length)
 
bool Execute () override
 
void CompileFunc (StdCompiler *pComp) override
 
void DenumeratePointers () override
 
void ClearPointers (C4Object *pObj) override
 

Static Public Member Functions

static const IDBaseLookup (const char *name)
 
static const IDBaseLookup (const std::type_info &type)
 

Public Attributes

C4Real Value
 

Detailed Description

Definition at line 164 of file C4MeshAnimation.h.

Constructor & Destructor Documentation

C4ValueProviderDist::C4ValueProviderDist ( )
inline

Definition at line 167 of file C4MeshAnimation.h.

167 : Object(nullptr), Begin(Fix0), End(Fix0) {}
const C4Real Fix0
Definition: C4Real.h:312
C4ValueProviderDist::C4ValueProviderDist ( C4Object object,
C4Real  pos,
C4Real  begin,
C4Real  end,
int32_t  length 
)

Definition at line 407 of file C4MeshAnimation.cpp.

References StdMeshInstanceValueProvider::Value.

407  :
408  Object(object), Begin(begin), End(end), Length(length)
409 {
410  Value = pos;
411 }

Member Function Documentation

void C4ValueProviderDist::ClearPointers ( C4Object pObj)
inlineoverridevirtual

Reimplemented from StdMeshInstance::SerializableValueProvider.

Definition at line 173 of file C4MeshAnimation.h.

173 { if(Object == pObj) Object = nullptr; }
void C4ValueProviderDist::CompileFunc ( StdCompiler pComp)
overridevirtual

Reimplemented from StdMeshInstance::SerializableValueProvider.

Definition at line 438 of file C4MeshAnimation.cpp.

References CompileFunc(), C4MenuItem::Object, StdCompiler::Separator(), and StdCompiler::Value().

439 {
441  pComp->Separator();
442  pComp->Value(Object);
443  pComp->Separator();
444  pComp->Value(Begin);
445  pComp->Separator();
446  pComp->Value(End);
447  pComp->Separator();
448  pComp->Value(Length);
449 }
virtual bool Separator(Sep eSep=SEP_SEP)
Definition: StdCompiler.h:119
void Value(const T &rStruct)
Definition: StdCompiler.h:161
void CompileFunc(C4Real &rValue, StdCompiler *pComp)
Definition: C4Real.cpp:9033

Here is the call graph for this function:

void C4ValueProviderDist::DenumeratePointers ( )
inlineoverridevirtual

Reimplemented from StdMeshInstance::SerializableValueProvider.

Definition at line 172 of file C4MeshAnimation.h.

References C4ObjectPtr::DenumeratePointers().

172 { Object.DenumeratePointers(); }
void DenumeratePointers()
Definition: C4ObjectPtr.cpp:47

Here is the call graph for this function:

bool C4ValueProviderDist::Execute ( )
overridevirtual

Implements StdMeshInstanceValueProvider.

Definition at line 413 of file C4MeshAnimation.cpp.

References Distance(), fixtoi(), itofix(), C4MenuItem::Object, StdMeshInstanceValueProvider::Value, C4Object::xdir, and C4Object::ydir.

414 {
415  // Object might have been removed
416  if(!Object) return false;
417 
418  // The following computes sqrt(xdir**2 + ydir**2), and it attempts to
419  // do so without involving floating point numbers, and at the same
420  // time cover a large range of xdir and ydir.
421  C4Real dist;
422  if(Object->xdir > itofix(256) || Object->ydir > itofix(256))
423  dist = itofix(Distance(0, 0, fixtoi(Object->xdir), fixtoi(Object->ydir)));
424  else if(Object->xdir > itofix(1) || Object->ydir > itofix(1))
425  dist = itofix(Distance(0, 0, fixtoi(Object->xdir, 256), fixtoi(Object->ydir, 256)), 256);
426  else
427  dist = itofix(Distance(0, 0, fixtoi(Object->xdir, 65536), fixtoi(Object->ydir, 65536)), 65536);
428 
429  Value += (End - Begin) * dist / Length;
430 
431  assert( (End >= Begin && Value >= Begin) || (End <= Begin && Value <= Begin));
432  while ( (End > Begin && Value > End) || (End < Begin && Value < End))
433  Value -= (End - Begin);
434 
435  return true;
436 }
Definition: C4Real.h:58
int32_t Distance(int32_t iX1, int32_t iY1, int32_t iX2, int32_t iY2)
Definition: Standard.cpp:25
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
C4Real xdir
Definition: C4Object.h:126
C4Real ydir
Definition: C4Object.h:126

Here is the call graph for this function:

static const IDBase* StdMeshInstance::SerializableValueProvider::Lookup ( const char *  name)
inlinestaticinherited

Definition at line 460 of file StdMesh.h.

References StdMeshInstance::SerializableValueProvider::IDBase::name.

461  {
462  if(!IDs) return nullptr;
463  for(auto & ID : *IDs)
464  if(strcmp(ID->name, name) == 0)
465  return ID;
466  return nullptr;
467  }
static const IDBase* StdMeshInstance::SerializableValueProvider::Lookup ( const std::type_info &  type)
inlinestaticinherited

Definition at line 469 of file StdMesh.h.

References StdMeshInstance::SerializableValueProvider::IDBase::type.

470  {
471  if(!IDs) return nullptr;
472  for(auto & ID : *IDs)
473  if(ID->type == type)
474  return ID;
475  return nullptr;
476  }

Member Data Documentation


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