Add documentation

This commit is contained in:
2025-01-06 13:45:18 -06:00
parent 57ceb8adce
commit 5d042e9353
5 changed files with 105 additions and 62 deletions

View File

@@ -13,10 +13,14 @@
namespace CaveGame::Client
{
enum AssetType { DATA, TEXT, AUDIO, MODEL, TEXTURE, FONT, SHADER };
enum AssetLifestyle { STATIC, STREAMED};
struct Asset {
std::string name;
std::string metadata;
std::string type;
};
class AssetService {

View File

@@ -20,7 +20,7 @@ namespace CaveGame::Client
public:
/// The default constructor does not initialize any values.
Camera2D();
void UpdateFreecamControls(float delta);
/// Performs one iteration of the camera's internal logic.
/// @param elapsed The delta-time (in seconds) between this iteration and the last.
@@ -46,6 +46,9 @@ namespace CaveGame::Client
/// Sets the amount of zoom in the camera transformation.
void Zoom(float val);
void SetFreeCam(bool freeCam);
bool GetFreeCam() const;
/// Zooms the camera in by the given amount.
void ZoomIn(float amt);
void ZoomOut(float amt);
@@ -106,6 +109,9 @@ namespace CaveGame::Client
/// Sets the base movement speed of the camera.
void MoveSpeed(float value);
protected:
// Process user-input for freecam.
void UpdateFreecamControls(float delta);
protected:
Vector2 velocity;
Vector2 position;

View File

@@ -5,7 +5,7 @@
/// This work is dedicated to the public domain.
/// @file Chunk.hpp
/// @desc A subdivision of the gameworld into discretized blocks.
/// @desc A subdivision of the game-world into discrete blocks.
/// @edit 12/2/2024
#pragma once
@@ -21,49 +21,35 @@ namespace CaveGame::Core
class Chunk {
public:
static constexpr int ChunkSize = 256;
static constexpr int ChunkSize = 128;
public:
/// The default constructor does not initialize any members.
Chunk() = default;
~Chunk()
{
}
~Chunk() { }
/// Constructs a chunk with empty (air) tiles, located at the given chunk-cell.
/// @param cell_coords Specifies the chunk-cell this chunk will occupy.
explicit Chunk(const Vector2 &cell_coords);
/// Constructs a chunk from a filesystem path. This constructor will load and parse the chunk file.
explicit Chunk(const Vector2 &cell_coords, const std::filesystem::path &file);
explicit Chunk(const Vector2 &cell_coords, const std::filesystem::path &file) : Chunk(cell_coords)
{
std::ifstream inp;
inp.open(file, std::ios::binary | std::ios::in);
inp.seekg(0, std::ios::end);
int length = inp.tellg();
inp.seekg(0, std::ios::beg);
char buffer[length];
inp.read(buffer, length);
inp.close();
SetData(buffer);
}
/// Returns the TileID enumeration that occupies the given tile-cell.
TileID GetTile(int x, int y) const;
/// Sets the tile ID at the given tile-cell.
/// @param trigger_tile_updates Whether to force adjacent tiles to update.
void SetTile(int x, int y, TileID t, bool trigger_tile_updates = true);
void SetTileSilent(int x, int y, TileID t)
{ SetTile(x, y, t, false); }
/// Sets the tile ID at the given tile-cell, and explicitly does not update adjacent tiles.
void SetTileSilent(int x, int y, TileID t);
bool GetTileUpdateFlag(int x, int y) const {
return tagged_for_update[x][y];
}
/// Returns the value of the update flag field at the given tile-cell.
bool GetTileUpdateFlag(int x, int y) const;
void SetTileUpdateFlag(int x, int y, bool flag = true) {
tagged_for_update[x][y] = flag;
}
/// Sets the value of the update flag field at the given tile-cell.A
void SetTileUpdateFlag(int x, int y, bool flag = true);
[[nodiscard]] Vector2 GetChunkCell() const;
[[nodiscard]] Vector2 GetChunkRealCoordinates() const;
@@ -71,41 +57,14 @@ namespace CaveGame::Core
[[nodiscard]] const TileID* ptr() const { return &tiles[0][0];}
[[nodiscard]] std::vector<TileID> DataContiguous() const
{
std::vector<TileID> data;
data.reserve(ChunkSize*ChunkSize);
for (int x = 0; x < ChunkSize; x++) {
for (int y = 0; y < ChunkSize; y++) {
data.push_back(tiles[x][y]);
}
}
return data;
}
[[nodiscard]] std::vector<TileID> DataContiguous() const;
void SetData(char* buffer)
{
auto* data = reinterpret_cast<TileID*>(buffer);
void SetData(char* buffer);
[[nodiscard]] static constexpr std::size_t BufferSizeBytes();
for (int x = 0; x < ChunkSize; x++)
{
for (int y = 0; y < ChunkSize; y++)
{
tiles[x][y] = data[y+(x*ChunkSize)];
}
}
}
[[nodiscard]] static constexpr std::size_t BufferSize();
[[nodiscard]] static constexpr std::size_t BufferSizeBytes()
{
return (ChunkSize*ChunkSize)*sizeof(TileID);
}
[[nodiscard]] static constexpr std::size_t BufferSize()
{
return (ChunkSize*ChunkSize);
}
public:
bool touched;
protected:
@@ -114,4 +73,14 @@ namespace CaveGame::Core
bool tagged_for_update[ChunkSize][ChunkSize];
};
}
constexpr std::size_t Chunk::BufferSizeBytes()
{
return (ChunkSize*ChunkSize)*sizeof(TileID);
}
constexpr std::size_t Chunk::BufferSize()
{
return (ChunkSize*ChunkSize);
}
}

