update on_physics_update & update standard components

This commit is contained in:
MihailRis
2025-09-13 23:24:57 +03:00
parent 2d29b8c46c
commit bf682daffe
9 changed files with 12 additions and 29 deletions
-1
View File
@@ -95,7 +95,6 @@ void LevelController::update(float delta, bool pause) {
if (!pause) {
// update all objects that needed
blocks->update(delta, settings.chunks.padding.get());
level->entities->updatePhysics(delta);
level->entities->update(delta);
for (const auto& [_, player] : *level->players) {
if (player->isSuspended()) {
+1 -1
View File
@@ -139,7 +139,7 @@ namespace scripting {
void on_entity_fall(const Entity& entity);
void on_entity_save(const Entity& entity);
void on_entities_update(int tps, int parts, int part);
void on_entities_physics_update(int tps, int parts, int part);
void on_entities_physics_update(float delta);
void on_entities_render(float delta);
void on_sensor_enter(const Entity& entity, size_t index, entityid_t oid);
void on_sensor_exit(const Entity& entity, size_t index, entityid_t oid);
+3 -5
View File
@@ -279,13 +279,11 @@ void scripting::on_entities_update(int tps, int parts, int part) {
lua::pop(L);
}
void scripting::on_entities_physics_update(int tps, int parts, int part) {
void scripting::on_entities_physics_update(float delta) {
auto L = lua::get_main_state();
lua::get_from(L, STDCOMP, "physics_update", true);
lua::pushinteger(L, tps);
lua::pushinteger(L, parts);
lua::pushinteger(L, part);
lua::call_nothrow(L, 3, 0);
lua::pushnumber(L, delta);
lua::call_nothrow(L, 1, 0);
lua::pop(L);
}
+3 -9
View File
@@ -27,8 +27,7 @@ static debug::Logger logger("entities");
Entities::Entities(Level& level)
: level(level),
sensorsTickClock(20, 3),
updateTickClock(20, 3),
physicsTickClock(60, 1) {
updateTickClock(20, 3) {
}
std::optional<Entity> Entities::get(entityid_t id) {
@@ -323,13 +322,8 @@ void Entities::update(float delta) {
updateTickClock.getPart()
);
}
if (physicsTickClock.update(delta)) {
scripting::on_entities_physics_update(
physicsTickClock.getTickRate(),
physicsTickClock.getParts(),
physicsTickClock.getPart()
);
}
updatePhysics(delta);
scripting::on_entities_physics_update(delta);
}
static void debug_render_skeleton(
-1
View File
@@ -39,7 +39,6 @@ class Entities {
entityid_t nextID = 1;
util::Clock sensorsTickClock;
util::Clock updateTickClock;
util::Clock physicsTickClock;
void updateSensors(
Rigidbody& body, const Transform& tsf, std::vector<Sensor*>& sensors
+1 -1
View File
@@ -10,7 +10,7 @@ Clock::Clock(int tickRate, int tickParts)
bool Clock::update(float delta) {
tickTimer += delta;
float delay = 1.0f / float(tickRate);
float delay = 1.0f / static_cast<float>(tickRate);
if (tickTimer > delay || tickPartsUndone) {
if (tickPartsUndone) {
tickPartsUndone--;