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

#include <C4FindObject.h>

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

Public Member Functions

 C4SortObjectSpeed ()
 
virtual int32_t Compare (C4Object *pObj1, C4Object *pObj2)
 
virtual bool PrepareCache (const C4ValueArray *pObjs)
 
virtual int32_t CompareCache (int32_t iObj1, int32_t iObj2, C4Object *pObj1, C4Object *pObj2)
 
void SortObjects (C4ValueArray *pArray)
 

Static Public Member Functions

static C4SortObjectCreateByValue (const C4Value &Data, const C4Object *context=nullptr)
 
static C4SortObjectCreateByValue (int32_t iType, const C4ValueArray &Data, const C4Object *context=nullptr)
 

Protected Member Functions

int32_t CompareGetValue (C4Object *pFor)
 

Detailed Description

Definition at line 496 of file C4FindObject.h.

Constructor & Destructor Documentation

C4SortObjectSpeed::C4SortObjectSpeed ( )
inline

Definition at line 499 of file C4FindObject.h.

Member Function Documentation

int32_t C4SortObjectByValue::Compare ( C4Object pObj1,
C4Object pObj2 
)
virtualinherited

Implements C4SortObject.

Definition at line 943 of file C4FindObject.cpp.

References C4SortObjectByValue::CompareGetValue().

944 {
945  // this is rather slow, should only be called in special cases
946 
947  // make sure to hardcode the call order, as it might lead to desyncs otherwise [Icewing]
948  int32_t iValue1 = CompareGetValue(pObj1);
949  int32_t iValue2 = CompareGetValue(pObj2);
950  return iValue2 - iValue1;
951 }
virtual int32_t CompareGetValue(C4Object *pOf)=0

Here is the call graph for this function:

int32_t C4SortObjectByValue::CompareCache ( int32_t  iObj1,
int32_t  iObj2,
C4Object pObj1,
C4Object pObj2 
)
virtualinherited

Reimplemented from C4SortObject.

Definition at line 953 of file C4FindObject.cpp.

954 {
955  assert(pVals); assert(iObj1 >= 0 && iObj1 < iSize); assert(iObj2 >= 0 && iObj2 < iSize);
956  // Might overflow for large values...!
957  return pVals[iObj2] - pVals[iObj1];
958 }
int iSize
Definition: TstC4NetIO.cpp:35
int32_t C4SortObjectSpeed::CompareGetValue ( C4Object pFor)
protectedvirtual

Implements C4SortObjectByValue.

Definition at line 1028 of file C4FindObject.cpp.

References fixtoi(), C4Object::xdir, and C4Object::ydir.

1029 {
1030  return fixtoi(pFor->xdir*pFor->xdir + pFor->ydir*pFor->ydir);
1031 }
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:

C4SortObject * C4SortObject::CreateByValue ( const C4Value Data,
const C4Object context = nullptr 
)
staticinherited

Definition at line 825 of file C4FindObject.cpp.

References C4Value::getArray().

Referenced by C4FindObject::CreateByValue(), and C4SortObject::CreateByValue().

826 {
827  // Must be an array
828  const C4ValueArray *pArray = C4Value(DataVal).getArray();
829  if (!pArray) return nullptr;
830  const C4ValueArray &Data = *pArray;
831  int32_t iType = Data[0].getInt();
832  return CreateByValue(iType, Data, context);
833 }
C4ValueArray * getArray() const
Definition: C4Value.h:118
static C4SortObject * CreateByValue(const C4Value &Data, const C4Object *context=nullptr)

Here is the call graph for this function:

Here is the caller graph for this function:

C4SortObject * C4SortObject::CreateByValue ( int32_t  iType,
const C4ValueArray Data,
const C4Object context = nullptr 
)
staticinherited

Definition at line 835 of file C4FindObject.cpp.

References C4SO_Distance, C4SO_Func, C4SO_Mass, C4SO_Multiple, C4SO_Random, C4SO_Reverse, C4SO_Speed, C4SO_Value, C4SortObject::CreateByValue(), C4ValueArray::GetSize(), C4Object::GetX(), C4Object::GetY(), iSize, and C4SortObjectFunc::SetPar().

