mirror of
https://github.com/godotengine/godot.git
synced 2025-01-30 21:33:18 +08:00
Changed Vector3.snap from fmod to stepify, which makes more sense, fixes #6399
This commit is contained in:
parent
78275aad87
commit
23ababdcd5
@ -65,13 +65,9 @@ int Vector3::max_axis() const {
|
||||
|
||||
void Vector3::snap(float p_val) {
|
||||
|
||||
x+=p_val/2.0;
|
||||
x-=Math::fmod(x,p_val);
|
||||
y+=p_val/2.0;
|
||||
y-=Math::fmod(y,p_val);
|
||||
z+=p_val/2.0;
|
||||
z-=Math::fmod(z,p_val);
|
||||
|
||||
x=Math::stepify(x,p_val);
|
||||
y=Math::stepify(y,p_val);
|
||||
z=Math::stepify(z,p_val);
|
||||
}
|
||||
Vector3 Vector3::snapped(float p_val) const {
|
||||
|
||||
|
@ -1417,7 +1417,8 @@ bool VisualScriptInstance::get(const StringName& p_name, Variant &r_ret) const {
|
||||
if (!E)
|
||||
return false;
|
||||
|
||||
return E->get();
|
||||
r_ret=E->get();
|
||||
return true;
|
||||
}
|
||||
void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const{
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -68,6 +68,11 @@ public:
|
||||
FUNC_MAX
|
||||
};
|
||||
|
||||
static int get_func_argument_count(BuiltinFunc p_func);
|
||||
static String get_func_name(BuiltinFunc p_func);
|
||||
static void exec_func(BuiltinFunc p_func, const Variant** p_inputs, Variant* r_return, Variant::CallError& r_error, String& r_error_str);
|
||||
static BuiltinFunc find_function(const String& p_string);
|
||||
|
||||
private:
|
||||
static const char* func_name[FUNC_MAX];
|
||||
BuiltinFunc func;
|
||||
|
@ -577,6 +577,13 @@ Error VisualScriptExpression::_get_token(Token& r_token) {
|
||||
}
|
||||
}
|
||||
|
||||
VisualScriptBuiltinFunc::BuiltinFunc bifunc = VisualScriptBuiltinFunc::find_function(id);
|
||||
if (bifunc!=VisualScriptBuiltinFunc::FUNC_MAX) {
|
||||
r_token.type=TK_BUILTIN_FUNC;
|
||||
r_token.value=bifunc;
|
||||
return OK;
|
||||
}
|
||||
|
||||
r_token.type=TK_IDENTIFIER;
|
||||
r_token.value=id;
|
||||
}
|
||||
@ -603,6 +610,7 @@ const char* VisualScriptExpression::token_name[TK_MAX]={
|
||||
"PARENTHESIS OPEN",
|
||||
"PARENTHESIS CLOSE",
|
||||
"IDENTIFIER",
|
||||
"BUILTIN FUNC",
|
||||
"SELF",
|
||||
"CONSTANT",
|
||||
"BASIC TYPE",
|
||||
@ -813,6 +821,53 @@ VisualScriptExpression::ENode* VisualScriptExpression::_parse_expression() {
|
||||
|
||||
expr=constructor;
|
||||
|
||||
} break;
|
||||
case TK_BUILTIN_FUNC: {
|
||||
//builtin function
|
||||
|
||||
Variant::Type bt = Variant::Type(int(tk.value));
|
||||
_get_token(tk);
|
||||
if (tk.type!=TK_PARENTHESIS_OPEN) {
|
||||
_set_error("Expected '('");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BuiltinFuncNode *bifunc = alloc_node<BuiltinFuncNode>();
|
||||
bifunc->func=VisualScriptBuiltinFunc::BuiltinFunc(int(tk.value));
|
||||
|
||||
while(true) {
|
||||
|
||||
int cofs=str_ofs;
|
||||
_get_token(tk);
|
||||
if (tk.type==TK_PARENTHESIS_CLOSE) {
|
||||
break;
|
||||
}
|
||||
str_ofs=cofs; //revert
|
||||
//parse an expression
|
||||
ENode* expr=_parse_expression();
|
||||
if (!expr)
|
||||
return NULL;
|
||||
|
||||
bifunc->arguments.push_back(expr);
|
||||
|
||||
cofs=str_ofs;
|
||||
_get_token(tk);
|
||||
if (tk.type==TK_COMMA) {
|
||||
//all good
|
||||
} else if (tk.type==TK_PARENTHESIS_CLOSE) {
|
||||
str_ofs=cofs;
|
||||
} else {
|
||||
_set_error("Expected ',' or ')'");
|
||||
}
|
||||
}
|
||||
|
||||
int expected_args = VisualScriptBuiltinFunc::get_func_argument_count(bifunc->func);
|
||||
if (bifunc->arguments.size() != expected_args) {
|
||||
_set_error("Builtin func '"+VisualScriptBuiltinFunc::get_func_name(bifunc->func)+"' expects "+itos(expected_args)+" arguments.");
|
||||
}
|
||||
|
||||
expr=bifunc;
|
||||
|
||||
} break;
|
||||
case TK_OP_SUB: {
|
||||
|
||||
@ -1337,6 +1392,34 @@ public:
|
||||
}
|
||||
|
||||
|
||||
} break;
|
||||
case VisualScriptExpression::ENode::TYPE_BUILTIN_FUNC: {
|
||||
|
||||
const VisualScriptExpression::BuiltinFuncNode *bifunc = static_cast<const VisualScriptExpression::BuiltinFuncNode*>(p_node);
|
||||
|
||||
Vector<Variant> arr;
|
||||
Vector<const Variant*> argp;
|
||||
arr.resize(bifunc->arguments.size());
|
||||
argp.resize(bifunc->arguments.size());
|
||||
|
||||
for (int i=0;i<bifunc->arguments.size();i++) {
|
||||
|
||||
Variant value;
|
||||
bool ret = _execute(p_inputs,bifunc->arguments[i],value,r_error_str,ce);
|
||||
if (ret)
|
||||
return true;
|
||||
arr[i]=value;
|
||||
argp[i]=&arr[i];
|
||||
}
|
||||
|
||||
|
||||
VisualScriptBuiltinFunc::exec_func(bifunc->func,argp.ptr(),&r_ret,ce,r_error_str);
|
||||
|
||||
if (ce.error!=Variant::CallError::CALL_OK) {
|
||||
r_error_str="Builtin Call Failed. "+r_error_str;
|
||||
return true;
|
||||
}
|
||||
|
||||
} break;
|
||||
case VisualScriptExpression::ENode::TYPE_CALL: {
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define VISUALSCRIPTEXPRESSION_H
|
||||
|
||||
#include "visual_script.h"
|
||||
#include "visual_script_builtin_funcs.h"
|
||||
|
||||
class VisualScriptExpression : public VisualScriptNode {
|
||||
|
||||
@ -35,6 +36,7 @@ friend class VisualScriptNodeInstanceExpression;
|
||||
TK_PARENTHESIS_OPEN,
|
||||
TK_PARENTHESIS_CLOSE,
|
||||
TK_IDENTIFIER,
|
||||
TK_BUILTIN_FUNC,
|
||||
TK_SELF,
|
||||
TK_CONSTANT,
|
||||
TK_BASIC_TYPE,
|
||||
@ -101,6 +103,7 @@ friend class VisualScriptNodeInstanceExpression;
|
||||
TYPE_ARRAY,
|
||||
TYPE_DICTIONARY,
|
||||
TYPE_CONSTRUCTOR,
|
||||
TYPE_BUILTIN_FUNC,
|
||||
TYPE_CALL
|
||||
};
|
||||
|
||||
@ -214,6 +217,14 @@ friend class VisualScriptNodeInstanceExpression;
|
||||
|
||||
};
|
||||
|
||||
struct BuiltinFuncNode : public ENode {
|
||||
VisualScriptBuiltinFunc::BuiltinFunc func;
|
||||
Vector<ENode*> arguments;
|
||||
BuiltinFuncNode() {
|
||||
type=TYPE_BUILTIN_FUNC;
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
T* alloc_node() {
|
||||
T* node = memnew(T);
|
||||
|
Loading…
Reference in New Issue
Block a user