Skip to content

Commit

Permalink
Gui: Convert LHVMViewer to Window class
Browse files Browse the repository at this point in the history
Uncomment LHVM loading challenge.chl
Move custom imgui code to imgui_user.cpp
  • Loading branch information
bwrsandman committed Nov 15, 2021
1 parent 8fe62fc commit 5cbca9b
Show file tree
Hide file tree
Showing 11 changed files with 889 additions and 827 deletions.
6 changes: 6 additions & 0 deletions ci/mock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ list(APPEND TERRAIN_MATERIAL_ARRAY ${TERRAIN_BINARY_DIR}/material_data3.rgb5a1.r
string(REPLACE ";" "," TERRAIN_MATERIAL_LIST "${TERRAIN_MATERIAL_ARRAY}")

set(SCRIPTS_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/Scripts)
set(QUESTS_BINARY_DIR ${SCRIPTS_BINARY_DIR}/Quests)
set(INFO_UNPACKED_OUTPUT ${SCRIPTS_BINARY_DIR}/Info)
set(INFO_DAT_OUTPUT ${SCRIPTS_BINARY_DIR}/info.dat)
set(QUEST_CHALLENGE_OUTPUT ${QUESTS_BINARY_DIR}/challenge.chl)

# TODO: Combine all texture generating scripts into a single one

Expand All @@ -42,6 +44,8 @@ add_custom_target(generate-mock-game-data
COMMAND ${CMAKE_COMMAND} -E make_directory ${SKY_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${TERRAIN_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${COFFRE_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${SCRIPTS_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${QUESTS_BINARY_DIR}
# Copy the Scripts Directory
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/Scripts ${CMAKE_CURRENT_BINARY_DIR}/Scripts
# Generate Mock Textures
Expand All @@ -66,6 +70,8 @@ add_custom_target(generate-mock-game-data
# Scripts/info.dat
COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/gen_zeroed_file.py --output-file ${INFO_UNPACKED_OUTPUT} --size 0x8E186
COMMAND packtool --write-raw ${INFO_DAT_OUTPUT} ${INFO_UNPACKED_OUTPUT}
# Scripts/Quests/challenge.chl
COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/Scripts/Quests/gen_challenge.py --output-file ${QUEST_CHALLENGE_OUTPUT}

COMMENT "Generating mock game data in ${CMAKE_CURRENT_BINARY_DIR}"

Expand Down
32 changes: 32 additions & 0 deletions ci/mock/Scripts/Quests/gen_challenge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

import sys
import os

def main(file_name):
version_black_and_white = 7
version_creature_isle = 8
version_black_and_white_2 = 12

with open(file_name, "wb") as f:
# Magic number
f.write(b"LHVM")
# Version of the file
f.write(version_black_and_white.to_bytes(4, byteorder='little'))
# Number of variables
f.write((0).to_bytes(4, byteorder='little'))
# Number of instructions
f.write((0).to_bytes(4, byteorder='little'))
# Number of Auto (?)
f.write((0).to_bytes(4, byteorder='little'))
# Number of Scripts
f.write((0).to_bytes(4, byteorder='little'))
# Number of Data segments
f.write((0).to_bytes(4, byteorder='little'))

if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description='Generate empty Challenge Files.')
parser.add_argument('--output-file', required=True, help='Where to generate challenge.')
args = parser.parse_args()
main(args.output_file)
23 changes: 23 additions & 0 deletions externals/imgui_user/imgui_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,27 @@ bool ListBox(const char* label, int* currIndex, const std::string_view* values,
return ListBox(label, currIndex, string_view_array_getter, static_cast<void*>(&userData), valueCount);
}

void AddUnderLine(ImColor col_)
{
ImVec2 min = ImGui::GetItemRectMin();
ImVec2 max = ImGui::GetItemRectMax();
min.y = max.y;
ImGui::GetWindowDrawList()->AddLine(min, max, col_, 1.0f);
}

bool TextButtonColored(ImVec4 color, const char* name_)
{
bool pressed = false;
ImGui::TextColored(color, "%s", name_);
if (ImGui::IsItemHovered())
{
if (ImGui::IsMouseClicked(0))
pressed = true;

AddUnderLine(color);
}

return pressed;
}

} // namespace ImGui
2 changes: 2 additions & 0 deletions externals/imgui_user/imgui_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ inline bool ListBox(const char* label, Index_t* currIndex, const std::array<std:
}
return false;
}
void AddUnderLine(ImColor col_);
bool TextButtonColored(ImVec4 color, const char* name_);

} // namespace ImGui
14 changes: 12 additions & 2 deletions src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,18 @@ bool Game::Run()
}
LoadMap(_fileSystem->ScriptsPath() / "Land1.txt");

// _lhvm = std::make_unique<LHVM::LHVM>();
// _lhvm->LoadBinary(GetGamePath() + fileSystem->QuestsPath() / "challenge.chl");
auto challengePath = _fileSystem->QuestsPath() / "challenge.chl";
if (_fileSystem->Exists(challengePath))
{
_lhvm = std::make_unique<LHVM::LHVM>();
_lhvm->LoadBinary((_fileSystem->GetGamePath() / challengePath).generic_string());
}
else
{
SPDLOG_LOGGER_ERROR(spdlog::get("game"), "Challenge file not found at {}",
(_fileSystem->GetGamePath() / challengePath).generic_string());
return false;
}

if (_window)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class Game
entities::components::Transform& GetHandTransform();
AnimationPack& GetAnimationPack() { return *_animationPack; }
MeshPack& GetMeshPack() { return *_meshPack; }
[[nodiscard]] const LHVM::LHVM* GetLhvm() { return _lhvm.get(); }
[[nodiscard]] const LHVM::LHVM& GetLhvm() { return *_lhvm; }
FileSystem& GetFileSystem() { return *_fileSystem; }
entities::Registry& GetEntityRegistry() { return *_entityRegistry; }
[[nodiscard]] entities::Registry& GetEntityRegistry() const { return *_entityRegistry; }
Expand Down
4 changes: 2 additions & 2 deletions src/Gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
#include <Entities/Registry.h>
#include <Game.h>
#include <GameWindow.h>
#include <LHVMViewer.h>

#include "Console.h"
#include "LHVMViewer.h"
#include "LandIsland.h"
#include "MeshViewer.h"
#include "Profiler.h"
Expand Down Expand Up @@ -96,6 +96,7 @@ std::unique_ptr<Gui> Gui::create(const GameWindow* window, graphics::RenderPass
debugWindows.emplace_back(new MeshViewer);
debugWindows.emplace_back(new Console);
debugWindows.emplace_back(new LandIsland);
debugWindows.emplace_back(new LHVMViewer);

auto gui = std::unique_ptr<Gui>(new Gui(imgui, static_cast<bgfx::ViewId>(viewId), std::move(debugWindows)));

Expand Down Expand Up @@ -519,7 +520,6 @@ bool Gui::Loop(Game& game, const Renderer& renderer)
}
ShowVillagerNames(game);
ShowCameraPositionOverlay(game);
LHVMViewer::Draw(game.GetLhvm());
ShowWaterFramebuffer(game);

ImGui::Render();
Expand Down
Loading

0 comments on commit 5cbca9b

Please sign in to comment.