mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r17498) -Add [NoAI]: Enable the squirrel std math library
This commit is contained in:
parent
6175ee0fa4
commit
ca6c4ee98a
@ -2447,6 +2447,10 @@
|
|||||||
RelativePath=".\..\src\3rdparty\squirrel\sqstdlib\sqstdaux.cpp"
|
RelativePath=".\..\src\3rdparty\squirrel\sqstdlib\sqstdaux.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\3rdparty\squirrel\sqstdlib\sqstdmath.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\3rdparty\squirrel\squirrel\sqtable.cpp"
|
RelativePath=".\..\src\3rdparty\squirrel\squirrel\sqtable.cpp"
|
||||||
>
|
>
|
||||||
|
@ -2444,6 +2444,10 @@
|
|||||||
RelativePath=".\..\src\3rdparty\squirrel\sqstdlib\sqstdaux.cpp"
|
RelativePath=".\..\src\3rdparty\squirrel\sqstdlib\sqstdaux.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\..\src\3rdparty\squirrel\sqstdlib\sqstdmath.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\..\src\3rdparty\squirrel\squirrel\sqtable.cpp"
|
RelativePath=".\..\src\3rdparty\squirrel\squirrel\sqtable.cpp"
|
||||||
>
|
>
|
||||||
|
@ -541,6 +541,7 @@ script/squirrel_std.hpp
|
|||||||
3rdparty/squirrel/squirrel/sqobject.cpp
|
3rdparty/squirrel/squirrel/sqobject.cpp
|
||||||
3rdparty/squirrel/squirrel/sqstate.cpp
|
3rdparty/squirrel/squirrel/sqstate.cpp
|
||||||
3rdparty/squirrel/sqstdlib/sqstdaux.cpp
|
3rdparty/squirrel/sqstdlib/sqstdaux.cpp
|
||||||
|
3rdparty/squirrel/sqstdlib/sqstdmath.cpp
|
||||||
3rdparty/squirrel/squirrel/sqtable.cpp
|
3rdparty/squirrel/squirrel/sqtable.cpp
|
||||||
3rdparty/squirrel/squirrel/sqvm.cpp
|
3rdparty/squirrel/squirrel/sqvm.cpp
|
||||||
|
|
||||||
|
1
src/3rdparty/squirrel/include/squirrel.h
vendored
1
src/3rdparty/squirrel/include/squirrel.h
vendored
@ -314,6 +314,7 @@ SQUIRREL_API bool sq_resumecatch(HSQUIRRELVM v, int suspend = -1);
|
|||||||
SQUIRREL_API bool sq_resumeerror(HSQUIRRELVM v);
|
SQUIRREL_API bool sq_resumeerror(HSQUIRRELVM v);
|
||||||
SQUIRREL_API SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
|
SQUIRREL_API SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
|
||||||
SQUIRREL_API SQInteger sq_getvmstate(HSQUIRRELVM v);
|
SQUIRREL_API SQInteger sq_getvmstate(HSQUIRRELVM v);
|
||||||
|
SQUIRREL_API void sq_decreaseops(HSQUIRRELVM v, int amount);
|
||||||
|
|
||||||
/*compiler*/
|
/*compiler*/
|
||||||
SQUIRREL_API SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
|
SQUIRREL_API SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
|
||||||
|
40
src/3rdparty/squirrel/sqstdlib/sqstdmath.cpp
vendored
40
src/3rdparty/squirrel/sqstdlib/sqstdmath.cpp
vendored
@ -4,15 +4,17 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sqstdmath.h>
|
#include <sqstdmath.h>
|
||||||
|
|
||||||
#define SINGLE_ARG_FUNC(_funcname) static SQInteger math_##_funcname(HSQUIRRELVM v){ \
|
#define SINGLE_ARG_FUNC(_funcname, num_ops) static SQInteger math_##_funcname(HSQUIRRELVM v){ \
|
||||||
SQFloat f; \
|
SQFloat f; \
|
||||||
|
sq_decreaseops(v,num_ops); \
|
||||||
sq_getfloat(v,2,&f); \
|
sq_getfloat(v,2,&f); \
|
||||||
sq_pushfloat(v,(SQFloat)_funcname(f)); \
|
sq_pushfloat(v,(SQFloat)_funcname(f)); \
|
||||||
return 1; \
|
return 1; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TWO_ARGS_FUNC(_funcname) static SQInteger math_##_funcname(HSQUIRRELVM v){ \
|
#define TWO_ARGS_FUNC(_funcname, num_ops) static SQInteger math_##_funcname(HSQUIRRELVM v){ \
|
||||||
SQFloat p1,p2; \
|
SQFloat p1,p2; \
|
||||||
|
sq_decreaseops(v,num_ops); \
|
||||||
sq_getfloat(v,2,&p1); \
|
sq_getfloat(v,2,&p1); \
|
||||||
sq_getfloat(v,3,&p2); \
|
sq_getfloat(v,3,&p2); \
|
||||||
sq_pushfloat(v,(SQFloat)_funcname(p1,p2)); \
|
sq_pushfloat(v,(SQFloat)_funcname(p1,p2)); \
|
||||||
@ -42,21 +44,21 @@ static SQInteger math_abs(HSQUIRRELVM v)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SINGLE_ARG_FUNC(sqrt)
|
SINGLE_ARG_FUNC(sqrt, 100)
|
||||||
SINGLE_ARG_FUNC(fabs)
|
SINGLE_ARG_FUNC(fabs, 1)
|
||||||
SINGLE_ARG_FUNC(sin)
|
SINGLE_ARG_FUNC(sin, 100)
|
||||||
SINGLE_ARG_FUNC(cos)
|
SINGLE_ARG_FUNC(cos, 100)
|
||||||
SINGLE_ARG_FUNC(asin)
|
SINGLE_ARG_FUNC(asin, 100)
|
||||||
SINGLE_ARG_FUNC(acos)
|
SINGLE_ARG_FUNC(acos, 100)
|
||||||
SINGLE_ARG_FUNC(log)
|
SINGLE_ARG_FUNC(log, 100)
|
||||||
SINGLE_ARG_FUNC(log10)
|
SINGLE_ARG_FUNC(log10, 100)
|
||||||
SINGLE_ARG_FUNC(tan)
|
SINGLE_ARG_FUNC(tan, 100)
|
||||||
SINGLE_ARG_FUNC(atan)
|
SINGLE_ARG_FUNC(atan, 100)
|
||||||
TWO_ARGS_FUNC(atan2)
|
TWO_ARGS_FUNC(atan2, 100)
|
||||||
TWO_ARGS_FUNC(pow)
|
TWO_ARGS_FUNC(pow, 100)
|
||||||
SINGLE_ARG_FUNC(floor)
|
SINGLE_ARG_FUNC(floor, 1)
|
||||||
SINGLE_ARG_FUNC(ceil)
|
SINGLE_ARG_FUNC(ceil, 1)
|
||||||
SINGLE_ARG_FUNC(exp)
|
SINGLE_ARG_FUNC(exp, 100)
|
||||||
|
|
||||||
#define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),math_##name,nparams,tycheck}
|
#define _DECL_FUNC(name,nparams,tycheck) {_SC(#name),math_##name,nparams,tycheck}
|
||||||
static SQRegFunction mathlib_funcs[] = {
|
static SQRegFunction mathlib_funcs[] = {
|
||||||
@ -74,8 +76,10 @@ static SQRegFunction mathlib_funcs[] = {
|
|||||||
_DECL_FUNC(floor,2,_SC(".n")),
|
_DECL_FUNC(floor,2,_SC(".n")),
|
||||||
_DECL_FUNC(ceil,2,_SC(".n")),
|
_DECL_FUNC(ceil,2,_SC(".n")),
|
||||||
_DECL_FUNC(exp,2,_SC(".n")),
|
_DECL_FUNC(exp,2,_SC(".n")),
|
||||||
|
#ifdef EXPORT_DEFAULT_SQUIRREL_FUNCTIONS
|
||||||
_DECL_FUNC(srand,2,_SC(".n")),
|
_DECL_FUNC(srand,2,_SC(".n")),
|
||||||
_DECL_FUNC(rand,1,NULL),
|
_DECL_FUNC(rand,1,NULL),
|
||||||
|
#endif /* EXPORT_DEFAULT_SQUIRREL_FUNCTIONS */
|
||||||
_DECL_FUNC(fabs,2,_SC(".n")),
|
_DECL_FUNC(fabs,2,_SC(".n")),
|
||||||
_DECL_FUNC(abs,2,_SC(".n")),
|
_DECL_FUNC(abs,2,_SC(".n")),
|
||||||
{0,0,0,0},
|
{0,0,0,0},
|
||||||
@ -96,9 +100,11 @@ SQRESULT sqstd_register_mathlib(HSQUIRRELVM v)
|
|||||||
sq_createslot(v,-3);
|
sq_createslot(v,-3);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
#ifdef EXPORT_DEFAULT_SQUIRREL_FUNCTIONS
|
||||||
sq_pushstring(v,_SC("RAND_MAX"),-1);
|
sq_pushstring(v,_SC("RAND_MAX"),-1);
|
||||||
sq_pushinteger(v,RAND_MAX);
|
sq_pushinteger(v,RAND_MAX);
|
||||||
sq_createslot(v,-3);
|
sq_createslot(v,-3);
|
||||||
|
#endif /* EXPORT_DEFAULT_SQUIRREL_FUNCTIONS */
|
||||||
sq_pushstring(v,_SC("PI"),-1);
|
sq_pushstring(v,_SC("PI"),-1);
|
||||||
sq_pushfloat(v,(SQFloat)M_PI);
|
sq_pushfloat(v,(SQFloat)M_PI);
|
||||||
sq_createslot(v,-3);
|
sq_createslot(v,-3);
|
||||||
|
5
src/3rdparty/squirrel/squirrel/sqapi.cpp
vendored
5
src/3rdparty/squirrel/squirrel/sqapi.cpp
vendored
@ -90,6 +90,11 @@ SQInteger sq_getvmstate(HSQUIRRELVM v)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sq_decreaseops(HSQUIRRELVM v, int amount)
|
||||||
|
{
|
||||||
|
v->DecreaseOps(amount);
|
||||||
|
}
|
||||||
|
|
||||||
bool sq_can_suspend(HSQUIRRELVM v)
|
bool sq_can_suspend(HSQUIRRELVM v)
|
||||||
{
|
{
|
||||||
return v->_nnativecalls <= 2;
|
return v->_nnativecalls <= 2;
|
||||||
|
@ -55,6 +55,7 @@ protected:
|
|||||||
public:
|
public:
|
||||||
friend class AIScanner;
|
friend class AIScanner;
|
||||||
friend class AIInstance;
|
friend class AIInstance;
|
||||||
|
friend void squirrel_register_std(Squirrel *engine);
|
||||||
|
|
||||||
Squirrel();
|
Squirrel();
|
||||||
~Squirrel();
|
~Squirrel();
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
/** @file squirrel_std.cpp Implements the Squirrel Standard Function class */
|
/** @file squirrel_std.cpp Implements the Squirrel Standard Function class */
|
||||||
|
|
||||||
#include <squirrel.h>
|
#include <squirrel.h>
|
||||||
|
#include <sqstdmath.h>
|
||||||
#include "../stdafx.h"
|
#include "../stdafx.h"
|
||||||
#include "../debug.h"
|
#include "../debug.h"
|
||||||
#include "squirrel.hpp"
|
#include "squirrel.hpp"
|
||||||
@ -17,17 +18,6 @@
|
|||||||
#include "../core/alloc_func.hpp"
|
#include "../core/alloc_func.hpp"
|
||||||
#include "../core/math_func.hpp"
|
#include "../core/math_func.hpp"
|
||||||
|
|
||||||
/* abs() is normally defined to myabs(), which we don't want in this file */
|
|
||||||
#undef abs
|
|
||||||
|
|
||||||
SQInteger SquirrelStd::abs(HSQUIRRELVM vm)
|
|
||||||
{
|
|
||||||
SQInteger tmp;
|
|
||||||
|
|
||||||
sq_getinteger(vm, 2, &tmp);
|
|
||||||
sq_pushinteger(vm, ::abs(tmp));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SQInteger SquirrelStd::min(HSQUIRRELVM vm)
|
SQInteger SquirrelStd::min(HSQUIRRELVM vm)
|
||||||
{
|
{
|
||||||
@ -118,7 +108,8 @@ void squirrel_register_std(Squirrel *engine)
|
|||||||
{
|
{
|
||||||
/* We don't use squirrel_helper here, as we want to register to the global
|
/* We don't use squirrel_helper here, as we want to register to the global
|
||||||
* scope and not to a class. */
|
* scope and not to a class. */
|
||||||
engine->AddMethod("abs", &SquirrelStd::abs, 2, ".i");
|
|
||||||
engine->AddMethod("min", &SquirrelStd::min, 3, ".ii");
|
engine->AddMethod("min", &SquirrelStd::min, 3, ".ii");
|
||||||
engine->AddMethod("max", &SquirrelStd::max, 3, ".ii");
|
engine->AddMethod("max", &SquirrelStd::max, 3, ".ii");
|
||||||
|
|
||||||
|
sqstd_register_mathlib(engine->GetVM());
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,6 @@
|
|||||||
*/
|
*/
|
||||||
class SquirrelStd {
|
class SquirrelStd {
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* Make an integer absolute.
|
|
||||||
*/
|
|
||||||
static SQInteger abs(HSQUIRRELVM vm);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the lowest of two integers.
|
* Get the lowest of two integers.
|
||||||
|
Loading…
Reference in New Issue
Block a user