summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt7
-rw-r--r--editor/editor.cpp1
-rw-r--r--editor/imgui-editors.cpp2
-rw-r--r--editor/inspect-draw.cpp2
-rw-r--r--editor/scenery-json.cpp1
-rw-r--r--editor/tile-editor.cpp1
-rw-r--r--loader/impl.hpp4
-rw-r--r--loader/json.cpp22
-rw-r--r--loader/loader.hpp7
-rw-r--r--loader/wall-atlas.cpp1
-rw-r--r--serialize/wall-atlas.cpp1
-rw-r--r--shaders/lightmap.cpp4
-rw-r--r--shaders/lightmap.hpp2
-rw-r--r--shaders/lightmap.vert1
-rw-r--r--src/chunk-render.cpp18
-rw-r--r--src/chunk.cpp5
-rw-r--r--src/chunk.hpp7
-rw-r--r--src/object.cpp3
-rw-r--r--src/tile.cpp12
-rw-r--r--test/scenery.cpp2
20 files changed, 49 insertions, 54 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index db17798f..c427b13b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,6 +4,10 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
project(floormat C CXX)
+set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
+set(CMAKE_POLICY_DEFAULT_CMP0068 NEW)
+#set(CMAKE_POLICY_DEFAULT_CMP0117 NEW)
+
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_DEFAULT 23)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
@@ -39,9 +43,6 @@ if(NOT GENERATOR_IS_MULTI_CONFIG)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "DEBUG;RELEASE;RELWITHDEBINFO")
endif()
-set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
-set(CMAKE_POLICY_DEFAULT_CMP0068 NEW)
-
if(CMAKE_INSTALL_PREFIX STREQUAL "" OR CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "" FORCE)
endif()
diff --git a/editor/editor.cpp b/editor/editor.cpp
index a3b69fb1..9f2761e2 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -100,7 +100,6 @@ Optional<global_coords> editor::mouse_drag_pos()
void editor::on_click_(world& world, global_coords pos, button b)
{
- // todo make template
if (auto* mode = current_ground_editor(); mode != nullptr)
{
if (auto opt = mode->get_selected(); opt || b == button::remove)
diff --git a/editor/imgui-editors.cpp b/editor/imgui-editors.cpp
index f4b546f1..4ffb74ba 100644
--- a/editor/imgui-editors.cpp
+++ b/editor/imgui-editors.cpp
@@ -230,7 +230,7 @@ template void impl_draw_editor_scenery_pane(wall_editor&, Vector2);
void app::draw_editor_pane(float main_menu_height)
{
auto* ed = _editor.current_ground_editor();
- auto* wa = _editor.current_wall_editor(); // todo
+ auto* wa = _editor.current_wall_editor();
auto* sc = _editor.current_scenery_editor();
auto* vo = _editor.current_vobj_editor();
diff --git a/editor/inspect-draw.cpp b/editor/inspect-draw.cpp
index f6d36e61..48f49ca1 100644
--- a/editor/inspect-draw.cpp
+++ b/editor/inspect-draw.cpp
@@ -16,7 +16,7 @@ void app::draw_inspector()
{
auto b = push_id("inspector");
- constexpr auto max_inspectors = 4; // todo change later to 32
+ constexpr auto max_inspectors = 10;
if (auto size = inspectors.size(); size > max_inspectors)
{
auto end = inspectors.begin() + (ptrdiff_t)size - max_inspectors;
diff --git a/editor/scenery-json.cpp b/editor/scenery-json.cpp
index c5d7d043..e8b4dfec 100644
--- a/editor/scenery-json.cpp
+++ b/editor/scenery-json.cpp
@@ -2,6 +2,7 @@
#include "serialize/scenery.hpp"
#include "loader/loader.hpp"
#include "loader/scenery.hpp"
+#include <Corrade/Containers/ArrayView.h>
namespace floormat {
diff --git a/editor/tile-editor.cpp b/editor/tile-editor.cpp
index 0bccd6d9..1b766208 100644
--- a/editor/tile-editor.cpp
+++ b/editor/tile-editor.cpp
@@ -153,7 +153,6 @@ auto tile_editor::check_snap(int mods) const -> editor_snap_mode
{
const bool ctrl = mods & kmod_ctrl, shift = mods & kmod_shift;
- // todo show on cursor while held
if (!(ctrl | shift))
return editor_snap_mode::none;
diff --git a/loader/impl.hpp b/loader/impl.hpp
index 37a00304..d88174ba 100644
--- a/loader/impl.hpp
+++ b/loader/impl.hpp
@@ -60,7 +60,9 @@ struct loader_impl final : loader_
// >-----> tile >----->
tsl::robin_map<StringView, std::shared_ptr<class tile_atlas>> tile_atlas_map;
+ std::vector<std::shared_ptr<class tile_atlas>> tile_atlas_array;
+ ArrayView<const std::shared_ptr<class tile_atlas>> tile_atlases(StringView filename) noexcept(false) override;
std::shared_ptr<class tile_atlas> tile_atlas(StringView filename, Vector2ub size, pass_mode pass) noexcept(false) override;
std::shared_ptr<class tile_atlas> tile_atlas(StringView filename) noexcept(false) override;
@@ -77,7 +79,7 @@ struct loader_impl final : loader_
std::vector<serialized_scenery> sceneries_array;
tsl::robin_map<StringView, const serialized_scenery*> sceneries_map;
- const std::vector<serialized_scenery>& sceneries() override;
+ ArrayView<const serialized_scenery> sceneries() override;
const scenery_proto& scenery(StringView name) noexcept(false) override;
void get_scenery_list();
diff --git a/loader/json.cpp b/loader/json.cpp
index e9da0339..7cf24015 100644
--- a/loader/json.cpp
+++ b/loader/json.cpp
@@ -7,6 +7,7 @@
#include "serialize/tile-atlas.hpp"
#include "serialize/scenery.hpp"
#include "loader/scenery.hpp"
+#include <Corrade/Containers/ArrayViewStl.h>
#include <Corrade/Containers/StringStlView.h>
#include <Corrade/Utility/Path.h>
@@ -32,10 +33,11 @@ void loader_impl::get_scenery_list()
fm_assert(!sceneries_map.empty());
}
-const std::vector<serialized_scenery>& loader_impl::sceneries()
+ArrayView<const serialized_scenery> loader_impl::sceneries()
{
- if (sceneries_array.empty())
+ if (sceneries_array.empty()) [[likely]]
get_scenery_list();
+ fm_assert(!sceneries_array.empty());
return sceneries_array;
}
@@ -44,21 +46,21 @@ const scenery_proto& loader_impl::scenery(StringView name) noexcept(false)
fm_soft_assert(check_atlas_name(name));
if (sceneries_array.empty())
get_scenery_list();
+ fm_assert(!sceneries_array.empty());
auto it = sceneries_map.find(name);
if (it == sceneries_map.end())
fm_throw("no such scenery: '{}'"_cf, name);
return it->second->proto;
}
-} // namespace floormat::loader_detail
-
-namespace floormat {
-
-std::vector<std::shared_ptr<class tile_atlas>> loader_::tile_atlases(StringView filename)
+ArrayView<const std::shared_ptr<class tile_atlas>> loader_impl::tile_atlases(StringView filename)
{
- auto vec = json_helper::from_json<std::vector<std::shared_ptr<class tile_atlas>>>(
+ if (!tile_atlas_array.empty()) [[likely]]
+ return tile_atlas_array;
+ tile_atlas_array = json_helper::from_json<std::vector<std::shared_ptr<class tile_atlas>>>(
Path::join(loader_::IMAGE_PATH, filename));
- return vec;
+ fm_assert(!tile_atlas_array.empty());
+ return tile_atlas_array;
}
-} // namespace floormat
+} // namespace floormat::loader_detail
diff --git a/loader/loader.hpp b/loader/loader.hpp
index 9b2d1c3c..f93e6967 100644
--- a/loader/loader.hpp
+++ b/loader/loader.hpp
@@ -2,7 +2,6 @@
#include "src/pass-mode.hpp"
#include <stdio.h>
#include <memory>
-#include <vector>
#include <Corrade/Containers/StringView.h>
namespace Magnum { using Vector2ub = Math::Vector2<unsigned char>; }
@@ -25,7 +24,6 @@ struct loader_
{
virtual StringView shader(StringView filename) noexcept = 0;
virtual Trade::ImageData2D texture(StringView prefix, StringView filename, bool fail_ok = true) noexcept(false) = 0;
- // todo remove Optional when wall_atlas is fully implemented -sh 20231122
virtual std::shared_ptr<class tile_atlas> tile_atlas(StringView filename, Vector2ub size, pass_mode pass) noexcept(false) = 0;
virtual std::shared_ptr<class tile_atlas> tile_atlas(StringView filename) noexcept(false) = 0;
virtual ArrayView<const String> anim_atlas_list() = 0;
@@ -34,9 +32,8 @@ struct loader_
virtual ArrayView<const wall_info> wall_atlas_list() = 0;
static void destroy();
static loader_& default_loader() noexcept;
- // todo move to ArrayView later, make non-static, and remove pass_mode
- static std::vector<std::shared_ptr<class tile_atlas>> tile_atlases(StringView filename);
- virtual const std::vector<serialized_scenery>& sceneries() = 0;
+ virtual ArrayView<const std::shared_ptr<class tile_atlas>> tile_atlases(StringView filename) noexcept(false) = 0;
+ virtual ArrayView<const serialized_scenery> sceneries() = 0;
virtual const scenery_proto& scenery(StringView name) noexcept(false) = 0;
virtual StringView startup_directory() noexcept = 0;
static StringView strip_prefix(StringView name);
diff --git a/loader/wall-atlas.cpp b/loader/wall-atlas.cpp
index 242702e3..66dc3ba5 100644
--- a/loader/wall-atlas.cpp
+++ b/loader/wall-atlas.cpp
@@ -104,7 +104,6 @@ std::shared_ptr<class wall_atlas> loader_impl::wall_atlas(StringView name, bool
missing:
{
- // todo allocate wall_info instead
missing_wall_atlases.push_back(String { AllocatedInit, name });
auto string_view = StringView{missing_wall_atlases.back()};
wall_atlas_map[string_view] = (wall_info*)-1;
diff --git a/serialize/wall-atlas.cpp b/serialize/wall-atlas.cpp
index ca37a13a..b47b3d79 100644
--- a/serialize/wall-atlas.cpp
+++ b/serialize/wall-atlas.cpp
@@ -188,7 +188,6 @@ Group read_group_metadata(const json& jgroup)
val.index = (uint32_t)index;
val.count = (uint32_t)count;
}
- // todo check index within range
}
val.default_tint = true;
diff --git a/shaders/lightmap.cpp b/shaders/lightmap.cpp
index f925cc98..1be58131 100644
--- a/shaders/lightmap.cpp
+++ b/shaders/lightmap.cpp
@@ -377,7 +377,7 @@ void lightmap_shader::add_geometry(Vector2 neighbor_offset, chunk& c)
if (atlas->info().passability == pass_mode::blocked)
{
auto start = tile_start(i);
- auto min = start - Vector2(0, shadow_wall_depth),
+ auto min = start - Vector2(0, shadow_wall_depth), // todo wall depth
max = start + Vector2(TILE_SIZE2[0], 0);
constexpr auto fuzz = Vector2(fuzz_pixels, 0), fuzz2 = fuzz*2;
add_rect(neighbor_offset, {min-fuzz, max+fuzz2});
@@ -386,7 +386,7 @@ void lightmap_shader::add_geometry(Vector2 neighbor_offset, chunk& c)
if (atlas->info().passability == pass_mode::blocked)
{
auto start = tile_start(i);
- auto min = start - Vector2(shadow_wall_depth, 0),
+ auto min = start - Vector2(shadow_wall_depth, 0), // todo wall depth
max = start + Vector2(0, TILE_SIZE[1]);
constexpr auto fuzz = Vector2(0, fuzz_pixels), fuzz2 = fuzz*2;
add_rect(neighbor_offset, {min-fuzz, max+fuzz2});
diff --git a/shaders/lightmap.hpp b/shaders/lightmap.hpp
index d4e09815..b8bbd0c7 100644
--- a/shaders/lightmap.hpp
+++ b/shaders/lightmap.hpp
@@ -87,7 +87,7 @@ private:
size_t count = 0, capacity = 0;
Framebuffer framebuffer;
GL::Mesh occlusion_mesh{NoCreate};
- static constexpr auto starting_capacity = 1; // todo
+ static constexpr auto starting_capacity = 32;
GL::Buffer light_vertex_buf{NoCreate};
GL::Mesh light_mesh{NoCreate};
diff --git a/shaders/lightmap.vert b/shaders/lightmap.vert
index 1a8a39f1..c292f5c8 100644
--- a/shaders/lightmap.vert
+++ b/shaders/lightmap.vert
@@ -16,7 +16,6 @@ uniform Lightmap {
layout (location = 0) in vec3 position;
void main() {
- // todo add interface blocks
vec2 pos = position.xy;
if (mode == 0)
{
diff --git a/src/chunk-render.cpp b/src/chunk-render.cpp
index 586018b1..d019a948 100644
--- a/src/chunk-render.cpp
+++ b/src/chunk-render.cpp
@@ -36,17 +36,17 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
return { ground_mesh, {}, 0 };
if (!_ground_modified)
- return { ground_mesh, _ground->ground_indexes, size_t(ground_mesh.count()/6) };
+ return { ground_mesh, _ground->indexes, size_t(ground_mesh.count()/6) };
_ground_modified = false;
size_t count = 0;
for (auto i = 0uz; i < TILE_COUNT; i++)
- if (_ground->_ground_atlases[i])
- _ground->ground_indexes[count++] = uint8_t(i);
+ if (_ground->atlases[i])
+ _ground->indexes[count++] = uint8_t(i);
- std::sort(_ground->ground_indexes.begin(), _ground->ground_indexes.begin() + count,
+ std::sort(_ground->indexes.begin(), _ground->indexes.begin() + count,
[this](uint8_t a, uint8_t b) {
- return _ground->_ground_atlases[a] < _ground->_ground_atlases[b];
+ return _ground->atlases[a] < _ground->atlases[b];
});
float hack_offset = _coord.z <= 0 ? -16 : 0; // XXX hack
@@ -54,11 +54,11 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
std::array<std::array<vertex, 4>, TILE_COUNT> vertexes;
for (auto k = 0uz; k < count; k++)
{
- const uint8_t i = _ground->ground_indexes[k];
- const auto& atlas = _ground->_ground_atlases[i];
+ const uint8_t i = _ground->indexes[k];
+ const auto& atlas = _ground->atlases[i];
const local_coords pos{i};
const auto quad = floor_quad(Vector3(pos) * TILE_SIZE, TILE_SIZE2);
- const auto texcoords = atlas->texcoords_for_id(_ground->_ground_variants[i]);
+ const auto texcoords = atlas->texcoords_for_id(_ground->variants[i]);
const float depth = tile_shader::depth_value(pos, tile_shader::ground_depth_offset + hack_offset);
auto& v = vertexes[k];
for (auto j = 0uz; j < 4; j++)
@@ -74,7 +74,7 @@ auto chunk::ensure_ground_mesh() noexcept -> ground_mesh_tuple
.setIndexBuffer(GL::Buffer{vert_index_view}, 0, GL::MeshIndexType::UnsignedShort)
.setCount(int32_t(6 * count));
ground_mesh = Utility::move(mesh);
- return { ground_mesh, _ground->ground_indexes, count };
+ return { ground_mesh, _ground->indexes, count };
}
diff --git a/src/chunk.cpp b/src/chunk.cpp
index aabb69f8..a49669c5 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -28,7 +28,7 @@ bool chunk::empty(bool force) const noexcept
return false;
for (auto i = 0uz; i < TILE_COUNT; i++)
if (!_objects.empty() ||
- _ground && _ground->_ground_atlases[i] ||
+ _ground && _ground->atlases[i] ||
_walls && (_walls->atlases[i*2+0] || _walls->atlases[i*2+1]))
return _maybe_empty = false;
if (!_objects.empty())
@@ -36,7 +36,7 @@ bool chunk::empty(bool force) const noexcept
return true;
}
-tile_atlas* chunk::ground_atlas_at(size_t i) const noexcept { return _ground ? _ground->_ground_atlases[i].get() : nullptr; }
+tile_atlas* chunk::ground_atlas_at(size_t i) const noexcept { return _ground ? _ground->atlases[i].get() : nullptr; }
tile_ref chunk::operator[](size_t idx) noexcept { return { *this, uint8_t(idx) }; }
tile_proto chunk::operator[](size_t idx) const noexcept { return tile_proto(tile_ref { *const_cast<chunk*>(this), uint8_t(idx) }); }
@@ -86,7 +86,6 @@ void chunk::mark_ground_modified() noexcept
mark_passability_modified();
}
-// todo this can use _replace_bbox too
void chunk::mark_walls_modified() noexcept
{
if (!_walls_modified && !is_log_quiet())
diff --git a/src/chunk.hpp b/src/chunk.hpp
index f2434281..3005475c 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -129,10 +129,9 @@ struct chunk final
private:
struct ground_stuff
{
- // todo remove "_ground" prefix
- std::array<std::shared_ptr<tile_atlas>, TILE_COUNT> _ground_atlases;
- std::array<uint8_t, TILE_COUNT> ground_indexes = {};
- std::array<variant_t, TILE_COUNT> _ground_variants = {};
+ std::array<std::shared_ptr<tile_atlas>, TILE_COUNT> atlases;
+ std::array<uint8_t, TILE_COUNT> indexes = {};
+ std::array<variant_t, TILE_COUNT> variants = {};
};
struct wall_stuff
diff --git a/src/object.cpp b/src/object.cpp
index 71ce905c..9d5aec5a 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -21,7 +21,7 @@ constexpr auto object_id_lessp = [](const auto& a, const auto& b) { return a->id
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
#endif
-// todo try this instead: x = 31; int((x+64+32)/64), (x + 64 + 32)%64 - 1
+// todo rewrite using bitwise ops. try this instead: x = 31; int((x+64+32)/64), (x + 64 + 32)%64 - 1
template<int tile_size>
constexpr inline Pair<int, int8_t> normalize_coord(const int8_t cur, const int new_off)
{
@@ -141,7 +141,6 @@ void object::rotate(size_t, rotation new_r)
const_cast<rotation&>(r) = new_r;
}
-// todo rewrite using bitwise ops
point object::normalize_coords(global_coords coord, Vector2b cur, Vector2i new_off)
{
auto [cx, ox] = normalize_coord<iTILE_SIZE2.x()>(cur.x(), new_off.x());
diff --git a/src/tile.cpp b/src/tile.cpp
index 4f49f214..ce21d506 100644
--- a/src/tile.cpp
+++ b/src/tile.cpp
@@ -18,22 +18,22 @@ wall_image_proto tile_proto::wall_west() const noexcept { return { wall_west_at
tile_ref::tile_ref(struct chunk& c, uint8_t i) noexcept : _chunk{&c}, i{i} {}
-std::shared_ptr<tile_atlas> tile_ref::ground_atlas() noexcept { return _chunk->_ground ? _chunk->_ground->_ground_atlases[i] : nullptr; }
+std::shared_ptr<tile_atlas> tile_ref::ground_atlas() noexcept { return _chunk->_ground ? _chunk->_ground->atlases[i] : nullptr; }
std::shared_ptr<wall_atlas> tile_ref::wall_north_atlas() noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+0] : nullptr; }
std::shared_ptr<wall_atlas> tile_ref::wall_west_atlas() noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+1] : nullptr; }
-std::shared_ptr<const tile_atlas> tile_ref::ground_atlas() const noexcept { return _chunk->_ground ? _chunk->_ground->_ground_atlases[i] : nullptr; }
+std::shared_ptr<const tile_atlas> tile_ref::ground_atlas() const noexcept { return _chunk->_ground ? _chunk->_ground->atlases[i] : nullptr; }
std::shared_ptr<const wall_atlas> tile_ref::wall_north_atlas() const noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+0] : nullptr; }
std::shared_ptr<const wall_atlas> tile_ref::wall_west_atlas() const noexcept { return _chunk->_walls ? _chunk->_walls->atlases[i*2+1] : nullptr; }
-tile_image_ref tile_ref::ground() noexcept { _chunk->ensure_alloc_ground(); return {_chunk->_ground->_ground_atlases[i], _chunk->_ground->_ground_variants[i] }; }
+tile_image_ref tile_ref::ground() noexcept { _chunk->ensure_alloc_ground(); return {_chunk->_ground->atlases[i], _chunk->_ground->variants[i] }; }
wall_image_ref tile_ref::wall_north() noexcept { _chunk->ensure_alloc_walls(); return {_chunk->_walls->atlases[i*2+0], _chunk->_walls->variants[i*2+0] }; }
wall_image_ref tile_ref::wall_west() noexcept { _chunk->ensure_alloc_walls(); return {_chunk->_walls->atlases[i*2+1], _chunk->_walls->variants[i*2+1] }; }
tile_image_proto tile_ref::ground() const noexcept
{
_chunk->ensure_alloc_ground();
- return { _chunk->_ground->_ground_atlases[i], _chunk->_ground->_ground_variants[i] };
+ return { _chunk->_ground->atlases[i], _chunk->_ground->variants[i] };
}
wall_image_proto tile_ref::wall_north() const noexcept
@@ -57,8 +57,8 @@ tile_ref::operator tile_proto() const noexcept
_chunk->ensure_alloc_ground();
_chunk->ensure_alloc_walls();
return {
- _chunk->_ground->_ground_atlases[i], _chunk->_walls->atlases[i*2+0], _chunk->_walls->atlases[i*2+1],
- _chunk->_ground->_ground_variants[i], _chunk->_walls->variants[i*2+0], _chunk->_walls->variants[i*2+1],
+ _chunk->_ground->atlases[i], _chunk->_walls->atlases[i*2+0], _chunk->_walls->atlases[i*2+1],
+ _chunk->_ground->variants[i], _chunk->_walls->variants[i*2+0], _chunk->_walls->variants[i*2+1],
};
}
diff --git a/test/scenery.cpp b/test/scenery.cpp
index 40669ec9..5d8606b5 100644
--- a/test/scenery.cpp
+++ b/test/scenery.cpp
@@ -8,7 +8,7 @@ namespace {
void test_loading()
{
- fm_assert(!loader.sceneries().empty());
+ fm_assert(!loader.sceneries().isEmpty());
for (const auto& [name, descr, proto] : loader.sceneries())
fm_assert(proto.sc_type != scenery_type::none);