Fixed CPlayer init, it was called too early.
nothing important on the logger
3 #include "sm_autonatives.h"
5 #include "sp_typeutil.h"
7 using namespace SourcePawn;
9 /****************************************
11 * FLOATING POINT NATIVE IMPLEMENTATIONS *
13 ****************************************/
16 static cell_t sm_float(IPluginContext *pCtx, const cell_t *params)
18 float val = static_cast<float>(params[1]);
23 static cell_t sm_FloatAbs(IPluginContext *pCtx, const cell_t *params)
25 float val = sp_ctof(params[1]);
26 val = (val >= 0) ? val : -val;
31 static cell_t sm_FloatAdd(IPluginContext *pCtx, const cell_t *params)
33 float val = sp_ctof(params[1]) + sp_ctof(params[2]);
38 static cell_t sm_FloatSub(IPluginContext *pCtx, const cell_t *params)
40 float val = sp_ctof(params[1]) - sp_ctof(params[2]);
45 static cell_t sm_FloatMul(IPluginContext *pCtx, const cell_t *params)
47 float val = sp_ctof(params[1]) * sp_ctof(params[2]);
52 static cell_t sm_FloatDiv(IPluginContext *pCtx, const cell_t *params)
54 float val = sp_ctof(params[1]) / sp_ctof(params[2]);
59 static cell_t sm_FloatCompare(IPluginContext *pCtx, const cell_t *params)
61 float val1 = sp_ctof(params[1]);
62 float val2 = sp_ctof(params[2]);
67 } else if (val1 < val2) {
74 static cell_t sm_Logarithm(IPluginContext *pCtx, const cell_t *params)
76 float val = sp_ctof(params[1]);
77 float base = sp_ctof(params[2]);
79 if ((val <= 0) || (base <= 0))
81 return pCtx->ThrowNativeError("Cannot evaluate the logarithm of zero or a negative number (val:%f base:%f).", val, base);
87 val = log(val) / log(base);
93 static cell_t sm_Exponential(IPluginContext *pCtx, const cell_t *params)
95 float val = sp_ctof(params[1]);
97 return sp_ftoc(exp(val));
100 static cell_t sm_Pow(IPluginContext *pCtx, const cell_t *params)
102 float base = sp_ctof(params[1]);
103 float exponent = sp_ctof(params[2]);
105 return sp_ftoc(pow(base, exponent));
108 static cell_t sm_SquareRoot(IPluginContext *pCtx, const cell_t *params)
110 float val = sp_ctof(params[1]);
114 return pCtx->ThrowNativeError("Cannot evaluate the square root of a negative number (val:%f).", val);
117 return sp_ftoc(sqrt(val));
120 static cell_t sm_FloatRound(IPluginContext *pCtx, const cell_t *params)
122 float val = sp_ctof(params[1]);
148 val = (float)floor(val + 0.5);
153 return static_cast<int>(val);
156 static cell_t sm_FloatStr(IPluginContext *pCtx, const cell_t *params)
160 pCtx->LocalToString(params[1], &str);
166 return sp_ftoc((float)atof(str));
169 static cell_t sm_FloatFraction(IPluginContext *pCtx, const cell_t *params)
171 float val = sp_ctof(params[1]);
172 val = val - floor(val);
177 static cell_t sm_Sine(IPluginContext *pCtx, const cell_t *params)
179 float val = sp_ctof(params[1]);
185 static cell_t sm_Cosine(IPluginContext *pCtx, const cell_t *params)
187 float val = sp_ctof(params[1]);
193 static cell_t sm_Tangent(IPluginContext *pCtx, const cell_t *params)
195 float val = sp_ctof(params[1]);
201 static cell_t sm_ArcSine(IPluginContext *pCtx, const cell_t *params)
203 float val = sp_ctof(params[1]);
209 static cell_t sm_ArcCosine(IPluginContext *pCtx, const cell_t *params)
211 float val = sp_ctof(params[1]);
217 static cell_t sm_ArcTangent(IPluginContext *pCtx, const cell_t *params)
219 float val = sp_ctof(params[1]);
225 static cell_t sm_ArcTangent2(IPluginContext *pCtx, const cell_t *params)
227 float val1 = sp_ctof(params[1]);
228 float val2 = sp_ctof(params[2]);
229 val1 = atan2(val1, val2);
231 return sp_ftoc(val1);
234 REGISTER_NATIVES(floatnatives)
237 {"FloatStr", sm_FloatStr},
238 {"FloatMul", sm_FloatMul},
239 {"FloatDiv", sm_FloatDiv},
240 {"FloatAdd", sm_FloatAdd},
241 {"FloatSub", sm_FloatSub},
242 {"FloatFraction", sm_FloatFraction},
243 {"FloatRound", sm_FloatRound},
244 {"FloatCompare", sm_FloatCompare},
245 {"SquareRoot", sm_SquareRoot},
247 {"Exponential", sm_Exponential},
248 {"Logarithm", sm_Logarithm},
250 {"Cosine", sm_Cosine},
251 {"Tangent", sm_Tangent},
252 {"FloatAbs", sm_FloatAbs},
253 {"ArcTangent", sm_ArcTangent},
254 {"ArcCosine", sm_ArcCosine},
255 {"ArcSine", sm_ArcSine},
256 {"ArcTangent2", sm_ArcTangent2},