mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-14 07:21:51 +00:00
cleanup
This commit is contained in:
parent
38b478bc8d
commit
b7cd116e62
3 changed files with 16 additions and 33 deletions
|
|
@ -17,7 +17,7 @@ inline constexpr float MAX_FIX = 0.15f;
|
||||||
|
|
||||||
static debug::Logger logger("physics-solver");
|
static debug::Logger logger("physics-solver");
|
||||||
|
|
||||||
PhysicsSolver::PhysicsSolver(glm::vec3 gravity) : gravity(std::move(gravity)) {}
|
PhysicsSolver::PhysicsSolver(const GlobalChunks& chunks, glm::vec3 gravity) : chunks(chunks), gravity(std::move(gravity)) {}
|
||||||
|
|
||||||
static float calc_step_height(
|
static float calc_step_height(
|
||||||
const GlobalChunks& chunks,
|
const GlobalChunks& chunks,
|
||||||
|
|
@ -116,12 +116,7 @@ static void calc_collision(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool calc_collision_neg_y(
|
bool PhysicsSolver::calcCollisionNegY(Hitbox& hitbox, const glm::vec3& half) {
|
||||||
Hitbox& hitbox,
|
|
||||||
const GlobalChunks& chunks,
|
|
||||||
const std::vector<Hitbox*>& solidHitboxes,
|
|
||||||
const glm::vec3& half
|
|
||||||
) {
|
|
||||||
auto& pos = hitbox.position;
|
auto& pos = hitbox.position;
|
||||||
auto& vel = hitbox.velocity;
|
auto& vel = hitbox.velocity;
|
||||||
|
|
||||||
|
|
@ -183,10 +178,9 @@ static bool calc_collision_neg_y(
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsSolver::calcCollisions(
|
void PhysicsSolver::calcCollisions(
|
||||||
const GlobalChunks& chunks,
|
Hitbox& hitbox,
|
||||||
Hitbox& hitbox,
|
glm::vec3& vel,
|
||||||
glm::vec3& vel,
|
glm::vec3& pos,
|
||||||
glm::vec3& pos,
|
|
||||||
const glm::vec3& half,
|
const glm::vec3& half,
|
||||||
float stepHeight
|
float stepHeight
|
||||||
) {
|
) {
|
||||||
|
|
@ -205,7 +199,7 @@ void PhysicsSolver::calcCollisions(
|
||||||
calc_collision<2, 1, 0, 1>(hitbox, chunks, solidHitboxes, half, stepHeight);
|
calc_collision<2, 1, 0, 1>(hitbox, chunks, solidHitboxes, half, stepHeight);
|
||||||
pos.x = xpos;
|
pos.x = xpos;
|
||||||
|
|
||||||
if (calc_collision_neg_y(hitbox, chunks, solidHitboxes, half)) {
|
if (calcCollisionNegY(hitbox, half)) {
|
||||||
hitbox.grounded = true;
|
hitbox.grounded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -290,7 +284,6 @@ void PhysicsSolver::calcCollisions(
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsSolver::calcSubstep(
|
void PhysicsSolver::calcSubstep(
|
||||||
const GlobalChunks& chunks,
|
|
||||||
Hitbox& hitbox,
|
Hitbox& hitbox,
|
||||||
glm::vec3& vel,
|
glm::vec3& vel,
|
||||||
glm::vec3& pos,
|
glm::vec3& pos,
|
||||||
|
|
@ -311,7 +304,6 @@ void PhysicsSolver::calcSubstep(
|
||||||
|
|
||||||
if (hitbox.type == BodyType::DYNAMIC) {
|
if (hitbox.type == BodyType::DYNAMIC) {
|
||||||
calcCollisions(
|
calcCollisions(
|
||||||
chunks,
|
|
||||||
hitbox,
|
hitbox,
|
||||||
vel,
|
vel,
|
||||||
pos,
|
pos,
|
||||||
|
|
@ -369,9 +361,7 @@ void PhysicsSolver::calcSubstep(
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsSolver::step(
|
void PhysicsSolver::step(
|
||||||
const GlobalChunks& chunks,
|
const GlobalChunks& chunks, float delta, uint substeps
|
||||||
float delta,
|
|
||||||
uint substeps
|
|
||||||
) {
|
) {
|
||||||
for (auto hitbox : hitboxes) {
|
for (auto hitbox : hitboxes) {
|
||||||
hitbox->groundMaterial.clear();
|
hitbox->groundMaterial.clear();
|
||||||
|
|
@ -386,7 +376,7 @@ void PhysicsSolver::step(
|
||||||
glm::vec3& pos = hitbox->position;
|
glm::vec3& pos = hitbox->position;
|
||||||
glm::vec3& vel = hitbox->velocity;
|
glm::vec3& vel = hitbox->velocity;
|
||||||
hitbox->prevPosition = hitbox->position;
|
hitbox->prevPosition = hitbox->position;
|
||||||
calcSubstep(chunks, *hitbox, vel, pos, dt, substeps);
|
calcSubstep(*hitbox, vel, pos, dt, substeps);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,7 +402,6 @@ void PhysicsSolver::step(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PhysicsSolver::updateSensors(Hitbox& hitbox) {
|
void PhysicsSolver::updateSensors(Hitbox& hitbox) {
|
||||||
auto aabb = hitbox.getAABB();
|
auto aabb = hitbox.getAABB();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,9 @@ struct Sensor;
|
||||||
|
|
||||||
class PhysicsSolver {
|
class PhysicsSolver {
|
||||||
public:
|
public:
|
||||||
PhysicsSolver(glm::vec3 gravity);
|
PhysicsSolver(const GlobalChunks& chunks, glm::vec3 gravity);
|
||||||
void step(
|
|
||||||
const GlobalChunks& chunks,
|
void step(const GlobalChunks& chunks, float delta, uint substeps);
|
||||||
float delta,
|
|
||||||
uint substeps
|
|
||||||
);
|
|
||||||
|
|
||||||
auto& getSensorsWriteable() {
|
auto& getSensorsWriteable() {
|
||||||
return sensors;
|
return sensors;
|
||||||
|
|
@ -36,13 +33,13 @@ public:
|
||||||
|
|
||||||
void removeSensor(Sensor* sensor);
|
void removeSensor(Sensor* sensor);
|
||||||
private:
|
private:
|
||||||
|
const GlobalChunks& chunks;
|
||||||
glm::vec3 gravity;
|
glm::vec3 gravity;
|
||||||
std::vector<Sensor*> sensors;
|
std::vector<Sensor*> sensors;
|
||||||
std::vector<Hitbox*> solidHitboxes;
|
std::vector<Hitbox*> solidHitboxes;
|
||||||
std::vector<Hitbox*> hitboxes;
|
std::vector<Hitbox*> hitboxes;
|
||||||
|
|
||||||
void calcCollisions(
|
void calcCollisions(
|
||||||
const GlobalChunks& chunks,
|
|
||||||
Hitbox& hitbox,
|
Hitbox& hitbox,
|
||||||
glm::vec3& vel,
|
glm::vec3& vel,
|
||||||
glm::vec3& pos,
|
glm::vec3& pos,
|
||||||
|
|
@ -51,13 +48,10 @@ private:
|
||||||
);
|
);
|
||||||
|
|
||||||
void calcSubstep(
|
void calcSubstep(
|
||||||
const GlobalChunks& chunks,
|
Hitbox& hitbox, glm::vec3& vel, glm::vec3& pos, float dt, int substeps
|
||||||
Hitbox& hitbox,
|
|
||||||
glm::vec3& vel,
|
|
||||||
glm::vec3& pos,
|
|
||||||
float dt,
|
|
||||||
int substeps
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
bool calcCollisionNegY(Hitbox& hitbox, const glm::vec3& half);
|
||||||
|
|
||||||
void updateSensors(Hitbox& hitbox);
|
void updateSensors(Hitbox& hitbox);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ Level::Level(
|
||||||
: world(std::move(worldPtr)),
|
: world(std::move(worldPtr)),
|
||||||
content(content),
|
content(content),
|
||||||
chunks(std::make_unique<GlobalChunks>(*this)),
|
chunks(std::make_unique<GlobalChunks>(*this)),
|
||||||
physics(std::make_unique<PhysicsSolver>(glm::vec3(0, -22.6f, 0))),
|
physics(std::make_unique<PhysicsSolver>(*chunks, glm::vec3(0, -22.6f, 0))),
|
||||||
events(std::make_unique<LevelEvents>()),
|
events(std::make_unique<LevelEvents>()),
|
||||||
entities(std::make_unique<Entities>(*this)),
|
entities(std::make_unique<Entities>(*this)),
|
||||||
players(std::make_unique<Players>(*this)),
|
players(std::make_unique<Players>(*this)),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue