Fix client-side segfault with uninitialized values.
parent
62d26bfee4
commit
b9b3db77fd
|
@ -0,0 +1,14 @@
|
|||
zepha.player:set_hud(zepha.build_gui(function()
|
||||
return Gui.Body {
|
||||
background = "base:viginette",
|
||||
|
||||
Gui.Rect {
|
||||
key = "crosshair",
|
||||
position = { pc(50), pc(50) },
|
||||
position_anchor = { pc(50), pc(50) },
|
||||
size = { 22 / 3, 22 / 3 },
|
||||
|
||||
background = "base:crosshair"
|
||||
}
|
||||
}
|
||||
end))
|
|
@ -1,8 +1,9 @@
|
|||
-- Load Libraries
|
||||
runfile(_PATH .. "dump")
|
||||
runfile(_PATH .. "math")
|
||||
runfile(_PATH .. "vector")
|
||||
runfile(_PATH .. "gui")
|
||||
runfile(_PATH .. "modules/dump")
|
||||
runfile(_PATH .. "modules/math")
|
||||
runfile(_PATH .. "modules/vector")
|
||||
runfile(_PATH .. "modules/gui")
|
||||
|
||||
-- Register base models (if not on main menu)
|
||||
if zepha.register_blockmodel then runfile(_PATH .. "models/_index") end
|
||||
if zepha.register_blockmodel then runfile(_PATH .. "models/_index") end
|
||||
if zepha.player then runfile(_PATH .. "hud") end
|
Binary file not shown.
Before Width: | Height: | Size: 326 B |
Binary file not shown.
Before Width: | Height: | Size: 4.3 KiB |
|
@ -203,9 +203,8 @@ set(ZEPHA_SRC
|
|||
lua/api/functions/update_entities.h
|
||||
lua/api/modules/register_keybind.h
|
||||
lua/LuaInputManager.cpp
|
||||
lua/LuaInputManager.h
|
||||
lua/api/usertype/cLocalPlayer.h
|
||||
lua/api/class/LocalLuaPlayer.cpp
|
||||
lua/LuaInputManager.h
|
||||
lua/api/class/LocalLuaPlayer.cpp
|
||||
lua/api/class/LocalLuaPlayer.h
|
||||
game/entity/Collidable.cpp
|
||||
game/entity/Collidable.h
|
||||
|
|
|
@ -97,24 +97,19 @@ void DebugGui::update(Player& player, LocalWorld& world, ClientGame& defs, doubl
|
|||
{ //Top-left Data
|
||||
glm::vec3 footPos = glm::floor(player.getPos()) - glm::vec3(0, 0.02, 0);
|
||||
|
||||
unsigned int blockID = world.getBlock(footPos);
|
||||
std::string on = defs.defs.fromId(blockID).identifier;
|
||||
|
||||
unsigned int biomeID = world.getBiome(glm::floor(player.getPos()));
|
||||
std::string biome = defs.biomes.biomeFromId(biomeID).identifier;
|
||||
|
||||
glm::vec3 playerPos = glm::floor(player.getPos());
|
||||
glm::vec3 chunkPos = Space::Chunk::world::fromBlock(playerPos);
|
||||
glm::vec3 mapBlockPos = Space::MapBlock::world::fromChunk(chunkPos);
|
||||
glm::vec3 regionPos = Space::Region::world::fromChunk(chunkPos);
|
||||
|
||||
//Block Coordinates offset from respective container
|
||||
glm::vec3 posOffsetFromChunk = Space::Block::relative::toChunk(playerPos);
|
||||
glm::vec3 posOffsetFromBlock = Space::Block::relative::toMapBlock(playerPos);
|
||||
glm::vec3 posOffsetFromRegion = Space::Block::relative::toRegion(playerPos);
|
||||
|
||||
glm::vec3 chunkCoordinate = chunkPos;
|
||||
glm::vec3 mapBlockCoordinate = Space::MapBlock::world::fromChunk(chunkPos);
|
||||
glm::vec3 regionCoordinate = Space::Region::world::fromChunk(chunkPos);
|
||||
|
||||
std::ostringstream str;
|
||||
|
||||
using namespace Util;
|
||||
|
@ -123,18 +118,13 @@ void DebugGui::update(Player& player, LocalWorld& world, ClientGame& defs, doubl
|
|||
str << " (" << floatVecToString(player.getPos()) << ")" << std::endl << std::endl;
|
||||
|
||||
str << "Chunk: " << vecToString(posOffsetFromChunk) << " [" << vecToString(chunkPos) << "]" << std::endl;
|
||||
str << "MapBlock: " << vecToString(posOffsetFromBlock) << std::endl;
|
||||
str << "Region: " << vecToString(posOffsetFromRegion) << std::endl << std::endl;
|
||||
|
||||
str << "Ch: " << vecToString(chunkCoordinate) << ", ";
|
||||
str << "Mb: " << vecToString(mapBlockCoordinate) << ", ";
|
||||
str << "Rg: " << vecToString(regionCoordinate) << std::endl;
|
||||
str << "MapBlock: " << vecToString(posOffsetFromBlock) << " [" << vecToString(mapBlockPos) << "]" << std::endl;
|
||||
str << "Region: " << vecToString(posOffsetFromRegion) << " [" << vecToString(regionPos) << "]" << std::endl << std::endl;
|
||||
|
||||
str << "Vel: " << floatVecToString(player.getVel()) << std::endl;
|
||||
str << "Yaw: " << floatToString(player.getYaw()) << ", ";
|
||||
str << "Pitch: " << floatToString(player.getPitch()) << std::endl << std::endl;
|
||||
|
||||
str << "Standing On: " << on << std::endl;
|
||||
str << "Biome: " << biome << std::endl << std::endl;
|
||||
|
||||
str << "Texture Slots: " << defs.textures.textureSlotsUsed << " / " << defs.textures.maxTextureSlots
|
||||
|
|
|
@ -11,17 +11,11 @@ GameGui::GameGui(LocalInventoryRefs& refs, glm::vec2 bufferSize, ClientGame& def
|
|||
win(bufferSize),
|
||||
renderer(renderer),
|
||||
|
||||
hudBuilder(refs, defs, hudRoot),
|
||||
menuBuilder(refs, defs, menuRoot) {
|
||||
hudBuilder(refs, defs, hudLuaRoot),
|
||||
menuBuilder(refs, defs, menuLuaRoot) {
|
||||
|
||||
auto crosshair = std::make_shared<GuiRect>("crosshair");
|
||||
crosshair->create({22, 22}, {}, defs.textures["crosshair"]);
|
||||
crosshair->setPos({bufferSize.x / 2 - 11, bufferSize.y / 2 - 9});
|
||||
hudRoot->add(crosshair);
|
||||
|
||||
auto viginette = std::make_shared<GuiRect>("viginette");
|
||||
viginette->create(bufferSize, {}, defs.textures["viginette"]);
|
||||
hudRoot->add(viginette);
|
||||
hudRoot->add(hudLuaRoot);
|
||||
menuRoot->add(menuLuaRoot);
|
||||
|
||||
handList->create({3, 3}, {}, {}, refs.getHand(), refs.getHand(), defs);
|
||||
menuRoot->add(handList);
|
||||
|
@ -31,6 +25,9 @@ void GameGui::update(double delta) {
|
|||
menuRoot->update(delta);
|
||||
hudRoot->update(delta);
|
||||
|
||||
hudBuilder.update();
|
||||
menuBuilder.update();
|
||||
|
||||
handList->setPos((renderer.window.getMousePos() - glm::ivec2(24)) / 3 * 3);
|
||||
menuRoot->handleMouseInput(renderer.window);
|
||||
}
|
||||
|
@ -44,8 +41,8 @@ void GameGui::winResized(glm::ivec2 win) {
|
|||
menuBuilder.build(win);
|
||||
}
|
||||
|
||||
void GameGui::buildMenu(sol::state_view state, sol::table menu) {
|
||||
// menuBuilder.setGuiTable(state, menu);
|
||||
void GameGui::showMenu(std::shared_ptr<LuaGuiElement> root) {
|
||||
menuBuilder.setGuiRoot(root);
|
||||
menuBuilder.build(win);
|
||||
inMenu = true;
|
||||
}
|
||||
|
@ -59,6 +56,16 @@ const bool GameGui::isInMenu() const {
|
|||
return inMenu;
|
||||
}
|
||||
|
||||
void GameGui::setHud(std::shared_ptr<LuaGuiElement> hud) {
|
||||
this->hudRootElem = hud;
|
||||
hudBuilder.setGuiRoot(hud);
|
||||
hudBuilder.build(win);
|
||||
}
|
||||
|
||||
std::shared_ptr<LuaGuiElement> GameGui::getHud() {
|
||||
return hudRootElem;
|
||||
}
|
||||
|
||||
void GameGui::setVisible(bool visible) {
|
||||
menuRoot->setVisible(visible);
|
||||
hudRoot->setVisible(visible);
|
||||
|
@ -74,4 +81,4 @@ void GameGui::drawHud(Renderer &renderer) {
|
|||
|
||||
void GameGui::drawMenu(Renderer &renderer) {
|
||||
menuRoot->draw(renderer);
|
||||
}
|
||||
}
|
|
@ -25,9 +25,12 @@ public:
|
|||
void setVisible(bool visible);
|
||||
bool isVisible();
|
||||
|
||||
void buildMenu(sol::state_view state, sol::table menu);
|
||||
const bool isInMenu() const;
|
||||
void showMenu(std::shared_ptr<LuaGuiElement> root);
|
||||
void closeMenu();
|
||||
const bool isInMenu() const;
|
||||
|
||||
void setHud(std::shared_ptr<LuaGuiElement> hud);
|
||||
std::shared_ptr<LuaGuiElement> getHud();
|
||||
|
||||
void drawHud(Renderer& renderer);
|
||||
void drawMenu(Renderer& renderer);
|
||||
|
@ -38,6 +41,8 @@ private:
|
|||
glm::ivec2 win {};
|
||||
bool inMenu = false;
|
||||
|
||||
std::shared_ptr<LuaGuiElement> hudRootElem = nullptr;
|
||||
|
||||
std::shared_ptr<GuiContainer> menuRoot = std::make_shared<GuiInventoryList>("menuRoot");
|
||||
std::shared_ptr<GuiContainer> menuLuaRoot = std::make_shared<GuiInventoryList>("menuLuaRoot");
|
||||
GameGuiBuilder menuBuilder;
|
||||
|
|
|
@ -17,6 +17,13 @@ void GuiBuilder::setGuiRoot(std::shared_ptr<LuaGuiElement> menu) {
|
|||
elements = menu;
|
||||
}
|
||||
|
||||
void GuiBuilder::update() {
|
||||
if (dirty) {
|
||||
build();
|
||||
dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiBuilder::build(glm::ivec2 winBounds) {
|
||||
clear(false);
|
||||
if (winBounds != glm::ivec2 {}) this->winBounds = winBounds;
|
||||
|
@ -87,7 +94,7 @@ void GuiBuilder::clearCallbacks(std::shared_ptr<GuiComponent> component) {
|
|||
}
|
||||
|
||||
void GuiBuilder::elementUpdated() {
|
||||
build();
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
GuiBuilder::~GuiBuilder() {
|
||||
|
|
|
@ -17,6 +17,7 @@ public:
|
|||
|
||||
GuiBuilder(TextureAtlas& textures, ModelStore& models, std::shared_ptr<GuiContainer> root);
|
||||
void setGuiRoot(std::shared_ptr<LuaGuiElement> menu);
|
||||
void update();
|
||||
void build(glm::ivec2 winBounds = {});
|
||||
void clear(bool deleteRoot = true);
|
||||
|
||||
|
@ -36,5 +37,7 @@ protected:
|
|||
std::shared_ptr<LuaGuiElement> elements = nullptr;
|
||||
unsigned int keyInd = 0;
|
||||
|
||||
bool dirty = false;
|
||||
|
||||
glm::ivec2 winBounds {};
|
||||
};
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
namespace SerialGui {
|
||||
const float SCALE_MODIFIER = 3;
|
||||
const float PERCENT_DIFF = 10000;
|
||||
|
||||
namespace {
|
||||
static std::vector<std::string> split(const std::string& value, unsigned int targetCount = 0) {
|
||||
|
@ -55,7 +56,7 @@ namespace SerialGui {
|
|||
if (input.find('%') == input.length() - 1) {
|
||||
double v = std::strtod(input.substr(0, input.find("%")).c_str(), &e) / 100;
|
||||
if (*e != '\0' || errno != 0) throw std::runtime_error("error decoding num from string");
|
||||
return v - 10.f; // Percentages are going to be stored in negatives. Ew.
|
||||
return v - PERCENT_DIFF; // Percentages are going to be stored in negatives. Ew.
|
||||
}
|
||||
|
||||
double v = round(std::strtod(input.c_str(), &e));
|
||||
|
@ -64,9 +65,9 @@ namespace SerialGui {
|
|||
}
|
||||
|
||||
static double convertNum(float input, unsigned int multiple) {
|
||||
if (input >= -20 && input < 0) {
|
||||
if (!multiple) return input + 10;
|
||||
else return (((input + 10) * multiple / SCALE_MODIFIER) * SCALE_MODIFIER);
|
||||
if (input >= -PERCENT_DIFF - 100 && input < -PERCENT_DIFF + 100) {
|
||||
if (!multiple) return input + PERCENT_DIFF;
|
||||
else return (((input + PERCENT_DIFF) * multiple / SCALE_MODIFIER) * SCALE_MODIFIER);
|
||||
}
|
||||
|
||||
return input * SCALE_MODIFIER;
|
||||
|
|
|
@ -48,6 +48,10 @@ void GuiInventoryList::create(glm::vec2 scale, glm::vec4 padding, glm::ivec2 inn
|
|||
drawContents();
|
||||
list->setGuiCallback(std::bind(&GuiInventoryList::drawContents, this));
|
||||
|
||||
setCallback(CallbackType::PRIMARY, nullptr);
|
||||
setCallback(CallbackType::SECONDARY, nullptr);
|
||||
setCallback(CallbackType::HOVER, nullptr);
|
||||
|
||||
hoverRect->create({}, {}, {1, 1, 1, 0.1});
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ void GameScene::update() {
|
|||
if (window.input.isKeyPressed(GLFW_KEY_F1)) {
|
||||
hudVisible = !hudVisible;
|
||||
debugGui.changeVisibilityState(hudVisible ? debugVisible ? 0 : 2 : 1);
|
||||
player.setGuiVisible(hudVisible);
|
||||
player.setHudVisible(hudVisible);
|
||||
}
|
||||
|
||||
if (window.input.isKeyPressed(GLFW_KEY_F3)) {
|
||||
|
|
|
@ -61,6 +61,11 @@ void MenuSandbox::windowResized() {
|
|||
builder.build(win);
|
||||
}
|
||||
|
||||
void MenuSandbox::update(double delta) {
|
||||
LuaParser::update(delta);
|
||||
builder.update();
|
||||
}
|
||||
|
||||
sol::protected_function_result MenuSandbox::runFileSandboxed(const std::string& file) {
|
||||
for (LuaModFile& f : mod.files) {
|
||||
if (f.path == file) {
|
||||
|
|
|
@ -19,13 +19,13 @@ public:
|
|||
MenuSandbox(glm::ivec2& win, ClientState& state, std::shared_ptr<GuiContainer> container);
|
||||
void load(const Subgame& subgame);
|
||||
|
||||
void update(double delta) override;
|
||||
void windowResized();
|
||||
|
||||
using LuaParser::update;
|
||||
private:
|
||||
void reset();
|
||||
void loadApi();
|
||||
void executeMods();
|
||||
void loadAndRunMod(const std::string& modPath);
|
||||
|
||||
sol::protected_function_result runFileSandboxed(const std::string& file);
|
||||
|
|
|
@ -31,9 +31,6 @@ MeshGenStream::MeshGenStream(ClientGame& game, LocalDimension &dimension) :
|
|||
for (int i = 0; i < THREADS; i++) threads.emplace_back(game, noiseSampler);
|
||||
}
|
||||
|
||||
MeshGenStream::Thread::Thread(ClientGame &defs, std::array<NoiseSample, 3>& offsetSamplers) :
|
||||
game(defs), offsetSamplers(offsetSamplers), thread(MeshGenStream::threadFunction, this) {}
|
||||
|
||||
std::vector<ChunkMeshDetails*> MeshGenStream::update() {
|
||||
std::vector<ChunkMeshDetails*> finishedChunks;
|
||||
|
||||
|
@ -75,15 +72,25 @@ std::vector<ChunkMeshDetails*> MeshGenStream::update() {
|
|||
return std::move(finishedChunks);
|
||||
}
|
||||
|
||||
void MeshGenStream::threadFunction(MeshGenStream::Thread *thread) {
|
||||
while (thread->keepAlive) {
|
||||
MeshGenStream::Thread::Thread(ClientGame &defs, std::array<NoiseSample, 3>& offsetSamplers) :
|
||||
game(defs), offsetSamplers(offsetSamplers), thread(std::bind(&MeshGenStream::Thread::exec, this)) {
|
||||
thread.detach();
|
||||
}
|
||||
|
||||
void MeshGenStream::Thread::exec() {
|
||||
while (keepAlive) {
|
||||
bool hasNoTasks = true;
|
||||
|
||||
for (auto i = 0; i < thread->tasks.size(); i++) {
|
||||
auto& u = thread->tasks[i];
|
||||
for (auto i = 0; i < tasks.size(); i++) {
|
||||
auto& u = tasks[i];
|
||||
if (!u.busy) continue;
|
||||
|
||||
ChunkMeshGenerator m(u.meshDetails, thread->game.defs, thread->game.biomes, u.thisChunk, u.adjacentChunks, thread->offsetSamplers);
|
||||
if (u.thisChunk == nullptr) {
|
||||
std::cout << Util::vecToString(u.thisChunk->pos) << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
ChunkMeshGenerator m(u.meshDetails, game.defs, game.biomes, u.thisChunk, u.adjacentChunks, offsetSamplers);
|
||||
hasNoTasks = false;
|
||||
u.busy = false;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
|
||||
struct Thread {
|
||||
explicit Thread(ClientGame &defs, std::array<NoiseSample, 3>& offsetSampler);
|
||||
void exec();
|
||||
|
||||
ClientGame &game;
|
||||
std::array<NoiseSample, 3>& offsetSamplers;
|
||||
|
@ -59,7 +60,6 @@ public:
|
|||
|
||||
std::vector<Thread> threads;
|
||||
private:
|
||||
static void threadFunction(Thread* thread);
|
||||
|
||||
LocalDimension& dimension;
|
||||
ClientGame& game;
|
||||
|
|
|
@ -276,8 +276,8 @@ void Player::setActiveBlock(const std::string& block) {
|
|||
handItemModel.setModel(defs.defs.fromId(activeBlock).entityModel);
|
||||
}
|
||||
|
||||
void Player::buildMenu(sol::state_view state, sol::table menu) {
|
||||
gameGui.buildMenu(state, menu);
|
||||
void Player::showMenu(std::shared_ptr<LuaGuiElement> root) {
|
||||
gameGui.showMenu(root);
|
||||
renderer.window.lockMouse(false);
|
||||
}
|
||||
|
||||
|
@ -286,14 +286,23 @@ void Player::closeMenu() {
|
|||
renderer.window.lockMouse(true);
|
||||
}
|
||||
|
||||
void Player::setGuiVisible(bool hudVisible) {
|
||||
gameGui.setVisible(hudVisible);
|
||||
}
|
||||
|
||||
bool Player::isInMenu() {
|
||||
return gameGui.isInMenu();
|
||||
}
|
||||
|
||||
void Player::setHud(std::shared_ptr<LuaGuiElement> hud) {
|
||||
gameGui.setHud(hud);
|
||||
}
|
||||
|
||||
std::shared_ptr<LuaGuiElement> Player::getHud() {
|
||||
return gameGui.getHud();
|
||||
}
|
||||
|
||||
|
||||
void Player::setHudVisible(bool hudVisible) {
|
||||
gameGui.setVisible(hudVisible);
|
||||
}
|
||||
|
||||
/*
|
||||
* Render functions
|
||||
*/
|
||||
|
|
|
@ -43,10 +43,14 @@ public:
|
|||
|
||||
void setActiveBlock(const std::string& block);
|
||||
|
||||
void buildMenu(sol::state_view state, sol::table menu);
|
||||
void showMenu(std::shared_ptr<LuaGuiElement> root);
|
||||
void closeMenu();
|
||||
bool isInMenu();
|
||||
void setGuiVisible(bool hudVisible);
|
||||
|
||||
void setHud(std::shared_ptr<LuaGuiElement> hud);
|
||||
std::shared_ptr<LuaGuiElement> getHud();
|
||||
|
||||
void setHudVisible(bool hudVisible);
|
||||
|
||||
void draw(Renderer& renderer) override;
|
||||
void drawHud(Renderer& renderer);
|
||||
|
|
|
@ -71,16 +71,15 @@ std::unique_ptr<std::vector<std::shared_ptr<BlockChunk>>> WorldInterpolationStre
|
|||
return finishedChunks;
|
||||
}
|
||||
|
||||
WorldInterpolationStream::Thread::Thread(MapGen *gen) : gen(gen) {
|
||||
thread = std::thread(WorldInterpolationStream::threadFunction, this);
|
||||
WorldInterpolationStream::Thread::Thread(MapGen *gen) : gen(gen),
|
||||
thread(std::bind(&WorldInterpolationStream::Thread::exec, this)) {
|
||||
thread.detach();
|
||||
}
|
||||
|
||||
void WorldInterpolationStream::threadFunction(WorldInterpolationStream::Thread *thread) {
|
||||
while (!thread->kill) {
|
||||
|
||||
void WorldInterpolationStream::Thread::exec() {
|
||||
while (!kill) {
|
||||
bool empty = true;
|
||||
for (Job& u : thread->tasks) {
|
||||
for (Job& u : tasks) {
|
||||
if (u.locked) {
|
||||
if (u.job == JobType::PACKET) {
|
||||
empty = false;
|
||||
|
|
|
@ -51,6 +51,8 @@ private:
|
|||
|
||||
struct Thread {
|
||||
explicit Thread(MapGen* gen);
|
||||
void exec();
|
||||
|
||||
std::thread thread;
|
||||
bool kill = false;
|
||||
|
||||
|
@ -58,9 +60,6 @@ private:
|
|||
std::vector<Job> tasks = std::vector<Job>(THREAD_QUEUE_SIZE);
|
||||
};
|
||||
|
||||
// Function that occurs on the threads.
|
||||
static void threadFunction(Thread* thread);
|
||||
|
||||
std::shared_ptr<MapGenProps> props;
|
||||
MapGen gen;
|
||||
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
#include "../../../../world/chunk/BlockChunk.h"
|
||||
|
||||
ChunkMeshGenerator::ChunkMeshGenerator(ChunkMeshDetails* meshDetails, LocalDefinitionAtlas& defs, LocalBiomeAtlas& biomes,
|
||||
std::shared_ptr<BlockChunk> chunk, std::array<std::shared_ptr<BlockChunk>, 6> adjacent, std::array<NoiseSample, 3>& blockOffsets) :
|
||||
std::shared_ptr<BlockChunk> chunk, std::array<std::shared_ptr<BlockChunk>, 6> adjacent,
|
||||
std::array<NoiseSample, 3>& blockOffsets) :
|
||||
|
||||
defs(defs),
|
||||
chunk(chunk),
|
||||
|
@ -102,19 +103,19 @@ void ChunkMeshGenerator::addFaces(const glm::vec3 &offset, const std::vector<Mes
|
|||
case ShaderMod::ROTATE_Z:
|
||||
case ShaderMod::SWAY_ATTACHED:
|
||||
case ShaderMod::SWAY_FULL_BLOCK:
|
||||
modData = {Util::packFloat((offset - 8.f) / 8.f), mp.modValue, 0};
|
||||
modData = { Util::packFloat((offset - 8.f) / 8.f), mp.modValue, 0 };
|
||||
break;
|
||||
}
|
||||
|
||||
for (const BlockModelVertex &vertex : mp.vertices) {
|
||||
meshDetails->vertices.push_back({
|
||||
vertex.pos + offset,
|
||||
vertex.tex,
|
||||
(mp.blendInd ? tint : glm::vec3 {1, 1, 1}),
|
||||
(mp.blendInd ? vertex.blendMask : glm::vec2 {-1, -1}),
|
||||
Util::packFloat(vertex.nml),
|
||||
static_cast<float>(mp.shaderMod),
|
||||
modData
|
||||
vertex.pos + offset,
|
||||
vertex.tex,
|
||||
mp.blendInd ? tint : glm::vec3 {1, 1, 1},
|
||||
mp.blendInd ? vertex.blendMask : glm::vec2 {-1, -1},
|
||||
Util::packFloat(vertex.nml),
|
||||
static_cast<float>(mp.shaderMod),
|
||||
modData
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ class BlockChunk;
|
|||
class ChunkMeshGenerator {
|
||||
public:
|
||||
ChunkMeshGenerator(ChunkMeshDetails* meshDetails, LocalDefinitionAtlas& defs, LocalBiomeAtlas& biomes,
|
||||
std::shared_ptr<BlockChunk> chunk, std::array<std::shared_ptr<BlockChunk>, 6> adjacent, std::array<NoiseSample, 3>& blockOffsets);
|
||||
std::shared_ptr<BlockChunk> chunk, std::array<std::shared_ptr<BlockChunk>, 6> adjacent,
|
||||
std::array<NoiseSample, 3>& blockOffsets);
|
||||
private:
|
||||
BlockDef& getBlockAt(const glm::ivec3 &pos);
|
||||
void addFaces(const glm::vec3 &offset, const std::vector<MeshPart> &meshParts, const glm::vec3& tint);
|
||||
|
|
|
@ -47,8 +47,16 @@ bool LocalLuaPlayer::is_in_menu() {
|
|||
return player.isInMenu();
|
||||
}
|
||||
|
||||
void LocalLuaPlayer::show_menu(sol::this_state s, sol::table menu) {
|
||||
player.buildMenu(s, menu);
|
||||
void LocalLuaPlayer::show_menu(std::shared_ptr<LuaGuiElement> root) {
|
||||
player.showMenu(root);
|
||||
}
|
||||
|
||||
std::shared_ptr<LuaGuiElement> LocalLuaPlayer::get_hud() {
|
||||
return player.getHud();
|
||||
}
|
||||
|
||||
void LocalLuaPlayer::set_hud(std::shared_ptr<LuaGuiElement> hud) {
|
||||
player.setHud(hud);
|
||||
}
|
||||
|
||||
void LocalLuaPlayer::close_menu() {
|
||||
|
|
|
@ -29,9 +29,12 @@ public:
|
|||
void set_look_pitch(float rot);
|
||||
float get_look_pitch();
|
||||
|
||||
bool is_in_menu();
|
||||
void show_menu(std::shared_ptr<LuaGuiElement> root);
|
||||
void close_menu();
|
||||
void show_menu(sol::this_state s, sol::table menu);
|
||||
bool is_in_menu();
|
||||
|
||||
void set_hud(std::shared_ptr<LuaGuiElement> hud);
|
||||
std::shared_ptr<LuaGuiElement> get_hud();
|
||||
|
||||
LocalLuaInventory get_inventory();
|
||||
|
||||
|
@ -40,3 +43,37 @@ public:
|
|||
void set_flying(bool shouldFly);
|
||||
bool get_flying();
|
||||
};
|
||||
|
||||
namespace ClientApi {
|
||||
static void local_player(sol::state& lua) {
|
||||
lua.new_usertype<LocalLuaPlayer>("LocalPlayer",
|
||||
"set_pos", &LocalLuaPlayer::set_pos,
|
||||
"get_pos", &LocalLuaPlayer::get_pos,
|
||||
"get_block_pos", &LocalLuaPlayer::get_block_pos,
|
||||
"set_vel", &LocalLuaPlayer::set_vel,
|
||||
"get_vel", &LocalLuaPlayer::get_vel,
|
||||
"set_look_yaw", &LocalLuaPlayer::set_look_yaw,
|
||||
"get_look_yaw", &LocalLuaPlayer::get_look_yaw,
|
||||
"set_look_pitch", &LocalLuaPlayer::set_look_pitch,
|
||||
"get_look_pitch", &LocalLuaPlayer::get_look_pitch,
|
||||
|
||||
"get_inventory", &LocalLuaPlayer::get_inventory,
|
||||
"set_selected_block", &LocalLuaPlayer::set_selected_block,
|
||||
|
||||
"show_menu", &LocalLuaPlayer::show_menu,
|
||||
"close_menu", &LocalLuaPlayer::close_menu,
|
||||
"set_hud", &LocalLuaPlayer::set_hud,
|
||||
"get_hud", &LocalLuaPlayer::get_hud,
|
||||
|
||||
"pos", sol::property(&LocalLuaPlayer::get_pos, &LocalLuaPlayer::set_pos),
|
||||
"block_pos", sol::property(&LocalLuaPlayer::get_block_pos, &LocalLuaPlayer::set_pos),
|
||||
"vel", sol::property(&LocalLuaPlayer::get_vel, &LocalLuaPlayer::set_vel),
|
||||
"look_yaw", sol::property(&LocalLuaPlayer::get_look_yaw, &LocalLuaPlayer::set_look_yaw),
|
||||
"look_pitch", sol::property(&LocalLuaPlayer::get_look_pitch, &LocalLuaPlayer::set_look_pitch),
|
||||
|
||||
"flying", sol::property(&LocalLuaPlayer::set_flying, &LocalLuaPlayer::get_flying),
|
||||
|
||||
"in_menu", sol::property(&LocalLuaPlayer::is_in_menu)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -8,18 +8,6 @@
|
|||
|
||||
#include "../../../game/hud/SerialGui.h"
|
||||
|
||||
//LuaGuiElement::LuaGuiElement(const std::string& type, sol::table data) :
|
||||
// type(type) {
|
||||
//
|
||||
// for (const auto& pair : data) {
|
||||
// if (pair.first.is<float>()) {
|
||||
// if (!pair.second.is<std::shared_ptr<LuaGuiElement>>()) throw std::runtime_error("Child is not a GuiElement.");
|
||||
// children.push_back(pair.second.as<std::shared_ptr<LuaGuiElement>>());
|
||||
// }
|
||||
// else if (pair.first.is<std::string>()) set_trait(pair.first.as<std::string>(), pair.second);
|
||||
// }
|
||||
//}
|
||||
|
||||
std::shared_ptr<LuaGuiElement> LuaGuiElement::create(const std::string& type, sol::table data) {
|
||||
auto elem = std::make_shared<LuaGuiElement>();
|
||||
elem->type = type;
|
||||
|
@ -28,6 +16,7 @@ std::shared_ptr<LuaGuiElement> LuaGuiElement::create(const std::string& type, so
|
|||
if (pair.first.is<float>()) {
|
||||
if (!pair.second.is<std::shared_ptr<LuaGuiElement>>()) throw std::runtime_error("Child is not a GuiElement.");
|
||||
elem->children.push_back(pair.second.as<std::shared_ptr<LuaGuiElement>>());
|
||||
elem->children.back()->parent = elem.get();
|
||||
}
|
||||
else if (pair.first.is<std::string>()) elem->set_trait(pair.first.as<std::string>(), pair.second);
|
||||
}
|
||||
|
@ -89,33 +78,45 @@ sol::object LuaGuiElement::get_child(sol::this_state s, sol::object key) {
|
|||
}
|
||||
|
||||
void LuaGuiElement::append(sol::this_state s, sol::object elem) {
|
||||
if (elem.is<LuaGuiElement>()) children.push_back(elem.as<std::shared_ptr<LuaGuiElement>>());
|
||||
if (elem.is<std::shared_ptr<LuaGuiElement>>()) children.push_back(elem.as<std::shared_ptr<LuaGuiElement>>());
|
||||
else if (elem.is<sol::function>()) children.push_back(call(s, elem.as<sol::function>()).as<std::shared_ptr<LuaGuiElement>>());
|
||||
else throw std::runtime_error("Append arg is not an element or a function to generate one.");
|
||||
|
||||
if (updateFunction) updateFunction();
|
||||
children.back()->updateFunction = updateFunction;
|
||||
children.back()->parent = this;
|
||||
}
|
||||
|
||||
void LuaGuiElement::prepend(sol::this_state s, sol::object elem) {
|
||||
if (elem.is<LuaGuiElement>()) children.insert(children.begin(), elem.as<std::shared_ptr<LuaGuiElement>>());
|
||||
if (elem.is<std::shared_ptr<LuaGuiElement>>()) children.insert(children.begin(), elem.as<std::shared_ptr<LuaGuiElement>>());
|
||||
else if (elem.is<sol::function>()) children.insert(children.begin(), call(s, elem.as<sol::function>()).as<std::shared_ptr<LuaGuiElement>>());
|
||||
else throw std::runtime_error("Append arg is not an element or a function to generate one.");
|
||||
|
||||
if (updateFunction) updateFunction();
|
||||
children.front()->updateFunction = updateFunction;
|
||||
children.front()->parent = this;
|
||||
}
|
||||
|
||||
void LuaGuiElement::remove(sol::optional<LuaGuiElement> elem) {
|
||||
void LuaGuiElement::remove(sol::this_state s, sol::object elem) {
|
||||
if (!elem) {
|
||||
if (parent != nullptr) parent->remove(sol::make_optional<LuaGuiElement>(*this));
|
||||
if (parent != nullptr) parent->remove(s, sol::make_object<std::string>(s, key));
|
||||
else throw std::runtime_error("Tried to remove self from nil parent.");
|
||||
}
|
||||
else {
|
||||
for (const auto it = children.cbegin(); it != children.cend();) {
|
||||
if ((*it)->key == elem->key) {
|
||||
children.erase(it);
|
||||
if (updateFunction) updateFunction();
|
||||
else if (elem.is<std::string>()) {
|
||||
auto child = this->get_child(s, sol::make_object<std::string>(s, elem.as<std::string>()));
|
||||
if (!child) throw std::runtime_error("Can't find child of key " + elem.as<std::string>());
|
||||
remove(s, child);
|
||||
}
|
||||
else if (elem.is<std::shared_ptr<LuaGuiElement>>()) {
|
||||
auto parent = elem.as<std::shared_ptr<LuaGuiElement>>()->parent;
|
||||
|
||||
for (auto it = parent->children.cbegin(); it != parent->children.cend(); it++) {
|
||||
if ((*it)->key == elem.as<std::shared_ptr<LuaGuiElement>>()->key) {
|
||||
(*it)->parent = nullptr;
|
||||
(*it)->updateFunction = nullptr;
|
||||
|
||||
parent->children.erase(it);
|
||||
if (parent->updateFunction) parent->updateFunction();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
|
||||
void append(sol::this_state s, sol::object elem);
|
||||
void prepend(sol::this_state s, sol::object elem);
|
||||
void remove(sol::optional<LuaGuiElement> elem);
|
||||
void remove(sol::this_state s, sol::object elem);
|
||||
|
||||
std::string type {}, key {};
|
||||
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
//
|
||||
// Created by aurailus on 2019-10-19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sol2/sol.hpp>
|
||||
#include "../class/LocalLuaPlayer.h"
|
||||
|
||||
namespace ClientApi {
|
||||
void local_player(sol::state& lua) {
|
||||
lua.new_usertype<LocalLuaPlayer>("LocalPlayer",
|
||||
"set_pos", &LocalLuaPlayer::set_pos,
|
||||
"get_pos", &LocalLuaPlayer::get_pos,
|
||||
"get_block_pos", &LocalLuaPlayer::get_block_pos,
|
||||
"set_vel", &LocalLuaPlayer::set_vel,
|
||||
"get_vel", &LocalLuaPlayer::get_vel,
|
||||
"set_look_yaw", &LocalLuaPlayer::set_look_yaw,
|
||||
"get_look_yaw", &LocalLuaPlayer::get_look_yaw,
|
||||
"set_look_pitch", &LocalLuaPlayer::set_look_pitch,
|
||||
"get_look_pitch", &LocalLuaPlayer::get_look_pitch,
|
||||
|
||||
"get_inventory", &LocalLuaPlayer::get_inventory,
|
||||
"set_selected_block", &LocalLuaPlayer::set_selected_block,
|
||||
|
||||
"show_menu", &LocalLuaPlayer::show_menu,
|
||||
"close_menu", &LocalLuaPlayer::close_menu,
|
||||
|
||||
"pos", sol::property(&LocalLuaPlayer::get_pos, &LocalLuaPlayer::set_pos),
|
||||
"block_pos", sol::property(&LocalLuaPlayer::get_block_pos, &LocalLuaPlayer::set_pos),
|
||||
"vel", sol::property(&LocalLuaPlayer::get_vel, &LocalLuaPlayer::set_vel),
|
||||
"look_yaw", sol::property(&LocalLuaPlayer::get_look_yaw, &LocalLuaPlayer::set_look_yaw),
|
||||
"look_pitch", sol::property(&LocalLuaPlayer::get_look_pitch, &LocalLuaPlayer::set_look_pitch),
|
||||
|
||||
"flying", sol::property(&LocalLuaPlayer::set_flying, &LocalLuaPlayer::get_flying),
|
||||
|
||||
"in_menu", sol::property(&LocalLuaPlayer::is_in_menu)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
// Usertypes
|
||||
#include "../api/class/LuaGuiElement.h"
|
||||
#include "../api/usertype/cItemStack.h"
|
||||
#include "../api/usertype/cLocalPlayer.h"
|
||||
#include "../api/class/LocalLuaPlayer.h"
|
||||
#include "../api/usertype/cLuaEntity.h"
|
||||
#include "../api/usertype/cInventoryRef.h"
|
||||
#include "../api/usertype/cAnimationManager.h"
|
||||
|
|
|
@ -51,19 +51,18 @@ std::unique_ptr<std::vector<std::shared_ptr<BlockChunk>>> ServerGenStream::updat
|
|||
return finishedChunks;
|
||||
}
|
||||
|
||||
ServerGenStream::Thread::Thread(MapGen *gen) : gen(gen) {
|
||||
thread = std::thread(ServerGenStream::threadFunction, this);
|
||||
ServerGenStream::Thread::Thread(MapGen *gen) : gen(gen),
|
||||
thread(std::bind(&ServerGenStream::Thread::exec, this)) {
|
||||
thread.detach();
|
||||
}
|
||||
|
||||
void ServerGenStream::threadFunction(ServerGenStream::Thread *thread) {
|
||||
while (!thread->kill) {
|
||||
|
||||
void ServerGenStream::Thread::exec() {
|
||||
while (!kill) {
|
||||
bool empty = true;
|
||||
for (Job& u : thread->tasks) {
|
||||
for (Job& u : tasks) {
|
||||
if (u.locked) {
|
||||
empty = false;
|
||||
u.chunks = thread->gen->generateMapBlock(u.pos);
|
||||
u.chunks = gen->generateMapBlock(u.pos);
|
||||
u.locked = false;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ private:
|
|||
|
||||
struct Thread {
|
||||
explicit Thread(MapGen* gen);
|
||||
void exec();
|
||||
|
||||
std::thread thread;
|
||||
bool kill = false;
|
||||
|
||||
|
@ -44,9 +46,6 @@ private:
|
|||
std::vector<Job> tasks = std::vector<Job>(THREAD_QUEUE_SIZE);
|
||||
};
|
||||
|
||||
// Function that occurs on the threads.
|
||||
static void threadFunction(Thread* thread);
|
||||
|
||||
std::shared_ptr<MapGenProps> props;
|
||||
MapGen gen;
|
||||
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
zepha.set_gui(zepha.build_gui(function()
|
||||
local menu = zepha.build_gui(function()
|
||||
return Gui.Body {
|
||||
background = "zeus_background",
|
||||
background = "zeus_background_christmas_night",
|
||||
|
||||
Gui.Rect {
|
||||
key = "particle_wrap",
|
||||
size = { pc(100), pc(100) }
|
||||
},
|
||||
|
||||
Gui.Rect {
|
||||
key = "sidebar",
|
||||
|
@ -45,4 +50,47 @@ zepha.set_gui(zepha.build_gui(function()
|
|||
}
|
||||
}
|
||||
}
|
||||
end))
|
||||
end)
|
||||
|
||||
-- zepha.delay(function()
|
||||
-- menu:remove("buttonPlay")
|
||||
-- menu:remove("buttonServers")
|
||||
-- menu:get("sidebar"):append(function(m) return Gui.Text({
|
||||
-- position = {16, 120 },
|
||||
-- color = "#f00",
|
||||
-- content = "YOU LOSE" }
|
||||
-- ) end)
|
||||
-- end, 1)
|
||||
|
||||
local particle_wrap = menu:get("particle_wrap")
|
||||
menu(function()
|
||||
for _ = 1, 20 do
|
||||
local scale = 6 + math.random() * 4
|
||||
particle_wrap:append(Gui.Rect {
|
||||
position = { math.floor(math.random() * 600), math.floor(math.random() * 320) },
|
||||
background = "particle_dark",
|
||||
size = { scale, scale }
|
||||
})
|
||||
end
|
||||
end)
|
||||
|
||||
local tick = 0
|
||||
zepha.delay(function()
|
||||
local i = 1
|
||||
local part = particle_wrap:get(i)
|
||||
tick = tick + 0.012
|
||||
while part ~= nil do
|
||||
local xO = (-math.sin(tick) * 0.0125 - 0.0025) * part.size[1]
|
||||
local pos = { part.position[1] + xO, part.position[2] + 0.05 * part.size[1] }
|
||||
if pos[2] > 320 then pos[2] = -12 end
|
||||
if pos[1] < -12 then pos[1] = 600 end
|
||||
part.position = pos
|
||||
i = i + 1
|
||||
part = particle_wrap:get(i)
|
||||
end
|
||||
return true
|
||||
end, 0.016)
|
||||
|
||||
|
||||
|
||||
zepha.set_gui(menu)
|
Binary file not shown.
Before Width: | Height: | Size: 329 B After Width: | Height: | Size: 572 B |
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "@aurailus:hot_wheel",
|
||||
"description": "A speedy way to select items from your inventory :3",
|
||||
"version": "0.0.1"
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
if zepha.server then return end
|
||||
|
||||
local hud = zepha.player:get_hud()
|
||||
hud:append(function() return Gui.Rect {
|
||||
key = "hot_wheel_root",
|
||||
|
||||
size = { 139, 70 },
|
||||
position = { "0%", "100%" },
|
||||
position_anchor = { "-10%", "110%" },
|
||||
-- background = "#966"
|
||||
} end)
|
||||
local root = hud:get("hot_wheel_root")
|
||||
|
||||
root(function(e)
|
||||
|
||||
e:append(Gui.Rect {
|
||||
size = { 68, 68 },
|
||||
background = "@aurailus:hot_wheel:hot_wheel_circle",
|
||||
|
||||
Gui.InventoryList {
|
||||
position = { 1, 1 },
|
||||
slot_spacing = { 2, 2 },
|
||||
length = 1,
|
||||
source = "current_player",
|
||||
list = "main",
|
||||
}
|
||||
})
|
||||
|
||||
e:append(Gui.Rect {
|
||||
size = { 84, 18 },
|
||||
position = { 47, 13 },
|
||||
background = "@aurailus:hot_wheel:hot_wheel_line",
|
||||
})
|
||||
|
||||
-- e:append(Gui.Rect {
|
||||
-- size = { 88, 28 },
|
||||
-- position = { 52, 12 },
|
||||
-- background = "@aurailus:hot_wheel:slots_expanded"
|
||||
-- })
|
||||
|
||||
end)
|
|
@ -51,17 +51,17 @@ local menu = zepha.build_gui(function()
|
|||
key = "player_clamp",
|
||||
|
||||
position = { 41, -8 },
|
||||
size = { 32, 52 },
|
||||
size = { 34, 52 },
|
||||
overflow = "hidden",
|
||||
|
||||
Gui.Model {
|
||||
position = { 15, 52 },
|
||||
scale = { 86, 86 },
|
||||
scale = { 28, 28 },
|
||||
|
||||
type = "model",
|
||||
source = "zeus:default:player",
|
||||
texture = "zeus:default:player",
|
||||
anim_range = { 0, 300 }
|
||||
anim_range = { 0, 100 }
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue