Merge pull request #7787 from SaracenOne/nan_and_inf
Inf and NaN support added to GDScript
This commit is contained in:
commit
c5df3d4d8d
|
@ -39,6 +39,7 @@
|
||||||
#define Math_PI 3.14159265358979323846
|
#define Math_PI 3.14159265358979323846
|
||||||
#define Math_SQRT12 0.7071067811865475244008443621048490
|
#define Math_SQRT12 0.7071067811865475244008443621048490
|
||||||
#define Math_LN2 0.693147180559945309417
|
#define Math_LN2 0.693147180559945309417
|
||||||
|
#define Math_INF INFINITY
|
||||||
#define Math_NAN NAN
|
#define Math_NAN NAN
|
||||||
|
|
||||||
class Math {
|
class Math {
|
||||||
|
|
|
@ -323,6 +323,16 @@ void GDScriptLanguage::get_public_constants(List<Pair<String,Variant> > *p_const
|
||||||
pi.first="PI";
|
pi.first="PI";
|
||||||
pi.second=Math_PI;
|
pi.second=Math_PI;
|
||||||
p_constants->push_back(pi);
|
p_constants->push_back(pi);
|
||||||
|
|
||||||
|
Pair<String, Variant> infinity;
|
||||||
|
infinity.first = "INF";
|
||||||
|
infinity.second = Math_INF;
|
||||||
|
p_constants->push_back(infinity);
|
||||||
|
|
||||||
|
Pair<String, Variant> nan;
|
||||||
|
nan.first = "NAN";
|
||||||
|
nan.second = Math_NAN;
|
||||||
|
p_constants->push_back(nan);
|
||||||
}
|
}
|
||||||
|
|
||||||
String GDScriptLanguage::make_function(const String& p_class,const String& p_name,const PoolStringArray& p_args) const {
|
String GDScriptLanguage::make_function(const String& p_class,const String& p_name,const PoolStringArray& p_args) const {
|
||||||
|
|
|
@ -375,6 +375,22 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
|
||||||
constant->value=Math_PI;
|
constant->value=Math_PI;
|
||||||
tokenizer->advance();
|
tokenizer->advance();
|
||||||
expr=constant;
|
expr=constant;
|
||||||
|
}
|
||||||
|
else if (tokenizer->get_token() == GDTokenizer::TK_CONST_INF) {
|
||||||
|
|
||||||
|
//constant defined by tokenizer
|
||||||
|
ConstantNode *constant = alloc_node<ConstantNode>();
|
||||||
|
constant->value = Math_INF;
|
||||||
|
tokenizer->advance();
|
||||||
|
expr = constant;
|
||||||
|
}
|
||||||
|
else if (tokenizer->get_token() == GDTokenizer::TK_CONST_NAN) {
|
||||||
|
|
||||||
|
//constant defined by tokenizer
|
||||||
|
ConstantNode *constant = alloc_node<ConstantNode>();
|
||||||
|
constant->value = Math_NAN;
|
||||||
|
tokenizer->advance();
|
||||||
|
expr = constant;
|
||||||
} else if (tokenizer->get_token()==GDTokenizer::TK_PR_PRELOAD) {
|
} else if (tokenizer->get_token()==GDTokenizer::TK_PR_PRELOAD) {
|
||||||
|
|
||||||
//constant defined by tokenizer
|
//constant defined by tokenizer
|
||||||
|
|
|
@ -1517,6 +1517,8 @@ void GDScriptLanguage::init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_add_global(StaticCString::create("PI"),Math_PI);
|
_add_global(StaticCString::create("PI"),Math_PI);
|
||||||
|
_add_global(StaticCString::create("INF"),Math_INF);
|
||||||
|
_add_global(StaticCString::create("NAN"),Math_NAN);
|
||||||
|
|
||||||
//populate native classes
|
//populate native classes
|
||||||
|
|
||||||
|
@ -1909,6 +1911,8 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
|
||||||
"bool",
|
"bool",
|
||||||
"null",
|
"null",
|
||||||
"PI",
|
"PI",
|
||||||
|
"INF",
|
||||||
|
"NAN",
|
||||||
"self",
|
"self",
|
||||||
"true",
|
"true",
|
||||||
// functions
|
// functions
|
||||||
|
|
|
@ -120,6 +120,8 @@ const char* GDTokenizer::token_names[TK_MAX]={
|
||||||
"'\\n'",
|
"'\\n'",
|
||||||
"PI",
|
"PI",
|
||||||
"_",
|
"_",
|
||||||
|
"INF",
|
||||||
|
"NAN",
|
||||||
"Error",
|
"Error",
|
||||||
"EOF",
|
"EOF",
|
||||||
"Cursor"};
|
"Cursor"};
|
||||||
|
@ -901,6 +903,8 @@ void GDTokenizerText::_advance() {
|
||||||
{TK_SELF,"self"},
|
{TK_SELF,"self"},
|
||||||
{TK_CONST_PI,"PI"},
|
{TK_CONST_PI,"PI"},
|
||||||
{TK_WILDCARD,"_"},
|
{TK_WILDCARD,"_"},
|
||||||
|
{TK_CONST_INF,"INF"},
|
||||||
|
{TK_CONST_NAN,"NAN"},
|
||||||
{TK_ERROR,NULL}
|
{TK_ERROR,NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -128,6 +128,8 @@ public:
|
||||||
TK_NEWLINE,
|
TK_NEWLINE,
|
||||||
TK_CONST_PI,
|
TK_CONST_PI,
|
||||||
TK_WILDCARD,
|
TK_WILDCARD,
|
||||||
|
TK_CONST_INF,
|
||||||
|
TK_CONST_NAN,
|
||||||
TK_ERROR,
|
TK_ERROR,
|
||||||
TK_EOF,
|
TK_EOF,
|
||||||
TK_CURSOR, //used for code completion
|
TK_CURSOR, //used for code completion
|
||||||
|
|
|
@ -558,6 +558,12 @@ Error VisualScriptExpression::_get_token(Token& r_token) {
|
||||||
} else if (id=="PI") {
|
} else if (id=="PI") {
|
||||||
r_token.type=TK_CONSTANT;
|
r_token.type=TK_CONSTANT;
|
||||||
r_token.value=Math_PI;
|
r_token.value=Math_PI;
|
||||||
|
} else if (id == "INF") {
|
||||||
|
r_token.type = TK_CONSTANT;
|
||||||
|
r_token.value = Math_INF;
|
||||||
|
} else if (id == "NAN") {
|
||||||
|
r_token.type = TK_CONSTANT;
|
||||||
|
r_token.value = Math_NAN;
|
||||||
} else if (id=="not") {
|
} else if (id=="not") {
|
||||||
r_token.type=TK_OP_NOT;
|
r_token.type=TK_OP_NOT;
|
||||||
} else if (id=="or") {
|
} else if (id=="or") {
|
||||||
|
|
|
@ -1738,6 +1738,8 @@ const char* VisualScriptMathConstant::const_name[MATH_CONSTANT_MAX]={
|
||||||
"PI/2",
|
"PI/2",
|
||||||
"E",
|
"E",
|
||||||
"Sqrt2",
|
"Sqrt2",
|
||||||
|
"INF",
|
||||||
|
"NAN"
|
||||||
};
|
};
|
||||||
|
|
||||||
double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX]={
|
double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX]={
|
||||||
|
@ -1746,7 +1748,9 @@ double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX]={
|
||||||
Math_PI*2,
|
Math_PI*2,
|
||||||
Math_PI*0.5,
|
Math_PI*0.5,
|
||||||
2.71828182845904523536,
|
2.71828182845904523536,
|
||||||
Math::sqrt(2.0)
|
Math::sqrt(2.0),
|
||||||
|
Math_INF,
|
||||||
|
Math_NAN
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -467,7 +467,9 @@ public:
|
||||||
MATH_CONSTANT_HALF_PI,
|
MATH_CONSTANT_HALF_PI,
|
||||||
MATH_CONSTANT_E,
|
MATH_CONSTANT_E,
|
||||||
MATH_CONSTANT_SQRT2,
|
MATH_CONSTANT_SQRT2,
|
||||||
MATH_CONSTANT_MAX,
|
MATH_CONSTANT_INF,
|
||||||
|
MATH_CONSTANT_NAN,
|
||||||
|
MATH_CONSTANT_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -711,7 +711,7 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode
|
||||||
else
|
else
|
||||||
rem = _process_node(tsn->inputs[0].node,r_prev_anim,p_time*tsn->scale,false,p_fallback_weight,p_weights);
|
rem = _process_node(tsn->inputs[0].node,r_prev_anim,p_time*tsn->scale,false,p_fallback_weight,p_weights);
|
||||||
if (tsn->scale == 0)
|
if (tsn->scale == 0)
|
||||||
return INFINITY;
|
return Math_INF;
|
||||||
else
|
else
|
||||||
return rem / tsn->scale;
|
return rem / tsn->scale;
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ public:
|
||||||
|
|
||||||
Plane get_plane() const;
|
Plane get_plane() const;
|
||||||
|
|
||||||
virtual real_t get_area() const { return INFINITY; }
|
virtual real_t get_area() const { return Math_INF; }
|
||||||
virtual PhysicsServer::ShapeType get_type() const { return PhysicsServer::SHAPE_PLANE; }
|
virtual PhysicsServer::ShapeType get_type() const { return PhysicsServer::SHAPE_PLANE; }
|
||||||
virtual void project_range(const Vector3& p_normal, const Transform& p_transform, real_t &r_min, real_t &r_max) const;
|
virtual void project_range(const Vector3& p_normal, const Transform& p_transform, real_t &r_min, real_t &r_max) const;
|
||||||
virtual Vector3 get_support(const Vector3& p_normal) const;
|
virtual Vector3 get_support(const Vector3& p_normal) const;
|
||||||
|
|
Loading…
Reference in New Issue