feat: enhance physics and map modules with Box2D integration and documentation updates
- Updated the physics module to include Box2D support, enabling management of physics bodies and collision events. - Enhanced the map module to support tile layers and improved hot-reload functionality for tilemaps. - Updated documentation to reflect the new features in the physics and map systems, including usage examples and API references. - Modified CMakeLists.txt to include new modules for physics and font management, ensuring proper build configurations. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
6ae6a778db
commit
c19b8fda41
38 files changed
+3063
-40
No files matched your search
@@ -0,0 +1,72 @@
|
||||
#include "physics/Fixture.h"
|
||||
#include "physics/Body.h"
|
||||
#include "physics/World.h"
|
||||
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace eve::physics {
|
||||
|
||||
Fixture::Fixture(World *world, Body *body, b2Fixture *fixture)
|
||||
: world_(world), body_(body), fixture_(fixture) {}
|
||||
|
||||
Fixture::~Fixture() {
|
||||
if (fixture_ && body_ && body_->raw()) {
|
||||
fixture_->SetUserData(nullptr);
|
||||
body_->raw()->DestroyFixture(fixture_);
|
||||
if (world_) world_->forgetFixture(this);
|
||||
}
|
||||
fixture_ = nullptr;
|
||||
body_ = nullptr;
|
||||
world_ = nullptr;
|
||||
}
|
||||
|
||||
void Fixture::invalidate() {
|
||||
if (fixture_) fixture_->SetUserData(nullptr);
|
||||
fixture_ = nullptr;
|
||||
body_ = nullptr;
|
||||
world_ = nullptr;
|
||||
}
|
||||
|
||||
void Fixture::destroy() {
|
||||
if (!fixture_ || !body_ || !body_->raw()) {
|
||||
invalidate();
|
||||
return;
|
||||
}
|
||||
fixture_->SetUserData(nullptr);
|
||||
body_->raw()->DestroyFixture(fixture_);
|
||||
if (world_) world_->forgetFixture(this);
|
||||
fixture_ = nullptr;
|
||||
body_ = nullptr;
|
||||
world_ = nullptr;
|
||||
}
|
||||
|
||||
void Fixture::setSensor(bool sensor) {
|
||||
if (!fixture_) return;
|
||||
fixture_->SetSensor(sensor);
|
||||
}
|
||||
|
||||
bool Fixture::isSensor() const { return fixture_ ? fixture_->IsSensor() : false; }
|
||||
|
||||
void Fixture::setFriction(float friction) {
|
||||
if (!fixture_) return;
|
||||
fixture_->SetFriction(friction);
|
||||
}
|
||||
|
||||
float Fixture::getFriction() const { return fixture_ ? fixture_->GetFriction() : 0.f; }
|
||||
|
||||
void Fixture::setRestitution(float restitution) {
|
||||
if (!fixture_) return;
|
||||
fixture_->SetRestitution(restitution);
|
||||
}
|
||||
|
||||
float Fixture::getRestitution() const { return fixture_ ? fixture_->GetRestitution() : 0.f; }
|
||||
|
||||
void Fixture::setDensity(float density) {
|
||||
if (!fixture_) return;
|
||||
fixture_->SetDensity(density);
|
||||
if (body_ && body_->raw()) body_->raw()->ResetMassData();
|
||||
}
|
||||
|
||||
float Fixture::getDensity() const { return fixture_ ? fixture_->GetDensity() : 0.f; }
|
||||
|
||||
} // namespace eve::physics
|
||||
Reference in new issue
Block a user