Add seed/get_inst function for GDScript

seed -> Math::seed
get_inst -> ObjectDB::get_instance
This commit is contained in:
sanikoyes 2015-03-25 11:01:12 +08:00
parent cbad0440ab
commit 97f34a1dd6
2 changed files with 36 additions and 0 deletions

View File

@ -71,6 +71,7 @@ const char *GDFunctions::get_func_name(Function p_func) {
"randi", "randi",
"randf", "randf",
"rand_range", "rand_range",
"seed",
"rand_seed", "rand_seed",
"deg2rad", "deg2rad",
"rad2deg", "rad2deg",
@ -97,6 +98,7 @@ const char *GDFunctions::get_func_name(Function p_func) {
"dict2inst", "dict2inst",
"hash", "hash",
"print_stack", "print_stack",
"get_inst",
}; };
return _names[p_func]; return _names[p_func];
@ -328,6 +330,13 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(1);
r_ret=Math::random(*p_args[0],*p_args[1]); r_ret=Math::random(*p_args[0],*p_args[1]);
} break; } break;
case MATH_SEED: {
VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0);
uint32_t seed=*p_args[0];
Math::seed(seed);
r_ret=Variant();
} break;
case MATH_RANDSEED: { case MATH_RANDSEED: {
VALIDATE_ARG_COUNT(1); VALIDATE_ARG_COUNT(1);
VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(0);
@ -895,6 +904,20 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
}; };
} break; } break;
case GET_INST: {
VALIDATE_ARG_COUNT(1);
if (p_args[0]->get_type()!=Variant::INT && p_args[0]->get_type()!=Variant::REAL) {
r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument=0;
r_ret=Variant();
break;
}
uint32_t id=*p_args[0];
r_ret=ObjectDB::get_instance(id);
} break;
case FUNC_MAX: { case FUNC_MAX: {
ERR_FAIL_V(); ERR_FAIL_V();
@ -1130,6 +1153,11 @@ MethodInfo GDFunctions::get_info(Function p_func) {
mi.return_val.type=Variant::REAL; mi.return_val.type=Variant::REAL;
return mi; return mi;
} break; } break;
case MATH_SEED: {
MethodInfo mi("seed",PropertyInfo(Variant::REAL,"seed"));
mi.return_val.type=Variant::NIL;
return mi;
} break;
case MATH_RANDSEED: { case MATH_RANDSEED: {
MethodInfo mi("rand_seed",PropertyInfo(Variant::REAL,"seed")); MethodInfo mi("rand_seed",PropertyInfo(Variant::REAL,"seed"));
mi.return_val.type=Variant::ARRAY; mi.return_val.type=Variant::ARRAY;
@ -1288,6 +1316,12 @@ MethodInfo GDFunctions::get_info(Function p_func) {
return mi; return mi;
} break; } break;
case GET_INST: {
MethodInfo mi("get_info",PropertyInfo(Variant::INT,"instance_id"));
mi.return_val.type=Variant::OBJECT;
return mi;
} break;
case FUNC_MAX: { case FUNC_MAX: {
ERR_FAIL_V(MethodInfo()); ERR_FAIL_V(MethodInfo());

View File

@ -67,6 +67,7 @@ public:
MATH_RAND, MATH_RAND,
MATH_RANDF, MATH_RANDF,
MATH_RANDOM, MATH_RANDOM,
MATH_SEED,
MATH_RANDSEED, MATH_RANDSEED,
MATH_DEG2RAD, MATH_DEG2RAD,
MATH_RAD2DEG, MATH_RAD2DEG,
@ -93,6 +94,7 @@ public:
DICT2INST, DICT2INST,
HASH, HASH,
PRINT_STACK, PRINT_STACK,
GET_INST,
FUNC_MAX FUNC_MAX
}; };