From af02db535683f26bea8f3f7428a570a361bcb423 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Tue, 29 Jun 2021 14:41:00 +0500 Subject: Removed old items ids --- src/AssetManager.cpp | 26 -------------------------- src/AssetManager.hpp | 2 -- 2 files changed, 28 deletions(-) (limited to 'src') diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index 63dc596..d5b8d68 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -21,7 +21,6 @@ namespace fs = std::filesystem; const fs::path pathToAssets = "./assets/"; const std::string pathToAssetsList = "./items.json"; -std::map assetIds; std::map blockIdToBlockName; std::unique_ptr assetTree; std::unique_ptr atlas; @@ -29,7 +28,6 @@ std::map blockIdToBlockFaces; BlockFaces errorFaces; -void LoadIds(); void LoadAssets(); void LoadTextures(); void LoadScripts(); @@ -62,7 +60,6 @@ void AssetManager::InitAssetManager() LoadTextures(); - LoadIds(); ParseBlockModels(); PluginSystem::Init(); @@ -79,19 +76,6 @@ void AssetManager::InitPostRml() { } } -void LoadIds() { - std::ifstream in(pathToAssetsList); - nlohmann::json index; - in >> index; - for (auto &it : index) { - unsigned short id = it["type"].get(); - unsigned char state = it["meta"].get(); - std::string blockName = it["text_type"].get(); - assetIds[blockName] = BlockId{ id, state }; - } - LOG(INFO) << "Loaded " << assetIds.size() << " ids"; -} - void LoadAssets() { assetTree = std::make_unique(); assetTree->name = "/"; @@ -661,16 +645,6 @@ BlockFaces &AssetManager::GetBlockModelByBlockId(BlockId block) { return blockIdToBlockFaces.insert(std::make_pair(block, blockFaces)).first->second; } -std::string AssetManager::GetAssetNameByBlockId(BlockId block) { - for (auto& it : assetIds) { - BlockId value = it.second; - value.state = 0; - if (value == block) - return it.first; - } - return "#NF"; -} - Asset *AssetManager::GetAssetPtr(const std::string & assetName) { OPTICK_EVENT(); AssetTreeNode *node; diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp index b67d920..7f6c4fb 100644 --- a/src/AssetManager.hpp +++ b/src/AssetManager.hpp @@ -178,8 +178,6 @@ namespace AssetManager { BlockFaces &GetBlockModelByBlockId(BlockId block); - std::string GetAssetNameByBlockId(BlockId block); - Asset *GetAssetPtr(const std::string &assetName); template -- cgit v1.2.3 From cfb56c9255fbf37a6bb9f0a6758db87320364cf6 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Tue, 29 Jun 2021 16:22:31 +0500 Subject: Added more debug values --- src/DebugInfo.cpp | 3 ++- src/DebugInfo.hpp | 3 ++- src/Plugin.cpp | 24 ++++++++++++++++++++++++ src/RendererWorld.cpp | 2 +- src/RendererWorld.hpp | 3 +-- 5 files changed, 30 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/DebugInfo.cpp b/src/DebugInfo.cpp index 89e9425..37d181d 100644 --- a/src/DebugInfo.cpp +++ b/src/DebugInfo.cpp @@ -4,4 +4,5 @@ std::atomic_int DebugInfo::totalSections(0); std::atomic_int DebugInfo::renderSections(0); std::atomic_int DebugInfo::readyRenderer(0); std::atomic_int DebugInfo::gameThreadTime(0); -std::atomic_int DebugInfo::renderFaces(0); \ No newline at end of file +std::atomic_int DebugInfo::renderFaces(0); +std::atomic_int DebugInfo::culledSections(0); diff --git a/src/DebugInfo.hpp b/src/DebugInfo.hpp index e6aa17c..7ba1686 100644 --- a/src/DebugInfo.hpp +++ b/src/DebugInfo.hpp @@ -5,7 +5,8 @@ struct DebugInfo { static std::atomic_int totalSections; static std::atomic_int renderSections; + static std::atomic_int culledSections; static std::atomic_int readyRenderer; static std::atomic_int gameThreadTime; static std::atomic_int renderFaces; -}; \ No newline at end of file +}; diff --git a/src/Plugin.cpp b/src/Plugin.cpp index ce995fc..f759d5f 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -11,6 +11,7 @@ #include "Event.hpp" #include "AssetManager.hpp" #include "Settings.hpp" +#include "DebugInfo.hpp" struct Plugin { @@ -108,6 +109,25 @@ namespace PluginApi { void SettingsUpdate() { PUSH_EVENT("SettingsUpdate", 0); } + + int GetDebugValue(int valId) { + switch (valId) { + case 0: + return DebugInfo::totalSections; + case 1: + return DebugInfo::renderSections; + case 2: + return DebugInfo::readyRenderer; + case 3: + return DebugInfo::gameThreadTime; + case 4: + return DebugInfo::renderFaces; + case 5: + return DebugInfo::culledSections; + default: + return 0; + } + } } int LoadFileRequire(lua_State* L) { @@ -194,6 +214,8 @@ void PluginSystem::Init() { "GetEntitiesList", &World::GetEntitiesList, "GetEntity",&World::GetEntityPtr, "Raycast", &World::Raycast, + "GetBlockLight", sol::resolve(&World::GetBlockLight), + "GetBlockSkyLight", sol::resolve(&World::GetBlockSkyLight), "GetBlockId", &World::GetBlockId, "SetBlockId", &World::SetBlockId); @@ -268,6 +290,8 @@ void PluginSystem::Init() { apiSettings["WriteDouble"] = Settings::WriteDouble; apiTable["SettingsUpdate"] = PluginApi::SettingsUpdate; apiTable["GetTime"] = GetTime; + apiTable["GetBlockInfo"] = GetBlockInfo; + apiTable["GetDebugValue"] = PluginApi::GetDebugValue; } lua_State* PluginSystem::GetLuaState() { diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp index e3ef738..6996762 100644 --- a/src/RendererWorld.cpp +++ b/src/RendererWorld.cpp @@ -428,7 +428,7 @@ void RendererWorld::Render(RenderState & renderState) { section.second.Render(renderState); renderedFaces += section.second.numOfFaces; } - this->culledSections = culledSections; + DebugInfo::culledSections = culledSections; DebugInfo::renderFaces = renderedFaces; glCheckError(); } diff --git a/src/RendererWorld.hpp b/src/RendererWorld.hpp index d031179..85cb736 100644 --- a/src/RendererWorld.hpp +++ b/src/RendererWorld.hpp @@ -60,5 +60,4 @@ public: void Update(double timeToUpdate); - int culledSections = 0; -}; \ No newline at end of file +}; -- cgit v1.2.3 From 12990cee44efdae378ffbfb4d717ed8a1eafc6dc Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Wed, 30 Jun 2021 18:08:59 +0500 Subject: Added Loading screen --- src/GameState.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/GameState.cpp b/src/GameState.cpp index be408dd..bb93c45 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -6,6 +6,7 @@ #include "Event.hpp" #include "Packet.hpp" +#include "Game.hpp" void GameState::Update(double deltaTime) { OPTICK_EVENT(); @@ -383,7 +384,6 @@ void GameState::UpdatePacket(std::shared_ptr ptr) { auto packetResponse = std::make_shared(packet->TeleportId); PUSH_EVENT("SendPacket", std::static_pointer_cast(packetResponse)); - break; } @@ -418,6 +418,9 @@ void GameState::UpdatePacket(std::shared_ptr ptr) { gameStatus.dimension = packet->Dimension; gameStatus.difficulty = packet->Difficulty; gameStatus.levelType = packet->LevelType; + SetState(State::Loading); + gameStatus.isGameStarted = false; + receivedEnoughChunks = false; break; } case EntityHeadLook: -- cgit v1.2.3 From 48e564a32c266c8d4649c6f50bf4eac56f771c0d Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Fri, 2 Jul 2021 12:26:39 +0500 Subject: Added Respawn screen --- src/Game.hpp | 1 + src/GameState.cpp | 12 ++++++++---- src/GameState.hpp | 4 ++++ src/Plugin.cpp | 3 ++- src/Render.cpp | 4 ++++ 5 files changed, 19 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Game.hpp b/src/Game.hpp index f7efd11..74eeea9 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -13,6 +13,7 @@ enum class State { Paused, Inventory, Chat, + NeedRespawn, }; void RunGame(); diff --git a/src/GameState.cpp b/src/GameState.cpp index bb93c45..50a9004 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -456,9 +456,8 @@ void GameState::UpdatePacket(std::shared_ptr ptr) { auto packet = std::static_pointer_cast(ptr); playerStatus.health = packet->Health; if (playerStatus.health <= 0) { - LOG(INFO) << "Player is dead. Respawning..."; - auto packetPerformRespawn = std::make_shared(0); - PUSH_EVENT("SendPacket", std::static_pointer_cast(packetPerformRespawn)); + LOG(INFO) << "Player is dead. Need respawn..."; + SetState(State::NeedRespawn); } break; } @@ -681,4 +680,9 @@ void GameState::PlaceBlock() { auto packet = std::static_pointer_cast(packetPlace); PUSH_EVENT("SendPacket", packet); -} \ No newline at end of file +} + +void GameState::PerformRespawn() { + auto packetPerformRespawn = std::make_shared(0); + PUSH_EVENT("SendPacket", std::static_pointer_cast(packetPerformRespawn)); +} diff --git a/src/GameState.hpp b/src/GameState.hpp index 0ca858f..ca2ea81 100644 --- a/src/GameState.hpp +++ b/src/GameState.hpp @@ -75,6 +75,8 @@ class GameState { bool receivedFirstPlayerPosAndLook = false; + std::shared_ptr packetRespawn; + public: void Update(double deltaTime); @@ -89,6 +91,8 @@ public: void PlaceBlock(); + void PerformRespawn(); + enum MoveType { FORWARD, BACKWARD, LEFT, RIGHT, JUMP }; diff --git a/src/Plugin.cpp b/src/Plugin.cpp index f759d5f..64fc00b 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -174,7 +174,8 @@ void PluginSystem::Init() { "GetGameStatus", &GameState::GetGameStatus, "GetPlayerStatus", &GameState::GetPlayerStatus, "GetSelectionStatus", &GameState::GetSelectionStatus, - "GetInventory", &GameState::GetInventory); + "GetInventory", &GameState::GetInventory, + "PerformRespawn", &GameState::PerformRespawn); lua.new_usertype("TimeStatus", "interpolatedTimeOfDay", &TimeStatus::interpolatedTimeOfDay, diff --git a/src/Render.cpp b/src/Render.cpp index bee8ffb..6aecd88 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -498,6 +498,10 @@ void Render::InitEvents() { PluginSystem::CallOnChangeState("Chat"); SetMouseCapture(false); break; + case State::NeedRespawn: + PluginSystem::CallOnChangeState("NeedRespawn"); + SetMouseCapture(false); + break; } }); -- cgit v1.2.3 From 2d2fc243662fe5a24b4e3e388d3a3525a0bd48f1 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Sun, 4 Jul 2021 15:05:00 +0500 Subject: Added RmlDebugger --- src/Render.cpp | 18 ++++++++++++++++++ src/Rml.cpp | 10 ++++++++-- src/Rml.hpp | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Render.cpp b/src/Render.cpp index 6aecd88..a76bba7 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "Shader.hpp" #include "AssetManager.hpp" @@ -293,6 +294,15 @@ void Render::HandleEvents() { break; } + case SDL_SCANCODE_F8: + Rml::Debugger::SetVisible(!Rml::Debugger::IsVisible()); + break; + + case SDL_SCANCODE_F7: { + SetMouseCapture(!isMouseCaptured); + break; + } + default: break; } @@ -358,6 +368,11 @@ void Render::HandleEvents() { break; } + case SDL_MOUSEWHEEL: { + rmlContext->ProcessMouseWheel(-event.wheel.y, rmlKeymods); + break; + } + case SDL_TEXTINPUT: { rmlContext->ProcessTextInput(Rml::String(event.text.text)); break; @@ -567,4 +582,7 @@ void Render::InitRml() { Rml::Lua::Initialise(PluginSystem::GetLuaState()); rmlContext = Rml::CreateContext("default", Rml::Vector2i(renderState.WindowWidth, renderState.WindowHeight)); + + if (!Rml::Debugger::Initialise(rmlContext)) + LOG(WARNING) << "Rml debugger not initialized"; } diff --git a/src/Rml.cpp b/src/Rml.cpp index 6ed83c1..179d4b9 100644 --- a/src/Rml.cpp +++ b/src/Rml.cpp @@ -117,11 +117,15 @@ void RmlRenderInterface::RenderGeometry(Rml::Vertex* vertices, int num_vertices, } void RmlRenderInterface::EnableScissorRegion(bool enable) { - + if (enable) + glEnable(GL_SCISSOR_TEST); + else + glDisable(GL_SCISSOR_TEST); } void RmlRenderInterface::SetScissorRegion(int x, int y, int width, int height) { - + glScissor(x, vpHeight - (y + height), width, height); + glCheckError(); } bool RmlRenderInterface::LoadTexture(Rml::TextureHandle& texture_handle, Rml::Vector2i& texture_dimensions, const Rml::String& source) { @@ -161,6 +165,8 @@ void RmlRenderInterface::Update(unsigned int windowWidth, unsigned int windowHei AssetManager::GetAsset("/altcraft/shaders/rmltex")->shader->SetUniform("viewportSize", windowWidth, windowHeight); AssetManager::GetAsset("/altcraft/shaders/rmltex")->shader->SetUniform("fontTexture", 0); glCheckError(); + vpWidth = windowWidth; + vpHeight = windowHeight; } Rml::FileHandle RmlFileInterface::Open(const Rml::String& path) { diff --git a/src/Rml.hpp b/src/Rml.hpp index 6e4d857..edcdc8b 100644 --- a/src/Rml.hpp +++ b/src/Rml.hpp @@ -34,6 +34,7 @@ class RmlRenderInterface : public Rml::RenderInterface { GLuint Vao, Vbo, Ebo; + unsigned int vpWidth, vpHeight; public: RmlRenderInterface(RenderState &renderState); -- cgit v1.2.3 From b37e52c9facd4c41183c016fd5c91f8829407766 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Sun, 4 Jul 2021 17:21:50 +0500 Subject: Added basic Chat --- src/GameState.cpp | 3 ++- src/Plugin.cpp | 25 +++++++++++++++++++++++++ src/Plugin.hpp | 3 +++ src/Render.cpp | 12 ++---------- src/Render.hpp | 1 - 5 files changed, 32 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/GameState.cpp b/src/GameState.cpp index 50a9004..89743e4 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -7,6 +7,7 @@ #include "Event.hpp" #include "Packet.hpp" #include "Game.hpp" +#include "Plugin.hpp" void GameState::Update(double deltaTime) { OPTICK_EVENT(); @@ -168,7 +169,7 @@ void GameState::UpdatePacket(std::shared_ptr ptr) { case ChatMessageCB: { auto packet = std::static_pointer_cast(ptr); LOG(INFO) << "Message (" << int(packet->Position) << "): " << packet->JsonData.ToPlainText(); - PUSH_EVENT("ChatMessageReceived", std::make_tuple(packet->JsonData, packet->Position)); + PluginSystem::CallOnChatMessage(packet->JsonData, packet->Position); break; } diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 64fc00b..98df8c3 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -12,6 +12,7 @@ #include "AssetManager.hpp" #include "Settings.hpp" #include "DebugInfo.hpp" +#include "Chat.hpp" struct Plugin { @@ -23,6 +24,7 @@ struct Plugin { const std::function onChangeState; const std::function onTick; const std::function onRequestBlockInfo; + const std::function onChatMessage; }; @@ -42,6 +44,7 @@ namespace PluginApi { plugin["onChangeState"].get_or(std::function()), plugin["onTick"].get_or(std::function()), plugin["onRequestBlockInfo"].get_or(std::function()), + plugin["onChatMessage"].get_or(std::function()), }; plugins.push_back(nativePlugin); LOG(INFO)<<"Loading plugin " << (!nativePlugin.displayName.empty() ? nativePlugin.displayName : nativePlugin.name); @@ -128,6 +131,10 @@ namespace PluginApi { return 0; } } + + void SendChatMessage(const std::string& msg) { + PUSH_EVENT("SendChatMessage", msg); + } } int LoadFileRequire(lua_State* L) { @@ -265,6 +272,9 @@ void PluginSystem::Init() { "GetDeltaS", &LoopExecutionTimeController::GetDeltaS, "GetRealDeltaS", &LoopExecutionTimeController::GetRealDeltaS); + lua.new_usertype("Chat", + "ToPlainText", &Chat::ToPlainText); + sol::table apiTable = lua["AC"].get_or_create(); sol::table apiSettings = lua["AC"]["Settings"].get_or_create(); @@ -293,6 +303,7 @@ void PluginSystem::Init() { apiTable["GetTime"] = GetTime; apiTable["GetBlockInfo"] = GetBlockInfo; apiTable["GetDebugValue"] = PluginApi::GetDebugValue; + apiTable["SendChatMessage"] = PluginApi::SendChatMessage; } lua_State* PluginSystem::GetLuaState() { @@ -356,3 +367,17 @@ BlockInfo PluginSystem::RequestBlockInfo(Vector blockPos) { } return ret; } + +void PluginSystem::CallOnChatMessage(const Chat& chat, int position) { + OPTICK_EVENT(); + for (Plugin& plugin : plugins) { + if (plugin.onRequestBlockInfo && plugin.errors < 10) + try { + plugin.onChatMessage(chat, position); + } + catch (sol::error& e) { + LOG(ERROR) << e.what(); + plugin.errors++; + } + } +} diff --git a/src/Plugin.hpp b/src/Plugin.hpp index 7af27a4..13b126e 100644 --- a/src/Plugin.hpp +++ b/src/Plugin.hpp @@ -6,6 +6,7 @@ class BlockInfo; struct lua_State; +class Chat; namespace PluginSystem { void Init(); @@ -19,4 +20,6 @@ namespace PluginSystem { void CallOnTick(double deltaTime); BlockInfo RequestBlockInfo(Vector blockPos); + + void CallOnChatMessage(const Chat& chat, int position); } \ No newline at end of file diff --git a/src/Render.cpp b/src/Render.cpp index a76bba7..3bf1e6b 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -29,7 +29,8 @@ const std::map keyMapping = { {SDLK_RIGHT, Rml::Input::KI_RIGHT}, {SDLK_UP, Rml::Input::KI_UP}, {SDLK_DOWN, Rml::Input::KI_DOWN}, - {SDLK_TAB, Rml::Input::KI_TAB} + {SDLK_TAB, Rml::Input::KI_TAB}, + {SDLK_RETURN, Rml::Input::KI_RETURN} }; inline int ConvertKeymodsSdlToRml(unsigned short keyMods) { @@ -288,9 +289,6 @@ void Render::HandleEvents() { if (state == State::Playing) { SetState(State::Chat); } - else if (state == State::Chat) { - SetState(State::Playing); - } break; } @@ -477,12 +475,6 @@ void Render::InitEvents() { SetState(State::Loading); }); - listener.RegisterHandler("ChatMessageReceived", [this](const Event& eventData) { - auto data = eventData.get>(); - std::string msg = "(" + std::to_string((int)std::get<1>(data)) + ") " + (std::get<0>(data).ToPlainText()); - chatMessages.push_back(msg); - }); - listener.RegisterHandler("StateUpdated", [this](const Event& eventData) { switch (GetState()) { case State::Playing: diff --git a/src/Render.hpp b/src/Render.hpp index 4f993c3..b8963c7 100644 --- a/src/Render.hpp +++ b/src/Render.hpp @@ -37,7 +37,6 @@ class Render { float sensetivity = 0.1f; bool isWireframe = false; std::unique_ptr framebuffer; - std::vector chatMessages; EventListener listener; std::string stateString; std::unique_ptr rmlRender; -- cgit v1.2.3 From 8ee59be130a72645a36527f8e718c5a251a371f8 Mon Sep 17 00:00:00 2001 From: LaG1924 Date: Sun, 4 Jul 2021 17:26:14 +0500 Subject: Added screenshot-mode --- src/Render.cpp | 7 ++++++- src/Render.hpp | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Render.cpp b/src/Render.cpp index 3bf1e6b..896a05f 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -292,6 +292,10 @@ void Render::HandleEvents() { break; } + case SDL_SCANCODE_F4: + hideRml = !hideRml; + break; + case SDL_SCANCODE_F8: Rml::Debugger::SetVisible(!Rml::Debugger::IsVisible()); break; @@ -430,7 +434,8 @@ void Render::Update() { void Render::RenderGui() { OPTICK_EVENT(); - rmlContext->Render(); + if (!hideRml) + rmlContext->Render(); } void Render::InitEvents() { diff --git a/src/Render.hpp b/src/Render.hpp index b8963c7..9a9feee 100644 --- a/src/Render.hpp +++ b/src/Render.hpp @@ -44,6 +44,7 @@ class Render { std::unique_ptr rmlFile; Rml::Context* rmlContext; unsigned short sdlKeyMods = 0; + bool hideRml = false; void SetMouseCapture(bool IsCaptured); -- cgit v1.2.3