Move content registry, Object/BlockDef to Content namespace

master
Dorian Wouters 2016-08-11 22:39:03 +02:00
parent 41a326a737
commit dd04f4a968
No known key found for this signature in database
GPG Key ID: 6E9DA8063322434B
10 changed files with 56 additions and 51 deletions

View File

@ -281,7 +281,7 @@ void Chunk::updateClient() {
imcUncompress();
#endif
mut.lock();
ContentRegistry &CR = *G->CR;
Content::Registry &CR = *G->CR;
Vertex vertex[CX * CY * CZ * 6 /* faces */ * 4 /* vertices */ / 2 /* face removing (HSR) makes a lower vert max */];
GLushort idxOpaque[CX * CY * CZ * 6 /* faces */ * 6 /* indices */ / 2 /* HSR */],
idxTransp[CX*CY*CZ*6*6/2];

View File

@ -19,7 +19,7 @@ Game::Game() :
}
void Game::init() {
CR = new ContentRegistry;
CR = new Content::Registry;
LS = new Scripting::Lua::State(this);
if (GlobalProperties::IsClient) {
PM = new ProgramManager(*this);

View File

@ -11,6 +11,10 @@ using std::shared_ptr;
namespace Diggler {
namespace Content {
class Registry;
}
namespace Render {
class Renderer;
}
@ -26,7 +30,6 @@ class Manager;
}
class Audio;
class ContentRegistry;
class Config;
class GameWindow;
class KeyBinds;
@ -39,7 +42,7 @@ public:
Net::Host H;
Universe *U;
PlayerList players;
ContentRegistry *CR;
Content::Registry *CR;
Scripting::Lua::State *LS;
// Server

View File

@ -1,5 +1,5 @@
#ifndef DIGGLER_BLOCK_DEF_HPP
#define DIGGLER_BLOCK_DEF_HPP
#ifndef DIGGLER_CONTENT_BLOCK_DEF_HPP
#define DIGGLER_CONTENT_BLOCK_DEF_HPP
#include <unordered_map>
@ -9,6 +9,7 @@
//#include "../AABB.hpp"
namespace Diggler {
namespace Content {
class BlockDef : public ObjectDef {
public:
@ -51,6 +52,7 @@ public:
} phys;
};
}
}
#endif /* DIGGLER_BLOCK_DEF_HPP */
#endif /* DIGGLER_CONTENT_BLOCK_DEF_HPP */

View File

@ -1,7 +1,7 @@
#ifndef CONTENT_HPP
#define CONTENT_HPP
#ifndef DIGGLER_CONTENT_HPP
#define DIGGLER_CONTENT_HPP
#include "../Platform.hpp"
#include "../platform/Types.hpp"
#include <limits>
#include <type_traits>
@ -43,4 +43,4 @@ namespace Content {
}
}
#endif
#endif /* DIGGLER_CONTENT_HPP */

View File

@ -1,8 +1,9 @@
#ifndef OBJECT_DEF_HPP
#define OBJECT_DEF_HPP
#ifndef DIGGLER_CONTENT_OBJECT_DEF_HPP
#define DIGGLER_CONTENT_OBJECT_DEF_HPP
#include "../Platform.hpp"
namespace Diggler {
namespace Content {
class ObjectDef {
public:
@ -13,6 +14,7 @@ public:
};
};
}
}
#endif
#endif /* DIGGLER_CONTENT_OBJECT_DEF_HPP */

View File

