removing more boost usage

This commit is contained in:
Alister
2021-12-12 20:47:45 +00:00
parent f41ef1914f
commit 486af54129
13 changed files with 66 additions and 70 deletions

View File

@@ -429,7 +429,7 @@ void noggit::Action::finish()
continue;
}
auto obj = boost::get<selected_object_type>(instance.get());
auto obj = boost::get<selected_object_type>(instance.value());
post.second.pos = obj->pos;
post.second.dir = obj->dir;

View File

@@ -937,16 +937,16 @@ void MapTile::saveTile(World* world)
}
else
{
if (model.get().which() == eEntry_Object)
if (model.value().which() == eEntry_Object)
{
auto which = boost::get<selected_object_type>(model.get())->which();
auto which = boost::get<selected_object_type>(model.value())->which();
if (which == eWMO)
{
lObjectInstances.emplace_back(*static_cast<WMOInstance*>(boost::get<selected_object_type>(model.get())));
lObjectInstances.emplace_back(*static_cast<WMOInstance*>(boost::get<selected_object_type>(model.value())));
}
else if (which == eMODEL)
{
lModelInstances.emplace_back(*static_cast<ModelInstance*>(boost::get<selected_object_type>(model.get())));
lModelInstances.emplace_back(*static_cast<ModelInstance*>(boost::get<selected_object_type>(model.value())));
}
}
@@ -1321,7 +1321,7 @@ void MapTile::remove_model(uint32_t uid)
{
uids.erase(it);
auto& obj = _world->get_model(uid).get();
const auto& obj = _world->get_model(uid).value();
auto instance = boost::get<selected_object_type>(obj);
auto& instances = object_instances[instance->instance_model()];
@@ -1378,7 +1378,7 @@ void MapTile::add_model(uint32_t uid)
{
uids.push_back(uid);
auto& obj = _world->get_model(uid).get();
const auto& obj = _world->get_model(uid).value();
auto instance = boost::get<selected_object_type>(obj);
object_instances[instance->instance_model()].push_back(instance);

View File

@@ -3071,8 +3071,8 @@ void MapView::paintGL()
_transform_gizmo.setCurrentGizmoMode(_gizmo_mode);
_transform_gizmo.setUseMultiselectionPivot(_use_median_pivot_point.get());
auto pivot = _world->multi_select_pivot().is_initialized() ?
_world->multi_select_pivot().get() : glm::vec3(0.f, 0.f, 0.f);
auto pivot = _world->multi_select_pivot().has_value() ?
_world->multi_select_pivot().value() : glm::vec3(0.f, 0.f, 0.f);
_transform_gizmo.setMultiselectionPivot(pivot);

View File

@@ -153,7 +153,7 @@ void World::update_selection_pivot()
}
else
{
_multi_select_pivot = boost::none;
_multi_select_pivot = std::nullopt;
}
}
@@ -233,7 +233,7 @@ bool World::is_selected(std::uint32_t uid) const
return false;
}
boost::optional<selection_type> World::get_last_selected_model() const
std::optional<selection_type> World::get_last_selected_model() const
{
ZoneScoped;
auto const it
@@ -247,7 +247,7 @@ boost::optional<selection_type> World::get_last_selected_model() const
);
return it == _current_selection.rend()
? boost::optional<selection_type>() : boost::optional<selection_type> (*it);
? std::optional<selection_type>() : std::optional<selection_type> (*it);
}
glm::vec3 getBarycentricCoordinatesAt(
@@ -505,7 +505,7 @@ void World::set_current_selection(selection_type entry)
ZoneScoped;
_current_selection.clear();
_current_selection.push_back(entry);
_multi_select_pivot = boost::none;
_multi_select_pivot = std::nullopt;
_selected_model_count = entry.which() == eEntry_MapChunk ? 0 : 1;
}
@@ -567,7 +567,7 @@ void World::reset_selection()
{
ZoneScoped;
_current_selection.clear();
_multi_select_pivot = boost::none;
_multi_select_pivot = std::nullopt;
_selected_model_count = 0;
}
@@ -709,7 +709,7 @@ void World::set_selected_models_pos(glm::vec3 const& pos, bool change_height)
// move models relative to the pivot when several are selected
if (has_multiple_model_selected())
{
glm::vec3 diff = pos - _multi_select_pivot.get();
glm::vec3 diff = pos - _multi_select_pivot.value();
if (change_height)
{
@@ -767,7 +767,7 @@ void World::rotate_selected_models(math::degrees rx, math::degrees ry, math::deg
{
glm::vec3& pos = obj->pos;
math::degrees::vec3& dir = obj->dir;
glm::vec3 diff_pos = pos - _multi_select_pivot.get();
glm::vec3 diff_pos = pos - _multi_select_pivot.value();
glm::quat rotationQuat = glm::quat(glm::vec3(glm::radians(rx._), glm::radians(ry._), glm::radians(rz._)));
glm::vec3 rot_result = glm::toMat4(rotationQuat) * glm::vec4(diff_pos,0);
@@ -1355,8 +1355,8 @@ void World::draw (glm::mat4x4 const& model_view
ZoneScopedN("World::draw() : Draw pivot point");
opengl::scoped::bool_setter<GL_DEPTH_TEST, GL_FALSE> const disable_depth_test;
float dist = glm::distance(camera_pos, _multi_select_pivot.get());
_sphere_render.draw(mvp, _multi_select_pivot.get(), cursor_color, std::min(2.f, std::max(0.15f, dist * 0.02f)));
float dist = glm::distance(camera_pos, _multi_select_pivot.value());
_sphere_render.draw(mvp, _multi_select_pivot.value(), cursor_color, std::min(2.f, std::max(0.15f, dist * 0.02f)));
}
if (use_ref_pos)
@@ -1986,7 +1986,7 @@ void World::update_models_emitters(float dt)
unsigned int World::getAreaID (glm::vec3 const& pos)
{
ZoneScoped;
return for_maybe_chunk_at (pos, [&] (MapChunk* chunk) { return chunk->getAreaID(); }).get_value_or (-1);
return for_maybe_chunk_at (pos, [&] (MapChunk* chunk) { return chunk->getAreaID(); }).value_or(-1);
}
void World::clearHeight(glm::vec3 const& pos)
@@ -2724,7 +2724,7 @@ void World::addM2 ( BlizzardArchive::Listfile::FileKey const& file_key
std::uint32_t uid = _model_instance_storage.add_model_instance(std::move(model_instance), true);
_models_by_filename[file_key.filepath()].push_back(_model_instance_storage.get_model_instance(uid).get());
_models_by_filename[file_key.filepath()].push_back(_model_instance_storage.get_model_instance(uid).value());
}
ModelInstance* World::addM2AndGetInstance ( BlizzardArchive::Listfile::FileKey const& file_key
@@ -2773,7 +2773,7 @@ ModelInstance* World::addM2AndGetInstance ( BlizzardArchive::Listfile::FileKey c
std::uint32_t uid = _model_instance_storage.add_model_instance(std::move(model_instance), true);
auto instance = _model_instance_storage.get_model_instance(uid).get();
auto instance = _model_instance_storage.get_model_instance(uid).value();
_models_by_filename[file_key.filepath()].push_back(instance);
return instance;
@@ -2816,7 +2816,7 @@ WMOInstance* World::addWMOAndGetInstance ( BlizzardArchive::Listfile::FileKey co
std::uint32_t uid = _model_instance_storage.add_wmo_instance(std::move(wmo_instance), true);
return _model_instance_storage.get_wmo_instance(uid).get();
return _model_instance_storage.get_wmo_instance(uid).value();
}
@@ -2832,7 +2832,7 @@ std::uint32_t World::add_wmo_instance(WMOInstance wmo_instance, bool from_reload
return _model_instance_storage.add_wmo_instance(std::move(wmo_instance), from_reloading);
}
boost::optional<selection_type> World::get_model(std::uint32_t uid)
std::optional<selection_type> World::get_model(std::uint32_t uid)
{
ZoneScoped;
return _model_instance_storage.get_instance(uid);
@@ -3713,9 +3713,9 @@ void World::range_add_to_selection(glm::vec3 const& pos, float radius, bool remo
{
auto instance = _model_instance_storage.get_instance(uid);
if (instance && instance.get().which() == eEntry_Object)
if (instance && instance.value().which() == eEntry_Object)
{
auto obj = boost::get<selected_object_type>(instance.get());
auto obj = boost::get<selected_object_type>(instance.value());
if (glm::distance(obj->pos, pos) <= radius && is_selected(obj))
{
@@ -3731,9 +3731,9 @@ void World::range_add_to_selection(glm::vec3 const& pos, float radius, bool remo
{
auto instance = _model_instance_storage.get_instance(uid);
if (instance && instance.get().which() == eEntry_Object)
if (instance && instance.value().which() == eEntry_Object)
{
auto obj = boost::get<selected_object_type>(instance.get());
auto obj = boost::get<selected_object_type>(instance.value());
if (glm::distance(obj->pos, pos) <= radius && !is_selected(obj))
{
@@ -3761,9 +3761,9 @@ float World::getMaxTileHeight(const tile_index& tile)
{
auto instance = _model_instance_storage.get_instance(uid);
if (instance.get().which() == eEntry_Object)
if (instance.value().which() == eEntry_Object)
{
auto obj = boost::get<selected_object_type>(instance.get());
auto obj = boost::get<selected_object_type>(instance.value());
obj->ensureExtents();
max_height = std::max(max_height, std::max(obj->extents[0].y, obj->extents[1].y));
}
@@ -3781,9 +3781,9 @@ SceneObject* World::getObjectInstance(std::uint32_t uid)
if (!instance)
return nullptr;
if (instance.get().which() == eEntry_Object)
if (instance.value().which() == eEntry_Object)
{
return boost::get<selected_object_type>(instance.get());
return boost::get<selected_object_type>(instance.value());
}
return nullptr;

View File

@@ -22,11 +22,8 @@
#include <opengl/shader.fwd.hpp>
#include <opengl/types.hpp>
#include <noggit/LiquidTextureManager.hpp>
#include <boost/optional/optional.hpp>
#include <optional>
#include <QtCore/QSettings>
#include <map>
#include <string>
#include <unordered_set>
@@ -151,19 +148,19 @@ public:
private:
// Information about the currently selected model / WMO / triangle.
int _selected_model_count = 0;
boost::optional<glm::vec3> _multi_select_pivot;
std::optional<glm::vec3> _multi_select_pivot;
public:
void unload_shaders();
void update_selection_pivot();
boost::optional<glm::vec3> const& multi_select_pivot() const { return _multi_select_pivot; }
std::optional<glm::vec3> const& multi_select_pivot() const { return _multi_select_pivot; }
// Selection related methods.
bool is_selected(selection_type selection) const;
bool is_selected(std::uint32_t uid) const;
std::vector<selection_type> const& current_selection() const { return _current_selection; }
boost::optional<selection_type> get_last_selected_model() const;
std::optional<selection_type> get_last_selected_model() const;
bool has_selection() const { return !_current_selection.empty(); }
bool has_multiple_model_selected() const { return _selected_model_count > 1; }
int get_selected_model_count() const { return _selected_model_count; }
@@ -238,7 +235,7 @@ public:
template<typename Fun>
void for_chunk_at(glm::vec3 const& pos, Fun&& fun);
template<typename Fun>
auto for_maybe_chunk_at (glm::vec3 const& pos, Fun&& fun) -> boost::optional<decltype (fun (nullptr))>;
auto for_maybe_chunk_at (glm::vec3 const& pos, Fun&& fun) -> std::optional<decltype (fun (nullptr))>;
template<typename Fun>
void for_tile_at(const tile_index& pos, Fun&&);
@@ -321,7 +318,7 @@ public:
// add a wmo instance to the world (needs to be positioned already), return the uid
std::uint32_t add_wmo_instance(WMOInstance wmo_instance, bool from_reloading);
boost::optional<selection_type> get_model(std::uint32_t uid);
std::optional<selection_type> get_model(std::uint32_t uid);
void remove_models_if_needed(std::vector<uint32_t> const& uids);
void reload_tile(tile_index const& tile);

View File

@@ -38,7 +38,7 @@ void World::for_chunk_at(glm::vec3 const& pos, Fun&& fun)
}
template<typename Fun>
auto World::for_maybe_chunk_at(glm::vec3 const& pos, Fun&& fun) -> boost::optional<decltype (fun (nullptr))>
auto World::for_maybe_chunk_at(glm::vec3 const& pos, Fun&& fun) -> std::optional<decltype (fun (nullptr))>
{
MapTile* tile (mapIndex.getTile (pos));
if (tile && tile->finishedLoading())
@@ -47,7 +47,7 @@ auto World::for_maybe_chunk_at(glm::vec3 const& pos, Fun&& fun) -> boost::option
}
else
{
return boost::none;
return std::nullopt;
}
}

View File

@@ -524,7 +524,7 @@ namespace noggit
case PASTE_ON_SELECTION:
if (last_entry)
{
glm::vec3 last_entry_pos = boost::get<selected_object_type>(last_entry.get())->pos;
glm::vec3 last_entry_pos = boost::get<selected_object_type>(last_entry.value())->pos;
pos = last_entry_pos + model_pos;
}
@@ -685,7 +685,7 @@ namespace noggit
clone->scale = original->scale;
clone->dir = original->dir;
clone->pos = pivot ? original->pos - pivot.get() : glm::vec3();
clone->pos = pivot ? original->pos - pivot.value() : glm::vec3();
selected_model.push_back(clone);
_model_instance_created.push_back(clone);
@@ -695,7 +695,7 @@ namespace noggit
auto original = static_cast<WMOInstance*>(obj);
auto clone = new WMOInstance(original->wmo->file_key().filepath(), _map_view->getRenderContext());
clone->dir = original->dir;
clone->pos = pivot ? original->pos - pivot.get() : glm::vec3();
clone->pos = pivot ? original->pos - pivot.value() : glm::vec3();
selected_model.push_back(clone);
_model_instance_created.push_back(clone);

View File

@@ -239,7 +239,7 @@ namespace noggit
if (world->has_multiple_model_selected())
{
glm::vec3 const& p = world->multi_select_pivot().get();
glm::vec3 const& p = world->multi_select_pivot().value();
_position_x->setValue(p.x);
_position_y->setValue(p.y);
@@ -264,7 +264,7 @@ namespace noggit
if (entry)
{
selection_type selection = entry.get();
selection_type selection = entry.value();
auto obj = boost::get<selected_object_type>(selection);

View File

@@ -40,7 +40,7 @@ void GetObjectInstanceByUIDNode::compute()
return;
}
SceneObject* obj = boost::get<selected_object_type>(obj_optional.get());
SceneObject* obj = boost::get<selected_object_type>(obj_optional.value());
NOGGIT_CUR_ACTION->registerObjectTransformed(obj);

View File

@@ -35,7 +35,7 @@ void GetLastSelectedObjectInstanceNode::compute()
return;
}
SceneObject* obj = boost::get<selected_object_type>(obj_optional.get());
SceneObject* obj = boost::get<selected_object_type>(obj_optional.value());
_out_ports[0].out_value = std::make_shared<LogicData>(true);
_node->onDataUpdated(0);

View File

@@ -55,7 +55,7 @@ void SelectionInfoNode::compute()
return;
}
auto pivot_val = pivot.get();
auto pivot_val = pivot.value();
_out_ports[3].out_value = std::make_shared<Vector3DData>(glm::vec3(pivot_val.x, pivot_val.y, pivot_val.z));
_node->onDataUpdated(3);

View File

@@ -39,7 +39,7 @@ namespace noggit
if (existing_instance)
{
// instance already loaded
if (existing_instance.get()->isDuplicateOf(instance))
if (existing_instance.value()->isDuplicateOf(instance))
{
_instance_count_per_uid[uid]++;
return uid;
@@ -87,7 +87,7 @@ namespace noggit
if (existing_instance)
{
// instance already loaded
if (existing_instance.get()->isDuplicateOf(instance))
if (existing_instance.value()->isDuplicateOf(instance))
{
_instance_count_per_uid[uid]++;
@@ -187,8 +187,8 @@ namespace noggit
if (auto instance = get_instance(uid, false))
{
_world->updateTilesEntry(instance.get(), model_update::remove);
auto obj = boost::get<selected_object_type>(instance.get());
_world->updateTilesEntry(instance.value(), model_update::remove);
auto obj = boost::get<selected_object_type>(instance.value());
if (NOGGIT_CUR_ACTION)
{
@@ -230,12 +230,12 @@ namespace noggit
_wmos.clear();
}
boost::optional<ModelInstance*> world_model_instances_storage::get_model_instance(std::uint32_t uid)
std::optional<ModelInstance*> world_model_instances_storage::get_model_instance(std::uint32_t uid)
{
std::unique_lock<std::mutex> const lock (_mutex);
return unsafe_get_model_instance(uid);
}
boost::optional<ModelInstance*> world_model_instances_storage::unsafe_get_model_instance(std::uint32_t uid)
std::optional<ModelInstance*> world_model_instances_storage::unsafe_get_model_instance(std::uint32_t uid)
{
auto it = _m2s.find(uid);
@@ -245,16 +245,16 @@ namespace noggit
}
else
{
return boost::none;
return std::nullopt;
}
}
boost::optional<WMOInstance*> world_model_instances_storage::get_wmo_instance(std::uint32_t uid)
std::optional<WMOInstance*> world_model_instances_storage::get_wmo_instance(std::uint32_t uid)
{
std::unique_lock<std::mutex> const lock (_mutex);
return unsafe_get_wmo_instance(uid);
}
boost::optional<WMOInstance*> world_model_instances_storage::unsafe_get_wmo_instance(std::uint32_t uid)
std::optional<WMOInstance*> world_model_instances_storage::unsafe_get_wmo_instance(std::uint32_t uid)
{
auto it = _wmos.find(uid);
@@ -264,11 +264,11 @@ namespace noggit
}
else
{
return boost::none;
return std::nullopt;
}
}
boost::optional<selection_type> world_model_instances_storage::get_instance(std::uint32_t uid, bool lock)
std::optional<selection_type> world_model_instances_storage::get_instance(std::uint32_t uid, bool lock)
{
if (lock)
{
@@ -290,7 +290,7 @@ namespace noggit
}
else
{
return boost::none;
return std::nullopt;
}
}
}
@@ -312,7 +312,7 @@ namespace noggit
}
else
{
return boost::none;
return std::nullopt;
}
}
}

View File

@@ -1,7 +1,6 @@
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
#pragma once
#pragma once]
#include <noggit/ModelInstance.h>
#include <noggit/Selection.h>
#include <noggit/tile_index.hpp>
@@ -37,9 +36,9 @@ namespace noggit
// perform uid duplicate check, return the uid of the stored instance
std::uint32_t add_wmo_instance(WMOInstance instance, bool from_reloading);
boost::optional<ModelInstance*> get_model_instance(std::uint32_t uid);
boost::optional<WMOInstance*> get_wmo_instance(std::uint32_t uid);
boost::optional<selection_type> get_instance(std::uint32_t uid, bool lock=true);
std::optional<ModelInstance*> get_model_instance(std::uint32_t uid);
std::optional<WMOInstance*> get_wmo_instance(std::uint32_t uid);
std::optional<selection_type> get_instance(std::uint32_t uid, bool lock=true);
void delete_instances_from_tile(tile_index const& tile);
void delete_instances(std::vector<selection_type> const& instances);
@@ -63,8 +62,8 @@ namespace noggit
std::uint32_t unsafe_add_model_instance_no_world_upd(ModelInstance instance);
std::uint32_t unsafe_add_wmo_instance_no_world_upd(WMOInstance instance);
boost::optional<ModelInstance*> unsafe_get_model_instance(std::uint32_t uid);
boost::optional<WMOInstance*> unsafe_get_wmo_instance(std::uint32_t uid);
std::optional<ModelInstance*> unsafe_get_model_instance(std::uint32_t uid);
std::optional<WMOInstance*> unsafe_get_wmo_instance(std::uint32_t uid);
public:
template<typename Fun>