Fix Codacy issues

master
Nicole Collings 2020-02-26 13:42:15 -08:00
parent 228e0e4d30
commit 6b4c866ba7
64 changed files with 137 additions and 154 deletions

View File

@ -213,9 +213,9 @@ set(ZEPHA_SRC
game/hud/components/compound/GuiInventoryList.h
game/hud/components/basic/GuiInventoryItem.cpp
game/hud/components/basic/GuiInventoryItem.h
game/scene/world/InventoryList.cpp
game/scene/world/InventoryList.h
game/scene/world/ItemStack.h
game/inventory/InventoryList.cpp
game/inventory/InventoryList.h
game/inventory/ItemStack.h
server/LocalServerInstance.cpp
server/LocalServerInstance.h
game/hud/SerialGui.h
@ -251,11 +251,11 @@ set(ZEPHA_SRC
lua/api/class/ServerLuaInventoryList.h
lua/api/class/ServerLuaInventory.cpp
lua/api/class/ServerLuaInventory.h
game/scene/world/Inventory.cpp
game/scene/world/Inventory.h
game/inventory/Inventory.cpp
game/inventory/Inventory.h
lua/api/class/LuaItemStack.cpp
lua/api/class/LuaItemStack.h
game/scene/world/ItemStack.cpp
game/inventory/ItemStack.cpp
lua/api/usertype/cInventoryRef.h
lua/api/usertype/cItemStack.h
game/hud/components/basic/GuiModel.cpp
@ -306,10 +306,10 @@ set(ZEPHA_SRC
lua/parser/LocalModHandler.cpp
lua/parser/LocalModHandler.h
game/scene/net/NetPlayerField.h
game/scene/world/LocalInventoryRefs.cpp
game/scene/world/LocalInventoryRefs.h
game/scene/world/LocalInventory.cpp
game/scene/world/LocalInventory.h
game/inventory/LocalInventoryRefs.cpp
game/inventory/LocalInventoryRefs.h
game/inventory/LocalInventory.cpp
game/inventory/LocalInventory.h
lua/api/class/LocalLuaInventory.cpp
lua/api/class/LocalLuaInventory.h
lua/api/class/LocalLuaInventoryList.cpp

View File

@ -101,7 +101,7 @@ int StartGame(int argc, char* argv[]) {
break;
}
case Mode::SERVER: {
Server s(path, addr.port, subgame);
Server s(addr.port, subgame);
break;
}
}

View File

@ -5,10 +5,8 @@
#include "ServerGame.h"
#include "../server/conn/ClientList.h"
ServerGame::ServerGame(const std::string& subgame, const std::string& execPath) {
size_t exec = execPath.find_last_of('/');
std::string gamePath = execPath.substr(0, exec + 1);
subgamePath += "subgames/" + subgame + "/";
ServerGame::ServerGame(const std::string& subgame) :
subgamePath("subgames/" + subgame + "/") {
if (subgame.empty()) {
std::cout << Log::err << "No subgame specified." << Log::endl;

View File

@ -15,13 +15,11 @@ class ClientList;
class ServerGame {
public:
ServerGame(const std::string& subgame, const std::string& execPath);
ServerGame(const std::string& subgame);
void init(ServerWorld& world);
void update(double delta, ClientList& clients);
~ServerGame() = default;
std::string subgamePath = "";
std::string subgamePath;
ServerDefinitionAtlas defs;
ServerLuaParser parser;

View File

@ -88,7 +88,6 @@ void MapGen::buildDensityMap(MapGenJob* job, glm::ivec3 worldPos) {
// TODO: This is... a travesty. Please stop doing this weird jank insertion into a
// noisesample and create a proper constructor or *something*... could probs use a module owo
auto biome = biomes.getBiomeAt(job->temperature.get({}), job->humidity.get({}), job->roughness.get({}));
auto terrain = NoiseSample({4, 4});
float offsetH = 16.f / 4.f;

View File

@ -21,7 +21,7 @@ unsigned int Font::getCharWidth(char c) {
}
void Font::getCharWidths(TextureAtlas &atlas) {
const unsigned char* data = atlas.atlasData;
auto& data = atlas.atlasData;
charWidths[0] = 2;

View File

@ -8,7 +8,7 @@
TextureAtlas::TextureAtlas(unsigned int width, unsigned int height) :
pixelSize(width, (height == 0 ? width : height)),
tileSize(pixelSize.x / 16, pixelSize.y / 16),
atlasData(new unsigned char[pixelSize.x * 4 * pixelSize.y]) {
atlasData(pixelSize.x * 4 * pixelSize.y) {
maxTextureSlots = tileSize.x * tileSize.y;
@ -21,9 +21,7 @@ TextureAtlas::TextureAtlas(unsigned int width, unsigned int height) :
// std::cout << Log::info << "This GPU supports " << texUnits << " texture units." << Log::endl;
empty = std::vector<bool>(tileSize.x * tileSize.y, true);
for (int i = 0; i < pixelSize.x * 4 * pixelSize.y; i++) atlasData[i] = 0;
atlasTexture.loadFromBytes(atlasData, pixelSize.x, pixelSize.y);
atlasTexture.loadFromBytes(&atlasData[0], pixelSize.x, pixelSize.y);
createMissingImage();
}
@ -160,11 +158,6 @@ std::shared_ptr<AtlasRef> TextureAtlas::operator[](const std::string &name) {
return textures["_missing"];
}
TextureAtlas::~TextureAtlas() {
delete[] atlasData;
}
std::shared_ptr<AtlasRef> TextureAtlas::generateTexture(std::string req) {
req.erase(std::remove(req.begin(), req.end(), ' '), req.end());

View File

@ -22,25 +22,23 @@ class TextureAtlas {
public:
TextureAtlas() = default;
explicit TextureAtlas(unsigned int width, unsigned int height = 0);
std::vector<std::shared_ptr<AtlasRef>> loadDirectory(const std::string& path, bool base = true, bool recursive = true);
std::shared_ptr<AtlasRef> loadImage(const std::string& path, const std::string& name, bool base = false);
void update();
std::vector<std::shared_ptr<AtlasRef>> loadDirectory(const std::string& path, bool base = true, bool recursive = true);
std::shared_ptr<AtlasRef> loadImage(const std::string& path, const std::string& name, bool base = false);
glm::vec4 sampleTexturePixel(const std::shared_ptr<AtlasRef>& atlasRef, glm::vec2 pixel);
std::shared_ptr<AtlasRef> operator[](const std::string& name);
std::shared_ptr<AtlasRef> addImage(unsigned char *data, const std::string& name, bool base, int texWidth, int texHeight);
std::shared_ptr<AtlasRef> generateCrackImage(const std::string &name, unsigned short crackLevel);
std::shared_ptr<AtlasRef> operator[](const std::string& name);
~TextureAtlas();
glm::ivec2 pixelSize {};
glm::ivec2 tileSize {};
Texture atlasTexture {};
unsigned char* atlasData = nullptr;
std::vector<unsigned char> atlasData;
unsigned int textureSlotsUsed = 0;
unsigned int maxTextureSlots = 0;

View File

@ -41,13 +41,13 @@ void Client::loop() {
}
double now = glfwGetTime();
state.deltaTime = now - timeElapsed;
state.delta = now - timeElapsed;
timeElapsed = now;
glfwPollEvents();
sceneManager.update();
renderer.update(state.deltaTime);
renderer.update(state.delta);
state.fps = 1000.0 / (t.elapsedNs() / 1000000.0);
}

View File

@ -23,5 +23,5 @@ public:
std::string desiredState = "this";
double fps = 0;
double deltaTime = 0;
double delta = 0;
};

View File

@ -53,7 +53,6 @@ bool Collidable::collidesAt(glm::vec3& pos, float stepUpMax) {
// Find the minimum vertical increase needed to step up
float stepUpAmount = 0;
if (stepUpMax > 0) {
SelectionBox collidableBox = {collisionBox.a + pos, collisionBox.b + pos};
glm::vec3 offset {};
offset.x = collisionBox.a.x;

View File

@ -6,9 +6,7 @@
#include "Entity.h"
Entity::Entity() {
model = std::make_unique<Model>();
};
Entity::Entity() : model(std::make_unique<Model>()) {}
Entity::Entity(std::shared_ptr<Model> model) : animState(*model), model(model) {}

View File

@ -94,9 +94,10 @@ void Model::loadMeshAndBone(aiMesh *mesh, std::unique_ptr<EntityMesh>& target) {
vertex.colorBlend = {1, 1, 1};
assert(mesh->mMaterialIndex >= 0 && mesh->mMaterialIndex < textures.size());
auto& texture = textures[mesh->mMaterialIndex];
if (mesh->mTextureCoords[0]) {
auto& texture = textures[mesh->mMaterialIndex];
//Set texture coordinates
vertex.useTex = true;
vertex.colorData = {

View File

@ -45,9 +45,8 @@ public:
private:
void renderQuad();
unsigned int quadVAO = 0, quadVBO;
unsigned int sBuffer, sDepthMap;
unsigned int quadVAO = 0;
unsigned int quadVBO = 0;
glm::vec4 clearColor {0, 0, 0, 1};
Texture* activeTexture;

View File

@ -4,10 +4,7 @@
#include "FrustumAABB.h"
FrustumAABB::FrustumAABB(glm::vec3 a, glm::vec3 s) {
corner = a;
size = s;
}
FrustumAABB::FrustumAABB(glm::vec3 a, glm::vec3 s) : corner(a), size(s) {}
void FrustumAABB::set(glm::vec3 a, glm::vec3 s) {
corner = a;

View File

@ -21,10 +21,10 @@ public:
Uniforms uniforms {};
unsigned int fbo;
unsigned int colorBuffer;
unsigned int fbo = 0;
unsigned int colorBuffer = 0;
private:
glm::ivec2 windowSize;
float bufferScale;
glm::ivec2 windowSize {};
float bufferScale = 1;
};

View File

@ -25,11 +25,11 @@ public:
Uniforms uniforms {};
unsigned int gBuffer;
unsigned int gPosition;
unsigned int gNormal;
unsigned int gColorSpec;
unsigned int rDepth;
unsigned int gBuffer = 0;
unsigned int gPosition = 0;
unsigned int gNormal = 0;
unsigned int gColorSpec = 0;
unsigned int rDepth = 0;
private:
glm::ivec2 windowSize {};

View File

@ -31,9 +31,9 @@ public:
std::vector<glm::vec3> kernels {};
std::vector<glm::vec3> noise {};
unsigned int tex;
unsigned int fbo;
unsigned int colorBuffer;
unsigned int tex = 0;
unsigned int fbo = 0;
unsigned int colorBuffer = 0;
private:
glm::ivec2 windowSize {};

View File

@ -9,14 +9,14 @@
WorldGeometryShader::WorldGeometryShader(glm::ivec2 windowSize, float bufferScale) : Shader(),
windowSize(windowSize),
bufferScale(bufferScale),
swayData(new unsigned char[16 * 4 * 16]) {
swayData(16 * 4 * 16) {
swayNoise.SetFrequency(0.20);
swayNoise.SetOctaveCount(2);
}
void WorldGeometryShader::postCreate() {
swayTex.loadFromBytes(swayData, 16, 16, GL_LINEAR, GL_MIRRORED_REPEAT);
swayTex.loadFromBytes(&swayData[0], 16, 16, GL_LINEAR, GL_MIRRORED_REPEAT);
uniforms.proj = get("projection");
uniforms.model = get("model");
@ -39,10 +39,5 @@ void WorldGeometryShader::updateSwayMap(double delta) {
swayData[i*4+1] = static_cast<unsigned char>((fmax(-1, fmin(1, swayNoise.GetValue((i / 16) / 3.f, (i % 16) / 3.f, swayOffset + 50))) + 1) / 2.f * 255.f);
swayData[i*4+2] = static_cast<unsigned char>((fmax(-1, fmin(1, swayNoise.GetValue((i / 16) / 3.f, (i % 16) / 3.f, swayOffset + 100))) + 1) / 2.f * 255.f);
}
swayTex.updateTexture(0, 0, 16, 16, swayData);
}
WorldGeometryShader::~WorldGeometryShader() {
swayTex.clear();
delete[] swayData;
}
swayTex.updateTexture(0, 0, 16, 16, &swayData[0]);
}

View File

@ -4,8 +4,11 @@
#pragma once
#include <vector>
#include <noise/noise.h>
#include "Shader.h"
#include "../Texture.h"
class WorldGeometryShader : public Shader {
@ -16,8 +19,6 @@ public:
void windowResized(glm::ivec2 windowSize);
void updateSwayMap(double delta);
~WorldGeometryShader();
struct Uniforms {
GLint proj;
GLint model;
@ -33,7 +34,7 @@ public:
Texture swayTex;
double swayOffset = 0;
noise::module::Perlin swayNoise;
unsigned char* swayData = nullptr;
std::vector<unsigned char> swayData {};
glm::ivec2 windowSize {};
float bufferScale = 1;

View File

@ -38,7 +38,7 @@ public:
Input input;
bool keys[1024] {};
private:
GLFWwindow *mainWindow;
GLFWwindow *mainWindow = nullptr;
glm::ivec2 win;
glm::ivec2 center;

View File

@ -15,7 +15,7 @@
#include "components/basic/GuiGraph.h"
#include "components/basic/GuiText.h"
#include "components/basic/GuiContainer.h"
#include "../scene/world/InventoryList.h"
#include "../inventory/InventoryList.h"
class DebugGui : public GuiContainer {
public:

View File

@ -10,11 +10,11 @@
#include "components/basic/GuiRect.h"
#include "components/basic/GuiContainer.h"
#include "../graph/drawable/DrawableGroup.h"
#include "../scene/world/InventoryList.h"
#include "../inventory/InventoryList.h"
#include "../entity/Entity.h"
#include "../../util/Util.h"
#include "components/compound/GuiInventoryList.h"
#include "../scene/world/Inventory.h"
#include "../inventory/Inventory.h"
class GameGui : public GuiContainer {
public:

View File

@ -6,8 +6,8 @@
#include "GuiBuilder.h"
#include "../scene/world/Inventory.h"
#include "../scene/world/LocalInventoryRefs.h"
#include "../inventory/Inventory.h"
#include "../inventory/LocalInventoryRefs.h"
class GameGuiBuilder : public GuiBuilder {
public:

View File

@ -87,7 +87,7 @@ void GuiBuilder::deserialize(const std::string& menu) {
}
else {
component->children.push_back(std::move(g));
if (component != nullptr) stack.push_back(component);
stack.push_back(component);
component = &component->children[component->children.size() - 1];
}
}

View File

@ -32,7 +32,7 @@ std::shared_ptr<GuiText> GuiText::fromSerialized(SerialGui::Elem s, ClientGame &
if (scale == glm::vec2{0, 0}) scale = {1, 1};
pos -= offset * size;
size -= glm::vec2 {padding.y + padding.w, padding.x + padding.z};
// size -= glm::vec2 {padding.y + padding.w, padding.x + padding.z};
glm::vec4 background_color = Util::hexToColorVec("#0000");
if (s.tokens.count("background")) background_color = Util::hexToColorVec(s.tokens["background"]);

View File

@ -5,7 +5,7 @@
#include "GuiInventoryList.h"
#include "../basic/GuiInventoryItem.h"
#include "../../../scene/world/LocalInventoryList.cpp"
#include "../../../inventory/LocalInventoryList.cpp"
#include "../../../../def/texture/Font.h"
GuiInventoryList::GuiInventoryList(const std::string &key) : GuiContainer(key) {}
@ -14,7 +14,7 @@ std::shared_ptr<GuiInventoryList> GuiInventoryList::fromSerialized(SerialGui::El
glm::vec2 pos = SerialGui::deserializeToken<glm::vec2>(s.tokens, "position", bounds);
glm::vec2 offset = SerialGui::deserializeToken<glm::vec2>(s.tokens, "position_anchor");
glm::vec2 size = SerialGui::deserializeToken<glm::vec2>(s.tokens, "size", bounds);
// glm::vec2 size = SerialGui::deserializeToken<glm::vec2>(s.tokens, "size", bounds);
glm::vec4 padding = SerialGui::deserializeToken<glm::vec4>(s.tokens, "padding", bounds);
glm::vec2 slotspc = SerialGui::deserializeToken<glm::vec2>(s.tokens, "slot_spacing", bounds);
@ -117,12 +117,11 @@ void GuiInventoryList::rightClick(bool down, glm::ivec2 pos) {
slot.y = std::min(slot.y, list->getLength() / list->getWidth() - 1);
unsigned short index = slot.x + slot.y * list->getWidth();
if (index < 0 || index >= list->getLength()) return;
if (index >= list->getLength()) return;
if (down) {
auto handStack = hand->getStack(0);
if (handStack.count <= 0) {
if (handStack.count == 0) {
hand->setStack(0, list->splitStack(index, true));
}
else {

View File

@ -9,9 +9,9 @@
#include "../basic/GuiRect.h"
#include "../../SerialGui.h"
#include "../../../../def/ClientGame.h"
#include "../../../scene/world/Inventory.h"
#include "../../../scene/world/LocalInventoryList.h"
#include "../../../scene/world/LocalInventoryRefs.h"
#include "../../../inventory/Inventory.h"
#include "../../../inventory/LocalInventoryList.h"
#include "../../../inventory/LocalInventoryRefs.h"
class GuiInventoryList : public GuiContainer {
public:
@ -38,5 +38,5 @@ private:
std::shared_ptr<LocalInventoryList> list, hand;
glm::ivec2 innerPadding;
ClientGame* defs;
ClientGame* defs = nullptr;
};

View File

@ -46,9 +46,6 @@ void GuiLabelledGraph::pushValue(float value) {
if (++ind >= 5) {
ind = 0;
float val = 0;
for (float i : history) val += i / 5;
std::string stringVal = (value == static_cast<int>(value))
? std::to_string(static_cast<int>(value))
: Util::floatToString(value);

View File

@ -5,9 +5,9 @@
#include <iostream>
#include <algorithm>
#include "InventoryList.h"
#include "../../../lua/api/class/LuaItemStack.h"
#include "../../lua/api/class/LuaItemStack.h"
InventoryList::InventoryList(DefinitionAtlas& defs, std::string name, unsigned short size, unsigned short width) :
InventoryList::InventoryList(DefinitionAtlas& defs, const std::string& name, unsigned short size, unsigned short width) :
defs(defs),
name(name),
itemstacks(size),

View File

@ -13,7 +13,7 @@ class InventoryList {
public:
enum class Callback { ALLOW_TAKE, ALLOW_PUT, ON_TAKE, ON_PUT };
InventoryList(DefinitionAtlas& defs, std::string name, unsigned short size, unsigned short width);
InventoryList(DefinitionAtlas& defs, const std::string& name, unsigned short size, unsigned short width);
unsigned short getLength();
unsigned short getWidth();

View File

@ -3,7 +3,7 @@
//
#include "ItemStack.h"
#include "../../../lua/api/class/LuaItemStack.h"
#include "../../lua/api/class/LuaItemStack.h"
ItemStack::ItemStack(LuaItemStack &stack, const DefinitionAtlas &atlas) :
id((stack.get_count() == 0) ? 0 : atlas.fromStr(stack.get_name()).index),

View File

@ -5,7 +5,7 @@
#pragma once
#include <string>
#include "../../../def/DefinitionAtlas.h"
#include "../../def/DefinitionAtlas.h"
class LuaItemStack;

View File

@ -17,11 +17,11 @@ bool LocalInventory::pruneLists(ClientNetworkInterpreter &net, double time) {
for (auto lIt = lists.begin(); lIt != lists.end();) {
if (lIt->second.first != -1) {
// Start the timeout for Inventories that aren't being used.
if (lIt->second.first == 0 && lIt->second.second.use_count() == 1) lIt->second.first = time + 60;
if (lIt->second.first == 0 && lIt->second.second.use_count() == 1) lIt->second.first = time + 15;
// Remove the timeout for Inventories that are being used.
else if (lIt->second.first != 0 && lIt->second.second.use_count() > 1) lIt->second.first = 0;
// Delete InventoryLists that have passed their timeout.
else if (lIt->second.first <= time) {
else if (lIt->second.first != 0 && lIt->second.first <= time) {
net.unwatchInv(name, lIt->first);
lIt = lists.erase(lIt);
}

View File

@ -6,8 +6,8 @@
#include "LocalInventoryList.h"
#include "../../../def/DefinitionAtlas.h"
#include "../net/ClientNetworkInterpreter.h"
#include "../../def/DefinitionAtlas.h"
#include "../scene/net/ClientNetworkInterpreter.h"
class LocalInventory {
public:

View File

@ -7,9 +7,9 @@
#include "LocalInventoryList.h"
#include "../../../lua/api/class/LuaItemStack.h"
#include "../../lua/api/class/LuaItemStack.h"
LocalInventoryList::LocalInventoryList(DefinitionAtlas& defs, std::string name, unsigned short size, unsigned short width) :
LocalInventoryList::LocalInventoryList(DefinitionAtlas& defs, const std::string& name, unsigned short size, unsigned short width) :
defs(defs),
name(name),
itemstacks(size),

View File

@ -14,7 +14,7 @@ class LocalInventoryList {
public:
enum class Callback { ALLOW_TAKE, ALLOW_PUT, ON_TAKE, ON_PUT };
LocalInventoryList(DefinitionAtlas& defs, std::string name, unsigned short size, unsigned short width);
LocalInventoryList(DefinitionAtlas& defs, const std::string& name, unsigned short size, unsigned short width);
unsigned short getLength();
unsigned short getWidth();

View File

@ -8,7 +8,6 @@ LocalInventoryRefs::LocalInventoryRefs(LocalDefinitionAtlas& defs, ClientNetwork
defs(defs),
net(net) {
std::cout << "Constructred default inv" << std::endl;
inventories.insert({"current_player", std::make_shared<LocalInventory>(defs, "current_player")});
inventories["current_player"]->createList("hand", 1, 1, true);
}
@ -17,8 +16,7 @@ void LocalInventoryRefs::update(double delta) {
time += delta;
for (auto mIt = inventories.begin(); mIt != inventories.end();) {
bool del = mIt->second->pruneLists(net, time);
if (del) mIt = inventories.erase(mIt);
if (mIt->second->pruneLists(net, time)) mIt = inventories.erase(mIt);
else mIt++;
}
}

View File

@ -9,8 +9,8 @@
#include "LocalInventory.h"
#include "LocalInventoryList.h"
#include "../net/ClientNetworkInterpreter.h"
#include "../../../def/LocalDefinitionAtlas.h"
#include "../scene/net/ClientNetworkInterpreter.h"
#include "../../def/LocalDefinitionAtlas.h"
class LocalInventoryRefs {
public:

View File

@ -179,7 +179,7 @@ void ConnectScene::handleConnecting() {
case ServerConnection::State::ATTEMPTING_CONNECT:
connection.processConnecting();
dotsTime += state.deltaTime;
dotsTime += state.delta;
if (dotsTime > 1) {
dotsTime -= 1;
statusText->setText(statusText->getText() + ".");

View File

@ -28,24 +28,25 @@ GameScene::GameScene(ClientState& state) : Scene(state),
}
void GameScene::update() {
game.update(state.deltaTime, state.renderer.window.keys);
game.update(state.delta, state.renderer.window.keys);
game.textures.update();
refs.update(state.delta);
net.update();
Window& window = state.renderer.window;
//Update Player
player.update(window.input, state.deltaTime, window.getDelta());
player.update(window.input, state.delta, window.getDelta());
playerPos = player.getPos();
for (auto entity : entities) entity->update(state.deltaTime);
for (auto entity : entities) entity->update(state.delta);
for (auto &chunkPacket : net.chunkPackets) world.loadChunkPacket(std::move(chunkPacket));
net.chunkPackets.clear();
debugGui.update(player, world, game, state.fps, world.getMeshChunkCount(), drawCalls, net.serverSideChunkGens, net.recvPackets);
net.recvPackets = 0;
world.update(state.deltaTime);
world.update(state.delta);
if (window.input.isKeyPressed(GLFW_KEY_F1)) {
hudVisible = !hudVisible;

View File

@ -194,7 +194,7 @@ void MainMenuScene::positionElements() {
void MainMenuScene::update() {
state.defs.textures.update();
sandbox.update(state.deltaTime);
sandbox.update(state.delta);
state.renderer.window.setCursorHand(components.mouseActivity(state.renderer.window.getMousePos()));
if (state.renderer.window.input.isMousePressed(GLFW_MOUSE_BUTTON_LEFT))

View File

@ -52,7 +52,7 @@ void MenuSandbox::windowResized() {
builder.build(win);
}
sol::protected_function_result MenuSandbox::DoFileSandboxed(std::string file) {
sol::protected_function_result MenuSandbox::DoFileSandboxed(const std::string& file) {
for (LuaModFile& f : mod.files) {
if (f.path == file) {

View File

@ -26,7 +26,8 @@ private:
void setup();
void loadMod(const std::string& modPath);
sol::protected_function_result DoFileSandboxed(std::string file);
sol::protected_function_result DoFileSandboxed(const std::string& file);
LuaMod mod {};
std::vector<std::shared_ptr<AtlasRef>> modAssets {};

View File

@ -4,7 +4,7 @@
#pragma once
#include "Inventory.h"
#include "../../inventory/Inventory.h"
#include "../../hud/GameGui.h"
#include "../../entity/Collidable.h"
#include "../../hud/GameGuiBuilder.h"

View File

@ -5,7 +5,7 @@
#pragma once
#include "LocalLuaInventoryList.h"
#include "../../../game/scene/world/LocalInventory.h"
#include "../../../game/inventory/LocalInventory.h"
class LocalLuaInventory {
public:

View File

@ -4,7 +4,7 @@
#pragma once
#include "../../../game/scene/world/LocalInventoryList.h"
#include "../../../game/inventory/LocalInventoryList.h"
class LocalLuaInventoryList {
public:

View File

@ -8,7 +8,7 @@ LuaItemStack::LuaItemStack(const ItemStack &stack, const DefinitionAtlas &defs)
name((stack.count == 0 ? "" : defs.fromId(stack.id).identifier)),
count(stack.count) {}
LuaItemStack::LuaItemStack(std::string name, unsigned short count) :
LuaItemStack::LuaItemStack(const std::string& name, unsigned short count) :
name(name), count(count) {}
LuaItemStack::LuaItemStack(sol::table tbl) :

View File

@ -4,14 +4,14 @@
#pragma once
#include "../../../game/scene/world/ItemStack.h"
#include "../../../game/inventory/ItemStack.h"
#include "../../../def/DefinitionAtlas.h"
class LuaItemStack {
public:
LuaItemStack() = default;
LuaItemStack(const ItemStack& stack, const DefinitionAtlas& defs);
LuaItemStack(std::string name, unsigned short count);
LuaItemStack(const std::string& name, unsigned short count);
LuaItemStack(sol::table tbl);
std::string get_name();

View File

@ -4,7 +4,7 @@
#pragma once
#include "../../../game/scene/world/Inventory.h"
#include "../../../game/inventory/Inventory.h"
#include "ServerLuaInventoryList.h"
class ServerLuaInventory {

View File

@ -4,7 +4,7 @@
#pragma once
#include "../../../game/scene/world/InventoryList.h"
#include "../../../game/inventory/InventoryList.h"
#include "LuaItemStack.h"
class ServerLuaInventoryList {

View File

@ -38,7 +38,7 @@
#include "../api/functions/update_entities.h"
void ServerLuaParser::init(ServerGame& defs, ServerWorld& world, std::string path) {
void ServerLuaParser::init(ServerGame& defs, ServerWorld& world, const std::string& path) {
lua.open_libraries(sol::lib::base, sol::lib::string, sol::lib::math, sol::lib::table);
loadApi(defs, world);

View File

@ -13,7 +13,7 @@ class ServerWorld;
class ServerLuaParser : public LuaParser {
public:
void init(ServerGame& defs, ServerWorld& world, std::string rootPath);
void init(ServerGame& defs, ServerWorld& world, const std::string& rootPath);
void update(double delta) override;
void sendModsPacket(ENetPeer* peer) const;

View File

@ -82,7 +82,7 @@ std::list<std::string> ServerModHandler::findModDirectories(const std::string& p
return std::move(modDirs);
}
std::vector<LuaMod> ServerModHandler::initializeLuaMods(const std::list<std::string> modDirs) {
std::vector<LuaMod> ServerModHandler::initializeLuaMods(const std::list<std::string>& modDirs) {
using nlohmann::json;
std::vector<LuaMod> mods {};
@ -159,7 +159,7 @@ std::vector<LuaMod> ServerModHandler::initializeLuaMods(const std::list<std::str
try {
fileStr = VenusParser::parse(file, fileStr);
}
catch (std::runtime_error e) {
catch (const std::runtime_error& e) {
std::cout << Log::err << "Encountered a venus compilation err" << std::endl << e.what() << Log::endl;
exit(1);
}

View File

@ -17,7 +17,7 @@ public:
const std::vector<LuaMod>& cGetMods() const;
private:
static std::list<std::string> findModDirectories(const std::string& path);
static std::vector<LuaMod> initializeLuaMods(const std::list<std::string> modDirs);
static std::vector<LuaMod> initializeLuaMods(const std::list<std::string>& modDirs);
static void loadTextures(ServerGame &defs, const std::vector<LuaMod>& mods);
static void loadModels(ServerGame &defs, const std::vector<LuaMod>& mods);
static void organizeDependencies(std::vector<LuaMod>& mods);

View File

@ -8,13 +8,13 @@
#include "Server.h"
Server::Server(const std::string& path, unsigned short port, const std::string& subgame) :
defs(subgame, path),
clientList(defs),
world(10, defs, clientList),
Server::Server(unsigned short port, const std::string& subgame) :
port(port),
config(defs),
defs(subgame),
clientList(defs),
handler(port, 32),
config(defs) {
world(10, defs, clientList) {
defs.init(world);
world.init();
@ -139,6 +139,24 @@ void Server::handlePlayerPacket(ServerClient &client, Packet& p) {
}
break;
}
case PacketType::WATCH_INV: {
Deserializer d(p.data);
// std::string source = d.read<std::string>();
// std::string list = d.read<std::string>();
// std::cout << "watching " << source << ":" << list << std::endl;
break;
}
case PacketType::UNWATCH_INV: {
Deserializer d(p.data);
// std::string source = d.read<std::string>();
// std::string list = d.read<std::string>();
// std::cout << "unwatching " << source << ":" << list << std::endl;
break;
}
}
}

View File

@ -15,7 +15,7 @@ class Packet;
class Server {
public:
explicit Server(const std::string& path, unsigned short port, const std::string& subgame);
explicit Server(unsigned short port, const std::string& subgame);
void update();
void handlePlayerPacket(ServerClient& client, Packet& p);

View File

@ -33,11 +33,7 @@ void ServerClient::setPos(glm::vec3 pos) {
glm::vec3 lastMapBlock = Space::MapBlock::world::fromBlock(this->pos);
glm::vec3 newMapBlock = Space::MapBlock::world::fromBlock(pos);
if (newMapBlock != lastMapBlock && !changedMapBlocks) {
lastMapBlock = newMapBlock;
changedMapBlocks = true;
}
if (newMapBlock != lastMapBlock && !changedMapBlocks) changedMapBlocks = true;
this->pos = pos;
}

View File

@ -9,8 +9,8 @@
#include <unordered_map>
#include "../../util/Vec.h"
#include "../../game/scene/world/InventoryList.h"
#include "../../game/scene/world/Inventory.h"
#include "../../game/inventory/InventoryList.h"
#include "../../game/inventory/Inventory.h"
class ServerClient {
public:

View File

@ -55,7 +55,7 @@ float ServerEntity::getScale() {
return scale;
}
void ServerEntity::setAppearance(std::string displayMode, std::string displayArgument1, std::string displayArgument2) {
void ServerEntity::setAppearance(const std::string& displayMode, const std::string& displayArgument1, const std::string& displayArgument2) {
this->displayMode = displayMode;
this->displayArgument1 = displayArgument1;
this->displayArgument2 = displayArgument2;

View File

@ -31,7 +31,7 @@ public:
void setScale(float scale);
float getScale();
void setAppearance(std::string displayMode, std::string displayArgument1, std::string displayArgument2);
void setAppearance(const std::string& displayMode, const std::string& displayArgument1, const std::string& displayArgument2);
bool checkAndResetDirty();
Packet createPacket(bool reliable = true);

View File

@ -6,9 +6,8 @@
#include <glm/glm.hpp>
Voronoi3D::Voronoi3D(unsigned short size) :
size(size) {
data = voronoi_data(size);
size(size),
data(voronoi_data(size)) {
for (unsigned short i = 0; i < size; i++) {
data[i].resize(size);
@ -53,8 +52,6 @@ void Voronoi3D::setColorValues(const std::vector<glm::vec3>& values) {
void Voronoi3D::generateImage(unsigned short depth) {
auto colorData = new unsigned char[size * size * 3];
depth = depth;
for (int i = 0; i < size * size; i++) {
int x = i % size;
int y = i / size;