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

View File

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

View File

@ -133,33 +133,34 @@ void LuaGUIState::loadGUI(LuaGUI &gui) {
m_widgets.emplace_back(button);
}
for (auto &it : gui.inventoryWidgetList) {
auto &inventoryWidget = m_inventoryWidgets.emplace_back(&m_mainWidget);
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);
if (data) {
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);
}
}
for (auto &it : gui.furnaceWidgetList) {
BlockData *data = World::getInstance().getBlockData(it.block.x, it.block.y, it.block.z);
if (data) {
auto *furnaceWidget = new FurnaceWidget(m_mouseItemWidget, World::getInstance().getPlayer()->inventory(), *data, &m_mainWidget);
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);
}
}
// FIXME
// for (auto &it : gui.inventoryWidgetList) {
// auto &inventoryWidget = m_inventoryWidgets.emplace_back(&m_mainWidget);
// 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);
// if (data) {
// 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);
// }
// }
//
// for (auto &it : gui.furnaceWidgetList) {
// BlockData *data = World::getInstance().getBlockData(it.block.x, it.block.y, it.block.z);
// if (data) {
// auto *furnaceWidget = new FurnaceWidget(m_mouseItemWidget, World::getInstance().getPlayer()->inventory(), *data, &m_mainWidget);
// 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);
// }
// }
}

View File

@ -77,27 +77,20 @@ void ClientChunk::setData(int x, int y, int z, u16 data) {
m_hasChanged = true;
}
void ClientChunk::draw(gk::RenderTarget &target, gk::RenderStates states) const {
// 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));
void ClientChunk::drawLayer(gk::RenderTarget &target, gk::RenderStates states, u8 layer) const {
if (m_verticesCount.at(layer) == 0) return;
states.texture = &m_texture;
// if (layer == ChunkBuilder::Layer::Other)
// glDisable(GL_CULL_FACE);
// else
if (layer == ChunkBuilder::Layer::Other)
glDisable(GL_CULL_FACE);
else
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
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(ChunkBuilder::Layer::Solid), GL_TRIANGLES, 0, m_verticesCount.at(ChunkBuilder::Layer::Solid), states);
target.draw(m_vbo.at(layer), GL_TRIANGLES, 0, m_verticesCount.at(layer), states);
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);
// }
// FIXME
// for (u8 i = 0 ; i < ChunkBuilder::layers ; ++i) {
// for (auto &it : chunks) {
// states.transform = it.second;
// it.first->drawLayer(target, states, i);
// }
// }
for (auto &it : chunks) {
states.transform = it.second;
target.draw(*it.first, states);
for (u8 i = 0 ; i < ChunkBuilder::layers ; ++i) {
for (auto &it : chunks) {
states.transform = it.second;
it.first->drawLayer(target, states, i);
}
}
}

View File

@ -25,7 +25,7 @@ class World : public gk::IDrawable {
public:
World();
void update(Player &player);
void update();
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);
Player *getPlayer() const { return m_player; }
// Render distance in chunks
static u16 renderDistance;
static bool isReloadRequested;
static World &getInstance() { return *s_instance; }
static void setInstance(World &instance) { s_instance = &instance; }
private:
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_height = 4;
const s32 m_depth = 32;

View File

@ -14,7 +14,6 @@
#include <iostream>
#include "Block.hpp"
#include "Player.hpp"
#include "World.hpp"
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 {
try {
if (m_onTick && m_onTickEnabled) {
m_onTick(pos, player, chunk, world);
// FIXME
// m_onTick(pos, player, chunk, world);
}
}
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 {
try {
if (m_onBlockActivated) {
m_onBlockActivated(pos, player, world);
// FIXME
// m_onBlockActivated(pos, player, world);
return true;
}
}

View File

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