OpenClonk
C4MeshAnimation.cpp File Reference
#include "C4Include.h"
#include "object/C4MeshAnimation.h"
#include "object/C4Object.h"
#include "script/C4Aul.h"
#include "script/C4ValueArray.h"
Include dependency graph for C4MeshAnimation.cpp:

Go to the source code of this file.

Functions

StdMeshInstance::ValueProviderCreateValueProviderFromArray (C4Object *pForObj, C4ValueArray &Data, const StdMeshAnimation *pos_for_animation)
 

Function Documentation

◆ CreateValueProviderFromArray()

StdMeshInstance::ValueProvider* CreateValueProviderFromArray ( C4Object pForObj,
C4ValueArray Data,
const StdMeshAnimation pos_for_animation 
)

Definition at line 46 of file C4MeshAnimation.cpp.

47 {
48  int32_t type = Data[0].getInt();
49  switch (type)
50  {
51  case C4AVP_Const:
52  return new C4ValueProviderConst(itofix(Data[1].getInt(), 1000));
53  case C4AVP_Linear:
54  {
55  int32_t end = Data[3].getInt(), len = Data[4].getInt();
56  if (len == 0)
57  throw C4AulExecError("Length cannot be zero");
58  // Sanity check for linear animations that are too long and could cause excessive animation stacks
59  if (pos_for_animation)
60  {
61  int32_t max_end = fixtoi(ftofix(pos_for_animation->Length), 1000);
62  if (end < 0 || end > max_end)
63  throw C4AulExecError(FormatString("End (%d) not in range of animation '%s' (0-%d).", (int)end, pos_for_animation->Name.getData(), (int)max_end).getData());
64  }
65  return new C4ValueProviderLinear(itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(end, 1000), len, static_cast<C4AnimationEnding>(Data[5].getInt()));
66  }
67  case C4AVP_X:
68  if (!pForObj) return nullptr;
69  if (Data[4].getInt() == 0)
70  throw C4AulExecError("Length cannot be zero");
71 
72  return new C4ValueProviderX(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(), 1000), Data[4].getInt());
73  case C4AVP_Y:
74  if (!pForObj) return nullptr;
75  if (Data[4].getInt() == 0)
76  throw C4AulExecError("Length cannot be zero");
77 
78  return new C4ValueProviderY(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(), 1000), Data[4].getInt());
79  case C4AVP_R:
80  if(Data.GetSize() >= 4 && Data[3] != C4VNull)
81  pForObj = Data[3].getObj();
82  if (!pForObj) return nullptr;
83  return new C4ValueProviderR(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000));
84  case C4AVP_AbsX:
85  if (!pForObj) return nullptr;
86  if (Data[4].getInt() == 0)
87  throw C4AulExecError("Length cannot be zero");
88  return new C4ValueProviderAbsX(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(), 1000), Data[4].getInt());
89  case C4AVP_AbsY:
90  if (!pForObj) return nullptr;
91  if (Data[4].getInt() == 0)
92  throw C4AulExecError("Length cannot be zero");
93  return new C4ValueProviderAbsY(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(), 1000), Data[4].getInt());
94  case C4AVP_Dist:
95  if (!pForObj) return nullptr;
96  if (Data[4].getInt() == 0)
97  throw C4AulExecError("Length cannot be zero");
98  return new C4ValueProviderDist(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(), 1000), Data[4].getInt());
99  case C4AVP_XDir:
100  if (!pForObj) return nullptr;
101  if (Data[3].getInt() == 0)
102  throw C4AulExecError("MaxXDir cannot be zero");
103  return new C4ValueProviderXDir(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(),Data[4].getInt()));
104  case C4AVP_YDir:
105  if (!pForObj) return nullptr;
106  if (Data[3].getInt() == 0)
107  throw C4AulExecError("MaxYDir cannot be zero");
108  return new C4ValueProviderYDir(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(),Data[4].getInt()));
109  case C4AVP_RDir:
110  if (!pForObj) return nullptr;
111  if (Data[4].getInt() - Data[3].getInt() == 0)
112  throw C4AulExecError("MaxRDir - MinRDir cannot be zero");
113  return new C4ValueProviderRDir(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(),Data[5].getInt()), itofix(Data[4].getInt(),Data[5].getInt()));
114 
115  case C4AVP_AbsRDir:
116  if (!pForObj) return nullptr;
117  if (Data[4].getInt() - Data[3].getInt() == 0)
118  throw C4AulExecError("MaxRDir - MinRDir cannot be zero");
119  return new C4ValueProviderAbsRDir(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(),Data[5].getInt()), itofix(Data[4].getInt(),Data[5].getInt()));
120  case C4AVP_CosR:
121  if (!pForObj) return nullptr;
122  return new C4ValueProviderCosR(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(),Data[4].getInt()));
123  case C4AVP_SinR:
124  if (!pForObj) return nullptr;
125  return new C4ValueProviderSinR(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(),Data[4].getInt()));
126  case C4AVP_CosV:
127  if (!pForObj) return nullptr;
128  return new C4ValueProviderCosV(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(),Data[4].getInt()));
129  case C4AVP_SinV:
130  if (!pForObj) return nullptr;
131  return new C4ValueProviderSinV(pForObj, itofix(Data[1].getInt(), 1000), itofix(Data[2].getInt(), 1000), itofix(Data[3].getInt(),Data[4].getInt()));
132  case C4AVP_Action:
133  if (!pForObj) return nullptr;
134  return new C4ValueProviderAction(pForObj);
135  default:
136  return nullptr;
137  }
138 }
@ C4AVP_XDir
@ C4AVP_CosV
@ C4AVP_YDir
@ C4AVP_X
@ C4AVP_Y
@ C4AVP_AbsY
@ C4AVP_Dist
@ C4AVP_Linear
@ C4AVP_AbsRDir
@ C4AVP_AbsX
@ C4AVP_Action
@ C4AVP_R
@ C4AVP_CosR
@ C4AVP_SinR
@ C4AVP_Const
@ C4AVP_SinV
@ C4AVP_RDir
C4AnimationEnding
C4Fixed itofix(int32_t x)
Definition: C4Real.h:261
int fixtoi(const C4Fixed &x)
Definition: C4Real.h:259
C4Fixed ftofix(float x)
Definition: C4Real.h:258
const C4Value C4VNull
Definition: C4Value.cpp:30
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:270
int32_t GetSize() const
Definition: C4ValueArray.h:36
StdCopyStrBuf Name
Definition: StdMesh.h:97
float Length
Definition: StdMesh.h:98
const char * getData() const
Definition: StdBuf.h:442

References C4AVP_AbsRDir, C4AVP_AbsX, C4AVP_AbsY, C4AVP_Action, C4AVP_Const, C4AVP_CosR, C4AVP_CosV, C4AVP_Dist, C4AVP_Linear, C4AVP_R, C4AVP_RDir, C4AVP_SinR, C4AVP_SinV, C4AVP_X, C4AVP_XDir, C4AVP_Y, C4AVP_YDir, C4VNull, fixtoi(), FormatString(), ftofix(), StdStrBuf::getData(), C4ValueArray::GetSize(), itofix(), StdMeshAnimation::Length, and StdMeshAnimation::Name.

Here is the call graph for this function: