Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "block.h"
- #include "graphics\texture_loader.h"
- #include <GL\glew.h>
- uint32 Block::textureID = 0;
- bool Block::initialized = false;
- std::map<uint16, Block> Block::idMap = std::map<uint16, Block>();
- std::map<std::string, Block> Block::nameMap = std::map<std::string, Block>();
- uint32 Block::GetTextureID()
- {
- return textureID;
- }
- bool Block::IdInUse(uint16 id)
- {
- return idMap.find(id) != idMap.end();
- }
- const Block& Block::GetBlock(uint16 id)
- {
- if (!IdInUse(id))
- {
- fprintf(stderr, "Could not find Block with ID %u.", (uint32)id);
- throw std::runtime_error("Could not find Block with passed id.");
- }
- return idMap.at(id);
- }
- bool Block::NameInUse(std::string name)
- {
- return nameMap.find(name) != nameMap.end();
- }
- const Block& Block::GetBlock(std::string name)
- {
- if (!NameInUse(name))
- {
- fprintf(stderr, "Could not find Block with name s.", name);
- throw std::runtime_error("Could not find Block with passed name.");
- }
- return nameMap.at(name);
- }
- //========================================Block=============================================
- Block::Block(std::string name, uint16 id, uint8 tex)
- {
- //Check for repeat ids
- if (IdInUse(id))
- {
- fprintf(stderr, "Block id %u is already in use!", (uint32)id);
- throw std::runtime_error("You cannot reuse block ids!");
- }
- _id = id;
- idMap.insert(std::make_pair(id, *this));
- //Check for repeat names
- if (NameInUse(name))
- {
- fprintf(stderr, "Block name %s is already in use!", name);
- throw std::runtime_error("You cannot reuse block names!");
- }
- _name = name;
- nameMap.insert(std::make_pair(name, *this));
- _tex = tex;
- fprintf(stdout, "Using texture %u\n", _tex);
- _transparent = false;
- }
- uint16 Block::GetID() const
- {
- return _id;
- }
- uint8 Block::GetIndex() const
- {
- fprintf(stdout, "Returning texture %u\n", _tex);
- return _tex;
- }
- std::string Block::GetName() const
- {
- return _name;
- }
- bool Block::IsTransparent() const
- {
- return _transparent;
- }
- void Block::setTransparent(bool b)
- {
- _transparent = b;
- }
- //=========Virtual Methods===========
- //=========================================================================================
- //=================================STATIC BLOCK INITIALIZATION=======================================
- const Block Block::Test = Block("Test", 1, 0);
- //=========================BLOCK DATA============================
- #define V1 glm::vec3(0.0f,0.0f,0.0f)
- #define V2 glm::vec3(1.0f,0.0f,0.0f)
- #define V3 glm::vec3(1.0f,0.0f,1.0f)
- #define V4 glm::vec3(0.0f,0.0f,1.0f)
- #define V5 glm::vec3(0.0f,1.0f,0.0f)
- #define V6 glm::vec3(1.0f,1.0f,0.0f)
- #define V7 glm::vec3(1.0f,1.0f,1.0f)
- #define V8 glm::vec3(0.0f,1.0f,1.0f)
- #define NXP glm::vec3(1.0f,0.0f,0.0f)
- #define NXN glm::vec3(-1.0f,0.0f,0.0f)
- #define NYP glm::vec3(0.0f,1.0f,0.0f)
- #define NYN glm::vec3(0.0f,-1.0f,0.0f)
- #define NZP glm::vec3(0.0f,0.0f,1.0f)
- #define NZN glm::vec3(0.0f,0.0f,-1.0f)
- const glm::vec3 Block::VERT_X_POS[6] = { V7, V6, V3, V6, V2, V3 };
- const glm::vec3 Block::VERT_X_NEG[6] = { V5, V8, V1, V8, V4, V1 };
- const glm::vec3 Block::VERT_Y_POS[6] = { V5, V6, V8, V6, V7, V8 };
- const glm::vec3 Block::VERT_Y_NEG[6] = { V1, V4, V2, V4, V3, V2 };
- const glm::vec3 Block::VERT_Z_POS[6] = { V8, V7, V4, V7, V3, V4 };
- const glm::vec3 Block::VERT_Z_NEG[6] = { V6, V5, V2, V5, V1, V2 };
- const glm::vec3 Block::NORM_X_POS = NXP;
- const glm::vec3 Block::NORM_X_NEG = NXN;
- const glm::vec3 Block::NORM_Y_POS = NYP;
- const glm::vec3 Block::NORM_Y_NEG = NYN;
- const glm::vec3 Block::NORM_Z_POS = NZP;
- const glm::vec3 Block::NORM_Z_NEG = NZN;
Advertisement
Add Comment
Please, Sign In to add comment