From b60a3e72028349493effe26811725d420c7e125b Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 31 Dec 2015 00:54:00 -0300 Subject: -Changed var2str and str2var in GDScript to use VariantWriter and VariantParser -It is now finally possible to parse back a variant from text! --- modules/gdscript/gd_functions.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'modules/gdscript/gd_functions.cpp') diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index fd92c8a9ec..28eb7d54de 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -33,6 +33,7 @@ #include "gd_script.h" #include "func_ref.h" #include "os/os.h" +#include "variant_parser.h" const char *GDFunctions::get_func_name(Function p_func) { @@ -607,7 +608,9 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va } break; case VAR_TO_STR: { VALIDATE_ARG_COUNT(1); - r_ret=p_args[0]->get_construct_string(); + String vars; + VariantWriter::write_to_string(*p_args[0],vars); + r_ret=vars; } break; case STR_TO_VAR: { VALIDATE_ARG_COUNT(1); @@ -618,7 +621,21 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va r_ret=Variant(); return; } - Variant::construct_from_string(*p_args[0],r_ret); + + VariantParser::StreamString ss; + ss.s=*p_args[0]; + + String errs; + int line; + Error err = VariantParser::parse(&ss,r_ret,errs,line); + + if (err!=OK) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::STRING; + r_ret=Variant(); + } + } break; case GEN_RANGE: { -- cgit v1.2.3 From ec3d17b4e2b3d87ec6b46c57280ec853b264b20b Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 31 Dec 2015 16:24:27 -0300 Subject: force thread model to single-safe when running editor, fixes #2387 --- modules/gdscript/gd_functions.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/gdscript/gd_functions.cpp') diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index 28eb7d54de..251b0ae392 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -525,6 +525,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va for(int i=0;ioperator String();; + if (i==0) str=os; else -- cgit v1.2.3 From 37f2222dd77d4ebb9c4df1af598635ac73f0bcf6 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 31 Dec 2015 18:26:49 -0300 Subject: -Added Color8(r8,g8,b8,a8) function as well as .r8,.g8,.b8,.a8 members to Color, to deal with colors in the 0-255 range. Closes #2345 --- modules/gdscript/gd_functions.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'modules/gdscript/gd_functions.cpp') diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index 251b0ae392..1990afb787 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -98,6 +98,7 @@ const char *GDFunctions::get_func_name(Function p_func) { "load", "inst2dict", "dict2inst", + "Color8", "hash", "print_stack", "instance_from_id", @@ -937,6 +938,33 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va VALIDATE_ARG_COUNT(1); r_ret=p_args[0]->hash(); + } break; + case COLOR8: { + + if (p_arg_count<3) { + r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument=3; + return; + } + if (p_arg_count>4) { + r_error.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; + r_error.argument=4; + return; + } + + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + VALIDATE_ARG_NUM(2); + + Color color(*p_args[0],*p_args[1],*p_args[2]); + + if (p_arg_count==4) { + VALIDATE_ARG_NUM(3); + color.a=*p_args[3]; + } + + r_ret=color; + } break; case PRINT_STACK: { @@ -1017,6 +1045,7 @@ bool GDFunctions::is_deterministic(Function p_func) { case TYPE_CONVERT: case TYPE_OF: case TEXT_STR: + case COLOR8: // enable for debug only, otherwise not desirable - case GEN_RANGE: return true; default: @@ -1360,6 +1389,12 @@ MethodInfo GDFunctions::get_info(Function p_func) { mi.return_val.type=Variant::INT; return mi; } break; + case COLOR8: { + + MethodInfo mi("Color8",PropertyInfo(Variant::INT,"r8"),PropertyInfo(Variant::INT,"g8"),PropertyInfo(Variant::INT,"b8"),PropertyInfo(Variant::INT,"a8")); + mi.return_val.type=Variant::COLOR; + return mi; + } break; case PRINT_STACK: { MethodInfo mi("print_stack"); -- cgit v1.2.3 From 64872ca8112f5b9c726914c51922e2c4e5c8f667 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 31 Dec 2015 18:32:56 -0300 Subject: small fixes to color8 --- modules/gdscript/gd_functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gdscript/gd_functions.cpp') diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index 1990afb787..cdf3838053 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -98,8 +98,8 @@ const char *GDFunctions::get_func_name(Function p_func) { "load", "inst2dict", "dict2inst", - "Color8", "hash", + "Color8", "print_stack", "instance_from_id", }; -- cgit v1.2.3 From 5be9ff7b6715a661e85f99b108f96340de7ef435 Mon Sep 17 00:00:00 2001 From: George Marques Date: Fri, 1 Jan 2016 11:50:53 -0200 Subject: Update copyright to 2016 in headers --- modules/gdscript/gd_functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gdscript/gd_functions.cpp') diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index cdf3838053..11bb3a859a 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ -- cgit v1.2.3 From 23441ec8676f6d804692fe1e49e7fea2bec55341 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 2 Jan 2016 21:07:03 -0300 Subject: Added var2bytes and bytes2var to convet any variable to bytes and back. Closes #2075 --- modules/gdscript/gd_functions.cpp | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'modules/gdscript/gd_functions.cpp') diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index 11bb3a859a..e015ddb65e 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -34,6 +34,7 @@ #include "func_ref.h" #include "os/os.h" #include "variant_parser.h" +#include "io/marshalls.h" const char *GDFunctions::get_func_name(Function p_func) { @@ -94,6 +95,8 @@ const char *GDFunctions::get_func_name(Function p_func) { "printraw", "var2str", "str2var", + "var2bytes", + "bytes2var", "range", "load", "inst2dict", @@ -638,6 +641,57 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va r_ret=Variant(); } + } break; + case VAR_TO_BYTES: { + VALIDATE_ARG_COUNT(1); + + ByteArray barr; + int len; + Error err = encode_variant(*p_args[0],NULL,len); + if (err) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::NIL; + r_ret=Variant(); + return; + } + + barr.resize(len); + { + ByteArray::Write w = barr.write(); + encode_variant(*p_args[0],w.ptr(),len); + + } + r_ret=barr; + } break; + case BYTES_TO_VAR: { + VALIDATE_ARG_COUNT(1); + if (p_args[0]->get_type()!=Variant::RAW_ARRAY) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::RAW_ARRAY; + r_ret=Variant(); + return; + } + + ByteArray varr=*p_args[0]; + Variant ret; + { + ByteArray::Read r=varr.read(); + Error err = decode_variant(ret,r.ptr(),varr.size(),NULL); + if (err!=OK) { + ERR_PRINT("Not enough bytes for decoding.."); + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::RAW_ARRAY; + r_ret=Variant(); + return; + } + + } + + r_ret=ret; + } break; case GEN_RANGE: { @@ -1358,6 +1412,18 @@ MethodInfo GDFunctions::get_info(Function p_func) { mi.return_val.type=Variant::NIL; return mi; } break; + case VAR_TO_BYTES: { + MethodInfo mi("var2bytes",PropertyInfo(Variant::NIL,"var")); + mi.return_val.type=Variant::RAW_ARRAY; + return mi; + + } break; + case BYTES_TO_VAR: { + + MethodInfo mi("bytes2var:Variant",PropertyInfo(Variant::RAW_ARRAY,"bytes")); + mi.return_val.type=Variant::NIL; + return mi; + } break; case GEN_RANGE: { MethodInfo mi("range",PropertyInfo(Variant::NIL,"...")); -- cgit v1.2.3