Adapted to DEBUG macro removal in GameKit.

This commit is contained in:
Quentin Bazin 2020-04-03 07:27:57 +02:00
parent 15218e2214
commit 423237f484
17 changed files with 48 additions and 50 deletions

View File

@ -54,8 +54,7 @@ float Config::aoStrength = 1.0f;
// Input
u8 Config::mouseSensitivity = 8;
#include <iostream>
#include <gk/core/Debug.hpp>
#include <gk/core/Filesystem.hpp>
#include <sol.hpp>
@ -91,10 +90,10 @@ void Config::loadConfigFromFile(const char *file) {
mouseSensitivity = lua["mouseSensitivity"].get_or(mouseSensitivity);
std::cout << "Config file loaded successfully" << std::endl;
gkInfo() << "Config file loaded successfully";
}
catch (sol::error &e) {
std::cerr << e.what() << std::endl;
gkError() << e.what();
}
}
}

View File

@ -39,7 +39,7 @@ void TextureAtlas::addFile(const std::string &path, const std::string &filename)
SurfacePtr surface{IMG_Load((path + filename).c_str()), &SDL_FreeSurface};
if(!surface) {
DEBUG("WARNING: Failed to load texture:", path + filename);
gkWarning() << "Failed to load texture:" << path + filename;
return;
}

View File

