update on_physics_update & update standard components
This commit is contained in:
parent
2d29b8c46c
commit
bf682daffe
@ -133,21 +133,17 @@ return {
|
|||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
physics_update = function(tps, parts, part)
|
physics_update = function(delta)
|
||||||
for uid, entity in pairs(entities) do
|
for uid, entity in pairs(entities) do
|
||||||
if uid % parts ~= part then
|
|
||||||
goto continue
|
|
||||||
end
|
|
||||||
for _, component in pairs(entity.components) do
|
for _, component in pairs(entity.components) do
|
||||||
local callback = component.on_physics_update
|
local callback = component.on_physics_update
|
||||||
if not component.__disabled and callback then
|
if not component.__disabled and callback then
|
||||||
local result, err = pcall(callback, tps)
|
local result, err = pcall(callback, delta)
|
||||||
if err then
|
if err then
|
||||||
debug.error(err)
|
debug.error(err)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
::continue::
|
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
render = function(delta)
|
render = function(delta)
|
||||||
|
|||||||
@ -151,9 +151,7 @@ function set_flight(flag) flight = flag end
|
|||||||
|
|
||||||
local prev_angle = (vec2.angle({dir[3], dir[1]})) % 360
|
local prev_angle = (vec2.angle({dir[3], dir[1]})) % 360
|
||||||
|
|
||||||
function on_physics_update(tps)
|
function on_physics_update(delta)
|
||||||
local delta = (1.0 / tps)
|
|
||||||
|
|
||||||
local grounded = body:is_grounded()
|
local grounded = body:is_grounded()
|
||||||
body:set_vdamping(flight)
|
body:set_vdamping(flight)
|
||||||
body:set_gravity_scale({0, flight and 0.0 or props.gravity_scale, 0})
|
body:set_gravity_scale({0, flight and 0.0 or props.gravity_scale, 0})
|
||||||
|
|||||||
@ -51,8 +51,7 @@ local function process_player_inputs(pid, delta)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_physics_update(tps)
|
function on_physics_update(delta)
|
||||||
local delta = (1.0 / tps)
|
|
||||||
local pid = entity:get_player()
|
local pid = entity:get_player()
|
||||||
if pid ~= -1 then
|
if pid ~= -1 then
|
||||||
local pos = tsf:get_pos()
|
local pos = tsf:get_pos()
|
||||||
|
|||||||
@ -95,7 +95,6 @@ void LevelController::update(float delta, bool pause) {
|
|||||||
if (!pause) {
|
if (!pause) {
|
||||||
// update all objects that needed
|
// update all objects that needed
|
||||||
blocks->update(delta, settings.chunks.padding.get());
|
blocks->update(delta, settings.chunks.padding.get());
|
||||||
level->entities->updatePhysics(delta);
|
|
||||||
level->entities->update(delta);
|
level->entities->update(delta);
|
||||||
for (const auto& [_, player] : *level->players) {
|
for (const auto& [_, player] : *level->players) {
|
||||||
if (player->isSuspended()) {
|
if (player->isSuspended()) {
|
||||||
|
|||||||
@ -139,7 +139,7 @@ namespace scripting {
|
|||||||
void on_entity_fall(const Entity& entity);
|
void on_entity_fall(const Entity& entity);
|
||||||
void on_entity_save(const Entity& entity);
|
void on_entity_save(const Entity& entity);
|
||||||
void on_entities_update(int tps, int parts, int part);
|
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_entities_render(float delta);
|
||||||
void on_sensor_enter(const Entity& entity, size_t index, entityid_t oid);
|
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);
|
void on_sensor_exit(const Entity& entity, size_t index, entityid_t oid);
|
||||||
|
|||||||
@ -279,13 +279,11 @@ void scripting::on_entities_update(int tps, int parts, int part) {
|
|||||||
lua::pop(L);
|
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();
|
auto L = lua::get_main_state();
|
||||||
lua::get_from(L, STDCOMP, "physics_update", true);
|
lua::get_from(L, STDCOMP, "physics_update", true);
|
||||||
lua::pushinteger(L, tps);
|
lua::pushnumber(L, delta);
|
||||||
lua::pushinteger(L, parts);
|
lua::call_nothrow(L, 1, 0);
|
||||||
lua::pushinteger(L, part);
|
|
||||||
lua::call_nothrow(L, 3, 0);
|
|
||||||
lua::pop(L);
|
lua::pop(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,8 +27,7 @@ static debug::Logger logger("entities");
|
|||||||
Entities::Entities(Level& level)
|
Entities::Entities(Level& level)
|
||||||
: level(level),
|
: level(level),
|
||||||
sensorsTickClock(20, 3),
|
sensorsTickClock(20, 3),
|
||||||
updateTickClock(20, 3),
|
updateTickClock(20, 3) {
|
||||||
physicsTickClock(60, 1) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<Entity> Entities::get(entityid_t id) {
|
std::optional<Entity> Entities::get(entityid_t id) {
|
||||||
@ -323,13 +322,8 @@ void Entities::update(float delta) {
|
|||||||
updateTickClock.getPart()
|
updateTickClock.getPart()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (physicsTickClock.update(delta)) {
|
updatePhysics(delta);
|
||||||
scripting::on_entities_physics_update(
|
scripting::on_entities_physics_update(delta);
|
||||||
physicsTickClock.getTickRate(),
|
|
||||||
physicsTickClock.getParts(),
|
|
||||||
physicsTickClock.getPart()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void debug_render_skeleton(
|
static void debug_render_skeleton(
|
||||||
|
|||||||
@ -39,7 +39,6 @@ class Entities {
|
|||||||
entityid_t nextID = 1;
|
entityid_t nextID = 1;
|
||||||
util::Clock sensorsTickClock;
|
util::Clock sensorsTickClock;
|
||||||
util::Clock updateTickClock;
|
util::Clock updateTickClock;
|
||||||
util::Clock physicsTickClock;
|
|
||||||
|
|
||||||
void updateSensors(
|
void updateSensors(
|
||||||
Rigidbody& body, const Transform& tsf, std::vector<Sensor*>& sensors
|
Rigidbody& body, const Transform& tsf, std::vector<Sensor*>& sensors
|
||||||
|
|||||||
@ -10,7 +10,7 @@ Clock::Clock(int tickRate, int tickParts)
|
|||||||
|
|
||||||
bool Clock::update(float delta) {
|
bool Clock::update(float delta) {
|
||||||
tickTimer += delta;
|
tickTimer += delta;
|
||||||
float delay = 1.0f / float(tickRate);
|
float delay = 1.0f / static_cast<float>(tickRate);
|
||||||
if (tickTimer > delay || tickPartsUndone) {
|
if (tickTimer > delay || tickPartsUndone) {
|
||||||
if (tickPartsUndone) {
|
if (tickPartsUndone) {
|
||||||
tickPartsUndone--;
|
tickPartsUndone--;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user