diff options
Diffstat (limited to 'modules')
37 files changed, 889 insertions, 124 deletions
diff --git a/modules/chibi/cp_loader_it_samples.cpp b/modules/chibi/cp_loader_it_samples.cpp index 60db9b7f7..c736c99c0 100644 --- a/modules/chibi/cp_loader_it_samples.cpp +++ b/modules/chibi/cp_loader_it_samples.cpp @@ -147,7 +147,7 @@ CPLoader::Error CPLoader_IT::load_sample(CPSample *p_sample) { p_sample->set_sample_data(samp_id); if (!samp_id.is_null()) { - // printf("Loaded ID: stereo: %i len %i 16bit %i\n",CPSampleManager::get_singleton()->is_stereo(samp_id), CPSampleManager::get_singleton()->get_size( samp_id), CPSampleManager::get_singleton()->is_16bits( samp_id) ); + //printf("Loaded ID: stereo: %i len %i 16bit %i\n",CPSampleManager::get_singleton()->is_stereo(samp_id), CPSampleManager::get_singleton()->get_size( samp_id), CPSampleManager::get_singleton()->is_16bits( samp_id) ); } CP_ERR_COND_V( file->eof_reached(),FILE_CORRUPTED ); diff --git a/modules/chibi/cp_loader_mod.cpp b/modules/chibi/cp_loader_mod.cpp index 4a47ce5c4..cfa3e3473 100644 --- a/modules/chibi/cp_loader_mod.cpp +++ b/modules/chibi/cp_loader_mod.cpp @@ -208,7 +208,7 @@ CPLoader::Error CPLoader_MOD::load_song(const char *p_file,CPSong *p_song,bool p uint8_t order_count=file->get_byte(); -// uint8_t loop_to=file->get_byte(); + //uint8_t loop_to=file->get_byte(); int pattern_count=0; diff --git a/modules/chibi/cp_loader_s3m.cpp b/modules/chibi/cp_loader_s3m.cpp index eb5fad12e..4943e6d86 100644 --- a/modules/chibi/cp_loader_s3m.cpp +++ b/modules/chibi/cp_loader_s3m.cpp @@ -102,7 +102,7 @@ void CPLoader_S3M::set_header() { song->set_name( header.songname ); -// song->variables.filename= + //song->variables.filename= song->set_row_highlight_minor( 4 ); song->set_row_highlight_major( 16 ); @@ -135,7 +135,7 @@ CPLoader::Error CPLoader_S3M::load_sample(CPSample *p_sample) { uint32_t samplepos=(uint32_t)file->get_byte() << 16; samplepos|=file->get_word(); samplepos*=16; -// printf("sample at %i\n",samplepos); + //printf("sample at %i\n",samplepos); /**/ int sample_size=file->get_dword(); @@ -178,7 +178,7 @@ CPLoader::Error CPLoader_S3M::load_sample(CPSample *p_sample) { if ((type!=1) || scrs[0]!='S' || scrs[1]!='C' || scrs[2]!='R' || scrs[3]!='S' ) { -// printf("type: %i, %c%c%c%c\n",type,scrs[0],scrs[1],scrs[2],scrs[3]); + //printf("type: %i, %c%c%c%c\n",type,scrs[0],scrs[1],scrs[2],scrs[3]); CP_PRINTERR("Not an S3M CPSample!"); return FILE_CORRUPTED; } diff --git a/modules/chibi/cp_loader_xm.cpp b/modules/chibi/cp_loader_xm.cpp index 65c7bc7ee..cbd883642 100644 --- a/modules/chibi/cp_loader_xm.cpp +++ b/modules/chibi/cp_loader_xm.cpp @@ -399,7 +399,7 @@ CPLoader::Error CPLoader_XM::load_song(const char *p_file,CPSong *p_song,bool p_ instrument.set_name( instrname ); -// printf("Header Len: %i, CPInstrument %i, %i samples , name: s,\n",hsize,i,sampnum,instrname); + //printf("Header Len: %i, CPInstrument %i, %i samples , name: s,\n",hsize,i,sampnum,instrname); if (sampnum==0) { //aux=file->get_dword(); //Why is this for? -- for nothing, skipped diff --git a/modules/chibi/cp_player_data.h b/modules/chibi/cp_player_data.h index c59df5f0d..215731985 100644 --- a/modules/chibi/cp_player_data.h +++ b/modules/chibi/cp_player_data.h @@ -124,7 +124,7 @@ class CPPlayer { CPInstrument* instrument_ptr; CPSample* sample_ptr; -// Sample_Data *sample_data; + //Sample_Data *sample_data; int32_t period; diff --git a/modules/chibi/cp_player_data_effects.cpp b/modules/chibi/cp_player_data_effects.cpp index 6c774afb1..56fb7a290 100644 --- a/modules/chibi/cp_player_data_effects.cpp +++ b/modules/chibi/cp_player_data_effects.cpp @@ -615,7 +615,7 @@ void CPPlayer::do_effect_S(int p_track) { break; case 8: {/* S8x set panning position */ -// if (pf->panflag) { + //if (pf->panflag) { if (inf<=8) inf<<=4; else inf*=17; control.channel[p_track].panning=control.channel[p_track].channel_panning=inf; diff --git a/modules/chibi/cp_player_data_events.cpp b/modules/chibi/cp_player_data_events.cpp index 7ec3f1931..94a048ab2 100644 --- a/modules/chibi/cp_player_data_events.cpp +++ b/modules/chibi/cp_player_data_events.cpp @@ -194,7 +194,7 @@ void CPPlayer::Voice_Control::update_info_from_master_channel() { reverb_send=master_channel->reverb_send; chorus_send=master_channel->chorus_send; -// last_note_type=master_channel->last_note_type; + //last_note_type=master_channel->last_note_type; sample_start_index=master_channel->sample_start_index; filter=master_channel->filter; @@ -262,7 +262,7 @@ void CPPlayer::update_mixer() { /* Start Envelopes */ if ( song->has_instruments() && ((v.kick==KICK_NOTE)||(v.kick==KICK_ENVELOPE))) { -// Voice_Control *carry=0; + //Voice_Control *carry=0; if (v.has_master_channel && v.master_channel->carry.maybe) { @@ -462,7 +462,7 @@ void CPPlayer::update_mixer() { } else { filter_env=pe_value+32; //max 64 -// printf("pitch envelope at %i",filter_env); + //printf("pitch envelope at %i",filter_env); } } @@ -602,17 +602,19 @@ void CPPlayer::handle_tick() { /* process pattern-delay. pf->patdly2 is the counter and pf->patdly is the command memory. */ -// if (control.pattern_delay_1) { + /* + if (control.pattern_delay_1) { -// control.pattern_delay_2=control.pattern_delay_1; -// control.pattern_delay_1=0; -// } -// if (control.pattern_delay_2) { -// patterndelay active -// if (--control.pattern_delay_2) -// so turn back pf->patpos by 1 -// if (pf->patpos) pf->patpos--; -// } + control.pattern_delay_2=control.pattern_delay_1; + control.pattern_delay_1=0; + } + if (control.pattern_delay_2) { + patterndelay active + if (--control.pattern_delay_2) + // so turn back pf->patpos by 1 + if (pf->patpos) pf->patpos--; + } + */ if (control.play_mode!=PLAY_NOTHING) { diff --git a/modules/chibi/cp_player_data_notes.cpp b/modules/chibi/cp_player_data_notes.cpp index 1bfe24bc2..189403343 100644 --- a/modules/chibi/cp_player_data_notes.cpp +++ b/modules/chibi/cp_player_data_notes.cpp @@ -67,7 +67,7 @@ void CPPlayer::process_new_note(int p_track,uint8_t p_note) { // if there's real bool CPPlayer::process_new_instrument(int p_track,uint8_t p_instrument) { -// bool different_instrument=false; + //bool different_instrument=false; ERR_FAIL_INDEX_V(p_instrument,CPSong::MAX_INSTRUMENTS,false); if ( song->has_instruments() ) { diff --git a/modules/chibi/cp_player_data_utils.cpp b/modules/chibi/cp_player_data_utils.cpp index 1ee3f30b3..b99dbfcb9 100644 --- a/modules/chibi/cp_player_data_utils.cpp +++ b/modules/chibi/cp_player_data_utils.cpp @@ -111,8 +111,10 @@ int CPPlayer::find_empty_voice() { for (i=0;i<control.max_voices;i++) { /* allow us to take over a nonexisting sample */ -// if ((voice[i].s==NULL) -// return k; + /* + if ((voice[i].s==NULL) + return k; + */ if ((voice[i].kick==KICK_NOTHING)||(voice[i].kick==KICK_ENVELOPE)) { diff --git a/modules/chibi/event_stream_chibi.cpp b/modules/chibi/event_stream_chibi.cpp index 73d1c01e3..ab3408052 100644 --- a/modules/chibi/event_stream_chibi.cpp +++ b/modules/chibi/event_stream_chibi.cpp @@ -408,8 +408,8 @@ void CPMixerImpl::set_voice_chorus_send(int p_voice_index,int p_chorus){ void CPMixerImpl::set_reverb_mode(ReverbMode p_mode){ -// Voice &v=voices[p_voice_index]; -// ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); + //Voice &v=voices[p_voice_index]; + //ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); switch(p_mode) { case CPMixer::REVERB_MODE_STUDIO_SMALL: reverb_type=AudioMixer::REVERB_SMALL; break; case CPMixer::REVERB_MODE_STUDIO_MEDIUM: reverb_type=AudioMixer::REVERB_MEDIUM; break; @@ -422,8 +422,8 @@ void CPMixerImpl::set_reverb_mode(ReverbMode p_mode){ void CPMixerImpl::set_chorus_params(unsigned int p_delay_ms,unsigned int p_separation_ms,unsigned int p_depth_ms10,unsigned int p_speed_hz10){ -// Voice &v=voices[p_voice_index]; -// ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); + //Voice &v=voices[p_voice_index]; + //ERR_FAIL_COND(v.channel==AudioMixer::INVALID_CHANNEL); } @@ -785,7 +785,7 @@ RES ResourceFormatLoaderChibi::load(const String &p_path, const String& p_origin if (r_error) *r_error=ERR_FILE_CANT_OPEN; - String el = p_path.extension().to_lower(); + String el = p_path.get_extension().to_lower(); CPFileAccessWrapperImpl f; @@ -849,7 +849,7 @@ bool ResourceFormatLoaderChibi::handles_type(const String& p_type) const { } String ResourceFormatLoaderChibi::get_resource_type(const String &p_path) const { - String el = p_path.extension().to_lower(); + String el = p_path.get_extension().to_lower(); if (el=="it" || el=="s3m" || el=="xm" || el=="mod") return "EventStreamChibi"; return ""; diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index 1de98a6b1..5295183c3 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -221,7 +221,7 @@ RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path, if (!(flags&DDSD_MIPMAPCOUNT)) mipmaps=1; -// print_line("found format: "+String(dds_format_info[dds_format].name)); + //print_line("found format: "+String(dds_format_info[dds_format].name)); PoolVector<uint8_t> src_data; @@ -478,7 +478,7 @@ bool ResourceFormatDDS::handles_type(const String& p_type) const { String ResourceFormatDDS::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="dds") + if (p_path.get_extension().to_lower()=="dds") return "ImageTexture"; return ""; } diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 43d9988de..d10634e9e 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -506,8 +506,10 @@ uint32_t NetworkedMultiplayerENet::_gen_unique_id() const { (uint32_t)OS::get_singleton()->get_unix_time(), hash ); hash = hash_djb2_one_32( (uint32_t)OS::get_singleton()->get_data_dir().hash64(), hash ); - //hash = hash_djb2_one_32( - // (uint32_t)OS::get_singleton()->get_unique_ID().hash64(), hash ); + /* + hash = hash_djb2_one_32( + (uint32_t)OS::get_singleton()->get_unique_ID().hash64(), hash ); + */ hash = hash_djb2_one_32( (uint32_t)((uint64_t)this), hash ); //rely on aslr heap hash = hash_djb2_one_32( diff --git a/modules/etc1/image_etc.cpp b/modules/etc1/image_etc.cpp index 845084fef..36ff1b86d 100644 --- a/modules/etc1/image_etc.cpp +++ b/modules/etc1/image_etc.cpp @@ -138,13 +138,13 @@ static void _compress_etc(Image *p_img) { uint8_t *dst = &w[dst_data.size()-mmsize]; -// print_line("bh: "+itos(bh)+" bw: "+itos(bw)); + //print_line("bh: "+itos(bh)+" bw: "+itos(bw)); for(int y=0;y<bh;y++) { for(int x=0;x<bw;x++) { -// print_line("x: "+itos(x)+" y: "+itos(y)); + //print_line("x: "+itos(x)+" y: "+itos(y)); uint8_t block[4*4*4]; zeromem(block,4*4*4); diff --git a/modules/etc1/texture_loader_pkm.cpp b/modules/etc1/texture_loader_pkm.cpp index 42c9937b8..e720e1fb4 100644 --- a/modules/etc1/texture_loader_pkm.cpp +++ b/modules/etc1/texture_loader_pkm.cpp @@ -78,7 +78,7 @@ bool ResourceFormatPKM::handles_type(const String& p_type) const { String ResourceFormatPKM::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="pkm") + if (p_path.get_extension().to_lower()=="pkm") return "ImageTexture"; return ""; } diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index 7483af298..a5351a584 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -1099,7 +1099,72 @@ Error GDCompiler::_parse_block(CodeGen& codegen,const GDParser::BlockNode *p_blo switch(cf->cf_type) { + case GDParser::ControlFlowNode::CF_MATCH: { + GDParser::MatchNode *match = cf->match; + + GDParser::IdentifierNode *id = memnew(GDParser::IdentifierNode); + id->name = "#match_value"; + + // var #match_value + // copied because there is no _parse_statement :( + codegen.add_stack_identifier(id->name, p_stack_level++); + codegen.alloc_stack(p_stack_level); + new_identifiers++; + GDParser::OperatorNode *op = memnew(GDParser::OperatorNode); + op->op=GDParser::OperatorNode::OP_ASSIGN; + op->arguments.push_back(id); + op->arguments.push_back(match->val_to_match); + + int ret = _parse_expression(codegen, op, p_stack_level); + if (ret < 0) { + return ERR_PARSE_ERROR; + } + + // break address + codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(codegen.opcodes.size() + 3); + int break_addr = codegen.opcodes.size(); + codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(0); // break addr + + for (int j = 0; j < match->compiled_pattern_branches.size(); j++) { + GDParser::MatchNode::CompiledPatternBranch branch = match->compiled_pattern_branches[j]; + + // jump over continue + // jump unconditionally + // continue address + // compile the condition + int ret = _parse_expression(codegen, branch.compiled_pattern, p_stack_level); + if (ret < 0) { + return ERR_PARSE_ERROR; + } + + codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF); + codegen.opcodes.push_back(ret); + codegen.opcodes.push_back(codegen.opcodes.size() + 3); + int continue_addr = codegen.opcodes.size(); + codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(0); + + + + Error err = _parse_block(codegen, branch.body, p_stack_level, p_break_addr, continue_addr); + if (err) { + return ERR_PARSE_ERROR; + } + + codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(break_addr); + + codegen.opcodes[continue_addr + 1] = codegen.opcodes.size(); + } + + codegen.opcodes[break_addr + 1] = codegen.opcodes.size(); + + + } break; + case GDParser::ControlFlowNode::CF_IF: { #ifdef DEBUG_ENABLED @@ -1420,9 +1485,10 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode * GDFunction *gdfunc=NULL; - //if (String(p_func->name)=="") { //initializer func - // gdfunc = &p_script->initializer; - + /* + if (String(p_func->name)=="") { //initializer func + gdfunc = &p_script->initializer; + */ //} else { //regular func p_script->member_functions[func_name]=memnew(GDFunction); gdfunc = p_script->member_functions[func_name]; @@ -1729,9 +1795,14 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa } + }else { + // without extends, implicitly extend Reference + int native_idx = GDScriptLanguage::get_singleton()->get_global_map()["Reference"]; + native = GDScriptLanguage::get_singleton()->get_global_array()[native_idx]; + ERR_FAIL_COND_V(native.is_null(), ERR_BUG); + p_script->native=native; } - //print_line("Script: "+p_script->get_path()+" indices: "+itos(p_script->member_indices.size())); diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index 00b080190..19472d3d4 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -364,10 +364,12 @@ static GDCompletionIdentifier _get_type_from_variant(const Variant& p_variant) { if (p_variant.get_type()==Variant::OBJECT) { Object *obj = p_variant; if (obj) { - //if (obj->cast_to<GDNativeClass>()) { - // t.obj_type=obj->cast_to<GDNativeClass>()->get_name(); - // t.value=Variant(); - //} else { + /* + if (obj->cast_to<GDNativeClass>()) { + t.obj_type=obj->cast_to<GDNativeClass>()->get_name(); + t.value=Variant(); + } else { + */ t.obj_type=obj->get_class(); //} } @@ -671,7 +673,7 @@ static bool _guess_expression_type(GDCompletionContext& context,const GDParser:: if (!script.ends_with(".gd")) { //not a script, try find the script anyway, //may have some success - script=script.basename()+".gd"; + script=script.get_basename()+".gd"; } if (FileAccess::exists(script)) { @@ -1168,7 +1170,7 @@ static bool _guess_identifier_type(GDCompletionContext& context,int p_line,const if (!script.ends_with(".gd")) { //not a script, try find the script anyway, //may have some success - script=script.basename()+".gd"; + script=script.get_basename()+".gd"; } if (FileAccess::exists(script)) { @@ -1771,7 +1773,7 @@ static void _find_type_arguments(GDCompletionContext& context,const GDParser::No String s = E->get().name; if (!s.begins_with("autoload/")) continue; - // print_line("found "+s); + //print_line("found "+s); String name = s.get_slice("/",1); result.insert("\"/root/"+name+"\""); } @@ -1998,10 +2000,10 @@ static void _find_call_arguments(GDCompletionContext& context,const GDParser::No List<MethodInfo> methods; ClassDB::get_method_list(type,&methods); for(List<MethodInfo>::Element *E=methods.front();E;E=E->next()) { - //if (E->get().arguments.size()) - // result.insert(E->get().name+"("); - //else - // result.insert(E->get().name+"()"); + if (E->get().arguments.size()) + result.insert(E->get().name+"("); + else + result.insert(E->get().name+"()"); }*/ } break; @@ -2832,7 +2834,7 @@ Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol if (!script.ends_with(".gd")) { //not a script, try find the script anyway, //may have some success - script=script.basename()+".gd"; + script=script.get_basename()+".gd"; } if (FileAccess::exists(script)) { diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 6aed7c949..4a36fbb4f 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -225,8 +225,8 @@ bool GDParser::_get_completable_identifier(CompletionType p_type,StringName& ide GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_allow_assign,bool p_parsing_constant) { -// Vector<Node*> expressions; -// Vector<OperatorNode::Operator> operators; + //Vector<Node*> expressions; + //Vector<OperatorNode::Operator> operators; Vector<Expression> expression; @@ -724,6 +724,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ }; Node *key=NULL; + Set<Variant> keys; DictExpect expecting=DICT_EXPECT_KEY; @@ -819,6 +820,16 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ return NULL; expecting=DICT_EXPECT_COMMA; + if (key->type == GDParser::Node::TYPE_CONSTANT) { + Variant const& keyName = static_cast<const GDParser::ConstantNode*>(key)->value; + + if (keys.has(keyName)) { + _set_error("Duplicate key found in Dictionary literal"); + return NULL; + } + keys.insert(keyName); + } + DictionaryNode::Pair pair; pair.key=key; pair.value=value; @@ -1679,6 +1690,542 @@ bool GDParser::_recover_from_completion() { return true; } +GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) +{ + + PatternNode *pattern = alloc_node<PatternNode>(); + + GDTokenizer::Token token = tokenizer->get_token(); + if (error_set) + return NULL; + + if (token == GDTokenizer::TK_EOF) { + return NULL; + } + + switch (token) { + // dictionary + case GDTokenizer::TK_BRACKET_OPEN: { + tokenizer->advance(); + pattern->pt_type = GDParser::PatternNode::PT_ARRAY; + while (true) { + + if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_CLOSE) { + tokenizer->advance(); + break; + } + + if (tokenizer->get_token() == GDTokenizer::TK_PERIOD && tokenizer->get_token(1) == GDTokenizer::TK_PERIOD) { + // match everything + tokenizer->advance(2); + PatternNode *sub_pattern = alloc_node<PatternNode>(); + sub_pattern->pt_type = GDParser::PatternNode::PT_IGNORE_REST; + pattern->array.push_back(sub_pattern); + if (tokenizer->get_token() == GDTokenizer::TK_COMMA && tokenizer->get_token(1) == GDTokenizer::TK_BRACKET_CLOSE) { + tokenizer->advance(2); + break; + } else if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_CLOSE) { + tokenizer->advance(1); + break; + } else { + _set_error("'..' pattern only allowed at the end of an array pattern"); + return NULL; + } + } + + PatternNode *sub_pattern = _parse_pattern(p_static); + if (!sub_pattern) { + return NULL; + } + + pattern->array.push_back(sub_pattern); + + if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + tokenizer->advance(); + continue; + } else if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_CLOSE) { + tokenizer->advance(); + break; + } else { + _set_error("Not a valid pattern"); + return NULL; + } + } + } break; + // bind + case GDTokenizer::TK_PR_VAR: { + tokenizer->advance(); + pattern->pt_type = GDParser::PatternNode::PT_BIND; + pattern->bind = tokenizer->get_token_identifier(); + tokenizer->advance(); + } break; + // array + case GDTokenizer::TK_CURLY_BRACKET_OPEN: { + tokenizer->advance(); + pattern->pt_type = GDParser::PatternNode::PT_DICTIONARY; + while (true) { + + if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + tokenizer->advance(); + break; + } + + if (tokenizer->get_token() == GDTokenizer::TK_PERIOD && tokenizer->get_token(1) == GDTokenizer::TK_PERIOD) { + // match everything + tokenizer->advance(2); + PatternNode *sub_pattern = alloc_node<PatternNode>(); + sub_pattern->pt_type = PatternNode::PT_IGNORE_REST; + pattern->array.push_back(sub_pattern); + if (tokenizer->get_token() == GDTokenizer::TK_COMMA && tokenizer->get_token(1) == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + tokenizer->advance(2); + break; + } else if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + tokenizer->advance(1); + break; + } else { + _set_error("'..' pattern only allowed at the end of an dictionary pattern"); + return NULL; + } + } + + Node *key = _parse_and_reduce_expression(pattern, p_static); + if (!key) { + _set_error("Not a valid key in pattern"); + return NULL; + } + + if (key->type != GDParser::Node::TYPE_CONSTANT) { + _set_error("Not a constant expression as key"); + return NULL; + } + + if (tokenizer->get_token() == GDTokenizer::TK_COLON) { + tokenizer->advance(); + + PatternNode *value = _parse_pattern(p_static); + if (!value) { + _set_error("Expected pattern in dictionary value"); + return NULL; + } + + pattern->dictionary.insert(static_cast<ConstantNode*>(key), value); + } else { + pattern->dictionary.insert(static_cast<ConstantNode*>(key), NULL); + } + + + if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + tokenizer->advance(); + continue; + } else if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + tokenizer->advance(); + break; + } else { + _set_error("Not a valid pattern"); + return NULL; + } + } + } break; + // all the constants like strings and numbers + default: { + Node *value = _parse_and_reduce_expression(pattern, p_static); + if (error_set) { + return NULL; + } + if (value->type == Node::TYPE_IDENTIFIER && static_cast<IdentifierNode*>(value)->name == "_") { + // wildcard pattern + pattern->pt_type = PatternNode::PT_WILDCARD; + break; + } + + if (value->type != Node::TYPE_IDENTIFIER && value->type != Node::TYPE_CONSTANT) { + _set_error("Only constant expressions or variables allowed in a pattern"); + return NULL; + } + + pattern->pt_type = PatternNode::PT_CONSTANT; + pattern->constant = value; + } break; + } + + return pattern; +} + +void GDParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode*> &p_branches, bool p_static) +{ + int indent_level = tab_level.back()->get(); + + while (true) { + + while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE && _parse_newline()); + + // GDTokenizer::Token token = tokenizer->get_token(); + if (error_set) + return; + + if (indent_level > tab_level.back()->get()) { + return; // go back a level + } + + if (pending_newline!=-1) { + pending_newline=-1; + } + + PatternBranchNode *branch = alloc_node<PatternBranchNode>(); + + branch->patterns.push_back(_parse_pattern(p_static)); + if (!branch->patterns[0]) { + return; + } + + while (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + tokenizer->advance(); + branch->patterns.push_back(_parse_pattern(p_static)); + if (!branch->patterns[branch->patterns.size() - 1]) { + return; + } + } + + if(!_enter_indent_block()) { + _set_error("Expected block in pattern branch"); + return; + } + + branch->body = alloc_node<BlockNode>(); + branch->body->parent_block = p_block; + p_block->sub_blocks.push_back(branch->body); + current_block = branch->body; + + _parse_block(branch->body, p_static); + + current_block = p_block; + + p_branches.push_back(branch); + } +} + + +void GDParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node*> &p_bindings) +{ + switch (p_pattern->pt_type) { + case PatternNode::PT_CONSTANT: { + + // typecheck + BuiltInFunctionNode *typeof_node = alloc_node<BuiltInFunctionNode>(); + typeof_node->function = GDFunctions::TYPE_OF; + + OperatorNode *typeof_match_value = alloc_node<OperatorNode>(); + typeof_match_value->op = OperatorNode::OP_CALL; + typeof_match_value->arguments.push_back(typeof_node); + typeof_match_value->arguments.push_back(p_node_to_match); + + OperatorNode *typeof_pattern_value = alloc_node<OperatorNode>(); + typeof_pattern_value->op = OperatorNode::OP_CALL; + typeof_pattern_value->arguments.push_back(typeof_node); + typeof_pattern_value->arguments.push_back(p_pattern->constant); + + OperatorNode *type_comp = alloc_node<OperatorNode>(); + type_comp->op = OperatorNode::OP_EQUAL; + type_comp->arguments.push_back(typeof_match_value); + type_comp->arguments.push_back(typeof_pattern_value); + + + // comare the actual values + OperatorNode *value_comp = alloc_node<OperatorNode>(); + value_comp->op = OperatorNode::OP_EQUAL; + value_comp->arguments.push_back(p_pattern->constant); + value_comp->arguments.push_back(p_node_to_match); + + + OperatorNode *comparison = alloc_node<OperatorNode>(); + comparison->op = OperatorNode::OP_AND; + comparison->arguments.push_back(type_comp); + comparison->arguments.push_back(value_comp); + + p_resulting_node = comparison; + + } break; + case PatternNode::PT_BIND: { + p_bindings[p_pattern->bind] = p_node_to_match; + + // a bind always matches + ConstantNode *true_value = alloc_node<ConstantNode>(); + true_value->value = Variant(true); + p_resulting_node = true_value; + } break; + case PatternNode::PT_ARRAY: { + + bool open_ended = false; + + if (p_pattern->array.size() > 0) { + if (p_pattern->array[p_pattern->array.size() - 1]->pt_type == PatternNode::PT_IGNORE_REST) { + open_ended = true; + } + } + + // typeof(value_to_match) == TYPE_ARRAY && value_to_match.size() >= length + // typeof(value_to_match) == TYPE_ARRAY && value_to_match.size() == length + + { + // typecheck + BuiltInFunctionNode *typeof_node = alloc_node<BuiltInFunctionNode>(); + typeof_node->function = GDFunctions::TYPE_OF; + + OperatorNode *typeof_match_value = alloc_node<OperatorNode>(); + typeof_match_value->op = OperatorNode::OP_CALL; + typeof_match_value->arguments.push_back(typeof_node); + typeof_match_value->arguments.push_back(p_node_to_match); + + IdentifierNode *typeof_array = alloc_node<IdentifierNode>(); + typeof_array->name = "TYPE_ARRAY"; + + OperatorNode *type_comp = alloc_node<OperatorNode>(); + type_comp->op = OperatorNode::OP_EQUAL; + type_comp->arguments.push_back(typeof_match_value); + type_comp->arguments.push_back(typeof_array); + + + // size + ConstantNode *length = alloc_node<ConstantNode>(); + length->value = Variant(open_ended ? p_pattern->array.size() - 1 : p_pattern->array.size()); + + OperatorNode *call = alloc_node<OperatorNode>(); + call->op = OperatorNode::OP_CALL; + call->arguments.push_back(p_node_to_match); + + IdentifierNode *size = alloc_node<IdentifierNode>(); + size->name = "size"; + call->arguments.push_back(size); + + OperatorNode *length_comparison = alloc_node<OperatorNode>(); + length_comparison->op = open_ended ? OperatorNode::OP_GREATER_EQUAL : OperatorNode::OP_EQUAL; + length_comparison->arguments.push_back(call); + length_comparison->arguments.push_back(length); + + OperatorNode *type_and_length_comparison = alloc_node<OperatorNode>(); + type_and_length_comparison->op = OperatorNode::OP_AND; + type_and_length_comparison->arguments.push_back(type_comp); + type_and_length_comparison->arguments.push_back(length_comparison); + + p_resulting_node = type_and_length_comparison; + } + + + + for (int i = 0; i < p_pattern->array.size(); i++) { + PatternNode *pattern = p_pattern->array[i]; + + Node *condition = NULL; + + ConstantNode *index = alloc_node<ConstantNode>(); + index->value = Variant(i); + + OperatorNode *indexed_value = alloc_node<OperatorNode>(); + indexed_value->op = OperatorNode::OP_INDEX; + indexed_value->arguments.push_back(p_node_to_match); + indexed_value->arguments.push_back(index); + + _generate_pattern(pattern, indexed_value, condition, p_bindings); + + // concatenate all the patterns with && + OperatorNode *and_node = alloc_node<OperatorNode>(); + and_node->op = OperatorNode::OP_AND; + and_node->arguments.push_back(p_resulting_node); + and_node->arguments.push_back(condition); + + p_resulting_node = and_node; + } + + + } break; + case PatternNode::PT_DICTIONARY: { + + bool open_ended = false; + + if (p_pattern->array.size() > 0) { + open_ended = true; + } + + // typeof(value_to_match) == TYPE_DICTIONARY && value_to_match.size() >= length + // typeof(value_to_match) == TYPE_DICTIONARY && value_to_match.size() == length + + + { + // typecheck + BuiltInFunctionNode *typeof_node = alloc_node<BuiltInFunctionNode>(); + typeof_node->function = GDFunctions::TYPE_OF; + + OperatorNode *typeof_match_value = alloc_node<OperatorNode>(); + typeof_match_value->op = OperatorNode::OP_CALL; + typeof_match_value->arguments.push_back(typeof_node); + typeof_match_value->arguments.push_back(p_node_to_match); + + IdentifierNode *typeof_dictionary = alloc_node<IdentifierNode>(); + typeof_dictionary->name = "TYPE_DICTIONARY"; + + OperatorNode *type_comp = alloc_node<OperatorNode>(); + type_comp->op = OperatorNode::OP_EQUAL; + type_comp->arguments.push_back(typeof_match_value); + type_comp->arguments.push_back(typeof_dictionary); + + // size + ConstantNode *length = alloc_node<ConstantNode>(); + length->value = Variant(open_ended ? p_pattern->dictionary.size() - 1 : p_pattern->dictionary.size()); + + OperatorNode *call = alloc_node<OperatorNode>(); + call->op = OperatorNode::OP_CALL; + call->arguments.push_back(p_node_to_match); + + IdentifierNode *size = alloc_node<IdentifierNode>(); + size->name = "size"; + call->arguments.push_back(size); + + OperatorNode *length_comparison = alloc_node<OperatorNode>(); + length_comparison->op = open_ended ? OperatorNode::OP_GREATER_EQUAL : OperatorNode::OP_EQUAL; + length_comparison->arguments.push_back(call); + length_comparison->arguments.push_back(length); + + OperatorNode *type_and_length_comparison = alloc_node<OperatorNode>(); + type_and_length_comparison->op = OperatorNode::OP_AND; + type_and_length_comparison->arguments.push_back(type_comp); + type_and_length_comparison->arguments.push_back(length_comparison); + + p_resulting_node = type_and_length_comparison; + } + + + + for (Map<ConstantNode*, PatternNode*>::Element *e = p_pattern->dictionary.front(); e; e = e->next()) { + + Node *condition = NULL; + + // chech for has, then for pattern + + IdentifierNode *has = alloc_node<IdentifierNode>(); + has->name = "has"; + + OperatorNode *has_call = alloc_node<OperatorNode>(); + has_call->op = OperatorNode::OP_CALL; + has_call->arguments.push_back(p_node_to_match); + has_call->arguments.push_back(has); + has_call->arguments.push_back(e->key()); + + + if (e->value()) { + + OperatorNode *indexed_value = alloc_node<OperatorNode>(); + indexed_value->op = OperatorNode::OP_INDEX; + indexed_value->arguments.push_back(p_node_to_match); + indexed_value->arguments.push_back(e->key()); + + _generate_pattern(e->value(), indexed_value, condition, p_bindings); + + OperatorNode *has_and_pattern = alloc_node<OperatorNode>(); + has_and_pattern->op = OperatorNode::OP_AND; + has_and_pattern->arguments.push_back(has_call); + has_and_pattern->arguments.push_back(condition); + + condition = has_and_pattern; + + } else { + condition = has_call; + } + + + + // concatenate all the patterns with && + OperatorNode *and_node = alloc_node<OperatorNode>(); + and_node->op = OperatorNode::OP_AND; + and_node->arguments.push_back(p_resulting_node); + and_node->arguments.push_back(condition); + + p_resulting_node = and_node; + } + + } break; + case PatternNode::PT_IGNORE_REST: + case PatternNode::PT_WILDCARD: { + // simply generate a `true` + ConstantNode *true_value = alloc_node<ConstantNode>(); + true_value->value = Variant(true); + p_resulting_node = true_value; + } break; + default: { + + } break; + } +} + +void GDParser::_transform_match_statment(BlockNode *p_block, MatchNode *p_match_statement) +{ + IdentifierNode *id = alloc_node<IdentifierNode>(); + id->name = "#match_value"; + + for (int i = 0; i < p_match_statement->branches.size(); i++) { + + PatternBranchNode *branch = p_match_statement->branches[i]; + + MatchNode::CompiledPatternBranch compiled_branch; + compiled_branch.compiled_pattern = NULL; + + Map<StringName, Node*> binding; + + for (int j = 0; j < branch->patterns.size(); j++) { + PatternNode *pattern = branch->patterns[j]; + + Map<StringName, Node*> bindings; + Node *resulting_node; + _generate_pattern(pattern, id, resulting_node, bindings); + + if (!binding.empty() && !bindings.empty()) { + _set_error("Multipatterns can't contain bindings"); + return; + } else { + binding = bindings; + } + + if (compiled_branch.compiled_pattern) { + OperatorNode *or_node = alloc_node<OperatorNode>(); + or_node->op = OperatorNode::OP_OR; + or_node->arguments.push_back(compiled_branch.compiled_pattern); + or_node->arguments.push_back(resulting_node); + + compiled_branch.compiled_pattern = or_node; + } else { + // single pattern | first one + compiled_branch.compiled_pattern = resulting_node; + } + + } + + + // prepare the body ...hehe + for (Map<StringName, Node*>::Element *e = binding.front(); e; e = e->next()) { + LocalVarNode *local_var = alloc_node<LocalVarNode>(); + local_var->name = e->key(); + local_var->assign = e->value(); + + + IdentifierNode *id = alloc_node<IdentifierNode>(); + id->name = local_var->name; + + OperatorNode *op = alloc_node<OperatorNode>(); + op->op=OperatorNode::OP_ASSIGN; + op->arguments.push_back(id); + op->arguments.push_back(local_var->assign); + + branch->body->statements.push_front(op); + branch->body->statements.push_front(local_var); + } + + compiled_branch.body = branch->body; + + + p_match_statement->compiled_pattern_branches.push_back(compiled_branch); + } + +} + void GDParser::_parse_block(BlockNode *p_block,bool p_static) { int indent_level = tab_level.back()->get(); @@ -1762,6 +2309,24 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { } StringName n = tokenizer->get_token_identifier(); tokenizer->advance(); + if (current_function){ + for (int i=0;i<current_function->arguments.size();i++){ + if (n == current_function->arguments[i]){ + _set_error("Variable '"+String(n)+"' already defined in the scope (at line: "+itos(current_function->line)+")."); + return; + } + } + } + BlockNode *check_block = p_block; + while (check_block){ + for (int i=0;i<check_block->variables.size();i++){ + if (n == check_block->variables[i]){ + _set_error("Variable '"+String(n)+"' already defined in the scope (at line: "+itos(check_block->variable_lines[i])+")."); + return; + } + } + check_block = check_block->parent_block; + } p_block->variables.push_back(n); //line? p_block->variable_lines.push_back(tokenizer->get_token_line()); @@ -2079,7 +2644,14 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { } current_block=cf_for->body; + + // this is for checking variable for redefining + // inside this _parse_block + cf_for->body->variables.push_back(id->name); + cf_for->body->variable_lines.push_back(id->line); _parse_block(cf_for->body,p_static); + cf_for->body->variables.remove(0); + cf_for->body->variable_lines.remove(0); current_block=p_block; if (error_set) @@ -2141,6 +2713,46 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) { } break; + case GDTokenizer::TK_CF_MATCH: { + + tokenizer->advance(); + + MatchNode *match_node = alloc_node<MatchNode>(); + + Node *val_to_match = _parse_and_reduce_expression(p_block, p_static); + + if (!val_to_match) { + if (_recover_from_completion()) { + break; + } + return; + } + + match_node->val_to_match = val_to_match; + + if (!_enter_indent_block()) { + _set_error("Expected indented pattern matching block after 'match'"); + return; + } + + BlockNode *compiled_branches = alloc_node<BlockNode>(); + compiled_branches->parent_block = p_block; + compiled_branches->parent_class = p_block->parent_class; + + p_block->sub_blocks.push_back(compiled_branches); + + _parse_pattern_block(compiled_branches, match_node->branches, p_static); + + _transform_match_statment(compiled_branches, match_node); + + ControlFlowNode *match_cf_node = alloc_node<ControlFlowNode>(); + match_cf_node->cf_type = ControlFlowNode::CF_MATCH; + match_cf_node->match = match_node; + + p_block->statements.push_back(match_cf_node); + + _end_statement(); + } break; case GDTokenizer::TK_PR_ASSERT: { tokenizer->advance(); diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h index e8f5f0f98..7968bf85d 100644 --- a/modules/gdscript/gd_parser.h +++ b/modules/gdscript/gd_parser.h @@ -258,6 +258,44 @@ public: Vector<Node*> arguments; OperatorNode() { type=TYPE_OPERATOR; } }; + + + struct PatternNode : public Node { + + enum PatternType { + PT_CONSTANT, + PT_BIND, + PT_DICTIONARY, + PT_ARRAY, + PT_IGNORE_REST, + PT_WILDCARD + }; + + PatternType pt_type; + + Node *constant; + StringName bind; + Map<ConstantNode*, PatternNode*> dictionary; + Vector<PatternNode*> array; + + }; + + struct PatternBranchNode : public Node { + Vector<PatternNode*> patterns; + BlockNode *body; + }; + + struct MatchNode : public Node { + Node *val_to_match; + Vector<PatternBranchNode*> branches; + + struct CompiledPatternBranch { + Node *compiled_pattern; + BlockNode *body; + }; + + Vector<CompiledPatternBranch> compiled_pattern_branches; + }; struct ControlFlowNode : public Node { enum CFType { @@ -267,13 +305,16 @@ public: CF_SWITCH, CF_BREAK, CF_CONTINUE, - CF_RETURN + CF_RETURN, + CF_MATCH }; CFType cf_type; Vector<Node*> arguments; BlockNode *body; BlockNode *body_else; + + MatchNode *match; ControlFlowNode *_else; //used for if ControlFlowNode() { type=TYPE_CONTROL_FLOW; cf_type=CF_IF; body=NULL; body_else=NULL;} @@ -452,6 +493,15 @@ private: Node* _reduce_expression(Node *p_node,bool p_to_const=false); Node* _parse_and_reduce_expression(Node *p_parent,bool p_static,bool p_reduce_const=false,bool p_allow_assign=false); + + + + PatternNode *_parse_pattern(bool p_static); + void _parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode*> &p_branches, bool p_static); + void _transform_match_statment(BlockNode *p_block, MatchNode *p_match_statement); + void _generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node*> &p_bindings); + + void _parse_block(BlockNode *p_block,bool p_static); void _parse_extends(ClassNode *p_class); void _parse_class(ClassNode *p_class); diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 0b81780b0..d9a3dd13f 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -160,6 +160,8 @@ Variant GDScript::_new(const Variant** p_args,int p_argcount,Variant::CallError& _baseptr=_baseptr->_base; } + ERR_FAIL_COND_V(_baseptr->native.is_null(), Variant()); + if (_baseptr->native.ptr()) { owner=_baseptr->native->instance(); } else { @@ -356,9 +358,11 @@ bool GDScript::get_property_default_value(const StringName& p_property, Variant #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()))); - //} + /* + 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(); @@ -1860,7 +1864,7 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script>& p_script,bool p_sof void GDScriptLanguage::frame() { - // print_line("calls: "+itos(calls)); + //print_line("calls: "+itos(calls)); calls=0; #ifdef DEBUG_ENABLED @@ -1934,6 +1938,7 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const { "for", "pass", "return", + "match", "while", "remote", "sync", @@ -2066,7 +2071,7 @@ bool ResourceFormatLoaderGDScript::handles_type(const String& p_type) const { String ResourceFormatLoaderGDScript::get_resource_type(const String &p_path) const { - String el = p_path.extension().to_lower(); + String el = p_path.get_extension().to_lower(); if (el=="gd" || el=="gdc" || el=="gde") return "GDScript"; return ""; diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 960b06f3f..4d3baa5bc 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -139,7 +139,7 @@ protected: void _get_property_list(List<PropertyInfo> *p_properties) const; Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error); -// void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount); + //void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount); static void _bind_methods(); public: diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 30ac98829..70fc991bc 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -85,6 +85,7 @@ const char* GDTokenizer::token_names[TK_MAX]={ "continue", "pass", "return", +"match", "func", "class", "extends", @@ -513,9 +514,11 @@ void GDTokenizerText::_advance() { if (GETCHAR(1)=='=') { _make_token(TK_OP_ASSIGN_ADD); INCPOS(1); - //} else if (GETCHAR(1)=='+') { - // _make_token(TK_OP_PLUS_PLUS); - // INCPOS(1); + /* + } else if (GETCHAR(1)=='+') { + _make_token(TK_OP_PLUS_PLUS); + INCPOS(1); + */ } else { _make_token(TK_OP_ADD); } @@ -526,9 +529,11 @@ void GDTokenizerText::_advance() { if (GETCHAR(1)=='=') { _make_token(TK_OP_ASSIGN_SUB); INCPOS(1); - //} else if (GETCHAR(1)=='-') { - // _make_token(TK_OP_MINUS_MINUS); - // INCPOS(1); + /* + } else if (GETCHAR(1)=='-') { + _make_token(TK_OP_MINUS_MINUS); + INCPOS(1); + */ } else { _make_token(TK_OP_SUB); } @@ -890,6 +895,7 @@ void GDTokenizerText::_advance() { {TK_CF_BREAK,"break"}, {TK_CF_CONTINUE,"continue"}, {TK_CF_RETURN,"return"}, + {TK_CF_MATCH, "match"}, {TK_CF_PASS,"pass"}, {TK_SELF,"self"}, {TK_CONST_PI,"PI"}, diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h index 18e5547d3..9a6f4df9c 100644 --- a/modules/gdscript/gd_tokenizer.h +++ b/modules/gdscript/gd_tokenizer.h @@ -92,6 +92,7 @@ public: TK_CF_CONTINUE, TK_CF_PASS, TK_CF_RETURN, + TK_CF_MATCH, TK_PR_FUNCTION, TK_PR_CLASS, TK_PR_EXTENDS, diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 11bdf783f..051d1d85c 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -100,7 +100,7 @@ public: if (err==OK) { fae->store_buffer(file.ptr(),file.size()); - p_path=p_path.basename()+".gde"; + p_path=p_path.get_basename()+".gde"; } memdelete(fae); @@ -111,7 +111,7 @@ public: } else { - p_path=p_path.basename()+".gdc"; + p_path=p_path.get_basename()+".gdc"; return file; } } diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index b5fa55846..271db4bab 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -731,7 +731,7 @@ void GridMap::_octant_update(const OctantKey &p_key) { ii.shape->add_vertices_to_array(col_debug,xform); } - // print_line("PHIS x: "+xform); + //print_line("PHIS x: "+xform); } // add the item's navmesh at given xform to GridMap's Navigation ancestor @@ -796,7 +796,7 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { for(Map<int,Octant::ItemInstances>::Element *E=g.items.front();E;E=E->next()) { VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance,RID()); - // VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); + //VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); VS::get_singleton()->instance_set_room(E->get().multimesh_instance,RID()); } @@ -1001,8 +1001,8 @@ void GridMap::_notification(int p_what) { _update_area_instances(); for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { -// IndexKey ik; -// ik.key = E->key().indexkey; + //IndexKey ik; + //ik.key = E->key().indexkey; _octant_enter_world(E->key()); _octant_update(E->key()); } @@ -1201,7 +1201,7 @@ void GridMap::_bind_methods() { ClassDB::bind_method(_MD("get_cell_item","x","y","z"),&GridMap::get_cell_item); ClassDB::bind_method(_MD("get_cell_item_orientation","x","y","z"),&GridMap::get_cell_item_orientation); -// ClassDB::bind_method(_MD("_recreate_octants"),&GridMap::_recreate_octants); + //ClassDB::bind_method(_MD("_recreate_octants"),&GridMap::_recreate_octants); ClassDB::bind_method(_MD("_update_dirty_map_callback"),&GridMap::_update_dirty_map_callback); ClassDB::bind_method(_MD("resource_changed","resource"),&GridMap::resource_changed); @@ -1706,10 +1706,12 @@ void GridMap::bake_geometry() { void GridMap::_baked_light_changed() { -// if (!baked_light_instance) -// VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),RID()); -// else -// VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),baked_light_instance->get_baked_light_instance()); + /* + if (!baked_light_instance) + VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),RID()); + else + VS::get_singleton()->instance_geometry_set_baked_light(get_instance(),baked_light_instance->get_baked_light_instance()); + */ for(Map<OctantKey,Octant*>::Element *E=octant_map.front();E;E=E->next()) { for(Map<int,Octant::ItemInstances>::Element *F=E->get()->items.front();F;F=F->next()) { @@ -1831,6 +1833,7 @@ GridMap::GridMap() { use_baked_light=false; navigation = NULL; + set_notify_transform(true); } diff --git a/modules/openssl/stream_peer_openssl.cpp b/modules/openssl/stream_peer_openssl.cpp index 140ea1b9e..43a1f610d 100644 --- a/modules/openssl/stream_peer_openssl.cpp +++ b/modules/openssl/stream_peer_openssl.cpp @@ -35,8 +35,8 @@ bool StreamPeerOpenSSL::_match_host_name(const char *name, const char *hostname) { return Tool_Curl_cert_hostcheck(name,hostname)==CURL_HOST_MATCH; -// print_line("MATCH: "+String(name)+" vs "+String(hostname)); -// return true; + //print_line("MATCH: "+String(name)+" vs "+String(hostname)); + //return true; } Error StreamPeerOpenSSL::_match_common_name(const char *hostname, const X509 *server_cert) { @@ -293,10 +293,10 @@ BIO_METHOD StreamPeerOpenSSL::_bio_method = { _bio_destroy }; -Error StreamPeerOpenSSL::connect(Ref<StreamPeer> p_base, bool p_validate_certs, const String& p_for_hostname) { +Error StreamPeerOpenSSL::connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs, const String& p_for_hostname) { if (connected) - disconnect(); + disconnect_from_stream(); hostname=p_for_hostname; @@ -415,7 +415,7 @@ Error StreamPeerOpenSSL::connect(Ref<StreamPeer> p_base, bool p_validate_certs, return OK; } -Error StreamPeerOpenSSL::accept(Ref<StreamPeer> p_base) { +Error StreamPeerOpenSSL::accept_stream(Ref<StreamPeer> p_base) { return ERR_UNAVAILABLE; @@ -451,7 +451,7 @@ Error StreamPeerOpenSSL::put_data(const uint8_t* p_data,int p_bytes) { int ret = SSL_write(ssl,p_data,p_bytes); if (ret<=0) { _print_error(ret); - disconnect(); + disconnect_from_stream(); return ERR_CONNECTION_ERROR; } p_data+=ret; @@ -486,7 +486,7 @@ Error StreamPeerOpenSSL::get_data(uint8_t* p_buffer, int p_bytes){ int ret = SSL_read(ssl,p_buffer,p_bytes); if (ret<=0) { _print_error(ret); - disconnect(); + disconnect_from_stream(); return ERR_CONNECTION_ERROR; } p_buffer+=ret; @@ -529,7 +529,7 @@ StreamPeerOpenSSL::StreamPeerOpenSSL() { flags=0; } -void StreamPeerOpenSSL::disconnect() { +void StreamPeerOpenSSL::disconnect_from_stream() { if (!connected) return; @@ -552,7 +552,7 @@ StreamPeerOpenSSL::Status StreamPeerOpenSSL::get_status() const { StreamPeerOpenSSL::~StreamPeerOpenSSL() { - disconnect(); + disconnect_from_stream(); } StreamPeerSSL* StreamPeerOpenSSL::_create_func() { diff --git a/modules/openssl/stream_peer_openssl.h b/modules/openssl/stream_peer_openssl.h index d79fb97ff..3d6875698 100644 --- a/modules/openssl/stream_peer_openssl.h +++ b/modules/openssl/stream_peer_openssl.h @@ -85,11 +85,11 @@ protected: public: - virtual Error accept(Ref<StreamPeer> p_base); - virtual Error connect(Ref<StreamPeer> p_base,bool p_validate_certs=false,const String& p_for_hostname=String()); + virtual Error accept_stream(Ref<StreamPeer> p_base); + virtual Error connect_to_stream(Ref<StreamPeer> p_base,bool p_validate_certs=false,const String& p_for_hostname=String()); virtual Status get_status() const; - virtual void disconnect(); + virtual void disconnect_from_stream(); virtual Error put_data(const uint8_t* p_data,int p_bytes); virtual Error put_partial_data(const uint8_t* p_data,int p_bytes, int &r_sent); diff --git a/modules/opus/audio_stream_opus.cpp b/modules/opus/audio_stream_opus.cpp index f438dde68..4a6b2e224 100644 --- a/modules/opus/audio_stream_opus.cpp +++ b/modules/opus/audio_stream_opus.cpp @@ -366,7 +366,7 @@ void ResourceFormatLoaderAudioStreamOpus::get_recognized_extensions(List<String> } String ResourceFormatLoaderAudioStreamOpus::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="opus") + if (p_path.get_extension().to_lower()=="opus") return "AudioStreamOpus"; return ""; } diff --git a/modules/pbm/bitmap_loader_pbm.cpp b/modules/pbm/bitmap_loader_pbm.cpp index 6caaf1033..ab0805a6b 100644 --- a/modules/pbm/bitmap_loader_pbm.cpp +++ b/modules/pbm/bitmap_loader_pbm.cpp @@ -244,7 +244,7 @@ bool ResourceFormatPBM::handles_type(const String& p_type) const { } String ResourceFormatPBM::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="pbm") + if (p_path.get_extension().to_lower()=="pbm") return "BitMap"; return ""; } diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index 9f8db98e0..0d8cabb33 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -185,7 +185,7 @@ bool ResourceFormatPVR::handles_type(const String& p_type) const { String ResourceFormatPVR::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="pvr") + if (p_path.get_extension().to_lower()=="pvr") return "Texture"; return ""; } @@ -669,9 +669,11 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int static void _pvrtc_decompress(Image* p_img) { -// static void decompress_pvrtc(const void *p_comp_img, const int p_2bit, const int p_width, const int p_height, unsigned char* p_dst) { -// decompress_pvrtc((PVRTCBlock*)p_comp_img,p_2bit,p_width,p_height,1,p_dst); -// } + /* + static void decompress_pvrtc(const void *p_comp_img, const int p_2bit, const int p_width, const int p_height, unsigned char* p_dst) { + decompress_pvrtc((PVRTCBlock*)p_comp_img,p_2bit,p_width,p_height,1,p_dst); + } + */ ERR_FAIL_COND( p_img->get_format()!=Image::FORMAT_PVRTC2 && p_img->get_format()!=Image::FORMAT_PVRTC2A && p_img->get_format()!=Image::FORMAT_PVRTC4 && p_img->get_format()!=Image::FORMAT_PVRTC4A); @@ -687,9 +689,11 @@ static void _pvrtc_decompress(Image* p_img) { decompress_pvrtc((PVRTCBlock*)r.ptr(),_2bit,p_img->get_width(),p_img->get_height(),0,(unsigned char*)w.ptr()); - //for(int i=0;i<newdata.size();i++) { - // print_line(itos(w[i])); - //} + /* + for(int i=0;i<newdata.size();i++) { + print_line(itos(w[i])); + } + */ w=PoolVector<uint8_t>::Write(); r=PoolVector<uint8_t>::Read(); diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index b847f17bb..9d2dfc7f5 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -81,6 +81,9 @@ void VideoStreamPlaybackTheora::video_write(void){ th_ycbcr_buffer yuv; th_decode_ycbcr_out(td,yuv); + // FIXME: The way stuff is commented out with `//*/` closing comments + // sounds very fishy... + /* int y_offset, uv_offset; y_offset=(ti.pic_x&~1)+yuv[0].stride*(ti.pic_y&~1); @@ -105,7 +108,7 @@ void VideoStreamPlaybackTheora::video_write(void){ } format = Image::FORMAT_RGBA8; } - // */ + //*/ //* @@ -228,7 +231,7 @@ void VideoStreamPlaybackTheora::video_write(void){ format = Image::FORMAT_YUV_422; }; }; - // */ + //*/ frames_pending = 1; } @@ -598,7 +601,7 @@ void VideoStreamPlaybackTheora::update(float p_delta) { if (vd.granulepos>=0) { - // print_line("wrote: "+itos(audio_frames_wrote)+" gpos: "+itos(vd.granulepos)); + //print_line("wrote: "+itos(audio_frames_wrote)+" gpos: "+itos(vd.granulepos)); } //print_line("mix audio!"); @@ -933,7 +936,7 @@ bool ResourceFormatLoaderVideoStreamTheora::handles_type(const String& p_type) c String ResourceFormatLoaderVideoStreamTheora::get_resource_type(const String &p_path) const { - String exl=p_path.extension().to_lower(); + String exl=p_path.get_extension().to_lower(); if (exl=="ogm" || exl=="ogv") return "VideoStreamTheora"; return ""; diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index 79bf3d50b..5fe87a495 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -82,7 +82,7 @@ void register_visual_script_types() { ClassDB::register_class<VisualScriptFunctionCall>(); ClassDB::register_class<VisualScriptPropertySet>(); ClassDB::register_class<VisualScriptPropertyGet>(); -// ClassDB::register_type<VisualScriptScriptCall>(); + //ClassDB::register_type<VisualScriptScriptCall>(); ClassDB::register_class<VisualScriptEmitSignal>(); ClassDB::register_class<VisualScriptReturn>(); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 08796b386..e1e180432 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -2631,7 +2631,7 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level,List<String> const StringName *f = _call_stack[l].function; ERR_FAIL_COND(!_call_stack[l].instance->functions.has(*f)); -// VisualScriptInstance::Function *func = &_call_stack[l].instance->functions[*f]; + //VisualScriptInstance::Function *func = &_call_stack[l].instance->functions[*f]; VisualScriptNodeInstance *node =_call_stack[l].instance->instances[*_call_stack[l].current_id]; ERR_FAIL_COND(!node); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 6f3ea3b4a..37ee225ae 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -590,9 +590,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) { t=type_icons[left_type]; } if (t.is_valid()) { - TextureFrame *tf = memnew(TextureFrame); + TextureRect *tf = memnew(TextureRect); tf->set_texture(t); - tf->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED); + tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); hbc->add_child(tf); } @@ -657,9 +657,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) { t=type_icons[right_type]; } if (t.is_valid()) { - TextureFrame *tf = memnew(TextureFrame); + TextureRect *tf = memnew(TextureRect); tf->set_texture(t); - tf->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED); + tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); hbc->add_child(tf); } @@ -822,7 +822,7 @@ void VisualScriptEditor::_member_selected() { selected=ti->get_metadata(0); -// print_line("selected: "+String(selected)); + //print_line("selected: "+String(selected)); if (ti->get_parent()==members->get_root()->get_children()) { @@ -1136,9 +1136,11 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt undo_redo->add_undo_method(script.ptr(),"data_connect",name,E->get().from_node,E->get().from_port,E->get().to_node,E->get().to_port); } - //for(int i=0;i<script->function_get_argument_count(name);i++) { - //// undo_redo->add_undo_method(script.ptr(),"function_add_argument",name,script->function_get_argument_name(name,i),script->function_get_argument_type(name,i)); - //} + /* + for(int i=0;i<script->function_get_argument_count(name);i++) { + undo_redo->add_undo_method(script.ptr(),"function_add_argument",name,script->function_get_argument_name(name,i),script->function_get_argument_type(name,i)); + } + */ undo_redo->add_do_method(this,"_update_members"); undo_redo->add_undo_method(this,"_update_members"); undo_redo->add_do_method(this,"_update_graph"); @@ -1776,7 +1778,7 @@ void VisualScriptEditor::drop_data_fw(const Point2& p_point,const Variant& p_dat if (node) { graph->set_selected(node); _node_selected(node); - } + } } if (d.has("type") && String(d["type"])=="resource") { @@ -3082,7 +3084,7 @@ void VisualScriptEditor::_menu_option(int p_what) { //popup disappearing grabs focus to owner, so use call deferred node_filter->call_deferred("grab_focus"); node_filter->call_deferred("select_all"); - } break; + } break; case EDIT_COPY_NODES: case EDIT_CUT_NODES: { @@ -3346,8 +3348,8 @@ VisualScriptEditor::VisualScriptEditor() { node_filter->connect("text_changed",this,"_node_filter_changed"); hbc_nodes->add_child(node_filter); node_filter->set_h_size_flags(SIZE_EXPAND_FILL); - node_filter_icon = memnew( TextureFrame ); - node_filter_icon->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED); + node_filter_icon = memnew( TextureRect ); + node_filter_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED); hbc_nodes->add_child(node_filter_icon); vbc_nodes->add_child(hbc_nodes); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index e120bdc65..1dc62b3e6 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -58,7 +58,7 @@ class VisualScriptEditor : public ScriptEditorBase { GraphEdit *graph; LineEdit *node_filter; - TextureFrame *node_filter_icon; + TextureRect *node_filter_icon; VisualScriptEditorSignalEdit *signal_editor; diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 9f3ba8a8c..a8d78b929 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -396,7 +396,7 @@ void VisualScriptFunctionCall::_update_method_cache() { } -// print_line("BASE: "+String(type)+" FUNC: "+String(function)); + //print_line("BASE: "+String(type)+" FUNC: "+String(function)); MethodBind *mb = ClassDB::get_method(type,function); if (mb) { use_default_args=mb->get_default_argument_count(); @@ -2508,7 +2508,7 @@ void register_visual_script_func_nodes() { VisualScriptLanguage::singleton->add_register_func("functions/get",create_node_generic<VisualScriptPropertyGet>); //VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_self",create_script_call_node<VisualScriptScriptCall::CALL_MODE_SELF>); -// VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_node",create_script_call_node<VisualScriptScriptCall::CALL_MODE_NODE_PATH>); + //VisualScriptLanguage::singleton->add_register_func("functions/call_script/call_node",create_script_call_node<VisualScriptScriptCall::CALL_MODE_NODE_PATH>); VisualScriptLanguage::singleton->add_register_func("functions/emit_signal",create_node_generic<VisualScriptEmitSignal>); diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp index 7abcd0a8b..2b05daca1 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp @@ -78,7 +78,7 @@ int AudioStreamPlaybackOGGVorbis::_ov_seek_func(void *_f,ogg_int64_t offs, int w } int AudioStreamPlaybackOGGVorbis::_ov_close_func(void *_f) { -// printf("close %p\n",_f); + //printf("close %p\n",_f); if (!_f) return 0; FileAccess *fa=(FileAccess*)_f; @@ -419,7 +419,7 @@ void ResourceFormatLoaderAudioStreamOGGVorbis::get_recognized_extensions(List<St } String ResourceFormatLoaderAudioStreamOGGVorbis::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="ogg") + if (p_path.get_extension().to_lower()=="ogg") return "AudioStreamOGGVorbis"; return ""; } diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp index d132e8969..bdd97f1df 100644 --- a/modules/webm/video_stream_webm.cpp +++ b/modules/webm/video_stream_webm.cpp @@ -415,7 +415,7 @@ bool ResourceFormatLoaderVideoStreamWebm::handles_type(const String &p_type) con String ResourceFormatLoaderVideoStreamWebm::get_resource_type(const String &p_path) const { - const String exl = p_path.extension().to_lower(); + const String exl = p_path.get_extension().to_lower(); if (exl == "webm") return "VideoStreamWebm"; return ""; |
