summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/gd_compiler.cpp42
-rw-r--r--modules/gdscript/gd_compiler.h4
-rw-r--r--modules/gdscript/gd_editor.cpp66
-rw-r--r--modules/gdscript/gd_functions.cpp125
-rw-r--r--modules/gdscript/gd_functions.h5
-rw-r--r--modules/gdscript/gd_parser.cpp83
-rw-r--r--modules/gdscript/gd_parser.h8
-rw-r--r--modules/gdscript/gd_pretty_print.cpp2
-rw-r--r--modules/gdscript/gd_pretty_print.h2
-rw-r--r--modules/gdscript/gd_script.cpp71
-rw-r--r--modules/gdscript/gd_script.h7
-rw-r--r--modules/gdscript/gd_tokenizer.cpp11
-rw-r--r--modules/gdscript/gd_tokenizer.h5
-rw-r--r--modules/gdscript/register_types.cpp2
-rw-r--r--modules/gdscript/register_types.h2
-rw-r--r--modules/gridmap/grid_map.cpp4
-rw-r--r--modules/gridmap/grid_map.h2
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp2
-rw-r--r--modules/gridmap/grid_map_editor_plugin.h2
-rw-r--r--modules/gridmap/register_types.cpp2
-rw-r--r--modules/gridmap/register_types.h2
21 files changed, 394 insertions, 55 deletions
diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp
index a62225f663..53519030fc 100644
--- a/modules/gdscript/gd_compiler.cpp
+++ b/modules/gdscript/gd_compiler.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 */
@@ -1156,6 +1156,10 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
codegen.opcodes.push_back(GDFunction::OPCODE_ASSERT);
codegen.opcodes.push_back(ret);
} break;
+ case GDParser::Node::TYPE_BREAKPOINT: {
+ // try subblocks
+ codegen.opcodes.push_back(GDFunction::OPCODE_BREAKPOINT);
+ } break;
case GDParser::Node::TYPE_LOCAL_VAR: {
@@ -1181,7 +1185,7 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo
}
-Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *p_class,const GDParser::FunctionNode *p_func) {
+Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *p_class,const GDParser::FunctionNode *p_func,bool p_for_ready) {
Vector<int> bytecode;
CodeGen codegen;
@@ -1212,9 +1216,9 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
/* Parse initializer -if applies- */
- bool is_initializer=false || !p_func;
+ bool is_initializer=!p_for_ready && !p_func;
- if (!p_func || String(p_func->name)=="_init") {
+ if (is_initializer || (p_func && String(p_func->name)=="_init")) {
//parse initializer for class members
if (!p_func && p_class->extends_used && p_script->native.is_null()){
@@ -1232,12 +1236,24 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
}
+ if (p_for_ready || (p_func && String(p_func->name)=="_ready")) {
+ //parse initializer for class members
+ if (p_class->ready->statements.size()) {
+ Error err = _parse_block(codegen,p_class->ready,stack_level);
+ if (err)
+ return err;
+ }
+
+ }
+
+
/* Parse default argument code -if applies- */
Vector<int> defarg_addr;
StringName func_name;
if (p_func) {
+
if (p_func->default_values.size()) {
codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_TO_DEF_ARGUMENT);
@@ -1260,7 +1276,10 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
func_name=p_func->name;
} else {
- func_name="_init";
+ if (p_for_ready)
+ func_name="_ready";
+ else
+ func_name="_init";
}
codegen.opcodes.push_back(GDFunction::OPCODE_END);
@@ -1328,7 +1347,7 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
if (defarg_addr.size()) {
gdfunc->default_arguments=defarg_addr;
- gdfunc->_default_arg_count=defarg_addr.size();
+ gdfunc->_default_arg_count=defarg_addr.size()-1;
gdfunc->_default_arg_ptr=&gdfunc->default_arguments[0];
} else {
gdfunc->_default_arg_count=0;
@@ -1614,10 +1633,14 @@ Error GDCompiler::_parse_class(GDScript *p_script,GDScript *p_owner,const GDPars
//parse methods
bool has_initializer=false;
+ bool has_ready=false;
+
for(int i=0;i<p_class->functions.size();i++) {
if (!has_initializer && p_class->functions[i]->name=="_init")
has_initializer=true;
+ if (!has_ready && p_class->functions[i]->name=="_ready")
+ has_ready=true;
Error err = _parse_function(p_script,p_class,p_class->functions[i]);
if (err)
return err;
@@ -1640,6 +1663,13 @@ Error GDCompiler::_parse_class(GDScript *p_script,GDScript *p_owner,const GDPars
return err;
}
+ if (!has_ready && p_class->ready->statements.size()) {
+ //create a constructor
+ Error err = _parse_function(p_script,p_class,NULL,true);
+ if (err)
+ return err;
+ }
+
#ifdef DEBUG_ENABLED
//validate setters/getters if debug is enabled
for(int i=0;i<p_class->variables.size();i++) {
diff --git a/modules/gdscript/gd_compiler.h b/modules/gdscript/gd_compiler.h
index bdf4e9816a..5bf7ec980d 100644
--- a/modules/gdscript/gd_compiler.h
+++ b/modules/gdscript/gd_compiler.h
@@ -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 */
@@ -143,7 +143,7 @@ class GDCompiler {
int _parse_assign_right_expression(CodeGen& codegen,const GDParser::OperatorNode *p_expression, int p_stack_level);
int _parse_expression(CodeGen& codegen,const GDParser::Node *p_expression, int p_stack_level,bool p_root=false,bool p_initializer=false);
Error _parse_block(CodeGen& codegen,const GDParser::BlockNode *p_block,int p_stack_level=0,int p_break_addr=-1,int p_continue_addr=-1);
- Error _parse_function(GDScript *p_script,const GDParser::ClassNode *p_class,const GDParser::FunctionNode *p_func);
+ Error _parse_function(GDScript *p_script,const GDParser::ClassNode *p_class,const GDParser::FunctionNode *p_func,bool p_for_ready=false);
Error _parse_class(GDScript *p_script,GDScript *p_owner,const GDParser::ClassNode *p_class);
int err_line;
int err_column;
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp
index 381edcba50..126a8cd1eb 100644
--- a/modules/gdscript/gd_editor.cpp
+++ b/modules/gdscript/gd_editor.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 */
@@ -1147,8 +1147,54 @@ static bool _guess_identifier_type(GDCompletionContext& context,int p_line,const
}
}
+ //autoloads as singletons
+ List<PropertyInfo> props;
+ Globals::get_singleton()->get_property_list(&props);
+ for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
+ String s = E->get().name;
+ if (!s.begins_with("autoload/"))
+ continue;
+ String name = s.get_slice("/",1);
+ if (name==String(p_identifier)) {
+
+ String path = Globals::get_singleton()->get(s);
+ if (path.begins_with("*")) {
+ String script =path.substr(1,path.length());
+
+ if (!script.ends_with(".gd")) {
+ //not a script, try find the script anyway,
+ //may have some success
+ script=script.basename()+".gd";
+ }
+
+ if (FileAccess::exists(script)) {
+
+ //print_line("is a script");
+
+
+ Ref<Script> scr;
+ if (ScriptCodeCompletionCache::get_sigleton())
+ scr = ScriptCodeCompletionCache::get_sigleton()->get_cached_resource(script);
+ else
+ scr = ResourceLoader::load(script);
+
+
+ r_type.obj_type="Node";
+ r_type.type=Variant::OBJECT;
+ r_type.script=scr;
+ r_type.value=Variant();
+
+ return true;
+
+ }
+ }
+ }
+
+ }
+
+ //global
for(Map<StringName,int>::Element *E=GDScriptLanguage::get_singleton()->get_global_map().front();E;E=E->next()) {
if (E->key()==p_identifier) {
@@ -1336,6 +1382,24 @@ static void _find_identifiers(GDCompletionContext& context,int p_line,bool p_onl
result.insert(_type_names[i]);
}
+ //autoload singletons
+ List<PropertyInfo> props;
+ Globals::get_singleton()->get_property_list(&props);
+
+ for(List<PropertyInfo>::Element *E=props.front();E;E=E->next()) {
+
+ String s = E->get().name;
+ if (!s.begins_with("autoload/"))
+ continue;
+ String name = s.get_slice("/",1);
+ String path = Globals::get_singleton()->get(s);
+ if (path.begins_with("*")) {
+ result.insert(name);
+ }
+
+ }
+
+
for(const Map<StringName,int>::Element *E=GDScriptLanguage::get_singleton()->get_global_map().front();E;E=E->next()) {
result.insert(E->key().operator String());
}
diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp
index fd92c8a9ec..e015ddb65e 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 */
@@ -33,6 +33,8 @@
#include "gd_script.h"
#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) {
@@ -93,11 +95,14 @@ const char *GDFunctions::get_func_name(Function p_func) {
"printraw",
"var2str",
"str2var",
+ "var2bytes",
+ "bytes2var",
"range",
"load",
"inst2dict",
"dict2inst",
"hash",
+ "Color8",
"print_stack",
"instance_from_id",
};
@@ -524,6 +529,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
for(int i=0;i<p_arg_count;i++) {
String os = p_args[i]->operator String();;
+
if (i==0)
str=os;
else
@@ -607,7 +613,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 +626,72 @@ 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 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: {
@@ -920,6 +993,33 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
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: {
@@ -999,6 +1099,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:
@@ -1311,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,"..."));
@@ -1342,6 +1455,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");
diff --git a/modules/gdscript/gd_functions.h b/modules/gdscript/gd_functions.h
index ad35a628d5..8c88472567 100644
--- a/modules/gdscript/gd_functions.h
+++ b/modules/gdscript/gd_functions.h
@@ -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 */
@@ -89,11 +89,14 @@ public:
TEXT_PRINTRAW,
VAR_TO_STR,
STR_TO_VAR,
+ VAR_TO_BYTES,
+ BYTES_TO_VAR,
GEN_RANGE,
RESOURCE_LOAD,
INST2DICT,
DICT2INST,
HASH,
+ COLOR8,
PRINT_STACK,
INSTANCE_FROM_ID,
FUNC_MAX
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp
index 4339a13edf..c4175e048d 100644
--- a/modules/gdscript/gd_parser.cpp
+++ b/modules/gdscript/gd_parser.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 */
@@ -75,20 +75,28 @@ bool GDParser::_enter_indent_block(BlockNode* p_block) {
if (tokenizer->get_token()!=GDTokenizer::TK_NEWLINE) {
- _set_error("newline expected after ':'.");
- return false;
+ // be more python-like
+ int current = tab_level.back()->get();
+ tab_level.push_back(current+1);
+ return true;
+ //_set_error("newline expected after ':'.");
+ //return false;
}
while(true) {
if (tokenizer->get_token()!=GDTokenizer::TK_NEWLINE) {
+ print_line("no newline");
return false; //wtf
} else if (tokenizer->get_token(1)!=GDTokenizer::TK_NEWLINE) {
int indent = tokenizer->get_token_line_indent();
int current = tab_level.back()->get();
- if (indent<=current)
+ if (indent<=current) {
+ print_line("current: "+itos(current)+" indent: "+itos(indent));
+ print_line("less than current");
return false;
+ }
tab_level.push_back(indent);
tokenizer->advance();
@@ -259,6 +267,13 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
constant->value=tokenizer->get_token_constant();
tokenizer->advance();
expr=constant;
+ } else if (tokenizer->get_token()==GDTokenizer::TK_CONST_PI) {
+
+ //constant defined by tokenizer
+ ConstantNode *constant = alloc_node<ConstantNode>();
+ constant->value=Math_PI;
+ tokenizer->advance();
+ expr=constant;
} else if (tokenizer->get_token()==GDTokenizer::TK_PR_PRELOAD) {
//constant defined by tokenizer
@@ -1588,6 +1603,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
p_block->sub_blocks.push_back(cf_if->body);
if (!_enter_indent_block(cf_if->body)) {
+ _set_error("Expected intended block after 'if'");
p_block->end_line=tokenizer->get_token_line();
return;
}
@@ -1647,6 +1663,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
if (!_enter_indent_block(cf_if->body)) {
+ _set_error("Expected indented block after 'elif'");
p_block->end_line=tokenizer->get_token_line();
return;
}
@@ -1661,7 +1678,6 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
} else if (tokenizer->get_token()==GDTokenizer::TK_CF_ELSE) {
if (tab_level.back()->get() > indent_level) {
-
_set_error("Invalid indent");
return;
}
@@ -1673,6 +1689,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
p_block->sub_blocks.push_back(cf_if->body_else);
if (!_enter_indent_block(cf_if->body_else)) {
+ _set_error("Expected indented block after 'else'");
p_block->end_line=tokenizer->get_token_line();
return;
}
@@ -1713,6 +1730,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
p_block->sub_blocks.push_back(cf_while->body);
if (!_enter_indent_block(cf_while->body)) {
+ _set_error("Expected indented block after 'while'");
p_block->end_line=tokenizer->get_token_line();
return;
}
@@ -1764,6 +1782,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
p_block->sub_blocks.push_back(cf_for->body);
if (!_enter_indent_block(cf_for->body)) {
+ _set_error("Expected indented block after 'while'");
p_block->end_line=tokenizer->get_token_line();
return;
}
@@ -1850,6 +1869,17 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
return;
}
} break;
+ case GDTokenizer::TK_PR_BREAKPOINT: {
+
+ tokenizer->advance();
+ BreakpointNode *bn = alloc_node<BreakpointNode>();
+ p_block->statements.push_back(bn);
+
+ if (!_end_statement()) {
+ _set_error("Expected end of statement after breakpoint.");
+ return;
+ }
+ } break;
default: {
Node *expression = _parse_and_reduce_expression(p_block,p_static,false,true);
@@ -2058,6 +2088,8 @@ void GDParser::_parse_class(ClassNode *p_class) {
ClassNode *newclass = alloc_node<ClassNode>();
newclass->initializer = alloc_node<BlockNode>();
newclass->initializer->parent_class=newclass;
+ newclass->ready = alloc_node<BlockNode>();
+ newclass->ready->parent_class=newclass;
newclass->name=name;
newclass->owner=p_class;
@@ -2767,6 +2799,17 @@ void GDParser::_parse_class(ClassNode *p_class) {
}
}; //fallthrough to var
+ case GDTokenizer::TK_PR_ONREADY: {
+
+ if (token==GDTokenizer::TK_PR_ONREADY) {
+ //may be fallthrough from export, ignore if so
+ tokenizer->advance();
+ if (tokenizer->get_token()!=GDTokenizer::TK_PR_VAR) {
+ _set_error("Expected 'var'.");
+ return;
+ }
+ }
+ }; //fallthrough to var
case GDTokenizer::TK_PR_VAR: {
//variale declaration and (eventual) initialization
@@ -2777,6 +2820,8 @@ void GDParser::_parse_class(ClassNode *p_class) {
current_export=PropertyInfo();
}
+ bool onready = tokenizer->get_token(-1)==GDTokenizer::TK_PR_ONREADY;
+
tokenizer->advance();
if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) {
@@ -2807,6 +2852,21 @@ void GDParser::_parse_class(ClassNode *p_class) {
return;
}
+ //discourage common error
+ if (!onready && subexpr->type==Node::TYPE_OPERATOR) {
+
+ OperatorNode *op=static_cast<OperatorNode*>(subexpr);
+ if (op->op==OperatorNode::OP_CALL && op->arguments[0]->type==Node::TYPE_SELF && op->arguments[1]->type==Node::TYPE_IDENTIFIER) {
+ IdentifierNode *id=static_cast<IdentifierNode*>(op->arguments[1]);
+ if (id->name=="get_node") {
+
+ _set_error("Use 'onready var "+String(member.identifier)+" = get_node(..)' instead");
+ return;
+
+ }
+ }
+ }
+
member.expression=subexpr;
if (autoexport) {
@@ -2853,12 +2913,19 @@ void GDParser::_parse_class(ClassNode *p_class) {
op->arguments.push_back(id);
op->arguments.push_back(subexpr);
+
#ifdef DEBUG_ENABLED
NewLineNode *nl = alloc_node<NewLineNode>();
nl->line=line;
- p_class->initializer->statements.push_back(nl);
+ if (onready)
+ p_class->ready->statements.push_back(nl);
+ else
+ p_class->initializer->statements.push_back(nl);
#endif
- p_class->initializer->statements.push_back(op);
+ if (onready)
+ p_class->ready->statements.push_back(op);
+ else
+ p_class->initializer->statements.push_back(op);
@@ -3009,6 +3076,8 @@ Error GDParser::_parse(const String& p_base_path) {
ClassNode *main_class = alloc_node<ClassNode>();
main_class->initializer = alloc_node<BlockNode>();
main_class->initializer->parent_class=main_class;
+ main_class->ready = alloc_node<BlockNode>();
+ main_class->ready->parent_class=main_class;
current_class=main_class;
_parse_class(main_class);
diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h
index 04f3dff3de..9ad8633968 100644
--- a/modules/gdscript/gd_parser.h
+++ b/modules/gdscript/gd_parser.h
@@ -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 */
@@ -54,6 +54,7 @@ public:
TYPE_CONTROL_FLOW,
TYPE_LOCAL_VAR,
TYPE_ASSERT,
+ TYPE_BREAKPOINT,
TYPE_NEWLINE,
};
@@ -105,6 +106,7 @@ public:
Vector<FunctionNode*> static_functions;
Vector<Signal> _signals;
BlockNode *initializer;
+ BlockNode *ready;
ClassNode *owner;
//Vector<Node*> initializers;
int end_line;
@@ -275,6 +277,10 @@ public:
AssertNode() { type=TYPE_ASSERT; }
};
+ struct BreakpointNode : public Node {
+ BreakpointNode() { type=TYPE_BREAKPOINT; }
+ };
+
struct NewLineNode : public Node {
NewLineNode() { type=TYPE_NEWLINE; }
};
diff --git a/modules/gdscript/gd_pretty_print.cpp b/modules/gdscript/gd_pretty_print.cpp
index 9c290eac4a..cca3cd3984 100644
--- a/modules/gdscript/gd_pretty_print.cpp
+++ b/modules/gdscript/gd_pretty_print.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 */
diff --git a/modules/gdscript/gd_pretty_print.h b/modules/gdscript/gd_pretty_print.h
index 998fdc53ab..0106d873d9 100644
--- a/modules/gdscript/gd_pretty_print.h
+++ b/modules/gdscript/gd_pretty_print.h
@@ -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 */
diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp
index 62006cf18b..9a3f50d3b8 100644
--- a/modules/gdscript/gd_script.cpp
+++ b/modules/gdscript/gd_script.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 */
@@ -33,17 +33,6 @@
#include "os/file_access.h"
#include "io/file_access_encrypted.h"
-/* TODO:
-
- *populate globals
- *do checks as close to debugger as possible (but don't do debugger)
- *const check plz
- *check arguments and default arguments in GDFunction
- -get property list in instance?
- *missing opcodes
- -const checks
- -make thread safe
- */
@@ -232,6 +221,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
r_err.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
r_err.argument=_argument_count;
+
return Variant();
} else if (p_argcount < _argument_count - _default_arg_count) {
@@ -1077,6 +1067,14 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
ip+=2;
} continue;
+ case OPCODE_BREAKPOINT: {
+#ifdef DEBUG_ENABLED
+ if (ScriptDebugger::get_singleton()) {
+ GDScriptLanguage::get_singleton()->debug_break("Breakpoint Statement",true);
+ }
+#endif
+ ip+=1;
+ } continue;
case OPCODE_LINE: {
CHECK_SPACE(2);
@@ -1141,7 +1139,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
if (!GDScriptLanguage::get_singleton()->debug_break(err_text,false)) {
// debugger break did not happen
- _err_print_error(err_func.utf8().get_data(),err_file.utf8().get_data(),err_line,err_text.utf8().get_data());
+ _err_print_error(err_func.utf8().get_data(),err_file.utf8().get_data(),err_line,err_text.utf8().get_data(),ERR_HANDLER_SCRIPT);
}
@@ -1595,6 +1593,28 @@ void GDScript::_update_placeholder(PlaceHolderScriptInstance *p_placeholder) {
}*/
#endif
+
+bool GDScript::get_property_default_value(const StringName& p_property, Variant &r_value) const {
+
+#ifdef TOOLS_ENABLED
+
+ //for (const Map<StringName,Variant>::Element *I=member_default_values.front();I;I=I->next()) {
+ // print_line("\t"+String(String(I->key())+":"+String(I->get())));
+ //}
+ const Map<StringName,Variant>::Element *E=member_default_values_cache.find(p_property);
+ if (E) {
+ r_value=E->get();
+ return true;
+ }
+
+ if (base_cache.is_valid()) {
+ return base_cache->get_property_default_value(p_property,r_value);
+ }
+#endif
+ return false;
+
+}
+
ScriptInstance* GDScript::instance_create(Object *p_this) {
@@ -1732,16 +1752,21 @@ bool GDScript::_update_exports() {
}
}
- Ref<GDScript> bf = ResourceLoader::load(path);
+ if (path!=get_path()) {
- if (bf.is_valid()) {
+ Ref<GDScript> bf = ResourceLoader::load(path);
- //print_line("parent is: "+bf->get_path());
- base_cache=bf;
- bf->inheriters_cache.insert(get_instance_ID());
+ if (bf.is_valid()) {
- //bf->_update_exports(p_instances,true,false);
+ //print_line("parent is: "+bf->get_path());
+ base_cache=bf;
+ bf->inheriters_cache.insert(get_instance_ID());
+ //bf->_update_exports(p_instances,true,false);
+
+ }
+ } else {
+ ERR_PRINT(("Path extending itself in "+path).utf8().get_data());
}
}
@@ -2570,6 +2595,12 @@ void GDScriptLanguage::_add_global(const StringName& p_name,const Variant& p_val
_global_array=global_array.ptr();
}
+void GDScriptLanguage::add_global_constant(const StringName& p_variable,const Variant& p_value) {
+
+ _add_global(p_variable,p_value);
+}
+
+
void GDScriptLanguage::init() {
@@ -2646,6 +2677,7 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
"elif",
"enum",
"extends" ,
+ "onready",
"for" ,
"func" ,
"if" ,
@@ -2665,6 +2697,7 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
"or",
"export",
"assert",
+ "breakpoint",
"yield",
"static",
"float",
diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h
index 3d16b59065..a69f99314a 100644
--- a/modules/gdscript/gd_script.h
+++ b/modules/gdscript/gd_script.h
@@ -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 */
@@ -71,6 +71,7 @@ public:
OPCODE_ITERATE_BEGIN,
OPCODE_ITERATE,
OPCODE_ASSERT,
+ OPCODE_BREAKPOINT,
OPCODE_LINE,
OPCODE_END
};
@@ -351,6 +352,8 @@ public:
Vector<uint8_t> get_as_byte_code() const;
+ bool get_property_default_value(const StringName& p_property,Variant& r_value) const;
+
virtual ScriptLanguage *get_language() const;
GDScript();
@@ -529,6 +532,8 @@ public:
virtual String make_function(const String& p_class,const String& p_name,const StringArray& p_args) const;
virtual Error complete_code(const String& p_code, const String& p_base_path, Object*p_owner,List<String>* r_options,String& r_call_hint);
virtual void auto_indent_code(String& p_code,int p_from_line,int p_to_line) const;
+ virtual void add_global_constant(const StringName& p_variable,const Variant& p_value);
+
/* DEBUGGER FUNCTIONS */
diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp
index e445701669..cbcb08334a 100644
--- a/modules/gdscript/gd_tokenizer.cpp
+++ b/modules/gdscript/gd_tokenizer.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 */
@@ -88,6 +88,7 @@ const char* GDTokenizer::token_names[TK_MAX]={
"func",
"class",
"extends",
+"onready",
"tool",
"static",
"export",
@@ -98,6 +99,7 @@ const char* GDTokenizer::token_names[TK_MAX]={
"assert",
"yield",
"signal",
+"breakpoint",
"'['",
"']'",
"'{'",
@@ -110,6 +112,7 @@ const char* GDTokenizer::token_names[TK_MAX]={
"'?'",
"':'",
"'\\n'",
+"PI",
"Error",
"EOF",
"Cursor"};
@@ -259,6 +262,7 @@ void GDTokenizerText::_advance() {
}
INCPOS(1);
+ line++;
while(GETCHAR(0)==' ' || GETCHAR(0)=='\t') {
INCPOS(1);
@@ -851,6 +855,7 @@ void GDTokenizerText::_advance() {
{TK_PR_FUNCTION,"function"},
{TK_PR_CLASS,"class"},
{TK_PR_EXTENDS,"extends"},
+ {TK_PR_ONREADY,"onready"},
{TK_PR_TOOL,"tool"},
{TK_PR_STATIC,"static"},
{TK_PR_EXPORT,"export"},
@@ -860,6 +865,7 @@ void GDTokenizerText::_advance() {
{TK_PR_ASSERT,"assert"},
{TK_PR_YIELD,"yield"},
{TK_PR_SIGNAL,"signal"},
+ {TK_PR_BREAKPOINT,"breakpoint"},
{TK_PR_CONST,"const"},
//controlflow
{TK_CF_IF,"if"},
@@ -874,6 +880,7 @@ void GDTokenizerText::_advance() {
{TK_CF_RETURN,"return"},
{TK_CF_PASS,"pass"},
{TK_SELF,"self"},
+ {TK_CONST_PI,"PI"},
{TK_ERROR,NULL}
};
@@ -1040,7 +1047,7 @@ void GDTokenizerText::advance(int p_amount) {
//////////////////////////////////////////////////////////////////////////////////////////////////////
-#define BYTECODE_VERSION 5
+#define BYTECODE_VERSION 10
Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> & p_buffer) {
diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h
index d6bd63c5b8..aaff573090 100644
--- a/modules/gdscript/gd_tokenizer.h
+++ b/modules/gdscript/gd_tokenizer.h
@@ -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 */
@@ -95,6 +95,7 @@ public:
TK_PR_FUNCTION,
TK_PR_CLASS,
TK_PR_EXTENDS,
+ TK_PR_ONREADY,
TK_PR_TOOL,
TK_PR_STATIC,
TK_PR_EXPORT,
@@ -105,6 +106,7 @@ public:
TK_PR_ASSERT,
TK_PR_YIELD,
TK_PR_SIGNAL,
+ TK_PR_BREAKPOINT,
TK_BRACKET_OPEN,
TK_BRACKET_CLOSE,
TK_CURLY_BRACKET_OPEN,
@@ -117,6 +119,7 @@ public:
TK_QUESTION_MARK,
TK_COLON,
TK_NEWLINE,
+ TK_CONST_PI,
TK_ERROR,
TK_EOF,
TK_CURSOR, //used for code completion
diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp
index 4470b7ca0c..2aea494f39 100644
--- a/modules/gdscript/register_types.cpp
+++ b/modules/gdscript/register_types.cpp
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/*************************************************/
/* Source code within this file is: */
-/* (c) 2007-2010 Juan Linietsky, Ariel Manzur */
+/* (c) 2007-2016 Juan Linietsky, Ariel Manzur */
/* All Rights Reserved. */
/*************************************************/
diff --git a/modules/gdscript/register_types.h b/modules/gdscript/register_types.h
index 9eb5d1846b..aed11cd1d4 100644
--- a/modules/gdscript/register_types.h
+++ b/modules/gdscript/register_types.h
@@ -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 */
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index ad7c392cd0..7d463b13d4 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.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 */
@@ -1096,7 +1096,7 @@ void GridMap::_bind_methods() {
// ObjectTypeDB::bind_method(_MD("_recreate_octants"),&GridMap::_recreate_octants);
ObjectTypeDB::bind_method(_MD("_update_dirty_map_callback"),&GridMap::_update_dirty_map_callback);
- ObjectTypeDB::bind_method(_MD("resource_changed"),&GridMap::resource_changed);
+ ObjectTypeDB::bind_method(_MD("resource_changed","resource"),&GridMap::resource_changed);
ObjectTypeDB::bind_method(_MD("set_center_x","enable"),&GridMap::set_center_x);
ObjectTypeDB::bind_method(_MD("get_center_x"),&GridMap::get_center_x);
diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h
index 9d3b1dcf95..66d3e6b44a 100644
--- a/modules/gridmap/grid_map.h
+++ b/modules/gridmap/grid_map.h
@@ -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 */
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index e4559ca100..6043807db3 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.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 */
diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h
index 03b2d4226e..fc43866ef3 100644
--- a/modules/gridmap/grid_map_editor_plugin.h
+++ b/modules/gridmap/grid_map_editor_plugin.h
@@ -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 */
diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp
index 2bc440759d..9dcc04b22a 100644
--- a/modules/gridmap/register_types.cpp
+++ b/modules/gridmap/register_types.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 */
diff --git a/modules/gridmap/register_types.h b/modules/gridmap/register_types.h
index 326d7acf24..7b5c10f9e5 100644
--- a/modules/gridmap/register_types.h
+++ b/modules/gridmap/register_types.h
@@ -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 */