[graphics|hud] Moved to client.

This commit is contained in:
Quentin Bazin 2019-01-12 19:38:30 +01:00
parent 9d8e9a297d
commit ca90070905
24 changed files with 51 additions and 75 deletions

View File

@ -20,7 +20,7 @@
#include "ChunkLightmap.hpp" #include "ChunkLightmap.hpp"
#include "Config.hpp" #include "Config.hpp"
class ClientChunk : public gk::IDrawable { class ClientChunk {
public: public:
enum { enum {
Left, Left,
@ -57,9 +57,9 @@ class ClientChunk : public gk::IDrawable {
ChunkLightmap &lightmap() { return m_lightmap; } ChunkLightmap &lightmap() { return m_lightmap; }
const ChunkLightmap &lightmap() const { return m_lightmap; } const ChunkLightmap &lightmap() const { return m_lightmap; }
private: void drawLayer(gk::RenderTarget &target, gk::RenderStates states, u8 layer) const;
void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
private:
s32 m_x; s32 m_x;
s32 m_y; s32 m_y;
s32 m_z; s32 m_z;

View File

@ -134,7 +134,7 @@ void GameState::draw(gk::RenderTarget &target, gk::RenderStates states) const {
states.shader = &m_shader; states.shader = &m_shader;
target.setView(m_camera); target.setView(m_camera);
target.draw(m_skybox, states); // target.draw(m_skybox, states);
target.draw(m_world, states); target.draw(m_world, states);
target.draw(m_hud, states); target.draw(m_hud, states);
} }

View File

@ -133,33 +133,34 @@ void LuaGUIState::loadGUI(LuaGUI &gui) {
m_widgets.emplace_back(button); m_widgets.emplace_back(button);
} }
for (auto &it : gui.inventoryWidgetList) { // FIXME
auto &inventoryWidget = m_inventoryWidgets.emplace_back(&m_mainWidget); // for (auto &it : gui.inventoryWidgetList) {
inventoryWidget.setPosition(it.x, it.y); // auto &inventoryWidget = m_inventoryWidgets.emplace_back(&m_mainWidget);
inventoryWidget.init(World::getInstance().getPlayer()->inventory(), it.offset, it.count); // inventoryWidget.setPosition(it.x, it.y);
} // inventoryWidget.init(World::getInstance().getPlayer()->inventory(), it.offset, it.count);
// }
for (auto &it : gui.craftingWidgetList) { //
BlockData *data = World::getInstance().getBlockData(it.block.x, it.block.y, it.block.z); // for (auto &it : gui.craftingWidgetList) {
if (data) { // BlockData *data = World::getInstance().getBlockData(it.block.x, it.block.y, it.block.z);
auto &craftingWidget = m_craftingWidgets.emplace_back(data->inventory, &m_mainWidget); // if (data) {
craftingWidget.setPosition(it.x, it.y); // auto &craftingWidget = m_craftingWidgets.emplace_back(data->inventory, &m_mainWidget);
} // craftingWidget.setPosition(it.x, it.y);
else { // }
DEBUG("ERROR: No inventory found at", it.block.x, it.block.y, it.block.z); // else {
} // DEBUG("ERROR: No inventory found at", it.block.x, it.block.y, it.block.z);
} // }
// }
for (auto &it : gui.furnaceWidgetList) { //
BlockData *data = World::getInstance().getBlockData(it.block.x, it.block.y, it.block.z); // for (auto &it : gui.furnaceWidgetList) {
if (data) { // BlockData *data = World::getInstance().getBlockData(it.block.x, it.block.y, it.block.z);
auto *furnaceWidget = new FurnaceWidget(m_mouseItemWidget, World::getInstance().getPlayer()->inventory(), *data, &m_mainWidget); // if (data) {
furnaceWidget->setPosition(it.x, it.y); // auto *furnaceWidget = new FurnaceWidget(m_mouseItemWidget, World::getInstance().getPlayer()->inventory(), *data, &m_mainWidget);
m_widgets.emplace_back(furnaceWidget); // furnaceWidget->setPosition(it.x, it.y);
} // m_widgets.emplace_back(furnaceWidget);
else { // }
DEBUG("ERROR: No inventory found at", it.block.x, it.block.y, it.block.z); // else {
} // DEBUG("ERROR: No inventory found at", it.block.x, it.block.y, it.block.z);
} // }
// }
} }

View File

@ -77,27 +77,20 @@ void ClientChunk::setData(int x, int y, int z, u16 data) {
m_hasChanged = true; m_hasChanged = true;
} }
void ClientChunk::draw(gk::RenderTarget &target, gk::RenderStates states) const { void ClientChunk::drawLayer(gk::RenderTarget &target, gk::RenderStates states, u8 layer) const {
// if (m_verticesCount.at(layer) == 0) return; if (m_verticesCount.at(layer) == 0) return;
if (m_verticesCount.at(ChunkBuilder::Layer::Solid) == 0) return;
// states.transform = glm::translate(glm::mat4(1.0f),
// glm::vec3(m_x * CHUNK_WIDTH,
// m_y * CHUNK_HEIGHT,
// m_z * CHUNK_DEPTH));
states.texture = &m_texture; states.texture = &m_texture;
// if (layer == ChunkBuilder::Layer::Other) if (layer == ChunkBuilder::Layer::Other)
// glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
// else else
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
if(Config::isWireframeModeEnabled) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); if(Config::isWireframeModeEnabled) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// target.draw(m_vbo.at(layer), GL_QUADS, 0, m_verticesCount.at(layer), states); target.draw(m_vbo.at(layer), GL_TRIANGLES, 0, m_verticesCount.at(layer), states);
// target.draw(m_vbo.at(layer), GL_TRIANGLES, 0, m_verticesCount.at(layer), states);
target.draw(m_vbo.at(ChunkBuilder::Layer::Solid), GL_TRIANGLES, 0, m_verticesCount.at(ChunkBuilder::Layer::Solid), states);
if(Config::isWireframeModeEnabled) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if(Config::isWireframeModeEnabled) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
} }

