Skip to content

Commit

Permalink
Remove namespace Block
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopson97 committed Jul 28, 2017
1 parent 49bf655 commit 6fbef8c
Show file tree
Hide file tree
Showing 22 changed files with 265 additions and 346 deletions.
2 changes: 1 addition & 1 deletion Source/Renderer/MasterRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void MasterRenderer::clear()

void MasterRenderer::update(const Camera& camera)
{
Block::Database::get().getTextureAtlas().bind();
BlockDatabase::get().getTextureAtlas().bind();

glEnable(GL_DEPTH_TEST);
m_simpleRenderer.update(camera);
Expand Down
2 changes: 1 addition & 1 deletion Source/Renderer/SimpleRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace

SimpleRenderer::SimpleRenderer()
{
auto& textureAtlas = Block::Database::get().getTextureAtlas();
auto& textureAtlas = BlockDatabase::get().getTextureAtlas();
insertTextureCoords(textureAtlas.getTextureCoords({1, 0}));
insertTextureCoords(textureAtlas.getTextureCoords({1, 0}));
insertTextureCoords(textureAtlas.getTextureCoords({1, 0}));
Expand Down
128 changes: 56 additions & 72 deletions Source/World/Block/BlockData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,83 +7,67 @@

#include "../../Util/STD_Util.h"

namespace Block
BlockData::BlockData(std::string&& fileName)
: m_fileName (std::move(fileName))
{
BlockData::BlockData(std::string&& fileName)
: m_fileName (std::move(fileName))
std::string fullName = "Data/Blocks/" + m_fileName + ".block";
Loader::load(fullName);
}

bool BlockData::parseLine(const std::string& line, std::ifstream& inFile)
{
if(areStringsSame(line, "Name"))
{
std::string fullName = "Data/Blocks/" + m_fileName + ".block";
Loader::load(fullName);
std::getline(inFile, m_holder.name);
}

bool BlockData::parseLine(const std::string& line, std::ifstream& inFile)
else if (areStringsSame(line, "ID"))
{
loadEnum(inFile, m_holder.blockID);
}
else if (areStringsSame(line, "Opaque"))
{
inFile >> m_holder.isOpaque;
}
else if (areStringsSame(line, "Obstacle"))
{
inFile >> m_holder.isObstacle;
}
else if (areStringsSame(line, "Update"))
{
if(areStringsSame(line, "Name"))
{
std::getline(inFile, m_holder.name);
}
else if (areStringsSame(line, "ID"))
{
loadEnum(inFile, m_holder.blockID);
}
else if (areStringsSame(line, "Opaque"))
{
inFile >> m_holder.isOpaque;
}
else if (areStringsSame(line, "Obstacle"))
{
inFile >> m_holder.isObstacle;
}
else if (areStringsSame(line, "Update"))
{
inFile >> m_holder.canUpdate;
}
else if (areStringsSame(line, "Mesht"))
{
loadEnum(inFile, m_holder.meshType);
}
else if (areStringsSame(line, "Style"))
{
loadEnum(inFile, m_holder.meshStyle);
}
else if (areStringsSame(line, "State"))
{
loadEnum(inFile, m_holder.state);
}
else if (areStringsSame(line, "Texture Top"))
{
inFile >> m_holder.topTextureCoords.x
>> m_holder.topTextureCoords.y;
}
else if (areStringsSame(line, "Texture Side"))
{
inFile >> m_holder.sideTextureCoords.x
>> m_holder.sideTextureCoords.y;
}
else if (areStringsSame(line, "Texture Bottom"))
{
inFile >> m_holder.bottomTextureCoords.x
>> m_holder.bottomTextureCoords.y;
}
else
{
return false;
}
return true;
inFile >> m_holder.canUpdate;
}
else if (areStringsSame(line, "Mesht"))
{
loadEnum(inFile, m_holder.meshType);
}
else if (areStringsSame(line, "Style"))
{
loadEnum(inFile, m_holder.meshStyle);
}
else if (areStringsSame(line, "State"))
{
loadEnum(inFile, m_holder.state);
}
else if (areStringsSame(line, "Texture Top"))
{
inFile >> m_holder.topTextureCoords.x
>> m_holder.topTextureCoords.y;
}
else if (areStringsSame(line, "Texture Side"))
{
inFile >> m_holder.sideTextureCoords.x
>> m_holder.sideTextureCoords.y;
}
else if (areStringsSame(line, "Texture Bottom"))
{
inFile >> m_holder.bottomTextureCoords.x
>> m_holder.bottomTextureCoords.y;
}
else
{
return false;
}
return true;
}















128 changes: 63 additions & 65 deletions Source/World/Block/BlockData.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,69 @@
#include "../../Maths/GLM.h"
#include "../../Util/Loader.h"

namespace Block
enum class MeshType
{
enum MeshType
{
Solid = 0,
Flora = 1,
Liquid = 2,
};

enum MeshStyle
{
Block = 0,
XStyle = 1
};

enum class State
{
Solid = 0,
Liquid = 1,
Gas = 2
};

struct DataHolder
{
DataHolder() = default;
DataHolder(DataHolder& other) = delete;

ID blockID;
std::string name;

bool isOpaque = true;
bool isObstacle = true;
bool canUpdate = false;

MeshType meshType = MeshType ::Solid;
MeshStyle meshStyle = MeshStyle ::Block;
State state = State ::Solid;

Vector2 topTextureCoords;
Vector2 sideTextureCoords;
Vector2 bottomTextureCoords;
};

class BlockData : public Loader
{
public:
BlockData(std::string&& fileName);

const DataHolder& get() const { return m_holder; }

private:
bool parseLine (const std::string& line, std::ifstream& stream) override;

template<typename T>
void loadEnum(std::ifstream& stream, T& BlockData)
{
int32_t val;
stream >> val;
BlockData = static_cast<T>(val);
}

std::string m_fileName;

DataHolder m_holder;
};
}
Solid = 0,
Flora = 1,
Liquid = 2,
};

enum class MeshStyle
{
Block = 0,
XStyle = 1
};

enum class State
{
Solid = 0,
Liquid = 1,
Gas = 2
};

struct BlockDataHolder
{
BlockDataHolder() = default;
BlockDataHolder(BlockDataHolder& other) = delete;

BlockID blockID;
std::string name;

bool isOpaque = true;
bool isObstacle = true;
bool canUpdate = false;

MeshType meshType = MeshType::Solid;
MeshStyle meshStyle = MeshStyle::Block;
State state = State::Solid;

Vector2 topTextureCoords;
Vector2 sideTextureCoords;
Vector2 bottomTextureCoords;
};

class BlockData : public Loader
{
public:
BlockData(std::string&& fileName);

const BlockDataHolder& get() const { return m_holder; }

private:
bool parseLine (const std::string& line, std::ifstream& stream) override;

template<typename T>
void loadEnum(std::ifstream& stream, T& BlockData)
{
int32_t val;
stream >> val;
BlockData = static_cast<T>(val);
}

std::string m_fileName;

BlockDataHolder m_holder;
};


#endif // BlockBlockData_H_INCLUDED
85 changes: 40 additions & 45 deletions Source/World/Block/BlockDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,58 @@
#include <iostream>


#include "Types/BDefault.h"
#include "Types/BPlant.h"
#include "Types/BWater.h"
#include "Types/DefaultBlock.h"
#include "Types/PlantBlock.h"

#include "../../Util/FileUtil.h"

namespace Block
BlockDatabase& BlockDatabase::get()
{
Database& Database::get()
{
static Database database;
return database;
}

Database::Database()
: m_textures ("Atlas/Low", 512, 16)
{
m_blocks[(int)ID::Air ] = std::make_unique<Default> ("Air");
m_blocks[(int)ID::Grass ] = std::make_unique<Default> ("Grass");
m_blocks[(int)ID::Dirt ] = std::make_unique<Default> ("Dirt");
m_blocks[(int)ID::Stone ] = std::make_unique<Default> ("Stone");
m_blocks[(int)ID::Sand ] = std::make_unique<Default> ("Sand");
static BlockDatabase database;
return database;
}

m_blocks[(int)ID::Oak_Wood ] = std::make_unique<Default> ("Oak_Wood");
m_blocks[(int)ID::Oak_Leaf ] = std::make_unique<Default> ("Oak_Leaf");
BlockDatabase::BlockDatabase()
: m_textures ("Atlas/Low", 512, 16)
{
m_blocks[(int)BlockID::Air ] = std::make_unique<DefaultBlock> ("Air");
m_blocks[(int)BlockID::Grass ] = std::make_unique<DefaultBlock> ("Grass");
m_blocks[(int)BlockID::Dirt ] = std::make_unique<DefaultBlock> ("Dirt");
m_blocks[(int)BlockID::Stone ] = std::make_unique<DefaultBlock> ("Stone");
m_blocks[(int)BlockID::Sand ] = std::make_unique<DefaultBlock> ("Sand");

m_blocks[(int)ID::Water ] = std::make_unique<BWater> ();
m_blocks[(int)BlockID::Oak_Wood ] = std::make_unique<DefaultBlock> ("Oak_Wood");
m_blocks[(int)BlockID::Oak_Leaf ] = std::make_unique<DefaultBlock> ("Oak_Leaf");

m_blocks[(int)ID::Rose ] = std::make_unique<BPlant> ("Rose");
m_blocks[(int)ID::Tall_Grass ] = std::make_unique<BPlant> ("Tall_Grass");
}
m_blocks[(int)BlockID::Water ] = std::make_unique<DefaultBlock> ("Water");

const BlockType& Database::getBlock(uint8_t id) const
{
return *m_blocks[id];
}
m_blocks[(int)BlockID::Rose ] = std::make_unique<PlantBlock> ("Rose");
m_blocks[(int)BlockID::Tall_Grass ] = std::make_unique<PlantBlock> ("Tall_Grass");
}

const BlockType& Database::getBlock(ID blockID) const
{
return *m_blocks[(int)blockID];
}
const BlockType& BlockDatabase::getBlock(uint8_t id) const
{
return *m_blocks[id];
}

const TextureAtlas& Database::getTextureAtlas() const
{
return m_textures;
}
const BlockType& BlockDatabase::getBlock(BlockID blockID) const
{
return *m_blocks[(int)blockID];
}

const TextureAtlas& BlockDatabase::getTextureAtlas() const
{
return m_textures;
}

const BlockType& get(uint8_t id)
{
return BlockDatabase::get().getBlock(id);
}

const BlockType& get(uint8_t id)
{
return Database::get().getBlock(id);
}
const BlockType& get(BlockID blockID)
{
return BlockDatabase::get().getBlock(blockID);
}

const BlockType& get(ID blockID)
{
return Database::get().getBlock(blockID);
}

}
Loading

0 comments on commit 6fbef8c

Please sign in to comment.