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;
}
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)
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);
}
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);
}
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);
}
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<int> FaceNormal(Face face) {
+ static glm::tvec3<int> 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) {
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;
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)];
}
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;
};
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<BlockType> types;
namespace blank {
-Camera::Camera()
+Camera::Camera() noexcept
: fov(PI_0p25)
, aspect(1.0f)
, near_clip(0.1f)
}
-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);
}
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;
#include <algorithm>
#include <limits>
#include <queue>
-#include <glm/gtx/transform.hpp>
namespace blank {
-Chunk::Chunk(const BlockTypeRegistry &types)
+Chunk::Chunk(const BlockTypeRegistry &types) noexcept
: types(&types)
, neighbor{0}
, blocks{}
}
-Chunk::Chunk(Chunk &&other)
+Chunk::Chunk(Chunk &&other) noexcept
: types(other.types)
, model(std::move(other.model))
, position(other.position)
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);
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());
}
: 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<SetNode> light_queue;
std::queue<UnsetNode> dark_queue;
-void work_light() {
+void work_light() noexcept {
while (!light_queue.empty()) {
SetNode node = light_queue.front();
light_queue.pop();
}
}
-void work_dark() {
+void work_dark() noexcept {
while (!dark_queue.empty()) {
UnsetNode node = dark_queue.front();
dark_queue.pop();
}
-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);
}
}
-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;
}
}
-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;
}
}
-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;
}
-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));
}
-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;
}
-void Chunk::Draw() {
+void Chunk::Draw() noexcept {
if (dirty) {
Update();
}
int &blkid,
float &dist,
glm::vec3 &normal
-) const {
+) const noexcept {
// TODO: should be possible to heavily optimize this
int id = 0;
blkid = -1;
}
}
-void Chunk::Position(const Pos &pos) {
- position = pos;
-}
-
-glm::mat4 Chunk::Transform(const Pos &offset) const {
- return glm::translate((position - offset) * Extent());
-}
-
namespace {
}
-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;
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;
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)) {
}
}
-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)) {
}
-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)
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
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;
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;
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);
}
#include <list>
#include <vector>
#include <glm/glm.hpp>
+#include <glm/gtx/transform.hpp>
namespace blank {
using Pos = glm::tvec3<int>;
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
(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);
}
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;
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;
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<Chunk> &Loaded() { return loaded; }
+ std::list<Chunk> &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 &);
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;
namespace blank {
-FPSController::FPSController(Entity &entity)
+FPSController::FPSController(Entity &entity) noexcept
: entity(entity)
, pitch(0)
, yaw(0) {
}
-void FPSController::Pitch(float p) {
+void FPSController::Pitch(float p) noexcept {
pitch = p;
if (pitch > PI / 2) {
pitch = PI / 2;
}
}
-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;
}
}
-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);
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;
class RandomWalk {
public:
- explicit RandomWalk(Entity &);
+ explicit RandomWalk(Entity &) noexcept;
- void Update(int dt);
+ void Update(int dt) noexcept;
private:
Entity &entity;
namespace blank {
-Entity::Entity()
+Entity::Entity() noexcept
: shape(nullptr)
, model()
, velocity(0, 0, 0)
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();
}
}
-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;
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();
}
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;
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)
}
-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) {
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<Block::Type> &s) { solids = s; }
private:
const glm::mat4 &M,
float *dist,
glm::vec3 *normal
-) {
+) noexcept {
float t_min = 0.0f;
float t_max = std::numeric_limits<float>::infinity();
const glm::vec3 aabb_pos(M[3].x, M[3].y, M[3].z);
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 },
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);
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;
}
+++ /dev/null
-#ifndef BLANKL_GLMIO_HPP_
-#define BLANKL_GLMIO_HPP_
-
-#include <ostream>
-#include <glm/glm.hpp>
-
-
-namespace blank {
-
-template<class T>
-std::ostream &operator <<(std::ostream &out, const glm::tvec3<T> &v) {
- return out << '<' << v.x << ", " << v.y << ", " << v.z << '>';
-}
-
-template<class T>
-std::ostream &operator <<(std::ostream &out, const glm::tvec4<T> &v) {
- return out << '<' << v.x << ", " << v.y << ", " << v.z << ", " << v.w << '>';
-}
-
-template<class T>
-std::ostream &operator <<(std::ostream &out, const glm::tmat4x4<T> &m) {
- return out << '[' << m[0] << ", " << m[1] << ", " << m[2] << ", " << m[3] << ']';
-}
-
-}
-
-#endif
}
-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());
}
-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
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;
}
}
-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);
}
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;
mod_chunk->Invalidate();
}
-void Interface::RemoveBlock() {
+void Interface::RemoveBlock() noexcept {
if (!aim_chunk) return;
aim_chunk->SetBlock(aim_block, remove);
aim_chunk->Invalidate();
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);
}
}
-void Interface::Render(DirectionalLighting &program) {
+void Interface::Render(DirectionalLighting &program) noexcept {
if (config.visual_disabled) return;
if (aim_chunk) {
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();
void Update(int dt);
- void Render(DirectionalLighting &);
+ void Render(DirectionalLighting &) noexcept;
private:
World &world;
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;
}
}
-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]);
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);
}
-void Model::Draw() const {
+void Model::Draw() const noexcept {
glBindVertexArray(va);
glDrawElements(
GL_TRIANGLES, // how
}
-BlockModel::BlockModel()
+BlockModel::BlockModel() noexcept
: va(0)
, handle{}
, count(0) {
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;
}
}
-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]);
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);
}
-void BlockModel::Draw() const {
+void BlockModel::Draw() const noexcept {
glBindVertexArray(va);
glDrawElements(
GL_TRIANGLES, // how
);
}
-OutlineModel::OutlineModel()
+OutlineModel::OutlineModel() noexcept
: vertices()
, colors()
, indices()
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();
}
-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);
}
-void OutlineModel::Draw() {
+void OutlineModel::Draw() noexcept {
glBindVertexArray(va);
if (dirty) {
Normals normals;
Indices indices;
- void Clear() {
+ void Clear() noexcept {
vertices.clear();
colors.clear();
normals.clear();
};
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 {
Lights lights;
Indices indices;
- void Clear() {
+ void Clear() noexcept {
vertices.clear();
colors.clear();
lights.clear();
};
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 {
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 {
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) {
}
-SimplexNoise::SimplexNoise(unsigned int seed)
+SimplexNoise::SimplexNoise(unsigned int seed) noexcept
: grad({
{ 1.0f, 1.0f, 0.0f },
{ -1.0f, 1.0f, 0.0f },
}
-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));
}
-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
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<class T>
- void operator ()(T &out) {
+ void operator ()(T &out) noexcept {
constexpr int num_bits =
std::numeric_limits<T>::digits +
std::numeric_limits<T>::is_signed;
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];
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;
namespace blank {
-Runtime::Runtime()
+Runtime::Runtime() noexcept
: name("blank")
, mode(NORMAL)
, n(0)
ERROR,
};
- Runtime();
+ Runtime() noexcept;
void ReadArgs(int argc, const char *const *argv);
}
}
-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;
}
-void Shader::AttachToProgram(GLuint id) const {
+void Shader::AttachToProgram(GLuint id) const noexcept {
glAttachShader(id, handle);
}
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;
}
-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);
}
}
-void DirectionalLighting::Activate() {
+void DirectionalLighting::Activate() noexcept {
GLContext::EnableDepthTest();
GLContext::EnableBackfaceCulling();
program.Use();
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]);
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);
}
}
-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);
}
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;
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;
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;
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;
const Ray &,
const glm::mat4 &,
float &, glm::vec3 &
-) const {
+) const noexcept {
return false;
}
const Ray &ray,
const glm::mat4 &M,
float &dist, glm::vec3 &normal
-) const {
+) const noexcept {
return Intersection(ray, bb, M, &dist, &normal);
}
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);
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));
}
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) {
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;
};
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;
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;