summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/os/os.h2
-rw-r--r--doc/tools/makerst.py45
-rw-r--r--drivers/unix/os_unix.h2
-rw-r--r--editor/editor_data.cpp10
-rw-r--r--editor/editor_data.h4
-rw-r--r--editor/editor_log.cpp4
-rw-r--r--editor/editor_plugin.cpp10
-rw-r--r--editor/editor_plugin.h3
-rw-r--r--editor/editor_settings.cpp36
-rw-r--r--editor/editor_themes.cpp3
-rw-r--r--editor/project_manager.cpp1
-rw-r--r--main/main.cpp5
-rw-r--r--modules/bullet/bullet_types_converter.cpp11
-rw-r--r--modules/bullet/bullet_types_converter.h1
-rw-r--r--modules/bullet/collision_object_bullet.cpp22
-rw-r--r--modules/bullet/collision_object_bullet.h1
-rw-r--r--modules/bullet/rigid_body_bullet.cpp39
-rw-r--r--modules/bullet/shape_bullet.cpp55
-rw-r--r--modules/bullet/shape_bullet.h20
-rw-r--r--modules/bullet/space_bullet.cpp235
-rw-r--r--modules/bullet/space_bullet.h13
-rw-r--r--modules/stb_vorbis/audio_stream_ogg_vorbis.cpp15
-rw-r--r--modules/stb_vorbis/audio_stream_ogg_vorbis.h2
-rw-r--r--platform/android/os_android.cpp4
-rw-r--r--platform/android/os_android.h2
-rw-r--r--platform/haiku/os_haiku.cpp6
-rw-r--r--platform/haiku/os_haiku.h2
-rw-r--r--platform/iphone/os_iphone.cpp4
-rw-r--r--platform/iphone/os_iphone.h2
-rw-r--r--platform/javascript/os_javascript.cpp6
-rw-r--r--platform/javascript/os_javascript.h2
-rw-r--r--platform/osx/os_osx.h2
-rw-r--r--platform/osx/os_osx.mm34
-rw-r--r--platform/server/os_server.cpp6
-rw-r--r--platform/server/os_server.h2
-rw-r--r--platform/uwp/os_uwp.cpp4
-rw-r--r--platform/uwp/os_uwp.h2
-rw-r--r--platform/windows/os_windows.cpp10
-rw-r--r--platform/windows/os_windows.h2
-rw-r--r--platform/x11/os_x11.cpp27
-rw-r--r--platform/x11/os_x11.h2
-rw-r--r--scene/register_scene_types.cpp74
-rw-r--r--scene/resources/default_theme/default_theme.cpp4
-rw-r--r--servers/visual/shader_language.cpp6
44 files changed, 480 insertions, 262 deletions
diff --git a/core/os/os.h b/core/os/os.h
index c9c228cfaf..a4f07df0e8 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -121,7 +121,7 @@ protected:
void add_logger(Logger *p_logger);
virtual void initialize_core() = 0;
- virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) = 0;
+ virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) = 0;
virtual void set_main_loop(MainLoop *p_main_loop) = 0;
virtual void delete_main_loop() = 0;
diff --git a/doc/tools/makerst.py b/doc/tools/makerst.py
index cd0108019b..492f3b6d54 100644
--- a/doc/tools/makerst.py
+++ b/doc/tools/makerst.py
@@ -276,6 +276,15 @@ def make_type(t):
return ':ref:`' + t + '<class_' + t.lower() + '>`'
return t
+def make_enum(t):
+ global class_names
+ p = t.find(".")
+ if p >= 0:
+ c = t[0:p]
+ e = t[p+1:]
+ if c in class_names:
+ return ':ref:`' + e + '<enum_' + c.lower() + '_' + e.lower() + '>`'
+ return t
def make_method(
f,
@@ -470,7 +479,10 @@ def make_rst_class(node):
# Leading two spaces necessary to prevent breaking the <ul>
f.write(" .. _class_" + name + "_" + c.attrib['name'] + ":\n\n")
s = '- '
- s += make_type(c.attrib['type']) + ' '
+ if 'enum' in c.attrib:
+ s += make_enum(c.attrib['enum']) + ' '
+ else:
+ s += make_type(c.attrib['type']) + ' '
s += '**' + c.attrib['name'] + '**'
if c.text.strip() != '':
s += ' - ' + rstize_text(c.text.strip(), name)
@@ -478,9 +490,20 @@ def make_rst_class(node):
f.write('\n')
constants = node.find('constants')
+ consts = []
+ enum_names = set()
+ enums = []
if constants != None and len(list(constants)) > 0:
- f.write(make_heading('Numeric Constants', '-'))
for c in list(constants):
+ if 'enum' in c.attrib:
+ enum_names.add(c.attrib['enum'])
+ enums.append(c)
+ else:
+ consts.append(c)
+
+ if len(consts) > 0:
+ f.write(make_heading('Numeric Constants', '-'))
+ for c in list(consts):
s = '- '
s += '**' + c.attrib['name'] + '**'
if 'value' in c.attrib:
@@ -489,6 +512,24 @@ def make_rst_class(node):
s += ' --- ' + rstize_text(c.text.strip(), name)
f.write(s + '\n')
f.write('\n')
+
+ if len(enum_names) > 0:
+ f.write(make_heading('Enums', '-'))
+ for e in enum_names:
+ f.write(" .. _enum_" + name + "_" + e + ":\n\n")
+ f.write("enum **" + e + "**\n\n")
+ for c in enums:
+ if c.attrib['enum'] != e:
+ continue
+ s = '- '
+ s += '**' + c.attrib['name'] + '**'
+ if 'value' in c.attrib:
+ s += ' = **' + c.attrib['value'] + '**'
+ if c.text.strip() != '':
+ s += ' --- ' + rstize_text(c.text.strip(), name)
+ f.write(s + '\n')
+ f.write('\n')
+ f.write('\n')
descr = node.find('description')
if descr != None and descr.text.strip() != '':
diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h
index 7929a791cb..d224a55647 100644
--- a/drivers/unix/os_unix.h
+++ b/drivers/unix/os_unix.h
@@ -55,7 +55,7 @@ protected:
virtual void initialize_core();
virtual int unix_initialize_audio(int p_audio_driver);
- //virtual void initialize(int p_video_driver,int p_audio_driver);
+ //virtual Error initialize(int p_video_driver,int p_audio_driver);
virtual void finalize_core();
diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp
index 4acee1363c..c12a112fa4 100644
--- a/editor/editor_data.cpp
+++ b/editor/editor_data.cpp
@@ -880,6 +880,7 @@ void EditorSelection::_bind_methods() {
ClassDB::bind_method(D_METHOD("remove_node", "node"), &EditorSelection::remove_node);
ClassDB::bind_method(D_METHOD("get_selected_nodes"), &EditorSelection::_get_selected_nodes);
ClassDB::bind_method(D_METHOD("get_transformable_selected_nodes"), &EditorSelection::_get_transformable_selected_nodes);
+ ClassDB::bind_method(D_METHOD("_emit_change"), &EditorSelection::_emit_change);
ADD_SIGNAL(MethodInfo("selection_changed"));
}
@@ -923,7 +924,15 @@ void EditorSelection::update() {
if (!changed)
return;
changed = false;
+ if (!emitted) {
+ emitted = true;
+ call_deferred("_emit_change");
+ }
+}
+
+void EditorSelection::_emit_change() {
emit_signal("selection_changed");
+ emitted = false;
}
List<Node *> &EditorSelection::get_selected_node_list() {
@@ -947,6 +956,7 @@ void EditorSelection::clear() {
}
EditorSelection::EditorSelection() {
+ emitted = false;
changed = false;
nl_changed = false;
}
diff --git a/editor/editor_data.h b/editor/editor_data.h
index 2c95c3feea..3bc0e6e75c 100644
--- a/editor/editor_data.h
+++ b/editor/editor_data.h
@@ -210,9 +210,10 @@ class EditorSelection : public Object {
GDCLASS(EditorSelection, Object);
-public:
+private:
Map<Node *, Object *> selection;
+ bool emitted;
bool changed;
bool nl_changed;
@@ -224,6 +225,7 @@ public:
void _update_nl();
Array _get_selected_nodes();
Array _get_transformable_selected_nodes();
+ void _emit_change();
protected:
static void _bind_methods();
diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp
index 1b885adf37..79542f3b5c 100644
--- a/editor/editor_log.cpp
+++ b/editor/editor_log.cpp
@@ -66,7 +66,9 @@ void EditorLog::_notification(int p_what) {
Ref<DynamicFont> df_output_code = get_font("output_source", "EditorFonts");
if (df_output_code.is_valid()) {
df_output_code->set_size(int(EDITOR_DEF("run/output/font_size", 13)) * EDSCALE);
- log->add_font_override("normal_font", get_font("output_source", "EditorFonts"));
+ if (log != NULL) {
+ log->add_font_override("normal_font", get_font("output_source", "EditorFonts"));
+ }
}
}
diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp
index b3ac5e4ce5..16e60edda7 100644
--- a/editor/editor_plugin.cpp
+++ b/editor/editor_plugin.cpp
@@ -200,6 +200,14 @@ ScriptEditor *EditorInterface::get_script_editor() {
return ScriptEditor::get_singleton();
}
+void EditorInterface::select_file(const String &p_file) {
+ return EditorNode::get_singleton()->get_filesystem_dock()->select_file(p_file);
+}
+
+String EditorInterface::get_selected_path() const {
+ return EditorNode::get_singleton()->get_filesystem_dock()->get_selected_path();
+}
+
void EditorInterface::inspect_object(Object *p_obj, const String &p_for_property) {
EditorNode::get_singleton()->push_item(p_obj, p_for_property);
@@ -259,6 +267,8 @@ void EditorInterface::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_resource_filesystem"), &EditorInterface::get_resource_file_system);
ClassDB::bind_method(D_METHOD("get_editor_viewport"), &EditorInterface::get_editor_viewport);
ClassDB::bind_method(D_METHOD("make_mesh_previews", "meshes", "preview_size"), &EditorInterface::_make_mesh_previews);
+ ClassDB::bind_method(D_METHOD("select_file", "p_file"), &EditorInterface::select_file);
+ ClassDB::bind_method(D_METHOD("get_selected_path"), &EditorInterface::get_selected_path);
ClassDB::bind_method(D_METHOD("save_scene"), &EditorInterface::save_scene);
ClassDB::bind_method(D_METHOD("save_scene_as", "path", "with_preview"), &EditorInterface::save_scene_as, DEFVAL(true));
diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h
index 4bfa1fa7cf..887e599208 100644
--- a/editor/editor_plugin.h
+++ b/editor/editor_plugin.h
@@ -76,6 +76,9 @@ public:
Array get_open_scenes() const;
ScriptEditor *get_script_editor();
+ void select_file(const String &p_file);
+ String get_selected_path() const;
+
void inspect_object(Object *p_obj, const String &p_for_property = String());
EditorSelection *get_selection();
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index dc82a02f46..a5001cb1ac 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -1329,8 +1329,44 @@ Ref<ShortCut> ED_GET_SHORTCUT(const String &p_path) {
return sc;
}
+struct ShortCutMapping {
+ const char *path;
+ uint32_t keycode;
+};
+
Ref<ShortCut> ED_SHORTCUT(const String &p_path, const String &p_name, uint32_t p_keycode) {
+#ifdef OSX_ENABLED
+ static const ShortCutMapping macos_mappings[] = {
+ { "editor/play", KEY_MASK_CMD | KEY_B },
+ { "editor/play_scene", KEY_MASK_CMD | KEY_R },
+ { "editor/pause_scene", KEY_MASK_CMD | KEY_MASK_CTRL | KEY_Y },
+ { "editor/stop", KEY_MASK_CMD | KEY_PERIOD },
+ { "editor/play_custom_scene", KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_R },
+ { "editor/editor_2d", KEY_MASK_ALT | KEY_1 },
+ { "editor/editor_3d", KEY_MASK_ALT | KEY_2 },
+ { "editor/editor_script", KEY_MASK_ALT | KEY_3 },
+ { "editor/editor_help", KEY_MASK_ALT | KEY_SPACE },
+ { "editor/fullscreen_mode", KEY_MASK_CMD | KEY_MASK_CTRL | KEY_F },
+ { "editor/distraction_free_mode", KEY_MASK_CMD | KEY_MASK_CTRL | KEY_D },
+ { "script_text_editor/contextual_help", KEY_MASK_ALT | KEY_MASK_SHIFT | KEY_SPACE },
+ { "script_text_editor/find_next", KEY_MASK_CMD | KEY_G },
+ { "script_text_editor/find_previous", KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_G },
+ { "script_text_editor/toggle_breakpoint", KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B }
+ };
+
+ if (p_keycode == KEY_DELETE) {
+ p_keycode = KEY_MASK_CMD | KEY_BACKSPACE;
+ } else {
+ for (int i = 0; i < sizeof(macos_mappings) / sizeof(ShortCutMapping); i++) {
+ if (p_path == macos_mappings[i].path) {
+ p_keycode = macos_mappings[i].keycode;
+ break;
+ }
+ }
+ }
+#endif
+
Ref<InputEventKey> ie;
if (p_keycode) {
ie.instance();
diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp
index b19d015455..8a3e7e6716 100644
--- a/editor/editor_themes.cpp
+++ b/editor/editor_themes.cpp
@@ -332,6 +332,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
const Color font_color = mono_color.linear_interpolate(base_color, 0.25);
const Color font_color_hl = mono_color.linear_interpolate(base_color, 0.15);
const Color font_color_disabled = Color(mono_color.r, mono_color.g, mono_color.b, 0.3);
+ const Color font_color_selection = Color::html("#7d7d7d");
const Color color_disabled = mono_color.inverted().linear_interpolate(base_color, 0.7);
const Color color_disabled_bg = mono_color.inverted().linear_interpolate(base_color, 0.9);
@@ -790,6 +791,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_color("read_only", "LineEdit", font_color_disabled);
theme->set_color("font_color", "LineEdit", font_color);
theme->set_color("cursor_color", "LineEdit", font_color);
+ theme->set_color("selection_color", "LineEdit", font_color_selection);
// TextEdit
theme->set_stylebox("normal", "TextEdit", style_widget);
@@ -799,6 +801,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_icon("tab", "TextEdit", theme->get_icon("GuiTab", "EditorIcons"));
theme->set_color("font_color", "TextEdit", font_color);
theme->set_color("caret_color", "TextEdit", highlight_color);
+ theme->set_color("selection_color", "TextEdit", font_color_selection);
// H/VSplitContainer
theme->set_stylebox("bg", "VSplitContainer", make_stylebox(theme->get_icon("GuiVsplitBg", "EditorIcons"), 1, 1, 1, 1));
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index eb5cec2a2e..3d4ae90c89 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -1101,6 +1101,7 @@ void ProjectManager::_load_recent_projects() {
hb->add_child(vb);
Control *ec = memnew(Control);
ec->set_custom_minimum_size(Size2(0, 1));
+ ec->set_mouse_filter(MOUSE_FILTER_PASS);
vb->add_child(ec);
Label *title = memnew(Label(project_name));
title->add_font_override("font", gui_base->get_font("title", "EditorFonts"));
diff --git a/main/main.cpp b/main/main.cpp
index ac68fe1296..1cb89e87ef 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -983,7 +983,10 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
Thread::_main_thread_id = p_main_tid_override;
}
- OS::get_singleton()->initialize(video_mode, video_driver_idx, audio_driver_idx);
+ Error err = OS::get_singleton()->initialize(video_mode, video_driver_idx, audio_driver_idx);
+ if (err != OK) {
+ return err;
+ }
if (init_use_custom_pos) {
OS::get_singleton()->set_window_position(init_custom_pos);
}
diff --git a/modules/bullet/bullet_types_converter.cpp b/modules/bullet/bullet_types_converter.cpp
index 03247a91ca..42a6f156a5 100644
--- a/modules/bullet/bullet_types_converter.cpp
+++ b/modules/bullet/bullet_types_converter.cpp
@@ -92,3 +92,14 @@ void G_TO_B(Transform const &inVal, btTransform &outVal) {
G_TO_B(inVal.basis, outVal.getBasis());
G_TO_B(inVal.origin, outVal.getOrigin());
}
+
+void UNSCALE_BT_BASIS(btTransform &scaledBasis) {
+ btMatrix3x3 &m(scaledBasis.getBasis());
+ btVector3 column0(m[0][0], m[1][0], m[2][0]);
+ btVector3 column1(m[0][1], m[1][1], m[2][1]);
+ btVector3 column2(m[0][2], m[1][2], m[2][2]);
+ column0.normalize();
+ column1.normalize();
+ column2.normalize();
+ m.setValue(column0[0], column1[0], column2[0], column0[1], column1[1], column2[1], column0[2], column1[2], column2[2]);
+}
diff --git a/modules/bullet/bullet_types_converter.h b/modules/bullet/bullet_types_converter.h
index 5fa30c1d74..349cad65aa 100644
--- a/modules/bullet/bullet_types_converter.h
+++ b/modules/bullet/bullet_types_converter.h
@@ -54,4 +54,5 @@ extern void G_TO_B(Basis const &inVal, btMatrix3x3 &outVal);
extern void INVERT_G_TO_B(Basis const &inVal, btMatrix3x3 &outVal);
extern void G_TO_B(Transform const &inVal, btTransform &outVal);
+extern void UNSCALE_BT_BASIS(btTransform &scaledBasis);
#endif
diff --git a/modules/bullet/collision_object_bullet.cpp b/modules/bullet/collision_object_bullet.cpp
index 70d604fa70..1350be20b6 100644
--- a/modules/bullet/collision_object_bullet.cpp
+++ b/modules/bullet/collision_object_bullet.cpp
@@ -57,7 +57,8 @@ CollisionObjectBullet::CollisionObjectBullet(Type p_type) :
collisionsEnabled(true),
m_isStatic(false),
bt_collision_object(NULL),
- body_scale(1., 1., 1.) {}
+ body_scale(1., 1., 1.),
+ force_shape_reset(false) {}
CollisionObjectBullet::~CollisionObjectBullet() {
// Remove all overlapping
@@ -88,6 +89,7 @@ btVector3 CollisionObjectBullet::get_bt_body_scale() const {
}
void CollisionObjectBullet::on_body_scale_changed() {
+ force_shape_reset = true;
}
void CollisionObjectBullet::destroyBulletCollisionObject() {
@@ -289,15 +291,27 @@ void RigidCollisionObjectBullet::on_shape_changed(const ShapeBullet *const p_sha
void RigidCollisionObjectBullet::on_shapes_changed() {
int i;
+
// Remove all shapes, reverse order for performance reason (Array resize)
for (i = compoundShape->getNumChildShapes() - 1; 0 <= i; --i) {
compoundShape->removeChildShapeByIndex(i);
}
- // Insert all shapes
ShapeWrapper *shpWrapper;
- const int size = shapes.size();
- for (i = 0; i < size; ++i) {
+ const int shapes_size = shapes.size();
+
+ // Reset shape if required
+ if (force_shape_reset) {
+ for (i = 0; i < shapes_size; ++i) {
+ shpWrapper = &shapes[i];
+ bulletdelete(shpWrapper->bt_shape);
+ }
+ force_shape_reset = false;
+ }
+
+ // Insert all shapes
+
+ for (i = 0; i < shapes_size; ++i) {
shpWrapper = &shapes[i];
if (shpWrapper->active) {
if (!shpWrapper->bt_shape) {
diff --git a/modules/bullet/collision_object_bullet.h b/modules/bullet/collision_object_bullet.h
index 4168133e0d..6a3fbe65ff 100644
--- a/modules/bullet/collision_object_bullet.h
+++ b/modules/bullet/collision_object_bullet.h
@@ -115,6 +115,7 @@ protected:
bool ray_pickable;
btCollisionObject *bt_collision_object;
Vector3 body_scale;
+ bool force_shape_reset;
SpaceBullet *space;
VSet<RID> exceptions;
diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp
index e7342e2ae8..c183b012ab 100644
--- a/modules/bullet/rigid_body_bullet.cpp
+++ b/modules/bullet/rigid_body_bullet.cpp
@@ -205,41 +205,20 @@ void RigidBodyBullet::KinematicUtilities::copyAllOwnerShapes() {
if (!shape_wrapper->active) {
continue;
}
- shapes[i].transform = shape_wrapper->transform;
-
- btConvexShape *&kin_shape_ref = shapes[i].shape;
+ shapes[i].transform = shape_wrapper->transform;
+ shapes[i].transform.getOrigin() *= owner_body_scale;
switch (shape_wrapper->shape->get_type()) {
- case PhysicsServer::SHAPE_SPHERE: {
- SphereShapeBullet *sphere = static_cast<SphereShapeBullet *>(shape_wrapper->shape);
- kin_shape_ref = ShapeBullet::create_shape_sphere(sphere->get_radius() * owner_body_scale[0] + safe_margin);
- break;
- }
- case PhysicsServer::SHAPE_BOX: {
- BoxShapeBullet *box = static_cast<BoxShapeBullet *>(shape_wrapper->shape);
- kin_shape_ref = ShapeBullet::create_shape_box((box->get_half_extents() * owner_body_scale) + btVector3(safe_margin, safe_margin, safe_margin));
- break;
- }
- case PhysicsServer::SHAPE_CAPSULE: {
- CapsuleShapeBullet *capsule = static_cast<CapsuleShapeBullet *>(shape_wrapper->shape);
-
- kin_shape_ref = ShapeBullet::create_shape_capsule(capsule->get_radius() * owner_body_scale[0] + safe_margin, capsule->get_height() * owner_body_scale[1] + safe_margin);
- break;
- }
- case PhysicsServer::SHAPE_CONVEX_POLYGON: {
- ConvexPolygonShapeBullet *godot_convex = static_cast<ConvexPolygonShapeBullet *>(shape_wrapper->shape);
- kin_shape_ref = ShapeBullet::create_shape_convex(godot_convex->vertices);
- kin_shape_ref->setLocalScaling(owner_body_scale + btVector3(safe_margin, safe_margin, safe_margin));
- break;
- }
+ case PhysicsServer::SHAPE_SPHERE:
+ case PhysicsServer::SHAPE_BOX:
+ case PhysicsServer::SHAPE_CAPSULE:
+ case PhysicsServer::SHAPE_CONVEX_POLYGON:
case PhysicsServer::SHAPE_RAY: {
- RayShapeBullet *godot_ray = static_cast<RayShapeBullet *>(shape_wrapper->shape);
- kin_shape_ref = ShapeBullet::create_shape_ray(godot_ray->length * owner_body_scale[1] + safe_margin);
- break;
- }
+ shapes[i].shape = static_cast<btConvexShape *>(shape_wrapper->shape->create_bt_shape(owner_body_scale, safe_margin));
+ } break;
default:
WARN_PRINT("This shape is not supported to be kinematic!");
- kin_shape_ref = NULL;
+ shapes[i].shape = NULL;
}
}
}
diff --git a/modules/bullet/shape_bullet.cpp b/modules/bullet/shape_bullet.cpp
index 55cc742f0a..d5a89e39e2 100644
--- a/modules/bullet/shape_bullet.cpp
+++ b/modules/bullet/shape_bullet.cpp
@@ -43,6 +43,17 @@ ShapeBullet::ShapeBullet() {}
ShapeBullet::~ShapeBullet() {}
+btCollisionShape *ShapeBullet::create_bt_shape() {
+ btVector3 s(1, 1, 1);
+ return create_bt_shape(s);
+}
+
+btCollisionShape *ShapeBullet::create_bt_shape(const Vector3 &p_implicit_scale, real_t p_margin) {
+ btVector3 s;
+ G_TO_B(p_implicit_scale, s);
+ return create_bt_shape(s, p_margin);
+}
+
btCollisionShape *ShapeBullet::prepare(btCollisionShape *p_btShape) const {
p_btShape->setUserPointer(const_cast<ShapeBullet *>(this));
p_btShape->setMargin(0.);
@@ -150,7 +161,7 @@ void PlaneShapeBullet::setup(const Plane &p_plane) {
notifyShapeChanged();
}
-btCollisionShape *PlaneShapeBullet::create_bt_shape() {
+btCollisionShape *PlaneShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) {
btVector3 btPlaneNormal;
G_TO_B(plane.normal, btPlaneNormal);
return prepare(PlaneShapeBullet::create_shape_plane(btPlaneNormal, plane.d));
@@ -178,8 +189,8 @@ void SphereShapeBullet::setup(real_t p_radius) {
notifyShapeChanged();
}
-btCollisionShape *SphereShapeBullet::create_bt_shape() {
- return prepare(ShapeBullet::create_shape_sphere(radius));
+btCollisionShape *SphereShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) {
+ return prepare(ShapeBullet::create_shape_sphere(radius * p_implicit_scale[0] + p_margin));
}
/* Box */
@@ -205,8 +216,8 @@ void BoxShapeBullet::setup(const Vector3 &p_half_extents) {
notifyShapeChanged();
}
-btCollisionShape *BoxShapeBullet::create_bt_shape() {
- return prepare(ShapeBullet::create_shape_box(half_extents));
+btCollisionShape *BoxShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) {
+ return prepare(ShapeBullet::create_shape_box((half_extents * p_implicit_scale) + btVector3(p_margin, p_margin, p_margin)));
}
/* Capsule */
@@ -238,8 +249,8 @@ void CapsuleShapeBullet::setup(real_t p_height, real_t p_radius) {
notifyShapeChanged();
}
-btCollisionShape *CapsuleShapeBullet::create_bt_shape() {
- return prepare(ShapeBullet::create_shape_capsule(radius, height));
+btCollisionShape *CapsuleShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) {
+ return prepare(ShapeBullet::create_shape_capsule(radius * p_implicit_scale[0] + p_margin, height * p_implicit_scale[1] + p_margin));
}
/* Convex polygon */
@@ -280,8 +291,12 @@ void ConvexPolygonShapeBullet::setup(const Vector<Vector3> &p_vertices) {
notifyShapeChanged();
}
-btCollisionShape *ConvexPolygonShapeBullet::create_bt_shape() {
- return prepare(ShapeBullet::create_shape_convex(vertices));
+btCollisionShape *ConvexPolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) {
+ btCollisionShape *cs(ShapeBullet::create_shape_convex(vertices));
+ cs->setLocalScaling(p_implicit_scale);
+ prepare(cs);
+ cs->setMargin(p_margin);
+ return cs;
}
/* Concave polygon */
@@ -349,13 +364,15 @@ void ConcavePolygonShapeBullet::setup(PoolVector<Vector3> p_faces) {
notifyShapeChanged();
}
-btCollisionShape *ConcavePolygonShapeBullet::create_bt_shape() {
+btCollisionShape *ConcavePolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) {
btCollisionShape *cs = ShapeBullet::create_shape_concave(meshShape);
- if (!cs) {
+ if (!cs)
// This is necessary since if 0 faces the creation of concave return NULL
cs = ShapeBullet::create_shape_empty();
- }
- return prepare(cs);
+ cs->setLocalScaling(p_implicit_scale);
+ prepare(cs);
+ cs->setMargin(p_margin);
+ return cs;
}
/* Height map shape */
@@ -407,8 +424,12 @@ void HeightMapShapeBullet::setup(PoolVector<real_t> &p_heights, int p_width, int
notifyShapeChanged();
}
-btCollisionShape *HeightMapShapeBullet::create_bt_shape() {
- return prepare(ShapeBullet::create_shape_height_field(heights, width, depth, cell_size));
+btCollisionShape *HeightMapShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) {
+ btCollisionShape *cs(ShapeBullet::create_shape_height_field(heights, width, depth, cell_size));
+ cs->setLocalScaling(p_implicit_scale);
+ prepare(cs);
+ cs->setMargin(p_margin);
+ return cs;
}
/* Ray shape */
@@ -433,6 +454,6 @@ void RayShapeBullet::setup(real_t p_length) {
notifyShapeChanged();
}
-btCollisionShape *RayShapeBullet::create_bt_shape() {
- return prepare(ShapeBullet::create_shape_ray(length));
+btCollisionShape *RayShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) {
+ return prepare(ShapeBullet::create_shape_ray(length * p_implicit_scale[1] + p_margin));
}
diff --git a/modules/bullet/shape_bullet.h b/modules/bullet/shape_bullet.h
index fa12e95efc..a9782a9333 100644
--- a/modules/bullet/shape_bullet.h
+++ b/modules/bullet/shape_bullet.h
@@ -58,7 +58,9 @@ public:
ShapeBullet();
virtual ~ShapeBullet();
- virtual btCollisionShape *create_bt_shape() = 0;
+ btCollisionShape *create_bt_shape();
+ btCollisionShape *create_bt_shape(const Vector3 &p_implicit_scale, real_t p_margin = 0);
+ virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0) = 0;
void add_owner(ShapeOwnerBullet *p_owner);
void remove_owner(ShapeOwnerBullet *p_owner, bool p_permanentlyFromThisBody = false);
@@ -94,7 +96,7 @@ public:
virtual void set_data(const Variant &p_data);
virtual Variant get_data() const;
virtual PhysicsServer::ShapeType get_type() const;
- virtual btCollisionShape *create_bt_shape();
+ virtual btCollisionShape *create_bt_shape(const btVector3 &p_scale, real_t p_margin = 0);
private:
void setup(const Plane &p_plane);
@@ -111,7 +113,7 @@ public:
virtual void set_data(const Variant &p_data);
virtual Variant get_data() const;
virtual PhysicsServer::ShapeType get_type() const;
- virtual btCollisionShape *create_bt_shape();
+ virtual btCollisionShape *create_bt_shape(const btVector3 &p_scale, real_t p_margin = 0);
private:
void setup(real_t p_radius);
@@ -128,7 +130,7 @@ public:
virtual void set_data(const Variant &p_data);
virtual Variant get_data() const;
virtual PhysicsServer::ShapeType get_type() const;
- virtual btCollisionShape *create_bt_shape();
+ virtual btCollisionShape *create_bt_shape(const btVector3 &p_scale, real_t p_margin = 0);
private:
void setup(const Vector3 &p_half_extents);
@@ -147,7 +149,7 @@ public:
virtual void set_data(const Variant &p_data);
virtual Variant get_data() const;
virtual PhysicsServer::ShapeType get_type() const;
- virtual btCollisionShape *create_bt_shape();
+ virtual btCollisionShape *create_bt_shape(const btVector3 &p_scale, real_t p_margin = 0);
private:
void setup(real_t p_height, real_t p_radius);
@@ -164,7 +166,7 @@ public:
void get_vertices(Vector<Vector3> &out_vertices);
virtual Variant get_data() const;
virtual PhysicsServer::ShapeType get_type() const;
- virtual btCollisionShape *create_bt_shape();
+ virtual btCollisionShape *create_bt_shape(const btVector3 &p_scale, real_t p_margin = 0);
private:
void setup(const Vector<Vector3> &p_vertices);
@@ -182,7 +184,7 @@ public:
virtual void set_data(const Variant &p_data);
virtual Variant get_data() const;
virtual PhysicsServer::ShapeType get_type() const;
- virtual btCollisionShape *create_bt_shape();
+ virtual btCollisionShape *create_bt_shape(const btVector3 &p_scale, real_t p_margin = 0);
private:
void setup(PoolVector<Vector3> p_faces);
@@ -201,7 +203,7 @@ public:
virtual void set_data(const Variant &p_data);
virtual Variant get_data() const;
virtual PhysicsServer::ShapeType get_type() const;
- virtual btCollisionShape *create_bt_shape();
+ virtual btCollisionShape *create_bt_shape(const btVector3 &p_scale, real_t p_margin = 0);
private:
void setup(PoolVector<real_t> &p_heights, int p_width, int p_depth, real_t p_cell_size);
@@ -217,7 +219,7 @@ public:
virtual void set_data(const Variant &p_data);
virtual Variant get_data() const;
virtual PhysicsServer::ShapeType get_type() const;
- virtual btCollisionShape *create_bt_shape();
+ virtual btCollisionShape *create_bt_shape(const btVector3 &p_scale, real_t p_margin = 0);
private:
void setup(real_t p_length);
diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp
index dc16d8402d..a67c627ba4 100644
--- a/modules/bullet/space_bullet.cpp
+++ b/modules/bullet/space_bullet.cpp
@@ -116,7 +116,7 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra
ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape);
- btCollisionShape *btShape = shape->create_bt_shape();
+ btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale(), p_margin);
if (!btShape->isConvex()) {
bulletdelete(btShape);
ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type()));
@@ -124,12 +124,9 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra
}
btConvexShape *btConvex = static_cast<btConvexShape *>(btShape);
- btVector3 scale_with_margin;
- G_TO_B(p_xform.basis.get_scale(), scale_with_margin);
- btConvex->setLocalScaling(scale_with_margin);
-
btTransform bt_xform;
G_TO_B(p_xform, bt_xform);
+ UNSCALE_BT_BASIS(bt_xform);
btCollisionObject collision_object;
collision_object.setCollisionShape(btConvex);
@@ -138,7 +135,7 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra
GodotAllContactResultCallback btQuery(&collision_object, p_results, p_result_max, &p_exclude);
btQuery.m_collisionFilterGroup = 0;
btQuery.m_collisionFilterMask = p_collision_mask;
- btQuery.m_closestDistanceThreshold = p_margin;
+ btQuery.m_closestDistanceThreshold = 0;
space->dynamicsWorld->contactTest(&collision_object, btQuery);
bulletdelete(btConvex);
@@ -149,7 +146,7 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra
bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, ShapeRestInfo *r_info) {
ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape);
- btCollisionShape *btShape = shape->create_bt_shape();
+ btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale(), p_margin);
if (!btShape->isConvex()) {
bulletdelete(btShape);
ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type()));
@@ -160,12 +157,9 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf
btVector3 bt_motion;
G_TO_B(p_motion, bt_motion);
- btVector3 scale_with_margin;
- G_TO_B(p_xform.basis.get_scale() + Vector3(p_margin, p_margin, p_margin), scale_with_margin);
- bt_convex_shape->setLocalScaling(scale_with_margin);
-
btTransform bt_xform_from;
G_TO_B(p_xform, bt_xform_from);
+ UNSCALE_BT_BASIS(bt_xform_from);
btTransform bt_xform_to(bt_xform_from);
bt_xform_to.getOrigin() += bt_motion;
@@ -202,7 +196,7 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform &
ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape);
- btCollisionShape *btShape = shape->create_bt_shape();
+ btCollisionShape *btShape = shape->create_bt_shape(p_shape_xform.basis.get_scale(), p_margin);
if (!btShape->isConvex()) {
bulletdelete(btShape);
ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type()));
@@ -210,12 +204,9 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform &
}
btConvexShape *btConvex = static_cast<btConvexShape *>(btShape);
- btVector3 scale_with_margin;
- G_TO_B(p_shape_xform.basis.get_scale(), scale_with_margin);
- btConvex->setLocalScaling(scale_with_margin);
-
btTransform bt_xform;
G_TO_B(p_shape_xform, bt_xform);
+ UNSCALE_BT_BASIS(bt_xform);
btCollisionObject collision_object;
collision_object.setCollisionShape(btConvex);
@@ -224,7 +215,7 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform &
GodotContactPairContactResultCallback btQuery(&collision_object, r_results, p_result_max, &p_exclude);
btQuery.m_collisionFilterGroup = 0;
btQuery.m_collisionFilterMask = p_collision_mask;
- btQuery.m_closestDistanceThreshold = p_margin;
+ btQuery.m_closestDistanceThreshold = 0;
space->dynamicsWorld->contactTest(&collision_object, btQuery);
r_result_count = btQuery.m_count;
@@ -237,7 +228,7 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh
ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape);
- btCollisionShape *btShape = shape->create_bt_shape();
+ btCollisionShape *btShape = shape->create_bt_shape(p_shape_xform.basis.get_scale(), p_margin);
if (!btShape->isConvex()) {
bulletdelete(btShape);
ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type()));
@@ -245,12 +236,9 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh
}
btConvexShape *btConvex = static_cast<btConvexShape *>(btShape);
- btVector3 scale_with_margin;
- G_TO_B(p_shape_xform.basis.get_scale() + Vector3(p_margin, p_margin, p_margin), scale_with_margin);
- btConvex->setLocalScaling(scale_with_margin);
-
btTransform bt_xform;
G_TO_B(p_shape_xform, bt_xform);
+ UNSCALE_BT_BASIS(bt_xform);
btCollisionObject collision_object;
collision_object.setCollisionShape(btConvex);
@@ -259,7 +247,7 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh
GodotRestInfoContactResultCallback btQuery(&collision_object, r_info, &p_exclude);
btQuery.m_collisionFilterGroup = 0;
btQuery.m_collisionFilterMask = p_collision_mask;
- btQuery.m_closestDistanceThreshold = p_margin;
+ btQuery.m_closestDistanceThreshold = 0;
space->dynamicsWorld->contactTest(&collision_object, btQuery);
bulletdelete(btConvex);
@@ -796,7 +784,9 @@ void SpaceBullet::update_gravity() {
/// I'm leaving this here just for future tests.
/// Debug motion and normal vector drawing
#define debug_test_motion 0
-#define PERFORM_INITIAL_UNSTACK 1
+#define PERFORM_INITIAL_UNSTACK 0
+#define RECOVERING_MOVEMENT_SCALE 0.4
+#define RECOVERING_MOVEMENT_CYCLES 4
#if debug_test_motion
@@ -820,6 +810,9 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f
SceneTree::get_singleton()->get_current_scene()->add_child(motionVec);
SceneTree::get_singleton()->get_current_scene()->add_child(normalLine);
+ motionVec->set_as_toplevel(true);
+ normalLine->set_as_toplevel(true);
+
red_mat = Ref<SpatialMaterial>(memnew(SpatialMaterial));
red_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
red_mat->set_line_width(20.0);
@@ -850,20 +843,24 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f
// }
//}
- btVector3 recover_initial_position(0, 0, 0);
-
btTransform body_safe_position;
G_TO_B(p_from, body_safe_position);
+ UNSCALE_BT_BASIS(body_safe_position);
- { /// Phase one - multi shapes depenetration using margin
#if PERFORM_INITIAL_UNSTACK
- if (recover_from_penetration(p_body, body_safe_position, recover_initial_position)) {
+ btVector3 recover_initial_position(0, 0, 0);
+ { /// Phase one - multi shapes depenetration using margin
+ for (int t(RECOVERING_MOVEMENT_CYCLES); 0 < t; --t) {
+ if (recover_from_penetration(p_body, body_safe_position, RECOVERING_MOVEMENT_SCALE, recover_initial_position)) {
- // Add recover position to "From" and "To" transforms
- body_safe_position.getOrigin() += recover_initial_position;
+ // Add recover position to "From" and "To" transforms
+ body_safe_position.getOrigin() += recover_initial_position;
+ } else {
+ break;
+ }
}
-#endif
}
+#endif
btVector3 recovered_motion;
G_TO_B(p_motion, recovered_motion);
@@ -872,13 +869,13 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f
{ /// phase two - sweep test, from a secure position without margin
#if debug_test_motion
- Vector3 sup_line;
- B_TO_G(body_safe_position.getOrigin(), sup_line);
- motionVec->clear();
- motionVec->begin(Mesh::PRIMITIVE_LINES, NULL);
- motionVec->add_vertex(sup_line);
- motionVec->add_vertex(sup_line + p_motion * 10);
- motionVec->end();
+//Vector3 sup_line;
+//B_TO_G(body_safe_position.getOrigin(), sup_line);
+//motionVec->clear();
+//motionVec->begin(Mesh::PRIMITIVE_LINES, NULL);
+//motionVec->add_vertex(sup_line);
+//motionVec->add_vertex(sup_line + p_motion * 10);
+//motionVec->end();
#endif
for (int shIndex = 0; shIndex < shape_count; ++shIndex) {
@@ -892,11 +889,7 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f
}
btConvexShape *convex_shape_test(static_cast<btConvexShape *>(p_body->get_bt_shape(shIndex)));
- btTransform shape_world_from;
- G_TO_B(p_body->get_shape_transform(shIndex), shape_world_from);
-
- // Add local shape transform
- shape_world_from = body_safe_position * shape_world_from;
+ btTransform shape_world_from = body_safe_position * p_body->get_kinematic_utilities()->shapes[shIndex].transform;
btTransform shape_world_to(shape_world_from);
shape_world_to.getOrigin() += recovered_motion;
@@ -915,59 +908,75 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f
}
}
- bool hasPenetration = false;
+ bool has_penetration = false;
{ /// Phase three - Recover + contact test with margin
RecoverResult r_recover_result;
+ bool l_has_penetration;
+ real_t l_penetration_distance = 1e20;
- hasPenetration = recover_from_penetration(p_body, body_safe_position, recovered_motion, &r_recover_result);
+ for (int t(RECOVERING_MOVEMENT_CYCLES); 0 < t; --t) {
+ l_has_penetration = recover_from_penetration(p_body, body_safe_position, RECOVERING_MOVEMENT_SCALE, recovered_motion, &r_recover_result);
- if (r_result) {
-
- B_TO_G(recovered_motion + recover_initial_position, r_result->motion);
-
- if (hasPenetration) {
- const btRigidBody *btRigid = static_cast<const btRigidBody *>(r_recover_result.other_collision_object);
- CollisionObjectBullet *collisionObject = static_cast<CollisionObjectBullet *>(btRigid->getUserPointer());
-
- r_result->remainder = p_motion - r_result->motion; // is the remaining movements
- B_TO_G(r_recover_result.pointWorld, r_result->collision_point);
- B_TO_G(r_recover_result.pointNormalWorld, r_result->collision_normal);
- B_TO_G(btRigid->getVelocityInLocalPoint(r_recover_result.pointWorld - btRigid->getWorldTransform().getOrigin()), r_result->collider_velocity); // It calculates velocity at point and assign it using special function Bullet_to_Godot
- r_result->collider = collisionObject->get_self();
- r_result->collider_id = collisionObject->get_instance_id();
- r_result->collider_shape = r_recover_result.other_compound_shape_index;
- r_result->collision_local_shape = r_recover_result.local_shape_most_recovered;
+ if (r_result) {
+#if PERFORM_INITIAL_UNSTACK
+ B_TO_G(recovered_motion + recover_initial_position, r_result->motion);
+#else
+ B_TO_G(recovered_motion, r_result->motion);
+#endif
+ if (l_has_penetration) {
+ has_penetration = true;
+ if (l_penetration_distance <= r_recover_result.penetration_distance) {
+ continue;
+ }
- //{ /// Add manifold point to manage collisions
- // btPersistentManifold* manifold = dynamicsWorld->getDispatcher()->getNewManifold(p_body->getBtBody(), btRigid);
- // btManifoldPoint manifoldPoint(result_callabck.m_pointWorld, result_callabck.m_pointWorld, result_callabck.m_pointNormalWorld, result_callabck.m_penetration_distance);
- // manifoldPoint.m_index0 = r_result->collision_local_shape;
- // manifoldPoint.m_index1 = r_result->collider_shape;
- // manifold->addManifoldPoint(manifoldPoint);
- // p_body->get_kinematic_utilities()->m_generatedManifold.push_back(manifold);
- //}
+ l_penetration_distance = r_recover_result.penetration_distance;
+
+ const btRigidBody *btRigid = static_cast<const btRigidBody *>(r_recover_result.other_collision_object);
+ CollisionObjectBullet *collisionObject = static_cast<CollisionObjectBullet *>(btRigid->getUserPointer());
+
+ r_result->remainder = p_motion - r_result->motion; // is the remaining movements
+ B_TO_G(r_recover_result.pointWorld, r_result->collision_point);
+ B_TO_G(r_recover_result.normal, r_result->collision_normal);
+ B_TO_G(btRigid->getVelocityInLocalPoint(r_recover_result.pointWorld - btRigid->getWorldTransform().getOrigin()), r_result->collider_velocity); // It calculates velocity at point and assign it using special function Bullet_to_Godot
+ r_result->collider = collisionObject->get_self();
+ r_result->collider_id = collisionObject->get_instance_id();
+ r_result->collider_shape = r_recover_result.other_compound_shape_index;
+ r_result->collision_local_shape = r_recover_result.local_shape_most_recovered;
+
+ //{ /// Add manifold point to manage collisions
+ // btPersistentManifold* manifold = dynamicsWorld->getDispatcher()->getNewManifold(p_body->getBtBody(), btRigid);
+ // btManifoldPoint manifoldPoint(result_callabck.m_pointWorld, result_callabck.m_pointWorld, result_callabck.m_pointNormalWorld, result_callabck.m_penetration_distance);
+ // manifoldPoint.m_index0 = r_result->collision_local_shape;
+ // manifoldPoint.m_index1 = r_result->collider_shape;
+ // manifold->addManifoldPoint(manifoldPoint);
+ // p_body->get_kinematic_utilities()->m_generatedManifold.push_back(manifold);
+ //}
#if debug_test_motion
- Vector3 sup_line2;
- B_TO_G(recovered_motion, sup_line2);
- //Vector3 sup_pos;
- //B_TO_G( pt.getPositionWorldOnB(), sup_pos);
- normalLine->clear();
- normalLine->begin(Mesh::PRIMITIVE_LINES, NULL);
- normalLine->add_vertex(r_result->collision_point);
- normalLine->add_vertex(r_result->collision_point + r_result->collision_normal * 10);
- normalLine->end();
+//Vector3 sup_line2;
+//B_TO_G(recovered_motion, sup_line2);
+////Vector3 sup_pos;
+////B_TO_G( pt.getPositionWorldOnB(), sup_pos);
+//normalLine->clear();
+//normalLine->begin(Mesh::PRIMITIVE_LINES, NULL);
+//normalLine->add_vertex(r_result->collision_point);
+//normalLine->add_vertex(r_result->collision_point + r_result->collision_normal * 10);
+//normalLine->end();
#endif
+ } else {
+ r_result->remainder = Vector3();
+ }
} else {
- r_result->remainder = Vector3();
+ if (!l_has_penetration)
+ break;
}
}
}
- return hasPenetration;
+ return has_penetration;
}
struct RecoverPenetrationBroadPhaseCallback : public btBroadphaseAabbCallback {
@@ -1004,7 +1013,7 @@ public:
}
};
-bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_body_position, btVector3 &r_recover_position, RecoverResult *r_recover_result) {
+bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_body_position, btScalar p_recover_movement_scale, btVector3 &r_recover_position, RecoverResult *r_recover_result) {
RecoverPenetrationBroadPhaseCallback recover_broad_result(p_body->get_bt_collision_object(), p_body->get_collision_layer(), p_body->get_collision_mask());
@@ -1045,24 +1054,24 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran
for (int x = cs->getNumChildShapes() - 1; 0 <= x; --x) {
if (cs->getChildShape(x)->isConvex()) {
- if (RFP_convex_convex_test(kin_shape.shape, static_cast<const btConvexShape *>(cs->getChildShape(x)), otherObject, x, body_shape_position, otherObject->getWorldTransform() * cs->getChildTransform(x), r_recover_position, r_recover_result)) {
+ if (RFP_convex_convex_test(kin_shape.shape, static_cast<const btConvexShape *>(cs->getChildShape(x)), otherObject, x, body_shape_position_recovered, otherObject->getWorldTransform() * cs->getChildTransform(x), p_recover_movement_scale, r_recover_position, r_recover_result)) {
penetration = true;
}
} else {
- if (RFP_convex_world_test(kin_shape.shape, cs->getChildShape(x), p_body->get_bt_collision_object(), otherObject, kinIndex, x, body_shape_position, otherObject->getWorldTransform() * cs->getChildTransform(x), r_recover_position, r_recover_result)) {
+ if (RFP_convex_world_test(kin_shape.shape, cs->getChildShape(x), p_body->get_bt_collision_object(), otherObject, kinIndex, x, body_shape_position_recovered, otherObject->getWorldTransform() * cs->getChildTransform(x), p_recover_movement_scale, r_recover_position, r_recover_result)) {
penetration = true;
}
}
}
} else if (otherObject->getCollisionShape()->isConvex()) { /// Execute GJK test against object shape
- if (RFP_convex_convex_test(kin_shape.shape, static_cast<const btConvexShape *>(otherObject->getCollisionShape()), otherObject, 0, body_shape_position, otherObject->getWorldTransform(), r_recover_position, r_recover_result)) {
+ if (RFP_convex_convex_test(kin_shape.shape, static_cast<const btConvexShape *>(otherObject->getCollisionShape()), otherObject, 0, body_shape_position_recovered, otherObject->getWorldTransform(), p_recover_movement_scale, r_recover_position, r_recover_result)) {
penetration = true;
}
} else {
- if (RFP_convex_world_test(kin_shape.shape, otherObject->getCollisionShape(), p_body->get_bt_collision_object(), otherObject, kinIndex, 0, body_shape_position, otherObject->getWorldTransform(), r_recover_position, r_recover_result)) {
+ if (RFP_convex_world_test(kin_shape.shape, otherObject->getCollisionShape(), p_body->get_bt_collision_object(), otherObject, kinIndex, 0, body_shape_position_recovered, otherObject->getWorldTransform(), p_recover_movement_scale, r_recover_position, r_recover_result)) {
penetration = true;
}
@@ -1070,15 +1079,26 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran
}
}
+#if debug_test_motion
+ Vector3 pos;
+ B_TO_G(p_body_position.getOrigin(), pos);
+ Vector3 sup_line;
+ B_TO_G(sum_recover_normals, sup_line);
+ motionVec->clear();
+ motionVec->begin(Mesh::PRIMITIVE_LINES, NULL);
+ motionVec->add_vertex(pos);
+ motionVec->add_vertex(pos + (sup_line * 10));
+ motionVec->end();
+#endif
+
return penetration;
}
-bool SpaceBullet::RFP_convex_convex_test(const btConvexShape *p_shapeA, const btConvexShape *p_shapeB, btCollisionObject *p_objectB, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btVector3 &r_recover_position, RecoverResult *r_recover_result) {
+bool SpaceBullet::RFP_convex_convex_test(const btConvexShape *p_shapeA, const btConvexShape *p_shapeB, btCollisionObject *p_objectB, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_recover_movement_scale, btVector3 &r_recover_position, RecoverResult *r_recover_result) {
// Initialize GJK input
btGjkPairDetector::ClosestPointInput gjk_input;
gjk_input.m_transformA = p_transformA;
- gjk_input.m_transformA.getOrigin() += r_recover_position;
gjk_input.m_transformB = p_transformB;
// Perform GJK test
@@ -1087,30 +1107,28 @@ bool SpaceBullet::RFP_convex_convex_test(const btConvexShape *p_shapeA, const bt
gjk_pair_detector.getClosestPoints(gjk_input, result, 0);
if (0 > result.m_distance) {
// Has penetration
- r_recover_position += result.m_normalOnBInWorld * (result.m_distance * -1);
+ r_recover_position += result.m_normalOnBInWorld * (result.m_distance * -1 * p_recover_movement_scale);
if (r_recover_result) {
-
- r_recover_result->hasPenetration = true;
- r_recover_result->other_collision_object = p_objectB;
- r_recover_result->other_compound_shape_index = p_shapeId_B;
- r_recover_result->penetration_distance = result.m_distance;
- r_recover_result->pointNormalWorld = result.m_normalOnBInWorld;
- r_recover_result->pointWorld = result.m_pointInWorld;
+ if (result.m_distance < r_recover_result->penetration_distance) {
+ r_recover_result->hasPenetration = true;
+ r_recover_result->other_collision_object = p_objectB;
+ r_recover_result->other_compound_shape_index = p_shapeId_B;
+ r_recover_result->penetration_distance = result.m_distance;
+ r_recover_result->pointWorld = result.m_pointInWorld;
+ r_recover_result->normal = result.m_normalOnBInWorld;
+ }
}
return true;
}
return false;
}
-bool SpaceBullet::RFP_convex_world_test(const btConvexShape *p_shapeA, const btCollisionShape *p_shapeB, btCollisionObject *p_objectA, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btVector3 &r_recover_position, RecoverResult *r_recover_result) {
+bool SpaceBullet::RFP_convex_world_test(const btConvexShape *p_shapeA, const btCollisionShape *p_shapeB, btCollisionObject *p_objectA, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_recover_movement_scale, btVector3 &r_recover_position, RecoverResult *r_recover_result) {
/// Contact test
- btTransform p_recovered_transformA(p_transformA);
- p_recovered_transformA.getOrigin() += r_recover_position;
-
- btCollisionObjectWrapper obA(NULL, p_shapeA, p_objectA, p_recovered_transformA, -1, p_shapeId_A);
+ btCollisionObjectWrapper obA(NULL, p_shapeA, p_objectA, p_transformA, -1, p_shapeId_A);
btCollisionObjectWrapper obB(NULL, p_shapeB, p_objectB, p_transformB, -1, p_shapeId_B);
btCollisionAlgorithm *algorithm = dispatcher->findAlgorithm(&obA, &obB, NULL, BT_CLOSEST_POINT_ALGORITHMS);
@@ -1123,16 +1141,17 @@ bool SpaceBullet::RFP_convex_world_test(const btConvexShape *p_shapeA, const btC
dispatcher->freeCollisionAlgorithm(algorithm);
if (contactPointResult.hasHit()) {
- r_recover_position += contactPointResult.m_pointNormalWorld * (contactPointResult.m_penetration_distance * -1);
+ r_recover_position += contactPointResult.m_pointNormalWorld * (contactPointResult.m_penetration_distance * -1 * p_recover_movement_scale);
if (r_recover_result) {
-
- r_recover_result->hasPenetration = true;
- r_recover_result->other_collision_object = p_objectB;
- r_recover_result->other_compound_shape_index = p_shapeId_B;
- r_recover_result->penetration_distance = contactPointResult.m_penetration_distance;
- r_recover_result->pointNormalWorld = contactPointResult.m_pointNormalWorld;
- r_recover_result->pointWorld = contactPointResult.m_pointWorld;
+ if (contactPointResult.m_penetration_distance < r_recover_result->penetration_distance) {
+ r_recover_result->hasPenetration = true;
+ r_recover_result->other_collision_object = p_objectB;
+ r_recover_result->other_compound_shape_index = p_shapeId_B;
+ r_recover_result->penetration_distance = contactPointResult.m_penetration_distance;
+ r_recover_result->pointWorld = contactPointResult.m_pointWorld;
+ r_recover_result->normal = contactPointResult.m_pointNormalWorld;
+ }
}
return true;
}
diff --git a/modules/bullet/space_bullet.h b/modules/bullet/space_bullet.h
index 6e71a25773..69ea2fcc58 100644
--- a/modules/bullet/space_bullet.h
+++ b/modules/bullet/space_bullet.h
@@ -178,23 +178,24 @@ private:
struct RecoverResult {
bool hasPenetration;
- btVector3 pointNormalWorld;
+ btVector3 normal;
btVector3 pointWorld;
- btScalar penetration_distance; // Negative is penetration
+ btScalar penetration_distance; // Negative mean penetration
int other_compound_shape_index;
const btCollisionObject *other_collision_object;
int local_shape_most_recovered;
RecoverResult() :
- hasPenetration(false) {}
+ hasPenetration(false),
+ penetration_distance(1e20) {}
};
- bool recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_from, btVector3 &r_recover_position, RecoverResult *r_recover_result = NULL);
+ bool recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_from, btScalar p_recover_movement_scale, btVector3 &r_recover_position, RecoverResult *r_recover_result = NULL);
/// This is an API that recover a kinematic object from penetration
/// This allow only Convex Convex test and it always use GJK algorithm, With this API we don't benefit of Bullet special accelerated functions
- bool RFP_convex_convex_test(const btConvexShape *p_shapeA, const btConvexShape *p_shapeB, btCollisionObject *p_objectB, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btVector3 &r_recover_position, RecoverResult *r_recover_result);
+ bool RFP_convex_convex_test(const btConvexShape *p_shapeA, const btConvexShape *p_shapeB, btCollisionObject *p_objectB, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_movement_scale, btVector3 &r_recover_position, RecoverResult *r_recover_result = NULL);
/// This is an API that recover a kinematic object from penetration
/// Using this we leave Bullet to select the best algorithm, For example GJK in case we have Convex Convex, or a Bullet accelerated algorithm
- bool RFP_convex_world_test(const btConvexShape *p_shapeA, const btCollisionShape *p_shapeB, btCollisionObject *p_objectA, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btVector3 &r_recover_position, RecoverResult *r_recover_result);
+ bool RFP_convex_world_test(const btConvexShape *p_shapeA, const btCollisionShape *p_shapeB, btCollisionObject *p_objectA, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_movement_scale, btVector3 &r_recover_position, RecoverResult *r_recover_result = NULL);
};
#endif
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
index 7ab3d0a140..786c2bf051 100644
--- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
+++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp
@@ -164,6 +164,14 @@ String AudioStreamOGGVorbis::get_stream_name() const {
return ""; //return stream_name;
}
+void AudioStreamOGGVorbis::clear_data() {
+ if (data) {
+ AudioServer::get_singleton()->audio_data_free(data);
+ data = NULL;
+ data_len = 0;
+ }
+}
+
void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t> &p_data) {
int src_data_len = p_data.size();
@@ -209,6 +217,9 @@ void AudioStreamOGGVorbis::set_data(const PoolVector<uint8_t> &p_data) {
length = stb_vorbis_stream_length_in_seconds(ogg_stream);
stb_vorbis_close(ogg_stream);
+ // free any existing data
+ clear_data();
+
data = AudioServer::get_singleton()->audio_data_alloc(src_data_len, src_datar.ptr());
data_len = src_data_len;
@@ -275,3 +286,7 @@ AudioStreamOGGVorbis::AudioStreamOGGVorbis() {
decode_mem_size = 0;
loop = false;
}
+
+AudioStreamOGGVorbis::~AudioStreamOGGVorbis() {
+ clear_data();
+}
diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h
index f920047703..8644e1ba37 100644
--- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h
+++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h
@@ -93,6 +93,7 @@ class AudioStreamOGGVorbis : public AudioStream {
float length;
bool loop;
float loop_offset;
+ void clear_data();
protected:
static void _bind_methods();
@@ -111,6 +112,7 @@ public:
PoolVector<uint8_t> get_data() const;
AudioStreamOGGVorbis();
+ virtual ~AudioStreamOGGVorbis();
};
#endif
diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp
index 97e81874c9..1542f4a5e4 100644
--- a/platform/android/os_android.cpp
+++ b/platform/android/os_android.cpp
@@ -120,7 +120,7 @@ void OS_Android::set_opengl_extensions(const char *p_gl_extensions) {
gl_extensions = p_gl_extensions;
}
-void OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
+Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
use_gl2 = p_video_driver != 1;
@@ -146,6 +146,8 @@ void OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int
input->set_fallback_mapping("Default Android Gamepad");
//power_manager = memnew(power_android);
+
+ return OK;
}
void OS_Android::set_main_loop(MainLoop *p_main_loop) {
diff --git a/platform/android/os_android.h b/platform/android/os_android.h
index adfd88b59b..c0ab2acd2e 100644
--- a/platform/android/os_android.h
+++ b/platform/android/os_android.h
@@ -145,7 +145,7 @@ public:
virtual const char *get_audio_driver_name(int p_driver) const;
virtual void initialize_core();
- virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
+ virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void set_main_loop(MainLoop *p_main_loop);
virtual void delete_main_loop();
diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp
index 65a220f8ca..2d1d976399 100644
--- a/platform/haiku/os_haiku.cpp
+++ b/platform/haiku/os_haiku.cpp
@@ -79,7 +79,7 @@ const char *OS_Haiku::get_video_driver_name(int p_driver) const {
return "GLES3";
}
-void OS_Haiku::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
+Error OS_Haiku::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
main_loop = NULL;
current_video_mode = p_desired;
@@ -114,7 +114,7 @@ void OS_Haiku::initialize(const VideoMode &p_desired, int p_video_driver, int p_
visual_server = memnew(VisualServerRaster(rasterizer));
- ERR_FAIL_COND(!visual_server);
+ ERR_FAIL_COND(!visual_server, ERR_UNAVAILABLE);
// TODO: enable multithreaded VS
/*
@@ -132,6 +132,8 @@ void OS_Haiku::initialize(const VideoMode &p_desired, int p_video_driver, int p_
AudioDriverManager::initialize(p_audio_driver);
power_manager = memnew(PowerHaiku);
+
+ return OK;
}
void OS_Haiku::finalize() {
diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h
index 6d69c1997f..9af15eefc0 100644
--- a/platform/haiku/os_haiku.h
+++ b/platform/haiku/os_haiku.h
@@ -66,7 +66,7 @@ protected:
virtual int get_video_driver_count() const;
virtual const char *get_video_driver_name(int p_driver) const;
- virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
+ virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void finalize();
virtual void set_main_loop(MainLoop *p_main_loop);
diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp
index 507d4f22db..d420f95e33 100644
--- a/platform/iphone/os_iphone.cpp
+++ b/platform/iphone/os_iphone.cpp
@@ -97,7 +97,7 @@ void OSIPhone::initialize_core() {
set_data_dir(data_dir);
};
-void OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
+Error OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
supported_orientations = 0;
supported_orientations |= ((GLOBAL_DEF("video_mode/allow_horizontal", true) ? 1 : 0) << LandscapeLeft);
@@ -144,6 +144,8 @@ void OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_
//icloud->connect();
#endif
Engine::get_singleton()->add_singleton(Engine::Singleton("iOS", memnew(iOS)));
+
+ return OK;
};
MainLoop *OSIPhone::get_main_loop() const {
diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h
index 8e701a7fab..611bc2d4cb 100644
--- a/platform/iphone/os_iphone.h
+++ b/platform/iphone/os_iphone.h
@@ -87,7 +87,7 @@ private:
virtual const char *get_video_driver_name(int p_driver) const;
virtual void initialize_core();
- virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
+ virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void set_main_loop(MainLoop *p_main_loop);
virtual MainLoop *get_main_loop() const;
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 0bdd090ba9..665280df96 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -419,7 +419,7 @@ void send_notification(int notif) {
}
}
-void OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
+Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
print_line("Init OS");
@@ -429,7 +429,7 @@ void OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, i
attributes.antialias = false;
attributes.majorVersion = 2;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(NULL, &attributes);
- ERR_FAIL_COND(emscripten_webgl_make_context_current(ctx) != EMSCRIPTEN_RESULT_SUCCESS);
+ ERR_FAIL_COND(emscripten_webgl_make_context_current(ctx) != EMSCRIPTEN_RESULT_SUCCESS, ERR_UNAVAILABLE);
video_mode = p_desired;
// can't fulfil fullscreen request due to browser security
@@ -507,6 +507,8 @@ void OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, i
#undef EM_CHECK
visual_server->init();
+
+ return OK;
}
void OS_JavaScript::set_main_loop(MainLoop *p_main_loop) {
diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h
index 8acaac9ef3..eaf8465be9 100644
--- a/platform/javascript/os_javascript.h
+++ b/platform/javascript/os_javascript.h
@@ -82,7 +82,7 @@ public:
virtual const char *get_audio_driver_name(int p_driver) const;
virtual void initialize_core();
- virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
+ virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void set_main_loop(MainLoop *p_main_loop);
virtual void delete_main_loop();
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 0411b4e72b..2a71de12e9 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -123,7 +123,7 @@ protected:
virtual const char *get_video_driver_name(int p_driver) const;
virtual void initialize_core();
- virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
+ virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void finalize();
virtual void set_main_loop(MainLoop *p_main_loop);
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 99c5995d7a..a16391c30f 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -99,10 +99,28 @@ static Vector2 get_mouse_pos(NSEvent *event) {
@implementation GodotApplication
-// From http://cocoadev.com/index.pl?GameKeyboardHandlingAlmost
-// This works around an AppKit bug, where key up events while holding
-// down the command key don't get sent to the key window.
- (void)sendEvent:(NSEvent *)event {
+
+ // special case handling of command-period, which is traditionally a special
+ // shortcut in macOS and doesn't arrive at our regular keyDown handler.
+ if ([event type] == NSKeyDown) {
+ if (([event modifierFlags] & NSEventModifierFlagCommand) && [event keyCode] == 0x2f) {
+
+ Ref<InputEventKey> k;
+ k.instance();
+
+ get_key_modifier_state([event modifierFlags], k);
+ k->set_pressed(true);
+ k->set_scancode(KEY_PERIOD);
+ k->set_echo([event isARepeat]);
+
+ OS_OSX::singleton->push_input(k);
+ }
+ }
+
+ // From http://cocoadev.com/index.pl?GameKeyboardHandlingAlmost
+ // This works around an AppKit bug, where key up events while holding
+ // down the command key don't get sent to the key window.
if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask))
[[self keyWindow] sendEvent:event];
else
@@ -958,7 +976,7 @@ static void displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplay
displays_arrangement_dirty = true;
}
-void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
+Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
/*** OSX INITIALIZATION ***/
/*** OSX INITIALIZATION ***/
@@ -995,7 +1013,7 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
backing:NSBackingStoreBuffered
defer:NO];
- ERR_FAIL_COND(window_object == nil);
+ ERR_FAIL_COND(window_object == nil, ERR_UNAVAILABLE);
window_view = [[GodotContentView alloc] init];
@@ -1082,11 +1100,11 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
#undef ADD_ATTR2
pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
- ERR_FAIL_COND(pixelFormat == nil);
+ ERR_FAIL_COND(pixelFormat == nil, ERR_UNAVAILABLE);
context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
- ERR_FAIL_COND(context == nil);
+ ERR_FAIL_COND(context == nil, ERR_UNAVAILABLE);
[context setView:window_view];
@@ -1130,6 +1148,8 @@ void OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
_ensure_user_data_dir();
restore_rect = Rect2(get_window_position(), get_window_size());
+
+ return OK;
}
void OS_OSX::finalize() {
diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp
index 13264ed46e..e8d076322c 100644
--- a/platform/server/os_server.cpp
+++ b/platform/server/os_server.cpp
@@ -47,7 +47,7 @@ const char *OS_Server::get_video_driver_name(int p_driver) const {
return "Dummy";
}
-void OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
+Error OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
args = OS::get_singleton()->get_cmdline_args();
current_videomode = p_desired;
@@ -67,13 +67,15 @@ void OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p
spatial_sound_2d_server = memnew(SpatialSound2DServerSW);
spatial_sound_2d_server->init();
- ERR_FAIL_COND(!visual_server);
+ ERR_FAIL_COND(!visual_server, ERR_UNAVAILABLE);
visual_server->init();
input = memnew(InputDefault);
_ensure_user_data_dir();
+
+ return OK;
}
void OS_Server::finalize() {
diff --git a/platform/server/os_server.h b/platform/server/os_server.h
index 7b7d4a38a8..6739375468 100644
--- a/platform/server/os_server.h
+++ b/platform/server/os_server.h
@@ -66,7 +66,7 @@ protected:
virtual int get_video_driver_count() const;
virtual const char *get_video_driver_name(int p_driver) const;
- virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
+ virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void finalize();
virtual void set_main_loop(MainLoop *p_main_loop);
diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp
index 603a918cca..96f9c895bc 100644
--- a/platform/uwp/os_uwp.cpp
+++ b/platform/uwp/os_uwp.cpp
@@ -194,7 +194,7 @@ void OSUWP::screen_size_changed() {
gl_context->reset();
};
-void OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
+Error OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
main_loop = NULL;
outside = true;
@@ -297,6 +297,8 @@ void OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_aud
display_request->RequestActive();
set_keep_screen_on(GLOBAL_DEF("display/window/keep_screen_on", true));
+
+ return OK;
}
void OSUWP::set_clipboard(const String &p_text) {
diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h
index 976eda1fe1..ad12b6286f 100644
--- a/platform/uwp/os_uwp.h
+++ b/platform/uwp/os_uwp.h
@@ -158,7 +158,7 @@ protected:
virtual const char *get_audio_driver_name(int p_driver) const;
virtual void initialize_core();
- virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
+ virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void set_main_loop(MainLoop *p_main_loop);
virtual void delete_main_loop();
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index e3af82b629..a48ae8cc8c 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -929,7 +929,7 @@ typedef enum _SHC_PROCESS_DPI_AWARENESS {
SHC_PROCESS_PER_MONITOR_DPI_AWARE = 2
} SHC_PROCESS_DPI_AWARENESS;
-void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
+Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
main_loop = NULL;
outside = true;
@@ -975,7 +975,7 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
if (!RegisterClassExW(&wc)) {
MessageBox(NULL, "Failed To Register The Window Class.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
- return; // Return
+ return ERR_UNAVAILABLE;
}
pre_fs_valid = true;
@@ -1045,7 +1045,7 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
RECT rect;
if (!GetClientRect(hWnd, &rect)) {
MessageBoxW(NULL, L"Window Creation Error.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
- return; // Return FALSE
+ return ERR_UNAVAILABLE;
};
video_mode.width = rect.right;
video_mode.height = rect.bottom;
@@ -1063,7 +1063,7 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
NULL, NULL, hInstance, NULL);
if (!hWnd) {
MessageBoxW(NULL, L"Window Creation Error.", L"ERROR", MB_OK | MB_ICONEXCLAMATION);
- return; // Return FALSE
+ return ERR_UNAVAILABLE;
}
};
@@ -1127,6 +1127,8 @@ void OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
SetForegroundWindow(hWnd); // Slightly Higher Priority
SetFocus(hWnd); // Sets Keyboard Focus To
}
+
+ return OK;
}
void OS_Windows::set_clipboard(const String &p_text) {
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index 9d254ccf27..1863642f39 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -148,7 +148,7 @@ protected:
virtual const char *get_audio_driver_name(int p_driver) const;
virtual void initialize_core();
- virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
+ virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void set_main_loop(MainLoop *p_main_loop);
virtual void delete_main_loop();
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index e9920b18a4..5ca3ad45b8 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -100,7 +100,7 @@ void OS_X11::initialize_core() {
OS_Unix::initialize_core();
}
-void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
+Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
long im_event_mask = 0;
last_button_state = 0;
@@ -123,21 +123,24 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
/** XLIB INITIALIZATION **/
x11_display = XOpenDisplay(NULL);
+ if (!x11_display) {
+ ERR_PRINT("X11 Display is not available");
+ return ERR_UNAVAILABLE;
+ }
+
char *modifiers = NULL;
Bool xkb_dar = False;
- if (x11_display) {
- XAutoRepeatOn(x11_display);
- xkb_dar = XkbSetDetectableAutoRepeat(x11_display, True, NULL);
+ XAutoRepeatOn(x11_display);
+ xkb_dar = XkbSetDetectableAutoRepeat(x11_display, True, NULL);
- // Try to support IME if detectable auto-repeat is supported
- if (xkb_dar == True) {
+ // Try to support IME if detectable auto-repeat is supported
+ if (xkb_dar == True) {
#ifdef X_HAVE_UTF8_STRING
- // Xutf8LookupString will be used later instead of XmbLookupString before
- // the multibyte sequences can be converted to unicode string.
- modifiers = XSetLocaleModifiers("");
+ // Xutf8LookupString will be used later instead of XmbLookupString before
+ // the multibyte sequences can be converted to unicode string.
+ modifiers = XSetLocaleModifiers("");
#endif
- }
}
if (modifiers == NULL) {
@@ -331,8 +334,8 @@ void OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_au
AudioDriverManager::initialize(p_audio_driver);
- ERR_FAIL_COND(!visual_server);
- ERR_FAIL_COND(x11_window == 0);
+ ERR_FAIL_COND_V(!visual_server, ERR_UNAVAILABLE);
+ ERR_FAIL_COND_V(x11_window == 0, ERR_UNAVAILABLE);
XSetWindowAttributes new_attr;
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 04243a9b36..2bf2f3cf26 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -193,7 +193,7 @@ protected:
virtual const char *get_audio_driver_name(int p_driver) const;
virtual void initialize_core();
- virtual void initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
+ virtual Error initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver);
virtual void finalize();
virtual void set_main_loop(MainLoop *p_main_loop);
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 4036735807..998c790c94 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -220,31 +220,17 @@ void register_scene_types() {
resource_loader_theme = memnew(ResourceFormatLoaderTheme);
ResourceLoader::add_resource_format_loader(resource_loader_theme);
- bool default_theme_hidpi = GLOBAL_DEF("gui/theme/use_hidpi", false);
- ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/use_hidpi", PropertyInfo(Variant::BOOL, "gui/theme/use_hidpi", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED));
- String theme_path = GLOBAL_DEF("gui/theme/custom", "");
- ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/custom", PropertyInfo(Variant::STRING, "gui/theme/custom", PROPERTY_HINT_FILE, "*.tres,*.res", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED));
- String font_path = GLOBAL_DEF("gui/theme/custom_font", "");
- ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/custom_font", PropertyInfo(Variant::STRING, "gui/theme/custom_font", PROPERTY_HINT_FILE, "*.tres,*.res,*.font", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED));
+ resource_saver_text = memnew(ResourceFormatSaverText);
+ ResourceSaver::add_resource_format_saver(resource_saver_text, true);
- bool has_theme = false;
- if (theme_path != String()) {
- Ref<Theme> theme = ResourceLoader::load(theme_path);
- if (theme.is_valid()) {
- Theme::set_default(theme);
- has_theme = true;
- } else {
- ERR_PRINTS("Error loading custom theme '" + theme_path + "'");
- }
- }
+ resource_loader_text = memnew(ResourceFormatLoaderText);
+ ResourceLoader::add_resource_format_loader(resource_loader_text, true);
- if (!has_theme) {
- Ref<Font> font;
- if (font_path != String()) {
- font = ResourceLoader::load(font_path);
- }
- make_default_theme(default_theme_hidpi, font);
- }
+ resource_saver_shader = memnew(ResourceFormatSaverShader);
+ ResourceSaver::add_resource_format_saver(resource_saver_shader, true);
+
+ resource_loader_shader = memnew(ResourceFormatLoaderShader);
+ ResourceLoader::add_resource_format_loader(resource_loader_shader, true);
OS::get_singleton()->yield(); //may take time to init
@@ -604,24 +590,42 @@ void register_scene_types() {
OS::get_singleton()->yield(); //may take time to init
- resource_saver_text = memnew(ResourceFormatSaverText);
- ResourceSaver::add_resource_format_saver(resource_saver_text, true);
-
- resource_loader_text = memnew(ResourceFormatLoaderText);
- ResourceLoader::add_resource_format_loader(resource_loader_text, true);
-
- resource_saver_shader = memnew(ResourceFormatSaverShader);
- ResourceSaver::add_resource_format_saver(resource_saver_shader, true);
-
- resource_loader_shader = memnew(ResourceFormatLoaderShader);
- ResourceLoader::add_resource_format_loader(resource_loader_shader, true);
-
for (int i = 0; i < 20; i++) {
GLOBAL_DEF("layer_names/2d_render/layer_" + itos(i + 1), "");
GLOBAL_DEF("layer_names/2d_physics/layer_" + itos(i + 1), "");
GLOBAL_DEF("layer_names/3d_render/layer_" + itos(i + 1), "");
GLOBAL_DEF("layer_names/3d_physics/layer_" + itos(i + 1), "");
}
+
+ bool default_theme_hidpi = GLOBAL_DEF("gui/theme/use_hidpi", false);
+ ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/use_hidpi", PropertyInfo(Variant::BOOL, "gui/theme/use_hidpi", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED));
+ String theme_path = GLOBAL_DEF("gui/theme/custom", "");
+ ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/custom", PropertyInfo(Variant::STRING, "gui/theme/custom", PROPERTY_HINT_FILE, "*.tres,*.res,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED));
+ String font_path = GLOBAL_DEF("gui/theme/custom_font", "");
+ ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/custom_font", PropertyInfo(Variant::STRING, "gui/theme/custom_font", PROPERTY_HINT_FILE, "*.tres,*.res,*.font", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED));
+
+ Ref<Font> font;
+ if (font_path != String()) {
+ font = ResourceLoader::load(font_path);
+ if (!font.is_valid()) {
+ ERR_PRINTS("Error loading custom font '" + font_path + "'");
+ }
+ }
+
+ // Always make the default theme to avoid invalid default font/icon/style in the given theme
+ make_default_theme(default_theme_hidpi, font);
+
+ if (theme_path != String()) {
+ Ref<Theme> theme = ResourceLoader::load(theme_path);
+ if (theme.is_valid()) {
+ Theme::set_default(theme);
+ if (font.is_valid()) {
+ Theme::set_default_font(font);
+ }
+ } else {
+ ERR_PRINTS("Error loading custom theme '" + theme_path + "'");
+ }
+ }
}
void unregister_scene_types() {
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index b18583dfb1..a4049e4461 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -880,7 +880,7 @@ void make_default_theme(bool p_hidpi, Ref<Font> p_font) {
Ref<StyleBox> default_style;
Ref<Texture> default_icon;
- Ref<BitmapFont> default_font;
+ Ref<Font> default_font;
if (p_font.is_valid()) {
default_font = p_font;
} else if (p_hidpi) {
@@ -888,7 +888,7 @@ void make_default_theme(bool p_hidpi, Ref<Font> p_font) {
} else {
default_font = make_font2(_lodpi_font_height, _lodpi_font_ascent, _lodpi_font_charcount, &_lodpi_font_charrects[0][0], _lodpi_font_kerning_pair_count, &_lodpi_font_kerning_pairs[0][0], _lodpi_font_img_width, _lodpi_font_img_height, _lodpi_font_img_data);
}
- Ref<BitmapFont> large_font = default_font;
+ Ref<Font> large_font = default_font;
fill_default_theme(t, default_font, large_font, default_icon, default_style, p_hidpi ? 2.0 : 1.0);
Theme::set_default(t);
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index 1828cf8a4b..f0f93ff2a7 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -3209,8 +3209,6 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
var.precision = precision;
var.line = tk_line;
- p_block->variables[name] = var;
-
VariableDeclarationNode::Declaration decl;
decl.name = name;
@@ -3219,7 +3217,7 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
tk = _get_token();
if (tk.type == TK_OP_ASSIGN) {
- //variable creted with assignment! must parse an expression
+ //variable created with assignment! must parse an expression
Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
if (!n)
return ERR_PARSE_ERROR;
@@ -3233,6 +3231,8 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui
tk = _get_token();
}
+ p_block->variables[name] = var;
+
vardecl->declarations.push_back(decl);
if (tk.type == TK_COMMA) {