View File

@ -164,17 +164,11 @@ void ClientWorld::draw(gk::RenderTarget &target, gk::RenderStates states) const
// getChunk(ux, uy, uz)->setInitialized(true); // getChunk(ux, uy, uz)->setInitialized(true);
// } // }
// FIXME for (u8 i = 0 ; i < ChunkBuilder::layers ; ++i) {
// for (u8 i = 0 ; i < ChunkBuilder::layers ; ++i) { for (auto &it : chunks) {
// for (auto &it : chunks) { states.transform = it.second;
// states.transform = it.second; it.first->drawLayer(target, states, i);
// it.first->drawLayer(target, states, i); }
// }
// }
for (auto &it : chunks) {
states.transform = it.second;
target.draw(*it.first, states);
} }
} }

View File

@ -25,7 +25,7 @@ class World : public gk::IDrawable {
public: public:
World(); World();
void update(Player &player); void update();
Chunk *getChunk(int cx, int cy, int cz) const; Chunk *getChunk(int cx, int cy, int cz) const;
@ -37,22 +37,13 @@ class World : public gk::IDrawable {
BlockData *getBlockData(int x, int y, int z); BlockData *getBlockData(int x, int y, int z);
Player *getPlayer() const { return m_player; }
// Render distance in chunks // Render distance in chunks
static u16 renderDistance; static u16 renderDistance;
static bool isReloadRequested; static bool isReloadRequested;
static World &getInstance() { return *s_instance; }
static void setInstance(World &instance) { s_instance = &instance; }
private: private:
void draw(gk::RenderTarget &target, gk::RenderStates states) const override; void draw(gk::RenderTarget &target, gk::RenderStates states) const override;
// FIXME: Needed for LuaGUIState
static World *s_instance;
Player *m_player = nullptr;
const s32 m_width = 32; const s32 m_width = 32;
const s32 m_height = 4; const s32 m_height = 4;
const s32 m_depth = 32; const s32 m_depth = 32;

View File

@ -14,7 +14,6 @@
#include <iostream> #include <iostream>
#include "Block.hpp" #include "Block.hpp"
#include "Player.hpp"
#include "World.hpp" #include "World.hpp"
Block::Block(u32 id, u32 textureID, const std::string &name, const std::string &label) { Block::Block(u32 id, u32 textureID, const std::string &name, const std::string &label) {
@ -31,7 +30,8 @@ Block::Block(u32 id, u32 textureID, const std::string &name, const std::string &
void Block::onTick(const glm::ivec3 &pos, Player &player, Chunk &chunk, World &world) const { void Block::onTick(const glm::ivec3 &pos, Player &player, Chunk &chunk, World &world) const {
try { try {
if (m_onTick && m_onTickEnabled) { if (m_onTick && m_onTickEnabled) {
m_onTick(pos, player, chunk, world); // FIXME
// m_onTick(pos, player, chunk, world);
} }
} }
catch (const sol::error &e) { catch (const sol::error &e) {
@ -44,7 +44,8 @@ void Block::onTick(const glm::ivec3 &pos, Player &player, Chunk &chunk, World &w
bool Block::onBlockActivated(const glm::ivec3 &pos, Player &player, World &world) const { bool Block::onBlockActivated(const glm::ivec3 &pos, Player &player, World &world) const {
try { try {
if (m_onBlockActivated) { if (m_onBlockActivated) {
m_onBlockActivated(pos, player, world); // FIXME
// m_onBlockActivated(pos, player, world);
return true; return true;
} }
} }

View File

@ -22,8 +22,6 @@
u16 World::renderDistance = 8; u16 World::renderDistance = 8;
bool World::isReloadRequested = false; bool World::isReloadRequested = false;
World *World::s_instance = nullptr;
World::World() : m_texture(gk::ResourceHandler::getInstance().get<gk::Texture>("texture-blocks")) { World::World() : m_texture(gk::ResourceHandler::getInstance().get<gk::Texture>("texture-blocks")) {
for(s32 z = 0 ; z < m_depth ; z++) { for(s32 z = 0 ; z < m_depth ; z++) {
for(s32 y = 0 ; y < m_height ; y++) { for(s32 y = 0 ; y < m_height ; y++) {
@ -52,9 +50,7 @@ World::World() : m_texture(gk::ResourceHandler::getInstance().get<gk::Texture>("
} }
} }
void World::update(Player &player) { void World::update() {
m_player = &player;
// FIXME // FIXME
// for (auto &it : m_chunks) { // for (auto &it : m_chunks) {
// if (isReloadRequested) // if (isReloadRequested)