diff options
386 files changed, 7660 insertions, 7660 deletions
diff --git a/bin/tests/test_containers.cpp b/bin/tests/test_containers.cpp index f8cc8ccd41..4bc297d0ba 100644 --- a/bin/tests/test_containers.cpp +++ b/bin/tests/test_containers.cpp @@ -44,9 +44,9 @@ MainLoop * test() { /* HashMap<int,int> int_map; - + for (int i=0;i<68000;i++) { - + int num=(int)Math::random(0,1024); int_map[i]=num; } @@ -70,21 +70,21 @@ MainLoop * test() { }; }; - -#if 0 + +#if 0 Set<int> set; - + print_line("Begin Insert"); for (int i=0;i<1100;i++) { - + int num=i;//(int)Math::random(0,1024); - // print_line("inserting "+itos(num)); + // print_line("inserting "+itos(num)); set.insert( num ); } - + /* for (int i=0;i<400;i++) { - + int num=(int)Math::random(0,1024); set.erase(num); } @@ -92,11 +92,11 @@ MainLoop * test() { //set.print_tree(); for(Set<int>::Element *I=set.front();I;I=I->next()) { - + print_line("inserted "+itos(I->get())+" prev is "+itos(I->prev()?I->prev()->get():-100)); } - + print_line("depth is "+itos(set.calculate_depth())); print_line("Insert Success"); #endif diff --git a/bin/tests/test_detailer.cpp b/bin/tests/test_detailer.cpp index 616356077e..5dba7c3f72 100644 --- a/bin/tests/test_detailer.cpp +++ b/bin/tests/test_detailer.cpp @@ -44,7 +44,7 @@ class TestMainLoop : public MainLoop { RID light; RID mesh; RID scenario; - + #define MULTIMESH_COUNT 1500 float ofs_x,ofs_y; @@ -122,9 +122,9 @@ public: } virtual void input_event(const InputEvent& p_event) { - + if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&4) { - + ofs_x+=p_event.mouse_motion.relative_y/200.0; ofs_y+=p_event.mouse_motion.relative_x/200.0; } @@ -142,16 +142,16 @@ public: } - + virtual void request_quit() { - + quit=true; } virtual void init() { - + VisualServer *vs=VisualServer::get_singleton(); @@ -163,13 +163,13 @@ public: _update_qh(); instance = vs->instance_create2(mesh,scenario); - + camera = vs->camera_create(); - + vs->camera_set_perspective( camera, 60.0,0.1, 100.0 ); viewport = vs->viewport_create(); - vs->viewport_attach_camera( viewport, camera ); + vs->viewport_attach_camera( viewport, camera ); vs->viewport_attach_to_screen(viewport); vs->viewport_set_scenario( viewport, scenario ); @@ -179,7 +179,7 @@ public: //vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.3,0.3,0.3) ); light = vs->instance_create2( lightaux,scenario ); vs->instance_set_transform(light,Transform(Matrix3(Vector3(0.1,0.4,0.7).normalized(),0.9))); - + ofs_x=0; ofs_y=0; quit=false; @@ -190,20 +190,20 @@ public: } virtual bool iteration(float p_time) { - + VisualServer *vs=VisualServer::get_singleton(); - + Transform tr_camera; tr_camera.rotate( Vector3(0,1,0), ofs_y ); tr_camera.rotate( Vector3(1,0,0),ofs_x ); tr_camera.translate(0,0,10); - + vs->camera_set_transform( camera, tr_camera ); - + return quit; } virtual void finish() { - + } }; diff --git a/bin/tests/test_gdscript.cpp b/bin/tests/test_gdscript.cpp index 683191fba2..4578f5aa02 100644 --- a/bin/tests/test_gdscript.cpp +++ b/bin/tests/test_gdscript.cpp @@ -81,7 +81,7 @@ static String _parser_expr(const GDParser::Node *p_expr) { case GDParser::Node::TYPE_IDENTIFIER: { - const GDParser::IdentifierNode *id_node = static_cast<const GDParser::IdentifierNode *>(p_expr); + const GDParser::IdentifierNode *id_node = static_cast<const GDParser::IdentifierNode *>(p_expr); txt=id_node->name; } break; case GDParser::Node::TYPE_CONSTANT: { diff --git a/bin/tests/test_gui.cpp b/bin/tests/test_gui.cpp index cba488a3da..f4341fd7b3 100644 --- a/bin/tests/test_gui.cpp +++ b/bin/tests/test_gui.cpp @@ -62,16 +62,16 @@ class TestMainLoop : public SceneTree { Control *control; - + public: virtual void request_quit() { - + quit(); - + } virtual void init() { - + SceneTree::init(); @@ -112,7 +112,7 @@ public: Ref<Theme> t = memnew( Theme ); frame->set_theme(t); - + get_root()->add_child( frame ); Label *label = memnew( Label ); @@ -198,21 +198,21 @@ public: //root->add_child( control ); - + LineEdit *line_edit = memnew( LineEdit ); - + line_edit->set_pos( Point2( 30,190 ) ); line_edit->set_size( Point2( 180,1 ) ); - + frame->add_child(line_edit); - + HScrollBar *hscroll = memnew( HScrollBar ); - + hscroll->set_pos( Point2( 30,290 ) ); hscroll->set_size( Point2( 180,1 ) ); hscroll->set_max(10); hscroll->set_page(4); - + frame->add_child(hscroll); @@ -234,36 +234,36 @@ public: hscroll->share(progress); MenuButton *menu_button = memnew( MenuButton ); - + menu_button->set_text("I'm a menu!"); menu_button->set_pos( Point2( 30,380 ) ); menu_button->set_size( Point2( 1,1 ) ); - - frame->add_child(menu_button); - + + frame->add_child(menu_button); + PopupMenu *popup = menu_button->get_popup(); - + popup->add_item("Hello, testing"); popup->add_item("My Dearest"); popup->add_separator(); popup->add_item("Popup"); popup->add_check_item("Check Popup"); - popup->set_item_checked(4,true); - + popup->set_item_checked(4,true); + OptionButton *options = memnew( OptionButton ); - + options->add_item("Hello, testing"); options->add_item("My Dearest"); - + options->set_pos( Point2( 230,180 ) ); options->set_size( Point2( 1,1 ) ); - - frame->add_child(options); + + frame->add_child(options); /* Tree * tree = memnew( Tree ); tree->set_columns(2); - + tree->set_pos( Point2( 230,210 ) ); tree->set_size( Point2( 150,250 ) ); @@ -286,7 +286,7 @@ public: item->set_editable(0,true); item->set_text(0,"Have,Many,Several,Options!"); item->set_range(0,2); - + frame->add_child(tree); */ @@ -365,11 +365,11 @@ public: tabc->add_child(ctl); frame->add_child(tabc); - + tabc->set_pos( Point2( 400,210 ) ); tabc->set_size( Point2( 180,250 ) ); - + Ref<ImageTexture> text = memnew( ImageTexture ); text->load("test_data/concave.png"); @@ -387,13 +387,13 @@ public: } - + }; MainLoop* test() { - + return memnew( TestMainLoop ); } diff --git a/bin/tests/test_io.cpp b/bin/tests/test_io.cpp index a1eb2be19b..a8e8d7d0fd 100644 --- a/bin/tests/test_io.cpp +++ b/bin/tests/test_io.cpp @@ -47,37 +47,37 @@ namespace TestIO { class TestMainLoop : public MainLoop { - - + + bool quit; - + public: virtual void input_event(const InputEvent& p_event) { - - + + } virtual bool idle(float p_time) { return false; } virtual void request_quit() { - + quit=true; - + } virtual void init() { quit=true; } virtual bool iteration(float p_time) { - + return quit; } virtual void finish() { - + } - - + + }; diff --git a/bin/tests/test_main.cpp b/bin/tests/test_main.cpp index 8143a95d66..363aede96e 100644 --- a/bin/tests/test_main.cpp +++ b/bin/tests/test_main.cpp @@ -64,7 +64,7 @@ const char ** tests_get_names() { "physics", NULL }; - + return test_names; } @@ -72,22 +72,22 @@ MainLoop* test_main(String p_test,const List<String>& p_args) { if (p_test=="string") { - + return TestString::test(); } - + if (p_test=="containers") { - + return TestContainers::test(); } - + if (p_test=="math") { - + return TestMath::test(); } - + if (p_test=="physics") { - + return TestPhysics::test(); } @@ -97,15 +97,15 @@ MainLoop* test_main(String p_test,const List<String>& p_args) { } if (p_test=="misc") { - + return TestMisc::test(); } if (p_test=="render") { - + return TestRender::test(); } - + #ifndef _3D_DISABLED if (p_test=="gui") { @@ -119,17 +119,17 @@ MainLoop* test_main(String p_test,const List<String>& p_args) { } if (p_test=="io") { - + return TestIO::test(); } - + if (p_test=="particles") { return TestParticles::test(); } - + if (p_test=="multimesh") { - + return TestMultiMesh::test(); } @@ -171,7 +171,7 @@ MainLoop* test_main(String p_test,const List<String>& p_args) { #ifdef PYTHON_ENABLED if (p_test=="python") { - + return TestPython::test(); } #endif diff --git a/bin/tests/test_math.cpp b/bin/tests/test_math.cpp index 05acd5c1ec..22d14ada34 100644 --- a/bin/tests/test_math.cpp +++ b/bin/tests/test_math.cpp @@ -70,7 +70,7 @@ fix: 0, 0, 49.949951, 50 v0: 0, 0, 100, 100 v1: 0, 0, 100, 100 fix: 0, 0, 100, 100 -*/ +*/ } diff --git a/bin/tests/test_particles.cpp b/bin/tests/test_particles.cpp index bafd78eda0..23a4b9e635 100644 --- a/bin/tests/test_particles.cpp +++ b/bin/tests/test_particles.cpp @@ -43,38 +43,38 @@ class TestMainLoop : public MainLoop { RID viewport; RID light; RID scenario; - + struct InstanceInfo { - + RID instance; Transform base; Vector3 rot_axis; }; - + List<InstanceInfo> instances; - + float ofs; bool quit; public: virtual void input_event(const InputEvent& p_event) { - - + + } virtual void request_quit() { - + quit=true; } virtual void init() { - + VisualServer *vs=VisualServer::get_singleton(); particles = vs->particles_create(); vs->particles_set_amount(particles,1000); - + instance = vs->instance_create2(particles,scenario); - - + + camera = vs->camera_create(); - + // vs->camera_set_perspective( camera, 60.0,0.1, 100.0 ); viewport = vs->viewport_create(); vs->viewport_attach_camera( viewport, camera ); @@ -89,7 +89,7 @@ public: RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL ); // vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) ); light = vs->instance_create2( lightaux, scenario ); - + ofs=0; quit=false; } @@ -99,14 +99,14 @@ public: virtual bool iteration(float p_time) { - + // VisualServer *vs=VisualServer::get_singleton(); - + ofs+=p_time; return quit; } virtual void finish() { - + } }; diff --git a/bin/tests/test_physics.cpp b/bin/tests/test_physics.cpp index ce96f37f3f..ecd90a13d4 100644 --- a/bin/tests/test_physics.cpp +++ b/bin/tests/test_physics.cpp @@ -47,7 +47,7 @@ class TestPhysicsMainLoop : public MainLoop { }; RID test_cube; - + RID plane; RID sphere; RID light; @@ -74,13 +74,13 @@ class TestPhysicsMainLoop : public MainLoop { //t.basis.scale( Vector3(1.0,0.5,0.2) ); vs->instance_set_transform(p_visual_instance,t); } - + bool quit; - + protected: static void _bind_methods() { - + ObjectTypeDB::bind_method("body_changed_transform",&TestPhysicsMainLoop::body_changed_transform); } @@ -90,11 +90,11 @@ protected: PhysicsServer * ps = PhysicsServer::get_singleton(); RID mesh_instance = vs->instance_create2(type_mesh_map[p_shape],scenario); - RID body = ps->body_create(p_body,!p_active_default); + RID body = ps->body_create(p_body,!p_active_default); ps->body_set_space(body,space); ps->body_set_param(body,PhysicsServer::BODY_PARAM_BOUNCE,0.0); //todo set space - ps->body_add_shape(body,type_shape_map[p_shape]); + ps->body_add_shape(body,type_shape_map[p_shape]); ps->body_set_force_integration_callback(body,this,"body_changed_transform",mesh_instance); ps->body_set_state( body, PhysicsServer::BODY_STATE_TRANSFORM,p_location); @@ -289,7 +289,7 @@ protected: public: virtual void input_event(const InputEvent& p_event) { - + if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&4) { ofs_y-=p_event.mouse_motion.relative_y/200.0; @@ -329,7 +329,7 @@ public: } virtual void request_quit() { - + quit=true; } virtual void init() { @@ -388,53 +388,53 @@ public: /* Make Trimesh */ quit=false; return; - + #if 0 #define GRID_SIZE 5 - + float grid[GRID_SIZE][GRID_SIZE]; - + for (int i=0;i<GRID_SIZE;i++) { - + for (int j=0;j<GRID_SIZE;j++) { - + grid[j][i]=Math::random(0.0, 1.0 ); } } - + Vector<Vector3> faces; - + for (int i=1;i<GRID_SIZE;i++) { - + for (int j=1;j<GRID_SIZE;j++) { - - + + #define MAKE_VERTEX(m_x,m_z)\ faces.push_back( Vector3( m_x-GRID_SIZE/2.0, grid[m_x][m_z], m_z-GRID_SIZE/2.0 )*3.0 ) - + MAKE_VERTEX(i,j-1); MAKE_VERTEX(i,j); MAKE_VERTEX(i-1,j); - + MAKE_VERTEX(i-1,j-1); MAKE_VERTEX(i,j-1); MAKE_VERTEX(i-1,j); - + } } /* - faces.clear(); + faces.clear(); faces.push_back( Vector3(0,0,-5) ); faces.push_back( Vector3(1,0,-1) ); faces.push_back( Vector3(-1,-0,-1) ); */ - + RID trimesh_shape = ps->shape_create(); ps->shape_set_data(trimesh_shape, PhysicsServer::SHAPE_CONCAVE_POLYGON,faces); faces=ps->shape_get_shape(trimesh_shape, 0); Vector<Vector3> normals; // for drawing for (int i=0;i<faces.size()/3;i++) { - + Plane p( faces[i*3+0],faces[i*3+1], faces[i*3+2] ); normals.push_back(p.normal); normals.push_back(p.normal); @@ -448,11 +448,11 @@ public: RID trimesh_mat = vs->fixed_material_create(); vs->material_generate( trimesh_mat, Color(1.0,0.5,0.3) ); vs->mesh_surface_set_material( trimesh_mesh, 0, trimesh_mat ); - + RID triins = vs->instance_create2(trimesh_mesh); - - - + + + RID tribody = ps->body_create( PhysicsServer::BODY_MODE_STATIC, trimesh_shape); Transform tritrans = Transform( Matrix3(), Vector3(0,0,-2) ); ps->body_set_state( tribody, PhysicsServer::BODY_STATE_TRANSFORM, tritrans ); @@ -483,7 +483,7 @@ public: return quit; } virtual void finish() { - + } void test_joint() { @@ -599,7 +599,7 @@ public: PhysicsServer::ShapeType type=shape_idx[i%4]; //type=PhysicsServer::SHAPE_CONVEX_POLYGON; - Transform t; + Transform t; t.origin=Vector3(0.0*i,3.5+1.1*i,0.7+0.0*i); //t.origin=Vector3(-0.7+0.0*i,0.5+4.1*i,0); diff --git a/bin/tests/test_python.cpp b/bin/tests/test_python.cpp index 575caf2513..26fb4bdafb 100644 --- a/bin/tests/test_python.cpp +++ b/bin/tests/test_python.cpp @@ -47,7 +47,7 @@ void test() { PyRun_SimpleString("b=Moch();\n"); PyRun_SimpleString("b.mooch();\n"); PyRun_SimpleString("b.meis();\n"); - + } diff --git a/bin/tests/test_render.cpp b/bin/tests/test_render.cpp index 568699e5e6..9c3a287afa 100644 --- a/bin/tests/test_render.cpp +++ b/bin/tests/test_render.cpp @@ -49,16 +49,16 @@ class TestMainLoop : public MainLoop { RID viewport; RID light; RID scenario; - + struct InstanceInfo { - + RID instance; Transform base; Vector3 rot_axis; }; - + List<InstanceInfo> instances; - + float ofs; bool quit; protected: @@ -66,13 +66,13 @@ protected: public: virtual void input_event(const InputEvent& p_event) { - + if (p_event.type==InputEvent::KEY && p_event.key.pressed) quit=true; } virtual void init() { - + print_line("INITIALIZING TEST RENDER"); VisualServer *vs=VisualServer::get_singleton(); @@ -150,26 +150,26 @@ public: }; for (int i=0;i<object_count;i++) { - + InstanceInfo ii; - - + + ii.instance = vs->instance_create2( test_cube, scenario ); - - + + ii.base.translate( Math::random(-20,20), Math::random(-20,20),Math::random(-20,18) ); ii.base.rotate( Vector3(0,1,0), Math::randf() * Math_PI ); ii.base.rotate( Vector3(1,0,0), Math::randf() * Math_PI ); - vs->instance_set_transform( ii.instance, ii.base ); - + vs->instance_set_transform( ii.instance, ii.base ); + ii.rot_axis = Vector3( Math::random(-1,1), Math::random(-1,1), Math::random(-1,1) ).normalized(); - + instances.push_back(ii); - + } - + camera = vs->camera_create(); - + // vs->camera_set_perspective( camera, 60.0,0.1, 100.0 ); viewport = vs->viewport_create(); @@ -226,9 +226,9 @@ public: ofs+=p_time*0.05; //return quit; - + for(List<InstanceInfo>::Element *E=instances.front();E;E=E->next()) { - + Transform pre( Matrix3(E->get().rot_axis, ofs), Vector3() ); vs->instance_set_transform( E->get().instance, pre * E->get().base ); /* @@ -238,7 +238,7 @@ public: instances.erase(E ); }*/ } - + return quit; } diff --git a/bin/tests/test_shader_lang.cpp b/bin/tests/test_shader_lang.cpp index e55ad3074f..9c0075c47d 100644 --- a/bin/tests/test_shader_lang.cpp +++ b/bin/tests/test_shader_lang.cpp @@ -290,7 +290,7 @@ MainLoop* test() { FileAccess *fa = FileAccess::open(test,FileAccess::READ); - if (!fa) { + if (!fa) { ERR_FAIL_V(NULL); } diff --git a/bin/tests/test_string.cpp b/bin/tests/test_string.cpp index 27707b1a00..be37ce118f 100644 --- a/bin/tests/test_string.cpp +++ b/bin/tests/test_string.cpp @@ -38,145 +38,145 @@ namespace TestString { bool test_1() { - + OS::get_singleton()->print("\n\nTest 1: Assign from cstr\n"); - + String s = "Hello"; - + OS::get_singleton()->print("\tExpected: Hello\n"); OS::get_singleton()->print("\tResulted: %ls\n",s.c_str()); - + return (wcscmp(s.c_str(),L"Hello")==0); - + } bool test_2() { - + OS::get_singleton()->print("\n\nTest 2: Assign from string (operator=)\n"); - + String s = "Dolly"; String t = s; - + OS::get_singleton()->print("\tExpected: Dolly\n"); OS::get_singleton()->print("\tResulted: %ls\n",t.c_str()); - + return (wcscmp(t.c_str(),L"Dolly")==0); - + } bool test_3() { - + OS::get_singleton()->print("\n\nTest 3: Assign from c-string (copycon)\n"); - + String s("Sheep"); String t(s); - + OS::get_singleton()->print("\tExpected: Sheep\n"); OS::get_singleton()->print("\tResulted: %ls\n",t.c_str()); - + return (wcscmp(t.c_str(),L"Sheep")==0); - + } bool test_4() { - + OS::get_singleton()->print("\n\nTest 4: Assign from c-widechar (operator=)\n"); - + String s(L"Give me"); - + OS::get_singleton()->print("\tExpected: Give me\n"); OS::get_singleton()->print("\tResulted: %ls\n",s.c_str()); - + return (wcscmp(s.c_str(),L"Give me")==0); - + } bool test_5() { - + OS::get_singleton()->print("\n\nTest 5: Assign from c-widechar (copycon)\n"); - + String s(L"Wool"); - + OS::get_singleton()->print("\tExpected: Wool\n"); OS::get_singleton()->print("\tResulted: %ls\n",s.c_str()); - + return (wcscmp(s.c_str(),L"Wool")==0); - + } bool test_6() { - + OS::get_singleton()->print("\n\nTest 6: comparisons (equal)\n"); - - + + String s="Test Compare"; - + OS::get_singleton()->print("\tComparing to \"Test Compare\"\n"); - + if (! ( s=="Test Compare" ) ) return false; - + if (! ( s==L"Test Compare" ) ) return false; - + if (! ( s==String("Test Compare") ) ) return false; - + return true; - + } bool test_7() { - + OS::get_singleton()->print("\n\nTest 7: comparisons (unequal)\n"); - - + + String s="Test Compare"; - + OS::get_singleton()->print("\tComparing to \"Test Compare\"\n"); - + if (! ( s!="Peanut" ) ) return false; - + if (! ( s!=L"Coconut" ) ) return false; - + if (! ( s!=String("Butter") ) ) return false; - + return true; - + } bool test_8() { - + OS::get_singleton()->print("\n\nTest 8: comparisons (operator<)\n"); - - + + String s="Bees"; - + OS::get_singleton()->print("\tComparing to \"Bees\"\n"); - + if ( ! (s < "Elephant") ) return false; - + if ( s < L"Amber" ) return false; - + if ( s < String("Beatrix") ) return false; - + return true; - + } bool test_9() { - + OS::get_singleton()->print("\n\nTest 9: Concatenation\n"); - - + + String s; - + s+="Have"; s+=' '; s+='a'; @@ -184,279 +184,279 @@ bool test_9() { s = s + L"Nice"; s = s + " "; s = s + String("Day"); - + OS::get_singleton()->print("\tComparing to \"Have a Nice Day\"\n"); - + return (s == "Have a Nice Day"); - + } bool test_10() { - + OS::get_singleton()->print("\n\nTest 10: Misc funcs (size/length/empty/etc)\n"); - + if (! String("").empty()) return false; - + if (String("Mellon").size() != 7) return false; if (String("Oranges").length() != 7) return false; - + return true; - + } bool test_11() { - + OS::get_singleton()->print("\n\nTest 11: Operator[]\n"); - + String a="Kugar Sane"; - + a[0]='S'; a[6]='C'; - + if (a != "Sugar Cane") return false; - + if (a[1]!='u') return false; - + return true; - + } bool test_12() { - + OS::get_singleton()->print("\n\nTest 12: case functions\n"); - - + + String a="MoMoNgA"; - + if (a.to_upper() != "MOMONGA") return false; - + if (a.nocasecmp_to("momonga")!=0) return false; - + return true; - + } bool test_13() { - + OS::get_singleton()->print("\n\nTest 13: UTF8\n"); - + /* how can i embed UTF in here? */ - + static const CharType ustr[] = { 0x304A , 0x360F, 0x3088, 0x3046, 0 }; // static const wchar_t ustr[] = { 'P', 0xCE, 'p',0xD3, 0 }; String s=ustr; - + OS::get_singleton()->print("\tUnicode: %ls\n",ustr); s.parse_utf8( s.utf8().get_data() ); OS::get_singleton()->print("\tConvert/Parse UTF8: %ls\n",s.c_str()); - + return (s==ustr); - + } bool test_14() { - + OS::get_singleton()->print("\n\nTest 14: ASCII\n"); - + String s = L"Primero Leche"; OS::get_singleton()->print("\tAscii: %s\n",s.ascii().get_data()); - + String t=s.ascii().get_data(); return (s==t); - + } bool test_15() { - + OS::get_singleton()->print("\n\nTest 15: substr\n"); - + String s="Killer Baby"; OS::get_singleton()->print("\tsubstr(3,4) of \"%ls\" is \"%ls\"\n",s.c_str(),s.substr(3,4).c_str()); - + return (s.substr(3,4)=="ler "); - + } bool test_16() { - + OS::get_singleton()->print("\n\nTest 16: find\n"); - + String s="Pretty Woman"; OS::get_singleton()->print("\tString: %ls\n",s.c_str()); OS::get_singleton()->print("\t\"tty\" is at %i pos.\n",s.find("tty")); OS::get_singleton()->print("\t\"Revenge of the Monster Truck\" is at %i pos.\n",s.find("Revenge of the Monster Truck")); - + if (s.find("tty")!=3) return false; - + if (s.find("Revenge of the Monster Truck")!=-1) return false; - + return true; - + } bool test_17() { - + OS::get_singleton()->print("\n\nTest 17: find no case\n"); - + String s="Pretty Whale"; OS::get_singleton()->print("\tString: %ls\n",s.c_str()); OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n",s.findn("WHA")); OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n",s.findn("Revenge of the Monster Truck")); - + if (s.findn("WHA")!=7) return false; - + if (s.findn("Revenge of the Monster SawFish")!=-1) return false; - + return true; - + } bool test_18() { - + OS::get_singleton()->print("\n\nTest 18: find no case\n"); - + String s="Pretty Whale"; OS::get_singleton()->print("\tString: %ls\n",s.c_str()); OS::get_singleton()->print("\t\"WHA\" is at %i pos.\n",s.findn("WHA")); OS::get_singleton()->print("\t\"Revenge of the Monster SawFish\" is at %i pos.\n",s.findn("Revenge of the Monster Truck")); - + if (s.findn("WHA")!=7) return false; - + if (s.findn("Revenge of the Monster SawFish")!=-1) return false; - + return true; - + } bool test_19() { - + OS::get_singleton()->print("\n\nTest 19: Search & replace\n"); - + String s="Happy Birthday, Anna!"; OS::get_singleton()->print("\tString: %ls\n",s.c_str()); - + s=s.replace("Birthday","Halloween"); OS::get_singleton()->print("\tReplaced Birthday/Halloween: %ls.\n",s.c_str()); - + return (s=="Happy Halloween, Anna!"); - + } bool test_20() { - + OS::get_singleton()->print("\n\nTest 20: Insertion\n"); - + String s="Who is Frederic?"; - + OS::get_singleton()->print("\tString: %ls\n",s.c_str()); s=s.insert( s.find("?")," Chopin" ); OS::get_singleton()->print("\tInserted Chopin: %ls.\n",s.c_str()); - + return (s=="Who is Frederic Chopin?"); - + } bool test_21() { - + OS::get_singleton()->print("\n\nTest 21: Number -> String\n"); - + OS::get_singleton()->print("\tPi is %f\n",33.141593); OS::get_singleton()->print("\tPi String is %ls\n",String::num(3.141593).c_str()); - + return String::num(3.141593)=="3.141593"; - + } bool test_22() { - + OS::get_singleton()->print("\n\nTest 22: String -> Int\n"); - + static const char* nums[4]={ "1237461283", "- 22", "0", " - 1123412" }; static const int num[4]={ 1237461283, -22, 0, -1123412 }; - + for (int i=0;i<4;i++) { OS::get_singleton()->print("\tString: \"%s\" as Int is %i\n",nums[i],String(nums[i]).to_int()); - + if (String(nums[i]).to_int()!=num[i]) return false; } - + return true; - + } bool test_23() { - + OS::get_singleton()->print("\n\nTest 23: String -> Float\n"); - + static const char* nums[4]={ "-12348298412.2", "0.05", "2.0002", " -0.0001" }; static const double num[4]={ -12348298412.2, 0.05, 2.0002, -0.0001 }; - + for (int i=0;i<4;i++) { OS::get_singleton()->print("\tString: \"%s\" as Float is %f\n",nums[i],String(nums[i]).to_double()); - + if ( ABS(String(nums[i]).to_double()-num[i])>0.00001) return false; } - + return true; - + } bool test_24() { - + OS::get_singleton()->print("\n\nTest 24: Slicing\n"); - + String s="Mars,Jupiter,Saturn,Uranus"; - + const char*slices[4]={"Mars","Jupiter","Saturn","Uranus"}; - + OS::get_singleton()->print("\tSlicing \"%ls\" by \"%s\"..\n",s.c_str(),","); - + for (int i=0;i<s.get_slice_count(",");i++) { - + OS::get_singleton()->print("\t\t%i- %ls\n",i+1,s.get_slice(",",i).c_str()); - - + + if (s.get_slice(",",i)!=slices[i]) return false; } - + return true; - + } bool test_25() { - + OS::get_singleton()->print("\n\nTest 25: Erasing\n"); - + String s="Josephine is such a cute girl!"; - + OS::get_singleton()->print("\tString: %ls\n",s.c_str()); OS::get_singleton()->print("\tRemoving \"cute\"\n"); - + s.erase(s.find("cute "),String("cute ").length()); OS::get_singleton()->print("\tResult: %ls\n",s.c_str()); - - + + return (s=="Josephine is such a girl!"); - + } bool test_26() { @@ -516,7 +516,7 @@ bool test_28() { String format, output; Array args; bool error; - + // %% format = "fish %% frog"; args.clear(); @@ -846,7 +846,7 @@ bool test_28() { typedef bool (*TestFunc)(void); TestFunc test_funcs[] = { - + test_1, test_2, test_3, @@ -876,18 +876,18 @@ TestFunc test_funcs[] = { test_27, test_28, 0 - + }; MainLoop* test() { - + /** A character length != wchar_t may be forced, so the tests wont work */ - + ERR_FAIL_COND_V( sizeof(CharType) != sizeof(wchar_t), NULL ); - + int count=0; int passed=0; - + while(true) { if (!test_funcs[count]) break; @@ -895,17 +895,17 @@ MainLoop* test() { if (pass) passed++; OS::get_singleton()->print("\t%s\n",pass?"PASS":"FAILED"); - + count++; } - + OS::get_singleton()->print("\n\n\n"); OS::get_singleton()->print("*************\n"); OS::get_singleton()->print("***TOTALS!***\n"); OS::get_singleton()->print("*************\n"); - + OS::get_singleton()->print("Passed %i of %i tests\n", passed, count); - + return NULL; } diff --git a/core/color.cpp b/core/color.cpp index 56a550c024..bf9c94462f 100644 --- a/core/color.cpp +++ b/core/color.cpp @@ -75,11 +75,11 @@ float Color::get_h() const { h = 2 + ( b - r ) / delta; // between cyan & yellow else h = 4 + ( r - g ) / delta; // between magenta & cyan - + h/=6.0; if (h<0) h+=1.0; - + return h; } @@ -119,7 +119,7 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) { p_h *=6.0; p_h = Math::fmod(p_h,6); i = Math::floor( p_h ); - + f = p_h - i; p = p_v * ( 1 - p_s ); q = p_v * ( 1 - p_s * f ); @@ -136,7 +136,7 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) { g = p_v; b = p; break; - case 2: + case 2: r = p; g = p_v; b = t; @@ -162,8 +162,8 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) { void Color::invert() { r=1.0-r; - g=1.0-g; - b=1.0-b; + g=1.0-g; + b=1.0-b; } void Color::contrast() { @@ -368,7 +368,7 @@ String Color::to_html(bool p_alpha) const { float Color::gray() const { - return (r+g+b)/3.0; + return (r+g+b)/3.0; } Color::operator String() const { diff --git a/core/color.h b/core/color.h index d0a1e8835c..5b671d5f62 100644 --- a/core/color.h +++ b/core/color.h @@ -37,13 +37,13 @@ struct Color { union { - + struct { float r; float g; float b; float a; - }; + }; float components[4]; }; @@ -58,28 +58,28 @@ struct Color { float get_v() const; void set_hsv(float p_h, float p_s, float p_v, float p_alpha=1.0); - _FORCE_INLINE_ float& operator[](int idx) { + _FORCE_INLINE_ float& operator[](int idx) { return components[idx]; } - _FORCE_INLINE_ const float& operator[](int idx) const { + _FORCE_INLINE_ const float& operator[](int idx) const { return components[idx]; } - + void invert(); void contrast(); Color inverted() const; Color contrasted() const; _FORCE_INLINE_ Color linear_interpolate(const Color& p_b, float p_t) const { - + Color res=*this; - + res.r+= (p_t * (p_b.r-r)); res.g+= (p_t * (p_b.g-g)); res.b+= (p_t * (p_b.b-b)); res.a+= (p_t * (p_b.a-a)); - - return res; + + return res; } _FORCE_INLINE_ Color blend(const Color& p_over) const { diff --git a/core/command_queue_mt.cpp b/core/command_queue_mt.cpp index a2507b1378..acd3aeddfb 100644 --- a/core/command_queue_mt.cpp +++ b/core/command_queue_mt.cpp @@ -76,7 +76,7 @@ CommandQueueMT::SyncSemaphore* CommandQueueMT::_alloc_sync_sem() { CommandQueueMT::CommandQueueMT(bool p_sync){ read_ptr=0; - write_ptr=0; + write_ptr=0; mutex = Mutex::create(); for(int i=0;i<SYNC_SEMAPHORES;i++) { diff --git a/core/command_queue_mt.h b/core/command_queue_mt.h index 142668f6f6..b1e0066c35 100644 --- a/core/command_queue_mt.h +++ b/core/command_queue_mt.h @@ -47,69 +47,69 @@ class CommandQueueMT { }; struct CommandBase { - + virtual void call()=0; virtual ~CommandBase() {}; }; - + template<class T,class M> struct Command0 : public CommandBase { T*instance; M method; - + virtual void call() { (instance->*method)(); } }; - + template<class T,class M,class P1> struct Command1 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; - + virtual void call() { (instance->*method)(p1); } }; - + template<class T,class M,class P1,class P2> struct Command2 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; typename GetSimpleTypeT<P2>::type_t p2; - + virtual void call() { (instance->*method)(p1,p2); } }; template<class T,class M,class P1,class P2,class P3> struct Command3 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; typename GetSimpleTypeT<P2>::type_t p2; typename GetSimpleTypeT<P3>::type_t p3; - + virtual void call() { (instance->*method)(p1,p2,p3); } }; template<class T,class M,class P1,class P2,class P3,class P4> struct Command4 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; typename GetSimpleTypeT<P2>::type_t p2; typename GetSimpleTypeT<P3>::type_t p3; typename GetSimpleTypeT<P4>::type_t p4; - + virtual void call() { (instance->*method)(p1,p2,p3,p4); } }; template<class T,class M,class P1,class P2,class P3,class P4,class P5> struct Command5 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; @@ -117,13 +117,13 @@ class CommandQueueMT { typename GetSimpleTypeT<P3>::type_t p3; typename GetSimpleTypeT<P4>::type_t p4; typename GetSimpleTypeT<P5>::type_t p5; - + virtual void call() { (instance->*method)(p1,p2,p3,p4,p5); } }; template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6> struct Command6 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; @@ -132,13 +132,13 @@ class CommandQueueMT { typename GetSimpleTypeT<P4>::type_t p4; typename GetSimpleTypeT<P5>::type_t p5; typename GetSimpleTypeT<P6>::type_t p6; - + virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6); } }; - + template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7> struct Command7 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; @@ -148,12 +148,12 @@ class CommandQueueMT { typename GetSimpleTypeT<P5>::type_t p5; typename GetSimpleTypeT<P6>::type_t p6; typename GetSimpleTypeT<P7>::type_t p7; - + virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7); } }; - + /* comands that return */ - + template<class T,class M,class R> struct CommandRet0 : public CommandBase { @@ -161,38 +161,38 @@ class CommandQueueMT { M method; R* ret; SyncSemaphore *sync; - + virtual void call() { *ret = (instance->*method)(); sync->sem->post(); sync->in_use=false; ; } }; - + template<class T,class M,class P1,class R> struct CommandRet1 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; R* ret; SyncSemaphore *sync; - + virtual void call() { *ret = (instance->*method)(p1); sync->sem->post(); sync->in_use=false; } }; - + template<class T,class M,class P1,class P2,class R> struct CommandRet2 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; typename GetSimpleTypeT<P2>::type_t p2; R* ret; SyncSemaphore *sync; - + virtual void call() { *ret = (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; ; } }; template<class T,class M,class P1,class P2,class P3,class R> struct CommandRet3 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; @@ -200,13 +200,13 @@ class CommandQueueMT { typename GetSimpleTypeT<P3>::type_t p3; R* ret; SyncSemaphore *sync; - + virtual void call() { *ret = (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; ; } }; template<class T,class M,class P1,class P2,class P3,class P4,class R> struct CommandRet4 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; @@ -215,13 +215,13 @@ class CommandQueueMT { typename GetSimpleTypeT<P4>::type_t p4; R* ret; SyncSemaphore *sync; - + virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4); sync->sem->post(); sync->in_use=false; ; } }; template<class T,class M,class P1,class P2,class P3,class P4,class P5,class R> struct CommandRet5 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; @@ -231,13 +231,13 @@ class CommandQueueMT { typename GetSimpleTypeT<P5>::type_t p5; R* ret; SyncSemaphore *sync; - + virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5); sync->sem->post(); sync->in_use=false; ; } }; template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class R> struct CommandRet6 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; @@ -248,13 +248,13 @@ class CommandQueueMT { typename GetSimpleTypeT<P6>::type_t p6; R* ret; SyncSemaphore *sync; - + virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6); sync->sem->post(); sync->in_use=false; ; } - }; + }; template<class T,class M,class P1,class P2,class P3,class P4,class P5,class P6,class P7,class R> struct CommandRet7 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT<P1>::type_t p1; @@ -266,9 +266,9 @@ class CommandQueueMT { typename GetSimpleTypeT<P7>::type_t p7; R* ret; SyncSemaphore *sync; - + virtual void call() { *ret = (instance->*method)(p1,p2,p3,p4,p5,p6,p7); sync->sem->post(); sync->in_use=false; ; } - }; + }; /** commands that don't return but sync */ @@ -392,7 +392,7 @@ class CommandQueueMT { /***** BASE *******/ - enum { + enum { COMMAND_MEM_SIZE_KB=256, COMMAND_MEM_SIZE=COMMAND_MEM_SIZE_KB*1024, SYNC_SEMAPHORES=8 @@ -405,30 +405,30 @@ class CommandQueueMT { SyncSemaphore sync_sems[SYNC_SEMAPHORES]; Mutex *mutex; Semaphore *sync; - - + + template<class T> T* allocate() { - + // alloc size is size+T+safeguard uint32_t alloc_size=sizeof(T)+sizeof(uint32_t); - + tryagain: - + if (write_ptr < read_ptr) { // behind read_ptr, check that there is room if ( (read_ptr-write_ptr) <= alloc_size ) return NULL; } else if (write_ptr >= read_ptr) { // ahead of read_ptr, check that there is room - - + + if ( (COMMAND_MEM_SIZE-write_ptr) < alloc_size+4 ) { // no room at the end, wrap down; - + if (read_ptr==0) // dont want write_ptr to become read_ptr return NULL; - + // if this happens, it's a bug ERR_FAIL_COND_V( (COMMAND_MEM_SIZE-write_ptr) < sizeof(uint32_t), NULL ); // zero means, wrap to begining @@ -447,147 +447,147 @@ class CommandQueueMT { T* cmd = memnew_placement( &command_mem[write_ptr], T ); write_ptr+=sizeof(T); return cmd; - + } - + template<class T> T* allocate_and_lock() { - + lock(); T* ret; - + while ( (ret=allocate<T>())==NULL ) { - + unlock(); - // sleep a little until fetch happened and some room is made + // sleep a little until fetch happened and some room is made wait_for_flush(); lock(); - + } - + return ret; } - - + + bool flush_one() { - + tryagain: - + // tried to read an empty queue if (read_ptr == write_ptr ) return false; - + uint32_t size = *(uint32_t*)( &command_mem[read_ptr] ); - + if (size==0) { //end of ringbuffer, wrap read_ptr=0; goto tryagain; } - + read_ptr+=sizeof(uint32_t); - + CommandBase *cmd = reinterpret_cast<CommandBase*>( &command_mem[read_ptr] ); - + cmd->call(); cmd->~CommandBase(); - - read_ptr+=size; + + read_ptr+=size; return true; } - - + + void lock(); void unlock(); void wait_for_flush(); SyncSemaphore* _alloc_sync_sem(); - - + + public: /* NORMAL PUSH COMMANDS */ - + template<class T, class M> void push( T * p_instance, M p_method ) { - + Command0<T,M> * cmd = allocate_and_lock< Command0<T,M> >(); - + cmd->instance=p_instance; cmd->method=p_method; - + unlock(); - + if (sync) sync->post(); } template<class T, class M, class P1> void push( T * p_instance, M p_method, P1 p1 ) { - + Command1<T,M,P1> * cmd = allocate_and_lock< Command1<T,M,P1> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; - + unlock(); - + if (sync) sync->post(); } template<class T, class M, class P1, class P2> void push( T * p_instance, M p_method, P1 p1, P2 p2 ) { - + Command2<T,M,P1,P2> * cmd = allocate_and_lock< Command2<T,M,P1,P2> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; cmd->p2=p2; - + unlock(); - + if (sync) sync->post(); } template<class T, class M, class P1, class P2, class P3> void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3 ) { - + Command3<T,M,P1,P2,P3> * cmd = allocate_and_lock< Command3<T,M,P1,P2,P3> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; cmd->p2=p2; cmd->p3=p3; - + unlock(); - + if (sync) sync->post(); } template<class T, class M, class P1, class P2, class P3, class P4> void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4 ) { - + Command4<T,M,P1,P2,P3,P4> * cmd = allocate_and_lock< Command4<T,M,P1,P2,P3,P4> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; cmd->p2=p2; cmd->p3=p3; cmd->p4=p4; - + unlock(); - + if (sync) sync->post(); } template<class T, class M, class P1, class P2, class P3, class P4, class P5> void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5 ) { - + Command5<T,M,P1,P2,P3,P4,P5> * cmd = allocate_and_lock< Command5<T,M,P1,P2,P3,P4,P5> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; @@ -595,17 +595,17 @@ public: cmd->p3=p3; cmd->p4=p4; cmd->p5=p5; - + unlock(); - + if (sync) sync->post(); } template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6> void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6 ) { - + Command6<T,M,P1,P2,P3,P4,P5,P6> * cmd = allocate_and_lock< Command6<T,M,P1,P2,P3,P4,P5,P6> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; @@ -614,17 +614,17 @@ public: cmd->p4=p4; cmd->p5=p5; cmd->p6=p6; - + unlock(); - + if (sync) sync->post(); } template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6, class P7> void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7 ) { - + Command7<T,M,P1,P2,P3,P4,P5,P6,P7> * cmd = allocate_and_lock< Command7<T,M,P1,P2,P3,P4,P5,P6,P7> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; @@ -634,19 +634,19 @@ public: cmd->p5=p5; cmd->p6=p6; cmd->p7=p7; - + unlock(); - + if (sync) sync->post(); } /*** PUSH AND RET COMMANDS ***/ - - + + template<class T, class M,class R> void push_and_ret( T * p_instance, M p_method, R* r_ret) { - + CommandRet0<T,M,R> * cmd = allocate_and_lock< CommandRet0<T,M,R> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->ret=r_ret; @@ -654,34 +654,34 @@ public: cmd->sync=ss; unlock(); - + if (sync) sync->post(); ss->sem->wait(); } template<class T, class M, class P1,class R> void push_and_ret( T * p_instance, M p_method, P1 p1, R* r_ret) { - + CommandRet1<T,M,P1,R> * cmd = allocate_and_lock< CommandRet1<T,M,P1,R> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; cmd->ret=r_ret; SyncSemaphore *ss=_alloc_sync_sem(); cmd->sync=ss; - + unlock(); - + if (sync) sync->post(); ss->sem->wait(); } template<class T, class M, class P1, class P2,class R> void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, R* r_ret) { - + CommandRet2<T,M,P1,P2,R> * cmd = allocate_and_lock< CommandRet2<T,M,P1,P2,R> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; @@ -691,16 +691,16 @@ public: cmd->sync=ss; unlock(); - + if (sync) sync->post(); ss->sem->wait(); } template<class T, class M, class P1, class P2, class P3,class R> void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, R* r_ret ) { - + CommandRet3<T,M,P1,P2,P3,R> * cmd = allocate_and_lock< CommandRet3<T,M,P1,P2,P3,R> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; @@ -711,16 +711,16 @@ public: cmd->sync=ss; unlock(); - + if (sync) sync->post(); ss->sem->wait(); } template<class T, class M, class P1, class P2, class P3, class P4,class R> void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, R* r_ret ) { - + CommandRet4<T,M,P1,P2,P3,P4,R> * cmd = allocate_and_lock< CommandRet4<T,M,P1,P2,P3,P4,R> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; @@ -732,16 +732,16 @@ public: cmd->sync=ss; unlock(); - + if (sync) sync->post(); ss->sem->wait(); } template<class T, class M, class P1, class P2, class P3, class P4, class P5,class R> void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, R* r_ret ) { - + CommandRet5<T,M,P1,P2,P3,P4,P5,R> * cmd = allocate_and_lock< CommandRet5<T,M,P1,P2,P3,P4,P5,R> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; @@ -754,16 +754,16 @@ public: cmd->sync=ss; unlock(); - + if (sync) sync->post(); ss->sem->wait(); } template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6,class R> void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, R* r_ret ) { - + CommandRet6<T,M,P1,P2,P3,P4,P5,P6,R> * cmd = allocate_and_lock< CommandRet6<T,M,P1,P2,P3,P4,P5,P6,R> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; @@ -777,16 +777,16 @@ public: cmd->sync=ss; unlock(); - + if (sync) sync->post(); ss->sem->wait(); } - + template<class T, class M, class P1, class P2, class P3, class P4, class P5, class P6,class P7,class R> void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6,P7 p7, R* r_ret ) { - + CommandRet7<T,M,P1,P2,P3,P4,P5,P6,P7,R> * cmd = allocate_and_lock< CommandRet7<T,M,P1,P2,P3,P4,P5,P6,P7,R> >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; @@ -801,7 +801,7 @@ public: cmd->sync=ss; unlock(); - + if (sync) sync->post(); ss->sem->wait(); } @@ -975,12 +975,12 @@ public: ERR_FAIL_COND(!sync); sync->wait(); lock(); - flush_one(); + flush_one(); unlock(); } - + void flush_all() { - + //ERR_FAIL_COND(sync); lock(); while (true) { @@ -990,10 +990,10 @@ public: } unlock(); } - + CommandQueueMT(bool p_sync); ~CommandQueueMT(); - + }; #endif diff --git a/core/dvector.h b/core/dvector.h index 17431b33a6..fbb1fc4824 100644 --- a/core/dvector.h +++ b/core/dvector.h @@ -43,18 +43,18 @@ template<class T> class DVector { mutable MID mem; - - + + void copy_on_write() { - + if (!mem.is_valid()) return; if (dvector_lock) dvector_lock->lock(); - + MID_Lock lock( mem ); - + if ( *(int*)lock.data() == 1 ) { // one reference, means no refcount changes @@ -62,114 +62,114 @@ class DVector { dvector_lock->unlock(); return; } - + MID new_mem= dynalloc( mem.get_size() ); - + if (!new_mem.is_valid()) { - + if (dvector_lock) dvector_lock->unlock(); - ERR_FAIL_COND( new_mem.is_valid() ); // out of memory + ERR_FAIL_COND( new_mem.is_valid() ); // out of memory } - + MID_Lock dst_lock( new_mem ); - + int *rc = (int*)dst_lock.data(); - + *rc=1; - + T * dst = (T*)(rc + 1 ); - + T * src =(T*) ((int*)lock.data() + 1 ); - + int count = (mem.get_size() - sizeof(int)) / sizeof(T); - + for (int i=0;i<count;i++) { - + memnew_placement( &dst[i], T(src[i]) ); } - + (*(int*)lock.data())--; - + // unlock all dst_lock=MID_Lock(); lock=MID_Lock(); - + mem=new_mem; - + if (dvector_lock) dvector_lock->unlock(); - + } - + void reference( const DVector& p_dvector ) { - + unreference(); - + if (dvector_lock) dvector_lock->lock(); - + if (!p_dvector.mem.is_valid()) { - + if (dvector_lock) dvector_lock->unlock(); - return; + return; } - + MID_Lock lock(p_dvector.mem); - + int * rc = (int*)lock.data(); (*rc)++; - + lock = MID_Lock(); mem=p_dvector.mem; - + if (dvector_lock) dvector_lock->unlock(); - + } - - + + void unreference() { - + if (dvector_lock) dvector_lock->lock(); - + if (!mem.is_valid()) { - + if (dvector_lock) dvector_lock->unlock(); - return; + return; } - + MID_Lock lock(mem); - + int * rc = (int*)lock.data(); (*rc)--; - + if (*rc==0) { // no one else using it, destruct - + T * t= (T*)(rc+1); int count = (mem.get_size() - sizeof(int)) / sizeof(T); - + for (int i=0;i<count;i++) { - + t[i].~T(); } - + } - - + + lock = MID_Lock(); - + mem = MID (); - + if (dvector_lock) dvector_lock->unlock(); - + } - + public: class Read { @@ -177,10 +177,10 @@ public: MID_Lock lock; const T * mem; public: - + _FORCE_INLINE_ const T& operator[](int p_index) const { return mem[p_index]; } _FORCE_INLINE_ const T *ptr() const { return mem; } - + Read() { mem=NULL; } }; @@ -189,32 +189,32 @@ public: MID_Lock lock; T * mem; public: - + _FORCE_INLINE_ T& operator[](int p_index) { return mem[p_index]; } _FORCE_INLINE_ T *ptr() { return mem; } - + Write() { mem=NULL; } }; Read read() const { - + Read r; - if (mem.is_valid()) { + if (mem.is_valid()) { r.lock = MID_Lock( mem ); r.mem = (const T*)((int*)r.lock.data()+1); } - return r; + return r; } Write write() { - + Write w; if (mem.is_valid()) { copy_on_write(); w.lock = MID_Lock( mem ); w.mem = (T*)((int*)w.lock.data()+1); } - return w; + return w; } template<class MC> @@ -280,12 +280,12 @@ public: bool is_locked() const { return mem.is_locked(); } - + inline const T operator[](int p_index) const; Error resize(int p_size); - - + + void operator=(const DVector& p_dvector) { reference(p_dvector); } DVector() {} DVector(const DVector& p_dvector) { reference(p_dvector); } @@ -308,7 +308,7 @@ T DVector<T>::get(int p_index) const { template<class T> void DVector<T>::set(int p_index, const T& p_val) { - if (p_index<0 || p_index>=size()) { + if (p_index<0 || p_index>=size()) { ERR_FAIL_COND(p_index<0 || p_index>=size()); } @@ -332,7 +332,7 @@ const T DVector<T>::operator[](int p_index) const { } Read r = read(); - + return r[p_index]; } @@ -344,83 +344,83 @@ Error DVector<T>::resize(int p_size) { dvector_lock->lock(); bool same = p_size==size(); - + if (dvector_lock) dvector_lock->unlock(); - // no further locking is necesary because we are supposed to own the only copy of this (using copy on write) - + // no further locking is necesary because we are supposed to own the only copy of this (using copy on write) + if (same) return OK; if (p_size == 0 ) { - + unreference(); return OK; } copy_on_write(); // make it unique - + ERR_FAIL_COND_V( mem.is_locked(), ERR_LOCKED ); // if after copy on write, memory is locked, fail. - + if (p_size > size() ) { - + int oldsize=size(); - + MID_Lock lock; - + if (oldsize==0) { mem = dynalloc( p_size * sizeof(T) + sizeof(int) ); lock=MID_Lock(mem); int *rc = ((int*)lock.data()); *rc=1; - + } else { if (dynrealloc( mem, p_size * sizeof(T) + sizeof(int) )!=OK ) { - + ERR_FAIL_V(ERR_OUT_OF_MEMORY); // out of memory } - - lock=MID_Lock(mem); + + lock=MID_Lock(mem); } - - - - + + + + T *t = (T*)((int*)lock.data() + 1); - + for (int i=oldsize;i<p_size;i++) { - + memnew_placement(&t[i], T ); } - + lock = MID_Lock(); // clear } else { - + int oldsize=size(); - + MID_Lock lock(mem); - - + + T *t = (T*)((int*)lock.data() + 1); - + for (int i=p_size;i<oldsize;i++) { - + t[i].~T(); } - + lock = MID_Lock(); // clear - + if (dynrealloc( mem, p_size * sizeof(T) + sizeof(int) )!=OK ) { - - ERR_FAIL_V(ERR_OUT_OF_MEMORY); // wtf error + + ERR_FAIL_V(ERR_OUT_OF_MEMORY); // wtf error } - - + + } - + return OK; } diff --git a/core/error_macros.h b/core/error_macros.h index 47b1de5df3..6d931e899e 100644 --- a/core/error_macros.h +++ b/core/error_macros.h @@ -33,12 +33,12 @@ /** * Error macros. Unlike exceptions and asserts, these macros try to mantain consistency and stability * inside the code. It is recommended to always return processable data, so in case of an error, the - * engine can stay working well. + * engine can stay working well. * In most cases, bugs and/or invalid data are not fatal and should never allow a perfectly running application * to fail or crash. */ -/** +/** * Pointer to the error macro priting function. Reassign to any function to have errors printed */ @@ -136,7 +136,7 @@ extern bool _err_error_exists; return m_retval; \ }else _err_error_exists=false; } \ -/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). +/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). * the function will exit. */ @@ -146,7 +146,7 @@ extern bool _err_error_exists; return; \ }else _err_error_exists=false; } \ -/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). +/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). * the function will exit. * This function returns an error value, if returning Error, please select the most * appropriate error condition from error_macros.h @@ -158,7 +158,7 @@ extern bool _err_error_exists; return m_retval; \ }else _err_error_exists=false; } \ -/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). +/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). * the loop will skip to the next iteration. */ @@ -168,7 +168,7 @@ extern bool _err_error_exists; continue;\ } else _err_error_exists=false;} \ -/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). +/** An error condition happened (m_cond tested true) (WARNING this is the opposite as assert(). * the loop will break */ diff --git a/core/event_queue.cpp b/core/event_queue.cpp index 088e80b266..53638c5431 100644 --- a/core/event_queue.cpp +++ b/core/event_queue.cpp @@ -43,118 +43,118 @@ Error EventQueue::push_call(uint32_t p_instance_ID, const StringName& p_method, args=2; else if (p_arg1.get_type()!=Variant::NIL) args=1; - else + else args=0; - + room_needed+=sizeof(Variant)*args; - + ERR_FAIL_COND_V( (buffer_end+room_needed) >= buffer_size , ERR_OUT_OF_MEMORY ); Event * ev = memnew_placement( &event_buffer[ buffer_end ], Event ); ev->args=args; ev->instance_ID=p_instance_ID; ev->method=p_method; - + buffer_end+=sizeof(Event); - + if (args>=1) { - + Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg1; } if (args>=2) { - + Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg2; } if (args>=3) { - + Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg3; - + } if (args>=4) { - + Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg4; } if (args>=5) { - + Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg5; } - + if (buffer_max_used>buffer_end); buffer_max_used=buffer_end; - + return OK; } void EventQueue::flush_events() { uint32_t read_pos=0; - + while (read_pos < buffer_end ) { - + Event *event = (Event*)&event_buffer[ read_pos ]; Variant *args= (Variant*)(event+1); Object *obj = ObjectDB::get_instance(event->instance_ID); - - if (obj) { + + if (obj) { // events don't expect a return value - obj->call( event->method, + obj->call( event->method, (event->args>=1) ? args[0] : Variant(), (event->args>=2) ? args[1] : Variant(), (event->args>=3) ? args[2] : Variant(), (event->args>=4) ? args[3] : Variant(), (event->args>=5) ? args[4] : Variant() ); } - + if (event->args>=1) args[0].~Variant(); if (event->args>=2) args[1].~Variant(); if (event->args>=3) args[2].~Variant(); if (event->args>=4) args[3].~Variant(); if (event->args>=5) args[4].~Variant(); event->~Event(); - + read_pos+=sizeof(Event)+sizeof(Variant)*event->args; } - + buffer_end=0; // reset buffer } EventQueue::EventQueue(uint32_t p_buffer_size) { - + buffer_end=0; buffer_max_used=0; buffer_size=p_buffer_size; event_buffer = memnew_arr( uint8_t, buffer_size ); - + } EventQueue::~EventQueue() { uint32_t read_pos=0; - + while (read_pos < buffer_end ) { - + Event *event = (Event*)&event_buffer[ read_pos ]; Variant *args= (Variant*)(event+1); for (int i=0;i<event->args;i++) args[i].~Variant(); event->~Event(); - + read_pos+=sizeof(Event)+sizeof(Variant)*event->args; } - + memdelete_arr(event_buffer); event_buffer=NULL; } diff --git a/core/event_queue.h b/core/event_queue.h index af0a4df2b8..99e853fd28 100644 --- a/core/event_queue.h +++ b/core/event_queue.h @@ -36,18 +36,18 @@ class EventQueue { enum { - + DEFAULT_EVENT_QUEUE_SIZE_KB=256 }; struct Event { - + uint32_t instance_ID; StringName method; int args; }; - - + + uint8_t *event_buffer; uint32_t buffer_end; uint32_t buffer_max_used; @@ -57,7 +57,7 @@ public: Error push_call(uint32_t p_instance_ID, const StringName& p_method, VARIANT_ARG_LIST); void flush_events(); - + EventQueue(uint32_t p_buffer_size=DEFAULT_EVENT_QUEUE_SIZE_KB*1024); ~EventQueue(); diff --git a/core/globals.cpp b/core/globals.cpp index d63f9c1bb4..c0c1171ae6 100644 --- a/core/globals.cpp +++ b/core/globals.cpp @@ -40,7 +40,7 @@ Globals *Globals::singleton=NULL; Globals *Globals::get_singleton() { - + return singleton; } @@ -108,7 +108,7 @@ bool Globals::is_persisting(const String& p_name) const { String Globals::globalize_path(const String& p_path) const { - + if (p_path.begins_with("res://")) { if (resource_path != "") { @@ -125,7 +125,7 @@ String Globals::globalize_path(const String& p_path) const { bool Globals::_set(const StringName& p_name, const Variant& p_value) { _THREAD_SAFE_METHOD_ - + if (p_value.get_type()==Variant::NIL) props.erase(p_name); else { @@ -174,7 +174,7 @@ bool Globals::_get(const StringName& p_name,Variant &r_ret) const { return false; r_ret=props[p_name].variant; return true; - + } struct _VCSort { @@ -188,13 +188,13 @@ struct _VCSort { }; void Globals::_get_property_list(List<PropertyInfo> *p_list) const { - + _THREAD_SAFE_METHOD_ Set<_VCSort> vclist; - + for(Map<StringName,VariantContainer>::Element *E=props.front();E;E=E->next()) { - + const VariantContainer *v=&E->get(); if (v->hide_from_editor) @@ -250,7 +250,7 @@ bool Globals::_load_resource_pack(const String& p_pack) { Error Globals::setup(const String& p_path,const String & p_main_pack) { //an absolute mess of a function, must be cleaned up and reorganized somehow at some point - + //_load_settings(p_path+"/override.cfg"); if (p_main_pack!="") { @@ -292,7 +292,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) { } } - + if (FileAccessNetworkClient::get_singleton()) { @@ -332,7 +332,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) { resource_path = p_path; } else { - + d->change_dir(p_path); String candidate = d->get_current_dir(); @@ -395,7 +395,7 @@ Error Globals::setup(const String& p_path,const String & p_main_pack) { } bool Globals::has(String p_var) const { - + _THREAD_SAFE_METHOD_ return props.has(p_var); @@ -1410,7 +1410,7 @@ void Globals::_bind_methods() { } Globals::Globals() { - + singleton=this; last_order=0; @@ -1531,7 +1531,7 @@ Globals::Globals() { Globals::~Globals() { - + singleton=NULL; } diff --git a/core/globals.h b/core/globals.h index 8951f5fbd2..68bb859ace 100644 --- a/core/globals.h +++ b/core/globals.h @@ -38,7 +38,7 @@ class Globals : public Object { - + OBJ_TYPE( Globals, Object ); _THREAD_SAFE_CLASS_ @@ -77,13 +77,13 @@ protected: bool using_datapack; List<String> input_presets; - + bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list(List<PropertyInfo> *p_list) const; - + static Globals *singleton; - + Error _load_settings(const String p_path); Error _load_settings_binary(const String p_path); @@ -101,7 +101,7 @@ protected: static void _bind_methods(); public: - + bool has(String p_var) const; String localize_path(const String& p_path) const; String globalize_path(const String& p_path) const; @@ -110,13 +110,13 @@ public: bool is_persisting(const String& p_name) const; String get_resource_path() const; - + static Globals *get_singleton(); void clear(const String& p_name); int get_order(const String& p_name) const; void set_order(const String& p_name, int p_order); - + Error setup(const String& p_path, const String &p_main_pack); Error save_custom(const String& p_path="",const CustomMap& p_custom=CustomMap(),const Set<String>& p_ignore_masks=Set<String>()); @@ -141,7 +141,7 @@ public: void set_registering_order(bool p_registering); - Globals(); + Globals(); ~Globals(); }; diff --git a/core/hash_map.h b/core/hash_map.h index 33eb25652c..e83710c700 100644 --- a/core/hash_map.h +++ b/core/hash_map.h @@ -38,7 +38,7 @@ class HashMapHahserDefault { public: - + static _FORCE_INLINE_ uint32_t hash(const String &p_string) { return p_string.hash(); } static _FORCE_INLINE_ uint32_t hash(const char *p_cstr) { return hash_djb2(p_cstr); } static _FORCE_INLINE_ uint32_t hash(const uint64_t p_int) { @@ -66,8 +66,8 @@ public: /** * @class HashMap - * @author Juan Linietsky <reduzio@gmail.com> - * + * @author Juan Linietsky <reduzio@gmail.com> + * * Implementation of a standard Hashing HashMap, for quick lookups of Data associated with a Key. * The implementation provides hashers for the default types, if you need a special kind of hasher, provide * your own. @@ -77,213 +77,213 @@ public: * @param MIN_HASH_TABLE_POWER Miminum size of the hash table, as a power of two. You rarely need to change this parameter. * @param RELATIONSHIP Relationship at which the hash table is resized. if amount of elements is RELATIONSHIP * times bigger than the hash table, table is resized to solve this condition. if RELATIONSHIP is zero, table is always MIN_HASH_TABLE_POWER. - * + * */ template<class TKey, class TData, class Hasher=HashMapHahserDefault,uint8_t MIN_HASH_TABLE_POWER=3,uint8_t RELATIONSHIP=8> class HashMap { -public: - +public: + struct Pair { - + TKey key; TData data; - + Pair() {} Pair(const TKey& p_key, const TData& p_data) { key=p_key; data=p_data; } }; - - -private: + + +private: struct Entry { - + uint32_t hash; Entry *next; Pair pair; - + Entry() { next=0; } }; - + Entry **hash_table; uint8_t hash_table_power; uint32_t elements; - + void make_hash_table() { - + ERR_FAIL_COND( hash_table ); - - + + hash_table = memnew_arr( Entry*, (1<<MIN_HASH_TABLE_POWER) ); - + hash_table_power = MIN_HASH_TABLE_POWER; elements=0; for (int i=0;i<(1<<MIN_HASH_TABLE_POWER);i++) hash_table[i]=0; } - + void erase_hash_table() { - + ERR_FAIL_COND(elements); - + memdelete_arr( hash_table ); hash_table=0; - hash_table_power=0; - elements=0; - } - + hash_table_power=0; + elements=0; + } + void check_hash_table() { int new_hash_table_power=-1; - + if ((int)elements > ( (1<<hash_table_power) * RELATIONSHIP ) ) { /* rehash up */ new_hash_table_power=hash_table_power+1; - + while( (int)elements > ( (1<<new_hash_table_power) * RELATIONSHIP ) ) { - + new_hash_table_power++; } - + } else if ( (hash_table_power>(int)MIN_HASH_TABLE_POWER) && ((int)elements < ( (1<<(hash_table_power-1)) * RELATIONSHIP ) ) ) { - + /* rehash down */ new_hash_table_power=hash_table_power-1; - + while( (int)elements < ( (1<<(new_hash_table_power-1)) * RELATIONSHIP ) ) { - + new_hash_table_power--; } - + if (new_hash_table_power<(int)MIN_HASH_TABLE_POWER) new_hash_table_power=MIN_HASH_TABLE_POWER; } - - + + if (new_hash_table_power==-1) return; - + Entry ** new_hash_table = memnew_arr( Entry*, (1<<new_hash_table_power) ); if (!new_hash_table) { - + ERR_PRINT("Out of Memory"); return; } - + for (int i=0;i<(1<<new_hash_table_power);i++) { - + new_hash_table[i]=0; } - + for (int i=0;i<(1<<hash_table_power);i++) { - + while( hash_table[i] ) { - + Entry *se=hash_table[i]; hash_table[i]=se->next; int new_pos = se->hash & ((1<<new_hash_table_power)-1); se->next=new_hash_table[new_pos]; new_hash_table[new_pos]=se; } - + } - + if (hash_table) memdelete_arr( hash_table ); hash_table=new_hash_table; - hash_table_power=new_hash_table_power; + hash_table_power=new_hash_table_power; } /* I want to have only one function.. */ _FORCE_INLINE_ const Entry * get_entry( const TKey& p_key ) const { - + uint32_t hash = Hasher::hash( p_key ); uint32_t index = hash&((1<<hash_table_power)-1); - + Entry *e = hash_table[index]; - + while (e) { - + /* checking hash first avoids comparing key, which may take longer */ if (e->hash == hash && e->pair.key == p_key ) { - + /* the pair exists in this hashtable, so just update data */ return e; } - + e=e->next; } - + return NULL; } - + Entry * create_entry(const TKey& p_key) { - + /* if entry doesn't exist, create it */ Entry *e = memnew( Entry ); ERR_FAIL_COND_V(!e,NULL); /* out of memory */ uint32_t hash = Hasher::hash( p_key ); uint32_t index = hash&((1<<hash_table_power)-1); - e->next = hash_table[index]; + e->next = hash_table[index]; e->hash = hash; e->pair.key=p_key; - + hash_table[index]=e; elements++; - + return e; } - - + + void copy_from(const HashMap& p_t) { - + if (&p_t==this) return; /* much less bother with that */ - + clear(); - + if (!p_t.hash_table || p_t.hash_table_power==0) return; /* not copying from empty table */ - + hash_table = memnew_arr(Entry*,1<<p_t.hash_table_power); hash_table_power=p_t.hash_table_power; elements=p_t.elements; - + for (int i=0;i<( 1<<p_t.hash_table_power );i++) { - + hash_table[i]=NULL; /* elements will be in the reverse order, but it doesn't matter */ - + const Entry *e = p_t.hash_table[i]; - + while(e) { - + Entry *le = memnew( Entry ); /* local entry */ - + *le=*e; /* copy data */ - + /* add to list and reassign pointers */ le->next=hash_table[i]; hash_table[i]=le; - + e=e->next; } - - + + } - - + + } public: - - + + void set( const TKey& p_key, const TData& p_data ) { - + set( Pair( p_key, p_data ) ); - + } - + void set( const Pair& p_pair ) { Entry *e=NULL; @@ -291,63 +291,63 @@ public: make_hash_table(); // if no table, make one else e = const_cast<Entry*>( get_entry(p_pair.key) ); - + /* if we made it up to here, the pair doesn't exist, create and assign */ - + if (!e) { - + e=create_entry(p_pair.key); if (!e) return; check_hash_table(); // perform mantenience routine } - + e->pair.data = p_pair.data; - + } - - + + bool has( const TKey& p_key ) const { - + return getptr(p_key)!=NULL; } - + /** - * Get a key from data, return a const reference. + * Get a key from data, return a const reference. * WARNING: this doesn't check errors, use either getptr and check NULL, or check * first with has(key) */ - + const TData& get( const TKey& p_key ) const { - + const TData* res = getptr(p_key); ERR_FAIL_COND_V(!res,*res); return *res; } - + TData& get( const TKey& p_key ) { - + TData* res = getptr(p_key); ERR_FAIL_COND_V(!res,*res); return *res; } - + /** * Same as get, except it can return NULL when item was not found. * This is mainly used for speed purposes. */ - + _FORCE_INLINE_ TData* getptr( const TKey& p_key ) { - + if (!hash_table) return NULL; - + Entry *e=const_cast<Entry*>(get_entry(p_key )); - + if (e) return &e->pair.data; - + return NULL; } @@ -427,108 +427,108 @@ public: /** * Erase an item, return true if erasing was succesful */ - + bool erase( const TKey& p_key ) { - + if (!hash_table) return false; - + uint32_t hash = Hasher::hash( p_key ); uint32_t index = hash&((1<<hash_table_power)-1); - - + + Entry *e = hash_table[index]; Entry *p=NULL; while (e) { - + /* checking hash first avoids comparing key, which may take longer */ if (e->hash == hash && e->pair.key == p_key ) { - + if (p) { - + p->next=e->next; - } else { + } else { //begin of list hash_table[index]=e->next; } - + memdelete(e); elements--; - + if (elements==0) erase_hash_table(); else - check_hash_table(); + check_hash_table(); return true; } - + p=e; e=e->next; } - - + + return false; - + } - + inline const TData& operator[](const TKey& p_key) const { //constref - + return get(p_key); } inline TData& operator[](const TKey& p_key ) { //assignment - + Entry *e=NULL; if (!hash_table) make_hash_table(); // if no table, make one else e = const_cast<Entry*>( get_entry(p_key) ); - + /* if we made it up to here, the pair doesn't exist, create */ if (!e) { - + e=create_entry(p_key); if (!e) return *(TData*)NULL; /* panic! */ check_hash_table(); // perform mantenience routine } - + return e->pair.data; - + } - - /** - * Get the next key to p_key, and the first key if p_key is null. + + /** + * Get the next key to p_key, and the first key if p_key is null. * Returns a pointer to the next key if found, NULL otherwise. * Adding/Removing elements while iterating will, of course, have unexpected results, don't do it. - * + * * Example: - * + * * const TKey *k=NULL; - * + * * while( (k=table.next(k)) ) { - * + * * print( *k ); * } - * + * */ const TKey* next(const TKey* p_key) const { - + if (!hash_table) return NULL; - + if (!p_key) { /* get the first key */ - + for (int i=0;i<(1<<hash_table_power);i++) { - + if (hash_table[i]) { return &hash_table[i]->pair.key; } } } else { /* get the next key */ - + const Entry *e = get_entry( *p_key ); ERR_FAIL_COND_V( !e, NULL ); /* invalid key supplied */ - + if (e->next) { /* if there is a "next" in the list, return that */ return &e->next->pair.key; @@ -537,60 +537,60 @@ public: uint32_t index = e->hash&((1<<hash_table_power)-1); index++; for (int i=index;i<(1<<hash_table_power);i++) { - + if (hash_table[i]) { return &hash_table[i]->pair.key; } } } - + /* nothing found, was at end */ - + } - - + + return NULL; /* nothing found */ } - + inline unsigned int size() const { - + return elements; } - + inline bool empty() const { - + return elements==0; } - + void clear() { - + /* clean up */ if (hash_table) { for (int i=0;i<(1<<hash_table_power);i++) { - + while (hash_table[i]) { - + Entry *e=hash_table[i]; hash_table[i]=e->next; memdelete( e ); } } - + memdelete_arr( hash_table ); } - + hash_table=0; hash_table_power=0; - elements=0; + elements=0; } - - + + void operator=(const HashMap& p_table) { - + copy_from(p_table); } - - HashMap() { + + HashMap() { hash_table=NULL; elements=0; hash_table_power=0; @@ -609,18 +609,18 @@ public: } } - HashMap(const HashMap& p_table) { - + HashMap(const HashMap& p_table) { + hash_table=NULL; elements=0; hash_table_power=0; - + copy_from(p_table); - + } - + ~HashMap() { - + clear(); } diff --git a/core/hashfuncs.h b/core/hashfuncs.h index c2ed5bd679..a917ee5edb 100644 --- a/core/hashfuncs.h +++ b/core/hashfuncs.h @@ -47,10 +47,10 @@ static inline uint32_t hash_djb2(const char *p_cstr) { const unsigned char* chr=(const unsigned char*)p_cstr; uint32_t hash = 5381; uint32_t c; - + while ((c = *chr++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ - + return hash; } @@ -86,7 +86,7 @@ static inline uint32_t make_uint32_t(T p_in) { T t; uint32_t _u32; } _u; - _u._u32=0; + _u._u32=0; _u.t=p_in; return _u._u32; } @@ -106,7 +106,7 @@ static inline uint64_t make_uint64_t(T p_in) { uint64_t _u64; } _u; _u._u64=0; // in case p_in is smaller - + _u.t=p_in; return _u._u64; } diff --git a/core/image.cpp b/core/image.cpp index 798fc41f40..184ab70dc4 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -382,7 +382,7 @@ void Image::convert( Format p_new_format ){ Image new_img(width,height,0,p_new_format); - + int len=data.size(); DVector<uint8_t>::Read r = data.read(); @@ -413,7 +413,7 @@ void Image::convert( Format p_new_format ){ w = DVector<uint8_t>::Write(); bool gen_mipmaps=mipmaps>0; - + *this=new_img; if (gen_mipmaps) @@ -643,13 +643,13 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) { ERR_FAIL_COND(p_height<=0); ERR_FAIL_COND(p_width>MAX_WIDTH); ERR_FAIL_COND(p_height>MAX_HEIGHT); - + if (p_width==width && p_height==height) return; - + Image dst( p_width, p_height, 0, format ); - + if (format==FORMAT_INDEXED) p_interpolation=INTERPOLATE_NEAREST; @@ -714,34 +714,34 @@ void Image::crop( int p_width, int p_height ) { ERR_FAIL_COND(p_height<=0); ERR_FAIL_COND(p_width>MAX_WIDTH); ERR_FAIL_COND(p_height>MAX_HEIGHT); - + /* to save memory, cropping should be done in-place, however, since this function will most likely either not be used much, or in critical areas, for now it wont, because it's a waste of time. */ if (p_width==width && p_height==height) return; - + Image dst( p_width, p_height,0, format ); - + for (int y=0;y<p_height;y++) { - + for (int x=0;x<p_width;x++) { Color col = (x>=width || y>=height)? Color() : get_pixel(x,y); dst.put_pixel(x,y,col); } } - + if (mipmaps>0) dst.generate_mipmaps(); *this=dst; - + } void Image::flip_y() { - + if (!_can_modify(format)) { ERR_EXPLAIN("Cannot flip_y in indexed, compressed or custom image formats."); ERR_FAIL(); @@ -756,12 +756,12 @@ void Image::flip_y() { for (int y=0;y<(height/2);y++) { - + for (int x=0;x<width;x++) { Color up = get_pixel(x,y); Color down = get_pixel(x,height-y-1); - + put_pixel(x,y,down); put_pixel(x,height-y-1,up); } @@ -783,12 +783,12 @@ void Image::flip_x() { clear_mipmaps();; for (int y=0;y<(height/2);y++) { - + for (int x=0;x<width;x++) { - + Color up = get_pixel(x,y); Color down = get_pixel(width-x-1,y); - + put_pixel(x,y,down); put_pixel(width-x-1,y,up); } @@ -1040,26 +1040,26 @@ void Image::make_normalmap(float p_height_scale) { } ERR_FAIL_COND( empty() ); - + Image normalmap(width,height,0, FORMAT_RGB); /* for (int y=0;y<height;y++) { for (int x=0;x<width;x++) { - + float center=get_pixel(x,y).gray()/255.0; float up=(y>0)?get_pixel(x,y-1).gray()/255.0:center; float down=(y<(height-1))?get_pixel(x,y+1).gray()/255.0:center; float left=(x>0)?get_pixel(x-1,y).gray()/255.0:center; float right=(x<(width-1))?get_pixel(x+1,y).gray()/255.0:center; - - + + // uhm, how do i do this? .... - + Color result( (uint8_t)((normal.x+1.0)*127.0), (uint8_t)((normal.y+1.0)*127.0), (uint8_t)((normal.z+1.0)*127.0) ); - + normalmap.put_pixel( x, y, result ); } - + } */ *this=normalmap; @@ -1071,14 +1071,14 @@ bool Image::empty() const { } DVector<uint8_t> Image::get_data() const { - + return data; } void Image::create(int p_width, int p_height, bool p_use_mipmaps,Format p_format) { - int mm=0; + int mm=0; int size = _get_dst_image_size(p_width,p_height,p_format,mm,p_use_mipmaps?-1:0); data.resize( size ); { @@ -1095,7 +1095,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps,Format p_format } void Image::create(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data) { - + ERR_FAIL_INDEX(p_width-1,MAX_WIDTH); ERR_FAIL_INDEX(p_height-1,MAX_HEIGHT); @@ -1108,48 +1108,48 @@ void Image::create(int p_width, int p_height, int p_mipmaps, Format p_format, co ERR_FAIL_COND(p_data.size()!=size); } }; - + height=p_height; width=p_width; format=p_format; - data=p_data; + data=p_data; mipmaps=p_mipmaps; } void Image::create( const char ** p_xpm ) { - + int size_width,size_height; int pixelchars=0; mipmaps=0; bool has_alpha=false; - + enum Status { READING_HEADER, READING_COLORS, READING_PIXELS, DONE }; - + Status status = READING_HEADER; int line=0; - + HashMap<String,Color> colormap; int colormap_size; - + while (status!=DONE) { - + const char * line_ptr = p_xpm[line]; - - + + switch (status) { - + case READING_HEADER: { - + String line_str=line_ptr; line_str.replace("\t"," "); - + size_width=line_str.get_slicec(' ',0).to_int(); size_height=line_str.get_slicec(' ',1).to_int(); colormap_size=line_str.get_slicec(' ',2).to_int(); @@ -1161,10 +1161,10 @@ void Image::create( const char ** p_xpm ) { status=READING_COLORS; } break; case READING_COLORS: { - + String colorstring; for (int i=0;i<pixelchars;i++) { - + colorstring+=*line_ptr; line_ptr++; } @@ -1175,25 +1175,25 @@ void Image::create( const char ** p_xpm ) { line_ptr++; } if (*line_ptr=='c') { - + line_ptr++; while (*line_ptr==' ' || *line_ptr=='\t' || *line_ptr==0) { if (*line_ptr==0) break; line_ptr++; } - + if (*line_ptr=='#') { line_ptr++; uint8_t col_r; uint8_t col_g; uint8_t col_b; // uint8_t col_a=255; - + for (int i=0;i<6;i++) { - + char v = line_ptr[i]; - + if (v>='0' && v<='9') v-='0'; else if (v>='A' && v<='F') @@ -1202,7 +1202,7 @@ void Image::create( const char ** p_xpm ) { v=(v-'a')+10; else break; - + switch(i) { case 0: col_r=v<<4; break; case 1: col_r|=v; break; @@ -1211,48 +1211,48 @@ void Image::create( const char ** p_xpm ) { case 4: col_b=v<<4; break; case 5: col_b|=v; break; }; - + } - + // magenta mask if (col_r==255 && col_g==0 && col_b==255) { - + colormap[colorstring]=Color(0,0,0,0); has_alpha=true; } else { colormap[colorstring]=Color(col_r/255.0,col_g/255.0,col_b/255.0,1.0); } - + } } if (line==colormap_size) { - + status=READING_PIXELS; create(size_width,size_height,0,has_alpha?FORMAT_RGBA:FORMAT_RGB); } } break; case READING_PIXELS: { - + int y=line-colormap_size-1; for (int x=0;x<size_width;x++) { - + char pixelstr[6]={0,0,0,0,0,0}; for (int i=0;i<pixelchars;i++) pixelstr[i]=line_ptr[x*pixelchars+i]; - + Color *colorptr = colormap.getptr(pixelstr); ERR_FAIL_COND(!colorptr); put_pixel(x,y,*colorptr); - + } - + if (y==(size_height-1)) status=DONE; } break; default:{} } - + line++; } } @@ -2022,7 +2022,7 @@ Image Image::compressed(int p_mode) { }; Image::Image(const char **p_xpm) { - + width=0; height=0; mipmaps=0; diff --git a/core/image.h b/core/image.h index aea5dc6438..8f8fff755e 100644 --- a/core/image.h +++ b/core/image.h @@ -46,7 +46,7 @@ typedef Error (*SavePNGFunc)(const String &p_path, Image& p_img); class Image { - enum { + enum { MAX_WIDTH=16384, // force a limit somehow MAX_HEIGHT=16384// force a limit somehow }; @@ -55,12 +55,12 @@ public: static SavePNGFunc save_png_func; enum Format { - FORMAT_GRAYSCALE, ///< one byte per pixel, 0-255 - FORMAT_INTENSITY, ///< one byte per pixel, 0-255 - FORMAT_GRAYSCALE_ALPHA, ///< two bytes per pixel, 0-255. alpha 0-255 - FORMAT_RGB, ///< one byte R, one byte G, one byte B - FORMAT_RGBA, ///< one byte R, one byte G, one byte B, one byte A - FORMAT_INDEXED, ///< index byte 0-256, and after image end, 256*3 bytes of palette + FORMAT_GRAYSCALE, ///< one byte per pixel, 0-255 + FORMAT_INTENSITY, ///< one byte per pixel, 0-255 + FORMAT_GRAYSCALE_ALPHA, ///< two bytes per pixel, 0-255. alpha 0-255 + FORMAT_RGB, ///< one byte R, one byte G, one byte B + FORMAT_RGBA, ///< one byte R, one byte G, one byte B, one byte A + FORMAT_INDEXED, ///< index byte 0-256, and after image end, 256*3 bytes of palette FORMAT_INDEXED_ALPHA, ///< index byte 0-256, and after image end, 256*4 bytes of palette (alpha) FORMAT_YUV_422, FORMAT_YUV_444, @@ -89,7 +89,7 @@ public: static const char* format_names[FORMAT_MAX]; enum Interpolation { - + INTERPOLATE_NEAREST, INTERPOLATE_BILINEAR, INTERPOLATE_CUBIC, @@ -186,7 +186,7 @@ private: DVector<uint8_t> data; int width,height,mipmaps; - + _FORCE_INLINE_ BColor _get_pixel(int p_x,int p_y,const unsigned char *p_data,int p_data_size) const; _FORCE_INLINE_ BColor _get_pixelw(int p_x,int p_y,int p_width,const unsigned char *p_data,int p_data_size) const; @@ -207,7 +207,7 @@ public: int get_width() const; ///< Get image width int get_height() const; ///< Get image height int get_mipmaps() const; - + /** * Get a pixel from the image. for grayscale or indexed formats, use Color::gray to obtain the actual * value. @@ -217,7 +217,7 @@ public: * Set a pixel into the image. for grayscale or indexed formats, a suitable Color constructor. */ void put_pixel(int p_x,int p_y, const Color& p_color,int p_mipmap=0); /* alpha and index are averaged */ - + /** * Convert the image to another format, as close as it can be done. */ @@ -230,7 +230,7 @@ public: ret.convert((Format)p_new_format); return ret; }; - + /** * Get the current image format. */ @@ -243,7 +243,7 @@ public: /** * Resize the image, using the prefered interpolation method. * Indexed-Color images always use INTERPOLATE_NEAREST. - */ + */ void resize_to_po2(bool p_square=false); void resize( int p_width, int p_height, Interpolation p_interpolation=INTERPOLATE_BILINEAR ); @@ -252,22 +252,22 @@ public: * Crop the image to a specific size, if larger, then the image is filled by black */ void crop( int p_width, int p_height ); - - + + void flip_x(); void flip_y(); /** - * Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1) + * Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1) */ Error generate_mipmaps(int p_amount=-1,bool p_keep_existing=false); void clear_mipmaps(); - + /** * Generate a normal map from a grayscale image */ - + void make_normalmap(float p_height_scale=1.0); /** @@ -276,26 +276,26 @@ public: void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format); void create(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data); - void create( const char ** p_xpm ); + void create( const char ** p_xpm ); /** * returns true when the image is empty (0,0) in size */ bool empty() const; - + DVector<uint8_t> get_data() const; - + Error load(const String& p_path); Error save_png(const String& p_path); - - /** + + /** * create an empty image */ Image(); - /** + /** * create an empty image of a specific size and format */ Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format); - /** + /** * import an image of a specific size and format from a pointer */ Image(int p_width, int p_height, int p_mipmaps, Format p_format, const DVector<uint8_t>& p_data); @@ -313,7 +313,7 @@ public: uint8_t get_indexed_pixel(int p_x, int p_y,int p_mipmap=0) const; void set_pallete(const DVector<uint8_t>& p_data); - + static int get_format_pixel_size(Format p_format); static int get_format_pixel_rshift(Format p_format); static int get_format_pallete_size(Format p_format); diff --git a/core/input_map.cpp b/core/input_map.cpp index 874ce1c424..5a9b035771 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -38,7 +38,7 @@ void InputMap::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_action_from_id","id"),&InputMap::get_action_from_id); ObjectTypeDB::bind_method(_MD("add_action","action"),&InputMap::add_action); ObjectTypeDB::bind_method(_MD("erase_action","action"),&InputMap::erase_action); - + ObjectTypeDB::bind_method(_MD("action_add_event","action","event"),&InputMap::action_add_event); ObjectTypeDB::bind_method(_MD("action_has_event","action","event"),&InputMap::action_has_event); ObjectTypeDB::bind_method(_MD("action_erase_event","action","event"),&InputMap::action_erase_event); diff --git a/core/io/aes256.h b/core/io/aes256.h index fabbcf1968..8fcc25a4de 100644 --- a/core/io/aes256.h +++ b/core/io/aes256.h @@ -1,6 +1,6 @@ -/* +/* * Byte-oriented AES-256 implementation. -* All lookup tables replaced with 'on the fly' calculations. +* All lookup tables replaced with 'on the fly' calculations. * * Copyright (c) 2007-2009 Ilya O. Levin, http://www.literatecode.com * Other contributors: Hal Finney @@ -24,14 +24,14 @@ #include "typedefs.h" #ifdef __cplusplus -extern "C" { +extern "C" { #endif typedef struct { - uint8_t key[32]; - uint8_t enckey[32]; + uint8_t key[32]; + uint8_t enckey[32]; uint8_t deckey[32]; - } aes256_context; + } aes256_context; void aes256_init(aes256_context *, uint8_t * /* key */); diff --git a/core/io/fastlz.h b/core/io/fastlz.h index f87bc7be31..e5ca8dfc02 100644 --- a/core/io/fastlz.h +++ b/core/io/fastlz.h @@ -1,4 +1,4 @@ -/* +/* FastLZ - lightning-fast lossless compression library Copyright (C) 2007 Ariya Hidayat (ariya@kde.org) @@ -40,11 +40,11 @@ extern "C" { #endif /** - Compress a block of data in the input buffer and returns the size of - compressed block. The size of input buffer is specified by length. The + Compress a block of data in the input buffer and returns the size of + compressed block. The size of input buffer is specified by length. The minimum input buffer size is 16. - The output buffer must be at least 5% larger than the input buffer + The output buffer must be at least 5% larger than the input buffer and can not be smaller than 66 bytes. If the input is not compressible, the return value might be larger than @@ -56,9 +56,9 @@ extern "C" { int fastlz_compress(const void* input, int length, void* output); /** - Decompress a block of compressed data and returns the size of the - decompressed block. If error occurs, e.g. the compressed data is - corrupted or the output buffer is not large enough, then 0 (zero) + Decompress a block of compressed data and returns the size of the + decompressed block. If error occurs, e.g. the compressed data is + corrupted or the output buffer is not large enough, then 0 (zero) will be returned instead. The input buffer and the output buffer can not overlap. @@ -67,14 +67,14 @@ int fastlz_compress(const void* input, int length, void* output); more than what is specified in maxout. */ -int fastlz_decompress(const void* input, int length, void* output, int maxout); +int fastlz_decompress(const void* input, int length, void* output, int maxout); /** - Compress a block of data in the input buffer and returns the size of - compressed block. The size of input buffer is specified by length. The + Compress a block of data in the input buffer and returns the size of + compressed block. The size of input buffer is specified by length. The minimum input buffer size is 16. - The output buffer must be at least 5% larger than the input buffer + The output buffer must be at least 5% larger than the input buffer and can not be smaller than 66 bytes. If the input is not compressible, the return value might be larger than @@ -82,14 +82,14 @@ int fastlz_decompress(const void* input, int length, void* output, int maxout); The input buffer and the output buffer can not overlap. - Compression level can be specified in parameter level. At the moment, + Compression level can be specified in parameter level. At the moment, only level 1 and level 2 are supported. Level 1 is the fastest compression and generally useful for short data. Level 2 is slightly slower but it gives better compression ratio. Note that the compressed data, regardless of the level, can always be decompressed using the function fastlz_decompress above. -*/ +*/ int fastlz_compress_level(int level, const void* input, int length, void* output); diff --git a/core/io/file_access_buffered.cpp b/core/io/file_access_buffered.cpp index b38fda3686..e6b01475b6 100644 --- a/core/io/file_access_buffered.cpp +++ b/core/io/file_access_buffered.cpp @@ -33,17 +33,17 @@ #include "error_macros.h" Error FileAccessBuffered::set_error(Error p_error) const { - + return (last_error = p_error); }; void FileAccessBuffered::set_cache_size(int p_size) { - + cache_size = p_size; }; int FileAccessBuffered::get_cache_size() { - + return cache_size; }; @@ -66,27 +66,27 @@ int FileAccessBuffered::cache_data_left() const { }; void FileAccessBuffered::seek(size_t p_position) { - + file.offset = p_position; }; void FileAccessBuffered::seek_end(int64_t p_position) { - + file.offset = file.size + p_position; }; size_t FileAccessBuffered::get_pos() const { - + return file.offset; }; size_t FileAccessBuffered::get_len() const { - + return file.size; }; bool FileAccessBuffered::eof_reached() const { - + return file.offset > file.size; }; @@ -165,12 +165,12 @@ int FileAccessBuffered::get_buffer(uint8_t *p_dest,int p_elements) const { }; bool FileAccessBuffered::is_open() const { - + return file.open; }; Error FileAccessBuffered::get_error() const { - + return last_error; }; @@ -180,5 +180,5 @@ FileAccessBuffered::FileAccessBuffered() { }; FileAccessBuffered::~FileAccessBuffered(){ - + } diff --git a/core/io/file_access_buffered.h b/core/io/file_access_buffered.h index 9d405e15f7..058c26b8a9 100644 --- a/core/io/file_access_buffered.h +++ b/core/io/file_access_buffered.h @@ -60,9 +60,9 @@ protected: String name; int access_flags; } file; - + mutable struct Cache { - + Vector<uint8_t> buffer; int offset; } cache; @@ -71,7 +71,7 @@ protected: void set_cache_size(int p_size); int get_cache_size(); - + public: virtual size_t get_pos() const; ///< get position in the file diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index e63b57533f..a3c839e761 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -217,7 +217,7 @@ Error FileAccessNetworkClient::connect(const String& p_host,int p_port,const Str return ERR_CANT_CONNECT; } - CharString cs = p_password.utf8(); + CharString cs = p_password.utf8(); put_32(cs.length()); client->put_data((const uint8_t*)cs.ptr(),cs.length()); diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index dd53c8f8eb..e0c01c9422 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -305,7 +305,7 @@ Error HTTPClient::poll(){ String header = responses[i].strip_edges(); String s = header.to_lower(); if (s.length()==0) - continue; + continue; if (s.begins_with("content-length:")) { body_size = s.substr(s.find(":")+1,s.length()).strip_edges().to_int(); body_left=body_size; diff --git a/core/io/image_loader.cpp b/core/io/image_loader.cpp index aa641f00b4..05bad97e90 100644 --- a/core/io/image_loader.cpp +++ b/core/io/image_loader.cpp @@ -30,16 +30,16 @@ #include "print_string.h" bool ImageFormatLoader::recognize(const String& p_extension) const { - - + + List<String> extensions; get_recognized_extensions(&extensions); for (List<String>::Element *E=extensions.front();E;E=E->next()) { - + if (E->get().nocasecmp_to(p_extension.extension())==0) return true; } - + return false; } @@ -55,12 +55,12 @@ Error ImageLoader::load_image(String p_file,Image *p_image, FileAccess *p_custom return err; } } - + String extension = p_file.extension(); for (int i=0;i<loader_count;i++) { - + if (!loader[i]->recognize(extension)) continue; Error err = loader[i]->load_image(p_image,f); @@ -73,25 +73,25 @@ Error ImageLoader::load_image(String p_file,Image *p_image, FileAccess *p_custom return err; } - - + + } print_line("NO LOADER?"); if (!p_custom) - memdelete(f); - + memdelete(f); + return ERR_FILE_UNRECOGNIZED; } void ImageLoader::get_recognized_extensions(List<String> *p_extensions) { - + for (int i=0;i<loader_count;i++) { - + loader[i]->get_recognized_extensions(p_extensions); - - } + + } } bool ImageLoader::recognize(const String& p_extension) { diff --git a/core/io/image_loader.h b/core/io/image_loader.h index 3cc6c6cf43..c799837792 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -41,11 +41,11 @@ /** * @class ImageScanLineLoader * @author Juan Linietsky <reduzio@gmail.com> - * - + * + */ class ImageLoader; - + /** * @class ImageLoader @@ -60,8 +60,8 @@ protected: virtual Error load_image(Image *p_image,FileAccess *p_fileaccess)=0; virtual void get_recognized_extensions(List<String> *p_extensions) const=0; bool recognize(const String& p_extension) const; - - + + public: virtual ~ImageFormatLoader() {} }; @@ -79,11 +79,11 @@ protected: public: - + static Error load_image(String p_file,Image *p_image, FileAccess *p_custom=NULL); static void get_recognized_extensions(List<String> *p_extensions) ; static bool recognize(const String& p_extension) ; - + static void add_image_format_loader(ImageFormatLoader *p_loader); }; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index b8bd00c2fb..a77aace07f 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -49,7 +49,7 @@ struct _IP_ResolverPrivate { response = IP_Address(); hostname=""; }; - + QueueItem() { clear(); }; diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 4dccf21d2d..1733aecd46 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -95,7 +95,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int * str.parse_utf8((const char*)buf,strlen); r_variant=str; - if (r_len) { + if (r_len) { if (strlen%4) (*r_len)+=4-strlen%4; (*r_len)+=4+strlen; @@ -294,7 +294,7 @@ Error decode_variant(Variant& r_variant,const uint8_t *p_buffer, int p_len,int * } break; case Variant::NODE_PATH: { - ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA); + ERR_FAIL_COND_V(len<4,ERR_INVALID_DATA); uint32_t strlen = decode_uint32(buf); if (strlen&0x80000000) { @@ -1077,7 +1077,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) { r_len+=data.size()+5*4+pad; - } break; + } break; /*case Variant::RESOURCE: { ERR_EXPLAIN("Can't marshallize resources"); @@ -1238,7 +1238,7 @@ Error encode_variant(const Variant& p_variant, uint8_t *r_buffer, int &r_len) { DVector<uint8_t> data = p_variant; int datalen=data.size(); int datasize=sizeof(uint8_t); - + if (buf) { encode_uint32(datalen,buf); buf+=4; diff --git a/core/io/marshalls.h b/core/io/marshalls.h index 7a5b16e8af..6a46e9882a 100644 --- a/core/io/marshalls.h +++ b/core/io/marshalls.h @@ -37,7 +37,7 @@ * Miscelaneous helpers for marshalling data types, and encoding * in an endian independent way */ - + union MarshallFloat { @@ -54,22 +54,22 @@ union MarshallDouble { static inline unsigned int encode_uint16(uint16_t p_uint, uint8_t *p_arr) { for (int i=0;i<2;i++) { - + *p_arr=p_uint&0xFF; p_arr++; p_uint>>=8; } - + return sizeof( uint16_t ); } static inline unsigned int encode_uint32(uint32_t p_uint, uint8_t *p_arr) { for (int i=0;i<4;i++) { - + *p_arr=p_uint&0xFF; p_arr++; p_uint>>=8; } - + return sizeof( uint32_t ); } @@ -85,11 +85,11 @@ static inline unsigned int encode_float(float p_float, uint8_t *p_arr) { static inline unsigned int encode_uint64(uint64_t p_uint, uint8_t *p_arr) { for (int i=0;i<8;i++) { - + *p_arr=p_uint&0xFF; p_arr++; p_uint>>=8; } - + return sizeof(uint64_t); } @@ -100,25 +100,25 @@ static inline unsigned int encode_double(double p_double, uint8_t *p_arr) { encode_uint64( md.l, p_arr ); return sizeof(uint64_t); - + } static inline int encode_cstring(const char *p_string, uint8_t * p_data) { int len=0; - + while (*p_string) { if (p_data) { - + *p_data=(uint8_t)*p_string; p_data++; } p_string++; len++; }; - + if (p_data) *p_data = 0; return len+1; } @@ -126,35 +126,35 @@ static inline int encode_cstring(const char *p_string, uint8_t * p_data) { static inline uint16_t decode_uint16(const uint8_t *p_arr) { uint16_t u=0; - + for (int i=0;i<2;i++) { - + uint16_t b = *p_arr; b<<=(i*8); u|=b; p_arr++; } - + return u; } static inline uint32_t decode_uint32(const uint8_t *p_arr) { uint32_t u=0; - + for (int i=0;i<4;i++) { - + uint32_t b = *p_arr; b<<=(i*8); u|=b; p_arr++; } - + return u; } static inline float decode_float(const uint8_t *p_arr) { - + MarshallFloat mf; mf.i = decode_uint32(p_arr); return mf.f; @@ -163,15 +163,15 @@ static inline float decode_float(const uint8_t *p_arr) { static inline uint64_t decode_uint64(const uint8_t *p_arr) { uint64_t u=0; - + for (int i=0;i<8;i++) { - + uint64_t b = (*p_arr)&0xFF; b<<=(i*8); u|=b; p_arr++; } - + return u; } diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index 973a2ec9a5..22b8bc0b39 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -180,10 +180,10 @@ int PacketPeerStream::get_available_packet_count() const { ring_buffer.copy(lbuf,ofs,4); uint32_t len = decode_uint32(lbuf); remaining-=4; - ofs+=4; + ofs+=4; if (len>remaining) break; - remaining-=len; + remaining-=len; ofs+=len; count++; } @@ -201,7 +201,7 @@ Error PacketPeerStream::get_packet(const uint8_t **r_buffer,int &r_buffer_size) uint8_t lbuf[4]; ring_buffer.copy(lbuf,0,4); remaining-=4; - uint32_t len = decode_uint32(lbuf); + uint32_t len = decode_uint32(lbuf); ERR_FAIL_COND_V(remaining<(int)len,ERR_UNAVAILABLE); ring_buffer.read(lbuf,4); //get rid of first 4 bytes diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index c008c3f9a4..58f3a4df2b 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -378,7 +378,7 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant& r_v) { } break; case OBJECT_INTERNAL_RESOURCE: { uint32_t index=f->get_32(); - String path = res_path+"::"+itos(index); + String path = res_path+"::"+itos(index); RES res = ResourceLoader::load(path); if (res.is_null()) { WARN_PRINT(String("Couldn't load resource: "+path).utf8().get_data()); @@ -2100,7 +2100,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path,const RES& p_ p.value=E->get()->get(F->get().name); if ((F->get().usage&PROPERTY_USAGE_STORE_IF_NONZERO && p.value.is_zero())||(F->get().usage&PROPERTY_USAGE_STORE_IF_NONONE && p.value.is_one()) ) continue; - p.pi=F->get(); + p.pi=F->get(); rd.properties.push_back(p); diff --git a/core/io/resource_format_xml.cpp b/core/io/resource_format_xml.cpp index 03b77a4aab..a42a922baf 100644 --- a/core/io/resource_format_xml.cpp +++ b/core/io/resource_format_xml.cpp @@ -1818,7 +1818,7 @@ Error ResourceInteractiveLoaderXML::rename_dependencies(FileAccess *p_f, const S void ResourceInteractiveLoaderXML::open(FileAccess *p_f) { - error=OK; + error=OK; lines=1; f=p_f; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 67208b5960..abb1082256 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -49,16 +49,16 @@ Error ResourceInteractiveLoader::wait() { bool ResourceFormatLoader::recognize(const String& p_extension) const { - - + + List<String> extensions; get_recognized_extensions(&extensions); for (List<String>::Element *E=extensions.front();E;E=E->next()) { - + if (E->get().nocasecmp_to(p_extension.extension())==0) return true; } - + return false; } @@ -184,9 +184,9 @@ RES ResourceLoader::load(const String &p_path, const String& p_type_hint, bool p String extension=remapped_path.extension(); bool found=false; - + for (int i=0;i<loader_count;i++) { - + if (!loader[i]->recognize(extension)) continue; if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) @@ -356,7 +356,7 @@ Ref<ResourceInteractiveLoader> ResourceLoader::load_interactive(const String &p_ } void ResourceLoader::add_resource_format_loader(ResourceFormatLoader *p_format_loader) { - + ERR_FAIL_COND( loader_count >= MAX_LOADERS ); loader[loader_count++]=p_format_loader; } diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index fe58303066..6404e6cb13 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -47,7 +47,7 @@ public: virtual Ref<Resource> get_resource()=0; virtual Error poll()=0; virtual int get_stage() const=0; - virtual int get_stage_count() const=0; + virtual int get_stage_count() const=0; virtual Error wait(); ResourceInteractiveLoader() {} @@ -76,12 +76,12 @@ typedef void (*ResourceLoadErrorNotify)(void *p_ud,const String& p_text); typedef void (*DependencyErrorNotify)(void *p_ud,const String& p_loading,const String& p_which,const String& p_type); -class ResourceLoader { - +class ResourceLoader { + enum { MAX_LOADERS=64 }; - + static ResourceFormatLoader *loader[MAX_LOADERS]; static int loader_count; static bool timestamp_on_load; @@ -96,7 +96,7 @@ class ResourceLoader { public: - + static Ref<ResourceInteractiveLoader> load_interactive(const String &p_path,const String& p_type_hint="",bool p_no_cache=false,Error *r_error=NULL); static RES load(const String &p_path,const String& p_type_hint="",bool p_no_cache=false,Error *r_error=NULL); static Ref<ResourceImportMetadata> load_import_metadata(const String &p_path); diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 51020a0285..8d78ecabbf 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -39,30 +39,30 @@ bool ResourceSaver::timestamp_on_save=false; ResourceSavedCallback ResourceSaver::save_callback=0; Error ResourceSaver::save(const String &p_path,const RES& p_resource,uint32_t p_flags) { - + String extension=p_path.extension(); Error err=ERR_FILE_UNRECOGNIZED; for (int i=0;i<saver_count;i++) { - + if (!saver[i]->recognize(p_resource)) continue; - + List<String> extensions; bool recognized=false; saver[i]->get_recognized_extensions(p_resource,&extensions); - + for (List<String>::Element *E=extensions.front();E;E=E->next()) { - + if (E->get().nocasecmp_to(extension.extension())==0) recognized=true; } if (!recognized) continue; - + String old_path=p_resource->get_path(); - + String local_path=Globals::get_singleton()->localize_path(p_path); @@ -92,10 +92,10 @@ Error ResourceSaver::save(const String &p_path,const RES& p_resource,uint32_t p_ return OK; } else { - + } } - + return err; } @@ -108,16 +108,16 @@ void ResourceSaver::set_save_callback(ResourceSavedCallback p_callback) { void ResourceSaver::get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) { - + for (int i=0;i<saver_count;i++) { - + saver[i]->get_recognized_extensions(p_resource,p_extensions); } - + } void ResourceSaver::add_resource_format_saver(ResourceFormatSaver *p_format_saver) { - + ERR_FAIL_COND( saver_count >= MAX_SAVERS ); saver[saver_count++]=p_format_saver; } diff --git a/core/io/resource_saver.h b/core/io/resource_saver.h index 7bc96c1087..97500c46f4 100644 --- a/core/io/resource_saver.h +++ b/core/io/resource_saver.h @@ -42,7 +42,7 @@ class ResourceFormatSaver { public: - + virtual Error save(const String &p_path,const RES& p_resource,uint32_t p_flags=0)=0; virtual bool recognize(const RES& p_resource) const=0; virtual void get_recognized_extensions(const RES& p_resource,List<String> *p_extensions) const=0; @@ -52,12 +52,12 @@ public: typedef void (*ResourceSavedCallback)(const String& p_path); -class ResourceSaver { - +class ResourceSaver { + enum { MAX_SAVERS=64 }; - + static ResourceFormatSaver *saver[MAX_SAVERS]; static int saver_count; static bool timestamp_on_save; @@ -86,7 +86,7 @@ public: static void set_save_callback(ResourceSavedCallback p_callback); - + }; diff --git a/core/list.h b/core/list.h index fbeb653da4..b989f009a9 100644 --- a/core/list.h +++ b/core/list.h @@ -245,7 +245,7 @@ public: _data->first=n; _data->size_cache++; - + return n; }; @@ -285,7 +285,7 @@ public: _data->last=n; _data->size_cache++; - + return n; }; @@ -363,30 +363,30 @@ public: } void swap(Element* p_A, Element *p_B) { - + ERR_FAIL_COND(!p_A || !p_B); ERR_FAIL_COND(p_A->data!=_data); ERR_FAIL_COND(p_B->data!=_data); - + Element* A_prev=p_A->prev_ptr; Element* A_next=p_A->next_ptr; - + p_A->next_ptr=p_B->next_ptr; p_A->prev_ptr=p_B->prev_ptr; - + p_B->next_ptr=A_next; - p_B->prev_ptr=A_prev; - + p_B->prev_ptr=A_prev; + if (p_A->prev_ptr) p_A->prev_ptr->next_ptr=p_A; if (p_A->next_ptr) - p_A->next_ptr->prev_ptr=p_A; - + p_A->next_ptr->prev_ptr=p_A; + if (p_B->prev_ptr) p_B->prev_ptr->next_ptr=p_B; if (p_B->next_ptr) - p_B->next_ptr->prev_ptr=p_B; - + p_B->next_ptr->prev_ptr=p_B; + } /** * copy the list @@ -552,10 +552,10 @@ public: */ void sort() { - + sort_custom< Comparator<T> >(); } - + template<class C> void sort_custom_inplace() { @@ -565,44 +565,44 @@ public: Element *from=front(); Element *current=from; Element *to=from; - + while(current) { - + Element *next=current->next_ptr; - + //disconnect current->next_ptr=NULL; - + if (from!=current) { - + current->prev_ptr=NULL; current->next_ptr=from; - + Element *find=from; C less; while( find && less(find->value,current->value) ) { - + current->prev_ptr=find; current->next_ptr=find->next_ptr; find=find->next_ptr; } - + if (current->prev_ptr) current->prev_ptr->next_ptr=current; else from=current; - + if (current->next_ptr) current->next_ptr->prev_ptr=current; else to=current; } else { - + current->prev_ptr=NULL; current->next_ptr=NULL; - + } - + current=next; } _data->first=from; diff --git a/core/map.h b/core/map.h index 35dc73df48..81cda1ece2 100644 --- a/core/map.h +++ b/core/map.h @@ -39,12 +39,12 @@ template <class K,class V,class C=Comparator<K>,class A=DefaultAllocator> class Map { - - enum Color { + + enum Color { RED, BLACK }; - struct _Data; + struct _Data; public: class Element { @@ -66,34 +66,34 @@ public: public: const Element *next() const { - + return _next; } Element *next() { - + return _next; } const Element *prev() const { - + return _prev; } Element *prev() { - + return _prev; } - const K& key() const { + const K& key() const { return _key; }; - V& value() { + V& value() { return _value; }; - const V& value() const { + const V& value() const { return _value; }; - V& get() { + V& get() { return _value; }; - const V& get() const { + const V& get() const { return _value; }; Element() { @@ -106,15 +106,15 @@ public: }; }; - + private: struct _Data { - + Element* _root; Element* _nil; int size_cache; - + _FORCE_INLINE_ _Data() { #ifdef GLOBALNIL_DISABLED _nil = memnew_allocator( Element, A ); @@ -126,7 +126,7 @@ private: _root=NULL; size_cache=0; } - + void _create_root() { _root = memnew_allocator( Element,A ); @@ -145,23 +145,23 @@ private: ~_Data() { _free_root(); - + #ifdef GLOBALNIL_DISABLED memdelete_allocator<Element,A>(_nil); #endif // memdelete_allocator<Element,A>(_root); } }; - + _Data _data; - + inline void _set_color(Element *p_node, int p_color) { - + ERR_FAIL_COND( p_node == _data._nil && p_color == RED ); p_node->color=p_color; } inline void _rotate_left(Element *p_node) { - + Element *r=p_node->right; p_node->right=r->left; if (r->left != _data._nil ) @@ -171,14 +171,14 @@ private: p_node->parent->left=r; else p_node->parent->right=r; - + r->left=p_node; p_node->parent=r; - + } - + inline void _rotate_right(Element *p_node) { - + Element *l=p_node->left; p_node->left=l->right; if (l->right != _data._nil) @@ -188,25 +188,25 @@ private: p_node->parent->right=l; else p_node->parent->left=l; - + l->right=p_node; p_node->parent=l; - + } - - inline Element* _successor(Element *p_node) const { - + + inline Element* _successor(Element *p_node) const { + Element *node=p_node; - + if (node->right != _data._nil) { - + node=node->right; while(node->left != _data._nil) { /* returns the minium of the right subtree of node */ node=node->left; } return node; } else { - + while(node == node->parent->right) { node=node->parent; } @@ -215,44 +215,44 @@ private: return node->parent; } } - - inline Element* _predecessor(Element *p_node) const { + + inline Element* _predecessor(Element *p_node) const { Element *node=p_node; - + if (node->left != _data._nil) { - + node=node->left; while(node->right != _data._nil) { /* returns the minium of the left subtree of node */ node=node->right; } return node; } else { - + while(node == node->parent->left) { if (node->parent == _data._root) - return NULL; + return NULL; node=node->parent; } return node->parent; } } - - + + Element *_find(const K& p_key) const { - + Element *node = _data._root->left; - C less; - + C less; + while(node!=_data._nil) { - - if (less(p_key,node->_key)) + + if (less(p_key,node->_key)) node=node->left; else if (less(node->_key,p_key)) node=node->right; else break; // found } - + return (node!=_data._nil)?node:NULL; } @@ -289,73 +289,73 @@ private: } Element *_insert(const K& p_key, bool& r_exists) { - + Element *new_parent=_data._root; Element *node = _data._root->left; - C less; - + C less; + while (node!=_data._nil) { - + new_parent=node; - + if (less(p_key,node->_key)) node=node->left; else if (less(node->_key,p_key)) node=node->right; - else { + else { r_exists=true; return node; - } + } } - + Element *new_node = memnew_allocator( Element, A ); - + new_node->parent=new_parent; new_node->right=_data._nil; new_node->left=_data._nil; new_node->_key=p_key; //new_node->data=_data; if (new_parent==_data._root || less(p_key,new_parent->_key)) { - + new_parent->left=new_node; } else { new_parent->right=new_node; } - + r_exists=false; - + new_node->_next=_successor(new_node); new_node->_prev=_predecessor(new_node); if (new_node->_next) new_node->_next->_prev=new_node; if (new_node->_prev) new_node->_prev->_next=new_node; - + return new_node; } - + Element * _insert_rb(const K& p_key, const V& p_value) { - + bool exists=false; Element *new_node = _insert(p_key,exists); - + if (new_node) { new_node->_value=p_value; } if (exists) return new_node; - + Element *node=new_node; _data.size_cache++; - while(node->parent->color==RED) { - + while(node->parent->color==RED) { + if (node->parent == node->parent->parent->left) { - + Element *aux=node->parent->parent->right; - + if (aux->color==RED) { _set_color(node->parent,BLACK); _set_color(aux,BLACK); @@ -369,10 +369,10 @@ private: _set_color(node->parent,BLACK); _set_color(node->parent->parent,RED); _rotate_right(node->parent->parent); - } - } else { + } + } else { Element *aux=node->parent->parent->left; - + if (aux->color==RED) { _set_color(node->parent,BLACK); _set_color(aux,BLACK); @@ -386,19 +386,19 @@ private: _set_color(node->parent,BLACK); _set_color(node->parent->parent,RED); _rotate_left(node->parent->parent); - } + } } } _set_color(_data._root->left,BLACK); - return new_node; - } + return new_node; + } void _erase_fix(Element *p_node) { - + Element *root = _data._root->left; Element *node=p_node; - - + + while( (node->color==BLACK) && (root != node)) { if (node == node->parent->left) { Element *aux=node->parent->right; @@ -408,7 +408,7 @@ private: _rotate_left(node->parent); aux=node->parent->right; } - if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) { + if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) { _set_color(aux,RED); node=node->parent; } else { @@ -432,7 +432,7 @@ private: _rotate_right(node->parent); aux=node->parent->left; } - if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) { + if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) { _set_color(aux,RED); node=node->parent; } else { @@ -446,24 +446,24 @@ private: _set_color(node->parent,BLACK); _set_color(aux->left,BLACK); _rotate_right(node->parent); - node=root; + node=root; } } } - + _set_color(node,BLACK); - + ERR_FAIL_COND(_data._nil->color!=BLACK); } - + void _erase(Element *p_node) { - - + + Element *rp= ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : _successor(p_node); if (!rp) rp=_data._nil; Element *node= (rp->left == _data._nil) ? rp->right : rp->left; - + if (_data._root == (node->parent=rp->parent) ) { _data._root->left=node; } else { @@ -473,47 +473,47 @@ private: rp->parent->right=node; } } - - if (rp != p_node) { - + + if (rp != p_node) { + ERR_FAIL_COND( rp == _data._nil ); - + if (rp->color==BLACK) _erase_fix(node); - - + + rp->left=p_node->left; rp->right=p_node->right; rp->parent=p_node->parent; rp->color=p_node->color; p_node->left->parent=rp; p_node->right->parent=rp; - + if (p_node == p_node->parent->left) { - p_node->parent->left=rp; + p_node->parent->left=rp; } else { p_node->parent->right=rp; } } else { - if (p_node->color==BLACK) + if (p_node->color==BLACK) _erase_fix(node); - + } - - + + if (p_node->_next) p_node->_next->_prev=p_node->_prev; if (p_node->_prev) p_node->_prev->_next=p_node->_next; - + memdelete_allocator<Element,A>(p_node); _data.size_cache--; ERR_FAIL_COND( _data._nil->color==RED ); } - - + + void _calculate_depth(Element *p_element,int &max_d,int d) const { - + if (p_element==_data._nil) { return; } @@ -522,23 +522,23 @@ private: if (d>max_d) max_d=d; } - + void _cleanup_tree(Element *p_element) { - + if (p_element==_data._nil) return; - + _cleanup_tree(p_element->left); _cleanup_tree(p_element->right); memdelete_allocator<Element,A>( p_element ); } - + void _copy_from( const Map& p_map) { - + clear(); // not the fastest way, but safeset to write. for(Element *I=p_map.front();I;I=I->next()) { - + insert(I->key(),I->value()); } } @@ -554,7 +554,7 @@ public: } Element *find(const K& p_key) { - + if (!_data._root) return NULL; Element *res=_find(p_key); @@ -578,15 +578,15 @@ public: } Element *insert(const K& p_key,const V& p_value) { - + if (!_data._root) _data._create_root(); return _insert_rb(p_key,p_value); - + } - + void erase(Element* p_element) { - + if (!_data._root) return; _erase(p_element); @@ -595,72 +595,72 @@ public: } bool erase(const K& p_key) { - + if (!_data._root) return false; Element *e=find(p_key); if (!e) return false; - _erase(e); + _erase(e); return true; } - + bool has(const K& p_key) const { - + if (!_data._root) return false; return find(p_key) != NULL; } - + const V& operator[](const K& p_key) const { - + ERR_FAIL_COND_V(!_data._root, *(V*)NULL); // crash on purpose const Element *e=find(p_key); ERR_FAIL_COND_V(!e, *(V*)NULL); // crash on purpose return e->_value; } V& operator[](const K& p_key) { - + if (!_data._root) _data._create_root(); Element *e=find(p_key); if (!e) e=insert(p_key,V()); - - ERR_FAIL_COND_V(!e, *(V*)NULL); // crash on purpose + + ERR_FAIL_COND_V(!e, *(V*)NULL); // crash on purpose return e->_value; } - + Element *front() const { - + if (!_data._root) return NULL; Element *e=_data._root->left; if (e==_data._nil) return NULL; - + while(e->left!=_data._nil) e=e->left; - + return e; } - + Element *back() const { - + if (!_data._root) return NULL; Element *e=_data._root->left; if (e==_data._nil) return NULL; - + while(e->right!=_data._nil) e=e->right; - + return e; } - + inline bool empty() const { return _data.size_cache==0; } inline int size() const { return _data.size_cache; } int calculate_depth() const { @@ -671,9 +671,9 @@ public: _calculate_depth(_data._root->left,max_d,0); return max_d; } - + void clear() { - + if (!_data._root) return; _cleanup_tree(_data._root->left); @@ -682,25 +682,25 @@ public: _data._nil->parent=_data._nil; _data._free_root(); } - + void operator=(const Map& p_map) { - + _copy_from( p_map ); } - + Map(const Map& p_map) { - + _copy_from( p_map ); } _FORCE_INLINE_ Map() { - + } - - + + ~Map() { - - clear(); + + clear(); } }; diff --git a/core/math/aabb.h b/core/math/aabb.h index 0fada859c0..57fe1b32f5 100644 --- a/core/math/aabb.h +++ b/core/math/aabb.h @@ -47,21 +47,21 @@ public: float get_area() const; /// get area _FORCE_INLINE_ bool has_no_area() const { - + return (size.x<=CMP_EPSILON || size.y<=CMP_EPSILON || size.z<=CMP_EPSILON); } _FORCE_INLINE_ bool has_no_surface() const { - + return (size.x<=CMP_EPSILON && size.y<=CMP_EPSILON && size.z<=CMP_EPSILON); } - + const Vector3& get_pos() const { return pos; } void set_pos(const Vector3& p_pos) { pos=p_pos; } const Vector3& get_size() const { return size; } void set_size(const Vector3& p_size) { size=p_size; } - + bool operator==(const AABB& p_rval) const; bool operator!=(const AABB& p_rval) const; @@ -265,7 +265,7 @@ bool AABB::has_point(const Vector3& p_point) const { return false; if (p_point.z>pos.z+size.z) return false; - + return true; } @@ -297,11 +297,11 @@ void AABB::project_range_in_plane(const Plane& p_plane,float &r_min,float& r_max Vector3 half_extents( size.x * 0.5, size.y * 0.5, size.z * 0.5 ); Vector3 center( pos.x + half_extents.x, pos.y + half_extents.y, pos.z + half_extents.z ); - + float length = p_plane.normal.abs().dot(half_extents); float distance = p_plane.distance_to( center ); r_min = distance - length; - r_max = distance + length; + r_max = distance + length; } inline real_t AABB::get_longest_axis_size() const { diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp index 0c07b733f0..d16495217c 100644 --- a/core/math/bsp_tree.cpp +++ b/core/math/bsp_tree.cpp @@ -66,12 +66,12 @@ Vector<Plane> BSP_Tree::get_planes() const { return planes; } - + AABB BSP_Tree::get_aabb() const { return aabb; } - + int BSP_Tree::_get_points_inside(int p_node,const Vector3* p_points,int *p_indices, const Vector3& p_center,const Vector3& p_half_extents,int p_indices_count) const { @@ -245,22 +245,22 @@ bool BSP_Tree::point_is_inside(const Vector3& p_point) const { if (!aabb.has_point(p_point)) { return false; } - + int node_count=nodes.size(); - + if (node_count==0) // no nodes! return false; - - + + const Node *nodesptr=&nodes[0]; const Plane *planesptr=&planes[0]; int plane_count=planes.size(); - + int idx=node_count-1; int steps=0; - + while(true) { - + if (idx==OVER_LEAF) { return false; } @@ -268,28 +268,28 @@ bool BSP_Tree::point_is_inside(const Vector3& p_point) const { return true; } - + uint16_t plane=nodesptr[ idx ].plane; #ifdef DEBUG_ENABLED - + ERR_FAIL_INDEX_V( plane, plane_count, false ); #endif bool over = planesptr[ nodesptr[ idx ].plane ].is_point_over(p_point); idx = over ? nodes[ idx ].over : nodes[ idx ].under; - + #ifdef DEBUG_ENABLED - + ERR_FAIL_COND_V( idx<MAX_NODES && idx>=node_count, false ); #endif - + steps++; } return false; } - - + + static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_indices,float p_tolerance) { int ic = p_indices.size(); @@ -304,7 +304,7 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i const Face3& f=p_faces[ indices[i] ]; Plane p = f.get_plane(); - + int num_over=0,num_under=0,num_spanning=0; for(int j=0;j<ic;j++) { @@ -335,17 +335,17 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i num_over++; else num_under++; - + } //double split_cost = num_spanning / (double) face_count; double relation = Math::abs(num_over-num_under) / (double) ic; - + // being honest, i never found a way to add split cost to the mix in a meaninguful way // in this engine, also, will likely be ignored anyway - + double plane_cost = /*split_cost +*/ relation; //printf("plane %i, %i over, %i under, %i spanning, cost is %g\n",i,num_over,num_under,num_spanning,plane_cost); @@ -360,10 +360,10 @@ static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector<int>& p_i return best_plane; } - + static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Vector<Plane> &p_planes, Vector<BSP_Tree::Node> &p_nodes,float p_tolerance) { - + ERR_FAIL_COND_V( p_nodes.size() == BSP_Tree::MAX_NODES, -1 ); // should not reach here @@ -387,7 +387,7 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve if (i==divisor_idx) continue; - + const Face3& f=p_faces[ indices[i] ]; //if (f.get_plane().is_almost_like(divisor_plane)) @@ -416,7 +416,7 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve } - + uint16_t over_idx=BSP_Tree::OVER_LEAF,under_idx=BSP_Tree::UNDER_LEAF; if (faces_over.size()>0) { //have facess above? @@ -434,13 +434,13 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve } /* Create the node */ - + // find existing divisor plane int divisor_plane_idx=-1; - - + + for (int i=0;i<p_planes.size();i++) { - + if (p_planes[i].is_almost_like( divisor_plane )) { divisor_plane_idx=i; break; @@ -448,22 +448,22 @@ static int _bsp_create_node(const Face3 *p_faces,const Vector<int>& p_indices,Ve } if (divisor_plane_idx==-1) { - + ERR_FAIL_COND_V( p_planes.size() == BSP_Tree::MAX_PLANES, -1 ); divisor_plane_idx=p_planes.size(); p_planes.push_back( divisor_plane ); } - + BSP_Tree::Node node; node.plane=divisor_plane_idx; node.under=under_idx; node.over=over_idx; - + p_nodes.push_back(node); - + return p_nodes.size()-1; } - + BSP_Tree::operator Variant() const { @@ -563,7 +563,7 @@ BSP_Tree::BSP_Tree(const Variant& p_variant) { BSP_Tree::BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius) { // compute aabb - + int face_count=p_faces.size(); DVector<Face3>::Read faces_r=p_faces.read(); const Face3 *facesptr = faces_r.ptr(); @@ -574,26 +574,26 @@ BSP_Tree::BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius) { Vector<int> indices; for (int i=0;i<face_count;i++) { - + const Face3& f=facesptr[i]; - + if (f.is_degenerate()) continue; - + for (int j=0;j<3;j++) { - + if (first) { - + aabb.pos=f.vertex[0]; first=false; } else { - + aabb.expand_to(f.vertex[j]); } } indices.push_back(i); - + } ERR_FAIL_COND( aabb.has_no_area() ); @@ -609,7 +609,7 @@ BSP_Tree::BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius) { - + error_radius=p_error_radius; } diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h index a7145f9ff1..2bfc26b51e 100644 --- a/core/math/bsp_tree.h +++ b/core/math/bsp_tree.h @@ -43,7 +43,7 @@ class BSP_Tree { public: enum { - + UNDER_LEAF=0xFFFF, OVER_LEAF=0xFFFE, MAX_NODES=0xFFFE, @@ -51,22 +51,22 @@ public: }; struct Node { - + uint16_t plane; uint16_t under; uint16_t over; }; - -private: - // thanks to the properties of Vector, + +private: + // thanks to the properties of Vector, // this class can be assigned and passed around between threads // with no cost. - + Vector<Node> nodes; Vector<Plane> planes; AABB aabb; - float error_radius; + float error_radius; int _get_points_inside(int p_node,const Vector3* p_points,int *p_indices, const Vector3& p_center,const Vector3& p_half_extents,int p_indices_count) const; @@ -79,8 +79,8 @@ public: Vector<Node> get_nodes() const; Vector<Plane> get_planes() const; AABB get_aabb() const; - - bool point_is_inside(const Vector3& p_point) const; + + bool point_is_inside(const Vector3& p_point) const; int get_points_inside(const Vector3* p_points, int p_point_count) const; template<class T> bool convex_is_inside(const T& p_convex) const; @@ -91,8 +91,8 @@ public: BSP_Tree(); BSP_Tree(const Variant& p_variant); - BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius=0); - BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const AABB& p_aabb,float p_error_radius=0); + BSP_Tree(const DVector<Face3>& p_faces,float p_error_radius=0); + BSP_Tree(const Vector<Node> &p_nodes, const Vector<Plane> &p_planes, const AABB& p_aabb,float p_error_radius=0); ~BSP_Tree(); }; diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index 61c8b78e0a..f7dd8839b8 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -33,9 +33,9 @@ void CameraMatrix::set_identity() { for (int i=0;i<4;i++) { - + for (int j=0;j<4;j++) { - + matrix[i][j]=(i==j)?1:0; } } @@ -90,7 +90,7 @@ void CameraMatrix::set_perspective(float p_fovy_degrees, float p_aspect, float p matrix[2][2] = -(p_z_far + p_z_near) / deltaZ; matrix[2][3] = -1; matrix[3][2] = -2 * p_z_near * p_z_far / deltaZ; - matrix[3][3] = 0; + matrix[3][3] = 0; } @@ -155,95 +155,95 @@ void CameraMatrix::set_frustum(float p_left, float p_right, float p_bottom, floa float CameraMatrix::get_z_far() const { - - const float * matrix = (const float*)this->matrix; + + const float * matrix = (const float*)this->matrix; Plane new_plane=Plane(matrix[ 3] - matrix[ 2], matrix[ 7] - matrix[ 6], matrix[11] - matrix[10], matrix[15] - matrix[14]); - + new_plane.normal=-new_plane.normal; new_plane.normalize(); - + return new_plane.d; } float CameraMatrix::get_z_near() const { - - const float * matrix = (const float*)this->matrix; + + const float * matrix = (const float*)this->matrix; Plane new_plane=Plane(matrix[ 3] + matrix[ 2], matrix[ 7] + matrix[ 6], matrix[11] + matrix[10], -matrix[15] - matrix[14]); - + new_plane.normalize(); return new_plane.d; } void CameraMatrix::get_viewport_size(float& r_width, float& r_height) const { - const float * matrix = (const float*)this->matrix; + const float * matrix = (const float*)this->matrix; ///////--- Near Plane ---/////// Plane near_plane=Plane(matrix[ 3] + matrix[ 2], matrix[ 7] + matrix[ 6], matrix[11] + matrix[10], -matrix[15] - matrix[14]).normalized(); - + ///////--- Right Plane ---/////// Plane right_plane=Plane(matrix[ 3] - matrix[ 0], matrix[ 7] - matrix[ 4], matrix[11] - matrix[ 8], - matrix[15] + matrix[12]).normalized(); - + Plane top_plane=Plane(matrix[ 3] - matrix[ 1], matrix[ 7] - matrix[ 5], matrix[11] - matrix[ 9], -matrix[15] + matrix[13]).normalized(); - + Vector3 res; near_plane.intersect_3(right_plane,top_plane,&res); - + r_width=res.x; r_height=res.y; } bool CameraMatrix::get_endpoints(const Transform& p_transform, Vector3 *p_8points) const { - const float * matrix = (const float*)this->matrix; - + const float * matrix = (const float*)this->matrix; + ///////--- Near Plane ---/////// Plane near_plane=Plane(matrix[ 3] + matrix[ 2], matrix[ 7] + matrix[ 6], matrix[11] + matrix[10], -matrix[15] - matrix[14]).normalized(); - + ///////--- Far Plane ---/////// Plane far_plane=Plane(matrix[ 2] - matrix[ 3], matrix[ 6] - matrix[ 7], matrix[10] - matrix[11], matrix[15] - matrix[14]).normalized(); - + ///////--- Right Plane ---/////// Plane right_plane=Plane(matrix[ 0] - matrix[ 3], matrix[ 4] - matrix[ 7], matrix[8] - matrix[ 11], - matrix[15] + matrix[12]).normalized(); - - ///////--- Top Plane ---/////// + + ///////--- Top Plane ---/////// Plane top_plane=Plane(matrix[ 1] - matrix[ 3], matrix[ 5] - matrix[ 7], matrix[9] - matrix[ 11], -matrix[15] + matrix[13]).normalized(); - + Vector3 near_endpoint; Vector3 far_endpoint; - + bool res=near_plane.intersect_3(right_plane,top_plane,&near_endpoint); ERR_FAIL_COND_V(!res,false); - + res=far_plane.intersect_3(right_plane,top_plane,&far_endpoint); ERR_FAIL_COND_V(!res,false); - + p_8points[0]=p_transform.xform( Vector3( near_endpoint.x, near_endpoint.y, near_endpoint.z ) ); p_8points[1]=p_transform.xform( Vector3( near_endpoint.x,-near_endpoint.y, near_endpoint.z ) ); p_8points[2]=p_transform.xform( Vector3(-near_endpoint.x, near_endpoint.y, near_endpoint.z ) ); @@ -252,7 +252,7 @@ bool CameraMatrix::get_endpoints(const Transform& p_transform, Vector3 *p_8point p_8points[5]=p_transform.xform( Vector3( far_endpoint.x,-far_endpoint.y, far_endpoint.z ) ); p_8points[6]=p_transform.xform( Vector3(-far_endpoint.x, far_endpoint.y, far_endpoint.z ) ); p_8points[7]=p_transform.xform( Vector3(-far_endpoint.x,-far_endpoint.y, far_endpoint.z ) ); - + return true; } @@ -263,10 +263,10 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform) * http://www.markmorley.com/opengl/frustumculling.html * http://www2.ravensoft.com/users/ggribb/plane%20extraction.pdf */ - + Vector<Plane> planes; - - const float * matrix = (const float*)this->matrix; + + const float * matrix = (const float*)this->matrix; Plane new_plane; @@ -275,7 +275,7 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform) matrix[ 7] + matrix[ 6], matrix[11] + matrix[10], matrix[15] + matrix[14]); - + new_plane.normal=-new_plane.normal; new_plane.normalize(); @@ -298,7 +298,7 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform) matrix[ 7] + matrix[ 4], matrix[11] + matrix[ 8], matrix[15] + matrix[12]); - + new_plane.normal=-new_plane.normal; new_plane.normalize(); @@ -310,8 +310,8 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform) matrix[ 7] - matrix[ 5], matrix[11] - matrix[ 9], matrix[15] - matrix[13]); - - + + new_plane.normal=-new_plane.normal; new_plane.normalize(); @@ -324,10 +324,10 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform) matrix[11] - matrix[ 8], matrix[15] - matrix[12]); - + new_plane.normal=-new_plane.normal; new_plane.normalize(); - + planes.push_back( p_transform.xform(new_plane) ); @@ -337,12 +337,12 @@ Vector<Plane> CameraMatrix::get_projection_planes(const Transform& p_transform) matrix[11] + matrix[ 9], matrix[15] + matrix[13]); - + new_plane.normal=-new_plane.normal; new_plane.normalize(); planes.push_back( p_transform.xform(new_plane) ); - + return planes; } @@ -356,7 +356,7 @@ CameraMatrix CameraMatrix::inverse() const { } void CameraMatrix::invert() { - + int i,j,k; int pvt_i[4], pvt_j[4]; /* Locations of pivot matrix */ float pvt_val; /* Value of current pivot element */ @@ -448,7 +448,7 @@ void CameraMatrix::invert() { } } - + } CameraMatrix::CameraMatrix() { @@ -475,31 +475,31 @@ CameraMatrix CameraMatrix::operator*(const CameraMatrix& p_matrix) const { void CameraMatrix::set_light_bias() { float *m=&matrix[0][0]; - - m[0]=0.5, - m[1]=0.0, - m[2]=0.0, + + m[0]=0.5, + m[1]=0.0, + m[2]=0.0, m[3]=0.0, - m[4]=0.0, - m[5]=0.5, - m[6]=0.0, + m[4]=0.0, + m[5]=0.5, + m[6]=0.0, m[7]=0.0, - m[8]=0.0, - m[9]=0.0, - m[10]=0.5, + m[8]=0.0, + m[9]=0.0, + m[10]=0.5, m[11]=0.0, - m[12]=0.5, - m[13]=0.5, - m[14]=0.5, - m[15]=1.0; - + m[12]=0.5, + m[13]=0.5, + m[14]=0.5, + m[15]=1.0; + } CameraMatrix::operator String() const { String str; - for (int i=0;i<4;i++) - for (int j=0;j<4;j++) + for (int i=0;i<4;i++) + for (int j=0;j<4;j++) str+=String((j>0)?", ":"\n")+rtos(matrix[i][j]); return str; @@ -513,7 +513,7 @@ float CameraMatrix::get_aspect() const { } float CameraMatrix::get_fov() const { - const float * matrix = (const float*)this->matrix; + const float * matrix = (const float*)this->matrix; Plane right_plane=Plane(matrix[ 3] - matrix[ 0], matrix[ 7] - matrix[ 4], @@ -588,7 +588,7 @@ CameraMatrix::CameraMatrix(const Transform& p_transform) { const Transform &tr = p_transform; float *m=&matrix[0][0]; - + m[0]=tr.basis.elements[0][0]; m[1]=tr.basis.elements[1][0]; m[2]=tr.basis.elements[2][0]; @@ -604,7 +604,7 @@ CameraMatrix::CameraMatrix(const Transform& p_transform) { m[12]=tr.origin.x; m[13]=tr.origin.y; m[14]=tr.origin.z; - m[15]=1.0; + m[15]=1.0; } CameraMatrix::~CameraMatrix() diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h index 27500a545e..d192b1fef1 100644 --- a/core/math/camera_matrix.h +++ b/core/math/camera_matrix.h @@ -48,8 +48,8 @@ struct CameraMatrix { }; float matrix[4][4]; - - + + void set_identity(); void set_zero(); void set_light_bias(); @@ -67,12 +67,12 @@ struct CameraMatrix { float get_z_near() const; float get_aspect() const; float get_fov() const; - + Vector<Plane> get_projection_planes(const Transform& p_transform) const; - + bool get_endpoints(const Transform& p_transform,Vector3 *p_8points) const; void get_viewport_size(float& r_width, float& r_height) const; - + void invert(); CameraMatrix inverse() const; @@ -80,15 +80,15 @@ struct CameraMatrix { Plane xform4(const Plane& p_vec4); _FORCE_INLINE_ Vector3 xform(const Vector3& p_vec3) const; - + operator String() const; void scale_translate_to_fit(const AABB& p_aabb); void make_scale(const Vector3 &p_scale); operator Transform() const; - CameraMatrix(); - CameraMatrix(const Transform& p_transform); + CameraMatrix(); + CameraMatrix(const Transform& p_transform); ~CameraMatrix(); }; diff --git a/core/math/face3.h b/core/math/face3.h index c36fdd1332..bc34be9935 100644 --- a/core/math/face3.h +++ b/core/math/face3.h @@ -55,7 +55,7 @@ public: * @param _epsilon constant used for numerical error rounding, to add "thickness" to the plane (so coplanar points can happen) * @return amount of faces generated by the split, either 0 (means no split possible), 2 or 3 */ - + int split_by_plane(const Plane& p_plane,Face3 *p_res,bool *p_is_point_over) const; Plane get_plane(ClockDirection p_dir=CLOCKWISE) const; @@ -77,7 +77,7 @@ public: void get_support(const Vector3& p_normal,const Transform& p_transform,Vector3 *p_vertices,int* p_count,int p_max) const; void project_range(const Vector3& p_normal,const Transform& p_transform,float& r_min, float& r_max) const; - + AABB get_aabb() const { AABB aabb( vertex[0], Vector3() ); diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index 2905d26fe5..5b767212f5 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -211,7 +211,7 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array int len = p_array.size(); DVector<Face3>::Read r=p_array.read(); - + const Face3* arrayptr = r.ptr(); DVector< _FaceClassify> fc; @@ -219,7 +219,7 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array fc.resize( len ); DVector< _FaceClassify >::Write fcw=fc.write(); - + _FaceClassify * _fcptr = fcw.ptr(); for (int i=0;i<len;i++) { @@ -278,7 +278,7 @@ DVector< DVector< Face3 > > Geometry::separate_objects( DVector< Face3 > p_array /*** GEOMETRY WRAPPER ***/ enum _CellFlags { - + _CELL_SOLID=1, _CELL_EXTERIOR=2, _CELL_STEP_MASK=0x1C, @@ -299,7 +299,7 @@ enum _CellFlags { _CELL_PREV_Z_POS=5<<5, _CELL_PREV_Z_NEG=6<<5, _CELL_PREV_FIRST=7<<5, - + }; static inline void _plot_face(uint8_t*** p_cell_status,int x,int y,int z,int len_x,int len_y,int len_z,const Vector3& voxelsize,const Face3& p_face) { @@ -316,9 +316,9 @@ static inline void _plot_face(uint8_t*** p_cell_status,int x,int y,int z,int len p_cell_status[x][y][z]=_CELL_SOLID; return; } - - - + + + int div_x=len_x>1?2:1; int div_y=len_y>1?2:1; int div_z=len_z>1?2:1; @@ -343,14 +343,14 @@ static inline void _plot_face(uint8_t*** p_cell_status,int x,int y,int z,int len int new_len_z; for (int i=0;i<div_x;i++) { - - + + _SPLIT(i,div_x,x,len_x,new_x,new_len_x); - + for (int j=0;j<div_y;j++) { _SPLIT(j,div_y,y,len_y,new_y,new_len_y); - + for (int k=0;k<div_z;k++) { _SPLIT(k,div_z,z,len_z,new_z,new_len_z); @@ -365,39 +365,39 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int if (p_cell_status[x][y][z]&3) return; // nothing to do, already used and/or visited - + p_cell_status[x][y][z]=_CELL_PREV_FIRST; - + while(true) { - + uint8_t &c = p_cell_status[x][y][z]; - + //printf("at %i,%i,%i\n",x,y,z); - - if ( (c&_CELL_STEP_MASK)==_CELL_STEP_NONE) { + + if ( (c&_CELL_STEP_MASK)==_CELL_STEP_NONE) { /* Haven't been in here, mark as outside */ p_cell_status[x][y][z]|=_CELL_EXTERIOR; //printf("not marked as anything, marking exterior\n"); } - + //printf("cell step is %i\n",(c&_CELL_STEP_MASK)); - + if ( (c&_CELL_STEP_MASK)!=_CELL_STEP_DONE) { /* if not done, increase step */ c+=1<<2; //printf("incrementing cell step\n"); } - + if ( (c&_CELL_STEP_MASK)==_CELL_STEP_DONE) { /* Go back */ //printf("done, going back a cell\n"); - + switch(c&_CELL_PREV_MASK) { case _CELL_PREV_FIRST: { - //printf("at end, finished marking\n"); + //printf("at end, finished marking\n"); return; } break; - case _CELL_PREV_Y_POS: { + case _CELL_PREV_Y_POS: { y++; ERR_FAIL_COND(y>=len_y); } break; @@ -427,16 +427,16 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int } continue; } - + //printf("attempting new cell!\n"); - + int next_x=x,next_y=y,next_z=z; uint8_t prev=0; - + switch(c&_CELL_STEP_MASK) { - + case _CELL_STEP_Y_POS: { - + next_y++; prev=_CELL_PREV_Y_NEG; } break; @@ -454,32 +454,32 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int } break; case _CELL_STEP_Z_POS: { next_z++; - prev=_CELL_PREV_Z_NEG; + prev=_CELL_PREV_Z_NEG; } break; case _CELL_STEP_Z_NEG: { next_z--; - prev=_CELL_PREV_Z_POS; + prev=_CELL_PREV_Z_POS; } break; - default: ERR_FAIL(); - + default: ERR_FAIL(); + } - + //printf("testing if new cell will be ok...!\n"); - + if (next_x<0 || next_x>=len_x) continue; if (next_y<0 || next_y>=len_y) continue; if (next_z<0 || next_z>=len_z) continue; - + //printf("testing if new cell is traversable\n"); - + if (p_cell_status[next_x][next_y][next_z]&3) continue; - + //printf("move to it\n"); - + x=next_x; y=next_y; z=next_z; @@ -488,14 +488,14 @@ static inline void _mark_outside(uint8_t*** p_cell_status,int x,int y,int z,int } static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int len_x,int len_y,int len_z,DVector<Face3>& p_faces) { - + ERR_FAIL_INDEX(x,len_x); ERR_FAIL_INDEX(y,len_y); ERR_FAIL_INDEX(z,len_z); - + if (p_cell_status[x][y][z]&_CELL_EXTERIOR) - return; - + return; + /* static const Vector3 vertices[8]={ Vector3(0,0,0), Vector3(0,0,1), @@ -510,73 +510,73 @@ static inline void _build_faces(uint8_t*** p_cell_status,int x,int y,int z,int l #define vert(m_idx) Vector3( (m_idx&4)>>2, (m_idx&2)>>1, m_idx&1 ) static const uint8_t indices[6][4]={ - {7,6,4,5}, + {7,6,4,5}, {7,3,2,6}, - {7,5,1,3}, - {0,2,3,1}, - {0,1,5,4}, + {7,5,1,3}, + {0,2,3,1}, + {0,1,5,4}, {0,4,6,2}, }; -/* +/* - {0,1,2,3}, - {0,1,4,5}, + {0,1,2,3}, + {0,1,4,5}, {0,2,4,6}, - {4,5,6,7}, + {4,5,6,7}, {2,3,7,6}, - {1,3,5,7}, + {1,3,5,7}, - {0,2,3,1}, - {0,1,5,4}, + {0,2,3,1}, + {0,1,5,4}, {0,4,6,2}, - {7,6,4,5}, + {7,6,4,5}, {7,3,2,6}, - {7,5,1,3}, + {7,5,1,3}, */ - + for (int i=0;i<6;i++) { - + Vector3 face_points[4]; int disp_x=x+((i%3)==0?((i<3)?1:-1):0); int disp_y=y+(((i-1)%3)==0?((i<3)?1:-1):0); int disp_z=z+(((i-2)%3)==0?((i<3)?1:-1):0); - + bool plot=false; - + if (disp_x<0 || disp_x>=len_x) plot=true; if (disp_y<0 || disp_y>=len_y) plot=true; if (disp_z<0 || disp_z>=len_z) plot=true; - + if (!plot && (p_cell_status[disp_x][disp_y][disp_z]&_CELL_EXTERIOR)) plot=true; - + if (!plot) continue; - + for (int j=0;j<4;j++) face_points[j]=vert( indices[i][j] ) + Vector3(x,y,z); - - p_faces.push_back( - Face3( + + p_faces.push_back( + Face3( face_points[0], face_points[1], face_points[2] ) ); - - p_faces.push_back( - Face3( + + p_faces.push_back( + Face3( face_points[2], face_points[3], face_points[0] ) ); - - } + + } } @@ -601,7 +601,7 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro global_aabb.merge_with( faces[i].get_aabb() ); } } - + global_aabb.grow_by(0.01); // avoid numerical error // determine amount of cells in grid axis @@ -649,7 +649,7 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro // plot faces into cells print_line("Wrapper (1/6): Plotting Faces"); - + for (int i=0;i<face_count;i++) { Face3 f=faces[i]; @@ -666,68 +666,68 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro print_line("Wrapper (2/6) Flood Filling"); for (int i=0;i<div_x;i++) { - + for (int j=0;j<div_y;j++) { - + _mark_outside(cell_status,i,j,0,div_x,div_y,div_z); _mark_outside(cell_status,i,j,div_z-1,div_x,div_y,div_z); } } - + for (int i=0;i<div_z;i++) { - + for (int j=0;j<div_y;j++) { - + _mark_outside(cell_status,0,j,i,div_x,div_y,div_z); _mark_outside(cell_status,div_x-1,j,i,div_x,div_y,div_z); } } - + for (int i=0;i<div_x;i++) { - + for (int j=0;j<div_z;j++) { - + _mark_outside(cell_status,i,0,j,div_x,div_y,div_z); _mark_outside(cell_status,i,div_y-1,j,div_x,div_y,div_z); } } - + // build faces for the inside-outside cell divisors - + print_line("Wrapper (3/6): Building Faces"); DVector<Face3> wrapped_faces; - + for (int i=0;i<div_x;i++) { - + for (int j=0;j<div_y;j++) { - + for (int k=0;k<div_z;k++) { - - _build_faces(cell_status,i,j,k,div_x,div_y,div_z,wrapped_faces); + + _build_faces(cell_status,i,j,k,div_x,div_y,div_z,wrapped_faces); } } } - + print_line("Wrapper (4/6): Transforming Back Vertices"); // transform face vertices to global coords - + int wrapped_faces_count=wrapped_faces.size(); DVector<Face3>::Write wrapped_facesw=wrapped_faces.write(); Face3* wrapped_faces_ptr=wrapped_facesw.ptr(); - + for(int i=0;i<wrapped_faces_count;i++) { - + for(int j=0;j<3;j++) { - + Vector3& v = wrapped_faces_ptr[i].vertex[j]; v=v*voxelsize; v+=global_aabb.pos; } } - - // clean up grid + + // clean up grid print_line("Wrapper (5/6): Grid Cleanup"); for(int i=0;i<div_x;i++) { @@ -736,14 +736,14 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro memdelete_arr( cell_status[i][j] ); } - + memdelete_arr( cell_status[i] ); } - + memdelete_arr(cell_status); if (p_error) *p_error=voxelsize.length(); - + print_line("Wrapper (6/6): Finished."); return wrapped_faces; } @@ -751,67 +751,67 @@ DVector< Face3 > Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) { MeshData mesh; - - + + #define SUBPLANE_SIZE 1024.0 - + float subplane_size = 1024.0; // should compute this from the actual plane for (int i=0;i<p_planes.size();i++) { - + Plane p =p_planes[i]; - + Vector3 ref=Vector3(0.0,1.0,0.0); - + if (ABS(p.normal.dot(ref))>0.95) ref=Vector3(0.0,0.0,1.0); // change axis - + Vector3 right = p.normal.cross(ref).normalized(); Vector3 up = p.normal.cross( right ).normalized(); - + Vector< Vector3 > vertices; - + Vector3 center = p.get_any_point(); // make a quad clockwise vertices.push_back( center - up * subplane_size + right * subplane_size ); vertices.push_back( center - up * subplane_size - right * subplane_size ); vertices.push_back( center + up * subplane_size - right * subplane_size ); vertices.push_back( center + up * subplane_size + right * subplane_size ); - + for (int j=0;j<p_planes.size();j++) { if (j==i) continue; - + Vector< Vector3 > new_vertices; Plane clip=p_planes[j]; - + if (clip.normal.dot(p.normal)>0.95) continue; - + if (vertices.size()<3) break; - + for(int k=0;k<vertices.size();k++) { - + int k_n=(k+1)%vertices.size(); - + Vector3 edge0_A=vertices[k]; Vector3 edge1_A=vertices[k_n]; - + real_t dist0 = clip.distance_to(edge0_A); real_t dist1 = clip.distance_to(edge1_A); - - - if ( dist0 <= 0 ) { // behind plane - - new_vertices.push_back(vertices[k]); + + + if ( dist0 <= 0 ) { // behind plane + + new_vertices.push_back(vertices[k]); } - - + + // check for different sides and non coplanar - if ( (dist0*dist1) < 0) { - + if ( (dist0*dist1) < 0) { + // calculate intersection Vector3 rel = edge1_A - edge0_A; @@ -822,55 +822,55 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) { real_t dist=-(clip.normal.dot( edge0_A )-clip.d)/den; Vector3 inters = edge0_A+rel*dist; new_vertices.push_back(inters); - } + } } - + vertices=new_vertices; } - + if (vertices.size()<3) continue; - - + + //result is a clockwise face - + MeshData::Face face; - + // add face indices for (int j=0;j<vertices.size();j++) { - - + + int idx=-1; for (int k=0;k<mesh.vertices.size();k++) { - + if (mesh.vertices[k].distance_to(vertices[j])<0.001) { - + idx=k; break; } } - + if (idx==-1) { - + idx=mesh.vertices.size(); mesh.vertices.push_back(vertices[j]); } - + face.indices.push_back(idx); } face.plane=p; mesh.faces.push_back(face); - + //add edge - + for(int j=0;j<face.indices.size();j++) { - + int a=face.indices[j]; int b=face.indices[(j+1)%face.indices.size()]; - + bool found=false; for(int k=0;k<mesh.edges.size();k++) { - + if (mesh.edges[k].a==a && mesh.edges[k].b==b) { found=true; break; @@ -878,9 +878,9 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) { if (mesh.edges[k].b==a && mesh.edges[k].a==b) { found=true; break; - } + } } - + if (found) continue; MeshData::Edge edge; @@ -888,8 +888,8 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) { edge.b=b; mesh.edges.push_back(edge); } - - + + } return mesh; @@ -899,36 +899,36 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector<Plane> &p_planes) { DVector<Plane> Geometry::build_box_planes(const Vector3& p_extents) { DVector<Plane> planes; - + planes.push_back( Plane( Vector3(1,0,0), p_extents.x ) ); planes.push_back( Plane( Vector3(-1,0,0), p_extents.x ) ); planes.push_back( Plane( Vector3(0,1,0), p_extents.y ) ); planes.push_back( Plane( Vector3(0,-1,0), p_extents.y ) ); planes.push_back( Plane( Vector3(0,0,1), p_extents.z ) ); planes.push_back( Plane( Vector3(0,0,-1), p_extents.z ) ); - + return planes; } DVector<Plane> Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) { DVector<Plane> planes; - + for (int i=0;i<p_sides;i++) { - + Vector3 normal; normal[(p_axis+1)%3]=Math::cos(i*(2.0*Math_PI)/p_sides); normal[(p_axis+2)%3]=Math::sin(i*(2.0*Math_PI)/p_sides); - + planes.push_back( Plane( normal, p_radius ) ); } - + Vector3 axis; axis[p_axis]=1.0; - + planes.push_back( Plane( axis, p_height*0.5 ) ); planes.push_back( Plane( -axis, p_height*0.5 ) ); - + return planes; } @@ -972,34 +972,34 @@ DVector<Plane> Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lo DVector<Plane> Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) { DVector<Plane> planes; - + Vector3 axis; axis[p_axis]=1.0; - - Vector3 axis_neg; + + Vector3 axis_neg; axis_neg[(p_axis+1)%3]=1.0; axis_neg[(p_axis+2)%3]=1.0; axis_neg[p_axis]=-1.0; - + for (int i=0;i<p_sides;i++) { - + Vector3 normal; normal[(p_axis+1)%3]=Math::cos(i*(2.0*Math_PI)/p_sides); normal[(p_axis+2)%3]=Math::sin(i*(2.0*Math_PI)/p_sides); - + planes.push_back( Plane( normal, p_radius ) ); - + for (int j=1;j<=p_lats;j++) { - + Vector3 angle = normal.linear_interpolate(axis,j/(float)p_lats).normalized(); Vector3 pos = axis*p_height*0.5 + angle*p_radius; planes.push_back( Plane( pos, angle ) ); planes.push_back( Plane( pos * axis_neg, angle * axis_neg) ); - + } } - + return planes; } diff --git a/core/math/geometry.h b/core/math/geometry.h index 8370990d6e..b353423851 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -44,7 +44,7 @@ class Geometry { Geometry(); public: - + @@ -201,37 +201,37 @@ public: real_t a =e1.dot(h); if (a>-CMP_EPSILON && a < CMP_EPSILON) // parallel test return false; - + real_t f=1.0/a; - + Vector3 s=p_from-p_v0; real_t u = f * s.dot(h); - + if ( u< 0.0 || u > 1.0) return false; - + Vector3 q=s.cross(e1); - + real_t v = f * p_dir.dot(q); - + if (v < 0.0 || u + v > 1.0) return false; - - // at this stage we can compute t to find out where + + // at this stage we can compute t to find out where // the intersection point is on the line real_t t = f * e2.dot(q); - + if (t > 0.00001) {// ray intersection if (r_res) *r_res=p_from+p_dir*t; return true; - } else // this means that there is a line intersection + } else // this means that there is a line intersection // but not a ray intersection return false; - } - + } + static inline bool segment_intersects_triangle( const Vector3& p_from, const Vector3& p_to, const Vector3& p_v0,const Vector3& p_v1,const Vector3& p_v2,Vector3* r_res=0) { - + Vector3 rel=p_to-p_from; Vector3 e1=p_v1-p_v0; Vector3 e2=p_v2-p_v0; @@ -239,34 +239,34 @@ public: real_t a =e1.dot(h); if (a>-CMP_EPSILON && a < CMP_EPSILON) // parallel test return false; - + real_t f=1.0/a; - + Vector3 s=p_from-p_v0; real_t u = f * s.dot(h); - + if ( u< 0.0 || u > 1.0) return false; - + Vector3 q=s.cross(e1); - + real_t v = f * rel.dot(q); - + if (v < 0.0 || u + v > 1.0) return false; - - // at this stage we can compute t to find out where + + // at this stage we can compute t to find out where // the intersection point is on the line real_t t = f * e2.dot(q); - + if (t > CMP_EPSILON && t<=1.0) {// ray intersection if (r_res) *r_res=p_from+rel*t; return true; - } else // this means that there is a line intersection + } else // this means that there is a line intersection // but not a ray intersection return false; - } + } static inline bool segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius,Vector3* r_res=0,Vector3 *r_norm=0) { @@ -356,24 +356,24 @@ public: real_t box_end=size[i]; real_t cmin,cmax; - + if (seg_from < seg_to) { - + if (seg_from > box_end || seg_to < box_begin) return false; real_t length=seg_to-seg_from; cmin = (seg_from < box_begin)?((box_begin - seg_from)/length):0; cmax = (seg_to > box_end)?((box_end - seg_from)/length):1; - + } else { - + if (seg_to > box_end || seg_from < box_begin) return false; real_t length=seg_to-seg_from; cmin = (seg_from > box_end)?(box_end - seg_from)/length:0; cmax = (seg_to < box_begin)?(box_begin - seg_from)/length:1; } - + if (cmin > min) { min = cmin; axis=i; @@ -468,9 +468,9 @@ public: if (l<1e-10) return p_segment[0]; // both points are the same, just give any n/=l; - + float d=n.dot(p); - + if (d<=0.0) return p_segment[0]; // before first point else if (d>=l) @@ -570,27 +570,27 @@ public: static inline bool point_in_projected_triangle(const Vector3& p_point,const Vector3& p_v1,const Vector3& p_v2,const Vector3& p_v3) { - - - Vector3 face_n = (p_v1-p_v3).cross(p_v1-p_v2); - - Vector3 n1 = (p_point-p_v3).cross(p_point-p_v2); - + + + Vector3 face_n = (p_v1-p_v3).cross(p_v1-p_v2); + + Vector3 n1 = (p_point-p_v3).cross(p_point-p_v2); + if (face_n.dot(n1)<0) return false; - - Vector3 n2 = (p_v1-p_v3).cross(p_v1-p_point); - + + Vector3 n2 = (p_v1-p_v3).cross(p_v1-p_point); + if (face_n.dot(n2)<0) return false; - - Vector3 n3 = (p_v1-p_point).cross(p_v1-p_v2); - + + Vector3 n3 = (p_v1-p_point).cross(p_v1-p_v2); + if (face_n.dot(n3)<0) return false; - + return true; - + } static inline bool triangle_sphere_intersection_test(const Vector3 *p_triangle,const Vector3& p_normal,const Vector3& p_sphere_pos, real_t p_sphere_radius,Vector3& r_triangle_contact,Vector3& r_sphere_contact) { @@ -814,21 +814,21 @@ public: struct MeshData { - + struct Face { Plane plane; Vector<int> indices; }; - + Vector<Face> faces; - + struct Edge { - + int a,b; }; - + Vector<Edge> edges; - + Vector< Vector3 > vertices; void optimize_vertices(); @@ -927,7 +927,7 @@ public: static void make_atlas(const Vector<Size2i>& p_rects,Vector<Point2i>& r_result, Size2i& r_size); - + }; diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index a485125cb4..0e2060008c 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -45,10 +45,10 @@ float Vector2::length_squared() const { } void Vector2::normalize() { - + float l = x*x + y*y; if (l!=0) { - + l=Math::sqrt(l); x/=l; y/=l; @@ -56,14 +56,14 @@ void Vector2::normalize() { } Vector2 Vector2::normalized() const { - + Vector2 v=*this; v.normalize(); return v; } float Vector2::distance_to(const Vector2& p_vector2) const { - + return Math::sqrt( (x-p_vector2.x)*(x-p_vector2.x) + (y-p_vector2.y)*(y-p_vector2.y)); } @@ -73,7 +73,7 @@ float Vector2::distance_squared_to(const Vector2& p_vector2) const { } float Vector2::angle_to(const Vector2& p_vector2) const { - + return Math::atan2( tangent().dot(p_vector2), dot(p_vector2) ); } @@ -83,7 +83,7 @@ float Vector2::angle_to_point(const Vector2& p_vector2) const { } float Vector2::dot(const Vector2& p_other) const { - + return x*p_other.x + y*p_other.y; } @@ -99,62 +99,62 @@ Vector2 Vector2::cross(real_t p_other) const { Vector2 Vector2::operator+(const Vector2& p_v) const { - + return Vector2(x+p_v.x,y+p_v.y); } void Vector2::operator+=(const Vector2& p_v) { - + x+=p_v.x; y+=p_v.y; } Vector2 Vector2::operator-(const Vector2& p_v) const { - + return Vector2(x-p_v.x,y-p_v.y); } void Vector2::operator-=(const Vector2& p_v) { - + x-=p_v.x; y-=p_v.y; } Vector2 Vector2::operator*(const Vector2 &p_v1) const { - + return Vector2(x * p_v1.x, y * p_v1.y); }; Vector2 Vector2::operator*(const float &rvalue) const { - + return Vector2(x * rvalue, y * rvalue); }; void Vector2::operator*=(const float &rvalue) { - + x *= rvalue; y *= rvalue; }; Vector2 Vector2::operator/(const Vector2 &p_v1) const { - + return Vector2(x / p_v1.x, y / p_v1.y); }; Vector2 Vector2::operator/(const float &rvalue) const { - + return Vector2(x / rvalue, y / rvalue); }; void Vector2::operator/=(const float &rvalue) { - + x /= rvalue; y /= rvalue; }; Vector2 Vector2::operator-() const { - + return Vector2(-x,-y); } bool Vector2::operator==(const Vector2& p_vec2) const { - + return x==p_vec2.x && y==p_vec2.y; } bool Vector2::operator!=(const Vector2& p_vec2) const { - + return x!=p_vec2.x || y!=p_vec2.y; } Vector2 Vector2::floor() const { @@ -621,25 +621,25 @@ float Matrix32::basis_determinant() const { } Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, float p_c) const { - + //extract parameters Vector2 p1 = get_origin(); Vector2 p2 = p_transform.get_origin(); - + real_t r1 = get_rotation(); real_t r2 = p_transform.get_rotation(); - + Vector2 s1 = get_scale(); Vector2 s2 = p_transform.get_scale(); - + //slerp rotation Vector2 v1(Math::cos(r1), Math::sin(r1)); Vector2 v2(Math::cos(r2), Math::sin(r2)); - + real_t dot = v1.dot(v2); - + dot = (dot < -1.0) ? -1.0 : ((dot > 1.0) ? 1.0 : dot); //clamp dot to [-1,1] - + Vector2 v; if (dot > 0.9995) { @@ -649,7 +649,7 @@ Matrix32 Matrix32::interpolate_with(const Matrix32& p_transform, float p_c) cons Vector2 v3 = (v2 - v1*dot).normalized(); v = v1*Math::cos(angle) + v3*Math::sin(angle); } - + //construct matrix Matrix32 res(Math::atan2(v.y, v.x), Vector2::linear_interpolate(p1, p2, p_c)); res.scale_basis(Vector2::linear_interpolate(s1, s2, p_c)); diff --git a/core/math/math_2d.h b/core/math/math_2d.h index 1171364671..ad4655b8f7 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -35,15 +35,15 @@ @author Juan Linietsky <reduzio@gmail.com> */ enum Margin { - + MARGIN_LEFT, MARGIN_TOP, MARGIN_RIGHT, - MARGIN_BOTTOM + MARGIN_BOTTOM }; enum Orientation { - + HORIZONTAL, VERTICAL }; @@ -63,7 +63,7 @@ enum VAlign { }; struct Vector2 { - + union { float x; float width; @@ -87,7 +87,7 @@ struct Vector2 { float length() const; float length_squared() const; - float distance_to(const Vector2& p_vector2) const; + float distance_to(const Vector2& p_vector2) const; float distance_squared_to(const Vector2& p_vector2) const; float angle_to(const Vector2& p_vector2) const; float angle_to_point(const Vector2& p_vector2) const; @@ -114,19 +114,19 @@ struct Vector2 { Vector2 operator-(const Vector2& p_v) const; void operator-=(const Vector2& p_v); Vector2 operator*(const Vector2 &p_v1) const; - + Vector2 operator*(const float &rvalue) const; void operator*=(const float &rvalue); void operator*=(const Vector2 &rvalue) { *this = *this * rvalue; } Vector2 operator/(const Vector2 &p_v1) const; - + Vector2 operator/(const float &rvalue) const; - + void operator/=(const float &rvalue); - + Vector2 operator-() const; - + bool operator==(const Vector2& p_vec2) const; bool operator!=(const Vector2& p_vec2) const; @@ -151,14 +151,14 @@ struct Vector2 { return Vector2(y,-x); } - + Vector2 floor() const; Vector2 snapped(const Vector2& p_by) const; float get_aspect() const { return width/height; } - + operator String() const { return String::num(x)+","+String::num(y); } - + _FORCE_INLINE_ Vector2(float p_x,float p_y) { x=p_x; y=p_y; } _FORCE_INLINE_ Vector2() { x=0; y=0; } }; @@ -202,7 +202,7 @@ struct Matrix32; struct Rect2 { - + Point2 pos; Size2 size; @@ -213,7 +213,7 @@ struct Rect2 { float get_area() const { return size.width*size.height; } - inline bool intersects(const Rect2& p_rect) const { + inline bool intersects(const Rect2& p_rect) const { if ( pos.x >= (p_rect.pos.x + p_rect.size.width) ) return false; if ( (pos.x+size.width) <= p_rect.pos.x ) @@ -222,7 +222,7 @@ struct Rect2 { return false; if ( (pos.y+size.height) <= p_rect.pos.y ) return false; - + return true; } @@ -254,73 +254,73 @@ struct Rect2 { bool intersects_segment(const Point2& p_from, const Point2& p_to, Point2* r_pos=NULL, Point2* r_normal=NULL) const; inline bool encloses(const Rect2& p_rect) const { - + return (p_rect.pos.x>=pos.x) && (p_rect.pos.y>=pos.y) && ((p_rect.pos.x+p_rect.size.x)<(pos.x+size.x)) && ((p_rect.pos.y+p_rect.size.y)<(pos.y+size.y)); - + } - + inline bool has_no_area() const { - + return (size.x<=0 || size.y<=0); - + } inline Rect2 clip(const Rect2& p_rect) const { /// return a clipped rect - + Rect2 new_rect=p_rect; - + if (!intersects( new_rect )) return Rect2(); - + new_rect.pos.x = MAX( p_rect.pos.x , pos.x ); new_rect.pos.y = MAX( p_rect.pos.y , pos.y ); - + Point2 p_rect_end=p_rect.pos+p_rect.size; Point2 end=pos+size; - + new_rect.size.x=MIN(p_rect_end.x,end.x) - new_rect.pos.x; new_rect.size.y=MIN(p_rect_end.y,end.y) - new_rect.pos.y; - + return new_rect; } - + inline Rect2 merge(const Rect2& p_rect) const { ///< return a merged rect - + Rect2 new_rect; - + new_rect.pos.x=MIN( p_rect.pos.x , pos.x ); new_rect.pos.y=MIN( p_rect.pos.y , pos.y ); - - + + new_rect.size.x = MAX( p_rect.pos.x+p_rect.size.x , pos.x+size.x ); new_rect.size.y = MAX( p_rect.pos.y+p_rect.size.y , pos.y+size.y ); - + new_rect.size = new_rect.size - new_rect.pos; //make relative again - + return new_rect; }; inline bool has_point(const Point2& p_point) const { if (p_point.x < pos.x) - return false; + return false; if (p_point.y < pos.y) - return false; - + return false; + if (p_point.x >= (pos.x+size.x) ) - return false; + return false; if (p_point.y >= (pos.y+size.y) ) - return false; - + return false; + return true; } - + inline bool no_area() const { return (size.width<=0 || size.height<=0 ); } - + bool operator==(const Rect2& p_rect) const { return pos==p_rect.pos && size==p_rect.size; } bool operator!=(const Rect2& p_rect) const { return pos!=p_rect.pos || size!=p_rect.size; } - + inline Rect2 grow(real_t p_by) const { - + Rect2 g=*this; g.pos.x-=p_by; g.pos.y-=p_by; @@ -357,9 +357,9 @@ struct Rect2 { operator String() const { return String(pos)+","+String(size); } - + Rect2() {} - Rect2( float p_x, float p_y, float p_width, float p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); } + Rect2( float p_x, float p_y, float p_width, float p_height) { pos=Point2(p_x,p_y); size=Size2( p_width, p_height ); } Rect2( const Point2& p_pos, const Size2& p_size ) { pos=p_pos; size=p_size; } }; diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 20d9db3375..07f114725d 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -185,12 +185,12 @@ double Math::fmod(double p_x,double p_y) { double Math::fposmod(double p_x,double p_y) { if (p_x>=0) { - + return Math::fmod(p_x,p_y); - + } else { - - return p_y-Math::fmod(-p_x,p_y); + + return p_y-Math::fmod(-p_x,p_y); } } @@ -205,7 +205,7 @@ double Math::ceil(double p_x) { } int Math::decimals(double p_step) { - + int max=4; double llimit = Math::pow(0.1,max); double ulimit = 1.0-llimit; @@ -220,7 +220,7 @@ int Math::decimals(double p_step) { max--; i++; } - + return i; } @@ -251,11 +251,11 @@ double Math::ease(double p_x, double p_c) { } double Math::stepify(double p_value,double p_step) { - + if (p_step!=0) { - - p_value=floor( p_value / p_step + 0.5 ) * p_step; - } + + p_value=floor( p_value / p_step + 0.5 ) * p_step; + } return p_value; } diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 62890b0371..2e1b9c989e 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -91,25 +91,25 @@ public: static uint32_t rand(); static double randf(); - + static double round(double p_val); static double random(double from, double to); - + static _FORCE_INLINE_ real_t abs(real_t g) { -#ifdef REAL_T_IS_DOUBLE - - return absd(g); +#ifdef REAL_T_IS_DOUBLE + + return absd(g); #else - return absf(g); + return absf(g); #endif } static _FORCE_INLINE_ float absf(float g) { - + union { float f; uint32_t i; @@ -174,7 +174,7 @@ public: static double pow(double x, double y); static double log(double x); static double exp(double x); - + }; diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp index f51da80a83..71e6b62212 100644 --- a/core/math/matrix3.cpp +++ b/core/math/matrix3.cpp @@ -62,11 +62,11 @@ void Matrix3::invert() { real_t det = elements[0][0] * co[0]+ elements[0][1] * co[1]+ elements[0][2] * co[2]; - + ERR_FAIL_COND( det == 0 ); real_t s = 1.0/det; - - set( co[0]*s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s, + + set( co[0]*s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s, co[1]*s, cofac(0, 0, 2, 2) * s, cofac(0, 2, 1, 0) * s, co[2]*s, cofac(0, 1, 2, 0) * s, cofac(0, 0, 1, 1) * s ); @@ -148,7 +148,7 @@ Vector3 Matrix3::get_scale() const { Vector3(elements[0][1],elements[1][1],elements[2][1]).length(), Vector3(elements[0][2],elements[1][2],elements[2][2]).length() ); - + } void Matrix3::rotate(const Vector3& p_axis, real_t p_phi) { @@ -223,7 +223,7 @@ bool Matrix3::operator==(const Matrix3& p_matrix) const { return false; } } - + return true; } bool Matrix3::operator!=(const Matrix3& p_matrix) const { @@ -235,16 +235,16 @@ Matrix3::operator String() const { String mtx; for (int i=0;i<3;i++) { - + for (int j=0;j<3;j++) { - + if (i!=0 || j!=0) mtx+=", "; - + mtx+=rtos( elements[i][j] ); } } - + return mtx; } @@ -255,34 +255,34 @@ Matrix3::operator Quat() const { real_t trace = m.elements[0][0] + m.elements[1][1] + m.elements[2][2]; real_t temp[4]; - - if (trace > 0.0) + + if (trace > 0.0) { real_t s = Math::sqrt(trace + 1.0); temp[3]=(s * 0.5); s = 0.5 / s; - + temp[0]=((m.elements[2][1] - m.elements[1][2]) * s); temp[1]=((m.elements[0][2] - m.elements[2][0]) * s); temp[2]=((m.elements[1][0] - m.elements[0][1]) * s); - } - else + } + else { int i = m.elements[0][0] < m.elements[1][1] ? (m.elements[1][1] < m.elements[2][2] ? 2 : 1) : (m.elements[0][0] < m.elements[2][2] ? 2 : 0); - int j = (i + 1) % 3; + int j = (i + 1) % 3; int k = (i + 2) % 3; - + real_t s = Math::sqrt(m.elements[i][i] - m.elements[j][j] - m.elements[k][k] + 1.0); temp[i] = s * 0.5; s = 0.5 / s; - + temp[3] = (m.elements[k][j] - m.elements[j][k]) * s; temp[j] = (m.elements[j][i] + m.elements[i][j]) * s; temp[k] = (m.elements[k][i] + m.elements[i][k]) * s; } - + return Quat(temp[0],temp[1],temp[2],temp[3]); } @@ -439,7 +439,7 @@ void Matrix3::get_axis_and_angle(Vector3 &r_axis,real_t& r_angle) const { Matrix3::Matrix3(const Vector3& p_euler) { set_euler( p_euler ); - + } Matrix3::Matrix3(const Quat& p_quat) { @@ -450,8 +450,8 @@ Matrix3::Matrix3(const Quat& p_quat) { real_t wx = p_quat.w * xs, wy = p_quat.w * ys, wz = p_quat.w * zs; real_t xx = p_quat.x * xs, xy = p_quat.x * ys, xz = p_quat.x * zs; real_t yy = p_quat.y * ys, yz = p_quat.y * zs, zz = p_quat.z * zs; - set( 1.0 - (yy + zz), xy - wz, xz + wy, - xy + wz, 1.0 - (xx + zz), yz - wx, + set( 1.0 - (yy + zz), xy - wz, xz + wy, + xy + wz, 1.0 - (xx + zz), yz - wx, xz - wy, yz + wx, 1.0 - (xx + yy)) ; } diff --git a/core/math/matrix3.h b/core/math/matrix3.h index 291934b8eb..e514f490f7 100644 --- a/core/math/matrix3.h +++ b/core/math/matrix3.h @@ -39,20 +39,20 @@ class Matrix3 { public: Vector3 elements[3]; - + _FORCE_INLINE_ const Vector3& operator[](int axis) const { - + return elements[axis]; } _FORCE_INLINE_ Vector3& operator[](int axis) { - + return elements[axis]; } - void invert(); + void invert(); void transpose(); - - Matrix3 inverse() const; + + Matrix3 inverse() const; Matrix3 transposed() const; _FORCE_INLINE_ float determinant() const; @@ -90,7 +90,7 @@ public: _FORCE_INLINE_ real_t tdotz(const Vector3& v) const { return elements[0][2] * v[0] + elements[1][2] * v[1] + elements[2][2] * v[2]; } - + bool operator==(const Matrix3& p_matrix) const; bool operator!=(const Matrix3& p_matrix) const; @@ -110,7 +110,7 @@ public: _FORCE_INLINE_ void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) { - + elements[0][0]=xx; elements[0][1]=xy; elements[0][2]=xz; @@ -119,15 +119,15 @@ public: elements[1][2]=yz; elements[2][0]=zx; elements[2][1]=zy; - elements[2][2]=zz; + elements[2][2]=zz; } _FORCE_INLINE_ Vector3 get_column(int i) const { - + return Vector3(elements[0][i],elements[1][i],elements[2][i]); } - + _FORCE_INLINE_ Vector3 get_row(int i) const { - + return Vector3(elements[i][0],elements[i][1],elements[i][2]); } _FORCE_INLINE_ void set_row(int i, const Vector3& p_row) { @@ -155,8 +155,8 @@ public: elements[0].z * m[0].y + elements[1].z * m[1].y + elements[2].z * m[2].y, elements[0].z * m[0].z + elements[1].z * m[1].z + elements[2].z * m[2].z); } - Matrix3(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) { - + Matrix3(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz) { + set(xx, xy, xz, yx, yy, yz, zx, zy, zz); } @@ -170,7 +170,7 @@ public: Matrix3(const Vector3& p_axis, real_t p_phi); _FORCE_INLINE_ Matrix3() { - + elements[0][0]=1; elements[0][1]=0; elements[0][2]=0; @@ -191,7 +191,7 @@ _FORCE_INLINE_ void Matrix3::operator*=(const Matrix3& p_matrix) { p_matrix.tdotx(elements[0]), p_matrix.tdoty(elements[0]), p_matrix.tdotz(elements[0]), p_matrix.tdotx(elements[1]), p_matrix.tdoty(elements[1]), p_matrix.tdotz(elements[1]), p_matrix.tdotx(elements[2]), p_matrix.tdoty(elements[2]), p_matrix.tdotz(elements[2])); - + } _FORCE_INLINE_ Matrix3 Matrix3::operator*(const Matrix3& p_matrix) const { diff --git a/core/math/octree.h b/core/math/octree.h index 69edf80e09..6080b21680 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -52,11 +52,11 @@ public: typedef void* (*PairCallback)(void*,OctreeElementID, T*,int,OctreeElementID, T*,int); typedef void (*UnpairCallback)(void*,OctreeElementID, T*,int,OctreeElementID, T*,int,void*); -private: +private: enum { - + NEG=0, - POS=1, + POS=1, }; enum { @@ -72,7 +72,7 @@ private: struct PairKey { - + union { struct { OctreeElementID A; @@ -80,66 +80,66 @@ private: }; uint64_t key; }; - + _FORCE_INLINE_ bool operator<(const PairKey& p_pair) const { - + return key<p_pair.key; } - + _FORCE_INLINE_ PairKey( OctreeElementID p_A, OctreeElementID p_B) { - + if (p_A<p_B) { - + A=p_A; - B=p_B; + B=p_B; } else { - + B=p_A; A=p_B; } } - + _FORCE_INLINE_ PairKey() {} - }; - + }; + struct Element; - + struct Octant { - + // cached for FAST plane check AABB aabb; - + uint64_t last_pass; Octant *parent; Octant *children[8]; - + int children_count; // cache for amount of childrens (fast check for removal) int parent_index; // cache for parent index (fast check for removal) - + List<Element*,AL> pairable_elements; List<Element*,AL> elements; - + Octant() { children_count=0; parent_index=-1; last_pass=0; parent=NULL; for (int i=0;i<8;i++) - children[i]=NULL; + children[i]=NULL; } - + ~Octant() { - + //for (int i=0;i<8;i++) // memdelete_notnull(children[i]); } }; - + struct PairData; struct Element { - + Octree *octree; T *userdata; @@ -147,28 +147,28 @@ private: bool pairable; uint32_t pairable_mask; uint32_t pairable_type; - + uint64_t last_pass; OctreeElementID _id; Octant *common_parent; - + AABB aabb; AABB container_aabb; List<PairData*,AL> pair_list; - + struct OctantOwner { - + Octant *octant; typename List<Element*,AL>::Element *E; - }; // an element can be in max 8 octants - + }; // an element can be in max 8 octants + List<OctantOwner,AL> octant_owners; - - + + Element() { last_pass=0; _id=0; pairable=false; subindex=0; userdata=0; octree=0; pairable_mask=0; pairable_type=0; common_parent=NULL; } }; - + struct PairData { @@ -181,15 +181,15 @@ private: typedef Map<OctreeElementID, Element, Comparator<OctreeElementID>, AL> ElementMap; typedef Map<PairKey, PairData, Comparator<PairKey>, AL> PairMap; - ElementMap element_map; - PairMap pair_map; + ElementMap element_map; + PairMap pair_map; PairCallback pair_callback; UnpairCallback unpair_callback; void *pair_callback_userdata; void *unpair_callback_userdata; - - OctreeElementID last_element_id; + + OctreeElementID last_element_id; uint64_t pass; real_t unit_size; @@ -231,7 +231,7 @@ private: if (p_A==p_B || (p_A->userdata==p_B->userdata && p_A->userdata)) return; - + if ( !(p_A->pairable_type&p_B->pairable_mask) && !(p_B->pairable_type&p_A->pairable_mask) ) return; // none can pair with none @@ -253,17 +253,17 @@ private: // if (pair_callback) // pair_callback(pair_callback_userdata,p_A->userdata,p_B->userdata); } else { - + E->get().refcount++; } - + } - + _FORCE_INLINE_ void _pair_unreference(Element* p_A,Element* p_B) { - + if (p_A==p_B) return; - + PairKey key(p_A->_id, p_B->_id); typename PairMap::Element *E=pair_map.find(key); if (!E) { @@ -293,7 +293,7 @@ private: p_B->pair_list.erase( E->get().eB ); pair_map.erase(E); } - + } _FORCE_INLINE_ void _element_check_pairs(Element *p_element) { @@ -341,7 +341,7 @@ private: void _ensure_valid_root(const AABB& p_aabb); bool _remove_element_from_octant(Element *p_element,Octant *p_octant,Octant *p_limit=NULL); void _remove_element(Element *p_element); - void _pair_element(Element *p_element,Octant *p_octant); + void _pair_element(Element *p_element,Octant *p_octant); void _unpair_element(Element *p_element,Octant *p_octant); @@ -361,16 +361,16 @@ private: void _cull_point(Octant *p_octant,const Vector3& p_point,T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask); void _remove_tree(Octant *p_octant) { - + if (!p_octant) return; for(int i=0;i<8;i++) { - + if (p_octant->children[i]) _remove_tree(p_octant->children[i]); } - + memdelete_allocator<Octant,AL>(p_octant); } public: @@ -432,24 +432,24 @@ template<class T,bool use_pairs,class AL> void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant) { float element_size = p_element->aabb.get_longest_axis_size() * 1.01; // avoid precision issues - + if (p_octant->aabb.size.x/OCTREE_DIVISOR < element_size) { - //if (p_octant->aabb.size.x*0.5 < element_size) { - - /* at smallest possible size for the element */ + //if (p_octant->aabb.size.x*0.5 < element_size) { + + /* at smallest possible size for the element */ typename Element::OctantOwner owner; owner.octant=p_octant; - + if (use_pairs && p_element->pairable) { - + p_octant->pairable_elements.push_back(p_element); owner.E = p_octant->pairable_elements.back(); } else { - + p_octant->elements.push_back(p_element); owner.E = p_octant->elements.back(); } - + p_element->octant_owners.push_back( owner ); if (p_element->common_parent==NULL) { @@ -461,13 +461,13 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant if (use_pairs && p_octant->children_count>0) { - + pass++; //elements below this only get ONE reference added for (int i=0;i<8;i++) { - + if (p_octant->children[i]) { - _pair_element(p_element,p_octant->children[i]); + _pair_element(p_element,p_octant->children[i]); } } } @@ -477,7 +477,7 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant bool candidate=p_element->common_parent==NULL; for (int i=0;i<8;i++) { - + if (p_octant->children[i]) { /* element exists, go straight to it */ if (p_octant->children[i]->aabb.intersects_inclusive( p_element->aabb ) ) { @@ -486,20 +486,20 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant } } else { /* check againt AABB where child should be */ - + AABB aabb=p_octant->aabb; aabb.size*=0.5; - + if (i&1) aabb.pos.x+=aabb.size.x; if (i&2) aabb.pos.y+=aabb.size.y; if (i&4) aabb.pos.z+=aabb.size.z; - + if (aabb.intersects_inclusive( p_element->aabb) ) { /* if actually intersects, create the child */ - + Octant *child = memnew_allocator( Octant, AL ); p_octant->children[i]=child; child->parent=p_octant; @@ -517,14 +517,14 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant } } - + if (candidate && splits>1) { p_element->common_parent=p_octant; } - + } - + if (use_pairs) { typename List<Element*,AL>::Element *E=p_octant->pairable_elements.front(); @@ -532,8 +532,8 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant while(E) { _pair_reference( p_element,E->get() ); E=E->next(); - } - + } + if (p_element->pairable) { // and always test non-pairable if element is pairable E=p_octant->elements.front(); @@ -541,9 +541,9 @@ void Octree<T,use_pairs,AL>::_insert_element(Element *p_element,Octant *p_octant _pair_reference( p_element,E->get() ); E=E->next(); } - } + } } - + } @@ -553,35 +553,35 @@ void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) { if (!root) { // octre is empty - + AABB base( Vector3(), Vector3(1.0,1.0,1.0) * unit_size); - + while ( !base.encloses(p_aabb) ) { - + if ( ABS(base.pos.x+base.size.x) <= ABS(base.pos.x) ) { /* grow towards positive */ base.size*=2.0; } else { - base.pos-=base.size; + base.pos-=base.size; base.size*=2.0; } } - + root = memnew_allocator( Octant, AL ); - root->parent=NULL; - root->parent_index=-1; + root->parent=NULL; + root->parent_index=-1; root->aabb=base; - + octant_count++; - - - } else { - + + + } else { + AABB base=root->aabb; - + while( !base.encloses( p_aabb ) ) { - + if (base.size.x > OCTREE_SIZE_LIMIT) { ERR_EXPLAIN("Octree upper size limit reeached, does the AABB supplied contain NAN?"); ERR_FAIL(); @@ -590,7 +590,7 @@ void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) { Octant * gp = memnew_allocator( Octant, AL ); octant_count++; root->parent=gp; - + if ( ABS(base.pos.x+base.size.x) <= ABS(base.pos.x) ) { /* grow towards positive */ base.size*=2.0; @@ -598,16 +598,16 @@ void Octree<T,use_pairs,AL>::_ensure_valid_root(const AABB& p_aabb) { gp->children[0]=root; root->parent_index=0; } else { - base.pos-=base.size; + base.pos-=base.size; base.size*=2.0; gp->aabb=base; gp->children[(1<<0)|(1<<1)|(1<<2)]=root; // add at all-positive root->parent_index=(1<<0)|(1<<1)|(1<<2); } - + gp->children_count=1; - root=gp; - } + root=gp; + } } } @@ -615,16 +615,16 @@ template<class T,bool use_pairs,class AL> bool Octree<T,use_pairs,AL>::_remove_element_from_octant(Element *p_element,Octant *p_octant,Octant *p_limit) { bool octant_removed=false; - + while(true) { - + // check all exit conditions - + if (p_octant==p_limit) // reached limit, nothing to erase, exit return octant_removed; - + bool unpaired=false; - + if (use_pairs && p_octant->last_pass!=pass) { // check wether we should unpair stuff // always test pairable @@ -644,21 +644,21 @@ bool Octree<T,use_pairs,AL>::_remove_element_from_octant(Element *p_element,Octa p_octant->last_pass=pass; unpaired=true; } - + bool removed=false; - + Octant *parent=p_octant->parent; - + if (p_octant->children_count==0 && p_octant->elements.empty() && p_octant->pairable_elements.empty()) { - + // erase octant - + if (p_octant==root) { // won't have a parent, just erase - + root=NULL; } else { ERR_FAIL_INDEX_V(p_octant->parent_index,8,octant_removed); - + parent->children[ p_octant->parent_index ]=NULL; parent->children_count--; } @@ -668,12 +668,12 @@ bool Octree<T,use_pairs,AL>::_remove_element_from_octant(Element *p_element,Octa removed=true; octant_removed=true; } - + if (!removed && !unpaired) return octant_removed; // no reason to keep going up anymore! was already visited and was not removed - + p_octant=parent; - + } return octant_removed; @@ -682,8 +682,8 @@ bool Octree<T,use_pairs,AL>::_remove_element_from_octant(Element *p_element,Octa template<class T,bool use_pairs,class AL> void Octree<T,use_pairs,AL>::_unpair_element(Element *p_element,Octant *p_octant) { - - // always test pairable + + // always test pairable typename List<Element*,AL>::Element *E=p_octant->pairable_elements.front(); while(E) { if (E->get()->last_pass!=pass) { // only remove ONE reference @@ -692,7 +692,7 @@ void Octree<T,use_pairs,AL>::_unpair_element(Element *p_element,Octant *p_octant } E=E->next(); } - + if (p_element->pairable) { // and always test non-pairable if element is pairable E=p_octant->elements.front(); @@ -704,14 +704,14 @@ void Octree<T,use_pairs,AL>::_unpair_element(Element *p_element,Octant *p_octant E=E->next(); } } - + p_octant->last_pass=pass; - + if (p_octant->children_count==0) return; // small optimization for leafs - + for (int i=0;i<8;i++) { - + if (p_octant->children[i]) _unpair_element(p_element,p_octant->children[i]); } @@ -732,7 +732,7 @@ void Octree<T,use_pairs,AL>::_pair_element(Element *p_element,Octant *p_octant) } E=E->next(); } - + if (p_element->pairable) { // and always test non-pairable if element is pairable E=p_octant->elements.front(); @@ -745,12 +745,12 @@ void Octree<T,use_pairs,AL>::_pair_element(Element *p_element,Octant *p_octant) } } p_octant->last_pass=pass; - + if (p_octant->children_count==0) return; // small optimization for leafs - + for (int i=0;i<8;i++) { - + if (p_octant->children[i]) _pair_element(p_element,p_octant->children[i]); } @@ -760,13 +760,13 @@ template<class T,bool use_pairs,class AL> void Octree<T,use_pairs,AL>::_remove_element(Element *p_element) { pass++; // will do a new pass for this - + typename List< typename Element::OctantOwner,AL >::Element *I=p_element->octant_owners.front(); - + /* FIRST remove going up normally */ for(;I;I=I->next()) { - + Octant *o=I->get().octant; if (!use_pairs) // small speedup @@ -809,14 +809,14 @@ void Octree<T,use_pairs,AL>::_remove_element(Element *p_element) { int remaining=p_element->pair_list.size(); //p_element->pair_list.clear(); ERR_FAIL_COND( remaining ); - } + } } template<class T,bool use_pairs,class AL> OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const AABB& p_aabb, int p_subindex,bool p_pairable,uint32_t p_pairable_type,uint32_t p_pairable_mask) { - // check for AABB validity + // check for AABB validity #ifdef DEBUG_ENABLED ERR_FAIL_COND_V( p_aabb.pos.x > 1e15 || p_aabb.pos.x < -1e15, 0 ); ERR_FAIL_COND_V( p_aabb.pos.y > 1e15 || p_aabb.pos.y < -1e15, 0 ); @@ -828,12 +828,12 @@ OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const AABB& p_aabb ERR_FAIL_COND_V( Math::is_nan(p_aabb.size.y) , 0 ); ERR_FAIL_COND_V( Math::is_nan(p_aabb.size.z) , 0 ); - + #endif typename ElementMap::Element *E = element_map.insert(last_element_id++, Element()); Element &e = E->get(); - + e.aabb=p_aabb; e.userdata=p_userdata; e.subindex=p_subindex; @@ -843,7 +843,7 @@ OctreeElementID Octree<T,use_pairs,AL>::create(T* p_userdata, const AABB& p_aabb e.pairable_type=p_pairable_type; e.pairable_mask=p_pairable_mask; e._id=last_element_id-1; - + if (!e.aabb.has_no_surface()) { _ensure_valid_root(p_aabb); _insert_element(&e,root); @@ -964,7 +964,7 @@ void Octree<T,use_pairs,AL>::move(OctreeElementID p_id, const AABB& p_aabb) { _insert_element(&e,common_parent); // reinsert from this point pass++; - + for(typename List<typename Element::OctantOwner,AL>::Element *E=owners.front();E;) { Octant *o=E->get().octant; @@ -1018,28 +1018,28 @@ void Octree<T,use_pairs,AL>::set_pairable(OctreeElementID p_id,bool p_pairable,u typename ElementMap::Element *E = element_map.find(p_id); ERR_FAIL_COND(!E); - + Element &e = E->get(); if (p_pairable == e.pairable && e.pairable_type==p_pairable_type && e.pairable_mask==p_pairable_mask) return; // no changes, return - + if (!e.aabb.has_no_surface()) { _remove_element(&e); } - + e.pairable=p_pairable; e.pairable_type=p_pairable_type; e.pairable_mask=p_pairable_mask; e.common_parent=NULL; - + if (!e.aabb.has_no_surface()) { _ensure_valid_root(e.aabb); _insert_element(&e,root); if (use_pairs) _element_check_pairs(&e); - } + } } @@ -1048,155 +1048,155 @@ void Octree<T,use_pairs,AL>::erase(OctreeElementID p_id) { typename ElementMap::Element *E = element_map.find(p_id); ERR_FAIL_COND(!E); - + Element &e = E->get(); if (!e.aabb.has_no_surface()) { - - _remove_element(&e); + + _remove_element(&e); } - + element_map.erase(p_id); _optimize(); } template<class T,bool use_pairs,class AL> void Octree<T,use_pairs,AL>::_cull_convex(Octant *p_octant,_CullConvexData *p_cull) { - + if (*p_cull->result_idx==p_cull->result_max) return; //pointless - + if (!p_octant->elements.empty()) { - + typename List< Element*,AL >::Element *I; I=p_octant->elements.front(); - + for(;I;I=I->next()) { - + Element *e=I->get(); - + if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_cull->mask))) continue; e->last_pass=pass; - + if (e->aabb.intersects_convex_shape(p_cull->planes,p_cull->plane_count)) { - + if (*p_cull->result_idx<p_cull->result_max) { p_cull->result_array[*p_cull->result_idx] = e->userdata; (*p_cull->result_idx)++; } else { - + return; // pointless to continue } } } } - + if (use_pairs && !p_octant->pairable_elements.empty()) { - + typename List< Element*,AL >::Element *I; I=p_octant->pairable_elements.front(); - + for(;I;I=I->next()) { - + Element *e=I->get(); - + if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_cull->mask))) continue; e->last_pass=pass; - + if (e->aabb.intersects_convex_shape(p_cull->planes,p_cull->plane_count)) { - + if (*p_cull->result_idx<p_cull->result_max) { p_cull->result_array[*p_cull->result_idx] = e->userdata; (*p_cull->result_idx)++; } else { - + return; // pointless to continue } } } } - + for (int i=0;i<8;i++) { - + if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_convex_shape(p_cull->planes,p_cull->plane_count)) { _cull_convex(p_octant->children[i],p_cull); } - } + } } template<class T,bool use_pairs,class AL> void Octree<T,use_pairs,AL>::_cull_AABB(Octant *p_octant,const AABB& p_aabb, T** p_result_array,int *p_result_idx,int p_result_max,int *p_subindex_array,uint32_t p_mask) { - + if (*p_result_idx==p_result_max) return; //pointless - + if (!p_octant->elements.empty()) { - + typename List< Element*,AL >::Element *I; I=p_octant->elements.front(); for(;I;I=I->next()) { - + Element *e=I->get(); - + if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_mask))) continue; e->last_pass=pass; - + if (p_aabb.intersects_inclusive(e->aabb)) { - + if (*p_result_idx<p_result_max) { - + p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - + return; // pointless to continue } } } } - + if (use_pairs && !p_octant->pairable_elements.empty()) { - + typename List< Element*,AL >::Element *I; I=p_octant->pairable_elements.front(); for(;I;I=I->next()) { - + Element *e=I->get(); - + if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_mask))) continue; e->last_pass=pass; - + if (p_aabb.intersects_inclusive(e->aabb)) { - + if (*p_result_idx<p_result_max) { - + p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - + return; // pointless to continue } } } - } + } for (int i=0;i<8;i++) { - + if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_inclusive(p_aabb)) { _cull_AABB(p_octant->children[i],p_aabb, p_result_array,p_result_idx,p_result_max,p_subindex_array,p_mask); } - } + } } @@ -1205,53 +1205,53 @@ void Octree<T,use_pairs,AL>::_cull_segment(Octant *p_octant,const Vector3& p_fro if (*p_result_idx==p_result_max) return; //pointless - + if (!p_octant->elements.empty()) { - + typename List< Element*,AL >::Element *I; I=p_octant->elements.front(); for(;I;I=I->next()) { - + Element *e=I->get(); - + if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_mask))) continue; e->last_pass=pass; - + if (e->aabb.intersects_segment(p_from,p_to)) { - + if (*p_result_idx<p_result_max) { - + p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; (*p_result_idx)++; } else { - + return; // pointless to continue } } } } - + if (use_pairs && !p_octant->pairable_elements.empty()) { - + typename List< Element*,AL >::Element *I; I=p_octant->pairable_elements.front(); for(;I;I=I->next()) { - + Element *e=I->get(); - + if (e->last_pass==pass || (use_pairs && !(e->pairable_type&p_mask))) continue; - + e->last_pass=pass; - + if (e->aabb.intersects_segment(p_from,p_to)) { - + if (*p_result_idx<p_result_max) { - + p_result_array[*p_result_idx] = e->userdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; @@ -1259,20 +1259,20 @@ void Octree<T,use_pairs,AL>::_cull_segment(Octant *p_octant,const Vector3& p_fro (*p_result_idx)++; } else { - + return; // pointless to continue } } } } - + for (int i=0;i<8;i++) { - + if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_segment(p_from,p_to)) { _cull_segment(p_octant->children[i],p_from,p_to, p_result_array,p_result_idx,p_result_max,p_subindex_array,p_mask); } - } + } } @@ -1357,7 +1357,7 @@ int Octree<T,use_pairs,AL>::cull_convex(const Vector<Plane>& p_convex,T** p_resu if (!root) return 0; - + int result_count=0; pass++; _CullConvexData cdata; @@ -1367,9 +1367,9 @@ int Octree<T,use_pairs,AL>::cull_convex(const Vector<Plane>& p_convex,T** p_resu cdata.result_max=p_result_max; cdata.result_idx=&result_count; cdata.mask=p_mask; - + _cull_convex(root,&cdata); - + return result_count; } @@ -1381,11 +1381,11 @@ int Octree<T,use_pairs,AL>::cull_AABB(const AABB& p_aabb,T** p_result_array,int if (!root) return 0; - + int result_count=0; pass++; _cull_AABB(root,p_aabb,p_result_array,&result_count,p_result_max,p_subindex_array,p_mask); - + return result_count; } @@ -1395,11 +1395,11 @@ int Octree<T,use_pairs,AL>::cull_segment(const Vector3& p_from, const Vector3& p if (!root) return 0; - + int result_count=0; pass++; _cull_segment(root,p_from,p_to,p_result_array,&result_count,p_result_max,p_subindex_array,p_mask); - + return result_count; } @@ -1436,7 +1436,7 @@ void Octree<T,use_pairs,AL>::set_unpair_callback( UnpairCallback p_callback, voi template<class T,bool use_pairs,class AL> Octree<T,use_pairs,AL>::Octree(real_t p_unit_size) { - + last_element_id=1; pass=1; unit_size=p_unit_size; diff --git a/core/math/plane.cpp b/core/math/plane.cpp index d17ce01bec..b29350fe3c 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -50,7 +50,7 @@ void Plane::normalize() { } Plane Plane::normalized() const { - + Plane p = *this; p.normalize(); return p; @@ -66,12 +66,12 @@ Vector3 Plane::get_any_perpendicular_normal() const { static const Vector3 p1 = Vector3(1,0,0); static const Vector3 p2 = Vector3(0,1,0); Vector3 p; - + if (ABS(normal.dot(p1)) > 0.99) // if too similar to p1 p=p2; // use p2 else p=p1; // use p1 - + p-=normal * normal.dot(p); p.normalize(); diff --git a/core/math/plane.h b/core/math/plane.h index d20e63dc47..81a968682e 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -62,9 +62,9 @@ public: bool intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3* p_intersection) const; _FORCE_INLINE_ Vector3 project(const Vector3& p_point) const { - + return p_point - normal * distance_to(p_point); - } + } /* misc */ diff --git a/core/math/quat.cpp b/core/math/quat.cpp index ebc5ec4e65..c6c12129b3 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -30,9 +30,9 @@ #include "print_string.h" void Quat::set_euler(const Vector3& p_euler) { - real_t half_yaw = p_euler.x * 0.5; - real_t half_pitch = p_euler.y * 0.5; - real_t half_roll = p_euler.z * 0.5; + real_t half_yaw = p_euler.x * 0.5; + real_t half_pitch = p_euler.y * 0.5; + real_t half_roll = p_euler.z * 0.5; real_t cos_yaw = Math::cos(half_yaw); real_t sin_yaw = Math::sin(half_yaw); real_t cos_pitch = Math::cos(half_pitch); @@ -75,7 +75,7 @@ void Quat::normalize() { Quat Quat::normalized() const { return *this / length(); -} +} Quat Quat::inverse() const { return Quat( -x, -y, -z, w ); @@ -252,7 +252,7 @@ Quat Quat::cubic_slerp(const Quat& q, const Quat& prep, const Quat& postq,const Quat::operator String() const { - return String::num(x)+","+String::num(y)+","+ String::num(z)+","+ String::num(w); + return String::num(x)+","+String::num(y)+","+ String::num(z)+","+ String::num(w); } Quat::Quat(const Vector3& axis, const real_t& angle) { @@ -261,7 +261,7 @@ Quat::Quat(const Vector3& axis, const real_t& angle) { set(0,0,0,0); else { real_t s = Math::sin(-angle * 0.5) / d; - set(axis.x * s, axis.y * s, axis.z * s, + set(axis.x * s, axis.y * s, axis.z * s, Math::cos(-angle * 0.5)); } } diff --git a/core/math/quat.h b/core/math/quat.h index 738b6946c7..0d206bb3b7 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -89,18 +89,18 @@ public: _FORCE_INLINE_ Quat operator-() const; _FORCE_INLINE_ Quat operator*(const real_t& s) const; _FORCE_INLINE_ Quat operator/(const real_t& s) const; - + _FORCE_INLINE_ bool operator==(const Quat& p_quat) const; _FORCE_INLINE_ bool operator!=(const Quat& p_quat) const; - + operator String() const; - + inline void set( real_t p_x, real_t p_y, real_t p_z, real_t p_w) { - x=p_x; y=p_y; z=p_z; w=p_w; + x=p_x; y=p_y; z=p_z; w=p_w; } inline Quat(real_t p_x, real_t p_y, real_t p_z, real_t p_w) { - x=p_x; y=p_y; z=p_z; w=p_w; + x=p_x; y=p_y; z=p_z; w=p_w; } Quat(const Vector3& axis, const real_t& angle); @@ -127,7 +127,7 @@ public: } inline Quat() {x=y=z=0; w=1; } - + }; @@ -141,7 +141,7 @@ real_t Quat::length_squared() const { } void Quat::operator+=(const Quat& q) { - x += q.x; y += q.y; z += q.z; w += q.w; + x += q.x; y += q.y; z += q.z; w += q.w; } void Quat::operator-=(const Quat& q) { diff --git a/core/math/transform.cpp b/core/math/transform.cpp index 8371f7e34b..22eb6c4fdd 100644 --- a/core/math/transform.cpp +++ b/core/math/transform.cpp @@ -30,7 +30,7 @@ #include "math_funcs.h" #include "os/copymem.h" #include "print_string.h" - + void Transform::affine_invert() { @@ -50,7 +50,7 @@ Transform Transform::affine_inverse() const { void Transform::invert() { basis.transpose(); - origin = basis.xform(-origin); + origin = basis.xform(-origin); } Transform Transform::inverse() const { @@ -87,30 +87,30 @@ void Transform::set_look_at( const Vector3& p_eye, const Vector3& p_target, cons // Reference: MESA source code Vector3 v_x, v_y, v_z; - + /* Make rotation matrix */ - + /* Z vector */ v_z = p_eye - p_target; - + v_z.normalize(); - + v_y = p_up; - + v_x=v_y.cross(v_z); - + /* Recompute Y = Z cross X */ v_y=v_z.cross(v_x); - + v_x.normalize(); v_y.normalize(); - + basis.set_axis(0,v_x); basis.set_axis(1,v_y); basis.set_axis(2,v_z); origin=p_eye; - + } Transform Transform::interpolate_with(const Transform& p_transform, float p_c) const { @@ -193,7 +193,7 @@ bool Transform::operator!=(const Transform& p_transform) const { void Transform::operator*=(const Transform& p_transform) { origin=xform(p_transform.origin); - basis*=p_transform.basis; + basis*=p_transform.basis; } Transform Transform::operator*(const Transform& p_transform) const { diff --git a/core/math/transform.h b/core/math/transform.h index bd1247084d..f948a4c919 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -40,9 +40,9 @@ public: Matrix3 basis; Vector3 origin; - - void invert(); - Transform inverse() const; + + void invert(); + Transform inverse() const; void affine_invert(); Transform affine_inverse() const; @@ -76,27 +76,27 @@ public: _FORCE_INLINE_ Vector3 xform(const Vector3& p_vector) const; _FORCE_INLINE_ Vector3 xform_inv(const Vector3& p_vector) const; - + _FORCE_INLINE_ Plane xform(const Plane& p_plane) const; _FORCE_INLINE_ Plane xform_inv(const Plane& p_plane) const; _FORCE_INLINE_ AABB xform(const AABB& p_aabb) const; _FORCE_INLINE_ AABB xform_inv(const AABB& p_aabb) const; - + void operator*=(const Transform& p_transform); Transform operator*(const Transform& p_transform) const; Transform interpolate_with(const Transform& p_transform, float p_c) const; - + _FORCE_INLINE_ Transform inverse_xform(const Transform& t) const { - + Vector3 v = t.origin - origin; return Transform(basis.transpose_xform(t.basis), basis.xform(v)); } - + void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz,real_t tx, real_t ty, real_t tz) { - + basis.elements[0][0]=xx; basis.elements[0][1]=xy; basis.elements[0][2]=xz; @@ -105,14 +105,14 @@ public: basis.elements[1][2]=yz; basis.elements[2][0]=zx; basis.elements[2][1]=zy; - basis.elements[2][2]=zz; + basis.elements[2][2]=zz; origin.x=tx; origin.y=ty; origin.z=tz; } - + operator String() const; - + Transform(const Matrix3& p_basis, const Vector3& p_origin=Vector3()); Transform() {} @@ -128,9 +128,9 @@ _FORCE_INLINE_ Vector3 Transform::xform(const Vector3& p_vector) const { ); } _FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3& p_vector) const { - + Vector3 v = p_vector - origin; - + return Vector3( (basis.elements[0][0]*v.x ) + ( basis.elements[1][0]*v.y ) + ( basis.elements[2][0]*v.z ), (basis.elements[0][1]*v.x ) + ( basis.elements[1][1]*v.y ) + ( basis.elements[2][1]*v.z ), @@ -140,16 +140,16 @@ _FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3& p_vector) const { _FORCE_INLINE_ Plane Transform::xform(const Plane& p_plane) const { - + Vector3 point=p_plane.normal*p_plane.d; Vector3 point_dir=point+p_plane.normal; point=xform(point); point_dir=xform(point_dir); - + Vector3 normal=point_dir-point; normal.normalize(); real_t d=normal.dot(point); - + return Plane(normal,d); } @@ -159,11 +159,11 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane& p_plane) const { Vector3 point_dir=point+p_plane.normal; xform_inv(point); xform_inv(point_dir); - + Vector3 normal=point_dir-point; normal.normalize(); real_t d=normal.dot(point); - + return Plane(normal,d); } @@ -199,17 +199,17 @@ _FORCE_INLINE_ AABB Transform::xform(const AABB& p_aabb) const { Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z), Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z) }; - - + + AABB ret; - + ret.pos=xform(vertices[0]); - + for (int i=1;i<8;i++) { - + ret.expand_to( xform(vertices[i]) ); } - + return ret; #endif @@ -227,17 +227,17 @@ _FORCE_INLINE_ AABB Transform::xform_inv(const AABB& p_aabb) const { Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z+p_aabb.size.z), Vector3(p_aabb.pos.x, p_aabb.pos.y, p_aabb.pos.z) }; - - + + AABB ret; - + ret.pos=xform_inv(vertices[0]); - + for (int i=1;i<8;i++) { - + ret.expand_to( xform_inv(vertices[i]) ); } - + return ret; } diff --git a/core/method_bind.h b/core/method_bind.h index da3d7c1062..48848c5848 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -58,8 +58,8 @@ template<class T> struct VariantCaster { static _FORCE_INLINE_ T cast(const Variant& p_variant) { - - return p_variant; + + return p_variant; } }; @@ -67,8 +67,8 @@ template<class T> struct VariantCaster<T&> { static _FORCE_INLINE_ T cast(const Variant& p_variant) { - - return p_variant; + + return p_variant; } }; @@ -76,8 +76,8 @@ template<class T> struct VariantCaster<const T&> { static _FORCE_INLINE_ T cast(const Variant& p_variant) { - - return p_variant; + + return p_variant; } }; diff --git a/core/object.cpp b/core/object.cpp index c92fc35b24..7bdec06c1b 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -255,7 +255,7 @@ Object::Connection::Connection(const Variant& p_variant) { bool Object::_predelete() { - + _predelete_ok=1; notification(NOTIFICATION_PREDELETE,true); if (_predelete_ok) { @@ -269,16 +269,16 @@ void Object::_postinitialize() { _type_ptr=_get_type_namev(); _initialize_typev(); notification(NOTIFICATION_POSTINITIALIZE); - + } void Object::get_valid_parents_static(List<String> *p_parents) { - - + + } void Object::_get_valid_parents_static(List<String> *p_parents) { - - + + } #if 0 //old style set, deprecated @@ -286,7 +286,7 @@ void Object::_get_valid_parents_static(List<String> *p_parents) { void Object::set(const String& p_name, const Variant& p_value) { _setv(p_name,p_value); - + //if (!_use_builtin_script()) // return; @@ -303,8 +303,8 @@ void Object::set(const String& p_name, const Variant& p_value) { } else if (script_instance) { script_instance->set(p_name,p_value); } - - + + } #endif @@ -348,7 +348,7 @@ void Object::set(const StringName& p_name, const Variant& p_value, bool *r_valid *r_valid=true; return; } else { - //something inside the object... :| + //something inside the object... :| bool success = _setv(p_name,p_value); if (success) { if (r_valid) @@ -420,7 +420,7 @@ Variant Object::get(const String& p_name) const { Variant ret=_getv(p_name); if (ret.get_type()!=Variant::NIL) return ret; - + bool success; ObjectTypeDB::get_property(const_cast<Object*>(this),p_name,ret,success); if (success) { @@ -431,11 +431,11 @@ Variant Object::get(const String& p_name) const { return metadata; else if (p_name=="script/script") return script; - + if (script_instance) { return script_instance->get(p_name); } - + return Variant(); } @@ -449,10 +449,10 @@ void Object::get_property_list(List<PropertyInfo> *p_list,bool p_reversed) const } _get_property_listv(p_list,p_reversed); - + if (!_use_builtin_script()) return; - + if (!is_type("Script")) // can still be set, but this is for userfriendlyness p_list->push_back( PropertyInfo( Variant::OBJECT, "script/script", PROPERTY_HINT_RESOURCE_TYPE, "Script",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_STORE_IF_NONZERO)); if (!metadata.empty()) @@ -460,15 +460,15 @@ void Object::get_property_list(List<PropertyInfo> *p_list,bool p_reversed) const if (script_instance && !p_reversed) { p_list->push_back( PropertyInfo(Variant::NIL,"Script Variables",PROPERTY_HINT_NONE,String(),PROPERTY_USAGE_CATEGORY)); script_instance->get_property_list(p_list); - } - + } + } void Object::get_method_list(List<MethodInfo> *p_list) const { ObjectTypeDB::get_method_list(get_type_name(),p_list); if (script_instance) { script_instance->get_method_list(p_list); - } + } } @@ -898,22 +898,22 @@ Variant Object::call(const StringName& p_method,const Variant** p_args,int p_arg void Object::notification(int p_notification,bool p_reversed) { - + _notificationv(p_notification,p_reversed); - + if (script_instance) { script_instance->notification(p_notification); } } void Object::_changed_callback(Object *p_changed,const char *p_prop) { - - + + } void Object::add_change_receptor( Object *p_receptor ) { - + change_receptors.insert(p_receptor); } @@ -941,8 +941,8 @@ void Object::set_script(const RefPtr& p_script) { memdelete(script_instance); script_instance=NULL; } - - script=p_script; + + script=p_script; Ref<Script> s(script); if (!s.is_null() && s->can_instance() ) { @@ -1760,7 +1760,7 @@ bool Object::is_edited() const { #endif Object::Object() { - + _type_ptr=NULL; _block_signals=false; _predelete_ok=0; @@ -1831,12 +1831,12 @@ Object::~Object() { bool predelete_handler(Object *p_object) { - + return p_object->_predelete(); } void postinitialize_handler(Object *p_object) { - + p_object->_postinitialize(); } @@ -1900,8 +1900,8 @@ void ObjectDB::cleanup() { GLOBAL_LOCK_FUNCTION; if (instances.size()) { - - WARN_PRINT("ObjectDB Instances still exist!"); + + WARN_PRINT("ObjectDB Instances still exist!"); if (OS::get_singleton()->is_stdout_verbose()) { const uint32_t *K=NULL; while((K=instances.next(K))) { diff --git a/core/object_type_db.cpp b/core/object_type_db.cpp index dd9304f1f9..14b595d61b 100644 --- a/core/object_type_db.cpp +++ b/core/object_type_db.cpp @@ -200,37 +200,37 @@ ObjectTypeDB::TypeInfo::TypeInfo() { disabled=false; } ObjectTypeDB::TypeInfo::~TypeInfo() { - - + + } bool ObjectTypeDB::is_type(const StringName &p_type,const StringName& p_inherits) { - + OBJTYPE_LOCK; - + StringName inherits=p_type; - + while (inherits.operator String().length()) { - + if (inherits==p_inherits) return true; inherits=type_inherits_from(inherits); } - + return false; } void ObjectTypeDB::get_type_list( List<StringName> *p_types) { - + OBJTYPE_LOCK; - + const StringName *k=NULL; - + while((k=types.next(k))) { - + p_types->push_back(*k); } - + p_types->sort(); } @@ -238,11 +238,11 @@ void ObjectTypeDB::get_type_list( List<StringName> *p_types) { void ObjectTypeDB::get_inheriters_from( const StringName& p_type,List<StringName> *p_types) { OBJTYPE_LOCK; - + const StringName *k=NULL; - + while((k=types.next(k))) { - + if (*k!=p_type && is_type(*k,p_type)) p_types->push_back(*k); } @@ -250,18 +250,18 @@ void ObjectTypeDB::get_inheriters_from( const StringName& p_type,List<StringName } StringName ObjectTypeDB::type_inherits_from(const StringName& p_type) { - + OBJTYPE_LOCK; - + TypeInfo *ti = types.getptr(p_type); ERR_FAIL_COND_V(!ti,""); return ti->inherits; } bool ObjectTypeDB::type_exists(const StringName &p_type) { - + OBJTYPE_LOCK; - return types.has(p_type); + return types.has(p_type); } void ObjectTypeDB::add_compatibility_type(const StringName& p_type,const StringName& p_fallback) { @@ -270,7 +270,7 @@ void ObjectTypeDB::add_compatibility_type(const StringName& p_type,const StringN } Object *ObjectTypeDB::instance(const StringName &p_type) { - + TypeInfo *ti; { OBJTYPE_LOCK; @@ -288,9 +288,9 @@ Object *ObjectTypeDB::instance(const StringName &p_type) { return ti->creation_func(); } bool ObjectTypeDB::can_instance(const StringName &p_type) { - + OBJTYPE_LOCK; - + TypeInfo *ti = types.getptr(p_type); ERR_FAIL_COND_V(!ti,false); return (!ti->disabled && ti->creation_func!=NULL); @@ -326,11 +326,11 @@ void ObjectTypeDB::get_method_list(StringName p_type,List<MethodInfo> *p_methods OBJTYPE_LOCK; - + TypeInfo *type=types.getptr(p_type); - + while(type) { - + if (type->disabled) { if (p_no_inheritance) @@ -348,14 +348,14 @@ void ObjectTypeDB::get_method_list(StringName p_type,List<MethodInfo> *p_methods } for( List<StringName>::Element *E=type->method_order.front();E;E=E->next()) { - + MethodBind *method=type->method_map.get(E->get()); MethodInfo minfo; minfo.name=E->get(); minfo.id=method->get_method_id(); for (int i=0;i<method->get_argument_count();i++) { - + //Variant::Type t=method->get_argument_type(i); minfo.arguments.push_back(method->get_argument_info(i)); @@ -386,24 +386,24 @@ void ObjectTypeDB::get_method_list(StringName p_type,List<MethodInfo> *p_methods #endif - + if (p_no_inheritance) break; - + type=type->inherits_ptr; } - + } MethodBind *ObjectTypeDB::get_method(StringName p_type, StringName p_name) { OBJTYPE_LOCK; - + TypeInfo *type=types.getptr(p_type); - + while(type) { - + MethodBind **method=type->method_map.getptr(p_name); if (method && *method) return *method; @@ -416,18 +416,18 @@ MethodBind *ObjectTypeDB::get_method(StringName p_type, StringName p_name) { void ObjectTypeDB::bind_integer_constant(const StringName& p_type, const StringName &p_name, int p_constant) { OBJTYPE_LOCK; - + TypeInfo *type=types.getptr(p_type); if (!type) { ERR_FAIL_COND(!type); } - + if (type->constant_map.has(p_name)) { ERR_FAIL(); } - + type->constant_map[p_name]=p_constant; #ifdef DEBUG_METHODS_ENABLED type->constant_order.push_back(p_name); @@ -438,11 +438,11 @@ void ObjectTypeDB::bind_integer_constant(const StringName& p_type, const StringN void ObjectTypeDB::get_integer_constant_list(const StringName& p_type, List<String> *p_constants, bool p_no_inheritance) { OBJTYPE_LOCK; - + TypeInfo *type=types.getptr(p_type); - + while(type) { - + #ifdef DEBUG_METHODS_ENABLED for(List<StringName>::Element *E=type->constant_order.front();E;E=E->next()) p_constants->push_back(E->get()); @@ -456,7 +456,7 @@ void ObjectTypeDB::get_integer_constant_list(const StringName& p_type, List<Stri #endif if (p_no_inheritance) break; - + type=type->inherits_ptr; } @@ -466,28 +466,28 @@ void ObjectTypeDB::get_integer_constant_list(const StringName& p_type, List<Stri int ObjectTypeDB::get_integer_constant(const StringName& p_type, const StringName &p_name, bool *p_success) { OBJTYPE_LOCK; - - + + TypeInfo *type=types.getptr(p_type); - + while(type) { - + int *constant=type->constant_map.getptr(p_name); if (constant) { - + if (p_success) *p_success=true; return *constant; } - + type=type->inherits_ptr; } - + if (p_success) - *p_success=false; + *p_success=false; - return 0; + return 0; } void ObjectTypeDB::add_signal(StringName p_type,const MethodInfo& p_signal) { @@ -966,7 +966,7 @@ void ObjectTypeDB::init() { } void ObjectTypeDB::cleanup() { - + #ifndef NO_THREADS @@ -974,19 +974,19 @@ void ObjectTypeDB::cleanup() { #endif //OBJTYPE_LOCK; hah not here - + const StringName *k=NULL; - + while((k=types.next(k))) { - + TypeInfo &ti=types[*k]; - + const StringName *m=NULL; while((m=ti.method_map.next(m))) { - + memdelete( ti.method_map[*m] ); } - } + } types.clear(); resource_base_extensions.clear(); compat_types.clear(); diff --git a/core/object_type_db.h b/core/object_type_db.h index f6caf14be5..a4896fff81 100644 --- a/core/object_type_db.h +++ b/core/object_type_db.h @@ -42,9 +42,9 @@ struct ParamHint { PropertyHint hint; String hint_text; Variant default_val; - + ParamHint(const String& p_name="", PropertyHint p_hint=PROPERTY_HINT_NONE, const String& p_hint_text="",Variant p_default_val=Variant()) { - + name=p_name; hint=p_hint; hint_text=p_hint_text; @@ -73,9 +73,9 @@ struct MethodDefinition { StringName name; Vector<StringName> args; - MethodDefinition() {} + MethodDefinition() {} MethodDefinition(const char *p_name) { name=p_name; } - MethodDefinition(const StringName& p_name) { name=p_name; } + MethodDefinition(const StringName& p_name) { name=p_name; } }; @@ -109,7 +109,7 @@ static _FORCE_INLINE_ const char* _MD(const char* m_name, ...) { return m_name; #endif class ObjectTypeDB { - + struct PropertySetGet { int index; @@ -121,7 +121,7 @@ class ObjectTypeDB { }; struct TypeInfo { - + TypeInfo *inherits_ptr; HashMap<StringName,MethodBind*,StringNameHasher> method_map; HashMap<StringName,int,StringNameHasher> constant_map; @@ -143,12 +143,12 @@ class ObjectTypeDB { TypeInfo(); ~TypeInfo(); }; - + template<class T> static Object *creator() { return memnew( T ); } - + static Mutex *lock; static HashMap<StringName,TypeInfo,StringNameHasher> types; static HashMap<StringName,StringName,StringNameHasher> resource_base_extensions; @@ -163,8 +163,8 @@ class ObjectTypeDB { static void _add_type2(const StringName& p_type, const StringName& p_inherits); -public: - +public: + // DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!! template<class T> static void _add_type() { @@ -195,7 +195,7 @@ public: template<class T> static void register_type() { - + GLOBAL_LOCK_FUNCTION; T::initialize_type(); TypeInfo *t=types.getptr(T::get_type_static()); @@ -206,7 +206,7 @@ public: template<class T> static void register_virtual_type() { - + GLOBAL_LOCK_FUNCTION; T::initialize_type(); //nothing @@ -247,9 +247,9 @@ public: ParamDef d4=ParamDef(), ParamDef d5=ParamDef() ) { - + return bind_methodf(METHOD_FLAGS_DEFAULT,p_method_name, p_method, d1,d2,d3,d4,d5); - } + } @@ -472,7 +472,7 @@ public: static void add_virtual_method(const StringName& p_type,const MethodInfo& p_method,bool p_virtual=true ); static void get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods,bool p_no_inheritance=false ); - + static void bind_integer_constant(const StringName& p_type, const StringName &p_name, int p_constant); static void get_integer_constant_list(const StringName& p_type, List<String> *p_constants, bool p_no_inheritance=false); static int get_integer_constant(const StringName& p_type, const StringName &p_name, bool *p_success=NULL); diff --git a/core/os/copymem.cpp b/core/os/copymem.cpp index 234ca50b45..49f53f1a51 100644 --- a/core/os/copymem.cpp +++ b/core/os/copymem.cpp @@ -32,7 +32,7 @@ void movemem_system(void *to, void *from,int amount) { - memmove(to,from,amount); + memmove(to,from,amount); } diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp index 32d66a7408..9a7135913a 100644 --- a/core/os/dir_access.cpp +++ b/core/os/dir_access.cpp @@ -344,7 +344,7 @@ DirAccess *DirAccess::open(const String& p_path,Error *r_error) { } DirAccess *DirAccess::create(AccessType p_access) { - + DirAccess * da = create_func[p_access]?create_func[p_access]():NULL; if (da) { da->_access_type=p_access; @@ -359,7 +359,7 @@ String DirAccess::get_full_path(const String& p_path,AccessType p_access) { DirAccess *d=DirAccess::create(p_access); if (!d) return p_path; - + d->change_dir(p_path); String full=d->get_current_dir(); memdelete(d); @@ -367,31 +367,31 @@ String DirAccess::get_full_path(const String& p_path,AccessType p_access) { } Error DirAccess::copy(String p_from,String p_to) { - + //printf("copy %s -> %s\n",p_from.ascii().get_data(),p_to.ascii().get_data()); Error err; FileAccess *fsrc = FileAccess::open(p_from, FileAccess::READ,&err); - + if (err) { ERR_FAIL_COND_V( err, err ); } - + FileAccess *fdst = FileAccess::open(p_to, FileAccess::WRITE,&err ); if (err) { - + fsrc->close(); memdelete( fsrc ); ERR_FAIL_COND_V( err, err ); } - + fsrc->seek_end(0); int size = fsrc->get_pos(); fsrc->seek(0); err = OK; while(size--) { - + if (fsrc->get_error()!=OK) { err= fsrc->get_error(); break; @@ -400,13 +400,13 @@ Error DirAccess::copy(String p_from,String p_to) { err= fdst->get_error(); break; } - + fdst->store_8( fsrc->get_8() ); } - + memdelete(fsrc); memdelete(fdst); - + return err; } diff --git a/core/os/dir_access.h b/core/os/dir_access.h index e97a065998..7a850ddc6d 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -79,13 +79,13 @@ public: virtual String get_next()=0; virtual bool current_is_dir() const=0; virtual bool current_is_hidden() const=0; - - virtual void list_dir_end()=0; ///< - + + virtual void list_dir_end()=0; ///< + virtual int get_drive_count()=0; virtual String get_drive(int p_drive)=0; virtual int get_current_drive(); - + virtual Error change_dir(String p_dir)=0; ///< can be relative or absolute, return false on success virtual String get_current_dir()=0; ///< return current dir location virtual Error make_dir(String p_dir)=0; @@ -100,7 +100,7 @@ public: virtual Error copy(String p_from,String p_to); virtual Error rename(String p_from, String p_to)=0; virtual Error remove(String p_name)=0; - + static String get_full_path(const String& p_path,AccessType p_access); static DirAccess *create_for_path(const String& p_path); @@ -111,7 +111,7 @@ public: FILE_TYPE_FILE, FILE_TYPE_DIR, }; - + //virtual DirType get_file_type() const=0; */ static DirAccess *create(AccessType p_access); diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp index 68c9dee84d..0846ef3eb0 100644 --- a/core/os/file_access.cpp +++ b/core/os/file_access.cpp @@ -169,69 +169,69 @@ String FileAccess::fix_path(const String& p_path) const { return r_path; } break; } - + return r_path; } /* these are all implemented for ease of porting, then can later be optimized */ uint16_t FileAccess::get_16()const { - + uint16_t res; uint8_t a,b; - + a=get_8(); b=get_8(); - + if (endian_swap) { - + SWAP( a,b ); } - + res=b; res<<=8; res|=a; - + return res; } uint32_t FileAccess::get_32() const{ - + uint32_t res; uint16_t a,b; - + a=get_16(); b=get_16(); - + if (endian_swap) { - + SWAP( a,b ); } - + res=b; res<<=16; res|=a; - - return res; + + return res; } uint64_t FileAccess::get_64()const { - + uint64_t res; uint32_t a,b; - + a=get_32(); b=get_32(); - + if (endian_swap) { - + SWAP( a,b ); } - + res=b; res<<=32; res|=a; - - return res; - + + return res; + } float FileAccess::get_float() const { @@ -262,15 +262,15 @@ String FileAccess::get_line() const { CharString line; CharType c=get_8(); - + while(!eof_reached()) { - + if (c=='\n' || c=='\0') { line.push_back(0); return String::utf8(line.get_data()); } else if (c!='\r') line.push_back(c); - + c=get_8(); } line.push_back(0); @@ -331,7 +331,7 @@ Vector<String> FileAccess::get_csv_line(String delim) const { int FileAccess::get_buffer(uint8_t *p_dst,int p_length) const{ - + int i=0; for (i=0; i<p_length && !eof_reached(); i++) p_dst[i]=get_8(); @@ -340,53 +340,53 @@ int FileAccess::get_buffer(uint8_t *p_dst,int p_length) const{ } void FileAccess::store_16(uint16_t p_dest) { - + uint8_t a,b; - + a=p_dest&0xFF; b=p_dest>>8; - + if (endian_swap) { - + SWAP( a,b ); } - + store_8(a); store_8(b); } void FileAccess::store_32(uint32_t p_dest) { - - + + uint16_t a,b; - + a=p_dest&0xFFFF; b=p_dest>>16; - + if (endian_swap) { - + SWAP( a,b ); } - + store_16(a); store_16(b); - + } void FileAccess::store_64(uint64_t p_dest) { - + uint32_t a,b; - + a=p_dest&0xFFFFFFFF; b=p_dest>>32; - + if (endian_swap) { - + SWAP( a,b ); } - + store_32(a); store_32(b); - + } void FileAccess::store_real(real_t p_real) { @@ -461,7 +461,7 @@ void FileAccess::store_line(const String& p_line) { } void FileAccess::store_buffer(const uint8_t *p_src,int p_length) { - + for (int i=0;i<p_length;i++) store_8(p_src[i]); } diff --git a/core/os/file_access.h b/core/os/file_access.h index 3249e21ffb..2c894c94eb 100644 --- a/core/os/file_access.h +++ b/core/os/file_access.h @@ -80,21 +80,21 @@ public: READ_WRITE=3, WRITE_READ=7, }; - - virtual void close()=0; ///< close a file - virtual bool is_open() const=0; ///< true when file is open - virtual void seek(size_t p_position)=0; ///< seek to a given position - virtual void seek_end(int64_t p_position=0)=0; ///< seek from the end of file - virtual size_t get_pos() const=0; ///< get position in the file - virtual size_t get_len() const=0; ///< get size of the file + virtual void close()=0; ///< close a file + virtual bool is_open() const=0; ///< true when file is open - virtual bool eof_reached() const=0; ///< reading passed EOF + virtual void seek(size_t p_position)=0; ///< seek to a given position + virtual void seek_end(int64_t p_position=0)=0; ///< seek from the end of file + virtual size_t get_pos() const=0; ///< get position in the file + virtual size_t get_len() const=0; ///< get size of the file - virtual uint8_t get_8() const=0; ///< get a byte - virtual uint16_t get_16() const; ///< get 16 bits uint - virtual uint32_t get_32() const; ///< get 32 bits uint - virtual uint64_t get_64() const; ///< get 64 bits uint + virtual bool eof_reached() const=0; ///< reading passed EOF + + virtual uint8_t get_8() const=0; ///< get a byte + virtual uint16_t get_16() const; ///< get 16 bits uint + virtual uint32_t get_32() const; ///< get 32 bits uint + virtual uint64_t get_64() const; ///< get 64 bits uint virtual float get_float() const; virtual double get_double() const; @@ -103,21 +103,21 @@ public: virtual int get_buffer(uint8_t *p_dst,int p_length) const; ///< get an array of bytes virtual String get_line() const; virtual Vector<String> get_csv_line(String delim=",") const; - + /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac) * It's not about the current CPU type but file formats. * this flags get reset to false (little endian) on each open */ - + virtual void set_endian_swap(bool p_swap) { endian_swap=p_swap; } inline bool get_endian_swap() const { return endian_swap; } - virtual Error get_error() const=0; ///< get last error + virtual Error get_error() const=0; ///< get last error - virtual void store_8(uint8_t p_dest)=0; ///< store a byte - virtual void store_16(uint16_t p_dest); ///< store 16 bits uint - virtual void store_32(uint32_t p_dest); ///< store 32 bits uint - virtual void store_64(uint64_t p_dest); ///< store 64 bits uint + virtual void store_8(uint8_t p_dest)=0; ///< store a byte + virtual void store_16(uint16_t p_dest); ///< store 16 bits uint + virtual void store_32(uint32_t p_dest); ///< store 32 bits uint + virtual void store_64(uint64_t p_dest); ///< store 64 bits uint virtual void store_float(float p_dest); virtual void store_double(double p_dest); @@ -129,9 +129,9 @@ public: virtual void store_pascal_string(const String& p_string); virtual String get_pascal_string(); - virtual void store_buffer(const uint8_t *p_src,int p_length); ///< store an array of bytes - - virtual bool file_exists(const String& p_name)=0; ///< return true if a file exists + virtual void store_buffer(const uint8_t *p_src,int p_length); ///< store an array of bytes + + virtual bool file_exists(const String& p_name)=0; ///< return true if a file exists virtual Error reopen(const String& p_path, int p_mode_flags); ///< does not change the AccessType diff --git a/core/os/input.h b/core/os/input.h index 2dd4496f26..535776f39c 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -55,7 +55,7 @@ public: static Input *get_singleton(); - virtual bool is_key_pressed(int p_scancode)=0; + virtual bool is_key_pressed(int p_scancode)=0; virtual bool is_mouse_button_pressed(int p_button)=0; virtual bool is_joy_button_pressed(int p_device, int p_button)=0; virtual bool is_action_pressed(const StringName& p_action)=0; diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 3022a56e2a..2d47645a66 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -30,7 +30,7 @@ #include "input_map.h" #include "os/keyboard.h" /** - * + * */ bool InputEvent::operator==(const InputEvent &p_event) const { @@ -40,15 +40,15 @@ bool InputEvent::operator==(const InputEvent &p_event) const { InputEvent::operator String() const { String str="Device "+itos(device)+" ID "+itos(ID)+" "; - + switch(type) { - + case NONE: { - + return "Event: None"; } break; case KEY: { - + str+= "Event: Key "; str=str+"Unicode: "+String::chr(key.unicode)+" Scan: "+itos( key.scancode )+" Echo: "+String(key.echo?"True":"False")+" Pressed"+String(key.pressed?"True":"False")+" Mod: "; if (key.mod.shift) @@ -59,15 +59,15 @@ InputEvent::operator String() const { str+="A"; if (key.mod.meta) str+="M"; - + return str; } break; case MOUSE_MOTION: { - + str+= "Event: Motion "; str=str+" Pos: " +itos(mouse_motion.x)+","+itos(mouse_motion.y)+" Rel: "+itos(mouse_motion.relative_x)+","+itos(mouse_motion.relative_y)+" Mask: "; for (int i=0;i<8;i++) { - + if ((1<<i)&mouse_motion.button_mask) str+=itos(i+1); } @@ -87,7 +87,7 @@ InputEvent::operator String() const { str+= "Event: Button "; str=str+"Pressed: "+itos(mouse_button.pressed)+" Pos: " +itos(mouse_button.x)+","+itos(mouse_button.y)+" Button: "+itos(mouse_button.button_index)+" Mask: "; for (int i=0;i<8;i++) { - + if ((1<<i)&mouse_button.button_mask) str+=itos(i+1); } @@ -102,9 +102,9 @@ InputEvent::operator String() const { str+="M"; str+=String(" DoubleClick: ")+(mouse_button.doubleclick?"Yes":"No"); - + return str; - + } break; case JOYSTICK_MOTION: { str+= "Event: JoystickMotion "; @@ -137,7 +137,7 @@ InputEvent::operator String() const { } break; } - + return ""; } diff --git a/core/os/input_event.h b/core/os/input_event.h index 36c1556524..0588374790 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -189,7 +189,7 @@ struct InputModifierState { struct InputEventKey { InputModifierState mod; - + bool pressed; /// otherwise release uint32_t scancode; ///< check keyboard.h , KeyCode enum, without modifier masks @@ -212,11 +212,11 @@ struct InputEventMouse { struct InputEventMouseButton : public InputEventMouse { - + int button_index; bool pressed; //otherwise released bool doubleclick; //last even less than doubleclick time - + }; struct InputEventMouseMotion : public InputEventMouse { diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 0848f8c28e..80472acc09 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -121,7 +121,7 @@ enum KeyList { KEY_DIRECTION_R=SPKEY | 0x33, KEY_BACK=SPKEY | 0x40, KEY_FORWARD=SPKEY | 0x41, - KEY_STOP=SPKEY | 0x42, + KEY_STOP=SPKEY | 0x42, KEY_REFRESH=SPKEY | 0x43, KEY_VOLUMEDOWN=SPKEY | 0x44, KEY_VOLUMEMUTE=SPKEY | 0x45, @@ -159,11 +159,11 @@ enum KeyList { KEY_LAUNCHD=SPKEY | 0x65, KEY_LAUNCHE=SPKEY | 0x66, KEY_LAUNCHF=SPKEY | 0x67, - + KEY_UNKNOWN=SPKEY | 0xFFFFFF, - + /* PRINTABLE LATIN 1 CODES */ - + KEY_SPACE=0x0020, KEY_EXCLAM=0x0021, KEY_QUOTEDBL=0x0022, @@ -297,18 +297,18 @@ enum KeyList { KEY_YACUTE=0x00DD, KEY_THORN=0x00DE, KEY_SSHARP=0x00DF, - + KEY_DIVISION=0x00F7, KEY_YDIAERESIS=0x00FF, - - + + }; enum KeyModifierMask { - + KEY_CODE_MASK=((1<<25)-1), ///< Apply this mask to any keycode to remove modifiers. - KEY_MODIFIER_MASK=(0xFF<<24), ///< Apply this mask to isolate modifiers. + KEY_MODIFIER_MASK=(0xFF<<24), ///< Apply this mask to isolate modifiers. KEY_MASK_SHIFT = (1<<25), KEY_MASK_ALT = (1<<26), KEY_MASK_META = (1<<27), @@ -322,7 +322,7 @@ enum KeyModifierMask { KEY_MASK_KPAD = (1<<29), KEY_MASK_GROUP_SWITCH = (1<<30) // bit 31 can't be used because variant uses regular 32 bits int as datatype - + }; String keycode_get_string(uint32_t p_code); diff --git a/core/os/main_loop.h b/core/os/main_loop.h index 059624dbe4..a34014983e 100644 --- a/core/os/main_loop.h +++ b/core/os/main_loop.h @@ -36,7 +36,7 @@ @author Juan Linietsky <reduzio@gmail.com> */ class MainLoop : public Object { - + OBJ_TYPE( MainLoop, Object ); OBJ_CATEGORY("Main Loop"); @@ -44,7 +44,7 @@ class MainLoop : public Object { protected: static void _bind_methods(); -public: +public: enum { NOTIFICATION_WM_MOUSE_ENTER = 3, @@ -55,7 +55,7 @@ public: NOTIFICATION_WM_UNFOCUS_REQUEST = 8, NOTIFICATION_OS_MEMORY_WARNING = 9, }; - + virtual void input_event( const InputEvent& p_event ); virtual void input_text( const String& p_text ); diff --git a/core/os/memory.cpp b/core/os/memory.cpp index f7f8fef2b7..c2ff2aa781 100644 --- a/core/os/memory.cpp +++ b/core/os/memory.cpp @@ -88,16 +88,16 @@ void Memory::dump_static_mem_to_file(const char* p_file) { MID Memory::alloc_dynamic(size_t p_bytes, const char *p_descr) { MemoryPoolDynamic::ID id = MemoryPoolDynamic::get_singleton()->alloc(p_bytes,p_descr); - + return MID(id); } Error Memory::realloc_dynamic(MID p_mid,size_t p_bytes) { MemoryPoolDynamic::ID id = p_mid.data?p_mid.data->id:MemoryPoolDynamic::INVALID_ID; - + if (id==MemoryPoolDynamic::INVALID_ID) return ERR_INVALID_PARAMETER; - + return MemoryPoolDynamic::get_singleton()->realloc(p_mid, p_bytes); } diff --git a/core/os/memory.h b/core/os/memory.h index 8eb5ceccb6..8257e66851 100644 --- a/core/os/memory.h +++ b/core/os/memory.h @@ -42,61 +42,61 @@ class MID { struct Data { - + SafeRefCount refcount; MemoryPoolDynamic::ID id; }; mutable Data *data; - + void unref() { - + if (!data) return; if (data->refcount.unref()) { - + if (data->id!=MemoryPoolDynamic::INVALID_ID) - MemoryPoolDynamic::get_singleton()->free(data->id); - MemoryPoolStatic::get_singleton()->free(data); + MemoryPoolDynamic::get_singleton()->free(data->id); + MemoryPoolStatic::get_singleton()->free(data); } - + data=NULL; } - + void ref(Data *p_data) { - + if (data==p_data) return; unref(); - + if (p_data && p_data->refcount.ref()) - data=p_data; + data=p_data; } - + friend class MID_Lock; inline void lock() { - + if (data && data->id!=MemoryPoolDynamic::INVALID_ID) MemoryPoolDynamic::get_singleton()->lock(data->id); } inline void unlock() { - + if (data && data->id!=MemoryPoolDynamic::INVALID_ID) MemoryPoolDynamic::get_singleton()->unlock(data->id); - + } - + inline void * get() { - + if (data && data->id!=MemoryPoolDynamic::INVALID_ID) return MemoryPoolDynamic::get_singleton()->get(data->id); - + return NULL; } - - Error _resize(size_t p_size) { - + + Error _resize(size_t p_size) { + if (p_size==0 && (!data || data->id==MemoryPoolDynamic::INVALID_ID)) return OK; if (p_size && !data) { @@ -104,46 +104,46 @@ friend class MID_Lock; data = (Data*)MemoryPoolStatic::get_singleton()->alloc(sizeof(Data),"MID::Data"); ERR_FAIL_COND_V( !data,ERR_OUT_OF_MEMORY ); data->refcount.init(); - data->id=MemoryPoolDynamic::INVALID_ID; + data->id=MemoryPoolDynamic::INVALID_ID; } - + if (p_size==0 && data && data->id==MemoryPoolDynamic::INVALID_ID) { - + MemoryPoolDynamic::get_singleton()->free(data->id); data->id=MemoryPoolDynamic::INVALID_ID; } - + if (p_size>0) { - + if (data->id==MemoryPoolDynamic::INVALID_ID) { - + data->id=MemoryPoolDynamic::get_singleton()->alloc(p_size,"Unnamed MID"); ERR_FAIL_COND_V( data->id==MemoryPoolDynamic::INVALID_ID, ERR_OUT_OF_MEMORY ); } else { - + MemoryPoolDynamic::get_singleton()->realloc(data->id,p_size); ERR_FAIL_COND_V( data->id==MemoryPoolDynamic::INVALID_ID, ERR_OUT_OF_MEMORY ); - + } - } - + } + return OK; } friend class Memory; - + MID(MemoryPoolDynamic::ID p_id) { - + data = (Data*)MemoryPoolStatic::get_singleton()->alloc(sizeof(Data),"MID::Data"); data->refcount.init(); data->id=p_id; } -public: +public: bool is_valid() const { return data; } operator bool() const { return data; } - - + + size_t get_size() const { return (data && data->id!=MemoryPoolDynamic::INVALID_ID) ? MemoryPoolDynamic::get_singleton()->get_size(data->id) : 0; } Error resize(size_t p_size) { return _resize(p_size); } inline void operator=(const MID& p_mid) { ref( p_mid.data ); } @@ -157,7 +157,7 @@ public: class MID_Lock { MID mid; - + public: void *data() { return mid.get(); } @@ -174,21 +174,21 @@ class Memory{ Memory(); public: - + static void * alloc_static(size_t p_bytes,const char *p_descr=""); static void * realloc_static(void *p_memory,size_t p_bytes); static void free_static(void *p_ptr); static size_t get_static_mem_available(); - static size_t get_static_mem_usage(); + static size_t get_static_mem_usage(); static size_t get_static_mem_max_usage(); static void dump_static_mem_to_file(const char* p_file); static MID alloc_dynamic(size_t p_bytes, const char *p_descr=""); static Error realloc_dynamic(MID p_mid,size_t p_bytes); - + static size_t get_dynamic_mem_available(); static size_t get_dynamic_mem_usage(); - + }; template<class T> @@ -241,7 +241,7 @@ _ALWAYS_INLINE_ void postinitialize_handler(void *) {} template<class T> _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) { - + postinitialize_handler(p_obj); return p_obj; } @@ -272,7 +272,7 @@ _ALWAYS_INLINE_ bool predelete_handler(void *) { return true; } template<class T> void memdelete(T *p_class) { - + if (!predelete_handler(p_class)) return; // doesn't want to be deleted p_class->~T(); diff --git a/core/os/memory_pool_dynamic.h b/core/os/memory_pool_dynamic.h index 82149bcf5d..70752fb10d 100644 --- a/core/os/memory_pool_dynamic.h +++ b/core/os/memory_pool_dynamic.h @@ -40,10 +40,10 @@ friend class Memory; friend class MID; enum { - + INVALID_ID=0xFFFFFFFF }; - + static MemoryPoolDynamic* get_singleton(); typedef uint64_t ID; @@ -55,12 +55,12 @@ friend class MID; virtual bool is_valid(ID p_id)=0; virtual size_t get_size(ID p_id) const=0; virtual const char* get_description(ID p_id) const=0; - + virtual Error lock(ID p_id)=0; virtual void * get(ID p_ID)=0; virtual Error unlock(ID p_id)=0; virtual bool is_locked(ID p_id) const=0; - + virtual size_t get_available_mem() const=0; virtual size_t get_total_usage() const=0; diff --git a/core/os/memory_pool_dynamic_static.cpp b/core/os/memory_pool_dynamic_static.cpp index 894066708e..c047c931ec 100644 --- a/core/os/memory_pool_dynamic_static.cpp +++ b/core/os/memory_pool_dynamic_static.cpp @@ -37,10 +37,10 @@ MemoryPoolDynamicStatic::Chunk *MemoryPoolDynamicStatic::get_chunk(ID p_id) { uint64_t check = p_id/MAX_CHUNKS; uint64_t idx = p_id%MAX_CHUNKS; - + if (!chunk[idx].mem || chunk[idx].check!=check) return NULL; - + return &chunk[idx]; } @@ -49,32 +49,32 @@ const MemoryPoolDynamicStatic::Chunk *MemoryPoolDynamicStatic::get_chunk(ID p_id uint64_t check = p_id/MAX_CHUNKS; uint64_t idx = p_id%MAX_CHUNKS; - + if (!chunk[idx].mem || chunk[idx].check!=check) return NULL; - + return &chunk[idx]; } MemoryPoolDynamic::ID MemoryPoolDynamicStatic::alloc(size_t p_amount,const char* p_description) { _THREAD_SAFE_METHOD_ - + int idx=-1; - + for (int i=0;i<MAX_CHUNKS;i++) { - + last_alloc++; if (last_alloc>=MAX_CHUNKS) last_alloc=0; - + if ( !chunk[last_alloc].mem ) { - + idx=last_alloc; break; } } - + if (idx==-1) { ERR_EXPLAIN("Out of dynamic Memory IDs"); @@ -86,36 +86,36 @@ MemoryPoolDynamic::ID MemoryPoolDynamicStatic::alloc(size_t p_amount,const char* chunk[idx].mem = memalloc(p_amount); if (!chunk[idx].mem) return INVALID_ID; - + chunk[idx].size=p_amount; chunk[idx].check=++last_check; chunk[idx].descr=p_description; chunk[idx].lock=0; - + total_usage+=p_amount; if (total_usage>max_usage) max_usage=total_usage; - + ID id = chunk[idx].check*MAX_CHUNKS + (uint64_t)idx; - + return id; - + } void MemoryPoolDynamicStatic::free(ID p_id) { _THREAD_SAFE_METHOD_ - + Chunk *c = get_chunk(p_id); ERR_FAIL_COND(!c); - - + + total_usage-=c->size; memfree(c->mem); c->mem=0; - + if (c->lock>0) { - + ERR_PRINT("Freed ID Still locked"); } } @@ -123,14 +123,14 @@ void MemoryPoolDynamicStatic::free(ID p_id) { Error MemoryPoolDynamicStatic::realloc(ID p_id, size_t p_amount) { _THREAD_SAFE_METHOD_ - + Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(c->lock > 0 , ERR_LOCKED ); - - + + void * new_mem = memrealloc(c->mem,p_amount); - + ERR_FAIL_COND_V(!new_mem,ERR_OUT_OF_MEMORY); total_usage-=c->size; c->mem=new_mem; @@ -138,37 +138,37 @@ Error MemoryPoolDynamicStatic::realloc(ID p_id, size_t p_amount) { total_usage+=c->size; if (total_usage>max_usage) max_usage=total_usage; - + return OK; } bool MemoryPoolDynamicStatic::is_valid(ID p_id) { _THREAD_SAFE_METHOD_ - + Chunk *c = get_chunk(p_id); - + return c!=NULL; } size_t MemoryPoolDynamicStatic::get_size(ID p_id) const { _THREAD_SAFE_METHOD_ - + const Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,0); - + return c->size; - + } const char* MemoryPoolDynamicStatic::get_description(ID p_id) const { _THREAD_SAFE_METHOD_ - + const Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,""); - + return c->descr; } @@ -177,10 +177,10 @@ const char* MemoryPoolDynamicStatic::get_description(ID p_id) const { bool MemoryPoolDynamicStatic::is_locked(ID p_id) const { _THREAD_SAFE_METHOD_ - + const Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,false); - + return c->lock>0; } @@ -188,10 +188,10 @@ bool MemoryPoolDynamicStatic::is_locked(ID p_id) const { Error MemoryPoolDynamicStatic::lock(ID p_id) { _THREAD_SAFE_METHOD_ - + Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,ERR_INVALID_PARAMETER); - + c->lock++; return OK; @@ -199,23 +199,23 @@ Error MemoryPoolDynamicStatic::lock(ID p_id) { void * MemoryPoolDynamicStatic::get(ID p_id) { _THREAD_SAFE_METHOD_ - + const Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,NULL); ERR_FAIL_COND_V( c->lock==0, NULL ); - + return c->mem; } Error MemoryPoolDynamicStatic::unlock(ID p_id) { _THREAD_SAFE_METHOD_ - + Chunk *c = get_chunk(p_id); ERR_FAIL_COND_V(!c,ERR_INVALID_PARAMETER); - + ERR_FAIL_COND_V( c->lock<=0, ERR_INVALID_PARAMETER ); c->lock--; - + return OK; } @@ -226,7 +226,7 @@ size_t MemoryPoolDynamicStatic::get_available_mem() const { size_t MemoryPoolDynamicStatic::get_total_usage() const { _THREAD_SAFE_METHOD_ - + return total_usage; } diff --git a/core/os/memory_pool_dynamic_static.h b/core/os/memory_pool_dynamic_static.h index 6177c78de7..a72d39355c 100644 --- a/core/os/memory_pool_dynamic_static.h +++ b/core/os/memory_pool_dynamic_static.h @@ -40,19 +40,19 @@ class MemoryPoolDynamicStatic : public MemoryPoolDynamic { enum { MAX_CHUNKS=65536 }; - - + + struct Chunk { - + uint64_t lock; uint64_t check; void *mem; size_t size; - const char *descr; - + const char *descr; + Chunk() { mem=NULL; lock=0; check=0; } }; - + Chunk chunk[MAX_CHUNKS]; uint64_t last_check; int last_alloc; @@ -62,14 +62,14 @@ class MemoryPoolDynamicStatic : public MemoryPoolDynamic { Chunk *get_chunk(ID p_id); const Chunk *get_chunk(ID p_id) const; public: - + virtual ID alloc(size_t p_amount,const char* p_description); virtual void free(ID p_id); virtual Error realloc(ID p_id, size_t p_amount); virtual bool is_valid(ID p_id); virtual size_t get_size(ID p_id) const; virtual const char* get_description(ID p_id) const; - + virtual bool is_locked(ID p_id) const; virtual Error lock(ID p_id); virtual void * get(ID p_ID); diff --git a/core/os/memory_pool_static.cpp b/core/os/memory_pool_static.cpp index 321f4d989e..88c2ba3b3e 100644 --- a/core/os/memory_pool_static.cpp +++ b/core/os/memory_pool_static.cpp @@ -31,13 +31,13 @@ MemoryPoolStatic *MemoryPoolStatic::singleton=0; MemoryPoolStatic *MemoryPoolStatic::get_singleton() { - + return singleton; } MemoryPoolStatic::MemoryPoolStatic() { - + singleton=this; } diff --git a/core/os/memory_pool_static.h b/core/os/memory_pool_static.h index 2e11b7ded4..f7f60b8df8 100644 --- a/core/os/memory_pool_static.h +++ b/core/os/memory_pool_static.h @@ -38,17 +38,17 @@ */ class MemoryPoolStatic { private: - + static MemoryPoolStatic *singleton; public: - + static MemoryPoolStatic *get_singleton(); - + virtual void* alloc(size_t p_bytes,const char *p_description)=0; ///< Pointer in p_description shold be to a const char const like "hello" virtual void* realloc(void * p_memory,size_t p_bytes)=0; ///< Pointer in p_description shold be to a const char const like "hello" virtual void free(void *p_ptr)=0; ///< Pointer in p_description shold be to a const char const - + virtual size_t get_available_mem() const=0; virtual size_t get_total_usage()=0; virtual size_t get_max_usage()=0; diff --git a/core/os/mutex.cpp b/core/os/mutex.cpp index 9b379009b9..21400d2ccf 100644 --- a/core/os/mutex.cpp +++ b/core/os/mutex.cpp @@ -50,13 +50,13 @@ Mutex::~Mutex() { Mutex *_global_mutex=NULL;; void _global_lock() { - + if (_global_mutex) _global_mutex->lock(); } void _global_unlock() { - + if (_global_mutex) - _global_mutex->unlock(); + _global_mutex->unlock(); } diff --git a/core/os/mutex.h b/core/os/mutex.h index f16375aa26..5870171dc7 100644 --- a/core/os/mutex.h +++ b/core/os/mutex.h @@ -33,7 +33,7 @@ /** - * @class Mutex + * @class Mutex * @author Juan Linietsky * Portable Mutex (thread-safe locking) implementation. * Mutexes are always recursive ( they don't self-lock in a single thread ). @@ -43,9 +43,9 @@ class Mutex { -protected: +protected: static Mutex* (*create_func)(bool); - + public: virtual void lock()=0; ///< Lock the mutex, block if locked by someone else @@ -53,7 +53,7 @@ public: virtual Error try_lock()=0; ///< Attempt to lock the mutex, OK on success, ERROR means it can't lock. static Mutex * create(bool p_recursive=true); ///< Create a mutex - + virtual ~Mutex(); }; diff --git a/core/os/os.h b/core/os/os.h index a80b81bfa2..65ce44465b 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -71,7 +71,7 @@ public: RENDER_SEPARATE_THREAD }; struct VideoMode { - + int width,height; bool fullscreen; bool resizable; @@ -80,33 +80,33 @@ public: }; protected: friend class Main; - + RenderThreadMode _render_thread_mode; // functions used by main to initialize/deintialize the OS virtual int get_video_driver_count() const=0; virtual const char * get_video_driver_name(int p_driver) const=0; - + virtual VideoMode get_default_video_mode() const=0; - + virtual int get_audio_driver_count() const=0; virtual const char * get_audio_driver_name(int p_driver) const=0; - + virtual void initialize_core()=0; virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver)=0; - - virtual void set_main_loop( MainLoop * p_main_loop )=0; + + virtual void set_main_loop( MainLoop * p_main_loop )=0; virtual void delete_main_loop()=0; - + virtual void finalize()=0; virtual void finalize_core()=0; virtual void set_cmdline(const char* p_execpath, const List<String>& p_args); void _ensure_data_dir(); - + public: - + typedef int64_t ProcessID; static OS* get_singleton(); @@ -148,7 +148,7 @@ public: virtual void set_clipboard(const String& p_text); virtual String get_clipboard() const; - + virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0)=0; virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const=0; @@ -219,7 +219,7 @@ public: DAY_FRIDAY, DAY_SATURDAY }; - + enum Month { MONTH_JANUARY, MONTH_FEBRUARY, @@ -236,7 +236,7 @@ public: }; struct Date { - + int year; Month month; int day; @@ -245,7 +245,7 @@ public: }; struct Time { - + int hour; int min; int sec; @@ -262,7 +262,7 @@ public: virtual uint64_t get_unix_time() const; virtual uint64_t get_system_time_secs() const; - virtual void delay_usec(uint32_t p_usec) const=0; + virtual void delay_usec(uint32_t p_usec) const=0; virtual uint64_t get_ticks_usec() const=0; uint32_t get_ticks_msec() const; uint64_t get_splash_tick_msec() const; @@ -412,7 +412,7 @@ public: virtual void set_context(int p_context); - OS(); + OS(); virtual ~OS(); }; diff --git a/core/os/semaphore.h b/core/os/semaphore.h index b65542ce35..8469408e65 100644 --- a/core/os/semaphore.h +++ b/core/os/semaphore.h @@ -35,17 +35,17 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Semaphore { -protected: +protected: static Semaphore* (*create_func)(); - + public: virtual Error wait()=0; ///< wait until semaphore has positive value, then decrement and pass virtual Error post()=0; ///< unlock the semaphore, incrementing the value virtual int get() const=0; ///< get semaphore value - + static Semaphore * create(); ///< Create a mutex - + virtual ~Semaphore(); }; diff --git a/core/os/shell.h b/core/os/shell.h index 805dd70301..8b0c286d73 100644 --- a/core/os/shell.h +++ b/core/os/shell.h @@ -42,7 +42,7 @@ public: static Shell * get_singleton(); virtual void execute(String p_path)=0; - + Shell(); virtual ~Shell(); }; diff --git a/core/os/thread.cpp b/core/os/thread.cpp index f5d984876d..c1ae53074b 100644 --- a/core/os/thread.cpp +++ b/core/os/thread.cpp @@ -37,26 +37,26 @@ Error (*Thread::set_name_func)(const String&)=NULL; Thread::ID Thread::_main_thread_id=0; Thread::ID Thread::get_caller_ID() { - + if (get_thread_ID_func) return get_thread_ID_func(); return 0; } Thread* Thread::create(ThreadCreateCallback p_callback,void * p_user,const Settings& p_settings) { - + if (create_func) { - + return create_func(p_callback,p_user,p_settings); } return NULL; } void Thread::wait_to_finish(Thread *p_thread) { - + if (wait_to_finish_func) wait_to_finish_func(p_thread); - + } Error Thread::set_name(const String &p_name) { diff --git a/core/os/thread.h b/core/os/thread.h index 4fead72b94..7349b83dbc 100644 --- a/core/os/thread.h +++ b/core/os/thread.h @@ -41,25 +41,25 @@ typedef void (*ThreadCreateCallback)(void *p_userdata); class Thread { public: - + enum Priority { - + PRIORITY_LOW, PRIORITY_NORMAL, PRIORITY_HIGH }; - + struct Settings { - + Priority priority; Settings() { priority=PRIORITY_NORMAL; } }; - + typedef uint64_t ID; -protected: +protected: static Thread* (*create_func)(ThreadCreateCallback p_callback,void *,const Settings&); static ID (*get_thread_ID_func)(); static void (*wait_to_finish_func)(Thread*); @@ -72,7 +72,7 @@ protected: Thread(); public: - + virtual ID get_ID() const=0; @@ -81,8 +81,8 @@ public: static ID get_caller_ID(); ///< get the ID of the caller function ID static void wait_to_finish(Thread *p_thread); ///< waits until thread is finished, and deallocates it. static Thread * create(ThreadCreateCallback p_callback,void * p_user,const Settings& p_settings=Settings()); ///< Static function to create a thread, will call p_callback - - + + virtual ~Thread(); }; diff --git a/core/os/thread_safe.cpp b/core/os/thread_safe.cpp index f252190504..a742b1144e 100644 --- a/core/os/thread_safe.cpp +++ b/core/os/thread_safe.cpp @@ -30,17 +30,17 @@ #include "error_macros.h" #include "os/memory.h" -ThreadSafe::ThreadSafe() { +ThreadSafe::ThreadSafe() { - mutex = Mutex::create(); + mutex = Mutex::create(); if (!mutex) { - + WARN_PRINT("THREAD_SAFE defined, but no default mutex type"); } } -ThreadSafe::~ThreadSafe() { - - if (mutex) - memdelete( mutex ); +ThreadSafe::~ThreadSafe() { + + if (mutex) + memdelete( mutex ); } diff --git a/core/os/thread_safe.h b/core/os/thread_safe.h index 793dd88543..1c82cbe704 100644 --- a/core/os/thread_safe.h +++ b/core/os/thread_safe.h @@ -42,7 +42,7 @@ public: ThreadSafe(); ~ThreadSafe(); - + }; @@ -51,11 +51,11 @@ class ThreadSafeMethod { const ThreadSafe *_ts; public: ThreadSafeMethod(const ThreadSafe *p_ts) { - + _ts=p_ts; _ts->lock(); } - + ~ThreadSafeMethod() { _ts->unlock(); } }; diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp index dd736502a3..91f886ff4b 100644 --- a/core/packed_data_container.cpp +++ b/core/packed_data_container.cpp @@ -182,12 +182,12 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs,const Variant& p_key,boo err=true; return Variant(); } - + } else if (type==TYPE_DICT) { uint32_t hash=p_key.hash(); uint32_t len = decode_uint32(r+4); - + bool found=false; for(int i=0;i<len;i++) { uint32_t khash=decode_uint32(r+8+i*12+0); @@ -214,7 +214,7 @@ Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs,const Variant& p_key,boo err=true; return Variant(); } - + } diff --git a/core/path_db.cpp b/core/path_db.cpp index d3521fcb23..7545088978 100644 --- a/core/path_db.cpp +++ b/core/path_db.cpp @@ -58,17 +58,17 @@ bool NodePath::is_absolute() const { if (!data) return false; - + return data->absolute; - + } int NodePath::get_name_count() const { if (!data) return 0; - + return data->path.size(); - + } StringName NodePath::get_name(int p_idx) const { @@ -103,24 +103,24 @@ StringName NodePath::get_subname(int p_idx) const { void NodePath::unref() { if (data && data->refcount.unref()) { - + memdelete(data); } data=NULL; - + } - + bool NodePath::operator==(const NodePath& p_path) const { if (data==p_path.data) return true; - + if (!data || !p_path.data) return false; - + if (data->absolute != p_path.data->absolute) return false; - + if (data->path.size() != p_path.data->path.size()) return false; @@ -131,7 +131,7 @@ bool NodePath::operator==(const NodePath& p_path) const { return false; for (int i=0;i<data->path.size();i++) { - + if (data->path[i]!=p_path.data->path[i]) return false; } @@ -148,17 +148,17 @@ bool NodePath::operator!=(const NodePath& p_path) const { return (!(*this == p_path)); } - - + + void NodePath::operator=(const NodePath& p_path) { if (this==&p_path) return; unref(); - + if (p_path.data && p_path.data->refcount.ref()) { - + data=p_path.data; } } @@ -167,13 +167,13 @@ NodePath::operator String() const { if (!data) return String(); - + String ret; if (data->absolute) ret="/"; - + for (int i=0;i<data->path.size();i++) { - + if (i>0) ret+="/"; ret+=data->path[i].operator String(); @@ -184,7 +184,7 @@ NodePath::operator String() const { ret+=":"+data->subpath[i].operator String(); } - if (data->property.operator String()!="") + if (data->property.operator String()!="") ret+=":"+String(data->property); return ret; } @@ -195,7 +195,7 @@ NodePath::NodePath(const NodePath& p_path) { data=NULL; if (p_path.data && p_path.data->refcount.ref()) { - + data=p_path.data; } } @@ -258,17 +258,17 @@ NodePath NodePath::rel_path_to(const NodePath& p_np) const { NodePath::NodePath(const Vector<StringName>& p_path,bool p_absolute,const String& p_property) { - + data=NULL; - + if (p_path.size()==0) return; - + data = memnew( Data ); data->refcount.init(); data->absolute=p_absolute; data->path=p_path; - data->property=p_property; + data->property=p_property; } NodePath::NodePath(const Vector<StringName>& p_path,const Vector<StringName>& p_subpath,bool p_absolute,const String& p_property) { @@ -327,17 +327,17 @@ NodePath::NodePath(const String& p_path) { String path=p_path; StringName property; Vector<StringName> subpath; - - int absolute=(path[0]=='/')?1:0;; + + int absolute=(path[0]=='/')?1:0;; bool valid=false; bool last_is_slash=true; int slices=0; int subpath_pos=path.find(":"); - + if (subpath_pos!=-1) { - + int from=subpath_pos+1; for (int i=from;i<=path.length();i++) { @@ -362,44 +362,44 @@ NodePath::NodePath(const String& p_path) { path=path.substr(0,subpath_pos); } - + for (int i=absolute;i<path.length();i++) { - + if (path[i]=='/') { - + last_is_slash=true; } else { - + if (last_is_slash) slices++; - + valid=true; last_is_slash=false; } } - + if (slices==0 && !absolute && !property) return; - + data = memnew( Data ); data->refcount.init(); data->absolute=absolute?true:false; data->property=property; data->subpath=subpath; - + if (slices==0) return; - data->path.resize(slices); + data->path.resize(slices); last_is_slash=true; int from=absolute; int slice=0; - + for (int i=absolute;i<path.length()+1;i++) { - + if (path[i]=='/' || path[i]==0) { - + if (!last_is_slash) { - + String name=path.substr(from,i-from); ERR_FAIL_INDEX( slice,data->path.size() ); data->path[slice++]=name; @@ -410,8 +410,8 @@ NodePath::NodePath(const String& p_path) { last_is_slash=false; } } - - + + } bool NodePath::is_empty() const { diff --git a/core/path_db.h b/core/path_db.h index 9c9be65d28..63adb42955 100644 --- a/core/path_db.h +++ b/core/path_db.h @@ -41,14 +41,14 @@ class NodePath { struct Data { - + SafeRefCount refcount; StringName property; - Vector<StringName> path; + Vector<StringName> path; Vector<StringName> subpath; bool absolute; }; - + Data *data; void unref(); public: @@ -77,7 +77,7 @@ public: NodePath get_parent() const; uint32_t hash() const; - + operator String() const; bool is_empty() const; @@ -88,7 +88,7 @@ public: void simplify(); NodePath simplified() const; - NodePath(const Vector<StringName>& p_path,bool p_absolute,const String& p_property=""); + NodePath(const Vector<StringName>& p_path,bool p_absolute,const String& p_property=""); NodePath(const Vector<StringName>& p_path,const Vector<StringName>& p_subpath,bool p_absolute,const String& p_property=""); NodePath(const NodePath& p_path); NodePath(const String& p_path); diff --git a/core/pool_allocator.cpp b/core/pool_allocator.cpp index 23be650fda..849fd75f50 100644 --- a/core/pool_allocator.cpp +++ b/core/pool_allocator.cpp @@ -42,11 +42,11 @@ do { \ } while (0); void PoolAllocator::mt_lock() const { - + } void PoolAllocator::mt_unlock() const { - + } @@ -61,7 +61,7 @@ bool PoolAllocator::get_free_entry(EntryArrayPos* p_pos) { *p_pos=i; return true; } - + } ERR_PRINT("Out of memory Chunks!"); @@ -78,7 +78,7 @@ bool PoolAllocator::get_free_entry(EntryArrayPos* p_pos) { bool PoolAllocator::find_hole(EntryArrayPos *p_pos, int p_for_size) { /* position where previous entry ends. Defaults to zero (begin of pool) */ - + int prev_entry_end_pos=0; for (int i=0;i<entry_count;i++) { @@ -106,16 +106,16 @@ bool PoolAllocator::find_hole(EntryArrayPos *p_pos, int p_for_size) { *p_pos=entry_count; return true; } - + return false; - + } void PoolAllocator::compact(int p_up_to) { - + uint32_t prev_entry_end_pos=0; - + if (p_up_to<0) p_up_to=entry_count; for (int i=0;i<p_up_to;i++) { @@ -129,16 +129,16 @@ void PoolAllocator::compact(int p_up_to) { /* if we can compact, do it */ if (hole_size>0 && !entry.lock) { - + COMPACT_CHUNK(entry,prev_entry_end_pos); - + } - + /* prepare for next one */ prev_entry_end_pos=entry_end(entry); } - - + + } void PoolAllocator::compact_up(int p_from) { @@ -169,81 +169,81 @@ void PoolAllocator::compact_up(int p_from) { bool PoolAllocator::find_entry_index(EntryIndicesPos *p_map_pos,Entry *p_entry) { - + EntryArrayPos entry_pos=entry_max; - + for (int i=0;i<entry_count;i++) { - + if (&entry_array[ entry_indices[ i ] ]==p_entry) { - + entry_pos=i; break; } } - + if (entry_pos==entry_max) return false; - + *p_map_pos=entry_pos; return true; - + } PoolAllocator::ID PoolAllocator::alloc(int p_size) { - + ERR_FAIL_COND_V(p_size<1,POOL_ALLOCATOR_INVALID_ID); #ifdef DEBUG_ENABLED if (p_size > free_mem) OS::get_singleton()->debug_break(); #endif ERR_FAIL_COND_V(p_size>free_mem,POOL_ALLOCATOR_INVALID_ID); - + mt_lock(); - + if (entry_count==entry_max) { mt_unlock(); ERR_PRINT("entry_count==entry_max"); return POOL_ALLOCATOR_INVALID_ID; } - - + + int size_to_alloc=aligned(p_size); - + EntryIndicesPos new_entry_indices_pos; - + if (!find_hole(&new_entry_indices_pos, size_to_alloc)) { /* No hole could be found, try compacting mem */ compact(); /* Then search again */ - + if (!find_hole(&new_entry_indices_pos, size_to_alloc)) { - + mt_unlock(); ERR_PRINT("memory can't be compacted further"); - return POOL_ALLOCATOR_INVALID_ID; + return POOL_ALLOCATOR_INVALID_ID; } } - + EntryArrayPos new_entry_array_pos; - + bool found_free_entry=get_free_entry(&new_entry_array_pos); - + if (!found_free_entry) { mt_unlock(); ERR_FAIL_COND_V( !found_free_entry , POOL_ALLOCATOR_INVALID_ID ); } - + /* move all entry indices up, make room for this one */ for (int i=entry_count;i>new_entry_indices_pos;i-- ) { - + entry_indices[i]=entry_indices[i-1]; } - + entry_indices[new_entry_indices_pos]=new_entry_array_pos; - + entry_count++; - + Entry &entry=entry_array[ entry_indices[ new_entry_indices_pos ] ]; - + entry.len=p_size; entry.pos=(new_entry_indices_pos==0)?0:entry_end(entry_array[ entry_indices[ new_entry_indices_pos-1 ] ]); //alloc either at begining or end of previous entry.lock=0; @@ -251,40 +251,40 @@ PoolAllocator::ID PoolAllocator::alloc(int p_size) { free_mem-=size_to_alloc; if (free_mem<free_mem_peak) free_mem_peak=free_mem; - + ID retval = (entry_indices[ new_entry_indices_pos ]<<CHECK_BITS)|entry.check; mt_unlock(); //ERR_FAIL_COND_V( (uintptr_t)get(retval)%align != 0, retval ); return retval; - + } PoolAllocator::Entry * PoolAllocator::get_entry(ID p_mem) { - + unsigned int check=p_mem&CHECK_MASK; int entry=p_mem>>CHECK_BITS; ERR_FAIL_INDEX_V(entry,entry_max,NULL); ERR_FAIL_COND_V(entry_array[entry].check!=check,NULL); ERR_FAIL_COND_V(entry_array[entry].len==0,NULL); - + return &entry_array[entry]; } const PoolAllocator::Entry * PoolAllocator::get_entry(ID p_mem) const { - + unsigned int check=p_mem&CHECK_MASK; int entry=p_mem>>CHECK_BITS; ERR_FAIL_INDEX_V(entry,entry_max,NULL); ERR_FAIL_COND_V(entry_array[entry].check!=check,NULL); ERR_FAIL_COND_V(entry_array[entry].len==0,NULL); - + return &entry_array[entry]; } void PoolAllocator::free(ID p_mem) { - + mt_lock(); Entry *e=get_entry(p_mem); if (!e) { @@ -297,23 +297,23 @@ void PoolAllocator::free(ID p_mem) { ERR_PRINT("e->lock"); return; } - + EntryIndicesPos entry_indices_pos; - + bool index_found = find_entry_index(&entry_indices_pos,e); if (!index_found) { - + mt_unlock(); ERR_FAIL_COND(!index_found); } - - + + for (int i=entry_indices_pos;i<(entry_count-1);i++) { - + entry_indices[ i ] = entry_indices[ i+1 ]; } - + entry_count--; free_mem+=aligned(e->len); e->clear(); @@ -327,21 +327,21 @@ int PoolAllocator::get_size(ID p_mem) const { const Entry *e=get_entry(p_mem); if (!e) { - + mt_unlock(); ERR_PRINT("!e"); return 0; } - + size=e->len; - + mt_unlock(); - + return size; -} +} Error PoolAllocator::resize(ID p_mem,int p_new_size) { - + mt_lock(); Entry *e=get_entry(p_mem); @@ -443,18 +443,18 @@ Error PoolAllocator::resize(ID p_mem,int p_new_size) { Error PoolAllocator::lock(ID p_mem) { - + if (!needs_locking) return OK; mt_lock(); Entry *e=get_entry(p_mem); if (!e) { - + mt_unlock(); ERR_PRINT("!e"); return ERR_INVALID_PARAMETER; } - e->lock++; + e->lock++; mt_unlock(); return OK; } @@ -480,85 +480,85 @@ bool PoolAllocator::is_locked(ID p_mem) const { const void *PoolAllocator::get(ID p_mem) const { if (!needs_locking) { - + const Entry *e=get_entry(p_mem); ERR_FAIL_COND_V(!e,NULL); return &pool[e->pos]; - + } - + mt_lock(); const Entry *e=get_entry(p_mem); - + if (!e) { - + mt_unlock(); ERR_FAIL_COND_V(!e,NULL); } if (e->lock==0) { - + mt_unlock(); ERR_PRINT( "e->lock == 0" ); return NULL; } - + if (e->pos<0 || (int)e->pos>=pool_size) { - + mt_unlock(); ERR_PRINT("e->pos<0 || e->pos>=pool_size"); return NULL; } const void *ptr=&pool[e->pos]; - + mt_unlock(); - + return ptr; } void *PoolAllocator::get(ID p_mem) { - + if (!needs_locking) { - + Entry *e=get_entry(p_mem); if (!e) { ERR_FAIL_COND_V(!e,NULL); }; return &pool[e->pos]; - + } - + mt_lock(); Entry *e=get_entry(p_mem); - + if (!e) { - + mt_unlock(); ERR_FAIL_COND_V(!e,NULL); } if (e->lock==0) { - + //assert(0); mt_unlock(); ERR_PRINT( "e->lock == 0" ); return NULL; } - + if (e->pos<0 || (int)e->pos>=pool_size) { - + mt_unlock(); ERR_PRINT("e->pos<0 || e->pos>=pool_size"); return NULL; } void *ptr=&pool[e->pos]; - + mt_unlock(); - + return ptr; - + } void PoolAllocator::unlock(ID p_mem) { - + if (!needs_locking) return; mt_lock(); @@ -568,7 +568,7 @@ void PoolAllocator::unlock(ID p_mem) { ERR_PRINT( "e->lock == 0" ); return; } - e->lock--; + e->lock--; mt_unlock(); } @@ -583,34 +583,34 @@ int PoolAllocator::get_free_peak() { } int PoolAllocator::get_free_mem() { - + return free_mem; } void PoolAllocator::create_pool(void * p_mem,int p_size,int p_max_entries) { - + pool=(uint8_t*)p_mem; pool_size=p_size; - + entry_array = memnew_arr( Entry, p_max_entries ); entry_indices = memnew_arr( int, p_max_entries ); entry_max = p_max_entries; entry_count=0; - + free_mem=p_size; free_mem_peak=p_size; - - check_count=0; + + check_count=0; } PoolAllocator::PoolAllocator(int p_size,bool p_needs_locking,int p_max_entries) { - + mem_ptr=Memory::alloc_static( p_size,"PoolAllocator()"); ERR_FAIL_COND(!mem_ptr); align=1; create_pool(mem_ptr,p_size,p_max_entries); needs_locking=p_needs_locking; - + } PoolAllocator::PoolAllocator(void * p_mem,int p_size, int p_align ,bool p_needs_locking,int p_max_entries) { @@ -626,16 +626,16 @@ PoolAllocator::PoolAllocator(void * p_mem,int p_size, int p_align ,bool p_needs_ p_mem = (void*)mem8; }; }; - + create_pool( p_mem,p_size,p_max_entries); needs_locking=p_needs_locking; align=p_align; - mem_ptr=NULL; + mem_ptr=NULL; } PoolAllocator::PoolAllocator(int p_align,int p_size,bool p_needs_locking,int p_max_entries) { - - ERR_FAIL_COND(p_align<1); + + ERR_FAIL_COND(p_align<1); mem_ptr=Memory::alloc_static( p_size+p_align,"PoolAllocator()"); uint8_t *mem8=(uint8_t*)mem_ptr; uint64_t ofs = (uint64_t)mem8; @@ -647,12 +647,12 @@ PoolAllocator::PoolAllocator(int p_align,int p_size,bool p_needs_locking,int p_m } PoolAllocator::~PoolAllocator() { - + if (mem_ptr) Memory::free_static( mem_ptr ); - + memdelete_arr( entry_array ); memdelete_arr( entry_indices ); - + } diff --git a/core/pool_allocator.h b/core/pool_allocator.h index 2c5920149b..438548bfe4 100644 --- a/core/pool_allocator.h +++ b/core/pool_allocator.h @@ -41,66 +41,66 @@ */ enum { - + POOL_ALLOCATOR_INVALID_ID=-1 ///< default invalid value. use INVALID_ID( id ) to test }; class PoolAllocator { -public: +public: typedef int ID; -private: +private: enum { CHECK_BITS=8, CHECK_LEN=(1<<CHECK_BITS), CHECK_MASK=CHECK_LEN-1 - + }; - - + + struct Entry { - + unsigned int pos; unsigned int len; unsigned int lock; - unsigned int check; - + unsigned int check; + inline void clear() { pos=0; len=0; lock=0; check=0; } Entry() { clear(); } }; - - + + typedef int EntryArrayPos; typedef int EntryIndicesPos; - + Entry *entry_array; int *entry_indices; int entry_max; int entry_count; - + uint8_t *pool; void *mem_ptr; int pool_size; - + int free_mem; int free_mem_peak; unsigned int check_count; int align; - + bool needs_locking; - - inline int entry_end(const Entry& p_entry) const { - return p_entry.pos+aligned(p_entry.len); + + inline int entry_end(const Entry& p_entry) const { + return p_entry.pos+aligned(p_entry.len); } inline int aligned(int p_size) const { - + int rem=p_size%align; if (rem) p_size+=align-rem; - + return p_size; } - + void compact(int p_up_to=-1); void compact_up(int p_from=0); bool get_free_entry(EntryArrayPos* p_pos); @@ -108,14 +108,14 @@ private: bool find_entry_index(EntryIndicesPos *p_map_pos,Entry *p_entry); Entry* get_entry(ID p_mem); const Entry* get_entry(ID p_mem) const; - + void create_pool(void * p_mem,int p_size,int p_max_entries); -protected: +protected: virtual void mt_lock() const; ///< Reimplement for custom mt locking virtual void mt_unlock() const; ///< Reimplement for custom mt locking - + public: - + enum { DEFAULT_MAX_ALLOCS=4096, }; @@ -124,7 +124,7 @@ public: void free(ID p_mem); ///< Free allocated memory Error resize(ID p_mem,int p_new_size); ///< resize a memory chunk int get_size(ID p_mem) const; - + int get_free_mem(); ///< get free memory int get_used_mem() const; int get_free_peak(); ///< get free memory @@ -134,13 +134,13 @@ public: const void *get(ID p_mem) const; void unlock(ID p_mem); bool is_locked(ID p_mem) const; - + PoolAllocator(int p_size,bool p_needs_locking=false,int p_max_entries=DEFAULT_MAX_ALLOCS); PoolAllocator(void * p_mem,int p_size, int p_align = 1, bool p_needs_locking=false,int p_max_entries=DEFAULT_MAX_ALLOCS); PoolAllocator(int p_align,int p_size,bool p_needs_locking=false,int p_max_entries=DEFAULT_MAX_ALLOCS); - + virtual ~PoolAllocator(); - + }; #endif diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 54431cf381..97bd5f2a32 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -81,7 +81,7 @@ extern void unregister_variant_methods(); void register_core_types() { - + _global_mutex=Mutex::create(); @@ -92,7 +92,7 @@ void register_core_types() { CoreStringNames::create(); - + resource_format_po = memnew( TranslationLoaderPO ); ResourceLoader::add_resource_format_loader( resource_format_po ); diff --git a/core/res_ptr.cpp b/core/res_ptr.cpp index 11312b8021..2fada627e7 100644 --- a/core/res_ptr.cpp +++ b/core/res_ptr.cpp @@ -53,7 +53,7 @@ RefPtr::RefPtr(const RefPtr& p_other) { Ref<Resource> *ref = reinterpret_cast<Ref<Resource>*>( &data[0] ); Ref<Resource> *ref_other = reinterpret_cast<Ref<Resource>*>( const_cast<char*>(&p_other.data[0]) ); - + *ref = *ref_other; } diff --git a/core/res_ptr.h b/core/res_ptr.h index e1dc66b290..54b74bb113 100644 --- a/core/res_ptr.h +++ b/core/res_ptr.h @@ -41,7 +41,7 @@ class ResBase; class RefPtr { -friend class ResBase; +friend class ResBase; enum { DATASIZE=sizeof(void*)*4 diff --git a/core/resource.cpp b/core/resource.cpp index e0706cf541..672e64b1bb 100644 --- a/core/resource.cpp +++ b/core/resource.cpp @@ -156,14 +156,14 @@ void Resource::_resource_path_changed() { } - + void Resource::set_path(const String& p_path, bool p_take_over) { if (path_cache==p_path) return; - + if (path_cache!="") { - + ResourceCache::resources.erase(path_cache); } @@ -179,19 +179,19 @@ void Resource::set_path(const String& p_path, bool p_take_over) { } path_cache=p_path; - + if (path_cache!="") { - + ResourceCache::resources[path_cache]=this;; } _change_notify("resource/path"); _resource_path_changed(); - + } String Resource::get_path() const { - + return path_cache; } @@ -342,7 +342,7 @@ Resource::Resource() { Resource::~Resource() { - + if (path_cache!="") ResourceCache::resources.erase(path_cache); if (owners.size()) { @@ -350,12 +350,12 @@ Resource::~Resource() { } } -HashMap<String,Resource*> ResourceCache::resources; +HashMap<String,Resource*> ResourceCache::resources; void ResourceCache::clear() { if (resources.size()) ERR_PRINT("Resources Still in use at Exit!"); - + resources.clear(); } @@ -374,18 +374,18 @@ void ResourceCache::reload_externals() { bool ResourceCache::has(const String& p_path) { GLOBAL_LOCK_FUNCTION - + return resources.has(p_path); } Resource *ResourceCache::get(const String& p_path) { - + GLOBAL_LOCK_FUNCTION - + Resource **res = resources.getptr(p_path); if (!res) { return NULL; } - + return *res; } diff --git a/core/resource.h b/core/resource.h index f0c86631cc..8bcdd6b4b7 100644 --- a/core/resource.h +++ b/core/resource.h @@ -87,7 +87,7 @@ public: class Resource : public Reference { - + OBJ_TYPE( Resource, Reference ); OBJ_CATEGORY("Resources"); RES_BASE_EXTENSION("res"); @@ -95,8 +95,8 @@ class Resource : public Reference { Set<ObjectID> owners; friend class ResBase; -friend class ResourceCache; - +friend class ResourceCache; + String name; String path_cache; int subindex; @@ -109,7 +109,7 @@ friend class ResourceCache; #endif protected: - + void emit_changed(); void notify_change_to_owners(); @@ -120,7 +120,7 @@ protected: void _set_path(const String& p_path); void _take_over_path(const String& p_path); public: - + virtual bool can_reload_from_file(); virtual void reload_from_file(); @@ -151,7 +151,7 @@ public: virtual RID get_rid() const; // some resources may offer conversion to RID - Resource(); + Resource(); ~Resource(); }; @@ -160,11 +160,11 @@ public: typedef Ref<Resource> RES; class ResourceCache { -friend class Resource; - static HashMap<String,Resource*> resources; +friend class Resource; + static HashMap<String,Resource*> resources; friend void unregister_core_types(); static void clear(); -public: +public: static void reload_externals(); static bool has(const String& p_path); diff --git a/core/rid.h b/core/rid.h index 85ae1b15d3..2de6956096 100644 --- a/core/rid.h +++ b/core/rid.h @@ -44,19 +44,19 @@ class RID_OwnerBase; typedef uint32_t ID; -class RID { -friend class RID_OwnerBase; +class RID { +friend class RID_OwnerBase; ID _id; RID_OwnerBase *owner; public: _FORCE_INLINE_ ID get_id() const { return _id; } bool operator==(const RID& p_rid) const { - + return _id==p_rid._id; } _FORCE_INLINE_ bool operator<(const RID& p_rid) const { - + return _id < p_rid._id; } _FORCE_INLINE_ bool operator<=(const RID& p_rid) const { @@ -64,11 +64,11 @@ public: return _id <= p_rid._id; } _FORCE_INLINE_ bool operator>(const RID& p_rid) const { - + return _id > p_rid._id; } bool operator!=(const RID& p_rid) const { - + return _id!=p_rid._id; } _FORCE_INLINE_ bool is_valid() const { return _id>0; } @@ -91,7 +91,7 @@ friend class RID; void set_ownage(RID& p_rid) const { p_rid.owner=const_cast<RID_OwnerBase*>(this); } ID new_ID(); public: - + virtual bool owns(const RID& p_rid) const=0; virtual void get_owned_list(List<RID> *p_owned) const=0; @@ -105,67 +105,67 @@ class RID_Owner : public RID_OwnerBase { public: typedef void (*ReleaseNotifyFunc)(void*user,T *p_data); -private: +private: Mutex *mutex; mutable HashMap<ID,T*> id_map; - + public: RID make_rid(T * p_data) { - + if (thread_safe) { mutex->lock(); } - + ID id = new_ID(); id_map[id]=p_data; RID rid; set_id(rid,id); set_ownage(rid); - + if (thread_safe) { mutex->unlock(); } - + return rid; } - + _FORCE_INLINE_ T * get(const RID& p_rid) { - + if (thread_safe) { mutex->lock(); } - + T**elem = id_map.getptr(p_rid.get_id()); - + if (thread_safe) { mutex->unlock(); } ERR_FAIL_COND_V(!elem,NULL); - + return *elem; } - + virtual bool owns(const RID& p_rid) const { - + if (thread_safe) { mutex->lock(); } - + T**elem = id_map.getptr(p_rid.get_id()); - + if (thread_safe) { mutex->lock(); } - + return elem!=NULL; } - - virtual void free(RID p_rid) { - + + virtual void free(RID p_rid) { + if (thread_safe) { mutex->lock(); } @@ -173,40 +173,40 @@ public: id_map.erase(p_rid.get_id()); } virtual void get_owned_list(List<RID> *p_owned) const { - + if (thread_safe) { mutex->lock(); } - + const ID*id=NULL; while((id=id_map.next(id))) { - + RID rid; set_id(rid,*id); set_ownage(rid); p_owned->push_back(rid); - + } - + if (thread_safe) { mutex->lock(); } } RID_Owner() { - + if (thread_safe) { - + mutex = Mutex::create(); } - + } - - + + ~RID_Owner() { - + if (thread_safe) { - + memdelete(mutex); } } diff --git a/core/ring_buffer.h b/core/ring_buffer.h index 4658ec5e51..7d78fac660 100644 --- a/core/ring_buffer.h +++ b/core/ring_buffer.h @@ -38,21 +38,21 @@ class RingBuffer { int read_pos; int write_pos; int size_mask; - + inline int inc(int& p_var, int p_size) { int ret = p_var; p_var += p_size; p_var = p_var&size_mask; return ret; }; - + public: T read() { ERR_FAIL_COND_V(space_left() < 1, T()); return data[inc(read_pos, 1)]; }; - + int read(T* p_buf, int p_size, bool p_advance=true) { int left = data_left(); p_size = MIN(left, p_size); @@ -76,7 +76,7 @@ public: }; int copy(T* p_buf, int p_offset, int p_size) { - + int left = data_left(); if ((p_offset+p_size)>left) { p_size-=left-p_offset; @@ -106,18 +106,18 @@ public: inc(read_pos, p_n); return p_n; }; - + Error write(const T& p_v) { ERR_FAIL_COND_V( space_left() < 1, FAILED); data[inc(write_pos, 1)] = p_v; return OK; }; - + int write(const T* p_buf, int p_size) { - + int left = space_left(); p_size = MIN(left, p_size); - + int pos = write_pos; int to_write = p_size; int src = 0; @@ -126,7 +126,7 @@ public: int end = pos + to_write; end = MIN(end, size()); int total = end - pos; - + for (int i=0; i<total; i++) { data[pos+i] = p_buf[src++]; }; @@ -137,7 +137,7 @@ public: inc(write_pos, p_size); return p_size; }; - + inline int space_left() { int left = read_pos - write_pos; if (left < 0) { @@ -151,7 +151,7 @@ public: inline int data_left() { return size() - space_left() - 1; }; - + inline int size() { return data.size(); }; @@ -161,7 +161,7 @@ public: write_pos = 0; } - + void resize(int p_power) { int old_size = size(); int new_size = 1<<p_power; @@ -176,10 +176,10 @@ public: read_pos = read_pos & mask; write_pos = write_pos & mask; }; - + size_mask = mask; }; - + RingBuffer<T>(int p_power=0) { read_pos = 0; write_pos = 0; diff --git a/core/safe_refcount.cpp b/core/safe_refcount.cpp index 7718e466f2..9736f96f34 100644 --- a/core/safe_refcount.cpp +++ b/core/safe_refcount.cpp @@ -40,9 +40,9 @@ long atomic_conditional_increment( register long * pw ) { while (true) { long tmp = static_cast< long const volatile& >( *pw ); - if( tmp == 0 ) + if( tmp == 0 ) return 0; // if zero, can't add to it anymore - if( InterlockedCompareExchange( pw, tmp + 1, tmp ) == tmp ) + if( InterlockedCompareExchange( pw, tmp + 1, tmp ) == tmp ) return tmp+1; } diff --git a/core/safe_refcount.h b/core/safe_refcount.h index e5dc854c23..d976458c1d 100644 --- a/core/safe_refcount.h +++ b/core/safe_refcount.h @@ -42,15 +42,15 @@ struct SafeRefCount { int count; public: - + // destroy() is called when weak_count_ drops to zero. - + bool ref() { //true on success - + if (count==0) return false; count++; - + return true; } @@ -66,17 +66,17 @@ public: if (count>0) count--; - + return count==0; } - + long get() const { // nothrow - + return static_cast<int const volatile &>( count ); } - + void init(int p_value=1) { - + count=p_value; }; @@ -105,9 +105,9 @@ static inline int atomic_conditional_increment( volatile int * pw ) { // int rv = *pw; // if( rv != 0 ) ++*pw; // return rv; - + int rv, tmp; - + __asm__ ( "movl %0, %%eax\n\t" @@ -124,22 +124,22 @@ static inline int atomic_conditional_increment( volatile int * pw ) { "m"( *pw ): // input (%3) "cc" // clobbers ); - + return rv; } static inline int atomic_decrement( volatile int *pw) { - + // return --(*pw); - + unsigned char rv; - + __asm__ ( "lock\n\t" "decl %0\n\t" - "setne %1": - "=m" (*pw), "=qm" (rv): + "setne %1": + "=m" (*pw), "=qm" (rv): "m" (*pw): "memory" ); @@ -266,15 +266,15 @@ inline long atomic_conditional_increment( register long * pw ) asm { loop: - + lwarx a, 0, pw cmpwi a, 0 beq store - + addi a, a, 1 - + store: - + stwcx. a, 0, pw bne- loop } @@ -288,16 +288,16 @@ inline long atomic_decrement( register long * pw ) register int a; asm { - + sync - + loop: - + lwarx a, 0, pw addi a, a, -1 stwcx. a, 0, pw bne- loop - + isync } @@ -338,11 +338,11 @@ struct SafeRefCount { REFCOUNT_T count; public: - + // destroy() is called when weak_count_ drops to zero. - + bool ref() { //true on success - + return atomic_conditional_increment( &count ) != 0; } @@ -356,17 +356,17 @@ public: if( atomic_decrement ( &count ) == 0 ) { return true; } - + return false; } - + long get() const { // nothrow - + return static_cast<REFCOUNT_GET_T>( count ); } - + void init(int p_value=1) { - + count=p_value; }; @@ -376,4 +376,4 @@ public: #endif // no thread safe -#endif +#endif diff --git a/core/script_language.cpp b/core/script_language.cpp index 0eac39e7d1..1503418269 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -61,26 +61,26 @@ void ScriptServer::set_scripting_enabled(bool p_enabled) { } bool ScriptServer::is_scripting_enabled() { - + return scripting_enabled; } int ScriptServer::get_language_count() { - + return _language_count; - + } ScriptLanguage* ScriptServer::get_language(int p_idx) { ERR_FAIL_INDEX_V(p_idx,_language_count,NULL); - + return _languages[p_idx]; } void ScriptServer::register_language(ScriptLanguage *p_language) { - + ERR_FAIL_COND( _language_count >= MAX_LANGUAGES ); _languages[_language_count++]=p_language; } diff --git a/core/script_language.h b/core/script_language.h index 7e278b8555..1be1aabdab 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -40,15 +40,15 @@ class ScriptLanguage; class ScriptServer { enum { - + MAX_LANGUAGES=4 }; - + static ScriptLanguage *_languages[MAX_LANGUAGES]; static int _language_count; static bool scripting_enabled; -public: - +public: + static void set_scripting_enabled(bool p_enabled); static bool is_scripting_enabled(); static int get_language_count(); @@ -76,14 +76,14 @@ protected: friend class PlaceHolderScriptInstance; virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) {} public: - + virtual bool can_instance() const=0; virtual StringName get_instance_base_type() const=0; // this may not work in all scripts, will return empty if so virtual ScriptInstance* instance_create(Object *p_this)=0; virtual bool instance_has(const Object *p_this) const=0; - + virtual bool has_source_code() const=0; virtual String get_source_code() const=0; virtual void set_source_code(const String& p_code)=0; @@ -102,7 +102,7 @@ public: virtual void update_exports() {} //editor tool - + Script() {} }; @@ -148,13 +148,13 @@ class ScriptLanguage { public: virtual String get_name() const=0; - + /* LANGUAGE FUNCTIONS */ - virtual void init()=0; + virtual void init()=0; virtual String get_type() const=0; virtual String get_extension() const=0; - virtual Error execute_file(const String& p_path) =0; - virtual void finish()=0; + virtual Error execute_file(const String& p_path) =0; + virtual void finish()=0; /* EDITOR FUNCTIONS */ virtual void get_reserved_words(List<String> *p_words) const=0; @@ -197,7 +197,7 @@ public: virtual void frame(); - virtual ~ScriptLanguage() {}; + virtual ~ScriptLanguage() {}; }; extern uint8_t script_encryption_key[32]; diff --git a/core/set.h b/core/set.h index 808ffe5b36..d4d19129d4 100644 --- a/core/set.h +++ b/core/set.h @@ -42,16 +42,16 @@ template <class T,class C=Comparator<T>,class A=DefaultAllocator > class Set { - - enum Color { + + enum Color { RED, BLACK }; - struct _Data; + struct _Data; public: - - + + class Element { private: @@ -72,18 +72,18 @@ public: return _next; } Element *next() { - + return _next; } const Element *prev() const { - + return _prev; } Element *prev() { - + return _prev; } - const T& get() const { + const T& get() const { return value; }; Element() { @@ -96,7 +96,7 @@ public: }; }; - + private: struct _Data { @@ -104,7 +104,7 @@ private: Element* _root; Element* _nil; int size_cache; - + _Data() { #ifdef GLOBALNIL_DISABLED @@ -119,7 +119,7 @@ private: size_cache=0; } - + void _create_root() { _root = memnew_allocator( Element,A ); @@ -136,7 +136,7 @@ private: } ~_Data() { - + _free_root(); #ifdef GLOBALNIL_DISABLED memdelete_allocator<Element,A>(_nil); @@ -144,16 +144,16 @@ private: // memdelete_allocator<Element,A>(_root); } }; - + _Data _data; - + inline void _set_color(Element *p_node, int p_color) { - + ERR_FAIL_COND( p_node == _data._nil && p_color == RED ); p_node->color=p_color; } inline void _rotate_left(Element *p_node) { - + Element *r=p_node->right; p_node->right=r->left; if (r->left != _data._nil ) @@ -163,14 +163,14 @@ private: p_node->parent->left=r; else p_node->parent->right=r; - + r->left=p_node; p_node->parent=r; - + } - + inline void _rotate_right(Element *p_node) { - + Element *l=p_node->left; p_node->left=l->right; if (l->right != _data._nil) @@ -180,25 +180,25 @@ private: p_node->parent->right=l; else p_node->parent->left=l; - + l->right=p_node; p_node->parent=l; - + } - - inline Element* _successor(Element *p_node) const { - + + inline Element* _successor(Element *p_node) const { + Element *node=p_node; - + if (node->right != _data._nil) { - + node=node->right; while(node->left != _data._nil) { /* returns the minium of the right subtree of node */ node=node->left; } return node; } else { - + while(node == node->parent->right) { node=node->parent; } @@ -207,19 +207,19 @@ private: return node->parent; } } - - inline Element* _predecessor(Element *p_node) const { + + inline Element* _predecessor(Element *p_node) const { Element *node=p_node; - + if (node->left != _data._nil) { - + node=node->left; while(node->right != _data._nil) { /* returns the minium of the left subtree of node */ node=node->right; } return node; } else { - + while(node == node->parent->left) { if (node->parent == _data._root) return NULL; @@ -229,23 +229,23 @@ private: return node->parent; } } - - + + Element *_find(const T& p_value) const { - + Element *node = _data._root->left; - C less; - + C less; + while(node!=_data._nil) { - - if (less(p_value,node->value)) + + if (less(p_value,node->value)) node=node->left; else if (less(node->value,p_value)) node=node->right; else break; // found } - + return (node!=_data._nil)?node:NULL; } @@ -282,68 +282,68 @@ private: Element *_insert(const T& p_value, bool& r_exists) { - + Element *new_parent=_data._root; Element *node = _data._root->left; - C less; - + C less; + while (node!=_data._nil) { - + new_parent=node; - + if (less(p_value,node->value)) node=node->left; else if (less(node->value,p_value)) node=node->right; - else { + else { r_exists=true; return node; - } + } } - + Element *new_node = memnew_allocator( Element,A ); - + new_node->parent=new_parent; new_node->right=_data._nil; new_node->left=_data._nil; new_node->value=p_value; // new_node->data=_data; if (new_parent==_data._root || less(p_value,new_parent->value)) { - + new_parent->left=new_node; } else { new_parent->right=new_node; } - + r_exists=false; - + new_node->_next=_successor(new_node); new_node->_prev=_predecessor(new_node); if (new_node->_next) new_node->_next->_prev=new_node; if (new_node->_prev) new_node->_prev->_next=new_node; - + return new_node; } - + Element * _insert_rb(const T& p_value) { - + bool exists=false; Element *new_node = _insert(p_value,exists); if (exists) return new_node; - + Element *node=new_node; _data.size_cache++; - while(node->parent->color==RED) { - + while(node->parent->color==RED) { + if (node->parent == node->parent->parent->left) { - + Element *aux=node->parent->parent->right; - + if (aux->color==RED) { _set_color(node->parent,BLACK); _set_color(aux,BLACK); @@ -357,10 +357,10 @@ private: _set_color(node->parent,BLACK); _set_color(node->parent->parent,RED); _rotate_right(node->parent->parent); - } - } else { + } + } else { Element *aux=node->parent->parent->left; - + if (aux->color==RED) { _set_color(node->parent,BLACK); _set_color(aux,BLACK); @@ -374,19 +374,19 @@ private: _set_color(node->parent,BLACK); _set_color(node->parent->parent,RED); _rotate_left(node->parent->parent); - } + } } } _set_color(_data._root->left,BLACK); - return new_node; - } + return new_node; + } void _erase_fix(Element *p_node) { - + Element *root = _data._root->left; Element *node=p_node; - - + + while( (node->color==BLACK) && (root != node)) { if (node == node->parent->left) { Element *aux=node->parent->right; @@ -396,7 +396,7 @@ private: _rotate_left(node->parent); aux=node->parent->right; } - if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) { + if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) { _set_color(aux,RED); node=node->parent; } else { @@ -420,7 +420,7 @@ private: _rotate_right(node->parent); aux=node->parent->left; } - if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) { + if ( (aux->right->color==BLACK) && (aux->left->color==BLACK) ) { _set_color(aux,RED); node=node->parent; } else { @@ -434,24 +434,24 @@ private: _set_color(node->parent,BLACK); _set_color(aux->left,BLACK); _rotate_right(node->parent); - node=root; + node=root; } } } - + _set_color(node,BLACK); - + ERR_FAIL_COND(_data._nil->color!=BLACK); } - + void _erase(Element *p_node) { - - + + Element *rp= ((p_node->left == _data._nil) || (p_node->right == _data._nil)) ? p_node : _successor(p_node); if (!rp) rp=_data._nil; Element *node= (rp->left == _data._nil) ? rp->right : rp->left; - + if (_data._root == (node->parent=rp->parent) ) { _data._root->left=node; } else { @@ -461,47 +461,47 @@ private: rp->parent->right=node; } } - - if (rp != p_node) { - + + if (rp != p_node) { + ERR_FAIL_COND( rp == _data._nil ); - + if (rp->color==BLACK) _erase_fix(node); - - + + rp->left=p_node->left; rp->right=p_node->right; rp->parent=p_node->parent; rp->color=p_node->color; p_node->left->parent=rp; p_node->right->parent=rp; - + if (p_node == p_node->parent->left) { - p_node->parent->left=rp; + p_node->parent->left=rp; } else { p_node->parent->right=rp; } } else { - if (p_node->color==BLACK) + if (p_node->color==BLACK) _erase_fix(node); - + } - - + + if (p_node->_next) p_node->_next->_prev=p_node->_prev; if (p_node->_prev) p_node->_prev->_next=p_node->_next; - + memdelete_allocator<Element,A>(p_node); _data.size_cache--; ERR_FAIL_COND( _data._nil->color==RED ); } - - + + void _calculate_depth(Element *p_element,int &max_d,int d) const { - + if (p_element==_data._nil) { return; } @@ -510,30 +510,30 @@ private: if (d>max_d) max_d=d; } - + void _cleanup_tree(Element *p_element) { - + if (p_element==_data._nil) return; - + _cleanup_tree(p_element->left); _cleanup_tree(p_element->right); memdelete_allocator<Element,A>( p_element ); } - + void _copy_from( const Set& p_set) { - + clear(); // not the fastest way, but safeset to write. for(Element *I=p_set.front();I;I=I->next()) { - + insert(I->get()); } } public: const Element *find(const T& p_value) const { - + if (!_data._root) return NULL; @@ -542,30 +542,30 @@ public: } Element *find(const T& p_value) { - + if (!_data._root) return NULL; Element *res=_find(p_value); return res; } - + bool has(const T& p_value) const { - + if (!_data._root) return false; return find(p_value)!=NULL; } - + Element *insert(const T& p_value) { - + if (!_data._root) _data._create_root(); return _insert_rb(p_value); - + } - + void erase(Element* p_element) { - + if (!_data._root) return; _erase(p_element); @@ -574,7 +574,7 @@ public: } bool erase(const T& p_value) { - + if (!_data._root) return false; Element *e=find(p_value); @@ -585,32 +585,32 @@ public: _data._free_root(); return true; } - + Element *front() const { - + if (!_data._root) return NULL; Element *e=_data._root->left; if (e==_data._nil) return NULL; - + while(e->left!=_data._nil) e=e->left; - + return e; } - + Element *back() const { - + if (!_data._root) return NULL; Element *e=_data._root->left; if (e==_data._nil) return NULL; - + while(e->right!=_data._nil) e=e->right; - + return e; } @@ -619,7 +619,7 @@ public: return _lower_bound(p_value); } - + inline int size() const { return _data.size_cache; } int calculate_depth() const { // used for debug mostly @@ -629,9 +629,9 @@ public: _calculate_depth(_data._root->left,max_d,0); return max_d; } - + void clear() { - + if (!_data._root) return; @@ -641,25 +641,25 @@ public: _data._nil->parent=_data._nil; _data._free_root(); } - + void operator=(const Set& p_set) { - + _copy_from( p_set ); } - + Set(const Set& p_set) { - + _copy_from( p_set ); } _FORCE_INLINE_ Set() { - + } - - + + ~Set() { - - clear(); + + clear(); } }; diff --git a/core/simple_type.h b/core/simple_type.h index 1cc597146e..1754deec71 100644 --- a/core/simple_type.h +++ b/core/simple_type.h @@ -33,61 +33,61 @@ template<class T> struct GetSimpleType { - + T type; }; template<class T> struct GetSimpleTypeT { - + typedef T type_t; }; template<class T> struct GetSimpleType<T&> { - + T type; - + }; template<class T> struct GetSimpleTypeT<T&> { - + typedef T type_t; }; template<class T> struct GetSimpleType<T const> { - + T type; _FORCE_INLINE_ GetSimpleType() { } - + }; template<class T> struct GetSimpleTypeT<T const> { - + typedef T type_t; }; template<class T> struct GetSimpleType<const T&> { - + T type; _FORCE_INLINE_ GetSimpleType() { } - + }; template<class T> struct GetSimpleType<T*> { - + T *type; _FORCE_INLINE_ GetSimpleType() { type=NULL; } }; template<class T> struct GetSimpleType<const T*> { - + T *type; _FORCE_INLINE_ GetSimpleType() { type=NULL; } }; diff --git a/core/sort.h b/core/sort.h index bd61921c8a..2070065a0d 100644 --- a/core/sort.h +++ b/core/sort.h @@ -44,7 +44,7 @@ template<class T, class Comparator=_DefaultComparator<T> > class SortArray { enum { - + INTROSORT_TRESHOLD=16 }; @@ -54,7 +54,7 @@ public: inline const T& median_of_3(const T& a, const T& b, const T& c) const { - + if (compare(a, b)) if (compare(b, c)) return b; @@ -69,90 +69,90 @@ public: else return b; } - - + + inline int bitlog(int n) const { int k; - for (k = 0; n != 1; n >>= 1) + for (k = 0; n != 1; n >>= 1) ++k; return k; } - - + + /* Heap / Heapsort functions */ - + inline void push_heap(int p_first,int p_hole_idx,int p_top_index,T p_value,T* p_array) const { - + int parent = (p_hole_idx - 1) / 2; while (p_hole_idx > p_top_index && compare(p_array[p_first + parent], p_value)) { - + p_array[p_first + p_hole_idx] = p_array[p_first + parent]; p_hole_idx = parent; parent = (p_hole_idx - 1) / 2; } - p_array[p_first + p_hole_idx] = p_value; - } - + p_array[p_first + p_hole_idx] = p_value; + } + inline void pop_heap(int p_first, int p_last, int p_result, T p_value, T* p_array) const { - + p_array[p_result]=p_array[p_first]; adjust_heap(p_first,0,p_last-p_first,p_value,p_array); } inline void pop_heap(int p_first,int p_last,T* p_array) const { - + pop_heap(p_first,p_last-1,p_last-1,p_array[p_last-1],p_array); } - + inline void adjust_heap(int p_first,int p_hole_idx,int p_len,T p_value,T* p_array) const { - - + + int top_index = p_hole_idx; int second_child = 2 * p_hole_idx + 2; - + while (second_child < p_len) { - + if (compare(p_array[p_first + second_child],p_array[p_first + (second_child - 1)])) second_child--; - + p_array[p_first + p_hole_idx] = p_array[p_first + second_child]; p_hole_idx = second_child; second_child = 2 * (second_child + 1); } - + if (second_child == p_len) { p_array[p_first + p_hole_idx] = p_array[p_first + (second_child - 1)]; p_hole_idx = second_child - 1; } push_heap(p_first, p_hole_idx, top_index, p_value,p_array); } - + inline void sort_heap(int p_first,int p_last,T* p_array) const { - + while(p_last-p_first > 1) { - + pop_heap(p_first,p_last--,p_array); } } - + inline void make_heap(int p_first, int p_last,T* p_array) const { - if (p_last - p_first < 2) + if (p_last - p_first < 2) return; int len = p_last - p_first; int parent = (len - 2)/2; - + while (true) { adjust_heap(p_first, parent, len, p_array[p_first + parent], p_array); - if (parent == 0) + if (parent == 0) return; parent--; } } - + inline void partial_sort(int p_first,int p_last,int p_middle,T* p_array) const { - + make_heap(p_first,p_middle,p_array); - for(int i=p_middle;i<p_last;i++) + for(int i=p_middle;i<p_last;i++) if (compare( p_array[i],p_array[p_first])) pop_heap(p_first,p_middle,i,p_array[i],p_array); sort_heap(p_first,p_middle,p_array); @@ -167,17 +167,17 @@ public: } inline int partitioner(int p_first, int p_last, T p_pivot, T* p_array) const { - + while (true) { - while (compare(p_array[p_first],p_pivot)) + while (compare(p_array[p_first],p_pivot)) p_first++; p_last--; while (compare(p_pivot,p_array[p_last])) p_last--; - + if (!(p_first < p_last)) return p_first; - + SWAP(p_array[p_first],p_array[p_last]); p_first++; } @@ -186,28 +186,28 @@ public: inline void introsort(int p_first, int p_last, T* p_array, int p_max_depth) const { while( p_last - p_first > INTROSORT_TRESHOLD ) { - + if (p_max_depth == 0) { partial_sort(p_first,p_last,p_last,p_array); return; } - + p_max_depth--; - - int cut = partitioner( - p_first, - p_last, - median_of_3( - p_array[p_first], - p_array[p_first + (p_last-p_first)/2], + + int cut = partitioner( + p_first, + p_last, + median_of_3( + p_array[p_first], + p_array[p_first + (p_last-p_first)/2], p_array[p_last-1] ), p_array ); - + introsort(cut,p_last,p_array,p_max_depth); p_last=cut; - + } } @@ -245,7 +245,7 @@ public: } inline void unguarded_linear_insert(int p_last,T p_value,T* p_array) const { - + int next = p_last-1; while (compare(p_value,p_array[next])) { p_array[p_last]=p_array[next]; @@ -254,48 +254,48 @@ public: } p_array[p_last] = p_value; } - + inline void linear_insert(int p_first,int p_last,T*p_array) const { - + T val = p_array[p_last]; if (compare(val, p_array[p_first])) { - + for (int i=p_last; i>p_first; i--) p_array[i]=p_array[i-1]; - + p_array[p_first] = val; } else - unguarded_linear_insert(p_last, val, p_array); + unguarded_linear_insert(p_last, val, p_array); } - + inline void insertion_sort(int p_first,int p_last,T* p_array) const { - + if (p_first==p_last) return; for (int i=p_first+1; i!=p_last ; i++) linear_insert(p_first,i,p_array); } - + inline void unguarded_insertion_sort(int p_first,int p_last,T* p_array) const { - + for (int i=p_first; i!=p_last ; i++) unguarded_linear_insert(i,p_array[i],p_array); } - + inline void final_insertion_sort(int p_first,int p_last,T* p_array) const { - + if (p_last - p_first > INTROSORT_TRESHOLD) { insertion_sort(p_first,p_first+INTROSORT_TRESHOLD,p_array); unguarded_insertion_sort(p_first+INTROSORT_TRESHOLD,p_last,p_array); } else { - + insertion_sort(p_first,p_last,p_array); - - } + + } } inline void sort_range(int p_first, int p_last,T* p_array) const { - + if (p_first != p_last) { introsort(p_first, p_last,p_array,bitlog(p_last - p_first) * 2); final_insertion_sort(p_first, p_last, p_array); @@ -303,7 +303,7 @@ public: } inline void sort(T* p_array,int p_len) const { - + sort_range(0,p_len,p_array); } diff --git a/core/string_db.cpp b/core/string_db.cpp index 0e953cc326..9a693f88e9 100644 --- a/core/string_db.cpp +++ b/core/string_db.cpp @@ -43,23 +43,23 @@ StringName _scs_create(const char *p_chr) { bool StringName::configured=false; void StringName::setup() { - + ERR_FAIL_COND(configured); for(int i=0;i<STRING_TABLE_LEN;i++) { - + _table[i]=NULL; } configured=true; } void StringName::cleanup() { - - _global_lock(); + + _global_lock(); int lost_strings=0; for(int i=0;i<STRING_TABLE_LEN;i++) { - + while(_table[i]) { - + _Data*d=_table[i]; lost_strings++; if (OS::get_singleton()->is_stdout_verbose()) { @@ -71,23 +71,23 @@ void StringName::cleanup() { } } - _table[i]=_table[i]->next; + _table[i]=_table[i]->next; memdelete(d); } } if (OS::get_singleton()->is_stdout_verbose() && lost_strings) { print_line("StringName: "+itos(lost_strings)+" unclaimed string names at exit."); } - _global_unlock(); + _global_unlock(); } void StringName::unref() { - + ERR_FAIL_COND(!configured); if (_data && _data->refcount.unref()) { - - _global_lock(); + + _global_lock(); if (_data->prev) { _data->prev->next=_data->next; @@ -97,26 +97,26 @@ void StringName::unref() { } _table[_data->idx]=_data->next; } - + if (_data->next) { _data->next->prev=_data->prev; } memdelete(_data); - _global_unlock(); + _global_unlock(); } - + _data=NULL; - + } bool StringName::operator==(const String& p_name) const { - + if (!_data) { - + return (p_name.length()==0); } - + return (_data->get_name()==p_name); } @@ -131,50 +131,50 @@ bool StringName::operator==(const char* p_name) const { } bool StringName::operator!=(const String& p_name) const { - + return !(operator==(p_name)); } bool StringName::operator!=(const StringName& p_name) const { - - // the real magic of all this mess happens here. + + // the real magic of all this mess happens here. // this is why path comparisons are very fast return _data!=p_name._data; - + } void StringName::operator=(const StringName& p_name) { - + if (this==&p_name) return; - + unref(); - + if (p_name._data && p_name._data->refcount.ref()) { - - _data = p_name._data; + + _data = p_name._data; } } /* was inlined StringName::operator String() const { - + if (_data) return _data->get_name(); - + return ""; } */ StringName::StringName(const StringName& p_name) { - + ERR_FAIL_COND(!configured); _data=NULL; if (p_name._data && p_name._data->refcount.ref()) { - - _data = p_name._data; - } + + _data = p_name._data; + } } StringName::StringName(const char *p_name) { @@ -184,17 +184,17 @@ StringName::StringName(const char *p_name) { ERR_FAIL_COND(!configured); ERR_FAIL_COND( !p_name || !p_name[0]); - - _global_lock(); - + + _global_lock(); + uint32_t hash = String::hash(p_name); - + uint32_t idx=hash&STRING_TABLE_MASK; - + _data=_table[idx]; - + while(_data) { - + // compare hash first if (_data->hash==hash && _data->get_name()==p_name) break; @@ -226,7 +226,7 @@ StringName::StringName(const char *p_name) { _global_unlock(); - + } StringName::StringName(const StaticCString& p_static_string) { @@ -268,7 +268,7 @@ StringName::StringName(const StaticCString& p_static_string) { _data->refcount.init(); _data->hash=hash; - _data->idx=idx; + _data->idx=idx; _data->cname=p_static_string.ptr; _data->next=_table[idx]; _data->prev=NULL; @@ -283,26 +283,26 @@ StringName::StringName(const StaticCString& p_static_string) { StringName::StringName(const String& p_name) { - + _data=NULL; ERR_FAIL_COND(!configured); - _global_lock(); - + _global_lock(); + uint32_t hash = p_name.hash(); - + uint32_t idx=hash&STRING_TABLE_MASK; _data=_table[idx]; - + while(_data) { - + if (_data->hash==hash && _data->get_name()==p_name) break; _data=_data->next; } - + if (_data) { if (_data->refcount.ref()) { @@ -329,7 +329,7 @@ StringName::StringName(const String& p_name) { _table[idx]=_data; _global_unlock(); - + } StringName StringName::search(const char *p_name) { @@ -435,12 +435,12 @@ StringName StringName::search(const String &p_name) { StringName::StringName() { - + _data=NULL; } StringName::~StringName() { - + unref(); } diff --git a/core/string_db.h b/core/string_db.h index f6c6ecefec..43bcccc902 100644 --- a/core/string_db.h +++ b/core/string_db.h @@ -46,16 +46,16 @@ struct StaticCString { class StringName { - + enum { - + STRING_TABLE_BITS=12, STRING_TABLE_LEN=1<<STRING_TABLE_BITS, STRING_TABLE_MASK=STRING_TABLE_LEN-1 }; - - struct _Data { + + struct _Data { SafeRefCount refcount; const char* cname; String name; @@ -67,32 +67,32 @@ class StringName { _Data *next; _Data() { cname=NULL; next=prev=NULL; hash=0; } }; - - + + static _Data *_table[STRING_TABLE_LEN]; - + _Data *_data; - + union _HashUnion { - + _Data *ptr; uint32_t hash; }; - + void unref(); friend void register_core_types(); friend void unregister_core_types(); - + static void setup(); static void cleanup(); static bool configured; - + StringName(_Data *p_data) { _data=p_data; } public: operator const void*() const { return (_data && (_data->cname || !_data->name.empty()))?(void*)1:0; } - + bool operator==(const String& p_name) const; bool operator==(const char* p_name) const; bool operator!=(const String& p_name) const; @@ -101,19 +101,19 @@ public: return _data<p_name._data; } _FORCE_INLINE_ bool operator==(const StringName& p_name) const { - // the real magic of all this mess happens here. + // the real magic of all this mess happens here. // this is why path comparisons are very fast return _data==p_name._data; - } + } _FORCE_INLINE_ uint32_t hash() const { - + if (_data) return _data->hash; else return 0; } bool operator!=(const StringName& p_name) const; - + _FORCE_INLINE_ operator String() const { if (_data) { @@ -148,7 +148,7 @@ public: }; struct StringNameHasher { - + static _FORCE_INLINE_ uint32_t hash(const StringName &p_string) { return p_string.hash(); } }; diff --git a/core/typedefs.h b/core/typedefs.h index eab0ebc545..5047644692 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -270,7 +270,7 @@ void _global_lock(); void _global_unlock(); struct _GlobalLock { - + _GlobalLock() { _global_lock(); } ~_GlobalLock() { _global_unlock(); } }; diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index ecbda1d3fd..d6d32ccaef 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -239,7 +239,7 @@ void UndoRedo::_process_operation_list(List<Operation>::Element *E) { case Operation::TYPE_METHOD: { - obj->call(op.name,VARIANT_ARGS_FROM_ARRAY(op.args)); + obj->call(op.name,VARIANT_ARGS_FROM_ARRAY(op.args)); #ifdef TOOLS_ENABLED Resource* res = obj->cast_to<Resource>(); if (res) @@ -450,10 +450,10 @@ void UndoRedo::_bind_methods() { ObjectTypeDB::bind_method(_MD("create_action","name","mergeable"),&UndoRedo::create_action, DEFVAL(false) ); ObjectTypeDB::bind_method(_MD("commit_action"),&UndoRedo::commit_action); - + //ObjectTypeDB::bind_method(_MD("add_do_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_do_method); //ObjectTypeDB::bind_method(_MD("add_undo_method","p_object", "p_method", "VARIANT_ARG_LIST"),&UndoRedo::add_undo_method); - + { MethodInfo mi; mi.name="add_do_method"; diff --git a/core/ustring.cpp b/core/ustring.cpp index 1017fc0ca3..a9d0012ebe 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -67,14 +67,14 @@ void String::copy_from(const char *p_cstr) { len++; if (len==0) { - + resize(0); return; } - + resize(len+1); // include 0 - + CharType *dst = this->ptr(); for (int i=0;i<len+1;i++) { @@ -85,35 +85,35 @@ void String::copy_from(const char *p_cstr) { } void String::copy_from(const CharType* p_cstr, int p_clip_to) { - + int len=0; const CharType *ptr=p_cstr; while (*(ptr++)!=0) len++; - + if (p_clip_to>=0 && len>p_clip_to) len=p_clip_to; - + if (len==0) { - + resize(0); return; } - + resize(len+1); set(len,0); - + CharType *dst = &operator[](0); - - + + for (int i=0;i<len;i++) { - + dst[i]=p_cstr[i]; } } void String::copy_from(const CharType& p_char) { - + resize(2); set(0,p_char); set(1,0); @@ -126,12 +126,12 @@ bool String::operator==(const String& p_str) const { return false; if (empty()) return true; - + int l=length(); - + const CharType *src = c_str(); const CharType *dst = p_str.c_str(); - + /* Compare char by char */ for (int i=0;i<l;i++) { @@ -170,19 +170,19 @@ String& String::operator+=(const String &p_str) { *this=p_str; return *this; } - + if (p_str.empty()) return *this; - + int from=length(); - + resize( length() + p_str.size() ); - + const CharType *src = p_str.c_str(); CharType *dst = &operator[](0); set( length(), 0 ); - + for (int i=0;i<p_str.length();i++) dst[from+i]=src[i]; @@ -200,11 +200,11 @@ String& String::operator+=(const CharType *p_str) { String& String::operator+=(CharType p_char) { - + resize( size() ? size() + 1 : 2); set( length(), 0 ); set( length() -1, p_char ); - + return *this; } @@ -220,13 +220,13 @@ String& String::operator+=(const char * p_str) { src_len++; int from=length(); - + resize( from + src_len + 1 ); - + CharType *dst = &operator[](0); - + set( length(), 0 ); - + for (int i=0;i<src_len;i++) dst[from+i]=p_str[i]; @@ -283,11 +283,11 @@ bool String::operator==(const char *p_str) const { return false; if (empty()) return true; - + int l=length(); - + const CharType *dst = c_str(); - + /* Compare char by char */ for (int i=0;i<l;i++) { @@ -312,11 +312,11 @@ bool String::operator==(const CharType *p_str) const { return false; if (empty()) return true; - + int l=length(); - + const CharType *dst = c_str(); - + /* Compare char by char */ for (int i=0;i<l;i++) { @@ -347,8 +347,8 @@ bool String::operator<(const CharType *p_str) const { return false; if (empty()) return true; - - + + const CharType *this_str=c_str(); while (true) { @@ -382,7 +382,7 @@ bool String::operator<(const char *p_str) const { return false; if (empty()) return true; - + const CharType *this_str=c_str(); while (true) { @@ -412,7 +412,7 @@ bool String::operator<(String p_str) const { return operator<(p_str.c_str()); } -signed char String::nocasecmp_to(const String &p_str) const { +signed char String::nocasecmp_to(const String &p_str) const { if (empty() && p_str.empty()) return 0; @@ -423,7 +423,7 @@ signed char String::nocasecmp_to(const String &p_str) const { const CharType *that_str=p_str.c_str(); const CharType *this_str=c_str(); - + while (true) { if (*that_str==0 && *this_str==0) @@ -445,7 +445,7 @@ signed char String::nocasecmp_to(const String &p_str) const { } -signed char String::casecmp_to(const String &p_str) const { +signed char String::casecmp_to(const String &p_str) const { if (empty() && p_str.empty()) return 0; @@ -456,7 +456,7 @@ signed char String::casecmp_to(const String &p_str) const { const CharType *that_str=p_str.c_str(); const CharType *this_str=c_str(); - + while (true) { if (*that_str==0 && *this_str==0) @@ -493,17 +493,17 @@ String String::capitalize() const { String aux=this->replace("_"," ").to_lower(); String cap; for (int i=0;i<aux.get_slice_count(" ");i++) { - + String slice=aux.get_slicec(' ',i); if (slice.length()>0) { - + slice[0]=_find_upper(slice[0]); if (i>0) cap+=" "; cap+=slice; } } - + return cap; } @@ -542,7 +542,7 @@ int String::get_slice_count(String p_splitter) const{ return 0; if (p_splitter.empty()) return 0; - + int pos=0; int slices=1; @@ -559,7 +559,7 @@ String String::get_slice(String p_splitter, int p_slice) const { if (empty() || p_splitter.empty()) return ""; - + int pos=0; int prev_pos=0; // int slices=1; @@ -844,7 +844,7 @@ int String::length() const { const CharType * String::c_str() const { static const CharType zero=0; - + return size()?&operator[](0):&zero; } @@ -867,10 +867,10 @@ String String::md5(const uint8_t *p_md5) { } String String::chr(CharType p_char) { - + CharType c[2]={p_char,0}; return String(c); - + } String String::num(double p_num,int p_decimals) { @@ -1014,7 +1014,7 @@ String String::num(double p_num,int p_decimals) { String decimal; for (int i=0;i<digit;i++) { - + char num[2]={0,0}; num[0]='0'+dec_int%10; decimal=num+decimal; @@ -1200,10 +1200,10 @@ CharString String::ascii(bool p_allow_extended) const { CharString cs; cs.resize(size()); - + for (int i=0;i<size();i++) cs[i]=operator[](i); - + return cs; } @@ -1608,7 +1608,7 @@ int String::to_int() const { integer+=c-'0'; } else if (integer==0 && c=='-') { - + sign=-sign; } @@ -2207,14 +2207,14 @@ double String::to_double() const { double exp=0; double exp_sign=1.0; int reading=READING_SIGN; - + const CharType *str=&operator[](0); while(*str && reading!=READING_DONE) { - + CharType c=*(str++); switch(reading) { - case READING_SIGN: { + case READING_SIGN: { if (c>='0' && c<='9') reading=READING_INT; // let it fallthrough @@ -2228,26 +2228,26 @@ double String::to_double() const { } else { break; } - } + } case READING_INT: { - + if (c>='0' && c<='9') { - + integer*=10; - integer+=c-'0'; - } else if (c=='.') { + integer+=c-'0'; + } else if (c=='.') { reading=READING_DEC; } else if (c=='e') { reading=READING_EXP; } else { reading=READING_DONE; } - + } break; case READING_DEC: { - + if (c>='0' && c<='9') { - + decimal+=(c-'0')*decimal_mult; decimal_mult*=0.1; } else if (c=='e') { @@ -2255,12 +2255,12 @@ double String::to_double() const { } else { reading=READING_DONE; } - + } break; case READING_EXP: { - + if (c>='0' && c<='9') { - + exp*=10.0; exp+=(c-'0'); } else if (c=='-' && exp==0) { @@ -2274,14 +2274,14 @@ double String::to_double() const { } break; } } - + return sign*(integer+decimal)*Math::pow(10,exp_sign*exp); #endif #if 0 double ret=sign*(integer+decimal)*Math::pow(10,exp_sign*exp); - + print_line(*this +" == "+rtos(ret)); return ret; #endif @@ -2308,14 +2308,14 @@ String operator+(CharType p_chr, const String& p_str) { } uint32_t String::hash(const char* p_cstr) { - + uint32_t hashv = 5381; uint32_t c; - + while ((c = *p_cstr++)) hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */ - - return hashv; + + return hashv; } uint32_t String::hash(const char* p_cstr,int p_len) { @@ -2348,19 +2348,19 @@ uint32_t String::hash(const CharType* p_cstr) { } uint32_t String::hash() const { - + /* simple djb2 hashing */ - + const CharType * chr = c_str(); uint32_t hashv = 5381; uint32_t c; - + while ((c = *chr++)) hashv = ((hashv << 5) + hashv) + c; /* hash * 33 + c */ - + return hashv; - - + + } uint64_t String::hash64() const { @@ -2442,16 +2442,16 @@ String String::substr(int p_from,int p_chars) const{ } int String::find_last(String p_str) const { - + int pos=-1; int findfrom=0; int findres=-1; while((findres=find(p_str,findfrom))!=-1) { - + pos=findres; findfrom=pos+1; } - + return pos; } int String::find(String p_str,int p_from) const { @@ -2708,48 +2708,48 @@ bool String::ends_with(const String& p_string) const { } bool String::begins_with(const String& p_string) const { - + if (p_string.length() > length()) return false; - + int l=p_string.length(); if (l==0) return true; - + const CharType *src=&p_string[0]; const CharType *str=&operator[](0); - + int i = 0; for (;i<l;i++) { - + if (src[i]!=str[i]) return false; } - + // only if i == l the p_string matches the beginning return i == l; - + } bool String::begins_with(const char* p_string) const { - + int l=length(); if (l==0||!p_string) return false; - + const CharType *str=&operator[](0); int i=0; - + while (*p_string && i<l) { - + if (*p_string != str[i]) return false; i++; p_string++; - + } - + return *p_string == 0; - + } @@ -2762,27 +2762,27 @@ static bool _wildcard_match(const CharType* p_pattern, const CharType* p_string, case '?' : return *p_string && (*p_string != '.') && _wildcard_match(p_pattern+1, p_string+1,p_case_sensitive); default : - + return (p_case_sensitive?(*p_string==*p_pattern):(_find_upper(*p_string)==_find_upper(*p_pattern))) && _wildcard_match(p_pattern+1, p_string+1,p_case_sensitive); - } + } } bool String::match(const String& p_wildcard) const { - + if (!p_wildcard.length() || !length()) return false; - + return _wildcard_match(p_wildcard.c_str(),c_str(),true); } bool String::matchn(const String& p_wildcard) const { - + if (!p_wildcard.length() || !length()) return false; return _wildcard_match(p_wildcard.c_str(),c_str(),false); - + } String String::replace(String p_key,String p_with) const { @@ -2854,7 +2854,7 @@ String String::right(int p_pos) const { if (p_pos>=size()) return *this; - + if (p_pos<0) return ""; @@ -2868,26 +2868,26 @@ CharType String::ord_at(int p_idx) const { } String String::strip_edges() const { - + int len=length(); int beg=0,end=len; - + for (int i=0;i<length();i++) { - + if (operator[](i)<=32) beg++; else break; } - + for (int i=(int)(length()-1);i>=0;i--) { - + if (operator[](i)<=32) end--; else break; } - + if (beg==0 && end==len) return *this; @@ -3012,7 +3012,7 @@ String String::humanize_size(size_t p_size) { int digits=prefix_idx>0?_humanize_digits(p_size/_div):0; double divisor = prefix_idx>0?_div:1; - + return String::num(p_size/divisor,digits)+prefix[prefix_idx]; } bool String::is_abs_path() const { @@ -3587,12 +3587,12 @@ String String::get_file() const { } String String::extension() const { - + int pos = find_last("."); if (pos<0) return *this; - - return substr( pos+1, length() ); + + return substr( pos+1, length() ); } String String::plus_file(const String& p_file) const { @@ -3749,7 +3749,7 @@ String String::sprintf(const Array& values, bool* error) const { if (!values[value_index].is_num()) { return "a number is required"; } - + int64_t value = values[value_index]; int base; bool capitalize = false; @@ -3811,7 +3811,7 @@ String String::sprintf(const Array& values, bool* error) const { formatted += str; ++value_index; in_format = false; - + break; } case 's': { // String diff --git a/core/ustring.h b/core/ustring.h index e65103ff99..6310d0a854 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -40,7 +40,7 @@ class CharString : public Vector<char> { -public: +public: int length() const { return size() ? size()-1 : 0; } const char *get_data() const; operator const char*() {return get_data();}; @@ -120,7 +120,7 @@ public: bool match(const String& p_wildcard) const; bool matchn(const String& p_wildcard) const; bool begins_with(const String& p_string) const; - bool begins_with(const char* p_string) const; + bool begins_with(const char* p_string) const; bool ends_with(const String& p_string) const; String replace_first(String p_key,String p_with) const; String replace(String p_key,String p_with) const; @@ -182,17 +182,17 @@ public: CharString utf8() const; bool parse_utf8(const char* p_utf8,int p_len=-1); //return true on error static String utf8(const char* p_utf8,int p_len=-1); - + static uint32_t hash(const CharType* p_str,int p_len); /* hash the string */ static uint32_t hash(const CharType* p_str); /* hash the string */ static uint32_t hash(const char* p_cstr,int p_len); /* hash the string */ static uint32_t hash(const char* p_cstr); /* hash the string */ uint32_t hash() const; /* hash the string */ - uint64_t hash64() const; /* hash the string */ + uint64_t hash64() const; /* hash the string */ String md5_text() const; Vector<uint8_t> md5_buffer() const; - inline bool empty() const { return length() == 0; } + inline bool empty() const { return length() == 0; } // path functions bool is_abs_path() const; @@ -213,7 +213,7 @@ public: String c_unescape() const; String json_escape() const; String world_wrap(int p_chars_per_line) const; - + String percent_encode() const; String percent_decode() const; @@ -247,9 +247,9 @@ String rtoss(double p_val); //scientific version struct NoCaseComparator { - + bool operator()(const String& p_a, const String& p_b) const { - + return p_a.nocasecmp_to(p_b)<0; } }; diff --git a/core/variant.cpp b/core/variant.cpp index 1fdbc9f753..527a0d238f 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -37,7 +37,7 @@ String Variant::get_type_name(Variant::Type p_type) { - + switch( p_type ) { case NIL: { @@ -297,7 +297,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) { valid_types=valid; - } break; + } break; case COLOR: { @@ -948,52 +948,52 @@ bool Variant::is_one() const { void Variant::reference(const Variant& p_variant) { - + if (this == &p_variant) return; - + clear(); - + type=p_variant.type; - + switch( p_variant.type ) { case NIL: { - + // none } break; - - // atomic types + + // atomic types case BOOL: { - + _data._bool=p_variant._data._bool; } break; case INT: { - + _data._int=p_variant._data._int; - + } break; case REAL: { - + _data._real=p_variant._data._real; - + } break; case STRING: { - + memnew_placement( _data._mem, String( *reinterpret_cast<const String*>(p_variant._data._mem) ) ); - + } break; - + // math types - + case VECTOR2: { - + memnew_placement( _data._mem, Vector2( *reinterpret_cast<const Vector2*>(p_variant._data._mem) ) ); - + } break; case RECT2: { - + memnew_placement( _data._mem, Rect2( *reinterpret_cast<const Rect2*>(p_variant._data._mem) ) ); - + } break; case MATRIX32: { @@ -1001,100 +1001,100 @@ void Variant::reference(const Variant& p_variant) { } break; case VECTOR3: { - + memnew_placement( _data._mem, Vector3( *reinterpret_cast<const Vector3*>(p_variant._data._mem) ) ); - + } break; case PLANE: { - + memnew_placement( _data._mem, Plane( *reinterpret_cast<const Plane*>(p_variant._data._mem) ) ); - + } break; -/* +/* case QUAT: { - - + + } break;*/ case _AABB: { - + _data._aabb = memnew( AABB( *p_variant._data._aabb ) ); } break; case QUAT: { - + memnew_placement( _data._mem, Quat( *reinterpret_cast<const Quat*>(p_variant._data._mem) ) ); - + } break; case MATRIX3: { - + _data._matrix3 = memnew( Matrix3( *p_variant._data._matrix3 ) ); - + } break; case TRANSFORM: { - + _data._transform = memnew( Transform( *p_variant._data._transform ) ); - + } break; - - // misc types + + // misc types case COLOR: { - + memnew_placement( _data._mem, Color( *reinterpret_cast<const Color*>(p_variant._data._mem) ) ); - + } break; case IMAGE: { - + _data._image = memnew( Image( *p_variant._data._image ) ); - + } break; case _RID: { - + memnew_placement( _data._mem, RID( *reinterpret_cast<const RID*>(p_variant._data._mem) ) ); } break; case OBJECT: { - + memnew_placement( _data._mem, ObjData( p_variant._get_obj() ) ); } break; case NODE_PATH: { - + memnew_placement( _data._mem, NodePath( *reinterpret_cast<const NodePath*>(p_variant._data._mem) ) ); - + } break; case INPUT_EVENT: { - + _data._input_event= memnew( InputEvent( *p_variant._data._input_event ) ); - + } break; case DICTIONARY: { - + memnew_placement( _data._mem, Dictionary( *reinterpret_cast<const Dictionary*>(p_variant._data._mem) ) ); - + } break; case ARRAY: { - + memnew_placement( _data._mem, Array ( *reinterpret_cast<const Array*>(p_variant._data._mem) ) ); - + } break; - + // arrays case RAW_ARRAY: { - + memnew_placement( _data._mem, DVector<uint8_t> ( *reinterpret_cast<const DVector<uint8_t>*>(p_variant._data._mem) ) ); - + } break; case INT_ARRAY: { - + memnew_placement( _data._mem, DVector<int> ( *reinterpret_cast<const DVector<int>*>(p_variant._data._mem) ) ); - + } break; case REAL_ARRAY: { - + memnew_placement( _data._mem, DVector<real_t> ( *reinterpret_cast<const DVector<real_t>*>(p_variant._data._mem) ) ); - + } break; case STRING_ARRAY: { - + memnew_placement( _data._mem, DVector<String> ( *reinterpret_cast<const DVector<String>*>(p_variant._data._mem) ) ); - + } break; case VECTOR2_ARRAY: { @@ -1102,17 +1102,17 @@ void Variant::reference(const Variant& p_variant) { } break; case VECTOR3_ARRAY: { - + memnew_placement( _data._mem, DVector<Vector3> ( *reinterpret_cast<const DVector<Vector3>*>(p_variant._data._mem) ) ); - + } break; case COLOR_ARRAY: { - + memnew_placement( _data._mem, DVector<Color> ( *reinterpret_cast<const DVector<Color>*>(p_variant._data._mem) ) ); - + } break; default: {} - } + } } @@ -1135,7 +1135,7 @@ void Variant::clear() { switch(type) { case STRING: { - + reinterpret_cast<String*>(_data._mem)->~String(); } break; /* @@ -1153,33 +1153,33 @@ void Variant::clear() { } break; case _AABB: { - + memdelete( _data._aabb ); - + } break; case MATRIX3: { - + memdelete( _data._matrix3 ); } break; case TRANSFORM: { - + memdelete( _data._transform ); - + } break; - - // misc types + + // misc types case IMAGE: { - + memdelete( _data._image ); - + } break; case NODE_PATH: { - + reinterpret_cast<NodePath*>(_data._mem)->~NodePath(); - + } break; case OBJECT: { - + _get_obj().obj=NULL; _get_obj().ref.unref(); } break; @@ -1188,41 +1188,41 @@ void Variant::clear() { reinterpret_cast<RID*>(_data._mem)->~RID(); } break; case DICTIONARY: { - + reinterpret_cast<Dictionary*>(_data._mem)->~Dictionary(); - + } break; case ARRAY: { - + reinterpret_cast<Array*>(_data._mem)->~Array(); - + } break; case INPUT_EVENT: { - + memdelete( _data._input_event ); - + } break; - + // arrays case RAW_ARRAY: { - + reinterpret_cast< DVector<uint8_t>* >(_data._mem)->~DVector<uint8_t>(); - + } break; case INT_ARRAY: { - + reinterpret_cast< DVector<int>* >(_data._mem)->~DVector<int>(); - + } break; case REAL_ARRAY: { - + reinterpret_cast< DVector<real_t>* >(_data._mem)->~DVector<real_t>(); - + } break; case STRING_ARRAY: { - + reinterpret_cast< DVector<String>* >(_data._mem)->~DVector<String>(); - + } break; case VECTOR2_ARRAY: { @@ -1230,55 +1230,55 @@ void Variant::clear() { } break; case VECTOR3_ARRAY: { - + reinterpret_cast< DVector<Vector3>* >(_data._mem)->~DVector<Vector3>(); - + } break; case COLOR_ARRAY: { - + reinterpret_cast< DVector<Color>* >(_data._mem)->~DVector<Color>(); - + } break; default: {} /* not needed */ } - + type=NIL; } - + Variant::operator signed int() const { switch( type ) { - - case NIL: return 0; + + case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; case REAL: return _data._real; case STRING: return operator String().to_int(); default: { - + return 0; - } + } } - + return 0; } Variant::operator unsigned int() const { switch( type ) { - - case NIL: return 0; + + case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; case REAL: return _data._real; case STRING: return operator String().to_int(); default: { - + return 0; - } + } } - + return 0; } @@ -1380,69 +1380,69 @@ Variant::operator unsigned long() const { Variant::operator signed short() const { switch( type ) { - - case NIL: return 0; + + case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; case REAL: return _data._real; case STRING: return operator String().to_int(); default: { - + return 0; - } + } } - + return 0; } Variant::operator unsigned short() const { switch( type ) { - - case NIL: return 0; + + case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; case REAL: return _data._real; case STRING: return operator String().to_int(); default: { - + return 0; - } + } } - + return 0; } Variant::operator signed char() const { switch( type ) { - - case NIL: return 0; + + case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; case REAL: return _data._real; case STRING: return operator String().to_int(); default: { - + return 0; - } + } } - + return 0; } Variant::operator unsigned char() const { switch( type ) { - - case NIL: return 0; + + case NIL: return 0; case BOOL: return _data._bool ? 1 : 0; case INT: return _data._int; case REAL: return _data._real; case STRING: return operator String().to_int(); default: { - + return 0; - } + } } - + return 0; } #ifndef CHARTYPE_16BITS @@ -1455,40 +1455,40 @@ Variant::operator CharType() const { Variant::operator float() const { switch( type ) { - - case NIL: return 0; + + case NIL: return 0; case BOOL: return _data._bool ? 1.0 : 0.0; case INT: return (float)_data._int; case REAL: return _data._real; case STRING: return operator String().to_double(); default: { - + return 0; - } + } } - + return 0; } Variant::operator double() const { switch( type ) { - - case NIL: return 0; + + case NIL: return 0; case BOOL: return _data._bool ? 1.0 : 0.0; case INT: return (float)_data._int; case REAL: return _data._real; case STRING: return operator String().to_double(); default: { - + return 0; - } + } } - + return true; } Variant::operator StringName() const { - + if (type==NODE_PATH) { return reinterpret_cast<const NodePath*>(_data._mem)->get_sname(); } @@ -1509,8 +1509,8 @@ struct _VariantStrPair { Variant::operator String() const { switch( type ) { - - case NIL: return ""; + + case NIL: return ""; case BOOL: return _data._bool ? "True" : "False"; case INT: return String::num(_data._int); case REAL: return String::num(_data._real); @@ -1520,7 +1520,7 @@ Variant::operator String() const { case MATRIX32: return operator Matrix32(); case VECTOR3: return operator Vector3(); case PLANE: return operator Plane(); - //case QUAT: + //case QUAT: case _AABB: return operator AABB(); case QUAT: return operator Quat(); case MATRIX3: return operator Matrix3(); @@ -1529,7 +1529,7 @@ Variant::operator String() const { case INPUT_EVENT: return operator InputEvent(); case COLOR: return String::num( operator Color().r)+","+String::num( operator Color().g)+","+String::num( operator Color().b)+","+String::num( operator Color().a) ; case DICTIONARY: { - + const Dictionary &d =*reinterpret_cast<const Dictionary*>(_data._mem); //const String *K=NULL; String str; @@ -1553,15 +1553,15 @@ Variant::operator String() const { str+=", "; str+="("+pairs[i].key+":"+pairs[i].value+")"; } - + return str; } break; - case VECTOR3_ARRAY: { - + case VECTOR3_ARRAY: { + DVector<Vector3> vec = operator DVector<Vector3>(); String str; for(int i=0;i<vec.size();i++) { - + if (i>0) str+=", "; str=str+Variant( vec[i] ); @@ -1634,9 +1634,9 @@ Variant::operator String() const { } break; default: { return "["+get_type_name(type)+"]"; - } + } } - + return ""; } @@ -1819,7 +1819,7 @@ Variant::operator Control*() const { } Variant::operator InputEvent() const { - + if (type==INPUT_EVENT) return *reinterpret_cast<const InputEvent*>(_data._input_event); else @@ -1827,8 +1827,8 @@ Variant::operator InputEvent() const { } Variant::operator Dictionary() const { - - if (type==DICTIONARY) + + if (type==DICTIONARY) return *reinterpret_cast<const Dictionary*>(_data._mem); else return Dictionary(); @@ -1869,10 +1869,10 @@ inline DA _convert_array_from_variant(const Variant& p_variant) { } Variant::operator Array() const { - - if (type==ARRAY) + + if (type==ARRAY) return *reinterpret_cast<const Array*>(_data._mem); - else + else return _convert_array_from_variant<Array >(*this); } @@ -2019,17 +2019,17 @@ Variant::operator Vector<Plane>() const { } Variant::operator Vector<Variant>() const { - + Array from=operator Array(); Vector<Variant> to; int len=from.size(); to.resize(len); for (int i=0;i<len;i++) { - + to[i]=from[i]; } return to; - + } Variant::operator Vector<uint8_t>() const { @@ -2039,7 +2039,7 @@ Variant::operator Vector<uint8_t>() const { int len=from.size(); to.resize(len); for (int i=0;i<len;i++) { - + to[i]=from[i]; } return to; @@ -2051,7 +2051,7 @@ Variant::operator Vector<int>() const { int len=from.size(); to.resize(len); for (int i=0;i<len;i++) { - + to[i]=from[i]; } return to; @@ -2063,7 +2063,7 @@ Variant::operator Vector<real_t>() const { int len=from.size(); to.resize(len); for (int i=0;i<len;i++) { - + to[i]=from[i]; } return to; @@ -2076,7 +2076,7 @@ Variant::operator Vector<String>() const { int len=from.size(); to.resize(len); for (int i=0;i<len;i++) { - + to[i]=from[i]; } return to; @@ -2093,7 +2093,7 @@ Variant::operator Vector<Vector3>() const { DVector<Vector3>::Read r = from.read(); Vector3 *w = &to[0]; for (int i=0;i<len;i++) { - + w[i]=r[i]; } return to; @@ -2168,16 +2168,16 @@ Variant::Variant(unsigned int p_int) { #ifdef NEED_LONG_INT Variant::Variant(signed long p_int) { - + type=INT; _data._int=p_int; - + } Variant::Variant(unsigned long p_int) { - + type=INT; _data._int=p_int; - + } #endif @@ -2232,10 +2232,10 @@ Variant::Variant(double p_double) { } Variant::Variant(const StringName& p_string) { - + type=STRING; memnew_placement( _data._mem, String( p_string.operator String() ) ); - + } Variant::Variant(const String& p_string) { @@ -2335,9 +2335,9 @@ Variant::Variant(const NodePath& p_node_path) { } Variant::Variant(const InputEvent& p_input_event) { - + type=INPUT_EVENT; - _data._input_event = memnew( InputEvent(p_input_event) ); + _data._input_event = memnew( InputEvent(p_input_event) ); } @@ -2367,10 +2367,10 @@ Variant::Variant(const Object* p_object) { } Variant::Variant(const Dictionary& p_dictionary) { - + type=DICTIONARY; memnew_placement( _data._mem, (Dictionary)( p_dictionary) ); - + } Variant::Variant(const Array& p_array) { @@ -2382,15 +2382,15 @@ Variant::Variant(const Array& p_array) { Variant::Variant(const DVector<Plane>& p_array) { - + type=ARRAY; Array *plane_array=memnew_placement( _data._mem, Array ); - + plane_array->resize( p_array.size() ); - + for (int i=0;i<p_array.size();i++) { - + plane_array->operator [](i)=Variant(p_array[i]); } } diff --git a/core/variant.h b/core/variant.h index d8813c4937..ed33de6660 100644 --- a/core/variant.h +++ b/core/variant.h @@ -75,17 +75,17 @@ class Variant { public: enum Type { - - NIL, - - // atomic types + + NIL, + + // atomic types BOOL, INT, REAL, STRING, - + // math types - + VECTOR2, // 5 RECT2, VECTOR3, @@ -95,17 +95,17 @@ public: _AABB, //sorry naming convention fail :( not like it's used often MATRIX3, TRANSFORM, - - // misc types + + // misc types COLOR, IMAGE, // 15 NODE_PATH, _RID, - OBJECT, + OBJECT, INPUT_EVENT, DICTIONARY, // 20 ARRAY, - + // arrays RAW_ARRAY, INT_ARRAY, @@ -114,10 +114,10 @@ public: VECTOR2_ARRAY, VECTOR3_ARRAY, COLOR_ARRAY, - + VARIANT_MAX - - }; + + }; private: @@ -125,7 +125,7 @@ private: friend class _VariantCall; // Variant takes 20 bytes when real_t is float, and 36 if double // it only allocates extra memory for aabb/matrix. - + Type type; struct ObjData { @@ -133,25 +133,25 @@ private: Object *obj; RefPtr ref; }; - + _FORCE_INLINE_ ObjData& _get_obj(); _FORCE_INLINE_ const ObjData& _get_obj() const; union { - + bool _bool; int _int; double _real; Matrix32 *_matrix32; AABB* _aabb; Matrix3 *_matrix3; - Transform *_transform; + Transform *_transform; RefPtr *_resource; InputEvent *_input_event; Image *_image; void *_ptr; //generic pointer -#ifdef USE_QUAD_VECTORS +#ifdef USE_QUAD_VECTORS uint8_t _mem[sizeof(ObjData) > (sizeof(real_t)*5) ? sizeof(ObjData) : (sizeof(real_t)*5)]; // plane uses an extra real #else uint8_t _mem[sizeof(ObjData) > (sizeof(real_t)*4) ? sizeof(ObjData) : (sizeof(real_t)*4)]; @@ -172,7 +172,7 @@ public: template<class T> static Type get_type_for() { - + GetSimpleType<T> t; Variant v(t.type); Type r = v.get_type(); @@ -231,7 +231,7 @@ public: operator Dictionary() const; operator Array() const; - + operator DVector<uint8_t>() const; operator DVector<int>() const; operator DVector<real_t>() const; @@ -260,7 +260,7 @@ public: operator IP_Address() const; - + Variant(bool p_bool); Variant(signed int p_int); // real one Variant(unsigned int p_int); @@ -286,8 +286,8 @@ public: Variant(const Vector3& p_vector3); Variant(const Plane& p_plane); Variant(const AABB& p_aabb); - Variant(const Quat& p_quat); - Variant(const Matrix3& p_transform); + Variant(const Quat& p_quat); + Variant(const Matrix3& p_transform); Variant(const Matrix32& p_transform); Variant(const Transform& p_transform); Variant(const Color& p_color); @@ -295,10 +295,10 @@ public: Variant(const NodePath& p_path); Variant(const RefPtr& p_resource); Variant(const RID& p_rid); - Variant(const Object* p_object); + Variant(const Object* p_object); Variant(const InputEvent& p_input_event); Variant(const Dictionary& p_dictionary); - + Variant(const Array& p_array); Variant(const DVector<Plane>& p_array); // helper Variant(const DVector<uint8_t>& p_raw_array); @@ -309,7 +309,7 @@ public: Variant(const DVector<Color>& p_color_array); Variant(const DVector<Face3>& p_face_array); - + Variant(const Vector<Variant>& p_array); Variant(const Vector<uint8_t>& p_raw_array); Variant(const Vector<int>& p_int_array); diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 9887c50dd8..f03ab43fce 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -662,7 +662,7 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant& case OP_DIVIDE: { switch(p_a.type) { - DEFAULT_OP_FAIL(NIL); + DEFAULT_OP_FAIL(NIL); DEFAULT_OP_NUM(/,BOOL,_bool); case INT: { switch(p_b.type) { @@ -779,7 +779,7 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant& } #endif _RETURN( p_a._data._int % p_b._data._int ); - + } else if (p_a.type==STRING) { const String* format=reinterpret_cast<const String*>(p_a._data._mem); @@ -2409,7 +2409,7 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const { } if (str=="value") { valid=true; return ie.joy_motion.axis_value; - } + } } if (ie.type==InputEvent::SCREEN_TOUCH) { diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp index a3775156ac..8bd1fddfad 100644 --- a/core/variant_parser.cpp +++ b/core/variant_parser.cpp @@ -451,7 +451,7 @@ Error VariantParser::_parse_construct(Stream *p_stream,Vector<T>& r_construct,in if (!first) { get_token(p_stream,token,line,r_err_str); if (token.type==TK_COMMA) { - //do none + //do none } else if (token.type==TK_PARENTHESIS_CLOSE) { break; } else { @@ -1206,7 +1206,7 @@ Error VariantParser::parse_value(Token& token,Variant &value,Stream *p_stream,in get_token(p_stream,token,line,r_err_str); if (token.type!=TK_STRING) { - r_err_str="Expected string"; + r_err_str="Expected string"; return ERR_PARSE_ERROR; } @@ -1676,7 +1676,7 @@ Error VariantParser::_parse_tag(Token& token, Stream *p_stream, int &line, Strin if (err) return err; - r_tag.fields[id]=value; + r_tag.fields[id]=value; } diff --git a/core/vector.h b/core/vector.h index 398d7f1bd5..16a09c1ddd 100644 --- a/core/vector.h +++ b/core/vector.h @@ -43,30 +43,30 @@ template<class T> class Vector { mutable T* _ptr; - + // internal helpers - + _FORCE_INLINE_ SafeRefCount* _get_refcount() const { - + if (!_ptr) return NULL; - + return reinterpret_cast<SafeRefCount*>((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount)); } - + _FORCE_INLINE_ int* _get_size() const { - + if (!_ptr) return NULL; return reinterpret_cast<int*>((uint8_t*)_ptr-sizeof(int)); - + } _FORCE_INLINE_ T* _get_data() const { - + if (!_ptr) return NULL; return reinterpret_cast<T*>(_ptr); - + } _FORCE_INLINE_ size_t _get_alloc_size(size_t p_elements) const { @@ -88,9 +88,9 @@ class Vector { return true; #endif } - + void _unref(void *p_data); - + void _copy_from(const Vector& p_from); void _copy_on_write(); public: @@ -101,18 +101,18 @@ public: _FORCE_INLINE_ void clear() { resize(0); } - + _FORCE_INLINE_ int size() const { int* size = _get_size(); if (size) return *size; - else + else return 0; } _FORCE_INLINE_ bool empty() const { return _ptr == 0; } Error resize(int p_size); bool push_back(T p_elem); - + void remove(int p_index); void erase(const T& p_val) { int idx = find(p_val); if (idx>=0) remove(idx); }; void invert(); @@ -132,7 +132,7 @@ public: } _copy_on_write(); // wants to write, so copy on write. - + return _get_data()[p_index]; } @@ -145,7 +145,7 @@ public: // no cow needed, since it's reading return _get_data()[p_index]; } - + Error insert(int p_pos,const T& p_val); template<class C> @@ -188,21 +188,21 @@ void Vector<T>::_unref(void *p_data) { if (!p_data) return; - + SafeRefCount *src = reinterpret_cast<SafeRefCount*>((uint8_t*)p_data-sizeof(int)-sizeof(SafeRefCount)); - + if (!src->unref()) return; // still in use // clean up - + int *count = (int*)(src+1); T *data = (T*)(count+1); - + for (int i=0;i<*count;i++) { - // call destructors + // call destructors data[i].~T(); } - + // free mem memfree((uint8_t*)p_data-sizeof(int)-sizeof(SafeRefCount)); @@ -213,7 +213,7 @@ void Vector<T>::_copy_on_write() { if (!_ptr) return; - + if (_get_refcount()->get() > 1 ) { /* in use by more than me */ void* mem_new = memalloc(_get_alloc_size(*_get_size())); @@ -221,15 +221,15 @@ void Vector<T>::_copy_on_write() { src_new->init(); int * _size = (int*)(src_new+1); *_size=*_get_size(); - + T*_data=(T*)(_size+1); - + // initialize new elements for (int i=0;i<*_size;i++) { - + memnew_placement(&_data[i], T( _get_data()[i] ) ); } - + _unref(_ptr); _ptr=_data; } @@ -240,11 +240,11 @@ template<class T> template<class T_val> int Vector<T>::find(const T_val &p_val) const { int ret = -1; - if (size() == 0) + if (size() == 0) return ret; - + for (int i=0; i<size(); i++) { - + if (operator[](i) == p_val) { ret = i; break; @@ -261,17 +261,17 @@ Error Vector<T>::resize(int p_size) { if (p_size==size()) return OK; - + if (p_size==0) { - // wants to clean up + // wants to clean up _unref(_ptr); _ptr=NULL; return OK; } - + // possibly changing size, copy on write _copy_on_write(); - + size_t alloc_size; ERR_FAIL_COND_V(!_get_alloc_size_checked(p_size, &alloc_size), ERR_OUT_OF_MEMORY); @@ -293,16 +293,16 @@ Error Vector<T>::resize(int p_size) { // construct the newly created elements T*elems = _get_data(); - + for (int i=*_get_size();i<p_size;i++) { - + memnew_placement(&elems[i], T) ; } *_get_size()=p_size; } else if (p_size<size()) { - + // deinitialize no longer needed elements for (int i=p_size;i<*_get_size();i++) { @@ -312,11 +312,11 @@ Error Vector<T>::resize(int p_size) { void *_ptrnew = (T*)memrealloc((uint8_t*)_ptr-sizeof(int)-sizeof(SafeRefCount), alloc_size); ERR_FAIL_COND_V( !_ptrnew ,ERR_OUT_OF_MEMORY); - + _ptr=(T*)((uint8_t*)_ptrnew+sizeof(int)+sizeof(SafeRefCount)); - + *_get_size()=p_size; - + } return OK; @@ -325,9 +325,9 @@ Error Vector<T>::resize(int p_size) { template<class T> void Vector<T>::invert() { - + for(int i=0;i<size()/2;i++) { - + SWAP( operator[](i), operator[](size()-i-1) ); } } @@ -374,13 +374,13 @@ void Vector<T>::_copy_from(const Vector& p_from) { if (_ptr == p_from._ptr) return; // self assign, do nothing. - + _unref(_ptr); _ptr=NULL; - + if (!p_from._ptr) return; //nothing to do - + if (p_from._get_refcount()->ref()) // could reference _ptr=p_from._ptr; @@ -395,13 +395,13 @@ void Vector<T>::operator=(const Vector& p_from) { template<class T> Error Vector<T>::insert(int p_pos,const T& p_val) { - + ERR_FAIL_INDEX_V(p_pos,size()+1,ERR_INVALID_PARAMETER); resize(size()+1); for (int i=(size()-1);i>p_pos;i--) set( i, get(i-1) ); set( p_pos, p_val ); - + return OK; } diff --git a/main/main.cpp b/main/main.cpp index 8c0c31835f..817b99924a 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -136,13 +136,13 @@ void Main::print_help(const char* p_binary) { const char **test_names=tests_get_names(); const char* coma = ""; while(*test_names) { - + OS::get_singleton()->print("%s%s", coma, *test_names); test_names++; coma = ", "; } OS::get_singleton()->print(")\n"); - + OS::get_singleton()->print("\t-r WIDTHxHEIGHT\t : Request Window Resolution\n"); OS::get_singleton()->print("\t-p XxY\t : Request Window Position\n"); OS::get_singleton()->print("\t-f\t\t : Request Fullscreen\n"); @@ -150,7 +150,7 @@ void Main::print_help(const char* p_binary) { OS::get_singleton()->print("\t-w\t\t Request Windowed\n"); OS::get_singleton()->print("\t-vd DRIVER\t : Video Driver ("); for (int i=0;i<OS::get_singleton()->get_video_driver_count();i++) { - + if (i!=0) OS::get_singleton()->print(", "); OS::get_singleton()->print("%s",OS::get_singleton()->get_video_driver_name(i)); @@ -158,7 +158,7 @@ void Main::print_help(const char* p_binary) { OS::get_singleton()->print(")\n"); OS::get_singleton()->print("\t-ad DRIVER\t : Audio Driver ("); for (int i=0;i<OS::get_singleton()->get_audio_driver_count();i++) { - + if (i!=0) OS::get_singleton()->print(", "); OS::get_singleton()->print("%s",OS::get_singleton()->get_audio_driver_name(i)); @@ -166,7 +166,7 @@ void Main::print_help(const char* p_binary) { OS::get_singleton()->print(")\n"); OS::get_singleton()->print("\t-rthread <mode>\t : Render Thread Mode ('unsafe', 'safe', 'separate)."); OS::get_singleton()->print(")\n"); - OS::get_singleton()->print("\t-s,-script [script] : Run a script.\n"); + OS::get_singleton()->print("\t-s,-script [script] : Run a script.\n"); OS::get_singleton()->print("\t-d,-debug : Debug (local stdout debugger).\n"); OS::get_singleton()->print("\t-rdebug ADDRESS : Remote debug (<ip>:<port> host address).\n"); OS::get_singleton()->print("\t-fdelay [msec]: Simulate high CPU load (delay each frame by [msec]).\n"); @@ -217,7 +217,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas /* argument parsing and main creation */ List<String> args; List<String> main_args; - + for(int i=0;i<argc;i++) { args.push_back(String::utf8(argv[i])); @@ -235,7 +235,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas } I=args.front(); - + video_mode = OS::get_singleton()->get_default_video_mode(); String video_driver=""; @@ -264,7 +264,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas packed_data = memnew(PackedData); #ifdef MINIZIP_ENABLED - + //XXX: always get_singleton() == 0x0 zip_packed_data = ZipArchive::get_singleton(); //TODO: remove this temporary fix @@ -285,44 +285,44 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas // no op } else if (I->get()=="-h" || I->get()=="--help" || I->get()=="/?") { // resolution - + goto error; - - + + } else if (I->get()=="-r") { // resolution - + if (I->next()) { - + String vm=I->next()->get(); - + if (vm.find("x")==-1) { // invalid parameter format - + OS::get_singleton()->print("Invalid -r argument: %s\n",vm.utf8().get_data()); goto error; - - + + } - + int w=vm.get_slice("x",0).to_int(); int h=vm.get_slice("x",1).to_int(); - + if (w==0 || h==0) { - + OS::get_singleton()->print("Invalid -r resolution, x and y must be >0\n"); goto error; - + } - + video_mode.width=w; video_mode.height=h; force_res=true; - + N=I->next()->next(); } else { OS::get_singleton()->print("Invalid -p argument, needs resolution\n"); goto error; - - + + } } else if (I->get()=="-p") { // position @@ -360,15 +360,15 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas init_windowed=true; } else if (I->get()=="-vd") { // video driver - + if (I->next()) { - + video_driver=I->next()->get(); N=I->next()->next(); } else { OS::get_singleton()->print("Invalid -cd argument, needs driver name\n"); goto error; - + } } else if (I->get()=="-lang") { // language @@ -420,18 +420,18 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas } } else if (I->get()=="-ad") { // video driver - + if (I->next()) { - + audio_driver=I->next()->get(); N=I->next()->next(); } else { goto error; - + } - + } else if (I->get()=="-f") { // fullscreen - + //video_mode.fullscreen=false; init_fullscreen=true; } else if (I->get()=="-e" || I->get()=="-editor") { // fonud editor @@ -446,9 +446,9 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas } else if (I->get()=="-v") { // fullscreen OS::get_singleton()->_verbose_stdout=true; } else if (I->get()=="-path") { // resolution - + if (I->next()) { - + String p = I->next()->get(); if (OS::get_singleton()->set_cwd(p)==OK) { //nothing @@ -458,7 +458,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas N=I->next()->next(); } else { goto error; - + } } else if (I->get()=="-bp") { // /breakpoints @@ -567,7 +567,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas main_args.push_back(I->get()); } } - + I=N; } @@ -641,7 +641,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas if (globals->setup(game_path,main_pack)!=OK) { - + #ifdef TOOLS_ENABLED editor=false; #else @@ -729,35 +729,35 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas if (audio_driver=="") { // specified in engine.cfg audio_driver=GLOBAL_DEF("audio/driver",OS::get_singleton()->get_audio_driver_name(0)); } - - + + for (int i=0;i<OS::get_singleton()->get_video_driver_count();i++) { if (video_driver==OS::get_singleton()->get_video_driver_name(i)) { - + video_driver_idx=i; break; } } if (video_driver_idx<0) { - + OS::get_singleton()->alert( "Invalid Video Driver: "+video_driver ); video_driver_idx = 0; //goto error; } for (int i=0;i<OS::get_singleton()->get_audio_driver_count();i++) { - + if (audio_driver==OS::get_singleton()->get_audio_driver_name(i)) { - + audio_driver_idx=i; break; } } if (audio_driver_idx<0) { - + OS::get_singleton()->alert( "Invalid Audio Driver: "+audio_driver ); audio_driver_idx = 0; //goto error; @@ -799,14 +799,14 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas return OK; error: - - video_driver=""; + + video_driver=""; audio_driver=""; game_path=""; - - args.clear(); + + args.clear(); main_args.clear(); - + print_help(execpath); if (performance) @@ -835,14 +835,14 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas unregister_core_driver_types(); unregister_core_types(); - + OS::get_singleton()->_cmdline.clear(); if (message_queue) memdelete( message_queue); OS::get_singleton()->finalize_core(); locale=String(); - + return ERR_INVALID_PARAMETER; } @@ -1136,9 +1136,9 @@ bool Main::start() { Ref<Script> script_res = ResourceLoader::load(script); ERR_EXPLAIN("Can't load script: "+script); ERR_FAIL_COND_V(script_res.is_null(),false); - + if( script_res->can_instance() /*&& script_res->inherits_from("SceneTreeScripted")*/) { - + StringName instance_type=script_res->get_instance_base_type(); Object *obj = ObjectTypeDB::instance(instance_type); @@ -1161,10 +1161,10 @@ bool Main::start() { } else { main_loop_type=GLOBAL_DEF("application/main_loop_type",""); } - + if (!main_loop && main_loop_type=="") main_loop_type="SceneTree"; - + if (!main_loop) { if (!ObjectTypeDB::type_exists(main_loop_type)) { OS::get_singleton()->alert("godot: error: MainLoop type doesn't exist: "+main_loop_type); @@ -1179,17 +1179,17 @@ bool Main::start() { main_loop=ml->cast_to<MainLoop>(); if (!main_loop) { - + memdelete(ml); ERR_EXPLAIN("Invalid MainLoop type"); ERR_FAIL_V(false); - + } } } if (main_loop->is_type("SceneTree")) { - + SceneTree *sml = main_loop->cast_to<SceneTree>(); if (debug_collisions) { @@ -1204,7 +1204,7 @@ bool Main::start() { EditorNode *editor_node=NULL; if (editor) { - editor_node = memnew( EditorNode ); + editor_node = memnew( EditorNode ); sml->get_root()->add_child(editor_node); //root_node->set_editor(editor); @@ -1656,13 +1656,13 @@ void Main::cleanup() { EditorNode::unregister_editor_types(); #endif - unregister_driver_types(); + unregister_driver_types(); unregister_module_types(); - unregister_scene_types(); + unregister_scene_types(); unregister_server_types(); OS::get_singleton()->finalize(); - + if (packed_data) memdelete(packed_data); if (file_access_network_client) diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index 403af8eb04..e8e8ce4e96 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -776,7 +776,7 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre if (named) { - key_idx = codegen.get_name_map_pos(static_cast<const GDParser::IdentifierNode*>(E->get()->arguments[1])->name); + key_idx = codegen.get_name_map_pos(static_cast<const GDParser::IdentifierNode*>(E->get()->arguments[1])->name); //printf("named key %x\n",key_idx); } else { @@ -1567,7 +1567,7 @@ Error GDCompiler::_parse_class(GDScript *p_script,GDScript *p_owner,const GDPars GDScript::MemberInfo minfo; minfo.index = p_script->member_indices.size(); minfo.setter = p_class->variables[i].setter; - minfo.getter = p_class->variables[i].getter; + minfo.getter = p_class->variables[i].getter; p_script->member_indices[name]=minfo; p_script->members.insert(name); diff --git a/modules/gdscript/gd_compiler.h b/modules/gdscript/gd_compiler.h index 5bf7ec980d..32e18c6dcf 100644 --- a/modules/gdscript/gd_compiler.h +++ b/modules/gdscript/gd_compiler.h @@ -44,7 +44,7 @@ class GDCompiler { List< Map<StringName,int> > stack_id_stack; Map<StringName,int> stack_identifiers; - + List<GDFunction::StackDebug> stack_debug; List< Map<StringName,int> > block_identifier_stack; Map<StringName,int> block_identifiers; @@ -65,7 +65,7 @@ class GDCompiler { void push_stack_identifiers() { stack_id_stack.push_back( stack_identifiers ); if (debug_stack) { - + block_identifier_stack.push_back(block_identifiers); block_identifiers.clear(); } @@ -74,10 +74,10 @@ class GDCompiler { void pop_stack_identifiers() { stack_identifiers = stack_id_stack.back()->get(); stack_id_stack.pop_back(); - + if (debug_stack) { for (Map<StringName,int>::Element *E=block_identifiers.front();E;E=E->next()) { - + GDFunction::StackDebug sd; sd.added=false; sd.identifier=E->key(); diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp index 4f572b7b6e..b713dc318f 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -912,7 +912,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ default: valid=false; break; } - if (valid) { + if (valid) { e.is_op=true; e.op=op; expression.push_back(e); diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index c1ee148ef3..beec314e44 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -1515,7 +1515,7 @@ Variant GDScript::_new(const Variant** p_args,int p_argcount,Variant::CallError& return Variant(); } - if (ref.is_valid()) { + if (ref.is_valid()) { return ref; } else { return owner; @@ -2013,7 +2013,7 @@ void GDScript::_get_property_list(List<PropertyInfo> *p_properties) const { void GDScript::_bind_methods() { - ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"new",&GDScript::_new,MethodInfo("new")); + ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"new",&GDScript::_new,MethodInfo("new")); ObjectTypeDB::bind_method(_MD("get_as_byte_code"),&GDScript::get_as_byte_code); diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index a69f99314a..663fc985a7 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -260,7 +260,7 @@ friend class GDScriptLanguage; Map<StringName,Variant> constants; Map<StringName,GDFunction> member_functions; Map<StringName,MemberInfo> member_indices; //members are just indices to the instanced script. - Map<StringName,Ref<GDScript> > subclasses; + Map<StringName,Ref<GDScript> > subclasses; Map<StringName,Vector<StringName> > _signals; #ifdef TOOLS_ENABLED diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 71c56aba01..56eacfd20e 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -541,14 +541,14 @@ void GDTokenizerText::_advance() { } INCPOS(1); is_node_path=true; - + case '\'': case '"': { - + if (GETCHAR(0)=='\'') string_mode=STRING_SINGLE_QUOTE; - - + + int i=1; if (string_mode==STRING_DOUBLE_QUOTE && GETCHAR(i)=='"' && GETCHAR(i+1)=='"') { i+=2; @@ -1054,7 +1054,7 @@ Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> & p_buffer) { const uint8_t *buf=p_buffer.ptr(); int total_len=p_buffer.size(); ERR_FAIL_COND_V( p_buffer.size()<24 || p_buffer[0]!='G' || p_buffer[1]!='D' || p_buffer[2]!='S' || p_buffer[3]!='C',ERR_INVALID_DATA); - + int version = decode_uint32(&buf[4]); if (version>BYTECODE_VERSION) { ERR_EXPLAIN("Bytecode is too New! Please use a newer engine version."); @@ -1066,13 +1066,13 @@ Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> & p_buffer) { int token_count = decode_uint32(&buf[20]); const uint8_t *b=buf; - + b=&buf[24]; total_len-=24; - + identifiers.resize(identifier_count); for(int i=0;i<identifier_count;i++) { - + int len = decode_uint32(b); ERR_FAIL_COND_V(len>total_len,ERR_INVALID_DATA); b+=4; @@ -1089,7 +1089,7 @@ Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> & p_buffer) { total_len-=len+4; identifiers[i]=s; } - + constants.resize(constant_count); for(int i=0;i<constant_count;i++) { diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 7d463b13d4..e8b443a9e3 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -122,7 +122,7 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { Octant &g = *octant_map[ok]; g.baked=b; - g.bake_instance=VS::get_singleton()->instance_create();; + 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()); } @@ -398,7 +398,7 @@ void GridMap::set_cell_item(int p_x,int p_y,int p_z, int p_item,int p_rot){ PhysicsServer::get_singleton()->free(g.collision_debug_instance); } - memdelete(&g); + memdelete(&g); octant_map.erase(octantkey); } else { @@ -984,7 +984,7 @@ void GridMap::_notification(int p_what) { void GridMap::_queue_dirty_map() { if (awaiting_update) - return; + return; if (is_inside_world()) { diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 6fc78e3264..0f1cbdc73a 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -1129,7 +1129,7 @@ Error EditorExportPlatformAndroid::export_project(const String& p_path, bool p_d if (file=="lib/armeabi/libgodot_android.so" && !export_arm) { skip=true; } - + if (file.begins_with("META-INF") && _signed) { skip=true; } diff --git a/platform/android/file_access_android.cpp b/platform/android/file_access_android.cpp index 7a038cca64..334d32de0c 100644 --- a/platform/android/file_access_android.cpp +++ b/platform/android/file_access_android.cpp @@ -122,7 +122,7 @@ uint8_t FileAccessAndroid::get_8() const { } - uint8_t byte; + uint8_t byte; AAsset_read(a,&byte,1); pos++; return byte; diff --git a/platform/android/file_access_jandroid.cpp b/platform/android/file_access_jandroid.cpp index b1b758edb1..da8ceaff14 100644 --- a/platform/android/file_access_jandroid.cpp +++ b/platform/android/file_access_jandroid.cpp @@ -203,7 +203,7 @@ void FileAccessJAndroid::setup( jobject p_io) { __android_log_print(ANDROID_LOG_INFO,"godot","STEP6"); cls=(jclass)env->NewGlobalRef(c); - _file_open = env->GetMethodID(cls, "file_open", "(Ljava/lang/String;Z)I"); + _file_open = env->GetMethodID(cls, "file_open", "(Ljava/lang/String;Z)I"); if(_file_open != 0) { __android_log_print(ANDROID_LOG_INFO,"godot","*******GOT METHOD _file_open ok!!"); } diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 1751334c9b..2ef28333be 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -304,7 +304,7 @@ void OS_Android::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) void OS_Android::set_keep_screen_on(bool p_enabled) { OS::set_keep_screen_on(p_enabled); - + if (set_keep_screen_on_func) { set_keep_screen_on_func(p_enabled); } @@ -796,7 +796,7 @@ OS_Android::OS_Android(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFu get_model_func=p_get_model_func; get_unique_id_func=p_get_unique_id; get_system_dir_func=p_get_sdir_func; - + video_play_func = p_video_play_func; video_is_playing_func = p_video_is_playing_func; video_pause_func = p_video_pause_func; diff --git a/platform/android/os_android.h b/platform/android/os_android.h index 5075e766bc..ec1f4119b4 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -193,9 +193,9 @@ public: virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0); virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const; - + virtual void set_keep_screen_on(bool p_enabled); - + virtual Size2 get_window_size() const; virtual String get_name(); diff --git a/platform/bb10/export/export.cpp b/platform/bb10/export/export.cpp index 2acd920f31..a17c4cb134 100644 --- a/platform/bb10/export/export.cpp +++ b/platform/bb10/export/export.cpp @@ -482,7 +482,7 @@ Error EditorExportPlatformBB10::export_project(const String& p_path, bool p_debu return err; if (ec!=0) return ERR_CANT_CREATE; - + return OK; } diff --git a/platform/flash/include/GL/gl.h b/platform/flash/include/GL/gl.h index e65e1bc8a8..d6387cc5a4 100644 --- a/platform/flash/include/GL/gl.h +++ b/platform/flash/include/GL/gl.h @@ -35,7 +35,7 @@ /********************************************************************** * Begin system-specific stuff. Do not do any of this when building * for SciTech SNAP, as this is all done before this header file is - * included. + * included. */ #if !defined(__SCITECH_SNAP__) @@ -60,7 +60,7 @@ # define GLAPI extern # endif /* _STATIC_MESA support */ # if defined(__MINGW32__) && defined(GL_NO_STDCALL) || defined(UNDER_CE) /* The generated DLLs by MingW with STDCALL are not compatible with the ones done by Microsoft's compilers */ -# define GLAPIENTRY +# define GLAPIENTRY # else # define GLAPIENTRY __stdcall # endif diff --git a/platform/flash/include/GL/glext.h b/platform/flash/include/GL/glext.h index 73467e3cad..d032419a10 100644 --- a/platform/flash/include/GL/glext.h +++ b/platform/flash/include/GL/glext.h @@ -7,7 +7,7 @@ extern "C" { /* ** Copyright (c) 2007-2011 The Khronos Group Inc. -** +** ** Permission is hereby granted, free of charge, to any person obtaining a ** copy of this software and/or associated documentation files (the ** "Materials"), to deal in the Materials without restriction, including @@ -15,10 +15,10 @@ extern "C" { ** distribute, sublicense, and/or sell copies of the Materials, and to ** permit persons to whom the Materials are furnished to do so, subject to ** the following conditions: -** +** ** The above copyright notice and this permission notice shall be included ** in all copies or substantial portions of the Materials. -** +** ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. diff --git a/platform/flash/include/GL/glxext.h b/platform/flash/include/GL/glxext.h index e042cf8794..47eeae61dc 100644 --- a/platform/flash/include/GL/glxext.h +++ b/platform/flash/include/GL/glxext.h @@ -7,7 +7,7 @@ extern "C" { /* ** Copyright (c) 2007-2010 The Khronos Group Inc. -** +** ** Permission is hereby granted, free of charge, to any person obtaining a ** copy of this software and/or associated documentation files (the ** "Materials"), to deal in the Materials without restriction, including @@ -15,10 +15,10 @@ extern "C" { ** distribute, sublicense, and/or sell copies of the Materials, and to ** permit persons to whom the Materials are furnished to do so, subject to ** the following conditions: -** +** ** The above copyright notice and this permission notice shall be included ** in all copies or substantial portions of the Materials. -** +** ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. diff --git a/platform/flash/rasterizer_flash.cpp b/platform/flash/rasterizer_flash.cpp index a36890e3d8..f450956592 100644 --- a/platform/flash/rasterizer_flash.cpp +++ b/platform/flash/rasterizer_flash.cpp @@ -1612,7 +1612,7 @@ void RasterizerFlash::_add_geometry( const Geometry* p_geometry, const InstanceD if (m->flags[VS::MATERIAL_FLAG_UNSHADED]) { - e->light_key-=1; + e->light_key-=1; } else { //setup lights diff --git a/platform/haiku/context_gl_haiku.cpp b/platform/haiku/context_gl_haiku.cpp index 21107a52a4..330046162d 100644 --- a/platform/haiku/context_gl_haiku.cpp +++ b/platform/haiku/context_gl_haiku.cpp @@ -38,6 +38,6 @@ int ContextGL_Haiku::get_window_width() { int ContextGL_Haiku::get_window_height() { return window->Bounds().IntegerHeight(); -} +} #endif diff --git a/platform/haiku/context_gl_haiku.h b/platform/haiku/context_gl_haiku.h index e37fe14970..63caec6fb3 100644 --- a/platform/haiku/context_gl_haiku.h +++ b/platform/haiku/context_gl_haiku.h @@ -18,8 +18,8 @@ public: ~ContextGL_Haiku(); virtual Error initialize(); - virtual void release_current(); - virtual void make_current(); + virtual void release_current(); + virtual void make_current(); virtual void swap_buffers(); virtual int get_window_width(); virtual int get_window_height(); diff --git a/platform/haiku/godot_haiku.cpp b/platform/haiku/godot_haiku.cpp index b4e5e50891..fa5651d89a 100644 --- a/platform/haiku/godot_haiku.cpp +++ b/platform/haiku/godot_haiku.cpp @@ -3,17 +3,17 @@ int main(int argc, char* argv[]) { OS_Haiku os; - + Error error = Main::setup(argv[0], argc-1, &argv[1]); if (error != OK) { return 255; } - + if (Main::start()) { os.run(); } - + Main::cleanup(); - + return os.get_exit_code(); } diff --git a/platform/haiku/key_mapping_haiku.cpp b/platform/haiku/key_mapping_haiku.cpp index 1c0584523a..f0622d3f1d 100644 --- a/platform/haiku/key_mapping_haiku.cpp +++ b/platform/haiku/key_mapping_haiku.cpp @@ -70,7 +70,7 @@ static _HaikuTranslatePair _hb_to_keycode[] = { { KEY_INSERT, B_INSERT }, { KEY_DELETE, B_DELETE }, // { KEY_HELP, ??? }, - + { KEY_0, (0x30) }, { KEY_1, (0x31) }, { KEY_2, (0x32) }, diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index ef483657ca..308800cec0 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -138,7 +138,7 @@ void OS_Haiku::finalize() { memdelete(spatial_sound_2d_server); memdelete(sample_manager); - + audio_server->finish(); memdelete(audio_server); diff --git a/platform/iphone/Appirater.h b/platform/iphone/Appirater.h index 6ff25532f7..9c7e3febf6 100644 --- a/platform/iphone/Appirater.h +++ b/platform/iphone/Appirater.h @@ -27,10 +27,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ This file is part of Appirater. - + Copyright (c) 2010, Arash Payan All rights reserved. - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without @@ -39,10 +39,10 @@ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -119,7 +119,7 @@ extern NSString *const kAppiraterDeclinedToRate; a 'use'. You tell Appirater about these events using the two methods: [Appirater appLaunched:] [Appirater appEnteredForeground:] - + Users need to 'use' the same version of the app this many times before before they will be prompted to rate it. */ @@ -161,7 +161,7 @@ extern NSString *const kAppiraterDeclinedToRate; /* DEPRECATED: While still functional, it's better to use appLaunched:(BOOL)canPromptForRating instead. - + Calls [Appirater appLaunched:YES]. See appLaunched: for details of functionality. */ + (void)appLaunched:(int)p_app_id; @@ -171,7 +171,7 @@ extern NSString *const kAppiraterDeclinedToRate; support multitasking, the 'uses' count will be incremented. You should call this method at the end of your application delegate's application:didFinishLaunchingWithOptions: method. - + If the app has been used enough to be rated (and enough significant events), you can suppress the rating alert by passing NO for canPromptForRating. The rating alert will simply be postponed @@ -185,7 +185,7 @@ extern NSString *const kAppiraterDeclinedToRate; Tells Appirater that the app was brought to the foreground on multitasking devices. You should call this method from the application delegate's applicationWillEnterForeground: method. - + If the app has been used enough to be rated (and enough significant events), you can suppress the rating alert by passing NO for canPromptForRating. The rating alert will simply be postponed @@ -201,7 +201,7 @@ extern NSString *const kAppiraterDeclinedToRate; calls, then you might want to call this method whenever the user places a call. If it's a game, you might want to call this whenever the user beats a level boss. - + If the user has performed enough significant events and used the app enough, you can suppress the rating alert by passing NO for canPromptForRating. The rating alert will simply be postponed until it is called again with YES for diff --git a/platform/iphone/gl_view.h b/platform/iphone/gl_view.h index e69ddc839a..9c27c6a025 100755 --- a/platform/iphone/gl_view.h +++ b/platform/iphone/gl_view.h @@ -42,15 +42,15 @@ // The pixel dimensions of the backbuffer GLint backingWidth; GLint backingHeight; - + EAGLContext *context; - + // OpenGL names for the renderbuffer and framebuffers used to render to this view GLuint viewRenderbuffer, viewFramebuffer; - + // OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) GLuint depthRenderbuffer; - + BOOL useCADisplayLink; // CADisplayLink available on 3.1+ synchronizes the animation timer & drawing with the refresh rate of the display, only supports animation intervals of 1/60 1/30 & 1/15 CADisplayLink *displayLink; @@ -58,12 +58,12 @@ // An animation timer that, when animation is started, will periodically call -drawView at the given rate. // Only used if CADisplayLink is not NSTimer *animationTimer; - + NSTimeInterval animationInterval; - + // Delegate to do our drawing, called by -drawView, which can be called manually or via the animation timer. id<GLViewDelegate> delegate; - + // Flag to denote that the -setupView method of a delegate has been called. // Resets to NO whenever the delegate changes. BOOL delegateSetup; diff --git a/platform/iphone/icloud.h b/platform/iphone/icloud.h index c772555835..dcf3677c85 100644 --- a/platform/iphone/icloud.h +++ b/platform/iphone/icloud.h @@ -44,13 +44,13 @@ class ICloud : public Object { List<Variant> pending_events; public: - + Error remove_key(Variant p_param); Variant set_key_values(Variant p_param); Variant get_key_value(Variant p_param); Error synchronize_key_values(); Variant get_all_key_values(); - + int get_pending_event_count(); Variant pop_pending_event(); diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index 9f6b8433aa..56dffc8aa4 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -160,13 +160,13 @@ void OSIPhone::initialize(const VideoMode& p_desired,int p_video_driver,int p_au #ifdef STOREKIT_ENABLED store_kit = memnew(InAppStore); Globals::get_singleton()->add_singleton(Globals::Singleton("InAppStore", store_kit)); -#endif +#endif #ifdef ICLOUD_ENABLED icloud = memnew(ICloud); Globals::get_singleton()->add_singleton(Globals::Singleton("ICloud", icloud)); //icloud->connect(); -#endif +#endif }; MainLoop *OSIPhone::get_main_loop() const { @@ -303,7 +303,7 @@ void OSIPhone::queue_event(const InputEvent& p_event) { ERR_FAIL_INDEX( event_count, MAX_EVENTS ); - event_queue[event_count++] = p_event; + event_queue[event_count++] = p_event; }; void OSIPhone::touches_cancelled() { @@ -490,7 +490,7 @@ String OSIPhone::get_name() { }; Size2 OSIPhone::get_window_size() const { - + return Vector2(video_mode.width, video_mode.height); } @@ -522,7 +522,7 @@ Error OSIPhone::native_video_play(String p_path, float p_volume, String p_audio_ String tempFile = get_data_dir(); if (!exists) return FAILED; - + if (p_path.begins_with("res://")) { if (PackedData::get_singleton()->has_path(p_path)) { print("Unable to play %S using the native player as it resides in a .pck file\n", p_path.c_str()); @@ -535,7 +535,7 @@ Error OSIPhone::native_video_play(String p_path, float p_volume, String p_audio_ memdelete(f); - print("Playing video: %S\n", p_path.c_str()); + print("Playing video: %S\n", p_path.c_str()); if (_play_video(p_path, p_volume, p_audio_track, p_subtitle_track) ) return OK; return FAILED; diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index d34e8bfe95..9f919940c0 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -166,7 +166,7 @@ public: virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0); virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const; - + virtual void set_keep_screen_on(bool p_enabled); virtual bool can_draw() const; @@ -176,7 +176,7 @@ public: virtual void hide_virtual_keyboard(); virtual void set_cursor_shape(CursorShape p_shape); - + virtual Size2 get_window_size() const; virtual bool has_touchscreen_ui_hint() const; @@ -188,7 +188,7 @@ public: Error shell_open(String p_uri); String get_data_dir() const; - + void set_locale(String p_locale); String get_locale() const; diff --git a/platform/iphone/rasterizer_iphone.cpp b/platform/iphone/rasterizer_iphone.cpp index 29364d091a..f06f12547f 100644 --- a/platform/iphone/rasterizer_iphone.cpp +++ b/platform/iphone/rasterizer_iphone.cpp @@ -2071,7 +2071,7 @@ void RasterizerIPhone::_setup_light(LightInstance* p_instance, int p_idx) { glPopMatrix(); - + } break; default: break; diff --git a/platform/nacl/pepper_main.cpp b/platform/nacl/pepper_main.cpp index fe10db19a9..6b81776624 100644 --- a/platform/nacl/pepper_main.cpp +++ b/platform/nacl/pepper_main.cpp @@ -198,7 +198,7 @@ NPError NPP_New(NPMIMEType pluginType, NPError NPP_Destroy(NPP instance, NPSavedData** save) { nacl_cleanup(); - + return NPERR_NO_ERROR; } diff --git a/platform/osx/context_gl_osx.h b/platform/osx/context_gl_osx.h index 4a94c20c00..565a0ee02a 100644 --- a/platform/osx/context_gl_osx.h +++ b/platform/osx/context_gl_osx.h @@ -48,8 +48,8 @@ class ContextGL_OSX : public ContextGL { public: - virtual void release_current(); - virtual void make_current(); + virtual void release_current(); + virtual void make_current(); virtual void swap_buffers(); virtual Error initialize(); diff --git a/platform/osx/dir_access_osx.h b/platform/osx/dir_access_osx.h index caeeaf643c..8b742b64fa 100644 --- a/platform/osx/dir_access_osx.h +++ b/platform/osx/dir_access_osx.h @@ -43,44 +43,44 @@ @author Juan Linietsky <reduzio@gmail.com> */ class DirAccessOSX : public DirAccess { - + DIR *dir_stream; - + static DirAccess *create_fs(); - + String current_dir; bool _cisdir; bool _cishidden; - + public: - + virtual bool list_dir_begin(); ///< This starts dir listing virtual String get_next(); virtual bool current_is_dir() const; virtual bool current_is_hidden() const; - - virtual void list_dir_end(); ///< - + + virtual void list_dir_end(); ///< + virtual int get_drive_count(); virtual String get_drive(int p_drive); - + virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success virtual String get_current_dir(); ///< return current dir location virtual Error make_dir(String p_dir); - + virtual bool file_exists(String p_file); virtual bool dir_exists(String p_dir); virtual uint64_t get_modified_time(String p_file); - + virtual Error rename(String p_from, String p_to); virtual Error remove(String p_name); virtual size_t get_space_left(); - - + + DirAccessOSX(); ~DirAccessOSX(); diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index a1fd34def7..29c652051a 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -138,7 +138,7 @@ public: virtual Point2 get_mouse_pos() const; virtual int get_mouse_button_state() const; virtual void set_window_title(const String& p_title); - + virtual Size2 get_window_size() const; virtual void set_icon(const Image& p_icon); diff --git a/platform/server/godot_server.cpp b/platform/server/godot_server.cpp index db6c13633d..1c55c03bd7 100644 --- a/platform/server/godot_server.cpp +++ b/platform/server/godot_server.cpp @@ -30,16 +30,16 @@ #include "os_server.h" int main(int argc, char* argv[]) { - + OS_Server os; - + Error err = Main::setup(argv[0],argc-1,&argv[1]); if (err!=OK) return 255; - + if (Main::start()) os.run(); // it is actually the OS that decides how to run Main::cleanup(); - + return os.get_exit_code(); } diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp index f042318f78..5404980ff3 100644 --- a/platform/server/os_server.cpp +++ b/platform/server/os_server.cpp @@ -56,7 +56,7 @@ void OS_Server::initialize(const VideoMode& p_desired,int p_video_driver,int p_a args=OS::get_singleton()->get_cmdline_args(); current_videomode=p_desired; main_loop=NULL; - + rasterizer = memnew( RasterizerDummy ); visual_server = memnew( VisualServerRaster(rasterizer) ); @@ -76,7 +76,7 @@ void OS_Server::initialize(const VideoMode& p_desired,int p_video_driver,int p_a spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); spatial_sound_2d_server->init(); - + ERR_FAIL_COND(!visual_server); visual_server->init(); @@ -90,7 +90,7 @@ void OS_Server::initialize(const VideoMode& p_desired,int p_video_driver,int p_a _ensure_data_dir(); - + } void OS_Server::finalize() { @@ -115,7 +115,7 @@ void OS_Server::finalize() { visual_server->finish(); memdelete(visual_server); memdelete(rasterizer); - + physics_server->finish(); memdelete(physics_server); @@ -218,18 +218,18 @@ void OS_Server::set_cursor_shape(CursorShape p_shape) { void OS_Server::run() { force_quit = false; - + if (!main_loop) return; - + main_loop->init(); - + while (!force_quit) { - + if (Main::iteration()==true) break; }; - + main_loop->finish(); } diff --git a/platform/server/os_server.h b/platform/server/os_server.h index 2487c7b3fb..2081d5f2f4 100644 --- a/platform/server/os_server.h +++ b/platform/server/os_server.h @@ -55,11 +55,11 @@ class OS_Server : public OS_Unix { VisualServer *visual_server; VideoMode current_videomode; List<String> args; - MainLoop *main_loop; + MainLoop *main_loop; AudioDriverDummy driver_dummy; bool grab; - + PhysicsServer *physics_server; Physics2DServer *physics_2d_server; @@ -80,13 +80,13 @@ class OS_Server : public OS_Unix { protected: virtual int get_video_driver_count() const; - virtual const char * get_video_driver_name(int p_driver) const; + virtual const char * get_video_driver_name(int p_driver) const; virtual VideoMode get_default_video_mode() const; - - virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); + + virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); virtual void finalize(); - virtual void set_main_loop( MainLoop * p_main_loop ); + virtual void set_main_loop( MainLoop * p_main_loop ); public: @@ -102,7 +102,7 @@ public: virtual void set_window_title(const String& p_title); virtual MainLoop *get_main_loop() const; - + virtual bool can_draw() const; virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0); diff --git a/platform/windows/context_gl_win.cpp b/platform/windows/context_gl_win.cpp index e671101432..ab66b81421 100644 --- a/platform/windows/context_gl_win.cpp +++ b/platform/windows/context_gl_win.cpp @@ -31,7 +31,7 @@ // // C++ Implementation: context_gl_x11 // -// Description: +// Description: // // // Author: Juan Linietsky <reduzio@gmail.com>, (C) 2008 @@ -105,21 +105,21 @@ Error ContextGL_Win::initialize() { PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, - PFD_TYPE_RGBA, + PFD_TYPE_RGBA, 24, 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0,// No Alpha Buffer 0,// Shift Bit Ignored 0,// No Accumulation Buffer 0, 0, 0, 0,// Accumulation Bits Ignored - 24,// 24Bit Z-Buffer (Depth Buffer) + 24,// 24Bit Z-Buffer (Depth Buffer) 0,// No Stencil Buffer 0,// No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0,// Reserved 0, 0, 0 // Layer Masks Ignored }; - + if (!(hDC=GetDC(hWnd))) { MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return ERR_CANT_CREATE; // Return FALSE diff --git a/platform/windows/context_gl_win.h b/platform/windows/context_gl_win.h index af15ad2659..055e0b2f51 100644 --- a/platform/windows/context_gl_win.h +++ b/platform/windows/context_gl_win.h @@ -30,7 +30,7 @@ // // C++ Interface: context_gl_x11 // -// Description: +// Description: // // // Author: Juan Linietsky <reduzio@gmail.com>, (C) 2008 @@ -62,14 +62,14 @@ public: virtual void release_current(); virtual void make_current(); - + virtual int get_window_width(); virtual int get_window_height(); virtual void swap_buffers(); - + virtual Error initialize(); - - + + ContextGL_Win(HWND hwnd,bool p_opengl_3_context); ~ContextGL_Win(); diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp index fa7989c726..c89d02bb05 100644 --- a/platform/windows/godot_win.cpp +++ b/platform/windows/godot_win.cpp @@ -179,5 +179,5 @@ HINSTANCE godot_hinstance = NULL; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { godot_hinstance = hInstance; - return main(0,NULL); + return main(0,NULL); } diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 95a6a6ac58..cad14430e6 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -178,9 +178,9 @@ void OS_Windows::initialize_core() { maximized=false; minimized=false; - ThreadWindows::make_default(); - SemaphoreWindows::make_default(); - MutexWindows::make_default(); + ThreadWindows::make_default(); + SemaphoreWindows::make_default(); + MutexWindows::make_default(); FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES); FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA); @@ -193,7 +193,7 @@ void OS_Windows::initialize_core() { TCPServerWinsock::make_default(); StreamPeerWinsock::make_default(); PacketPeerUDPWinsock::make_default(); - + mempool_static = new MemoryPoolStaticMalloc; #if 1 mempool_dynamic = memnew( MemoryPoolDynamicStatic ); @@ -203,7 +203,7 @@ void OS_Windows::initialize_core() { mempool_dynamic = memnew( MemoryPoolDynamicPrealloc(buffer,DYNPOOL_SIZE) ); #endif - + // We need to know how often the clock is updated if( !QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second) ) ticks_per_second = 1000; @@ -426,7 +426,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { if (main_loop) input->parse_input_event(event); - + } break; case WM_LBUTTONDOWN: @@ -476,7 +476,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { } break; case WM_MBUTTONUP: { mb.pressed=false; - mb.button_index=3; + mb.button_index=3; } break; case WM_RBUTTONDOWN: { mb.pressed=true; @@ -551,7 +551,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { mb.button_mask|=(wParam&MK_XBUTTON1)?(1<<5):0; mb.button_mask|=(wParam&MK_XBUTTON2)?(1<<6):0;*/ mb.x=GET_X_LPARAM(lParam); - mb.y=GET_Y_LPARAM(lParam); + mb.y=GET_Y_LPARAM(lParam); if (mouse_mode==MOUSE_MODE_CAPTURED) { @@ -822,11 +822,11 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ outside=true; WNDCLASSEXW wc; - + video_mode=p_desired; //printf("**************** desired %s, mode %s\n", p_desired.fullscreen?"true":"false", video_mode.fullscreen?"true":"false"); RECT WindowRect; - + WindowRect.left=0; WindowRect.right=video_mode.width; WindowRect.top=0; @@ -840,18 +840,18 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ wc.cbWndExtra= 0; //wc.hInstance = hInstance; wc.hInstance = godot_hinstance ? godot_hinstance : GetModuleHandle(NULL); - wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); + wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = NULL;//LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; + wc.lpszMenuName = NULL; wc.lpszClassName = L"Engine"; if (!RegisterClassExW(&wc)) { MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); - return; // Return + return; // Return } - - + + EnumDisplayMonitors(NULL,NULL,MonitorEnumProc,0); print_line("DETECTED MONITORS: "+itos(monitor_info.size())); @@ -861,7 +861,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ DEVMODE current; memset(¤t,0,sizeof(current)); EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, ¤t); - + WindowRect.right = current.dmPelsWidth; WindowRect.bottom = current.dmPelsHeight; @@ -888,7 +888,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ dwExStyle=WS_EX_APPWINDOW; dwStyle=WS_POPUP; - + } else { dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle=WS_OVERLAPPEDWINDOW; @@ -937,7 +937,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ }; - + #if defined(OPENGL_ENABLED) || defined(GLES2_ENABLED) || defined(LEGACYGL_ENABLED) gl_context = memnew( ContextGL_Win(hWnd,false) ); gl_context->initialize(); @@ -981,7 +981,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ */ - visual_server->init(); + visual_server->init(); input = memnew( InputDefault ); joystick = memnew (joystick_windows(input, &hWnd)); @@ -1280,7 +1280,7 @@ OS::VideoMode OS_Windows::get_video_mode(int p_screen) const { } void OS_Windows::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const { - + } int OS_Windows::get_screen_count() const { @@ -1714,18 +1714,18 @@ void OS_Windows::delay_usec(uint32_t p_usec) const { Sleep(1); else Sleep(p_usec / 1000); - + } uint64_t OS_Windows::get_ticks_usec() const { uint64_t ticks; - uint64_t time; + uint64_t time; // This is the number of clock ticks since start if( !QueryPerformanceCounter((LARGE_INTEGER *)&ticks) ) ticks = (UINT64)timeGetTime(); // Divide by frequency to get the time in seconds time = ticks * 1000000L / ticks_per_second; - // Subtract the time at game start to get + // Subtract the time at game start to get // the time since the game started time -= ticks_start; return time; @@ -1737,13 +1737,13 @@ void OS_Windows::process_events() { MSG msg; last_id = joystick->process_joysticks(last_id); - + while(PeekMessageW(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessageW(&msg); - + } process_key_events(); @@ -2034,21 +2034,21 @@ void OS_Windows::run() { if (!main_loop) return; - + main_loop->init(); - + uint64_t last_ticks=get_ticks_usec(); - + int frames=0; uint64_t frame=0; - + while (!force_quit) { - + process_events(); // get rid of pending events if (Main::iteration()==true) break; }; - + main_loop->finish(); } @@ -2156,7 +2156,7 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) { } -OS_Windows::~OS_Windows() +OS_Windows::~OS_Windows() { #ifdef STDOUT_FILE fclose(stdo); diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index ab4acf312c..28bb30b370 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -138,27 +138,27 @@ class OS_Windows : public OS { void _touch_event(bool p_pressed, int p_x, int p_y, int idx); // functions used by main to initialize/deintialize the OS -protected: +protected: virtual int get_video_driver_count() const; virtual const char * get_video_driver_name(int p_driver) const; - + virtual VideoMode get_default_video_mode() const; - + virtual int get_audio_driver_count() const; virtual const char * get_audio_driver_name(int p_driver) const; - + virtual void initialize_core(); virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); - - virtual void set_main_loop( MainLoop * p_main_loop ); + + virtual void set_main_loop( MainLoop * p_main_loop ); virtual void delete_main_loop(); - + virtual void finalize(); virtual void finalize_core(); - + void process_events(); void process_key_events(); - + struct ProcessInfo { STARTUPINFO si; @@ -200,7 +200,7 @@ public: virtual Point2 get_mouse_pos() const; virtual int get_mouse_button_state() const; virtual void set_window_title(const String& p_title); - + virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0); virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const; @@ -226,7 +226,7 @@ public: virtual MainLoop *get_main_loop() const; virtual String get_name(); - + virtual Date get_date(bool utc) const; virtual Time get_time(bool utc) const; virtual TimeZoneInfo get_time_zone_info() const; @@ -236,12 +236,12 @@ public: virtual bool can_draw() const; virtual Error set_cwd(const String& p_cwd); - virtual void delay_usec(uint32_t p_usec) const; + virtual void delay_usec(uint32_t p_usec) const; virtual uint64_t get_ticks_usec() const; virtual Error execute(const String& p_path, const List<String>& p_arguments,bool p_blocking,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL); virtual Error kill(const ProcessID& p_pid); - + virtual bool has_environment(const String& p_var) const; virtual String get_environment(const String& p_var) const; @@ -273,7 +273,7 @@ public: virtual bool is_joy_known(int p_device); virtual String get_joy_guid(int p_device) const; - OS_Windows(HINSTANCE _hInstance); + OS_Windows(HINSTANCE _hInstance); ~OS_Windows(); }; diff --git a/platform/winrt/app.cpp b/platform/winrt/app.cpp index 263cd684c4..ea7619a64b 100644 --- a/platform/winrt/app.cpp +++ b/platform/winrt/app.cpp @@ -61,7 +61,7 @@ void App::Initialize(CoreApplicationView^ applicationView) { // Register event handlers for app lifecycle. This example includes Activated, so that we // can make the CoreWindow active and start rendering on the window. - applicationView->Activated += + applicationView->Activated += ref new TypedEventHandler<CoreApplicationView^, IActivatedEventArgs^>(this, &App::OnActivated); // Logic for other event handlers could go here. @@ -78,10 +78,10 @@ void App::SetWindow(CoreWindow^ p_window) window->VisibilityChanged += ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &App::OnVisibilityChanged); - window->Closed += + window->Closed += ref new TypedEventHandler<CoreWindow^, CoreWindowEventArgs^>(this, &App::OnWindowClosed); - window->SizeChanged += + window->SizeChanged += ref new TypedEventHandler<CoreWindow^, WindowSizeChangedEventArgs^>(this, &App::OnWindowSizeChanged); #if !(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) diff --git a/platform/winrt/app.h b/platform/winrt/app.h index 9ce2fe560f..25b0d524ae 100644 --- a/platform/winrt/app.h +++ b/platform/winrt/app.h @@ -46,7 +46,7 @@ namespace $ext_safeprojectname$ bool mWindowVisible; GLsizei mWindowWidth; GLsizei mWindowHeight; - + EGLDisplay mEglDisplay; EGLContext mEglContext; EGLSurface mEglSurface; diff --git a/platform/winrt/include/FunctionDiscoveryKeys_devpkey.h b/platform/winrt/include/FunctionDiscoveryKeys_devpkey.h index 303e70b029..25fa6660c2 100644 --- a/platform/winrt/include/FunctionDiscoveryKeys_devpkey.h +++ b/platform/winrt/include/FunctionDiscoveryKeys_devpkey.h @@ -29,7 +29,7 @@ Revision History: 20-June-2006 dougb Copied Jim's version replaced "DEFINE_DEVPROPKEY(DEVPKEY_" with "DEFINE_PROPERTYKEY(PKEY_" - + --*/ //#include <devpropdef.h> diff --git a/platform/winrt/include/GLES2/gl2ext.h b/platform/winrt/include/GLES2/gl2ext.h index d77fdbaebc..d5a9dd195b 100644 --- a/platform/winrt/include/GLES2/gl2ext.h +++ b/platform/winrt/include/GLES2/gl2ext.h @@ -94,23 +94,23 @@ typedef void* GLeglImageOES; #endif /* GL_OES_required_internalformat */ -#ifndef GL_OES_required_internalformat +#ifndef GL_OES_required_internalformat #define GL_ALPHA8_OES 0x803C #define GL_DEPTH_COMPONENT16_OES 0x81A5 -/* reuse GL_DEPTH_COMPONENT24_OES */ -/* reuse GL_DEPTH24_STENCIL8_OES */ -/* reuse GL_DEPTH_COMPONENT32_OES */ +/* reuse GL_DEPTH_COMPONENT24_OES */ +/* reuse GL_DEPTH24_STENCIL8_OES */ +/* reuse GL_DEPTH_COMPONENT32_OES */ #define GL_LUMINANCE4_ALPHA4_OES 0x8043 #define GL_LUMINANCE8_ALPHA8_OES 0x8045 #define GL_LUMINANCE8_OES 0x8040 #define GL_RGBA4_OES 0x8056 #define GL_RGB5_A1_OES 0x8057 #define GL_RGB565_OES 0x8D62 -/* reuse GL_RGB8_OES */ -/* reuse GL_RGBA8_OES */ +/* reuse GL_RGB8_OES */ +/* reuse GL_RGBA8_OES */ /* reuse GL_RGB10_EXT */ /* reuse GL_RGB10_A2_EXT */ -#endif +#endif /* GL_OES_rgb8_rgba8 */ #ifndef GL_OES_rgb8_rgba8 @@ -210,9 +210,9 @@ typedef void (GL_APIENTRYP GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLen #define GL_SHADER 0x82E1 #define GL_PROGRAM 0x82E2 #define GL_QUERY 0x82E3 -/* PROGRAM_PIPELINE only in GL */ +/* PROGRAM_PIPELINE only in GL */ #define GL_SAMPLER 0x82E6 -/* DISPLAY_LIST only in GL */ +/* DISPLAY_LIST only in GL */ #define GL_MAX_LABEL_LENGTH 0x82E8 #define GL_MAX_DEBUG_MESSAGE_LENGTH 0x9143 #define GL_MAX_DEBUG_LOGGED_MESSAGES 0x9144 @@ -322,12 +322,12 @@ typedef void (GL_APIENTRYP GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLen #endif /* GL_ANGLE_instanced_arrays */ -#ifndef GL_ANGLE_instanced_arrays +#ifndef GL_ANGLE_instanced_arrays #define GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE 0x88FE #endif /* GL_ANGLE_pack_reverse_row_order */ -#ifndef GL_ANGLE_pack_reverse_row_order +#ifndef GL_ANGLE_pack_reverse_row_order #define GL_PACK_REVERSE_ROW_ORDER_ANGLE 0x93A4 #endif @@ -337,23 +337,23 @@ typedef void (GL_APIENTRYP GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLen #endif /* GL_ANGLE_texture_compression_dxt3 */ -#ifndef GL_ANGLE_texture_compression_dxt3 +#ifndef GL_ANGLE_texture_compression_dxt3 #define GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE 0x83F2 #endif /* GL_ANGLE_texture_compression_dxt5 */ -#ifndef GL_ANGLE_texture_compression_dxt5 +#ifndef GL_ANGLE_texture_compression_dxt5 #define GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE 0x83F3 #endif /* GL_ANGLE_texture_usage */ -#ifndef GL_ANGLE_texture_usage +#ifndef GL_ANGLE_texture_usage #define GL_TEXTURE_USAGE_ANGLE 0x93A2 #define GL_FRAMEBUFFER_ATTACHMENT_ANGLE 0x93A3 #endif /* GL_ANGLE_translated_shader_source */ -#ifndef GL_ANGLE_translated_shader_source +#ifndef GL_ANGLE_translated_shader_source #define GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE 0x93A0 #endif @@ -363,7 +363,7 @@ typedef void (GL_APIENTRYP GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLen /* GL_APPLE_copy_texture_levels */ /* No new tokens introduced by this extension. */ - + /* GL_APPLE_framebuffer_multisample */ #ifndef GL_APPLE_framebuffer_multisample #define GL_RENDERBUFFER_SAMPLES_APPLE 0x8CAB @@ -388,9 +388,9 @@ typedef void (GL_APIENTRYP GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLen #ifndef __gl3_h_ /* These types are defined with reference to <inttypes.h> * in the Apple extension spec, but here we use the Khronos - * portable types in khrplatform.h, and assume those types + * portable types in khrplatform.h, and assume those types * are always defined. - * If any other extensions using these types are defined, + * If any other extensions using these types are defined, * the typedefs must move out of this block and be shared. */ typedef khronos_int64_t GLint64; @@ -496,7 +496,7 @@ typedef struct __GLsync *GLsync; /* GL_EXT_multisampled_render_to_texture */ #ifndef GL_EXT_multisampled_render_to_texture #define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT 0x8D6C -/* reuse values from GL_EXT_framebuffer_multisample (desktop extension) */ +/* reuse values from GL_EXT_framebuffer_multisample (desktop extension) */ #define GL_RENDERBUFFER_SAMPLES_EXT 0x8CAB #define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT 0x8D56 #define GL_MAX_SAMPLES_EXT 0x8D57 @@ -604,10 +604,10 @@ typedef struct __GLsync *GLsync; /* GL_EXT_texture_storage */ #ifndef GL_EXT_texture_storage #define GL_TEXTURE_IMMUTABLE_FORMAT_EXT 0x912F -#define GL_ALPHA8_EXT 0x803C +#define GL_ALPHA8_EXT 0x803C #define GL_LUMINANCE8_EXT 0x8040 #define GL_LUMINANCE8_ALPHA8_EXT 0x8045 -#define GL_RGBA32F_EXT 0x8814 +#define GL_RGBA32F_EXT 0x8814 #define GL_RGB32F_EXT 0x8815 #define GL_ALPHA32F_EXT 0x8816 #define GL_LUMINANCE32F_EXT 0x8818 @@ -617,12 +617,12 @@ typedef struct __GLsync *GLsync; #define GL_ALPHA16F_EXT 0x881C #define GL_LUMINANCE16F_EXT 0x881E #define GL_LUMINANCE_ALPHA16F_EXT 0x881F -#define GL_RGB10_A2_EXT 0x8059 +#define GL_RGB10_A2_EXT 0x8059 #define GL_RGB10_EXT 0x8052 #define GL_BGRA8_EXT 0x93A1 #define GL_R8_EXT 0x8229 #define GL_RG8_EXT 0x822B -#define GL_R32F_EXT 0x822E +#define GL_R32F_EXT 0x822E #define GL_RG32F_EXT 0x8230 #define GL_R16F_EXT 0x822D #define GL_RG16F_EXT 0x822F @@ -817,7 +817,7 @@ typedef struct __GLsync *GLsync; #ifndef GL_NV_framebuffer_blit #define GL_READ_FRAMEBUFFER_NV 0x8CA8 #define GL_DRAW_FRAMEBUFFER_NV 0x8CA9 -#define GL_DRAW_FRAMEBUFFER_BINDING_NV 0x8CA6 +#define GL_DRAW_FRAMEBUFFER_BINDING_NV 0x8CA6 #define GL_READ_FRAMEBUFFER_BINDING_NV 0x8CAA #endif @@ -856,10 +856,10 @@ typedef struct __GLsync *GLsync; /* GL_NV_shadow_samplers_array */ #ifndef GL_NV_shadow_samplers_array #define GL_SAMPLER_2D_ARRAY_SHADOW_NV 0x8DC4 -#endif - +#endif + /* GL_NV_shadow_samplers_cube */ -#ifndef GL_NV_shadow_samplers_cube +#ifndef GL_NV_shadow_samplers_cube #define GL_SAMPLER_CUBE_SHADOW_NV 0x8DC5 #endif @@ -1194,7 +1194,7 @@ GL_APICALL void GL_APIENTRY glGetObjectLabel (GLenum identifier, GLuint name, GL GL_APICALL void GL_APIENTRY glObjectPtrLabel (const void *ptr, GLsizei length, const GLchar *label); GL_APICALL void GL_APIENTRY glGetObjectPtrLabel (const void *ptr, GLsizei bufSize, GLsizei *length, GLchar *label); GL_APICALL void GL_APIENTRY glGetPointerv (GLenum pname, void **params); -#endif +#endif typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGECONTROLPROC) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint *ids, GLboolean enabled); typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGEINSERTPROC) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *buf); typedef void (GL_APIENTRYP PFNGLDEBUGMESSAGECALLBACKPROC) (GLDEBUGPROC callback, const void *userParam); @@ -1288,7 +1288,7 @@ GL_APICALL void GL_APIENTRY glRenderbufferStorageMultisampleANGLE (GLenum target typedef void (GL_APIENTRYP PFNGLRENDERBUFFERSTORAGEMULTISAMPLEANGLEPROC) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); #endif -#ifndef GL_ANGLE_instanced_arrays +#ifndef GL_ANGLE_instanced_arrays #define GL_ANGLE_instanced_arrays 1 #ifdef GL_GLEXT_PROTOTYPES GL_APICALL void GL_APIENTRY glDrawArraysInstancedANGLE (GLenum mode, GLint first, GLsizei count, GLsizei primcount); @@ -1301,7 +1301,7 @@ typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISORANGLEPROC) (GLuint index, GLu #endif /* GL_ANGLE_pack_reverse_row_order */ -#ifndef GL_ANGLE_pack_reverse_row_order +#ifndef GL_ANGLE_pack_reverse_row_order #define GL_ANGLE_pack_reverse_row_order 1 #endif @@ -1311,21 +1311,21 @@ typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISORANGLEPROC) (GLuint index, GLu #endif /* GL_ANGLE_texture_compression_dxt3 */ -#ifndef GL_ANGLE_texture_compression_dxt3 +#ifndef GL_ANGLE_texture_compression_dxt3 #define GL_ANGLE_texture_compression_dxt3 1 #endif /* GL_ANGLE_texture_compression_dxt5 */ -#ifndef GL_ANGLE_texture_compression_dxt5 +#ifndef GL_ANGLE_texture_compression_dxt5 #define GL_ANGLE_texture_compression_dxt5 1 #endif /* GL_ANGLE_texture_usage */ -#ifndef GL_ANGLE_texture_usage +#ifndef GL_ANGLE_texture_usage #define GL_ANGLE_texture_usage 1 #endif -#ifndef GL_ANGLE_translated_shader_source +#ifndef GL_ANGLE_translated_shader_source #define GL_ANGLE_translated_shader_source 1 #ifdef GL_GLEXT_PROTOTYPES GL_APICALL void GL_APIENTRY glGetTranslatedShaderSourceANGLE (GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source); diff --git a/platform/winrt/include/GLES3/gl3.h b/platform/winrt/include/GLES3/gl3.h index 9c79862c0d..b7e91e6881 100644 --- a/platform/winrt/include/GLES3/gl3.h +++ b/platform/winrt/include/GLES3/gl3.h @@ -1,7 +1,7 @@ #ifndef __gl3_h_ #define __gl3_h_ -/* +/* * gl3.h last updated on $Date: 2013-02-12 14:37:24 -0800 (Tue, 12 Feb 2013) $ */ diff --git a/platform/winrt/include/GLSLANG/ShaderLang.h b/platform/winrt/include/GLSLANG/ShaderLang.h index 647fed6a02..e486692482 100644 --- a/platform/winrt/include/GLSLANG/ShaderLang.h +++ b/platform/winrt/include/GLSLANG/ShaderLang.h @@ -107,7 +107,7 @@ typedef enum { // This is needed only as a workaround for certain OpenGL driver bugs. SH_EMULATE_BUILT_IN_FUNCTIONS = 0x0100, - // This is an experimental flag to enforce restrictions that aim to prevent + // This is an experimental flag to enforce restrictions that aim to prevent // timing attacks. // It generates compilation errors for shaders that could expose sensitive // texture information via the timing channel. diff --git a/platform/winrt/include/KHR/khrplatform.h b/platform/winrt/include/KHR/khrplatform.h index c9e6f17d34..43aac97a73 100644 --- a/platform/winrt/include/KHR/khrplatform.h +++ b/platform/winrt/include/KHR/khrplatform.h @@ -223,7 +223,7 @@ typedef signed short int khronos_int16_t; typedef unsigned short int khronos_uint16_t; /* - * Types that differ between LLP64 and LP64 architectures - in LLP64, + * Types that differ between LLP64 and LP64 architectures - in LLP64, * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears * to be the only LLP64 architecture in current use. */ diff --git a/platform/winrt/os_winrt.cpp b/platform/winrt/os_winrt.cpp index b6ce7f950d..5ec1bd2756 100644 --- a/platform/winrt/os_winrt.cpp +++ b/platform/winrt/os_winrt.cpp @@ -95,7 +95,7 @@ void OSWinrt::initialize_core() { ThreadWinrt::make_default(); //SemaphoreWindows::make_default(); - MutexWindows::make_default(); + MutexWindows::make_default(); FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES); FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA); @@ -107,7 +107,7 @@ void OSWinrt::initialize_core() { //TCPServerWinsock::make_default(); //StreamPeerWinsock::make_default(); - + mempool_static = new MemoryPoolStaticMalloc; #if 1 mempool_dynamic = memnew( MemoryPoolDynamicStatic ); @@ -117,7 +117,7 @@ void OSWinrt::initialize_core() { mempool_dynamic = memnew( MemoryPoolDynamicPrealloc(buffer,DYNPOOL_SIZE) ); #endif - + // We need to know how often the clock is updated if( !QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second) ) ticks_per_second = 1000; @@ -175,7 +175,7 @@ void OSWinrt::initialize(const VideoMode& p_desired,int p_video_driver,int p_aud physics_2d_server = memnew( Physics2DServerSW ); physics_2d_server->init(); - visual_server->init(); + visual_server->init(); input = memnew( InputDefault ); @@ -307,7 +307,7 @@ void OSWinrt::finalize() { memdelete(main_loop); main_loop=NULL; - + visual_server->finish(); memdelete(visual_server); #ifdef OPENGL_ENABLED @@ -325,7 +325,7 @@ void OSWinrt::finalize() { //if (debugger_connection_console) { // memdelete(debugger_connection_console); //} - + memdelete(sample_manager); audio_server->finish(); @@ -418,7 +418,7 @@ OS::VideoMode OSWinrt::get_video_mode(int p_screen) const { } void OSWinrt::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const { - + } void OSWinrt::print_error(const char* p_function, const char* p_file, int p_line, const char* p_code, const char* p_rationale, ErrorType p_type) { @@ -527,7 +527,7 @@ void OSWinrt::delay_usec(uint32_t p_usec) const { // no Sleep() WaitForSingleObjectEx(GetCurrentThread(), msec, false); - + } uint64_t OSWinrt::get_ticks_usec() const { @@ -633,22 +633,22 @@ void OSWinrt::run() { if (!main_loop) return; - + main_loop->init(); - + uint64_t last_ticks=get_ticks_usec(); - + int frames=0; uint64_t frame=0; - + while (!force_quit) { - + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); process_events(); // get rid of pending events if (Main::iteration()==true) break; }; - + main_loop->finish(); } diff --git a/platform/winrt/os_winrt.h b/platform/winrt/os_winrt.h index 3fbb4a4c1b..0307f81954 100644 --- a/platform/winrt/os_winrt.h +++ b/platform/winrt/os_winrt.h @@ -122,7 +122,7 @@ class OSWinrt : public OS { List<Joystick> joystick_change_queue; int joystick_count; Joystick joysticks[JOYSTICKS_MAX]; - + VideoMode video_mode; MainLoop *main_loop; @@ -153,30 +153,30 @@ class OSWinrt : public OS { // functions used by main to initialize/deintialize the OS -protected: +protected: virtual int get_video_driver_count() const; virtual const char * get_video_driver_name(int p_driver) const; - + virtual VideoMode get_default_video_mode() const; - + virtual int get_audio_driver_count() const; virtual const char * get_audio_driver_name(int p_driver) const; - + virtual void initialize_core(); virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); - - virtual void set_main_loop( MainLoop * p_main_loop ); + + virtual void set_main_loop( MainLoop * p_main_loop ); virtual void delete_main_loop(); - + virtual void finalize(); virtual void finalize_core(); - + void process_events(); void probe_joysticks(); void process_joysticks(); void process_key_events(); - + public: void print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type); @@ -191,7 +191,7 @@ public: virtual Point2 get_mouse_pos() const; virtual int get_mouse_button_state() const; virtual void set_window_title(const String& p_title); - + virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0); virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const; @@ -199,7 +199,7 @@ public: virtual MainLoop *get_main_loop() const; virtual String get_name(); - + virtual Date get_date(bool utc) const; virtual Time get_time(bool utc) const; virtual TimeZoneInfo get_time_zone_info() const; @@ -208,7 +208,7 @@ public: virtual bool can_draw() const; virtual Error set_cwd(const String& p_cwd); - virtual void delay_usec(uint32_t p_usec) const; + virtual void delay_usec(uint32_t p_usec) const; virtual uint64_t get_ticks_usec() const; virtual Error execute(const String& p_path, const List<String>& p_arguments,bool p_blocking,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL); diff --git a/platform/x11/context_gl_x11.cpp b/platform/x11/context_gl_x11.cpp index 89bd5f58ff..9f987e1376 100644 --- a/platform/x11/context_gl_x11.cpp +++ b/platform/x11/context_gl_x11.cpp @@ -41,7 +41,7 @@ typedef GLXContext (*GLXCREATECONTEXTATTRIBSARBPROC)(Display*, GLXFBConfig, GLXContext, Bool, const int*); -struct ContextGL_X11_Private { +struct ContextGL_X11_Private { ::GLXContext glx_context; }; @@ -76,13 +76,13 @@ static GLWrapperFuncPtr wrapper_get_proc_address(const char* p_function) { Error ContextGL_X11::initialize() { - + GLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = NULL; - + // const char *extensions = glXQueryExtensionsString(x11_display, DefaultScreen(x11_display)); - + glXCreateContextAttribsARB = (GLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB"); - + ERR_FAIL_COND_V( !glXCreateContextAttribsARB, ERR_UNCONFIGURED ); @@ -94,13 +94,13 @@ Error ContextGL_X11::initialize() { GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 24, - None + None }; int fbcount; GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs, &fbcount); ERR_FAIL_COND_V(!fbc,ERR_UNCONFIGURED); - + XVisualInfo *vi = glXGetVisualFromFBConfig(x11_display, fbc[0]); XSetWindowAttributes swa; @@ -140,7 +140,7 @@ Error ContextGL_X11::initialize() { GLX_CONTEXT_MINOR_VERSION_ARB, 0, None }; - + p->glx_context = glXCreateContextAttribsARB(x11_display, fbc[0], NULL, true, context_attribs); ERR_FAIL_COND_V(!p->glx_context,ERR_UNCONFIGURED); } @@ -150,7 +150,7 @@ Error ContextGL_X11::initialize() { /* glWrapperInit(wrapper_get_proc_address); glFlush(); - + glXSwapBuffers(x11_display,x11_window); */ //glXMakeCurrent(x11_display, None, NULL); @@ -165,14 +165,14 @@ int ContextGL_X11::get_window_width() { XWindowAttributes xwa; XGetWindowAttributes(x11_display,x11_window,&xwa); - + return xwa.width; } int ContextGL_X11::get_window_height() { XWindowAttributes xwa; XGetWindowAttributes(x11_display,x11_window,&xwa); - + return xwa.height; } @@ -181,9 +181,9 @@ ContextGL_X11::ContextGL_X11(::Display *p_x11_display,::Window &p_x11_window,con default_video_mode=p_default_video_mode; x11_display=p_x11_display; - + opengl_3_context=p_opengl_3_context; - + double_buffer=false; direct_render=false; glx_minor=glx_major=0; diff --git a/platform/x11/context_gl_x11.h b/platform/x11/context_gl_x11.h index 56404d0fae..c77fb3e333 100644 --- a/platform/x11/context_gl_x11.h +++ b/platform/x11/context_gl_x11.h @@ -50,22 +50,22 @@ class ContextGL_X11 : public ContextGL { OS::VideoMode default_video_mode; // ::Colormap x11_colormap; ::Display *x11_display; - ::Window& x11_window; + ::Window& x11_window; bool double_buffer; bool direct_render; int glx_minor,glx_major; bool opengl_3_context; public: - virtual void release_current(); - virtual void make_current(); + virtual void release_current(); + virtual void make_current(); virtual void swap_buffers(); virtual int get_window_width(); virtual int get_window_height(); virtual Error initialize(); - ContextGL_X11(::Display *p_x11_display,::Window &p_x11_window,const OS::VideoMode& p_default_video_mode,bool p_opengl_3_context); + ContextGL_X11(::Display *p_x11_display,::Window &p_x11_window,const OS::VideoMode& p_default_video_mode,bool p_opengl_3_context); ~ContextGL_X11(); }; diff --git a/platform/x11/godot_x11.cpp b/platform/x11/godot_x11.cpp index ee83da25c1..c500f939c4 100644 --- a/platform/x11/godot_x11.cpp +++ b/platform/x11/godot_x11.cpp @@ -30,16 +30,16 @@ #include "os_x11.h" int main(int argc, char* argv[]) { - + OS_X11 os; - + Error err = Main::setup(argv[0],argc-1,&argv[1]); if (err!=OK) return 255; - + if (Main::start()) os.run(); // it is actually the OS that decides how to run Main::cleanup(); - + return os.get_exit_code(); } diff --git a/platform/x11/key_mapping_x11.cpp b/platform/x11/key_mapping_x11.cpp index 46f1483767..190d6925dd 100644 --- a/platform/x11/key_mapping_x11.cpp +++ b/platform/x11/key_mapping_x11.cpp @@ -32,14 +32,14 @@ /***** SCAN CODE CONVERSION ******/ struct _XTranslatePair { - + KeySym keysym; unsigned int keycode; }; -static _XTranslatePair _xkeysym_to_keycode[]={ +static _XTranslatePair _xkeysym_to_keycode[]={ // misc keys - + { XK_Escape, KEY_ESCAPE }, { XK_Tab, KEY_TAB }, { XK_ISO_Left_Tab, KEY_BACKTAB }, @@ -136,8 +136,8 @@ static _XTranslatePair _xkeysym_to_keycode[]={ { XK_F14, KEY_F14}, { XK_F15, KEY_F15}, { XK_F16, KEY_F16}, - - // media keys + + // media keys { XF86XK_Back, KEY_BACK }, { XF86XK_Forward, KEY_FORWARD }, { XF86XK_Stop, KEY_STOP }, @@ -146,7 +146,7 @@ static _XTranslatePair _xkeysym_to_keycode[]={ { XF86XK_AudioMedia, KEY_LAUNCHMEDIA }, { XF86XK_OpenURL, KEY_OPENURL }, { XF86XK_HomePage, KEY_HOMEPAGE }, - { XF86XK_Search, KEY_SEARCH }, + { XF86XK_Search, KEY_SEARCH }, { XF86XK_AudioLowerVolume, KEY_VOLUMEDOWN }, { XF86XK_AudioMute, KEY_VOLUMEMUTE }, { XF86XK_AudioRaiseVolume, KEY_VOLUMEUP }, @@ -155,13 +155,13 @@ static _XTranslatePair _xkeysym_to_keycode[]={ { XF86XK_AudioPrev, KEY_MEDIAPREVIOUS }, { XF86XK_AudioNext, KEY_MEDIANEXT }, { XF86XK_AudioRecord, KEY_MEDIARECORD }, - + // launch keys { XF86XK_Mail, KEY_LAUNCHMAIL }, { XF86XK_MyComputer, KEY_LAUNCH0 }, { XF86XK_Calculator, KEY_LAUNCH1 }, { XF86XK_Standby, KEY_STANDBY }, - + { XF86XK_Launch0, KEY_LAUNCH2 }, { XF86XK_Launch1, KEY_LAUNCH3 }, { XF86XK_Launch2, KEY_LAUNCH4 }, @@ -176,41 +176,41 @@ static _XTranslatePair _xkeysym_to_keycode[]={ { XF86XK_LaunchB, KEY_LAUNCHD }, { XF86XK_LaunchC, KEY_LAUNCHE }, { XF86XK_LaunchD, KEY_LAUNCHF }, - + {0, 0 } }; unsigned int KeyMappingX11::get_keycode(KeySym p_keysym) { - + // kinda bruteforce.. could optimize. - + if (p_keysym<0x100) // Latin 1, maps 1-1 return p_keysym; - + // look for special key for(int idx=0;_xkeysym_to_keycode[idx].keysym!=0;idx++) { - + if (_xkeysym_to_keycode[idx].keysym==p_keysym) return _xkeysym_to_keycode[idx].keycode; } - + return 0; } KeySym KeyMappingX11::get_keysym(unsigned int p_code) { - + // kinda bruteforce.. could optimize. - + if (p_code<0x100) // Latin 1, maps 1-1 return p_code; - + // look for special key for(int idx=0;_xkeysym_to_keycode[idx].keysym!=0;idx++) { - + if (_xkeysym_to_keycode[idx].keycode==p_code) return _xkeysym_to_keycode[idx].keysym; } - + return 0; } @@ -220,13 +220,13 @@ KeySym KeyMappingX11::get_keysym(unsigned int p_code) { // Tables taken from FOX toolkit struct _XTranslateUnicodePair { - + KeySym keysym; unsigned int unicode; }; enum { - + _KEYSYM_MAX=759 }; @@ -992,7 +992,7 @@ static _XTranslateUnicodePair _xkeysym_to_unicode[_KEYSYM_MAX] = { }; unsigned int KeyMappingX11::get_unicode_from_keysym(KeySym p_keysym) { - + /* Latin-1 */ if (p_keysym>=0x20 && p_keysym<=0x7e) return p_keysym; @@ -1001,13 +1001,13 @@ unsigned int KeyMappingX11::get_unicode_from_keysym(KeySym p_keysym) { // keypad to latin1 is easy if (p_keysym>=0xffaa && p_keysym<=0xffb9) return p_keysym-0xff80; - + /* Unicode (may be present)*/ - - if((p_keysym&0xff000000)==0x01000000) + + if((p_keysym&0xff000000)==0x01000000) return p_keysym&0x00ffffff; - - int middle,low=0,high=_KEYSYM_MAX-1; + + int middle,low=0,high=_KEYSYM_MAX-1; do { middle=(high+low)/2; if ( _xkeysym_to_unicode[middle].keysym==p_keysym) @@ -1017,19 +1017,19 @@ unsigned int KeyMappingX11::get_unicode_from_keysym(KeySym p_keysym) { else high=middle-1; } while (high>=low); - + return 0; - + } struct _XTranslateUnicodePairReverse { - + unsigned int unicode; KeySym keysym; }; enum { - + _UNICODE_MAX=750 }; @@ -1783,20 +1783,20 @@ static _XTranslateUnicodePairReverse _unicode_to_xkeysym[_UNICODE_MAX] = { { 0x0EF4, 0x3184 }, { 0x0EF5, 0x3186 }, { 0x0EF6, 0x318D }, - { 0x0EF7, 0x318E } + { 0x0EF7, 0x318E } }; KeySym KeyMappingX11::get_keysym_from_unicode(unsigned int p_unicode) { - + /* Latin 1 */ - + if (p_unicode>=0x20 && p_unicode<=0x7e) return p_unicode; - + if (p_unicode>=0xa0 && p_unicode<=0xff) return p_unicode; - - int middle,low=0,high=_UNICODE_MAX-1; + + int middle,low=0,high=_UNICODE_MAX-1; do { middle=(high+low)/2; if ( _unicode_to_xkeysym[middle].keysym==p_unicode) @@ -1806,7 +1806,7 @@ KeySym KeyMappingX11::get_keysym_from_unicode(unsigned int p_unicode) { else high=middle-1; } while (high>=low); - + // if not found, let's hope X understands it as unicode return p_unicode|0x01000000; } diff --git a/platform/x11/key_mapping_x11.h b/platform/x11/key_mapping_x11.h index 979d8a112f..e3aede8388 100644 --- a/platform/x11/key_mapping_x11.h +++ b/platform/x11/key_mapping_x11.h @@ -48,7 +48,7 @@ public: static KeySym get_keysym(unsigned int p_code); static unsigned int get_unicode_from_keysym(KeySym p_keysym); static KeySym get_keysym_from_unicode(unsigned int p_unicode); - + }; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index e5591810e7..f60610693f 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -109,15 +109,15 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi if (get_render_thread_mode()==RENDER_SEPARATE_THREAD) { XInitThreads(); } - + /** XLIB INITIALIZATION **/ x11_display = XOpenDisplay(NULL); - + char * modifiers = XSetLocaleModifiers ("@im=none"); ERR_FAIL_COND( modifiers == NULL ); - + xim = XOpenIM (x11_display, NULL, NULL, NULL); - + if (xim == NULL) { WARN_PRINT("XOpenIM failed"); @@ -130,19 +130,19 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi if (imvalret != NULL || xim_styles == NULL) { fprintf (stderr, "Input method doesn't support any styles\n"); } - + if (xim_styles) { xim_style = 0L; for (int i=0;i<xim_styles->count_styles;i++) { - + if (xim_styles->supported_styles[i] == (XIMPreeditNothing | XIMStatusNothing)) { - + xim_style = xim_styles->supported_styles[i]; break; } } - + XFree (xim_styles); } XFree( imvalret ); @@ -225,7 +225,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi } else { XGetWindowAttributes(x11_display,x11_window,&xwa); } - xsh->min_width = xwa.width; + xsh->min_width = xwa.width; xsh->max_width = xwa.width; xsh->min_height = xwa.height; xsh->max_height = xwa.height; @@ -282,7 +282,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); spatial_sound_2d_server->init(); - + ERR_FAIL_COND(!visual_server); ERR_FAIL_COND(x11_window==0); @@ -302,7 +302,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi ColormapChangeMask | OwnerGrabButtonMask; XChangeWindowAttributes(x11_display, x11_window,CWEventMask,&new_attr); - + XClassHint* classHint; /* set the titlebar name */ @@ -317,19 +317,19 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XSetClassHint(x11_display, x11_window, classHint); XFree(classHint); - wm_delete = XInternAtom(x11_display, "WM_DELETE_WINDOW", true); + wm_delete = XInternAtom(x11_display, "WM_DELETE_WINDOW", true); XSetWMProtocols(x11_display, x11_window, &wm_delete, 1); - + if (xim && xim_style) { - + xic = XCreateIC (xim,XNInputStyle, xim_style,XNClientWindow,x11_window,XNFocusWindow, x11_window, (char*)NULL); } else { - + xic=NULL; WARN_PRINT("XCreateIC couldn't create xic"); - } + } XcursorSetTheme(x11_display,"default"); cursor_size = XcursorGetDefaultSize(x11_display); @@ -459,7 +459,7 @@ void OS_X11::finalize() { visual_server->finish(); memdelete(visual_server); memdelete(rasterizer); - + physics_server->finish(); memdelete(physics_server); @@ -474,10 +474,10 @@ void OS_X11::finalize() { #endif for(int i=0;i<CURSOR_MAX;i++) { if( cursors[i] != None ) - XFreeCursor( x11_display, cursors[i] ); + XFreeCursor( x11_display, cursors[i] ); if( img[i] != NULL ) XcursorImageDestroy( img[i] ); - }; + }; XDestroyIC( xic ); XCloseIM( xim ); @@ -486,7 +486,7 @@ void OS_X11::finalize() { if (xmbstring) memfree(xmbstring); - + args.clear(); } @@ -630,7 +630,7 @@ int OS_X11::get_screen_count() const { int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return 0; - + int count; XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); XFree(xsi); @@ -647,7 +647,7 @@ int OS_X11::get_current_screen() const { Point2i pos = get_screen_position(i); Size2i size = get_screen_size(i); if( (x >= pos.x && x <pos.x + size.width) && (y >= pos.y && y < pos.y + size.height) ) - return i; + return i; } return 0; } @@ -655,7 +655,7 @@ int OS_X11::get_current_screen() const { void OS_X11::set_current_screen(int p_screen) { int count = get_screen_count(); if(p_screen >= count) return; - + if( current_videomode.fullscreen ) { Point2i position = get_screen_position(p_screen); Size2i size = get_screen_size(p_screen); @@ -677,13 +677,13 @@ Point2 OS_X11::get_screen_position(int p_screen) const { if( !ext_okay ) { return Point2i(0,0); } - + int count; XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); if( p_screen >= count ) { return Point2i(0,0); } - + Point2i position = Point2i(xsi[p_screen].x_org, xsi[p_screen].y_org); XFree(xsi); @@ -696,11 +696,11 @@ Size2 OS_X11::get_screen_size(int p_screen) const { int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return Size2i(0,0); - + int count; XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); if( p_screen >= count ) return Size2i(0,0); - + Size2i size = Point2i(xsi[p_screen].width, xsi[p_screen].height); XFree(xsi); return size; @@ -714,12 +714,12 @@ Point2 OS_X11::get_window_position() const { int screen = get_current_screen(); Point2i screen_position = get_screen_position(screen); - return Point2i(x-screen_position.x, y-screen_position.y); + return Point2i(x-screen_position.x, y-screen_position.y); } void OS_X11::set_window_position(const Point2& p_position) { // Using EWMH -- Extended Window Manager Hints - // to get the size of the decoration + // to get the size of the decoration #if 0 Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True); Atom type; @@ -742,17 +742,17 @@ void OS_X11::set_window_position(const Point2& p_position) { &len, &remaining, &data - ); + ); long left = 0L; long top = 0L; if( result == Success ) { long *extends = (long *) data; - + left = extends[0]; top = extends[2]; - + XFree(data); } @@ -794,7 +794,7 @@ void OS_X11::set_window_resizable(bool p_enabled) { if(!p_enabled) { XWindowAttributes xwa; XGetWindowAttributes(x11_display,x11_window,&xwa); - xsh->min_width = xwa.width; + xsh->min_width = xwa.width; xsh->max_width = xwa.width; xsh->min_height = xwa.height; xsh->max_height = xwa.height; @@ -821,7 +821,7 @@ void OS_X11::set_window_minimized(bool p_enabled) { xev.xclient.data.l[0] = p_enabled ? WM_IconicState : WM_NormalState; XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); - + //XEvent xev; Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); Atom wm_hidden = XInternAtom(x11_display, "_NET_WM_STATE_HIDDEN", False); @@ -834,7 +834,7 @@ void OS_X11::set_window_minimized(bool p_enabled) { xev.xclient.data.l[0] = _NET_WM_STATE_ADD; xev.xclient.data.l[1] = wm_hidden; - XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); } bool OS_X11::is_window_minimized() const { @@ -863,14 +863,14 @@ bool OS_X11::is_window_minimized() const { if( result == Success ) { long *state = (long *) data; - if( state[0] == WM_IconicState ) + if( state[0] == WM_IconicState ) return true; } return false; } void OS_X11::set_window_maximized(bool p_enabled) { - // Using EWMH -- Extended Window Manager Hints + // Using EWMH -- Extended Window Manager Hints XEvent xev; Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); Atom wm_max_horz = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); @@ -928,7 +928,7 @@ bool OS_X11::is_window_maximized() const { &data ); - if(result == Success) { + if(result == Success) { Atom *atoms = (Atom*) data; Atom wm_max_horz = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); Atom wm_max_vert = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_VERT", False); @@ -952,65 +952,65 @@ bool OS_X11::is_window_maximized() const { InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { - + InputModifierState state; - + state.shift = (p_x11_state&ShiftMask); state.control = (p_x11_state&ControlMask); state.alt = (p_x11_state&Mod1Mask /*|| p_x11_state&Mod5Mask*/); //altgr should not count as alt state.meta = (p_x11_state&Mod4Mask); - + return state; } unsigned int OS_X11::get_mouse_button_state(unsigned int p_x11_state) { unsigned int state=0; - + if (p_x11_state&Button1Mask) { - + state|=1<<0; } if (p_x11_state&Button3Mask) { - + state|=1<<1; } if (p_x11_state&Button2Mask) { - + state|=1<<2; } - + if (p_x11_state&Button4Mask) { - + state|=1<<3; } if (p_x11_state&Button5Mask) { - + state|=1<<4; } last_button_state=state; return state; } - + void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { - + // X11 functions don't know what const is XKeyEvent *xkeyevent = p_event; - + // This code was pretty difficult to write. // The docs stink and every toolkit seems to - // do it in a different way. - + // do it in a different way. + /* Phase 1, obtain a proper keysym */ - + // This was also very difficult to figure out. // You'd expect you could just use Keysym provided by - // XKeycodeToKeysym to obtain internationalized - // input.. WRONG!! + // XKeycodeToKeysym to obtain internationalized + // input.. WRONG!! // you must use XLookupString (???) which not only wastes // cycles generating an unnecesary string, but also // still works in half the cases. (won't handle deadkeys) @@ -1019,57 +1019,57 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { // So.. then you have to chosse which of both results // you want to keep. // This is a real bizarreness and cpu waster. - + KeySym keysym_keycode=0; // keysym used to find a keycode KeySym keysym_unicode=0; // keysym used to find unicode - + // XLookupString returns keysyms usable as nice scancodes/ char str[256+1]; XLookupString(xkeyevent, str, 256, &keysym_keycode, NULL); - + // Meanwhile, XLookupString returns keysyms useful for unicode. - - + + if (!xmbstring) { // keep a temporary buffer for the string xmbstring=(char*)memalloc(sizeof(char)*8); xmblen=8; - } - + } + if (xkeyevent->type == KeyPress && xic) { Status status; do { - + int mnbytes = XmbLookupString (xic, xkeyevent, xmbstring, xmblen - 1, &keysym_unicode, &status); xmbstring[mnbytes] = '\0'; if (status == XBufferOverflow) { xmblen = mnbytes + 1; xmbstring = (char*)memrealloc (xmbstring, xmblen); - } + } } while (status == XBufferOverflow); - } + } + - /* Phase 2, obtain a pigui keycode from the keysym */ - + // KeyMappingX11 just translated the X11 keysym to a PIGUI // keysym, so it works in all platforms the same. unsigned int keycode = KeyMappingX11::get_keycode(keysym_keycode); - + /* Phase 3, obtain an unicode character from the keysym */ - + // KeyMappingX11 also translates keysym to unicode. // It does a binary search on a table to translate - // most properly. + // most properly. //print_line("keysym_unicode: "+rtos(keysym_unicode)); unsigned int unicode = keysym_unicode>0? KeyMappingX11::get_unicode_from_keysym(keysym_unicode):0; - + /* Phase 4, determine if event must be filtered */ - + // This seems to be a side-effect of using XIM. // XEventFilter looks like a core X11 funciton, // but it's actually just used to see if we must @@ -1078,47 +1078,47 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { // Guess it was a design problem of the extension bool keypress = xkeyevent->type == KeyPress; - + if (xkeyevent->type == KeyPress && xic) { if (XFilterEvent((XEvent*)xkeyevent, x11_window)) - return; + return; } - + if (keycode==0 && unicode==0) return; /* Phase 5, determine modifier mask */ - + // No problems here, except I had no way to // know Mod1 was ALT and Mod4 was META (applekey/winkey) // just tried Mods until i found them. //print_line("mod1: "+itos(xkeyevent->state&Mod1Mask)+" mod 5: "+itos(xkeyevent->state&Mod5Mask)); - + InputModifierState state = get_key_modifier_state(xkeyevent->state); - + /* Phase 6, determine echo character */ - + // Echo characters in X11 are a keyrelease and a keypress // one after the other with the (almot) same timestamp. // To detect them, i use XPeekEvent and check that their // difference in time is below a treshold. - + if (xkeyevent->type != KeyPress) { - + // make sure there are events pending, // so this call won't block. if (XPending(x11_display)>0) { XEvent peek_event; XPeekEvent(x11_display, &peek_event); - - // I'm using a treshold of 5 msecs, + + // I'm using a treshold of 5 msecs, // since sometimes there seems to be a little // jitter. I'm still not convinced that all this approach // is correct, but the xorg developers are // not very helpful today. - + ::Time tresh=ABS(peek_event.xkey.time-xkeyevent->time); if (peek_event.type == KeyPress && tresh<5 ) { KeySym rk; @@ -1130,16 +1130,16 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { return; //ignore current, echo next } } - + // use the time from peek_event so it always works } - - // save the time to check for echo when keypress happens + + // save the time to check for echo when keypress happens } - - + + /* Phase 7, send event to Window */ - + InputEvent event; event.ID=++event_id; event.type = InputEvent::KEY; @@ -1234,24 +1234,24 @@ void OS_X11::process_xevents() { case ConfigureNotify: /* call resizeGLScene only if our window-size changed */ - - if ((event.xconfigure.width == current_videomode.width) && + + if ((event.xconfigure.width == current_videomode.width) && (event.xconfigure.height == current_videomode.height)) break; - + current_videomode.width=event.xconfigure.width; current_videomode.height=event.xconfigure.height; break; case ButtonPress: case ButtonRelease: { - + /* exit in case of a mouse button press */ last_timestamp=event.xbutton.time; if (mouse_mode==MOUSE_MODE_CAPTURED) { event.xbutton.x=last_mouse_pos.x; event.xbutton.y=last_mouse_pos.y; } - + InputEvent mouse_event; mouse_event.ID=++event_id; mouse_event.type = InputEvent::MOUSE_BUTTON; @@ -1267,31 +1267,31 @@ void OS_X11::process_xevents() { mouse_event.mouse_button.button_index=3; else if (mouse_event.mouse_button.button_index==3) mouse_event.mouse_button.button_index=2; - + mouse_event.mouse_button.pressed=(event.type==ButtonPress); if (event.type==ButtonPress && event.xbutton.button==1) { - + uint64_t diff = get_ticks_usec()/1000 - last_click_ms; if (diff<400 && Point2(last_click_pos).distance_to(Point2(event.xbutton.x,event.xbutton.y))<5) { - + last_click_ms=0; last_click_pos = Point2(-100,-100); - mouse_event.mouse_button.doubleclick=true; + mouse_event.mouse_button.doubleclick=true; mouse_event.ID=++event_id; - + } else { - last_click_ms+=diff; + last_click_ms+=diff; last_click_pos = Point2(event.xbutton.x,event.xbutton.y); } - } + } input->parse_input_event( mouse_event); - - } break; + + } break; case MotionNotify: { // FUCK YOU X11 API YOU SERIOUSLY GROSS ME OUT @@ -1304,7 +1304,7 @@ void OS_X11::process_xevents() { // PLEASE DO ME A FAVOR AND DIE DROWNED IN A FECAL // MOUNTAIN BECAUSE THAT'S WHERE YOU BELONG. - + while(true) { if (mouse_mode==MOUSE_MODE_CAPTURED && event.xmotion.x==current_videomode.width/2 && event.xmotion.y==current_videomode.height/2) { //this is likely the warp event since it was warped here @@ -1326,7 +1326,7 @@ void OS_X11::process_xevents() { } last_timestamp=event.xmotion.time; - + // Motion is also simple. // A little hack is in order // to be able to send relative motion events. @@ -1359,13 +1359,13 @@ void OS_X11::process_xevents() { 0,0,0,0, (int)center.x, (int)center.y); #endif } - + if (!last_mouse_pos_valid) { - + last_mouse_pos=pos; last_mouse_pos_valid=true; } - + Point2i rel = pos - last_mouse_pos; #ifdef NEW_WM_API @@ -1379,7 +1379,7 @@ void OS_X11::process_xevents() { motion_event.ID=++event_id; motion_event.type=InputEvent::MOUSE_MOTION; motion_event.device=0; - + motion_event.mouse_motion.mod = get_key_modifier_state(event.xmotion.state); motion_event.mouse_motion.button_mask = get_mouse_button_state(event.xmotion.state); motion_event.mouse_motion.x=pos.x; @@ -1392,23 +1392,23 @@ void OS_X11::process_xevents() { motion_event.mouse_motion.relative_x=rel.x; motion_event.mouse_motion.relative_y=rel.y; - + last_mouse_pos=pos; // printf("rel: %d,%d\n", rel.x, rel.y ); - + input->parse_input_event( motion_event); - - } break; - case KeyPress: + + } break; + case KeyPress: case KeyRelease: { last_timestamp=event.xkey.time; - + // key event is a little complex, so // it will be handled in it's own function. handle_key_event( (XKeyEvent*)&event ); - } break; + } break; case SelectionRequest: { XSelectionRequestEvent *req; @@ -1455,8 +1455,8 @@ void OS_X11::process_xevents() { } break; - case ClientMessage: - + case ClientMessage: + if ((unsigned int)event.xclient.data.l[0]==(unsigned int)wm_delete) main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST); break; @@ -1464,7 +1464,7 @@ void OS_X11::process_xevents() { break; } } - + XFlush(x11_display); if (do_mouse_warp) { @@ -1472,7 +1472,7 @@ void OS_X11::process_xevents() { XWarpPointer(x11_display, None, x11_window, 0,0,0,0, (int)current_videomode.width/2, (int)current_videomode.height/2); - /* + /* Window root, child; int root_x, root_y; int win_x, win_y; @@ -1753,19 +1753,19 @@ void OS_X11::set_icon(const Image& p_icon) { void OS_X11::run() { force_quit = false; - + if (!main_loop) return; - + main_loop->init(); - + // uint64_t last_ticks=get_ticks_usec(); - + // int frames=0; // uint64_t frame=0; - + while (!force_quit) { - + process_xevents(); // get rid of pending events #ifdef JOYDEV_ENABLED event_id = joystick->process_joysticks(event_id); @@ -1773,7 +1773,7 @@ void OS_X11::run() { if (Main::iteration()==true) break; }; - + main_loop->finish(); } diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 0891e4b8eb..d9a5b1688c 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -78,7 +78,7 @@ class OS_X11 : public OS_Unix { VideoMode current_videomode; List<String> args; Window x11_window; - MainLoop *main_loop; + MainLoop *main_loop; ::Display* x11_display; char *xmbstring; int xmblen; @@ -93,7 +93,7 @@ class OS_X11 : public OS_Unix { uint64_t last_click_ms; unsigned int event_id; uint32_t last_button_state; - + PhysicsServer *physics_server; unsigned int get_mouse_button_state(unsigned int p_x11_state); InputModifierState get_key_modifier_state(unsigned int p_x11_state); @@ -101,7 +101,7 @@ class OS_X11 : public OS_Unix { MouseMode mouse_mode; Point2i center; - + void handle_key_event(XKeyEvent *p_event,bool p_echo=false); void process_xevents(); virtual void delete_main_loop(); @@ -154,16 +154,16 @@ class OS_X11 : public OS_Unix { protected: virtual int get_video_driver_count() const; - virtual const char * get_video_driver_name(int p_driver) const; + virtual const char * get_video_driver_name(int p_driver) const; virtual VideoMode get_default_video_mode() const; virtual int get_audio_driver_count() const; virtual const char * get_audio_driver_name(int p_driver) const; - virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); + virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); virtual void finalize(); - virtual void set_main_loop( MainLoop * p_main_loop ); + virtual void set_main_loop( MainLoop * p_main_loop ); public: @@ -183,7 +183,7 @@ public: virtual void set_icon(const Image& p_icon); virtual MainLoop *get_main_loop() const; - + virtual bool can_draw() const; virtual void set_clipboard(const String& p_text); diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index 3c51bbf220..22e5bc382a 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -103,7 +103,7 @@ public: bool is_v_drag_enabled() const; void set_drag_margin(Margin p_margin,float p_drag_margin); - float get_drag_margin(Margin p_margin) const; + float get_drag_margin(Margin p_margin) const; void set_v_offset(float p_offset); float get_v_offset() const; diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 316097fbcf..483feea5c4 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -233,7 +233,7 @@ bool CanvasItem::is_visible() const { const CanvasItem *p=this; - while(p) { + while(p) { if (p->hidden) return false; p=p->get_parent_item(); @@ -310,11 +310,11 @@ void CanvasItem::hide() { } void CanvasItem::set_hidden(bool p_hidden) { - + if (hidden == p_hidden) { return; } - + _set_visible_(!p_hidden); } @@ -1209,7 +1209,7 @@ CanvasItem::CanvasItem() : xform_change(this) { pending_update=false; opacity=1; self_opacity=1; - toplevel=false; + toplevel=false; pending_children_sort=false; first_draw=false; blend_mode=BLEND_MODE_MIX; diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index 3a45b0c84e..b5a6cc435f 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -261,7 +261,7 @@ void CollisionObject2D::add_shape(const Ref<Shape2D>& p_shape, const Matrix32& p else Physics2DServer::get_singleton()->body_add_shape(get_rid(),p_shape->get_rid(),p_transform); - shapes.push_back(sdata); + shapes.push_back(sdata); } int CollisionObject2D::get_shape_count() const { diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 5b13c32d93..ffea060e82 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -504,7 +504,7 @@ void Particles2D::_notification(int p_what) { invxform=get_global_transform().affine_inverse(); int start_particle = (int)(time * (float)particle_count / lifetime); - + for (int id=0;id<particle_count;++id) { int i = start_particle + id; if (i >= particle_count) { @@ -645,7 +645,7 @@ static const char* _particlesframe_property_rnames[Particles2D::PARAM_MAX]={ "randomness/gravity_strength", "randomness/radial_accel", "randomness/tangential_accel", - "randomness/damping", + "randomness/damping", "randomness/initial_angle", "randomness/initial_size", "randomness/final_size", diff --git a/scene/2d/particles_2d.h b/scene/2d/particles_2d.h index 101395589e..06dcda7165 100644 --- a/scene/2d/particles_2d.h +++ b/scene/2d/particles_2d.h @@ -88,7 +88,7 @@ public: enum Parameter { PARAM_DIRECTION, PARAM_SPREAD, - PARAM_LINEAR_VELOCITY, + PARAM_LINEAR_VELOCITY, PARAM_SPIN_VELOCITY, PARAM_ORBIT_VELOCITY, PARAM_GRAVITY_DIRECTION, @@ -150,7 +150,7 @@ private: Point2 emissor_offset; Vector2 initial_velocity; Vector2 extents; - DVector<Vector2> emission_points; + DVector<Vector2> emission_points; float time; int active_count; diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 1cd6399962..34a67c088f 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -454,7 +454,7 @@ void TileMap::_update_dirty_quadrants() { shape->draw(debug_canvas_item,debug_collision_color); } - ps->body_add_shape(q.body,shape->get_rid(),xform); + ps->body_add_shape(q.body,shape->get_rid(),xform); ps->body_set_shape_metadata(q.body,shape_idx++,Vector2(E->key().x,E->key().y)); } diff --git a/scene/3d/baked_light_instance.cpp b/scene/3d/baked_light_instance.cpp index 1ae7866f0b..4487415030 100644 --- a/scene/3d/baked_light_instance.cpp +++ b/scene/3d/baked_light_instance.cpp @@ -13,7 +13,7 @@ RID BakedLightInstance::get_baked_light_instance() const { void BakedLightInstance::set_baked_light(const Ref<BakedLight>& p_baked_light) { - baked_light=p_baked_light; + baked_light=p_baked_light; RID base_rid; diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index 01163e40e8..e76c0938fb 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -56,8 +56,8 @@ void Camera::_update_camera_mode() { } break; case PROJECTION_ORTHOGONAL: { set_orthogonal(size,near,far); - } break; - + } break; + } } @@ -81,7 +81,7 @@ bool Camera::_set(const StringName& p_name, const Variant& p_value) { else if (p_name=="near") near=p_value; else if (p_name=="far") - far=p_value; + far=p_value; else if (p_name=="keep_aspect") set_keep_aspect_mode(KeepAspect(int(p_value))); else if (p_name=="vaspect") @@ -102,7 +102,7 @@ bool Camera::_set(const StringName& p_name, const Variant& p_value) { set_environment(p_value); } else return false; - + _update_camera_mode(); if (changed_all) _change_notify(); @@ -147,21 +147,21 @@ bool Camera::_get(const StringName& p_name,Variant &r_ret) const { void Camera::_get_property_list( List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::INT, "projection", PROPERTY_HINT_ENUM, "Perspective,Orthogonal") ); - + switch(mode) { - + case PROJECTION_PERSPECTIVE: { - + p_list->push_back( PropertyInfo( Variant::REAL, "fov" , PROPERTY_HINT_RANGE, "1,179,0.1",PROPERTY_USAGE_NOEDITOR) ); if (keep_aspect==KEEP_WIDTH) p_list->push_back( PropertyInfo( Variant::REAL, "fovx" , PROPERTY_HINT_RANGE, "1,179,0.1",PROPERTY_USAGE_EDITOR) ); else p_list->push_back( PropertyInfo( Variant::REAL, "fovy" , PROPERTY_HINT_RANGE, "1,179,0.1",PROPERTY_USAGE_EDITOR) ); - + } break; case PROJECTION_ORTHOGONAL: { - + p_list->push_back( PropertyInfo( Variant::REAL, "size" , PROPERTY_HINT_RANGE, "1,16384,0.01",PROPERTY_USAGE_NOEDITOR ) ); if (keep_aspect==KEEP_WIDTH) p_list->push_back( PropertyInfo( Variant::REAL, "sizex" , PROPERTY_HINT_RANGE, "0.1,16384,0.01",PROPERTY_USAGE_EDITOR) ); @@ -169,9 +169,9 @@ void Camera::_get_property_list( List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::REAL, "sizey" , PROPERTY_HINT_RANGE, "0.1,16384,0.01",PROPERTY_USAGE_EDITOR) ); } break; - + } - + p_list->push_back( PropertyInfo( Variant::REAL, "near" , PROPERTY_HINT_EXP_RANGE, "0.01,4096.0,0.01") ); p_list->push_back( PropertyInfo( Variant::REAL, "far" , PROPERTY_HINT_EXP_RANGE, "0.01,4096.0,0.01") ); p_list->push_back( PropertyInfo( Variant::INT, "keep_aspect",PROPERTY_HINT_ENUM,"Keep Width,Keep Height") ); @@ -209,7 +209,7 @@ void Camera::_update_camera() { void Camera::_notification(int p_what) { switch(p_what) { - + case NOTIFICATION_ENTER_WORLD: { @@ -218,13 +218,13 @@ void Camera::_notification(int p_what) { make_current(); - } break; + } break; case NOTIFICATION_TRANSFORM_CHANGED: { - + _request_camera_update(); } break; case NOTIFICATION_EXIT_WORLD: { - + if (!get_tree()->is_node_being_edited(this)) { if (is_current()) { clear_current(); @@ -250,7 +250,7 @@ void Camera::_notification(int p_what) { } } break; - + } } @@ -270,7 +270,7 @@ void Camera::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far near=p_z_near; far=p_z_far; mode=PROJECTION_PERSPECTIVE; - + VisualServer::get_singleton()->camera_set_perspective(camera,fov,near,far); update_gizmo(); force_change=false; @@ -281,12 +281,12 @@ void Camera::set_orthogonal(float p_size, float p_z_near, float p_z_far) { return; size = p_size; - + near=p_z_near; far=p_z_far; mode=PROJECTION_ORTHOGONAL; force_change=false; - + VisualServer::get_singleton()->camera_set_orthogonal(camera,size,near,far); update_gizmo(); } diff --git a/scene/3d/camera.h b/scene/3d/camera.h index 02ca6ffb9a..30c6928245 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera.h @@ -41,7 +41,7 @@ class Camera : public Spatial { OBJ_TYPE( Camera, Spatial ); public: enum Projection { - + PROJECTION_PERSPECTIVE, PROJECTION_ORTHOGONAL }; @@ -57,14 +57,14 @@ private: bool current; Projection mode; - + float fov; float size; float near,far; float v_offset; float h_offset; KeepAspect keep_aspect; - + RID camera; RID scenario_id; @@ -86,14 +86,14 @@ protected: void _update_camera(); virtual void _request_camera_update(); void _update_camera_mode(); - + bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; void _notification(int p_what); - + static void _bind_methods(); - + public: enum { @@ -104,7 +104,7 @@ public: void set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far); void set_orthogonal(float p_size, float p_z_near, float p_z_far); - + void make_current(); void clear_current(); bool is_current() const; @@ -145,7 +145,7 @@ public: float get_h_offset() const; - Camera(); + Camera(); ~Camera(); }; diff --git a/scene/3d/character_camera.cpp b/scene/3d/character_camera.cpp index 2b22026fe9..fc3dfcd645 100644 --- a/scene/3d/character_camera.cpp +++ b/scene/3d/character_camera.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "character_camera.h" - + #include "physics_body.h" #if 0 void CharacterCamera::_set(const String& p_name, const Variant& p_value) { diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index 18463742c6..227bb3a59d 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "light.h" - + #include "globals.h" #include "scene/resources/surface_tool.h" @@ -86,7 +86,7 @@ void Light::set_project_shadows(bool p_enabled) { _change_notify("shadow"); } bool Light::has_project_shadows() const { - + return shadows; } @@ -175,9 +175,9 @@ RES Light::_get_gizmo_geometry() const { Ref< Mesh > mesh; Ref<SurfaceTool> surftool( memnew( SurfaceTool )); - + switch(type) { - + case VisualServer::LIGHT_DIRECTIONAL: { @@ -260,9 +260,9 @@ RES Light::_get_gizmo_geometry() const { surftool->set_material(mat_light); mesh=surftool->commit(mesh); } break; - + case VisualServer::LIGHT_SPOT: { - + _make_sphere( 5,5,0.1, surftool ); surftool->set_material(mat_light); mesh=surftool->commit(mesh); @@ -273,14 +273,14 @@ RES Light::_get_gizmo_geometry() const { float size=Math::tan(Math::deg2rad(vars[PARAM_SPOT_ANGLE]))*len; surftool->begin(Mesh::PRIMITIVE_TRIANGLES); - + for(int i = 0; i < points; i++) { - + float x0=Math::sin(i * Math_PI * 2 / points); float y0=Math::cos(i * Math_PI * 2 / points); float x1=Math::sin((i+1) * Math_PI * 2 / points); float y1=Math::cos((i+1) * Math_PI * 2 / points); - + Vector3 v1=Vector3(x0*size,y0*size,-len).normalized()*len; Vector3 v2=Vector3(x1*size,y1*size,-len).normalized()*len; @@ -288,7 +288,7 @@ RES Light::_get_gizmo_geometry() const { Vector3 v4=Vector3(0,0,v1.z); Vector3 n = Plane(v1,v2,v3).normal; - + surftool->add_normal(n); surftool->add_vertex(v1); @@ -306,7 +306,7 @@ RES Light::_get_gizmo_geometry() const { surftool->add_normal(n); surftool->add_vertex(v4); - + } surftool->set_material(mat_area); @@ -323,15 +323,15 @@ RES Light::_get_gizmo_geometry() const { AABB Light::get_aabb() const { if (type==VisualServer::LIGHT_DIRECTIONAL) { - - return AABB( Vector3(-1,-1,-1), Vector3(2, 2, 2 ) ); - + + return AABB( Vector3(-1,-1,-1), Vector3(2, 2, 2 ) ); + } else if (type==VisualServer::LIGHT_OMNI) { - + return AABB( Vector3(-1,-1,-1) * vars[PARAM_RADIUS], Vector3(2, 2, 2 ) * vars[PARAM_RADIUS]); - + } else if (type==VisualServer::LIGHT_SPOT) { - + float len=vars[PARAM_RADIUS]; float size=Math::tan(Math::deg2rad(vars[PARAM_SPOT_ANGLE]))*len; return AABB( Vector3( -size,-size,-len ), Vector3( size*2, size*2, len ) ); @@ -542,7 +542,7 @@ void Light::_bind_methods() { BIND_CONSTANT( COLOR_DIFFUSE ); - BIND_CONSTANT( COLOR_SPECULAR ); + BIND_CONSTANT( COLOR_SPECULAR ); BIND_CONSTANT( BAKE_MODE_DISABLED ); BIND_CONSTANT( BAKE_MODE_INDIRECT ); diff --git a/scene/3d/light.h b/scene/3d/light.h index b74085b7a9..b25c6a44b5 100644 --- a/scene/3d/light.h +++ b/scene/3d/light.h @@ -43,7 +43,7 @@ class Light : public VisualInstance { OBJ_CATEGORY("3D Light Nodes"); public: - + enum Parameter { PARAM_RADIUS=VisualServer::LIGHT_PARAM_RADIUS, PARAM_ENERGY=VisualServer::LIGHT_PARAM_ENERGY, @@ -57,10 +57,10 @@ public: PARAM_SHADOW_BLUR_PASSES=VisualServer::LIGHT_PARAM_SHADOW_BLUR_PASSES, PARAM_MAX=VisualServer::LIGHT_PARAM_MAX }; - - + + enum LightColor { - + COLOR_DIFFUSE=VisualServer::LIGHT_COLOR_DIFFUSE, COLOR_SPECULAR=VisualServer::LIGHT_COLOR_SPECULAR }; @@ -81,13 +81,13 @@ public: OPERATOR_SUB }; private: - - + + Ref<Texture> projector; float vars[PARAM_MAX]; Color colors[3]; - - + + BakeMode bake_mode; VisualServer::LightType type; bool shadows; @@ -98,18 +98,18 @@ private: void _update_visibility(); // bind helpers -protected: +protected: RID light; virtual bool _can_gizmo_scale() const; virtual RES _get_gizmo_geometry() const; - + static void _bind_methods(); void _notification(int p_what); - - Light(VisualServer::LightType p_type); + + Light(VisualServer::LightType p_type); public: VS::LightType get_light_type() const { return type; } diff --git a/scene/3d/mesh_instance.cpp b/scene/3d/mesh_instance.cpp index 997d2dea7c..cfe273fa20 100644 --- a/scene/3d/mesh_instance.cpp +++ b/scene/3d/mesh_instance.cpp @@ -139,7 +139,7 @@ AABB MeshInstance::get_aabb() const { if (!mesh.is_null()) return mesh->get_aabb(); - + return AABB(); } @@ -150,7 +150,7 @@ DVector<Face3> MeshInstance::get_faces(uint32_t p_usage_flags) const { if (mesh.is_null()) return DVector<Face3>(); - + return mesh->get_faces(); } @@ -177,7 +177,7 @@ void MeshInstance::create_trimesh_collision() { StaticBody* static_body = create_trimesh_collision_node()->cast_to<StaticBody>(); ERR_FAIL_COND(!static_body); static_body->set_name( String(get_name()) + "_col" ); - + add_child(static_body); if (get_owner()) static_body->set_owner( get_owner() ); @@ -233,7 +233,7 @@ void MeshInstance::_notification(int p_what) { void MeshInstance::_bind_methods() { - + ObjectTypeDB::bind_method(_MD("set_mesh","mesh:Mesh"),&MeshInstance::set_mesh); ObjectTypeDB::bind_method(_MD("get_mesh:Mesh"),&MeshInstance::get_mesh); ObjectTypeDB::bind_method(_MD("set_skeleton_path","skeleton_path:NodePath"),&MeshInstance::set_skeleton_path); diff --git a/scene/3d/mesh_instance.h b/scene/3d/mesh_instance.h index f26ef52000..7c605c2d6d 100644 --- a/scene/3d/mesh_instance.h +++ b/scene/3d/mesh_instance.h @@ -38,7 +38,7 @@ class MeshInstance : public GeometryInstance { OBJ_TYPE( MeshInstance, GeometryInstance ); - + Ref<Mesh> mesh; NodePath skeleton_path; @@ -68,7 +68,7 @@ public: void set_skeleton_path(const NodePath& p_skeleton); NodePath get_skeleton_path(); - + Node* create_trimesh_collision_node(); void create_trimesh_collision(); @@ -78,7 +78,7 @@ public: virtual AABB get_aabb() const; virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const; - MeshInstance(); + MeshInstance(); ~MeshInstance(); }; diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp index ce28350be0..186f0d8e00 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation.cpp @@ -455,7 +455,7 @@ Vector<Vector3> Navigation::get_simple_path(const Vector3& p_start, const Vector _clip_path(path,apex_poly,portal_right,right_poly); - apex_point=portal_right; + apex_point=portal_right; p=right_poly; left_poly=p; apex_poly=p; diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp index 47662bcccb..3ac5d8ed7b 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/particles.cpp @@ -100,10 +100,10 @@ void Particles::set_amount(int p_amount) { VisualServer::get_singleton()->particles_set_amount(particles,p_amount); } int Particles::get_amount() const { - + return amount; } - + void Particles::set_emitting(bool p_emitting) { emitting=p_emitting; @@ -115,19 +115,19 @@ bool Particles::is_emitting() const { return emitting; } - + void Particles::set_visibility_aabb(const AABB& p_aabb) { visibility_aabb=p_aabb; VisualServer::get_singleton()->particles_set_visibility_aabb(particles,p_aabb); update_gizmo(); - + } AABB Particles::get_visibility_aabb() const { return visibility_aabb; } - + void Particles::set_emission_points(const DVector<Vector3>& p_points) { @@ -179,7 +179,7 @@ Vector3 Particles::get_gravity_normal() const { return gravity_normal; } - + void Particles::set_variable(Variable p_variable,float p_value) { ERR_FAIL_INDEX(p_variable,VAR_MAX); @@ -273,7 +273,7 @@ float Particles::get_emit_timeout() const { Ref<Material> Particles::get_material() const { return material; -} +} void Particles::set_height_from_velocity(bool p_enable) { @@ -507,11 +507,11 @@ Particles::Particles() { set_amount(64); set_emitting(true); set_visibility_aabb(AABB( Vector3(-4,-4,-4), Vector3(8,8,8) ) ); - + for (int i=0;i<VAR_MAX;i++) { set_randomness((Variable)i,0.0); } - + set_variable( VAR_LIFETIME, 5.0); set_variable( VAR_SPREAD, 0.2); set_variable( VAR_GRAVITY, 9.8); @@ -523,7 +523,7 @@ Particles::Particles() { set_variable( VAR_DAMPING, 0.0); set_variable( VAR_INITIAL_SIZE, 1.0); set_variable( VAR_FINAL_SIZE, 1.0); - set_variable( VAR_INITIAL_ANGLE, 0.0); + set_variable( VAR_INITIAL_ANGLE, 0.0); set_variable( VAR_HEIGHT, 1.0); set_variable( VAR_HEIGHT_SPEED_SCALE, 0.0); diff --git a/scene/3d/particles.h b/scene/3d/particles.h index b9cae332e2..42d27c41d7 100644 --- a/scene/3d/particles.h +++ b/scene/3d/particles.h @@ -63,7 +63,7 @@ private: OBJ_TYPE( Particles, GeometryInstance ); RID particles; - + int amount; bool emitting; float emit_timeout; @@ -71,14 +71,14 @@ private: Vector3 gravity_normal; Vector3 emission_half_extents; bool using_points; - float var[VAR_MAX]; - float var_random[VAR_MAX]; + float var[VAR_MAX]; + float var_random[VAR_MAX]; bool height_from_velocity; Vector3 emission_base_velocity; bool local_coordinates; - + struct ColorPhase { - + Color color; float pos; }; @@ -87,18 +87,18 @@ private: virtual RES _get_gizmo_geometry() const; int color_phase_count; - + ColorPhase color_phase[4]; - + Ref<Material> material; Timer* timer; void setup_timer(); -protected: - +protected: + static void _bind_methods(); - + public: @@ -107,13 +107,13 @@ public: void set_amount(int p_amount); int get_amount() const; - + void set_emitting(bool p_emitting); bool is_emitting() const; - + void set_visibility_aabb(const AABB& p_aabb); AABB get_visibility_aabb() const; - + void set_emission_half_extents(const Vector3& p_half_extents); Vector3 get_emission_half_extents() const; @@ -125,25 +125,25 @@ public: void set_gravity_normal(const Vector3& p_normal); Vector3 get_gravity_normal() const; - + void set_variable(Variable p_variable,float p_value); float get_variable(Variable p_variable) const; - + void set_randomness(Variable p_variable,float p_randomness); float get_randomness(Variable p_variable) const; void set_color_phases(int p_phases); int get_color_phases() const; - + void set_color_phase_pos(int p_phase, float p_pos); float get_color_phase_pos(int p_phase) const; - + void set_color_phase_color(int p_phase, const Color& p_color); Color get_color_phase_color(int p_phase) const; void set_height_from_velocity(bool p_enable); bool has_height_from_velocity() const; - + void set_material(const Ref<Material>& p_material); Ref<Material> get_material() const; @@ -156,7 +156,7 @@ public: void start_emitting(float p_time); - Particles(); + Particles(); ~Particles(); }; diff --git a/scene/3d/portal.cpp b/scene/3d/portal.cpp index 84f94402d5..23bc64615d 100644 --- a/scene/3d/portal.cpp +++ b/scene/3d/portal.cpp @@ -40,7 +40,7 @@ bool Portal::_set(const StringName& p_name, const Variant& p_value) { ERR_FAIL_COND_V(src_coords_size%2,false); points.resize(src_coords_size/2); for (int i=0;i<points.size();i++) { - + points[i].x=src_coords[i*2+0]; points[i].y=src_coords[i*2+1]; set_shape(points); @@ -65,13 +65,13 @@ bool Portal::_get(const StringName& p_name,Variant &r_ret) const { Vector<Point2> points=get_shape(); DVector<float> dst_coords; dst_coords.resize(points.size()*2); - + for (int i=0;i<points.size();i++) { - + dst_coords.set(i*2+0,points[i].x); dst_coords.set(i*2+1,points[i].y); } - + r_ret= dst_coords; } else if (p_name=="enabled") { r_ret= is_enabled(); @@ -115,17 +115,17 @@ RES Portal::_get_gizmo_geometry() const { Vector2 center; for (int i=0;i<shape.size();i++) { - + int n=(i+1)%shape.size(); Vector<Vector3> points; surface_tool->add_vertex( Vector3( shape[i].x, shape[i].y,0 )); surface_tool->add_vertex( Vector3( shape[n].x, shape[n].y,0 )); center+=shape[i]; - + } if (shape.size()>0) { - + center/=shape.size(); Vector<Vector3> points; surface_tool->add_vertex( Vector3( center.x, center.y,0 )); @@ -139,7 +139,7 @@ RES Portal::_get_gizmo_geometry() const { AABB Portal::get_aabb() const { - return aabb; + return aabb; } DVector<Face3> Portal::get_faces(uint32_t p_usage_flags) const { @@ -149,28 +149,28 @@ DVector<Face3> Portal::get_faces(uint32_t p_usage_flags) const { Vector<Point2> shape = get_shape(); if (shape.size()==0) return DVector<Face3>(); - + Vector2 center; for (int i=0;i<shape.size();i++) { - + center+=shape[i]; - + } - + DVector<Face3> ret; center/=shape.size(); for (int i=0;i<shape.size();i++) { int n=(i+1)%shape.size(); - + Face3 f; f.vertex[0]=Vector3( center.x, center.y, 0 ); f.vertex[1]=Vector3( shape[i].x, shape[i].y, 0 ); f.vertex[2]=Vector3( shape[n].x, shape[n].y, 0 ); ret.push_back(f); } - + return ret; } diff --git a/scene/3d/portal.h b/scene/3d/portal.h index 388eac4dd3..149a56900f 100644 --- a/scene/3d/portal.h +++ b/scene/3d/portal.h @@ -45,14 +45,14 @@ class Portal : public VisualInstance { OBJ_TYPE(Portal, VisualInstance); - + RID portal; - + bool enabled; float disable_distance; Color disabled_color; float connect_range; - + AABB aabb; virtual RES _get_gizmo_geometry() const; @@ -62,9 +62,9 @@ protected: bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; - + static void _bind_methods(); - + public: virtual AABB get_aabb() const; diff --git a/scene/3d/room_instance.cpp b/scene/3d/room_instance.cpp index e358da136b..9e6867d2a2 100644 --- a/scene/3d/room_instance.cpp +++ b/scene/3d/room_instance.cpp @@ -29,7 +29,7 @@ #include "room_instance.h" #include "servers/visual_server.h" - + #include "geometry.h" #include "globals.h" #include "scene/resources/surface_tool.h" diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp index 64133f67b5..d0b739e17f 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "skeleton.h" - + #include "message_queue.h" #include "scene/resources/surface_tool.h" @@ -40,19 +40,19 @@ bool Skeleton::_set(const StringName& p_path, const Variant& p_value) { if (!path.begins_with("bones/")) return false; - + int which=path.get_slicec('/',1).to_int(); String what=path.get_slicec('/',2); if (which==bones.size() && what=="name") { - + add_bone(p_value); return true; } - + ERR_FAIL_INDEX_V( which, bones.size(), false ); - + if (what=="parent") set_bone_parent(which, p_value ); else if (what=="rest") @@ -63,11 +63,11 @@ bool Skeleton::_set(const StringName& p_path, const Variant& p_value) { set_bone_pose(which, p_value); else if (what=="bound_childs") { Array children=p_value; - + bones[which].nodes_bound.clear(); - + for (int i=0;i<children.size();i++) { - + NodePath path=children[i]; ERR_CONTINUE( path.operator String()=="" ); Node *node = get_node(path); @@ -87,12 +87,12 @@ bool Skeleton::_get(const StringName& p_name,Variant &r_ret) const { if (!path.begins_with("bones/")) return false; - + int which=path.get_slicec('/',1).to_int(); String what=path.get_slicec('/',2); - + ERR_FAIL_INDEX_V( which, bones.size(), false ); - + if (what=="name") r_ret=get_bone_name(which); else if (what=="parent") @@ -105,29 +105,29 @@ bool Skeleton::_get(const StringName& p_name,Variant &r_ret) const { r_ret=get_bone_pose(which); else if (what=="bound_childs") { Array children; - + for (const List<uint32_t>::Element *E=bones[which].nodes_bound.front();E;E=E->next()) { - + Object *obj=ObjectDB::get_instance(E->get()); ERR_CONTINUE(!obj); Node *node=obj->cast_to<Node>(); ERR_CONTINUE(!node); NodePath path=get_path_to(node); children.push_back(path); - + } - + r_ret=children; } else return false; - + return true; } void Skeleton::_get_property_list( List<PropertyInfo>* p_list ) const { for (int i=0;i<bones.size();i++) { - + String prep="bones/"+itos(i)+"/"; p_list->push_back( PropertyInfo( Variant::STRING, prep+"name" ) ); p_list->push_back( PropertyInfo( Variant::INT, prep+"parent" , PROPERTY_HINT_RANGE,"-1,"+itos(i-1)+",1") ); @@ -141,18 +141,18 @@ void Skeleton::_get_property_list( List<PropertyInfo>* p_list ) const { void Skeleton::_notification(int p_what) { switch(p_what) { - + case NOTIFICATION_ENTER_WORLD: { - + if (dirty) { - + dirty=false; _make_dirty(); // property make it dirty } - + } break; case NOTIFICATION_EXIT_WORLD: { - + } break; case NOTIFICATION_UPDATE_SKELETON: { @@ -178,15 +178,15 @@ void Skeleton::_notification(int p_what) { Bone &b=bonesptr[i]; b.rest_global_inverse.affine_invert(); } - + rest_global_inverse_dirty=false; } - + for (int i=0;i<len;i++) { - + Bone &b=bonesptr[i]; - + if (b.disable_rest) { if (b.enabled) { @@ -241,7 +241,7 @@ void Skeleton::_notification(int p_what) { } } } - + vs->skeleton_bone_set_transform( skeleton, i, b.pose_global * b.rest_global_inverse ); for(List<uint32_t>::Element *E=b.nodes_bound.front();E;E=E->next()) { @@ -255,7 +255,7 @@ void Skeleton::_notification(int p_what) { } dirty=false; - } break; + } break; } } @@ -298,16 +298,16 @@ RID Skeleton::get_skeleton() const { void Skeleton::add_bone(const String& p_name) { ERR_FAIL_COND( p_name=="" || p_name.find(":")!=-1 || p_name.find("/")!=-1 ); - + for (int i=0;i<bones.size();i++) { - + ERR_FAIL_COND( bones[i].name=="p_name"); } Bone b; b.name=p_name; bones.push_back(b); - + rest_global_inverse_dirty=true; _make_dirty(); update_gizmo(); @@ -315,11 +315,11 @@ void Skeleton::add_bone(const String& p_name) { int Skeleton::find_bone(String p_name) const { for (int i=0;i<bones.size();i++) { - + if (bones[i].name==p_name) return i; } - + return -1; } String Skeleton::get_bone_name(int p_bone) const { @@ -338,7 +338,7 @@ void Skeleton::set_bone_parent(int p_bone, int p_parent) { ERR_FAIL_INDEX( p_bone, bones.size() ); ERR_FAIL_COND( p_parent!=-1 && (p_parent<0 || p_parent>=p_bone)); - + bones[p_bone].parent=p_parent; rest_global_inverse_dirty=true; _make_dirty(); @@ -378,14 +378,14 @@ bool Skeleton::is_bone_rest_disabled(int p_bone) const { int Skeleton::get_bone_parent(int p_bone) const { ERR_FAIL_INDEX_V( p_bone, bones.size(), -1 ); - + return bones[p_bone].parent; } void Skeleton::set_bone_rest(int p_bone, const Transform& p_rest) { ERR_FAIL_INDEX( p_bone, bones.size() ); - + bones[p_bone].rest=p_rest; rest_global_inverse_dirty=true; _make_dirty(); @@ -394,7 +394,7 @@ void Skeleton::set_bone_rest(int p_bone, const Transform& p_rest) { Transform Skeleton::get_bone_rest(int p_bone) const { ERR_FAIL_INDEX_V( p_bone, bones.size(), Transform() ); - + return bones[p_bone].rest; } @@ -402,7 +402,7 @@ Transform Skeleton::get_bone_rest(int p_bone) const { void Skeleton::set_bone_enabled(int p_bone, bool p_enabled) { ERR_FAIL_INDEX( p_bone, bones.size() ); - + bones[p_bone].enabled=p_enabled; rest_global_inverse_dirty=true; _make_dirty(); @@ -418,23 +418,23 @@ void Skeleton::bind_child_node_to_bone(int p_bone,Node *p_node) { ERR_FAIL_NULL(p_node); ERR_FAIL_INDEX( p_bone, bones.size() ); - + uint32_t id=p_node->get_instance_ID(); - + for (List<uint32_t>::Element *E=bones[p_bone].nodes_bound.front();E;E=E->next()) { - + if (E->get()==id) return; // already here } - + bones[p_bone].nodes_bound.push_back(id); - + } void Skeleton::unbind_child_node_from_bone(int p_bone,Node *p_node) { ERR_FAIL_NULL(p_node); ERR_FAIL_INDEX( p_bone, bones.size() ); - + uint32_t id=p_node->get_instance_ID(); bones[p_bone].nodes_bound.erase(id); @@ -442,9 +442,9 @@ void Skeleton::unbind_child_node_from_bone(int p_bone,Node *p_node) { void Skeleton::get_bound_child_nodes_to_bone(int p_bone,List<Node*> *p_bound) const { ERR_FAIL_INDEX( p_bone, bones.size() ); - + for (const List<uint32_t>::Element *E=bones[p_bone].nodes_bound.front();E;E=E->next()) { - + Object *obj=ObjectDB::get_instance(E->get()); ERR_CONTINUE(!obj); p_bound->push_back(obj->cast_to<Node>()); @@ -465,7 +465,7 @@ void Skeleton::set_bone_pose(int p_bone, const Transform& p_pose) { ERR_FAIL_INDEX( p_bone, bones.size() ); ERR_FAIL_COND( !is_inside_tree() ); - + bones[p_bone].pose=p_pose; _make_dirty(); @@ -501,7 +501,7 @@ void Skeleton::_make_dirty() { if (dirty) return; - + if (!is_inside_tree()) { dirty=true; return; @@ -538,13 +538,13 @@ RES Skeleton::_get_gizmo_geometry() const { int len=bones.size(); for (int i=0;i<len;i++) { - + const Bone &b=bonesptr[i]; - + Transform t; if (b.parent<0) continue; - + Vector3 v1=(bonesptr[b.parent].pose_global * bonesptr[b.parent].rest_global_inverse).xform(bonesptr[b.parent].rest_global_inverse.affine_inverse().origin); Vector3 v2=(b.pose_global * b.rest_global_inverse).xform(b.rest_global_inverse.affine_inverse().origin); @@ -576,10 +576,10 @@ void Skeleton::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_bone","name"),&Skeleton::add_bone); ObjectTypeDB::bind_method(_MD("find_bone","name"),&Skeleton::find_bone); ObjectTypeDB::bind_method(_MD("get_bone_name","bone_idx"),&Skeleton::get_bone_name); - + ObjectTypeDB::bind_method(_MD("get_bone_parent","bone_idx"),&Skeleton::get_bone_parent); ObjectTypeDB::bind_method(_MD("set_bone_parent","bone_idx","parent_idx"),&Skeleton::set_bone_parent); - + ObjectTypeDB::bind_method(_MD("get_bone_count"),&Skeleton::get_bone_count); ObjectTypeDB::bind_method(_MD("unparent_bone_and_rest","bone_idx"),&Skeleton::unparent_bone_and_rest); @@ -593,9 +593,9 @@ void Skeleton::_bind_methods() { ObjectTypeDB::bind_method(_MD("bind_child_node_to_bone","bone_idx","node:Node"),&Skeleton::bind_child_node_to_bone); ObjectTypeDB::bind_method(_MD("unbind_child_node_from_bone","bone_idx","node:Node"),&Skeleton::unbind_child_node_from_bone); ObjectTypeDB::bind_method(_MD("get_bound_child_nodes_to_bone","bone_idx"),&Skeleton::_get_bound_child_nodes_to_bone); - + ObjectTypeDB::bind_method(_MD("clear_bones"),&Skeleton::clear_bones); - + ObjectTypeDB::bind_method(_MD("get_bone_pose","bone_idx"),&Skeleton::get_bone_pose); ObjectTypeDB::bind_method(_MD("set_bone_pose","bone_idx","pose"),&Skeleton::set_bone_pose); diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton.h index 033f212a58..bfdb1d1499 100644 --- a/scene/3d/skeleton.h +++ b/scene/3d/skeleton.h @@ -49,36 +49,36 @@ class Skeleton : public Spatial { bool disable_rest; Transform rest; Transform rest_global_inverse; - + Transform pose; Transform pose_global; bool custom_pose_enable; Transform custom_pose; - + List<uint32_t> nodes_bound; - + Bone() { parent=-1; enabled=true; custom_pose_enable=false; disable_rest=false; } }; bool rest_global_inverse_dirty; Vector<Bone> bones; - + RID skeleton; - + void _make_dirty(); bool dirty; - + //bind helpers Array _get_bound_child_nodes_to_bone(int p_bone) const { - + Array bound; List<Node*> childs; get_bound_child_nodes_to_bone(p_bone,&childs); - + for (int i=0;i<childs.size();i++) { - + bound.push_back( childs[i] ); } return bound; @@ -93,11 +93,11 @@ protected: void _get_property_list( List<PropertyInfo>* p_list ) const; void _notification(int p_what); static void _bind_methods(); - + public: enum { - + NOTIFICATION_UPDATE_SKELETON=50 }; @@ -108,7 +108,7 @@ public: void add_bone(const String&p_name); int find_bone(String p_name) const; String get_bone_name(int p_bone) const; - + void set_bone_parent(int p_bone, int p_parent); int get_bone_parent(int p_bone) const; @@ -118,7 +118,7 @@ public: bool is_bone_rest_disabled(int p_bone) const; int get_bone_count() const; - + void set_bone_rest(int p_bone, const Transform& p_rest); Transform get_bone_rest(int p_bone) const; Transform get_bone_transform(int p_bone) const; @@ -128,15 +128,15 @@ public: void set_bone_enabled(int p_bone, bool p_enabled); bool is_bone_enabled(int p_bone) const; - + void bind_child_node_to_bone(int p_bone,Node *p_node); void unbind_child_node_from_bone(int p_bone,Node *p_node); void get_bound_child_nodes_to_bone(int p_bone,List<Node*> *p_bound) const; - + void clear_bones(); - + // posing api - + void set_bone_pose(int p_bone, const Transform& p_pose); Transform get_bone_pose(int p_bone) const; @@ -144,8 +144,8 @@ public: Transform get_bone_custom_pose(int p_bone) const; void localize_rests(); // used for loaders and tools - - Skeleton(); + + Skeleton(); ~Skeleton(); }; diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index 0c1e1e2d1c..c2d318e8a7 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "spatial.h" - + #include "scene/main/viewport.h" #include "message_queue.h" #include "scene/scene_string_names.h" @@ -99,14 +99,14 @@ void Spatial::_propagate_transform_changed(Spatial *p_origin) { // return; //already dirty data.children_lock++; - + for (List<Spatial*>::Element *E=data.children.front();E;E=E->next()) { - + if (E->get()->data.toplevel_active) continue; //don't propagate to a toplevel E->get()->_propagate_transform_changed(p_origin); } - + if (!data.ignore_notification && !xform_change.in_list()) { @@ -211,14 +211,14 @@ void Spatial::_notification(int p_what) { case NOTIFICATION_TRANSFORM_CHANGED: { - + #ifdef TOOLS_ENABLED if (data.gizmo.is_valid()) { data.gizmo->transform(); } #endif } break; - + default: {} } } @@ -257,7 +257,7 @@ Transform Spatial::get_transform() const { _update_local_transform(); } - + return data.local_transform; } Transform Spatial::get_global_transform() const { @@ -272,16 +272,16 @@ Transform Spatial::get_global_transform() const { } if (data.parent && !data.toplevel_active) { - + data.global_transform=data.parent->get_global_transform() * data.local_transform; } else { - + data.global_transform=data.local_transform; } - + data.dirty&=~DIRTY_GLOBAL; } - + return data.global_transform; } #if 0 @@ -290,7 +290,7 @@ void Spatial::add_child_notify(Node *p_child) { Spatial *s=p_child->cast_to<Spatial>(); if (!s) return; - + ERR_FAIL_COND(data.children_lock>0); s->data.dirty=DIRTY_GLOBAL; // don't allow global transform to be valid @@ -305,12 +305,12 @@ void Spatial::remove_child_notify(Node *p_child) { Spatial *s=p_child->cast_to<Spatial>(); if (!s) return; - + ERR_FAIL_COND(data.children_lock>0); - + if (s->data.C) data.children.erase(s->data.C); - s->data.parent=NULL; + s->data.parent=NULL; s->data.C=NULL; */ } @@ -595,11 +595,11 @@ bool Spatial::is_hidden() const{ } void Spatial::set_hidden(bool p_hidden) { - + if (data.visible != p_hidden) { return; } - + _set_visible_(!p_hidden); } diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index 23f1c6d103..50123b2d81 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -57,7 +57,7 @@ class Spatial : public Node { OBJ_TYPE( Spatial, Node ); OBJ_CATEGORY("3D"); - + enum TransformDirty { DIRTY_NONE=0, DIRTY_VECTORS=1, @@ -68,7 +68,7 @@ class Spatial : public Node { mutable SelfList<Node> xform_change; struct Data { - + mutable Transform global_transform; @@ -84,12 +84,12 @@ class Spatial : public Node { bool toplevel_active; bool toplevel; bool inside_world; - + int children_lock; Spatial *parent; List<Spatial*> children; List<Spatial*>::Element *C; - + bool ignore_notification; bool notify_local_transform; @@ -130,7 +130,7 @@ protected: public: enum { - + NOTIFICATION_TRANSFORM_CHANGED=SceneTree::NOTIFICATION_TRANSFORM_CHANGED, NOTIFICATION_ENTER_WORLD=41, NOTIFICATION_EXIT_WORLD=42, @@ -153,7 +153,7 @@ public: void set_transform(const Transform& p_transform); void set_global_transform(const Transform& p_transform); - + Transform get_transform() const; Transform get_global_transform() const; @@ -198,7 +198,7 @@ public: Transform get_import_transform() const; #endif - Spatial(); + Spatial(); ~Spatial(); }; diff --git a/scene/3d/spatial_sample_player.h b/scene/3d/spatial_sample_player.h index 9b3220458e..037cdc906a 100644 --- a/scene/3d/spatial_sample_player.h +++ b/scene/3d/spatial_sample_player.h @@ -47,7 +47,7 @@ public: typedef int VoiceID; -private: +private: Ref<SampleLibrary> library; int polyphony; diff --git a/scene/3d/test_cube.h b/scene/3d/test_cube.h index 21f2b3c794..332276ab89 100644 --- a/scene/3d/test_cube.h +++ b/scene/3d/test_cube.h @@ -42,14 +42,14 @@ class TestCube : public GeometryInstance { OBJ_TYPE( TestCube, GeometryInstance ); RID instance; - + public: virtual AABB get_aabb() const; virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const; - TestCube(); + TestCube(); ~TestCube(); }; diff --git a/scene/3d/visual_instance.h b/scene/3d/visual_instance.h index 2b8292261b..e286d5fa88 100644 --- a/scene/3d/visual_instance.h +++ b/scene/3d/visual_instance.h @@ -65,7 +65,7 @@ public: RID get_instance() const; virtual AABB get_aabb() const=0; virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const=0; - + virtual AABB get_transformed_aabb() const; // helper void set_base(const RID& p_base); @@ -74,7 +74,7 @@ public: uint32_t get_layer_mask() const; - VisualInstance(); + VisualInstance(); ~VisualInstance(); }; diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 0bc54b3d43..32958112e5 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "animation_player.h" - + #include "message_queue.h" #include "scene/scene_string_names.h" @@ -50,10 +50,10 @@ bool AnimationPlayer::_set(const StringName& p_name, const Variant& p_value) { else play(which); } else if (name.begins_with("anims/")) { - + String which=name.get_slicec('/',1); - + add_animation(which,p_value); } else if (name.begins_with("next/")) { @@ -62,7 +62,7 @@ bool AnimationPlayer::_set(const StringName& p_name, const Variant& p_value) { animation_set_next(which,p_value); } else if (p_name==SceneStringNames::get_singleton()->blend_times) { - + Array array=p_value; int len = array.size(); ERR_FAIL_COND_V(len%3,false); @@ -79,7 +79,7 @@ bool AnimationPlayer::_set(const StringName& p_name, const Variant& p_value) { } else if (p_name==SceneStringNames::get_singleton()->autoplay) { autoplay=p_value; - + } else return false; @@ -92,7 +92,7 @@ bool AnimationPlayer::_get(const StringName& p_name,Variant &r_ret) const { String name=p_name; if (name=="playback/speed") { //bw compatibility - + r_ret=speed_scale; } else if (name=="playback/active") { @@ -105,9 +105,9 @@ bool AnimationPlayer::_get(const StringName& p_name,Variant &r_ret) const { r_ret="[stop]"; } else if (name.begins_with("anims/")) { - + String which=name.get_slicec('/',1); - + r_ret= get_animation(which).get_ref_ptr(); } else if (name.begins_with("next/")) { @@ -117,7 +117,7 @@ bool AnimationPlayer::_get(const StringName& p_name,Variant &r_ret) const { } else if (name=="blend_times") { - + Array array; array.resize(blend_times.size()*3); @@ -195,7 +195,7 @@ void AnimationPlayer::advance(float p_time) { void AnimationPlayer::_notification(int p_what) { switch(p_what) { - + case NOTIFICATION_ENTER_TREE: { if (!processing) { @@ -222,7 +222,7 @@ void AnimationPlayer::_notification(int p_what) { _animation_process( get_process_delta_time() ); } break; case NOTIFICATION_FIXED_PROCESS: { - + if (animation_process_mode==ANIMATION_PROCESS_IDLE) break; @@ -230,7 +230,7 @@ void AnimationPlayer::_notification(int p_what) { _animation_process( get_fixed_process_delta_time() ); } break; case NOTIFICATION_EXIT_TREE: { - + //stop_all(); clear_caches(); } break; @@ -240,15 +240,15 @@ void AnimationPlayer::_notification(int p_what) { void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { Node *parent = get_node(root); - + ERR_FAIL_COND(!parent); Animation *a=p_anim->animation.operator->(); - + p_anim->node_cache.resize( a->get_track_count() ); - + for (int i=0;i<a->get_track_count();i++) { - + p_anim->node_cache[i]=NULL; RES resource; Node *child = parent->get_node_and_resource(a->track_get_path(i),resource); @@ -267,7 +267,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { continue; } } - + { if (!child->is_connected("exit_tree",this,"_node_removed")) child->connect("exit_tree",this,"_node_removed",make_binds(child),CONNECT_ONESHOT); @@ -277,15 +277,15 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { key.id=id; key.bone_idx=bone_idx; - + if (node_cache_map.has(key)) { - + p_anim->node_cache[i]=&node_cache_map[key]; } else { - + node_cache_map[key]=TrackNodeCache(); - + p_anim->node_cache[i]=&node_cache_map[key]; p_anim->node_cache[i]->path=a->track_get_path(i); p_anim->node_cache[i]->node=child; @@ -293,7 +293,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { p_anim->node_cache[i]->node_2d=child->cast_to<Node2D>(); if (a->track_get_type(i)==Animation::TYPE_TRANSFORM) { // special cases and caches for transform tracks - + // cache spatial p_anim->node_cache[i]->spatial=child->cast_to<Spatial>(); // cache skeleton @@ -302,7 +302,7 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { StringName bone_name=a->track_get_path(i).get_property(); if (bone_name.operator String()!="") { - + p_anim->node_cache[i]->bone_idx=p_anim->node_cache[i]->skeleton->find_bone(bone_name); if (p_anim->node_cache[i]->bone_idx<0) { // broken track (nonexistent bone) @@ -314,9 +314,9 @@ void AnimationPlayer::_generate_node_caches(AnimationData* p_anim) { } } else { // no property, just use spatialnode - p_anim->node_cache[i]->skeleton=NULL; + p_anim->node_cache[i]->skeleton=NULL; } - + } } } @@ -356,29 +356,29 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p ERR_FAIL_COND( p_anim->node_cache.size() != p_anim->animation->get_track_count() ); - + Animation *a=p_anim->animation.operator->(); bool can_call = is_inside_tree() && !get_tree()->is_editor_hint(); - + for (int i=0;i<a->get_track_count();i++) { - + TrackNodeCache *nc=p_anim->node_cache[i]; - + if (!nc) // no node cache for this track, skip it continue; - + if (a->track_get_key_count(i)==0) continue; // do nothing if track is empty switch(a->track_get_type(i)) { - + case Animation::TYPE_TRANSFORM: { - + if (!nc->spatial) continue; - - + + Vector3 loc; Quat rot; Vector3 scale; @@ -406,10 +406,10 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p nc->scale_accum=nc->scale_accum.linear_interpolate(scale,p_interp); } - + } break; case Animation::TYPE_VALUE: { - + if (!nc->node) continue; @@ -488,21 +488,21 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p } } - + } break; case Animation::TYPE_METHOD: { - + if (!nc->node) continue; if (p_delta==0) continue; if (!p_allow_discrete) break; - + List<int> indices; a->method_track_get_key_indices(i,p_time,p_delta,&indices); - + for(List<int>::Element *E=indices.front();E;E=E->next()) { StringName method=a->method_track_get_name(i,E->get()); @@ -523,8 +523,8 @@ void AnimationPlayer::_animation_process_animation(AnimationData* p_anim,float p ); } } - - + + } break; } } @@ -535,17 +535,17 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd,float p_delta,flo float delta=p_delta*speed_scale*cd.speed_scale; bool backwards=delta<0; float next_pos=cd.pos+delta; - + float len=cd.from->animation->get_length(); bool loop=cd.from->animation->has_loop(); - + if (!loop) { - + if (next_pos<0) next_pos=0; else if (next_pos>len) next_pos=len; - + // fix delta delta=next_pos-cd.pos; @@ -564,39 +564,39 @@ void AnimationPlayer::_animation_process_data(PlaybackData &cd,float p_delta,flo } } else { - + next_pos=Math::fposmod(next_pos,len); } - + cd.pos=next_pos; _animation_process_animation(cd.from,cd.pos,delta,p_blend,&cd == &playback.current); - + } void AnimationPlayer::_animation_process2(float p_delta) { Playback &c=playback; - + float prev_blend=1.0; accum_pass++; - + int pop_count=1; int pop=0; // if >0, then amount of elements to pop from the back for (List<Blend>::Element *E=c.blend.back();E;E=E->prev(),pop_count++) { - + Blend& b=E->get(); _animation_process_data(b.data,p_delta,prev_blend); - + prev_blend=1.0-b.blend_left/b.blend_time; - + b.blend_left-=Math::absf(speed_scale*p_delta); - + if (b.blend_left<0) { pop=pop_count; @@ -608,22 +608,22 @@ void AnimationPlayer::_animation_process2(float p_delta) { c.blend.pop_back(); } - + _animation_process_data(c.current,p_delta,prev_blend); - + } void AnimationPlayer::_animation_update_transforms() { for (int i=0;i<cache_update_size;i++) { - + TrackNodeCache *nc=cache_update[i]; ERR_CONTINUE( nc->accum_pass!=accum_pass ); if (nc->spatial) { - + Transform t; t.origin=nc->loc_accum; t.basis=nc->rot_accum; @@ -638,9 +638,9 @@ void AnimationPlayer::_animation_update_transforms() { nc->spatial->set_transform(t); } } - + } - + cache_update_size=0; for (int i=0;i<cache_update_prop_size;i++) { @@ -712,7 +712,7 @@ void AnimationPlayer::_animation_process(float p_delta) { // bool any_active=false; - + if (playback.current.from) { end_notify=false; @@ -750,7 +750,7 @@ Error AnimationPlayer::add_animation(const StringName& p_name, const Ref<Animati #endif ERR_FAIL_COND_V( p_animation.is_null() , ERR_INVALID_PARAMETER ); - + //print_line("Add anim: "+String(p_name)+" name: "+p_animation->get_name()); if (animation_set.has(p_name)) { @@ -759,12 +759,12 @@ Error AnimationPlayer::add_animation(const StringName& p_name, const Ref<Animati animation_set[p_name].animation=p_animation; clear_caches(); } else { - + AnimationData ad; ad.animation=p_animation; ad.name=p_name; animation_set[p_name]=ad; - } + } _ref_anim(p_animation); _change_notify(); @@ -774,10 +774,10 @@ Error AnimationPlayer::add_animation(const StringName& p_name, const Ref<Animati void AnimationPlayer::remove_animation(const StringName& p_name) { ERR_FAIL_COND(!animation_set.has(p_name) ); - + stop_all(); _unref_anim(animation_set[p_name].animation); - animation_set.erase(p_name); + animation_set.erase(p_name); clear_caches(); _change_notify(); @@ -876,7 +876,7 @@ Ref<Animation> AnimationPlayer::get_animation(const StringName& p_name) const { ERR_FAIL_COND_V( !animation_set.has(p_name), Ref<Animation>() ); const AnimationData& data = animation_set[p_name]; - + return data.animation; } @@ -950,7 +950,7 @@ void AnimationPlayer::play(const StringName& p_name, float p_custom_blend, float //printf("animation is %ls\n", String(p_name).c_str()); //ERR_FAIL_COND(!is_inside_scene()); StringName name=p_name; - + if (String(name)=="") name=playback.assigned; @@ -958,11 +958,11 @@ void AnimationPlayer::play(const StringName& p_name, float p_custom_blend, float ERR_EXPLAIN("Animation not found: "+name); ERR_FAIL(); } - + Playback &c=playback; if (c.current.from) { - + float blend_time=0; // find if it can blend BlendKey bk; @@ -972,37 +972,37 @@ void AnimationPlayer::play(const StringName& p_name, float p_custom_blend, float if (p_custom_blend>=0) { blend_time=p_custom_blend; } else if (blend_times.has(bk)) { - + blend_time=blend_times[bk]; } else { - + bk.from="*"; if (blend_times.has(bk)) { blend_time=blend_times[bk]; } else { - + bk.from=c.current.from->name; bk.to="*"; - + if (blend_times.has(bk)) { - + blend_time=blend_times[bk]; } } } - + if (p_custom_blend<0 && blend_time==0 && default_blend_time) blend_time=default_blend_time; if (blend_time>0) { - + Blend b; b.data=c.current; b.blend_time=b.blend_left=blend_time; - c.blend.push_back(b); + c.blend.push_back(b); } } - + c.current.from=&animation_set[name]; c.current.pos=p_from_end ? c.current.from->animation->get_length() : 0; c.current.speed_scale=p_custom_scale; @@ -1059,7 +1059,7 @@ String AnimationPlayer::get_current_animation() const { } void AnimationPlayer::stop(bool p_reset) { - + Playback &c=playback; c.blend.clear(); if (p_reset) { @@ -1073,15 +1073,15 @@ void AnimationPlayer::stop(bool p_reset) { void AnimationPlayer::stop_all() { stop(); - + _set_process(false); // always process when starting an animation - + } void AnimationPlayer::set_speed(float p_speed) { speed_scale=p_speed; - + } float AnimationPlayer::get_speed() const { @@ -1151,7 +1151,7 @@ void AnimationPlayer::_node_removed(Node *p_node) { void AnimationPlayer::clear_caches() { - + node_cache_map.clear(); for( Map<StringName, AnimationData>::Element *E=animation_set.front();E;E=E->next()) { @@ -1296,7 +1296,7 @@ void AnimationPlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("has_animation","name"),&AnimationPlayer::has_animation); ObjectTypeDB::bind_method(_MD("get_animation:Animation","name"),&AnimationPlayer::get_animation); ObjectTypeDB::bind_method(_MD("get_animation_list"),&AnimationPlayer::_get_animation_list); - + ObjectTypeDB::bind_method(_MD("set_blend_time","anim_from","anim_to","sec"),&AnimationPlayer::set_blend_time); ObjectTypeDB::bind_method(_MD("get_blend_time","anim_from","anim_to"),&AnimationPlayer::get_blend_time); @@ -1315,7 +1315,7 @@ void AnimationPlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_active","active"),&AnimationPlayer::set_active); ObjectTypeDB::bind_method(_MD("is_active"),&AnimationPlayer::is_active); - + ObjectTypeDB::bind_method(_MD("set_speed","speed"),&AnimationPlayer::set_speed); ObjectTypeDB::bind_method(_MD("get_speed"),&AnimationPlayer::get_speed); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index 853526c80a..2ae3a0756c 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -53,7 +53,7 @@ public: private: enum { - + NODE_CACHE_UPDATE_MAX=1024, BLEND_FROM_MAX=3 }; @@ -96,23 +96,23 @@ private: Map<StringName,PropertyAnim> property_anim; - + TrackNodeCache() { skeleton=NULL; spatial=NULL; node=NULL; accum_pass=0; bone_idx=-1; node_2d=NULL; } - + }; struct TrackNodeCacheKey { - + uint32_t id; int bone_idx; inline bool operator<(const TrackNodeCacheKey& p_right) const { - + if (id<p_right.id) return true; else if (id>p_right.id) return false; - else + else return bone_idx<p_right.bone_idx; } }; @@ -135,7 +135,7 @@ private: StringName next; Vector<TrackNodeCache*> node_cache; Ref<Animation> animation; - + }; Map<StringName, AnimationData> animation_set; @@ -148,41 +148,41 @@ private: Map<BlendKey, float > blend_times; - - + + struct PlaybackData { - + AnimationData* from; float pos; float speed_scale; PlaybackData() { - + pos=0; speed_scale=1.0; - from=NULL; + from=NULL; } }; - + struct Blend { - + PlaybackData data; - + float blend_time; float blend_left; - + Blend() { - + blend_left=0; blend_time=0; } }; - + struct Playback { - - List<Blend> blend; + + List<Blend> blend; PlaybackData current; StringName assigned; } playback; @@ -197,25 +197,25 @@ private: bool active; NodePath root; - + void _animation_process_animation(AnimationData* p_anim,float p_time, float p_delta,float p_interp, bool p_allow_discrete=true); - - void _generate_node_caches(AnimationData* p_anim); + + void _generate_node_caches(AnimationData* p_anim); void _animation_process_data(PlaybackData &cd,float p_delta,float p_blend); void _animation_process2(float p_delta); void _animation_update_transforms(); void _animation_process(float p_delta); - + void _node_removed(Node *p_node); - + // bind helpers DVector<String> _get_animation_list() const { - + List<StringName> animations; get_animation_list(&animations); DVector<String> ret; while(animations.size()) { - + ret.push_back( animations.front()->get()); animations.pop_front(); } @@ -236,9 +236,9 @@ protected: bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; void _notification(int p_what); - - static void _bind_methods(); - + + static void _bind_methods(); + public: StringName find_animation(const Ref<Animation>& p_animation) const; @@ -249,7 +249,7 @@ public: bool has_animation(const StringName& p_name) const; Ref<Animation> get_animation(const StringName& p_name) const; void get_animation_list( List<StringName> * p_animations) const; - + void set_blend_time(const StringName& p_animation1, const StringName& p_animation2, float p_time); float get_blend_time( const StringName& p_animation1, const StringName& p_animation2) const; @@ -258,7 +258,7 @@ public: void set_default_blend_time(float p_default); float get_default_blend_time() const; - + void play(const StringName& p_name=StringName(),float p_custom_blend=-1,float p_custom_scale=1.0,bool p_from_end=false); void play_backwards(const StringName& p_name=StringName(),float p_custom_blend=-1); void queue(const StringName& p_name); @@ -271,7 +271,7 @@ public: void set_active(bool p_active); bool is_active() const; bool is_valid() const; - + void set_speed(float p_speed); float get_speed() const; @@ -295,8 +295,8 @@ public: void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const; - - AnimationPlayer(); + + AnimationPlayer(); ~AnimationPlayer(); }; diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp index a66a2849ae..cc9e6c71e3 100644 --- a/scene/animation/animation_tree_player.cpp +++ b/scene/animation/animation_tree_player.cpp @@ -420,7 +420,7 @@ void AnimationTreePlayer::_notification(int p_what) { _process_animation( get_process_delta_time() ); } break; case NOTIFICATION_FIXED_PROCESS: { - + if (animation_process_mode==ANIMATION_PROCESS_IDLE) break; @@ -507,7 +507,7 @@ float AnimationTreePlayer::_process_node(const StringName& p_node,AnimationNode if (!(*r_prev_anim)) active_list=an; - else + else (*r_prev_anim)->next=an; an->next=NULL; @@ -1831,7 +1831,7 @@ void AnimationTreePlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("reset"),&AnimationTreePlayer::reset); - ObjectTypeDB::bind_method(_MD("recompute_caches"),&AnimationTreePlayer::recompute_caches); + ObjectTypeDB::bind_method(_MD("recompute_caches"),&AnimationTreePlayer::recompute_caches); ADD_PROPERTY(PropertyInfo(Variant::INT, "playback/process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), _SCS("set_animation_process_mode"), _SCS("get_animation_process_mode")); diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 31f30dd1d9..7edd57603b 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -126,7 +126,7 @@ bool Tween::_get(const StringName& p_name,Variant &r_ret) const { String name=p_name; if (name=="playback/speed") { //bw compatibility - + r_ret=speed_scale; } else if (name=="playback/active") { @@ -149,7 +149,7 @@ void Tween::_get_property_list(List<PropertyInfo> *p_list) const { void Tween::_notification(int p_what) { switch(p_what) { - + case NOTIFICATION_ENTER_TREE: { if (!processing) { @@ -170,7 +170,7 @@ void Tween::_notification(int p_what) { _tween_process( get_process_delta_time() ); } break; case NOTIFICATION_FIXED_PROCESS: { - + if (tween_process_mode==TWEEN_PROCESS_IDLE) break; @@ -178,7 +178,7 @@ void Tween::_notification(int p_what) { _tween_process( get_fixed_process_delta_time() ); } break; case NOTIFICATION_EXIT_TREE: { - + stop_all(); } break; } @@ -1183,7 +1183,7 @@ bool Tween::interpolate_callback(Object *p_object args=2; else if (p_arg1.get_type()!=Variant::NIL) args=1; - else + else args=0; data.args = args; @@ -1247,7 +1247,7 @@ bool Tween::interpolate_deferred_callback(Object *p_object args=2; else if (p_arg1.get_type()!=Variant::NIL) args=1; - else + else args=0; data.args = args; diff --git a/scene/animation/tween.h b/scene/animation/tween.h index f06ca1e9e7..d0455cdc71 100644 --- a/scene/animation/tween.h +++ b/scene/animation/tween.h @@ -57,7 +57,7 @@ public: TRANS_COUNT, }; - + enum EaseType { EASE_IN, EASE_OUT, @@ -206,7 +206,7 @@ public: , String p_callback , VARIANT_ARG_DECLARE ); - + bool interpolate_deferred_callback(Object *p_object , real_t p_times_in_sec , String p_callback diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 698dbce2b5..3bcc60b86a 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -37,19 +37,19 @@ void BaseButton::_input_event(InputEvent p_event) { if (status.disabled) // no interaction with disabled button return; - + switch(p_event.type) { - + case InputEvent::MOUSE_BUTTON: { - + const InputEventMouseButton &b=p_event.mouse_button; - + if ( status.disabled || b.button_index!=1 ) return; if (status.pressing_button) break; - + if (status.click_on_press) { if (b.pressed) { @@ -96,13 +96,13 @@ void BaseButton::_input_event(InputEvent p_event) { } if (b.pressed) { - + status.press_attempt=true; status.pressing_inside=true; - + } else { - - + + if (status.press_attempt &&status.pressing_inside) { if (!toggle_mode) { //mouse press attempt @@ -114,14 +114,14 @@ void BaseButton::_input_event(InputEvent p_event) { } emit_signal("pressed"); - + } else { status.pressed=!status.pressed; - + pressed(); emit_signal("pressed"); - + toggled(status.pressed); emit_signal("toggled",status.pressed); if (get_script_instance()) { @@ -134,10 +134,10 @@ void BaseButton::_input_event(InputEvent p_event) { } status.press_attempt=false; - + } - - update(); + + update(); } break; case InputEvent::MOUSE_MOTION: { @@ -151,7 +151,7 @@ void BaseButton::_input_event(InputEvent p_event) { case InputEvent::ACTION: case InputEvent::JOYSTICK_BUTTON: case InputEvent::KEY: { - + if (p_event.is_echo()) { break; @@ -166,7 +166,7 @@ void BaseButton::_input_event(InputEvent p_event) { } if (p_event.is_action("ui_accept")) { - + if (p_event.is_pressed()) { status.pressing_button++; @@ -183,18 +183,18 @@ void BaseButton::_input_event(InputEvent p_event) { status.press_attempt=false; status.pressing_inside=false; - + if (!toggle_mode) { //mouse press attempt - + pressed(); - emit_signal("pressed"); + emit_signal("pressed"); } else { - + status.pressed=!status.pressed; - + pressed(); emit_signal("pressed"); - + toggled(status.pressed); if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_toggled,status.pressed); @@ -202,29 +202,29 @@ void BaseButton::_input_event(InputEvent p_event) { emit_signal("toggled",status.pressed); } } - + accept_event(); - update(); + update(); } - } - + } + } } void BaseButton::_notification(int p_what) { - + if (p_what==NOTIFICATION_MOUSE_ENTER) { - + status.hovering=true; update(); } - + if (p_what==NOTIFICATION_MOUSE_EXIT) { status.hovering=false; update(); - } + } if (p_what==NOTIFICATION_FOCUS_EXIT) { if (status.pressing_button && status.press_attempt) { @@ -282,7 +282,7 @@ void BaseButton::toggled(bool p_pressed) { void BaseButton::set_disabled(bool p_disabled) { - + status.disabled = p_disabled; update(); _change_notify("disabled"); @@ -298,7 +298,7 @@ bool BaseButton::is_disabled() const { } void BaseButton::set_pressed(bool p_pressed) { - + if (!toggle_mode) return; if (status.pressed==p_pressed) @@ -309,12 +309,12 @@ void BaseButton::set_pressed(bool p_pressed) { } bool BaseButton::is_pressing() const{ - + return status.press_attempt; } bool BaseButton::is_pressed() const { - + return toggle_mode?status.pressed:status.press_attempt; } @@ -324,11 +324,11 @@ bool BaseButton::is_hovered() const { } BaseButton::DrawMode BaseButton::get_draw_mode() const { - + if (status.disabled) { return DRAW_DISABLED; }; - + //print_line("press attempt: "+itos(status.press_attempt)+" hover: "+itos(status.hovering)+" pressed: "+itos(status.pressed)); if (status.press_attempt==false && status.hovering && !status.pressed) { @@ -336,34 +336,34 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const { return DRAW_HOVER; } else { /* determine if pressed or not */ - + bool pressing; if (status.press_attempt) { - + pressing=status.pressing_inside; if (status.pressed) pressing=!pressing; } else { - + pressing=status.pressed; } - - if (pressing) + + if (pressing) return DRAW_PRESSED; - else + else return DRAW_NORMAL; - } + } return DRAW_NORMAL; } void BaseButton::set_toggle_mode(bool p_on) { - + toggle_mode=p_on; } bool BaseButton::is_toggle_mode() const { - + return toggle_mode; } @@ -414,7 +414,7 @@ void BaseButton::_bind_methods() { } BaseButton::BaseButton() { - + toggle_mode=false; status.pressed=false; status.press_attempt=false; @@ -426,7 +426,7 @@ BaseButton::BaseButton() { set_focus_mode( FOCUS_ALL ); group=NULL; - + } BaseButton::~BaseButton() diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index 83c66326c5..9a5213d971 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -42,9 +42,9 @@ class BaseButton : public Control { OBJ_TYPE( BaseButton, Control ); bool toggle_mode; - + struct Status { - + bool pressed; bool hovering; bool press_attempt; @@ -55,15 +55,15 @@ class BaseButton : public Control { int pressing_button; } status; - + ButtonGroup *group; - + protected: - + virtual void pressed(); virtual void toggled(bool p_pressed); static void _bind_methods(); @@ -82,7 +82,7 @@ public: DrawMode get_draw_mode() const; /* Signals */ - + bool is_pressed() const; ///< return wether button is pressed (toggled in) bool is_pressing() const; ///< return wether button is pressed (toggled in) bool is_hovered() const; @@ -90,7 +90,7 @@ public: void set_pressed(bool p_pressed); ///only works in toggle mode void set_toggle_mode(bool p_on); bool is_toggle_mode() const; - + void set_disabled(bool p_disabled); bool is_disabled() const; @@ -98,7 +98,7 @@ public: bool get_click_on_press() const; - BaseButton(); + BaseButton(); ~BaseButton(); }; diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index b9ce46d738..0f3f762ba1 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -45,7 +45,7 @@ Size2 Button::get_minimum_size() const { _icon=icon; if (!_icon.is_null()) { - + minsize.height=MAX( minsize.height, _icon->get_height() ); minsize.width+=_icon->get_width(); if (text!="") @@ -53,48 +53,48 @@ Size2 Button::get_minimum_size() const { } return get_stylebox("normal" )->get_minimum_size() + minsize; - + } void Button::_notification(int p_what) { - + if (p_what==NOTIFICATION_DRAW) { - + RID ci = get_canvas_item(); Size2 size=get_size(); Color color; //print_line(get_text()+": "+itos(is_flat())+" hover "+itos(get_draw_mode())); - + switch( get_draw_mode() ) { - + case DRAW_NORMAL: { - + if (!flat) get_stylebox("normal" )->draw( ci, Rect2(Point2(0,0), size) ); - color=get_color("font_color"); + color=get_color("font_color"); } break; case DRAW_PRESSED: { - + get_stylebox("pressed" )->draw( ci, Rect2(Point2(0,0), size) ); if (has_color("font_color_pressed")) color=get_color("font_color_pressed"); else color=get_color("font_color"); - + } break; case DRAW_HOVER: { - + get_stylebox("hover" )->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color_hover"); - + } break; case DRAW_DISABLED: { get_stylebox("disabled" )->draw( ci, Rect2(Point2(0,0), size) ); color=get_color("font_color_disabled"); - + } break; } @@ -139,12 +139,12 @@ void Button::_notification(int p_what) { if (!_icon.is_null()) { int valign = size.height-style->get_minimum_size().y; - + _icon->draw(ci,style->get_offset()+Point2(0, Math::floor( (valign-_icon->get_height())/2.0 ) ),is_disabled()?Color(1,1,1,0.4):Color(1,1,1) ); } - + } } @@ -236,7 +236,7 @@ void Button::_bind_methods() { } Button::Button(const String &p_text) { - + flat=false; clip_text=false; set_stop_mouse(true); diff --git a/scene/gui/button.h b/scene/gui/button.h index bd244f5087..8a17a164a0 100644 --- a/scene/gui/button.h +++ b/scene/gui/button.h @@ -34,7 +34,7 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Button : public BaseButton { - + OBJ_TYPE( Button, BaseButton ); public: @@ -49,25 +49,25 @@ private: bool flat; String text; - Ref<Texture> icon; + Ref<Texture> icon; bool clip_text; TextAlign align; - -protected: + +protected: virtual Size2 get_minimum_size() const; void _notification(int p_what); - static void _bind_methods(); + static void _bind_methods(); public: -// +// void set_text(const String& p_text); String get_text() const; - + void set_icon(const Ref<Texture>& p_icon); Ref<Texture> get_icon() const; - + void set_flat(bool p_flat); bool is_flat() const; diff --git a/scene/gui/button_array.cpp b/scene/gui/button_array.cpp index 9e3476899f..de77b83403 100644 --- a/scene/gui/button_array.cpp +++ b/scene/gui/button_array.cpp @@ -171,9 +171,9 @@ void ButtonArray::_notification(int p_what) { case NOTIFICATION_READY:{ MethodInfo mi; mi.name="mouse_sub_enter"; - + add_user_signal(mi); - + }break; case NOTIFICATION_DRAW: { diff --git a/scene/gui/button_array.h b/scene/gui/button_array.h index 39661eaabd..c4b9b0c9e3 100644 --- a/scene/gui/button_array.h +++ b/scene/gui/button_array.h @@ -69,7 +69,7 @@ protected: void _notification(int p_what); static void _bind_methods(); - + public: void _input_event(const InputEvent& p_event); diff --git a/scene/gui/button_group.h b/scene/gui/button_group.h index 38c61991b7..4afba22228 100644 --- a/scene/gui/button_group.h +++ b/scene/gui/button_group.h @@ -55,7 +55,7 @@ friend class BaseButton; public: void get_button_list(List<BaseButton*> *p_buttons) const; - BaseButton *get_pressed_button() const; + BaseButton *get_pressed_button() const; BaseButton *get_focused_button() const; void set_pressed_button(BaseButton *p_button); int get_pressed_button_index() const; diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index ecaea251a5..f8c0c6b208 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -33,9 +33,9 @@ void CheckButton::_notification(int p_what) { - + if (p_what==NOTIFICATION_DRAW) { - + RID ci = get_canvas_item(); Ref<Texture> on=Control::get_icon("on"); @@ -50,17 +50,17 @@ void CheckButton::_notification(int p_what) { else off->draw(ci,ofs); - + } } CheckButton::CheckButton() { - + set_toggle_mode(true); set_text_align(ALIGN_LEFT); - + } diff --git a/scene/gui/check_button.h b/scene/gui/check_button.h index 022ade2193..a1ed4c1896 100644 --- a/scene/gui/check_button.h +++ b/scene/gui/check_button.h @@ -35,18 +35,18 @@ @author Juan Linietsky <reduzio@gmail.com> */ class CheckButton : public Button { - + OBJ_TYPE( CheckButton, Button ); - - -protected: + + +protected: void _notification(int p_what); public: - - CheckButton(); + + CheckButton(); ~CheckButton(); - + }; #endif diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index f1b910d23f..f8f8b1f6d1 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -246,7 +246,7 @@ void ColorPicker::set_raw_mode(bool p_enabled) { raw_mode_enabled=p_enabled; if (btn_mode->is_pressed()!=p_enabled) btn_mode->set_pressed(p_enabled); - + if (!is_inside_tree()) return; @@ -322,7 +322,7 @@ void ColorPicker::_w_input(const InputEvent &ev) { if (bev.pressed) { changing_color = true; h=1-((float)bev.y)/256.0; - + } else { changing_color = false; } @@ -502,7 +502,7 @@ ColorPicker::ColorPicker() : args.push_back(1); args.push_back(c); c->connect("draw",this,"_hsv_draw",args); - + hb_edit->add_child(uv_edit); hb_edit->add_child(memnew( VSeparator )); hb_edit->add_child(w_edit); @@ -543,7 +543,7 @@ ColorPicker::ColorPicker() : } HBoxContainer *hhb = memnew( HBoxContainer ); - + btn_mode = memnew( CheckButton ); btn_mode->set_text("RAW Mode"); btn_mode->connect("toggled", this, "set_raw_mode"); @@ -570,7 +570,7 @@ ColorPicker::ColorPicker() : uv_material->set_shader(s_uv); w_material.instance(); - + Ref<Shader> s_w = get_shader("w_editor"); w_material->set_shader(s_w); diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/color_ramp_edit.cpp index 14a48fe3d3..2ab004e04b 100644 --- a/scene/gui/color_ramp_edit.cpp +++ b/scene/gui/color_ramp_edit.cpp @@ -185,7 +185,7 @@ void ColorRampEdit::_input_event(const InputEvent& p_event) { int x = p_event.mouse_motion.x; float newofs = CLAMP(x/float(total_w),0,1); - + //Snap to nearest point if holding shift if (p_event.key.mod.shift) { float snap_treshhold = 0.03; diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index af3b37bec2..295ec03702 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -226,9 +226,9 @@ bool Control::_get(const StringName& p_name,Variant &r_ret) const { return false; - + return true; - + } void Control::_get_property_list( List<PropertyInfo> *p_list) const { @@ -326,7 +326,7 @@ Control *Control::get_parent_control() const { void Control::_resize(const Size2& p_size) { - + _size_changed(); } @@ -626,7 +626,7 @@ void Control::set_drag_preview(Control *p_control) { } - + bool Control::is_window_modal_on_top() const { @@ -640,7 +640,7 @@ bool Control::is_window_modal_on_top() const { Size2 Control::get_minimum_size() const { - + ScriptInstance *si = const_cast<Control*>(this)->get_script_instance(); if (si) { @@ -654,7 +654,7 @@ Size2 Control::get_minimum_size() const { Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type) const { - + if (p_type==StringName()) { const Ref<Texture>* tex = data.icon_override.getptr(p_name); @@ -714,7 +714,7 @@ Ref<Shader> Control::get_shader(const StringName& p_name,const StringName& p_typ } Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p_type) const { - + if (p_type==StringName()) { const Ref<StyleBox>* style = data.style_override.getptr(p_name); if (style) @@ -828,12 +828,12 @@ int Control::get_constant(const StringName& p_name,const StringName& p_type) con return Theme::get_default()->get_constant( p_name, type ); - + } bool Control::has_icon(const StringName& p_name,const StringName& p_type) const { - + if (p_type==StringName()) { const Ref<Texture>* tex = data.icon_override.getptr(p_name); if (tex) @@ -859,7 +859,7 @@ bool Control::has_icon(const StringName& p_name,const StringName& p_type) const } return Theme::get_default()->has_icon( p_name, type ); - + } bool Control::has_shader(const StringName &p_name, const StringName &p_type) const @@ -889,10 +889,10 @@ bool Control::has_shader(const StringName &p_name, const StringName &p_type) con } return Theme::get_default()->has_shader( p_name, type ); - + } bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) const { - + if (p_type==StringName()) { const Ref<StyleBox>* style = data.style_override.getptr(p_name); @@ -922,7 +922,7 @@ bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) co } bool Control::has_font(const StringName& p_name,const StringName& p_type) const { - + if (p_type==StringName()) { const Ref<Font>* font = data.font_override.getptr(p_name); if (font) @@ -952,7 +952,7 @@ bool Control::has_font(const StringName& p_name,const StringName& p_type) const } bool Control::has_color(const StringName& p_name,const StringName& p_type) const { - + if (p_type==StringName()) { const Color* color = data.color_override.getptr(p_name); if (color) @@ -1024,7 +1024,7 @@ Size2 Control::get_parent_area_size() const { } else { parent_size=get_viewport()->get_visible_rect().size; - } + } return parent_size; } @@ -1083,11 +1083,11 @@ void Control::_size_changed() { } float Control::_get_parent_range(int p_idx) const { - + if (!is_inside_tree()) { - + return 1.0; - + } if (data.parent_canvas_item) { return data.parent_canvas_item->get_item_rect().size[p_idx&1]; @@ -1100,21 +1100,21 @@ float Control::_get_parent_range(int p_idx) const { float Control::_get_range(int p_idx) const { - + p_idx&=1; float parent_range = _get_parent_range( p_idx ); float from = _a2s( data.margin[p_idx], data.anchor[p_idx], parent_range ); float to = _a2s( data.margin[p_idx+2], data.anchor[p_idx+2], parent_range ); - + return to-from; } float Control::_s2a(float p_val, AnchorType p_anchor,float p_range) const { - + switch(p_anchor) { - - case ANCHOR_BEGIN: { + + case ANCHOR_BEGIN: { return p_val; } break; case ANCHOR_END: { @@ -1122,21 +1122,21 @@ float Control::_s2a(float p_val, AnchorType p_anchor,float p_range) const { } break; case ANCHOR_RATIO: { return p_val/p_range; - } break; + } break; case ANCHOR_CENTER: { return (p_range/2)-p_val; } break; - } - + } + return 0; } float Control::_a2s(float p_val, AnchorType p_anchor,float p_range) const { - + switch(p_anchor) { - - case ANCHOR_BEGIN: { + + case ANCHOR_BEGIN: { return Math::floor(p_val); } break; case ANCHOR_END: { @@ -1144,7 +1144,7 @@ float Control::_a2s(float p_val, AnchorType p_anchor,float p_range) const { } break; case ANCHOR_RATIO: { return Math::floor(p_range*p_val); - } break; + } break; case ANCHOR_CENTER: { return Math::floor((p_range/2)-p_val); } break; @@ -1154,9 +1154,9 @@ float Control::_a2s(float p_val, AnchorType p_anchor,float p_range) const { void Control::set_anchor(Margin p_margin,AnchorType p_anchor) { - + if (!is_inside_tree()) { - + data.anchor[p_margin]=p_anchor; } else { float pr = _get_parent_range(p_margin); @@ -1175,8 +1175,8 @@ void Control::set_anchor_and_margin(Margin p_margin,AnchorType p_anchor, float p Control::AnchorType Control::get_anchor(Margin p_margin) const { - - return data.anchor[p_margin]; + + return data.anchor[p_margin]; } @@ -1204,40 +1204,40 @@ void Control::set_margin(Margin p_margin,float p_value) { } void Control::set_begin(const Size2& p_point) { - + data.margin[0]=p_point.x; data.margin[1]=p_point.y; _size_changed(); } void Control::set_end(const Size2& p_point) { - + data.margin[2]=p_point.x; data.margin[3]=p_point.y; _size_changed(); } float Control::get_margin(Margin p_margin) const { - + return data.margin[p_margin]; } Size2 Control::get_begin() const { - + return Size2( data.margin[0], data.margin[1] ); } Size2 Control::get_end() const { - + return Size2( data.margin[2], data.margin[3] ); } Point2 Control::get_global_pos() const { - + return get_global_transform().get_origin(); } void Control::set_global_pos(const Point2& p_point) { - + Matrix32 inv; if (data.parent_canvas_item) { @@ -1264,10 +1264,10 @@ void Control::set_pos(const Size2& p_point) { Size2 size = Size2(MAX( min.width, ret.width),MAX( min.height, ret.height)); float w=size.x; float h=size.y; - + x=p_point.x; y=p_point.y; - + data.margin[0] = _s2a( x, data.anchor[0], pw ); data.margin[1] = _s2a( y, data.anchor[1], ph ); data.margin[2] = _s2a( x+w, data.anchor[2], pw ); @@ -1277,26 +1277,26 @@ void Control::set_pos(const Size2& p_point) { } void Control::set_size(const Size2& p_size) { - + Size2 new_size=p_size; Size2 min=get_combined_minimum_size(); if (new_size.x<min.x) new_size.x=min.x; if (new_size.y<min.y) new_size.y=min.y; - + float pw = _get_parent_range(0); float ph = _get_parent_range(1); - + float x = _a2s( data.margin[0], data.anchor[0], pw ); float y = _a2s( data.margin[1], data.anchor[1], ph ); - + float w=new_size.width; float h=new_size.height; - + data.margin[2] = _s2a( x+w, data.anchor[2], pw ); data.margin[3] = _s2a( y+h, data.anchor[3], ph ); - + _size_changed(); } @@ -1308,13 +1308,13 @@ Size2 Control::get_pos() const { } Size2 Control::get_size() const { - + return data.size_cache; } Rect2 Control::get_global_rect() const { - - return Rect2( get_global_pos(), get_size() ); + + return Rect2( get_global_pos(), get_size() ); } Rect2 Control::get_window_rect() const { @@ -1326,7 +1326,7 @@ Rect2 Control::get_window_rect() const { Rect2 Control::get_rect() const { - + return Rect2(get_pos(),get_size()); } @@ -1336,7 +1336,7 @@ Rect2 Control::get_item_rect() const { } void Control::set_area_as_parent_rect(int p_margin) { - + data.anchor[MARGIN_LEFT]=ANCHOR_BEGIN; data.anchor[MARGIN_TOP]=ANCHOR_BEGIN; data.anchor[MARGIN_RIGHT]=ANCHOR_END; @@ -1345,7 +1345,7 @@ void Control::set_area_as_parent_rect(int p_margin) { data.margin[i]=p_margin; _size_changed(); - + } void Control::add_icon_override(const StringName& p_name, const Ref<Texture>& p_icon) { @@ -1354,7 +1354,7 @@ void Control::add_icon_override(const StringName& p_name, const Ref<Texture>& p_ data.icon_override[p_name]=p_icon; notification(NOTIFICATION_THEME_CHANGED); update(); - + } void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) { @@ -1406,7 +1406,7 @@ static Control *_next_control(Control *p_from) { if (p_from->is_set_as_toplevel()) return NULL; // can't go above - Control *parent = p_from->get_parent()?p_from->get_parent()->cast_to<Control>():NULL; + Control *parent = p_from->get_parent()?p_from->get_parent()->cast_to<Control>():NULL; if (!parent) { @@ -1432,10 +1432,10 @@ static Control *_next_control(Control *p_from) { Control *Control::find_next_valid_focus() const { Control *from = const_cast<Control*>(this); - + while(true) { - - + + // find next child Control *next_child=NULL; @@ -1494,7 +1494,7 @@ Control *Control::find_next_valid_focus() const { from = next_child; } - + return NULL; @@ -1610,7 +1610,7 @@ void Control::grab_focus() { get_viewport()->_gui_control_grab_focus(this); -} +} void Control::release_focus() { @@ -1630,7 +1630,7 @@ bool Control::is_toplevel_control() const { } void Control::show_modal(bool p_exclusive) { - + ERR_FAIL_COND(!is_inside_tree()); ERR_FAIL_COND(!data.SI); @@ -1642,7 +1642,7 @@ void Control::show_modal(bool p_exclusive) { raise(); data.modal_exclusive=p_exclusive; data.MI=get_viewport()->_gui_show_modal(this); - + } void Control::_modal_set_prev_focus_owner(ObjectID p_prev) { @@ -2135,7 +2135,7 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_theme","theme:Theme"),&Control::set_theme); ObjectTypeDB::bind_method(_MD("get_theme:Theme"),&Control::get_theme); - + ObjectTypeDB::bind_method(_MD("add_icon_override","name","texture:Texture"),&Control::add_icon_override); ObjectTypeDB::bind_method(_MD("add_shader_override","name","shader:Shader"),&Control::add_shader_override); ObjectTypeDB::bind_method(_MD("add_style_override","name","stylebox:StyleBox"),&Control::add_style_override); @@ -2150,7 +2150,7 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_constant","name","type"),&Control::get_constant,DEFVAL("")); - ObjectTypeDB::bind_method(_MD("get_parent_control:Control"),&Control::get_parent_control); + ObjectTypeDB::bind_method(_MD("get_parent_control:Control"),&Control::get_parent_control); ObjectTypeDB::bind_method(_MD("set_tooltip","tooltip"),&Control::set_tooltip); ObjectTypeDB::bind_method(_MD("get_tooltip","atpos"),&Control::get_tooltip,DEFVAL(Point2())); @@ -2214,7 +2214,7 @@ void Control::_bind_methods() { BIND_CONSTANT( ANCHOR_BEGIN ); BIND_CONSTANT( ANCHOR_END ); - BIND_CONSTANT( ANCHOR_RATIO ); + BIND_CONSTANT( ANCHOR_RATIO ); BIND_CONSTANT( ANCHOR_CENTER ); BIND_CONSTANT( FOCUS_NONE ); BIND_CONSTANT( FOCUS_CLICK ); @@ -2261,11 +2261,11 @@ void Control::_bind_methods() { ADD_SIGNAL( MethodInfo("minimum_size_changed") ); ADD_SIGNAL( MethodInfo("modal_close") ); - + } Control::Control() { - - data.parent=NULL; + + data.parent=NULL; data.ignore_mouse=false; data.stop_mouse=true; @@ -2297,7 +2297,7 @@ Control::Control() { - + } diff --git a/scene/gui/control.h b/scene/gui/control.h index 74d40b7579..851d8316fb 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -45,19 +45,19 @@ class Label; class Panel; class Control : public CanvasItem { - + OBJ_TYPE( Control, CanvasItem ); OBJ_CATEGORY("GUI Nodes"); public: - - enum AnchorType { + + enum AnchorType { ANCHOR_BEGIN, ANCHOR_END, ANCHOR_RATIO, ANCHOR_CENTER, }; - + enum FocusMode { FOCUS_NONE, FOCUS_CLICK, @@ -106,7 +106,7 @@ private: }; struct Data { - + Point2 pos_cache; Size2 size_cache; @@ -132,7 +132,7 @@ private: bool modal; bool modal_exclusive; Ref<Theme> theme; - Control *theme_owner; + Control *theme_owner; String tooltip; CursorShape default_cursor; @@ -153,7 +153,7 @@ private: HashMap<StringName, Color, StringNameHasher > color_override; HashMap<StringName, int, StringNameHasher > constant_override; } data; - + // used internally Control* _find_control_at_pos(CanvasItem* p_node,const Point2& p_pos,const Matrix32& p_xform,Matrix32& r_inv_xform); @@ -184,7 +184,7 @@ friend class Viewport; void _modal_stack_remove(); void _modal_set_prev_focus_owner(ObjectID p_prev); -protected: +protected: //virtual void _window_input_event(InputEvent p_event); @@ -194,15 +194,15 @@ protected: void _notification(int p_notification); - - static void _bind_methods(); - - //bind helpers - + + static void _bind_methods(); + + //bind helpers + public: enum { - + /* NOTIFICATION_DRAW=30, NOTIFICATION_VISIBILITY_CHANGED=38*/ NOTIFICATION_RESIZED=40, @@ -241,29 +241,29 @@ public: Control *get_parent_control() const; - + /* POSITIONING */ - + void set_anchor(Margin p_margin,AnchorType p_anchor); void set_anchor_and_margin(Margin p_margin,AnchorType p_anchor, float p_pos); - + AnchorType get_anchor(Margin p_margin) const; - + void set_margin(Margin p_margin,float p_value); - + void set_begin(const Point2& p_point); // helper void set_end(const Point2& p_point); // helper - - - + + + float get_margin(Margin p_margin) const; Point2 get_begin() const; Point2 get_end() const; - + void set_pos(const Point2& p_point); void set_size(const Size2& p_size); void set_global_pos(const Point2& p_point); - + Point2 get_pos() const; Point2 get_global_pos() const; Size2 get_size() const; @@ -277,9 +277,9 @@ public: void set_scale(const Vector2& p_scale); Vector2 get_scale() const; - + void set_area_as_parent_rect(int p_margin=0); - + void show_modal(bool p_exclusive=false); void set_theme(const Ref<Theme>& p_theme); @@ -297,7 +297,7 @@ public: void minimum_size_changed(); /* FOCUS */ - + void set_focus_mode(FocusMode p_focus_mode); FocusMode get_focus_mode() const; bool has_focus() const; @@ -319,7 +319,7 @@ public: bool is_stopping_mouse() const; /* SKINNING */ - + void add_icon_override(const StringName& p_name, const Ref<Texture>& p_icon); void add_shader_override(const StringName& p_name, const Ref<Shader>& p_shader); void add_style_override(const StringName& p_name, const Ref<StyleBox>& p_style); @@ -367,9 +367,9 @@ public: Control *get_root_parent_control() const; - Control(); + Control(); ~Control(); - + }; VARIANT_ENUM_CAST(Control::AnchorType); diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 9f08b6f845..d00dacd256 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -188,7 +188,7 @@ void AcceptDialog::_post_popup() { } void AcceptDialog::_notification(int p_what) { - + if (p_what==NOTIFICATION_MODAL_CLOSE) { cancel_pressed(); @@ -197,7 +197,7 @@ void AcceptDialog::_notification(int p_what) { - } + } } void AcceptDialog::_builtin_text_entered(const String& p_text) { @@ -206,7 +206,7 @@ void AcceptDialog::_builtin_text_entered(const String& p_text) { } void AcceptDialog::_ok_pressed() { - + if (hide_on_ok) hide(); ok_pressed(); @@ -214,7 +214,7 @@ void AcceptDialog::_ok_pressed() { } void AcceptDialog::_close_pressed() { - + cancel_pressed(); } @@ -223,7 +223,7 @@ String AcceptDialog::get_text() const { return label->get_text(); } void AcceptDialog::set_text(String p_text) { - + label->set_text(p_text); } @@ -291,7 +291,7 @@ Button* AcceptDialog::add_cancel(const String &p_cancel) { } void AcceptDialog::_bind_methods() { - + ObjectTypeDB::bind_method(_MD("_ok"),&AcceptDialog::_ok_pressed); ObjectTypeDB::bind_method(_MD("get_ok"),&AcceptDialog::get_ok); ObjectTypeDB::bind_method(_MD("get_label"),&AcceptDialog::get_label); @@ -321,11 +321,11 @@ void AcceptDialog::set_swap_ok_cancel(bool p_swap) { } AcceptDialog::AcceptDialog() { - + int margin = get_constant("margin","Dialogs"); int button_margin = get_constant("button_margin","Dialogs"); - - + + label = memnew( Label ); label->set_anchor(MARGIN_RIGHT,ANCHOR_END); label->set_anchor(MARGIN_BOTTOM,ANCHOR_END); @@ -345,8 +345,8 @@ AcceptDialog::AcceptDialog() { hbc->add_child(ok); hbc->add_spacer(); //add_child(ok); - - + + ok->connect("pressed", this,"_ok"); set_as_toplevel(true); diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h index 7c06ded866..f256c49aee 100644 --- a/scene/gui/dialogs.h +++ b/scene/gui/dialogs.h @@ -142,7 +142,7 @@ public: class ConfirmationDialog : public AcceptDialog { - + OBJ_TYPE(ConfirmationDialog,AcceptDialog); Button *cancel; protected: diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 56b9260837..b8b8c99c39 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -51,7 +51,7 @@ void FileDialog::_notification(int p_what) { refresh->set_icon(get_icon("reload")); } - + if (p_what==NOTIFICATION_DRAW) { //RID ci = get_canvas_item(); @@ -117,13 +117,13 @@ Vector<String> FileDialog::get_selected_files() const { }; void FileDialog::update_dir() { - + dir->set_text(dir_access->get_current_dir()); } void FileDialog::_dir_entered(String p_dir) { - - + + dir_access->change_dir(p_dir); file->set_text(""); invalidate(); @@ -132,13 +132,13 @@ void FileDialog::_dir_entered(String p_dir) { void FileDialog::_file_entered(const String& p_file) { - _action_pressed(); + _action_pressed(); } void FileDialog::_save_confirm_pressed() { String f=dir_access->get_current_dir().plus_file(file->get_text()); emit_signal("file_selected",f); - hide(); + hide(); } void FileDialog::_post_popup() { @@ -158,7 +158,7 @@ void FileDialog::_post_popup() { } void FileDialog::_action_pressed() { - + if (mode==MODE_OPEN_FILES) { TreeItem *ti=tree->get_next_selected(NULL); @@ -180,7 +180,7 @@ void FileDialog::_action_pressed() { } String f=dir_access->get_current_dir().plus_file(file->get_text()); - + if (mode==MODE_OPEN_FILE && dir_access->file_exists(f)) { emit_signal("file_selected",f); hide(); @@ -202,7 +202,7 @@ void FileDialog::_action_pressed() { } if (mode==MODE_SAVE_FILE) { - + bool valid=false; if (filter->get_selected()==filter->get_item_count()-1) { @@ -263,7 +263,7 @@ void FileDialog::_action_pressed() { confirm_save->set_text("File Exists, Overwrite?"); confirm_save->popup_centered(Size2(200,80)); } else { - + emit_signal("file_selected",f); hide(); @@ -279,51 +279,51 @@ void FileDialog::_cancel_pressed() { } void FileDialog::_tree_selected() { - + TreeItem *ti=tree->get_selected(); if (!ti) return; Dictionary d=ti->get_metadata(0); - + if (!d["dir"]) { - + file->set_text(d["name"]); } - + } void FileDialog::_tree_dc_selected() { - + TreeItem *ti=tree->get_selected(); if (!ti) return; - + Dictionary d=ti->get_metadata(0); if (d["dir"]) { - + dir_access->change_dir(d["name"]); if (mode==MODE_OPEN_FILE || mode==MODE_OPEN_FILES || mode==MODE_OPEN_DIR) file->set_text(""); call_deferred("_update_file_list"); call_deferred("_update_dir"); } else { - + _action_pressed(); } } void FileDialog::update_file_list() { - + tree->clear(); dir_access->list_dir_begin(); - + TreeItem *root = tree->create_item(); Ref<Texture> folder = get_icon("folder"); List<String> files; List<String> dirs; - + bool isdir; bool ishidden; bool show_hidden = show_hidden_files; @@ -340,12 +340,12 @@ void FileDialog::update_file_list() { dirs.push_back(item); } } - + dirs.sort_custom<NoCaseComparator>(); files.sort_custom<NoCaseComparator>(); - + while(!dirs.empty()) { - + if (dirs.front()->get()!=".") { TreeItem *ti=tree->create_item(root); ti->set_text(0,dirs.front()->get()+"/"); @@ -356,23 +356,23 @@ void FileDialog::update_file_list() { ti->set_metadata(0,d); } dirs.pop_front(); - + } - + dirs.clear(); - + List<String> patterns; // build filter if (filter->get_selected()==filter->get_item_count()-1) { - - // match all + + // match all } else if (filters.size()>1 && filter->get_selected()==0) { // match all filters for (int i=0;i<filters.size();i++) { - + String f=filters[i].get_slice(";",0); for (int j=0;j<f.get_slice_count(",");j++) { - + patterns.push_back(f.get_slice(",",j).strip_edges()); } } @@ -380,34 +380,34 @@ void FileDialog::update_file_list() { int idx=filter->get_selected(); if (filters.size()>1) idx--; - + if (idx>=0 && idx<filters.size()) { - + String f=filters[idx].get_slice(";",0); for (int j=0;j<f.get_slice_count(",");j++) { - + patterns.push_back(f.get_slice(",",j).strip_edges()); - } + } } } String base_dir = dir_access->get_current_dir(); - - + + while(!files.empty()) { - + bool match=patterns.empty(); - + for(List<String>::Element *E=patterns.front();E;E=E->next()) { - + if (files.front()->get().matchn(E->get())) { - + match=true; break; } } - + if (match) { TreeItem *ti=tree->create_item(root); ti->set_text(0,files.front()->get()); @@ -426,35 +426,35 @@ void FileDialog::update_file_list() { d["name"]=files.front()->get(); d["dir"]=false; ti->set_metadata(0,d); - + if (file->get_text()==files.front()->get()) ti->select(0); } - + files.pop_front(); } - + if (tree->get_root() && tree->get_root()->get_children()) tree->get_root()->get_children()->select(0); - + files.clear(); - + } void FileDialog::_filter_selected(int) { - + update_file_list(); } void FileDialog::update_filters() { - + filter->clear(); - + if (filters.size()>1) { String all_filters; const int max_filters=5; - + for(int i=0;i<MIN( max_filters, filters.size()) ;i++) { String flt=filters[i].get_slice(";",0); if (i>0) @@ -464,11 +464,11 @@ void FileDialog::update_filters() { if (max_filters<filters.size()) all_filters+=", ..."; - + filter->add_item("All Recognized ( "+all_filters+" )"); } for(int i=0;i<filters.size();i++) { - + String flt=filters[i].get_slice(";",0).strip_edges(); String desc=filters[i].get_slice(";",1).strip_edges(); if (desc.length()) @@ -476,46 +476,46 @@ void FileDialog::update_filters() { else filter->add_item("( "+flt+" )"); } - + filter->add_item("All Files (*)"); - + } void FileDialog::clear_filters() { - + filters.clear(); update_filters(); invalidate(); } void FileDialog::add_filter(const String& p_filter) { - + filters.push_back(p_filter); update_filters(); invalidate(); - + } String FileDialog::get_current_dir() const { - - return dir->get_text(); + + return dir->get_text(); } String FileDialog::get_current_file() const { - + return file->get_text(); } String FileDialog::get_current_path() const { - + return dir->get_text().plus_file(file->get_text()); } void FileDialog::set_current_dir(const String& p_dir) { - + dir_access->change_dir(p_dir); update_dir(); invalidate(); - + } void FileDialog::set_current_file(const String& p_file) { - + file->set_text(p_file); update_dir(); invalidate(); @@ -525,18 +525,18 @@ void FileDialog::set_current_file(const String& p_file) { file->grab_focus(); } - + } void FileDialog::set_current_path(const String& p_path) { - + if (!p_path.size()) return; int pos=MAX( p_path.find_last("/"), p_path.find_last("\\") ); if (pos==-1) { - + set_current_file(p_path); } else { - + String dir=p_path.substr(0,pos); String file=p_path.substr(pos+1,p_path.length()); set_current_dir(dir); @@ -546,10 +546,10 @@ void FileDialog::set_current_path(const String& p_path) { void FileDialog::set_mode(Mode p_mode) { - + mode=p_mode; switch(mode) { - + case MODE_OPEN_FILE: get_ok()->set_text("Open"); set_title("Open a File"); makedir->hide(); break; case MODE_OPEN_FILES: get_ok()->set_text("Open"); set_title("Open File(s)"); makedir->hide(); break; case MODE_SAVE_FILE: get_ok()->set_text("Save"); set_title("Save a File"); makedir->show(); break; @@ -565,7 +565,7 @@ void FileDialog::set_mode(Mode p_mode) { } FileDialog::Mode FileDialog::get_mode() const { - + return mode; } @@ -655,7 +655,7 @@ void FileDialog::_update_drives() { drives->show(); for(int i=0;i<dir_access->get_drive_count();i++) { - String d = dir_access->get_drive(i); + String d = dir_access->get_drive(i); drives->add_item(dir_access->get_drive(i)); } @@ -668,7 +668,7 @@ bool FileDialog::default_show_hidden_files=false; void FileDialog::_bind_methods() { - + ObjectTypeDB::bind_method(_MD("_unhandled_input"),&FileDialog::_unhandled_input); ObjectTypeDB::bind_method(_MD("_tree_selected"),&FileDialog::_tree_selected); @@ -679,7 +679,7 @@ void FileDialog::_bind_methods() { ObjectTypeDB::bind_method(_MD("_cancel_pressed"),&FileDialog::_cancel_pressed); ObjectTypeDB::bind_method(_MD("_filter_selected"),&FileDialog::_filter_selected); ObjectTypeDB::bind_method(_MD("_save_confirm_pressed"),&FileDialog::_save_confirm_pressed); - + ObjectTypeDB::bind_method(_MD("clear_filters"),&FileDialog::clear_filters); ObjectTypeDB::bind_method(_MD("add_filter","filter"),&FileDialog::add_filter); ObjectTypeDB::bind_method(_MD("get_current_dir"),&FileDialog::get_current_dir); @@ -742,7 +742,7 @@ FileDialog::FileDialog() { mode=MODE_SAVE_FILE; set_title("Save a File"); - + dir = memnew(LineEdit); HBoxContainer *pathhb = memnew( HBoxContainer ); pathhb->add_child(dir); @@ -760,17 +760,17 @@ FileDialog::FileDialog() { makedir->set_text("Create Folder"); makedir->connect("pressed",this,"_make_dir"); pathhb->add_child(makedir); - + vbc->add_margin_child("Path:",pathhb); - + tree = memnew(Tree); tree->set_hide_root(true); vbc->add_margin_child("Directories & Files:",tree,true); - + file = memnew(LineEdit); //add_child(file); vbc->add_margin_child("File:",file); - + filter = memnew( OptionButton ); //add_child(filter); @@ -781,7 +781,7 @@ FileDialog::FileDialog() { access=ACCESS_RESOURCES; _update_drives(); - + connect("confirmed", this,"_action_pressed"); //cancel->connect("pressed", this,"_cancel_pressed"); tree->connect("cell_selected", this,"_tree_selected",varray(),CONNECT_DEFERRED); @@ -790,12 +790,12 @@ FileDialog::FileDialog() { file->connect("text_entered", this,"_file_entered"); filter->connect("item_selected", this,"_filter_selected"); - + confirm_save = memnew( ConfirmationDialog ); confirm_save->set_as_toplevel(true); add_child(confirm_save); - + confirm_save->connect("confirmed", this,"_save_confirm_pressed"); makedialog = memnew( ConfirmationDialog ); @@ -828,12 +828,12 @@ FileDialog::FileDialog() { invalidated=true; if (register_func) register_func(this); - + } FileDialog::~FileDialog() { - + if (unregister_func) unregister_func(this); memdelete(dir_access); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index b71a157fa7..2042adbc20 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -41,9 +41,9 @@ @author Juan Linietsky <reduzio@gmail.com> */ class FileDialog : public ConfirmationDialog { - + OBJ_TYPE( FileDialog, ConfirmationDialog ); - + public: enum Access { @@ -89,7 +89,7 @@ private: ConfirmationDialog *confirm_save; ToolButton *refresh; - + Vector<String> filters; @@ -97,13 +97,13 @@ private: bool show_hidden_files; bool invalidated; - + void update_dir(); void update_file_list(); void update_filters(); - + void _tree_selected(); - + void _select_drive(int p_idx); void _tree_dc_selected(); void _dir_entered(String p_dir); @@ -122,18 +122,18 @@ private: virtual void _post_popup(); protected: - + void _notification(int p_what); static void _bind_methods(); //bind helpers public: - + void clear_filters(); void add_filter(const String& p_filter); void set_enable_multiple_selection(bool p_enable); Vector<String> get_selected_files() const; - + String get_current_dir() const; String get_current_file() const; String get_current_path() const; @@ -156,8 +156,8 @@ public: static void set_default_show_hidden_files(bool p_show); void invalidate(); - - FileDialog(); + + FileDialog(); ~FileDialog(); }; diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h index a189c10046..8a7721b9b5 100644 --- a/scene/gui/graph_edit.h +++ b/scene/gui/graph_edit.h @@ -118,7 +118,7 @@ public: void set_right_disconnects(bool p_enable); bool is_right_disconnects_enabled() const; - + Vector2 get_scroll_ofs() const; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 2a62ab30fc..3953ef06a5 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -36,20 +36,20 @@ void LineEdit::_input_event(InputEvent p_event) { switch(p_event.type) { - + case InputEvent::MOUSE_BUTTON: { - + const InputEventMouseButton &b = p_event.mouse_button; if (b.button_index!=1) break; - + if (b.pressed) { - + set_cursor_at_pixel_pos(b.x); - + if (b.doubleclick) { - + selection.enabled=true; selection.begin=0; selection.end=text.length(); @@ -57,9 +57,9 @@ void LineEdit::_input_event(InputEvent p_event) { } selection.drag_attempt=false; - + if ((cursor_pos<selection.begin) || (cursor_pos>selection.end) || !selection.enabled) { - + selection_clear(); selection.cursor_start=cursor_pos; selection.creating=true; @@ -67,13 +67,13 @@ void LineEdit::_input_event(InputEvent p_event) { selection.drag_attempt=true; } - + // if (!editable) // non_editable_clicked_signal.call(); update(); - + } else { - + if ( (!selection.creating) && (!selection.doubleclick)) { selection_clear(); } @@ -83,29 +83,29 @@ void LineEdit::_input_event(InputEvent p_event) { if (OS::get_singleton()->has_virtual_keyboard()) OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect()); } - - update(); + + update(); } break; case InputEvent::MOUSE_MOTION: { - + const InputEventMouseMotion& m=p_event.mouse_motion; - + if (m.button_mask&1) { - + if (selection.creating) { set_cursor_at_pixel_pos(m.x); selection_fill_at_cursor(); } } - + } break; case InputEvent::KEY: { - + const InputEventKey &k =p_event.key; - + if (!k.pressed) return; - unsigned int code = k.scancode; + unsigned int code = k.scancode; if (k.mod.command) { @@ -346,11 +346,11 @@ void LineEdit::_input_event(InputEvent p_event) { } - + return; - + } break; - + } } @@ -405,30 +405,30 @@ void LineEdit::drop_data(const Point2& p_point,const Variant& p_data){ void LineEdit::_notification(int p_what) { - + switch(p_what) { - + case NOTIFICATION_RESIZED: { - + set_cursor_pos( get_cursor_pos() ); - + } break; case NOTIFICATION_DRAW: { - + int width,height; - + Size2 size=get_size(); width=size.width; height=size.height; - + RID ci = get_canvas_item(); - + Ref<StyleBox> style = get_stylebox("normal"); if (!is_editable()) style=get_stylebox("read_only"); Ref<Font> font=get_font("font"); - + style->draw( ci, Rect2( Point2(), size ) ); if (has_focus()) { @@ -439,7 +439,7 @@ void LineEdit::_notification(int p_what) { int x_ofs=0; switch (align) { - + case ALIGN_FILL: case ALIGN_LEFT: { @@ -457,19 +457,19 @@ void LineEdit::_notification(int p_what) { int ofs_max=width-style->get_minimum_size().width; int char_ofs=window_pos; - + int y_area=height-style->get_minimum_size().height; int y_ofs=style->get_offset().y; - + int font_ascent=font->get_ascent(); - + Color selection_color=get_color("selection_color"); Color font_color=get_color("font_color"); Color font_color_selected=get_color("font_color_selected"); Color cursor_color=get_color("cursor_color"); - + while(true) { - + //end of string, break! if (char_ofs>=text.length()) break; @@ -477,32 +477,32 @@ void LineEdit::_notification(int p_what) { CharType cchar=pass?'*':text[char_ofs]; CharType next=pass?'*':text[char_ofs+1]; int char_width=font->get_char_size( cchar,next ).width; - + // end of widget, break! if ((x_ofs + char_width) > ofs_max) break; - - + + bool selected=selection.enabled && char_ofs>=selection.begin && char_ofs<selection.end; - + if (selected) VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, y_area)), selection_color); - + font->draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, selected ? font_color_selected : font_color); - + if (char_ofs==cursor_pos && has_focus()) VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2( Point2( x_ofs , y_ofs ), Size2( 1, y_area ) ), cursor_color ); - + x_ofs+=char_width; char_ofs++; } if (char_ofs==cursor_pos && has_focus()) //may be at the end VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2( - Point2( x_ofs , y_ofs ), Size2( 1, y_area ) ), cursor_color ); - + Point2( x_ofs , y_ofs ), Size2( 1, y_area ) ), cursor_color ); + } break; case NOTIFICATION_FOCUS_ENTER: { @@ -521,15 +521,15 @@ void LineEdit::_notification(int p_what) { } void LineEdit::copy_text() { - + if(selection.enabled) { - + OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin)); } } void LineEdit::cut_text() { - + if(selection.enabled) { undo_text = text; OS::get_singleton()->set_clipboard(text.substr(selection.begin, selection.end - selection.begin)); @@ -538,9 +538,9 @@ void LineEdit::cut_text() { } void LineEdit::paste_text() { - + String paste_buffer = OS::get_singleton()->get_clipboard(); - + if(paste_buffer != "") { if(selection.enabled) selection_delete(); @@ -550,28 +550,28 @@ void LineEdit::paste_text() { _change_notify("text"); } - + } void LineEdit::shift_selection_check_pre(bool p_shift) { - + if (!selection.old_shift && p_shift) { selection.cursor_start=cursor_pos; } if (!p_shift) selection_clear(); - + } void LineEdit::shift_selection_check_post(bool p_shift) { - + if (p_shift) selection_fill_at_cursor(); } void LineEdit::set_cursor_at_pixel_pos(int p_x) { - + Ref<Font> font = get_font("font"); int ofs = window_pos; Ref<StyleBox> style = get_stylebox("normal"); @@ -579,10 +579,10 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) { Size2 size = get_size(); switch (align) { - + case ALIGN_FILL: case ALIGN_LEFT: { - + pixel_ofs = int(style->get_offset().x); } break; case ALIGN_CENTER: { @@ -597,30 +597,30 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) { while (ofs<text.length()) { - + int char_w = 0; if (font != NULL) { char_w = font->get_char_size(text[ofs]).width; } pixel_ofs+=char_w; - + if (pixel_ofs > p_x) { //found what we look for - - + + if ( (pixel_ofs-p_x) < (char_w >> 1 ) ) { - + ofs+=1; } - + break; } - - + + ofs++; } - + set_cursor_pos( ofs ); - + /* int new_cursor_pos=p_x; int charwidth=draw_area->get_font_char_width(' ',0); @@ -631,29 +631,29 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) { void LineEdit::delete_char() { - + if ((text.length()<=0) || (cursor_pos==0)) return; - + Ref<Font> font = get_font("font"); if (font != NULL) { cached_width -= font->get_char_size(text[cursor_pos - 1]).width; } - + text.erase( cursor_pos-1, 1 ); - + set_cursor_pos(get_cursor_pos()-1); - + if (cursor_pos==window_pos) { - + // set_window_pos(cursor_pos-get_window_length()); } - + emit_signal("text_changed",text); _change_notify("text"); } void LineEdit::set_text(String p_text) { - + clear_internal(); append_at_cursor(p_text); update(); @@ -662,86 +662,86 @@ void LineEdit::set_text(String p_text) { } void LineEdit::clear() { - + clear_internal(); } String LineEdit::get_text() const { - + return text; } void LineEdit::set_cursor_pos(int p_pos) { - + if (p_pos>(int)text.length()) p_pos=text.length(); - + if(p_pos<0) p_pos=0; - - - + + + cursor_pos=p_pos; - + // if (cursor_pos>(window_pos+get_window_length())) { // set_window_pos(cursor_pos-get_window_lengt//h()); // } - + if (!is_inside_tree()) { - + window_pos=cursor_pos; return; } - + Ref<StyleBox> style = get_stylebox("normal"); Ref<Font> font=get_font("font"); - + if (cursor_pos<window_pos) { /* Adjust window if cursor goes too much to the left */ set_window_pos(cursor_pos); } else if (cursor_pos>window_pos) { /* Adjust window if cursor goes too much to the right */ int window_width=get_size().width-style->get_minimum_size().width; - + if (window_width<0) return; int width_to_cursor=0; int wp=window_pos; - + if (font != NULL) { for (int i=window_pos;i<cursor_pos;i++) width_to_cursor+=font->get_char_size( text[i] ).width; - + while (width_to_cursor >= window_width && wp < text.length()) { width_to_cursor -= font->get_char_size(text[wp]).width; wp++; } } - + if (wp!=window_pos) set_window_pos( wp ); - + } update(); } int LineEdit::get_cursor_pos() const { - + return cursor_pos; } void LineEdit::set_window_pos(int p_pos) { - + window_pos=p_pos; if (window_pos<0) window_pos=0; } void LineEdit::append_at_cursor(String p_text) { - - + + if ( ( max_length <= 0 ) || (text.length()+p_text.length() <= max_length)) { - + undo_text = text; Ref<Font> font = get_font("font"); @@ -761,7 +761,7 @@ void LineEdit::append_at_cursor(String p_text) { } void LineEdit::clear_internal() { - + cached_width = 0; cursor_pos=0; window_pos=0; @@ -771,21 +771,21 @@ void LineEdit::clear_internal() { } Size2 LineEdit::get_minimum_size() const { - + Ref<StyleBox> style = get_stylebox("normal"); Ref<Font> font=get_font("font"); - + Size2 min=style->get_minimum_size(); min.height+=font->get_height(); min.width+=get_constant("minimum_spaces")*font->get_char_size(' ').x; - + return min; } /* selection */ void LineEdit::selection_clear() { - + selection.begin=0; selection.end=0; selection.cursor_start=0; @@ -798,9 +798,9 @@ void LineEdit::selection_clear() { void LineEdit::selection_delete() { - + if (selection.enabled) { - + undo_text = text; if (text.size() > 0) @@ -818,80 +818,80 @@ void LineEdit::selection_delete() { text.erase(selection.begin,selection.end-selection.begin); cursor_pos-=CLAMP( cursor_pos-selection.begin, 0, selection.end-selection.begin); - + if (cursor_pos>=text.length()) { - + cursor_pos=text.length(); } if (window_pos>cursor_pos) { - + window_pos=cursor_pos; } - + emit_signal("text_changed",text); _change_notify("text"); }; - + selection_clear(); } void LineEdit::set_max_length(int p_max_length) { - + ERR_FAIL_COND(p_max_length<0); max_length = p_max_length; set_text(text); } int LineEdit::get_max_length() const { - + return max_length; } void LineEdit::selection_fill_at_cursor() { - + int aux; - + selection.begin=cursor_pos; selection.end=selection.cursor_start; - + if (selection.end<selection.begin) { aux=selection.end; selection.end=selection.begin; selection.begin=aux; } - + selection.enabled=(selection.begin!=selection.end); } void LineEdit::select_all() { - + if (!text.length()) return; - + selection.begin=0; selection.end=text.length(); selection.enabled=true; update(); - + } void LineEdit::set_editable(bool p_editable) { - + editable=p_editable; update(); } bool LineEdit::is_editable() const { - + return editable; } void LineEdit::set_secret(bool p_secret) { - + pass=p_secret; update(); } bool LineEdit::is_secret() const { - + return pass; } @@ -928,24 +928,24 @@ bool LineEdit::is_text_field() const { } void LineEdit::_bind_methods() { - + ObjectTypeDB::bind_method(_MD("set_align", "align"), &LineEdit::set_align); ObjectTypeDB::bind_method(_MD("get_align"), &LineEdit::get_align); ObjectTypeDB::bind_method(_MD("_input_event"),&LineEdit::_input_event); - ObjectTypeDB::bind_method(_MD("clear"),&LineEdit::clear); - ObjectTypeDB::bind_method(_MD("select_all"),&LineEdit::select_all); + ObjectTypeDB::bind_method(_MD("clear"),&LineEdit::clear); + ObjectTypeDB::bind_method(_MD("select_all"),&LineEdit::select_all); ObjectTypeDB::bind_method(_MD("set_text","text"),&LineEdit::set_text); - ObjectTypeDB::bind_method(_MD("get_text"),&LineEdit::get_text); + ObjectTypeDB::bind_method(_MD("get_text"),&LineEdit::get_text); ObjectTypeDB::bind_method(_MD("set_cursor_pos","pos"),&LineEdit::set_cursor_pos); - ObjectTypeDB::bind_method(_MD("get_cursor_pos"),&LineEdit::get_cursor_pos); + ObjectTypeDB::bind_method(_MD("get_cursor_pos"),&LineEdit::get_cursor_pos); ObjectTypeDB::bind_method(_MD("set_max_length","chars"),&LineEdit::set_max_length); - ObjectTypeDB::bind_method(_MD("get_max_length"),&LineEdit::get_max_length); + ObjectTypeDB::bind_method(_MD("get_max_length"),&LineEdit::get_max_length); ObjectTypeDB::bind_method(_MD("append_at_cursor","text"),&LineEdit::append_at_cursor); ObjectTypeDB::bind_method(_MD("set_editable","enabled"),&LineEdit::set_editable); - ObjectTypeDB::bind_method(_MD("is_editable"),&LineEdit::is_editable); + ObjectTypeDB::bind_method(_MD("is_editable"),&LineEdit::is_editable); ObjectTypeDB::bind_method(_MD("set_secret","enabled"),&LineEdit::set_secret); - ObjectTypeDB::bind_method(_MD("is_secret"),&LineEdit::is_secret); + ObjectTypeDB::bind_method(_MD("is_secret"),&LineEdit::is_secret); ObjectTypeDB::bind_method(_MD("select","from","to"),&LineEdit::select,DEFVAL(0),DEFVAL(-1)); ADD_SIGNAL( MethodInfo("text_changed", PropertyInfo( Variant::STRING, "text" )) ); @@ -964,25 +964,25 @@ void LineEdit::_bind_methods() { } LineEdit::LineEdit() { - + align = ALIGN_LEFT; cached_width = 0; cursor_pos=0; window_pos=0; max_length = 0; pass=false; - + selection_clear(); set_focus_mode( FOCUS_ALL ); editable=true; set_default_cursor_shape(CURSOR_IBEAM); set_stop_mouse(true); - - + + } LineEdit::~LineEdit() { - - + + } diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index bf6459361a..207c6b115b 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -34,7 +34,7 @@ @author Juan Linietsky <reduzio@gmail.com> */ class LineEdit : public Control { - + OBJ_TYPE( LineEdit, Control ); public: @@ -50,18 +50,18 @@ private: bool editable; bool pass; - + String undo_text; String text; - + int cursor_pos; int window_pos; int max_length; // 0 for no maximum int cached_width; - + struct Selection { - + int begin; int end; int cursor_start; @@ -71,41 +71,41 @@ private: bool doubleclick; bool drag_attempt; } selection; - + void shift_selection_check_pre(bool); void shift_selection_check_post(bool); - + void selection_clear(); void selection_fill_at_cursor(); void selection_delete(); void set_window_pos(int p_pos); - + void set_cursor_at_pixel_pos(int p_x); - + void clear_internal(); void changed_internal(); - + void copy_text(); void cut_text(); void paste_text(); - + void _input_event(InputEvent p_event); void _notification(int p_what); - -protected: - static void _bind_methods(); + +protected: + static void _bind_methods(); public: void set_align(Align p_align); Align get_align() const; - + virtual Variant get_drag_data(const Point2& p_point); virtual bool can_drop_data(const Point2& p_point,const Variant& p_data) const; virtual void drop_data(const Point2& p_point,const Variant& p_data); - + void select_all(); - + void delete_char(); void set_text(String p_text); String get_text() const; @@ -115,11 +115,11 @@ public: int get_max_length() const; void append_at_cursor(String p_text); void clear(); - - + + void set_editable(bool p_editable); bool is_editable() const; - + void set_secret(bool p_secret); bool is_secret() const; @@ -130,7 +130,7 @@ public: virtual bool is_text_field() const; LineEdit(); ~LineEdit(); - + }; diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 26540843de..cb8806e2ef 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -76,18 +76,18 @@ void MenuButton::_unhandled_key_input(InputEvent p_event) { void MenuButton::pressed() { - + emit_signal("about_to_show"); Size2 size=get_size(); Point2 gp = get_global_pos(); popup->set_global_pos( gp + Size2( 0, size.height ) ); - popup->set_size( Size2( size.width, 0) ); + popup->set_size( Size2( size.width, 0) ); popup->set_parent_rect( Rect2(Point2(gp-popup->get_global_pos()),get_size())); popup->popup(); popup->call_deferred("grab_click_focus"); popup->set_invalidate_click_until_motion(); - + } void MenuButton::_input_event(InputEvent p_event) { @@ -111,7 +111,7 @@ void MenuButton::_input_event(InputEvent p_event) { } PopupMenu *MenuButton::get_popup() { - + return popup; } @@ -136,7 +136,7 @@ void MenuButton::_bind_methods() { ADD_SIGNAL( MethodInfo("about_to_show") ); } MenuButton::MenuButton() { - + set_flat(true); set_focus_mode(FOCUS_NONE); diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h index 2df632811f..650e4aba5c 100644 --- a/scene/gui/menu_button.h +++ b/scene/gui/menu_button.h @@ -35,24 +35,24 @@ @author Juan Linietsky <reduzio@gmail.com> */ class MenuButton : public Button { - + OBJ_TYPE( MenuButton, Button ); bool clicked; PopupMenu *popup; - virtual void pressed(); + virtual void pressed(); void _unhandled_key_input(InputEvent p_event); Array _get_items() const; void _set_items(const Array& p_items); void _input_event(InputEvent p_event); -protected: - +protected: + - static void _bind_methods(); + static void _bind_methods(); public: - + PopupMenu *get_popup(); MenuButton(); ~MenuButton(); diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 5c8e5a7381..587a68ae37 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -55,7 +55,7 @@ void OptionButton::_notification(int p_what) { Ref<Texture> arrow = Control::get_icon("arrow"); Ref<StyleBox> normal = get_stylebox("normal" ); - Size2 size = get_size(); + Size2 size = get_size(); Point2 ofs( size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height-arrow->get_height())/2))); arrow->draw(ci,ofs); @@ -66,7 +66,7 @@ void OptionButton::_notification(int p_what) { void OptionButton::_selected(int p_which) { - + int selid = -1; for (int i=0;i<popup->get_item_count();i++) { @@ -89,39 +89,39 @@ void OptionButton::_selected(int p_which) { void OptionButton::pressed() { - + Size2 size=get_size(); popup->set_global_pos( get_global_pos() + Size2( 0, size.height ) ); popup->set_size( Size2( size.width, 0) ); - + popup->popup(); } void OptionButton::add_icon_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID) { - - popup->add_icon_check_item( p_icon, p_label, p_ID ); + + popup->add_icon_check_item( p_icon, p_label, p_ID ); if (popup->get_item_count()==1) select(0); } void OptionButton::add_item(const String& p_label,int p_ID) { - - popup->add_check_item( p_label, p_ID ); + + popup->add_check_item( p_label, p_ID ); if (popup->get_item_count()==1) - select(0); + select(0); } void OptionButton::set_item_text(int p_idx,const String& p_text) { - + popup->set_item_text(p_idx,p_text); - + } void OptionButton::set_item_icon(int p_idx,const Ref<Texture>& p_icon) { - + popup->set_item_icon(p_idx,p_icon); - + } void OptionButton::set_item_ID(int p_idx,int p_ID) { - + popup->set_item_ID(p_idx,p_ID); } @@ -136,17 +136,17 @@ void OptionButton::set_item_disabled(int p_idx,bool p_disabled) { } String OptionButton::get_item_text(int p_idx) const { - + return popup->get_item_text(p_idx); } Ref<Texture> OptionButton::get_item_icon(int p_idx) const { - + return popup->get_item_icon(p_idx); } int OptionButton::get_item_ID(int p_idx) const { - + return popup->get_item_ID(p_idx); } Variant OptionButton::get_item_metadata(int p_idx) const { @@ -161,17 +161,17 @@ bool OptionButton::is_item_disabled(int p_idx) const { int OptionButton::get_item_count() const { - + return popup->get_item_count(); } void OptionButton::add_separator() { - + popup->add_separator(); } void OptionButton::clear() { - + popup->clear(); set_text(""); current=-1; @@ -210,12 +210,12 @@ void OptionButton::_select_int(int p_which) { } void OptionButton::select(int p_idx) { - + _select(p_idx,false); } int OptionButton::get_selected() const { - + return current; } @@ -286,9 +286,9 @@ void OptionButton::get_translatable_strings(List<String> *p_strings) const { void OptionButton::_bind_methods() { - + ObjectTypeDB::bind_method(_MD("_selected"),&OptionButton::_selected); - + ObjectTypeDB::bind_method(_MD("add_item","label","id"),&OptionButton::add_item,DEFVAL(-1)); ObjectTypeDB::bind_method(_MD("add_icon_item","texture:Texture","label","id"),&OptionButton::add_icon_item); ObjectTypeDB::bind_method(_MD("set_item_text","idx","text"),&OptionButton::set_item_text); @@ -305,7 +305,7 @@ void OptionButton::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_separator"),&OptionButton::add_separator); ObjectTypeDB::bind_method(_MD("clear"),&OptionButton::clear); ObjectTypeDB::bind_method(_MD("select","idx"),&OptionButton::select); - ObjectTypeDB::bind_method(_MD("get_selected"),&OptionButton::get_selected); + ObjectTypeDB::bind_method(_MD("get_selected"),&OptionButton::get_selected); ObjectTypeDB::bind_method(_MD("get_selected_ID"),&OptionButton::get_selected_ID); ObjectTypeDB::bind_method(_MD("get_selected_metadata"),&OptionButton::get_selected_metadata); ObjectTypeDB::bind_method(_MD("remove_item","idx"),&OptionButton::remove_item); @@ -320,23 +320,23 @@ void OptionButton::_bind_methods() { } OptionButton::OptionButton() { - - + + popup = memnew( PopupMenu ); popup->hide(); popup->set_as_toplevel(true); add_child(popup); popup->connect("item_pressed", this,"_selected"); - + current=-1; set_text_align(ALIGN_LEFT); } OptionButton::~OptionButton() { - - + + } diff --git a/scene/gui/option_button.h b/scene/gui/option_button.h index 34e2bdd384..70ebc66a46 100644 --- a/scene/gui/option_button.h +++ b/scene/gui/option_button.h @@ -35,12 +35,12 @@ @author Juan Linietsky <reduzio@gmail.com> */ class OptionButton : public Button { - + OBJ_TYPE( OptionButton, Button ); - + PopupMenu *popup; int current; - + void _selected(int p_which); void _select(int p_which,bool p_emit=false); void _select_int(int p_which); @@ -55,10 +55,10 @@ protected: void _notification(int p_what); static void _bind_methods(); public: - + void add_icon_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1); void add_item(const String& p_label,int p_ID=-1); - + void set_item_text(int p_idx,const String& p_text); void set_item_icon(int p_idx,const Ref<Texture>& p_icon); void set_item_ID(int p_idx,int p_ID); @@ -73,11 +73,11 @@ public: int get_item_count() const; - + void add_separator(); - + void clear(); - + void select(int p_idx); int get_selected() const; int get_selected_ID() const; @@ -87,7 +87,7 @@ public: virtual void get_translatable_strings(List<String> *p_strings) const; - OptionButton(); + OptionButton(); ~OptionButton(); }; diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp index d40daa972c..682ea5b92c 100644 --- a/scene/gui/panel.cpp +++ b/scene/gui/panel.cpp @@ -30,7 +30,7 @@ #include "print_string.h" void Panel::_notification(int p_what) { - + if (p_what==NOTIFICATION_DRAW) { RID ci = get_canvas_item(); @@ -40,7 +40,7 @@ void Panel::_notification(int p_what) { } Panel::Panel() { - + set_stop_mouse(true); } diff --git a/scene/gui/panel.h b/scene/gui/panel.h index ee4bcd139e..efa9ebcaa0 100644 --- a/scene/gui/panel.h +++ b/scene/gui/panel.h @@ -34,13 +34,13 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Panel : public Control{ - + OBJ_TYPE(Panel,Control); protected: void _notification(int p_what); public: - Panel(); + Panel(); ~Panel(); }; diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 1f04985ec6..0d9a76937c 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -32,12 +32,12 @@ void Popup::_input_event(InputEvent p_event) { - + } void Popup::_notification(int p_what) { - + if (p_what==NOTIFICATION_VISIBILITY_CHANGED) { if (popped_up && !is_visible()) { popped_up=false; @@ -58,11 +58,11 @@ void Popup::_notification(int p_what) { } void Popup::_fix_size() { - + #if 0 Point2 pos = get_pos(); - Size2 size = get_size(); + Size2 size = get_size(); Point2 window_size = window==this ? get_parent_area_size() :window->get_size(); #else @@ -75,7 +75,7 @@ void Popup::_fix_size() { pos.x=window_size.width-size.width; if (pos.x<0) pos.x=0; - + if (pos.y+size.height > window_size.height) pos.y=window_size.height-size.height; if (pos.y<0) @@ -179,7 +179,7 @@ void Popup::popup_centered_minsize(const Size2& p_minsize) { } void Popup::popup_centered(const Size2& p_size) { - + Point2 window_size = get_viewport_rect().size; emit_signal("about_to_show"); @@ -203,9 +203,9 @@ void Popup::popup_centered(const Size2& p_size) { } void Popup::popup_centered_ratio(float p_screen_ratio) { - - - + + + emit_signal("about_to_show"); Rect2 rect; @@ -214,7 +214,7 @@ void Popup::popup_centered_ratio(float p_screen_ratio) { rect.pos = ((window_size-rect.size)/2.0).floor(); set_pos( rect.pos ); set_size( rect.size ); - + show_modal(exclusive); _fix_size(); diff --git a/scene/gui/popup.h b/scene/gui/popup.h index 9c66e6d7bd..8afcdc01db 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -35,12 +35,12 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Popup : public Control { - + OBJ_TYPE( Popup, Control ); bool exclusive; bool popped_up; - + protected: virtual void _post_popup() {} @@ -48,14 +48,14 @@ protected: void _input_event(InputEvent p_event); void _notification(int p_what); void _fix_size(); - static void _bind_methods(); + static void _bind_methods(); public: enum { NOTIFICATION_POST_POPUP=80, NOTIFICATION_POPUP_HIDE=81 }; - + void set_exclusive(bool p_exclusive); bool is_exclusive() const; @@ -65,8 +65,8 @@ public: void set_as_minsize(); virtual void popup(); - - Popup(); + + Popup(); ~Popup(); }; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index a93d8e524f..3329d24890 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -59,34 +59,34 @@ Size2 PopupMenu::get_minimum_size() const { int vseparation = get_constant("vseparation"); int hseparation = get_constant("hseparation"); - + Size2 minsize = get_stylebox("panel")->get_minimum_size(); Ref<Font> font = get_font("font"); - + float max_w=0; int font_h = font->get_height(); int check_w = get_icon("checked")->get_width(); int accel_max_w=0; - + for (int i=0;i<items.size();i++) { - + Size2 size; if (!items[i].icon.is_null()) { - + Size2 icon_size = items[i].icon->get_size(); size.height = MAX( icon_size.height, font_h ); size.width+=icon_size.width; size.width+=hseparation; } else { - + size.height=font_h; } - + if (items[i].checkable) { - + size.width+=check_w+hseparation; } - + size.width+=font->get_string_size(items[i].text).width; if (i>0) size.height+=vseparation; @@ -100,11 +100,11 @@ Size2 PopupMenu::get_minimum_size() const { minsize.height+=size.height; max_w = MAX( max_w, size.width ); - + } - + minsize.width+=max_w+accel_max_w; - + return minsize; } @@ -115,41 +115,41 @@ int PopupMenu::_get_mouse_over(const Point2& p_over) const { return -1; Ref<StyleBox> style = get_stylebox("panel"); - + Point2 ofs=style->get_offset(); - + if (ofs.y>p_over.y) return -1; - - - Ref<Font> font = get_font("font"); + + + Ref<Font> font = get_font("font"); int vseparation = get_constant("vseparation"); // int hseparation = get_constant("hseparation"); float font_h=font->get_height(); - + for (int i=0;i<items.size();i++) { - + if (i>0) ofs.y+=vseparation; float h; - + if (!items[i].icon.is_null()) { - + Size2 icon_size = items[i].icon->get_size(); h = MAX( icon_size.height, font_h ); } else { - + h=font_h; } - + ofs.y+=h; if (p_over.y < ofs.y) { return i; - } + } } - + return -1; } @@ -271,11 +271,11 @@ void PopupMenu::_input_event(const InputEvent &p_event) { } break; case InputEvent::MOUSE_BUTTON: { - - + + const InputEventMouseButton &b=p_event.mouse_button; if (b.pressed) - break; + break; switch(b.button_index) { @@ -347,11 +347,11 @@ void PopupMenu::_input_event(const InputEvent &p_event) { } break; } - + //update(); } break; case InputEvent::MOUSE_MOTION: { - + if (invalidated_click) { moved+=Vector2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y); @@ -409,13 +409,13 @@ bool PopupMenu::has_point(const Point2& p_point) const { void PopupMenu::_notification(int p_what) { switch(p_what) { - + case NOTIFICATION_DRAW: { - + RID ci = get_canvas_item(); Size2 size=get_size(); - + Ref<StyleBox> style = get_stylebox("panel"); Ref<StyleBox> hover = get_stylebox("hover"); Ref<Font> font = get_font("font"); @@ -423,7 +423,7 @@ void PopupMenu::_notification(int p_what) { Ref<Texture> uncheck = get_icon("unchecked"); Ref<Texture> submenu= get_icon("submenu"); Ref<StyleBox> separator = get_stylebox("separator"); - + style->draw( ci, Rect2( Point2(), get_size() ) ); Point2 ofs=style->get_offset(); int vseparation = get_constant("vseparation"); @@ -433,36 +433,36 @@ void PopupMenu::_notification(int p_what) { Color font_color_accel = get_color("font_color_accel"); Color font_color_hover = get_color("font_color_hover"); float font_h=font->get_height(); - + for (int i=0;i<items.size();i++) { - + if (i>0) ofs.y+=vseparation; Point2 item_ofs=ofs; float h; Size2 icon_size; - + if (!items[i].icon.is_null()) { - + icon_size = items[i].icon->get_size(); h = MAX( icon_size.height, font_h ); } else { - + h=font_h; } - + if (i==mouse_over) { - + hover->draw(ci, Rect2( ofs+Point2(-hseparation,-vseparation), Size2( get_size().width - style->get_minimum_size().width + hseparation*2, h+vseparation*2 ) )); } - + if (items[i].separator) { - + int sep_h=separator->get_center_size().height+separator->get_minimum_size().height; separator->draw(ci, Rect2( ofs+Point2(0,Math::floor((h-sep_h)/2.0)), Size2( get_size().width - style->get_minimum_size().width , sep_h ) )); - + } - + if (items[i].checkable) { if (items[i].checked) @@ -499,16 +499,16 @@ void PopupMenu::_notification(int p_what) { items[i]._ofs_cache=ofs.y; ofs.y+=h; - + } - + } break; case NOTIFICATION_MOUSE_ENTER: { grab_focus(); } break; case NOTIFICATION_MOUSE_EXIT: { - + if (mouse_over>=0) { mouse_over=-1; update(); @@ -574,7 +574,7 @@ void PopupMenu::set_item_text(int p_idx,const String& p_text) { ERR_FAIL_INDEX(p_idx,items.size()); items[p_idx].text=XL_MESSAGE(p_text); - + update(); } @@ -597,8 +597,8 @@ void PopupMenu::set_item_checked(int p_idx,bool p_checked) { void PopupMenu::set_item_ID(int p_idx,int p_ID) { ERR_FAIL_INDEX(p_idx,items.size()); - items[p_idx].ID=p_ID; - + items[p_idx].ID=p_ID; + update(); } @@ -785,7 +785,7 @@ void PopupMenu::add_separator() { items.push_back(sep); update(); } - + void PopupMenu::clear() { items.clear(); @@ -888,7 +888,7 @@ void PopupMenu::clear_autohide_areas(){ void PopupMenu::_bind_methods() { - ObjectTypeDB::bind_method(_MD("_input_event"),&PopupMenu::_input_event); + ObjectTypeDB::bind_method(_MD("_input_event"),&PopupMenu::_input_event); ObjectTypeDB::bind_method(_MD("add_icon_item","texture","label","id","accel"),&PopupMenu::add_icon_item,DEFVAL(-1),DEFVAL(0)); ObjectTypeDB::bind_method(_MD("add_item","label","id","accel"),&PopupMenu::add_item,DEFVAL(-1),DEFVAL(0)); ObjectTypeDB::bind_method(_MD("add_icon_check_item","texture","label","id","accel"),&PopupMenu::add_icon_check_item,DEFVAL(-1),DEFVAL(0)); @@ -916,7 +916,7 @@ void PopupMenu::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_item_ID","idx"),&PopupMenu::get_item_ID); ObjectTypeDB::bind_method(_MD("get_item_index","id"),&PopupMenu::get_item_index); ObjectTypeDB::bind_method(_MD("get_item_count"),&PopupMenu::get_item_count); - ObjectTypeDB::bind_method(_MD("add_separator"),&PopupMenu::add_separator); + ObjectTypeDB::bind_method(_MD("add_separator"),&PopupMenu::add_separator); ObjectTypeDB::bind_method(_MD("remove_item","idx"),&PopupMenu::remove_item); ObjectTypeDB::bind_method(_MD("clear"),&PopupMenu::clear); @@ -930,7 +930,7 @@ void PopupMenu::_bind_methods() { ADD_SIGNAL( MethodInfo("item_pressed", PropertyInfo( Variant::INT,"ID") ) ); } - + void PopupMenu::set_invalidate_click_until_motion() { moved=Vector2(); @@ -941,7 +941,7 @@ PopupMenu::PopupMenu() { mouse_over=-1; - + set_focus_mode(FOCUS_ALL); set_as_toplevel(true); diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index 624f4f542a..72f8795067 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -37,7 +37,7 @@ class PopupMenu : public Popup { OBJ_TYPE(PopupMenu, Popup ); - + struct Item { Ref<Texture> icon; String text; @@ -45,16 +45,16 @@ class PopupMenu : public Popup { bool checkable; bool separator; bool disabled; - int ID; + int ID; Variant metadata; String submenu; String tooltip; uint32_t accel; int _ofs_cache; - + Item() { checked=false; checkable=false; separator=false; accel=0; disabled=false; _ofs_cache=0; } }; - + Timer *submenu_timer; List<Rect2> autohide_areas; @@ -64,7 +64,7 @@ class PopupMenu : public Popup { Rect2 parent_rect; String _get_accel_text(uint32_t p_accel) const; int _get_mouse_over(const Point2& p_over) const; - virtual Size2 get_minimum_size() const; + virtual Size2 get_minimum_size() const; void _input_event(const InputEvent &p_event); void _activate_submenu(int over); void _submenu_timeout(); @@ -79,11 +79,11 @@ protected: virtual bool has_point(const Point2& p_point) const; -friend class MenuButton; +friend class MenuButton; void _notification(int p_what); - static void _bind_methods(); + static void _bind_methods(); public: - + void add_icon_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1,uint32_t p_accel=0); void add_item(const String& p_label,int p_ID=-1,uint32_t p_accel=0); void add_icon_check_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1,uint32_t p_accel=0); @@ -92,7 +92,7 @@ public: void set_item_text(int p_idx,const String& p_text); void set_item_icon(int p_idx,const Ref<Texture>& p_icon); - void set_item_checked(int p_idx,bool p_checked); + void set_item_checked(int p_idx,bool p_checked); void set_item_ID(int p_idx,int p_ID); void set_item_accelerator(int p_idx,uint32_t p_accel); void set_item_metadata(int p_idx,const Variant& p_meta); @@ -110,7 +110,7 @@ public: uint32_t get_item_accelerator(int p_idx) const; Variant get_item_metadata(int p_idx) const; bool is_item_disabled(int p_idx) const; - String get_item_submenu(int p_ID) const; + String get_item_submenu(int p_ID) const; bool is_item_separator(int p_idx) const; bool is_item_checkable(int p_idx) const; String get_item_tooltip(int p_idx) const; @@ -121,9 +121,9 @@ public: void activate_item(int p_item); void remove_item(int p_idx); - + void add_separator(); - + void clear(); void set_parent_rect(const Rect2& p_rect); @@ -137,7 +137,7 @@ public: void set_invalidate_click_until_motion(); - PopupMenu(); + PopupMenu(); ~PopupMenu(); }; diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index ffcdf98519..b00fcfe42c 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -67,14 +67,14 @@ void Range::Shared::emit_changed(const char *p_what) { void Range::set_val(double p_val) { - + if(_rounded_values){ p_val = Math::round(p_val); } - + if (p_val>shared->max-shared->page) p_val=shared->max-shared->page; - + if (p_val<shared->min) p_val=shared->min; @@ -84,58 +84,58 @@ void Range::set_val(double p_val) { if (shared->val==p_val) return; - + shared->val=p_val; - + shared->emit_value_changed(); } void Range::set_min(double p_min) { - + shared->min=p_min; set_val(shared->val); - + shared->emit_changed("range/min"); } void Range::set_max(double p_max) { - + shared->max=p_max; set_val(shared->val); - + shared->emit_changed("range/max"); } void Range::set_step(double p_step) { - + shared->step=p_step; shared->emit_changed("range/step"); } void Range::set_page(double p_page) { - + shared->page=p_page; set_val(shared->val); - + shared->emit_changed("range/page"); } double Range::get_val() const { - + return shared->val; } double Range::get_min() const { - + return shared->min; } double Range::get_max() const { - + return shared->max; } double Range::get_step() const { - + return shared->step; } double Range::get_page() const { - + return shared->page; } diff --git a/scene/gui/range.h b/scene/gui/range.h index d96ecdfb0b..85c3687b7d 100644 --- a/scene/gui/range.h +++ b/scene/gui/range.h @@ -34,7 +34,7 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Range : public Control { - + OBJ_TYPE( Range, Control ); @@ -57,15 +57,15 @@ class Range : public Control { void _value_changed_notify(); void _changed_notify(const char *p_what=""); -protected: +protected: virtual void _value_changed(double) {} static void _bind_methods(); - + bool _rounded_values; public: - + void set_val(double p_val); void set_min(double p_min); void set_max(double p_max); @@ -89,7 +89,7 @@ public: void share(Range *p_range); void unshare(); - Range(); + Range(); ~Range(); }; diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index d4ac2652dc..98bc0b9434 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -237,7 +237,7 @@ if (m_height > line_height) {\ if (font.is_null()) font=p_base_font; - const CharType *c = text->text.c_str(); + const CharType *c = text->text.c_str(); const CharType *cf=c; int fh=font->get_height(); int ascent = font->get_ascent(); @@ -297,7 +297,7 @@ if (m_height > line_height) {\ fw+=cw; } - end++; + end++; } ENSURE_WIDTH(w); @@ -2058,7 +2058,7 @@ RichTextLabel::RichTextLabel() { scroll_active=true; scroll_w=0; - vscroll = memnew( VScrollBar ); + vscroll = memnew( VScrollBar ); add_child(vscroll); vscroll->set_drag_slave(String("..")); vscroll->set_step(1); diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 0fd4286f38..d8365feb24 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -35,7 +35,7 @@ bool ScrollBar::focus_by_default=false; void ScrollBar::set_can_focus_by_default(bool p_can_focus) { - + focus_by_default=p_can_focus; } @@ -43,14 +43,14 @@ void ScrollBar::_input_event(InputEvent p_event) { switch(p_event.type) { - + case InputEvent::MOUSE_BUTTON: { - + const InputEventMouseButton &b=p_event.mouse_button; accept_event(); if (b.button_index==5 && b.pressed) { - + //if (orientation==VERTICAL) // set_val( get_val() + get_page() / 4.0 ); //else @@ -58,16 +58,16 @@ void ScrollBar::_input_event(InputEvent p_event) { accept_event(); } - + if (b.button_index==4 && b.pressed) { - + //if (orientation==HORIZONTAL) // set_val( get_val() - get_page() / 4.0 ); //else set_val( get_val() - get_page() / 4.0 ); accept_event(); } - + if (b.button_index!=1) return; @@ -78,177 +78,177 @@ void ScrollBar::_input_event(InputEvent p_event) { double ofs = orientation==VERTICAL ? b.y : b.x ; Ref<Texture> decr = get_icon("decrement"); Ref<Texture> incr = get_icon("increment"); - + double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation==VERTICAL ? incr->get_height() : incr->get_width(); double grabber_ofs = get_grabber_offset(); double grabber_size = get_grabber_size(); double total = orientation==VERTICAL ? get_size().height : get_size().width; - + if (ofs < decr_size ) { - + set_val( get_val() - (custom_step>=0?custom_step:get_step()) ); break; } - + if (ofs > total-incr_size ) { - + set_val( get_val() + (custom_step>=0?custom_step:get_step()) ); break; } - + ofs-=decr_size; - + if ( ofs < grabber_ofs ) { - + set_val( get_val() - get_page() ); break; - - } - + + } + ofs-=grabber_ofs; - + if (ofs < grabber_size ) { - + drag.active=true; drag.pos_at_click=grabber_ofs+ofs; - drag.value_at_click=get_unit_value(); + drag.value_at_click=get_unit_value(); update(); } else { - - + + set_val( get_val() + get_page() ); } - - + + } else { - + drag.active=false; update(); } - + } break; case InputEvent::MOUSE_MOTION: { - + const InputEventMouseMotion &m=p_event.mouse_motion; accept_event(); - + if (drag.active) { - + double ofs = orientation==VERTICAL ? m.y : m.x ; Ref<Texture> decr = get_icon("decrement"); - + double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width(); ofs-=decr_size; - + double diff = (ofs-drag.pos_at_click) / get_area_size(); - set_unit_value( drag.value_at_click + diff ); + set_unit_value( drag.value_at_click + diff ); } else { - - + + double ofs = orientation==VERTICAL ? m.y : m.x ; Ref<Texture> decr = get_icon("decrement"); Ref<Texture> incr = get_icon("increment"); - + double decr_size = orientation==VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation==VERTICAL ? incr->get_height() : incr->get_width(); double total = orientation==VERTICAL ? get_size().height : get_size().width; - + HiliteStatus new_hilite; - + if (ofs < decr_size ) { - + new_hilite=HILITE_DECR; - + } else if (ofs > total-incr_size ) { - + new_hilite=HILITE_INCR; - + } else { - + new_hilite=HILITE_RANGE; } - + if (new_hilite!=hilite) { - + hilite=new_hilite; update(); - + } - + } } break; case InputEvent::KEY: { - + const InputEventKey &k=p_event.key; - + if (!k.pressed) return; - + switch (k.scancode) { - + case KEY_LEFT: { - + if (orientation!=HORIZONTAL) return; set_val( get_val() - (custom_step>=0?custom_step:get_step()) ); - + } break; case KEY_RIGHT: { - + if (orientation!=HORIZONTAL) return; set_val( get_val() + (custom_step>=0?custom_step:get_step()) ); - + } break; case KEY_UP: { - + if (orientation!=VERTICAL) return; - + set_val( get_val() - (custom_step>=0?custom_step:get_step()) ); - - + + } break; case KEY_DOWN: { - + if (orientation!=VERTICAL) return; set_val( get_val() + (custom_step>=0?custom_step:get_step()) ); - + } break; case KEY_HOME: { - + set_val( get_min() ); - + } break; case KEY_END: { - + set_val( get_max() ); - + } break; - + } break; - } + } } } void ScrollBar::_notification(int p_what) { - + if (p_what==NOTIFICATION_DRAW) { - + RID ci = get_canvas_item(); - + Ref<Texture> decr = hilite==HILITE_DECR ? get_icon("decrement_hilite") : get_icon("decrement"); Ref<Texture> incr = hilite==HILITE_INCR ? get_icon("increment_hilite") : get_icon("increment"); Ref<StyleBox> bg = has_focus() ? get_stylebox("scroll_focus") : get_stylebox("scroll"); Ref<StyleBox> grabber = (drag.active || hilite==HILITE_RANGE) ? get_stylebox("grabber_hilite") : get_stylebox("grabber"); - + Point2 ofs; - + VisualServer *vs = VisualServer::get_singleton(); vs->canvas_item_add_texture_rect( ci, Rect2( Point2(), decr->get_size()),decr->get_rid() ); @@ -266,33 +266,33 @@ void ScrollBar::_notification(int p_what) { area.height-=incr->get_height()+decr->get_height(); bg->draw(ci,Rect2(ofs,area)); - - if (orientation==HORIZONTAL) + + if (orientation==HORIZONTAL) ofs.width+=area.width; else ofs.height+=area.height; vs->canvas_item_add_texture_rect( ci, Rect2( ofs, decr->get_size()),incr->get_rid() ); Rect2 grabber_rect; - + if (orientation==HORIZONTAL) { - + grabber_rect.size.width=get_grabber_size(); grabber_rect.size.height=get_size().height; grabber_rect.pos.y=0; grabber_rect.pos.x=get_grabber_offset()+decr->get_width()+bg->get_margin( MARGIN_LEFT ); } else { - + grabber_rect.size.width=get_size().width; grabber_rect.size.height=get_grabber_size(); grabber_rect.pos.y=get_grabber_offset()+decr->get_height()+bg->get_margin( MARGIN_TOP ); - grabber_rect.pos.x=0; + grabber_rect.pos.x=0; } - + grabber->draw(ci,grabber_rect); - + } - + if (p_what==NOTIFICATION_ENTER_TREE) { @@ -405,48 +405,48 @@ void ScrollBar::_notification(int p_what) { } if (p_what==NOTIFICATION_MOUSE_EXIT) { - + hilite=HILITE_NONE; update(); } } double ScrollBar::get_grabber_min_size() const { - + Ref<StyleBox> grabber=get_stylebox("grabber"); Size2 gminsize=grabber->get_minimum_size()+grabber->get_center_size(); - return (orientation==VERTICAL)?gminsize.height:gminsize.width; + return (orientation==VERTICAL)?gminsize.height:gminsize.width; } double ScrollBar::get_grabber_size() const { - + float range = get_max()-get_min(); if (range<=0) return 0; - + float page = (get_page()>0)? get_page() : 0; // if (grabber_range < get_step()) // grabber_range=get_step(); - + double area_size=get_area_size(); double grabber_size = page / range * area_size; return grabber_size+get_grabber_min_size(); - -} + +} double ScrollBar::get_area_size() const { - + if (orientation==VERTICAL) { - + double area=get_size().height; area-=get_stylebox("scroll")->get_minimum_size().height; area-=get_icon("increment")->get_height(); area-=get_icon("decrement")->get_height(); area-=get_grabber_min_size(); return area; - + } else if (orientation==HORIZONTAL) { - + double area=get_size().width; area-=get_stylebox("scroll")->get_minimum_size().width; area-=get_icon("increment")->get_width(); @@ -454,38 +454,38 @@ double ScrollBar::get_area_size() const { area-=get_grabber_min_size(); return area; } else { - + return 0; } - + } double ScrollBar::get_area_offset() const { - + double ofs=0; - + if (orientation==VERTICAL) { - + ofs+=get_stylebox("hscroll")->get_margin( MARGIN_TOP ); ofs+=get_icon("decrement")->get_height(); - } - + } + if (orientation==HORIZONTAL) { - + ofs+=get_stylebox("hscroll")->get_margin( MARGIN_LEFT ); ofs+=get_icon("decrement")->get_width(); } - - return ofs; + + return ofs; } double ScrollBar::get_click_pos(const Point2& p_pos) const { - - + + float pos=(orientation==VERTICAL)?p_pos.y:p_pos.x; pos-=get_area_offset(); - + float area=get_area_size(); if (area==0) return 0; @@ -495,8 +495,8 @@ double ScrollBar::get_click_pos(const Point2& p_pos) const { } double ScrollBar::get_grabber_offset() const { - - + + return (get_area_size()) * get_unit_value(); } @@ -504,30 +504,30 @@ double ScrollBar::get_grabber_offset() const { Size2 ScrollBar::get_minimum_size() const { - + Ref<Texture> incr = get_icon("increment"); Ref<Texture> decr = get_icon("decrement"); Ref<StyleBox> bg = get_stylebox("scroll"); Size2 minsize; - + if (orientation==VERTICAL) { - + minsize.width=MAX(incr->get_size().width,(bg->get_minimum_size()+bg->get_center_size()).width); minsize.height+=incr->get_size().height; minsize.height+=decr->get_size().height; minsize.height+=bg->get_minimum_size().height; minsize.height+=get_grabber_min_size(); } - + if (orientation==HORIZONTAL) { - + minsize.height=MAX(incr->get_size().height,(bg->get_center_size()+bg->get_minimum_size()).height); minsize.width+=incr->get_size().width; minsize.width+=decr->get_size().width; minsize.width+=bg->get_minimum_size().width; minsize.width+=get_grabber_min_size(); } - + return minsize; } @@ -671,65 +671,65 @@ NodePath ScrollBar::get_drag_slave() const{ #if 0 void ScrollBar::mouse_button(const Point2& p_pos, int b.button_index,bool b.pressed,int p_modifier_mask) { - - // wheel! - + + // wheel! + if (b.button_index==BUTTON_WHEEL_UP && b.pressed) { - + if (orientation==VERTICAL) set_val( get_val() - get_page() / 4.0 ); else set_val( get_val() + get_page() / 4.0 ); - + } if (b.button_index==BUTTON_WHEEL_DOWN && b.pressed) { - + if (orientation==HORIZONTAL) set_val( get_val() - get_page() / 4.0 ); else set_val( get_val() + get_page() / 4.0 ); } - + if (b.button_index!=BUTTON_LEFT) return; - + if (b.pressed) { - + int ofs = orientation==VERTICAL ? p_pos.y : p_pos.x ; int grabber_ofs = get_grabber_offset(); int grabber_size = get_grabber_size(); - + if ( ofs < grabber_ofs ) { - + set_val( get_val() - get_page() ); - + } else if (ofs > grabber_ofs + grabber_size ) { - + set_val( get_val() + get_page() ); - + } else { - - + + drag.active=true; drag.pos_at_click=get_click_pos(p_pos); drag.value_at_click=get_unit_value(); } - - + + } else { - + drag.active=false; } - + } void ScrollBar::mouse_motion(const Point2& p_pos, const Point2& p_rel, int b.button_index_mask) { - + if (!drag.active) return; - + double value_ofs=drag.value_at_click+(get_click_pos(p_pos)-drag.pos_at_click); - - + + value_ofs=value_ofs*( get_max() - get_min() ); if (value_ofs<get_min()) value_ofs=get_min(); @@ -737,64 +737,64 @@ void ScrollBar::mouse_motion(const Point2& p_pos, const Point2& p_rel, int b.but value_ofs=get_max()-get_page(); if (get_val()==value_ofs) return; //dont bother if the value is the same - + set_val( value_ofs ); - + } bool ScrollBar::key(unsigned long p_unicode, unsigned long p_scan_code,bool b.pressed,bool p_repeat,int p_modifier_mask) { - + if (!b.pressed) return false; - + switch (p_scan_code) { - + case KEY_LEFT: { - + if (orientation!=HORIZONTAL) return false; set_val( get_val() - get_step() ); - + } break; case KEY_RIGHT: { - + if (orientation!=HORIZONTAL) return false; set_val( get_val() + get_step() ); - + } break; case KEY_UP: { - + if (orientation!=VERTICAL) return false; - + set_val( get_val() - get_step() ); - - + + } break; case KEY_DOWN: { - + if (orientation!=VERTICAL) return false; set_val( get_val() + get_step() ); - + } break; case KEY_HOME: { - + set_val( get_min() ); - + } break; case KEY_END: { - + set_val( get_max() ); - + } break; - + default: return false; - + } - + return true; } @@ -823,7 +823,7 @@ ScrollBar::ScrollBar(Orientation p_orientation) hilite=HILITE_NONE; custom_step=-1; drag_slave=NULL; - + drag.active=false; drag_slave_speed=Vector2(); @@ -833,7 +833,7 @@ ScrollBar::ScrollBar(Orientation p_orientation) if (focus_by_default) set_focus_mode( FOCUS_ALL ); - + } diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h index a629ddc56c..c68db02b33 100644 --- a/scene/gui/scroll_bar.h +++ b/scene/gui/scroll_bar.h @@ -36,40 +36,40 @@ @author Juan Linietsky <reduzio@gmail.com> */ class ScrollBar : public Range { - + OBJ_TYPE( ScrollBar, Range ); - + enum HiliteStatus { HILITE_NONE, HILITE_DECR, HILITE_RANGE, - HILITE_INCR, + HILITE_INCR, }; - + static bool focus_by_default; - + Orientation orientation; Size2 size; float custom_step; - + HiliteStatus hilite; - + struct Drag { - + bool active; float pos_at_click; float value_at_click; } drag; - - + + double get_grabber_size() const; double get_grabber_min_size() const; double get_area_size() const; double get_area_offset() const; double get_click_pos(const Point2& p_pos) const; double get_grabber_offset() const; - - static void set_can_focus_by_default(bool p_can_focus); + + static void set_can_focus_by_default(bool p_can_focus); Node* drag_slave; NodePath drag_slave_path; @@ -86,12 +86,12 @@ class ScrollBar : public Range { void _drag_slave_exit(); void _drag_slave_input(const InputEvent& p_input); - + void _input_event(InputEvent p_event); -protected: +protected: void _notification(int p_what); - static void _bind_methods(); + static void _bind_methods(); public: @@ -101,25 +101,25 @@ public: void set_drag_slave(const NodePath& p_path); NodePath get_drag_slave() const; - virtual Size2 get_minimum_size() const; - ScrollBar(Orientation p_orientation=VERTICAL); + virtual Size2 get_minimum_size() const; + ScrollBar(Orientation p_orientation=VERTICAL); ~ScrollBar(); }; class HScrollBar : public ScrollBar { - + OBJ_TYPE( HScrollBar, ScrollBar ); public: - + HScrollBar() : ScrollBar(HORIZONTAL) { set_v_size_flags(0); } }; class VScrollBar : public ScrollBar { - + OBJ_TYPE( VScrollBar, ScrollBar ); public: - + VScrollBar() : ScrollBar(VERTICAL) { set_h_size_flags(0); } }; diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 7ef9d4216b..f66f909517 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -231,13 +231,13 @@ void Slider::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&Slider::_input_event); ObjectTypeDB::bind_method(_MD("set_ticks","count"),&Slider::set_ticks); ObjectTypeDB::bind_method(_MD("get_ticks"),&Slider::get_ticks); - - ObjectTypeDB::bind_method(_MD("get_ticks_on_borders"),&Slider::get_ticks_on_borders); + + ObjectTypeDB::bind_method(_MD("get_ticks_on_borders"),&Slider::get_ticks_on_borders); ObjectTypeDB::bind_method(_MD("set_ticks_on_borders","ticks_on_border"),&Slider::set_ticks_on_borders); - + ADD_PROPERTY( PropertyInfo( Variant::INT, "tick_count", PROPERTY_HINT_RANGE,"0,4096,1"), _SCS("set_ticks"), _SCS("get_ticks") ); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "ticks_on_borders" ), _SCS("set_ticks_on_borders"), _SCS("get_ticks_on_borders") ); - + } Slider::Slider(Orientation p_orientation) { diff --git a/scene/gui/slider.h b/scene/gui/slider.h index f85e6d1807..cf009b9a75 100644 --- a/scene/gui/slider.h +++ b/scene/gui/slider.h @@ -53,7 +53,7 @@ protected: void _notification(int p_what); static void _bind_methods(); bool ticks_on_borders; - + public: virtual Size2 get_minimum_size() const; diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 91d0fc157e..1c6a97bab8 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "tab_container.h" - + #include "message_queue.h" @@ -209,7 +209,7 @@ void TabContainer::_notification(int p_what) { Ref<Texture> incr = get_icon("increment"); Ref<Texture> incr_hl = get_icon("increment_hilite"); Ref<Texture> decr = get_icon("decrement"); - Ref<Texture> decr_hl = get_icon("decrement_hilite"); + Ref<Texture> decr_hl = get_icon("decrement_hilite"); Ref<Texture> menu = get_icon("menu"); Ref<Texture> menu_hl = get_icon("menu_hl"); Ref<Font> font = get_font("font"); diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index c3e75842c3..9692d08882 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -493,7 +493,7 @@ void Tabs::set_current_tab(int p_current) { ERR_FAIL_INDEX( p_current, get_tab_count() ); //printf("DEBUG %p: set_current_tab to %i\n", this, p_current); - current=p_current; + current=p_current; _change_notify("current_tab"); //emit_signal("tab_changed",current); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 96c3d28650..32f4be5d17 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -38,12 +38,12 @@ #define TAB_PIXELS static bool _is_text_char(CharType c) { - + return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_'; } static bool _is_symbol(CharType c) { - + return c!='_' && ((c>='!' && c<='/') || (c>=':' && c<='@') || (c>='[' && c<='`') || (c>='{' && c<='~') || c=='\t'); } @@ -84,81 +84,81 @@ static CharType _get_right_pair_symbol(CharType c) { } void TextEdit::Text::set_font(const Ref<Font>& p_font) { - + font=p_font; } void TextEdit::Text::set_tab_size(int p_tab_size) { - + tab_size=p_tab_size; } void TextEdit::Text::_update_line_cache(int p_line) const { - + int w = 0; int tab_w=font->get_char_size(' ').width*tab_size; int len = text[p_line].data.length(); const CharType *str = text[p_line].data.c_str(); - + //update width - + for(int i=0;i<len;i++) { if (str[i]=='\t') { - + int left = w%tab_w; if (left==0) w+=tab_w; else w+=tab_w-w%tab_w; // is right... - + } else { - + w+=font->get_char_size(str[i],str[i+1]).width; } } - - + + text[p_line].width_cache=w; - + //update regions - + text[p_line].region_info.clear(); - + for(int i=0;i<len;i++) { - + if (!_is_symbol(str[i])) continue; if (str[i]=='\\') { i++; //skip quoted anything continue; } - + int left=len-i; - + for(int j=0;j<color_regions->size();j++) { - + const ColorRegion& cr=color_regions->operator [](j); - + /* BEGIN */ - + int lr=cr.begin_key.length(); if (lr==0 || lr>left) continue; - + const CharType* kc = cr.begin_key.c_str(); - + bool match=true; - + for(int k=0;k<lr;k++) { if (kc[k]!=str[i+k]) { match=false; break; } } - + if (match) { - + ColorRegionInfo cri; cri.end=false; cri.region=j; @@ -166,26 +166,26 @@ void TextEdit::Text::_update_line_cache(int p_line) const { i+=lr-1; break; } - + /* END */ - + lr=cr.end_key.length(); if (lr==0 || lr>left) continue; - + kc = cr.end_key.c_str(); - + match=true; - + for(int k=0;k<lr;k++) { if (kc[k]!=str[i+k]) { match=false; break; } } - + if (match) { - + ColorRegionInfo cri; cri.end=true; cri.region=j; @@ -193,72 +193,72 @@ void TextEdit::Text::_update_line_cache(int p_line) const { i+=lr-1; break; } - + } } - - + + } const Map<int,TextEdit::Text::ColorRegionInfo>& TextEdit::Text::get_color_region_info(int p_line) { - + Map<int,ColorRegionInfo> *cri=NULL; ERR_FAIL_INDEX_V(p_line,text.size(),*cri); //enjoy your crash - + if (text[p_line].width_cache==-1) { _update_line_cache(p_line); } - + return text[p_line].region_info; } int TextEdit::Text::get_line_width(int p_line) const { - + ERR_FAIL_INDEX_V(p_line,text.size(),-1); - + if (text[p_line].width_cache==-1) { _update_line_cache(p_line); } - + return text[p_line].width_cache; } void TextEdit::Text::clear_caches() { - + for(int i=0;i<text.size();i++) text[i].width_cache=-1; - + } void TextEdit::Text::clear() { - - + + text.clear();; insert(0,""); } int TextEdit::Text::get_max_width() const { //quite some work.. but should be fast enough. - + int max = 0; - + for(int i=0;i<text.size();i++) max=MAX(max,get_line_width(i)); return max; - + } void TextEdit::Text::set(int p_line,const String& p_text) { - + ERR_FAIL_INDEX(p_line,text.size()); - + text[p_line].width_cache=-1; text[p_line].data=p_text; } void TextEdit::Text::insert(int p_at,const String& p_text) { - + Line line; line.marked=false; line.breakpoint=false; @@ -267,26 +267,26 @@ void TextEdit::Text::insert(int p_at,const String& p_text) { text.insert(p_at,line); } void TextEdit::Text::remove(int p_at) { - + text.remove(p_at); } void TextEdit::_update_scrollbars() { - - + + Size2 size = get_size(); Size2 hmin = h_scroll->get_combined_minimum_size(); Size2 vmin = v_scroll->get_combined_minimum_size(); - - - + + + v_scroll->set_begin( Point2(size.width - vmin.width, cache.style_normal->get_margin(MARGIN_TOP)) ); v_scroll->set_end( Point2(size.width, size.height - cache.style_normal->get_margin(MARGIN_TOP) - cache.style_normal->get_margin(MARGIN_BOTTOM)) ); - + h_scroll->set_begin( Point2( 0, size.height - hmin.height) ); h_scroll->set_end( Point2(size.width-vmin.width, size.height) ); - - + + int hscroll_rows = ((hmin.height-1)/get_row_height())+1; int visible_rows = get_visible_rows(); int total_rows = text.size(); @@ -297,59 +297,59 @@ void TextEdit::_update_scrollbars() { int vscroll_pixels = v_scroll->get_combined_minimum_size().width; int visible_width = size.width - cache.style_normal->get_minimum_size().width; int total_width = text.get_max_width() + vmin.x; - + if (line_numbers) total_width += cache.line_number_w; - + bool use_hscroll=true; bool use_vscroll=true; - + if (total_rows <= visible_rows && total_width <= visible_width) { //thanks yessopie for this clever bit of logic use_hscroll=false; use_vscroll=false; - + } else { - + if (total_rows > visible_rows && total_width <= visible_width - vscroll_pixels) { //thanks yessopie for this clever bit of logic use_hscroll=false; } - + if (total_rows <= visible_rows - hscroll_rows && total_width > visible_width) { //thanks yessopie for this clever bit of logic use_vscroll=false; } } - + updating_scrolls=true; - + if (use_vscroll) { - + v_scroll->show(); v_scroll->set_max(total_rows); v_scroll->set_page(visible_rows); v_scroll->set_val(cursor.line_ofs); - + } else { cursor.line_ofs = 0; v_scroll->hide(); } - + if (use_hscroll) { - + h_scroll->show(); h_scroll->set_max(total_width); h_scroll->set_page(visible_width); h_scroll->set_val(cursor.x_ofs); - + } else { - + h_scroll->hide(); } - - - + + + updating_scrolls=false; } @@ -378,32 +378,32 @@ void TextEdit::_click_selection_held() { void TextEdit::_notification(int p_what) { - + switch(p_what) { case NOTIFICATION_ENTER_TREE: { - + _update_caches(); if (cursor_changed_dirty) MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit"); if (text_changed_dirty) MessageQueue::get_singleton()->push_call(this,"_text_changed_emit"); - + } break; case NOTIFICATION_RESIZED: { - + cache.size=get_size(); adjust_viewport_to_cursor(); - - + + } break; case NOTIFICATION_THEME_CHANGED: { - + _update_caches(); }; case NOTIFICATION_DRAW: { - + int line_number_char_count=0; - + { int lc=text.size()+1; cache.line_number_w=0; @@ -411,20 +411,20 @@ void TextEdit::_notification(int p_what) { cache.line_number_w+=1; lc/=10; }; - + if (line_numbers) { - + line_number_char_count=cache.line_number_w; cache.line_number_w=(cache.line_number_w+1)*cache.font->get_char_size('0').width; } else { cache.line_number_w=0; } - - + + } _update_scrollbars(); - - + + RID ci = get_canvas_item(); int xmargin_beg=cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w; int xmargin_end=cache.size.width-cache.style_normal->get_margin(MARGIN_RIGHT); @@ -432,56 +432,56 @@ void TextEdit::_notification(int p_what) { cache.style_normal->draw(ci,Rect2(Point2(),cache.size)); if (has_focus()) cache.style_focus->draw(ci,Rect2(Point2(),cache.size)); - - + + int ascent=cache.font->get_ascent(); - + int visible_rows = get_visible_rows(); - + int tab_w = cache.font->get_char_size(' ').width*tab_size; - + Color color = cache.font_color; int in_region=-1; - + if (syntax_coloring) { - + if (custom_bg_color.a>0.01) { - + Point2i ofs = Point2i(cache.style_normal->get_offset())/2.0; VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(ofs, get_size()-cache.style_normal->get_minimum_size()+ofs),custom_bg_color); } //compute actual region to start (may be inside say, a comment). //slow in very large documments :( but ok for source! - + for(int i=0;i<cursor.line_ofs;i++) { - + const Map<int,Text::ColorRegionInfo>& cri_map=text.get_color_region_info(i); - + if (in_region>=0 && color_regions[in_region].line_only) { in_region=-1; //reset regions that end at end of line } - + for( const Map<int,Text::ColorRegionInfo>::Element* E= cri_map.front();E;E=E->next() ) { - + const Text::ColorRegionInfo &cri=E->get(); - + if (in_region==-1) { - + if (!cri.end) { - + in_region=cri.region; } } else if (in_region==cri.region && !color_regions[cri.region].line_only) { //ignore otherwise - + if (cri.end || color_regions[cri.region].eq) { - + in_region=-1; } } } } } - + int brace_open_match_line=-1; int brace_open_match_column=-1; bool brace_open_matching=false; @@ -490,15 +490,15 @@ void TextEdit::_notification(int p_what) { int brace_close_match_column=-1; bool brace_close_matching=false; bool brace_close_mismatch=false; - - + + if (brace_matching_enabled) { - + if (cursor.column<text[cursor.line].length()) { //check for open CharType c = text[cursor.line][cursor.column]; CharType closec=0; - + if (c=='[') { closec=']'; } else if (c=='{') { @@ -506,17 +506,17 @@ void TextEdit::_notification(int p_what) { } else if (c=='(') { closec=')'; } - + if (closec!=0) { - + int stack=1; - - + + for(int i=cursor.line;i<text.size();i++) { - + int from = i==cursor.line?cursor.column+1:0; for(int j=from;j<text[i].length();j++) { - + CharType cc = text[i][j]; //ignore any brackets inside a string if (cc== '"' || cc == '\'') { @@ -544,32 +544,32 @@ void TextEdit::_notification(int p_what) { stack++; else if (cc==closec) stack--; - + if (stack==0) { brace_open_match_line=i; brace_open_match_column=j; brace_open_matching=true; - + break; } } if (brace_open_match_line!=-1) break; } - + if (!brace_open_matching) brace_open_mismatch=true; - - + + } } - + if (cursor.column>0) { CharType c = text[cursor.line][cursor.column-1]; CharType closec=0; - - - + + + if (c==']') { closec='['; } else if (c=='}') { @@ -577,17 +577,17 @@ void TextEdit::_notification(int p_what) { } else if (c==')') { closec='('; } - + if (closec!=0) { - + int stack=1; - - + + for(int i=cursor.line;i>=0;i--) { - + int from = i==cursor.line?cursor.column-2:text[i].length()-1; for(int j=from;j>=0;j--) { - + CharType cc = text[i][j]; //ignore any brackets inside a string if (cc== '"' || cc == '\'') { @@ -616,49 +616,49 @@ void TextEdit::_notification(int p_what) { stack++; else if (cc==closec) stack--; - + if (stack==0) { brace_close_match_line=i; brace_close_match_column=j; brace_close_matching=true; - + break; } } if (brace_close_match_line!=-1) break; } - + if (!brace_close_matching) brace_close_mismatch=true; - - + + } - - + + } } - - + + int deregion=0; //force it to clear inrgion Point2 cursor_pos; - + for (int i=0;i<visible_rows;i++) { - + int line=i+cursor.line_ofs; - + if (line<0 || line>=(int)text.size()) continue; - + const String &str=text[line]; - + int char_margin=xmargin_beg-cursor.x_ofs; int char_ofs=0; int ofs_y=i*get_row_height()+cache.line_spacing/2; bool prev_is_char=false; bool in_keyword=false; Color keyword_color; - + if (cache.line_number_w) { Color fcol = cache.font_color; fcol.a*=0.4; @@ -666,190 +666,190 @@ void TextEdit::_notification(int p_what) { while (fc.length() < line_number_char_count) { fc="0"+fc; } - + cache.font->draw(ci,Point2(cache.style_normal->get_margin(MARGIN_LEFT),ofs_y+cache.font->get_ascent()),fc,fcol); } - + const Map<int,Text::ColorRegionInfo>& cri_map=text.get_color_region_info(line); - - + + if (text.is_marked(line)) { - + VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.mark_color); } - + if (text.is_breakpoint(line)) { - + VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.breakpoint_color); } - - + + if (line==cursor.line) { - + VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.current_line_color); - + } for (int j=0;j<str.length();j++) { - + //look for keyword - + if (deregion>0) { deregion--; if (deregion==0) in_region=-1; } if (syntax_coloring && deregion==0) { - - + + color = cache.font_color; //reset //find keyword bool is_char = _is_text_char(str[j]); bool is_symbol=_is_symbol(str[j]); - + if (j==0 && in_region>=0 && color_regions[in_region].line_only) { in_region=-1; //reset regions that end at end of line } - + if (is_symbol && cri_map.has(j)) { - - + + const Text::ColorRegionInfo &cri=cri_map[j]; - + if (in_region==-1) { - + if (!cri.end) { - + in_region=cri.region; } } else if (in_region==cri.region && !color_regions[cri.region].line_only) { //ignore otherwise - + if (cri.end || color_regions[cri.region].eq) { - + deregion=color_regions[cri.region].eq?color_regions[cri.region].begin_key.length():color_regions[cri.region].end_key.length(); } } } - + if (!is_char) in_keyword=false; - + if (in_region==-1 && !in_keyword && is_char && !prev_is_char) { - + int to=j; while(to<str.length() && _is_text_char(str[to])) to++; - + uint32_t hash = String::hash(&str[j],to-j); StrRange range(&str[j],to-j); - + const Color *col=keywords.custom_getptr(range,hash); - + if (col) { - + in_keyword=true; keyword_color=*col; } } - - + + if (in_region>=0) color=color_regions[in_region].color; else if (in_keyword) color=keyword_color; else if (is_symbol) color=symbol_color; - + prev_is_char=is_char; - + } int char_w; - + //handle tabulator - - + + if (str[j]=='\t') { int left = char_ofs%tab_w; if (left==0) char_w=tab_w; else char_w=tab_w-char_ofs%tab_w; // is right... - + } else { char_w=cache.font->get_char_size(str[j],str[j+1]).width; } - + if ( (char_ofs+char_margin)<xmargin_beg) { char_ofs+=char_w; continue; } - + if ( (char_ofs+char_margin+char_w)>=xmargin_end) { if (syntax_coloring) continue; else break; } - + bool in_selection = (selection.active && line>=selection.from_line && line<=selection.to_line && (line>selection.from_line || j>=selection.from_column) && (line<selection.to_line || j<selection.to_column)); - - + + if (in_selection) { //inside selection! VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(Point2i( char_ofs+char_margin, ofs_y ), Size2i(char_w,get_row_height())),cache.selection_color); } - - + + if (brace_matching_enabled) { if ( (brace_open_match_line==line && brace_open_match_column==j) || (cursor.column==j && cursor.line==line && (brace_open_matching||brace_open_mismatch))) { - + if (brace_open_mismatch) color=cache.brace_mismatch_color; cache.font->draw_char(ci,Point2i( char_ofs+char_margin, ofs_y+ascent),'_',str[j+1],in_selection?cache.font_selected_color:color); - + } - + if ( (brace_close_match_line==line && brace_close_match_column==j) || (cursor.column==j+1 && cursor.line==line && (brace_close_matching||brace_close_mismatch))) { - - + + if (brace_close_mismatch) color=cache.brace_mismatch_color; cache.font->draw_char(ci,Point2i( char_ofs+char_margin, ofs_y+ascent),'_',str[j+1],in_selection?cache.font_selected_color:color); - + } } - - + + if (str[j]>=32) cache.font->draw_char(ci,Point2i( char_ofs+char_margin, ofs_y+ascent),str[j],str[j+1],in_selection?cache.font_selected_color:color); - + else if (draw_tabs && str[j]=='\t') { int yofs= (get_row_height() - cache.tab_icon->get_height())/2; cache.tab_icon->draw(ci, Point2(char_ofs+char_margin,ofs_y+yofs),in_selection?cache.font_selected_color:color); } - - + + if (cursor.column==j && cursor.line==line) { - + cursor_pos = Point2i( char_ofs+char_margin, ofs_y ); VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color); - - + + } char_ofs+=char_w; - + } - + if (cursor.column==str.length() && cursor.line==line && (char_ofs+char_margin)>=xmargin_beg) { - + cursor_pos=Point2i( char_ofs+char_margin, ofs_y ); VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color); - + } } - + bool completion_below = false; if (completion_active) { // code completion box @@ -861,15 +861,15 @@ void TextEdit::_notification(int p_what) { existing.a=0.2; int scrollw = get_constant("completion_scroll_width"); Color scrollc = get_color("completion_scroll_color"); - - - + + + int lines = MIN(completion_options.size(),maxlines); int w=0; int h=lines*get_row_height(); int nofs = cache.font->get_string_size(completion_base).width; - - + + if (completion_options.size() < 50) { for(int i=0;i<completion_options.size();i++) { int w2=MIN(cache.font->get_string_size(completion_options[i]).x,cmax_width); @@ -879,40 +879,40 @@ void TextEdit::_notification(int p_what) { } else { w=cmax_width; } - + int th = h + csb->get_minimum_size().y; - + if (cursor_pos.y+get_row_height()+th > get_size().height) { completion_rect.pos.y=cursor_pos.y-th; } else { completion_rect.pos.y=cursor_pos.y+get_row_height()+csb->get_offset().y; completion_below = true; } - + if (cursor_pos.x-nofs+w+scrollw > get_size().width) { completion_rect.pos.x=get_size().width-w-scrollw; } else { completion_rect.pos.x=cursor_pos.x-nofs; } - + completion_rect.size.width=w+2; completion_rect.size.height=h; if (completion_options.size()<=maxlines) scrollw=0; - + draw_style_box(csb,Rect2(completion_rect.pos-csb->get_offset(),completion_rect.size+csb->get_minimum_size()+Size2(scrollw,0))); - - + + int line_from = CLAMP(completion_index - lines/2, 0, completion_options.size() - lines); draw_style_box(csel,Rect2(Point2(completion_rect.pos.x,completion_rect.pos.y+(completion_index-line_from)*get_row_height()),Size2(completion_rect.size.width,get_row_height()))); - + draw_rect(Rect2(completion_rect.pos,Size2(nofs,completion_rect.size.height)),existing); - - - - + + + + for(int i=0;i<lines;i++) { - + int l = line_from + i; ERR_CONTINUE( l < 0 || l>= completion_options.size()); Color text_color = cache.font_color; @@ -923,16 +923,16 @@ void TextEdit::_notification(int p_what) { } draw_string(cache.font,Point2(completion_rect.pos.x,completion_rect.pos.y+i*get_row_height()+cache.font->get_ascent()),completion_options[l],text_color,completion_rect.size.width); } - + if (scrollw) { //draw a small scroll rectangle to show a position in the options float r = maxlines / (float)completion_options.size(); float o = line_from / (float)completion_options.size(); draw_rect(Rect2(completion_rect.pos.x+completion_rect.size.width,completion_rect.pos.y+o*completion_rect.size.y,scrollw,completion_rect.size.y*r),scrollc); } - + completion_line_ofs=line_from; - + } // check to see if the hint should be drawn @@ -950,20 +950,20 @@ void TextEdit::_notification(int p_what) { show_hint = true; } } - + if (show_hint) { - + Ref<StyleBox> sb = get_stylebox("panel","TooltipPanel"); Ref<Font> font = cache.font; Color font_color = get_color("font_color","TooltipLabel"); - - + + int max_w=0; int sc = completion_hint.get_slice_count("\n"); int offset=0; int spacing=0; for(int i=0;i<sc;i++) { - + String l = completion_hint.get_slice("\n",i); int len = font->get_string_size(l).x; max_w = MAX(len,max_w); @@ -972,21 +972,21 @@ void TextEdit::_notification(int p_what) { } else { spacing+=cache.line_spacing; } - - + + } - - - + + + Size2 size = Size2(max_w,sc*font->get_height()+spacing); Size2 minsize = size+sb->get_minimum_size(); - - + + if (completion_hint_offset==-0xFFFF) { completion_hint_offset=cursor_pos.x-offset; } - - + + Point2 hint_ofs = Vector2(completion_hint_offset,cursor_pos.y) + callhint_offset; if (callhint_below) { @@ -997,18 +997,18 @@ void TextEdit::_notification(int p_what) { } draw_style_box(sb,Rect2(hint_ofs,minsize)); - + spacing=0; for(int i=0;i<sc;i++) { int begin=0; int end=0; String l = completion_hint.get_slice("\n",i); - + if (l.find(String::chr(0xFFFF))!=-1) { begin = font->get_string_size(l.substr(0,l.find(String::chr(0xFFFF)))).x; end = font->get_string_size(l.substr(0,l.rfind(String::chr(0xFFFF)))).x; } - + draw_string(font,hint_ofs+sb->get_offset()+Vector2(0,font->get_ascent()+font->get_height()*i+spacing),l.replace(String::chr(0xFFFF),""),font_color); if (end>0) { Vector2 b = hint_ofs+sb->get_offset()+Vector2(begin,font->get_height()+font->get_height()*i+spacing-1); @@ -1017,60 +1017,60 @@ void TextEdit::_notification(int p_what) { spacing+=cache.line_spacing; } } - - + + } break; case NOTIFICATION_FOCUS_ENTER: { - + if (OS::get_singleton()->has_virtual_keyboard()) OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect()); - + } break; case NOTIFICATION_FOCUS_EXIT: { - + if (OS::get_singleton()->has_virtual_keyboard()) OS::get_singleton()->hide_virtual_keyboard(); - + } break; - + } } void TextEdit::_consume_pair_symbol(CharType ch) { - + int cursor_position_to_move = cursor_get_column() + 1; - + CharType ch_single[2] = {ch, 0}; CharType ch_single_pair[2] = {_get_right_pair_symbol(ch), 0}; CharType ch_pair[3] = {ch, _get_right_pair_symbol(ch), 0}; - + if(is_selection_active()) { - + int new_column,new_line; - + _begin_compex_operation(); _insert_text(get_selection_from_line(), get_selection_from_column(), ch_single, &new_line, &new_column); - + int to_col_offset = 0; if(get_selection_from_line() == get_selection_to_line()) to_col_offset = 1; - + _insert_text(get_selection_to_line(), get_selection_to_column() + to_col_offset, ch_single_pair, &new_line,&new_column); _end_compex_operation(); - + cursor_set_line(get_selection_to_line()); cursor_set_column(get_selection_to_column() + to_col_offset); - + deselect(); update(); return; } - + if( (ch == '\'' || ch == '"') && cursor_get_column() > 0 && _is_text_char(text[cursor.line][cursor_get_column() - 1]) @@ -1079,7 +1079,7 @@ void TextEdit::_consume_pair_symbol(CharType ch) { cursor_set_column(cursor_position_to_move); return; } - + if(cursor_get_column() < text[cursor.line].length()) { if(_is_text_char(text[cursor.line][cursor_get_column()])) { insert_text_at_cursor(ch_single); @@ -1093,34 +1093,34 @@ void TextEdit::_consume_pair_symbol(CharType ch) { return; } } - - + + insert_text_at_cursor(ch_pair); cursor_set_column(cursor_position_to_move); return; - + } void TextEdit::_consume_backspace_for_pair_symbol(int prev_line, int prev_column) { - + bool remove_right_symbol = false; - + if(cursor.column < text[cursor.line].length() && cursor.column > 0) { - + CharType left_char = text[cursor.line][cursor.column - 1]; CharType right_char = text[cursor.line][cursor.column]; - + if(right_char == _get_right_pair_symbol(left_char)) { remove_right_symbol = true; } - + } if(remove_right_symbol) { _remove_text(prev_line,prev_column,cursor.line,cursor.column + 1); } else { _remove_text(prev_line,prev_column,cursor.line,cursor.column); } - + } void TextEdit::backspace_at_cursor() { @@ -1129,7 +1129,7 @@ void TextEdit::backspace_at_cursor() { if (cursor.column==0 && cursor.line==0) return; - + int prev_line = cursor.column?cursor.line:cursor.line-1; int prev_column = cursor.column?(cursor.column-1):(text[cursor.line-1].length()); if(auto_brace_completion_enabled && @@ -1139,15 +1139,15 @@ void TextEdit::backspace_at_cursor() { } else { _remove_text(prev_line,prev_column,cursor.line,cursor.column); } - + cursor_set_line(prev_line); cursor_set_column(prev_column); - + } void TextEdit::_get_mouse_pos(const Point2i& p_mouse, int &r_row, int &r_col) const { - + float rows=p_mouse.y; rows-=cache.style_normal->get_margin(MARGIN_TOP); rows/=get_row_height(); @@ -1157,56 +1157,56 @@ void TextEdit::_get_mouse_pos(const Point2i& p_mouse, int &r_row, int &r_col) co row=0; int col=0; - + if (row>=text.size()) { - + row=text.size()-1; col=text[row].size(); } else { - + col=p_mouse.x-(cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w); col+=cursor.x_ofs; col=get_char_pos_for( col, get_line(row) ); } - + r_row=row; r_col=col; } void TextEdit::_input_event(const InputEvent& p_input_event) { - + switch(p_input_event.type) { - + case InputEvent::MOUSE_BUTTON: { - + const InputEventMouseButton &mb=p_input_event.mouse_button; - + if (completion_active && completion_rect.has_point(Point2(mb.x,mb.y))) { - + if (!mb.pressed) return; - + if (mb.button_index==BUTTON_WHEEL_UP) { if (completion_index>0) { completion_index--; completion_current=completion_options[completion_index]; update(); } - + } if (mb.button_index==BUTTON_WHEEL_DOWN) { - + if (completion_index<completion_options.size()-1) { completion_index++; completion_current=completion_options[completion_index]; update(); } } - + if (mb.button_index==BUTTON_LEFT) { - + completion_index=CLAMP(completion_line_ofs+(mb.y-completion_rect.pos.y)/get_row_height(),0,completion_options.size()-1); - + completion_current=completion_options[completion_index]; update(); if (mb.doubleclick) @@ -1217,7 +1217,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { _cancel_completion(); _cancel_code_hint(); } - + if (mb.pressed) { if (mb.button_index==BUTTON_WHEEL_UP) { v_scroll->set_val( v_scroll->get_val() -3 ); @@ -1232,18 +1232,18 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { h_scroll->set_val( h_scroll->get_val() +3 ); } if (mb.button_index==BUTTON_LEFT) { - + int row,col; _get_mouse_pos(Point2i(mb.x,mb.y), row,col); - + int prev_col=cursor.column; int prev_line=cursor.line; - - - + + + cursor_set_line( row ); cursor_set_column( col ); - + if (mb.mod.shift && (cursor.column!=prev_col || cursor.line!=prev_line)) { if (!selection.active) { @@ -1298,99 +1298,99 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { - + } else { - + //if sel active and dblick last time < something - + //else selection.active=false; selection.selecting_mode=Selection::MODE_POINTER; selection.selecting_line=row; selection.selecting_column=col; } - - + + if (!mb.doubleclick && (OS::get_singleton()->get_ticks_msec()-last_dblclk)<600 && cursor.line==prev_line) { //tripleclick select line select(cursor.line,0,cursor.line,text[cursor.line].length()); selection.selecting_column=0; last_dblclk=0; - + } else if (mb.doubleclick && text[cursor.line].length()) { - + //doubleclick select world String s = text[cursor.line]; int beg=CLAMP(cursor.column,0,s.length()); int end=beg; - + if (s[beg]>32 || beg==s.length()) { - + bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this - + while(beg>0 && s[beg-1]>32 && (symbol==_is_symbol(s[beg-1]))) { beg--; } while(end<s.length() && s[end+1]>32 && (symbol==_is_symbol(s[end+1]))) { end++; } - + if (end<s.length()) end+=1; - + select(cursor.line,beg,cursor.line,end); selection.selecting_column=beg; } - + last_dblclk = OS::get_singleton()->get_ticks_msec(); - + } - + update(); } } else { if (mb.button_index==BUTTON_LEFT) click_select_held->stop(); - + // notify to show soft keyboard notification(NOTIFICATION_FOCUS_ENTER); } - + } break; case InputEvent::MOUSE_MOTION: { - + const InputEventMouseMotion &mm=p_input_event.mouse_motion; - + if (mm.button_mask&BUTTON_MASK_LEFT) { - + if (selection.selecting_mode!=Selection::MODE_NONE) { int row,col; _get_mouse_pos(Point2i(mm.x,mm.y), row,col); - + select(selection.selecting_line,selection.selecting_column,row,col); - + cursor_set_line( row ); cursor_set_column( col ); update(); click_select_held->start(); - + } - + } - + } break; - + case InputEvent::KEY: { - + InputEventKey k=p_input_event.key; - + if (!k.pressed) return; - + if (completion_active) { if (readonly) break; @@ -1398,9 +1398,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { bool valid=true; if (k.mod.command || k.mod.meta) valid=false; - + if (valid) { - + if (!k.mod.alt) { if (k.scancode==KEY_UP) { @@ -1499,13 +1499,13 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { return; } } - + if (k.unicode>32) { - + if (cursor.column<text[cursor.line].length() && text[cursor.line][cursor.column]==k.unicode) { //same char, move ahead cursor_set_column(cursor.column+1); - + } else { //different char, go back const CharType chr[2] = {(CharType)k.unicode, 0}; @@ -1515,34 +1515,34 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { _insert_text_at_cursor(chr); } } - + _update_completion_candidates(); accept_event(); - + return; } } - + _cancel_completion(); - + } - + /* TEST CONTROL FIRST!! */ - + // some remaps for duplicate functions.. if (k.mod.command && !k.mod.shift && !k.mod.alt && !k.mod.meta && k.scancode==KEY_INSERT) { - + k.scancode=KEY_C; } if (!k.mod.command && k.mod.shift && !k.mod.alt && !k.mod.meta && k.scancode==KEY_INSERT) { - + k.scancode=KEY_V; k.mod.command=true; k.mod.shift=false; } - + // stuff to do when selection is active.. - + if (selection.active) { if (readonly) @@ -1551,16 +1551,16 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { bool clear=false; bool unselect=false; bool dobreak=false; - + switch(k.scancode) { - + case KEY_TAB: { - + String txt = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); String prev_txt=txt; - + if (k.mod.shift) { - + for(int i=0;i<txt.length();i++) { if (((i>0 && txt[i-1]=='\n') || (i==0 /*&& selection.from_column==0*/)) && (txt[i]=='\t' || txt[i]==' ')) { txt.remove(i); @@ -1568,21 +1568,21 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } } } else { - + for(int i=0;i<txt.length();i++) { - + if (((i>0 && txt[i-1]=='\n') || (i==0 /*&& selection.from_column==0*/))) { txt=txt.insert(i,"\t"); //i--; } } } - + if (txt!=prev_txt) { - + int sel_line=selection.from_line; int sel_column=selection.from_column; - + cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); _begin_compex_operation(); @@ -1596,10 +1596,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { selection.to_line=cursor.line; update(); } - + dobreak=true; accept_event(); - + } break; case KEY_X: case KEY_C: @@ -1624,21 +1624,21 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { break; unselect=true; break; - + default: if (k.unicode>=32 && !k.mod.command && !k.mod.alt && !k.mod.meta) clear=true; if (auto_brace_completion_enabled && _is_pair_left_symbol(k.unicode)) clear=false; } - + if (unselect) { selection.active=false; selection.selecting_mode=Selection::MODE_NONE; update(); } if (clear) { - + selection.active=false; update(); _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); @@ -1649,15 +1649,15 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { if (dobreak) break; } - + selection.selecting_text=false; - + bool scancode_handled=true; - + // special scancode test... - + switch (k.scancode) { - + case KEY_ENTER: case KEY_RETURN: { @@ -1665,7 +1665,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { break; String ins="\n"; - + //keep indentation for(int i=0;i<text[cursor.line].length();i++) { if (text[cursor.line][i]=='\t') @@ -1697,37 +1697,37 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { cursor_set_column(text[cursor.line].length()); } } - + _insert_text_at_cursor(ins); _push_current_op(); if (first_line) { cursor_set_line(0); } - + } break; case KEY_ESCAPE: { if (completion_hint!="") { completion_hint=""; update(); - + } } break; case KEY_TAB: { - + if (readonly) break; - + if (selection.active) { - - + + } else { if (k.mod.shift) { - + int cc = cursor.column; if (cc>0 && cc<=text[cursor.line].length() && text[cursor.line][cursor.column-1]=='\t') { //simple unindent - + backspace_at_cursor(); } } else { @@ -1735,7 +1735,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { _insert_text_at_cursor("\t"); } } - + } break; case KEY_BACKSPACE: { if (readonly) @@ -1803,15 +1803,15 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { // numlock disabled. fallthrough to key_left } case KEY_LEFT: { - + if (k.mod.shift) _pre_shift_selection(); - + #ifdef APPLE_STYLE_KEYS if (k.mod.command) { cursor_set_column(0); } else if (k.mod.alt) { - + #else if (k.mod.alt) { scancode_handled=false; @@ -1821,21 +1821,21 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { bool prev_char=false; int cc=cursor.column; while (cc>0) { - + bool ischar=_is_text_char(text[cursor.line][cc-1]); - + if (prev_char && !ischar) break; - + prev_char=ischar; cc--; - + } - + cursor_set_column(cc); - + } else if (cursor.column==0) { - + if (cursor.line>0) { cursor_set_line(cursor.line-1); cursor_set_column(text[cursor.line].length()); @@ -1843,10 +1843,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } else { cursor_set_column(cursor_get_column()-1); } - + if (k.mod.shift) _post_shift_selection(); - + } break; case KEY_KP_6: { if (k.unicode != 0) { @@ -1856,10 +1856,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { // numlock disabled. fallthrough to key_right } case KEY_RIGHT: { - + if (k.mod.shift) _pre_shift_selection(); - + #ifdef APPLE_STYLE_KEYS if (k.mod.command) { cursor_set_column(text[cursor.line].length()); @@ -1873,19 +1873,19 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { bool prev_char=false; int cc=cursor.column; while (cc<text[cursor.line].length()) { - + bool ischar=_is_text_char(text[cursor.line][cc]); - + if (prev_char && !ischar) break; prev_char=ischar; cc++; } - + cursor_set_column(cc); - + } else if (cursor.column==text[cursor.line].length()) { - + if (cursor.line<text.size()-1) { cursor_set_line(cursor.line+1); cursor_set_column(0); @@ -1893,10 +1893,10 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } else { cursor_set_column(cursor_get_column()+1); } - + if (k.mod.shift) _post_shift_selection(); - + } break; case KEY_KP_8: { if (k.unicode != 0) { @@ -1906,7 +1906,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { // numlock disabled. fallthrough to key_up } case KEY_UP: { - + if (k.mod.shift) _pre_shift_selection(); if (k.mod.alt) { @@ -1919,11 +1919,11 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { else #endif cursor_set_line(cursor_get_line()-1); - + if (k.mod.shift) _post_shift_selection(); _cancel_code_hint(); - + } break; case KEY_KP_2: { if (k.unicode != 0) { @@ -1933,7 +1933,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { // numlock disabled. fallthrough to key_down } case KEY_DOWN: { - + if (k.mod.shift) _pre_shift_selection(); if (k.mod.alt) { @@ -1946,22 +1946,22 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { else #endif cursor_set_line(cursor_get_line()+1); - + if (k.mod.shift) _post_shift_selection(); _cancel_code_hint(); - + } break; - + case KEY_DELETE: { - + if (readonly) break; int curline_len = text[cursor.line].length(); - + if (cursor.line==text.size()-1 && cursor.column==curline_len) break; //nothing to do - + int next_line=cursor.column<curline_len?cursor.line:cursor.line+1; int next_column; @@ -2029,24 +2029,24 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } #ifdef APPLE_STYLE_KEYS case KEY_HOME: { - - + + if (k.mod.shift) _pre_shift_selection(); - + cursor_set_line(0); - + if (k.mod.shift) _post_shift_selection(); - + } break; #else case KEY_HOME: { - - + + if (k.mod.shift) _pre_shift_selection(); - + // compute whitespace symbols seq length int current_line_whitespace_len = 0; while(current_line_whitespace_len < text[cursor.line].length()) { @@ -2055,20 +2055,20 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { break; current_line_whitespace_len++; } - + if(cursor_get_column() == current_line_whitespace_len) cursor_set_column(0); else cursor_set_column(current_line_whitespace_len); - + if (k.mod.command) cursor_set_line(0); - + if (k.mod.shift) _post_shift_selection(); _cancel_completion(); completion_hint=""; - + } break; #endif case KEY_KP_1: { @@ -2092,20 +2092,20 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } break; #else case KEY_END: { - + if (k.mod.shift) _pre_shift_selection(); - + if (k.mod.command) cursor_set_line(text.size()-1); cursor_set_column(text[cursor.line].length()); - + if (k.mod.shift) _post_shift_selection(); _cancel_completion(); completion_hint=""; - + } break; #endif case KEY_KP_9: { @@ -2116,19 +2116,19 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { // numlock disabled. fallthrough to key_pageup } case KEY_PAGEUP: { - + if (k.mod.shift) _pre_shift_selection(); - + cursor_set_line(cursor_get_line()-get_visible_rows()); - + if (k.mod.shift) _post_shift_selection(); _cancel_completion(); completion_hint=""; - + } break; case KEY_KP_3: { if (k.unicode != 0) { @@ -2138,75 +2138,75 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { // numlock disabled. fallthrough to key_pageup } case KEY_PAGEDOWN: { - + if (k.mod.shift) _pre_shift_selection(); - + cursor_set_line(cursor_get_line()+get_visible_rows()); - + if (k.mod.shift) _post_shift_selection(); _cancel_completion(); completion_hint=""; - + } break; case KEY_A: { - + if (!k.mod.command || k.mod.shift || k.mod.alt) { scancode_handled=false; break; } - + select_all(); - + } break; case KEY_X: { - + if (!k.mod.command || k.mod.shift || k.mod.alt) { scancode_handled=false; break; } - + if (!selection.active){ - + String clipboard = text[cursor.line]; OS::get_singleton()->set_clipboard(clipboard); cursor_set_line(cursor.line); cursor_set_column(0); _remove_text(cursor.line,0,cursor.line,text[cursor.line].length()); - + backspace_at_cursor(); update(); cursor_set_line(cursor.line+1); cut_copy_line = true; - + } else { - + String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); OS::get_singleton()->set_clipboard(clipboard); - + cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); - + _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); selection.active=false; selection.selecting_mode=Selection::MODE_NONE; update(); cut_copy_line = false; } - + } break; case KEY_C: { - + if (!k.mod.command || k.mod.shift || k.mod.alt) { scancode_handled=false; break; } - + if (!selection.active){ String clipboard = _base_get_text(cursor.line,0,cursor.line,text[cursor.line].length()); OS::get_singleton()->set_clipboard(clipboard); @@ -2219,32 +2219,32 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } } break; case KEY_Z: { - + if (!k.mod.command) { scancode_handled=false; break; } - + if (k.mod.shift) redo(); else undo(); } break; case KEY_V: { - + if (!k.mod.command || k.mod.shift || k.mod.alt) { scancode_handled=false; break; } - + String clipboard = OS::get_singleton()->get_clipboard(); - + if (selection.active) { selection.active=false; _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); - + } else if (cut_copy_line) { @@ -2252,9 +2252,9 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { String ins="\n"; clipboard += ins; } - + _insert_text_at_cursor(clipboard); - + update(); } break; case KEY_SPACE: { @@ -2263,15 +2263,15 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { #else if (completion_enabled && k.mod.command) { #endif - + query_code_comple(); scancode_handled=true; } else { scancode_handled=false; } - + } break; - + case KEY_U:{ if (!k.mod.command || k.mod.shift) { scancode_handled=false; @@ -2294,40 +2294,40 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { update(); } break;} - + default: { - + scancode_handled=false; } break; - + } - + if (scancode_handled) accept_event(); /* if (!scancode_handled && !k.mod.command && !k.mod.alt) { - + if (k.unicode>=32) { - + if (readonly) break; - + accept_event(); } else { - + break; } } */ if (!scancode_handled && !k.mod.command) { //for german kbds - + if (k.unicode>=32) { - + if (readonly) break; - + const CharType chr[2] = {(CharType)k.unicode, 0}; - + if (completion_hint!="" && k.unicode==')') { completion_hint=""; } @@ -2336,27 +2336,27 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { } else { _insert_text_at_cursor(chr); } - + accept_event(); } else { - + break; } } - + return; } break; - + } - + } void TextEdit::_pre_shift_selection() { - - + + if (!selection.active || selection.selecting_mode==Selection::MODE_NONE) { - + selection.selecting_line=cursor.line; selection.selecting_column=cursor.column; selection.active=true; @@ -2366,115 +2366,115 @@ void TextEdit::_pre_shift_selection() { } void TextEdit::_post_shift_selection() { - - + + if (selection.active && selection.selecting_mode==Selection::MODE_SHIFT) { - + select(selection.selecting_line,selection.selecting_column,cursor.line,cursor.column); update(); } - - + + selection.selecting_text=true; } /**** TEXT EDIT CORE API ****/ void TextEdit::_base_insert_text(int p_line, int p_char,const String& p_text,int &r_end_line,int &r_end_column) { - + //save for undo... ERR_FAIL_INDEX(p_line,text.size()); ERR_FAIL_COND(p_char<0); - + /* STEP 1 add spaces if the char is greater than the end of the line */ while(p_char>text[p_line].length()) { - + text.set(p_line,text[p_line]+String::chr(' ')); } - + /* STEP 2 separate dest string in pre and post text */ - + String preinsert_text = text[p_line].substr(0,p_char); String postinsert_text = text[p_line].substr(p_char,text[p_line].size()); - + /* STEP 3 remove \r from source text and separate in substrings */ - + //buh bye \r and split Vector<String> substrings = p_text.replace("\r","").split("\n"); - - + + for(int i=0;i<substrings.size();i++) { //insert the substrings - + if (i==0) { - + text.set(p_line,preinsert_text+substrings[i]); } else { - + text.insert(p_line+i,substrings[i]); } - + if (i==substrings.size()-1){ - + text.set(p_line+i,text[p_line+i]+postinsert_text); } } - + r_end_line=p_line+substrings.size()-1; r_end_column=text[r_end_line].length()-postinsert_text.length(); - + if (!text_changed_dirty && !setting_text) { if (is_inside_tree()) MessageQueue::get_singleton()->push_call(this,"_text_changed_emit"); text_changed_dirty=true; } - + } String TextEdit::_base_get_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) const { - + ERR_FAIL_INDEX_V(p_from_line,text.size(),String()); ERR_FAIL_INDEX_V(p_from_column,text[p_from_line].length()+1,String()); ERR_FAIL_INDEX_V(p_to_line,text.size(),String()); ERR_FAIL_INDEX_V(p_to_column,text[p_to_line].length()+1,String()); ERR_FAIL_COND_V(p_to_line < p_from_line ,String()); // from > to ERR_FAIL_COND_V(p_to_line == p_from_line && p_to_column<p_from_column,String()); // from > to - + String ret; - + for(int i=p_from_line;i<=p_to_line;i++) { - + int begin = (i==p_from_line)?p_from_column:0; int end = (i==p_to_line)?p_to_column:text[i].length(); - + if (i>p_from_line) ret+="\n"; ret+=text[i].substr(begin,end-begin); } - + return ret; } void TextEdit::_base_remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) { - + ERR_FAIL_INDEX(p_from_line,text.size()); ERR_FAIL_INDEX(p_from_column,text[p_from_line].length()+1); ERR_FAIL_INDEX(p_to_line,text.size()); ERR_FAIL_INDEX(p_to_column,text[p_to_line].length()+1); ERR_FAIL_COND(p_to_line < p_from_line ); // from > to ERR_FAIL_COND(p_to_line == p_from_line && p_to_column<p_from_column); // from > to - - + + String pre_text = text[p_from_line].substr(0,p_from_column); String post_text = text[p_to_line].substr(p_to_column,text[p_to_line].length()); - + for(int i=p_from_line;i<p_to_line;i++) { - + text.remove(p_from_line+1); } - + text.set(p_from_line,pre_text+post_text); - + if (!text_changed_dirty && !setting_text) { if (is_inside_tree()) MessageQueue::get_singleton()->push_call(this,"_text_changed_emit"); @@ -2483,24 +2483,24 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column,int p_to_lin } void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_end_line,int *r_end_column) { - + if (!setting_text) idle_detect->start(); - + if (undo_enabled) { _clear_redo(); } - + int retline,retchar; _base_insert_text(p_line,p_char,p_text,retline,retchar); if (r_end_line) *r_end_line=retline; if (r_end_column) *r_end_column=retchar; - + if (!undo_enabled) return; - + /* UNDO!! */ TextOperation op; op.type=TextOperation::TYPE_INSERT; @@ -2512,12 +2512,12 @@ void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_e op.version=++version; op.chain_forward=false; op.chain_backward=false; - + //see if it shold just be set as current op if (current_op.type!=op.type) { _push_current_op(); current_op=op; - + return; //set as current op, return } //see if it can be merged @@ -2527,30 +2527,30 @@ void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_e return; //set as current op, return } //merge current op - + current_op.text+=p_text; current_op.to_column=retchar; current_op.to_line=retline; current_op.version=op.version; - + } void TextEdit::_remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) { - + if (!setting_text) idle_detect->start(); - + String text; if (undo_enabled) { _clear_redo(); text=_base_get_text(p_from_line,p_from_column,p_to_line,p_to_column); } - + _base_remove_text(p_from_line,p_from_column,p_to_line,p_to_column); - + if (!undo_enabled) return; - + /* UNDO!! */ TextOperation op; op.type=TextOperation::TYPE_REMOVE; @@ -2562,7 +2562,7 @@ void TextEdit::_remove_text(int p_from_line, int p_from_column,int p_to_line,int op.version=++version; op.chain_forward=false; op.chain_backward=false; - + //see if it shold just be set as current op if (current_op.type!=op.type) { _push_current_op(); @@ -2578,26 +2578,26 @@ void TextEdit::_remove_text(int p_from_line, int p_from_column,int p_to_line,int return; //update current op } if (current_op.from_line==p_from_line && current_op.from_column==p_from_column) { - + //current_op.text=text+current_op.text; //current_op.from_line=p_from_line; //current_op.from_column=p_from_column; //return; //update current op } - + _push_current_op(); current_op=op; - + } void TextEdit::_insert_text_at_cursor(const String& p_text) { - + int new_column,new_line; _insert_text(cursor.line,cursor.column,p_text,&new_line,&new_column); cursor_set_line(new_line); cursor_set_column(new_column); - + update(); } @@ -2605,144 +2605,144 @@ void TextEdit::_insert_text_at_cursor(const String& p_text) { int TextEdit::get_char_count() { - + int totalsize=0; - + for (int i=0;i<text.size();i++) { - + if (i>0) totalsize++; // incliude \n totalsize+=text[i].length(); } - + return totalsize; // omit last \n } Size2 TextEdit::get_minimum_size() { - + return cache.style_normal->get_minimum_size(); } int TextEdit::get_visible_rows() const { - + int total=cache.size.height; total-=cache.style_normal->get_minimum_size().height; total/=get_row_height(); return total; } void TextEdit::adjust_viewport_to_cursor() { - + if (cursor.line_ofs>cursor.line) cursor.line_ofs=cursor.line; - + int visible_width=cache.size.width-cache.style_normal->get_minimum_size().width-cache.line_number_w; if (v_scroll->is_visible()) visible_width-=v_scroll->get_combined_minimum_size().width; visible_width-=20; // give it a little more space - - + + //printf("rowofs %i, visrows %i, cursor.line %i\n",cursor.line_ofs,get_visible_rows(),cursor.line); - + int visible_rows = get_visible_rows(); if (h_scroll->is_visible()) visible_rows-=((h_scroll->get_combined_minimum_size().height-1)/get_row_height()); - + if (cursor.line>=(cursor.line_ofs+visible_rows)) cursor.line_ofs=cursor.line-visible_rows+1; if (cursor.line<cursor.line_ofs) cursor.line_ofs=cursor.line; - + int cursor_x = get_column_x_offset( cursor.column, text[cursor.line] ); - + if (cursor_x>(cursor.x_ofs+visible_width)) cursor.x_ofs=cursor_x-visible_width+1; - + if (cursor_x < cursor.x_ofs) cursor.x_ofs=cursor_x; - + update(); /* get_range()->set_max(text.size()); - + get_range()->set_page(get_visible_rows()); - + get_range()->set((int)cursor.line_ofs); */ - - + + } void TextEdit::cursor_set_column(int p_col, bool p_adjust_viewport) { - + if (p_col<0) p_col=0; - + cursor.column=p_col; if (cursor.column > get_line( cursor.line ).length()) cursor.column=get_line( cursor.line ).length(); - + cursor.last_fit_x=get_column_x_offset(cursor.column,get_line(cursor.line)); - + if (p_adjust_viewport) adjust_viewport_to_cursor(); - + if (!cursor_changed_dirty) { if (is_inside_tree()) MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit"); cursor_changed_dirty=true; } - + } void TextEdit::cursor_set_line(int p_row, bool p_adjust_viewport) { - + if (setting_row) return; - + setting_row=true; if (p_row<0) p_row=0; - - + + if (p_row>=(int)text.size()) p_row=(int)text.size()-1; - + cursor.line=p_row; cursor.column=get_char_pos_for( cursor.last_fit_x, get_line( cursor.line) ); - + if (p_adjust_viewport) adjust_viewport_to_cursor(); - + setting_row=false; - - + + if (!cursor_changed_dirty) { if (is_inside_tree()) MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit"); cursor_changed_dirty=true; } - + } int TextEdit::cursor_get_column() const { - + return cursor.column; } int TextEdit::cursor_get_line() const { - + return cursor.line; } void TextEdit::_scroll_moved(double p_to_val) { - + if (updating_scrolls) return; - + if (h_scroll->is_visible()) cursor.x_ofs=h_scroll->get_val(); if (v_scroll->is_visible()) @@ -2755,87 +2755,87 @@ void TextEdit::_scroll_moved(double p_to_val) { int TextEdit::get_row_height() const { - + return cache.font->get_height()+cache.line_spacing; } int TextEdit::get_char_pos_for(int p_px,String p_str) const { - + int px=0; int c=0; - + int tab_w = cache.font->get_char_size(' ').width*tab_size; - + while (c<p_str.length()) { - + int w=0; - + if (p_str[c]=='\t') { - + int left = px%tab_w; if (left==0) w=tab_w; else w=tab_w-px%tab_w; // is right... - + } else { - + w=cache.font->get_char_size(p_str[c],p_str[c+1]).width; } - + if (p_px<(px+w/2)) break; px+=w; c++; } - + return c; } int TextEdit::get_column_x_offset(int p_char,String p_str) { - + int px=0; - + int tab_w = cache.font->get_char_size(' ').width*tab_size; - + for (int i=0;i<p_char;i++) { - + if (i>=p_str.length()) break; - + if (p_str[i]=='\t') { - + int left = px%tab_w; if (left==0) px+=tab_w; else px+=tab_w-px%tab_w; // is right... - + } else { px+=cache.font->get_char_size(p_str[i],p_str[i+1]).width; } } - + return px; - + } void TextEdit::insert_text_at_cursor(const String& p_text) { - + if (selection.active) { - + cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); - + _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); selection.active=false; selection.selecting_mode=Selection::MODE_NONE; - + } - + _insert_text_at_cursor(p_text); update(); - + } Control::CursorShape TextEdit::get_cursor_shape(const Point2& p_pos) const { @@ -2847,7 +2847,7 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2& p_pos) const { void TextEdit::set_text(String p_text){ - + setting_text=true; clear(); _insert_text_at_cursor(p_text); @@ -2861,7 +2861,7 @@ void TextEdit::set_text(String p_text){ cursor_set_column(0); update(); setting_text=false; - + //get_range()->set(0); }; @@ -2869,53 +2869,53 @@ String TextEdit::get_text() { String longthing; int len = text.size(); for (int i=0;i<len;i++) { - - + + longthing+=text[i]; if (i!=len-1) longthing+="\n"; } - + return longthing; - + }; String TextEdit::get_text_for_completion() { - + String longthing; int len = text.size(); for (int i=0;i<len;i++) { - + if (i==cursor.line) { longthing+=text[i].substr(0,cursor.column); longthing+=String::chr(0xFFFF); //not unicode, represents the cursor longthing+=text[i].substr(cursor.column,text[i].size()); } else { - + longthing+=text[i]; } - - + + if (i!=len-1) longthing+="\n"; } - + return longthing; - + }; String TextEdit::get_line(int line) const { - + if (line<0 || line>=text.size()) return ""; - + return text[line]; - + }; void TextEdit::_clear() { - + clear_undo_history(); text.clear(); cursor.column=0; @@ -2928,31 +2928,31 @@ void TextEdit::_clear() { void TextEdit::clear() { - + setting_text=true; _clear(); setting_text=false; - + }; void TextEdit::set_readonly(bool p_readonly) { - - + + readonly=p_readonly; } void TextEdit::set_wrap(bool p_wrap) { - + wrap=p_wrap; } void TextEdit::set_max_chars(int p_max_chars) { - + max_chars=p_max_chars; } void TextEdit::_update_caches() { - + cache.style_normal=get_stylebox("normal"); cache.style_focus=get_stylebox("focus"); cache.font=get_font("font"); @@ -2968,12 +2968,12 @@ void TextEdit::_update_caches() { cache.row_height = cache.font->get_height() + cache.line_spacing; cache.tab_icon=get_icon("tab"); text.set_font(cache.font); - + } void TextEdit::clear_colors() { - + keywords.clear(); color_regions.clear();; text.clear_caches(); @@ -2981,40 +2981,40 @@ void TextEdit::clear_colors() { } void TextEdit::set_custom_bg_color(const Color& p_color) { - + custom_bg_color=p_color; update(); } void TextEdit::add_keyword_color(const String& p_keyword,const Color& p_color) { - + keywords[p_keyword]=p_color; update(); - + } void TextEdit::add_color_region(const String& p_begin_key,const String& p_end_key,const Color &p_color,bool p_line_only) { - + color_regions.push_back(ColorRegion(p_begin_key,p_end_key,p_color,p_line_only)); text.clear_caches(); update(); - + } void TextEdit::set_symbol_color(const Color& p_color) { - + symbol_color=p_color; update(); } void TextEdit::set_syntax_coloring(bool p_enabled) { - + syntax_coloring=p_enabled; update(); } bool TextEdit::is_syntax_coloring_enabled() const { - + return syntax_coloring; } @@ -3023,28 +3023,28 @@ void TextEdit::set_auto_indent(bool p_auto_indent) { } void TextEdit::cut() { - + if (!selection.active) return; - + String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); OS::get_singleton()->set_clipboard(clipboard); - + cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); - + _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); selection.active=false; selection.selecting_mode=Selection::MODE_NONE; update(); - + } void TextEdit::copy() { - + if (!selection.active) return; - + print_line("from line: "+itos(selection.from_line)); print_line("from column: "+itos(selection.from_column)); print_line("to line: "+itos(selection.to_line)); @@ -3052,29 +3052,29 @@ void TextEdit::copy() { String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); OS::get_singleton()->set_clipboard(clipboard); - + } void TextEdit::paste() { - + if (selection.active) { - + cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); - + _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); selection.active=false; selection.selecting_mode=Selection::MODE_NONE; - + } - + String clipboard = OS::get_singleton()->get_clipboard(); _insert_text_at_cursor(clipboard); update(); - + } void TextEdit::select_all() { - + if (text.size()==1 && text[0].length()==0) return; selection.active=true; @@ -3089,43 +3089,43 @@ void TextEdit::select_all() { cursor_set_line( selection.to_line, false ); cursor_set_column( selection.to_column, false ); update(); - + } void TextEdit::deselect() { - + selection.active=false; update(); } void TextEdit::select(int p_from_line,int p_from_column,int p_to_line,int p_to_column) { - + if (p_from_line>=text.size()) p_from_line=text.size()-1; if (p_from_column>=text[p_from_line].length()) p_from_column=text[p_from_line].length(); - + if (p_to_line>=text.size()) p_to_line=text.size()-1; if (p_to_column>=text[p_to_line].length()) p_to_column=text[p_to_line].length(); - + selection.from_line=p_from_line; selection.from_column=p_from_column; selection.to_line=p_to_line; selection.to_column=p_to_column; - + selection.active=true; - + if (selection.from_line==selection.to_line) { - + if (selection.from_column==selection.to_column) { - + selection.active=false; - + } else if (selection.from_column>selection.to_column) { - + selection.shiftclick_left = false; SWAP( selection.from_column, selection.to_column ); } else { @@ -3133,7 +3133,7 @@ void TextEdit::select(int p_from_line,int p_from_column,int p_to_line,int p_to_c selection.shiftclick_left = true; } } else if (selection.from_line>selection.to_line) { - + selection.shiftclick_left = false; SWAP( selection.from_line, selection.to_line ); SWAP( selection.from_column, selection.to_column ); @@ -3141,51 +3141,51 @@ void TextEdit::select(int p_from_line,int p_from_column,int p_to_line,int p_to_c selection.shiftclick_left = true; } - - + + update(); } bool TextEdit::is_selection_active() const { - + return selection.active; } int TextEdit::get_selection_from_line() const { - + ERR_FAIL_COND_V(!selection.active,-1); return selection.from_line; - + } int TextEdit::get_selection_from_column() const { - + ERR_FAIL_COND_V(!selection.active,-1); return selection.from_column; - + } int TextEdit::get_selection_to_line() const { - + ERR_FAIL_COND_V(!selection.active,-1); return selection.to_line; - + } int TextEdit::get_selection_to_column() const { - + ERR_FAIL_COND_V(!selection.active,-1); return selection.to_column; - + } String TextEdit::get_selection_text() const { - + if (!selection.active) return ""; - + return _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column); - + } String TextEdit::get_word_under_cursor() const { - + int prev_cc = cursor.column; while(prev_cc >0) { bool is_char = _is_text_char(text[cursor.line][prev_cc-1]); @@ -3193,7 +3193,7 @@ String TextEdit::get_word_under_cursor() const { break; --prev_cc; } - + int next_cc = cursor.column; while(next_cc<text[cursor.line].length()) { bool is_char = _is_text_char(text[cursor.line][next_cc]); @@ -3207,7 +3207,7 @@ String TextEdit::get_word_under_cursor() const { } DVector<int> TextEdit::_search_bind(const String &p_key,uint32_t p_search_flags, int p_from_line,int p_from_column) const { - + int col,line; if (search(p_key,p_search_flags,p_from_line,p_from_column,col,line)) { DVector<int> result; @@ -3215,46 +3215,46 @@ DVector<int> TextEdit::_search_bind(const String &p_key,uint32_t p_search_flags, result.set(0,line); result.set(1,col); return result; - + } else { - + return DVector<int>(); } } bool TextEdit::search(const String &p_key,uint32_t p_search_flags, int p_from_line, int p_from_column,int &r_line,int &r_column) const { - + if (p_key.length()==0) return false; ERR_FAIL_INDEX_V(p_from_line,text.size(),false); ERR_FAIL_INDEX_V(p_from_column,text[p_from_line].length()+1,false); - + //search through the whole documment, but start by current line - + int line=-1; int pos=-1; - + line=p_from_line; - + for(int i=0;i<text.size()+1;i++) { //backwards is broken... //int idx=(p_search_flags&SEARCH_BACKWARDS)?(text.size()-i):i; //do backwards seearch - - + + if (line<0) { line=text.size()-1; } if (line==text.size()) { line=0; } - + String text_line = text[line]; int from_column=0; if (line==p_from_line) { - + if (i==text.size()) { //wrapped - + if (p_search_flags&SEARCH_BACKWARDS) { text_line=text_line.substr(from_column,text_line.length()); from_column=text_line.length(); @@ -3262,13 +3262,13 @@ bool TextEdit::search(const String &p_key,uint32_t p_search_flags, int p_from_li text_line=text_line.substr(0,from_column); from_column=0; } - + } else { - + from_column=p_from_column; } - - + + } else { //text_line=text_line.substr(0,p_from_column); //wrap around for missing begining. if (p_search_flags&SEARCH_BACKWARDS) @@ -3276,17 +3276,17 @@ bool TextEdit::search(const String &p_key,uint32_t p_search_flags, int p_from_li else from_column=0; } - + pos=-1; - + if (!(p_search_flags&SEARCH_BACKWARDS)) { - + pos = (p_search_flags&SEARCH_MATCH_CASE)?text_line.find(p_key,from_column):text_line.findn(p_key,from_column); } else { - + pos = (p_search_flags&SEARCH_MATCH_CASE)?text_line.rfind(p_key,from_column):text_line.rfindn(p_key,from_column); } - + if (pos!=-1 && (p_search_flags&SEARCH_WHOLE_WORDS)) { //validate for whole words if (pos>0 && _is_text_char(text_line[pos-1])) @@ -3294,66 +3294,66 @@ bool TextEdit::search(const String &p_key,uint32_t p_search_flags, int p_from_li else if (_is_text_char(text_line[pos+p_key.length()])) pos=-1; } - + if (pos!=-1) break; - + if (p_search_flags&SEARCH_BACKWARDS) line--; else line++; - + } - + if (pos==-1) { r_line=-1; r_column=-1; return false; } - + r_line=line; r_column=pos; - - + + return true; } void TextEdit::_cursor_changed_emit() { - + emit_signal("cursor_changed"); cursor_changed_dirty=false; } void TextEdit::_text_changed_emit() { - + emit_signal("text_changed"); text_changed_dirty=false; } void TextEdit::set_line_as_marked(int p_line,bool p_marked) { - + ERR_FAIL_INDEX(p_line,text.size()); text.set_marked(p_line,p_marked); update(); } bool TextEdit::is_line_set_as_breakpoint(int p_line) const { - + ERR_FAIL_INDEX_V(p_line,text.size(),false); return text.is_breakpoint(p_line); - + } void TextEdit::set_line_as_breakpoint(int p_line,bool p_breakpoint) { - - + + ERR_FAIL_INDEX(p_line,text.size()); text.set_breakpoint(p_line,p_breakpoint); update(); } void TextEdit::get_breakpoints(List<int> *p_breakpoints) const { - + for(int i=0;i<text.size();i++) { if (text.is_breakpoint(i)) p_breakpoints->push_back(i); @@ -3361,39 +3361,39 @@ void TextEdit::get_breakpoints(List<int> *p_breakpoints) const { } int TextEdit::get_line_count() const { - + return text.size(); } void TextEdit::_do_text_op(const TextOperation& p_op, bool p_reverse) { - + ERR_FAIL_COND(p_op.type==TextOperation::TYPE_NONE); - + bool insert = p_op.type==TextOperation::TYPE_INSERT; if (p_reverse) insert=!insert; - + if (insert) { - + int check_line; int check_column; _base_insert_text(p_op.from_line,p_op.from_column,p_op.text,check_line,check_column); ERR_FAIL_COND( check_line != p_op.to_line ); // BUG ERR_FAIL_COND( check_column != p_op.to_column ); // BUG } else { - + _base_remove_text(p_op.from_line,p_op.from_column,p_op.to_line,p_op.to_column); } - + } void TextEdit::_clear_redo() { - + if (undo_stack_pos==NULL) return; //nothing to clear - + _push_current_op(); - + while (undo_stack_pos) { List<TextOperation>::Element *elem = undo_stack_pos; undo_stack_pos=undo_stack_pos->next(); @@ -3403,21 +3403,21 @@ void TextEdit::_clear_redo() { void TextEdit::undo() { - + _push_current_op(); - + if (undo_stack_pos==NULL) { - + if (!undo_stack.size()) return; //nothing to undo - + undo_stack_pos=undo_stack.back(); - + } else if (undo_stack_pos==undo_stack.front()) return; // at the bottom of the undo stack else undo_stack_pos=undo_stack_pos->prev(); - + _do_text_op( undo_stack_pos->get(),true); if(undo_stack_pos->get().chain_backward) { do { @@ -3425,19 +3425,19 @@ void TextEdit::undo() { _do_text_op(undo_stack_pos->get(), true); } while(!undo_stack_pos->get().chain_forward); } - + cursor_set_line(undo_stack_pos->get().from_line); cursor_set_column(undo_stack_pos->get().from_column); update(); } void TextEdit::redo() { - + _push_current_op(); - + if (undo_stack_pos==NULL) return; //nothing to do. - + _do_text_op(undo_stack_pos->get(), false); if(undo_stack_pos->get().chain_forward) { do { @@ -3452,12 +3452,12 @@ void TextEdit::redo() { } void TextEdit::clear_undo_history() { - + saved_version=0; current_op.type=TextOperation::TYPE_NONE; undo_stack_pos=NULL; undo_stack.clear(); - + } void TextEdit::_begin_compex_operation() { @@ -3466,42 +3466,42 @@ void TextEdit::_begin_compex_operation() { } void TextEdit::_end_compex_operation() { - + _push_current_op(); ERR_FAIL_COND(undo_stack.size() == 0); - + if(undo_stack.back()->get().chain_forward) { undo_stack.back()->get().chain_forward=false; return; } - + undo_stack.back()->get().chain_backward=true; } void TextEdit::_push_current_op() { - + if (current_op.type==TextOperation::TYPE_NONE) return; // do nothing - + if(next_operation_is_complex) { current_op.chain_forward=true; next_operation_is_complex=false; } - + undo_stack.push_back(current_op); current_op.type=TextOperation::TYPE_NONE; current_op.text=""; current_op.chain_forward=false; - + } void TextEdit::set_draw_tabs(bool p_draw) { - + draw_tabs=p_draw; } bool TextEdit::is_drawing_tabs() const{ - + return draw_tabs; } @@ -3509,35 +3509,35 @@ uint32_t TextEdit::get_version() const { return current_op.version; } uint32_t TextEdit::get_saved_version() const { - + return saved_version; } void TextEdit::tag_saved_version() { - + saved_version=get_version(); } int TextEdit::get_v_scroll() const { - + return v_scroll->get_val(); } void TextEdit::set_v_scroll(int p_scroll) { - + v_scroll->set_val(p_scroll); cursor.line_ofs=p_scroll; } int TextEdit::get_h_scroll() const { - + return h_scroll->get_val(); } void TextEdit::set_h_scroll(int p_scroll) { - + h_scroll->set_val(p_scroll); } void TextEdit::set_completion(bool p_enabled,const Vector<String>& p_prefixes) { - + completion_prefixes.clear(); completion_enabled=p_enabled; for(int i=0;i<p_prefixes.size();i++) @@ -3545,7 +3545,7 @@ void TextEdit::set_completion(bool p_enabled,const Vector<String>& p_prefixes) { } void TextEdit::_confirm_completion() { - + String remaining=completion_current.substr(completion_base.length(),completion_current.length()-completion_base.length()); String l = text[cursor.line]; bool same=true; @@ -3557,7 +3557,7 @@ void TextEdit::_confirm_completion() { break; } } - + if (same) cursor_set_column(cursor.column+remaining.length()); else { @@ -3567,7 +3567,7 @@ void TextEdit::_confirm_completion() { cursor.column--; } } - + _cancel_completion(); } @@ -3578,27 +3578,27 @@ void TextEdit::_cancel_code_hint() { } void TextEdit::_cancel_completion() { - + if (!completion_active) return; - + completion_active=false; update(); - + } static bool _is_completable(CharType c) { - + return !_is_symbol(c) || c=='"' || c=='\''; } void TextEdit::_update_completion_candidates() { - + String l = text[cursor.line]; int cofs = CLAMP(cursor.column,0,l.length()); - - + + String s; //look for keywords first @@ -3654,15 +3654,15 @@ void TextEdit::_update_completion_candidates() { } } - + update(); - + if (cancel || (!pre_keyword && s=="" && (cofs==0 || !completion_prefixes.has(String::chr(l[cofs-1]))))) { //none to complete, cancel _cancel_completion(); return; } - + completion_options.clear(); completion_index=0; completion_base=s; @@ -3675,7 +3675,7 @@ void TextEdit::_update_completion_candidates() { if (max<ci_match) continue; for(int j=0;j<max;j++) { - + if (j>=completion_strings[i].length()) break; if (completion_current[j]!=completion_strings[i][j]) @@ -3686,21 +3686,21 @@ void TextEdit::_update_completion_candidates() { ci_match=m; completion_index=completion_options.size()-1; } - + } } - - - + + + if (completion_options.size()==0) { //no options to complete, cancel _cancel_completion(); return; - + } - + completion_current=completion_options[completion_index]; - + #if 0 // even there's only one option, user still get the chance to choose using it or not if (completion_options.size()==1) { //one option to complete, just complete it automagically @@ -3708,22 +3708,22 @@ void TextEdit::_update_completion_candidates() { // insert_text_at_cursor(completion_options[0].substr(s.length(),completion_options[0].length()-s.length())); _cancel_completion(); return; - + } #endif if (completion_options.size()==1 && s==completion_options[0]) _cancel_completion(); - + completion_enabled=true; } void TextEdit::query_code_comple() { - + String l = text[cursor.line]; int ofs = CLAMP(cursor.column,0,l.length()); - + bool inquote=false; int c=ofs-1; @@ -3735,20 +3735,20 @@ void TextEdit::query_code_comple() { if (ofs>0 && (inquote || _is_completable(l[ofs-1]) || completion_prefixes.has(String::chr(l[ofs-1])))) emit_signal("request_completion"); - + } void TextEdit::set_code_hint(const String& p_hint) { - + completion_hint=p_hint; completion_hint_offset=-0xFFFF; update(); } void TextEdit::code_complete(const Vector<String> &p_strings) { - - + + completion_strings=p_strings; completion_active=true; completion_current=""; @@ -3759,7 +3759,7 @@ void TextEdit::code_complete(const Vector<String> &p_strings) { String TextEdit::get_tooltip(const Point2& p_pos) const { - + if (!tooltip_obj) return Control::get_tooltip(p_pos); int row,col; @@ -3770,34 +3770,34 @@ String TextEdit::get_tooltip(const Point2& p_pos) const { return Control::get_tooltip(p_pos); int beg=CLAMP(col,0,s.length()); int end=beg; - - + + if (s[beg]>32 || beg==s.length()) { - + bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this - + while(beg>0 && s[beg-1]>32 && (symbol==_is_symbol(s[beg-1]))) { beg--; } while(end<s.length() && s[end+1]>32 && (symbol==_is_symbol(s[end+1]))) { end++; } - + if (end<s.length()) end+=1; - + String tt = tooltip_obj->call(tooltip_func,s.substr(beg,end-beg),tooltip_ud); - + return tt; - + } - + return Control::get_tooltip(p_pos); - + } void TextEdit::set_tooltip_request_func(Object *p_obj, const StringName& p_function,const Variant& p_udata) { - + tooltip_obj=p_obj; tooltip_func=p_function; tooltip_ud=p_udata; @@ -3822,7 +3822,7 @@ void TextEdit::insert_at(const String &p_text, int at) } void TextEdit::set_show_line_numbers(bool p_show) { - + line_numbers=p_show; update(); } @@ -3832,48 +3832,48 @@ bool TextEdit::is_text_field() const { return true; } void TextEdit::_bind_methods() { - - + + ObjectTypeDB::bind_method(_MD("_input_event"),&TextEdit::_input_event); ObjectTypeDB::bind_method(_MD("_scroll_moved"),&TextEdit::_scroll_moved); ObjectTypeDB::bind_method(_MD("_cursor_changed_emit"),&TextEdit::_cursor_changed_emit); ObjectTypeDB::bind_method(_MD("_text_changed_emit"),&TextEdit::_text_changed_emit); ObjectTypeDB::bind_method(_MD("_push_current_op"),&TextEdit::_push_current_op); ObjectTypeDB::bind_method(_MD("_click_selection_held"),&TextEdit::_click_selection_held); - + BIND_CONSTANT( SEARCH_MATCH_CASE ); BIND_CONSTANT( SEARCH_WHOLE_WORDS ); BIND_CONSTANT( SEARCH_BACKWARDS ); - + /* ObjectTypeDB::bind_method(_MD("delete_char"),&TextEdit::delete_char); ObjectTypeDB::bind_method(_MD("delete_line"),&TextEdit::delete_line); */ - + ObjectTypeDB::bind_method(_MD("set_text","text"),&TextEdit::set_text); ObjectTypeDB::bind_method(_MD("insert_text_at_cursor","text"),&TextEdit::insert_text_at_cursor); - + ObjectTypeDB::bind_method(_MD("get_line_count"),&TextEdit::get_line_count); ObjectTypeDB::bind_method(_MD("get_text"),&TextEdit::get_text); ObjectTypeDB::bind_method(_MD("get_line","line"),&TextEdit::get_line); - + ObjectTypeDB::bind_method(_MD("cursor_set_column","column","adjust_viewport"),&TextEdit::cursor_set_column,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("cursor_set_line","line","adjust_viewport"),&TextEdit::cursor_set_line,DEFVAL(false)); - + ObjectTypeDB::bind_method(_MD("cursor_get_column"),&TextEdit::cursor_get_column); ObjectTypeDB::bind_method(_MD("cursor_get_line"),&TextEdit::cursor_get_line); - - + + ObjectTypeDB::bind_method(_MD("set_readonly","enable"),&TextEdit::set_readonly); ObjectTypeDB::bind_method(_MD("set_wrap","enable"),&TextEdit::set_wrap); ObjectTypeDB::bind_method(_MD("set_max_chars","amount"),&TextEdit::set_max_chars); - + ObjectTypeDB::bind_method(_MD("cut"),&TextEdit::cut); ObjectTypeDB::bind_method(_MD("copy"),&TextEdit::copy); ObjectTypeDB::bind_method(_MD("paste"),&TextEdit::paste); ObjectTypeDB::bind_method(_MD("select_all"),&TextEdit::select_all); ObjectTypeDB::bind_method(_MD("select","from_line","from_column","to_line","to_column"),&TextEdit::select); - + ObjectTypeDB::bind_method(_MD("is_selection_active"),&TextEdit::is_selection_active); ObjectTypeDB::bind_method(_MD("get_selection_from_line"),&TextEdit::get_selection_from_line); ObjectTypeDB::bind_method(_MD("get_selection_from_column"),&TextEdit::get_selection_from_column); @@ -3882,30 +3882,30 @@ void TextEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_selection_text"),&TextEdit::get_selection_text); ObjectTypeDB::bind_method(_MD("get_word_under_cursor"),&TextEdit::get_word_under_cursor); ObjectTypeDB::bind_method(_MD("search","flags","from_line","from_column","to_line","to_column"),&TextEdit::_search_bind); - + ObjectTypeDB::bind_method(_MD("undo"),&TextEdit::undo); ObjectTypeDB::bind_method(_MD("redo"),&TextEdit::redo); ObjectTypeDB::bind_method(_MD("clear_undo_history"),&TextEdit::clear_undo_history); - + ObjectTypeDB::bind_method(_MD("set_syntax_coloring","enable"),&TextEdit::set_syntax_coloring); ObjectTypeDB::bind_method(_MD("is_syntax_coloring_enabled"),&TextEdit::is_syntax_coloring_enabled); - - + + ObjectTypeDB::bind_method(_MD("add_keyword_color","keyword","color"),&TextEdit::add_keyword_color); ObjectTypeDB::bind_method(_MD("add_color_region","begin_key","end_key","color","line_only"),&TextEdit::add_color_region,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("set_symbol_color","color"),&TextEdit::set_symbol_color); ObjectTypeDB::bind_method(_MD("set_custom_bg_color","color"),&TextEdit::set_custom_bg_color); ObjectTypeDB::bind_method(_MD("clear_colors"),&TextEdit::clear_colors); - - + + ADD_SIGNAL(MethodInfo("cursor_changed")); ADD_SIGNAL(MethodInfo("text_changed")); ADD_SIGNAL(MethodInfo("request_completion")); - + } TextEdit::TextEdit() { - + readonly=false; setting_row=false; draw_tabs=false; @@ -3925,29 +3925,29 @@ TextEdit::TextEdit() { // text.insert(1,"Mongolia.."); // text.insert(2,"PAIS GENEROSO!!"); text.set_color_regions(&color_regions); - + h_scroll = memnew( HScrollBar ); v_scroll = memnew( VScrollBar ); - + add_child(h_scroll); add_child(v_scroll); - + updating_scrolls=false; selection.active=false; - + h_scroll->connect("value_changed", this,"_scroll_moved"); v_scroll->connect("value_changed", this,"_scroll_moved"); - + cursor_changed_dirty=false; text_changed_dirty=false; - + selection.selecting_mode=Selection::MODE_NONE; selection.selecting_line=0; selection.selecting_column=0; selection.selecting_text=false; selection.active=false; syntax_coloring=false; - + custom_bg_color=Color(0,0,0,0); idle_detect = memnew( Timer ); add_child(idle_detect); @@ -3959,7 +3959,7 @@ TextEdit::TextEdit() { add_child(click_select_held); click_select_held->set_wait_time(0.05); click_select_held->connect("timeout", this,"_click_selection_held"); - + #if 0 syntax_coloring=true; keywords["void"]=Color(0.3,0.0,0.1); @@ -3969,15 +3969,15 @@ TextEdit::TextEdit() { keywords["extends"]=Color(0.3,0.0,0.1); keywords["constructor"]=Color(0.3,0.0,0.1); symbol_color=Color(0.1,0.0,0.3,1.0); - + color_regions.push_back(ColorRegion("/*","*/",Color(0.4,0.6,0,4))); color_regions.push_back(ColorRegion("//","",Color(0.6,0.6,0.4))); color_regions.push_back(ColorRegion("\"","\"",Color(0.4,0.7,0.7))); color_regions.push_back(ColorRegion("'","'",Color(0.4,0.8,0.8))); color_regions.push_back(ColorRegion("#","",Color(0.2,1.0,0.2))); - + #endif - + current_op.type=TextOperation::TYPE_NONE; undo_enabled=true; undo_stack_pos=NULL; @@ -3986,7 +3986,7 @@ TextEdit::TextEdit() { current_op.version=0; version=0; saved_version=0; - + completion_enabled=false; completion_active=false; completion_line_ofs=0; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 8d0efc406a..2eff8e89c7 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -128,7 +128,7 @@ class TextEdit : public Control { void set_font(const Ref<Font>& p_font); void set_color_regions(const Vector<ColorRegion>*p_regions) { color_regions=p_regions; } int get_line_width(int p_line) const; - int get_max_width() const; + int get_max_width() const; const Map<int,ColorRegionInfo>& get_color_region_info(int p_line); void set(int p_line,const String& p_string); void set_marked(int p_line,bool p_marked) { text[p_line].marked=p_marked; } @@ -210,7 +210,7 @@ class TextEdit : public Control { bool text_changed_dirty; bool undo_enabled; bool line_numbers; - + bool scroll_past_end_of_file_enabled; bool auto_brace_completion_enabled; bool brace_matching_enabled; @@ -229,7 +229,7 @@ class TextEdit : public Control { Object *tooltip_obj; StringName tooltip_func; Variant tooltip_ud; - + bool next_operation_is_complex; bool callhint_below; @@ -258,13 +258,13 @@ class TextEdit : public Control { void _update_caches(); void _cursor_changed_emit(); void _text_changed_emit(); - + void _begin_compex_operation(); void _end_compex_operation(); void _push_current_op(); /* super internal api, undo/redo builds on it */ - + void _base_insert_text(int p_line, int p_column,const String& p_text,int &r_end_line,int &r_end_column); String _base_get_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) const; void _base_remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column); @@ -282,16 +282,16 @@ class TextEdit : public Control { protected: virtual String get_tooltip(const Point2& p_pos) const; - + void _insert_text(int p_line, int p_column,const String& p_text,int *r_end_line=NULL,int *r_end_char=NULL); void _remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column); void _insert_text_at_cursor(const String& p_text); void _input_event(const InputEvent& p_input); void _notification(int p_what); - + void _consume_pair_symbol(CharType ch); void _consume_backspace_for_pair_symbol(int prev_line, int prev_column); - + static void _bind_methods(); @@ -304,7 +304,7 @@ public: SEARCH_WHOLE_WORDS=2, SEARCH_BACKWARDS=4 }; - + virtual CursorShape get_cursor_shape(const Point2& p_pos=Point2i()) const; //void delete_char(); @@ -322,7 +322,7 @@ public: String get_line(int line) const; void set_line(int line, String new_text); void backspace_at_cursor(); - + inline void set_scroll_pass_end_of_file(bool p_enabled) { scroll_past_end_of_file_enabled = p_enabled; update(); @@ -402,7 +402,7 @@ public: void set_tooltip_request_func(Object *p_obj, const StringName& p_function, const Variant& p_udata); - void set_completion(bool p_enabled,const Vector<String>& p_prefixes); + void set_completion(bool p_enabled,const Vector<String>& p_prefixes); void code_complete(const Vector<String> &p_strings); void set_code_hint(const String& p_hint); void query_code_comple(); diff --git a/scene/gui/texture_frame.h b/scene/gui/texture_frame.h index f6fe6ae89d..e1f0de92df 100644 --- a/scene/gui/texture_frame.h +++ b/scene/gui/texture_frame.h @@ -42,7 +42,7 @@ class TextureFrame : public Control { Ref<Texture> texture; protected: - void _notification(int p_what); + void _notification(int p_what); virtual Size2 get_minimum_size() const; static void _bind_methods(); diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp index e05d35a81d..923a35031c 100644 --- a/scene/gui/texture_progress.cpp +++ b/scene/gui/texture_progress.cpp @@ -195,7 +195,7 @@ void TextureProgress::_notification(int p_what){ draw_texture_rect_region(progress,Rect2(Point2(),Size2(s.x*get_unit_value(),s.y)),Rect2(Point2(),Size2(s.x*get_unit_value(),s.y))); } - + } if (over.is_valid()) draw_texture(over,Point2()); @@ -269,10 +269,10 @@ void TextureProgress::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_radial_initial_angle","mode"),&TextureProgress::set_radial_initial_angle); ObjectTypeDB::bind_method(_MD("get_radial_initial_angle"), &TextureProgress::get_radial_initial_angle); - + ObjectTypeDB::bind_method(_MD("set_radial_center_offset","mode"),&TextureProgress::set_radial_center_offset); ObjectTypeDB::bind_method(_MD("get_radial_center_offset"), &TextureProgress::get_radial_center_offset); - + ObjectTypeDB::bind_method(_MD("set_fill_degrees","mode"),&TextureProgress::set_fill_degrees); ObjectTypeDB::bind_method(_MD("get_fill_degrees"), &TextureProgress::get_fill_degrees); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 05b1e8bcea..f793bbe3c6 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -2164,7 +2164,7 @@ void Tree::_input_event(InputEvent p_event) { float diff_y = -b.relative_y; diff_y=Math::pow(ABS(diff_y),1.8)*SGN(diff_y); diff_y*=0.1; - range_drag_base=CLAMP(range_drag_base + c.step * diff_y, c.min, c.max); + range_drag_base=CLAMP(range_drag_base + c.step * diff_y, c.min, c.max); popup_edited_item->set_range(popup_edited_item_col,range_drag_base); item_edited(popup_edited_item_col,popup_edited_item); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index e5c95b4d66..421cfc47bc 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -46,22 +46,22 @@ class TreeItem : public Object { OBJ_TYPE(TreeItem,Object); public: - + enum TreeCellMode { - + CELL_MODE_STRING, ///< just a string CELL_MODE_CHECK, ///< string + check CELL_MODE_RANGE, ///< Contains a range CELL_MODE_ICON, ///< Contains a icon, not editable CELL_MODE_CUSTOM, ///< Contains a custom value, show a string, and an edit button }; - + private: friend class Tree; - - + + struct Cell { - + TreeCellMode mode; Ref<Texture> icon; @@ -92,9 +92,9 @@ friend class Tree; }; Vector< Button > buttons; - + Cell() { - + custom_draw_obj=0; mode=TreeItem::CELL_MODE_STRING; min=0; @@ -116,30 +116,30 @@ friend class Tree; void draw_icon(const RID& p_where, const Point2& p_pos, const Size2& p_size=Size2()) const; }; - + Vector<Cell> cells; - + bool collapsed; // wont show childs - + TreeItem *parent; // parent item TreeItem *next; // next in list TreeItem *childs; //child items Tree *tree; //tree (for reference) - + TreeItem(Tree *p_tree); - + void _changed_notify(int p_cell); void _changed_notify(); void _cell_selected(int p_cell); void _cell_deselected(int p_cell); protected: - + static void _bind_methods(); //bind helpers - Dictionary _get_range_config( int p_column ) { + Dictionary _get_range_config( int p_column ) { Dictionary d; double min,max,step; get_range_config(p_column,min,max,step); @@ -152,18 +152,18 @@ protected: } void _remove_child(Object *p_child) { remove_child( p_child->cast_to<TreeItem>() ); } public: - + /* cell mode */ void set_cell_mode( int p_column, TreeCellMode p_mode ); TreeCellMode get_cell_mode( int p_column ) const; - + /* check mode */ void set_checked(int p_column,bool p_checked); bool is_checked(int p_column) const; - + void set_text(int p_column,String p_text); String get_text(int p_column) const; - + void set_icon(int p_column,const Ref<Texture>& p_icon); Ref<Texture> get_icon(int p_column) const; @@ -183,22 +183,22 @@ public: void set_button(int p_column,int p_idx,const Ref<Texture>& p_button); /* range works for mode number or mode combo */ - + void set_range(int p_column,double p_value); double get_range(int p_column) const; - + void set_range_config(int p_column,double p_min,double p_max,double p_step,bool p_exp=false); void get_range_config(int p_column,double& r_min,double& r_max,double &r_step) const; bool is_range_exponential(int p_column) const; - + void set_metadata(int p_column,const Variant& p_meta); Variant get_metadata(int p_column) const; - + void set_custom_draw(int p_column,Object *p_object,const StringName& p_callback); - + void set_collapsed(bool p_collapsed); bool is_collapsed(); - + TreeItem *get_prev(); TreeItem *get_next(); TreeItem *get_parent(); @@ -206,20 +206,20 @@ public: TreeItem *get_prev_visible(); TreeItem *get_next_visible(); - + void remove_child(TreeItem *p_item); - + void set_selectable(int p_column,bool p_selectable); bool is_selectable(int p_column) const; - + bool is_selected(int p_column); void select(int p_column); void deselect(int p_column); void set_as_cursor(int p_column); - + void set_editable(int p_column,bool p_editable); bool is_editable(int p_column); - + void set_custom_color(int p_column,const Color& p_color); void clear_custom_color(int p_column); @@ -237,7 +237,7 @@ public: void move_to_bottom(); ~TreeItem(); - + }; @@ -245,18 +245,18 @@ VARIANT_ENUM_CAST( TreeItem::TreeCellMode ); class Tree : public Control { - + OBJ_TYPE( Tree, Control ); -public: +public: enum SelectMode { SELECT_SINGLE, SELECT_ROW, SELECT_MULTI }; - -private: -friend class TreeItem; - + +private: +friend class TreeItem; + TreeItem *root; TreeItem *popup_edited_item; TreeItem *selected_item; @@ -287,7 +287,7 @@ friend class TreeItem; int blocked; struct ColumnInfo { - + int min_width; bool expand; String title; @@ -320,21 +320,21 @@ friend class TreeItem; void value_editor_changed(double p_value); void popup_select(int p_option); - + void _input_event(InputEvent p_event); void _notification(int p_what); - + Size2 get_minimum_size() const; - + void item_edited(int p_column,TreeItem *p_item); void item_changed(int p_column,TreeItem *p_item); void item_selected(int p_column,TreeItem *p_item); void item_deselected(int p_column,TreeItem *p_item); - + void propagate_set_columns(TreeItem *p_item); - + struct Cache { - + Ref<Font> font; Ref<Font> tb_font; Ref<StyleBox> bg; @@ -354,14 +354,14 @@ friend class TreeItem; Ref<Texture> arrow; Ref<Texture> select_arrow; Ref<Texture> updown; - + Color font_color; Color font_color_selected; Color guide_color; int hseparation; int vseparation; int item_margin; - int guide_width; + int guide_width; int button_margin; Point2 offset; @@ -381,14 +381,14 @@ friend class TreeItem; int hover_index; } cache; - - + + int _get_title_button_height() const; void _scroll_moved(float p_value); HScrollBar *h_scroll; VScrollBar *v_scroll; - + Size2 get_internal_min_size() const; void update_cache(); void update_scrollbars(); @@ -423,10 +423,10 @@ friend class TreeItem; protected: static void _bind_methods(); - + //bind helpers Object* _create_item(Object *p_parent) { return create_item(p_parent->cast_to<TreeItem>() ); } - TreeItem *_get_next_selected(Object *p_item) { return get_next_selected(p_item->cast_to<TreeItem>() ); } + TreeItem *_get_next_selected(Object *p_item) { return get_next_selected(p_item->cast_to<TreeItem>() ); } Rect2 _get_item_rect(Object *p_item,int p_column) const { return get_item_rect(p_item->cast_to<TreeItem>(),p_column ); } public: @@ -434,21 +434,21 @@ public: void clear(); - TreeItem* create_item(TreeItem *p_parent=0); + TreeItem* create_item(TreeItem *p_parent=0); TreeItem* get_root(); TreeItem* get_last_item(); void set_column_min_width(int p_column,int p_min_width); - void set_column_expand(int p_column,bool p_expand); + void set_column_expand(int p_column,bool p_expand); int get_column_width(int p_column) const; - + void set_hide_root(bool p_eanbled); TreeItem *get_next_selected( TreeItem* p_item); TreeItem *get_selected() const; int get_selected_column() const; int get_pressed_button() const; void set_select_mode(SelectMode p_mode); - + void set_columns(int p_columns); int get_columns() const; @@ -462,11 +462,11 @@ public: int get_edited_column() const; void ensure_cursor_is_visible(); - + Rect2 get_custom_popup_rect() const; int get_item_offset(TreeItem *p_item) const; - Rect2 get_item_rect(TreeItem *p_item,int p_column=-1) const; + Rect2 get_item_rect(TreeItem *p_item,int p_column=-1) const; bool edit_selected(); TreeItem* search_item_text(const String& p_find,int *r_col=NULL,bool p_selectable=false); @@ -484,7 +484,7 @@ public: Tree(); - ~Tree(); + ~Tree(); }; diff --git a/scene/io/resource_format_image.cpp b/scene/io/resource_format_image.cpp index c80975dbfe..6174d134a3 100644 --- a/scene/io/resource_format_image.cpp +++ b/scene/io/resource_format_image.cpp @@ -32,7 +32,7 @@ #include "globals.h" #include "os/os.h" RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_original_path, Error *r_error) { - + if (r_error) *r_error=ERR_CANT_OPEN; @@ -45,31 +45,31 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin Error err; FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err); if (err) { - + ERR_FAIL_COND_V( err, RES() ); } - + String base_path=p_path.substr( 0, p_path.find_last("/")+1 ); for(int i=0;i<6;i++) { - + String file = f->get_line().strip_edges(); Image image; - + Error err = ImageLoader::load_image(base_path+file,&image); - + if (err) { - + memdelete(f); ERR_FAIL_COND_V( err, RES() ); } - + if (i==0) { - + //cubemap->create(image.get_width(),image.get_height(),image.get_format(),Texture::FLAGS_DEFAULT|Texture::FLAG_CUBEMAP); } - + static const CubeMap::Side cube_side[6]= { CubeMap::SIDE_LEFT, CubeMap::SIDE_RIGHT, @@ -78,10 +78,10 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin CubeMap::SIDE_FRONT, CubeMap::SIDE_BACK }; - + cubemap->set_side(cube_side[i],image); } - + memdelete(f); cubemap->set_name(p_path.get_file()); @@ -89,9 +89,9 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin *r_error=OK; return cubemap; - + } else { - // simple image + // simple image ImageTexture* ptr = memnew(ImageTexture); Ref<ImageTexture> texture( ptr ); @@ -115,7 +115,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin ERR_EXPLAIN("Failed loading image: "+p_path); - ERR_FAIL_COND_V(err, RES()); + ERR_FAIL_COND_V(err, RES()); if (r_error) *r_error=ERR_FILE_CORRUPT; @@ -134,8 +134,8 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin } #endif #endif - - + + uint32_t flags=0; FileAccess *f2 = FileAccess::open(p_path+".flags",FileAccess::READ); @@ -186,7 +186,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin if (flags_found["tolinear"]) flags|=Texture::FLAG_CONVERT_TO_LINEAR; } - + if (flags_found.has("mirroredrepeat")) { if (flags_found["mirroredrepeat"]) flags|=Texture::FLAG_MIRRORED_REPEAT; @@ -210,7 +210,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String& p_origin return RES( texture ); } - + } @@ -220,7 +220,7 @@ bool ResourceFormatLoaderImage::handles_type(const String& p_type) const { } void ResourceFormatLoaderImage::get_recognized_extensions(List<String> *p_extensions) const { - + ImageLoader::get_recognized_extensions(p_extensions); p_extensions->push_back("cube"); } diff --git a/scene/main/misc.h b/scene/main/misc.h index 1c5bc7208e..d5db8c3247 100644 --- a/scene/main/misc.h +++ b/scene/main/misc.h @@ -37,7 +37,7 @@ class Misc : public Node { OBJ_TYPE( Misc, Node ); public: - Misc(); + Misc(); ~Misc(); }; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 450578a241..b90edb38b2 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -41,7 +41,7 @@ VARIANT_ENUM_CAST(Node::PauseMode); void Node::_notification(int p_notification) { - + switch(p_notification) { case NOTIFICATION_PROCESS: { @@ -114,21 +114,21 @@ void Node::_notification(int p_notification) { case NOTIFICATION_PREDELETE: { set_owner(NULL); - + while ( data.owned.size() ) { - - data.owned.front()->get()->set_owner(NULL); + + data.owned.front()->get()->set_owner(NULL); } if (data.parent) { - + data.parent->remove_child(this); } // kill children as cleanly as possible while( data.children.size() ) { - - Node *child = data.children[0]; + + Node *child = data.children[0]; remove_child(child); memdelete( child ); } @@ -161,7 +161,7 @@ void Node::_propagate_enter_tree() { data.depth=1; } - + data.viewport = cast_to<Viewport>(); if (!data.viewport) data.viewport = data.parent->data.viewport; @@ -191,10 +191,10 @@ void Node::_propagate_enter_tree() { //block while adding children for (int i=0;i<data.children.size();i++) { - + if (!data.children[i]->is_inside_tree()) // could have been added in enter_tree data.children[i]->_propagate_enter_tree(); - } + } data.blocked--; @@ -279,15 +279,15 @@ void Node::_propagate_exit_tree() { -void Node::move_child(Node *p_child,int p_pos) { - +void Node::move_child(Node *p_child,int p_pos) { + ERR_FAIL_NULL(p_child); ERR_EXPLAIN("Invalid new child position: "+itos(p_pos)); ERR_FAIL_INDEX( p_pos, data.children.size()+1 ); ERR_EXPLAIN("child is not a child of this node."); ERR_FAIL_COND(p_child->data.parent!=this); ERR_FAIL_COND(data.blocked>0); - + data.children.remove( p_child->data.pos ); data.children.insert( p_pos, p_child ); @@ -298,7 +298,7 @@ void Node::move_child(Node *p_child,int p_pos) { data.blocked++; //new pos first for (int i=0;i<data.children.size();i++) { - + data.children[i]->data.pos=i; } // notification second @@ -313,17 +313,17 @@ void Node::move_child(Node *p_child,int p_pos) { } void Node::raise() { - + if (!data.parent) return; - + data.parent->move_child(this,data.parent->data.children.size()-1); } void Node::add_child_notify(Node *p_child) { - - // to be used when not wanted + + // to be used when not wanted } /* @@ -340,26 +340,26 @@ void Node::remove_and_delete_child(Node *p_child) { void Node::remove_child_notify(Node *p_child) { - // to be used when not wanted + // to be used when not wanted } void Node::move_child_notify(Node *p_child) { - // to be used when not wanted + // to be used when not wanted } void Node::set_fixed_process(bool p_process) { - + if (data.fixed_process==p_process) return; data.fixed_process=p_process; - + if (data.fixed_process) add_to_group("fixed_process",false); else remove_from_group("fixed_process"); - + data.fixed_process=p_process; _change_notify("fixed_process"); } @@ -437,7 +437,7 @@ bool Node::can_process() const { float Node::get_fixed_process_delta_time() const { - + if (data.tree) return data.tree->get_fixed_process_time(); else @@ -469,7 +469,7 @@ float Node::get_process_delta_time() const { } bool Node::is_fixed_processing() const { - + return data.fixed_process; } @@ -541,7 +541,7 @@ bool Node::is_processing_unhandled_key_input() const { StringName Node::get_name() const { - + return data.name; } @@ -552,14 +552,14 @@ void Node::_set_name_nocheck(const StringName& p_name) { } void Node::set_name(const String& p_name) { - + String name=p_name.replace(":","").replace("/","").replace("@",""); ERR_FAIL_COND(name==""); data.name=name; - + if (data.parent) { - + data.parent->_validate_child_name(this); } @@ -741,12 +741,12 @@ void Node::add_child(Node *p_child, bool p_legible_unique_name) { ERR_FAIL_COND( p_child->data.parent ); ERR_EXPLAIN("Can't add child while a notification is happening"); ERR_FAIL_COND( data.blocked > 0 ); - + /* Validate name */ _validate_child_name(p_child,p_legible_unique_name); _add_child_nocheck(p_child,p_child->data.name); - + } @@ -791,36 +791,36 @@ void Node::remove_child(Node *p_child) { ERR_FAIL_NULL(p_child); ERR_FAIL_COND( data.blocked > 0 ); - + int idx=-1; for (int i=0;i<data.children.size();i++) { - + if (data.children[i]==p_child) { - + idx=i; break; } } - + ERR_FAIL_COND( idx==-1 ); //ERR_FAIL_COND( p_child->data.blocked > 0 ); - + //if (data.scene) { does not matter - + p_child->_set_tree(NULL); //} - - remove_child_notify(p_child); + + remove_child_notify(p_child); p_child->notification(NOTIFICATION_UNPARENTED); - + data.children.remove(idx); - + for (int i=idx;i<data.children.size();i++) { - + data.children[i]->data.pos=i; } - + p_child->data.parent=NULL; p_child->data.pos=-1; @@ -828,17 +828,17 @@ void Node::remove_child(Node *p_child) { // validate owner p_child->_propagate_validate_owner(); - + } int Node::get_child_count() const { - - return data.children.size(); + + return data.children.size(); } Node *Node::get_child(int p_index) const { - + ERR_FAIL_INDEX_V( p_index, data.children.size(), NULL ); - + return data.children[p_index]; } @@ -862,10 +862,10 @@ Node *Node::_get_node(const NodePath& p_path) const { ERR_EXPLAIN("Can't use get_node() with absolute paths from outside the active scene tree."); ERR_FAIL_V(NULL); } - - Node *current=NULL; + + Node *current=NULL; Node *root=NULL; - + if (!p_path.is_absolute()) { current=const_cast<Node*>(this); //start from this } else { @@ -874,42 +874,42 @@ Node *Node::_get_node(const NodePath& p_path) const { while (root->data.parent) root=root->data.parent; //start from root } - + for(int i=0;i<p_path.get_name_count();i++) { - - - StringName name = p_path.get_name(i); + + + StringName name = p_path.get_name(i); Node *next = NULL; - + if (name==SceneStringNames::get_singleton()->dot) { // . - + next=current; - + } else if (name==SceneStringNames::get_singleton()->doubledot) { // .. - + if (current==NULL || !current->data.parent) return NULL; - + next=current->data.parent; } else if (current==NULL) { - + if (name==root->get_name()) next=root; - + } else { - + next=NULL; - + for(int j=0;j<current->data.children.size();j++) { - + Node *child = current->data.children[j]; if ( child->data.name == name ) { - + next = child; break; - } + } } if (next == NULL) { return NULL; @@ -917,7 +917,7 @@ Node *Node::_get_node(const NodePath& p_path) const { } current=next; } - + return current; } @@ -969,12 +969,12 @@ bool Node::is_a_parent_of(const Node *p_node) const { ERR_FAIL_NULL_V(p_node,false); Node *p=p_node->data.parent; while(p) { - + if (p==this) return true; p=p->data.parent; } - + return false; } @@ -983,25 +983,25 @@ bool Node::is_greater_than(const Node *p_node) const { ERR_FAIL_NULL_V(p_node,false); ERR_FAIL_COND_V( !data.inside_tree, false ); ERR_FAIL_COND_V( !p_node->data.inside_tree, false ); - + ERR_FAIL_COND_V( data.depth<0, false); ERR_FAIL_COND_V( p_node->data.depth<0, false); #ifdef NO_ALLOCA - + Vector<int> this_stack; Vector<int> that_stack; this_stack.resize(data.depth); that_stack.resize(p_node->data.depth); #else - + int *this_stack=(int*)alloca(sizeof(int)*data.depth); int *that_stack=(int*)alloca(sizeof(int)*p_node->data.depth); - + #endif - + const Node *n = this; - + int idx=data.depth-1; while(n) { ERR_FAIL_INDEX_V(idx, data.depth,false); @@ -1014,15 +1014,15 @@ bool Node::is_greater_than(const Node *p_node) const { while(n) { ERR_FAIL_INDEX_V(idx, p_node->data.depth,false); that_stack[idx--]=n->data.pos; - + n=n->data.parent; } ERR_FAIL_COND_V(idx!=-1,false); idx=0; - + bool res; while(true) { - + // using -2 since out-of-tree or nonroot nodes have -1 int this_idx = (idx >= data.depth)? -2 : this_stack[idx]; int that_idx = (idx >= p_node->data.depth)? -2 : that_stack[idx]; @@ -1039,7 +1039,7 @@ bool Node::is_greater_than(const Node *p_node) const { } idx++; } - + return res; } @@ -1063,39 +1063,39 @@ void Node::_set_owner_nocheck(Node* p_owner) { } void Node::set_owner(Node *p_owner) { - + if (data.owner) { - + data.owner->data.owned.erase( data.OW ); data.OW=NULL; data.owner=NULL; } - + ERR_FAIL_COND(p_owner==this); - + if (!p_owner) return; - + Node *check=this->get_parent(); bool owner_valid=false; - + while(check) { - + if (check==p_owner) { owner_valid=true; break; } - + check=check->data.parent; } - + ERR_FAIL_COND(!owner_valid); _set_owner_nocheck(p_owner); } Node *Node::get_owner() const { - - return data.owner; + + return data.owner; } NodePath Node::get_path_to(const Node *p_node) const { @@ -1104,68 +1104,68 @@ NodePath Node::get_path_to(const Node *p_node) const { if (this==p_node) return NodePath("."); - + Set<const Node*> visited; - + const Node *n=this; - + while(n) { - + visited.insert(n); n=n->data.parent; } const Node *common_parent=p_node; - + while(common_parent) { - + if (visited.has(common_parent)) break; common_parent=common_parent->data.parent; } - + ERR_FAIL_COND_V(!common_parent,NodePath()); //nodes not in the same tree - + visited.clear(); - + Vector<StringName> path; - + n=p_node; - + while(n!=common_parent) { - + path.push_back( n->get_name() ); n=n->data.parent; } - + n=this; - StringName up=String(".."); - + StringName up=String(".."); + while(n!=common_parent) { - + path.push_back( up ); n=n->data.parent; } - + path.invert(); - - return NodePath(path,false); + + return NodePath(path,false); } NodePath Node::get_path() const { - + ERR_FAIL_COND_V(!is_inside_tree(),NodePath()); const Node *n = this; - + Vector<StringName> path; - + while(n) { path.push_back(n->get_name()); n=n->data.parent; - } - + } + path.invert(); - + return NodePath( path, true ); } @@ -1175,36 +1175,36 @@ bool Node::is_in_group(const StringName& p_identifier) const { } void Node::add_to_group(const StringName& p_identifier,bool p_persistent) { - + ERR_FAIL_COND(!p_identifier.operator String().length()); - + if (data.grouped.has(p_identifier)) return; - + GroupData gd; - + if (data.tree) data.tree->add_to_group(p_identifier,this); - gd.persistent=p_persistent; - + gd.persistent=p_persistent; + data.grouped[p_identifier]=gd; } void Node::remove_from_group(const StringName& p_identifier) { - + ERR_FAIL_COND(!data.grouped.has(p_identifier) ); - + GroupData *g=data.grouped.getptr(p_identifier); - + ERR_FAIL_COND(!g); - + if (data.tree) data.tree->remove_from_group(p_identifier,this); - data.grouped.erase(p_identifier); + data.grouped.erase(p_identifier); } @@ -1223,15 +1223,15 @@ Array Node::_get_groups() const { void Node::get_groups(List<GroupInfo> *p_groups) const { const StringName *K=NULL; - + while ((K=data.grouped.next(K))) { - + GroupInfo gi; gi.name=*K; gi.persistent=data.grouped[*K].persistent; p_groups->push_back(gi); } - + } @@ -1249,13 +1249,13 @@ void Node::print_tree() { void Node::_propagate_reverse_notification(int p_notification) { - - data.blocked++; + + data.blocked++; for (int i=data.children.size()-1;i>=0;i--) { - - data.children[i]->_propagate_reverse_notification(p_notification); + + data.children[i]->_propagate_reverse_notification(p_notification); } - + notification(p_notification,true); data.blocked--; } @@ -1281,75 +1281,75 @@ void Node::_propagate_deferred_notification(int p_notification, bool p_reverse) } void Node::propagate_notification(int p_notification) { - - data.blocked++; + + data.blocked++; notification(p_notification); - + for (int i=0;i<data.children.size();i++) { - - data.children[i]->propagate_notification(p_notification); + + data.children[i]->propagate_notification(p_notification); } - data.blocked--; + data.blocked--; } -void Node::_propagate_replace_owner(Node *p_owner,Node* p_by_owner) { +void Node::_propagate_replace_owner(Node *p_owner,Node* p_by_owner) { if (get_owner()==p_owner) set_owner(p_by_owner); - + data.blocked++; - for (int i=0;i<data.children.size();i++) + for (int i=0;i<data.children.size();i++) data.children[i]->_propagate_replace_owner(p_owner,p_by_owner); - data.blocked--; + data.blocked--; } int Node::get_index() const { - + return data.pos; } void Node::remove_and_skip() { - + ERR_FAIL_COND(!data.parent); - + Node *new_owner=get_owner(); - + List<Node*> children; - + while(true) { - + bool clear=true; for (int i=0;i<data.children.size();i++) { if (!data.children[i]->get_owner()) continue; - + remove_child(data.children[i]); data.children[i]->_propagate_replace_owner(this,NULL); - children.push_back(data.children[i]); + children.push_back(data.children[i]); clear=false; break; } - + if (clear) break; } - + while(!children.empty()) { - + Node *c=children.front()->get(); data.parent->add_child(c); - c->_propagate_replace_owner(NULL,new_owner); + c->_propagate_replace_owner(NULL,new_owner); children.pop_front(); } - + data.parent->remove_child(this); } void Node::set_filename(const String& p_filename) { - + data.filename=p_filename; } String Node::get_filename() const { - + return data.filename; } @@ -2117,7 +2117,7 @@ void Node::_bind_methods() { Node::Node() { - + data.pos=-1; data.depth=-1; data.blocked=0; @@ -2141,12 +2141,12 @@ Node::Node() { } Node::~Node() { - + data.grouped.clear(); data.owned.clear(); data.children.clear(); - + ERR_FAIL_COND(data.parent); ERR_FAIL_COND(data.children.size()); diff --git a/scene/main/node.h b/scene/main/node.h index 4d05dd381c..5c6147d644 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -43,7 +43,7 @@ class Node : public Object { OBJ_TYPE( Node, Object ); OBJ_CATEGORY("Nodes"); - + public: enum PauseMode { @@ -59,16 +59,16 @@ public: bool operator()(const Node* p_a, const Node* p_b) const { return p_b->is_greater_than(p_a); } }; -private: - +private: + struct GroupData { - - bool persistent; + + bool persistent; GroupData() { persistent=false; } }; - + struct Data { - + String filename; Ref<SceneState> instance_state; Ref<SceneState> inherited_state; @@ -90,11 +90,11 @@ private: Viewport *viewport; - + HashMap< StringName, GroupData,StringNameHasher> grouped; List<Node*>::Element *OW; // owned element List<Node*> owned; - + PauseMode pause_mode; Node *pause_owner; // variables used to properly sort the node when processing, ignored otherwise @@ -112,10 +112,10 @@ private: } data; - - void _print_tree(const Node *p_node); - + + void _print_tree(const Node *p_node); + virtual bool _use_builtin_script() const { return true; } Node *_get_node(const NodePath& p_path) const; Node *_get_child_by_name(const StringName& p_name) const; @@ -124,7 +124,7 @@ private: void _validate_child_name(Node *p_name, bool p_force_human_readable=false); - void _propagate_reverse_notification(int p_notification); + void _propagate_reverse_notification(int p_notification); void _propagate_deferred_notification(int p_notification, bool p_reverse); void _propagate_enter_tree(); void _propagate_ready(); @@ -147,15 +147,15 @@ protected: void _block() { data.blocked++; } void _unblock() { data.blocked--; } - void _notification(int p_notification); - + void _notification(int p_notification); + virtual void add_child_notify(Node *p_child); virtual void remove_child_notify(Node *p_child); virtual void move_child_notify(Node *p_child); //void remove_and_delete_child(Node *p_child); - - void _propagate_replace_owner(Node *p_owner,Node* p_by_owner); - + + void _propagate_replace_owner(Node *p_owner,Node* p_by_owner); + static void _bind_methods(); friend class SceneState; @@ -181,15 +181,15 @@ public: NOTIFICATION_UNPARENTED=19, NOTIFICATION_INSTANCED=20, }; - - /* NODE/TREE */ - + + /* NODE/TREE */ + StringName get_name() const; void set_name(const String& p_name); - + void add_child(Node *p_child,bool p_legible_unique_name=false); void remove_child(Node *p_child); - + int get_child_count() const; Node *get_child(int p_index) const; bool has_node(const NodePath& p_path) const; @@ -197,43 +197,43 @@ public: Node* find_node(const String& p_mask,bool p_recursive=true,bool p_owned=true) const; bool has_node_and_resource(const NodePath& p_path) const; Node *get_node_and_resource(const NodePath& p_path,RES& r_res) const; - + Node *get_parent() const; _FORCE_INLINE_ SceneTree *get_tree() const { ERR_FAIL_COND_V( !data.tree, NULL ); return data.tree; } _FORCE_INLINE_ bool is_inside_tree() const { return data.inside_tree; } - + bool is_a_parent_of(const Node *p_node) const; bool is_greater_than(const Node *p_node) const; - + NodePath get_path() const; NodePath get_path_to(const Node *p_node) const; - + void add_to_group(const StringName& p_identifier,bool p_persistent=false); void remove_from_group(const StringName& p_identifier); bool is_in_group(const StringName& p_identifier) const; - + struct GroupInfo { - + StringName name; bool persistent; }; - + void get_groups(List<GroupInfo> *p_groups) const; - + void move_child(Node *p_child,int p_pos); void raise(); - + void set_owner(Node *p_owner); Node *get_owner() const; void get_owned_by(Node *p_by,List<Node*> *p_owned); - + void remove_and_skip(); int get_index() const; - + void print_tree(); - + void set_filename(const String& p_filename); String get_filename() const; @@ -242,9 +242,9 @@ public: /* NOTIFICATIONS */ - + void propagate_notification(int p_notification); - + /* PROCESSING */ void set_fixed_process(bool p_process); float get_fixed_process_delta_time() const; diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index 8e2d6aa669..cc103b5115 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -211,7 +211,7 @@ void SceneTree::call_group(uint32_t p_call_flags,const StringName& p_group,const else nodes[i]->call(p_function,VARIANT_ARG_PASS); } else - MessageQueue::get_singleton()->push_call(nodes[i],p_function,VARIANT_ARG_PASS); + MessageQueue::get_singleton()->push_call(nodes[i],p_function,VARIANT_ARG_PASS); } } @@ -433,7 +433,7 @@ void SceneTree::input_event( const InputEvent& p_event ) { ScriptDebugger::get_singleton()->request_quit(); } - _flush_ugc(); + _flush_ugc(); root_lock--; MessageQueue::get_singleton()->flush(); //small little hack diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h index c6fc124345..b6a015c9ed 100644 --- a/scene/main/scene_main_loop.h +++ b/scene/main/scene_main_loop.h @@ -76,7 +76,7 @@ private: struct Group { Vector<Node*> nodes; - uint64_t last_tree_version; + uint64_t last_tree_version; Group() { last_tree_version=0; }; }; diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index a118bc9782..73458e03c0 100644 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -111,7 +111,7 @@ bool Timer::has_autostart() const { } void Timer::start() { - time_left=wait_time; + time_left=wait_time; _set_process(true); } @@ -154,7 +154,7 @@ Timer::TimerProcessMode Timer::get_timer_process_mode() const{ } -void Timer::_set_process(bool p_process, bool p_force) +void Timer::_set_process(bool p_process, bool p_force) { switch (timer_process_mode) { case TIMER_PROCESS_FIXED: set_fixed_process(p_process); break; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 550bae6306..2c94d2e093 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -318,10 +318,10 @@ void Viewport::_test_new_mouseover(ObjectID new_collider) { } void Viewport::_notification(int p_what) { - + switch( p_what ) { - + case NOTIFICATION_ENTER_TREE: { if (get_parent()) { @@ -696,8 +696,8 @@ void Viewport::_notification(int p_what) { } RID Viewport::get_viewport() const { - - return viewport; + + return viewport; } void Viewport::set_rect(const Rect2& p_rect) { @@ -715,12 +715,12 @@ Rect2 Viewport::get_visible_rect() const { Rect2 r; - + if (rect.pos==Vector2() && rect.size==Size2()) { - + r=Rect2( Point2(), Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height ) ); } else { - + r=Rect2( rect.pos , rect.size ); } @@ -733,7 +733,7 @@ Rect2 Viewport::get_visible_rect() const { } Rect2 Viewport::get_rect() const { - + return rect; } @@ -1335,7 +1335,7 @@ void Viewport::_vp_input(const InputEvent& p_ev) { //they are converted to viewport coordinates - InputEvent ev = p_ev; + InputEvent ev = p_ev; _make_input_local(ev); input(ev); @@ -2240,7 +2240,7 @@ void Viewport::input(const InputEvent& p_event) { ERR_FAIL_COND(!is_inside_tree()); - get_tree()->_call_input_pause(input_group,"_input",p_event); + get_tree()->_call_input_pause(input_group,"_input",p_event); _gui_input_event(p_event); //get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check } @@ -2409,10 +2409,10 @@ void Viewport::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_render_target_vflip","enable"), &Viewport::set_render_target_vflip); ObjectTypeDB::bind_method(_MD("get_render_target_vflip"), &Viewport::get_render_target_vflip); - + ObjectTypeDB::bind_method(_MD("set_render_target_clear_on_new_frame","enable"), &Viewport::set_render_target_clear_on_new_frame); ObjectTypeDB::bind_method(_MD("get_render_target_clear_on_new_frame"), &Viewport::get_render_target_clear_on_new_frame); - + ObjectTypeDB::bind_method(_MD("render_target_clear"), &Viewport::render_target_clear); ObjectTypeDB::bind_method(_MD("set_render_target_filter","enable"), &Viewport::set_render_target_filter); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 5bf7418ee9..afabd499a9 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -270,7 +270,7 @@ friend class Camera; void _camera_make_next_current(Camera* p_exclude); -protected: +protected: void _notification(int p_what); static void _bind_methods(); public: @@ -284,7 +284,7 @@ public: void set_as_audio_listener_2d(bool p_enable); bool is_audio_listener_2d() const; - void set_rect(const Rect2& p_rect); + void set_rect(const Rect2& p_rect); Rect2 get_rect() const; Rect2 get_visible_rect() const; RID get_viewport() const; @@ -362,7 +362,7 @@ public: bool gui_has_modal_stack() const; - Viewport(); + Viewport(); ~Viewport(); }; diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 6fa6085bb3..9930aa07f6 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -432,7 +432,7 @@ void register_scene_types() { ObjectTypeDB::register_type<ConeTwistJoint>(); ObjectTypeDB::register_type<Generic6DOFJoint>(); - //scenariofx + //scenariofx OS::get_singleton()->yield(); //may take time to init @@ -629,9 +629,9 @@ void register_scene_types() { } void unregister_scene_types() { - + clear_default_theme(); - + memdelete( resource_loader_image ); memdelete( resource_loader_wav ); #ifdef TOOLS_ENABLED diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index e8bd6c14ad..f7d5ddc744 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -41,33 +41,33 @@ bool Animation::_set(const StringName& p_name, const Variant& p_value) { else if (name=="step") set_step(p_value); else if (name.begins_with("tracks/")) { - + int track=name.get_slicec('/',1).to_int(); String what=name.get_slicec('/',2); if (tracks.size()==track && what=="type") { - + String type=p_value; - + if (type=="transform") { - + add_track(TYPE_TRANSFORM); } else if (type=="value") { - + add_track(TYPE_VALUE); } else if (type=="method") { - + add_track(TYPE_METHOD); } else { - + return false; } - + return true; } - + ERR_FAIL_INDEX_V( track, tracks.size(),false ); - + if (what=="path") track_set_path(track,p_value); else if (what=="interp") @@ -261,10 +261,10 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const { String what=name.get_slicec('/',2); ERR_FAIL_INDEX_V( track, tracks.size(), false ); if (what=="type") { - - + + switch (track_get_type(track)) { - + case TYPE_TRANSFORM: r_ret= "transform"; break; case TYPE_VALUE: r_ret= "value";break; case TYPE_METHOD: r_ret= "method";break; @@ -281,7 +281,7 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const { if (track_get_type(track)==TYPE_TRANSFORM) { DVector<real_t> keys; - int kk=track_get_key_count(track); + int kk=track_get_key_count(track); keys.resize(kk*12); DVector<real_t>::Write w = keys.write(); @@ -406,7 +406,7 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const { return false; } else return false; - + return true; } @@ -415,11 +415,11 @@ bool Animation::_get(const StringName& p_name,Variant &r_ret) const { void Animation::_get_property_list( List<PropertyInfo> *p_list) const { p_list->push_back( PropertyInfo( Variant::REAL, "length", PROPERTY_HINT_RANGE, "0.001,99999,0.001")); - p_list->push_back( PropertyInfo( Variant::BOOL, "loop" )); + p_list->push_back( PropertyInfo( Variant::BOOL, "loop" )); p_list->push_back( PropertyInfo( Variant::REAL, "step", PROPERTY_HINT_RANGE, "0,4096,0.001" )); for (int i=0;i<tracks.size();i++) { - + p_list->push_back( PropertyInfo( Variant::STRING, "tracks/"+itos(i)+"/type", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); p_list->push_back( PropertyInfo( Variant::NODE_PATH, "tracks/"+itos(i)+"/path", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); p_list->push_back( PropertyInfo( Variant::INT, "tracks/"+itos(i)+"/interp", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR) ); @@ -433,24 +433,24 @@ int Animation::add_track(TrackType p_type,int p_at_pos) { p_at_pos=tracks.size(); switch( p_type ) { - + case TYPE_TRANSFORM: { - + TransformTrack *tt = memnew( TransformTrack ); tracks.insert( p_at_pos,tt ); } break; case TYPE_VALUE: { - + tracks.insert( p_at_pos,memnew( ValueTrack ) ); - + } break; case TYPE_METHOD: { - + tracks.insert( p_at_pos,memnew( MethodTrack ) ); - + } break; default: { - + ERR_PRINT("Unknown track type"); } } @@ -462,29 +462,29 @@ void Animation::remove_track(int p_track) { ERR_FAIL_INDEX(p_track, tracks.size()); Track *t=tracks[p_track]; - + switch(t->type) { - + case TYPE_TRANSFORM: { - + TransformTrack * tt = static_cast<TransformTrack*>(t); _clear(tt->transforms); - + } break; case TYPE_VALUE: { - - ValueTrack * vt = static_cast<ValueTrack*>(t); + + ValueTrack * vt = static_cast<ValueTrack*>(t); _clear(vt->values); - + } break; case TYPE_METHOD: { - + MethodTrack * mt = static_cast<MethodTrack*>(t); _clear(mt->methods); - - } break; - } - + + } break; + } + memdelete( t ); tracks.remove(p_track); emit_changed(); @@ -548,30 +548,30 @@ template<class T> int Animation::_insert_pos(float p_time, T& p_keys) { // simple, linear time inset that should be fast enough in reality. - + int idx=p_keys.size(); - + while(true) { - - + + if (idx==0 || p_keys[idx-1].time < p_time) { //condition for insertion. p_keys.insert(idx,T()); return idx; } else if (p_keys[idx-1].time == p_time) { - + // condition for replacing. return idx-1; - } - + } + idx--; } - + } */ template<class T, class V> int Animation::_insert(float p_time, T& p_keys, const V& p_value) { - + int idx=p_keys.size(); while(true) { @@ -597,7 +597,7 @@ int Animation::_insert(float p_time, T& p_keys, const V& p_value) { template<class T> void Animation::_clear(T& p_keys) { - + p_keys.clear(); } @@ -727,11 +727,11 @@ void Animation::track_insert_key(int p_track, float p_time, const Variant& p_val ERR_FAIL_INDEX(p_track, tracks.size()); Track *t=tracks[p_track]; - + switch(t->type) { - + case TYPE_TRANSFORM: { - + Dictionary d = p_value; Vector3 loc; if (d.has("loc")) @@ -750,36 +750,36 @@ void Animation::track_insert_key(int p_track, float p_time, const Variant& p_val } break; case TYPE_VALUE: { - + ValueTrack * vt = static_cast<ValueTrack*>(t); - + TKey<Variant> k; k.time=p_time; k.transition=p_transition; k.value=p_value; _insert( p_time, vt->values, k ); - + } break; case TYPE_METHOD: { - + MethodTrack * mt = static_cast<MethodTrack*>(t); - + ERR_FAIL_COND( p_value.get_type() != Variant::DICTIONARY ); - + Dictionary d=p_value; ERR_FAIL_COND(!d.has("method") || d["method"].get_type()!=Variant::STRING); ERR_FAIL_COND(!d.has("args") || !d["args"].is_array()); MethodKey k; - + k.time=p_time; k.transition=p_transition; k.method=d["method"]; k.params=d["args"]; _insert( p_time, mt->methods, k ); - - } break; + + } break; } @@ -790,27 +790,27 @@ int Animation::track_get_key_count(int p_track) const { ERR_FAIL_INDEX_V(p_track, tracks.size(),-1); Track *t=tracks[p_track]; - + switch(t->type) { - + case TYPE_TRANSFORM: { - + TransformTrack * tt = static_cast<TransformTrack*>(t); return tt->transforms.size(); } break; case TYPE_VALUE: { - + ValueTrack * vt = static_cast<ValueTrack*>(t); return vt->values.size(); - + } break; case TYPE_METHOD: { - + MethodTrack * mt = static_cast<MethodTrack*>(t); return mt->methods.size(); - } break; + } break; } - + ERR_FAIL_V(-1); } @@ -818,11 +818,11 @@ Variant Animation::track_get_key_value(int p_track, int p_key_idx) const { ERR_FAIL_INDEX_V(p_track, tracks.size(), Variant()); Track *t=tracks[p_track]; - + switch(t->type) { - + case TYPE_TRANSFORM: { - + TransformTrack * tt = static_cast<TransformTrack*>(t); ERR_FAIL_INDEX_V( p_key_idx, tt->transforms.size(), Variant() ); @@ -834,25 +834,25 @@ Variant Animation::track_get_key_value(int p_track, int p_key_idx) const { return d; } break; case TYPE_VALUE: { - - ValueTrack * vt = static_cast<ValueTrack*>(t); + + ValueTrack * vt = static_cast<ValueTrack*>(t); ERR_FAIL_INDEX_V( p_key_idx, vt->values.size(), Variant() ); return vt->values[p_key_idx].value; } break; case TYPE_METHOD: { - + MethodTrack * mt = static_cast<MethodTrack*>(t); ERR_FAIL_INDEX_V( p_key_idx, mt->methods.size(), Variant() ); Dictionary d; d["method"]=mt->methods[p_key_idx].method; d["args"]=mt->methods[p_key_idx].params; - return d; - - } break; + return d; + + } break; } - + ERR_FAIL_V(Variant()); } @@ -860,33 +860,33 @@ float Animation::track_get_key_time(int p_track, int p_key_idx) const { ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); Track *t=tracks[p_track]; - + switch(t->type) { - + case TYPE_TRANSFORM: { - + TransformTrack * tt = static_cast<TransformTrack*>(t); ERR_FAIL_INDEX_V( p_key_idx, tt->transforms.size(), -1 ); return tt->transforms[p_key_idx].time; } break; case TYPE_VALUE: { - - ValueTrack * vt = static_cast<ValueTrack*>(t); + + ValueTrack * vt = static_cast<ValueTrack*>(t); ERR_FAIL_INDEX_V( p_key_idx, vt->values.size(), -1 ); return vt->values[p_key_idx].time; - + } break; case TYPE_METHOD: { - + MethodTrack * mt = static_cast<MethodTrack*>(t); ERR_FAIL_INDEX_V( p_key_idx, mt->methods.size(), -1 ); return mt->methods[p_key_idx].time; - - - } break; + + + } break; } - + ERR_FAIL_V(-1); } @@ -1004,19 +1004,19 @@ void Animation::track_set_key_transition(int p_track, int p_key_idx,float p_tran template<class K> int Animation::_find( const Vector<K>& p_keys, float p_time) const { - + int len=p_keys.size(); if (len==0) return -2; - + int low = 0; int high = len -1; int middle; - + const K* keys =&p_keys[0]; - + while( low <= high ) { - + middle = ( low + high ) / 2; if( p_time == keys[ middle ].time ) { //match @@ -1029,7 +1029,7 @@ int Animation::_find( const Vector<K>& p_keys, float p_time) const { if (keys[middle].time>p_time) middle--; - + return middle; } @@ -1197,58 +1197,58 @@ T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, Inter int len=_find( p_keys, length )+1; // try to find last key (there may be more past the end) - if (len<=0) { + if (len<=0) { // (-1 or -2 returned originally) (plus one above) // meaning no keys, or only key time is larger than length if (p_ok) *p_ok=false; return T(); } else if (len==1) { // one key found (0+1), return it - + if (p_ok) *p_ok=true; return p_keys[0].value; } - + int idx=_find(p_keys, p_time); - + ERR_FAIL_COND_V( idx==-2, T()); - + if (p_ok) *p_ok=true; int next=0; - float c=0; + float c=0; // prepare for all cases of interpolation - + if (loop) { // loop if (idx>=0) { - + if ((idx+1) < len) { - + next=idx+1; float delta=p_keys[next].time - p_keys[idx].time; float from=p_time-p_keys[idx].time; if (Math::absf(delta)>CMP_EPSILON) c=from/delta; - else + else c=0; - + } else { - + next=0; float delta=(length - p_keys[idx].time) + p_keys[next].time; float from=p_time-p_keys[idx].time; - + if (Math::absf(delta)>CMP_EPSILON) - c=from/delta; - else + c=from/delta; + else c=0; - + } - + } else { // on loop, behind first key idx=len-1; @@ -1258,47 +1258,47 @@ T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, Inter endtime=0; float delta=endtime + p_keys[next].time; float from=endtime+p_time; - + if (Math::absf(delta)>CMP_EPSILON) - c=from/delta; - else + c=from/delta; + else c=0; - } - - } else { // no loop + } + + } else { // no loop if (idx>=0) { - + if ((idx+1) < len) { - + next=idx+1; float delta=p_keys[next].time - p_keys[idx].time; float from=p_time - p_keys[idx].time; - + if (Math::absf(delta)>CMP_EPSILON) c=from/delta; else c=0; - + } else { - + next=idx; } - + } else if (idx<0) { - + idx=next=0; - } - + } + } - + float tr = p_keys[idx].transition; if (tr==0 || idx==next) { // don't interpolate if not needed return p_keys[idx].value; } - + if (tr!=1.0) { c = Math::ease(c,tr); @@ -1331,7 +1331,7 @@ T Animation::_interpolate( const Vector< TKey<T> >& p_keys, float p_time, Inter // do a barrel roll - + } @@ -1340,7 +1340,7 @@ Error Animation::transform_track_interpolate(int p_track, float p_time, Vector3 ERR_FAIL_INDEX_V(p_track, tracks.size(),ERR_INVALID_PARAMETER); Track *t=tracks[p_track]; ERR_FAIL_COND_V(t->type!=TYPE_TRANSFORM,ERR_INVALID_PARAMETER); - + TransformTrack * tt = static_cast<TransformTrack*>(t); bool ok; @@ -1368,7 +1368,7 @@ Variant Animation::value_track_interpolate(int p_track, float p_time) const { ERR_FAIL_INDEX_V(p_track, tracks.size(),0); Track *t=tracks[p_track]; ERR_FAIL_COND_V(t->type!=TYPE_VALUE, Variant()); - ValueTrack * vt = static_cast<ValueTrack*>(t); + ValueTrack * vt = static_cast<ValueTrack*>(t); bool ok; @@ -1377,7 +1377,7 @@ Variant Animation::value_track_interpolate(int p_track, float p_time) const { if (ok) { - + return res; } @@ -1426,15 +1426,15 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d float from_time=p_time-p_delta; float to_time=p_time; - + if (from_time>to_time) SWAP(from_time,to_time); - + if (loop) { - - from_time=Math::fposmod(from_time,length); - to_time=Math::fposmod(to_time,length); - + + from_time=Math::fposmod(from_time,length); + to_time=Math::fposmod(to_time,length); + if (from_time>to_time) { // handle loop by splitting _value_track_get_key_indices_in_range(vt,length-from_time,length,p_indices); @@ -1442,12 +1442,12 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d return; } } else { - + if (from_time<0) from_time=0; if (from_time>length) from_time=length; - + if (to_time<0) to_time=0; if (to_time>length) @@ -1455,10 +1455,10 @@ void Animation::value_track_get_key_indices(int p_track, float p_time, float p_d } - + _value_track_get_key_indices_in_range(vt,from_time,to_time,p_indices); - + } void Animation::value_track_set_continuous(int p_track, bool p_continuous) { @@ -1519,19 +1519,19 @@ void Animation::_method_track_get_key_indices_in_range(const MethodTrack * mt, f void Animation::method_track_get_key_indices(int p_track, float p_time, float p_delta,List<int> *p_indices) const { ERR_FAIL_INDEX(p_track, tracks.size()); - Track *t=tracks[p_track]; + Track *t=tracks[p_track]; ERR_FAIL_COND( t->type != TYPE_METHOD ); MethodTrack * mt = static_cast<MethodTrack*>(t); float from_time=p_time-p_delta; float to_time=p_time; - + if (from_time>to_time) SWAP(from_time,to_time); - + if (loop) { - + if (from_time > length || from_time < 0) from_time=Math::fposmod(from_time,length); @@ -1545,19 +1545,19 @@ void Animation::method_track_get_key_indices(int p_track, float p_time, float p_ return; } } else { - + if (from_time<0) from_time=0; if (from_time>length) from_time=length; - + if (to_time<0) to_time=0; if (to_time>length) to_time=length; - + } - + _method_track_get_key_indices_in_range(mt,from_time,to_time,p_indices); @@ -1569,9 +1569,9 @@ Vector<Variant> Animation::method_track_get_params(int p_track,int p_key_idx) co ERR_FAIL_COND_V( t->type != TYPE_METHOD, Vector<Variant>() ); MethodTrack * pm = static_cast<MethodTrack*>(t); - + ERR_FAIL_INDEX_V( p_key_idx, pm->methods.size(), Vector<Variant>() ); - + const MethodKey& mk=pm->methods[p_key_idx]; return mk.params; @@ -1583,9 +1583,9 @@ StringName Animation::method_track_get_name(int p_track,int p_key_idx) const { ERR_FAIL_COND_V( t->type != TYPE_METHOD, StringName() ); MethodTrack * pm = static_cast<MethodTrack*>(t); - + ERR_FAIL_INDEX_V( p_key_idx, pm->methods.size(), StringName() ); - + return pm->methods[ p_key_idx ].method; } @@ -1600,7 +1600,7 @@ void Animation::set_length(float p_length) { float Animation::get_length() const { return length; -} +} void Animation::set_loop(bool p_enabled) { @@ -1678,16 +1678,16 @@ void Animation::_bind_methods() { ObjectTypeDB::bind_method(_MD("transform_track_interpolate","idx","time_sec"),&Animation::_transform_track_interpolate); ObjectTypeDB::bind_method(_MD("value_track_set_continuous","idx","continuous"),&Animation::value_track_set_continuous); ObjectTypeDB::bind_method(_MD("value_track_is_continuous","idx"),&Animation::value_track_is_continuous); - + ObjectTypeDB::bind_method(_MD("value_track_get_key_indices","idx","time_sec","delta"),&Animation::_value_track_get_key_indices); ObjectTypeDB::bind_method(_MD("method_track_get_key_indices","idx","time_sec","delta"),&Animation::_method_track_get_key_indices); ObjectTypeDB::bind_method(_MD("method_track_get_name","idx","key_idx"),&Animation::method_track_get_name); ObjectTypeDB::bind_method(_MD("method_track_get_params","idx","key_idx"),&Animation::method_track_get_params); - + ObjectTypeDB::bind_method(_MD("set_length","time_sec"),&Animation::set_length); ObjectTypeDB::bind_method(_MD("get_length"),&Animation::get_length); - + ObjectTypeDB::bind_method(_MD("set_loop","enabled"),&Animation::set_loop); ObjectTypeDB::bind_method(_MD("has_loop"),&Animation::has_loop); @@ -1699,7 +1699,7 @@ void Animation::_bind_methods() { BIND_CONSTANT( TYPE_VALUE ); BIND_CONSTANT( TYPE_TRANSFORM ); BIND_CONSTANT( TYPE_METHOD ); - + BIND_CONSTANT( INTERPOLATION_NEAREST ); BIND_CONSTANT( INTERPOLATION_LINEAR ); BIND_CONSTANT( INTERPOLATION_CUBIC ); diff --git a/scene/resources/animation.h b/scene/resources/animation.h index 405b8b6a05..1f2d9b80ab 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -61,7 +61,7 @@ public: private: struct Track { - + TrackType type; InterpolationType interpolation; NodePath path; // path to something @@ -70,20 +70,20 @@ private: }; struct Key { - + float transition; - float time; // time in secs + float time; // time in secs Key() { transition=1; } }; - + // transform key holds either Vector3 or Quaternion template<class T> struct TKey : public Key { - + float time; T value; }; - + struct TransformKey { @@ -93,45 +93,45 @@ private: }; /* TRANSFORM TRACK */ - + struct TransformTrack : public Track { Vector< TKey<TransformKey> > transforms; - + TransformTrack() { type=TYPE_TRANSFORM; } }; - + /* PROPERTY VALUE TRACK */ struct ValueTrack : public Track { bool continuous; Vector< TKey<Variant> > values; - + ValueTrack() { type=TYPE_VALUE; continuous=true; } }; /* METHOD TRACK */ - + struct MethodKey : public Key { - + StringName method; Vector<Variant> params; }; - + struct MethodTrack : public Track { - + Vector< MethodKey > methods; MethodTrack() { type=TYPE_METHOD; } - }; - + }; + Vector<Track*> tracks; /* template<class T> int _insert_pos(float p_time, T& p_keys);*/ - + template<class T> void _clear(T& p_keys); @@ -140,7 +140,7 @@ private: template<class K> inline int _find( const Vector<K>& p_keys, float p_time) const; - + _FORCE_INLINE_ Animation::TransformKey _interpolate( const Animation::TransformKey& p_a, const Animation::TransformKey& p_b, float p_c) const; _FORCE_INLINE_ Vector3 _interpolate( const Vector3& p_a, const Vector3& p_b, float p_c) const; @@ -163,9 +163,9 @@ private: float length; float step; bool loop; - + // bind helpers -private: +private: Array _transform_track_interpolate(int p_track, float p_time) const { Vector3 loc; @@ -180,25 +180,25 @@ private: } DVector<int> _value_track_get_key_indices(int p_track, float p_time, float p_delta) const { - + List<int> idxs; value_track_get_key_indices(p_track,p_time,p_delta,&idxs); DVector<int> idxr; - + for (List<int>::Element *E=idxs.front();E;E=E->next()) { - + idxr.push_back(E->get()); } return idxr; } DVector<int> _method_track_get_key_indices(int p_track, float p_time, float p_delta) const { - + List<int> idxs; method_track_get_key_indices(p_track,p_time,p_delta,&idxs); DVector<int> idxr; - + for (List<int>::Element *E=idxs.front();E;E=E->next()) { - + idxr.push_back(E->get()); } return idxr; @@ -207,28 +207,28 @@ private: bool _transform_track_optimize_key(const TKey<TransformKey> &t0,const TKey<TransformKey> &t1, const TKey<TransformKey> &t2, float p_alowed_linear_err,float p_alowed_angular_err,float p_max_optimizable_angle,const Vector3& p_norm); void _transform_track_optimize(int p_idx, float p_allowed_err=0.05, float p_alowed_angular_err=0.01,float p_max_optimizable_angle=Math_PI*0.125); -protected: +protected: bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; - - static void _bind_methods(); - + + static void _bind_methods(); + public: - + int add_track(TrackType p_type,int p_at_pos=-1); void remove_track(int p_track); int get_track_count() const; TrackType track_get_type(int p_track) const; - + void track_set_path(int p_track,const NodePath& p_path); NodePath track_get_path(int p_track) const; int find_track(const NodePath& p_path) const; // transform - + void track_move_up(int p_track); void track_move_down(int p_track); @@ -248,9 +248,9 @@ public: void track_set_interpolation_type(int p_track,InterpolationType p_interp); InterpolationType track_get_interpolation_type(int p_track) const; - + Error transform_track_interpolate(int p_track, float p_time, Vector3 * r_loc, Quat *r_rot, Vector3 *r_scale) const; - + Variant value_track_interpolate(int p_track, float p_time) const; void value_track_get_key_indices(int p_track, float p_time, float p_delta,List<int> *p_indices) const; void value_track_set_continuous(int p_track, bool p_continuous); @@ -259,11 +259,11 @@ public: void method_track_get_key_indices(int p_track, float p_time, float p_delta,List<int> *p_indices) const; Vector<Variant> method_track_get_params(int p_track,int p_key_idx) const; StringName method_track_get_name(int p_track,int p_key_idx) const; - + void set_length(float p_length); float get_length() const; - + void set_loop(bool p_enabled); bool has_loop() const; @@ -274,7 +274,7 @@ public: void optimize(float p_allowed_linear_err=0.05,float p_allowed_angular_err=0.01,float p_max_optimizable_angle=Math_PI*0.125); - Animation(); + Animation(); ~Animation(); }; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index ea0dbc43e3..7158d067cf 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -558,10 +558,10 @@ void make_default_theme() { t->set_constant("close_v_ofs","WindowDialog", 20 ); t->set_constant("titlebar_height","WindowDialog", 18 ); t->set_constant("title_height","WindowDialog", 20 ); - - + + // File Dialog - + t->set_icon("reload","FileDialog",make_icon( icon_reload_png )); @@ -784,7 +784,7 @@ void make_default_theme() { t->set_icon("screen_picker","ColorPicker", make_icon( icon_color_pick_png ) ); t->set_icon("add_preset","ColorPicker", make_icon( icon_add_png ) ); - + t->set_shader("uv_editor", "ColorPicker", make_shader("", uv_editor_shader_code, "")); t->set_shader("w_editor", "ColorPicker", make_shader("", w_editor_shader_code, "")); diff --git a/scene/resources/environment.h b/scene/resources/environment.h index 4620bf567a..a72cc6a47f 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -51,7 +51,7 @@ public: enum BGParam { BG_PARAM_CANVAS_MAX_LAYER=VS::ENV_BG_PARAM_CANVAS_MAX_LAYER, - BG_PARAM_COLOR=VS::ENV_BG_PARAM_COLOR, + BG_PARAM_COLOR=VS::ENV_BG_PARAM_COLOR, BG_PARAM_TEXTURE=VS::ENV_BG_PARAM_TEXTURE, BG_PARAM_CUBEMAP=VS::ENV_BG_PARAM_CUBEMAP, BG_PARAM_ENERGY=VS::ENV_BG_PARAM_ENERGY, diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 0aae6fd978..ef5b7a3eb0 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -272,24 +272,24 @@ Error Font::create_from_fnt(const String& p_string) { void Font::set_height(float p_height) { - + height=p_height; } float Font::get_height() const{ - + return height; } void Font::set_ascent(float p_ascent){ - + ascent=p_ascent; } float Font::get_ascent() const { - + return ascent; } float Font::get_descent() const { - + return height-ascent; } @@ -349,7 +349,7 @@ void Font::add_char(CharType p_char, int p_texture_idx, const Rect2& p_rect, con c.v_align=p_align.y; c.advance=p_advance; c.h_align=p_align.x; - + char_map[p_char]=c; } @@ -411,7 +411,7 @@ bool Font::is_distance_field_hint() const{ void Font::clear() { - + height=1; ascent=0; char_map.clear(); @@ -423,14 +423,14 @@ void Font::clear() { Size2 Font::get_string_size(const String& p_string) const { float w=0; - + int l = p_string.length(); if (l==0) return Size2(0,height); const CharType *sptr = &p_string[0]; for (int i=0;i<l;i++) { - + w+=get_char_size(sptr[i],sptr[i+1]).width; } @@ -461,9 +461,9 @@ void Font::draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,fl } void Font::draw(RID p_canvas_item, const Point2& p_pos, const String& p_text, const Color& p_modulate,int p_clip_w) const { - + Vector2 ofs; - + for (int i=0;i<p_text.length();i++) { int width = get_char_size(p_text[i]).width; @@ -476,15 +476,15 @@ void Font::draw(RID p_canvas_item, const Point2& p_pos, const String& p_text, co } float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_char,const CharType& p_next,const Color& p_modulate) const { - + const Character * c = char_map.getptr(p_char); - + if (!c) { if (fallback.is_valid()) return fallback->draw_char(p_canvas_item,p_pos,p_char,p_next,p_modulate); return 0; } - + Point2 cpos=p_pos; cpos.x+=c->h_align; cpos.y-=ascent; @@ -492,7 +492,7 @@ float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_ ERR_FAIL_COND_V( c->texture_idx<-1 || c->texture_idx>=textures.size(),0); if (c->texture_idx!=-1) VisualServer::get_singleton()->canvas_item_add_texture_rect_region( p_canvas_item, Rect2( cpos, c->rect.size ), textures[c->texture_idx]->get_rid(),c->rect, p_modulate ); - + return get_char_size(p_char,p_next).width; } @@ -561,16 +561,16 @@ void Font::_bind_methods() { } Font::Font() { - + clear(); - + } Font::~Font() { - + clear(); } diff --git a/scene/resources/font.h b/scene/resources/font.h index 61f0352992..03b1ec5191 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -36,21 +36,21 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Font : public Resource { - + OBJ_TYPE( Font, Resource ); RES_BASE_EXTENSION("fnt"); - + Vector< Ref<Texture> > textures; public: struct Character { - + int texture_idx; Rect2 rect; float v_align; float h_align; float advance; - + Character() { texture_idx=0; v_align=0; } }; @@ -69,10 +69,10 @@ public: private: - + HashMap< CharType, Character > char_map; Map<KerningPairKey,int> kerning_map; - + float height; float ascent; bool distance_field_hint; @@ -86,20 +86,20 @@ private: Ref<Font> fallback; protected: - + static void _bind_methods(); public: Error create_from_fnt(const String& p_file); - + void set_height(float p_height); float get_height() const; - + void set_ascent(float p_ascent); - float get_ascent() const; + float get_ascent() const; float get_descent() const; - + void add_texture(const Ref<Texture>& p_texture); void add_char(CharType p_char, int p_texture_idx, const Rect2& p_rect, const Size2& p_align, float p_advance=-1); @@ -116,7 +116,7 @@ public: inline Size2 get_char_size(CharType p_char,CharType p_next=0) const; Size2 get_string_size(const String& p_string) const; - + void set_fallback(const Ref<Font> &p_fallback); Ref<Font> get_fallback() const; @@ -125,11 +125,11 @@ public: void set_distance_field_hint(bool p_distance_field); bool is_distance_field_hint() const; - + void draw(RID p_canvas_item, const Point2& p_pos, const String& p_text,const Color& p_modulate=Color(1,1,1),int p_clip_w=-1) const; void draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,float p_width,const String& p_text,const Color& p_modulate=Color(1,1,1)) const; float draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_char,const CharType& p_next=0,const Color& p_modulate=Color(1,1,1)) const; - + Font(); ~Font(); }; diff --git a/scene/resources/material.h b/scene/resources/material.h index 96b33ce129..dbd05c466f 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -41,7 +41,7 @@ class Material : public Resource { - OBJ_TYPE(Material,Resource); + OBJ_TYPE(Material,Resource); RES_BASE_EXTENSION("mtl"); OBJ_SAVE_TYPE( Material ); diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 9537fa269f..09c0a21f53 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -126,7 +126,7 @@ bool Mesh::_set(const StringName& p_name, const Variant& p_value) { add_custom_surface(p_value); return true; - } + } //create Dictionary d=p_value; @@ -223,7 +223,7 @@ void Mesh::_get_property_list( List<PropertyInfo> *p_list) const { } for (int i=0;i<surfaces.size();i++) { - + p_list->push_back( PropertyInfo( Variant::DICTIONARY,"surfaces/"+itos(i), PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR ) ); p_list->push_back( PropertyInfo( Variant::STRING,"surface_"+itos(i+1)+"/name", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_EDITOR ) ); p_list->push_back( PropertyInfo( Variant::OBJECT,"surface_"+itos(i+1)+"/material", PROPERTY_HINT_RESOURCE_TYPE,"Material",PROPERTY_USAGE_EDITOR ) ); @@ -238,9 +238,9 @@ void Mesh::_recompute_aabb() { // regenerate AABB aabb=AABB(); - + for (int i=0;i<surfaces.size();i++) { - + if (i==0) aabb=surfaces[i].aabb; else @@ -383,7 +383,7 @@ void Mesh::surface_remove(int p_idx) { ERR_FAIL_INDEX(p_idx, surfaces.size() ); VisualServer::get_singleton()->mesh_remove_surface(mesh,p_idx); surfaces.remove(p_idx); - + triangle_mesh=Ref<TriangleMesh>(); _recompute_aabb(); _change_notify(); @@ -472,14 +472,14 @@ void Mesh::add_surface_from_mesh_data(const Geometry::MeshData& p_mesh_data) { VisualServer::get_singleton()->mesh_add_surface_from_mesh_data( mesh, p_mesh_data ); AABB aabb; for (int i=0;i<p_mesh_data.vertices.size();i++) { - + if (i==0) aabb.pos=p_mesh_data.vertices[i]; else aabb.expand_to(p_mesh_data.vertices[i]); } - + Surface s; s.aabb=aabb; if (surfaces.size()==0) @@ -524,60 +524,60 @@ DVector<Face3> Mesh::get_faces() const { return DVector<Face3>(); /* for (int i=0;i<surfaces.size();i++) { - + if (VisualServer::get_singleton()->mesh_surface_get_primitive_type( mesh, i ) != VisualServer::PRIMITIVE_TRIANGLES ) continue; - + DVector<int> indices; DVector<Vector3> vertices; - + vertices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_VERTEX); - + int len=VisualServer::get_singleton()->mesh_surface_get_array_index_len(mesh, i); bool has_indices; - + if (len>0) { - + indices=VisualServer::get_singleton()->mesh_surface_get_array(mesh, i,VisualServer::ARRAY_INDEX); has_indices=true; - + } else { - + len=vertices.size(); has_indices=false; } - + if (len<=0) continue; - + DVector<int>::Read indicesr = indices.read(); const int *indicesptr = indicesr.ptr(); - + DVector<Vector3>::Read verticesr = vertices.read(); const Vector3 *verticesptr = verticesr.ptr(); - + int old_faces=faces.size(); int new_faces=old_faces+(len/3); - + faces.resize(new_faces); - + DVector<Face3>::Write facesw = faces.write(); Face3 *facesptr=facesw.ptr(); - - + + for (int i=0;i<len/3;i++) { - + Face3 face; - + for (int j=0;j<3;j++) { - + int idx=i*3+j; face.vertex[j] = has_indices ? verticesptr[ indicesptr[ idx ] ] : verticesptr[idx]; } - + facesptr[i+old_faces]=face; } - + } */ @@ -993,17 +993,17 @@ void Mesh::_bind_methods() { BIND_CONSTANT( NO_INDEX_ARRAY ); BIND_CONSTANT( ARRAY_WEIGHTS_SIZE ); - + BIND_CONSTANT( ARRAY_VERTEX ); BIND_CONSTANT( ARRAY_NORMAL ); BIND_CONSTANT( ARRAY_TANGENT ); BIND_CONSTANT( ARRAY_COLOR ); - BIND_CONSTANT( ARRAY_TEX_UV ); + BIND_CONSTANT( ARRAY_TEX_UV ); BIND_CONSTANT( ARRAY_TEX_UV2 ); BIND_CONSTANT( ARRAY_BONES ); BIND_CONSTANT( ARRAY_WEIGHTS ); BIND_CONSTANT( ARRAY_INDEX ); - + BIND_CONSTANT( ARRAY_FORMAT_VERTEX ); BIND_CONSTANT( ARRAY_FORMAT_NORMAL ); BIND_CONSTANT( ARRAY_FORMAT_TANGENT ); @@ -1013,7 +1013,7 @@ void Mesh::_bind_methods() { BIND_CONSTANT( ARRAY_FORMAT_BONES ); BIND_CONSTANT( ARRAY_FORMAT_WEIGHTS ); BIND_CONSTANT( ARRAY_FORMAT_INDEX ); - + BIND_CONSTANT( PRIMITIVE_POINTS ); BIND_CONSTANT( PRIMITIVE_LINES ); BIND_CONSTANT( PRIMITIVE_LINE_STRIP ); diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index e0d9bdf7a8..dc1d97a49e 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -43,9 +43,9 @@ class Mesh : public Resource { RES_BASE_EXTENSION("msh"); public: - + enum { - + NO_INDEX_ARRAY=VisualServer::NO_INDEX_ARRAY, ARRAY_WEIGHTS_SIZE=VisualServer::ARRAY_WEIGHTS_SIZE }; @@ -63,8 +63,8 @@ public: ARRAY_INDEX=VisualServer::ARRAY_INDEX, ARRAY_MAX=VisualServer::ARRAY_MAX - }; - + }; + enum ArrayFormat { /* ARRAY FORMAT FLAGS */ ARRAY_FORMAT_VERTEX=1<<ARRAY_VERTEX, // mandatory @@ -77,8 +77,8 @@ public: ARRAY_FORMAT_WEIGHTS=1<<ARRAY_WEIGHTS, ARRAY_FORMAT_INDEX=1<<ARRAY_INDEX, - }; - + }; + enum PrimitiveType { PRIMITIVE_POINTS=VisualServer::PRIMITIVE_POINTS, PRIMITIVE_LINES=VisualServer::PRIMITIVE_LINES, @@ -87,7 +87,7 @@ public: PRIMITIVE_TRIANGLES=VisualServer::PRIMITIVE_TRIANGLES, PRIMITIVE_TRIANGLE_STRIP=VisualServer::PRIMITIVE_TRIANGLE_STRIP, PRIMITIVE_TRIANGLE_FAN=VisualServer::PRIMITIVE_TRIANGLE_FAN, - }; + }; enum MorphTargetMode { @@ -95,7 +95,7 @@ public: MORPH_MODE_RELATIVE=VS::MORPH_MODE_RELATIVE, }; -private: +private: struct Surface { String name; AABB aabb; @@ -111,16 +111,16 @@ private: mutable Ref<TriangleMesh> triangle_mesh; - + void _recompute_aabb(); protected: - + bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; - + static void _bind_methods(); - + public: void add_surface(PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alphasort=false); @@ -174,7 +174,7 @@ public: DVector<Face3> get_faces() const; Ref<TriangleMesh> generate_triangle_mesh() const; Mesh(); - + ~Mesh(); }; diff --git a/scene/resources/mesh_library.cpp b/scene/resources/mesh_library.cpp index 8643e96303..76bb1c585f 100644 --- a/scene/resources/mesh_library.cpp +++ b/scene/resources/mesh_library.cpp @@ -103,7 +103,7 @@ void MeshLibrary::create_item(int p_item) { void MeshLibrary::set_item_name(int p_item,const String& p_name) { ERR_FAIL_COND(!item_map.has(p_item)); - item_map[p_item].name=p_name; + item_map[p_item].name=p_name; emit_changed(); _change_notify(); diff --git a/scene/resources/mesh_library.h b/scene/resources/mesh_library.h index 9a468d5555..bf0107d7a9 100644 --- a/scene/resources/mesh_library.h +++ b/scene/resources/mesh_library.h @@ -56,7 +56,7 @@ protected: void _get_property_list( List<PropertyInfo> *p_list) const; static void _bind_methods(); -public: +public: void create_item(int p_item); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index a9010e79a2..ef04c68e8e 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -646,7 +646,7 @@ https://github.com/godotengine/godot/issues/3127 } // Save the right type. If this node was created by an instance - // then flag that the node should not be created but reused + // then flag that the node should not be created but reused if (pack_state_stack.empty()) { //this node is not part of an instancing process, so save the type nd.type=_nm_get_string(p_node->get_type(),name_map); @@ -963,7 +963,7 @@ Ref<SceneState> SceneState::_get_base_scene_state() const { int SceneState::find_node_by_path(const NodePath& p_node) const { - if (!node_path_cache.has(p_node)) { + if (!node_path_cache.has(p_node)) { if (_get_base_scene_state().is_valid()) { int idx = _get_base_scene_state()->find_node_by_path(p_node); if (idx>=0) { @@ -1275,7 +1275,7 @@ Dictionary SceneState::get_bundled_scene() const { rnode_paths.resize(node_paths.size()); for(int i=0;i<node_paths.size();i++) { rnode_paths[i]=node_paths[i]; - } + } d["node_paths"]=rnode_paths; Array reditable_instances; diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index 6a26cc472c..6bde508d72 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -66,7 +66,7 @@ class SceneState : public Reference { }; Vector<Property> properties; - Vector<int> groups; + Vector<int> groups; }; diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp index e8cdec66df..1a7dc56e40 100644 --- a/scene/resources/polygon_path_finder.cpp +++ b/scene/resources/polygon_path_finder.cpp @@ -545,7 +545,7 @@ Vector2 PolygonPathFinder::get_closest_point(const Vector2& p_point) const { closest_point=closest; } } - + ERR_FAIL_COND_V(closest_dist==1e20,Vector2()); return closest_point; diff --git a/scene/resources/polygon_path_finder.h b/scene/resources/polygon_path_finder.h index 2cbe3e949d..b23dbd0bac 100644 --- a/scene/resources/polygon_path_finder.h +++ b/scene/resources/polygon_path_finder.h @@ -61,7 +61,7 @@ public: bool is_point_inside(const Vector2& p_point) const; Vector2 get_closest_point(const Vector2& p_point) const; - Vector<Vector2> get_intersections(const Vector2& p_from, const Vector2& p_to) const; + Vector<Vector2> get_intersections(const Vector2& p_from, const Vector2& p_to) const; Rect2 get_bounds() const; diff --git a/scene/resources/room.cpp b/scene/resources/room.cpp index 0f9eb85244..4024e2f45c 100644 --- a/scene/resources/room.cpp +++ b/scene/resources/room.cpp @@ -48,7 +48,7 @@ BSP_Tree RoomBounds::get_bounds() const { } void RoomBounds::set_geometry_hint(const DVector<Face3>& p_geometry_hint) { - + geometry_hint=p_geometry_hint; } diff --git a/scene/resources/room.h b/scene/resources/room.h index c5aaea311e..a9f159cd46 100644 --- a/scene/resources/room.h +++ b/scene/resources/room.h @@ -38,8 +38,8 @@ class RoomBounds : public Resource { OBJ_TYPE( RoomBounds, Resource ); RES_BASE_EXTENSION("room"); - - RID area; + + RID area; DVector<Face3> geometry_hint; void _regenerate_bsp(); @@ -54,10 +54,10 @@ public: void set_bounds( const BSP_Tree& p_bounds ); BSP_Tree get_bounds() const; - + void set_geometry_hint(const DVector<Face3>& geometry_hint); const DVector<Face3>& get_geometry_hint() const; - + RoomBounds(); ~RoomBounds(); diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp index 6bd5f520d2..f9f7f7807d 100644 --- a/scene/resources/scene_format_text.cpp +++ b/scene/resources/scene_format_text.cpp @@ -1144,7 +1144,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path,const RES& p_re if (packed_scene->get_state()->is_node_instance_placeholder(i)) continue; - Ref<PackedScene> instance=packed_scene->get_state()->get_node_instance(i); + Ref<PackedScene> instance=packed_scene->get_state()->get_node_instance(i); if (instance.is_valid() && !external_resources.has(instance)) { int index = external_resources.size(); external_resources[instance]=index; diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 71a775ee24..75e38f9701 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -37,7 +37,7 @@ void StyleBox::set_default_margin(Margin p_margin, float p_value) { margin[p_margin]=p_value; emit_changed(); - + } float StyleBox::get_default_margin(Margin p_margin) const{ @@ -59,7 +59,7 @@ Size2 StyleBox::get_minimum_size() const { Point2 StyleBox::get_offset() const { - + return Point2( get_margin( MARGIN_LEFT), get_margin( MARGIN_TOP) ); } @@ -94,33 +94,33 @@ void StyleBox::_bind_methods() { } StyleBox::StyleBox() { - + for (int i=0;i<4;i++) { - + margin[i]=-1; } } void StyleBoxTexture::set_texture(RES p_texture) { - + texture=p_texture; emit_changed(); } RES StyleBoxTexture::get_texture() const { - + return texture; } void StyleBoxTexture::set_margin_size(Margin p_margin,float p_size) { - + margin[p_margin]=p_size; emit_changed(); } float StyleBoxTexture::get_margin_size(Margin p_margin) const { - + return margin[p_margin]; } @@ -142,14 +142,14 @@ void StyleBoxTexture::draw(RID p_canvas_item,const Rect2& p_rect) const { } void StyleBoxTexture::set_draw_center(bool p_draw) { - + draw_center=p_draw; emit_changed(); } bool StyleBoxTexture::get_draw_center() const { - + return draw_center; } @@ -204,18 +204,18 @@ void StyleBoxTexture::_bind_methods() { } StyleBoxTexture::StyleBoxTexture() { - - + + for (int i=0;i<4;i++) { margin[i]=0; expand_margin[i]=0; } draw_center=true; - + } StyleBoxTexture::~StyleBoxTexture() { - - + + } //////////////// diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h index d0466ed5f1..02d79bc2ac 100644 --- a/scene/resources/style_box.h +++ b/scene/resources/style_box.h @@ -36,60 +36,60 @@ @author Juan Linietsky <reduzio@gmail.com> */ class StyleBox : public Resource { - + OBJ_TYPE( StyleBox, Resource ); RES_BASE_EXTENSION("sbx"); OBJ_SAVE_TYPE( StyleBox ); float margin[4]; - -protected: - + +protected: + virtual float get_style_margin(Margin p_margin) const=0; static void _bind_methods(); public: - + virtual bool test_mask(const Point2& p_point, const Rect2& p_rect) const; - + void set_default_margin(Margin p_margin, float p_value); float get_default_margin(Margin p_margin) const; float get_margin(Margin p_margin) const; virtual Size2 get_center_size() const; - + virtual void draw(RID p_canvas_item,const Rect2& p_rect) const=0; - + Size2 get_minimum_size() const; Point2 get_offset() const; - + StyleBox(); }; class StyleBoxEmpty : public StyleBox { - + OBJ_TYPE( StyleBoxEmpty, StyleBox ); virtual float get_style_margin(Margin p_margin) const { return 0; } -public: - +public: + virtual void draw(RID p_canvas_item,const Rect2& p_rect) const {} StyleBoxEmpty() {} - + }; class StyleBoxTexture : public StyleBox { - + OBJ_TYPE( StyleBoxTexture, StyleBox ); - + float expand_margin[4]; float margin[4]; Ref<Texture> texture; bool draw_center; - -protected: - + +protected: + virtual float get_style_margin(Margin p_margin) const; static void _bind_methods(); - + public: void set_expand_margin_size(Margin p_expand_margin,float p_size); @@ -105,12 +105,12 @@ public: bool get_draw_center() const; virtual Size2 get_center_size() const; - + virtual void draw(RID p_canvas_item,const Rect2& p_rect) const; - - StyleBoxTexture(); + + StyleBoxTexture(); ~StyleBoxTexture(); - + }; class StyleBoxFlat : public StyleBox { diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index bf5070fd7d..e3a02420c7 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -324,7 +324,7 @@ Ref<Mesh> SurfaceTool::commit(const Ref<Mesh>& p_existing) { w=DVector<Color>::Write(); a[i]=array; - } break; + } break; case Mesh::ARRAY_FORMAT_BONES: case Mesh::ARRAY_FORMAT_WEIGHTS: { diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 28754480f1..1893bfe524 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -163,7 +163,7 @@ bool ImageTexture::_get(const StringName& p_name,Variant &r_ret) const { r_ret= lossy_storage_quality; else return false; - + return true; } @@ -171,8 +171,8 @@ bool ImageTexture::_get(const StringName& p_name,Variant &r_ret) const { void ImageTexture::_get_property_list( List<PropertyInfo> *p_list) const { - - + + PropertyHint img_hint=PROPERTY_HINT_NONE; if (storage==STORAGE_COMPRESS_LOSSY) { img_hint=PROPERTY_HINT_IMAGE_COMPRESS_LOSSY; @@ -207,16 +207,16 @@ void ImageTexture::_reload_hook(const RID& p_hook) { } void ImageTexture::create(int p_width, int p_height,Image::Format p_format,uint32_t p_flags) { - + flags=p_flags; VisualServer::get_singleton()->texture_allocate(texture,p_width, p_height, p_format, p_flags); format=p_format; w=p_width; h=p_height; - + } void ImageTexture::create_from_image(const Image& p_image, uint32_t p_flags) { - + flags=p_flags; w=p_image.get_width(); h=p_image.get_height(); @@ -228,7 +228,7 @@ void ImageTexture::create_from_image(const Image& p_image, uint32_t p_flags) { } void ImageTexture::set_flags(uint32_t p_flags) { - + /* uint32_t cube = flags & FLAG_CUBEMAP; @@ -238,11 +238,11 @@ void ImageTexture::set_flags(uint32_t p_flags) { flags=p_flags|cube; */ flags=p_flags; VisualServer::get_singleton()->texture_set_flags(texture,p_flags); - + } uint32_t ImageTexture::get_flags() const { - + return ImageTexture::flags; } @@ -252,7 +252,7 @@ Image::Format ImageTexture::get_format() const { } void ImageTexture::load(const String& p_path) { - + Image img; img.load(p_path); create_from_image(img); @@ -260,7 +260,7 @@ void ImageTexture::load(const String& p_path) { } void ImageTexture::set_data(const Image& p_image) { - + VisualServer::get_singleton()->texture_set_data(texture,p_image); VisualServer::get_singleton()->texture_set_reload_hook(texture,0,StringName()); //hook is erased if data is changed _change_notify(); @@ -282,23 +282,23 @@ void ImageTexture::_resource_path_changed() { } Image ImageTexture::get_data() const { - + return VisualServer::get_singleton()->texture_get_data(texture); } int ImageTexture::get_width() const { - - return w; + + return w; } int ImageTexture::get_height() const { - + return h; } RID ImageTexture::get_rid() const { - + return texture; } @@ -458,13 +458,13 @@ ImageTexture::ImageTexture() { texture = VisualServer::get_singleton()->texture_create(); storage = STORAGE_RAW; lossy_storage_quality=0.7; - + } ImageTexture::~ImageTexture() { - + VisualServer::get_singleton()->free( texture ); } diff --git a/scene/resources/texture.h b/scene/resources/texture.h index 2627b9480a..103b425cd8 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -84,7 +84,7 @@ VARIANT_ENUM_CAST( Texture::Flags ); class ImageTexture : public Texture { - + OBJ_TYPE( ImageTexture, Texture ); RES_BASE_EXTENSION("tex"); public: @@ -97,12 +97,12 @@ private: RID texture; Image::Format format; uint32_t flags; - int w,h; + int w,h; Storage storage; Size2 size_override; float lossy_storage_quality; -protected: +protected: virtual bool can_reload_from_file(); virtual void reload_from_file(); @@ -117,24 +117,24 @@ protected: void _set_data(Dictionary p_data); public: - + void create(int p_width, int p_height,Image::Format p_format,uint32_t p_flags=FLAGS_DEFAULT); void create_from_image(const Image& p_image, uint32_t p_flags=FLAGS_DEFAULT); - + void set_flags(uint32_t p_flags); uint32_t get_flags() const; Image::Format get_format() const; void load(const String& p_path); void set_data(const Image& p_image); Image get_data() const; - + int get_width() const; int get_height() const; - + virtual RID get_rid() const; - + bool has_alpha() const; virtual void draw(RID p_canvas_item, const Point2& p_pos, const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const; virtual void draw_rect(RID p_canvas_item,const Rect2& p_rect, bool p_tile=false,const Color& p_modulate=Color(1,1,1), bool p_transpose=false) const; diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 685b2e07e1..74e59b09c3 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -104,67 +104,67 @@ bool Theme::_get(const StringName& p_name,Variant &r_ret) const { } void Theme::_get_property_list( List<PropertyInfo> *p_list) const { - + List<PropertyInfo> list; const StringName *key=NULL; - + while((key=icon_map.next(key))) { - + const StringName *key2=NULL; - + while((key2=icon_map[*key].next(key2))) { list.push_back( PropertyInfo( Variant::OBJECT, String()+*key+"/icons/"+*key2, PROPERTY_HINT_RESOURCE_TYPE, "Texture" ) ); } } - + key=NULL; - + while((key=style_map.next(key))) { - + const StringName *key2=NULL; - + while((key2=style_map[*key].next(key2))) { - + list.push_back( PropertyInfo( Variant::OBJECT, String()+*key+"/styles/"+*key2, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox" ) ); } } - + key=NULL; - + while((key=font_map.next(key))) { - + const StringName *key2=NULL; - + while((key2=font_map[*key].next(key2))) { - + list.push_back( PropertyInfo( Variant::OBJECT, String()+*key+"/fonts/"+*key2, PROPERTY_HINT_RESOURCE_TYPE, "Font" ) ); } } - + key=NULL; - + while((key=color_map.next(key))) { - + const StringName *key2=NULL; - + while((key2=color_map[*key].next(key2))) { - + list.push_back( PropertyInfo( Variant::COLOR, String()+*key+"/colors/"+*key2 ) ); } } - + key=NULL; - + while((key=constant_map.next(key))) { - + const StringName *key2=NULL; - + while((key2=constant_map[*key].next(key2))) { - + list.push_back( PropertyInfo( Variant::INT, String()+*key+"/constants/"+*key2 ) ); } } @@ -173,12 +173,12 @@ void Theme::_get_property_list( List<PropertyInfo> *p_list) const { for(List<PropertyInfo>::Element *E=list.front();E;E=E->next()) { p_list->push_back(E->get()); } - + } Ref<Theme> Theme::get_default() { - - return default_theme; + + return default_theme; } @@ -193,7 +193,7 @@ Ref<Font> Theme::get_default_theme_font() const { } void Theme::set_default(const Ref<Theme>& p_default) { - + default_theme=p_default; } @@ -221,7 +221,7 @@ void Theme::set_icon(const StringName& p_name,const StringName& p_type,const Ref bool new_value=!icon_map.has(p_type) || !icon_map[p_type].has(p_name); - icon_map[p_type][p_name]=p_icon; + icon_map[p_type][p_name]=p_icon; if (new_value) { _change_notify(); @@ -229,7 +229,7 @@ void Theme::set_icon(const StringName& p_name,const StringName& p_type,const Ref } } Ref<Texture> Theme::get_icon(const StringName& p_name,const StringName& p_type) const { - + if (icon_map.has(p_type) && icon_map[p_type].has(p_name) && icon_map[p_type][p_name].is_valid()) { return icon_map[p_type][p_name]; @@ -239,7 +239,7 @@ Ref<Texture> Theme::get_icon(const StringName& p_name,const StringName& p_type) } bool Theme::has_icon(const StringName& p_name,const StringName& p_type) const { - + return (icon_map.has(p_type) && icon_map[p_type].has(p_name)); } @@ -266,13 +266,13 @@ void Theme::get_icon_list(StringName p_type, List<StringName> *p_list) const { p_list->push_back(*key); } - + } void Theme::set_shader(const StringName &p_name,const StringName &p_type,const Ref<Shader>& p_shader) { bool new_value=!shader_map.has(p_type) || !shader_map[p_type].has(p_name); - shader_map[p_type][p_name]=p_shader; + shader_map[p_type][p_name]=p_shader; if (new_value) { _change_notify(); @@ -311,7 +311,7 @@ void Theme::get_shader_list(const StringName &p_type, List<StringName> *p_list) p_list->push_back(*key); } - + } @@ -331,7 +331,7 @@ void Theme::set_stylebox(const StringName& p_name,const StringName& p_type,const Ref<StyleBox> Theme::get_stylebox(const StringName& p_name,const StringName& p_type) const { - + if (style_map.has(p_type) && style_map[p_type].has(p_name) && style_map[p_type][p_name].is_valid()) { return style_map[p_type][p_name]; @@ -341,7 +341,7 @@ Ref<StyleBox> Theme::get_stylebox(const StringName& p_name,const StringName& p_t } bool Theme::has_stylebox(const StringName& p_name,const StringName& p_type) const { - + return (style_map.has(p_type) && style_map[p_type].has(p_name) ); } @@ -384,18 +384,18 @@ void Theme::set_font(const StringName& p_name,const StringName& p_type,const Ref } } Ref<Font> Theme::get_font(const StringName& p_name,const StringName& p_type) const { - + if (font_map.has(p_type) && font_map[p_type].has(p_name) && font_map[p_type][p_name].is_valid()) - return font_map[p_type][p_name]; + return font_map[p_type][p_name]; else if (default_theme_font.is_valid()) return default_theme_font; else return default_font; - + } bool Theme::has_font(const StringName& p_name,const StringName& p_type) const { - + return (font_map.has(p_type) && font_map[p_type].has(p_name)); } @@ -425,7 +425,7 @@ void Theme::get_font_list(StringName p_type, List<StringName> *p_list) const { } void Theme::set_color(const StringName& p_name,const StringName& p_type,const Color& p_color) { - + bool new_value=!color_map.has(p_type) || !color_map[p_type].has(p_name); color_map[p_type][p_name]=p_color; @@ -440,16 +440,16 @@ void Theme::set_color(const StringName& p_name,const StringName& p_type,const Co Color Theme::get_color(const StringName& p_name,const StringName& p_type) const { - + if (color_map.has(p_type) && color_map[p_type].has(p_name)) - return color_map[p_type][p_name]; + return color_map[p_type][p_name]; else return Color(); - + } bool Theme::has_color(const StringName& p_name,const StringName& p_type) const { - + return (color_map.has(p_type) && color_map[p_type].has(p_name)); } @@ -479,7 +479,7 @@ void Theme::get_color_list(StringName p_type, List<StringName> *p_list) const { } void Theme::set_constant(const StringName& p_name,const StringName& p_type,int p_constant) { - + bool new_value=!constant_map.has(p_type) || !constant_map[p_type].has(p_name); constant_map[p_type][p_name]=p_constant; @@ -490,17 +490,17 @@ void Theme::set_constant(const StringName& p_name,const StringName& p_type,int p } int Theme::get_constant(const StringName& p_name,const StringName& p_type) const { - + if (constant_map.has(p_type) && constant_map[p_type].has(p_name)) - return constant_map[p_type][p_name]; + return constant_map[p_type][p_name]; else { return 0; } - + } bool Theme::has_constant(const StringName& p_name,const StringName& p_type) const { - + return (constant_map.has(p_type) && constant_map[p_type].has(p_name)); } @@ -635,8 +635,8 @@ void Theme::_bind_methods() { } Theme::Theme() { - - + + } diff --git a/scene/resources/theme.h b/scene/resources/theme.h index 180f55381d..36630087f6 100644 --- a/scene/resources/theme.h +++ b/scene/resources/theme.h @@ -40,12 +40,12 @@ @author Juan Linietsky <reduzio@gmail.com> */ class Theme : public Resource { - + OBJ_TYPE( Theme, Resource ); RES_BASE_EXTENSION("thm"); - + static Ref<Theme> default_theme; - + HashMap<StringName,HashMap<StringName,Ref<Texture>,StringNameHasher >, StringNameHasher > icon_map; HashMap<StringName,HashMap<StringName,Ref<StyleBox>,StringNameHasher >,StringNameHasher > style_map; HashMap<StringName,HashMap<StringName,Ref<Font>,StringNameHasher >,StringNameHasher > font_map; @@ -56,7 +56,7 @@ protected: bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; - + static Ref<Texture> default_icon; static Ref<StyleBox> default_style; static Ref<Font> default_font; @@ -72,10 +72,10 @@ protected: static void _bind_methods(); public: - + static Ref<Theme> get_default(); static void set_default(const Ref<Theme>& p_default); - + static void set_default_icon( const Ref<Texture>& p_icon ); static void set_default_style( const Ref<StyleBox>& p_default_style); static void set_default_font( const Ref<Font>& p_default_font ); diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 6f71287750..bf01929191 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -344,13 +344,13 @@ Array TileSet::_tile_get_shapes(int p_id) const{ } Array TileSet::_get_tiles_ids() const{ - + Array arr; for (Map<int, Data>::Element *E = tile_map.front(); E; E = E->next()) { - arr.push_back(E->key()); + arr.push_back(E->key()); } - + return arr; } diff --git a/scene/resources/volume.cpp b/scene/resources/volume.cpp index 8eb96cb4ad..8e056158cb 100644 --- a/scene/resources/volume.cpp +++ b/scene/resources/volume.cpp @@ -33,10 +33,10 @@ void Volume::_set(const String& p_name, const Variant& p_value) { if (p_name.begins_with("shapes/")) { - + int idx=p_name.get_slice("/",1).to_int()-1; ERR_FAIL_COND( idx != get_shape_count() ); - + Dictionary shape = p_value; ERR_FAIL_COND( !shape.has("type") || !shape.has("data")); String type = shape["type"]; @@ -44,7 +44,7 @@ void Volume::_set(const String& p_name, const Variant& p_value) { Transform transform; if (shape.has("transform")) transform=shape["transform"]; - + if (type=="plane") add_shape(SHAPE_PLANE,data,transform); else if (type=="sphere") @@ -59,7 +59,7 @@ void Volume::_set(const String& p_name, const Variant& p_value) { add_shape(SHAPE_CONVEX_POLYGON,data,transform); else if (type=="concave_polygon") add_shape(SHAPE_CONCAVE_POLYGON,data,transform); - else { + else { ERR_FAIL(); } } @@ -68,14 +68,14 @@ void Volume::_set(const String& p_name, const Variant& p_value) { Variant Volume::_get(const String& p_name) const { if (p_name.begins_with("shapes/")) { - + int idx=p_name.get_slice("/",1).to_int()-1; ERR_FAIL_INDEX_V( idx, get_shape_count(), Variant() ); - + Dictionary shape; - + switch( get_shape_type(idx) ) { - + case SHAPE_PLANE: shape["type"]="plane"; break; case SHAPE_SPHERE: shape["type"]="sphere"; break; case SHAPE_BOX: shape["type"]="box"; break; @@ -83,15 +83,15 @@ Variant Volume::_get(const String& p_name) const { case SHAPE_CAPSULE: shape["type"]="capsule"; break; case SHAPE_CONVEX_POLYGON: shape["type"]="convex_polygon"; break; case SHAPE_CONCAVE_POLYGON: shape["type"]="concave_polygon"; break; - + } - + shape["transform"]=get_shape_transform(idx); shape["data"]=get_shape(idx); return shape; } - + return Variant(); } @@ -99,8 +99,8 @@ void Volume::_get_property_list( List<PropertyInfo> *p_list) const { int count=get_shape_count(); for(int i=0;i<count;i++) { - - p_list->push_back( PropertyInfo( Variant::DICTIONARY, "shapes/"+itos(i+1)) ); + + p_list->push_back( PropertyInfo( Variant::DICTIONARY, "shapes/"+itos(i+1)) ); } } @@ -118,7 +118,7 @@ void Volume::add_shape(ShapeType p_shape_type, const Variant& p_data, const Tran void Volume::add_plane_shape(const Plane& p_plane,const Transform& p_transform) { add_shape(SHAPE_PLANE, p_plane, p_transform ); -} +} void Volume::add_sphere_shape(float p_radius,const Transform& p_transform) { @@ -140,7 +140,7 @@ void Volume::add_cylinder_shape(float p_radius, float p_height,const Transform& void Volume::add_capsule_shape(float p_radius, float p_height,const Transform& p_transform) { Dictionary d; - d["radius"]=p_radius; + d["radius"]=p_radius; d["height"]=p_height; add_shape(SHAPE_CAPSULE,d,p_transform); @@ -179,7 +179,7 @@ void Volume::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_shape_type","shape_idx"),&Volume::get_shape_type); ObjectTypeDB::bind_method(_MD("get_shape_transform","shape_idx"),&Volume::get_shape_transform); ObjectTypeDB::bind_method(_MD("get_shape","shape_idx"),&Volume::get_shape); - + BIND_CONSTANT( SHAPE_PLANE ); BIND_CONSTANT( SHAPE_SPHERE ); BIND_CONSTANT( SHAPE_BOX ); @@ -198,7 +198,7 @@ RID Volume::get_rid() { Volume::Volume() { volume= PhysicsServer::get_singleton()->volume_create(); - + } diff --git a/scene/resources/volume.h b/scene/resources/volume.h index be3cbddbbd..f03e48f1d9 100644 --- a/scene/resources/volume.h +++ b/scene/resources/volume.h @@ -38,16 +38,16 @@ */ class Volume : public Resource { - OBJ_TYPE( Volume, Resource ); + OBJ_TYPE( Volume, Resource ); RID volume; - + protected: - + bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List<PropertyInfo> *p_list) const; - - static void _bind_methods(); + + static void _bind_methods(); public: enum ShapeType { @@ -59,22 +59,22 @@ public: SHAPE_CONVEX_POLYGON = PhysicsServer::SHAPE_CONVEX_POLYGON, ///< array of planes:"planes" SHAPE_CONCAVE_POLYGON = PhysicsServer::SHAPE_CONCAVE_POLYGON, ///< vector3 array:"triangles" }; - + void add_shape(ShapeType p_shape_type, const Variant& p_data, const Transform& p_transform=Transform ()); - + void add_plane_shape(const Plane& p_plane,const Transform& p_transform); void add_sphere_shape(float p_radius,const Transform& p_transform); void add_box_shape(const Vector3& p_half_extents,const Transform& p_transform); void add_cylinder_shape(float p_radius, float p_height,const Transform& p_transform); void add_capsule_shape(float p_radius, float p_height,const Transform& p_transform); - + int get_shape_count() const; ShapeType get_shape_type(int p_shape) const; Transform get_shape_transform(int p_shape) const; Variant get_shape(int p_shape) const; virtual RID get_rid(); - + Volume(); ~Volume(); diff --git a/servers/audio/audio_mixer_sw.cpp b/servers/audio/audio_mixer_sw.cpp index d1f36cb7b6..64369182b1 100644 --- a/servers/audio/audio_mixer_sw.cpp +++ b/servers/audio/audio_mixer_sw.cpp @@ -339,7 +339,7 @@ void AudioMixerSW::mix_channel(Channel& c) { c.mix.old_chorus_vol[i]=c.mix.chorus_vol[i]; } - c.first_mix=false; + c.first_mix=false; } @@ -734,7 +734,7 @@ int AudioMixerSW::_get_channel(ChannelID p_channel) const { if (channels[idx].check!=check) { return -1; } - if (!channels[idx].active) { + if (!channels[idx].active) { return -1; } @@ -918,7 +918,7 @@ void AudioMixerSW::channel_set_filter(ChannelID p_channel, FilterType p_type, fl if (type_changed) { //type changed reset filter - c.filter.old_coefs=c.filter.coefs; + c.filter.old_coefs=c.filter.coefs; c.mix.filter_l.ha[0]=0; c.mix.filter_l.ha[1]=0; c.mix.filter_l.hb[0]=0; diff --git a/servers/audio/audio_mixer_sw.h b/servers/audio/audio_mixer_sw.h index f5bd4cc5ba..950ed19af6 100644 --- a/servers/audio/audio_mixer_sw.h +++ b/servers/audio/audio_mixer_sw.h @@ -197,7 +197,7 @@ private: void mix_channel(Channel& p_channel); int mix_chunk_left; - void mix_chunk(); + void mix_chunk(); float channel_nrg; int channel_id_count; diff --git a/servers/audio/audio_server_sw.h b/servers/audio/audio_server_sw.h index bc6191729c..8d3d992e2b 100644 --- a/servers/audio/audio_server_sw.h +++ b/servers/audio/audio_server_sw.h @@ -68,7 +68,7 @@ class AudioServerSW : public AudioServer { SelfList<Voice>::List active_list; struct Stream { - bool active; + bool active; List<Stream*>::Element *E; AudioStream *audio_stream; EventStream *event_stream; diff --git a/servers/physics/gjk_epa.cpp b/servers/physics/gjk_epa.cpp index 229c6d3fb4..f76f8c646a 100644 --- a/servers/physics/gjk_epa.cpp +++ b/servers/physics/gjk_epa.cpp @@ -15,7 +15,7 @@ // Config -/* GJK */ +/* GJK */ #define GJK_MAX_ITERATIONS 128 #define GJK_ACCURARY ((real_t)0.0001) #define GJK_MIN_DISTANCE ((real_t)0.0001) @@ -24,7 +24,7 @@ #define GJK_SIMPLEX3_EPS ((real_t)0.0) #define GJK_SIMPLEX4_EPS ((real_t)0.0) -/* EPA */ +/* EPA */ #define EPA_MAX_VERTICES 64 #define EPA_MAX_FACES (EPA_MAX_VERTICES*2) #define EPA_MAX_ITERATIONS 255 @@ -38,12 +38,12 @@ namespace GjkEpa2 { struct sResults { enum eStatus { - Separated, /* Shapes doesnt penetrate */ - Penetrating, /* Shapes are penetrating */ - GJK_Failed, /* GJK phase fail, no big issue, shapes are probably just 'touching' */ - EPA_Failed /* EPA phase fail, bigger problem, need to save parameters, and debug */ + Separated, /* Shapes doesnt penetrate */ + Penetrating, /* Shapes are penetrating */ + GJK_Failed, /* GJK phase fail, no big issue, shapes are probably just 'touching' */ + EPA_Failed /* EPA phase fail, bigger problem, need to save parameters, and debug */ } status; - + Vector3 witnesses[2]; Vector3 normal; real_t distance; @@ -65,15 +65,15 @@ struct MinkowskiDiff { _FORCE_INLINE_ Vector3 Support0 ( const Vector3& d ) const { return transform_A.xform( m_shapes[0]->get_support( transform_A.basis.xform_inv(d).normalized() ) ); } - + _FORCE_INLINE_ Vector3 Support1 ( const Vector3& d ) const { return transform_B.xform( m_shapes[1]->get_support( transform_B.basis.xform_inv(d).normalized() ) ); } - + _FORCE_INLINE_ Vector3 Support ( const Vector3& d ) const { return ( Support0 ( d )-Support1 ( -d ) ); } - + _FORCE_INLINE_ Vector3 Support ( const Vector3& d,U index ) const { if ( index ) @@ -89,7 +89,7 @@ typedef MinkowskiDiff tShape; // GJK struct GJK { - /* Types */ + /* Types */ struct sSV { Vector3 d,w; @@ -104,7 +104,7 @@ struct GJK Valid, Inside, Failed };}; - /* Fields */ + /* Fields */ tShape m_shape; Vector3 m_ray; real_t m_distance; @@ -115,7 +115,7 @@ struct GJK U m_current; sSimplex* m_simplex; eStatus::_ m_status; - /* Methods */ + /* Methods */ GJK() { Initialize(); @@ -135,7 +135,7 @@ struct GJK real_t alpha=0; Vector3 lastw[4]; U clastw=0; - /* Initialize solver */ + /* Initialize solver */ m_free[0] = &m_store[0]; m_free[1] = &m_store[1]; m_free[2] = &m_store[2]; @@ -145,31 +145,31 @@ struct GJK m_status = eStatus::Valid; m_shape = shapearg; m_distance = 0; - /* Initialize simplex */ + /* Initialize simplex */ m_simplices[0].rank = 0; m_ray = guess; const real_t sqrl= m_ray.length_squared(); appendvertice(m_simplices[0],sqrl>0?-m_ray:Vector3(1,0,0)); m_simplices[0].p[0] = 1; - m_ray = m_simplices[0].c[0]->w; + m_ray = m_simplices[0].c[0]->w; sqdist = sqrl; lastw[0] = lastw[1] = lastw[2] = lastw[3] = m_ray; - /* Loop */ + /* Loop */ do { const U next=1-m_current; sSimplex& cs=m_simplices[m_current]; sSimplex& ns=m_simplices[next]; - /* Check zero */ + /* Check zero */ const real_t rl=m_ray.length(); if(rl<GJK_MIN_DISTANCE) - {/* Touching or inside */ + {/* Touching or inside */ m_status=eStatus::Inside; break; } - /* Append new vertice in -'v' direction */ + /* Append new vertice in -'v' direction */ appendvertice(cs,-m_ray); const Vector3& w=cs.c[cs.rank-1]->w; bool found=false; @@ -179,23 +179,23 @@ struct GJK { found=true;break; } } if(found) - {/* Return old simplex */ + {/* Return old simplex */ removevertice(m_simplices[m_current]); break; } else - {/* Update lastw */ + {/* Update lastw */ lastw[clastw=(clastw+1)&3]=w; } - /* Check for termination */ + /* Check for termination */ const real_t omega=vec3_dot(m_ray,w)/rl; alpha=MAX(omega,alpha); if(((rl-alpha)-(GJK_ACCURARY*rl))<=0) - {/* Return old simplex */ + {/* Return old simplex */ removevertice(m_simplices[m_current]); break; - } - /* Reduce simplex */ + } + /* Reduce simplex */ real_t weights[4]; U mask=0; switch(cs.rank) @@ -214,7 +214,7 @@ struct GJK weights,mask);break; } if(sqdist>=0) - {/* Valid */ + {/* Valid */ ns.rank = 0; m_ray = Vector3(0,0,0); m_current = next; @@ -234,7 +234,7 @@ struct GJK if(mask==15) m_status=eStatus::Inside; } else - {/* Return old simplex */ + {/* Return old simplex */ removevertice(m_simplices[m_current]); break; } @@ -246,7 +246,7 @@ struct GJK case eStatus::Valid: m_distance=m_ray.length();break; case eStatus::Inside: m_distance=0;break; default: {} - } + } return(m_status); } bool EncloseOrigin() @@ -314,7 +314,7 @@ struct GJK } return(false); } - /* Internals */ + /* Internals */ void getsupport(const Vector3& d,sSV& sv) const { sv.d = d/d.length(); @@ -378,13 +378,13 @@ struct GJK m = static_cast<U>(((subm&1)?1<<i:0)+((subm&2)?1<<j:0)); w[i] = subw[0]; w[j] = subw[1]; - w[imd3[j]] = 0; + w[imd3[j]] = 0; } } } if(mindist<0) { - const real_t d=vec3_dot(a,n); + const real_t d=vec3_dot(a,n); const real_t s=Math::sqrt(l); const Vector3 p=n*(d/l); mindist = p.length_squared(); @@ -451,7 +451,7 @@ struct GJK // EPA struct EPA { - /* Types */ + /* Types */ typedef GJK::sSV sSV; struct sFace { @@ -482,13 +482,13 @@ struct GJK Touching, Degenerated, NonConvex, - InvalidHull, + InvalidHull, OutOfFaces, OutOfVertices, AccuraryReached, FallBack, Failed };}; - /* Fields */ + /* Fields */ eStatus::_ m_status; GJK::sSimplex m_result; Vector3 m_normal; @@ -498,10 +498,10 @@ struct GJK U m_nextsv; sList m_hull; sList m_stock; - /* Methods */ + /* Methods */ EPA() { - Initialize(); + Initialize(); } @@ -544,7 +544,7 @@ struct GJK if((simplex.rank>1)&&gjk.EncloseOrigin()) { - /* Clean up */ + /* Clean up */ while(m_hull.root) { sFace* f = m_hull.root; @@ -553,7 +553,7 @@ struct GJK } m_status = eStatus::Valid; m_nextsv = 0; - /* Orient simplex */ + /* Orient simplex */ if(gjk.det( simplex.c[0]->w-simplex.c[3]->w, simplex.c[1]->w-simplex.c[3]->w, simplex.c[2]->w-simplex.c[3]->w)<0) @@ -561,7 +561,7 @@ struct GJK SWAP(simplex.c[0],simplex.c[1]); SWAP(simplex.p[0],simplex.p[1]); } - /* Build initial hull */ + /* Build initial hull */ sFace* tetra[]={newface(simplex.c[0],simplex.c[1],simplex.c[2],true), newface(simplex.c[1],simplex.c[0],simplex.c[3],true), newface(simplex.c[2],simplex.c[1],simplex.c[3],true), @@ -582,10 +582,10 @@ struct GJK for(;iterations<EPA_MAX_ITERATIONS;++iterations) { if(m_nextsv<EPA_MAX_VERTICES) - { + { sHorizon horizon; sSV* w=&m_sv_store[m_nextsv++]; - bool valid=true; + bool valid=true; best->pass = (U1)(++pass); gjk.getsupport(best->n,*w); const real_t wdist=vec3_dot(best->n,w->w)-best->d; @@ -628,7 +628,7 @@ struct GJK return(m_status); } } - /* Fallback */ + /* Fallback */ m_status = eStatus::FallBack; m_normal = -guess; const real_t nl=m_normal.length(); @@ -639,7 +639,7 @@ struct GJK m_depth = 0; m_result.rank=1; m_result.c[0]=simplex.c[0]; - m_result.p[0]=1; + m_result.p[0]=1; return(m_status); } sFace* newface(sSV* a,sSV* b,sSV* c,bool forced) @@ -739,16 +739,16 @@ struct GJK tShape& shape, bool withmargins) { - /* Results */ + /* Results */ results.witnesses[0] = results.witnesses[1] = Vector3(0,0,0); results.status = sResults::Separated; - /* Shape */ + /* Shape */ shape.m_shapes[0] = shape0; shape.m_shapes[1] = shape1; shape.transform_A = wtrs0; shape.transform_B = wtrs1; - + } @@ -808,7 +808,7 @@ bool Penetration( const ShapeSW* shape0, { tShape shape; Initialize(shape0,wtrs0,shape1,wtrs1,results,shape,false); - GJK gjk; + GJK gjk; GJK::eStatus::_ gjk_status=gjk.Evaluate(shape,-guess); switch(gjk_status) { @@ -841,7 +841,7 @@ bool Penetration( const ShapeSW* shape0, } -/* Symbols cleanup */ +/* Symbols cleanup */ #undef GJK_MAX_ITERATIONS #undef GJK_ACCURARY @@ -885,7 +885,7 @@ bool gjk_epa_calculate_distance(const ShapeSW *p_shape_A, const Transform& p_tra bool gjk_epa_calculate_penetration(const ShapeSW *p_shape_A, const Transform& p_transform_A, const ShapeSW *p_shape_B, const Transform& p_transform_B, CollisionSolverSW::CallbackResult p_result_callback,void *p_userdata, bool p_swap ) { GjkEpa2::sResults res; - + if (GjkEpa2::Penetration(p_shape_A,p_transform_A,p_shape_B,p_transform_B,p_transform_B.origin-p_transform_A.origin,res)) { if (p_result_callback) { if (p_swap) @@ -894,8 +894,8 @@ bool gjk_epa_calculate_penetration(const ShapeSW *p_shape_A, const Transform& p_ p_result_callback(res.witnesses[0],res.witnesses[1],p_userdata); } return true; - } - + } + return false; } diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index 08f280a976..4cf7729b09 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -318,7 +318,7 @@ bool PhysicsDirectSpaceStateSW::cast_motion(const RID& p_shape, const Transform& } p_closest_safe=best_safe; - p_closest_unsafe=best_unsafe; + p_closest_unsafe=best_unsafe; return true; } diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index f1f94f3485..ab1c7ef66f 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -260,7 +260,7 @@ void Body2DSW::set_state(Physics2DServer::BodyState p_state, const Variant& p_va if (mode==Physics2DServer::BODY_MODE_KINEMATIC) { - new_transform=p_variant; + new_transform=p_variant; //wakeup_neighbours(); set_active(true); if (first_time_kinematic) { @@ -396,7 +396,7 @@ void Body2DSW::_compute_area_gravity_and_dampenings(const Area2DSW *p_area) { } area_linear_damp += p_area->get_linear_damp(); - area_angular_damp += p_area->get_angular_damp(); + area_angular_damp += p_area->get_angular_damp(); } void Body2DSW::integrate_forces(real_t p_step) { @@ -518,7 +518,7 @@ void Body2DSW::integrate_forces(real_t p_step) { // damp_area=NULL; // clear the area, so it is set in the next frame def_area=NULL; // clear the area, so it is set in the next frame - contact_count=0; + contact_count=0; } @@ -597,7 +597,7 @@ void Body2DSW::call_queries() { set_force_integration_callback(0,StringName()); } else { - Variant::CallError ce; + Variant::CallError ce; if (fi_callback->callback_udata.get_type()) { obj->call(fi_callback->method,vp,2,ce); diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp index db7869c6a6..35f19605df 100644 --- a/servers/physics_2d/body_pair_2d_sw.cpp +++ b/servers/physics_2d/body_pair_2d_sw.cpp @@ -77,7 +77,7 @@ void BodyPair2DSW::_contact_added_callback(const Vector2& p_point_A,const Vector contact.acc_normal_impulse=c.acc_normal_impulse; contact.acc_tangent_impulse=c.acc_tangent_impulse; contact.acc_bias_impulse=c.acc_bias_impulse; - new_index=i; + new_index=i; break; } } @@ -259,10 +259,10 @@ bool BodyPair2DSW::setup(float p_step) { if (A->get_continuous_collision_detection_mode()==Physics2DServer::CCD_MODE_CAST_SHAPE) { motion_A=A->get_motion(); - } + } if (B->get_continuous_collision_detection_mode()==Physics2DServer::CCD_MODE_CAST_SHAPE) { motion_B=B->get_motion(); - } + } //faster to set than to check.. //bool prev_collided=collided; diff --git a/servers/physics_2d/collision_solver_2d_sw.cpp b/servers/physics_2d/collision_solver_2d_sw.cpp index d9bf235c86..fcc3f8067a 100644 --- a/servers/physics_2d/collision_solver_2d_sw.cpp +++ b/servers/physics_2d/collision_solver_2d_sw.cpp @@ -226,7 +226,7 @@ bool CollisionSolver2DSW::solve_concave(const Shape2DSW *p_shape_A,const Matrix3 concave_B->cull(local_aabb,concave_callback,&cinfo); -// print_line("Rect2 TESTS: "+itos(cinfo.aabb_tests)); +// print_line("Rect2 TESTS: "+itos(cinfo.aabb_tests)); return cinfo.collided; } diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index 28acf4e2d1..cd4dfc1a8b 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -258,7 +258,7 @@ public: virtual void set_active(bool p_active); virtual void init(); virtual void step(float p_step); - virtual void sync(); + virtual void sync(); virtual void flush_queries(); virtual void end_sync(); virtual void finish(); diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp index 3054ba8d59..bd36f4060b 100644 --- a/servers/physics_2d/shape_2d_sw.cpp +++ b/servers/physics_2d/shape_2d_sw.cpp @@ -746,7 +746,7 @@ Variant ConvexPolygonShape2DSW::get_data() const { dvr.resize(point_count); - for(int i=0;i<point_count;i++) { + for(int i=0;i<point_count;i++) { dvr.set(i,points[i].pos); } diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index eaf9427ad8..027e218bfc 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -337,7 +337,7 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Matrix32 Vector2 sep=mnormal; //important optimization for this to work fast enough bool collided = CollisionSolver2DSW::solve(shape,p_xform,p_motion*(hi+space->contact_max_allowed_penetration),col_obj->get_shape(shape_idx),col_obj_xform,Vector2(),Physics2DServerSW::_shape_col_cbk,&cbk,&sep,p_margin); - if (!collided || cbk.amount==0) { + if (!collided || cbk.amount==0) { continue; } @@ -1256,7 +1256,7 @@ void Space2DSW::set_param(Physics2DServer::SpaceParameter p_param, real_t p_valu case Physics2DServer::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION: contact_max_allowed_penetration=p_value; break; case Physics2DServer::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_TRESHOLD: body_linear_velocity_sleep_treshold=p_value; break; case Physics2DServer::SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_TRESHOLD: body_angular_velocity_sleep_treshold=p_value; break; - case Physics2DServer::SPACE_PARAM_BODY_TIME_TO_SLEEP: body_time_to_sleep=p_value; break; + case Physics2DServer::SPACE_PARAM_BODY_TIME_TO_SLEEP: body_time_to_sleep=p_value; break; case Physics2DServer::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: constraint_bias=p_value; break; } } diff --git a/servers/physics_2d/step_2d_sw.cpp b/servers/physics_2d/step_2d_sw.cpp index 94e1d26329..4f9d06ee96 100644 --- a/servers/physics_2d/step_2d_sw.cpp +++ b/servers/physics_2d/step_2d_sw.cpp @@ -35,7 +35,7 @@ void Step2DSW::_populate_island(Body2DSW* p_body,Body2DSW** p_island,Constraint2 p_body->set_island_next(*p_island); *p_island=p_body; - for(Map<Constraint2DSW*,int>::Element *E=p_body->get_constraint_map().front();E;E=E->next()) { + for(Map<Constraint2DSW*,int>::Element *E=p_body->get_constraint_map().front();E;E=E->next()) { Constraint2DSW *c=(Constraint2DSW*)E->key(); if (c->get_island_step()==_step) diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index 7a4365bea3..25875f16d3 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -533,7 +533,7 @@ public: virtual void damped_string_joint_set_param(RID p_joint, DampedStringParam p_param, real_t p_value)=0; virtual real_t damped_string_joint_get_param(RID p_joint, DampedStringParam p_param) const=0; - virtual JointType joint_get_type(RID p_joint) const=0; + virtual JointType joint_get_type(RID p_joint) const=0; /* QUERY API */ diff --git a/servers/physics_server.h b/servers/physics_server.h index 8e302bf363..9b00825d92 100644 --- a/servers/physics_server.h +++ b/servers/physics_server.h @@ -421,7 +421,7 @@ public: BODY_STATE_LINEAR_VELOCITY, BODY_STATE_ANGULAR_VELOCITY, BODY_STATE_SLEEPING, - BODY_STATE_CAN_SLEEP + BODY_STATE_CAN_SLEEP }; virtual void body_set_state(RID p_body, BodyState p_state, const Variant& p_variant)=0; @@ -648,7 +648,7 @@ public: virtual void damped_string_joint_set_param(RID p_joint, DampedStringParam p_param, real_t p_value)=0; virtual real_t damped_string_joint_get_param(RID p_joint, DampedStringParam p_param) const=0; - virtual JointType joint_get_type(RID p_joint) const=0; + virtual JointType joint_get_type(RID p_joint) const=0; #endif /* QUERY API */ diff --git a/servers/spatial_sound/spatial_sound_server_sw.cpp b/servers/spatial_sound/spatial_sound_server_sw.cpp index 1ce56a5cdd..d87d05dc4d 100644 --- a/servers/spatial_sound/spatial_sound_server_sw.cpp +++ b/servers/spatial_sound/spatial_sound_server_sw.cpp @@ -323,7 +323,7 @@ RID SpatialSoundServerSW::source_create(RID p_space) { void SpatialSoundServerSW::source_set_polyphony(RID p_source,int p_voice_count) { - + ERR_FAIL_COND(p_voice_count<=0); // more than 32 is too much, change this if you really need more if (p_voice_count>32) { @@ -378,8 +378,8 @@ float SpatialSoundServerSW::source_get_param(RID p_source, SourceParam p_param) Source *source = source_owner.get(p_source); ERR_FAIL_COND_V(!source,0); return source->params[p_param]; - - + + } void SpatialSoundServerSW::source_set_audio_stream(RID p_source, AudioServer::AudioStream *p_stream) { @@ -542,7 +542,7 @@ void SpatialSoundServerSW::free(RID p_id) { if (space_owner.owns(p_id)) { - Space *space = space_owner.get(p_id); + Space *space = space_owner.get(p_id); free(space->default_room); while(space->listeners.size()) { diff --git a/servers/spatial_sound/spatial_sound_server_sw.h b/servers/spatial_sound/spatial_sound_server_sw.h index 8a4dabdc3e..a8ae7beb59 100644 --- a/servers/spatial_sound/spatial_sound_server_sw.h +++ b/servers/spatial_sound/spatial_sound_server_sw.h @@ -154,7 +154,7 @@ class SpatialSoundServerSW : public SpatialSoundServer { }; mutable RID_Owner<Listener> listener_owner; - + struct ActiveVoice { Source *source; diff --git a/servers/visual/particle_system_sw.cpp b/servers/visual/particle_system_sw.cpp index 00c06b9e3c..07cc6d8a2a 100644 --- a/servers/visual/particle_system_sw.cpp +++ b/servers/visual/particle_system_sw.cpp @@ -34,11 +34,11 @@ ParticleSystemSW::ParticleSystemSW() { amount=8; emitting=true; - + for (int i=0;i<VS::PARTICLE_VAR_MAX;i++) { particle_randomness[i]=0.0; } - + particle_vars[VS::PARTICLE_LIFETIME]=2.0;// particle_vars[VS::PARTICLE_SPREAD]=0.2;// particle_vars[VS::PARTICLE_GRAVITY]=9.8;// @@ -89,7 +89,7 @@ _FORCE_INLINE_ static float _rand_from_seed(uint32_t *seed) { if (s < 0) s += 2147483647; (*seed) = s; - + float v=((float)((*seed) & 0xFFFFF))/(float)0xFFFFF; v=v*2.0-1.0; return v; @@ -144,10 +144,10 @@ void ParticleSystemProcessSW::process(const ParticleSystemSW *p_system,const Tra } float next_time = particle_system_time+p_time; - + if (next_time > lifetime) next_time=Math::fmod(next_time,lifetime); - + ParticleData *pdata=&particle_data[0]; Vector3 attractor_positions[VS::MAX_PARTICLE_ATTRACTORS]; @@ -159,13 +159,13 @@ void ParticleSystemProcessSW::process(const ParticleSystemSW *p_system,const Tra for(int i=0;i<particle_count;i++) { - + ParticleData &p=pdata[i]; - + float restart_time = (i * lifetime / p_system->amount); - + bool restart=false; - + if ( next_time < particle_system_time ) { if (restart_time > particle_system_time || restart_time < next_time ) @@ -191,11 +191,11 @@ void ParticleSystemProcessSW::process(const ParticleSystemSW *p_system,const Tra else p.pos = p_transform.xform( r[_irand_from_seed(&rand_seed)%emission_point_count] ); } - - + + float angle1 = _rand_from_seed(&rand_seed)*p_system->particle_vars[VS::PARTICLE_SPREAD]*Math_PI; float angle2 = _rand_from_seed(&rand_seed)*20.0*Math_PI; // make it more random like - + Vector3 rot_xz=Vector3( Math::sin(angle1), 0.0, Math::cos(angle1) ); Vector3 rot = Vector3( Math::cos(angle2)*rot_xz.x,Math::sin(angle2)*rot_xz.x, rot_xz.z); @@ -204,22 +204,22 @@ void ParticleSystemProcessSW::process(const ParticleSystemSW *p_system,const Tra p.vel=p_transform.basis.xform( p.vel ); p.vel+=p_system->emission_base_velocity; - - p.rot=p_system->particle_vars[VS::PARTICLE_INITIAL_ANGLE]+p_system->particle_randomness[VS::PARTICLE_INITIAL_ANGLE]*_rand_from_seed(&rand_seed); + + p.rot=p_system->particle_vars[VS::PARTICLE_INITIAL_ANGLE]+p_system->particle_randomness[VS::PARTICLE_INITIAL_ANGLE]*_rand_from_seed(&rand_seed); p.active=true; for(int r=0;r<PARTICLE_RANDOM_NUMBERS;r++) p.random[r]=_rand_from_seed(&rand_seed); } else { - + p.pos=Vector3(); p.rot=0; p.vel=Vector3(); p.active=false; } - + } else { - + if (!p.active) continue; diff --git a/servers/visual/particle_system_sw.h b/servers/visual/particle_system_sw.h index 9a176ba0d4..4edcecaaa9 100644 --- a/servers/visual/particle_system_sw.h +++ b/servers/visual/particle_system_sw.h @@ -37,13 +37,13 @@ struct ParticleSystemSW { enum { - + MAX_PARTICLES=1024 }; float particle_vars[VS::PARTICLE_VAR_MAX]; float particle_randomness[VS::PARTICLE_VAR_MAX]; - + Vector3 emission_half_extents; DVector<Vector3> emission_points; Vector3 gravity_normal; @@ -54,14 +54,14 @@ struct ParticleSystemSW { AABB visibility_aabb; bool sort; bool local_coordinates; - + struct ColorPhase { - + float pos; Color color; ColorPhase() { pos=1.0; color=Color(0.0,0.0,1.0,1.0); } }; - + int color_phase_count; ColorPhase color_phases[VS::MAX_PARTICLE_COLOR_PHASES]; @@ -71,12 +71,12 @@ struct ParticleSystemSW { Vector3 pos; float force; }; - + int attractor_count; Attractor attractors[VS::MAX_PARTICLE_ATTRACTORS]; - ParticleSystemSW(); + ParticleSystemSW(); ~ParticleSystemSW(); }; @@ -89,7 +89,7 @@ struct ParticleSystemProcessSW { }; struct ParticleData { - + Vector3 pos; Vector3 vel; float rot; @@ -102,7 +102,7 @@ struct ParticleSystemProcessSW { bool valid; float particle_system_time; - uint32_t rand_seed; + uint32_t rand_seed; Vector<ParticleData> particle_data; void process(const ParticleSystemSW *p_system,const Transform& p_transform,float p_time); diff --git a/servers/visual/rasterizer.cpp b/servers/visual/rasterizer.cpp index 26eca478fd..32f5b80e55 100644 --- a/servers/visual/rasterizer.cpp +++ b/servers/visual/rasterizer.cpp @@ -370,7 +370,7 @@ RID Rasterizer::fixed_material_create() { material_set_param(mat,_fixed_material_param_names[i],fm.param[i]); //must be there } fixed_material_dirty_list.add(&fm.dirty_list); - //print_line("FMC: "+itos(mat.get_id())); + //print_line("FMC: "+itos(mat.get_id())); return mat; } diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 345c8bb32e..276758ea95 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -178,7 +178,7 @@ public: /* TEXTURE API */ virtual RID texture_create()=0; - RID texture_create_from_image(const Image& p_image,uint32_t p_flags=VS::TEXTURE_FLAGS_DEFAULT); // helper + RID texture_create_from_image(const Image& p_image,uint32_t p_flags=VS::TEXTURE_FLAGS_DEFAULT); // helper virtual void texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags=VS::TEXTURE_FLAGS_DEFAULT)=0; virtual void texture_set_data(RID p_texture,const Image& p_image,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT)=0; virtual Image texture_get_data(RID p_texture,VS::CubeMapSide p_cube_side=VS::CUBEMAP_LEFT) const=0; @@ -263,10 +263,10 @@ public: virtual void fixed_material_set_point_size(RID p_material,float p_size); virtual float fixed_material_get_point_size(RID p_material) const; - /* MESH API */ - + /* MESH API */ + virtual RID mesh_create()=0; - + virtual void mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alpha_sort=false)=0; virtual Array mesh_get_surface_arrays(RID p_mesh,int p_surface) const=0; @@ -287,10 +287,10 @@ public: virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const=0; virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const=0; virtual VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const=0; - + virtual void mesh_remove_surface(RID p_mesh,int p_index)=0; virtual int mesh_get_surface_count(RID p_mesh) const=0; - + virtual AABB mesh_get_aabb(RID p_mesh,RID p_skeleton=RID()) const=0; virtual void mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb)=0; @@ -338,23 +338,23 @@ public: virtual void immediate_set_material(RID p_immediate,RID p_material)=0; virtual RID immediate_get_material(RID p_immediate) const=0; - + /* PARTICLES API */ - + virtual RID particles_create()=0; - + virtual void particles_set_amount(RID p_particles, int p_amount)=0; virtual int particles_get_amount(RID p_particles) const=0; - + virtual void particles_set_emitting(RID p_particles, bool p_emitting)=0; virtual bool particles_is_emitting(RID p_particles) const=0; - + virtual void particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility)=0; virtual AABB particles_get_visibility_aabb(RID p_particles) const=0; - + virtual void particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents)=0; virtual Vector3 particles_get_emission_half_extents(RID p_particles) const=0; - + virtual void particles_set_emission_base_velocity(RID p_particles, const Vector3& p_base_velocity)=0; virtual Vector3 particles_get_emission_base_velocity(RID p_particles) const=0; @@ -363,22 +363,22 @@ public: virtual void particles_set_gravity_normal(RID p_particles, const Vector3& p_normal)=0; virtual Vector3 particles_get_gravity_normal(RID p_particles) const=0; - + virtual void particles_set_variable(RID p_particles, VS::ParticleVariable p_variable,float p_value)=0; virtual float particles_get_variable(RID p_particles, VS::ParticleVariable p_variable) const=0; - + virtual void particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable,float p_randomness)=0; virtual float particles_get_randomness(RID p_particles, VS::ParticleVariable p_variable) const=0; - + virtual void particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos)=0; virtual float particles_get_color_phase_pos(RID p_particles, int p_phase) const=0; - + virtual void particles_set_color_phases(RID p_particles, int p_phases)=0; virtual int particles_get_color_phases(RID p_particles) const=0; virtual void particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color)=0; virtual Color particles_get_color_phase_color(RID p_particles, int p_phase) const=0; - + virtual void particles_set_attractors(RID p_particles, int p_attractors)=0; virtual int particles_get_attractors(RID p_particles) const=0; @@ -390,7 +390,7 @@ public: virtual void particles_set_material(RID p_particles, RID p_material,bool p_owned=false)=0; virtual RID particles_get_material(RID p_particles) const=0; - + virtual AABB particles_get_aabb(RID p_particles) const=0; virtual void particles_set_height_from_velocity(RID p_particles, bool p_enable)=0; @@ -400,31 +400,31 @@ public: virtual bool particles_is_using_local_coordinates(RID p_particles) const=0; /* SKELETON API */ - + virtual RID skeleton_create()=0; virtual void skeleton_resize(RID p_skeleton,int p_bones)=0; virtual int skeleton_get_bone_count(RID p_skeleton) const=0; virtual void skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform)=0; virtual Transform skeleton_bone_get_transform(RID p_skeleton,int p_bone)=0; - + /* LIGHT API */ - + virtual RID light_create(VS::LightType p_type)=0; virtual VS::LightType light_get_type(RID p_light) const=0; virtual void light_set_color(RID p_light,VS::LightColor p_type, const Color& p_color)=0; - virtual Color light_get_color(RID p_light,VS::LightColor p_type) const=0; - + virtual Color light_get_color(RID p_light,VS::LightColor p_type) const=0; + virtual void light_set_shadow(RID p_light,bool p_enabled)=0; - virtual bool light_has_shadow(RID p_light) const=0; - + virtual bool light_has_shadow(RID p_light) const=0; + virtual void light_set_volumetric(RID p_light,bool p_enabled)=0; - virtual bool light_is_volumetric(RID p_light) const=0; - + virtual bool light_is_volumetric(RID p_light) const=0; + virtual void light_set_projector(RID p_light,RID p_texture)=0; virtual RID light_get_projector(RID p_light) const=0; - + virtual void light_set_var(RID p_light, VS::LightParam p_var, float p_value)=0; virtual float light_get_var(RID p_light, VS::LightParam p_var) const=0; @@ -440,10 +440,10 @@ public: virtual float light_directional_get_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param) const=0; virtual AABB light_get_aabb(RID p_poly) const=0; - + virtual RID light_instance_create(RID p_light)=0; - virtual void light_instance_set_transform(RID p_light_instance,const Transform& p_transform)=0; - + virtual void light_instance_set_transform(RID p_light_instance,const Transform& p_transform)=0; + enum ShadowType { SHADOW_NONE, @@ -454,7 +454,7 @@ public: SHADOW_PSSM, //parallel split shadow map SHADOW_PSM //perspective shadow map }; - + enum ShadowPass { PASS_DUAL_PARABOLOID_FRONT=0, PASS_DUAL_PARABOLOID_BACK=1, @@ -463,7 +463,7 @@ public: PASS_CUBE_TOP=2, PASS_CUBE_BOTTOM=3, PASS_CUBE_LEFT=4, - PASS_CUBE_RIGHT=5, + PASS_CUBE_RIGHT=5, }; virtual ShadowType light_instance_get_shadow_type(RID p_light_instance,bool p_far=false) const=0; @@ -479,13 +479,13 @@ public: virtual bool shadow_allocate_far(RID p_light)=0; //true on successful alloc /* PARTICLES INSTANCE */ - + virtual RID particles_instance_create(RID p_particles)=0; virtual void particles_instance_set_transform(RID p_particles_instance,const Transform& p_transform)=0; - + /* RENDER API */ /* all calls (inside begin/end shadow) are always warranted to be in the following order: */ - + /* VIEWPORT API */ virtual RID viewport_data_create()=0; @@ -496,19 +496,19 @@ public: virtual bool render_target_renedered_in_frame(RID p_render_target)=0; virtual void begin_frame()=0; - + virtual void set_viewport(const VS::ViewportRect& p_viewport)=0; virtual void set_render_target(RID p_render_target,bool p_transparent_bg=false,bool p_vflip=false)=0; virtual void clear_viewport(const Color& p_color)=0; virtual void capture_viewport(Image* r_capture)=0; - + virtual void begin_scene(RID p_viewport_data,RID p_env,VS::ScenarioDebugMode p_debug)=0; virtual void begin_shadow_map( RID p_light_instance, int p_shadow_pass )=0; virtual void set_camera(const Transform& p_world,const CameraMatrix& p_projection,bool p_ortho_hint)=0; - + virtual void add_light( RID p_light_instance )=0; ///< all "add_light" calls happen before add_geometry calls - + typedef Map<StringName,Variant> ParamOverrideMap; struct BakedLightData { @@ -557,10 +557,10 @@ public: virtual void end_scene()=0; virtual void end_shadow_map()=0; - + virtual void end_frame()=0; virtual void flush_frame(); //not necesary in most cases - + /* CANVAS API */ enum CanvasRectFlags { @@ -614,7 +614,7 @@ public: CanvasLight *mask_next_ptr; CanvasLight() { - enabled=true; + enabled=true; color=Color(1,1,1); shadow_color=Color(0,0,0,0); height=0; @@ -979,7 +979,7 @@ public: virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache)=0; /* ENVIRONMENT */ - + virtual RID environment_create()=0; @@ -999,9 +999,9 @@ public: virtual RID sampled_light_dp_create(int p_width,int p_height)=0; virtual void sampled_light_dp_update(RID p_sampled_light,const Color *p_data,float p_multiplier)=0; - + /*MISC*/ - + virtual bool is_texture(const RID& p_rid) const=0; virtual bool is_material(const RID& p_rid) const=0; virtual bool is_mesh(const RID& p_rid) const=0; diff --git a/servers/visual/shader_graph.cpp b/servers/visual/shader_graph.cpp index 07bbf9f7b4..7fe949bec3 100644 --- a/servers/visual/shader_graph.cpp +++ b/servers/visual/shader_graph.cpp @@ -34,78 +34,78 @@ struct _ConnectionKey { int node; - int slot; - + int slot; + _FORCE_INLINE_ _ConnectionKey(int p_node=0,int p_slot=0) { node=p_node; slot=p_slot; } - + _FORCE_INLINE_ bool operator<(const _ConnectionKey& p_other) const { - + if (node<p_other.node) return true; else if (node>p_other.node) - return false; + return false; else return slot<p_other.slot; } }; Error ShaderGraph::generate(ShaderCodeGenerator * p_generator) const { - + Map<int,Node>::Element *E = node_map.front(); - int i=0; + int i=0; while(E) { - + E->get().order=i++; E->get().out_valid=false; E->get().in_valid=false; E=E->next(); - } + } int worst_case=connections.size() * connections.size(); // worst bubble case int iterations=0; int swaps; - - do { + + do { swaps=0; const List<Connection>::Element *E=connections.front(); while(E) { const Connection &c = E->get(); - + const Node *src = &node_map[c.src_id]; const Node *dst = &node_map[c.dst_id]; - + if (src->order > dst->order) { - + SWAP(src->order, dst->order); swaps++; } - + E=E->next(); } - - + + iterations++; - + } while (iterations<=worst_case && swaps>0); - + ERR_FAIL_COND_V( swaps != 0 , ERR_CYCLIC_LINK ); - + //node array Vector<const Node*> nodes; nodes.resize(node_map.size()); - + E = node_map.front(); while(E) { - + ERR_FAIL_INDEX_V( E->get().order, nodes.size(), ERR_BUG); nodes[E->get().order]=&E->get(); E=E->next(); } - + //connection set - + Map<_ConnectionKey,int> in_connection_map; Map<_ConnectionKey,List<int> > out_connection_map; Map<_ConnectionKey,int> in_node_map; @@ -115,7 +115,7 @@ Error ShaderGraph::generate(ShaderCodeGenerator * p_generator) const { i=0; while(CE) { const Connection &c = CE->get(); - + _ConnectionKey in_k; in_k.node=node_map[c.dst_id].order; in_k.slot=c.dst_slot; @@ -131,11 +131,11 @@ Error ShaderGraph::generate(ShaderCodeGenerator * p_generator) const { if(!out_node_map.has(out_k)) out_node_map[out_k]=List<int>(); out_node_map[out_k].push_back(node_map[c.dst_id].order); - + i++; CE=CE->next(); } - + // validate nodes if they are connected to an output for(int i=nodes.size()-1;i>=0;i--) { @@ -231,9 +231,9 @@ Error ShaderGraph::generate(ShaderCodeGenerator * p_generator) const { } // write code - + p_generator->begin(); - + for(int i=0;i<nodes.size();i++) { @@ -244,35 +244,35 @@ Error ShaderGraph::generate(ShaderCodeGenerator * p_generator) const { in_indices.resize(VS::shader_get_input_count(nodes[i]->type)); Vector<int> out_indices; Vector<int> out_slot_indices; - + for(int j=0;j<in_indices.size();j++) { - + _ConnectionKey key(nodes[i]->order,j); if (in_connection_map.has(key)) in_indices[j]=in_connection_map[key]; else - in_indices[j]=-1; + in_indices[j]=-1; } - + for(int j=0;j<VS::shader_get_output_count(nodes[i]->type);j++) { - + _ConnectionKey key(nodes[i]->order,j); if (out_connection_map.has(key)) { for(List<int>::Element *CE=out_connection_map[key].front();CE;CE=CE->next()) { - + out_indices.push_back(CE->get()); out_slot_indices.push_back(j); } } } - + Error err = p_generator->add_node(nodes[i]->type,i,nodes[i]->id,nodes[i]->param,in_indices,out_indices,out_slot_indices); ERR_FAIL_COND_V( err, err ); } - + p_generator->end(); - - + + return OK; } @@ -282,7 +282,7 @@ void ShaderGraph::node_add(VS::ShaderNodeType p_type,int p_id) { ERR_FAIL_COND( node_map.has(p_id ) ); ERR_FAIL_INDEX( p_type, VS::NODE_TYPE_MAX ); Node node; - + node.type=p_type; node.id=p_id; node.x=0; @@ -312,14 +312,14 @@ int ShaderGraph::node_get_pos_y(int p_id) const { void ShaderGraph::node_remove(int p_id) { ERR_FAIL_COND(!node_map.has(p_id)); - + //erase connections associated with node List<Connection>::Element *N,*E=connections.front(); while(E) { N=E->next(); const Connection &c = E->get(); if (c.src_id==p_id || c.dst_id==p_id) { - + connections.erase(E); } E=N; @@ -337,17 +337,17 @@ void ShaderGraph::node_change_type(int p_id, VS::ShaderNodeType p_type) { } void ShaderGraph::node_set_param(int p_id, const Variant& p_value) { - + ERR_FAIL_COND(!node_map.has(p_id)); - node_map[p_id].param=p_value; + node_map[p_id].param=p_value; } void ShaderGraph::get_node_list(List<int> *p_node_list) const { Map<int,Node>::Element *E = node_map.front(); - + while(E) { - + p_node_list->push_back(E->key()); E=E->next(); } @@ -363,7 +363,7 @@ VS::ShaderNodeType ShaderGraph::node_get_type(int p_id) const { Variant ShaderGraph::node_get_param(int p_id) const { ERR_FAIL_COND_V(!node_map.has(p_id),Variant()); - return node_map[p_id].param; + return node_map[p_id].param; } @@ -383,16 +383,16 @@ Error ShaderGraph::connect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_s while(E) { const Connection &c = E->get(); ERR_FAIL_COND_V(c.dst_slot==p_dst_slot && c.dst_id == p_dst_id, ERR_ALREADY_EXISTS); - + E=E->next(); } - + Connection c; c.src_slot=p_src_slot; c.src_id=p_src_id; c.dst_slot=p_dst_slot; c.dst_id=p_dst_id; - + connections.push_back(c); return OK; @@ -419,12 +419,12 @@ void ShaderGraph::disconnect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst N=E->next(); const Connection &c = E->get(); if (c.src_slot==p_src_slot && c.src_id==p_src_id && c.dst_slot==p_dst_slot && c.dst_id == p_dst_id) { - + connections.erase(E); } E=N; } - + } diff --git a/servers/visual/shader_graph.h b/servers/visual/shader_graph.h index 07e4bb3540..41df0f60f1 100644 --- a/servers/visual/shader_graph.h +++ b/servers/visual/shader_graph.h @@ -43,7 +43,7 @@ public: virtual void begin()=0; virtual Error add_node(VS::ShaderNodeType p_type,int p_node_pos,int p_id,const Variant& p_param,const Vector<int>& p_in_connections,const Vector<int>& p_out_connections,const Vector<int>& p_out_connection_outputs)=0; virtual void end()=0; - + virtual ~ShaderCodeGenerator() {} }; @@ -61,7 +61,7 @@ public: private: struct Node { - + int16_t x,y; VS::ShaderNodeType type; Variant param; @@ -74,7 +74,7 @@ private: Map<int,Node> node_map; List<Connection> connections; - + public: Error generate(ShaderCodeGenerator * p_generator) const; @@ -87,7 +87,7 @@ public: void node_set_pos(int p_id, int p_x,int p_y); int node_get_pos_x(int p_id) const; int node_get_pos_y(int p_id) const; - + void get_node_list(List<int> *p_node_list) const; void get_sorted_node_list(List<int> *p_node_list) const; VS::ShaderNodeType node_get_type(int p_id) const; @@ -95,14 +95,14 @@ public: Error connect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot); bool is_connected(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const; - void disconnect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot); + void disconnect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot); void clear(); List<Connection> get_connection_list() const; - ShaderGraph(); + ShaderGraph(); ~ShaderGraph(); }; diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index d0e8bfccd6..0b2a282c04 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -607,7 +607,7 @@ bool ShaderLanguage::test_existing_identifier(Node *p_node,const StringName p_id return true; } else if (node->type==Node::TYPE_PROGRAM) { - ProgramNode *program = (ProgramNode*)node; + ProgramNode *program = (ProgramNode*)node; for(int i=0;i<program->functions.size();i++) { if (program->functions[i].name==p_identifier) { @@ -1138,7 +1138,7 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_vertex_builtins_defs[]={ //builtins { "WORLD_MATRIX", TYPE_MAT4}, { "PROJECTION_MATRIX", TYPE_MAT4}, - { "EXTRA_MATRIX", TYPE_MAT4}, + { "EXTRA_MATRIX", TYPE_MAT4}, { "TIME", TYPE_FLOAT}, { NULL, TYPE_VOID}, }; diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index ec468b5e04..c9695b7859 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -45,7 +45,7 @@ BalloonAllocator<> *VisualServerRaster::OctreeAllocator::allocator=NULL; RID VisualServerRaster::texture_create() { - + return rasterizer->texture_create(); } @@ -340,7 +340,7 @@ VisualServerRaster::FixedMaterialLightShader VisualServerRaster::fixed_material_ -/* MESH API */ +/* MESH API */ RID VisualServerRaster::mesh_create() { @@ -625,14 +625,14 @@ RID VisualServerRaster::particles_create() { void VisualServerRaster::particles_set_amount(RID p_particles, int p_amount) { VS_CHANGED; - rasterizer->particles_set_amount(p_particles,p_amount); + rasterizer->particles_set_amount(p_particles,p_amount); } int VisualServerRaster::particles_get_amount(RID p_particles) const { return rasterizer->particles_get_amount(p_particles); } - + void VisualServerRaster::particles_set_emitting(RID p_particles, bool p_emitting) { VS_CHANGED; rasterizer->particles_set_emitting(p_particles,p_emitting); @@ -641,7 +641,7 @@ bool VisualServerRaster::particles_is_emitting(RID p_particles) const { return rasterizer->particles_is_emitting(p_particles); } - + void VisualServerRaster::particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility) { VS_CHANGED; rasterizer->particles_set_visibility_aabb(p_particles, p_visibility); @@ -650,7 +650,7 @@ AABB VisualServerRaster::particles_get_visibility_aabb(RID p_particles) const { return rasterizer->particles_get_visibility_aabb(p_particles); } - + void VisualServerRaster::particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents) { VS_CHANGED; rasterizer->particles_set_emission_half_extents(p_particles,p_half_extents); @@ -688,7 +688,7 @@ Vector3 VisualServerRaster::particles_get_gravity_normal(RID p_particles) const return rasterizer->particles_get_gravity_normal(p_particles); } - + void VisualServerRaster::particles_set_variable(RID p_particles, ParticleVariable p_variable,float p_value) { VS_CHANGED; rasterizer->particles_set_variable(p_particles,p_variable,p_value); @@ -770,7 +770,7 @@ RID VisualServerRaster::particles_get_material(RID p_particles) const { return rasterizer->particles_get_material(p_particles); } - + void VisualServerRaster::particles_set_height_from_velocity(RID p_particles, bool p_enable) { @@ -812,33 +812,33 @@ void VisualServerRaster::light_set_color(RID p_light,LightColor p_type, const Co } Color VisualServerRaster::light_get_color(RID p_light,LightColor p_type) const { - + return rasterizer->light_get_color(p_light,p_type); - + } void VisualServerRaster::light_set_shadow(RID p_light,bool p_enabled) { VS_CHANGED; - rasterizer->light_set_shadow(p_light,p_enabled); + rasterizer->light_set_shadow(p_light,p_enabled); } bool VisualServerRaster::light_has_shadow(RID p_light) const { return rasterizer->light_has_shadow(p_light); -} +} void VisualServerRaster::light_set_volumetric(RID p_light,bool p_enabled) { VS_CHANGED; - rasterizer->light_set_volumetric(p_light,p_enabled); + rasterizer->light_set_volumetric(p_light,p_enabled); } bool VisualServerRaster::light_is_volumetric(RID p_light) const { return rasterizer->light_is_volumetric(p_light); -} +} void VisualServerRaster::light_set_projector(RID p_light,RID p_texture) { VS_CHANGED; @@ -854,13 +854,13 @@ void VisualServerRaster::light_set_param(RID p_light, LightParam p_var, float p_ VS_CHANGED; rasterizer->light_set_var(p_light,p_var,p_value); _dependency_queue_update(p_light,true); - + } float VisualServerRaster::light_get_param(RID p_light, LightParam p_var) const { - - return rasterizer->light_get_var(p_light,p_var); + + return rasterizer->light_get_var(p_light,p_var); } void VisualServerRaster::light_set_operator(RID p_light,LightOp p_op) { @@ -940,7 +940,7 @@ Transform VisualServerRaster::skeleton_bone_get_transform(RID p_skeleton,int p_b return rasterizer->skeleton_bone_get_transform(p_skeleton,p_bone); } - + /* VISIBILITY API */ @@ -970,7 +970,7 @@ BSP_Tree VisualServerRaster::room_get_bounds(RID p_room) const { return room->bounds; } - + /* PORTAL API */ RID VisualServerRaster::portal_create() { @@ -1422,7 +1422,7 @@ void VisualServerRaster::camera_set_perspective(RID p_camera,float p_fovy_degree camera->fov=p_fovy_degrees; camera->znear=p_z_near; camera->zfar=p_z_far; - + } void VisualServerRaster::camera_set_orthogonal(RID p_camera,float p_size, float p_z_near, float p_z_far) { @@ -1440,7 +1440,7 @@ void VisualServerRaster::camera_set_transform(RID p_camera,const Transform& p_tr Camera *camera = camera_owner.get( p_camera ); ERR_FAIL_COND(!camera); camera->transform=p_transform.orthonormalized(); - + } @@ -1502,7 +1502,7 @@ RID VisualServerRaster::viewport_create() { Viewport *viewport = memnew( Viewport ); RID rid = viewport_owner.make_rid( viewport ); ERR_FAIL_COND_V( !rid.is_valid(), rid ); - + viewport->self=rid; viewport->hide_scenario=false; viewport->hide_canvas=false; @@ -1670,7 +1670,7 @@ void VisualServerRaster::viewport_set_rect(RID p_viewport,const ViewportRect& p_ viewport = viewport_owner.get( p_viewport ); ERR_FAIL_COND(!viewport); - + viewport->rect=p_rect; if (viewport->render_target.is_valid()) { rasterizer->render_target_set_size(viewport->render_target,viewport->rect.width,viewport->rect.height); @@ -1684,7 +1684,7 @@ VisualServer::ViewportRect VisualServerRaster::viewport_get_rect(RID p_viewport) viewport = viewport_owner.get( p_viewport ); ERR_FAIL_COND_V(!viewport, ViewportRect()); - + return viewport->rect; } @@ -1736,11 +1736,11 @@ void VisualServerRaster::viewport_attach_camera(RID p_viewport,RID p_camera) { - + if (p_camera.is_valid()) { ERR_FAIL_COND(!camera_owner.owns(p_camera)); - // a camera + // a camera viewport->camera=p_camera; } else { viewport->camera=RID(); @@ -1773,7 +1773,7 @@ RID VisualServerRaster::viewport_get_attached_camera(RID p_viewport) const { viewport = viewport_owner.get( p_viewport ); ERR_FAIL_COND_V(!viewport, RID()); - + return viewport->camera; } @@ -1862,7 +1862,7 @@ void VisualServerRaster::viewport_remove_canvas(RID p_viewport,RID p_canvas) { viewport = viewport_owner.get( p_viewport ); ERR_FAIL_COND(!viewport); - Canvas *canvas = canvas_owner.get( p_canvas ); + Canvas *canvas = canvas_owner.get( p_canvas ); ERR_FAIL_COND(!canvas); @@ -1894,7 +1894,7 @@ void VisualServerRaster::viewport_set_canvas_layer(RID p_viewport,RID p_canvas,i } E->get().layer=p_layer; - + } void VisualServerRaster::viewport_set_transparent_background(RID p_viewport,bool p_enabled) { @@ -1916,13 +1916,13 @@ bool VisualServerRaster::viewport_has_transparent_background(RID p_viewport) con RID VisualServerRaster::viewport_get_scenario(RID p_viewport) const { - + const Viewport *viewport=NULL; viewport = viewport_owner.get( p_viewport ); ERR_FAIL_COND_V(!viewport, RID()); - - return viewport->scenario; + + return viewport->scenario; } @@ -1976,38 +1976,38 @@ Variant VisualServerRaster::environment_fx_get_param(RID p_env,EnvironmentFxPara void VisualServerRaster::_dependency_queue_update(RID p_rid,bool p_update_aabb) { Map< RID, Set<RID> >::Element * E = instance_dependency_map.find( p_rid ); - + if (!E) return; - - + + Set<RID>::Element *I = E->get().front(); - + while(I) { - + Instance *ins = instance_owner.get( I->get() ); _instance_queue_update( ins , p_update_aabb ); - + I = I->next(); } - + } void VisualServerRaster::_instance_queue_update(Instance *p_instance,bool p_update_aabb) { if (p_update_aabb) p_instance->update_aabb=true; - + if (p_instance->update) return; p_instance->update_next=instance_update_list; instance_update_list=p_instance; p_instance->update=true; - + } RID VisualServerRaster::scenario_create() { - + Scenario *scenario = memnew( Scenario ); ERR_FAIL_COND_V(!scenario,RID()); RID scenario_rid = scenario_owner.make_rid( scenario ); @@ -2449,10 +2449,10 @@ void VisualServerRaster::instance_set_transform(RID p_instance, const Transform& VS_CHANGED; Instance *instance = instance_owner.get( p_instance ); ERR_FAIL_COND( !instance ); - + if (p_transform==instance->data.transform) // must improve somehow return; - + instance->data.transform=p_transform; if (instance->base_type==INSTANCE_LIGHT) instance->data.transform.orthonormalize(); @@ -2464,7 +2464,7 @@ Transform VisualServerRaster::instance_get_transform(RID p_instance) const { Instance *instance = instance_owner.get( p_instance ); ERR_FAIL_COND_V( !instance, Transform() ); - + return instance->data.transform; } @@ -2574,7 +2574,7 @@ void VisualServerRaster::instance_set_room( RID p_instance, RID p_room ) { ERR_EXPLAIN("Cycle in room assignment"); ERR_FAIL_COND( parent == room ); parent=parent->room; - } + } } if ( (1<<instance->base_type) & INSTANCE_GEOMETRY_MASK ) { @@ -2634,45 +2634,45 @@ real_t VisualServerRaster::instance_get_extra_visibility_margin( RID p_instance Vector<RID> VisualServerRaster::instances_cull_aabb(const AABB& p_aabb, RID p_scenario) const { - + Vector<RID> instances; Scenario *scenario=scenario_owner.get(p_scenario); - ERR_FAIL_COND_V(!scenario,instances); - + ERR_FAIL_COND_V(!scenario,instances); + const_cast<VisualServerRaster*>(this)->_update_instances(); // check dirty instances before culling - + int culled=0; Instance *cull[1024]; culled=scenario->octree.cull_AABB(p_aabb,cull,1024); - + for (int i=0;i<culled;i++) { - + Instance *instance=cull[i]; ERR_CONTINUE(!instance); instances.push_back(instance->self); } - + return instances; } Vector<RID> VisualServerRaster::instances_cull_ray(const Vector3& p_from, const Vector3& p_to, RID p_scenario) const{ Vector<RID> instances; Scenario *scenario=scenario_owner.get(p_scenario); - ERR_FAIL_COND_V(!scenario,instances); + ERR_FAIL_COND_V(!scenario,instances); const_cast<VisualServerRaster*>(this)->_update_instances(); // check dirty instances before culling - + int culled=0; - Instance *cull[1024]; + Instance *cull[1024]; culled=scenario->octree.cull_segment(p_from,p_to*10000,cull,1024); for (int i=0;i<culled;i++) { - + Instance *instance=cull[i]; ERR_CONTINUE(!instance); instances.push_back(instance->self); } - + return instances; } @@ -2680,22 +2680,22 @@ Vector<RID> VisualServerRaster::instances_cull_convex(const Vector<Plane>& p_con Vector<RID> instances; Scenario *scenario=scenario_owner.get(p_scenario); - ERR_FAIL_COND_V(!scenario,instances); + ERR_FAIL_COND_V(!scenario,instances); const_cast<VisualServerRaster*>(this)->_update_instances(); // check dirty instances before culling - + int culled=0; - Instance *cull[1024]; - + Instance *cull[1024]; + culled=scenario->octree.cull_convex(p_convex,cull,1024); - + for (int i=0;i<culled;i++) { - + Instance *instance=cull[i]; - ERR_CONTINUE(!instance); + ERR_CONTINUE(!instance); instances.push_back(instance->self); } - + return instances; } @@ -2976,9 +2976,9 @@ void VisualServerRaster::_update_instance(Instance *p_instance) { p_instance->version++; if (p_instance->base_type == INSTANCE_LIGHT) { - + rasterizer->light_instance_set_transform( p_instance->light_info->instance, p_instance->data.transform ); - + } if (p_instance->aabb.has_no_surface()) @@ -2986,10 +2986,10 @@ void VisualServerRaster::_update_instance(Instance *p_instance) { if (p_instance->base_type == INSTANCE_PARTICLES) { - + rasterizer->particles_instance_set_transform( p_instance->particles_info->instance, p_instance->data.transform ); } - + if ((1<<p_instance->base_type)&INSTANCE_GEOMETRY_MASK) { @@ -3041,7 +3041,7 @@ void VisualServerRaster::_update_instance(Instance *p_instance) { else portal_aabb.expand_to(point); } - + portal_aabb.grow_by(p_instance->portal_info->portal->connect_range); new_aabb = portal_aabb; @@ -3117,7 +3117,7 @@ void VisualServerRaster::_update_instance(Instance *p_instance) { } if (p_instance->base_type==INSTANCE_PORTAL) { - + _portal_attempt_connect(p_instance); } @@ -3138,18 +3138,18 @@ void VisualServerRaster::_update_instance(Instance *p_instance) { void VisualServerRaster::_update_instance_aabb(Instance *p_instance) { AABB new_aabb; - + ERR_FAIL_COND(p_instance->base_type!=INSTANCE_NONE && !p_instance->base_rid.is_valid()); - + switch(p_instance->base_type) { case VisualServer::INSTANCE_NONE: { // do nothing } break; case VisualServer::INSTANCE_MESH: { - + new_aabb = rasterizer->mesh_get_aabb(p_instance->base_rid,p_instance->data.skeleton); - + } break; case VisualServer::INSTANCE_MULTIMESH: { @@ -3163,41 +3163,41 @@ void VisualServerRaster::_update_instance_aabb(Instance *p_instance) { } break; case VisualServer::INSTANCE_PARTICLES: { - + new_aabb = rasterizer->particles_get_aabb(p_instance->base_rid); - + } break; case VisualServer::INSTANCE_LIGHT: { - + new_aabb = rasterizer->light_get_aabb(p_instance->base_rid); - + } break; case VisualServer::INSTANCE_ROOM: { - + Room *room = room_owner.get( p_instance->base_rid ); ERR_FAIL_COND(!room); new_aabb=room->bounds.get_aabb(); - + } break; case VisualServer::INSTANCE_PORTAL: { - + Portal *portal = portal_owner.get( p_instance->base_rid ); - ERR_FAIL_COND(!portal); + ERR_FAIL_COND(!portal); for (int i=0;i<portal->shape.size();i++) { - + Vector3 point( portal->shape[i].x, portal->shape[i].y, 0 ); if (i==0) { - + new_aabb.pos=point; new_aabb.size.z=0.01; // make it not flat for octree } else { - + new_aabb.expand_to(point); } } - } break; + } break; case VisualServer::INSTANCE_BAKED_LIGHT: { BakedLight *baked_light = baked_light_owner.get( p_instance->base_rid ); @@ -3220,24 +3220,24 @@ void VisualServerRaster::_update_instance_aabb(Instance *p_instance) { if (p_instance->extra_margin) new_aabb.grow_by(p_instance->extra_margin); - + p_instance->aabb=new_aabb; - + } void VisualServerRaster::_update_instances() { while(instance_update_list) { - + Instance *instance=instance_update_list; instance_update_list=instance_update_list->update_next; - + if (instance->update_aabb) _update_instance_aabb(instance); - + _update_instance(instance); - + instance->update=false; instance->update_aabb=false; instance->update_next=0; @@ -3277,7 +3277,7 @@ RID VisualServerRaster::canvas_create() { Canvas * canvas = memnew( Canvas ); ERR_FAIL_COND_V(!canvas,RID()); RID rid = canvas_owner.make_rid( canvas ); - + return rid; } @@ -3317,10 +3317,10 @@ void VisualServerRaster::canvas_set_modulate(RID p_canvas,const Color& p_color) RID VisualServerRaster::canvas_item_create() { - + CanvasItem *canvas_item = memnew( CanvasItem ); ERR_FAIL_COND_V(!canvas_item,RID()); - + return canvas_item_owner.make_rid( canvas_item ); } @@ -3448,7 +3448,7 @@ void VisualServerRaster::canvas_item_set_rect(RID p_item, const Rect2& p_rect) { VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + canvas_item->rect=p_rect; }*/ @@ -3456,7 +3456,7 @@ void VisualServerRaster::canvas_item_set_clip(RID p_item, bool p_clip) { VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + canvas_item->clip=p_clip; } @@ -3543,7 +3543,7 @@ void VisualServerRaster::canvas_item_add_line(RID p_item, const Point2& p_from, VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + CanvasItem::CommandLine * line = memnew( CanvasItem::CommandLine ); ERR_FAIL_COND(!line); line->color=p_color; @@ -3552,15 +3552,15 @@ void VisualServerRaster::canvas_item_add_line(RID p_item, const Point2& p_from, line->width=p_width; canvas_item->rect_dirty=true; - - canvas_item->commands.push_back(line); + + canvas_item->commands.push_back(line); } void VisualServerRaster::canvas_item_add_rect(RID p_item, const Rect2& p_rect, const Color& p_color) { VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + CanvasItem::CommandRect * rect = memnew( CanvasItem::CommandRect ); ERR_FAIL_COND(!rect); rect->modulate=p_color; @@ -3590,7 +3590,7 @@ void VisualServerRaster::canvas_item_add_texture_rect(RID p_item, const Rect2& p VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + CanvasItem::CommandRect * rect = memnew( CanvasItem::CommandRect ); ERR_FAIL_COND(!rect); rect->modulate=p_modulate; @@ -3622,7 +3622,7 @@ void VisualServerRaster::canvas_item_add_texture_rect_region(RID p_item, const R VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + CanvasItem::CommandRect * rect = memnew( CanvasItem::CommandRect ); ERR_FAIL_COND(!rect); rect->modulate=p_modulate; @@ -3648,8 +3648,8 @@ void VisualServerRaster::canvas_item_add_texture_rect_region(RID p_item, const R canvas_item->rect_dirty=true; - canvas_item->commands.push_back(rect); - + canvas_item->commands.push_back(rect); + } void VisualServerRaster::canvas_item_add_style_box(RID p_item, const Rect2& p_rect, RID p_texture,const Vector2& p_topleft, const Vector2& p_bottomright, bool p_draw_center,const Color& p_modulate) { @@ -3657,7 +3657,7 @@ void VisualServerRaster::canvas_item_add_style_box(RID p_item, const Rect2& p_re VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + CanvasItem::CommandStyle * style = memnew( CanvasItem::CommandStyle ); ERR_FAIL_COND(!style); style->texture=p_texture; @@ -3670,13 +3670,13 @@ void VisualServerRaster::canvas_item_add_style_box(RID p_item, const Rect2& p_re style->margin[MARGIN_BOTTOM]=p_bottomright.y; canvas_item->rect_dirty=true; - canvas_item->commands.push_back(style); + canvas_item->commands.push_back(style); } void VisualServerRaster::canvas_item_add_primitive(RID p_item,const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width) { VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - + CanvasItem::CommandPrimitive * prim = memnew( CanvasItem::CommandPrimitive ); ERR_FAIL_COND(!prim); prim->texture=p_texture; @@ -3686,7 +3686,7 @@ void VisualServerRaster::canvas_item_add_primitive(RID p_item,const Vector<Point prim->width=p_width; canvas_item->rect_dirty=true; - canvas_item->commands.push_back(prim); + canvas_item->commands.push_back(prim); } void VisualServerRaster::canvas_item_add_polygon(RID p_item, const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture) { @@ -3907,10 +3907,10 @@ void VisualServerRaster::canvas_item_clear(RID p_item) { VS_CHANGED; CanvasItem *canvas_item = canvas_item_owner.get( p_item ); ERR_FAIL_COND(!canvas_item); - - + + canvas_item->clear(); - + } void VisualServerRaster::canvas_item_raise(RID p_item) { @@ -4398,7 +4398,7 @@ void VisualServerRaster::black_bars_set_images(RID p_left, RID p_top, RID p_righ void VisualServerRaster::_free_attached_instances(RID p_rid,bool p_free_scenario) { Map< RID, Set<RID> >::Element * E = instance_dependency_map.find( p_rid ); - + if (E) { // has instances while( E->get().size() ) { @@ -4407,10 +4407,10 @@ void VisualServerRaster::_free_attached_instances(RID p_rid,bool p_free_scenario instance_set_scenario( E->get().front()->get(), RID() ); else instance_set_base( E->get().front()->get(), RID() ); - + } } - + instance_dependency_map.erase(p_rid); } @@ -4452,7 +4452,7 @@ void VisualServerRaster::free( RID p_rid ) { VS_CHANGED; if (rasterizer->is_texture(p_rid) || rasterizer->is_material(p_rid) || rasterizer->is_shader(p_rid) || rasterizer->is_environment(p_rid)) { - + rasterizer->free(p_rid); } else if (rasterizer->is_skeleton(p_rid)) { @@ -4470,14 +4470,14 @@ void VisualServerRaster::free( RID p_rid ) { rasterizer->free(p_rid); } else if (rasterizer->is_mesh(p_rid) || rasterizer->is_multimesh(p_rid) || rasterizer->is_light(p_rid) || rasterizer->is_particles(p_rid) || rasterizer->is_immediate(p_rid)) { //delete the resource - + _free_attached_instances(p_rid); rasterizer->free(p_rid); } else if (room_owner.owns(p_rid)) { _free_attached_instances(p_rid); - Room *room = room_owner.get(p_rid); - ERR_FAIL_COND(!room); + Room *room = room_owner.get(p_rid); + ERR_FAIL_COND(!room); room_owner.free(p_rid); memdelete(room); @@ -4515,16 +4515,16 @@ void VisualServerRaster::free( RID p_rid ) { } else if (camera_owner.owns(p_rid)) { // delete te camera - + Camera *camera = camera_owner.get(p_rid); ERR_FAIL_COND(!camera); - + camera_owner.free( p_rid ); memdelete(camera); - + } else if (viewport_owner.owns(p_rid)) { // delete the viewport - + Viewport *viewport = viewport_owner.get( p_rid ); ERR_FAIL_COND(!viewport); @@ -4549,15 +4549,15 @@ void VisualServerRaster::free( RID p_rid ) { viewport->canvas_map.erase(viewport->canvas_map.front()); } - - viewport_owner.free(p_rid); + + viewport_owner.free(p_rid); memdelete(viewport); - + } else if (instance_owner.owns(p_rid)) { // delete the instance - + _update_instances(); // be sure - + Instance *instance = instance_owner.get(p_rid); ERR_FAIL_COND(!instance); @@ -4572,9 +4572,9 @@ void VisualServerRaster::free( RID p_rid ) { instance_owner.free(p_rid); memdelete(instance); - + } else if (canvas_owner.owns(p_rid)) { - + Canvas *canvas = canvas_owner.get(p_rid); ERR_FAIL_COND(!canvas); @@ -4606,11 +4606,11 @@ void VisualServerRaster::free( RID p_rid ) { } canvas_owner.free( p_rid ); - + memdelete( canvas ); - + } else if (canvas_item_owner.owns(p_rid)) { - + CanvasItem *canvas_item = canvas_item_owner.get(p_rid); ERR_FAIL_COND(!canvas_item); @@ -4638,7 +4638,7 @@ void VisualServerRaster::free( RID p_rid ) { } canvas_item_owner.free( p_rid ); - + memdelete( canvas_item ); } else if (canvas_item_material_owner.owns(p_rid)) { @@ -4710,22 +4710,22 @@ void VisualServerRaster::free( RID p_rid ) { memdelete(occluder_poly); } else if (scenario_owner.owns(p_rid)) { - + Scenario *scenario=scenario_owner.get(p_rid); ERR_FAIL_COND(!scenario); - + _update_instances(); // be sure _free_attached_instances(p_rid,true); - + //rasterizer->free( scenario->environment ); scenario_owner.free(p_rid); memdelete(scenario); - + } else { - + ERR_FAIL(); } - + } @@ -4747,7 +4747,7 @@ void VisualServerRaster::_instance_draw(Instance *p_instance) { switch(p_instance->base_type) { - + case INSTANCE_MESH: { const float *morphs = NULL; if (!p_instance->data.morph_values.empty()) { @@ -4755,7 +4755,7 @@ void VisualServerRaster::_instance_draw(Instance *p_instance) { } rasterizer->add_mesh(p_instance->base_rid, &p_instance->data); - } break; + } break; case INSTANCE_MULTIMESH: { rasterizer->add_multimesh(p_instance->base_rid, &p_instance->data); } break; @@ -4865,17 +4865,17 @@ Vector<Plane> VisualServerRaster::_camera_generate_orthogonal_planes(Instance *p void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Scenario *p_scenario,Camera *p_camera,const CullRange& p_cull_range) { int splits = rasterizer->light_instance_get_shadow_passes( p_light->light_info->instance ); - + float split_weight=rasterizer->light_directional_get_shadow_param(p_light->base_rid,LIGHT_DIRECTIONAL_SHADOW_PARAM_PSSM_SPLIT_WEIGHT); float distances[5]; float texsize=rasterizer->light_instance_get_shadow_size( p_light->light_info->instance ); - + // float cull_min=p_cull_range.min; //float cull_max=p_cull_range.max; - + bool overlap = rasterizer->light_instance_get_pssm_shadow_overlap(p_light->light_info->instance); float cull_min=p_camera->znear; @@ -4883,7 +4883,7 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc float max_dist = rasterizer->light_directional_get_shadow_param(p_light->base_rid,VS::LIGHT_DIRECTIONAL_SHADOW_PARAM_MAX_DISTANCE); if (max_dist>0.0) cull_max=MIN(cull_max,max_dist); - + for(int i = 0; i < splits; i++) { float idm = i / (float)splits; float lg = cull_min * Math::pow(cull_max/cull_min, idm); @@ -4894,16 +4894,16 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc distances[0]=cull_min; distances[splits]=cull_max; - + for (int i=0;i<splits;i++) { - + // setup a camera matrix for that range! CameraMatrix camera_matrix; - + switch(p_camera->type) { - + case Camera::ORTHOGONAL: { - + camera_matrix.set_orthogonal( p_camera->size, viewport_rect.width / (float)viewport_rect.height, @@ -4914,7 +4914,7 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc ); } break; case Camera::PERSPECTIVE: { - + camera_matrix.set_perspective( p_camera->fov, @@ -4924,18 +4924,18 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc p_camera->vaspect ); - - } break; - } - + + } break; + } + //obtain the frustum endpoints - + Vector3 endpoints[8]; // frustum plane endpoints bool res = camera_matrix.get_endpoints(p_camera->transform,endpoints); ERR_CONTINUE(!res); - + // obtain the light frustm ranges (given endpoints) - + Vector3 x_vec=p_light->data.transform.basis.get_axis( Vector3::AXIS_X ).normalized(); Vector3 y_vec=p_light->data.transform.basis.get_axis( Vector3::AXIS_Y ).normalized(); Vector3 z_vec=p_light->data.transform.basis.get_axis( Vector3::AXIS_Z ).normalized(); @@ -4952,27 +4952,27 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc //used for culling for(int j=0;j<8;j++) { - + float d_x=x_vec.dot(endpoints[j]); float d_y=y_vec.dot(endpoints[j]); float d_z=z_vec.dot(endpoints[j]); - + if (j==0 || d_x<x_min) x_min=d_x; if (j==0 || d_x>x_max) x_max=d_x; - + if (j==0 || d_y<y_min) y_min=d_y; if (j==0 || d_y>y_max) y_max=d_y; - + if (j==0 || d_z<z_min) z_min=d_z; if (j==0 || d_z>z_max) z_max=d_z; - - + + } @@ -5024,10 +5024,10 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc } //now that we now all ranges, we can proceed to make the light frustum planes, for culling octree - + Vector<Plane> light_frustum_planes; light_frustum_planes.resize(6); - + //right/left light_frustum_planes[0]=Plane( x_vec, x_max ); light_frustum_planes[1]=Plane( -x_vec, -x_min ); @@ -5035,14 +5035,14 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc light_frustum_planes[2]=Plane( y_vec, y_max ); light_frustum_planes[3]=Plane( -y_vec, -y_min ); //near/far - light_frustum_planes[4]=Plane( z_vec, z_max+1e6 ); - light_frustum_planes[5]=Plane( -z_vec, -z_min ); // z_min is ok, since casters further than far-light plane are not needed - + light_frustum_planes[4]=Plane( z_vec, z_max+1e6 ); + light_frustum_planes[5]=Plane( -z_vec, -z_min ); // z_min is ok, since casters further than far-light plane are not needed + int caster_cull_count = p_scenario->octree.cull_convex(light_frustum_planes,instance_shadow_cull_result,MAX_INSTANCE_CULL,INSTANCE_GEOMETRY_MASK); - + // a pre pass will need to be needed to determine the actual z-near to be used for(int j=0;j<caster_cull_count;j++) { - + float min,max; Instance *ins=instance_shadow_cull_result[j]; if (!ins->visible || ins->data.cast_shadows == VS::SHADOW_CASTING_SETTING_OFF) @@ -5067,23 +5067,23 @@ void VisualServerRaster::_light_instance_update_pssm_shadow(Instance *p_light,Sc rasterizer->light_instance_set_shadow_transform(p_light->light_info->instance, i, ortho_camera, ortho_transform,distances[i],distances[i+1] ); } - + rasterizer->begin_shadow_map( p_light->light_info->instance, i ); - + for (int j=0;j<caster_cull_count;j++) { - + Instance *instance = instance_shadow_cull_result[j]; if (!instance->visible || instance->data.cast_shadows==VS::SHADOW_CASTING_SETTING_OFF) continue; _instance_draw(instance); } - + rasterizer->end_shadow_map(); - - + + } - - + + } @@ -5519,7 +5519,7 @@ void VisualServerRaster::_light_instance_update_shadow(Instance *p_light,Scenari Rasterizer::ShadowType shadow_type = rasterizer->light_instance_get_shadow_type(p_light->light_info->instance); switch(shadow_type) { - + case Rasterizer::SHADOW_SIMPLE: { /* SPOT SHADOW */ @@ -6047,7 +6047,7 @@ void VisualServerRaster::_cull_room(Camera *p_camera, Instance *p_room,Instance } - + } void VisualServerRaster::_process_sampled_light(const Transform& p_camera,Instance *p_sampled_light,bool p_linear_colorspace) { @@ -6379,7 +6379,7 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S switch(p_camera->type) { case Camera::ORTHOGONAL: { - + camera_matrix.set_orthogonal( p_camera->size, viewport_rect.width / (float)viewport_rect.height, @@ -6401,19 +6401,19 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S ); ortho=false; - - } break; + + } break; } rasterizer->set_camera(p_camera->transform, camera_matrix,ortho); - + Vector<Plane> planes = camera_matrix.get_projection_planes(p_camera->transform); CullRange cull_range; // cull range is used for PSSM, and having an idea of the rendering depth cull_range.nearp=Plane(p_camera->transform.origin,-p_camera->transform.basis.get_axis(2).normalized()); cull_range.z_near=camera_matrix.get_z_near(); - cull_range.z_far=camera_matrix.get_z_far(); + cull_range.z_far=camera_matrix.get_z_far(); cull_range.min=cull_range.z_far; cull_range.max=cull_range.z_near; @@ -6429,10 +6429,10 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S */ /* STEP 3 - PROCESS PORTALS, VALIDATE ROOMS */ - + // compute portals - + exterior_visited=false; exterior_portal_cull_count=0; @@ -6513,11 +6513,11 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S } /* STEP 4 - REMOVE FURTHER CULLED OBJECTS, ADD LIGHTS */ - + for(int i=0;i<cull_count;i++) { - + Instance *ins = instance_cull_result[i]; - + bool keep=false; @@ -6603,7 +6603,7 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S } } } - + } if (!keep) { @@ -6617,12 +6617,12 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S ins->last_render_pass=render_pass; } } - + if (cull_range.max > cull_range.z_far ) cull_range.max=cull_range.z_far; if (cull_range.min < cull_range.z_near ) cull_range.min=cull_range.z_near; - + /* STEP 5 - PROCESS LIGHTS */ rasterizer->shadow_clear_near(); //clear near shadows, will be recreated @@ -6649,7 +6649,7 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S //discard lights not affecting anything (useful for deferred rendering, shadowmaps, etc) for (int i=0;i<light_cull_count;i++) { - + Instance *ins = light_cull_result[i]; if (light_discard_enabled) { @@ -6678,7 +6678,7 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S } } - + } { //this should eventually change to @@ -6691,12 +6691,12 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S if (!rasterizer->light_has_shadow(ins->base_rid) || !shadows_enabled) continue; - + /* for far shadows? if (ins->version == ins->light_info->last_version && rasterizer->light_instance_has_far_shadow(ins->light_info->instance)) continue; // didn't change */ - + _light_instance_update_shadow(ins,p_scenario,p_camera,cull_range); ins->light_info->last_version=ins->version; } @@ -6726,17 +6726,17 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S } /* STEP 7 - PROCESS GEOMETRY AND DRAW SCENE*/ - + rasterizer->begin_scene(p_viewport->viewport_data,environment,p_scenario->debug); - rasterizer->set_viewport(viewport_rect); - + rasterizer->set_viewport(viewport_rect); + // add lights { List<RID>::Element *E=p_scenario->directional_lights.front(); - + for(;E;E=E->next()) { Instance *light = E->get().is_valid()?instance_owner.get(E->get()):NULL; @@ -6758,11 +6758,11 @@ void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, S // add geometry for(int i=0;i<cull_count;i++) { - + Instance *ins = instance_cull_result[i]; ERR_CONTINUE(!((1<<ins->base_type)&INSTANCE_GEOMETRY_MASK)); - + _instance_draw(ins); } @@ -6823,7 +6823,7 @@ void VisualServerRaster::_render_canvas_item(CanvasItem *p_canvas_item,const Mat if (global_rect.intersects(p_clip_rect) && ci->viewport.is_valid() && viewport_owner.owns(ci->viewport)) { - Viewport *vp = viewport_owner.get(ci->viewport); + Viewport *vp = viewport_owner.get(ci->viewport); Point2i from = xform.get_origin() + Point2(viewport_rect.x,viewport_rect.y); Point2i size = rect.size; @@ -7364,7 +7364,7 @@ void VisualServerRaster::_draw_viewports() { rasterizer->set_viewport(viewport_rect); } - rasterizer->canvas_begin(); + rasterizer->canvas_begin(); rasterizer->canvas_disable_blending(); rasterizer->canvas_begin_rect(Matrix32()); rasterizer->canvas_draw_rect(E->get()->rt_to_screen_rect,0,Rect2(Point2(),E->get()->rt_to_screen_rect.size),E->get()->render_target_texture,Color(1,1,1)); @@ -7492,7 +7492,7 @@ void VisualServerRaster::draw() { rasterizer->begin_frame(); _draw_viewports(); _draw_cursors_and_margins(); - rasterizer->end_frame(); + rasterizer->end_frame(); draw_extra_frame=rasterizer->needs_to_draw_next_frame(); } @@ -7574,13 +7574,13 @@ void VisualServerRaster::set_boot_image(const Image& p_image, const Color& p_col void VisualServerRaster::init() { rasterizer->init(); - + shadows_enabled=GLOBAL_DEF("render/shadows_enabled",true); //default_scenario = scenario_create(); //default_viewport = viewport_create(); for(int i=0;i<4;i++) black_margin[i]=0; - + Image img; img.create(default_mouse_cursor_xpm); //img.convert(Image::FORMAT_RGB); @@ -7597,7 +7597,7 @@ void VisualServerRaster::_clean_up_owner(RID_OwnerBase *p_owner,String p_type) { List<RID> rids; p_owner->get_owned_list(&rids); - + int lost=0; for(List<RID>::Element *I=rids.front();I;I=I->next()) { if (OS::get_singleton()->is_stdout_verbose()) { @@ -7622,19 +7622,19 @@ void VisualServerRaster::finish() { _clean_up_owner( &room_owner,"Room" ); _clean_up_owner( &portal_owner,"Portal" ); - + _clean_up_owner( &camera_owner,"Camera" ); _clean_up_owner( &viewport_owner,"Viewport" ); - + _clean_up_owner( &scenario_owner,"Scenario" ); _clean_up_owner( &instance_owner,"Instance" ); - + _clean_up_owner( &canvas_owner,"Canvas" ); _clean_up_owner( &canvas_item_owner,"CanvasItem" ); rasterizer->finish(); octree_allocator.clear(); - + if (instance_dependency_map.size()) { print_line("Base resources missing amount: "+itos(instance_dependency_map.size())); } @@ -7646,9 +7646,9 @@ RID VisualServerRaster::get_test_cube() { if (test_cube.is_valid()) return test_cube; - + test_cube=_make_test_cube(); - return test_cube; + return test_cube; } diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 4456843c79..77d5780c5f 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -44,7 +44,7 @@ class VisualServerRaster : public VisualServer { enum { - + MAX_INSTANCE_CULL=8192, MAX_INSTANCE_LIGHTS=4, LIGHT_CACHE_DIRTY=-1, @@ -58,13 +58,13 @@ class VisualServerRaster : public VisualServer { }; struct Room { - + bool occlude_exterior; BSP_Tree bounds; Room() { occlude_exterior=true; } }; - - + + BalloonAllocator<> octree_allocator; struct OctreeAllocator { @@ -116,10 +116,10 @@ class VisualServerRaster : public VisualServer { void _update_baked_light_sampler_dp_cache(BakedLightSampler * blsamp); struct Camera { - + enum Type { PERSPECTIVE, - ORTHOGONAL + ORTHOGONAL }; Type type; float fov; @@ -128,18 +128,18 @@ class VisualServerRaster : public VisualServer { uint32_t visible_layers; bool vaspect; RID env; - + Transform transform; - + Camera() { - + visible_layers=0xFFFFFFFF; fov=60; type=PERSPECTIVE; znear=0.1; zfar=100; size=1.0; vaspect=false; - + } }; @@ -147,24 +147,24 @@ class VisualServerRaster : public VisualServer { struct Instance; typedef Set<Instance*,Comparator<Instance*>,OctreeAllocator> InstanceSet; struct Scenario; - + struct Instance { - + enum { - + MAX_LIGHTS=4 }; - + RID self; - OctreeElementID octree_id; + OctreeElementID octree_id; Scenario *scenario; bool update; bool update_aabb; - Instance *update_next; + Instance *update_next; InstanceType base_type; RID base_rid; - + AABB aabb; AABB transformed_aabb; uint32_t object_ID; @@ -180,7 +180,7 @@ class VisualServerRaster : public VisualServer { Rasterizer::InstanceData data; - + Set<Instance*> auto_rooms; Set<Instance*> valid_auto_rooms; Instance *room; @@ -192,9 +192,9 @@ class VisualServerRaster : public VisualServer { uint64_t last_render_pass; uint64_t last_frame_pass; - + uint64_t version; // changes to this, and changes to base increase version - + InstanceSet lights; bool light_cache_dirty; @@ -205,7 +205,7 @@ class VisualServerRaster : public VisualServer { Transform affine_inverse; Room *room; List<Instance*> owned_geometry_instances; - List<Instance*> owned_portal_instances; + List<Instance*> owned_portal_instances; List<Instance*> owned_room_instances; List<Instance*> owned_light_instances; //not used, but just for the sake of it Set<Instance*> disconnected_child_portals; @@ -230,8 +230,8 @@ class VisualServerRaster : public VisualServer { }; struct LightInfo { - - RID instance; + + RID instance; int light_set_index; uint64_t last_version; uint64_t last_add_pass; @@ -240,10 +240,10 @@ class VisualServerRaster : public VisualServer { bool enabled; float dtc; //distance to camera, used for sorting - + LightInfo() { - - D=NULL; + + D=NULL; light_set_index=-1; last_add_pass=0; enabled=true; @@ -273,10 +273,10 @@ class VisualServerRaster : public VisualServer { resolution=0; } }; - + struct ParticlesInfo { - - RID instance; + + RID instance; }; @@ -288,7 +288,7 @@ class VisualServerRaster : public VisualServer { BakedLightSamplerInfo * baked_light_sampler_info; - Instance() { + Instance() { octree_id=0; update_next=0; object_ID=0; @@ -328,9 +328,9 @@ class VisualServerRaster : public VisualServer { light_cache_dirty=true; } - + ~Instance() { - + if (light_info) memdelete(light_info); if (particles_info) @@ -343,26 +343,26 @@ class VisualServerRaster : public VisualServer { memdelete(baked_light_info); }; }; - + struct _InstanceLightsort { bool operator()(const Instance* p_A, const Instance* p_B) const { return p_A->light_info->dtc < p_B->light_info->dtc; } }; struct Scenario { - + ScenarioDebugMode debug; RID self; // well wtf, balloon allocator is slower? typedef ::Octree<Instance,true> Octree; - + Octree octree; - + List<RID> directional_lights; RID environment; RID fallback_environment; - + Instance *dirty_instances; Scenario() { dirty_instances=NULL; debug=SCENARIO_DEBUG_DISABLED; } @@ -458,7 +458,7 @@ class VisualServerRaster : public VisualServer { } Canvas() { modulate=Color(1,1,1,1); } - + }; @@ -524,14 +524,14 @@ class VisualServerRaster : public VisualServer { Map<RID,int> screen_viewports; struct CullRange { - + Plane nearp; float min,max; float z_near,z_far; - + void add_aabb(const AABB& p_aabb) { - - + + } }; @@ -559,12 +559,12 @@ class VisualServerRaster : public VisualServer { Instance *instance_cull_result[MAX_INSTANCE_CULL]; Instance *instance_shadow_cull_result[MAX_INSTANCE_CULL]; //used for generating shadowmaps - Instance *light_cull_result[MAX_LIGHTS_CULLED]; + Instance *light_cull_result[MAX_LIGHTS_CULLED]; int light_cull_count; Instance *exterior_portal_cull_result[MAX_EXTERIOR_PORTALS]; int exterior_portal_cull_count; - bool exterior_visited; + bool exterior_visited; Instance *light_sampler_cull_result[MAX_LIGHT_SAMPLERS]; int light_samplers_culled; @@ -591,7 +591,7 @@ class VisualServerRaster : public VisualServer { void _update_instance(Instance *p_instance); void _free_attached_instances(RID p_rid,bool p_free_scenario=false); void _clean_up_owner(RID_OwnerBase *p_owner,String p_type); - + Instance *instance_update_list; //RID default_scenario; @@ -599,7 +599,7 @@ class VisualServerRaster : public VisualServer { RID test_cube; - + mutable RID_Owner<Room> room_owner; mutable RID_Owner<Portal> portal_owner; @@ -608,20 +608,20 @@ class VisualServerRaster : public VisualServer { mutable RID_Owner<Camera> camera_owner; mutable RID_Owner<Viewport> viewport_owner; - + mutable RID_Owner<Scenario> scenario_owner; mutable RID_Owner<Instance> instance_owner; - + mutable RID_Owner<Canvas> canvas_owner; mutable RID_Owner<CanvasItem> canvas_item_owner; Map< RID, Set<RID> > instance_dependency_map; Map< RID, Set<Instance*> > skeleton_dependency_map; - + ViewportRect viewport_rect; _FORCE_INLINE_ void _instance_draw(Instance *p_instance); - + bool _test_portal_cull(Camera *p_camera, Instance *p_portal_from, Instance *p_portal_to); void _cull_portal(Camera *p_camera, Instance *p_portal,Instance *p_from_portal); void _cull_room(Camera *p_camera, Instance *p_room,Instance *p_from_portal=NULL); @@ -640,9 +640,9 @@ class VisualServerRaster : public VisualServer { void _light_instance_update_lispsm_shadow(Instance *p_light,Scenario *p_scenario,Camera *p_camera,const CullRange& p_cull_range); void _light_instance_update_pssm_shadow(Instance *p_light,Scenario *p_scenario,Camera *p_camera,const CullRange& p_cull_range); - + void _light_instance_update_shadow(Instance *p_light,Scenario *p_scenario,Camera *p_camera,const CullRange& p_cull_range); - + uint64_t render_pass; int changes; bool draw_extra_frame; @@ -651,8 +651,8 @@ class VisualServerRaster : public VisualServer { void _draw_viewport(Viewport *p_viewport,int p_ofs_x, int p_ofs_y,int p_parent_w,int p_parent_h); void _draw_viewports(); void _draw_cursors_and_margins(); - - + + Rasterizer *rasterizer; public: @@ -676,7 +676,7 @@ public: /* SHADER API */ - + virtual RID shader_create(ShaderMode p_mode=SHADER_MATERIAL); virtual void shader_set_mode(RID p_shader,ShaderMode p_mode); @@ -764,7 +764,7 @@ public: virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const; virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const; virtual PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const; - + virtual void mesh_remove_surface(RID p_mesh,int p_index); virtual int mesh_get_surface_count(RID p_mesh) const; @@ -807,23 +807,23 @@ public: virtual void immediate_set_material(RID p_immediate,RID p_material); virtual RID immediate_get_material(RID p_immediate) const; - + /* PARTICLES API */ - + virtual RID particles_create(); - + virtual void particles_set_amount(RID p_particles, int p_amount); virtual int particles_get_amount(RID p_particles) const; - + virtual void particles_set_emitting(RID p_particles, bool p_emitting); virtual bool particles_is_emitting(RID p_particles) const; - + virtual void particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility); virtual AABB particles_get_visibility_aabb(RID p_particles) const; - + virtual void particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents); virtual Vector3 particles_get_emission_half_extents(RID p_particles) const; - + virtual void particles_set_emission_base_velocity(RID p_particles, const Vector3& p_base_velocity); virtual Vector3 particles_get_emission_base_velocity(RID p_particles) const; @@ -832,16 +832,16 @@ public: virtual void particles_set_gravity_normal(RID p_particles, const Vector3& p_normal); virtual Vector3 particles_get_gravity_normal(RID p_particles) const; - + virtual void particles_set_variable(RID p_particles, ParticleVariable p_variable,float p_value); virtual float particles_get_variable(RID p_particles, ParticleVariable p_variable) const; - + virtual void particles_set_randomness(RID p_particles, ParticleVariable p_variable,float p_randomness); virtual float particles_get_randomness(RID p_particles, ParticleVariable p_variable) const; - + virtual void particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos); virtual float particles_get_color_phase_pos(RID p_particles, int p_phase) const; - + virtual void particles_set_color_phases(RID p_particles, int p_phases); virtual int particles_get_color_phases(RID p_particles) const; @@ -859,32 +859,32 @@ public: virtual void particles_set_material(RID p_particles, RID p_material,bool p_owned=false); virtual RID particles_get_material(RID p_particles) const; - + virtual void particles_set_height_from_velocity(RID p_particles, bool p_enable); virtual bool particles_has_height_from_velocity(RID p_particles) const; virtual void particles_set_use_local_coordinates(RID p_particles, bool p_enable); virtual bool particles_is_using_local_coordinates(RID p_particles) const; - + /* Light API */ - + virtual RID light_create(LightType p_type); virtual LightType light_get_type(RID p_light) const; virtual void light_set_color(RID p_light,LightColor p_type, const Color& p_color); - virtual Color light_get_color(RID p_light,LightColor p_type) const; - + virtual Color light_get_color(RID p_light,LightColor p_type) const; + virtual void light_set_shadow(RID p_light,bool p_enabled); - virtual bool light_has_shadow(RID p_light) const; - + virtual bool light_has_shadow(RID p_light) const; + virtual void light_set_volumetric(RID p_light,bool p_enabled); - virtual bool light_is_volumetric(RID p_light) const; - + virtual bool light_is_volumetric(RID p_light) const; + virtual void light_set_projector(RID p_light,RID p_texture); virtual RID light_get_projector(RID p_light) const; - + virtual void light_set_param(RID p_light, LightParam p_var, float p_value); virtual float light_get_param(RID p_light, LightParam p_var) const; @@ -901,7 +901,7 @@ public: /* SKELETON API */ - + virtual RID skeleton_create(); virtual void skeleton_resize(RID p_skeleton,int p_bones); virtual int skeleton_get_bone_count(RID p_skeleton) const; @@ -913,9 +913,9 @@ public: virtual RID room_create(); virtual void room_set_bounds(RID p_room, const BSP_Tree& p_bounds); virtual BSP_Tree room_get_bounds(RID p_room) const; - + /* PORTAL API */ - + virtual RID portal_create(); virtual void portal_set_shape(RID p_portal, const Vector<Point2>& p_shape); virtual Vector<Point2> portal_get_shape(RID p_portal) const; @@ -961,12 +961,12 @@ public: virtual int baked_light_sampler_get_resolution(RID p_baked_light_sampler) const; /* CAMERA API */ - + virtual RID camera_create(); virtual void camera_set_perspective(RID p_camera,float p_fovy_degrees, float p_z_near, float p_z_far); virtual void camera_set_orthogonal(RID p_camera,float p_size, float p_z_near, float p_z_far); - virtual void camera_set_transform(RID p_camera,const Transform& p_transform); - + virtual void camera_set_transform(RID p_camera,const Transform& p_transform); + virtual void camera_set_visible_layers(RID p_camera,uint32_t p_layers); virtual uint32_t camera_get_visible_layers(RID p_camera) const; @@ -1000,7 +1000,7 @@ public: virtual void viewport_set_rect(RID p_viewport,const ViewportRect& p_rect); virtual ViewportRect viewport_get_rect(RID p_viewport) const; - + virtual void viewport_set_hide_scenario(RID p_viewport,bool p_hide); virtual void viewport_set_hide_canvas(RID p_viewport,bool p_hide); virtual void viewport_set_disable_environment(RID p_viewport,bool p_disable); @@ -1011,8 +1011,8 @@ public: virtual RID viewport_get_scenario(RID p_viewport) const; virtual void viewport_attach_canvas(RID p_viewport,RID p_canvas); virtual void viewport_remove_canvas(RID p_viewport,RID p_canvas); - virtual void viewport_set_canvas_transform(RID p_viewport,RID p_canvas,const Matrix32& p_offset); - virtual Matrix32 viewport_get_canvas_transform(RID p_viewport,RID p_canvas) const; + virtual void viewport_set_canvas_transform(RID p_viewport,RID p_canvas,const Matrix32& p_offset); + virtual Matrix32 viewport_get_canvas_transform(RID p_viewport,RID p_canvas) const; virtual void viewport_set_global_canvas_transform(RID p_viewport,const Matrix32& p_transform); virtual Matrix32 viewport_get_global_canvas_transform(RID p_viewport) const; virtual void viewport_set_canvas_layer(RID p_viewport,RID p_canvas,int p_layer); @@ -1037,10 +1037,10 @@ public: virtual void environment_fx_set_param(RID p_env,EnvironmentFxParam p_effect,const Variant& p_param); virtual Variant environment_fx_get_param(RID p_env,EnvironmentFxParam p_effect) const; - + /* SCENARIO API */ - - virtual RID scenario_create(); + + virtual RID scenario_create(); virtual void scenario_set_debug(RID p_scenario,ScenarioDebugMode p_debug_mode); virtual void scenario_set_environment(RID p_scenario, RID p_environment); @@ -1048,9 +1048,9 @@ public: virtual void scenario_set_fallback_environment(RID p_scenario, RID p_environment); - + /* INSTANCING API */ - + virtual RID instance_create(); virtual void instance_set_base(RID p_instance, RID p_base); @@ -1115,7 +1115,7 @@ public: virtual bool instance_light_is_enabled(RID p_instance) const; /* CANVAS (2D) */ - + virtual RID canvas_create(); virtual void canvas_set_item_mirroring(RID p_canvas,RID p_item,const Point2& p_mirroring); virtual Point2 canvas_get_item_mirroring(RID p_canvas,RID p_item) const; @@ -1217,7 +1217,7 @@ public: virtual RID canvas_item_material_create(); virtual void canvas_item_material_set_shader(RID p_material, RID p_shader); virtual void canvas_item_material_set_shader_param(RID p_material, const StringName& p_param, const Variant& p_value); - virtual Variant canvas_item_material_get_shader_param(RID p_material, const StringName& p_param) const; + virtual Variant canvas_item_material_get_shader_param(RID p_material, const StringName& p_param) const; virtual void canvas_item_material_set_shading_mode(RID p_material, CanvasItemShadingMode p_mode); @@ -1234,7 +1234,7 @@ public: virtual void black_bars_set_images(RID p_left, RID p_top, RID p_right, RID p_bottom); /* FREE */ - + virtual void free( RID p_rid ); /* CUSTOM SHADE MODEL */ @@ -1251,7 +1251,7 @@ public: virtual void draw(); virtual void sync(); - virtual void init(); + virtual void init(); virtual void finish(); virtual bool has_changed() const; @@ -1266,7 +1266,7 @@ public: virtual void set_boot_image(const Image& p_image, const Color& p_color, bool p_scale); virtual void set_default_clear_color(const Color& p_color); - VisualServerRaster(Rasterizer *p_rasterizer); + VisualServerRaster(Rasterizer *p_rasterizer); ~VisualServerRaster(); }; diff --git a/servers/visual/visual_server_wrap_mt.cpp b/servers/visual/visual_server_wrap_mt.cpp index 478a31806c..5ea4145342 100644 --- a/servers/visual/visual_server_wrap_mt.cpp +++ b/servers/visual/visual_server_wrap_mt.cpp @@ -35,20 +35,20 @@ void VisualServerWrapMT::thread_exit() { } void VisualServerWrapMT::thread_draw() { - - + + draw_mutex->lock(); - + draw_pending--; bool draw=(draw_pending==0);// only draw when no more flushes are pending - + draw_mutex->unlock(); - + if (draw) { - + visual_server->draw(); - } - + } + } void VisualServerWrapMT::thread_flush() { @@ -67,10 +67,10 @@ void VisualServerWrapMT::thread_flush() { void VisualServerWrapMT::_thread_callback(void *_instance) { VisualServerWrapMT *vsmt = reinterpret_cast<VisualServerWrapMT*>(_instance); - + vsmt->thread_loop(); -} +} void VisualServerWrapMT::thread_loop() { @@ -79,18 +79,18 @@ void VisualServerWrapMT::thread_loop() { OS::get_singleton()->make_rendering_thread(); visual_server->init(); - + exit=false; draw_thread_up=true; while(!exit) { // flush commands one by one, until exit is requested command_queue.wait_and_flush_one(); } - + command_queue.flush_all(); // flush all - + visual_server->finish(); - + } @@ -117,7 +117,7 @@ void VisualServerWrapMT::sync() { } void VisualServerWrapMT::draw() { - + if (create_thread) { @@ -155,7 +155,7 @@ void VisualServerWrapMT::init() { visual_server->init(); } - + } void VisualServerWrapMT::finish() { @@ -164,7 +164,7 @@ void VisualServerWrapMT::finish() { if (thread) { command_queue.push( this, &VisualServerWrapMT::thread_exit); - Thread::wait_to_finish( thread ); + Thread::wait_to_finish( thread ); memdelete(thread); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index 74630d67ef..52e38c8438 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -41,9 +41,9 @@ class VisualServerWrapMT : public VisualServer { // the real visual server mutable VisualServer *visual_server; - + mutable CommandQueueMT command_queue; - + static void _thread_callback(void *_instance); void thread_loop(); @@ -52,7 +52,7 @@ class VisualServerWrapMT : public VisualServer { Thread *thread; volatile bool draw_thread_up; bool create_thread; - + Mutex *draw_mutex; int draw_pending; void thread_draw(); @@ -433,7 +433,7 @@ public: FUNC2(viewport_set_render_target_vflip,RID,bool); FUNC1RC(bool,viewport_get_render_target_vflip,RID); FUNC2(viewport_set_render_target_to_screen_rect,RID,const Rect2&); - + FUNC2(viewport_set_render_target_clear_on_new_frame,RID,bool); FUNC1RC(bool,viewport_get_render_target_clear_on_new_frame,RID); FUNC1(viewport_render_target_clear,RID); @@ -663,7 +663,7 @@ public: FUNC0R(RID,canvas_item_material_create); FUNC2(canvas_item_material_set_shader,RID,RID); FUNC3(canvas_item_material_set_shader_param,RID,const StringName&,const Variant&); - FUNC2RC(Variant,canvas_item_material_get_shader_param,RID,const StringName&); + FUNC2RC(Variant,canvas_item_material_get_shader_param,RID,const StringName&); FUNC2(canvas_item_material_set_shading_mode,RID,CanvasItemShadingMode); /* CURSOR */ diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index fd2913cc7e..17d5b16b9f 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -73,11 +73,11 @@ DVector<String> VisualServer::_shader_get_param_list(RID p_shader) const { VisualServer *VisualServer::create() { ERR_FAIL_COND_V(singleton,NULL); - + if (create_func) return create_func(); - - return NULL; + + return NULL; } RID VisualServer::texture_create_from_image(const Image& p_image,uint32_t p_flags) { @@ -87,7 +87,7 @@ RID VisualServer::texture_create_from_image(const Image& p_image,uint32_t p_flag ERR_FAIL_COND_V(!texture.is_valid(),texture); texture_set_data(texture, p_image ); - + return texture; } @@ -152,9 +152,9 @@ RID VisualServer::_make_test_cube() { DVector<Vector3> vertices; DVector<Vector3> normals; - DVector<float> tangents; + DVector<float> tangents; DVector<Vector3> uvs; - + int vtx_idx=0; #define ADD_VTX(m_idx);\ vertices.push_back( face_points[m_idx] );\ @@ -168,20 +168,20 @@ RID VisualServer::_make_test_cube() { for (int i=0;i<6;i++) { - + Vector3 face_points[4]; Vector3 normal_points[4]; float uv_points[8]={0,0,0,1,1,1,1,0}; - + for (int j=0;j<4;j++) { - + float v[3]; v[0]=1.0; v[1]=1-2*((j>>1)&1); v[2]=v[1]*(1-2*(j&1)); - + for (int k=0;k<3;k++) { - + if (i<3) face_points[j][(i+k)%3]=v[k]*(i>=3?-1:1); else @@ -218,7 +218,7 @@ RID VisualServer::_make_test_cube() { d[VisualServer::ARRAY_INDEX]=indices; mesh_add_surface( test_cube, PRIMITIVE_TRIANGLES,d ); - + test_material = fixed_material_create(); @@ -231,51 +231,51 @@ RID VisualServer::_make_test_cube() { fixed_material_set_param( test_material, FIXED_MATERIAL_PARAM_SPECULAR, Color(1,1,1) ); mesh_surface_set_material(test_cube, 0, test_material ); - + return test_cube; } RID VisualServer::make_sphere_mesh(int p_lats,int p_lons,float p_radius) { - + DVector<Vector3> vertices; DVector<Vector3> normals; - + for(int i = 1; i <= p_lats; i++) { double lat0 = Math_PI * (-0.5 + (double) (i - 1) / p_lats); double z0 = Math::sin(lat0); double zr0 = Math::cos(lat0); - + double lat1 = Math_PI * (-0.5 + (double) i / p_lats); double z1 = Math::sin(lat1); double zr1 = Math::cos(lat1); - + for(int j = p_lons; j >= 1; j--) { - + double lng0 = 2 * Math_PI * (double) (j - 1) / p_lons; double x0 = Math::cos(lng0); double y0 = Math::sin(lng0); - + double lng1 = 2 * Math_PI * (double) (j) / p_lons; - double x1 = Math::cos(lng1); + double x1 = Math::cos(lng1); double y1 = Math::sin(lng1); - - + + Vector3 v[4]={ Vector3(x1 * zr0, z0, y1 *zr0), Vector3(x1 * zr1, z1, y1 *zr1), Vector3(x0 * zr1, z1, y0 *zr1), Vector3(x0 * zr0, z0, y0 *zr0) }; - + #define ADD_POINT(m_idx)\ normals.push_back(v[m_idx]); \ vertices.push_back(v[m_idx]*p_radius);\ - + ADD_POINT(0); ADD_POINT(1); ADD_POINT(2); - + ADD_POINT(2); ADD_POINT(3); ADD_POINT(0); @@ -313,7 +313,7 @@ RID VisualServer::material_2d_get(bool p_shaded, bool p_transparent, bool p_cut_ material_2d[version]=fixed_material_create(); fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_USE_ALPHA,p_transparent); - fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true); + fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true); fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_DISCARD_ALPHA,p_cut_alpha); material_set_flag(material_2d[version],MATERIAL_FLAG_UNSHADED,!p_shaded); material_set_flag(material_2d[version],MATERIAL_FLAG_DOUBLE_SIDED,true); @@ -736,23 +736,23 @@ void VisualServer::mesh_add_surface_from_mesh_data( RID p_mesh, const Geometry:: #if 1 DVector<Vector3> vertices; DVector<Vector3> normals; - + for (int i=0;i<p_mesh_data.faces.size();i++) { - + const Geometry::MeshData::Face& f = p_mesh_data.faces[i]; - + for (int j=2;j<f.indices.size();j++) { - + #define _ADD_VERTEX(m_idx)\ vertices.push_back( p_mesh_data.vertices[ f.indices[m_idx] ] );\ normals.push_back( f.plane.normal ); - + _ADD_VERTEX( 0 ); _ADD_VERTEX( j-1 ); _ADD_VERTEX( j ); - } + } } - + int s = mesh_get_surface_count(p_mesh); Array d; d.resize(VS::ARRAY_MAX); @@ -783,7 +783,7 @@ void VisualServer::mesh_add_surface_from_mesh_data( RID p_mesh, const Geometry:: #endif - + } void VisualServer::mesh_add_surface_from_planes( RID p_mesh, const DVector<Plane>& p_planes) { diff --git a/servers/visual_server.h b/servers/visual_server.h index bf689bd0a6..3a5b3d8d37 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -53,18 +53,18 @@ class VisualServer : public Object { void _viewport_set_rect(RID p_viewport,const Rect2& p_rect); Rect2 _viewport_get_rect(RID p_viewport) const; void _canvas_item_add_style_box(RID p_item, const Rect2& p_rect, RID p_texture,const Vector<float>& p_margins, const Color& p_modulate=Color(1,1,1)); -protected: +protected: RID _make_test_cube(); void _free_internal_rids(); RID test_texture; RID white_texture; RID test_material; RID material_2d[16]; - + static VisualServer* (*create_func)(); - static void _bind_methods(); + static void _bind_methods(); public: - + static VisualServer *get_singleton(); static VisualServer *create(); @@ -80,9 +80,9 @@ public: virtual MipMapPolicy get_mipmap_policy() const; - + enum { - + NO_INDEX_ARRAY=-1, CUSTOM_ARRAY_SIZE=8, ARRAY_WEIGHTS_SIZE=4, @@ -95,7 +95,7 @@ public: MAX_CURSORS = 8, }; - + /* TEXTURE API */ enum TextureFlags { @@ -108,21 +108,21 @@ public: TEXTURE_FLAG_CUBEMAP=2048, TEXTURE_FLAG_VIDEO_SURFACE=4096, TEXTURE_FLAGS_DEFAULT=TEXTURE_FLAG_REPEAT|TEXTURE_FLAG_MIPMAPS|TEXTURE_FLAG_FILTER - }; - + }; + enum CubeMapSide { - + CUBEMAP_LEFT, CUBEMAP_RIGHT, CUBEMAP_BOTTOM, CUBEMAP_TOP, - CUBEMAP_FRONT, + CUBEMAP_FRONT, CUBEMAP_BACK }; virtual RID texture_create()=0; - RID texture_create_from_image(const Image& p_image,uint32_t p_flags=TEXTURE_FLAGS_DEFAULT); // helper + RID texture_create_from_image(const Image& p_image,uint32_t p_flags=TEXTURE_FLAGS_DEFAULT); // helper virtual void texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags=TEXTURE_FLAGS_DEFAULT)=0; virtual void texture_set_data(RID p_texture,const Image& p_image,CubeMapSide p_cube_side=CUBEMAP_LEFT)=0; virtual Image texture_get_data(RID p_texture,CubeMapSide p_cube_side=CUBEMAP_LEFT) const=0; @@ -237,7 +237,7 @@ public: FIXED_MATERIAL_PARAM_SPECULAR_EXP, FIXED_MATERIAL_PARAM_GLOW, FIXED_MATERIAL_PARAM_NORMAL, - FIXED_MATERIAL_PARAM_SHADE_PARAM, + FIXED_MATERIAL_PARAM_SHADE_PARAM, FIXED_MATERIAL_PARAM_MAX }; @@ -299,15 +299,15 @@ public: ARRAY_VERTEX=0, ARRAY_NORMAL=1, ARRAY_TANGENT=2, - ARRAY_COLOR=3, - ARRAY_TEX_UV=4, + ARRAY_COLOR=3, + ARRAY_TEX_UV=4, ARRAY_TEX_UV2=5, ARRAY_BONES=6, - ARRAY_WEIGHTS=7, + ARRAY_WEIGHTS=7, ARRAY_INDEX=8, ARRAY_MAX=9 - }; - + }; + enum ArrayFormat { /* ARRAY FORMAT FLAGS */ ARRAY_FORMAT_VERTEX=1<<ARRAY_VERTEX, // mandatory @@ -319,8 +319,8 @@ public: ARRAY_FORMAT_BONES=1<<ARRAY_BONES, ARRAY_FORMAT_WEIGHTS=1<<ARRAY_WEIGHTS, ARRAY_FORMAT_INDEX=1<<ARRAY_INDEX, - }; - + }; + enum PrimitiveType { PRIMITIVE_POINTS=0, PRIMITIVE_LINES=1, @@ -330,10 +330,10 @@ public: PRIMITIVE_TRIANGLE_STRIP=5, PRIMITIVE_TRIANGLE_FAN=6, PRIMITIVE_MAX=7, - }; + }; virtual RID mesh_create()=0; - + virtual void mesh_add_surface(RID p_mesh,PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes=Array(),bool p_alpha_sort=false)=0; virtual Array mesh_get_surface_arrays(RID p_mesh,int p_surface) const=0; virtual Array mesh_get_surface_morph_arrays(RID p_mesh,int p_surface) const=0; @@ -358,7 +358,7 @@ public: virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const=0; virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const=0; virtual PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const=0; - + virtual void mesh_remove_surface(RID p_mesh,int p_index)=0; virtual int mesh_get_surface_count(RID p_mesh) const=0; @@ -405,9 +405,9 @@ public: /* PARTICLES API */ - + virtual RID particles_create()=0; - + enum ParticleVariable { PARTICLE_LIFETIME, PARTICLE_SPREAD, @@ -425,16 +425,16 @@ public: PARTICLE_HEIGHT_SPEED_SCALE, PARTICLE_VAR_MAX }; - + virtual void particles_set_amount(RID p_particles, int p_amount)=0; virtual int particles_get_amount(RID p_particles) const=0; - + virtual void particles_set_emitting(RID p_particles, bool p_emitting)=0; virtual bool particles_is_emitting(RID p_particles) const=0; - + virtual void particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility)=0; virtual AABB particles_get_visibility_aabb(RID p_particles) const=0; - + virtual void particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents)=0; virtual Vector3 particles_get_emission_half_extents(RID p_particles) const=0; @@ -443,13 +443,13 @@ public: virtual void particles_set_emission_points(RID p_particles, const DVector<Vector3>& p_points)=0; virtual DVector<Vector3> particles_get_emission_points(RID p_particles) const=0; - + virtual void particles_set_gravity_normal(RID p_particles, const Vector3& p_normal)=0; virtual Vector3 particles_get_gravity_normal(RID p_particles) const=0; - + virtual void particles_set_variable(RID p_particles, ParticleVariable p_variable,float p_value)=0; virtual float particles_get_variable(RID p_particles, ParticleVariable p_variable) const=0; - + virtual void particles_set_randomness(RID p_particles, ParticleVariable p_variable,float p_randomness)=0; virtual float particles_get_randomness(RID p_particles, ParticleVariable p_variable) const=0; @@ -458,7 +458,7 @@ public: virtual void particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos)=0; virtual float particles_get_color_phase_pos(RID p_particles, int p_phase) const=0; - + virtual void particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color)=0; virtual Color particles_get_color_phase_color(RID p_particles, int p_phase) const=0; @@ -473,7 +473,7 @@ public: virtual void particles_set_material(RID p_particles, RID p_material,bool p_owned=false)=0; virtual RID particles_get_material(RID p_particles) const=0; - + virtual void particles_set_height_from_velocity(RID p_particles, bool p_enable)=0; virtual bool particles_has_height_from_velocity(RID p_particles) const=0; @@ -481,20 +481,20 @@ public: virtual bool particles_is_using_local_coordinates(RID p_particles) const=0; /* Light API */ - + enum LightType { LIGHT_DIRECTIONAL, LIGHT_OMNI, LIGHT_SPOT }; - enum LightColor { + enum LightColor { LIGHT_COLOR_DIFFUSE, LIGHT_COLOR_SPECULAR }; - + enum LightParam { - + LIGHT_PARAM_SPOT_ATTENUATION, LIGHT_PARAM_SPOT_ANGLE, LIGHT_PARAM_RADIUS, @@ -512,20 +512,20 @@ public: virtual LightType light_get_type(RID p_light) const=0; virtual void light_set_color(RID p_light,LightColor p_type, const Color& p_color)=0; - virtual Color light_get_color(RID p_light,LightColor p_type) const=0; + virtual Color light_get_color(RID p_light,LightColor p_type) const=0; virtual void light_set_shadow(RID p_light,bool p_enabled)=0; - virtual bool light_has_shadow(RID p_light) const=0; - + virtual bool light_has_shadow(RID p_light) const=0; + virtual void light_set_volumetric(RID p_light,bool p_enabled)=0; - virtual bool light_is_volumetric(RID p_light) const=0; - + virtual bool light_is_volumetric(RID p_light) const=0; + virtual void light_set_projector(RID p_light,RID p_texture)=0; virtual RID light_get_projector(RID p_light) const=0; - + virtual void light_set_param(RID p_light, LightParam p_var, float p_value)=0; virtual float light_get_param(RID p_light, LightParam p_var) const=0; - + enum LightOp { LIGHT_OPERATOR_ADD, @@ -567,26 +567,26 @@ public: virtual float light_directional_get_shadow_param(RID p_light,LightDirectionalShadowParam p_param) const=0; //@TODO fallof model and all that stuff - + /* SKELETON API */ - + virtual RID skeleton_create()=0; virtual void skeleton_resize(RID p_skeleton,int p_bones)=0; virtual int skeleton_get_bone_count(RID p_skeleton) const=0; virtual void skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform)=0; virtual Transform skeleton_bone_get_transform(RID p_skeleton,int p_bone)=0; - + /* ROOM API */ virtual RID room_create()=0; virtual void room_set_bounds(RID p_room, const BSP_Tree& p_bounds)=0; virtual BSP_Tree room_get_bounds(RID p_room) const=0; - + /* PORTAL API */ // portals are only (x/y) points, forming a convex shape, which its clockwise // order points outside. (z is 0); - + virtual RID portal_create()=0; virtual void portal_set_shape(RID p_portal, const Vector<Point2>& p_shape)=0; virtual Vector<Point2> portal_get_shape(RID p_portal) const=0; @@ -645,11 +645,11 @@ public: virtual int baked_light_sampler_get_resolution(RID p_baked_light_sampler) const=0; /* CAMERA API */ - + virtual RID camera_create()=0; virtual void camera_set_perspective(RID p_camera,float p_fovy_degrees, float p_z_near, float p_z_far)=0; virtual void camera_set_orthogonal(RID p_camera,float p_size, float p_z_near, float p_z_far)=0; - virtual void camera_set_transform(RID p_camera,const Transform& p_transform)=0; + virtual void camera_set_transform(RID p_camera,const Transform& p_transform)=0; virtual void camera_set_visible_layers(RID p_camera,uint32_t p_layers)=0; virtual uint32_t camera_get_visible_layers(RID p_camera) const=0; @@ -711,14 +711,14 @@ public: struct ViewportRect { - + int x,y,width,height; ViewportRect() { x=y=width=height=0; } }; - + virtual void viewport_set_rect(RID p_viewport,const ViewportRect& p_rect)=0; virtual ViewportRect viewport_get_rect(RID p_viewport) const=0; - + virtual void viewport_set_hide_scenario(RID p_viewport,bool p_hide)=0; virtual void viewport_set_hide_canvas(RID p_viewport,bool p_hide)=0; virtual void viewport_set_disable_environment(RID p_viewport,bool p_disable)=0; @@ -845,7 +845,7 @@ public: - virtual RID scenario_create()=0; + virtual RID scenario_create()=0; enum ScenarioDebugMode { SCENARIO_DEBUG_DISABLED, @@ -863,9 +863,9 @@ public: /* INSTANCING API */ - + enum InstanceType { - + INSTANCE_NONE, INSTANCE_MESH, INSTANCE_MULTIMESH, @@ -879,7 +879,7 @@ public: INSTANCE_GEOMETRY_MASK=(1<<INSTANCE_MESH)|(1<<INSTANCE_MULTIMESH)|(1<<INSTANCE_IMMEDIATE)|(1<<INSTANCE_PARTICLES) }; - + virtual RID instance_create2(RID p_base, RID p_scenario); @@ -900,17 +900,17 @@ public: virtual void instance_set_transform(RID p_instance, const Transform& p_transform)=0; virtual Transform instance_get_transform(RID p_instance) const=0; - + virtual void instance_attach_object_instance_ID(RID p_instance,uint32_t p_ID)=0; virtual uint32_t instance_get_object_instance_ID(RID p_instance) const=0; virtual void instance_set_morph_target_weight(RID p_instance,int p_shape, float p_weight)=0; virtual float instance_get_morph_target_weight(RID p_instance,int p_shape) const=0; - + virtual void instance_attach_skeleton(RID p_instance,RID p_skeleton)=0; virtual RID instance_get_skeleton(RID p_instance) const=0; - + virtual void instance_set_exterior( RID p_instance, bool p_enabled )=0; virtual bool instance_is_exterior( RID p_instance) const=0; @@ -1152,10 +1152,10 @@ public: RID material_2d_get(bool p_shaded, bool p_transparent, bool p_cut_alpha,bool p_opaque_prepass); - + /* TESTING */ - + virtual RID get_test_cube()=0; virtual RID get_test_texture(); @@ -1177,7 +1177,7 @@ public: virtual bool has_feature(Features p_feature) const=0; - VisualServer(); + VisualServer(); virtual ~VisualServer(); }; diff --git a/tools/collada/collada.cpp b/tools/collada/collada.cpp index 07da72718e..8f40ec1469 100644 --- a/tools/collada/collada.cpp +++ b/tools/collada/collada.cpp @@ -1650,7 +1650,7 @@ Collada::Node* Collada::_parse_visual_scene_node(XMLParser& parser) { String name; - String id = parser.get_attribute_value_safe("id"); + String id = parser.get_attribute_value_safe("id"); bool found_name=false; diff --git a/tools/docdump/doc_dump.cpp b/tools/docdump/doc_dump.cpp index f8e035e3fa..fbf13f9e8f 100644 --- a/tools/docdump/doc_dump.cpp +++ b/tools/docdump/doc_dump.cpp @@ -248,7 +248,7 @@ void DocDump::dump(const String& p_file) { } - _write_string(f,1,"</methods>"); + _write_string(f,1,"</methods>"); List<MethodInfo> signal_list; ObjectTypeDB::get_signal_list(name,&signal_list,true); diff --git a/tools/editor/animation_editor.cpp b/tools/editor/animation_editor.cpp index 668a135bc8..091bc701cc 100644 --- a/tools/editor/animation_editor.cpp +++ b/tools/editor/animation_editor.cpp @@ -479,7 +479,7 @@ public: } break; } - + return false; @@ -2207,7 +2207,7 @@ void AnimationKeyEditor::_track_editor_input_event(const InputEvent& p_input) { if (ofsx < add_key_icon->get_width()) { - Animation::TrackType tt = animation->track_get_type(idx); + Animation::TrackType tt = animation->track_get_type(idx); float pos = timeline_pos; int existing = animation->track_find_key(idx,pos,true); @@ -3111,7 +3111,7 @@ void AnimationKeyEditor::_query_insert(const InsertData& p_id) { if (p_id.track_idx==-1) { if (bool(EDITOR_DEF("animation/confirm_insert_track",true))) { - //potential new key, does not exist + //potential new key, does not exist if (insert_data.size()==1) insert_confirm->set_text("Create NEW track for "+p_id.query+" and insert key?"); else @@ -3744,7 +3744,7 @@ void AnimationKeyEditor::_bind_methods() { ObjectTypeDB::bind_method(_MD("_animation_loop_changed"),&AnimationKeyEditor::_animation_loop_changed); - ObjectTypeDB::bind_method(_MD("_animation_len_changed"),&AnimationKeyEditor::_animation_len_changed); + ObjectTypeDB::bind_method(_MD("_animation_len_changed"),&AnimationKeyEditor::_animation_len_changed); ObjectTypeDB::bind_method(_MD("_create_value_item"),&AnimationKeyEditor::_create_value_item); ObjectTypeDB::bind_method(_MD("_pane_drag"),&AnimationKeyEditor::_pane_drag); diff --git a/tools/editor/animation_editor.h b/tools/editor/animation_editor.h index cd22dc3106..413c73b4b9 100644 --- a/tools/editor/animation_editor.h +++ b/tools/editor/animation_editor.h @@ -212,7 +212,7 @@ class AnimationKeyEditor : public VBoxContainer { ConfirmationDialog *scale_dialog; SpinBox *scale; - PropertyEditor *key_editor; + PropertyEditor *key_editor; SceneTreeDialog *call_select; diff --git a/tools/editor/call_dialog.cpp b/tools/editor/call_dialog.cpp index edcd7371f2..c5e9cdfa0d 100644 --- a/tools/editor/call_dialog.cpp +++ b/tools/editor/call_dialog.cpp @@ -39,22 +39,22 @@ class CallDialogParams : public Object { public: bool _set(const StringName& p_name, const Variant& p_value) { - + values[p_name]=p_value; return true; } - + bool _get(const StringName& p_name,Variant &r_ret) const { - + if (values.has(p_name)) { r_ret=values[p_name]; return true; } return false; } - + void _get_property_list( List<PropertyInfo> *p_list) const { - + for(int i=0;i<method.arguments.size();i++) p_list->push_back(method.arguments[i]); } @@ -67,9 +67,9 @@ public: void CallDialog::_notification(int p_what) { - + if (p_what==NOTIFICATION_READY) { - + call->connect("pressed", this,"_call"); cancel->connect("pressed", this,"_cancel"); //filter->get_path()->connect("text_changed", this,"_text_changed"); @@ -86,35 +86,35 @@ void CallDialog::_notification(int p_what) { } if (p_what==NOTIFICATION_DRAW) { - + RID ci = get_canvas_item(); - get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size())); - } + get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size())); + } } void CallDialog::_call() { - + if (!tree->get_selected()) return; - + TreeItem* item=tree->get_selected(); ERR_FAIL_COND(!item); int idx=item->get_metadata(0); ERR_FAIL_INDEX(idx,methods.size()); MethodInfo &m = methods[idx]; - + Variant args[VARIANT_ARG_MAX]; - + for(int i=0;i<VARIANT_ARG_MAX;i++) { - + if (i>=m.arguments.size()) continue; - + if (call_params->values.has(m.arguments[i].name)) args[i]=call_params->values[m.arguments[i].name]; } - + Variant ret = object->call(m.name,args[0],args[1],args[2],args[3],args[4]); if (ret.get_type()!=Variant::NIL) return_value->set_text(ret); @@ -123,7 +123,7 @@ void CallDialog::_call() { } void CallDialog::_cancel() { - + hide(); } @@ -132,23 +132,23 @@ void CallDialog::_item_selected() { TreeItem* item=tree->get_selected(); ERR_FAIL_COND(!item); - + if (item->get_metadata(0).get_type()==Variant::NIL) { - + call->set_disabled(true); return; } - + call->set_disabled(false); - + int idx=item->get_metadata(0); ERR_FAIL_INDEX(idx,methods.size()); - + MethodInfo &m = methods[idx]; call_params->values.clear(); call_params->method=m; - + property_editor->edit(call_params); property_editor->update_tree(); @@ -156,38 +156,38 @@ void CallDialog::_item_selected() { } void CallDialog::_update_method_list() { - + tree->clear(); if (!object) return; - + TreeItem *root = tree->create_item(); - + List<MethodInfo> method_list; object->get_method_list(&method_list); method_list.sort(); methods.clear(); - + List<String> inheritance_list; - + String type = object->get_type(); - - while(type!="") { + + while(type!="") { inheritance_list.push_back( type ); type=ObjectTypeDB::type_inherits_from(type); } - + TreeItem *selected_item=NULL; - + for(int i=0;i<inheritance_list.size();i++) { - + String type=inheritance_list[i]; String parent_type=ObjectTypeDB::type_inherits_from(type); TreeItem *type_item=NULL; - + List<MethodInfo>::Element *N,*E=method_list.front(); - + while(E) { N=E->next(); @@ -196,38 +196,38 @@ void CallDialog::_update_method_list() { E=N; continue; } - + if (!type_item) { type_item=tree->create_item(root); type_item->set_text(0,type); if (has_icon(type,"EditorIcons")) type_item->set_icon(0,get_icon(type,"EditorIcons")); } - + TreeItem *method_item = tree->create_item(type_item); method_item->set_text(0,E->get().name); method_item->set_metadata(0,methods.size()); if (E->get().name==selected) selected_item=method_item; methods.push_back( E->get() ); - + method_list.erase(E); E=N; } } - - - + + + if (selected_item) selected_item->select(0); } void CallDialog::_bind_methods() { - + ObjectTypeDB::bind_method("_call",&CallDialog::_call); ObjectTypeDB::bind_method("_cancel",&CallDialog::_cancel); ObjectTypeDB::bind_method("_item_selected", &CallDialog::_item_selected); - + } void CallDialog::set_object(Object *p_object,StringName p_selected) { @@ -252,22 +252,22 @@ CallDialog::CallDialog() { call->set_anchor( MARGIN_RIGHT, ANCHOR_END ); call->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); call->set_begin( Point2( 70, 29 ) ); - call->set_end( Point2( 15, 15 ) ); + call->set_end( Point2( 15, 15 ) ); call->set_text("Call"); - + add_child(call); - + cancel = memnew( Button ); cancel->set_anchor( MARGIN_TOP, ANCHOR_END ); cancel->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); cancel->set_begin( Point2( 15, 29 ) ); - cancel->set_end( Point2( 70, 15 ) ); + cancel->set_end( Point2( 70, 15 ) ); cancel->set_text("Close"); - + add_child(cancel); - + tree = memnew( Tree ); - + tree->set_anchor( MARGIN_RIGHT, ANCHOR_RATIO ); tree->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); tree->set_begin( Point2( 20,50 ) ); @@ -275,60 +275,60 @@ CallDialog::CallDialog() { tree->set_margin(MARGIN_RIGHT, 0.5 ); tree->set_select_mode( Tree::SELECT_ROW ); add_child(tree); - + tree->connect("item_selected", this,"_item_selected"); tree->set_hide_root(true); - + property_editor = memnew( PropertyEditor ); - + property_editor->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, 15 ); property_editor->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 50 ); property_editor->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 ); property_editor->set_anchor_and_margin( MARGIN_BOTTOM, ANCHOR_END, 90 ); property_editor->get_scene_tree()->set_hide_root( true ); property_editor->hide_top_label(); - + add_child(property_editor); method_label = memnew( Label ); method_label->set_pos( Point2( 15,25) ); method_label->set_text("Method List:"); - + add_child(method_label); - + Label *label = memnew( Label ); label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 ); label->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 25 ); label->set_text("Arguments:"); - + add_child(label); - + return_label = memnew( Label ); return_label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 ); return_label->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, 85 ); return_label->set_text("Return:"); - + add_child(return_label); - + return_value = memnew( LineEdit ); return_value->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 ); - return_value->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, 15 ); + return_value->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, 15 ); return_value->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, 65 ); - + add_child(return_value); - + /* label = memnew( Label ); label->set_anchor( MARGIN_TOP, ANCHOR_END ); label->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); - + label->set_begin( Point2( 15,54) ); label->set_end( Point2( 16,44) ); label->set_text("Parameters:"); - + add_child(label); */ - + call_params = memnew( CallDialogParams ); set_as_toplevel(true); } diff --git a/tools/editor/call_dialog.h b/tools/editor/call_dialog.h index 2d04e7b6cd..a2ca925ff1 100644 --- a/tools/editor/call_dialog.h +++ b/tools/editor/call_dialog.h @@ -43,39 +43,39 @@ class CallDialogParams; class CallDialog : public Popup { - + OBJ_TYPE( CallDialog, Popup ); - + Label* method_label; Tree *tree; Button *call; Button *cancel; - + CallDialogParams *call_params; PropertyEditor *property_editor; - + Label *return_label; LineEdit *return_value; - Object *object; + Object *object; StringName selected; - + Vector<MethodInfo> methods; - - + + void _item_selected(); void _update_method_list(); void _call(); void _cancel(); - + protected: - static void _bind_methods(); + static void _bind_methods(); void _notification(int p_what); public: - + void set_object(Object *p_object,StringName p_selected=""); - - CallDialog(); + + CallDialog(); ~CallDialog(); }; diff --git a/tools/editor/code_editor.cpp b/tools/editor/code_editor.cpp index f7d335fba3..968d02dfa5 100644 --- a/tools/editor/code_editor.cpp +++ b/tools/editor/code_editor.cpp @@ -85,7 +85,7 @@ void FindReplaceDialog::popup_search() { skip->hide(); popup_centered(Point2(300,190)); get_ok()->set_text("Find"); - search_text->grab_focus(); + search_text->grab_focus(); if (text_edit->is_selection_active() && ( text_edit->get_selection_from_line() == text_edit->get_selection_to_line())) { search_text->set_text( text_edit->get_selection_text() ); @@ -544,7 +544,7 @@ void CodeTextEditor::set_error(const String& p_error) { } void CodeTextEditor::_on_settings_change() { - + // FONTS String editor_font = EDITOR_DEF("text_editor/font", ""); bool font_overrode = false; @@ -557,8 +557,8 @@ void CodeTextEditor::_on_settings_change() { } if(!font_overrode) text_editor->add_font_override("font",get_font("source","Fonts")); - - // AUTO BRACE COMPLETION + + // AUTO BRACE COMPLETION text_editor->set_auto_brace_completion( EDITOR_DEF("text_editor/auto_brace_complete", true) ); diff --git a/tools/editor/code_editor.h b/tools/editor/code_editor.h index 5ed7ce9052..e28517c601 100644 --- a/tools/editor/code_editor.h +++ b/tools/editor/code_editor.h @@ -55,7 +55,7 @@ public: void set_text_editor(TextEdit *p_text_editor); - GotoLineDialog(); + GotoLineDialog(); }; diff --git a/tools/editor/connections_dialog.cpp b/tools/editor/connections_dialog.cpp index 1e530b21c2..962062ae01 100644 --- a/tools/editor/connections_dialog.cpp +++ b/tools/editor/connections_dialog.cpp @@ -30,7 +30,7 @@ #include "scene/gui/label.h" - + #include "print_string.h" #include "editor_settings.h" @@ -91,11 +91,11 @@ public: }; void ConnectDialog::_notification(int p_what) { - + if (p_what==NOTIFICATION_DRAW) { - + RID ci = get_canvas_item(); - get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size())); + get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size())); } if (p_what==NOTIFICATION_ENTER_TREE) { @@ -104,7 +104,7 @@ void ConnectDialog::_notification(int p_what) { } void ConnectDialog::_tree_node_selected() { - + //dst_method_list->get_popup()->clear(); Node *current=tree->get_selected(); @@ -151,17 +151,17 @@ void ConnectDialog::_tree_node_selected() { } void ConnectDialog::_dst_method_list_selected(int p_idx) { - + //dst_method->set_text( dst_method_list->get_popup()->get_item_text(p_idx)); } void ConnectDialog::edit(Node *p_node) { - + node=p_node; - + //dst_method_list->get_popup()->clear(); - - + + tree->set_selected(NULL); tree->set_marked(node,true); dst_path->set_text(""); @@ -173,7 +173,7 @@ void ConnectDialog::edit(Node *p_node) { } void ConnectDialog::ok_pressed() { - + if (dst_method->get_text()=="") { error->set_text("Method in target Node must be specified!"); @@ -185,13 +185,13 @@ void ConnectDialog::ok_pressed() { } void ConnectDialog::_cancel_pressed() { - + hide(); } NodePath ConnectDialog::get_dst_path() const { - + return dst_path->get_text(); } @@ -207,11 +207,11 @@ bool ConnectDialog::get_oneshot() const { } StringName ConnectDialog::get_dst_method() const { - + String txt=dst_method->get_text(); if (txt.find("(")!=-1) txt=txt.left( txt.find("(")).strip_edges(); - return txt; + return txt; } @@ -280,7 +280,7 @@ void ConnectDialog::set_dst_method(const StringName& p_method) { } void ConnectDialog::_bind_methods() { - + //ObjectTypeDB::bind_method("_ok",&ConnectDialog::_ok_pressed); ObjectTypeDB::bind_method("_cancel",&ConnectDialog::_cancel_pressed); //ObjectTypeDB::bind_method("_dst_method_list_selected",&ConnectDialog::_dst_method_list_selected); @@ -293,17 +293,17 @@ void ConnectDialog::_bind_methods() { } ConnectDialog::ConnectDialog() { - + int margin = get_constant("margin","Dialogs"); int button_margin = get_constant("button_margin","Dialogs"); - - + + Label * label = memnew( Label ); label->set_pos( Point2( 8,11) ); label->set_text("Connect To Node:"); - - add_child(label); + + add_child(label); label = memnew( Label ); label->set_anchor( MARGIN_LEFT, ANCHOR_RATIO ); label->set_pos( Point2( 0.5,11) ); @@ -379,7 +379,7 @@ ConnectDialog::ConnectDialog() { label->set_begin( Point2( 8,124) ); label->set_end( Point2( 15,99) ); label->set_text("Path To Node:"); - + add_child(label); dst_path = memnew(LineEdit); @@ -390,11 +390,11 @@ ConnectDialog::ConnectDialog() { dst_path->set_end( Point2( 15,80 ) ); add_child(dst_path); - + label = memnew( Label ); label->set_anchor( MARGIN_TOP, ANCHOR_END ); label->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - label->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); + label->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); label->set_begin( Point2( 8,78 ) ); label->set_end( Point2( 15,52 ) ); label->set_text("Method In Node:"); @@ -420,7 +420,7 @@ ConnectDialog::ConnectDialog() { dst_method_list->set_anchor( MARGIN_RIGHT, ANCHOR_END ); dst_method_list->set_anchor( MARGIN_LEFT, ANCHOR_END ); dst_method_list->set_anchor( MARGIN_TOP, ANCHOR_END ); - dst_method_list->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); + dst_method_list->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); dst_method_list->set_begin( Point2( 70,59) ); dst_method_list->set_end( Point2( 15,39 ) ); */ @@ -446,14 +446,14 @@ ConnectDialog::ConnectDialog() { realtime->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); realtime->set_anchor( MARGIN_RIGHT, ANCHOR_END ); realtime->set_begin( Point2( 120, button_margin-10 ) ); - realtime->set_end( Point2( 80, margin ) ); + realtime->set_end( Point2( 80, margin ) ); realtime->set_text("Realtime"); add_child(realtime); */ - - + + // dst_method_list->get_popup()->connect("item_pressed", this,"_dst_method_list_selected"); tree->connect("node_selected", this,"_tree_node_selected"); @@ -468,8 +468,8 @@ ConnectDialog::ConnectDialog() { // error->get_cancel()->set_text("Close"); - - + + } @@ -481,21 +481,21 @@ ConnectDialog::~ConnectDialog() void ConnectionsDialog::_notification(int p_what) { - + if (p_what==NOTIFICATION_DRAW) { - + RID ci = get_canvas_item(); - get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size())); - } + get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size())); + } } void ConnectionsDialog::_close() { - - hide(); + + hide(); } void ConnectionsDialog::_connect() { - + TreeItem *it = tree->get_selected(); ERR_FAIL_COND(!it); String signal=it->get_metadata(0).operator Dictionary()["name"]; @@ -534,7 +534,7 @@ void ConnectionsDialog::_connect() { void ConnectionsDialog::ok_pressed() { - + TreeItem *item = tree->get_selected(); if (!item) { @@ -585,31 +585,31 @@ void ConnectionsDialog::ok_pressed() { } /* void ConnectionsDialog::_remove() { - + if (!tree->get_selected()) return; - + TreeItem *selected=tree->get_selected(); if (!selected) return; - + Dictionary meta=selected->get_metadata(0); - + remove_confirm->set_text(String()+"Remove Connection \""+meta["from_event"].operator String()+"\" ?"); remove_confirm->popup_centered(Size2(340,80)); } */ /* void ConnectionsDialog::_remove_confirm() { - + if (!tree->get_selected()) return; TreeItem *selected=tree->get_selected(); if (!selected) return; - + Dictionary meta=selected->get_metadata(0); - + undo_redo->create_action("Remove Subscription"); undo_redo->add_do_method(node,"unsubscribe_path_event",meta["from_event"].operator String(),meta["from_path"].operator NodePath(),meta["to_method"].operator String()); undo_redo->add_undo_method(node,"subscribe_path_event_persist",meta["from_event"].operator String(),meta["from_path"].operator NodePath(),meta["to_method"].operator String(),Array(),false); @@ -628,14 +628,14 @@ struct _ConnectionsDialogMethodInfoSort { }; void ConnectionsDialog::update_tree() { - + if (!is_visible()) return; //don't update if not visible, of course tree->clear(); - + if (!node) return; - + TreeItem *root=tree->create_item(); @@ -779,7 +779,7 @@ void ConnectionsDialog::update_tree() { } void ConnectionsDialog::set_node(Node* p_node) { - + node=p_node; update_tree(); } @@ -806,7 +806,7 @@ void ConnectionsDialog::_something_selected() { } void ConnectionsDialog::_bind_methods() { - + ObjectTypeDB::bind_method("_connect",&ConnectionsDialog::_connect); ObjectTypeDB::bind_method("_something_selected",&ConnectionsDialog::_something_selected); @@ -814,11 +814,11 @@ void ConnectionsDialog::_bind_methods() { // ObjectTypeDB::bind_method("_remove_confirm",&ConnectionsDialog::_remove_confirm); ObjectTypeDB::bind_method("update_tree",&ConnectionsDialog::update_tree); - + } ConnectionsDialog::ConnectionsDialog(EditorNode *p_editor) { - + editor=p_editor; set_title("Edit Connections.."); set_hide_on_ok(false); @@ -828,28 +828,28 @@ ConnectionsDialog::ConnectionsDialog(EditorNode *p_editor) { set_child_rect(vbc); - + tree = memnew( Tree ); tree->set_columns(1); tree->set_select_mode(Tree::SELECT_ROW); tree->set_hide_root(true); vbc->add_margin_child("Connections:",tree,true); - + // add_child(tree); - + connect_dialog = memnew( ConnectDialog ); connect_dialog->set_as_toplevel(true); add_child(connect_dialog); - + remove_confirm = memnew( ConfirmationDialog ); remove_confirm->set_as_toplevel(true); add_child(remove_confirm); - - /* + + /* node_only->set_anchor( MARGIN_TOP, ANCHOR_END ); node_only->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); node_only->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - + node_only->set_begin( Point2( 20,51) ); node_only->set_end( Point2( 10,44) ); */ @@ -859,7 +859,7 @@ ConnectionsDialog::ConnectionsDialog(EditorNode *p_editor) { connect_dialog->connect("connected", this,"_connect"); tree->connect("item_selected", this,"_something_selected"); get_cancel()->set_text("Close"); - + } diff --git a/tools/editor/connections_dialog.h b/tools/editor/connections_dialog.h index d5e228e799..575bcf54d7 100644 --- a/tools/editor/connections_dialog.h +++ b/tools/editor/connections_dialog.h @@ -47,9 +47,9 @@ class ConnectDialogBinds; class ConnectDialog : public ConfirmationDialog { - + OBJ_TYPE( ConnectDialog, ConfirmationDialog ); - + ConfirmationDialog *error; LineEdit *dst_path; @@ -69,34 +69,34 @@ class ConnectDialog : public ConfirmationDialog { void _dst_method_list_selected(int p_idx); void _add_bind(); void _remove_bind(); - + protected: void _notification(int p_what); - static void _bind_methods(); + static void _bind_methods(); public: - + bool get_make_callback() { return !make_callback->is_hidden() && make_callback->is_pressed(); } NodePath get_dst_path() const; - StringName get_dst_method() const; + StringName get_dst_method() const; bool get_deferred() const; bool get_oneshot() const; Vector<Variant> get_binds() const; void set_dst_method(const StringName& p_method); void set_dst_node(Node* p_node); - + // Button *get_ok() { return ok; } // Button *get_cancel() { return cancel; } void edit(Node *p_node); - + ConnectDialog(); ~ConnectDialog(); - + }; class ConnectionsDialog : public ConfirmationDialog { - + OBJ_TYPE( ConnectionsDialog , ConfirmationDialog ); EditorNode *editor; @@ -104,7 +104,7 @@ class ConnectionsDialog : public ConfirmationDialog { Tree *tree; ConfirmationDialog *remove_confirm; ConnectDialog *connect_dialog; - + void update_tree(); void _close(); @@ -113,20 +113,20 @@ class ConnectionsDialog : public ConfirmationDialog { UndoRedo *undo_redo; protected: - + virtual void ok_pressed(); void _notification(int p_what); static void _bind_methods(); public: - + void set_undoredo(UndoRedo *p_undo_redo) { undo_redo=p_undo_redo; } void set_node(Node* p_node); String get_selected_type(); - + ConnectionsDialog(EditorNode *p_editor=NULL); ~ConnectionsDialog(); - + }; #endif diff --git a/tools/editor/create_dialog.cpp b/tools/editor/create_dialog.cpp index 23b8cad9ce..35688917fb 100644 --- a/tools/editor/create_dialog.cpp +++ b/tools/editor/create_dialog.cpp @@ -337,116 +337,116 @@ CreateDialog::CreateDialog() { //old create dialog, disabled void CreateDialog::_notification(int p_what) { - + if (p_what==NOTIFICATION_READY) { connect("confirmed",this,"_create"); update_tree(); } if (p_what==NOTIFICATION_DRAW) { - + //RID ci = get_canvas_item(); //get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size())); - } + } } void CreateDialog::_create() { - + if (tree->get_selected()) emit_signal("create"); hide(); } void CreateDialog::_cancel() { - + hide(); } void CreateDialog::_text_changed(String p_text) { - + update_tree(); } void CreateDialog::add_type(const String& p_type,HashMap<String,TreeItem*>& p_types,TreeItem *p_root) { - + if (p_types.has(p_type)) return; if (!ObjectTypeDB::is_type(p_type,base) || p_type==base) return; - + String inherits=ObjectTypeDB::type_inherits_from(p_type); - + TreeItem *parent=p_root; - + if (inherits.length()) { - + if (!p_types.has(inherits)) { - + add_type(inherits,p_types,p_root); } - + if (p_types.has(inherits) ) - parent=p_types[inherits]; - } - + parent=p_types[inherits]; + } + TreeItem *item = tree->create_item(parent); item->set_text(0,p_type); if (!ObjectTypeDB::can_instance(p_type)) { item->set_custom_color(0, Color(0.5,0.5,0.5) ); item->set_selectable(0,false); } - - + + if (has_icon(p_type,"EditorIcons")) { - + item->set_icon(0, get_icon(p_type,"EditorIcons")); } - + p_types[p_type]=item; } void CreateDialog::update_tree() { tree->clear(); - + List<String> type_list; - ObjectTypeDB::get_type_list(&type_list); - + ObjectTypeDB::get_type_list(&type_list); + HashMap<String,TreeItem*> types; - + TreeItem *root = tree->create_item(); - + root->set_text(0,base); List<String>::Element *I=type_list.front(); - + for(;I;I=I->next()) { - - + + String type=I->get(); - + if (!ObjectTypeDB::can_instance(type)) continue; // cant create what can't be instanced if (filter->get_text()=="") add_type(type,types,root); else { - + bool found=false; String type=I->get(); - while(type!="" && ObjectTypeDB::is_type(type,base) && type!=base) { + while(type!="" && ObjectTypeDB::is_type(type,base) && type!=base) { if (type.findn(filter->get_text())!=-1) { - + found=true; break; } - + type=ObjectTypeDB::type_inherits_from(type); } - + if (found) add_type(I->get(),types,root); @@ -528,12 +528,12 @@ Object *CreateDialog::instance_selected() { void CreateDialog::_bind_methods() { - + ObjectTypeDB::bind_method("_create",&CreateDialog::_create); ObjectTypeDB::bind_method("_cancel",&CreateDialog::_cancel); ObjectTypeDB::bind_method("_text_changed", &CreateDialog::_text_changed); ADD_SIGNAL( MethodInfo("create")); - + } @@ -547,7 +547,7 @@ void CreateDialog::set_base_type(const String& p_base) { return; base=p_base; if (is_inside_scene()) - update_tree(); + update_tree(); } String CreateDialog::get_base_type() const { @@ -563,14 +563,14 @@ CreateDialog::CreateDialog() { set_child_rect(vbc); get_ok()->set_text("Create"); - + tree = memnew( Tree ); vbc->add_margin_child("Type:",tree,true); //tree->set_hide_root(true); - - filter = memnew( LineEdit ); + + filter = memnew( LineEdit ); vbc->add_margin_child("Filter:",filter); - + base="Node"; set_as_toplevel(true); diff --git a/tools/editor/create_dialog.h b/tools/editor/create_dialog.h index 6f959fd467..a46ff5ae06 100644 --- a/tools/editor/create_dialog.h +++ b/tools/editor/create_dialog.h @@ -82,37 +82,37 @@ public: //old create dialog, disabled class CreateDialog : public ConfirmationDialog { - + OBJ_TYPE( CreateDialog, ConfirmationDialog ); - + Tree *tree; Button *create; Button *cancel; LineEdit *filter; - + void update_tree(); void _create(); void _cancel(); - void add_type(const String& p_type,HashMap<String,TreeItem*>& p_types,TreeItem + void add_type(const String& p_type,HashMap<String,TreeItem*>& p_types,TreeItem *p_root); - + String base; void _text_changed(String p_text); virtual void _post_popup() { tree->grab_focus();} protected: - static void _bind_methods(); + static void _bind_methods(); void _notification(int p_what); public: - + Object *instance_selected(); - + void set_base_type(const String& p_base); String get_base_type() const; - CreateDialog(); + CreateDialog(); ~CreateDialog(); }; diff --git a/tools/editor/editor_data.cpp b/tools/editor/editor_data.cpp index 6c1fc2ef05..f78ab93c30 100644 --- a/tools/editor/editor_data.cpp +++ b/tools/editor/editor_data.cpp @@ -261,13 +261,13 @@ EditorPlugin* EditorData::get_subeditor(Object *p_object) { } EditorPlugin* EditorData::get_editor(String p_name) { - + for(int i=0;i<editor_plugins.size();i++) { - + if (editor_plugins[i]->get_name()==p_name) return editor_plugins[i]; } - + return NULL; } diff --git a/tools/editor/editor_file_dialog.cpp b/tools/editor/editor_file_dialog.cpp index a9b23767f1..0e6cf3277a 100644 --- a/tools/editor/editor_file_dialog.cpp +++ b/tools/editor/editor_file_dialog.cpp @@ -590,7 +590,7 @@ void EditorFileDialog::update_file_list() { if (get_icon_func) { - + Ref<Texture> icon = get_icon_func(base_dir.plus_file(files.front()->get())); //ti->set_icon(0,icon); if (display_mode==DISPLAY_THUMBNAILS) { diff --git a/tools/editor/editor_file_system.cpp b/tools/editor/editor_file_system.cpp index ad59efc46f..05e8a559b7 100644 --- a/tools/editor/editor_file_system.cpp +++ b/tools/editor/editor_file_system.cpp @@ -463,7 +463,7 @@ void EditorFileSystem::scan() { filesystem=new_filesystem; new_filesystem=NULL; _update_scan_actions(); - scanning=false; + scanning=false; emit_signal("filesystem_changed"); emit_signal("sources_changed",sources_changed.size()>0); diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp index 39182bfd69..a1fe875287 100644 --- a/tools/editor/editor_import_export.cpp +++ b/tools/editor/editor_import_export.cpp @@ -671,7 +671,7 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func } break; //use default case EditorImportExport::IMAGE_ACTION_COMPRESS_RAM: { group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM; - } break; //use default + } break; //use default } String image_list_md5; diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 24df4544ec..b620e15670 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -205,8 +205,8 @@ void EditorNode::_notification(int p_what) { log->deinit(); // do not get messages anymore } if (p_what==NOTIFICATION_PROCESS) { - - //force the whole tree viewport + + //force the whole tree viewport #if 0 { Rect2 grect = scene_root_base->get_global_rect(); @@ -275,13 +275,13 @@ void EditorNode::_notification(int p_what) { } } - + } if (p_what==NOTIFICATION_ENTER_TREE) { //MessageQueue::get_singleton()->push_call(this,"_get_scene_metadata"); - get_tree()->set_editor_hint(true); + get_tree()->set_editor_hint(true); get_tree()->get_root()->set_as_audio_listener(false); get_tree()->get_root()->set_as_audio_listener_2d(false); get_tree()->set_auto_accept_quit(false); @@ -569,12 +569,12 @@ void EditorNode::save_resource_as(const Ref<Resource>& p_resource) { void EditorNode::_menu_option(int p_option) { - + _menu_option_confirm(p_option,false); } void EditorNode::_menu_confirm_current() { - + _menu_option_confirm(current_option,true); } @@ -583,27 +583,27 @@ void EditorNode::_dialog_display_file_error(String p_file,Error p_error) { if (p_error) { - + current_option=-1; //accept->"()->hide(); accept->get_ok()->set_text("I see.."); - + switch(p_error) { - + case ERR_FILE_CANT_WRITE: { accept->set_text("Can't open file for writing: "+p_file.extension()); } break; case ERR_FILE_UNRECOGNIZED: { - + accept->set_text("File format requested unknown: "+p_file.extension()); } break; default: { - + accept->set_text("Error Saving."); }break; } - + accept->popup_centered_minsize(); } @@ -1144,10 +1144,10 @@ void EditorNode::_import(const String &p_file) { } void EditorNode::_dialog_action(String p_file) { - + switch(current_option) { - + case RESOURCE_LOAD: { RES res = ResourceLoader::load(p_file); @@ -1162,7 +1162,7 @@ void EditorNode::_dialog_action(String p_file) { push_item(res.operator->() ); - } break; + } break; case FILE_NEW_INHERITED_SCENE: { @@ -1448,13 +1448,13 @@ void EditorNode::_dialog_action(String p_file) { } break; default: { //save scene? - + if (file->get_mode()==FileDialog::MODE_SAVE_FILE) { //_save_scene(p_file); _save_scene_with_preview(p_file); } - + } break; } } @@ -1548,13 +1548,13 @@ void EditorNode::_property_editor_forward() { if (editor_history.next()) _edit_current(); - + } void EditorNode::_property_editor_back() { - + if (editor_history.previous()) _edit_current(); - + } @@ -1584,7 +1584,7 @@ void EditorNode::_hide_top_editors() { } void EditorNode::_edit_current() { - + uint32_t current = editor_history.get_current(); Object *current_obj = current>0 ? ObjectDB::get_instance(current) : NULL; @@ -1596,7 +1596,7 @@ void EditorNode::_edit_current() { if (!current_obj) { - + scene_tree_dock->set_selected(NULL); property_editor->edit( NULL ); object_menu->set_disabled(true); @@ -1770,7 +1770,7 @@ void EditorNode::_resource_created() { } void EditorNode::_resource_selected(const RES& p_res,const String& p_property) { - + if (p_res.is_null()) return; @@ -1963,13 +1963,13 @@ void EditorNode::_cleanup_scene() { } } - + _update_title(); #endif } void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { - + //print_line("option "+itos(p_option)+" confirm "+itos(p_confirmed)); if (!p_confirmed) //this may be a hack.. current_option=(MenuOptions)p_option; @@ -1994,12 +1994,12 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { //_cleanup_scene(); - + } break; case FILE_NEW_INHERITED_SCENE: case FILE_OPEN_SCENE: { - - + + //print_tree(); file->set_mode(EditorFileDialog::MODE_OPEN_FILE); //not for now? @@ -2007,10 +2007,10 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { ResourceLoader::get_recognized_extensions_for_type("PackedScene",&extensions); file->clear_filters(); for(int i=0;i<extensions.size();i++) { - + file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); } - + //file->set_current_path(current_path); Node *scene = editor_data.get_edited_scene_root(); @@ -2019,7 +2019,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { }; file->set_title(p_option==FILE_OPEN_SCENE?"Open Scene":"Open Base Scene"); file->popup_centered_ratio(); - + } break; case FILE_QUICK_OPEN_SCENE: { @@ -2086,19 +2086,19 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { // fallthrough to save_as }; case FILE_SAVE_AS_SCENE: { - + Node *scene = editor_data.get_edited_scene_root(); - + if (!scene) { - + current_option=-1; //confirmation->get_cancel()->hide(); accept->get_ok()->set_text("I see.."); accept->set_text("This operation can't be done without a tree root."); accept->popup_centered_minsize(); - break; + break; } - + file->set_mode(EditorFileDialog::MODE_SAVE_FILE); bool relpaths = (scene->has_meta("__editor_relpaths__") && scene->get_meta("__editor_relpaths__").operator bool()); @@ -2111,7 +2111,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); } - + //file->set_current_path(current_path); if (scene->get_filename()!="") { file->set_current_path(scene->get_filename()); @@ -2132,7 +2132,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } file->popup_centered_ratio(); file->set_title("Save Scene As.."); - + } break; case FILE_SAVE_BEFORE_RUN: { @@ -2312,7 +2312,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; case FILE_QUIT: { - + if (!p_confirmed) { @@ -2326,7 +2326,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { _menu_option_confirm(RUN_STOP,true); get_tree()->quit(); - + } break; case FILE_EXTERNAL_OPEN_SCENE: { @@ -2535,13 +2535,13 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; case OBJECT_COPY_PARAMS: { - + editor_data.apply_changes_in_editors();; if (current) editor_data.copy_object_params(current); } break; case OBJECT_PASTE_PARAMS: { - + editor_data.apply_changes_in_editors();; if (current) editor_data.paste_object_params(current); @@ -2589,7 +2589,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; case OBJECT_CALL_METHOD: { - + editor_data.apply_changes_in_editors();; call_dialog->set_object(current); call_dialog->popup_centered_ratio(); @@ -2834,7 +2834,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; default: { - + if (p_option>=OBJECT_METHOD_BASE) { ERR_FAIL_COND(!current); @@ -2858,12 +2858,12 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } } - } + } } Control* EditorNode::get_viewport() { - + return viewport; } @@ -2908,7 +2908,7 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor) { if (p_editor->has_main_screen()) { - + ToolButton *tb = memnew( ToolButton ); tb->set_toggle_mode(true); tb->connect("pressed",singleton,"_editor_select",varray(singleton->main_editor_buttons.size())); @@ -3096,9 +3096,9 @@ void EditorNode::set_edited_scene(Node *p_scene) { if (get_editor_data().get_edited_scene_root()->get_parent()==scene_root) scene_root->remove_child(get_editor_data().get_edited_scene_root()); - } + } get_editor_data().set_edited_scene_root(p_scene); - + if (p_scene && p_scene->cast_to<Popup>()) p_scene->cast_to<Popup>()->show(); //show popups scene_tree_dock->set_edited_scene(p_scene); @@ -3667,7 +3667,7 @@ Error EditorNode::load_scene(const String& p_scene, bool p_ignore_broken_deps,bo if (p_set_inherited) { Ref<SceneState> state = sdata->get_state(); - state->set_path(lpath); + state->set_path(lpath); new_scene->set_scene_inherited_state(state); new_scene->set_filename(String()); //if (new_scene->get_scene_instance_state().is_valid()) @@ -3804,7 +3804,7 @@ void EditorNode::animation_editor_make_visible(bool p_visible) { if (p_visible) { - animation_editor->show(); + animation_editor->show(); animation_vb->get_parent_control()->minimum_size_changed(); //pd_anim->show(); top_split->set_collapsed(false); @@ -4226,7 +4226,7 @@ void EditorNode::_dock_popup_exit() { } void EditorNode::_dock_pre_popup(int p_which) { - + dock_popup_selected=p_which; } @@ -5866,7 +5866,7 @@ EditorNode::EditorNode() { - + call_dialog = memnew( CallDialog ); call_dialog->hide(); gui_base->add_child( call_dialog ); @@ -5919,7 +5919,7 @@ EditorNode::EditorNode() { dependency_fixer = memnew( DependencyEditor ); gui_base->add_child( dependency_fixer ); - + settings_config_dialog = memnew( EditorSettingsDialog ); gui_base->add_child(settings_config_dialog); @@ -6029,7 +6029,7 @@ EditorNode::EditorNode() { property_forward->connect("pressed", this,"_property_editor_forward"); property_back->connect("pressed", this,"_property_editor_back"); - + file_menu->get_popup()->connect("item_pressed", this,"_menu_option"); @@ -6266,7 +6266,7 @@ EditorNode::EditorNode() { } -EditorNode::~EditorNode() { +EditorNode::~EditorNode() { memdelete( EditorHelp::get_doc_data() ); diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h index 9fd8d07aef..5d26bae369 100644 --- a/tools/editor/editor_node.h +++ b/tools/editor/editor_node.h @@ -402,13 +402,13 @@ private: String external_file; List<String> previous_scenes; bool opening_prev; - + void _dialog_action(String p_file); void _edit_current(); void _dialog_display_file_error(String p_file,Error p_error); - + int current_option; //void _animation_visibility_toggle(); void _resource_created(); @@ -423,7 +423,7 @@ private: void _select_history(int p_idx); void _prepare_history(); - + void _fs_changed(); void _sources_changed(bool p_exist); void _imported(Node *p_node); @@ -693,7 +693,7 @@ public: void hide_bottom_panel(); void remove_bottom_panel_item(Control *p_item); - EditorNode(); + EditorNode(); ~EditorNode(); void get_singleton(const char* arg1, bool arg2); diff --git a/tools/editor/editor_plugin.h b/tools/editor/editor_plugin.h index a7460d7fde..c572ab210e 100644 --- a/tools/editor/editor_plugin.h +++ b/tools/editor/editor_plugin.h @@ -48,7 +48,7 @@ class EditorImportPlugin; class EditorExportPlugin; class EditorPlugin : public Node { - + OBJ_TYPE( EditorPlugin, Node ); friend class EditorData; UndoRedo *undo_redo; diff --git a/tools/editor/editor_sub_scene.cpp b/tools/editor/editor_sub_scene.cpp index e58e2c1351..a1a881bec5 100644 --- a/tools/editor/editor_sub_scene.cpp +++ b/tools/editor/editor_sub_scene.cpp @@ -147,7 +147,7 @@ void EditorSubScene::move(Node* p_new_parent, Node* p_new_owner) { } TreeItem *s = tree->get_selected(); if (!s) { - return; + return; } Node *selnode = s->get_metadata(0); diff --git a/tools/editor/groups_editor.h b/tools/editor/groups_editor.h index b5bccb2766..6a897d0cbb 100644 --- a/tools/editor/groups_editor.h +++ b/tools/editor/groups_editor.h @@ -63,7 +63,7 @@ public: void set_undo_redo(UndoRedo *p_undoredo) { undo_redo=p_undoredo; } void set_current(Node* p_node); - GroupsEditor(); + GroupsEditor(); ~GroupsEditor(); }; diff --git a/tools/editor/io_plugins/editor_import_collada.cpp b/tools/editor/io_plugins/editor_import_collada.cpp index 7de9d978f2..f008c4a736 100644 --- a/tools/editor/io_plugins/editor_import_collada.cpp +++ b/tools/editor/io_plugins/editor_import_collada.cpp @@ -1372,7 +1372,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize,Ref<Mesh>& p_mesh,con DVector<float> tangents; print_line("vertex source id: "+vertex_src_id); if(md.vertices[vertex_src_id].sources.has("NORMAL")){ - //has normals + //has normals normals.resize(vlen); //std::cout << "has normals" << std::endl; String normal_src_id = md.vertices[vertex_src_id].sources["NORMAL"]; @@ -1386,7 +1386,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize,Ref<Mesh>& p_mesh,con if (stride==0) stride=3; - + //read normals from morph target DVector<Vector3>::Write vertw = normals.write(); @@ -1421,7 +1421,7 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize,Ref<Mesh>& p_mesh,con } } } - + print_line("using built-in normals"); }else{ print_line("generating normals"); @@ -2070,7 +2070,7 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones animation->add_track(Animation::TYPE_TRANSFORM); - int track = animation->get_track_count() -1; + int track = animation->get_track_count() -1; animation->track_set_path( track , path ); Vector<float> snapshots = base_snapshots; diff --git a/tools/editor/io_plugins/editor_scene_import_plugin.cpp b/tools/editor/io_plugins/editor_scene_import_plugin.cpp index 322320780d..15e7a70111 100644 --- a/tools/editor/io_plugins/editor_scene_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_scene_import_plugin.cpp @@ -462,7 +462,7 @@ EditorImportAnimationOptions::EditorImportAnimationOptions() { items.push_back(ti); fname++; fdescr++; - } + } TreeItem *fps_base = flags->create_item(root); diff --git a/tools/editor/io_plugins/editor_texture_import_plugin.cpp b/tools/editor/io_plugins/editor_texture_import_plugin.cpp index 29273ebd06..ea7242c185 100644 --- a/tools/editor/io_plugins/editor_texture_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_texture_import_plugin.cpp @@ -1549,7 +1549,7 @@ Vector<uint8_t> EditorTextureImportPlugin::custom_export(const String& p_path, c } uint32_t flags = rimd->get_option("flags"); - uint8_t shrink = rimd->has_option("shrink") ? rimd->get_option("shrink"): Variant(1); + uint8_t shrink = rimd->has_option("shrink") ? rimd->get_option("shrink"): Variant(1); uint8_t format = rimd->get_option("format"); uint8_t comp = (format==EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM)?uint8_t(p_platform->get_image_compression()):uint8_t(255); @@ -1633,7 +1633,7 @@ EditorTextureImportPlugin::EditorTextureImportPlugin(EditorNode *p_editor, Mode singleton[p_mode]=this; editor=p_editor; - mode=p_mode; + mode=p_mode; dialog = memnew( EditorTextureImportDialog(this,p_mode==MODE_TEXTURE_2D || p_mode==MODE_ATLAS || p_mode==MODE_LARGE,p_mode==MODE_ATLAS,p_mode==MODE_LARGE) ); editor->get_gui_base()->add_child(dialog); diff --git a/tools/editor/output_strings.cpp b/tools/editor/output_strings.cpp index a19352f4ec..f1b49d2326 100644 --- a/tools/editor/output_strings.cpp +++ b/tools/editor/output_strings.cpp @@ -84,7 +84,7 @@ void OutputStrings::_notification(int p_what) { Ref<Texture> icon_warning = get_icon("Warning","EditorIcons"); // int lines = (size_height-(int)margin.y) / font_height; - Point2 ofs=tree_st->get_offset(); + Point2 ofs=tree_st->get_offset(); LineMap::Element *E = line_map.find(v_scroll->get_val()); float h_ofs = (int)h_scroll->get_val(); diff --git a/tools/editor/output_strings.h b/tools/editor/output_strings.h index 3d5deb1646..29c6ea799f 100644 --- a/tools/editor/output_strings.h +++ b/tools/editor/output_strings.h @@ -81,7 +81,7 @@ protected: public: - void add_line(const String& p_text, const Variant& p_meta=Variant(), const LineType p_type=LINE_NORMAL); + void add_line(const String& p_text, const Variant& p_meta=Variant(), const LineType p_type=LINE_NORMAL); OutputStrings(); }; diff --git a/tools/editor/plugins/animation_player_editor_plugin.cpp b/tools/editor/plugins/animation_player_editor_plugin.cpp index 010753e88c..0b06aab447 100644 --- a/tools/editor/plugins/animation_player_editor_plugin.cpp +++ b/tools/editor/plugins/animation_player_editor_plugin.cpp @@ -731,7 +731,7 @@ void AnimationPlayerEditor::_dialog_action(String p_file) { String current = animation->get_item_text(animation->get_selected()); if (current != "") { Ref<Animation> anim = player->get_animation(current); - + ERR_FAIL_COND(!anim->cast_to<Resource>()) RES current_res = RES(anim->cast_to<Resource>()); @@ -1424,7 +1424,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { add_child(error_dialog); name_dialog->connect("confirmed", this,"_animation_name_edited"); - + blend_editor.dialog = memnew( AcceptDialog ); add_child(blend_editor.dialog); blend_editor.dialog->get_ok()->set_text("Close"); @@ -1441,7 +1441,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { updating_blends=false; blend_editor.tree->connect("item_edited",this,"_blend_edited"); - + autoplay->connect("pressed", this,"_autoplay_pressed"); autoplay->set_toggle_mode(true); diff --git a/tools/editor/plugins/animation_tree_editor_plugin.cpp b/tools/editor/plugins/animation_tree_editor_plugin.cpp index d85553b4db..08c2a1c3ae 100644 --- a/tools/editor/plugins/animation_tree_editor_plugin.cpp +++ b/tools/editor/plugins/animation_tree_editor_plugin.cpp @@ -593,7 +593,7 @@ void AnimationTreeEditor::_draw_node(const StringName& p_node) { } break; case AnimationTreePlayer::NODE_ONESHOT: - case AnimationTreePlayer::NODE_MIX: + case AnimationTreePlayer::NODE_MIX: case AnimationTreePlayer::NODE_BLEND2: case AnimationTreePlayer::NODE_BLEND3: case AnimationTreePlayer::NODE_BLEND4: @@ -1155,7 +1155,7 @@ StringName AnimationTreeEditor::_add_node(int p_item) { anim_tree->node_set_pos(name,Point2(last_x,last_y)); order.push_back(name); last_x+=10; - last_y+=10; + last_y+=10; last_x=last_x % (int)get_size().width; last_y=last_y % (int)get_size().height; update(); diff --git a/tools/editor/plugins/baked_light_baker.h b/tools/editor/plugins/baked_light_baker.h index 8fbeeddc6a..5c172f79c6 100644 --- a/tools/editor/plugins/baked_light_baker.h +++ b/tools/editor/plugins/baked_light_baker.h @@ -96,7 +96,7 @@ public: struct Triangle { - AABB aabb; + AABB aabb; Vector3 vertices[3]; Vector2 uvs[3]; Vector2 bake_uvs[3]; diff --git a/tools/editor/plugins/baked_light_editor_plugin.cpp b/tools/editor/plugins/baked_light_editor_plugin.cpp index 22a188bce4..56aabaf6d9 100644 --- a/tools/editor/plugins/baked_light_editor_plugin.cpp +++ b/tools/editor/plugins/baked_light_editor_plugin.cpp @@ -131,7 +131,7 @@ void BakedLightEditor::_notification(int p_option) { last_rays_time=rays_snap; bake_info->set_text("rays/s: "+itos(rays_sec)); - update_timeout=1; + update_timeout=1; print_line("MSUPDATE: "+itos(OS::get_singleton()->get_ticks_msec()-t)); t=OS::get_singleton()->get_ticks_msec(); node->get_baked_light()->set_octree(octree_texture); diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp index f8bc97a433..6eb26542be 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.cpp +++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp @@ -49,10 +49,10 @@ friend class CanvasItemEditor; SpinBox *grid_offset_x; SpinBox *grid_offset_y; SpinBox *grid_step_x; - SpinBox *grid_step_y; - SpinBox *rotation_offset; + SpinBox *grid_step_y; + SpinBox *rotation_offset; SpinBox *rotation_step; - + public: SnapDialog() : ConfirmationDialog() { const int SPIN_BOX_GRID_RANGE = 256; @@ -134,7 +134,7 @@ public: rotation_step->set_suffix("deg"); child_container->add_child(rotation_step); } - + void set_fields(const Point2 p_grid_offset, const Size2 p_grid_step, const float p_rotation_offset, const float p_rotation_step) { grid_offset_x->set_val(p_grid_offset.x); grid_offset_y->set_val(p_grid_offset.y); @@ -143,7 +143,7 @@ public: rotation_offset->set_val(p_rotation_offset * (180 / Math_PI)); rotation_step->set_val(p_rotation_step * (180 / Math_PI)); } - + void get_fields(Point2 &p_grid_offset, Size2 &p_grid_step, float &p_rotation_offset, float &p_rotation_step) { p_grid_offset.x = grid_offset_x->get_val(); p_grid_offset.y = grid_offset_y->get_val(); @@ -1328,7 +1328,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { first=false; } - BoneIK bik; + BoneIK bik; bik.node=b; bik.len=len; bik.orig_state=b->edit_get_state(); @@ -2670,7 +2670,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { } #endif } break; - + case SPACE_HORIZONTAL: { //space_selected_items< proj_vector2_x, compare_items_x >(); } break; @@ -3164,7 +3164,7 @@ bool CanvasItemEditor::box_selection_end() { SWAP(bsfrom.x,bsto.x); if (bsfrom.y>bsto.y) SWAP(bsfrom.y,bsto.y); - + if ( bsfrom.distance_to( bsto ) < 3 ) { print_line( "box selection too small" ); box_selecting=false; @@ -3183,7 +3183,7 @@ bool CanvasItemEditor::box_selection_end() { box_selecting=false; viewport->update(); - + return true; } #endif diff --git a/tools/editor/plugins/canvas_item_editor_plugin.h b/tools/editor/plugins/canvas_item_editor_plugin.h index df24734fd7..301c67756c 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.h +++ b/tools/editor/plugins/canvas_item_editor_plugin.h @@ -302,11 +302,11 @@ class CanvasItemEditor : public VBoxContainer { bool _select(CanvasItem *item, Point2 p_click_pos, bool p_append, bool p_drag=true); ConfirmationDialog *snap_dialog; - + AcceptDialog *value_dialog; Label *dialog_label; SpinBox *dialog_val; - + CanvasItem *ref_item; void _edit_set_pivot(const Vector2& mouse_pos); @@ -369,29 +369,29 @@ protected: bool box_selection_end(); HBoxContainer *get_panel_hb() { return hb; } - + struct compare_items_x { bool operator()( const CanvasItem *a, const CanvasItem *b ) const { return a->get_global_transform().elements[2].x < b->get_global_transform().elements[2].x; } }; - + struct compare_items_y { bool operator()( const CanvasItem *a, const CanvasItem *b ) const { return a->get_global_transform().elements[2].y < b->get_global_transform().elements[2].y; } }; - + struct proj_vector2_x { float get( const Vector2 &v ) { return v.x; } void set( Vector2 &v, float f ) { v.x = f; } }; - + struct proj_vector2_y { float get( const Vector2 &v ) { return v.y; } void set( Vector2 &v, float f ) { v.y = f; } }; - + template< class P, class C > void space_selected_items(); static CanvasItemEditor *singleton; diff --git a/tools/editor/plugins/collision_polygon_editor_plugin.cpp b/tools/editor/plugins/collision_polygon_editor_plugin.cpp index d4198f3166..44854e655f 100644 --- a/tools/editor/plugins/collision_polygon_editor_plugin.cpp +++ b/tools/editor/plugins/collision_polygon_editor_plugin.cpp @@ -40,7 +40,7 @@ void CollisionPolygonEditor::_notification(int p_what) { case NOTIFICATION_READY: { button_create->set_icon( get_icon("Edit","EditorIcons")); - button_edit->set_icon( get_icon("MovePoint","EditorIcons")); + button_edit->set_icon( get_icon("MovePoint","EditorIcons")); button_edit->set_pressed(true); get_tree()->connect("node_removed",this,"_node_removed"); diff --git a/tools/editor/plugins/collision_shape_2d_editor_plugin.cpp b/tools/editor/plugins/collision_shape_2d_editor_plugin.cpp index 7e5d52d17d..1916d55ee1 100644 --- a/tools/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/tools/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -451,11 +451,11 @@ void CollisionShape2DEditor::_canvas_draw() { case LINE_SHAPE: { Ref<LineShape2D> shape = node->get_shape(); - + handles.resize(2); handles[0] = shape->get_normal() * shape->get_d(); handles[1] = shape->get_normal() * (shape->get_d() + 30.0); - + c->draw_texture(h,gt.xform(handles[0])-size); c->draw_texture(h,gt.xform(handles[1])-size); diff --git a/tools/editor/plugins/control_editor_plugin.cpp b/tools/editor/plugins/control_editor_plugin.cpp index 375622a89c..9dff5e6ce4 100644 --- a/tools/editor/plugins/control_editor_plugin.cpp +++ b/tools/editor/plugins/control_editor_plugin.cpp @@ -80,16 +80,16 @@ void ControlEditor::_node_removed(Node *p_node) { // slow as hell Control* ControlEditor::_select_control_at_pos(const Point2& p_pos,Node* p_node) { - + for (int i=p_node->get_child_count()-1;i>=0;i--) { - + Control *r=_select_control_at_pos(p_pos,p_node->get_child(i)); if (r) return r; } - + Control *c=p_node->cast_to<Control>(); - + if (c) { Rect2 rect = c->get_window_rect(); if (c->get_window()==current_window) { @@ -123,9 +123,9 @@ void ControlEditor::_key_move(const Vector2& p_dir, bool p_snap) { void ControlEditor::_input_event(InputEvent p_event) { - + if (p_event.type==InputEvent::MOUSE_BUTTON) { - + const InputEventMouseButton &b=p_event.mouse_button; if (b.button_index==BUTTON_RIGHT) { @@ -146,12 +146,12 @@ void ControlEditor::_input_event(InputEvent p_event) { } //if (!controls.size()) // return; - + if (b.button_index!=BUTTON_LEFT) return; if (!b.pressed) { - + if (drag!=DRAG_NONE) { if (undo_redo) { @@ -321,11 +321,11 @@ void ControlEditor::_input_event(InputEvent p_event) { } } - + if (p_event.type==InputEvent::MOUSE_MOTION) { - + const InputEventMouseMotion &m=p_event.mouse_motion; - + if (drag==DRAG_NONE || !current_window) return; @@ -449,7 +449,7 @@ void ControlEditor::_input_event(InputEvent p_event) { } - + } @@ -492,9 +492,9 @@ void ControlEditor::_update_scroll(float) { } void ControlEditor::_notification(int p_what) { - + if (p_what==NOTIFICATION_PROCESS) { - + for(ControlMap::Element *E=controls.front();E;E=E->next()) { Control *control = E->key(); @@ -504,16 +504,16 @@ void ControlEditor::_notification(int p_what) { E->get().last_rect=r; } } - + } - + if (p_what==NOTIFICATION_CHILDREN_CONFIGURED) { - + get_scene()->connect("node_removed",this,"_node_removed"); } - + if (p_what==NOTIFICATION_DRAW) { - + // TODO fetch the viewport? /* if (!control) { @@ -572,11 +572,11 @@ VisualServer::get_singleton()->canvas_item_add_rect(ci,m_rect,m_color); //DRAW_EMPTY_RECT( Rect2( current_window->get_scroll()-Point2(1,1), get_size()+Size2(2,2)), Color(0.8,0.8,1.0,0.8) ); E->get().last_rect = rect; } - } + } } void ControlEditor::edit(Control *p_control) { - + drag=DRAG_NONE; _clear_controls(); @@ -727,9 +727,9 @@ void ControlEditor::_popup_callback(int p_op) { } void ControlEditor::_bind_methods() { - + ObjectTypeDB::bind_method("_input_event",&ControlEditor::_input_event); - ObjectTypeDB::bind_method("_node_removed",&ControlEditor::_node_removed); + ObjectTypeDB::bind_method("_node_removed",&ControlEditor::_node_removed); ObjectTypeDB::bind_method("_update_scroll",&ControlEditor::_update_scroll); ObjectTypeDB::bind_method("_popup_callback",&ControlEditor::_popup_callback); ObjectTypeDB::bind_method("_visibility_changed",&ControlEditor::_visibility_changed); @@ -781,13 +781,13 @@ ControlEditor::ControlEditor(EditorNode *p_editor) { void ControlEditorPlugin::edit(Object *p_object) { - + control_editor->set_undo_redo(&get_undo_redo()); control_editor->edit(p_object->cast_to<Control>()); } bool ControlEditorPlugin::handles(Object *p_object) const { - + return p_object->is_type("Control"); } @@ -797,7 +797,7 @@ void ControlEditorPlugin::make_visible(bool p_visible) { control_editor->show(); control_editor->set_process(true); } else { - + control_editor->hide(); control_editor->set_process(false); } @@ -805,14 +805,14 @@ void ControlEditorPlugin::make_visible(bool p_visible) { } ControlEditorPlugin::ControlEditorPlugin(EditorNode *p_node) { - + editor=p_node; control_editor = memnew( ControlEditor(editor) ); editor->get_viewport()->add_child(control_editor); control_editor->set_area_as_parent_rect(); control_editor->hide(); - + } diff --git a/tools/editor/plugins/control_editor_plugin.h b/tools/editor/plugins/control_editor_plugin.h index 94cffc8d8d..6234698ee8 100644 --- a/tools/editor/plugins/control_editor_plugin.h +++ b/tools/editor/plugins/control_editor_plugin.h @@ -37,9 +37,9 @@ #if 0 class ControlEditor : public Control { - - OBJ_TYPE(ControlEditor, Control ); - + + OBJ_TYPE(ControlEditor, Control ); + EditorNode *editor; enum { @@ -103,13 +103,13 @@ class ControlEditor : public Control { void _find_controls_span(Node *p_node, Rect2& r_rect); -protected: +protected: void _notification(int p_what); - void _input_event(InputEvent p_event); + void _input_event(InputEvent p_event); void _node_removed(Node *p_node); static void _bind_methods(); -public: - +public: + bool get_remove_list(List<Node*> *p_list); void set_undo_redo(UndoRedo *p_undo_redo) {undo_redo=p_undo_redo; } void edit(Control *p_control); @@ -117,14 +117,14 @@ public: }; class ControlEditorPlugin : public EditorPlugin { - + OBJ_TYPE( ControlEditorPlugin, EditorPlugin ); - + ControlEditor *control_editor; EditorNode *editor; - + public: - + virtual String get_name() const { return "GUI"; } bool has_main_screen() const { return true; } virtual void edit(Object *p_object); @@ -132,7 +132,7 @@ public: virtual void make_visible(bool p_visible); virtual bool get_remove_list(List<Node*> *p_list) { return control_editor->get_remove_list(p_list); } - + ControlEditorPlugin(EditorNode *p_node); ~ControlEditorPlugin(); diff --git a/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp b/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp index c861a5841a..ab4f14b806 100644 --- a/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp +++ b/tools/editor/plugins/cube_grid_theme_editor_plugin.cpp @@ -27,7 +27,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "cube_grid_theme_editor_plugin.h" - + #include "scene/3d/mesh_instance.h" #include "scene/3d/physics_body.h" #include "scene/main/viewport.h" @@ -337,7 +337,7 @@ MeshLibraryEditorPlugin::MeshLibraryEditorPlugin(EditorNode *p_node) { theme_editor->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END ); theme_editor->set_anchor( MARGIN_BOTTOM, Control::ANCHOR_BEGIN ); theme_editor->set_end( Point2(0,22) ); - theme_editor->hide(); + theme_editor->hide(); } diff --git a/tools/editor/plugins/item_list_editor_plugin.cpp b/tools/editor/plugins/item_list_editor_plugin.cpp index 6f0db959ba..08af1a0643 100644 --- a/tools/editor/plugins/item_list_editor_plugin.cpp +++ b/tools/editor/plugins/item_list_editor_plugin.cpp @@ -119,7 +119,7 @@ void ItemListOptionButtonPlugin::set_object(Object *p_object) { bool ItemListOptionButtonPlugin::handles(Object *p_object) const { - return p_object->is_type("OptionButton"); + return p_object->is_type("OptionButton"); } int ItemListOptionButtonPlugin::get_flags() const { @@ -130,23 +130,23 @@ int ItemListOptionButtonPlugin::get_flags() const { void ItemListOptionButtonPlugin::add_item() { ob->add_item( "Item "+itos(ob->get_item_count())); - _change_notify(); + _change_notify(); } int ItemListOptionButtonPlugin::get_item_count() const { - return ob->get_item_count(); + return ob->get_item_count(); } void ItemListOptionButtonPlugin::erase(int p_idx) { - ob->remove_item(p_idx); + ob->remove_item(p_idx); _change_notify(); } ItemListOptionButtonPlugin::ItemListOptionButtonPlugin() { - ob=NULL; + ob=NULL; } /////////////////////////////////////////////////////////////// @@ -259,7 +259,7 @@ void ItemListEditor::edit(Node *p_item_list) { item_plugins[i]->set_object(p_item_list); property_editor->edit(item_plugins[i]); - + if (has_icon(item_list->get_type(), "EditorIcons")) toolbar_button->set_icon(get_icon(item_list->get_type(), "EditorIcons")); else diff --git a/tools/editor/plugins/multimesh_editor_plugin.cpp b/tools/editor/plugins/multimesh_editor_plugin.cpp index 3f63ef706b..15df9a6262 100644 --- a/tools/editor/plugins/multimesh_editor_plugin.cpp +++ b/tools/editor/plugins/multimesh_editor_plugin.cpp @@ -326,7 +326,7 @@ MultiMeshEditor::MultiMeshEditor() { options = memnew( MenuButton ); SpatialEditor::get_singleton()->add_control_to_menu_panel(options); - + options->set_text("MultiMesh"); options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("MultiMeshInstance","EditorIcons")); diff --git a/tools/editor/plugins/polygon_2d_editor_plugin.cpp b/tools/editor/plugins/polygon_2d_editor_plugin.cpp index 3e9c58d604..849fe82645 100644 --- a/tools/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/tools/editor/plugins/polygon_2d_editor_plugin.cpp @@ -69,7 +69,7 @@ void Polygon2DEditor::_node_removed(Node *p_node) { if(p_node==node) { edit(NULL); hide(); - + canvas_item_editor->get_viewport_control()->update(); } @@ -760,7 +760,7 @@ void Polygon2DEditor::edit(Node *p_collision_polygon) { node=p_collision_polygon->cast_to<Polygon2D>(); if (!canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) canvas_item_editor->get_viewport_control()->connect("draw",this,"_canvas_draw"); - + wip.clear(); wip_active=false; edited_point=-1; diff --git a/tools/editor/plugins/resource_preloader_editor_plugin.cpp b/tools/editor/plugins/resource_preloader_editor_plugin.cpp index 8490f63ff0..442046b069 100644 --- a/tools/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/tools/editor/plugins/resource_preloader_editor_plugin.cpp @@ -46,7 +46,7 @@ void ResourcePreloaderEditor::_notification(int p_what) { } if (p_what==NOTIFICATION_ENTER_TREE) { - load->set_icon( get_icon("Folder","EditorIcons") ); + load->set_icon( get_icon("Folder","EditorIcons") ); _delete->set_icon( get_icon("Del","EditorIcons") ); } diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index 4be8b3f95c..2fb5dd619e 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -711,7 +711,7 @@ void ScriptEditor::_close_current_tab() { int selected = tab_container->get_current_tab(); if (selected<0 || selected>=tab_container->get_child_count()) return; - + Node *tselected = tab_container->get_child(selected); ScriptTextEditor *current = tab_container->get_child(selected)->cast_to<ScriptTextEditor>(); if (current) { diff --git a/tools/editor/plugins/shader_editor_plugin.cpp b/tools/editor/plugins/shader_editor_plugin.cpp index 7161033111..2d3100ac0d 100644 --- a/tools/editor/plugins/shader_editor_plugin.cpp +++ b/tools/editor/plugins/shader_editor_plugin.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "shader_editor_plugin.h" #include "tools/editor/editor_settings.h" - + #include "spatial_editor_plugin.h" #include "io/resource_loader.h" #include "io/resource_saver.h" @@ -52,7 +52,7 @@ Ref<Shader> ShaderTextEditor::get_edited_shader() const { } void ShaderTextEditor::set_edited_shader(const Ref<Shader>& p_shader,ShaderLanguage::ShaderType p_type) { - shader=p_shader; + shader=p_shader; type=p_type; _load_theme_settings(); diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index 522da24ea6..e787c74702 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -1265,7 +1265,7 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { } else if (m.button_mask&1) { if (nav_scheme == NAVIGATION_MAYA && m.mod.alt) { - nav_mode = NAVIGATION_ORBIT; + nav_mode = NAVIGATION_ORBIT; } else if (nav_scheme == NAVIGATION_MODO && m.mod.alt && m.mod.shift) { nav_mode = NAVIGATION_PAN; } else if (nav_scheme == NAVIGATION_MODO && m.mod.alt && m.mod.control) { @@ -2606,15 +2606,15 @@ void SpatialEditor::_generate_selection_box() { aabb.grow_by( aabb.get_longest_axis_size()/20.0 ); Ref<SurfaceTool> st = memnew( SurfaceTool ); - + st->begin(Mesh::PRIMITIVE_LINES); for (int i=0;i<12;i++) { - + Vector3 a,b; - aabb.get_edge(i,a,b); - + aabb.get_edge(i,a,b); + /*Vector<Vector3> points; - Vector<Color> colors; + Vector<Color> colors; points.push_back(a); points.push_back(b);*/ @@ -2804,7 +2804,7 @@ void SpatialEditor::set_state(const Dictionary& p_state) { void SpatialEditor::edit(Spatial *p_spatial) { - + if (p_spatial!=selected) { if (selected) { @@ -2836,8 +2836,8 @@ void SpatialEditor::edit(Spatial *p_spatial) { // should become the selection } - - + + } void SpatialEditor::_xform_dialog_action() { @@ -4167,7 +4167,7 @@ SpatialEditor::~SpatialEditor() { void SpatialEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - + spatial_editor->show(); spatial_editor->set_process(true); @@ -4175,7 +4175,7 @@ void SpatialEditorPlugin::make_visible(bool p_visible) { spatial_editor->grab_focus(); } else { - + spatial_editor->hide(); spatial_editor->set_process(false); //VisualServer::get_singleton()->viewport_set_hide_scenario(editor->get_scene_root()->get_viewport(),true); @@ -4189,7 +4189,7 @@ void SpatialEditorPlugin::edit(Object *p_object) { } bool SpatialEditorPlugin::handles(Object *p_object) const { - + return p_object->is_type("Spatial"); } @@ -4223,7 +4223,7 @@ void SpatialEditorPlugin::snap_cursor_to_plane(const Plane& p_plane) { SpatialEditorPlugin::SpatialEditorPlugin(EditorNode *p_node) { - + editor=p_node; spatial_editor = memnew( SpatialEditor(p_node) ); spatial_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); @@ -4238,7 +4238,7 @@ SpatialEditorPlugin::SpatialEditorPlugin(EditorNode *p_node) { SpatialEditorPlugin::~SpatialEditorPlugin() { - + } diff --git a/tools/editor/plugins/spatial_editor_plugin.h b/tools/editor/plugins/spatial_editor_plugin.h index af1b6919a2..54086b0031 100644 --- a/tools/editor/plugins/spatial_editor_plugin.h +++ b/tools/editor/plugins/spatial_editor_plugin.h @@ -278,7 +278,7 @@ public: }; class SpatialEditor : public VBoxContainer { - + OBJ_TYPE(SpatialEditor, VBoxContainer ); public: @@ -338,7 +338,7 @@ private: Ref<Mesh> selection_box; RID indicators; - RID indicators_instance; + RID indicators_instance; RID cursor_mesh; RID cursor_instance; RID indicator_mat; @@ -352,7 +352,7 @@ private: Spatial *sp; RID poly_instance; }; - + Map<uint32_t,Selected> selected; */ struct Gizmo { @@ -361,8 +361,8 @@ private: float scale; Transform transform; } gizmo; - - + + enum MenuOption { @@ -471,7 +471,7 @@ private: void _update_default_light_angle(); void _default_light_angle_input(const InputEvent& p_event); -protected: +protected: @@ -481,7 +481,7 @@ protected: void _unhandled_key_input(InputEvent p_event); static void _bind_methods(); -public: +public: static SpatialEditor *get_singleton() { return singleton; } @@ -541,9 +541,9 @@ public: }; class SpatialEditorPlugin : public EditorPlugin { - + OBJ_TYPE( SpatialEditorPlugin, EditorPlugin ); - + SpatialEditor *spatial_editor; EditorNode *editor; protected: @@ -555,7 +555,7 @@ public: SpatialEditor *get_spatial_editor() { return spatial_editor; } virtual String get_name() const { return "3D"; } bool has_main_screen() const { return true; } - virtual void make_visible(bool p_visible); + virtual void make_visible(bool p_visible); virtual void edit(Object *p_object); virtual bool handles(Object *p_object) const; diff --git a/tools/editor/project_settings.cpp b/tools/editor/project_settings.cpp index bf7d8b190a..88833e4963 100644 --- a/tools/editor/project_settings.cpp +++ b/tools/editor/project_settings.cpp @@ -1012,7 +1012,7 @@ void ProjectSettings::_translation_delete(Object *p_item,int p_column, int p_but undo_redo->create_action("Remove Translation"); undo_redo->add_do_property(Globals::get_singleton(),"locale/translations",translations); - undo_redo->add_undo_property(Globals::get_singleton(),"locale/translations",Globals::get_singleton()->get("locale/translations")); + undo_redo->add_undo_property(Globals::get_singleton(),"locale/translations",Globals::get_singleton()->get("locale/translations")); undo_redo->add_do_method(this,"_update_translations"); undo_redo->add_undo_method(this,"_update_translations"); undo_redo->add_do_method(this,"_settings_changed"); @@ -1126,7 +1126,7 @@ void ProjectSettings::_translation_res_option_changed() { ERR_FAIL_COND(!remaps.has(key)); - StringArray r = remaps[key]; + StringArray r = remaps[key]; ERR_FAIL_INDEX(idx,r.size()); r.set(idx,path+":"+langs[which]); remaps[key]=r; diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index 4e98ae9e90..1340670db1 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -2162,7 +2162,7 @@ void PropertyEditor::_check_reload_status(const String&p_name, TreeItem* item) { //} - } + } } diff --git a/tools/editor/property_editor.h b/tools/editor/property_editor.h index 83923cb237..b870a618e9 100644 --- a/tools/editor/property_editor.h +++ b/tools/editor/property_editor.h @@ -174,7 +174,7 @@ class PropertyEditor : public Control { Map<StringName,Map<StringName,String> > descr_cache; Map<StringName,String > class_descr_cache; - + CustomPropertyEditor *custom_editor; void _resource_edit_request(); @@ -245,7 +245,7 @@ public: void set_subsection_selectable(bool p_selectable); - PropertyEditor(); + PropertyEditor(); ~PropertyEditor(); }; diff --git a/tools/editor/reparent_dialog.cpp b/tools/editor/reparent_dialog.cpp index 97b27603b2..2a886b85fa 100644 --- a/tools/editor/reparent_dialog.cpp +++ b/tools/editor/reparent_dialog.cpp @@ -47,19 +47,19 @@ void ReparentDialog::_notification(int p_what) { } if (p_what==NOTIFICATION_DRAW) { - + //RID ci = get_canvas_item(); //get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size())); - } + } } void ReparentDialog::_cancel() { - + hide(); - + } void ReparentDialog::_reparent() { - + if (tree->get_selected()) { emit_signal("reparent",tree->get_selected()->get_path(),keep_transform->is_pressed()); @@ -68,14 +68,14 @@ void ReparentDialog::_reparent() { } void ReparentDialog::set_current(const Set<Node*>& p_selection) { - + tree->set_marked(p_selection,false,false); //tree->set_selected(p_node->get_parent()); } void ReparentDialog::_bind_methods() { - - ObjectTypeDB::bind_method("_reparent",&ReparentDialog::_reparent); + + ObjectTypeDB::bind_method("_reparent",&ReparentDialog::_reparent); ObjectTypeDB::bind_method("_cancel",&ReparentDialog::_cancel); ADD_SIGNAL( MethodInfo("reparent",PropertyInfo(Variant::NODE_PATH,"path"),PropertyInfo(Variant::BOOL,"keep_global_xform"))); diff --git a/tools/editor/reparent_dialog.h b/tools/editor/reparent_dialog.h index 296102e4b9..1c0fbd2459 100644 --- a/tools/editor/reparent_dialog.h +++ b/tools/editor/reparent_dialog.h @@ -39,30 +39,30 @@ @author Juan Linietsky <reduzio@gmail.com> */ class ReparentDialog : public ConfirmationDialog { - + OBJ_TYPE( ReparentDialog, ConfirmationDialog ); - + SceneTreeEditor *tree; CheckBox *keep_transform; - + void update_tree(); void _reparent(); void _cancel(); protected: - + void _notification(int p_what); static void _bind_methods(); public: - + void set_current(const Set<Node*>& p_selection); String get_selected_type(); - - ReparentDialog(); + + ReparentDialog(); ~ReparentDialog(); - + }; #endif diff --git a/tools/editor/run_settings_dialog.cpp b/tools/editor/run_settings_dialog.cpp index e8c509d79d..9dc4d703fc 100644 --- a/tools/editor/run_settings_dialog.cpp +++ b/tools/editor/run_settings_dialog.cpp @@ -84,7 +84,7 @@ RunSettingsDialog::RunSettingsDialog() { run_mode->add_item("Main Scene"); run_mode->connect("item_selected",this,"_run_mode_changed"); arguments = memnew( LineEdit ); - vbc->add_margin_child("Main Scene Arguments:",arguments); + vbc->add_margin_child("Main Scene Arguments:",arguments); arguments->set_editable(false); get_ok()->set_text("Close"); diff --git a/tools/editor/scene_tree_editor.cpp b/tools/editor/scene_tree_editor.cpp index 45eecacb6b..c16152ae44 100644 --- a/tools/editor/scene_tree_editor.cpp +++ b/tools/editor/scene_tree_editor.cpp @@ -211,7 +211,7 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item,int p_column,int p_id) } void SceneTreeEditor::_add_nodes(Node *p_node,TreeItem *p_parent) { - + if (!p_node) return; @@ -252,7 +252,7 @@ void SceneTreeEditor::_add_nodes(Node *p_node,TreeItem *p_parent) { else icon=get_icon( (has_icon(p_node->get_type(),"EditorIcons")?p_node->get_type():String("Object")),"EditorIcons"); item->set_icon(0, icon ); - item->set_metadata( 0,p_node->get_path() ); + item->set_metadata( 0,p_node->get_path() ); if (part_of_subscene) { @@ -260,7 +260,7 @@ void SceneTreeEditor::_add_nodes(Node *p_node,TreeItem *p_parent) { item->set_custom_color(0,Color(0.8,0.4,0.20)); } else if (marked.has(p_node)) { - + item->set_selectable(0,marked_selectable); item->set_custom_color(0,Color(0.8,0.1,0.10)); } else if (!marked_selectable && !marked_children_selectable) { @@ -344,9 +344,9 @@ void SceneTreeEditor::_add_nodes(Node *p_node,TreeItem *p_parent) { item->select(0); item->set_as_cursor(0); } - + for (int i=0;i<p_node->get_child_count();i++) { - + _add_nodes(p_node->get_child(i),item); } } @@ -406,7 +406,7 @@ void SceneTreeEditor::_node_script_changed(Node *p_node) { } void SceneTreeEditor::_node_removed(Node *p_node) { - + if (p_node->is_connected("script_changed",this,"_node_script_changed")) p_node->disconnect("script_changed",this,"_node_script_changed"); @@ -419,8 +419,8 @@ void SceneTreeEditor::_node_removed(Node *p_node) { selected=NULL; emit_signal("node_selected"); } - - + + } void SceneTreeEditor::_update_tree() { @@ -492,11 +492,11 @@ void SceneTreeEditor::_tree_changed() { void SceneTreeEditor::_selected_changed() { - + TreeItem *s = tree->get_selected(); ERR_FAIL_COND(!s); NodePath np = s->get_metadata(0); - + Node *n=get_node(np); @@ -509,8 +509,8 @@ void SceneTreeEditor::_selected_changed() { blocked++; emit_signal("node_selected"); blocked--; - - + + } @@ -540,7 +540,7 @@ void SceneTreeEditor::_cell_multi_selected(Object *p_object,int p_cell,bool p_se } void SceneTreeEditor::_notification(int p_what) { - + if (p_what==NOTIFICATION_ENTER_TREE) { get_tree()->connect("tree_changed",this,"_tree_changed"); @@ -570,20 +570,20 @@ TreeItem* SceneTreeEditor::_find(TreeItem *p_node,const NodePath& p_path) { if (!p_node) return NULL; - + NodePath np=p_node->get_metadata(0); if (np==p_path) return p_node; - + TreeItem *children=p_node->get_children(); while(children) { - + TreeItem *n=_find(children,p_path); if (n) return n; children=children->get_next(); } - + return NULL; } @@ -598,24 +598,24 @@ void SceneTreeEditor::set_selected(Node *p_node,bool p_emit_selected) { if (selected==p_node) return; - - + + TreeItem* item=p_node?_find(tree->get_root(),p_node->get_path()):NULL; if (item) { item->select(0); item->set_as_cursor(0); - selected=p_node; + selected=p_node; tree->ensure_cursor_is_visible(); } else { if (!p_node) selected=NULL; _update_tree(); - selected=p_node; + selected=p_node; if (p_emit_selected) emit_signal("node_selected"); } - + } void SceneTreeEditor::_rename_node(ObjectID p_node,const String& p_name) { @@ -787,10 +787,10 @@ void SceneTreeEditor::_cell_collapsed(Object *p_obj) { void SceneTreeEditor::_bind_methods() { - + ObjectTypeDB::bind_method("_tree_changed",&SceneTreeEditor::_tree_changed); ObjectTypeDB::bind_method("_update_tree",&SceneTreeEditor::_update_tree); - ObjectTypeDB::bind_method("_node_removed",&SceneTreeEditor::_node_removed); + ObjectTypeDB::bind_method("_node_removed",&SceneTreeEditor::_node_removed); ObjectTypeDB::bind_method("_selected_changed",&SceneTreeEditor::_selected_changed); ObjectTypeDB::bind_method("_renamed",&SceneTreeEditor::_renamed); ObjectTypeDB::bind_method("_rename_node",&SceneTreeEditor::_rename_node); @@ -817,7 +817,7 @@ void SceneTreeEditor::_bind_methods() { SceneTreeEditor::SceneTreeEditor(bool p_label,bool p_can_rename, bool p_can_open_instance) { - + undo_redo=NULL; tree_dirty=true; @@ -829,23 +829,23 @@ SceneTreeEditor::SceneTreeEditor(bool p_label,bool p_can_rename, bool p_can_open can_open_instance=p_can_open_instance; display_foreign=false; editor_selection=NULL; - + if (p_label) { Label *label = memnew( Label ); label->set_pos( Point2(10, 0)); label->set_text("Scene Tree (Nodes):"); - + add_child(label); } - + tree = memnew( Tree ); tree->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - tree->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); + tree->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); tree->set_begin( Point2(0,p_label?18:0 )); tree->set_end( Point2(0,0 )); - + add_child( tree ); - + tree->connect("cell_selected", this,"_selected_changed"); tree->connect("item_edited", this,"_renamed",varray(),CONNECT_DEFERRED); tree->connect("multi_selected",this,"_cell_multi_selected"); @@ -889,7 +889,7 @@ SceneTreeEditor::SceneTreeEditor(bool p_label,bool p_can_rename, bool p_can_open SceneTreeEditor::~SceneTreeEditor() { - + } diff --git a/tools/editor/scene_tree_editor.h b/tools/editor/scene_tree_editor.h index 334debc148..27ccaaae01 100644 --- a/tools/editor/scene_tree_editor.h +++ b/tools/editor/scene_tree_editor.h @@ -38,7 +38,7 @@ @author Juan Linietsky <reduzio@gmail.com> */ class SceneTreeEditor : public Control { - + OBJ_TYPE( SceneTreeEditor, Control ); EditorSelection *editor_selection; @@ -70,7 +70,7 @@ class SceneTreeEditor : public Control { ConfirmationDialog *clear_inherit_confirm; int blocked; - + void _compute_hash(Node *p_node,uint64_t &hash); void _add_nodes(Node *p_node,TreeItem *p_parent); @@ -78,7 +78,7 @@ class SceneTreeEditor : public Control { void _update_tree(); void _tree_changed(); void _node_removed(Node *p_node); - + TreeItem* _find(TreeItem *p_node,const NodePath& p_path); void _notification(int p_what); void _selected_changed(); @@ -92,17 +92,17 @@ class SceneTreeEditor : public Control { bool can_open_instance; bool updating_tree; bool show_enabled_subscene; - + void _renamed(); UndoRedo *undo_redo; - + Set<Node*> marked; bool marked_selectable; bool marked_children_selectable; bool display_foreign; bool tree_dirty; bool pending_test_update; - static void _bind_methods(); + static void _bind_methods(); void _cell_button_pressed(Object *p_item,int p_column,int p_id); void _cell_multi_selected(Object *p_object,int p_cel,bool p_selected); @@ -119,7 +119,7 @@ public: void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo=p_undo_redo; }; void set_display_foreign_nodes(bool p_display); bool get_display_foreign_nodes() const; - + void set_marked(const Set<Node*>& p_marked,bool p_selectable=false,bool p_children_selectable=true); void set_marked(Node *p_marked,bool p_selectable=false,bool p_children_selectable=true); void set_selected(Node *p_node,bool p_emit_selected=true); @@ -150,7 +150,7 @@ class SceneTreeDialog : public ConfirmationDialog { void update_tree(); void _select(); - void _cancel(); + void _cancel(); protected: diff --git a/tools/editor/scenes_dock.cpp b/tools/editor/scenes_dock.cpp index 5abc4992df..e2b17f5e64 100644 --- a/tools/editor/scenes_dock.cpp +++ b/tools/editor/scenes_dock.cpp @@ -1122,7 +1122,7 @@ ScenesDock::ScenesDock(EditorNode *p_editor) { button_reload = memnew( Button ); button_reload->set_flat(true); - button_reload->connect("pressed",this,"_rescan"); + button_reload->connect("pressed",this,"_rescan"); toolbar_hbc->add_child(button_reload); button_reload->set_focus_mode(FOCUS_NONE); button_reload->set_tooltip("Re-Scan Filesystem"); @@ -1238,10 +1238,10 @@ ScenesDock::ScenesDock(EditorNode *p_editor) { add_child(remove_dialog); move_dialog = memnew( EditorDirDialog ); - add_child(move_dialog); + add_child(move_dialog); move_dialog->connect("dir_selected",this,"_move_operation"); move_dialog->get_ok()->set_text("Move"); - + rename_dialog = memnew( EditorFileDialog ); rename_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); rename_dialog->connect("file_selected",this,"_rename_operation"); diff --git a/tools/editor/scenes_dock.h b/tools/editor/scenes_dock.h index a1978a3ca4..a630d2506d 100644 --- a/tools/editor/scenes_dock.h +++ b/tools/editor/scenes_dock.h @@ -138,7 +138,7 @@ class ScenesDock : public VBoxContainer { void _rescan(); void _set_scannig_mode(); - void _favorites_pressed(); + void _favorites_pressed(); void _instance_pressed(); void _open_pressed(); diff --git a/tools/editor/script_create_dialog.cpp b/tools/editor/script_create_dialog.cpp index 409e8be870..34d9204061 100644 --- a/tools/editor/script_create_dialog.cpp +++ b/tools/editor/script_create_dialog.cpp @@ -138,7 +138,7 @@ void ScriptCreateDialog::ok_pressed() { return; } - Error err = ResourceSaver::save(lpath,scr,ResourceSaver::FLAG_CHANGE_PATH); + Error err = ResourceSaver::save(lpath,scr,ResourceSaver::FLAG_CHANGE_PATH); if (err!=OK) { alert->set_text("Could not create script in filesystem: "+String("")); @@ -195,7 +195,7 @@ void ScriptCreateDialog::_browse_path() { file_browse->add_filter("*."+E->get()); } - file_browse->set_current_path(file_path->get_text()); + file_browse->set_current_path(file_path->get_text()); file_browse->popup_centered_ratio(); } |