View File

@@ -250,8 +250,17 @@ namespace CaveGame::Core
GravityTile(TileID id, const std::string& name, const Color4& color, const std::vector<Color4>& pallet);
bool DoesForcedTicc() const override { return true;}
bool DoesRandomTicc() const override { return true;}
void ForcedTicc(ITileMap *world, TileState state, int x, int y) override {
if (world->GetTile(x, y+1) == TileID::AIR) {
if (world->GetTile(x, y+2) == TileID::AIR)
{
world->SetTile(x, y+2, numeric_id);
world->SetTile(x, y, TileID::AIR);
return;
}
world->SetTile(x, y+1, numeric_id);
world->SetTile(x, y, TileID::AIR);
return;

View File

@@ -28,6 +28,19 @@ namespace CaveGame::Core
}
}
void Chunk::SetTileSilent(int x, int y, TileID t)
{ SetTile(x, y, t, false); }
bool Chunk::GetTileUpdateFlag(int x, int y) const
{
return tagged_for_update[x][y];
}
void Chunk::SetTileUpdateFlag(int x, int y, bool flag)
{
tagged_for_update[x][y] = flag;
}
TileID Chunk::GetTile(int x, int y) const {
if (!(0 <= x && x < ChunkSize || 0 <= y && y < ChunkSize))
throw std::runtime_error("Out of bounds!");
@@ -37,10 +50,52 @@ namespace CaveGame::Core
Chunk::Chunk(const Vector2 &cell_coords) : cell(cell_coords)
{ }
Chunk::Chunk(const Vector2& cell_coords, const std::filesystem::path& file): Chunk(cell_coords)
{
std::ifstream inp;
inp.open(file, std::ios::binary | std::ios::in);
inp.seekg(0, std::ios::end);
int length = inp.tellg();
inp.seekg(0, std::ios::beg);
char buffer[length];
inp.read(buffer, length);
inp.close();
SetData(buffer);
}
Vector2 Chunk::GetChunkRealCoordinates() const {
return GetChunkCell()*Core::Chunk::ChunkSize;
}
std::vector<TileID> Chunk::DataContiguous() const
{
std::vector<TileID> data;
data.reserve(ChunkSize*ChunkSize);
for (int x = 0; x < ChunkSize; x++) {
for (int y = 0; y < ChunkSize; y++) {
data.push_back(tiles[x][y]);
}
}
return data;
}
void Chunk::SetData(char* buffer)
{
auto* data = reinterpret_cast<TileID*>(buffer);
for (int x = 0; x < ChunkSize; x++)
{
for (int y = 0; y < ChunkSize; y++)
{
tiles[x][y] = data[y+(x*ChunkSize)];
}
}
}
Vector2 Chunk::GetChunkCell() const { return cell;}
}