Merge branch 'android-testing'
This commit is contained in:
@@ -8,55 +8,65 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
find_package(Freetype REQUIRED)
|
find_package(Freetype REQUIRED)
|
||||||
find_package(glfw3 CONFIG REQUIRED)
|
|
||||||
find_package(Lua REQUIRED)
|
find_package(Lua REQUIRED)
|
||||||
|
find_package(SDL3 CONFIG REQUIRED)
|
||||||
|
find_package(SDL3_image CONFIG REQUIRED)
|
||||||
|
find_package(SQLiteCpp REQUIRED)
|
||||||
|
find_package(toml11 CONFIG REQUIRED)
|
||||||
|
|
||||||
pkg_check_modules(LUNASVG REQUIRED IMPORTED_TARGET lunasvg)
|
pkg_check_modules(LUNASVG REQUIRED IMPORTED_TARGET lunasvg)
|
||||||
add_library(lunasvg::lunasvg ALIAS PkgConfig::LUNASVG)
|
add_library(lunasvg::lunasvg ALIAS PkgConfig::LUNASVG)
|
||||||
|
|
||||||
#pkg_check_modules(SQLITE3 REQUIRED IMPORTED_TARGET sqlite3)
|
|
||||||
#add_library(sqlite3::sqlite3 ALIAS PkgConfig::SQLITE3)
|
|
||||||
|
|
||||||
find_package(SQLiteCpp REQUIRED)
|
|
||||||
|
|
||||||
find_package(toml11 CONFIG REQUIRED)
|
|
||||||
|
|
||||||
find_package(RmlUi CONFIG REQUIRED)
|
find_package(RmlUi CONFIG REQUIRED)
|
||||||
|
|
||||||
|
add_library(rmlui_backend STATIC
|
||||||
|
vendor/rmlui_backend/RmlUi_Backend_SDL_SDLrenderer.cpp
|
||||||
|
vendor/rmlui_backend/RmlUi_Platform_SDL.cpp
|
||||||
|
vendor/rmlui_backend/RmlUi_Renderer_SDL.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(rmlui_backend PUBLIC
|
||||||
|
vendor/rmlui_backend
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_definitions(rmlui_backend PUBLIC
|
||||||
|
RMLUI_SDL_VERSION_MAJOR=3
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(rmlui_backend PUBLIC
|
||||||
|
RmlUi::RmlUi
|
||||||
|
SDL3::SDL3
|
||||||
|
SDL3_image::SDL3_image
|
||||||
|
Freetype::Freetype
|
||||||
|
)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/database.cpp
|
src/database.cpp
|
||||||
src/ui.cpp
|
src/ui.cpp
|
||||||
src/image_utils.cpp
|
src/image_utils.cpp
|
||||||
|
|
||||||
vendor/rmlui_backend/RmlUi_Backend_GLFW_GL3.cpp
|
|
||||||
vendor/rmlui_backend/RmlUi_Platform_GLFW.cpp
|
|
||||||
vendor/rmlui_backend/RmlUi_Renderer_GL3.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||||
src
|
src
|
||||||
vendor/rmlui_backend
|
${FREETYPE_INCLUDE_DIRS}
|
||||||
${FREETYPE_INCLUDE_DIRS}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||||
RmlUi::RmlUi
|
rmlui_backend
|
||||||
RmlUi::Debugger
|
RmlUi::RmlUi
|
||||||
RmlUi::Lua
|
RmlUi::Debugger
|
||||||
${LUA_LIBRARIES}
|
RmlUi::Lua
|
||||||
Freetype::Freetype
|
${LUA_LIBRARIES}
|
||||||
lunasvg::lunasvg
|
Freetype::Freetype
|
||||||
glfw
|
lunasvg::lunasvg
|
||||||
toml11::toml11
|
toml11::toml11
|
||||||
SQLiteCpp
|
SQLiteCpp
|
||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
|
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
|
||||||
install(DIRECTORY assets DESTINATION bin)
|
install(DIRECTORY assets DESTINATION bin)
|
||||||
|
|
||||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||||
ASSETS_DIR="${CMAKE_SOURCE_DIR}/bin/assets"
|
ASSETS_DIR="${CMAKE_SOURCE_DIR}/bin/assets"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
22
flake.nix
22
flake.nix
@@ -14,6 +14,7 @@
|
|||||||
rmlui = pkgs.stdenv.mkDerivation rec {
|
rmlui = pkgs.stdenv.mkDerivation rec {
|
||||||
pname = "rmlui";
|
pname = "rmlui";
|
||||||
version = "master";
|
version = "master";
|
||||||
|
|
||||||
src = pkgs.fetchFromGitHub {
|
src = pkgs.fetchFromGitHub {
|
||||||
owner = "mikke89";
|
owner = "mikke89";
|
||||||
repo = "RmlUi";
|
repo = "RmlUi";
|
||||||
@@ -31,14 +32,14 @@
|
|||||||
pkgs.lunasvg
|
pkgs.lunasvg
|
||||||
pkgs.lua
|
pkgs.lua
|
||||||
];
|
];
|
||||||
|
|
||||||
cmakeFlags = [
|
cmakeFlags = [
|
||||||
"-DRMLUI_LUA_BINDINGS=ON"
|
"-DRMLUI_LUA_BINDINGS=ON"
|
||||||
"-DRMLUI_LUA_BINDINGS_LIBRARY=lua"
|
"-DRMLUI_LUA_BINDINGS_LIBRARY=lua"
|
||||||
"-DRMLUI_SVG_PLUGIN=ON"
|
"-DRMLUI_SVG_PLUGIN=ON"
|
||||||
"-DBUILD_SHARED_LIBS=ON"
|
"-DBUILD_SHARED_LIBS=ON"
|
||||||
"-DBUILD_SAMPLES=OFF"
|
"-DBUILD_SAMPLES=OFF"
|
||||||
"-DBUILD_TESTING=OFF"
|
"-DBUILD_TESTING=OFF"
|
||||||
"-DNO_FONT_INTERFACE_DEFAULT=OFF"
|
"-DNO_FONT_INTERFACE_DEFAULT=OFF"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
@@ -52,14 +53,9 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
runtimeDeps = with pkgs; [
|
runtimeDeps = with pkgs; [
|
||||||
raylib
|
sdl3
|
||||||
glfw
|
sdl3-image
|
||||||
libGL
|
libGL
|
||||||
libX11
|
|
||||||
libXcursor
|
|
||||||
libXrandr
|
|
||||||
libXinerama
|
|
||||||
libXi
|
|
||||||
wayland
|
wayland
|
||||||
libxkbcommon
|
libxkbcommon
|
||||||
rmlui
|
rmlui
|
||||||
@@ -77,10 +73,10 @@
|
|||||||
buildInputs = runtimeDeps;
|
buildInputs = runtimeDeps;
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
export CP_PATH="${pkgs.raylib}/include:${pkgs.glfw}/include:${rmlui}/include"
|
export CP_PATH="${rmlui}/include"
|
||||||
export LIBRARY_PATH="${pkgs.raylib}/lib:${pkgs.glfw}/lib:${pkgs.libGL}/lib:${rmlui}/lib"
|
export LIBRARY_PATH="${pkgs.libGL}/lib:${rmlui}/lib"
|
||||||
export LD_LIBRARY_PATH="$LIBRARY_PATH:$LD_LIBRARY_PATH"
|
export LD_LIBRARY_PATH="$LIBRARY_PATH:$LD_LIBRARY_PATH"
|
||||||
|
|
||||||
echo "Env ready"
|
echo "Env ready"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|||||||
55
src/main.cpp
55
src/main.cpp
@@ -3,18 +3,15 @@
|
|||||||
#include "ui.hpp"
|
#include "ui.hpp"
|
||||||
#include "../vendor/stb/stb_image.h"
|
#include "../vendor/stb/stb_image.h"
|
||||||
#include "../vendor/stb/stb_image_write.h"
|
#include "../vendor/stb/stb_image_write.h"
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include <RmlUi/Core.h>
|
#include <RmlUi/Core.h>
|
||||||
#include <RmlUi/Core/Core.h>
|
#include <RmlUi/Core/Core.h>
|
||||||
#include <RmlUi/Debugger/Debugger.h>
|
#include <RmlUi/Debugger/Debugger.h>
|
||||||
#include <RmlUi/Lua/Lua.h>
|
#include <RmlUi/Lua/Lua.h>
|
||||||
#include <RmlUi_Backend.h>
|
#include <RmlUi_Backend.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
static bool is_initalized = false;
|
static bool is_initalized = false;
|
||||||
static bool is_running = false;
|
static bool is_running = false;
|
||||||
static Rml::Context *ctx = nullptr;
|
static Rml::Context *ctx = nullptr;
|
||||||
@@ -22,47 +19,42 @@ static std::map<int, Critter> critters;
|
|||||||
static std::vector<CritterEntry> critter_list;
|
static std::vector<CritterEntry> critter_list;
|
||||||
static Rml::ElementDocument *doc;
|
static Rml::ElementDocument *doc;
|
||||||
static AppData app_data;
|
static AppData app_data;
|
||||||
|
|
||||||
void shutdown() {
|
void shutdown() {
|
||||||
Rml::Shutdown();
|
Rml::Shutdown();
|
||||||
Backend::Shutdown();
|
Backend::Shutdown();
|
||||||
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool initialize() {
|
bool initialize() {
|
||||||
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) {
|
||||||
|
std::cout << "[ERROR] Failed to initialize SDL3: " << SDL_GetError() << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (!Backend::Initialize("CritterFolio", 800, 600, true)) {
|
if (!Backend::Initialize("CritterFolio", 800, 600, true)) {
|
||||||
std::cout << "[ERROR] Failed to initialize backend.\n";
|
std::cout << "[ERROR] Failed to initialize backend.\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::cout << "[INFO] RmlUI Backend initialized.\n";
|
std::cout << "[INFO] RmlUI Backend initialized.\n";
|
||||||
|
|
||||||
Rml::SetSystemInterface(Backend::GetSystemInterface());
|
Rml::SetSystemInterface(Backend::GetSystemInterface());
|
||||||
Rml::SetRenderInterface(Backend::GetRenderInterface());
|
Rml::SetRenderInterface(Backend::GetRenderInterface());
|
||||||
Rml::Initialise();
|
Rml::Initialise();
|
||||||
Rml::Lua::Initialise();
|
Rml::Lua::Initialise();
|
||||||
|
|
||||||
std::cout << "[INFO] Loading local DB...\n";
|
std::cout << "[INFO] Loading local DB...\n";
|
||||||
if (!db_get_all_critters(critters)) {
|
if (!db_get_all_critters(critters)) {
|
||||||
std::cout << "[ERROR] Local DB failed to initialize.\n";
|
std::cout << "[ERROR] Local DB failed to initialize.\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::cout << "[INFO] Local DB initialized.\n";
|
std::cout << "[INFO] Local DB initialized.\n";
|
||||||
|
|
||||||
sync_map_to_list(critters, critter_list);
|
sync_map_to_list(critters, critter_list);
|
||||||
|
|
||||||
ctx = Rml::CreateContext("main", Rml::Vector2i(800, 600));
|
ctx = Rml::CreateContext("main", Rml::Vector2i(800, 600));
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
std::cout << "[ERROR] Failed to create context.\n";
|
std::cout << "[ERROR] Failed to create context.\n";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
std::cout << "[INFO] Main context initialized.\n";
|
std::cout << "[INFO] Main context initialized.\n";
|
||||||
|
|
||||||
Rml::LoadFontFace("./assets/fonts/Hubballi-Regular.ttf");
|
Rml::LoadFontFace("./assets/fonts/Hubballi-Regular.ttf");
|
||||||
|
|
||||||
Rml::Debugger::Initialise(ctx);
|
Rml::Debugger::Initialise(ctx);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool load_document() {
|
bool load_document() {
|
||||||
doc = ctx->LoadDocument("./assets/main.rml");
|
doc = ctx->LoadDocument("./assets/main.rml");
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
@@ -74,7 +66,6 @@ bool load_document() {
|
|||||||
doc->Show();
|
doc->Show();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reload_doc() {
|
bool reload_doc() {
|
||||||
if (doc) {
|
if (doc) {
|
||||||
Rml::Factory::ClearStyleSheetCache();
|
Rml::Factory::ClearStyleSheetCache();
|
||||||
@@ -82,79 +73,63 @@ bool reload_doc() {
|
|||||||
doc->Close();
|
doc->Close();
|
||||||
doc = nullptr;
|
doc = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!load_document()) {
|
if (!load_document()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool f5_was_pressed = false;
|
bool f5_was_pressed = false;
|
||||||
bool f8_was_pressed = false;
|
bool f8_was_pressed = false;
|
||||||
|
|
||||||
void handle_input() {
|
void handle_input() {
|
||||||
GLFWwindow *window = glfwGetCurrentContext();
|
const bool *state = SDL_GetKeyboardState(NULL);
|
||||||
if(window) {
|
if (state) {
|
||||||
// Reload ui
|
// Reload ui
|
||||||
bool f5_state = glfwGetKey(window, GLFW_KEY_F5);
|
bool f5_state = state[SDL_SCANCODE_F5];
|
||||||
if (f5_state == GLFW_PRESS && !f5_was_pressed) {
|
if (f5_state && !f5_was_pressed) {
|
||||||
f5_was_pressed = true;
|
f5_was_pressed = true;
|
||||||
reload_doc();
|
reload_doc();
|
||||||
} else if (f5_state == GLFW_RELEASE) {
|
} else if (!f5_state) {
|
||||||
f5_was_pressed = false;
|
f5_was_pressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle debugger window
|
// Toggle debugger window
|
||||||
bool f8_state = glfwGetKey(window, GLFW_KEY_F8);
|
bool f8_state = state[SDL_SCANCODE_F8];
|
||||||
if (f8_state == GLFW_PRESS && !f8_was_pressed) {
|
if (f8_state && !f8_was_pressed) {
|
||||||
f8_was_pressed = true;
|
f8_was_pressed = true;
|
||||||
bool is_visible = Rml::Debugger::IsVisible();
|
bool is_visible = Rml::Debugger::IsVisible();
|
||||||
Rml::Debugger::SetVisible(!is_visible);
|
Rml::Debugger::SetVisible(!is_visible);
|
||||||
} else if (f8_state == GLFW_RELEASE) {
|
} else if (!f8_state) {
|
||||||
f8_was_pressed = false;
|
f8_was_pressed = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "[INFO] Starting CritterFolio...\n";
|
std::cout << "[INFO] Starting CritterFolio...\n";
|
||||||
|
|
||||||
is_initalized = initialize();
|
is_initalized = initialize();
|
||||||
if (!is_initalized) {
|
if (!is_initalized) {
|
||||||
std::cout << "[ERROR] Failed to initialize, shutting down.\n";
|
std::cout << "[ERROR] Failed to initialize, shutting down.\n";
|
||||||
shutdown();
|
shutdown();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
is_running = true;
|
is_running = true;
|
||||||
|
|
||||||
Rml::DataModelHandle app_data_handle;
|
Rml::DataModelHandle app_data_handle;
|
||||||
if (!setup_data_binding(ctx, app_data_handle, app_data, critter_list, critters)) {
|
if (!setup_data_binding(ctx, app_data_handle, app_data, critter_list, critters)) {
|
||||||
shutdown();
|
shutdown();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!load_document()) {
|
if (!load_document()) {
|
||||||
shutdown();
|
shutdown();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::cout << "[INFO] Main page loaded.\n";
|
std::cout << "[INFO] Main page loaded.\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while (is_running) {
|
while (is_running) {
|
||||||
is_running = Backend::ProcessEvents(ctx);
|
is_running = Backend::ProcessEvents(ctx);
|
||||||
|
|
||||||
handle_input();
|
handle_input();
|
||||||
|
|
||||||
ctx->Update();
|
ctx->Update();
|
||||||
Backend::BeginFrame();
|
Backend::BeginFrame();
|
||||||
ctx->Render();
|
ctx->Render();
|
||||||
Backend::PresentFrame();
|
Backend::PresentFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
shutdown();
|
shutdown();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user