Fix GUI model rendering
* Un-hardcode inventory lists * Begin implementation of the hotwheelmaster
parent
0b60d433e6
commit
2338d5b96c
|
@ -189,7 +189,7 @@ void MapGen::generateStructures(chunk_partials_map& chunks, chunk_partial& chunk
|
|||
c.origin = {1, 0, 1};
|
||||
c.blocks = { cAir, cAir, cAir, cAir, cLeaves, cAir, cAir, cAir, cAir,
|
||||
cAir, cWood, cAir, cLeaves, cWood, cLeaves, cAir, cLeaves, cAir,
|
||||
cAir, cAir, cAir, cAir, cLeaves, cAir, cAir, cAir, cAir};
|
||||
cAir, cAir, cAir, cAir, cLeaves, cAir, cAir, cAir, cAir };
|
||||
|
||||
glm::ivec3 wp = chunk.second->pos;
|
||||
glm::ivec3 lp;
|
||||
|
@ -200,41 +200,11 @@ void MapGen::generateStructures(chunk_partials_map& chunks, chunk_partial& chunk
|
|||
glm::ivec3 p = wp * 16 + lp;
|
||||
|
||||
if (treeAbs.GetValue(p.x, p.y, p.z) > 1.2 && chunk.first->depth[m] <= 2 && chunk.first->depth[m] > 1) {
|
||||
|
||||
glm::ivec3 off = {};
|
||||
for (unsigned int i = 0; i < c.length(); i++) {
|
||||
c.assignOffset(i, off);
|
||||
setBlock(p + off - c.origin, c.blocks[i], chunks);
|
||||
}
|
||||
|
||||
// glm::ivec3 rp {};
|
||||
// for (unsigned int i = 0; i < 5; i++) {
|
||||
// rp.x = p.x - 2 + i;
|
||||
// for (unsigned int j = 0; j < 5; j++) {
|
||||
// rp.z = p.z - 2 + j;
|
||||
// for (unsigned int k = 0; k < 2; k++) {
|
||||
// rp.y = p.y + 48 + k;
|
||||
// setBlock(rp, cLeaves, chunks);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// rp = {};
|
||||
// for (unsigned int i = 0; i < 3; i++) {
|
||||
// rp.x = p.x - 1 + i;
|
||||
// for (unsigned int j = 0; j < 3; j++) {
|
||||
// rp.z = p.z - 1 + j;
|
||||
// for (unsigned int k = 0; k < 2; k++) {
|
||||
// rp.y = p.y + 50 + k;
|
||||
// setBlock(rp, cLeaves, chunks);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (unsigned int i = 0; i < 50; i++) {
|
||||
// setBlock(p, cWood, chunks);
|
||||
// p.y++;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -272,8 +242,7 @@ std::shared_ptr<BlockChunk> MapGen::combinePartials(std::shared_ptr<BlockChunk>
|
|||
for (unsigned int i = 0; i < 4096; i++) {
|
||||
if (src->getBlock(i) != DefinitionAtlas::INVALID) res->setBlock(i, src->getBlock(i));
|
||||
}
|
||||
res->generated = src->generated || res->generated;
|
||||
|
||||
assert(res != nullptr);
|
||||
res->generated = src->generated || res->generated;
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -103,8 +103,6 @@ void Renderer::beginChunkDeferredCalls() {
|
|||
}
|
||||
|
||||
void Renderer::beginEntityDeferredCalls() {
|
||||
// glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
||||
|
||||
currentModelUniform = entity.uniforms.model;
|
||||
|
||||
entity.use();
|
||||
|
@ -113,8 +111,6 @@ void Renderer::beginEntityDeferredCalls() {
|
|||
}
|
||||
|
||||
void Renderer::endDeferredCalls() {
|
||||
// glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
||||
|
||||
activeTexture = nullptr;
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, ssao.fbo);
|
||||
|
@ -186,7 +182,7 @@ void Renderer::beginGUIDrawCalls() {
|
|||
currentModelUniform = gu.model;
|
||||
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
|
@ -242,3 +238,11 @@ void Renderer::setBones(std::vector<glm::mat4> &transforms) {
|
|||
if (transforms.empty()) return;
|
||||
entity.setArr(entity.uniforms.bones, static_cast<GLsizei>(transforms.size()), transforms.at(0));
|
||||
}
|
||||
|
||||
void Renderer::toggleDepthTest(bool enable) {
|
||||
enable ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void Renderer::clearDepthBuffer() {
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ public:
|
|||
void swapBuffers();
|
||||
|
||||
void setClearColor(unsigned char r, unsigned char g, unsigned char b);
|
||||
void toggleDepthTest(bool enable);
|
||||
void clearDepthBuffer();
|
||||
|
||||
void setModelMatrix(const glm::mat4& modelMatrix);
|
||||
void setBones(std::vector<glm::mat4>& transforms);
|
||||
|
|
|
@ -66,14 +66,17 @@ void DebugGui::positionElements(glm::vec2 bufferSize) {
|
|||
get<GUILabelledGraph>("meshGraph")->setPos({bufferWidth - 254, bufferHeight - 70 - 80});
|
||||
get<GUILabelledGraph>("interpGraph")->setPos({bufferWidth - 254, bufferHeight - 70});
|
||||
|
||||
get<GUILabelledGraph>("fpsGraph")->setPos({10, bufferHeight - 70});
|
||||
get<GUILabelledGraph>("drawsGraph")->setPos({10, bufferHeight - 70 - 80});
|
||||
get<GUILabelledGraph>("gpuGraph")->setPos({bufferWidth - 254, 10});
|
||||
get<GUILabelledGraph>("fpsGraph")->setPos({bufferWidth - 254, 10});
|
||||
get<GUILabelledGraph>("drawsGraph")->setPos({bufferWidth - 254, 90});
|
||||
get<GUILabelledGraph>("gpuGraph")->setPos({bufferWidth - 254, 90 + 80});
|
||||
}
|
||||
|
||||
void DebugGui::update(Player& player, LocalWorld& world, LocalDefs& defs, double fps, int /*chunks*/, int drawCalls, int ssGen, int ssPack) {
|
||||
|
||||
{ //VRam Usage Graph (Top Right)
|
||||
{ //Top Right Graphs
|
||||
get<GUILabelledGraph>("fpsGraph")->pushValue(static_cast<float>(fps));
|
||||
get<GUILabelledGraph>("drawsGraph")->pushValue(drawCalls);
|
||||
|
||||
int videoMemAvail, videoMemTotal;
|
||||
|
||||
glGetIntegerv(0x9048, &videoMemTotal);
|
||||
|
@ -84,11 +87,6 @@ void DebugGui::update(Player& player, LocalWorld& world, LocalDefs& defs, double
|
|||
/ 100.0f);
|
||||
}
|
||||
|
||||
{ //Bottom Left Graphs
|
||||
get<GUILabelledGraph>("fpsGraph")->pushValue(static_cast<float>(fps));
|
||||
get<GUILabelledGraph>("drawsGraph")->pushValue(drawCalls);
|
||||
}
|
||||
|
||||
{ //Bottom Right Graphs
|
||||
get<GUILabelledGraph>("meshGraph")->pushValue(world.lastMeshUpdates);
|
||||
get<GUILabelledGraph>("interpGraph")->pushValue(world.lastGenUpdates);
|
||||
|
|
|
@ -159,8 +159,4 @@ bool GUIComponent::clickEvent(bool left, bool state, glm::ivec2 pos) {
|
|||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GUIComponent::setDepth(float depth) {
|
||||
entity.setDepth(depth);
|
||||
}
|
|
@ -25,8 +25,6 @@ public:
|
|||
virtual void setPos(glm::ivec2 pos);
|
||||
virtual glm::ivec2 getPos();
|
||||
|
||||
void setDepth(float depth);
|
||||
|
||||
bool mouseActivity(glm::ivec2 pos);
|
||||
bool leftClickEvent(bool state, glm::ivec2 pos);
|
||||
bool rightClickEvent(bool state, glm::ivec2 pos);
|
||||
|
|
|
@ -29,7 +29,6 @@ void GUIInventoryItem::create(glm::vec2 scale, unsigned short count, ItemDef& de
|
|||
item->create(scale * 10.5f, model);
|
||||
item->setPos(glm::vec2{7.75, 7.75} * scale);
|
||||
|
||||
item->setDepth(25);
|
||||
glm::mat4 rot;
|
||||
rot = glm::rotate(rot, glm::radians(180.f), {1, 0, 0});
|
||||
rot = glm::rotate(rot, glm::radians( 45.f), {0, 1, 0});
|
||||
|
@ -45,6 +44,5 @@ void GUIInventoryItem::create(glm::vec2 scale, unsigned short count, ItemDef& de
|
|||
text->setText(std::to_string(count));
|
||||
add(text);
|
||||
text->setPos({(19 - text->getWidth()) * scale.x, 9 * scale.y});
|
||||
text->setDepth(50);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,10 @@ void GUIModel::create(glm::vec2 scale, std::shared_ptr<GuiMesh> model) {
|
|||
|
||||
|
||||
void GUIModel::draw(Renderer &renderer) {
|
||||
renderer.toggleDepthTest(true);
|
||||
renderer.clearDepthBuffer();
|
||||
GUIComponent::draw(renderer);
|
||||
renderer.toggleDepthTest(false);
|
||||
}
|
||||
|
||||
void GUIModel::setRotation(glm::mat4 rotation) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "Inventory.h"
|
||||
|
||||
void Inventory::createList(std::string name, unsigned short length, unsigned short width) {
|
||||
lists.emplace(name, std::make_shared<InventoryList>(defs, length, width));
|
||||
lists.emplace(name, std::make_shared<InventoryList>(defs, name, length, width));
|
||||
}
|
||||
|
||||
std::shared_ptr<InventoryList> Inventory::operator[](std::string name) {
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
#include "InventoryList.h"
|
||||
#include "../../../lua/api/type/LuaItemStack.h"
|
||||
|
||||
InventoryList::InventoryList(DefinitionAtlas& defs, unsigned short size, unsigned short width) :
|
||||
InventoryList::InventoryList(DefinitionAtlas& defs, std::string name, unsigned short size, unsigned short width) :
|
||||
defs(defs),
|
||||
name(name),
|
||||
itemstacks(size),
|
||||
width(width) {}
|
||||
|
||||
|
@ -221,9 +222,6 @@ ItemStack InventoryList::removeStack(unsigned short ind, unsigned short count) {
|
|||
|
||||
void InventoryList::triggerCallback() {
|
||||
if (guiCallback != nullptr) guiCallback();
|
||||
// for (auto& cb : changeCallbacks) {
|
||||
// cb();
|
||||
// }
|
||||
}
|
||||
|
||||
unsigned short InventoryList::getLength() {
|
||||
|
@ -232,4 +230,8 @@ unsigned short InventoryList::getLength() {
|
|||
|
||||
unsigned short InventoryList::getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
std::string InventoryList::getName() {
|
||||
return name;
|
||||
}
|
|
@ -13,10 +13,11 @@ class InventoryList {
|
|||
public:
|
||||
enum class Callback { ALLOW_TAKE, ALLOW_PUT, ON_TAKE, ON_PUT };
|
||||
|
||||
InventoryList(DefinitionAtlas& defs, unsigned short size, unsigned short width);
|
||||
InventoryList(DefinitionAtlas& defs, std::string name, unsigned short size, unsigned short width);
|
||||
|
||||
unsigned short getLength();
|
||||
unsigned short getWidth();
|
||||
std::string getName();
|
||||
|
||||
// Place the stack at i into the existing stack, returning overflow or other stack.
|
||||
ItemStack placeStack(unsigned short i, const ItemStack& stack, bool playerInitiated = false);
|
||||
|
@ -46,6 +47,7 @@ private:
|
|||
|
||||
std::vector<ItemStack> itemstacks {};
|
||||
unsigned short width = 0;
|
||||
std::string name;
|
||||
|
||||
std::function<void()> guiCallback = nullptr;
|
||||
std::array<sol::function, 4> luaCallbacks = {};
|
||||
|
|
|
@ -7,16 +7,12 @@
|
|||
Player::Player(LocalWorld& world, LocalDefs& defs, Renderer& renderer) :
|
||||
Collidable(world, defs, {{-0.3, 0, -0.3}, {0.3, 1.8, 0.3}}),
|
||||
|
||||
hand(defs.defs, 1, 1),
|
||||
hand(defs.defs, "hand", 1, 1),
|
||||
inventory(defs.defs),
|
||||
gameGui(inventory, hand, renderer.window.getSize(), defs, renderer),
|
||||
wireframe({}, 0.01, {1, 1, 1}),
|
||||
renderer(renderer),
|
||||
defs(defs) {
|
||||
|
||||
inventory.createList("main", 44, 11);
|
||||
inventory.createList("craft", 4, 2);
|
||||
inventory.createList("craft_result", 2, 2);
|
||||
}
|
||||
|
||||
void Player::update(Input &input, double delta, glm::vec2 mouseDelta) {
|
||||
|
|
|
@ -12,6 +12,10 @@ int LuaInventoryList::get_width() {
|
|||
return list.getWidth();
|
||||
}
|
||||
|
||||
std::string LuaInventoryList::get_name() {
|
||||
return list.getName();
|
||||
}
|
||||
|
||||
LuaItemStack LuaInventoryList::get_stack(unsigned short i) {
|
||||
return LuaItemStack(list.getStack(i - 1), list.defs);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ public:
|
|||
|
||||
int get_length();
|
||||
int get_width();
|
||||
std::string get_name();
|
||||
|
||||
LuaItemStack get_stack(unsigned short i);
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace ClientApi {
|
|||
lua.new_usertype<LuaInventoryList>("InventoryListRef",
|
||||
"length", sol::property(&LuaInventoryList::get_length),
|
||||
"width", sol::property(&LuaInventoryList::get_width),
|
||||
"name", sol::property(&LuaInventoryList::get_name),
|
||||
|
||||
"get_stack", &LuaInventoryList::get_stack,
|
||||
"set_stack", sol::overload(
|
||||
|
|
|
@ -2,8 +2,10 @@ print("Hello from inventory")
|
|||
|
||||
if zepha.server then return end -- Only run the following code on the client.
|
||||
|
||||
local inventory = zepha.player:get_inventory()
|
||||
|
||||
local shit_adding = false
|
||||
local main = zepha.player:get_inventory():get_list("main")
|
||||
local main = inventory:add_list("main", 44, 11)
|
||||
|
||||
zepha.register_keybind("zeus:inventory:add_shit_b", {
|
||||
description = "Add testing items to inventory",
|
||||
|
@ -58,7 +60,7 @@ zepha.register_keybind("zeus:inventory:open_inventory", {
|
|||
size: 218px 160px
|
||||
|
||||
rect[inv_background]
|
||||
position: 0px 60px
|
||||
position: 0px 45px
|
||||
size: 218px 100px
|
||||
padding: 20px 10px 8px 10px
|
||||
background: asset(zeus:inventory:inventory)
|
||||
|
@ -73,6 +75,7 @@ zepha.register_keybind("zeus:inventory:open_inventory", {
|
|||
|
||||
rect[craft_background]
|
||||
size: 218px 72px
|
||||
position: 0px -15px
|
||||
padding: 20px 10px 8px 10px
|
||||
background: asset(zeus:inventory:crafting)
|
||||
|
||||
|
@ -90,6 +93,49 @@ zepha.register_keybind("zeus:inventory:open_inventory", {
|
|||
slot_spacing: 2px 2px
|
||||
end
|
||||
end
|
||||
|
||||
rect[hot_wheel]
|
||||
size: 214px 67px
|
||||
position: 2px 160px
|
||||
background: asset(zeus:inventory:inventory_wheel)
|
||||
|
||||
inventory
|
||||
source: current_player
|
||||
list: hot_wheel_1
|
||||
position: 9px 1px
|
||||
slot_spacing: 2px 2px
|
||||
end
|
||||
inventory
|
||||
source: current_player
|
||||
list: hot_wheel_2
|
||||
position: 117px 1px
|
||||
slot_spacing: 2px 2px
|
||||
end
|
||||
inventory
|
||||
source: current_player
|
||||
list: hot_wheel_3
|
||||
position: 125px 25px
|
||||
slot_spacing: 2px 2px
|
||||
end
|
||||
inventory
|
||||
source: current_player
|
||||
list: hot_wheel_4
|
||||
position: 117px 50px
|
||||
slot_spacing: 2px 2px
|
||||
end
|
||||
inventory
|
||||
source: current_player
|
||||
list: hot_wheel_5
|
||||
position: 9px 50px
|
||||
slot_spacing: 2px 2px
|
||||
end
|
||||
inventory
|
||||
source: current_player
|
||||
list: hot_wheel_6
|
||||
position: 1px 25px
|
||||
slot_spacing: 2px 2px
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
]], {
|
||||
|
@ -106,7 +152,31 @@ zepha.register_keybind("zeus:inventory:open_inventory", {
|
|||
end
|
||||
})
|
||||
|
||||
local craft_input = zepha.player:get_inventory():get_list("craft")
|
||||
local craft_output = zepha.player:get_inventory():get_list("craft_result")
|
||||
-- Bind crafting
|
||||
|
||||
crafting.bind(craft_input, craft_output)
|
||||
local craft_input = inventory:add_list("craft", 4, 2)
|
||||
local craft_output = inventory:add_list("craft_result", 2, 2)
|
||||
|
||||
crafting.bind(craft_input, craft_output)
|
||||
|
||||
-- Make hotwheel
|
||||
|
||||
local invs = {
|
||||
inventory:add_list("hot_wheel_1", 5, 5),
|
||||
inventory:add_list("hot_wheel_2", 5, 5),
|
||||
inventory:add_list("hot_wheel_3", 5, 5),
|
||||
inventory:add_list("hot_wheel_4", 5, 5),
|
||||
inventory:add_list("hot_wheel_5", 5, 5),
|
||||
inventory:add_list("hot_wheel_6", 5, 5)
|
||||
}
|
||||
|
||||
for i, inv in pairs(invs) do
|
||||
inv.allow_take = function() return 0 end
|
||||
inv.allow_put = function(slot, item)
|
||||
zepha.delay(function()
|
||||
-- This delay is necessary to avoid the engine overwriting it with nothing
|
||||
inv:set_stack(slot, item)
|
||||
end, 0)
|
||||
return 0
|
||||
end
|
||||
end
|
Binary file not shown.
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 2.5 KiB |
Loading…
Reference in New Issue