@ -112,14 +112,14 @@ void Client::update() {
Network::Command command;
packet >> command;
// std::cout << "UDP Message of type '" << Network::commandToString(command) << "' received from: " << senderAddress << ":" << senderPort << std::endl;
// gkDebug() << "UDP Message of type" << Network::commandToString(command) << "received from:" << senderAddress << ":" << senderPort;
}
while (m_tcpSocket->receive(packet) == sf::Socket::Done) {
Network::Command command;
packet >> command;
// DEBUG("TCP message received:", Network::commandToString(command));
// gkDebug() << "TCP message received:" << Network::commandToString(command);
auto it = m_commands.find(command);
if (it != m_commands.end())

View File

@ -98,7 +98,7 @@ void LuaGUIState::onEvent(const SDL_Event &event) {
}
if (!dest) {
DEBUG("WARNING: Destination not found: '" + shiftDestination + "'");
gkWarning() << "Destination not found:" << shiftDestination;
return;
}
@ -242,7 +242,7 @@ void LuaGUIState::loadInventoryWidget(const std::string &name, s32 x, s32 y, sf:
BlockData *data = m_world.getBlockData(block.x, block.y, block.z);
if (!data) {
DEBUG("ERROR: No inventory found at", block.x, block.y, block.z);
gkError() << "No inventory found at" << block.x << block.y << block.z;
return;
}
@ -259,7 +259,7 @@ void LuaGUIState::loadInventoryWidget(const std::string &name, s32 x, s32 y, sf:
else {
auto it = m_inventories.find(inventoryName);
if (it == m_inventories.end())
DEBUG("ERROR: Unable to find inventory '" + inventoryName + "' for widget '" + name + "'");
gkError() << "Unable to find inventory" << inventoryName << "for widget" << name;
widgetInventory = &it->second;
}
@ -275,7 +275,7 @@ void LuaGUIState::loadInventoryWidget(const std::string &name, s32 x, s32 y, sf:
inventoryWidget.setFilter(filter);
}
else {
DEBUG("ERROR: Inventory widget '" + name + "' is invalid");
gkError() << "Inventory widget" << name << " is invalid";
}
}
@ -292,7 +292,7 @@ void LuaGUIState::loadCraftingWidget(const std::string &name, s32 x, s32 y, sf::
BlockData *data = m_world.getBlockData(block.x, block.y, block.z);
if (!data) {
DEBUG("ERROR: No inventory found at", block.x, block.y, block.z);
gkError() << "No inventory found at" << block.x << block.y << block.z;
}
else {
craftingInventory = &data->inventory;
@ -315,7 +315,7 @@ void LuaGUIState::loadCraftingWidget(const std::string &name, s32 x, s32 y, sf::
craftingWidget.craftingResultInventoryWidget().setPosition(resultX, resultY);
}
else {
DEBUG("ERROR: Crafting inventory is invalid");
gkError() << "Crafting inventory is invalid";
}
}
@ -331,7 +331,7 @@ void LuaGUIState::loadProgressBarWidget(const std::string &, s32 x, s32 y, sf::P
BlockData *data = m_world.getBlockData(block.x, block.y, block.z);
if (!data) {
DEBUG("ERROR: No inventory found at", block.x, block.y, block.z);
gkError() << "No inventory found at" << block.x << block.y << block.z;
return;
}

View File

@ -215,7 +215,7 @@ void ClientWorld::createChunkNeighbours(ClientChunk *chunk) {
void ClientWorld::draw(gk::RenderTarget &target, gk::RenderStates states) const {
if (!target.getView() || !m_camera) {
DEBUG("ERROR: Trying to draw world without a camera");
gkError() << "Trying to draw world without a camera";
return;
}

View File

@ -76,7 +76,7 @@ void ServerApplication::init() {
m_scriptEngine.luaCore().setRegistry(&m_registry);
std::cout << "Server is running on localhost:" << m_server.port() << std::endl;
gkInfo() << ("Server is running on localhost:" + std::to_string(m_server.port())).c_str();
if (m_eventHandler)
m_eventHandler->emplaceEvent<ServerOnlineEvent>(true, m_server.port());

View File

@ -67,7 +67,7 @@ void CraftingWidgetDef::loadInventory(const sol::table &table) {
m_blockPosition.z = blockTable.value()["z"];
}
else
DEBUG("ERROR: For '" + m_name + "': Block position must be defined")
gkError() << "For" << m_name << ": Block position must be defined";
m_offset = inventoryTable["offset"].get_or<u16>(0);
m_size = inventoryTable["size"].get_or<u16>(3);
@ -76,10 +76,10 @@ void CraftingWidgetDef::loadInventory(const sol::table &table) {
m_size = inventoryTable["size"].get_or<u16>(3);
}
else {
DEBUG("ERROR: For '" + m_name + "': Inventory source '" + m_inventory + "' is not valid");
gkError() << "For" << m_name << ": Inventory source" << m_inventory + "is not valid";
}
}
else
DEBUG("ERROR: For '" + m_name + "': 'inventory' field must be a table");
gkError() << "For" << m_name << ": 'inventory' field must be a table";
}

View File

@ -57,7 +57,7 @@ void InventoryWidgetDef::loadFromLuaTable(const sol::table &table) {
m_height = size.value()["y"];
}
else
DEBUG("ERROR: For '" + m_name + "': Inventory size must be defined");
gkError() << "For" << m_name << ": Inventory size must be defined";
}
void InventoryWidgetDef::loadInventory(const sol::table &table) {
@ -84,13 +84,12 @@ void InventoryWidgetDef::loadInventory(const sol::table &table) {
m_blockPosition.z = blockTable.value()["z"];
}
else
DEBUG("ERROR: For '" + m_name + "': Block position must be defined");
}
else {
DEBUG("ERROR: For '" + m_name + "': Inventory source '" + m_inventory + "' is not valid");
gkError() << "For" << m_name << ": Block position must be defined";
}
else
gkError() << "For" << m_name << ": Inventory source" << m_inventory << "is not valid";
}
else
DEBUG("ERROR: For '" + m_name + "': 'inventory' field must be a table");
gkError() << "For" << m_name << ": 'inventory' field must be a table";
}

View File

@ -48,7 +48,7 @@ void ProgressBarWidgetDef::loadFromLuaTable(const sol::table &table) {
m_blockPosition.z = blockTable.value()["z"];
}
else {
DEBUG("ERROR: Attribute 'block' not defined for bar '" + m_name + "'");
gkError() << "Attribute 'block' not defined for bar" << m_name;
return;
}
@ -82,10 +82,10 @@ inline void ProgressBarWidgetDef::loadType(const sol::table &table) {
if (it != types.end())
m_type = u8(it->second);
else
DEBUG("ERROR: In '" + m_name + "' definition: Type invalid");
gkError() << "In" << m_name << "definition: Type invalid";
}
else
DEBUG("ERROR: In '" + m_name + "' definition: Type must be a string");
gkError() << "In" << m_name << "definition: Type must be a string";
}
}

