From: Daniel Karbach Date: Fri, 29 May 2015 13:16:46 +0000 (+0200) Subject: noexcept all the things X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=76b3ec0f6aa0dacf6d4944a2787991f3585299e8;p=blank.git noexcept all the things --- diff --git a/src/app.cpp b/src/app.cpp index 6a87042..21f5bcf 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -30,7 +30,7 @@ Application::Application(const Config &config) Entity &Application::MakeTestEntity(World &world) { Entity &e = world.AddEntity(); e.Position({ 0.0f, 0.0f, 0.0f }); - e.SetShape(world.BlockTypes()[1]->shape, { 1.0f, 1.0f, 0.0f }); + e.SetShape(world.BlockTypes()[1].shape, { 1.0f, 1.0f, 0.0f }); e.AngularVelocity(glm::quat(glm::vec3{ 0.00001f, 0.000006f, 0.000013f })); return e; } diff --git a/src/block.cpp b/src/block.cpp index b63b82f..ab090da 100644 --- a/src/block.cpp +++ b/src/block.cpp @@ -10,7 +10,7 @@ namespace blank { const NullShape BlockType::DEFAULT_SHAPE; -BlockType::BlockType(bool v, const glm::vec3 &col, const Shape *s) +BlockType::BlockType(bool v, const glm::vec3 &col, const Shape *s) noexcept : shape(s) , color(col) , outline_color(-1, -1, -1) @@ -26,7 +26,7 @@ void BlockType::FillModel( Model::Buffer &buf, const glm::mat4 &transform, Model::Index idx_offset -) const { +) const noexcept { shape->Vertices(buf.vertices, buf.normals, buf.indices, transform, idx_offset); buf.colors.insert(buf.colors.end(), shape->VertexCount(), color); } @@ -35,7 +35,7 @@ void BlockType::FillBlockModel( BlockModel::Buffer &buf, const glm::mat4 &transform, BlockModel::Index idx_offset -) const { +) const noexcept { shape->Vertices(buf.vertices, buf.indices, transform, idx_offset); buf.colors.insert(buf.colors.end(), shape->VertexCount(), color); } @@ -44,7 +44,7 @@ void BlockType::FillOutlineModel( OutlineModel &model, const glm::vec3 &pos_offset, OutlineModel::Index idx_offset -) const { +) const noexcept { shape->Outline(model.vertices, model.indices, pos_offset, idx_offset); model.colors.insert(model.colors.end(), shape->OutlineCount(), outline_color); } diff --git a/src/block.hpp b/src/block.hpp index ab34a30..2c26ed7 100644 --- a/src/block.hpp +++ b/src/block.hpp @@ -39,27 +39,27 @@ struct Block { Type type; unsigned char orient; - constexpr explicit Block(Type type = 0, Face face = FACE_UP, Turn turn = TURN_NONE) + constexpr explicit Block(Type type = 0, Face face = FACE_UP, Turn turn = TURN_NONE) noexcept : type(type), orient(face * TURN_COUNT + turn) { } - const glm::mat4 &Transform() const { return orient2transform[orient]; } + const glm::mat4 &Transform() const noexcept { return orient2transform[orient]; } - Face GetFace() const { return Face(orient / TURN_COUNT); } - void SetFace(Face face) { orient = face * TURN_COUNT + GetTurn(); } - Turn GetTurn() const { return Turn(orient % TURN_COUNT); } - void SetTurn(Turn turn) { orient = GetFace() * TURN_COUNT + turn; } + Face GetFace() const noexcept { return Face(orient / TURN_COUNT); } + void SetFace(Face face) noexcept { orient = face * TURN_COUNT + GetTurn(); } + Turn GetTurn() const noexcept { return Turn(orient % TURN_COUNT); } + void SetTurn(Turn turn) noexcept { orient = GetFace() * TURN_COUNT + turn; } - Face OrientedFace(Face f) const { return orient2face[orient][f]; } + Face OrientedFace(Face f) const noexcept { return orient2face[orient][f]; } - static Face Opposite(Face f) { + static Face Opposite(Face f) noexcept { return Face(f ^ 1); } - static glm::tvec3 FaceNormal(Face face) { + static glm::tvec3 FaceNormal(Face face) noexcept { return face2normal[face]; } - static Face NormalFace(const glm::vec3 &norm) { + static Face NormalFace(const glm::vec3 &norm) noexcept { const glm::vec3 anorm(abs(norm)); if (anorm.x > anorm.y) { if (anorm.x > anorm.z) { @@ -137,13 +137,13 @@ struct BlockType { struct Faces { bool face[Block::FACE_COUNT]; - Faces &operator =(const Faces &other) { + Faces &operator =(const Faces &other) noexcept { for (int i = 0; i < Block::FACE_COUNT; ++i) { face[i] = other.face[i]; } return *this; } - bool operator [](Block::Face f) const { + bool operator [](Block::Face f) const noexcept { return face[f]; } } fill; @@ -152,11 +152,11 @@ struct BlockType { bool v = false, const glm::vec3 &color = { 1, 1, 1 }, const Shape *shape = &DEFAULT_SHAPE - ); + ) noexcept; static const NullShape DEFAULT_SHAPE; - bool FaceFilled(const Block &block, Block::Face face) const { + bool FaceFilled(const Block &block, Block::Face face) const noexcept { return fill[block.OrientedFace(face)]; } @@ -164,17 +164,17 @@ struct BlockType { Model::Buffer &m, const glm::mat4 &transform = glm::mat4(1.0f), Model::Index idx_offset = 0 - ) const; + ) const noexcept; void FillBlockModel( BlockModel::Buffer &m, const glm::mat4 &transform = glm::mat4(1.0f), BlockModel::Index idx_offset = 0 - ) const; + ) const noexcept; void FillOutlineModel( OutlineModel &m, const glm::vec3 &pos_offset = { 0, 0, 0 }, OutlineModel::Index idx_offset = 0 - ) const; + ) const noexcept; }; @@ -187,10 +187,10 @@ public: public: Block::Type Add(const BlockType &); - size_t Size() const { return types.size(); } + size_t Size() const noexcept { return types.size(); } - BlockType *operator [](Block::Type id) { return &types[id]; } - const BlockType *Get(Block::Type id) const { return &types[id]; } + BlockType &operator [](Block::Type id) { return types[id]; } + const BlockType &Get(Block::Type id) const { return types[id]; } private: std::vector types; diff --git a/src/camera.cpp b/src/camera.cpp index 7bf15bf..f4e3171 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -8,7 +8,7 @@ namespace blank { -Camera::Camera() +Camera::Camera() noexcept : fov(PI_0p25) , aspect(1.0f) , near_clip(0.1f) @@ -18,37 +18,37 @@ Camera::Camera() } -void Camera::Viewport(int width, int height) { +void Camera::Viewport(int width, int height) noexcept { Viewport(0, 0, width, height); } -void Camera::Viewport(int x, int y, int width, int height) { +void Camera::Viewport(int x, int y, int width, int height) noexcept { glViewport(x, y, width, height); Aspect(width, height); } -void Camera::FOV(float f) { +void Camera::FOV(float f) noexcept { fov = f; UpdateProjection(); } -void Camera::Aspect(float r) { +void Camera::Aspect(float r) noexcept { aspect = r; UpdateProjection(); } -void Camera::Aspect(float w, float h) { +void Camera::Aspect(float w, float h) noexcept { Aspect(w / h); } -void Camera::Clip(float near, float far) { +void Camera::Clip(float near, float far) noexcept { near_clip = near; far_clip = far; UpdateProjection(); } -void Camera::UpdateProjection() { +void Camera::UpdateProjection() noexcept { projection = glm::perspective(fov, aspect, near_clip, far_clip); } diff --git a/src/camera.hpp b/src/camera.hpp index 1477a47..717da24 100644 --- a/src/camera.hpp +++ b/src/camera.hpp @@ -9,21 +9,21 @@ namespace blank { class Camera { public: - Camera(); + Camera() noexcept; - void Viewport(int width, int height); - void Viewport(int x, int y, int width, int height); + void Viewport(int width, int height) noexcept; + void Viewport(int x, int y, int width, int height) noexcept; /// FOV in radians - void FOV(float f); - void Aspect(float r); - void Aspect(float w, float h); - void Clip(float near, float far); + void FOV(float f) noexcept; + void Aspect(float r) noexcept; + void Aspect(float w, float h) noexcept; + void Clip(float near, float far) noexcept; - const glm::mat4 &Projection() { return projection; } + const glm::mat4 &Projection() noexcept { return projection; } private: - void UpdateProjection(); + void UpdateProjection() noexcept; private: float fov; diff --git a/src/chunk.cpp b/src/chunk.cpp index 23d5a13..c31926b 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -5,12 +5,11 @@ #include #include #include -#include namespace blank { -Chunk::Chunk(const BlockTypeRegistry &types) +Chunk::Chunk(const BlockTypeRegistry &types) noexcept : types(&types) , neighbor{0} , blocks{} @@ -21,7 +20,7 @@ Chunk::Chunk(const BlockTypeRegistry &types) } -Chunk::Chunk(Chunk &&other) +Chunk::Chunk(Chunk &&other) noexcept : types(other.types) , model(std::move(other.model)) , position(other.position) @@ -31,7 +30,7 @@ Chunk::Chunk(Chunk &&other) std::copy(other.light, other.light + sizeof(light), light); } -Chunk &Chunk::operator =(Chunk &&other) { +Chunk &Chunk::operator =(Chunk &&other) noexcept { types = other.types; std::copy(other.neighbor, other.neighbor + sizeof(neighbor), neighbor); std::copy(other.blocks, other.blocks + sizeof(blocks), blocks); @@ -53,14 +52,14 @@ struct SetNode { SetNode(Chunk *chunk, Chunk::Pos pos) : chunk(chunk), pos(pos) { } - int Get() const { return chunk->GetLight(pos); } - void Set(int level) { chunk->SetLight(pos, level); } + int Get() const noexcept { return chunk->GetLight(pos); } + void Set(int level) noexcept { chunk->SetLight(pos, level); } - bool HasNext(Block::Face face) { + bool HasNext(Block::Face face) noexcept { const BlockLookup next(chunk, pos, face); return next && !next.GetType().block_light; } - SetNode GetNext(Block::Face face) { + SetNode GetNext(Block::Face face) noexcept { const BlockLookup next(chunk, pos, face); return SetNode(&next.GetChunk(), next.GetBlockPos()); } @@ -79,18 +78,18 @@ struct UnsetNode : SetNode(set), level(Get()) { } - bool HasNext(Block::Face face) { + bool HasNext(Block::Face face) noexcept { const BlockLookup next(chunk, pos, face); return next; } - UnsetNode GetNext(Block::Face face) { return UnsetNode(SetNode::GetNext(face)); } + UnsetNode GetNext(Block::Face face) noexcept { return UnsetNode(SetNode::GetNext(face)); } }; std::queue light_queue; std::queue dark_queue; -void work_light() { +void work_light() noexcept { while (!light_queue.empty()) { SetNode node = light_queue.front(); light_queue.pop(); @@ -108,7 +107,7 @@ void work_light() { } } -void work_dark() { +void work_dark() noexcept { while (!dark_queue.empty()) { UnsetNode node = dark_queue.front(); dark_queue.pop(); @@ -130,7 +129,7 @@ void work_dark() { } -void Chunk::SetBlock(int index, const Block &block) { +void Chunk::SetBlock(int index, const Block &block) noexcept { const BlockType &old_type = Type(blocks[index]); const BlockType &new_type = Type(block); @@ -176,7 +175,7 @@ void Chunk::SetBlock(int index, const Block &block) { } } -void Chunk::SetNeighbor(Chunk &other) { +void Chunk::SetNeighbor(Chunk &other) noexcept { if (other.position == position + Pos(-1, 0, 0)) { if (neighbor[Block::FACE_LEFT] != &other) { neighbor[Block::FACE_LEFT] = &other; @@ -288,13 +287,13 @@ void Chunk::SetNeighbor(Chunk &other) { } } -void Chunk::ClearNeighbors() { +void Chunk::ClearNeighbors() noexcept { for (int i = 0; i < Block::FACE_COUNT; ++i) { neighbor[i] = nullptr; } } -void Chunk::Unlink() { +void Chunk::Unlink() noexcept { for (int face = 0; face < Block::FACE_COUNT; ++face) { if (neighbor[face]) { neighbor[face]->neighbor[Block::Opposite(Block::Face(face))] = nullptr; @@ -302,7 +301,7 @@ void Chunk::Unlink() { } } -void Chunk::Relink() { +void Chunk::Relink() noexcept { for (int face = 0; face < Block::FACE_COUNT; ++face) { if (neighbor[face]) { neighbor[face]->neighbor[Block::Opposite(Block::Face(face))] = this; @@ -311,18 +310,18 @@ void Chunk::Relink() { } -void Chunk::SetLight(int index, int level) { +void Chunk::SetLight(int index, int level) noexcept { if (light[index] != level) { light[index] = level; Invalidate(); } } -int Chunk::GetLight(int index) const { +int Chunk::GetLight(int index) const noexcept { return light[index]; } -float Chunk::GetVertexLight(int index, const BlockModel::Position &vtx, const Model::Normal &norm) const { +float Chunk::GetVertexLight(int index, const BlockModel::Position &vtx, const Model::Normal &norm) const noexcept { float light = GetLight(index); Chunk::Pos pos(ToPos(index)); @@ -349,7 +348,7 @@ float Chunk::GetVertexLight(int index, const BlockModel::Position &vtx, const Mo } -bool Chunk::IsSurface(const Pos &pos) const { +bool Chunk::IsSurface(const Pos &pos) const noexcept { const Block &block = BlockAt(pos); if (!Type(block).visible) { return false; @@ -364,7 +363,7 @@ bool Chunk::IsSurface(const Pos &pos) const { } -void Chunk::Draw() { +void Chunk::Draw() noexcept { if (dirty) { Update(); } @@ -378,7 +377,7 @@ bool Chunk::Intersection( int &blkid, float &dist, glm::vec3 &normal -) const { +) const noexcept { // TODO: should be possible to heavily optimize this int id = 0; blkid = -1; @@ -410,14 +409,6 @@ bool Chunk::Intersection( } } -void Chunk::Position(const Pos &pos) { - position = pos; -} - -glm::mat4 Chunk::Transform(const Pos &offset) const { - return glm::translate((position - offset) * Extent()); -} - namespace { @@ -425,13 +416,13 @@ BlockModel::Buffer buf; } -void Chunk::CheckUpdate() { +void Chunk::CheckUpdate() noexcept { if (dirty) { Update(); } } -void Chunk::Update() { +void Chunk::Update() noexcept { int vtx_count = 0, idx_count = 0; for (const auto &block : blocks) { const Shape *shape = Type(block).shape; @@ -464,7 +455,7 @@ void Chunk::Update() { dirty = false; } -Block::FaceSet Chunk::Obstructed(int idx) const { +Block::FaceSet Chunk::Obstructed(int idx) const noexcept { Chunk::Pos pos(ToPos(idx)); Block::FaceSet result; @@ -479,12 +470,12 @@ Block::FaceSet Chunk::Obstructed(int idx) const { return result; } -glm::mat4 Chunk::ToTransform(int idx) const { +glm::mat4 Chunk::ToTransform(int idx) const noexcept { return glm::translate(glm::mat4(1.0f), ToCoords(idx)) * blocks[idx].Transform(); } -BlockLookup::BlockLookup(Chunk *c, const Chunk::Pos &p) +BlockLookup::BlockLookup(Chunk *c, const Chunk::Pos &p) noexcept : chunk(c), pos(p) { while (pos.x >= Chunk::Width()) { if (chunk->HasNeighbor(Block::FACE_RIGHT)) { @@ -542,7 +533,7 @@ BlockLookup::BlockLookup(Chunk *c, const Chunk::Pos &p) } } -BlockLookup::BlockLookup(Chunk *c, const Chunk::Pos &p, Block::Face face) +BlockLookup::BlockLookup(Chunk *c, const Chunk::Pos &p, Block::Face face) noexcept : chunk(c), pos(p) { pos += Block::FaceNormal(face); if (!Chunk::InBounds(pos)) { @@ -552,7 +543,7 @@ BlockLookup::BlockLookup(Chunk *c, const Chunk::Pos &p, Block::Face face) } -ChunkLoader::ChunkLoader(const Config &config, const BlockTypeRegistry ®, const Generator &gen) +ChunkLoader::ChunkLoader(const Config &config, const BlockTypeRegistry ®, const Generator &gen) noexcept : base(0, 0, 0) , reg(reg) , gen(gen) @@ -568,10 +559,10 @@ namespace { struct ChunkLess { - explicit ChunkLess(const Chunk::Pos &base) + explicit ChunkLess(const Chunk::Pos &base) noexcept : base(base) { } - bool operator ()(const Chunk::Pos &a, const Chunk::Pos &b) const { + bool operator ()(const Chunk::Pos &a, const Chunk::Pos &b) const noexcept { Chunk::Pos da(base - a); Chunk::Pos db(base - b); return @@ -657,17 +648,17 @@ Chunk &ChunkLoader::Generate(const Chunk::Pos &pos) { return chunk; } -void ChunkLoader::Insert(Chunk &chunk) { +void ChunkLoader::Insert(Chunk &chunk) noexcept { for (Chunk &other : loaded) { chunk.SetNeighbor(other); } } -void ChunkLoader::Remove(Chunk &chunk) { +void ChunkLoader::Remove(Chunk &chunk) noexcept { chunk.Unlink(); } -Chunk *ChunkLoader::Loaded(const Chunk::Pos &pos) { +Chunk *ChunkLoader::Loaded(const Chunk::Pos &pos) noexcept { for (Chunk &chunk : loaded) { if (chunk.Position() == pos) { return &chunk; @@ -676,7 +667,7 @@ Chunk *ChunkLoader::Loaded(const Chunk::Pos &pos) { return nullptr; } -bool ChunkLoader::Queued(const Chunk::Pos &pos) { +bool ChunkLoader::Queued(const Chunk::Pos &pos) noexcept { for (const Chunk::Pos &chunk : to_generate) { if (chunk == pos) { return true; @@ -685,7 +676,7 @@ bool ChunkLoader::Queued(const Chunk::Pos &pos) { return nullptr; } -bool ChunkLoader::Known(const Chunk::Pos &pos) { +bool ChunkLoader::Known(const Chunk::Pos &pos) noexcept { if (Loaded(pos)) return true; return Queued(pos); } diff --git a/src/chunk.hpp b/src/chunk.hpp index 06dc98b..24024f9 100644 --- a/src/chunk.hpp +++ b/src/chunk.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace blank { @@ -19,54 +20,54 @@ public: using Pos = glm::tvec3; public: - explicit Chunk(const BlockTypeRegistry &); + explicit Chunk(const BlockTypeRegistry &) noexcept; - Chunk(Chunk &&); - Chunk &operator =(Chunk &&); + Chunk(Chunk &&) noexcept; + Chunk &operator =(Chunk &&) noexcept; static constexpr int Width() { return 16; } static constexpr int Height() { return 16; } static constexpr int Depth() { return 16; } - static Pos Extent() { return { Width(), Height(), Depth() }; } + static Pos Extent() noexcept { return { Width(), Height(), Depth() }; } static constexpr int Size() { return Width() * Height() * Depth(); } - static AABB Bounds() { return AABB{ { 0, 0, 0 }, Extent() }; } + static AABB Bounds() noexcept { return AABB{ { 0, 0, 0 }, Extent() }; } - static constexpr bool InBounds(const Block::Pos &pos) { + static constexpr bool InBounds(const Block::Pos &pos) noexcept { return pos.x >= 0 && pos.x < Width() && pos.y >= 0 && pos.y < Height() && pos.z >= 0 && pos.z < Depth(); } - static constexpr bool InBounds(const Pos &pos) { + static constexpr bool InBounds(const Pos &pos) noexcept { return pos.x >= 0 && pos.x < Width() && pos.y >= 0 && pos.y < Height() && pos.z >= 0 && pos.z < Depth(); } - static constexpr int ToIndex(const Pos &pos) { + static constexpr int ToIndex(const Pos &pos) noexcept { return pos.x + pos.y * Width() + pos.z * Width() * Height(); } - static constexpr bool InBounds(int idx) { + static constexpr bool InBounds(int idx) noexcept { return idx >= 0 && idx < Size(); } - static Block::Pos ToCoords(int idx) { + static Block::Pos ToCoords(int idx) noexcept { return Block::Pos( 0.5f + (idx % Width()), 0.5f + ((idx / Width()) % Height()), 0.5f + (idx / (Width() * Height())) ); } - static Pos ToPos(int idx) { + static Pos ToPos(int idx) noexcept { return Pos( (idx % Width()), ((idx / Width()) % Height()), (idx / (Width() * Height())) ); } - glm::mat4 ToTransform(int idx) const; + glm::mat4 ToTransform(int idx) const noexcept; - static constexpr bool IsBorder(int idx) { + static constexpr bool IsBorder(int idx) noexcept { return idx < Width() * Height() || // low Z plane idx % Width() == 0 || // low X plane @@ -76,48 +77,48 @@ public: (idx / Width()) % Height() == Height() - 1; // high Y plane } - bool IsSurface(int index) const { return IsSurface(ToPos(index)); } - bool IsSurface(const Block::Pos &pos) const { return IsSurface(Pos(pos)); } - bool IsSurface(const Pos &pos) const; + bool IsSurface(int index) const noexcept { return IsSurface(ToPos(index)); } + bool IsSurface(const Block::Pos &pos) const noexcept { return IsSurface(Pos(pos)); } + bool IsSurface(const Pos &pos) const noexcept; - void SetNeighbor(Chunk &); - bool HasNeighbor(Block::Face f) const { return neighbor[f]; } - Chunk &GetNeighbor(Block::Face f) { return *neighbor[f]; } - const Chunk &GetNeighbor(Block::Face f) const { return *neighbor[f]; } - void ClearNeighbors(); - void Unlink(); - void Relink(); + void SetNeighbor(Chunk &) noexcept; + bool HasNeighbor(Block::Face f) const noexcept { return neighbor[f]; } + Chunk &GetNeighbor(Block::Face f) noexcept { return *neighbor[f]; } + const Chunk &GetNeighbor(Block::Face f) const noexcept { return *neighbor[f]; } + void ClearNeighbors() noexcept; + void Unlink() noexcept; + void Relink() noexcept; // check which faces of a block at given index are obstructed (and therefore invisible) - Block::FaceSet Obstructed(int idx) const; + Block::FaceSet Obstructed(int idx) const noexcept; - void Invalidate() { dirty = true; } + void Invalidate() noexcept { dirty = true; } - void SetBlock(int index, const Block &); - void SetBlock(const Block::Pos &pos, const Block &block) { SetBlock(ToIndex(pos), block); } - void SetBlock(const Pos &pos, const Block &block) { SetBlock(ToIndex(pos), block); } + void SetBlock(int index, const Block &) noexcept; + void SetBlock(const Block::Pos &pos, const Block &block) noexcept { SetBlock(ToIndex(pos), block); } + void SetBlock(const Pos &pos, const Block &block) noexcept { SetBlock(ToIndex(pos), block); } - const Block &BlockAt(int index) const { return blocks[index]; } - const Block &BlockAt(const Block::Pos &pos) const { return BlockAt(ToIndex(pos)); } - const Block &BlockAt(const Pos &pos) const { return BlockAt(ToIndex(pos)); } + const Block &BlockAt(int index) const noexcept { return blocks[index]; } + const Block &BlockAt(const Block::Pos &pos) const noexcept { return BlockAt(ToIndex(pos)); } + const Block &BlockAt(const Pos &pos) const noexcept { return BlockAt(ToIndex(pos)); } - const BlockType &Type(const Block &b) const { return *types->Get(b.type); } + const BlockType &Type(const Block &b) const noexcept { return types->Get(b.type); } - void SetLight(int index, int level); - void SetLight(const Pos &pos, int level) { SetLight(ToIndex(pos), level); } - void SetLight(const Block::Pos &pos, int level) { SetLight(ToIndex(pos), level); } + void SetLight(int index, int level) noexcept; + void SetLight(const Pos &pos, int level) noexcept { SetLight(ToIndex(pos), level); } + void SetLight(const Block::Pos &pos, int level) noexcept { SetLight(ToIndex(pos), level); } - int GetLight(int index) const; - int GetLight(const Pos &pos) const { return GetLight(ToIndex(pos)); } - int GetLight(const Block::Pos &pos) const { return GetLight(ToIndex(pos)); } + int GetLight(int index) const noexcept; + int GetLight(const Pos &pos) const noexcept { return GetLight(ToIndex(pos)); } + int GetLight(const Block::Pos &pos) const noexcept { return GetLight(ToIndex(pos)); } - float GetVertexLight(int index, const BlockModel::Position &, const Model::Normal &) const; + float GetVertexLight(int index, const BlockModel::Position &, const Model::Normal &) const noexcept; bool Intersection( const Ray &ray, const glm::mat4 &M, float &dist - ) const { + ) const noexcept { return blank::Intersection(ray, Bounds(), M, &dist); } @@ -126,17 +127,19 @@ public: const glm::mat4 &M, int &blkid, float &dist, - glm::vec3 &normal) const; + glm::vec3 &normal) const noexcept; - void Position(const Pos &); - const Pos &Position() const { return position; } - glm::mat4 Transform(const Pos &offset) const; + void Position(const Pos &pos) noexcept { position = pos; } + const Pos &Position() const noexcept { return position; } + glm::mat4 Transform(const Pos &offset) const noexcept { + return glm::translate((position - offset) * Extent()); + } - void CheckUpdate(); - void Draw(); + void CheckUpdate() noexcept; + void Draw() noexcept; private: - void Update(); + void Update() noexcept; private: const BlockTypeRegistry *types; @@ -154,20 +157,20 @@ class BlockLookup { public: // resolve chunk/position from oob coordinates - BlockLookup(Chunk *c, const Chunk::Pos &p); + BlockLookup(Chunk *c, const Chunk::Pos &p) noexcept; // resolve chunk/position from ib coordinates and direction - BlockLookup(Chunk *c, const Chunk::Pos &p, Block::Face dir); + BlockLookup(Chunk *c, const Chunk::Pos &p, Block::Face dir) noexcept; // check if lookup was successful operator bool() const { return chunk; } // only valid if lookup was successful - Chunk &GetChunk() const { return *chunk; } - const Chunk::Pos &GetBlockPos() const { return pos; } - const Block &GetBlock() const { return GetChunk().BlockAt(GetBlockPos()); } - const BlockType &GetType() const { return GetChunk().Type(GetBlock()); } - int GetLight() const { return GetChunk().GetLight(GetBlockPos()); } + Chunk &GetChunk() const noexcept { return *chunk; } + const Chunk::Pos &GetBlockPos() const noexcept { return pos; } + const Block &GetBlock() const noexcept { return GetChunk().BlockAt(GetBlockPos()); } + const BlockType &GetType() const noexcept { return GetChunk().Type(GetBlock()); } + int GetLight() const noexcept { return GetChunk().GetLight(GetBlockPos()); } private: Chunk *chunk; @@ -186,16 +189,16 @@ public: int unload_dist = 8; }; - ChunkLoader(const Config &, const BlockTypeRegistry &, const Generator &); + ChunkLoader(const Config &, const BlockTypeRegistry &, const Generator &) noexcept; void Generate(const Chunk::Pos &from, const Chunk::Pos &to); void GenerateSurrounding(const Chunk::Pos &); - std::list &Loaded() { return loaded; } + std::list &Loaded() noexcept { return loaded; } - Chunk *Loaded(const Chunk::Pos &); - bool Queued(const Chunk::Pos &); - bool Known(const Chunk::Pos &); + Chunk *Loaded(const Chunk::Pos &) noexcept; + bool Queued(const Chunk::Pos &) noexcept; + bool Known(const Chunk::Pos &) noexcept; Chunk &ForceLoad(const Chunk::Pos &); void Rebase(const Chunk::Pos &); @@ -203,8 +206,8 @@ public: private: Chunk &Generate(const Chunk::Pos &pos); - void Insert(Chunk &); - void Remove(Chunk &); + void Insert(Chunk &) noexcept; + void Remove(Chunk &) noexcept; private: Chunk::Pos base; diff --git a/src/controller.cpp b/src/controller.cpp index fcdb407..e86551f 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -6,7 +6,7 @@ namespace blank { -FPSController::FPSController(Entity &entity) +FPSController::FPSController(Entity &entity) noexcept : entity(entity) , pitch(0) , yaw(0) { @@ -14,7 +14,7 @@ FPSController::FPSController(Entity &entity) } -void FPSController::Pitch(float p) { +void FPSController::Pitch(float p) noexcept { pitch = p; if (pitch > PI / 2) { pitch = PI / 2; @@ -23,11 +23,11 @@ void FPSController::Pitch(float p) { } } -void FPSController::RotatePitch(float delta) { +void FPSController::RotatePitch(float delta) noexcept { Pitch(pitch + delta); } -void FPSController::Yaw(float y) { +void FPSController::Yaw(float y) noexcept { yaw = y; if (yaw > PI) { yaw -= PI * 2; @@ -36,25 +36,25 @@ void FPSController::Yaw(float y) { } } -void FPSController::RotateYaw(float delta) { +void FPSController::RotateYaw(float delta) noexcept { Yaw(yaw + delta); } -void FPSController::Update(int dt) { +void FPSController::Update(int dt) noexcept { entity.Rotation(glm::eulerAngleYX(yaw, pitch)); entity.Velocity(glm::rotateY(velocity, yaw)); } -RandomWalk::RandomWalk(Entity &e) +RandomWalk::RandomWalk(Entity &e) noexcept : entity(e) , time_left(0) { } -void RandomWalk::Update(int dt) { +void RandomWalk::Update(int dt) noexcept { time_left -= dt; if (time_left > 0) return; time_left += 2500 + (rand() % 5000); diff --git a/src/controller.hpp b/src/controller.hpp index 7dd3d11..f674e23 100644 --- a/src/controller.hpp +++ b/src/controller.hpp @@ -12,22 +12,22 @@ namespace blank { class FPSController { public: - explicit FPSController(Entity &); + explicit FPSController(Entity &) noexcept; - Ray Aim() const { return entity.Aim(entity.ChunkCoords()); } + Ray Aim() const noexcept { return entity.Aim(entity.ChunkCoords()); } - const glm::vec3 &Velocity() const { return velocity; } - void Velocity(const glm::vec3 &vel) { velocity = vel; } + const glm::vec3 &Velocity() const noexcept { return velocity; } + void Velocity(const glm::vec3 &vel) noexcept { velocity = vel; } // all angles in radians (full circle = 2π) - float Pitch() const { return pitch; } - void Pitch(float p); - void RotatePitch(float delta); - float Yaw() const { return yaw; } - void Yaw(float y); - void RotateYaw(float delta); + float Pitch() const noexcept { return pitch; } + void Pitch(float p) noexcept; + void RotatePitch(float delta) noexcept; + float Yaw() const noexcept { return yaw; } + void Yaw(float y) noexcept; + void RotateYaw(float delta) noexcept; - void Update(int dt); + void Update(int dt) noexcept; private: Entity &entity; @@ -43,9 +43,9 @@ private: class RandomWalk { public: - explicit RandomWalk(Entity &); + explicit RandomWalk(Entity &) noexcept; - void Update(int dt); + void Update(int dt) noexcept; private: Entity &entity; diff --git a/src/entity.cpp b/src/entity.cpp index 2358601..054af2a 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -14,7 +14,7 @@ blank::Model::Buffer model_buffer; namespace blank { -Entity::Entity() +Entity::Entity() noexcept : shape(nullptr) , model() , velocity(0, 0, 0) @@ -34,16 +34,16 @@ void Entity::SetShape(const Shape *s, const glm::vec3 &color) { model.Update(model_buffer); } -void Entity::SetShapeless() { +void Entity::SetShapeless() noexcept { shape = nullptr; } -void Entity::Velocity(const glm::vec3 &vel) { +void Entity::Velocity(const glm::vec3 &vel) noexcept { velocity = vel; } -void Entity::Position(const Block::Pos &pos) { +void Entity::Position(const Block::Pos &pos) noexcept { position = pos; while (position.x >= Chunk::Width()) { position.x -= Chunk::Width(); @@ -71,28 +71,28 @@ void Entity::Position(const Block::Pos &pos) { } } -void Entity::Move(const glm::vec3 &delta) { +void Entity::Move(const glm::vec3 &delta) noexcept { Position(position + delta); } -void Entity::AngularVelocity(const glm::quat &v) { +void Entity::AngularVelocity(const glm::quat &v) noexcept { angular_velocity = v; } -void Entity::Rotation(const glm::mat4 &rot) { +void Entity::Rotation(const glm::mat4 &rot) noexcept { rotation = rot; } -void Entity::Rotate(const glm::quat &delta) { +void Entity::Rotate(const glm::quat &delta) noexcept { Rotation(rotation * glm::mat4_cast(delta)); } -glm::mat4 Entity::Transform(const Chunk::Pos &chunk_offset) const { +glm::mat4 Entity::Transform(const Chunk::Pos &chunk_offset) const noexcept { const glm::vec3 chunk_pos = (chunk - chunk_offset) * Chunk::Extent(); return glm::translate(position + chunk_pos) * rotation; } -Ray Entity::Aim(const Chunk::Pos &chunk_offset) const { +Ray Entity::Aim(const Chunk::Pos &chunk_offset) const noexcept { glm::mat4 transform = Transform(chunk_offset); glm::vec4 from = transform * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f); from /= from.w; @@ -101,13 +101,13 @@ Ray Entity::Aim(const Chunk::Pos &chunk_offset) const { return Ray{ glm::vec3(from), glm::normalize(glm::vec3(to - from)) }; } -void Entity::Update(int dt) { +void Entity::Update(int dt) noexcept { Move(velocity * float(dt)); Rotate(angular_velocity * float(dt)); } -void Entity::Draw() { +void Entity::Draw() noexcept { model.Draw(); } diff --git a/src/entity.hpp b/src/entity.hpp index 5ef8fbe..20c7630 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -17,35 +17,35 @@ class Shape; class Entity { public: - Entity(); + Entity() noexcept; - bool HasShape() const { return shape; } - const Shape *GetShape() const { return shape; } + bool HasShape() const noexcept { return shape; } + const Shape *GetShape() const noexcept { return shape; } void SetShape(const Shape *, const glm::vec3 &color); - void SetShapeless(); + void SetShapeless() noexcept; - const glm::vec3 &Velocity() const { return velocity; } - void Velocity(const glm::vec3 &); + const glm::vec3 &Velocity() const noexcept { return velocity; } + void Velocity(const glm::vec3 &) noexcept; - const Block::Pos &Position() const { return position; } - void Position(const Block::Pos &); - void Move(const glm::vec3 &delta); + const Block::Pos &Position() const noexcept { return position; } + void Position(const Block::Pos &) noexcept; + void Move(const glm::vec3 &delta) noexcept; - const Chunk::Pos ChunkCoords() const { return chunk; } + const Chunk::Pos ChunkCoords() const noexcept { return chunk; } - const glm::quat &AngularVelocity() const { return angular_velocity; } - void AngularVelocity(const glm::quat &); + const glm::quat &AngularVelocity() const noexcept { return angular_velocity; } + void AngularVelocity(const glm::quat &) noexcept; - const glm::mat4 &Rotation() const { return rotation; } - void Rotation(const glm::mat4 &); - void Rotate(const glm::quat &delta); + const glm::mat4 &Rotation() const noexcept { return rotation; } + void Rotation(const glm::mat4 &) noexcept; + void Rotate(const glm::quat &delta) noexcept; - glm::mat4 Transform(const Chunk::Pos &chunk_offset) const; - Ray Aim(const Chunk::Pos &chunk_offset) const; + glm::mat4 Transform(const Chunk::Pos &chunk_offset) const noexcept; + Ray Aim(const Chunk::Pos &chunk_offset) const noexcept; - void Update(int dt); + void Update(int dt) noexcept; - void Draw(); + void Draw() noexcept; private: const Shape *shape; diff --git a/src/generator.cpp b/src/generator.cpp index 373374f..3714065 100644 --- a/src/generator.cpp +++ b/src/generator.cpp @@ -5,7 +5,7 @@ namespace blank { -Generator::Generator(const Config &config) +Generator::Generator(const Config &config) noexcept : solidNoise(config.solid_seed) , typeNoise(config.type_seed) , stretch(1.0f/config.stretch) @@ -17,7 +17,7 @@ Generator::Generator(const Config &config) } -void Generator::operator ()(Chunk &chunk) const { +void Generator::operator ()(Chunk &chunk) const noexcept { Chunk::Pos pos(chunk.Position()); glm::vec3 coords(pos * Chunk::Extent()); for (int z = 0; z < Chunk::Depth(); ++z) { diff --git a/src/generator.hpp b/src/generator.hpp index 70c38f5..dedfb72 100644 --- a/src/generator.hpp +++ b/src/generator.hpp @@ -20,12 +20,12 @@ public: float solid_threshold = 0.5f; }; - explicit Generator(const Config &); + explicit Generator(const Config &) noexcept; - void operator ()(Chunk &) const; + void operator ()(Chunk &) const noexcept; - void Space(Block::Type t) { space = t; } - void Light(Block::Type t) { light = t; } + void Space(Block::Type t) noexcept { space = t; } + void Light(Block::Type t) noexcept { light = t; } void Solids(const std::vector &s) { solids = s; } private: diff --git a/src/geometry.cpp b/src/geometry.cpp index cd28bab..416d930 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -11,7 +11,7 @@ bool Intersection( const glm::mat4 &M, float *dist, glm::vec3 *normal -) { +) noexcept { float t_min = 0.0f; float t_max = std::numeric_limits::infinity(); const glm::vec3 aabb_pos(M[3].x, M[3].y, M[3].z); @@ -65,7 +65,7 @@ bool Intersection( return true; } -bool CullTest(const AABB &box, const glm::mat4 &MVP) { +bool CullTest(const AABB &box, const glm::mat4 &MVP) noexcept { // transform corners into clip space glm::vec4 corners[8] = { { box.min.x, box.min.y, box.min.z, 1.0f }, diff --git a/src/geometry.hpp b/src/geometry.hpp index 78fe5f5..df75f22 100644 --- a/src/geometry.hpp +++ b/src/geometry.hpp @@ -17,7 +17,7 @@ struct AABB { glm::vec3 min; glm::vec3 max; - void Adjust() { + void Adjust() noexcept { if (max.x < min.x) std::swap(max.x, min.x); if (max.y < min.y) std::swap(max.y, min.y); if (max.z < min.z) std::swap(max.z, min.z); @@ -34,9 +34,9 @@ bool Intersection( const AABB &, const glm::mat4 &M, float *dist = nullptr, - glm::vec3 *normal = nullptr); + glm::vec3 *normal = nullptr) noexcept; -bool CullTest(const AABB &box, const glm::mat4 &MVP); +bool CullTest(const AABB &box, const glm::mat4 &MVP) noexcept; } diff --git a/src/glmio.hpp b/src/glmio.hpp deleted file mode 100644 index f96d5fd..0000000 --- a/src/glmio.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef BLANKL_GLMIO_HPP_ -#define BLANKL_GLMIO_HPP_ - -#include -#include - - -namespace blank { - -template -std::ostream &operator <<(std::ostream &out, const glm::tvec3 &v) { - return out << '<' << v.x << ", " << v.y << ", " << v.z << '>'; -} - -template -std::ostream &operator <<(std::ostream &out, const glm::tvec4 &v) { - return out << '<' << v.x << ", " << v.y << ", " << v.z << ", " << v.w << '>'; -} - -template -std::ostream &operator <<(std::ostream &out, const glm::tmat4x4 &m) { - return out << '[' << m[0] << ", " << m[1] << ", " << m[2] << ", " << m[3] << ']'; -} - -} - -#endif diff --git a/src/hud.cpp b/src/hud.cpp index 0747cff..0f496c6 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -39,18 +39,18 @@ HUD::HUD(const BlockTypeRegistry &types) } -void HUD::Viewport(float width, float height) { +void HUD::Viewport(float width, float height) noexcept { Viewport(0, 0, width, height); } -void HUD::Viewport(float x, float y, float width, float height) { +void HUD::Viewport(float x, float y, float width, float height) noexcept { projection = glm::ortho(x, width, height, y, near, far); crosshair_transform = glm::translate(glm::mat4(1.0f), glm::vec3(width * 0.5f, height * 0.5f, 0.0f)); } void HUD::Display(const Block &b) { - const BlockType &type = *types.Get(b.type); + const BlockType &type = types.Get(b.type); block_buf.Clear(); type.FillModel(block_buf, b.Transform()); @@ -59,7 +59,7 @@ void HUD::Display(const Block &b) { } -void HUD::Render(DirectionalLighting &program) { +void HUD::Render(DirectionalLighting &program) noexcept { if (block_visible) { program.SetLightDirection({ 1.0f, 3.0f, 5.0f }); // disable distance fog diff --git a/src/hud.hpp b/src/hud.hpp index 4bfd5fb..984a24d 100644 --- a/src/hud.hpp +++ b/src/hud.hpp @@ -20,12 +20,12 @@ public: HUD(const HUD &) = delete; HUD &operator =(const HUD &) = delete; - void Viewport(float width, float height); - void Viewport(float x, float y, float width, float height); + void Viewport(float width, float height) noexcept; + void Viewport(float x, float y, float width, float height) noexcept; void Display(const Block &); - void Render(DirectionalLighting &); + void Render(DirectionalLighting &) noexcept; private: const BlockTypeRegistry &types; diff --git a/src/init.cpp b/src/init.cpp index 73a7309..a56674c 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -149,20 +149,20 @@ void GLContext::EnableVSync() { } } -void GLContext::EnableDepthTest() { +void GLContext::EnableDepthTest() noexcept { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); } -void GLContext::EnableBackfaceCulling() { +void GLContext::EnableBackfaceCulling() noexcept { glEnable(GL_CULL_FACE); } -void GLContext::Clear() { +void GLContext::Clear() noexcept { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } -void GLContext::ClearDepthBuffer() { +void GLContext::ClearDepthBuffer() noexcept { glClear(GL_DEPTH_BUFFER_BIT); } diff --git a/src/init.hpp b/src/init.hpp index d08437b..30da3be 100644 --- a/src/init.hpp +++ b/src/init.hpp @@ -82,11 +82,11 @@ public: GLContext &operator =(const GLContext &) = delete; static void EnableVSync(); - static void EnableDepthTest(); - static void EnableBackfaceCulling(); + static void EnableDepthTest() noexcept; + static void EnableBackfaceCulling() noexcept; - static void Clear(); - static void ClearDepthBuffer(); + static void Clear() noexcept; + static void ClearDepthBuffer() noexcept; private: SDL_GLContext handle; diff --git a/src/interface.cpp b/src/interface.cpp index e4888c5..12117f7 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -201,7 +201,7 @@ void Interface::PlaceBlock() { mod_chunk->Invalidate(); } -void Interface::RemoveBlock() { +void Interface::RemoveBlock() noexcept { if (!aim_chunk) return; aim_chunk->SetBlock(aim_block, remove); aim_chunk->Invalidate(); @@ -234,7 +234,7 @@ void Interface::SelectPrevious() { hud.Display(selection); } -void Interface::Handle(const SDL_WindowEvent &event) { +void Interface::Handle(const SDL_WindowEvent &event) noexcept { if (event.event == SDL_WINDOWEVENT_RESIZED) { hud.Viewport(event.data1, event.data2); } @@ -260,7 +260,7 @@ void Interface::Update(int dt) { } -void Interface::Render(DirectionalLighting &program) { +void Interface::Render(DirectionalLighting &program) noexcept { if (config.visual_disabled) return; if (aim_chunk) { diff --git a/src/interface.hpp b/src/interface.hpp index 1f4bb90..16ee89f 100644 --- a/src/interface.hpp +++ b/src/interface.hpp @@ -35,14 +35,14 @@ public: void Handle(const SDL_MouseMotionEvent &); void Handle(const SDL_MouseButtonEvent &); void Handle(const SDL_MouseWheelEvent &); - void Handle(const SDL_WindowEvent &); + void Handle(const SDL_WindowEvent &) noexcept; void FaceBlock(); void TurnBlock(); void PickBlock(); void PlaceBlock(); - void RemoveBlock(); + void RemoveBlock() noexcept; void PrintBlockInfo(); void PrintChunkInfo(); @@ -55,7 +55,7 @@ public: void Update(int dt); - void Render(DirectionalLighting &); + void Render(DirectionalLighting &) noexcept; private: World &world; diff --git a/src/model.cpp b/src/model.cpp index 1d4edef..4e75674 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -5,20 +5,20 @@ namespace blank { -Model::Model() -: va(0) +Model::Model() noexcept +: va(0) , handle{} , count(0) { glGenVertexArrays(1, &va); glGenBuffers(ATTRIB_COUNT, handle); } -Model::~Model() { +Model::~Model() noexcept { glDeleteBuffers(ATTRIB_COUNT, handle); glDeleteVertexArrays(1, &va); } -Model::Model(Model &&other) +Model::Model(Model &&other) noexcept : va(other.va) , count(other.count) { other.va = 0; @@ -28,7 +28,7 @@ Model::Model(Model &&other) } } -Model &Model::operator =(Model &&other) { +Model &Model::operator =(Model &&other) noexcept { std::swap(va, other.va); for (int i = 0; i < ATTRIB_COUNT; ++i) { std::swap(handle[i], other.handle[i]); @@ -37,7 +37,7 @@ Model &Model::operator =(Model &&other) { return *this; } -void Model::Update(const Buffer &buf) { +void Model::Update(const Buffer &buf) noexcept { glBindVertexArray(va); glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_VERTEX]); glBufferData(GL_ARRAY_BUFFER, buf.vertices.size() * sizeof(glm::vec3), buf.vertices.data(), GL_STATIC_DRAW); @@ -91,7 +91,7 @@ void Model::Update(const Buffer &buf) { } -void Model::Draw() const { +void Model::Draw() const noexcept { glBindVertexArray(va); glDrawElements( GL_TRIANGLES, // how @@ -102,7 +102,7 @@ void Model::Draw() const { } -BlockModel::BlockModel() +BlockModel::BlockModel() noexcept : va(0) , handle{} , count(0) { @@ -110,12 +110,12 @@ BlockModel::BlockModel() glGenBuffers(ATTRIB_COUNT, handle); } -BlockModel::~BlockModel() { +BlockModel::~BlockModel() noexcept { glDeleteBuffers(ATTRIB_COUNT, handle); glDeleteVertexArrays(1, &va); } -BlockModel::BlockModel(BlockModel &&other) +BlockModel::BlockModel(BlockModel &&other) noexcept : va(other.va) , count(other.count) { other.va = 0; @@ -125,7 +125,7 @@ BlockModel::BlockModel(BlockModel &&other) } } -BlockModel &BlockModel::operator =(BlockModel &&other) { +BlockModel &BlockModel::operator =(BlockModel &&other) noexcept { std::swap(va, other.va); for (int i = 0; i < ATTRIB_COUNT; ++i) { std::swap(handle[i], other.handle[i]); @@ -134,7 +134,7 @@ BlockModel &BlockModel::operator =(BlockModel &&other) { return *this; } -void BlockModel::Update(const Buffer &buf) { +void BlockModel::Update(const Buffer &buf) noexcept { glBindVertexArray(va); glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_VERTEX]); glBufferData(GL_ARRAY_BUFFER, buf.vertices.size() * sizeof(glm::vec3), buf.vertices.data(), GL_STATIC_DRAW); @@ -188,7 +188,7 @@ void BlockModel::Update(const Buffer &buf) { } -void BlockModel::Draw() const { +void BlockModel::Draw() const noexcept { glBindVertexArray(va); glDrawElements( GL_TRIANGLES, // how @@ -198,7 +198,7 @@ void BlockModel::Draw() const { ); } -OutlineModel::OutlineModel() +OutlineModel::OutlineModel() noexcept : vertices() , colors() , indices() @@ -209,13 +209,13 @@ OutlineModel::OutlineModel() glGenBuffers(ATTRIB_COUNT, handle); } -OutlineModel::~OutlineModel() { +OutlineModel::~OutlineModel() noexcept { glDeleteBuffers(ATTRIB_COUNT, handle); glDeleteVertexArrays(1, &va); } -void OutlineModel::Clear() { +void OutlineModel::Clear() noexcept { vertices.clear(); colors.clear(); indices.clear(); @@ -229,7 +229,7 @@ void OutlineModel::Reserve(int v, int i) { } -void OutlineModel::Update() { +void OutlineModel::Update() noexcept { glBindBuffer(GL_ARRAY_BUFFER, handle[ATTRIB_VERTEX]); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), vertices.data(), GL_STATIC_DRAW); glEnableVertexAttribArray(ATTRIB_VERTEX); @@ -267,7 +267,7 @@ void OutlineModel::Update() { } -void OutlineModel::Draw() { +void OutlineModel::Draw() noexcept { glBindVertexArray(va); if (dirty) { diff --git a/src/model.hpp b/src/model.hpp index 557b4ac..096e1cf 100644 --- a/src/model.hpp +++ b/src/model.hpp @@ -29,7 +29,7 @@ public: Normals normals; Indices indices; - void Clear() { + void Clear() noexcept { vertices.clear(); colors.clear(); normals.clear(); @@ -46,18 +46,18 @@ public: }; public: - Model(); - ~Model(); + Model() noexcept; + ~Model() noexcept; Model(const Model &) = delete; Model &operator =(const Model &) = delete; - Model(Model &&); - Model &operator =(Model &&); + Model(Model &&) noexcept; + Model &operator =(Model &&) noexcept; - void Update(const Buffer &); + void Update(const Buffer &) noexcept; - void Draw() const; + void Draw() const noexcept; private: enum Attribute { @@ -96,7 +96,7 @@ public: Lights lights; Indices indices; - void Clear() { + void Clear() noexcept { vertices.clear(); colors.clear(); lights.clear(); @@ -113,18 +113,18 @@ public: }; public: - BlockModel(); - ~BlockModel(); + BlockModel() noexcept; + ~BlockModel() noexcept; BlockModel(const BlockModel &) = delete; BlockModel &operator =(const Model &) = delete; - BlockModel(BlockModel &&); - BlockModel &operator =(BlockModel &&); + BlockModel(BlockModel &&) noexcept; + BlockModel &operator =(BlockModel &&) noexcept; - void Update(const Buffer &); + void Update(const Buffer &) noexcept; - void Draw() const; + void Draw() const noexcept; private: enum Attribute { @@ -159,21 +159,21 @@ public: Indices indices; public: - OutlineModel(); - ~OutlineModel(); + OutlineModel() noexcept; + ~OutlineModel() noexcept; OutlineModel(const OutlineModel &) = delete; OutlineModel &operator =(const OutlineModel &) = delete; - void Invalidate() { dirty = true; } + void Invalidate() noexcept { dirty = true; } - void Clear(); + void Clear() noexcept; void Reserve(int vtx_count, int idx_count); - void Draw(); + void Draw() noexcept; private: - void Update(); + void Update() noexcept; private: enum Attribute { diff --git a/src/noise.cpp b/src/noise.cpp index 8b71614..a5a9a20 100644 --- a/src/noise.cpp +++ b/src/noise.cpp @@ -12,12 +12,12 @@ constexpr float one_sixth = 1.0f/6.0f; namespace blank { -GaloisLFSR::GaloisLFSR(std::uint64_t seed) +GaloisLFSR::GaloisLFSR(std::uint64_t seed) noexcept : state(seed) { } -bool GaloisLFSR::operator ()() { +bool GaloisLFSR::operator ()() noexcept { bool result = state & 1; state >>= 1; if (result) { @@ -30,7 +30,7 @@ bool GaloisLFSR::operator ()() { } -SimplexNoise::SimplexNoise(unsigned int seed) +SimplexNoise::SimplexNoise(unsigned int seed) noexcept : grad({ { 1.0f, 1.0f, 0.0f }, { -1.0f, 1.0f, 0.0f }, @@ -53,7 +53,7 @@ SimplexNoise::SimplexNoise(unsigned int seed) } -float SimplexNoise::operator ()(const glm::vec3 &in) const { +float SimplexNoise::operator ()(const glm::vec3 &in) const noexcept { float skew = (in.x + in.y + in.z) * one_third; glm::vec3 skewed(glm::floor(in + skew)); @@ -118,22 +118,22 @@ float SimplexNoise::operator ()(const glm::vec3 &in) const { } -unsigned char SimplexNoise::Perm(size_t idx) const { +unsigned char SimplexNoise::Perm(size_t idx) const noexcept { return perm[idx]; } -const glm::vec3 &SimplexNoise::Grad(size_t idx) const { +const glm::vec3 &SimplexNoise::Grad(size_t idx) const noexcept { return grad[idx % 12]; } -WorleyNoise::WorleyNoise(unsigned int seed) +WorleyNoise::WorleyNoise(unsigned int seed) noexcept : seed(seed) , num_points(8) { } -float WorleyNoise::operator ()(const glm::vec3 &in) const { +float WorleyNoise::operator ()(const glm::vec3 &in) const noexcept { glm::vec3 center = floor(in); float closest = 1.0f; // cannot be farther away than 1.0 diff --git a/src/noise.hpp b/src/noise.hpp index 26e3766..0f37031 100644 --- a/src/noise.hpp +++ b/src/noise.hpp @@ -12,13 +12,13 @@ class GaloisLFSR { public: // seed should be non-zero - explicit GaloisLFSR(std::uint64_t seed); + explicit GaloisLFSR(std::uint64_t seed) noexcept; // get the next bit - bool operator ()(); + bool operator ()() noexcept; template - void operator ()(T &out) { + void operator ()(T &out) noexcept { constexpr int num_bits = std::numeric_limits::digits + std::numeric_limits::is_signed; @@ -40,13 +40,13 @@ private: class SimplexNoise { public: - explicit SimplexNoise(unsigned int seed); + explicit SimplexNoise(unsigned int seed) noexcept; - float operator ()(const glm::vec3 &) const; + float operator ()(const glm::vec3 &) const noexcept; private: - unsigned char Perm(size_t idx) const; - const glm::vec3 &Grad(size_t idx) const; + unsigned char Perm(size_t idx) const noexcept; + const glm::vec3 &Grad(size_t idx) const noexcept; private: unsigned char perm[512]; @@ -59,9 +59,9 @@ private: class WorleyNoise { public: - explicit WorleyNoise(unsigned int seed); + explicit WorleyNoise(unsigned int seed) noexcept; - float operator ()(const glm::vec3 &) const; + float operator ()(const glm::vec3 &) const noexcept; private: const unsigned int seed; diff --git a/src/runtime.cpp b/src/runtime.cpp index 18a06bf..7475c90 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -11,7 +11,7 @@ using namespace std; namespace blank { -Runtime::Runtime() +Runtime::Runtime() noexcept : name("blank") , mode(NORMAL) , n(0) diff --git a/src/runtime.hpp b/src/runtime.hpp index 1fbc4db..014cd32 100644 --- a/src/runtime.hpp +++ b/src/runtime.hpp @@ -19,7 +19,7 @@ public: ERROR, }; - Runtime(); + Runtime() noexcept; void ReadArgs(int argc, const char *const *argv); diff --git a/src/shader.cpp b/src/shader.cpp index 01f7861..b2ccb8b 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -42,27 +42,27 @@ Shader::~Shader() { } } -Shader::Shader(Shader &&other) +Shader::Shader(Shader &&other) noexcept : handle(other.handle) { other.handle = 0; } -Shader &Shader::operator =(Shader &&other) { +Shader &Shader::operator =(Shader &&other) noexcept { std::swap(handle, other.handle); return *this; } -void Shader::Source(const GLchar *src) { +void Shader::Source(const GLchar *src) noexcept { const GLchar* src_arr[] = { src }; glShaderSource(handle, 1, src_arr, nullptr); } -void Shader::Compile() { +void Shader::Compile() noexcept { glCompileShader(handle); } -bool Shader::Compiled() const { +bool Shader::Compiled() const noexcept { GLint compiled = GL_FALSE; glGetShaderiv(handle, GL_COMPILE_STATUS, &compiled); return compiled == GL_TRUE; @@ -77,7 +77,7 @@ void Shader::Log(std::ostream &out) const { } -void Shader::AttachToProgram(GLuint id) const { +void Shader::AttachToProgram(GLuint id) const noexcept { glAttachShader(id, handle); } @@ -109,15 +109,15 @@ const Shader &Program::LoadShader(GLenum type, const GLchar *src) { return shader; } -void Program::Attach(Shader &shader) { +void Program::Attach(Shader &shader) noexcept { shader.AttachToProgram(handle); } -void Program::Link() { +void Program::Link() noexcept { glLinkProgram(handle); } -bool Program::Linked() const { +bool Program::Linked() const noexcept { GLint linked = GL_FALSE; glGetProgramiv(handle, GL_LINK_STATUS, &linked); return linked == GL_TRUE; @@ -132,11 +132,11 @@ void Program::Log(std::ostream &out) const { } -GLint Program::AttributeLocation(const GLchar *name) const { +GLint Program::AttributeLocation(const GLchar *name) const noexcept { return glGetAttribLocation(handle, name); } -GLint Program::UniformLocation(const GLchar *name) const { +GLint Program::UniformLocation(const GLchar *name) const noexcept { return glGetUniformLocation(handle, name); } @@ -209,7 +209,7 @@ DirectionalLighting::DirectionalLighting() } -void DirectionalLighting::Activate() { +void DirectionalLighting::Activate() noexcept { GLContext::EnableDepthTest(); GLContext::EnableBackfaceCulling(); program.Use(); @@ -218,7 +218,7 @@ void DirectionalLighting::Activate() { glUniform3f(light_color_handle, light_color.x, light_color.y, light_color.z); } -void DirectionalLighting::SetM(const glm::mat4 &m) { +void DirectionalLighting::SetM(const glm::mat4 &m) noexcept { glm::mat4 mv(view * m); glm::mat4 mvp(vp * m); glUniformMatrix4fv(m_handle, 1, GL_FALSE, &m[0][0]); @@ -226,33 +226,33 @@ void DirectionalLighting::SetM(const glm::mat4 &m) { glUniformMatrix4fv(mvp_handle, 1, GL_FALSE, &mvp[0][0]); } -void DirectionalLighting::SetLightDirection(const glm::vec3 &dir) { +void DirectionalLighting::SetLightDirection(const glm::vec3 &dir) noexcept { light_direction = -dir; glUniform3f(light_direction_handle, light_direction.x, light_direction.y, light_direction.z); } -void DirectionalLighting::SetFogDensity(float f) { +void DirectionalLighting::SetFogDensity(float f) noexcept { fog_density = f; glUniform1f(fog_density_handle, fog_density); } -void DirectionalLighting::SetProjection(const glm::mat4 &p) { +void DirectionalLighting::SetProjection(const glm::mat4 &p) noexcept { projection = p; vp = p * view; } -void DirectionalLighting::SetView(const glm::mat4 &v) { +void DirectionalLighting::SetView(const glm::mat4 &v) noexcept { view = v; vp = projection * v; } -void DirectionalLighting::SetVP(const glm::mat4 &v, const glm::mat4 &p) { +void DirectionalLighting::SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept { projection = p; view = v; vp = p * v; } -void DirectionalLighting::SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) { +void DirectionalLighting::SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept { SetVP(v, p); SetM(m); } @@ -313,41 +313,41 @@ BlockLighting::BlockLighting() } -void BlockLighting::Activate() { +void BlockLighting::Activate() noexcept { GLContext::EnableDepthTest(); GLContext::EnableBackfaceCulling(); program.Use(); } -void BlockLighting::SetM(const glm::mat4 &m) { +void BlockLighting::SetM(const glm::mat4 &m) noexcept { glm::mat4 mv(view * m); glm::mat4 mvp(vp * m); glUniformMatrix4fv(mv_handle, 1, GL_FALSE, &mv[0][0]); glUniformMatrix4fv(mvp_handle, 1, GL_FALSE, &mvp[0][0]); } -void BlockLighting::SetFogDensity(float f) { +void BlockLighting::SetFogDensity(float f) noexcept { fog_density = f; glUniform1f(fog_density_handle, fog_density); } -void BlockLighting::SetProjection(const glm::mat4 &p) { +void BlockLighting::SetProjection(const glm::mat4 &p) noexcept { projection = p; vp = p * view; } -void BlockLighting::SetView(const glm::mat4 &v) { +void BlockLighting::SetView(const glm::mat4 &v) noexcept { view = v; vp = projection * v; } -void BlockLighting::SetVP(const glm::mat4 &v, const glm::mat4 &p) { +void BlockLighting::SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept { projection = p; view = v; vp = p * v; } -void BlockLighting::SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) { +void BlockLighting::SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept { SetVP(v, p); SetM(m); } diff --git a/src/shader.hpp b/src/shader.hpp index bb9ad84..df625c6 100644 --- a/src/shader.hpp +++ b/src/shader.hpp @@ -15,18 +15,18 @@ public: explicit Shader(GLenum type); ~Shader(); - Shader(Shader &&); - Shader &operator =(Shader &&); + Shader(Shader &&) noexcept; + Shader &operator =(Shader &&) noexcept; Shader(const Shader &) = delete; Shader &operator =(const Shader &) = delete; - void Source(const GLchar *src); - void Compile(); - bool Compiled() const; + void Source(const GLchar *src) noexcept; + void Compile() noexcept; + bool Compiled() const noexcept; void Log(std::ostream &) const; - void AttachToProgram(GLuint id) const; + void AttachToProgram(GLuint id) const noexcept; private: GLuint handle; @@ -44,15 +44,15 @@ public: Program &operator =(const Program &) = delete; const Shader &LoadShader(GLenum type, const GLchar *src); - void Attach(Shader &); - void Link(); - bool Linked() const; + void Attach(Shader &) noexcept; + void Link() noexcept; + bool Linked() const noexcept; void Log(std::ostream &) const; - GLint AttributeLocation(const GLchar *name) const; - GLint UniformLocation(const GLchar *name) const; + GLint AttributeLocation(const GLchar *name) const noexcept; + GLint UniformLocation(const GLchar *name) const noexcept; - void Use() const { glUseProgram(handle); } + void Use() const noexcept { glUseProgram(handle); } private: GLuint handle; @@ -66,21 +66,21 @@ class DirectionalLighting { public: DirectionalLighting(); - void Activate(); + void Activate() noexcept; - void SetLightDirection(const glm::vec3 &); + void SetLightDirection(const glm::vec3 &) noexcept; - void SetFogDensity(float); + void SetFogDensity(float) noexcept; - void SetM(const glm::mat4 &m); - void SetProjection(const glm::mat4 &p); - void SetView(const glm::mat4 &v); - void SetVP(const glm::mat4 &v, const glm::mat4 &p); - void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p); + void SetM(const glm::mat4 &m) noexcept; + void SetProjection(const glm::mat4 &p) noexcept; + void SetView(const glm::mat4 &v) noexcept; + void SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept; + void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept; - const glm::mat4 &Projection() const { return projection; } - const glm::mat4 &View() const { return view; } - const glm::mat4 &GetVP() const { return vp; } + const glm::mat4 &Projection() const noexcept { return projection; } + const glm::mat4 &View() const noexcept { return view; } + const glm::mat4 &GetVP() const noexcept { return vp; } private: Program program; @@ -108,19 +108,19 @@ class BlockLighting { public: BlockLighting(); - void Activate(); + void Activate() noexcept; - void SetFogDensity(float); + void SetFogDensity(float) noexcept; - void SetM(const glm::mat4 &m); - void SetProjection(const glm::mat4 &p); - void SetView(const glm::mat4 &v); - void SetVP(const glm::mat4 &v, const glm::mat4 &p); - void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p); + void SetM(const glm::mat4 &m) noexcept; + void SetProjection(const glm::mat4 &p) noexcept; + void SetView(const glm::mat4 &v) noexcept; + void SetVP(const glm::mat4 &v, const glm::mat4 &p) noexcept; + void SetMVP(const glm::mat4 &m, const glm::mat4 &v, const glm::mat4 &p) noexcept; - const glm::mat4 &Projection() const { return projection; } - const glm::mat4 &View() const { return view; } - const glm::mat4 &GetVP() const { return vp; } + const glm::mat4 &Projection() const noexcept { return projection; } + const glm::mat4 &View() const noexcept { return view; } + const glm::mat4 &GetVP() const noexcept { return vp; } private: Program program; diff --git a/src/shape.cpp b/src/shape.cpp index 545a8e4..59e4f1f 100644 --- a/src/shape.cpp +++ b/src/shape.cpp @@ -75,7 +75,7 @@ bool NullShape::Intersects( const Ray &, const glm::mat4 &, float &, glm::vec3 & -) const { +) const noexcept { return false; } @@ -162,7 +162,7 @@ bool CuboidShape::Intersects( const Ray &ray, const glm::mat4 &M, float &dist, glm::vec3 &normal -) const { +) const noexcept { return Intersection(ray, bb, M, &dist, &normal); } @@ -294,7 +294,7 @@ bool StairShape::Intersects( const glm::mat4 &M, float &dist, glm::vec3 &norm -) const { +) const noexcept { float top_dist, bot_dist; glm::vec3 top_norm, bot_norm; bool top_hit = Intersection(ray, top, M, &top_dist, &top_norm); diff --git a/src/shape.hpp b/src/shape.hpp index abf8795..4120f76 100644 --- a/src/shape.hpp +++ b/src/shape.hpp @@ -13,14 +13,14 @@ namespace blank { struct Shape { /// the number of vertices (and normals) this shape has - size_t VertexCount() const { return vtx_pos.size(); } + size_t VertexCount() const noexcept { return vtx_pos.size(); } /// the number of vertex indices this shape has - size_t VertexIndexCount() const { return vtx_idx.size(); } + size_t VertexIndexCount() const noexcept { return vtx_idx.size(); } - const Model::Normal &VertexNormal(size_t idx) const { return vtx_nrm[idx]; } + const Model::Normal &VertexNormal(size_t idx) const noexcept { return vtx_nrm[idx]; } Model::Normal VertexNormal( size_t idx, const glm::mat4 &transform - ) const { + ) const noexcept { return Model::Normal(transform * glm::vec4(vtx_nrm[idx], 0.0f)); } @@ -68,7 +68,7 @@ struct Shape { const glm::mat4 &, float &dist, glm::vec3 &normal - ) const = 0; + ) const noexcept = 0; protected: void SetShape(const Model::Positions &pos, const Model::Normals &nrm, const Model::Indices &idx) { @@ -98,7 +98,7 @@ class NullShape public: NullShape(); - bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const override; + bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override; }; @@ -109,7 +109,7 @@ class CuboidShape public: CuboidShape(const AABB &bounds); - bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const override; + bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override; private: AABB bb; @@ -123,7 +123,7 @@ class StairShape public: StairShape(const AABB &bounds, const glm::vec2 &clip); - bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const override; + bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const noexcept override; private: AABB top, bot;