From 4a4f2479146aa33e235ed57cde311efda68d3c8f Mon Sep 17 00:00:00 2001 From: Hubert Jarosz Date: Wed, 9 Mar 2016 00:00:52 +0100 Subject: [PATCH] remove trailing whitespace --- bin/tests/test_containers.cpp | 22 +- bin/tests/test_detailer.cpp | 30 +- bin/tests/test_gdscript.cpp | 2 +- bin/tests/test_gui.cpp | 56 +- bin/tests/test_io.cpp | 22 +- bin/tests/test_main.cpp | 32 +- bin/tests/test_math.cpp | 2 +- bin/tests/test_particles.cpp | 32 +- bin/tests/test_physics.cpp | 60 +- bin/tests/test_python.cpp | 2 +- bin/tests/test_render.cpp | 40 +- bin/tests/test_shader_lang.cpp | 2 +- bin/tests/test_string.cpp | 328 ++-- core/color.cpp | 14 +- core/color.h | 18 +- core/command_queue_mt.cpp | 2 +- core/command_queue_mt.h | 280 +-- core/dvector.h | 198 +- core/error_macros.h | 12 +- core/event_queue.cpp | 54 +- core/event_queue.h | 10 +- core/globals.cpp | 26 +- core/globals.h | 16 +- core/hash_map.h | 330 ++-- core/hashfuncs.h | 8 +- core/image.cpp | 120 +- core/image.h | 52 +- core/input_map.cpp | 2 +- core/io/aes256.h | 12 +- core/io/fastlz.h | 26 +- core/io/file_access_buffered.cpp | 22 +- core/io/file_access_buffered.h | 6 +- core/io/file_access_network.cpp | 2 +- core/io/http_client.cpp | 2 +- core/io/image_loader.cpp | 28 +- core/io/image_loader.h | 14 +- core/io/ip.cpp | 2 +- core/io/marshalls.cpp | 8 +- core/io/marshalls.h | 42 +- core/io/packet_peer.cpp | 6 +- core/io/resource_format_binary.cpp | 4 +- core/io/resource_format_xml.cpp | 2 +- core/io/resource_loader.cpp | 14 +- core/io/resource_loader.h | 10 +- core/io/resource_saver.cpp | 26 +- core/io/resource_saver.h | 10 +- core/list.h | 52 +- core/map.h | 284 +-- core/math/aabb.h | 14 +- core/math/bsp_tree.cpp | 84 +- core/math/bsp_tree.h | 22 +- core/math/camera_matrix.cpp | 118 +- core/math/camera_matrix.h | 16 +- core/math/face3.h | 4 +- core/math/geometry.cpp | 328 ++-- core/math/geometry.h | 106 +- core/math/math_2d.cpp | 54 +- core/math/math_2d.h | 92 +- core/math/math_funcs.cpp | 20 +- core/math/math_funcs.h | 16 +- core/math/matrix3.cpp | 42 +- core/math/matrix3.h | 32 +- core/math/octree.h | 406 ++-- core/math/plane.cpp | 6 +- core/math/plane.h | 4 +- core/math/quat.cpp | 12 +- core/math/quat.h | 14 +- core/math/transform.cpp | 24 +- core/math/transform.h | 62 +- core/method_bind.h | 12 +- core/object.cpp | 60 +- core/object_type_db.cpp | 114 +- core/object_type_db.h | 30 +- core/os/copymem.cpp | 2 +- core/os/dir_access.cpp | 22 +- core/os/dir_access.h | 12 +- core/os/file_access.cpp | 90 +- core/os/file_access.h | 44 +- core/os/input.h | 2 +- core/os/input_event.cpp | 24 +- core/os/input_event.h | 6 +- core/os/keyboard.h | 20 +- core/os/main_loop.h | 6 +- core/os/memory.cpp | 6 +- core/os/memory.h | 86 +- core/os/memory_pool_dynamic.h | 8 +- core/os/memory_pool_dynamic_static.cpp | 84 +- core/os/memory_pool_dynamic_static.h | 16 +- core/os/memory_pool_static.cpp | 4 +- core/os/memory_pool_static.h | 8 +- core/os/mutex.cpp | 6 +- core/os/mutex.h | 8 +- core/os/os.h | 32 +- core/os/semaphore.h | 8 +- core/os/shell.h | 2 +- core/os/thread.cpp | 10 +- core/os/thread.h | 18 +- core/os/thread_safe.cpp | 14 +- core/os/thread_safe.h | 6 +- core/packed_data_container.cpp | 6 +- core/path_db.cpp | 86 +- core/path_db.h | 10 +- core/pool_allocator.cpp | 202 +- core/pool_allocator.h | 58 +- core/register_core_types.cpp | 4 +- core/res_ptr.cpp | 2 +- core/res_ptr.h | 2 +- core/resource.cpp | 28 +- core/resource.h | 18 +- core/rid.h | 76 +- core/ring_buffer.h | 28 +- core/safe_refcount.cpp | 4 +- core/safe_refcount.h | 68 +- core/script_language.cpp | 10 +- core/script_language.h | 24 +- core/set.h | 264 +-- core/simple_type.h | 24 +- core/sort.h | 128 +- core/string_db.cpp | 104 +- core/string_db.h | 36 +- core/typedefs.h | 2 +- core/undo_redo.cpp | 6 +- core/ustring.cpp | 228 +-- core/ustring.h | 16 +- core/variant.cpp | 358 ++-- core/variant.h | 52 +- core/variant_op.cpp | 6 +- core/variant_parser.cpp | 6 +- core/vector.h | 94 +- main/main.cpp | 126 +- modules/gdscript/gd_compiler.cpp | 4 +- modules/gdscript/gd_compiler.h | 8 +- modules/gdscript/gd_parser.cpp | 2 +- modules/gdscript/gd_script.cpp | 4 +- modules/gdscript/gd_script.h | 2 +- modules/gdscript/gd_tokenizer.cpp | 18 +- modules/gridmap/grid_map.cpp | 6 +- platform/android/export/export.cpp | 2 +- platform/android/file_access_android.cpp | 2 +- platform/android/file_access_jandroid.cpp | 2 +- platform/android/os_android.cpp | 4 +- platform/android/os_android.h | 4 +- platform/bb10/export/export.cpp | 2 +- platform/flash/include/GL/gl.h | 4 +- platform/flash/include/GL/glext.h | 6 +- platform/flash/include/GL/glxext.h | 6 +- platform/flash/rasterizer_flash.cpp | 2 +- platform/haiku/context_gl_haiku.cpp | 2 +- platform/haiku/context_gl_haiku.h | 4 +- platform/haiku/godot_haiku.cpp | 8 +- platform/haiku/key_mapping_haiku.cpp | 2 +- platform/haiku/os_haiku.cpp | 2 +- platform/iphone/Appirater.h | 18 +- platform/iphone/gl_view.h | 14 +- platform/iphone/icloud.h | 4 +- platform/iphone/os_iphone.cpp | 12 +- platform/iphone/os_iphone.h | 6 +- platform/iphone/rasterizer_iphone.cpp | 2 +- platform/nacl/pepper_main.cpp | 2 +- platform/osx/context_gl_osx.h | 4 +- platform/osx/dir_access_osx.h | 26 +- platform/osx/os_osx.h | 2 +- platform/server/godot_server.cpp | 8 +- platform/server/os_server.cpp | 18 +- platform/server/os_server.h | 14 +- platform/windows/context_gl_win.cpp | 8 +- platform/windows/context_gl_win.h | 10 +- platform/windows/godot_win.cpp | 2 +- platform/windows/os_windows.cpp | 64 +- platform/windows/os_windows.h | 28 +- platform/winrt/app.cpp | 6 +- platform/winrt/app.h | 2 +- .../include/FunctionDiscoveryKeys_devpkey.h | 2 +- platform/winrt/include/GLES2/gl2ext.h | 68 +- platform/winrt/include/GLES3/gl3.h | 2 +- platform/winrt/include/GLSLANG/ShaderLang.h | 2 +- platform/winrt/include/KHR/khrplatform.h | 2 +- platform/winrt/os_winrt.cpp | 28 +- platform/winrt/os_winrt.h | 26 +- platform/x11/context_gl_x11.cpp | 26 +- platform/x11/context_gl_x11.h | 8 +- platform/x11/godot_x11.cpp | 8 +- platform/x11/key_mapping_x11.cpp | 76 +- platform/x11/key_mapping_x11.h | 2 +- platform/x11/os_x11.cpp | 258 +-- platform/x11/os_x11.h | 14 +- scene/2d/camera_2d.h | 2 +- scene/2d/canvas_item.cpp | 8 +- scene/2d/collision_object_2d.cpp | 2 +- scene/2d/particles_2d.cpp | 4 +- scene/2d/particles_2d.h | 4 +- scene/2d/tile_map.cpp | 2 +- scene/3d/baked_light_instance.cpp | 2 +- scene/3d/camera.cpp | 38 +- scene/3d/camera.h | 16 +- scene/3d/character_camera.cpp | 2 +- scene/3d/light.cpp | 36 +- scene/3d/light.h | 24 +- scene/3d/mesh_instance.cpp | 8 +- scene/3d/mesh_instance.h | 6 +- scene/3d/navigation.cpp | 2 +- scene/3d/particles.cpp | 20 +- scene/3d/particles.h | 38 +- scene/3d/portal.cpp | 28 +- scene/3d/portal.h | 10 +- scene/3d/room_instance.cpp | 2 +- scene/3d/skeleton.cpp | 110 +- scene/3d/skeleton.h | 38 +- scene/3d/spatial.cpp | 34 +- scene/3d/spatial.h | 14 +- scene/3d/spatial_sample_player.h | 2 +- scene/3d/test_cube.h | 4 +- scene/3d/visual_instance.h | 4 +- scene/animation/animation_player.cpp | 174 +- scene/animation/animation_player.h | 70 +- scene/animation/animation_tree_player.cpp | 6 +- scene/animation/tween.cpp | 12 +- scene/animation/tween.h | 4 +- scene/gui/base_button.cpp | 102 +- scene/gui/base_button.h | 16 +- scene/gui/button.cpp | 32 +- scene/gui/button.h | 16 +- scene/gui/button_array.cpp | 4 +- scene/gui/button_array.h | 2 +- scene/gui/button_group.h | 2 +- scene/gui/check_button.cpp | 10 +- scene/gui/check_button.h | 14 +- scene/gui/color_picker.cpp | 10 +- scene/gui/color_ramp_edit.cpp | 2 +- scene/gui/control.cpp | 142 +- scene/gui/control.h | 60 +- scene/gui/dialogs.cpp | 22 +- scene/gui/dialogs.h | 2 +- scene/gui/file_dialog.cpp | 170 +- scene/gui/file_dialog.h | 22 +- scene/gui/graph_edit.h | 2 +- scene/gui/line_edit.cpp | 276 +-- scene/gui/line_edit.h | 42 +- scene/gui/menu_button.cpp | 10 +- scene/gui/menu_button.h | 12 +- scene/gui/option_button.cpp | 60 +- scene/gui/option_button.h | 18 +- scene/gui/panel.cpp | 4 +- scene/gui/panel.h | 4 +- scene/gui/popup.cpp | 20 +- scene/gui/popup.h | 12 +- scene/gui/popup_menu.cpp | 112 +- scene/gui/popup_menu.h | 26 +- scene/gui/range.cpp | 34 +- scene/gui/range.h | 10 +- scene/gui/rich_text_label.cpp | 6 +- scene/gui/scroll_bar.cpp | 324 ++-- scene/gui/scroll_bar.h | 42 +- scene/gui/slider.cpp | 8 +- scene/gui/slider.h | 2 +- scene/gui/tab_container.cpp | 4 +- scene/gui/tabs.cpp | 2 +- scene/gui/text_edit.cpp | 1660 ++++++++--------- scene/gui/text_edit.h | 22 +- scene/gui/texture_frame.h | 2 +- scene/gui/texture_progress.cpp | 6 +- scene/gui/tree.cpp | 2 +- scene/gui/tree.h | 116 +- scene/io/resource_format_image.cpp | 40 +- scene/main/misc.h | 2 +- scene/main/node.cpp | 326 ++-- scene/main/node.h | 74 +- scene/main/scene_main_loop.cpp | 4 +- scene/main/scene_main_loop.h | 2 +- scene/main/timer.cpp | 4 +- scene/main/viewport.cpp | 24 +- scene/main/viewport.h | 6 +- scene/register_scene_types.cpp | 6 +- scene/resources/animation.cpp | 316 ++-- scene/resources/animation.h | 76 +- .../resources/default_theme/default_theme.cpp | 8 +- scene/resources/environment.h | 2 +- scene/resources/font.cpp | 36 +- scene/resources/font.h | 28 +- scene/resources/material.h | 2 +- scene/resources/mesh.cpp | 64 +- scene/resources/mesh.h | 26 +- scene/resources/mesh_library.cpp | 2 +- scene/resources/mesh_library.h | 2 +- scene/resources/packed_scene.cpp | 6 +- scene/resources/packed_scene.h | 2 +- scene/resources/polygon_path_finder.cpp | 2 +- scene/resources/polygon_path_finder.h | 2 +- scene/resources/room.cpp | 2 +- scene/resources/room.h | 8 +- scene/resources/scene_format_text.cpp | 2 +- scene/resources/style_box.cpp | 30 +- scene/resources/style_box.h | 46 +- scene/resources/surface_tool.cpp | 2 +- scene/resources/texture.cpp | 36 +- scene/resources/texture.h | 16 +- scene/resources/theme.cpp | 104 +- scene/resources/theme.h | 12 +- scene/resources/tile_set.cpp | 6 +- scene/resources/volume.cpp | 34 +- scene/resources/volume.h | 18 +- servers/audio/audio_mixer_sw.cpp | 6 +- servers/audio/audio_mixer_sw.h | 2 +- servers/audio/audio_server_sw.h | 2 +- servers/physics/gjk_epa.cpp | 104 +- servers/physics/space_sw.cpp | 2 +- servers/physics_2d/body_2d_sw.cpp | 8 +- servers/physics_2d/body_pair_2d_sw.cpp | 6 +- servers/physics_2d/collision_solver_2d_sw.cpp | 2 +- servers/physics_2d/physics_2d_server_sw.h | 2 +- servers/physics_2d/shape_2d_sw.cpp | 2 +- servers/physics_2d/space_2d_sw.cpp | 4 +- servers/physics_2d/step_2d_sw.cpp | 2 +- servers/physics_2d_server.h | 2 +- servers/physics_server.h | 4 +- .../spatial_sound/spatial_sound_server_sw.cpp | 8 +- .../spatial_sound/spatial_sound_server_sw.h | 2 +- servers/visual/particle_system_sw.cpp | 34 +- servers/visual/particle_system_sw.h | 18 +- servers/visual/rasterizer.cpp | 2 +- servers/visual/rasterizer.h | 94 +- servers/visual/shader_graph.cpp | 104 +- servers/visual/shader_graph.h | 12 +- servers/visual/shader_language.cpp | 4 +- servers/visual/visual_server_raster.cpp | 438 ++--- servers/visual/visual_server_raster.h | 192 +- servers/visual/visual_server_wrap_mt.cpp | 34 +- servers/visual/visual_server_wrap_mt.h | 10 +- servers/visual_server.cpp | 68 +- servers/visual_server.h | 130 +- tools/collada/collada.cpp | 2 +- tools/docdump/doc_dump.cpp | 2 +- tools/editor/animation_editor.cpp | 8 +- tools/editor/animation_editor.h | 2 +- tools/editor/call_dialog.cpp | 134 +- tools/editor/call_dialog.h | 26 +- tools/editor/code_editor.cpp | 8 +- tools/editor/code_editor.h | 2 +- tools/editor/connections_dialog.cpp | 120 +- tools/editor/connections_dialog.h | 30 +- tools/editor/create_dialog.cpp | 82 +- tools/editor/create_dialog.h | 18 +- tools/editor/editor_data.cpp | 6 +- tools/editor/editor_file_dialog.cpp | 2 +- tools/editor/editor_file_system.cpp | 2 +- tools/editor/editor_import_export.cpp | 2 +- tools/editor/editor_node.cpp | 112 +- tools/editor/editor_node.h | 8 +- tools/editor/editor_plugin.h | 2 +- tools/editor/editor_sub_scene.cpp | 2 +- tools/editor/groups_editor.h | 2 +- .../io_plugins/editor_import_collada.cpp | 8 +- .../io_plugins/editor_scene_import_plugin.cpp | 2 +- .../editor_texture_import_plugin.cpp | 4 +- tools/editor/output_strings.cpp | 2 +- tools/editor/output_strings.h | 2 +- .../animation_player_editor_plugin.cpp | 6 +- .../plugins/animation_tree_editor_plugin.cpp | 4 +- tools/editor/plugins/baked_light_baker.h | 2 +- .../plugins/baked_light_editor_plugin.cpp | 2 +- .../plugins/canvas_item_editor_plugin.cpp | 18 +- .../plugins/canvas_item_editor_plugin.h | 14 +- .../collision_polygon_editor_plugin.cpp | 2 +- .../collision_shape_2d_editor_plugin.cpp | 4 +- .../editor/plugins/control_editor_plugin.cpp | 56 +- tools/editor/plugins/control_editor_plugin.h | 24 +- .../plugins/cube_grid_theme_editor_plugin.cpp | 4 +- .../plugins/item_list_editor_plugin.cpp | 12 +- .../plugins/multimesh_editor_plugin.cpp | 2 +- .../plugins/polygon_2d_editor_plugin.cpp | 4 +- .../resource_preloader_editor_plugin.cpp | 2 +- tools/editor/plugins/script_editor_plugin.cpp | 2 +- tools/editor/plugins/shader_editor_plugin.cpp | 4 +- .../editor/plugins/spatial_editor_plugin.cpp | 28 +- tools/editor/plugins/spatial_editor_plugin.h | 20 +- tools/editor/project_settings.cpp | 4 +- tools/editor/property_editor.cpp | 2 +- tools/editor/property_editor.h | 4 +- tools/editor/reparent_dialog.cpp | 16 +- tools/editor/reparent_dialog.h | 16 +- tools/editor/run_settings_dialog.cpp | 2 +- tools/editor/scene_tree_editor.cpp | 64 +- tools/editor/scene_tree_editor.h | 16 +- tools/editor/scenes_dock.cpp | 6 +- tools/editor/scenes_dock.h | 2 +- tools/editor/script_create_dialog.cpp | 4 +- 386 files changed, 7664 insertions(+), 7664 deletions(-) diff --git a/bin/tests/test_containers.cpp b/bin/tests/test_containers.cpp index f8cc8ccd412..4bc297d0ba6 100644 --- a/bin/tests/test_containers.cpp +++ b/bin/tests/test_containers.cpp @@ -44,9 +44,9 @@ MainLoop * test() { /* HashMap 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 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::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 616356077e2..5dba7c3f724 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 683191fba2e..4578f5aa026 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(p_expr); + const GDParser::IdentifierNode *id_node = static_cast(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 cba488a3daa..f4341fd7b3e 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 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 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 a1eb2be19b9..a8e8d7d0fde 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 8143a95d669..363aede96e4 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& 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& 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& 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& 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 05acd5c1ec2..22d14ada34b 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 bafd78eda07..23a4b9e6359 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 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 ce96f37f3f5..ecd90a13d46 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 faces; - + for (int i=1;ishape_create(); ps->shape_set_data(trimesh_shape, PhysicsServer::SHAPE_CONCAVE_POLYGON,faces); faces=ps->shape_get_shape(trimesh_shape, 0); Vector normals; // for drawing for (int i=0;ifixed_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 575caf2513c..26fb4bdafbc 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 568699e5e6a..9c3a287afaa 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 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;iinstance_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::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 e55ad3074f2..9c0075c47d1 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 27707b1a00a..be37ce118ff 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;iprint("\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 56a550c0245..bf9c94462fc 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 d0a1e8835ca..5b671d5f62c 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 a2507b13789..acd3aeddfba 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 struct Command0 : public CommandBase { T*instance; M method; - + virtual void call() { (instance->*method)(); } }; - + template struct Command1 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; - + virtual void call() { (instance->*method)(p1); } }; - + template struct Command2 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; typename GetSimpleTypeT::type_t p2; - + virtual void call() { (instance->*method)(p1,p2); } }; template struct Command3 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; typename GetSimpleTypeT::type_t p2; typename GetSimpleTypeT::type_t p3; - + virtual void call() { (instance->*method)(p1,p2,p3); } }; template struct Command4 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; typename GetSimpleTypeT::type_t p2; typename GetSimpleTypeT::type_t p3; typename GetSimpleTypeT::type_t p4; - + virtual void call() { (instance->*method)(p1,p2,p3,p4); } }; template struct Command5 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; @@ -117,13 +117,13 @@ class CommandQueueMT { typename GetSimpleTypeT::type_t p3; typename GetSimpleTypeT::type_t p4; typename GetSimpleTypeT::type_t p5; - + virtual void call() { (instance->*method)(p1,p2,p3,p4,p5); } }; template struct Command6 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; @@ -132,13 +132,13 @@ class CommandQueueMT { typename GetSimpleTypeT::type_t p4; typename GetSimpleTypeT::type_t p5; typename GetSimpleTypeT::type_t p6; - + virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6); } }; - + template struct Command7 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; @@ -148,12 +148,12 @@ class CommandQueueMT { typename GetSimpleTypeT::type_t p5; typename GetSimpleTypeT::type_t p6; typename GetSimpleTypeT::type_t p7; - + virtual void call() { (instance->*method)(p1,p2,p3,p4,p5,p6,p7); } }; - + /* comands that return */ - + template 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 struct CommandRet1 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; R* ret; SyncSemaphore *sync; - + virtual void call() { *ret = (instance->*method)(p1); sync->sem->post(); sync->in_use=false; } }; - + template struct CommandRet2 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; typename GetSimpleTypeT::type_t p2; R* ret; SyncSemaphore *sync; - + virtual void call() { *ret = (instance->*method)(p1,p2); sync->sem->post(); sync->in_use=false; ; } }; template struct CommandRet3 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; @@ -200,13 +200,13 @@ class CommandQueueMT { typename GetSimpleTypeT::type_t p3; R* ret; SyncSemaphore *sync; - + virtual void call() { *ret = (instance->*method)(p1,p2,p3); sync->sem->post(); sync->in_use=false; ; } }; template struct CommandRet4 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; @@ -215,13 +215,13 @@ class CommandQueueMT { typename GetSimpleTypeT::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 struct CommandRet5 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; @@ -231,13 +231,13 @@ class CommandQueueMT { typename GetSimpleTypeT::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 struct CommandRet6 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; @@ -248,13 +248,13 @@ class CommandQueueMT { typename GetSimpleTypeT::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 struct CommandRet7 : public CommandBase { - + T*instance; M method; typename GetSimpleTypeT::type_t p1; @@ -266,9 +266,9 @@ class CommandQueueMT { typename GetSimpleTypeT::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 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 T* allocate_and_lock() { - + lock(); T* ret; - + while ( (ret=allocate())==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( &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 void push( T * p_instance, M p_method ) { - + Command0 * cmd = allocate_and_lock< Command0 >(); - + cmd->instance=p_instance; cmd->method=p_method; - + unlock(); - + if (sync) sync->post(); } template void push( T * p_instance, M p_method, P1 p1 ) { - + Command1 * cmd = allocate_and_lock< Command1 >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; - + unlock(); - + if (sync) sync->post(); } template void push( T * p_instance, M p_method, P1 p1, P2 p2 ) { - + Command2 * cmd = allocate_and_lock< Command2 >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; cmd->p2=p2; - + unlock(); - + if (sync) sync->post(); } template void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3 ) { - + Command3 * cmd = allocate_and_lock< Command3 >(); - + cmd->instance=p_instance; cmd->method=p_method; cmd->p1=p1; cmd->p2=p2; cmd->p3=p3; - + unlock(); - + if (sync) sync->post(); } template void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4 ) { - + Command4 * cmd = allocate_and_lock< Command4 >(); - + 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 void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5 ) { - + Command5 * cmd = allocate_and_lock< Command5 >(); - + 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 void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6 ) { - + Command6 * cmd = allocate_and_lock< Command6 >(); - + 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 void push( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7 ) { - + Command7 * cmd = allocate_and_lock< Command7 >(); - + 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 void push_and_ret( T * p_instance, M p_method, R* r_ret) { - + CommandRet0 * cmd = allocate_and_lock< CommandRet0 >(); - + 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 void push_and_ret( T * p_instance, M p_method, P1 p1, R* r_ret) { - + CommandRet1 * cmd = allocate_and_lock< CommandRet1 >(); - + 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 void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, R* r_ret) { - + CommandRet2 * cmd = allocate_and_lock< CommandRet2 >(); - + 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 void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, R* r_ret ) { - + CommandRet3 * cmd = allocate_and_lock< CommandRet3 >(); - + 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 void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, R* r_ret ) { - + CommandRet4 * cmd = allocate_and_lock< CommandRet4 >(); - + 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 void push_and_ret( T * p_instance, M p_method, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, R* r_ret ) { - + CommandRet5 * cmd = allocate_and_lock< CommandRet5 >(); - + 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 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 * cmd = allocate_and_lock< CommandRet6 >(); - + 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 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 * cmd = allocate_and_lock< CommandRet7 >(); - + 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 17431b33a6a..fbb1fc4824a 100644 --- a/core/dvector.h +++ b/core/dvector.h @@ -43,18 +43,18 @@ template 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;iunlock(); - + } - + 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;iunlock(); - + } - + 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 @@ -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::get(int p_index) const { template void DVector::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::operator[](int p_index) const { } Read r = read(); - + return r[p_index]; } @@ -344,83 +344,83 @@ Error DVector::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= 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;iargs;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 af0a4df2b89..99e853fd281 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 d63f9c1bb40..c0c1171ae61 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 *p_list) const { - + _THREAD_SAFE_METHOD_ Set<_VCSort> vclist; - + for(Map::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 8951f5fbd27..68bb859ace1 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 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 *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& p_ignore_masks=Set()); @@ -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 33eb25652c3..e83710c700e 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 - * + * @author Juan Linietsky + * * 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 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< ( (1< ( (1<(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<next; int new_pos = se->hash & ((1<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 == 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<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<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( 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(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 == 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( 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<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<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<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 c2ed5bd6792..a917ee5edb8 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 798fc41f401..184ab70dc48 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::Read r = data.read(); @@ -413,7 +413,7 @@ void Image::convert( Format p_new_format ){ w = DVector::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=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;x0)?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 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& 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 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='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 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& 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 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& 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& 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 874ce1c424b..5a9b0357717 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 fabbcf19688..8fcc25a4deb 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 f87bc7be31e..e5ca8dfc020 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 b38fda36864..e6b01475b6c 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 9d405e15f70..058c26b8a98 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 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 e63b57533f4..a3c839e7618 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 dd53c8f8ebd..e0c01c94223 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 aa641f00b4b..05bad97e90e 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 extensions; get_recognized_extensions(&extensions); for (List::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;irecognize(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 *p_extensions) { - + for (int i=0;iget_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 3cc6c6cf430..c7998377928 100644 --- a/core/io/image_loader.h +++ b/core/io/image_loader.h @@ -41,11 +41,11 @@ /** * @class ImageScanLineLoader * @author Juan Linietsky - * - + * + */ 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 *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 *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 b8bd00c2fbf..a77aace07f6 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 4dccf21d2d2..1733aecd46c 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 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 7a5b16e8afa..6a46e9882a1 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 973a2ec9a53..22b8bc0b39e 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 c008c3f9a46..58f3a4df2b5 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 03b77a4aab9..a42a922baf0 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 67208b59604..abb10822564 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 extensions; get_recognized_extensions(&extensions); for (List::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;irecognize(extension)) continue; if (p_type_hint!="" && !loader[i]->handles_type(p_type_hint)) @@ -356,7 +356,7 @@ Ref 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 fe583030661..6404e6cb132 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -47,7 +47,7 @@ public: virtual Ref 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 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 load_import_metadata(const String &p_path); diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index 51020a0285e..8d78ecabbf8 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;irecognize(p_resource)) continue; - + List extensions; bool recognized=false; saver[i]->get_recognized_extensions(p_resource,&extensions); - + for (List::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 *p_extensions) { - + for (int i=0;iget_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 7bc96c1087e..97500c46f43 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 *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 fbeb653da46..b989f009a96 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 >(); } - + template 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 35dc73df48f..81cda1ece2f 100644 --- a/core/map.h +++ b/core/map.h @@ -39,12 +39,12 @@ template ,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(_nil); #endif // memdelete_allocator(_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(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( 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 0fada859c05..57fe1b32f5e 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 0c07b733f01..d16495217c2 100644 --- a/core/math/bsp_tree.cpp +++ b/core/math/bsp_tree.cpp @@ -66,12 +66,12 @@ Vector 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=node_count, false ); #endif - + steps++; } return false; } - - + + static int _bsp_find_best_half_plane(const Face3* p_faces,const Vector& 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& 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& 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& p_i return best_plane; } - + static int _bsp_create_node(const Face3 *p_faces,const Vector& p_indices,Vector &p_planes, Vector &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& 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& 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& p_indices,Ve } /* Create the node */ - + // find existing divisor plane int divisor_plane_idx=-1; - - + + for (int i=0;i& 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& p_faces,float p_error_radius) { // compute aabb - + int face_count=p_faces.size(); DVector::Read faces_r=p_faces.read(); const Face3 *facesptr = faces_r.ptr(); @@ -574,26 +574,26 @@ BSP_Tree::BSP_Tree(const DVector& p_faces,float p_error_radius) { Vector indices; for (int i=0;i& 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 a7145f9ff16..2bfc26b51e9 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 nodes; Vector 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 get_nodes() const; Vector 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 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& p_faces,float p_error_radius=0); - BSP_Tree(const Vector &p_nodes, const Vector &p_planes, const AABB& p_aabb,float p_error_radius=0); + BSP_Tree(const DVector& p_faces,float p_error_radius=0); + BSP_Tree(const Vector &p_nodes, const Vector &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 61c8b78e0af..f7dd8839b83 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 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 planes; - - const float * matrix = (const float*)this->matrix; + + const float * matrix = (const float*)this->matrix; Plane new_plane; @@ -275,7 +275,7 @@ Vector 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 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 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 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 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 27500a545eb..d192b1fef17 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 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 c36fdd13322..bc34be99354 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 2905d26fe56..5b767212f56 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::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 > 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=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& 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 Geometry::wrap_geometry( DVector< Face3 > p_array,float *p_erro print_line("Wrapper (2/6) Flood Filling"); for (int i=0;i wrapped_faces; - + for (int i=0;i::Write wrapped_facesw=wrapped_faces.write(); Face3* wrapped_faces_ptr=wrapped_facesw.ptr(); - + for(int i=0;i 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 &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;i0.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 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 &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 &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 &p_planes) { edge.b=b; mesh.edges.push_back(edge); } - - + + } return mesh; @@ -899,36 +899,36 @@ Geometry::MeshData Geometry::build_convex_mesh(const DVector &p_planes) { DVector Geometry::build_box_planes(const Vector3& p_extents) { DVector 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 Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) { DVector planes; - + for (int i=0;i Geometry::build_sphere_planes(float p_radius, int p_lats,int p_lo DVector Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) { DVector 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-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 indices; }; - + Vector faces; - + struct Edge { - + int a,b; }; - + Vector edges; - + Vector< Vector3 > vertices; void optimize_vertices(); @@ -927,7 +927,7 @@ public: static void make_atlas(const Vector& p_rects,Vector& r_result, Size2i& r_size); - + }; diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index a485125cb4f..0e2060008c5 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 11713646711..ad4655b8f78 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -35,15 +35,15 @@ @author Juan Linietsky */ 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 20d9db33757..07f114725d9 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 62890b03712..2e1b9c989e0 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 f51da80a833..71e6b622123 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 291934b8ebd..e514f490f7b 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 69edf80e09d..6080b216802 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 pairable_elements; List 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 pair_list; - + struct OctantOwner { - + Octant *octant; typename List::Element *E; - }; // an element can be in max 8 octants - + }; // an element can be in max 8 octants + List 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, AL> ElementMap; typedef Map, 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(p_octant); } public: @@ -432,24 +432,24 @@ template void Octree::_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::_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::_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::_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::_insert_element(Element *p_element,Octant *p_octant } } - + if (candidate && splits>1) { p_element->common_parent=p_octant; } - + } - + if (use_pairs) { typename List::Element *E=p_octant->pairable_elements.front(); @@ -532,8 +532,8 @@ void Octree::_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::_insert_element(Element *p_element,Octant *p_octant _pair_reference( p_element,E->get() ); E=E->next(); } - } + } } - + } @@ -553,35 +553,35 @@ void Octree::_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::_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::_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 bool Octree::_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::_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::_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::_remove_element_from_octant(Element *p_element,Octa template void Octree::_unpair_element(Element *p_element,Octant *p_octant) { - - // always test pairable + + // always test pairable typename List::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::_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::_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::_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::_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 void Octree::_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::_remove_element(Element *p_element) { int remaining=p_element->pair_list.size(); //p_element->pair_list.clear(); ERR_FAIL_COND( remaining ); - } + } } template OctreeElementID Octree::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::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::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::move(OctreeElementID p_id, const AABB& p_aabb) { _insert_element(&e,common_parent); // reinsert from this point pass++; - + for(typename List::Element *E=owners.front();E;) { Octant *o=E->get().octant; @@ -1018,28 +1018,28 @@ void Octree::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::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 void Octree::_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_idxresult_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_idxresult_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 void Octree::_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_idxuserdata; 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_idxuserdata; 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::_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_idxuserdata; 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_idxuserdata; if (p_subindex_array) p_subindex_array[*p_result_idx] = e->subindex; @@ -1259,20 +1259,20 @@ void Octree::_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::cull_convex(const Vector& p_convex,T** p_resu if (!root) return 0; - + int result_count=0; pass++; _CullConvexData cdata; @@ -1367,9 +1367,9 @@ int Octree::cull_convex(const Vector& 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::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::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::set_unpair_callback( UnpairCallback p_callback, voi template Octree::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 d17ce01beca..b29350fe3c9 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 d20e63dc47a..81a968682e6 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 ebc5ec4e65f..c6c12129b30 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 738b6946c78..0d206bb3b76 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 8371f7e34b7..22eb6c4fdd3 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 bd1247084dc..f948a4c919f 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 da3d7c10626..48848c58486 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -58,8 +58,8 @@ template struct VariantCaster { static _FORCE_INLINE_ T cast(const Variant& p_variant) { - - return p_variant; + + return p_variant; } }; @@ -67,8 +67,8 @@ template struct VariantCaster { static _FORCE_INLINE_ T cast(const Variant& p_variant) { - - return p_variant; + + return p_variant; } }; @@ -76,8 +76,8 @@ template struct VariantCaster { 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 c92fc35b241..7bdec06c1be 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 *p_parents) { - - + + } void Object::_get_valid_parents_static(List *p_parents) { - - + + } #if 0 //old style set, deprecated @@ -286,7 +286,7 @@ void Object::_get_valid_parents_static(List *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(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 *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 *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 *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