836 {
837  switch (iType)
838  {
839  case C4SO_Reverse:
840  {
841  // create child sort
842  C4SortObject *pChildSort = C4SortObject::CreateByValue(Data[1], context);
843  if (!pChildSort) return nullptr;
844  // wrap
845  return new C4SortObjectReverse(pChildSort);
846  }
847 
848  case C4SO_Multiple:
849  {
850  // Trivial case (one sort)
851  if (Data.GetSize() == 2)
852  {
853  return C4SortObject::CreateByValue(Data[1], context);
854  }
855  // Create all children
856  int32_t i;
857  C4SortObject **ppSorts = new C4SortObject *[Data.GetSize() - 1];
858  for (i = 0; i < Data.GetSize() - 1; i++)
859  {
860  ppSorts[i] = C4SortObject::CreateByValue(Data[i+1], context);
861  }
862  // Count real entries, move them to start of list
863  int32_t iSize = 0;
864  for (i = 0; i < Data.GetSize() - 1; i++)
865  if (ppSorts[i])
866  if (iSize++ != i)
867  ppSorts[iSize-1] = ppSorts[i];
868  // Create
869  return new C4SortObjectMultiple(iSize, ppSorts);
870  }
871 
872  case C4SO_Distance:
873  {
874  int32_t x = Data[1].getInt();
875  int32_t y = Data[2].getInt();
876  if (context)
877  {
878  x += context->GetX();
879  y += context->GetY();
880  }
881  return new C4SortObjectDistance(x, y);
882  }
883 
884  case C4SO_Random:
885  return new C4SortObjectRandom();
886 
887  case C4SO_Speed:
888  return new C4SortObjectSpeed();
889 
890  case C4SO_Mass:
891  return new C4SortObjectMass();
892 
893  case C4SO_Value:
894  return new C4SortObjectValue();
895 
896  case C4SO_Func:
897  {
898  // Get function name
899  C4String *pStr = Data[1].getStr();
900  if (!pStr) return nullptr;
901  // Construct
902  C4SortObjectFunc *pSO = new C4SortObjectFunc(pStr);
903  // Add parameters
904  for (int i = 2; i < Data.GetSize(); i++)
905  pSO->SetPar(i - 2, Data[i]);
906  // Done
907  return pSO;
908  }
909 
910  }
911  return nullptr;
912 }
int32_t GetY() const
Definition: C4Object.h:287
int32_t GetX() const
Definition: C4Object.h:286
int32_t GetSize() const
Definition: C4ValueArray.h:36
static C4SortObject * CreateByValue(const C4Value &Data, const C4Object *context=nullptr)
void SetPar(int i, const C4Value &val)
int iSize
Definition: TstC4NetIO.cpp:35

Here is the call graph for this function:

bool C4SortObjectByValue::PrepareCache ( const C4ValueArray pObjs)
virtualinherited

Reimplemented from C4SortObject.

Definition at line 931 of file C4FindObject.cpp.

References C4Value::_getObj(), C4SortObjectByValue::CompareGetValue(), C4ValueArray::GetItem(), and C4ValueArray::GetSize().

932 {
933  // Clear old cache
934  delete [] pVals; pVals = nullptr; iSize = 0;
935  // Create new cache
936  iSize = pObjs->GetSize(); pVals = new int32_t [iSize];
937  for (int32_t i = 0; i < iSize; i++)
938  pVals[i] = CompareGetValue(pObjs->GetItem(i)._getObj());
939  // Okay
940  return true;
941 }
const C4Value & GetItem(int32_t iElem) const
Definition: C4ValueArray.h:38
virtual int32_t CompareGetValue(C4Object *pOf)=0
C4Object * _getObj() const
Definition: C4Value.cpp:75
int32_t GetSize() const
Definition: C4ValueArray.h:36
int iSize
Definition: TstC4NetIO.cpp:35

Here is the call graph for this function:

void C4SortObject::SortObjects ( C4ValueArray pArray)
inherited

Definition at line 914 of file C4FindObject.cpp.

References C4ValueArray::Sort().

Referenced by C4FindObject::FindMany().

915 {
916  pArray->Sort(*this);
917 }
void Sort(class C4SortObject &rSort)

Here is the call graph for this function:

Here is the caller graph for this function:


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