View File

@ -55,20 +55,20 @@ void ServerModLoader::loadMods() {
fs::current_path(basePath);
std::cout << "Mod '" + entry.path().filename().string() + "' loaded" << std::endl;
gkInfo() << "Mod" << entry.path().filename().string() << "loaded";
}
else
DEBUG("WARNING: The mod '" + entry.path().filename().string() + "' doesn't contain an 'init.lua' file.");
gkWarning() << "The mod" << entry.path().filename().string() << "doesn't contain an 'init.lua' file.";
}
for (auto &it : m_mods) {
// DEBUG("Applying mod '" + it.second.id() + "'...");
// gkDebug() << "Applying mod" << it.second.id() << "...";
it.second.commit();
}
}
LuaMod &ServerModLoader::registerMod(const std::string &name) {
// DEBUG("Registering mod '" + mod.id() + "'...");
// gkDebug("Registering mod" << mod.id() << "...";
if (!gk::regexMatch(name, "^[A-Za-z0-9_]+$") || name == "group")
throw std::runtime_error("Mod name '" + name + "' is invalid.");

View File

@ -43,7 +43,7 @@ void LuaBiomeLoader::loadTree(const sol::table &table) const {
tree.setTrunkHeight(trunkHeight["min"], trunkHeight["max"]);
}
else
DEBUG("ERROR: For tree '" + stringID + "': trunk_height must be a table");
gkError() << "For tree" << stringID << ": 'trunk_height' must be a table";
}
sol::object hasLeavesObject = table["has_leaves"];
@ -52,7 +52,7 @@ void LuaBiomeLoader::loadTree(const sol::table &table) const {
tree.setHasLeaves(hasLeavesObject.as<bool>());
}
else
DEBUG("ERROR: For tree '" + stringID + "': has_leaves must be a boolean");
gkError() << "For tree" << stringID << ": 'has_leaves' must be a boolean";
}
sol::object leavesBlockObject = table["leaves_block"];
@ -62,10 +62,10 @@ void LuaBiomeLoader::loadTree(const sol::table &table) const {
tree.setLeavesBlockID(Registry::getInstance().getBlockFromStringID(leavesBlock).id());
}
else
DEBUG("ERROR: For tree '" + stringID + "': leaves_block must be a string");
gkError() << "For tree" << stringID << ": 'leaves_block must be a string";
}
else if (tree.hasLeaves())
DEBUG("ERROR: For tree '" + stringID + "': leaves_block must be defined if has_leaves == true");
gkError() << "For tree" << stringID << ": 'leaves_block' must be defined if has_leaves == true";
}
void LuaBiomeLoader::loadBiome(const sol::table &table) const {
@ -103,7 +103,7 @@ inline void LuaBiomeLoader::loadBiomeBlocks(Biome &biome, const sol::table &tabl
biome.setPortalFrameBlockID(Registry::getInstance().getBlockFromStringID(table["portal_frame"]).id());
}
else
DEBUG("ERROR: For '" + biome.stringID() + "': 'blocks' field must be a table");
gkError() << "For" << biome.stringID() << ": 'blocks' field must be a table";
}
inline void LuaBiomeLoader::loadTreePlacementEntries(Biome &biome, const sol::table &table) const {

View File

@ -104,10 +104,10 @@ inline void LuaBlockLoader::loadDrawType(ServerBlock &block, const sol::table &t
if (it != drawTypes.end())
block.setDrawType(it->second);
else
DEBUG("ERROR: In '" + block.stringID() + "' definition: Block draw type invalid");
gkError() << "In" << block.stringID() << " definition: Block draw type invalid";
}
else
DEBUG("ERROR: In '" + block.stringID() + "' definition: Block draw type must be a string");
gkError() << "In" << block.stringID() << " definition: Block draw type must be a string";
}
}
@ -146,7 +146,7 @@ inline void LuaBlockLoader::loadGroups(ServerBlock &block, Item &item, const sol
}
}
else
DEBUG("ERROR: For block '" + block.stringID() + "': 'groups' should be a table");
gkError() << "For block" << block.stringID() << ": 'groups' should be a table";
}
}

