Optimized forwards, now paused functions are stored in a temp list so we dont have to check if they're runnable on each function execution.
2 * ===============================================================
3 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
4 * ===============================================================
6 * This file is not open source and may not be copied without explicit
7 * written permission of AlliedModders LLC. This file may not be redistributed
8 * in whole or significant part.
9 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
17 #include "sm_autonatives.h"
18 #include "sp_vm_api.h"
19 #include "sp_typeutil.h"
21 using namespace SourcePawn;
23 /****************************************
25 * FLOATING POINT NATIVE IMPLEMENTATIONS *
27 ****************************************/
30 static cell_t sm_float(IPluginContext *pCtx, const cell_t *params)
32 float val = static_cast<float>(params[1]);
37 static cell_t sm_FloatAbs(IPluginContext *pCtx, const cell_t *params)
39 float val = sp_ctof(params[1]);
40 val = (val >= 0) ? val : -val;
45 static cell_t sm_FloatAdd(IPluginContext *pCtx, const cell_t *params)
47 float val = sp_ctof(params[1]) + sp_ctof(params[2]);
52 static cell_t sm_FloatSub(IPluginContext *pCtx, const cell_t *params)
54 float val = sp_ctof(params[1]) - sp_ctof(params[2]);
59 static cell_t sm_FloatMul(IPluginContext *pCtx, const cell_t *params)
61 float val = sp_ctof(params[1]) * sp_ctof(params[2]);
66 static cell_t sm_FloatDiv(IPluginContext *pCtx, const cell_t *params)
68 float val = sp_ctof(params[1]) / sp_ctof(params[2]);
73 static cell_t sm_FloatCompare(IPluginContext *pCtx, const cell_t *params)
75 float val1 = sp_ctof(params[1]);
76 float val2 = sp_ctof(params[2]);
81 } else if (val1 < val2) {
88 static cell_t sm_Logarithm(IPluginContext *pCtx, const cell_t *params)
90 float val = sp_ctof(params[1]);
91 float base = sp_ctof(params[2]);
93 if ((val <= 0) || (base <= 0))
95 return pCtx->ThrowNativeError("Cannot evaluate the logarithm of zero or a negative number (val:%f base:%f).", val, base);
101 val = log(val) / log(base);
107 static cell_t sm_Exponential(IPluginContext *pCtx, const cell_t *params)
109 float val = sp_ctof(params[1]);
111 return sp_ftoc(exp(val));
114 static cell_t sm_Pow(IPluginContext *pCtx, const cell_t *params)
116 float base = sp_ctof(params[1]);
117 float exponent = sp_ctof(params[2]);
119 return sp_ftoc(pow(base, exponent));
122 static cell_t sm_SquareRoot(IPluginContext *pCtx, const cell_t *params)
124 float val = sp_ctof(params[1]);
128 return pCtx->ThrowNativeError("Cannot evaluate the square root of a negative number (val:%f).", val);
131 return sp_ftoc(sqrt(val));
134 static cell_t sm_FloatRound(IPluginContext *pCtx, const cell_t *params)
136 float val = sp_ctof(params[1]);
162 val = (float)floor(val + 0.5);
167 return static_cast<int>(val);
170 static cell_t sm_FloatStr(IPluginContext *pCtx, const cell_t *params)
174 pCtx->LocalToString(params[1], &str);
180 return sp_ftoc((float)atof(str));
183 static cell_t sm_FloatFraction(IPluginContext *pCtx, const cell_t *params)
185 float val = sp_ctof(params[1]);
186 val = val - floor(val);
191 static cell_t sm_Sine(IPluginContext *pCtx, const cell_t *params)
193 float val = sp_ctof(params[1]);
199 static cell_t sm_Cosine(IPluginContext *pCtx, const cell_t *params)
201 float val = sp_ctof(params[1]);
207 static cell_t sm_Tangent(IPluginContext *pCtx, const cell_t *params)
209 float val = sp_ctof(params[1]);
215 static cell_t sm_ArcSine(IPluginContext *pCtx, const cell_t *params)
217 float val = sp_ctof(params[1]);
223 static cell_t sm_ArcCosine(IPluginContext *pCtx, const cell_t *params)
225 float val = sp_ctof(params[1]);
231 static cell_t sm_ArcTangent(IPluginContext *pCtx, const cell_t *params)
233 float val = sp_ctof(params[1]);
239 static cell_t sm_ArcTangent2(IPluginContext *pCtx, const cell_t *params)
241 float val1 = sp_ctof(params[1]);
242 float val2 = sp_ctof(params[2]);
243 val1 = atan2(val1, val2);
245 return sp_ftoc(val1);
248 REGISTER_NATIVES(floatnatives)
251 {"FloatStr", sm_FloatStr},
252 {"FloatMul", sm_FloatMul},
253 {"FloatDiv", sm_FloatDiv},
254 {"FloatAdd", sm_FloatAdd},
255 {"FloatSub", sm_FloatSub},
256 {"FloatFraction", sm_FloatFraction},
257 {"FloatRound", sm_FloatRound},
258 {"FloatCompare", sm_FloatCompare},
259 {"SquareRoot", sm_SquareRoot},
261 {"Exponential", sm_Exponential},
262 {"Logarithm", sm_Logarithm},
264 {"Cosine", sm_Cosine},
265 {"Tangent", sm_Tangent},
266 {"FloatAbs", sm_FloatAbs},
267 {"ArcTangent", sm_ArcTangent},
268 {"ArcCosine", sm_ArcCosine},
269 {"ArcSine", sm_ArcSine},
270 {"ArcTangent2", sm_ArcTangent2},