diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | compat/assert.hpp | 53 | ||||
-rw-r--r-- | compat/defs.hpp | 2 | ||||
-rw-r--r-- | floor-mesh.cpp | 16 | ||||
-rw-r--r-- | floor-mesh.hpp | 7 | ||||
-rw-r--r-- | main.cpp | 2 | ||||
-rw-r--r-- | wall-mesh.cpp | 12 | ||||
-rw-r--r-- | wall-mesh.hpp | 7 |
8 files changed, 40 insertions, 61 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d4a5056..41ac4b9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,8 @@ set(CMAKE_C_LINKER_PREFERENCE_PROPAGATES OFF) set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES ON) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) +set(CMAKE_INSTALL_MESSAGE LAZY) + if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR CMAKE_INSTALL_PREFIX STREQUAL "") set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "" FORCE) endif() diff --git a/compat/assert.hpp b/compat/assert.hpp index 23dfdf42..89c89c64 100644 --- a/compat/assert.hpp +++ b/compat/assert.hpp @@ -1,54 +1,33 @@ #pragma once -#include "defs.hpp" +#include <cstdlib> #include <cstdio> -#include <limits> #include <type_traits> -namespace Magnum::Examples { - -struct exception { - const char* file = nullptr; - const char* function = nullptr; - int line = -1; -}; +namespace Magnum::Examples::detail { -struct assertion_failure final : exception +template<typename...Xs> +constexpr inline void abort(const char* fmt, Xs... xs) { - char msg[128 - sizeof(int) - sizeof(char*)]; -}; - -struct out_of_range final : exception { - ssize_t value = 0; - ssize_t min = std::numeric_limits<ssize_t>::min(); - ssize_t max = std::numeric_limits<ssize_t>::max(); -}; + if (std::is_constant_evaluated()) { + std::fprintf(stderr, fmt, xs...); + std::putc('\n', stderr); + std::fflush(stderr); + std::abort(); + } else + throw "aborting"; +} -#define OUT_OF_RANGE(value, min, max) \ - ::Magnum::Examples::out_of_range{ \ - {__FILE__, FUNCTION_NAME, __LINE__}, \ - ::Magnum::Examples::ssize_t((value)), \ - ::Magnum::Examples::ssize_t((min)), \ - ::Magnum::Examples::ssize_t((max)) \ - } +} // namespace Magnum::Examples::detail -#define ABORT_WITH(exc_type, ...) ([&]() { \ - if (std::is_constant_evaluated()) { \ - exc_type _e; \ - _e.line = __LINE__; \ - _e.file = __FILE__; \ - _e.function = FUNCTION_NAME; \ - std::snprintf(_e.msg, sizeof(_e.msg), __VA_ARGS__); \ - throw _e;/*NOLINT(misc-throw-by-value-catch-by-reference)*/ \ - } else \ - throw "aborting"; \ -}()) +namespace Magnum::Examples { #define ABORT(...) \ do { \ if (std::is_constant_evaluated()) \ throw "aborting"; \ else \ - ABORT_WITH(::Magnum::Examples::assertion_failure, __VA_ARGS__); \ + ::Magnum::Examples::detail:: \ + abort("aborting at %s:%d", __FILE__, __LINE__); \ } while (false) #define ASSERT(expr) \ diff --git a/compat/defs.hpp b/compat/defs.hpp index cc238022..bde7d7e3 100644 --- a/compat/defs.hpp +++ b/compat/defs.hpp @@ -5,7 +5,7 @@ namespace Magnum::Examples { using size_t = std::size_t; -using ssize_t = std::make_signed_t<std::size_t>; +using ssize_t = std::common_type_t<std::ptrdiff_t, std::make_signed_t<std::size_t>>; } // namespace Magnum::Examples diff --git a/floor-mesh.cpp b/floor-mesh.cpp index e1f3c744..48dfe5f2 100644 --- a/floor-mesh.cpp +++ b/floor-mesh.cpp @@ -7,9 +7,11 @@ namespace Magnum::Examples { +constexpr auto quad_index_count = 6; + floor_mesh::floor_mesh() { - _mesh.setCount((int)(_index_data.size() * _index_data[0].size())) + _mesh.setCount((int)(quad_index_count * TILE_COUNT)) .addVertexBuffer(_positions_buffer, 0, tile_shader::Position{}) .addVertexBuffer(_vertex_buffer, 0, tile_shader::TextureCoordinates{}) .setIndexBuffer(_index_buffer, 0, GL::MeshIndexType::UnsignedShort); @@ -26,7 +28,6 @@ void floor_mesh::set_tile(quad_data& data, tile& x) void floor_mesh::draw(tile_shader& shader, chunk& c) { - constexpr auto quad_index_count = _index_data[0].size(); std::array<quad_data, TILE_COUNT> data; c.foreach_tile([&](tile& x, std::size_t idx, local_coords) { set_tile(data[idx], x); @@ -46,15 +47,16 @@ void floor_mesh::draw(tile_shader& shader, chunk& c) }); } -static auto make_index_array() +std::array<std::array<UnsignedShort, 6>, TILE_COUNT> floor_mesh::make_index_array() { - std::array<std::array<UnsignedShort, 6>, TILE_COUNT> array; // NOLINT(cppcoreguidelines-pro-type-member-init) + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) + std::array<std::array<UnsignedShort, quad_index_count>, TILE_COUNT> array; for (std::size_t i = 0; i < std::size(array); i++) array[i] = tile_atlas::indices(i); return array; } -static auto make_floor_positions_array() +std::array<std::array<Vector3, 4>, TILE_COUNT> floor_mesh::make_position_array() { std::array<std::array<Vector3, 4>, TILE_COUNT> array; constexpr float X = TILE_SIZE[0], Y = TILE_SIZE[1]; @@ -67,7 +69,7 @@ static auto make_floor_positions_array() return array; } -const decltype(floor_mesh::_index_data) floor_mesh::_index_data = make_index_array(); -const decltype(floor_mesh::_position_data) floor_mesh::_position_data = make_floor_positions_array(); +//const decltype(floor_mesh::_index_data) floor_mesh::_index_data = make_index_array(); +//const decltype(floor_mesh::_position_data) floor_mesh::_position_data = make_floor_positions_array(); } // namespace Magnum::Examples diff --git a/floor-mesh.hpp b/floor-mesh.hpp index e263a6ed..41351fd9 100644 --- a/floor-mesh.hpp +++ b/floor-mesh.hpp @@ -24,13 +24,12 @@ private: struct vertex_data final { Vector2 texcoords; }; using quad_data = std::array<vertex_data, 4>; - static const std::array<std::array<UnsignedShort, 6>, TILE_COUNT> _index_data; - static const std::array<std::array<Vector3, 4>, TILE_COUNT> _position_data; + static std::array<std::array<UnsignedShort, 6>, TILE_COUNT> make_index_array(); + static std::array<std::array<Vector3, 4>, TILE_COUNT> make_position_array(); GL::Mesh _mesh; GL::Buffer _vertex_buffer{std::array<quad_data, TILE_COUNT>{}, Magnum::GL::BufferUsage::DynamicDraw}, - _index_buffer{_index_data}, - _positions_buffer{_position_data}; + _index_buffer{make_index_array()}, _positions_buffer{make_position_array()}; static void set_tile(quad_data& data, tile& x); }; @@ -105,7 +105,7 @@ app::app(const Arguments& arguments): .setTitle("Test") .setSize({1024, 768}, dpi_policy::Physical), GLConfiguration{} - //.setSampleCount(4) + //.setSampleCount(16) } { reset_camera_offset(); diff --git a/wall-mesh.cpp b/wall-mesh.cpp index c55de472..a27d34af 100644 --- a/wall-mesh.cpp +++ b/wall-mesh.cpp @@ -6,9 +6,11 @@ namespace Magnum::Examples { +constexpr auto quad_index_count = 6; + wall_mesh::wall_mesh() { - _mesh.setCount((int)(_index_data.size() * _index_data[0].size())) + _mesh.setCount((int)(quad_index_count * COUNT)) .addVertexBuffer(_vertex_buffer, 0, tile_shader::TextureCoordinates{}, tile_shader::Position{}) .setIndexBuffer(_index_buffer, 0, GL::MeshIndexType::UnsignedShort); CORRADE_INTERNAL_ASSERT(_mesh.isIndexed()); @@ -49,7 +51,6 @@ void wall_mesh::draw(tile_shader& shader, chunk& c) maybe_add_tile(data, textures, pos, x, pt); }); _vertex_buffer.setSubData(0, Containers::arrayView(data.data(), pos)); - //_vertex_buffer.setData(data, Magnum::GL::BufferUsage::DynamicDraw); } const GL::Texture2D* last_texture = nullptr; @@ -67,15 +68,14 @@ void wall_mesh::draw(tile_shader& shader, chunk& c) } } -decltype(wall_mesh::_index_data) wall_mesh::make_index_array() +std::array<std::array<UnsignedShort, 6>, wall_mesh::COUNT> wall_mesh::make_index_array() { - std::array<std::array<UnsignedShort, 6>, COUNT> array = {}; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) + std::array<std::array<UnsignedShort, 6>, COUNT> array; for (std::size_t i = 0; i < std::size(array); i++) array[i] = tile_atlas::indices(i); return array; } -const decltype(wall_mesh::_index_data) wall_mesh::_index_data = wall_mesh::make_index_array(); - } // namespace Magnum::Examples diff --git a/wall-mesh.hpp b/wall-mesh.hpp index ef73e02b..9356f384 100644 --- a/wall-mesh.hpp +++ b/wall-mesh.hpp @@ -20,7 +20,6 @@ struct wall_mesh final private: static constexpr auto COUNT = TILE_MAX_DIM*2 * TILE_MAX_DIM*2; - static constexpr auto quad_index_count = 6; using texcoords_array = std::array<Vector2, 4>; using position_array = std::array<Vector3, 4>; @@ -41,10 +40,8 @@ private: GL::Mesh _mesh; GL::Buffer _vertex_buffer{vertex_array{}, Magnum::GL::BufferUsage::DynamicDraw}, - _index_buffer{_index_data, Magnum::GL::BufferUsage::StaticDraw}; - - static const std::array<std::array<UnsignedShort, 6>, COUNT> _index_data; - static decltype(_index_data) make_index_array(); + _index_buffer{make_index_array(), Magnum::GL::BufferUsage::StaticDraw}; + static std::array<std::array<UnsignedShort, 6>, COUNT> make_index_array(); }; } // namespace Magnum::Examples |