This repository has been archived by the owner on Jun 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add position and velocity iteration. Also fix one way direction for r…
…igidbodies. (#32) * add position and velocity iteration * lint * fix windows err * upd * upd * upd * upd
- Loading branch information
Showing
12 changed files
with
154 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include "box2d_project_settings.h" | ||
|
||
#include <godot_cpp/classes/project_settings.hpp> | ||
|
||
using namespace godot; | ||
|
||
constexpr char RUN_ON_SEPARATE_THREAD[] = "physics/2d/run_on_separate_thread"; | ||
constexpr char MAX_THREADS[] = "threading/worker_pool/max_threads"; | ||
constexpr char POSITION_ITERATIONS[] = "physics/box_2d/solver/position_iterations"; | ||
constexpr char VELOCITY_ITERATIONS[] = "physics/box_2d/solver/velocity_iterations"; | ||
|
||
void register_setting( | ||
const String &p_name, | ||
const Variant &p_value, | ||
bool p_needs_restart, | ||
PropertyHint p_hint, | ||
const String &p_hint_string) { | ||
ProjectSettings *project_settings = ProjectSettings::get_singleton(); | ||
|
||
if (!project_settings->has_setting(p_name)) { | ||
project_settings->set(p_name, p_value); | ||
} | ||
|
||
Dictionary property_info; | ||
property_info["name"] = p_name; | ||
property_info["type"] = p_value.get_type(); | ||
property_info["hint"] = p_hint; | ||
property_info["hint_string"] = p_hint_string; | ||
|
||
project_settings->add_property_info(property_info); | ||
project_settings->set_initial_value(p_name, p_value); | ||
project_settings->set_restart_if_changed(p_name, p_needs_restart); | ||
|
||
// HACK(mihe): We want our settings to appear in the order we register them in, but if we start | ||
// the order at 0 we end up moving the entire `physics/` group to the top of the tree view, so | ||
// instead we give it a hefty starting order and increment from there, which seems to give us | ||
// the desired effect. | ||
static int32_t order = 1000000; | ||
|
||
project_settings->set_order(p_name, order++); | ||
} | ||
|
||
void register_setting_plain( | ||
const String &p_name, | ||
const Variant &p_value, | ||
bool p_needs_restart = false) { | ||
register_setting(p_name, p_value, p_needs_restart, PROPERTY_HINT_NONE, {}); | ||
} | ||
|
||
void register_setting_hinted( | ||
const String &p_name, | ||
const Variant &p_value, | ||
const String &p_hint_string, | ||
bool p_needs_restart = false) { | ||
register_setting(p_name, p_value, p_needs_restart, PROPERTY_HINT_NONE, p_hint_string); | ||
} | ||
|
||
void register_setting_ranged( | ||
const String &p_name, | ||
const Variant &p_value, | ||
const String &p_hint_string, | ||
bool p_needs_restart = false) { | ||
register_setting(p_name, p_value, p_needs_restart, PROPERTY_HINT_RANGE, p_hint_string); | ||
} | ||
|
||
void Box2DProjectSettings::register_settings() { | ||
register_setting_ranged(VELOCITY_ITERATIONS, 8, U"2,16,or_greater"); | ||
register_setting_ranged(POSITION_ITERATIONS, 3, U"1,16,or_greater"); | ||
} | ||
|
||
template <typename TType> | ||
TType get_setting(const char *p_setting) { | ||
const ProjectSettings *project_settings = ProjectSettings::get_singleton(); | ||
const Variant setting_value = project_settings->get_setting_with_override(p_setting); | ||
const Variant::Type setting_type = setting_value.get_type(); | ||
const Variant::Type expected_type = Variant(TType()).get_type(); | ||
|
||
ERR_FAIL_COND_V(setting_type != expected_type, Variant()); | ||
|
||
return setting_value; | ||
} | ||
|
||
bool Box2DProjectSettings::should_run_on_separate_thread() { | ||
return get_setting<bool>(RUN_ON_SEPARATE_THREAD); | ||
} | ||
|
||
int Box2DProjectSettings::get_max_threads() { | ||
return get_setting<int>(MAX_THREADS); | ||
} | ||
|
||
int Box2DProjectSettings::get_position_iterations() { | ||
return get_setting<int>(POSITION_ITERATIONS); | ||
} | ||
|
||
int Box2DProjectSettings::get_velocity_iterations() { | ||
return get_setting<int>(VELOCITY_ITERATIONS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
class Box2DProjectSettings { | ||
public: | ||
static void register_settings(); | ||
|
||
static bool should_run_on_separate_thread(); | ||
static int get_max_threads(); | ||
static int get_position_iterations(); | ||
static int get_velocity_iterations(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters