Skip to content

Commit

Permalink
game: Add more UI code and hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
leoetlino committed Mar 24, 2020
1 parent f985bbe commit 7457d95
Show file tree
Hide file tree
Showing 12 changed files with 377 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "source/lib/eigen"]
path = source/lib/eigen
url = https://gitlab.com/libeigen/eigen
2 changes: 2 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ set_target_properties(newcode PROPERTIES SUFFIX ".elf")
target_compile_options(newcode PRIVATE -fdiagnostics-color=always -Wall -Wextra -std=c++17 -fno-exceptions -fomit-frame-pointer -ffunction-sections)
target_include_directories(newcode PRIVATE ./)

target_include_directories(newcode SYSTEM PRIVATE lib/eigen/)

if (NOT DEFINED CODEADDR)
message(FATAL_ERROR "Set CODEADDR")
endif()
Expand Down
7 changes: 7 additions & 0 deletions source/common/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ class Flags {
constexpr void Set(FlagType v) { flags |= std::underlying_type_t<FlagType>(v); }
constexpr void Clear(FlagType v) { flags &= ~std::underlying_type_t<FlagType>(v); }

constexpr void Set(FlagType v, bool condition) {
if (condition)
Set(v);
else
Clear(v);
}

constexpr bool IsSet(FlagType v) const {
return (flags & std::underlying_type_t<FlagType>(v)) != 0;
}
Expand Down
7 changes: 7 additions & 0 deletions source/common/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <cmath>
#include <cstdint>

#include <Eigen/Dense>

using u8 = std::uint8_t;
using u16 = std::uint16_t;
using u32 = std::uint32_t;
Expand All @@ -16,6 +18,11 @@ using size_t = std::size_t;
static_assert(sizeof(u16) == sizeof(short));
static_assert(sizeof(u32) == sizeof(int));

using Matrix23 = Eigen::Matrix<float, 2, 3, Eigen::RowMajor | Eigen::DontAlign>;
using Matrix34 = Eigen::Matrix<float, 3, 4, Eigen::RowMajor | Eigen::DontAlign>;
using Vec2 = Eigen::Matrix<float, 2, 1, Eigen::DontAlign>;
using Vec4 = Eigen::Matrix<float, 4, 1, Eigen::DontAlign>;

template <typename T = float>
struct TVec3 {
T x;
Expand Down
2 changes: 1 addition & 1 deletion source/game/state_sot_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void StateSotSave::Calc() {
sotsave_status = Status::WaitingForPackageLoad;
break;
case Status::WaitingForPackageLoad:
if (ui::PackageMgr::Instance().IsLoading())
if (ui::Project::Instance().IsLoading())
return;
layout = ui::LayoutMgr::Instance().MakeLayout("Joker.Main.Ending.Ending");
press_start_layout = ui::LayoutMgr::Instance().MakeLayout("Joker.Main.Ending.EndingPressStart");
Expand Down
75 changes: 58 additions & 17 deletions source/game/ui.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "game/ui.h"

#include <string_view>

#include "common/context.h"
#include "common/debug.h"
#include "common/utils.h"
#include "game/context.h"
#include "game/static_context.h"
Expand Down Expand Up @@ -71,9 +74,39 @@ bool CheckCurrentScreen(ScreenType screen) {
return GetScreenContext().active_screen == GetScreen(screen);
}

void Layout::Calc() {
void LayoutBase::calc(float speed) {
// ends up calling this->Calc(...) with a bunch of global arguments
rst::util::GetPointer<void(Layout*)>(0x161AE8)(this);
rst::util::GetPointer<void(LayoutBase*, float)>(0x161AE8)(this, speed);
}

Widget* LayoutBase::GetWidget(const char* name) const {
return rst::util::GetPointer<Widget*(const LayoutBase*, const char*)>(0x13BE78)(this, name);
}

Pane* LayoutBase::GetPane(const char* name) const {
std::string_view name_sv = name;
for (auto* pane : panes) {
if (pane->GetName() == name_sv)
return pane;
}
return nullptr;
}

WidgetType Widget::GetType() const {
if (widgets.data)
return WidgetType::Widget;
if (layout)
return WidgetType::Layout;
if (main_widget_idx != 0xffff)
return WidgetType::MainWidget;
return WidgetType::Pane;
}

void Widget::PrintDebug() {
auto& tx = GetPos().translate;
rst::util::Print("%p %s tx=(%f %f %f) mtx=(%f %f %f) %08lx %08lx %f", this, GetName(), tx.x, tx.y,
tx.z, mtx(0, 3), mtx(1, 3), mtx(2, 3), GetPos().flags.flags,
GetPos().active_flags.flags, vec4(3));
}

LayoutMgr& LayoutMgr::Instance() {
Expand All @@ -85,37 +118,45 @@ void LayoutMgr::FreeLayout(Layout* layout) {
rst::util::GetPointer<void(LayoutMgr&, Layout*)>(0x169634)(*this, layout);
}

Layout* LayoutMgr::MakeLayout(LayoutFile* file, int x) {
return rst::util::GetPointer<Layout*(LayoutMgr&, LayoutFile*, int)>(0x16962C)(*this, file, x);
Layout* LayoutMgr::MakeLayout(int file, int x) {
return rst::util::GetPointer<Layout*(LayoutMgr&, int, int)>(0x16962C)(*this, file, x);
}

Layout* LayoutMgr::MakeLayout(const char* name) {
LayoutFile* file = PackageMgr::Instance().GetLayoutFile(name);
int file = Project::Instance().GetLayoutId(name);
return MakeLayout(file);
}

PackageMgr& PackageMgr::Instance() {
return *rst::util::GetPointer<PackageMgr>(0x7CDCA0);
Project& Project::Instance() {
return *rst::util::GetPointer<Project>(0x7CDCA0);
}

int Project::GetLayoutId(const char* name) {
return rst::util::GetPointer<int(Project&, const char*)>(0x16A014)(*this, name);
}

int Project::GetPackageId(const char* name) {
return rst::util::GetPointer<int(Project&, const char*)>(0x15A86C)(*this, name);
}

LayoutFile* PackageMgr::GetLayoutFile(const char* name) {
return rst::util::GetPointer<LayoutFile*(PackageMgr&, const char*)>(0x16A014)(*this, name);
bool Project::LoadPackage(int id, bool x) {
return rst::util::GetPointer<bool(Project&, int, bool)>(0x15141C)(*this, id, x);
}

int PackageMgr::GetHandle(const char* name) {
return rst::util::GetPointer<int(PackageMgr&, const char*)>(0x15A86C)(*this, name);
bool Project::UnloadPackage(int id) {
return rst::util::GetPointer<bool(Project&, int)>(0x161CB4)(*this, id);
}

bool PackageMgr::LoadPackage(int handle, bool x) {
return rst::util::GetPointer<bool(PackageMgr&, int, bool)>(0x15141C)(*this, handle, x);
bool Project::IsLoading() const {
return rst::util::GetPointer<bool(const Project&)>(0x180190)(*this);
}

bool PackageMgr::UnloadPackage(int handle) {
return rst::util::GetPointer<bool(PackageMgr&, int)>(0x161CB4)(*this, handle);
LayoutDrawMgr& LayoutDrawMgr::Instance() {
return *rst::util::GetPointer<LayoutDrawMgr*()>(0x17EC58)();
}

bool PackageMgr::IsLoading() const {
return rst::util::GetPointer<bool(const PackageMgr&)>(0x180190)(*this);
void LayoutDrawMgr::ControlLayout(Layout* layout, int a, int b) {
rst::util::GetPointer<void(LayoutDrawMgr*, Layout*, int, int)>(0x17EC58)(this, layout, a, b);
}

} // namespace game::ui
Loading

0 comments on commit 7457d95

Please sign in to comment.