@ -5,24 +5,23 @@
#define PRINT_BLOCK_REGISTRATIONS 1
namespace Diggler {
namespace Content {
using CR = ContentRegistry;
CR::BlockRegistration::BlockRegistration(ContentRegistry &registry,
const ContentRegistry::BlockNameMap::iterator &it) :
Registry::BlockRegistration::BlockRegistration(Registry &registry,
const Registry::BlockNameMap::iterator &it) :
registry(registry),
it(it),
state(Uncommitted),
def(it->second->second) {
}
CR::BlockRegistration::~BlockRegistration() {
Registry::BlockRegistration::~BlockRegistration() {
if (state == Uncommitted) {
registry.m_blocks.erase(it->second);
}
}
CR::BlockRegistration::BlockRegistration(CR::BlockRegistration &&o) :
Registry::BlockRegistration::BlockRegistration(Registry::BlockRegistration &&o) :
registry(o.registry),
it(o.it),
state(o.state),
@ -30,7 +29,7 @@ CR::BlockRegistration::BlockRegistration(CR::BlockRegistration &&o) :
o.state = Moved;
}
BlockId CR::BlockRegistration::commit() {
BlockId Registry::BlockRegistration::commit() {
state = Committed;
#if PRINT_BLOCK_REGISTRATIONS
getDebugStream() << "Registered block " << it->first << " with id " <<
@ -76,14 +75,14 @@ static const DefBlocksInfo DefBlocksInfos[] = {
{"diggler:transp_blue", "Force Field", 0, 0, 25, ANY, "translucent_blue.png"}
};
bool ContentRegistry::isTransparent(BlockId id) const {
bool Registry::isTransparent(BlockId id) const {
if (id == Content::BlockAirId)
return true;
return false;
// TODO return getBlockDef(id).isTransparent;
}
bool ContentRegistry::isFaceVisible(BlockId id1, BlockId id2) const {
bool Registry::isFaceVisible(BlockId id1, BlockId id2) const {
// TODO: node mesh/boxes -> not fullblock, faces may not be hidden
if (isTransparent(id1)) {
return (id1 != id2);
@ -92,7 +91,7 @@ bool ContentRegistry::isFaceVisible(BlockId id1, BlockId id2) const {
}
}
bool ContentRegistry::canEntityGoThrough(BlockId id/* , Entity& ent*/) const {
bool Registry::canEntityGoThrough(BlockId id/* , Entity& ent*/) const {
if (id == Content::BlockAirId)
return true;
return false;
@ -103,15 +102,15 @@ bool ContentRegistry::canEntityGoThrough(BlockId id/* , Entity& ent*/) const {
using Coord = TexturePacker::Coord;
static Coord unk1, unk2, unk3, unk4, unk5, unk6, unk7, unk8;
#define AddTex(b, t) Coord b = m_texturePacker->add(getAssetPath("blocks", t));
ContentRegistry::ContentRegistry() :
Registry::Registry() :
m_atlas(nullptr),
m_nextMaxBlockId(Content::BlockUnknownId + 1) {
{ ContentRegistry::BlockRegistration br(registerBlock(Content::BlockAirId, "air"));
{ Registry::BlockRegistration br(registerBlock(Content::BlockAirId, "air"));
br.def.appearance.look.type = BlockDef::Appearance::Look::Type::Hidden;
br.def.phys.hasCollision = false;
br.commit();
}
{ ContentRegistry::BlockRegistration br(registerBlock(Content::BlockUnknownId, "unknown"));
{ Registry::BlockRegistration br(registerBlock(Content::BlockUnknownId, "unknown"));
br.def.appearance.look.type = BlockDef::Appearance::Look::Type::Hidden;
br.def.phys.hasCollision = true;
br.commit();
@ -134,11 +133,11 @@ ContentRegistry::ContentRegistry() :
m_atlas = m_texturePacker->getAtlas();
}
ContentRegistry::~ContentRegistry() {
Registry::~Registry() {
delete m_texturePacker;
}
TexturePacker::Coord ContentRegistry::addTexture(const std::string &texName,
TexturePacker::Coord Registry::addTexture(const std::string &texName,
const std::string &path) {
const TexturePacker::Coord coord = m_texturePacker->add(path);
m_textureCoords.emplace(std::piecewise_construct,
@ -147,7 +146,7 @@ TexturePacker::Coord ContentRegistry::addTexture(const std::string &texName,
return coord;
}
const TexturePacker::Coord* ContentRegistry::blockTexCoord(BlockId t, FaceDirection d,
const TexturePacker::Coord* Registry::blockTexCoord(BlockId t, FaceDirection d,
const glm::ivec3 &pos) const {
if (t == Content::BlockUnknownId) {
const Coord *unk[] = {
@ -199,11 +198,11 @@ const TexturePacker::Coord* ContentRegistry::blockTexCoord(BlockId t, FaceDirect
return nullptr;
}
const Texture* ContentRegistry::getAtlas() const {
const Texture* Registry::getAtlas() const {
return m_atlas;
}
ContentRegistry::BlockRegistration ContentRegistry::registerBlock(BlockId id, const char *name) {
Registry::BlockRegistration Registry::registerBlock(BlockId id, const char *name) {
BlockIdMap::iterator bit = m_blocks.emplace(std::piecewise_construct,
std::forward_as_tuple(id),
std::forward_as_tuple())
@ -214,7 +213,7 @@ ContentRegistry::BlockRegistration ContentRegistry::registerBlock(BlockId id, co
.first);
}
ContentRegistry::BlockRegistration ContentRegistry::registerBlock(const char *name) {
Registry::BlockRegistration Registry::registerBlock(const char *name) {
BlockId id = Content::BlockUnknownId;
if (m_freedBlockIds.empty()) {
id = m_nextMaxBlockId;
@ -227,3 +226,4 @@ ContentRegistry::BlockRegistration ContentRegistry::registerBlock(const char *na
}
}
}

View File

@ -1,5 +1,5 @@
#ifndef CONTENT_REGISTRY_HPP
#define CONTENT_REGISTRY_HPP
#ifndef DIGGLER_CONTENT_REGISTRY_HPP
#define DIGGLER_CONTENT_REGISTRY_HPP
#include <unordered_map>
#include <vector>
@ -22,14 +22,16 @@ enum class FaceDirection : uint8_t {
ZDec = 5
};
class ContentRegistry {
namespace Content {
class Registry {
public:
using BlockIdMap = std::unordered_map<BlockId, BlockDef>;
using BlockNameMap = std::unordered_map<std::string, BlockIdMap::iterator>;
class BlockRegistration {
protected:
ContentRegistry &registry;
Registry &registry;
const BlockNameMap::iterator it;
enum {
Uncommitted,
@ -39,7 +41,7 @@ public:
public:
BlockDef &def;
BlockRegistration(ContentRegistry &registry, const BlockNameMap::iterator &it);
BlockRegistration(Registry &registry, const BlockNameMap::iterator &it);
~BlockRegistration();
BlockRegistration(const BlockRegistration&) = delete;
@ -66,14 +68,14 @@ private:
std::vector<BlockId> m_freedBlockIds;
// No copy
ContentRegistry(const ContentRegistry&) = delete;
ContentRegistry& operator=(const ContentRegistry&) = delete;
Registry(const Registry&) = delete;
Registry& operator=(const Registry&) = delete;
BlockRegistration registerBlock(BlockId id, const char *name);
public:
ContentRegistry();
~ContentRegistry();
Registry();
~Registry();
bool isTransparent(BlockId id) const;
bool isFaceVisible(BlockId id1, BlockId id2) const;
@ -89,6 +91,7 @@ public:
const BlockDef& getBlockDef(BlockId);
};
}
}
#endif
#endif /* DIGGLER_CONTENT_REGISTRY_HPP */

View File

@ -66,7 +66,7 @@ bool ClientMessageHandler::handleMessage(InMessage &msg) {
std::string playerName;
if (cpt.player.display.type == msgpack::type::NIL) {
const Player *blabbermouth = GS.G->players.getByGameId(cpt.player.id);
[[likely(true)]] if (blabbermouth != nullptr) {
if (blabbermouth != nullptr) {
playerName = blabbermouth->name + "> ";
} else {
playerName = "?> ";

View File

@ -8,8 +8,9 @@ using namespace Diggler;
void Diggler_Content_Registry_registerBlock(struct Diggler_Game *cG,
const char *name, struct Diggler_Content_BlockDef *cBdef) {
using namespace Content;
Game &G = *reinterpret_cast<Game*>(cG);
ContentRegistry::BlockRegistration br(G.CR->registerBlock(name));
Registry::BlockRegistration br(G.CR->registerBlock(name));
{ decltype(cBdef->appearance) &cApp = cBdef->appearance;
decltype(br.def.appearance) &app = br.def.appearance;
std::vector<decltype(app.textures)::iterator> textureIts;
@ -29,9 +30,6 @@ void Diggler_Content_Registry_registerBlock(struct Diggler_Game *cG,
if (cTex.repeatXdiv > 1 || cTex.repeatYdiv > 1) {
uint16 width = (tex.coord.u - tex.coord.x) / cTex.repeatXdiv,
height = (tex.coord.v - tex.coord.y) / cTex.repeatYdiv;
getDebugStream() << "Split " << tex.coord.x << ' ' << tex.coord.y << ' ' << tex.coord.u <<
' ' << tex.coord.v << " into " << static_cast<int>(tex.repeat.xdiv) << 'x' <<
static_cast<int>(tex.repeat.ydiv) << std::endl;
for (int16 y = cTex.repeatYdiv - 1; y >= 0; --y) {
for (int16 x = cTex.repeatXdiv - 1; x >= 0; --x) {
tex.divCoords.emplace_back(TexturePacker::Coord {
@ -40,9 +38,6 @@ void Diggler_Content_Registry_registerBlock(struct Diggler_Game *cG,
static_cast<uint16>(tex.coord.x + width * (x + 1)),
static_cast<uint16>(tex.coord.y + height * (y + 1))
});
const TexturePacker::Coord &coord = tex.divCoords.back();
getDebugStream() << "> " << coord.x << ' ' << coord.y << ' ' << coord.u <<
' ' << coord.v << std::endl;
}
}
}