diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/gd_script.cpp | 29 | ||||
-rw-r--r-- | modules/gdscript/gd_tokenizer.cpp | 1 | ||||
-rw-r--r-- | modules/gdscript/register_types.cpp | 78 | ||||
-rw-r--r-- | modules/gridmap/grid_map.cpp | 140 | ||||
-rw-r--r-- | modules/gridmap/grid_map.h | 13 |
5 files changed, 244 insertions, 17 deletions
diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index d183782864..2885b754be 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -31,6 +31,7 @@ #include "global_constants.h" #include "gd_compiler.h" #include "os/file_access.h" +#include "io/file_access_encrypted.h" /* TODO: @@ -1591,7 +1592,28 @@ void GDScript::_bind_methods() { Error GDScript::load_byte_code(const String& p_path) { - Vector<uint8_t> bytecode = FileAccess::get_file_as_array(p_path); + Vector<uint8_t> bytecode; + + if (p_path.ends_with("gde")) { + + FileAccess *fa = FileAccess::open(p_path,FileAccess::READ); + ERR_FAIL_COND_V(!fa,ERR_CANT_OPEN); + FileAccessEncrypted *fae = memnew( FileAccessEncrypted ); + ERR_FAIL_COND_V(!fae,ERR_CANT_OPEN); + Vector<uint8_t> key; + key.resize(32); + for(int i=0;i<key.size();i++) { + key[i]=script_encryption_key[i]; + } + Error err = fae->open_and_parse(fa,key,FileAccessEncrypted::MODE_READ); + ERR_FAIL_COND_V(err,err); + bytecode.resize(fae->get_len()); + fae->get_buffer(bytecode.ptr(),bytecode.size()); + memdelete(fae); + } else { + + bytecode = FileAccess::get_file_as_array(p_path); + } ERR_FAIL_COND_V(bytecode.size()==0,ERR_PARSE_ERROR); path=p_path; @@ -2225,7 +2247,7 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path,const String& p_orig Ref<GDScript> scriptres(script); - if (p_path.ends_with(".gdc")) { + if (p_path.ends_with(".gde") || p_path.ends_with(".gdc")) { script->set_script_path(p_original_path); // script needs this. script->set_path(p_original_path); @@ -2258,6 +2280,7 @@ void ResourceFormatLoaderGDScript::get_recognized_extensions(List<String> *p_ext p_extensions->push_back("gd"); p_extensions->push_back("gdc"); + p_extensions->push_back("gde"); } bool ResourceFormatLoaderGDScript::handles_type(const String& p_type) const { @@ -2268,7 +2291,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(); - if (el=="gd" || el=="gdc") + if (el=="gd" || el=="gdc" || el=="gde") return "GDScript"; return ""; } diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index aeee1f6667..a92e2f22ea 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -757,6 +757,7 @@ void GDTokenizerText::_advance() { {Variant::_RID,"RID"}, {Variant::OBJECT,"Object"}, {Variant::INPUT_EVENT,"InputEvent"}, + {Variant::NODE_PATH,"NodePath"}, {Variant::DICTIONARY,"dict"}, {Variant::DICTIONARY,"Dictionary"}, {Variant::ARRAY,"Array"}, diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 6bcd12857b..abb3d5a946 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -14,6 +14,8 @@ #include "gd_script.h" #include "io/resource_loader.h" #include "os/file_access.h" +#include "io/file_access_encrypted.h" + GDScriptLanguage *script_language_gd=NULL; @@ -25,6 +27,7 @@ ResourceFormatSaverGDScript *resource_saver_gd=NULL; #include "tools/editor/editor_import_export.h" #include "gd_tokenizer.h" #include "tools/editor/editor_node.h" +#include "tools/editor/editor_settings.h" class EditorExportGDScript : public EditorExportPlugin { @@ -34,20 +37,69 @@ public: virtual Vector<uint8_t> custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform) { //compile gdscript to bytecode - if (p_path.ends_with(".gd")) { - Vector<uint8_t> file = FileAccess::get_file_as_array(p_path); - if (file.empty()) - return file; - String txt; - txt.parse_utf8((const char*)file.ptr(),file.size()); - file = GDTokenizerBuffer::parse_code_string(txt); - if (!file.empty()) { - print_line("PREV: "+p_path); - p_path=p_path.basename()+".gdc"; - print_line("NOW: "+p_path); - return file; - } + if (EditorImportExport::get_singleton()->script_get_action()!=EditorImportExport::SCRIPT_ACTION_NONE) { + + if (p_path.ends_with(".gd")) { + Vector<uint8_t> file = FileAccess::get_file_as_array(p_path); + if (file.empty()) + return file; + String txt; + txt.parse_utf8((const char*)file.ptr(),file.size()); + file = GDTokenizerBuffer::parse_code_string(txt); + + if (!file.empty()) { + + if (EditorImportExport::get_singleton()->script_get_action()==EditorImportExport::SCRIPT_ACTION_ENCRYPT) { + + String tmp_path=EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/script.gde"); + FileAccess *fa = FileAccess::open(tmp_path,FileAccess::WRITE); + String skey=EditorImportExport::get_singleton()->script_get_encryption_key().to_lower(); + Vector<uint8_t> key; + key.resize(32); + for(int i=0;i<32;i++) { + int v=0; + if (i*2<skey.length()) { + CharType ct = skey[i*2]; + if (ct>='0' && ct<='9') + ct=ct-'0'; + else if (ct>='a' && ct<='f') + ct=10+ct-'a'; + v|=ct<<4; + } + + if (i*2+1<skey.length()) { + CharType ct = skey[i*2+1]; + if (ct>='0' && ct<='9') + ct=ct-'0'; + else if (ct>='a' && ct<='f') + ct=10+ct-'a'; + v|=ct; + } + key[i]=v; + } + FileAccessEncrypted *fae=memnew(FileAccessEncrypted); + Error err = fae->open_and_parse(fa,key,FileAccessEncrypted::MODE_WRITE_AES256); + if (err==OK) { + + fae->store_buffer(file.ptr(),file.size()); + p_path=p_path.basename()+".gde"; + } + + memdelete(fae); + + file=FileAccess::get_file_as_array(tmp_path); + return file; + + + } else { + + p_path=p_path.basename()+".gdc"; + return file; + } + } + + } } return Vector<uint8_t>(); diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 7ccd85702d..d258e26a0e 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -31,7 +31,9 @@ #include "scene/resources/surface_tool.h" #include "message_queue.h" #include "scene/3d/light.h" +#include "scene/3d/baked_light_instance.h" #include "io/marshalls.h" +#include "scene/scene_string_names.h" bool GridMap::_set(const StringName& p_name, const Variant& p_value) { @@ -53,6 +55,8 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { set_center_z(p_value); } else if (name=="cell/scale") { set_cell_scale(p_value); + } else if (name=="lighting/bake") { + set_use_baked_light(p_value); } else if (name=="theme/bake") { set_bake(p_value); /* } else if (name=="cells") { @@ -120,6 +124,7 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { g.baked=b; g.bake_instance=VS::get_singleton()->instance_create();; VS::get_singleton()->instance_set_base(g.bake_instance,g.baked->get_rid()); + VS::get_singleton()->instance_geometry_set_baked_light(g.bake_instance,baked_light_instance?baked_light_instance->get_baked_light_instance():RID()); } } @@ -169,6 +174,8 @@ bool GridMap::_get(const StringName& p_name,Variant &r_ret) const { r_ret= get_center_z(); } else if (name=="cell/scale") { r_ret= cell_scale; + } else if (name=="lighting/bake") { + r_ret=is_using_baked_light(); } else if (name=="theme/bake") { r_ret= bake; } else if (name=="data") { @@ -231,6 +238,7 @@ void GridMap::_get_property_list( List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::OBJECT, "theme/theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary")); p_list->push_back( PropertyInfo( Variant::BOOL, "theme/bake")); + p_list->push_back( PropertyInfo( Variant::BOOL, "lighting/bake")); p_list->push_back( PropertyInfo( Variant::REAL, "cell/size",PROPERTY_HINT_RANGE,"0.01,16384,0.01") ); p_list->push_back( PropertyInfo( Variant::INT, "cell/octant_size",PROPERTY_HINT_RANGE,"1,1024,1") ); p_list->push_back( PropertyInfo( Variant::BOOL, "cell/center_x") ); @@ -428,6 +436,8 @@ void GridMap::set_cell_item(int p_x,int p_y,int p_z, int p_item,int p_rot){ ii.multimesh->set_mesh(ii.mesh); ii.multimesh_instance = VS::get_singleton()->instance_create(); VS::get_singleton()->instance_set_base(ii.multimesh_instance,ii.multimesh->get_rid()); + VS::get_singleton()->instance_geometry_set_baked_light(ii.multimesh_instance,baked_light_instance?baked_light_instance->get_baked_light_instance():RID()); + if (!baked_lock) { //unbake just in case @@ -863,6 +873,12 @@ void GridMap::_notification(int p_what) { awaiting_update=false; last_transform=get_global_transform(); + + if (use_baked_light) { + + _find_baked_light(); + } + } break; case NOTIFICATION_TRANSFORM_CHANGED: { @@ -883,6 +899,17 @@ void GridMap::_notification(int p_what) { _octant_exit_world(E->key()); } + if (use_baked_light) { + + if (baked_light_instance) { + baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed); + baked_light_instance=NULL; + } + _baked_light_changed(); + + } + + //_queue_dirty_map(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS); //_update_dirty_map_callback(); //_update_area_instances(); @@ -1028,6 +1055,14 @@ void GridMap::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_unused_area_id","area"),&GridMap::get_unused_area_id); ObjectTypeDB::bind_method(_MD("bake_geometry"),&GridMap::bake_geometry); + ObjectTypeDB::bind_method(_MD("_baked_light_changed"),&GridMap::_baked_light_changed); + ObjectTypeDB::bind_method(_MD("set_use_baked_light","use"),&GridMap::set_use_baked_light); + ObjectTypeDB::bind_method(_MD("is_using_baked_light","use"),&GridMap::is_using_baked_light); + + ObjectTypeDB::bind_method(_MD("_get_baked_light_meshes"),&GridMap::_get_baked_light_meshes); + + + ObjectTypeDB::set_method_flags("GridMap","bake_geometry",METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); ObjectTypeDB::bind_method(_MD("clear"),&GridMap::clear); @@ -1496,6 +1531,108 @@ 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()); + 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()) { + + VS::get_singleton()->instance_geometry_set_baked_light(F->get().multimesh_instance,baked_light_instance?baked_light_instance->get_baked_light_instance():RID()); + } + + } + +} + +void GridMap::_find_baked_light() { + + Node *n=get_parent(); + while(n) { + + BakedLightInstance *bl=n->cast_to<BakedLightInstance>(); + if (bl) { + + baked_light_instance=bl; + baked_light_instance->connect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed); + _baked_light_changed(); + + return; + } + + n=n->get_parent(); + } + + _baked_light_changed(); +} + + +Array GridMap::_get_baked_light_meshes() { + + if (theme.is_null()) + return Array(); + + Vector3 ofs(cell_size*0.5*int(center_x),cell_size*0.5*int(center_y),cell_size*0.5*int(center_z)); + Array meshes; + + for (Map<IndexKey,Cell>::Element *E=cell_map.front();E;E=E->next()) { + + + int id = E->get().item; + if (!theme->has_item(id)) + continue; + Ref<Mesh> mesh=theme->get_item_mesh(id); + if (mesh.is_null()) + continue; + + IndexKey ik=E->key(); + + Vector3 cellpos = Vector3(ik.x,ik.y,ik.z ); + + Transform xform; + + xform.basis.set_orthogonal_index(E->get().rot); + + + xform.set_origin( cellpos*cell_size+ofs); + xform.basis.scale(Vector3(cell_scale,cell_scale,cell_scale)); + + meshes.push_back(xform); + meshes.push_back(mesh); + + } + + return meshes; +} + +void GridMap::set_use_baked_light(bool p_use) { + + if (use_baked_light==p_use) + return; + + use_baked_light=p_use; + + if (is_inside_world()) { + if (!p_use) { + if (baked_light_instance) { + baked_light_instance->disconnect(SceneStringNames::get_singleton()->baked_light_changed,this,SceneStringNames::get_singleton()->_baked_light_changed); + baked_light_instance=NULL; + } + _baked_light_changed(); + } else { + _find_baked_light(); + } + } + +} + +bool GridMap::is_using_baked_light() const{ + + return use_baked_light; +} GridMap::GridMap() { @@ -1516,7 +1653,8 @@ GridMap::GridMap() { bake=false; cell_scale=1.0; - + baked_light_instance=NULL; + use_baked_light=false; } diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 7a13ace143..df805d99fa 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -38,6 +38,8 @@ //should scale better with hardware that supports instancing +class BakedLightInstance; + class GridMap : public Spatial { @@ -202,6 +204,14 @@ class GridMap : public Spatial { void _clear_internal(bool p_keep_areas=false); + BakedLightInstance *baked_light_instance; + bool use_baked_light; + void _find_baked_light(); + void _baked_light_changed(); + + + Array _get_baked_light_meshes(); + protected: bool _set(const StringName& p_name, const Variant& p_value); @@ -211,6 +221,7 @@ protected: void _notification(int p_what); static void _bind_methods(); + public: enum { @@ -262,6 +273,8 @@ public: void bake_geometry(); + void set_use_baked_light(bool p_use); + bool is_using_baked_light() const; void clear(); GridMap(); |