diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/globals.cpp | 42 | ||||
| -rw-r--r-- | core/image.cpp | 55 | ||||
| -rw-r--r-- | core/image.h | 2 | ||||
| -rw-r--r-- | core/io/resource_import.cpp | 25 | ||||
| -rw-r--r-- | core/io/resource_import.h | 1 | ||||
| -rw-r--r-- | core/os/os.h | 2 | ||||
| -rw-r--r-- | core/variant_parser.cpp | 18 |
7 files changed, 89 insertions, 56 deletions
diff --git a/core/globals.cpp b/core/globals.cpp index af3ec403d..ed0b6f6d8 100644 --- a/core/globals.cpp +++ b/core/globals.cpp @@ -38,6 +38,8 @@ #include "io/file_access_network.h" #include "variant_parser.h" +#define FORMAT_VERSION 3 + GlobalConfig *GlobalConfig::singleton=NULL; GlobalConfig *GlobalConfig::get_singleton() { @@ -123,6 +125,7 @@ bool GlobalConfig::_set(const StringName& p_name, const Variant& p_value) { _THREAD_SAFE_METHOD_ + if (p_value.get_type()==Variant::NIL) props.erase(p_name); else { @@ -253,7 +256,7 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { bool ok = _load_resource_pack(p_main_pack); ERR_FAIL_COND_V(!ok,ERR_CANT_OPEN); - if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { + if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) { _load_settings("res://override.cfg"); @@ -275,7 +278,7 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { memdelete(d); } - if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { + if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) { _load_settings("res://override.cfg"); @@ -291,7 +294,7 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { if (FileAccessNetworkClient::get_singleton()) { - if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { + if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) { _load_settings("res://override.cfg"); @@ -311,9 +314,9 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { if (!_load_resource_pack("res://data.pck")) _load_resource_pack("res://data.zip"); // make sure this is load from the resource path - print_line("exists engine cfg? "+itos(FileAccess::exists("/engine.cfg"))); - if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { - print_line("loaded engine.cfg"); + print_line("exists engine cfg? "+itos(FileAccess::exists("/godot.cfg"))); + if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) { + print_line("loaded godot.cfg"); _load_settings("res://override.cfg"); } @@ -341,7 +344,7 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { //tries to open pack, but only first time if (first_time && (_load_resource_pack(current_dir+"/"+exec_name+".pck") || _load_resource_pack(current_dir+"/"+exec_name+".zip") )) { - if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { + if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) { _load_settings("res://override.cfg"); found=true; @@ -350,7 +353,7 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { } break; } else if (first_time && (_load_resource_pack(current_dir+"/data.pck") || _load_resource_pack(current_dir+"/data.zip") )) { - if (_load_settings("res://engine.cfg")==OK || _load_settings_binary("res://engine.cfb")==OK) { + if (_load_settings("res://godot.cfg")==OK || _load_settings_binary("res://godot.cfb")==OK) { _load_settings("res://override.cfg"); found=true; @@ -358,7 +361,7 @@ Error GlobalConfig::setup(const String& p_path,const String & p_main_pack) { } break; - } else if (_load_settings(current_dir+"/engine.cfg")==OK || _load_settings_binary(current_dir+"/engine.cfb")==OK) { + } else if (_load_settings(current_dir+"/godot.cfg")==OK || _load_settings_binary(current_dir+"/godot.cfb")==OK) { _load_settings(current_dir+"/override.cfg"); candidate=current_dir; @@ -416,7 +419,7 @@ Error GlobalConfig::_load_settings_binary(const String p_path) { if (hdr[0]!='E'|| hdr[1]!='C' || hdr[2]!='F' || hdr[3]!='G') { memdelete(f); - ERR_EXPLAIN("Corrupted header in binary engine.cfb (not ECFG)"); + ERR_EXPLAIN("Corrupted header in binary godot.cfb (not ECFG)"); ERR_FAIL_V(ERR_FILE_CORRUPT;) } @@ -491,6 +494,14 @@ Error GlobalConfig::_load_settings(const String p_path) { } if (assign!=String()) { + if (section==String() && assign=="config_version") { + int config_version = value; + if (config_version > FORMAT_VERSION) { + memdelete(f); + ERR_FAIL_COND_V(config_version > FORMAT_VERSION,ERR_FILE_CANT_OPEN); + } + + } set(section+"/"+assign,value); } else if (next_tag.name!=String()) { section=next_tag.name; @@ -526,7 +537,7 @@ void GlobalConfig::clear(const String& p_name) { Error GlobalConfig::save() { - return save_custom(get_resource_path()+"/engine.cfg"); + return save_custom(get_resource_path()+"/godot.cfg"); } Error GlobalConfig::_save_settings_binary(const String& p_file,const Map<String,List<String> > &props,const CustomMap& p_custom) { @@ -536,7 +547,7 @@ Error GlobalConfig::_save_settings_binary(const String& p_file,const Map<String, FileAccess *file = FileAccess::open(p_file,FileAccess::WRITE,&err); if (err!=OK) { - ERR_EXPLAIN("Coudln't save engine.cfb at "+p_file); + ERR_EXPLAIN("Coudln't save godot.cfb at "+p_file); ERR_FAIL_COND_V(err,err) } @@ -604,10 +615,13 @@ Error GlobalConfig::_save_settings_text(const String& p_file,const Map<String,Li FileAccess *file = FileAccess::open(p_file,FileAccess::WRITE,&err); if (err) { - ERR_EXPLAIN("Coudln't save engine.cfg - "+p_file); + ERR_EXPLAIN("Coudln't save godot.cfg - "+p_file); ERR_FAIL_COND_V(err,err) } + file->store_string("config_version="+itos(FORMAT_VERSION)+"\n"); + + for(Map<String,List<String> >::Element *E=props.front();E;E=E->next()) { if (E!=props.front()) @@ -734,7 +748,7 @@ Error GlobalConfig::save_custom(const String& p_path,const CustomMap& p_custom,c Error err = file->open(dst_file,FileAccess::WRITE); if (err) { memdelete(file); - ERR_EXPLAIN("Coudln't save engine.cfg"); + ERR_EXPLAIN("Coudln't save godot.cfg"); ERR_FAIL_COND_V(err,err) } diff --git a/core/image.cpp b/core/image.cpp index 2d038691f..037ff8245 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -245,7 +245,7 @@ void Image::_get_mipmap_offset_and_size(int p_mipmap,int &r_offset, int &r_width } int Image::get_mipmap_offset(int p_mipmap) const { - ERR_FAIL_INDEX_V(p_mipmap,(mipmaps+1),-1); + ERR_FAIL_INDEX_V(p_mipmap,get_mipmap_count()+1,-1); int ofs,w,h; _get_mipmap_offset_and_size(p_mipmap,ofs,w,h); @@ -1011,7 +1011,7 @@ void Image::shrink_x2() { } } -Error Image::generate_mipmaps(bool p_keep_existing) { +Error Image::generate_mipmaps() { if (!_can_modify(format)) { ERR_EXPLAIN("Cannot generate mipmaps in indexed, compressed or custom image formats."); @@ -1019,15 +1019,14 @@ Error Image::generate_mipmaps(bool p_keep_existing) { } - int mmcount = get_mipmap_count(); + ERR_FAIL_COND_V(width==0 || height==0,ERR_UNCONFIGURED); + + int mmcount; - int from_mm=1; - if (p_keep_existing) { - from_mm=mmcount+1; - } int size = _get_dst_image_size(width,height,format,mmcount); data.resize(size); + print_line("to gen mipmaps w "+itos(width)+" h "+itos(height) +" format "+get_format_name(format)+" mipmaps " +itos(mmcount)+" new size is: "+itos(size)); PoolVector<uint8_t>::Write wp=data.write(); @@ -1043,18 +1042,16 @@ Error Image::generate_mipmaps(bool p_keep_existing) { int ofs,w,h; _get_mipmap_offset_and_size(i,ofs, w,h); - if (i>=from_mm) { - switch(format) { + switch(format) { - case FORMAT_L8: - case FORMAT_R8: _generate_po2_mipmap<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; - case FORMAT_LA8: - case FORMAT_RG8: _generate_po2_mipmap<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; - case FORMAT_RGB8: _generate_po2_mipmap<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; - case FORMAT_RGBA8: _generate_po2_mipmap<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; - default: {} - } + case FORMAT_L8: + case FORMAT_R8: _generate_po2_mipmap<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; + case FORMAT_LA8: + case FORMAT_RG8: _generate_po2_mipmap<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; + case FORMAT_RGB8: _generate_po2_mipmap<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; + case FORMAT_RGBA8: _generate_po2_mipmap<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h); break; + default: {} } prev_ofs=ofs; @@ -1077,18 +1074,15 @@ Error Image::generate_mipmaps(bool p_keep_existing) { int ofs,w,h; _get_mipmap_offset_and_size(i,ofs, w,h); - if (i>=from_mm) { - - switch(format) { + switch(format) { - case FORMAT_L8: - case FORMAT_R8: _scale_bilinear<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; - case FORMAT_LA8: - case FORMAT_RG8: _scale_bilinear<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; - case FORMAT_RGB8:_scale_bilinear<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; - case FORMAT_RGBA8: _scale_bilinear<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; - default: {} - } + case FORMAT_L8: + case FORMAT_R8: _scale_bilinear<1>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; + case FORMAT_LA8: + case FORMAT_RG8: _scale_bilinear<2>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; + case FORMAT_RGB8:_scale_bilinear<3>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; + case FORMAT_RGBA8: _scale_bilinear<4>(&wp[prev_ofs], &wp[ofs], prev_w,prev_h,w,h); break; + default: {} } prev_ofs=ofs; @@ -1096,8 +1090,11 @@ Error Image::generate_mipmaps(bool p_keep_existing) { prev_h=h; } + + } + mipmaps=true; return OK; } @@ -1154,7 +1151,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma ERR_FAIL_INDEX(p_height-1,MAX_HEIGHT); int mm; - int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps); + int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps?-1:0); if (size!=p_data.size()) { ERR_EXPLAIN("Expected data size of "+itos(size)+" in Image::create()"); diff --git a/core/image.h b/core/image.h index 620160147..1a257f28a 100644 --- a/core/image.h +++ b/core/image.h @@ -196,7 +196,7 @@ public: /** * Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1) */ - Error generate_mipmaps(bool p_keep_existing=false); + Error generate_mipmaps(); void clear_mipmaps(); diff --git a/core/io/resource_import.cpp b/core/io/resource_import.cpp index d0799cdbe..556dff312 100644 --- a/core/io/resource_import.cpp +++ b/core/io/resource_import.cpp @@ -1,5 +1,6 @@ #include "resource_import.h" #include "variant_parser.h" +#include "os/os.h" Error ResourceFormatImporter::_get_path_and_type(const String& p_path, PathAndType &r_path_and_type) const { @@ -36,7 +37,13 @@ Error ResourceFormatImporter::_get_path_and_type(const String& p_path, PathAndTy } if (assign!=String()) { - if (assign=="path") { + if (assign.begins_with("path.") && r_path_and_type.path==String()) { + String feature = assign.get_slicec('.',1); + if (OS::get_singleton()->check_feature_support(feature)) { + r_path_and_type.path=value; + } + + } else if (assign=="path") { r_path_and_type.path=value; } else if (assign=="type") { r_path_and_type.type=value; @@ -84,7 +91,6 @@ RES ResourceFormatImporter::load(const String &p_path,const String& p_original_p void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extensions) const{ - print_line("getting exts from: "+itos(importers.size())); Set<String> found; for (Set< Ref<ResourceImporter> >::Element *E=importers.front();E;E=E->next()) { @@ -92,7 +98,6 @@ void ResourceFormatImporter::get_recognized_extensions(List<String> *p_extension E->get()->get_recognized_extensions(&local_exts); for (List<String>::Element *F=local_exts.front();F;F=F->next()) { if (!found.has(F->get())) { - print_line("adding ext "+String(F->get())); p_extensions->push_back(F->get()); found.insert(F->get()); } @@ -154,6 +159,20 @@ bool ResourceFormatImporter::handles_type(const String& p_type) const { return true; } + +String ResourceFormatImporter::get_internal_resource_path(const String& p_path) const { + + PathAndType pat; + Error err = _get_path_and_type(p_path,pat); + + if (err!=OK) { + + return String(); + } + + return pat.path; +} + String ResourceFormatImporter::get_resource_type(const String &p_path) const { PathAndType pat; diff --git a/core/io/resource_import.h b/core/io/resource_import.h index 939cecfbd..387b3902f 100644 --- a/core/io/resource_import.h +++ b/core/io/resource_import.h @@ -31,6 +31,7 @@ public: virtual bool can_be_imported(const String& p_path) const; + String get_internal_resource_path(const String& p_path) const; void add_importer(const Ref<ResourceImporter>& p_importer) { importers.insert(p_importer); } Ref<ResourceImporter> get_importer_by_name(const String& p_name); diff --git a/core/os/os.h b/core/os/os.h index 42c7c18b0..e179b82da 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -403,6 +403,8 @@ public: virtual void set_use_vsync(bool p_enable); virtual bool is_vsync_enabled() const; + virtual bool check_feature_support(const String& p_feature)=0; + bool is_hidpi_allowed() const { return _allow_hidpi; } OS(); virtual ~OS(); diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index 1e938b489..3507501f2 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -430,7 +430,7 @@ Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String>& strings, Token token; get_token(p_stream,token,line,r_err_str); if (token.type!=TK_PARENTHESIS_OPEN) { - r_err_str="Expected '(' in old-style engine.cfg construct"; + r_err_str="Expected '(' in old-style godot.cfg construct"; return ERR_PARSE_ERROR; } @@ -442,7 +442,7 @@ Error VariantParser::_parse_enginecfg(Stream *p_stream, Vector<String>& strings, CharType c=p_stream->get_char(); if (p_stream->is_eof()) { - r_err_str="Unexpected EOF while parsing old-style engine.cfg construct"; + r_err_str="Unexpected EOF while parsing old-style godot.cfg construct"; return ERR_PARSE_ERROR; } @@ -1328,7 +1328,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in value=arr; return OK; - } else if (id=="key") { // compatibility with engine.cfg + } else if (id=="key") { // compatibility with godot.cfg Vector<String> params; Error err = _parse_enginecfg(p_stream,params,line,r_err_str); @@ -1364,7 +1364,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in value=ie; return OK; - } else if (id=="mbutton") { // compatibility with engine.cfg + } else if (id=="mbutton") { // compatibility with godot.cfg Vector<String> params; Error err = _parse_enginecfg(p_stream,params,line,r_err_str); @@ -1379,7 +1379,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in value=ie; return OK; - } else if (id=="jbutton") { // compatibility with engine.cfg + } else if (id=="jbutton") { // compatibility with godot.cfg Vector<String> params; Error err = _parse_enginecfg(p_stream,params,line,r_err_str); @@ -1394,7 +1394,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in value=ie; return OK; - } else if (id=="jaxis") { // compatibility with engine.cfg + } else if (id=="jaxis") { // compatibility with godot.cfg Vector<String> params; Error err = _parse_enginecfg(p_stream,params,line,r_err_str); @@ -1412,19 +1412,19 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in value= ie; return OK; - } else if (id=="img") { // compatibility with engine.cfg + } else if (id=="img") { // compatibility with godot.cfg Token token; get_token(p_stream,token,line,r_err_str); if (token.type!=TK_PARENTHESIS_OPEN) { - r_err_str="Expected '(' in old-style engine.cfg construct"; + r_err_str="Expected '(' in old-style godot.cfg construct"; return ERR_PARSE_ERROR; } while(true) { CharType c = p_stream->get_char(); if (p_stream->is_eof()) { - r_err_str="Unexpected EOF in old style engine.cfg img()"; + r_err_str="Unexpected EOF in old style godot.cfg img()"; return ERR_PARSE_ERROR; } if (c==')') |