View File

@ -44,10 +44,10 @@ void LuaDimensionLoader::loadDimension(const sol::table &table) const {
if (it.second.get_type() == sol::type::string)
dimension.addBiome(it.second.as<std::string>());
else
DEBUG("ERROR: For dimension '" + id + "': Invalid biome string");
gkError() << "For dimension" << id << ": Invalid biome string";
}
}
else
DEBUG("ERROR: For dimension '" + id + "': Invalid biome table");
gkError() << "For dimension" << id << ": Invalid biome table";
}

View File

@ -50,7 +50,7 @@ void LuaItemLoader::loadItem(const sol::table &table) const {
}
}
else
DEBUG("ERROR: For item '" + stringID + "': 'groups' should be a table");
gkError() << "For item" << stringID << ": 'groups' should be a table";
}
}

View File

@ -52,7 +52,7 @@ void Server::handleKeyState() {
u16 clientId;
packet >> command >> timestamp >> clientId;
// std::cout << "UDP Message of type '" << Network::commandToString(command) << "' received from: " << senderAddress << ":" << senderPort << std::endl;
// gkDebug() << "UDP Message of type" << Network::commandToString(command) << "received from:" << senderAddress << ":" << senderPort;
if (command == Network::Command::KeyState) {
ClientInfo *client = m_info.getClient(clientId);
@ -65,7 +65,7 @@ void Server::handleKeyState() {
packet >> key >> isPressed;
if (client->inputHandler.keysPressed().at(key) != isPressed)
DEBUG((int)key, "changed state to", isPressed ? "true" : "false");
gkDebug() << (int)key << "changed state to" << (isPressed ? "true" : "false");
client->inputHandler.setKeyPressed(key, isPressed);
}
@ -133,7 +133,7 @@ void Server::handleClientMessages() {
Network::Command command;
packet >> command;
// DEBUG("TCP message received:", Network::commandToString(command));
// gkDebug() << "TCP message received:" << Network::commandToString(command);
if (m_isRunning) {
for (auto &it : m_commands) {

View File

@ -193,7 +193,7 @@ void ServerCommandHandler::setupCallbacks() {
func(client, screenWidth, screenHeight, guiScale);
}
catch (const sol::error &error) {
DEBUG("Failed to send inventory GUI\n", error.what());
gkError() << "Failed to send inventory GUI: " << error.what();
}
});
@ -208,7 +208,7 @@ void ServerCommandHandler::setupCallbacks() {
func(client, screenWidth, screenHeight, guiScale);
}
catch (const sol::error &error) {
DEBUG("Failed to send creative window GUI\n", error.what());
gkError() << "Failed to send creative window GUI: " << error.what();
}
});
@ -236,7 +236,7 @@ void ServerCommandHandler::setupCallbacks() {
if (data)
packet >> data->inventory;
else
DEBUG("BlockInvUpdate: No block data found at", pos.x, pos.y, pos.z);
gkError() << "BlockInvUpdate: No block data found at" << pos.x << pos.y << pos.z;
});
m_server.setCommandCallback(Network::Command::BlockDataUpdate, [this](ClientInfo &client, sf::Packet &packet) {

View File

@ -47,7 +47,7 @@ void ServerWorld::update() {
for (auto &client : m_server->server().info().clients())
sendChunkData(client, *it.second.get());
// DEBUG("Chunk updated at", it.second->x(), it.second->y(), it.second->z());
// gkDebug() << "Chunk updated at" << it.second->x() << it.second->y() << it.second->z();
}
}
}