optimize game view performance

This commit is contained in:
T1ti
2023-07-20 03:11:11 +02:00
parent 9038d9af4c
commit 9aeefcbe3b
3 changed files with 19 additions and 7 deletions

View File

@@ -3998,20 +3998,22 @@ void MapView::tick (float dt)
if (moving)
{
_camera.move_forward(moving, dt);
_camera_moved_since_last_draw = true;
// TODO use normalized speed (doesn't slow down when looking up)
// _camera.move_forward_normalized(moving, dt);
}
if (strafing)
{
_camera.move_horizontal(strafing, dt);
_camera_moved_since_last_draw = true;
}
// get ground z position
// can be optimized by calling this only when moving/strafing or changing camera mode.
auto ground_pos = _world.get()->get_ground_height(_camera.position);
_camera.position.y = ground_pos.y + 2;
_camera_moved_since_last_draw = true;
// hack to update camera when entering mode in void ViewToolbar::add_tool_icon()
if (_camera_moved_since_last_draw)
{
auto ground_pos = _world.get()->get_ground_height(_camera.position);
_camera.position.y = ground_pos.y + 2;
}
}
else
{

View File

@@ -280,6 +280,7 @@ public:
void randomizeStampRotation();
void onSettingsSave();
void updateRotationEditor() { _rotation_editor_need_update = true; };
void setCameraDirty() { _camera_moved_since_last_draw = true; };
[[nodiscard]]
Noggit::Ui::minimap_widget* getMinimapWidget() const { return _minimap; }

View File

@@ -398,7 +398,16 @@ void ViewToolbar::add_tool_icon(MapView* mapView,
}
});
connect (view_state, &Noggit::BoolToggleProperty::changed, [action, view_state] () {
connect (view_state, &Noggit::BoolToggleProperty::changed, [action, view_state, mapView] () {
if (action->text() == "Game view" && view_state->get())
{
// hack, manually update camera when switch to game_view
mapView->setCameraDirty();
auto ground_pos = mapView->getWorld()->get_ground_height(mapView->getCamera()->position);
mapView->getCamera()->position.y = ground_pos.y + 2;
}
action->setChecked(view_state->get());
});