add on_update, on_render to docs & change entities tps to 20
This commit is contained in:
@@ -188,6 +188,7 @@ void WorldRenderer::renderLevel(
|
||||
const DrawContext&,
|
||||
Camera* camera,
|
||||
const EngineSettings& settings,
|
||||
float delta,
|
||||
bool pause
|
||||
) {
|
||||
auto assets = engine->getAssets();
|
||||
@@ -206,7 +207,7 @@ void WorldRenderer::renderLevel(
|
||||
auto entityShader = assets->get<Shader>("entity");
|
||||
setupWorldShader(entityShader, camera, settings, fogFactor);
|
||||
|
||||
level->entities->render(assets, *modelBatch, *frustumCulling, pause);
|
||||
level->entities->render(assets, *modelBatch, *frustumCulling, delta, pause);
|
||||
|
||||
if (!pause) {
|
||||
scripting::on_frontend_render();
|
||||
@@ -339,7 +340,7 @@ void WorldRenderer::draw(
|
||||
DrawContext ctx = wctx.sub();
|
||||
ctx.setDepthTest(true);
|
||||
ctx.setCullFace(true);
|
||||
renderLevel(ctx, camera, settings, pause);
|
||||
renderLevel(ctx, camera, settings, delta, pause);
|
||||
// Debug lines
|
||||
if (hudVisible){
|
||||
renderLines(camera, linesShader, ctx);
|
||||
|
||||
@@ -94,6 +94,7 @@ public:
|
||||
const DrawContext& context,
|
||||
Camera* camera,
|
||||
const EngineSettings& settings,
|
||||
float delta,
|
||||
bool pause
|
||||
);
|
||||
};
|
||||
|
||||
@@ -41,7 +41,7 @@ void LevelController::update(float delta, bool input, bool pause) {
|
||||
blocks->update(delta);
|
||||
player->update(delta, input, pause);
|
||||
level->entities->updatePhysics(delta);
|
||||
level->entities->update();
|
||||
level->entities->update(delta);
|
||||
}
|
||||
level->entities->clean();
|
||||
player->postUpdate(delta, input, pause);
|
||||
|
||||
@@ -475,17 +475,21 @@ void scripting::on_entity_used(const Entity& entity, Player* player) {
|
||||
});
|
||||
}
|
||||
|
||||
void scripting::on_entities_update() {
|
||||
void scripting::on_entities_update(int tps, int parts, int part) {
|
||||
auto L = lua::get_main_thread();
|
||||
lua::get_from(L, STDCOMP, "update", true);
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
lua::pushinteger(L, tps);
|
||||
lua::pushinteger(L, parts);
|
||||
lua::pushinteger(L, part);
|
||||
lua::call_nothrow(L, 3, 0);
|
||||
lua::pop(L);
|
||||
}
|
||||
|
||||
void scripting::on_entities_render() {
|
||||
void scripting::on_entities_render(float delta) {
|
||||
auto L = lua::get_main_thread();
|
||||
lua::get_from(L, STDCOMP, "render", true);
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
lua::pushnumber(L, delta);
|
||||
lua::call_nothrow(L, 1, 0);
|
||||
lua::pop(L);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,8 +89,8 @@ namespace scripting {
|
||||
void on_entity_grounded(const Entity& entity, float force);
|
||||
void on_entity_fall(const Entity& entity);
|
||||
void on_entity_save(const Entity& entity);
|
||||
void on_entities_update();
|
||||
void on_entities_render();
|
||||
void on_entities_update(int tps, int parts, int part);
|
||||
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);
|
||||
void on_aim_on(const Entity& entity, Player* player);
|
||||
|
||||
@@ -59,7 +59,8 @@ void Entity::setRig(const rigging::SkeletonConfig* rigConfig) {
|
||||
);
|
||||
}
|
||||
|
||||
Entities::Entities(Level* level) : level(level), sensorsTickClock(20, 3) {
|
||||
Entities::Entities(Level* level)
|
||||
: level(level), sensorsTickClock(20, 3), updateTickClock(20, 3) {
|
||||
}
|
||||
|
||||
template<void(*callback)(const Entity&, size_t, entityid_t)>
|
||||
@@ -440,8 +441,13 @@ void Entities::updatePhysics(float delta) {
|
||||
}
|
||||
}
|
||||
|
||||
void Entities::update() {
|
||||
scripting::on_entities_update();
|
||||
void Entities::update(float delta) {
|
||||
if (updateTickClock.update(delta)) {
|
||||
scripting::on_entities_update(
|
||||
updateTickClock.getTickRate(),
|
||||
updateTickClock.getParts(),
|
||||
updateTickClock.getPart());
|
||||
}
|
||||
}
|
||||
|
||||
static void debug_render_skeleton(
|
||||
@@ -505,10 +511,10 @@ void Entities::renderDebug(
|
||||
}
|
||||
|
||||
void Entities::render(
|
||||
Assets* assets, ModelBatch& batch, const Frustum& frustum, bool pause
|
||||
Assets* assets, ModelBatch& batch, const Frustum& frustum, float delta, bool pause
|
||||
) {
|
||||
if (!pause) {
|
||||
scripting::on_entities_render();
|
||||
scripting::on_entities_render(delta);
|
||||
}
|
||||
|
||||
auto view = registry.view<Transform, rigging::Skeleton>();
|
||||
|
||||
@@ -167,6 +167,7 @@ class Entities {
|
||||
std::unordered_map<entt::entity, entityid_t> uids;
|
||||
entityid_t nextID = 1;
|
||||
util::Clock sensorsTickClock;
|
||||
util::Clock updateTickClock;
|
||||
|
||||
void updateSensors(
|
||||
Rigidbody& body, const Transform& tsf, std::vector<Sensor*>& sensors
|
||||
@@ -183,10 +184,10 @@ public:
|
||||
|
||||
void clean();
|
||||
void updatePhysics(float delta);
|
||||
void update();
|
||||
void update(float delta);
|
||||
|
||||
void renderDebug(LineBatch& batch, const Frustum& frustum, const DrawContext& ctx);
|
||||
void render(Assets* assets, ModelBatch& batch, const Frustum& frustum, bool pause);
|
||||
void render(Assets* assets, ModelBatch& batch, const Frustum& frustum, float delta, bool pause);
|
||||
|
||||
entityid_t spawn(
|
||||
EntityDef& def,
|
||||
|
||||
Reference in New Issue
Block a user