Skip to content

Commit 69762e6

Browse files
authored
Fix signal enter bug (#299)
When the `body_set_max_contacts_reported` is called, we don't update the shapes. Recreate them so they have that flag(a bit excessive, maybe in future we can just iterate and change that flag. - Fixes #298
1 parent 21a1fa4 commit 69762e6

16 files changed

+184
-16
lines changed

.github/workflows/module_builds.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ jobs:
2020
with:
2121
name: static-rapier-${{ matrix.dimensions }}-${{ matrix.precision }}-${{ matrix.features }}-module
2222
path: |
23-
module
23+
module${{ matrix.dimensions }}
2424
if-no-files-found: error

module/register_types.h

-9
This file was deleted.

module/SCsub module2d/SCsub

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ def get_sufix():
1717

1818
# Libraries
1919
if env["platform"] == "macos" or env["platform"] == "ios":
20-
base_path = "#modules/rapier/bin/addons/my_library/bin/libmy_library{}.framework".format(get_sufix())
20+
base_path = "#modules/rapier_2d/bin/addons/rapier_2d/bin/librapier_2d{}.framework".format(get_sufix())
2121
base_file = "libgodot_riscv{}".format(get_sufix())
2222
else:
23-
base_path = "#modules/rapier/bin/addons/my_library/bin"
23+
base_path = "#modules/rapier_2d/bin/addons/rapier_2d/bin"
2424
base_file = "libgodot_riscv{}".format(get_sufix())
2525

2626
env.Append(LIBS=[base_file])
2727
env.Append(LIBPATH=[base_path])
2828

2929
# Godot-cpp
30-
base_path = "#modules/rapier/ext/godot-cpp/bin"
30+
base_path = "#modules/rapier_2d/ext/godot-cpp/bin"
3131
base_file = "libgodot-cpp{}".format(get_sufix())
3232

3333
env.Append(LIBS=[base_file])
File renamed without changes.

module/register_types.cpp module2d/register_types.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void initialize_sandbox_module(ModuleInitializationLevel p_level) {
2121
Ref<GDExtensionStaticLibraryLoader> loader;
2222
loader.instantiate();
2323
loader->set_entry_funcptr((void*)&gdext_rust_init);
24-
GDExtensionManager::get_singleton()->load_extension_with_loader("rapier", loader);
24+
GDExtensionManager::get_singleton()->load_extension_with_loader("rapier_2d", loader);
2525
}
2626

2727
void uninitialize_sandbox_module(ModuleInitializationLevel p_level) {

module2d/register_types.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef RAPIER_2D_REGISTER_TYPES_H
2+
#define RAPIER_2D_REGISTER_TYPES_H
3+
4+
#include "modules/register_module_types.h"
5+
6+
void initialize_rapier_2d_module(ModuleInitializationLevel p_level);
7+
void uninitialize_rapier_2d_module(ModuleInitializationLevel p_level);
8+
9+
#endif // RAPIER_2D_REGISTER_TYPES_H

module3d/SCsub

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
from misc.utility.scons_hints import *
3+
4+
Import("env")
5+
Import("env_modules")
6+
7+
def get_sufix():
8+
suffix = ".{}.{}".format(env["platform"], env["target"])
9+
if env.dev_build:
10+
suffix += ".dev"
11+
if env["precision"] == "double":
12+
suffix += ".double"
13+
suffix += "." + env["arch"]
14+
if not env["threads"]:
15+
suffix += ".nothreads"
16+
return suffix.replace("editor", "template_release")
17+
18+
# Libraries
19+
if env["platform"] == "macos" or env["platform"] == "ios":
20+
base_path = "#modules/rapier_3d/bin/addons/rapier_3d/bin/librapier_3d{}.framework".format(get_sufix())
21+
base_file = "libgodot_riscv{}".format(get_sufix())
22+
else:
23+
base_path = "#modules/rapier_3d/bin/addons/rapier_3d/bin"
24+
base_file = "libgodot_riscv{}".format(get_sufix())
25+
26+
env.Append(LIBS=[base_file])
27+
env.Append(LIBPATH=[base_path])
28+
29+
# Godot-cpp
30+
base_path = "#modules/rapier_3d/ext/godot-cpp/bin"
31+
base_file = "libgodot-cpp{}".format(get_sufix())
32+
33+
env.Append(LIBS=[base_file])
34+
env.Append(LIBPATH=[base_path])
35+
36+
# Sources
37+
env_gdextension = env_modules.Clone()
38+
39+
env_gdextension.add_source_files(env.modules_sources, "*.cpp")

module3d/config.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def can_build(env, platform):
2+
return True
3+
4+
5+
def configure(env):
6+
pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "gdextension_static_library_loader.h"
2+
3+
#include "core/config/project_settings.h"
4+
#include "core/io/dir_access.h"
5+
#include "core/version.h"
6+
#include "core/extension/gdextension.h"
7+
8+
Error GDExtensionStaticLibraryLoader::open_library(const String &p_path) {
9+
library_path = p_path;
10+
return OK;
11+
}
12+
13+
Error GDExtensionStaticLibraryLoader::initialize(GDExtensionInterfaceGetProcAddress p_get_proc_address, const Ref<GDExtension> &p_extension, GDExtensionInitialization *r_initialization) {
14+
15+
GDExtensionInitializationFunction initialization_function = (GDExtensionInitializationFunction)entry_funcptr;
16+
if (initialization_function == nullptr) {
17+
}
18+
GDExtensionBool ret = initialization_function(p_get_proc_address, p_extension.ptr(), r_initialization);
19+
20+
if (ret) {
21+
return OK;
22+
} else {
23+
ERR_PRINT("GDExtension initialization function '" + library_path + "' returned an error.");
24+
return FAILED;
25+
}
26+
}
27+
28+
void GDExtensionStaticLibraryLoader::close_library() {
29+
}
30+
31+
bool GDExtensionStaticLibraryLoader::is_library_open() const {
32+
return true;
33+
}
34+
35+
bool GDExtensionStaticLibraryLoader::has_library_changed() const {
36+
return false;
37+
}
38+
39+
bool GDExtensionStaticLibraryLoader::library_exists() const {
40+
return true;
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef GDEXTENSION_STATIC_LIBRARY_LOADER_H
2+
#define GDEXTENSION_STATIC_LIBRARY_LOADER_H
3+
4+
#include <functional>
5+
6+
#include "core/extension/gdextension_loader.h"
7+
#include "core/io/config_file.h"
8+
#include "core/os/shared_object.h"
9+
10+
class GDExtensionStaticLibraryLoader : public GDExtensionLoader {
11+
friend class GDExtensionManager;
12+
friend class GDExtension;
13+
14+
private:
15+
String resource_path;
16+
void *entry_funcptr = nullptr;
17+
String library_path;
18+
Vector<SharedObject> library_dependencies;
19+
20+
HashMap<String, String> class_icon_paths;
21+
22+
public:
23+
void set_entry_funcptr(void *p_entry_funcptr) { entry_funcptr = p_entry_funcptr; }
24+
virtual Error open_library(const String &p_path) override;
25+
virtual Error initialize(GDExtensionInterfaceGetProcAddress p_get_proc_address, const Ref<GDExtension> &p_extension, GDExtensionInitialization *r_initialization) override;
26+
virtual void close_library() override;
27+
virtual bool is_library_open() const override;
28+
virtual bool has_library_changed() const override;
29+
virtual bool library_exists() const override;
30+
};
31+
32+
#endif // GDEXTENSION_STATIC_LIBRARY_LOADER_H

module3d/register_types.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "register_types.h"
2+
#include "core/object/object.h"
3+
#include "core/extension/gdextension_interface.h"
4+
#include "core/extension/gdextension_manager.h"
5+
#include "./gdextension_static_library_loader.h"
6+
#include "core/object/ref_counted.h"
7+
8+
extern "C" {
9+
GDExtensionBool gdext_rust_init(
10+
GDExtensionInterfaceGetProcAddress p_get_proc_address,
11+
GDExtensionClassLibraryPtr p_library,
12+
GDExtensionInitialization *r_initialization
13+
);
14+
}
15+
16+
void initialize_sandbox_module(ModuleInitializationLevel p_level) {
17+
if (p_level != MODULE_INITIALIZATION_LEVEL_SERVERS) {
18+
return;
19+
}
20+
21+
Ref<GDExtensionStaticLibraryLoader> loader;
22+
loader.instantiate();
23+
loader->set_entry_funcptr((void*)&gdext_rust_init);
24+
GDExtensionManager::get_singleton()->load_extension_with_loader("rapier_3d", loader);
25+
}
26+
27+
void uninitialize_sandbox_module(ModuleInitializationLevel p_level) {
28+
}

module3d/register_types.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef RAPIER_3D_REGISTER_TYPES_H
2+
#define RAPIER_3D_REGISTER_TYPES_H
3+
4+
#include "modules/register_module_types.h"
5+
6+
void initialize_rapier_3d_module(ModuleInitializationLevel p_level);
7+
void uninitialize_rapier_3d_module(ModuleInitializationLevel p_level);
8+
9+
#endif // RAPIER_3D_REGISTER_TYPES_H

src/bodies/rapier_body.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -836,11 +836,19 @@ impl RapierBody {
836836
);
837837
}
838838

839-
pub fn set_max_contacts_reported(&mut self, size: i32) {
839+
pub fn set_max_contacts_reported(
840+
&mut self,
841+
size: i32,
842+
physics_engine: &mut PhysicsEngine,
843+
physics_spaces: &mut PhysicsSpaces,
844+
physics_ids: &PhysicsIds,
845+
) {
840846
self.state
841847
.contacts
842848
.resize(size as usize, Contact::default());
843849
self.state.contact_count = 0;
850+
// update all contact forces
851+
self.recreate_shapes(physics_engine, physics_spaces, physics_ids);
844852
}
845853

846854
pub fn reset_contact_count(&mut self) {

src/servers/rapier_physics_server_impl.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,12 @@ impl RapierPhysicsServerImpl {
14471447
let physics_data = physics_data();
14481448
if let Some(body) = physics_data.collision_objects.get_mut(&body) {
14491449
if let Some(body) = body.get_mut_body() {
1450-
body.set_max_contacts_reported(amount);
1450+
body.set_max_contacts_reported(
1451+
amount,
1452+
&mut physics_data.physics_engine,
1453+
&mut physics_data.spaces,
1454+
&physics_data.ids,
1455+
);
14511456
}
14521457
}
14531458
}

0 commit comments

Comments
 (0)