Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
More stuff I think
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed Jan 10, 2024
1 parent 7514659 commit 06e2ce1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 29 deletions.
20 changes: 7 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ elseif(HYDRA_IOS)
"-framework OpenGL"
)
elseif(HYDRA_WEB)
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "" FORCE)
set(CMAKE_C_FLAGS "-fPIC")
set(CMAKE_CXX_FLAGS "-fPIC")
set(LONG_INT 8) # for openssl
set(CMAKE_EXECUTABLE_SUFFIX ".html")
set_target_properties(hydra PROPERTIES LINK_FLAGS "-sEXPORTED_FUNCTIONS=[_main_impl,_main] -sEXPORTED_RUNTIME_METHODS=ccall -sNO_DISABLE_EXCEPTION_CATCHING -sASSERTIONS -sALLOW_MEMORY_GROWTH -s TOTAL_MEMORY=192MB -lidbfs.js -s ELIMINATE\_DUPLICATE\_FUNCTIONS=1 --shell-file ${PROJECT_SOURCE_DIR}/data/shell.html -flto -s USE_CLOSURE_COMPILER=0 --closure 0")
set_target_properties(hydra PROPERTIES LINK_FLAGS "-sASSERTIONS -sEXPORTED_FUNCTIONS=[_malloc,_free,_main,_main_impl] -sEXPORTED_RUNTIME_METHODS=ccall -sNO_DISABLE_EXCEPTION_CATCHING -sALLOW_MEMORY_GROWTH -sTOTAL_MEMORY=192MB -lidbfs.js -s ELIMINATE_DUPLICATE_FUNCTIONS=1 --shell-file ${PROJECT_SOURCE_DIR}/data/shell.html -flto -sMAIN_MODULE=1 -sUSE_CLOSURE_COMPILER=0 --closure 0")
else()
message(FATAL_ERROR "Unsupported platform")
endif()
Expand All @@ -97,6 +100,7 @@ add_subdirectory(vendored/fmt)
add_subdirectory(vendored/argparse)
add_subdirectory(vendored/toml11)
set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE)
set(SDL_STATIC_PIC ON CACHE BOOL "" FORCE)
add_subdirectory(vendored/SDL)

set(HYDRA_INCLUDES ${HYDRA_INCLUDES}
Expand Down Expand Up @@ -140,9 +144,6 @@ if(HYDRA_MACOS OR HYDRA_IOS)
MACOSX_BUNDLE_BUNDLE_IDENTIFIER "com.hydra.hydra_emu")
endif()

add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)

set(HYDRA_QT_FILES
data/resources.qrc
qt/mainwindow.cxx
Expand Down Expand Up @@ -206,19 +207,12 @@ set(HYDRA_LIBRARIES
toml11
)

cmrc_add_resource_library(hydra_images ALIAS hydra::images NAMESPACE hydra
WHENCE data/images
PREFIX images
cmrc_add_resource_library(hydra_data ALIAS hydra::data NAMESPACE hydra
data/images/hydra.png
)

cmrc_add_resource_library(hydra_other ALIAS hydra::other NAMESPACE hydra
WHENCE data
PREFIX other
data/cacert.pem
)

set(HYDRA_LIBRARIES ${HYDRA_LIBRARIES} hydra::images hydra::other)
set(HYDRA_LIBRARIES ${HYDRA_LIBRARIES} hydra::data)

if (BUILD_QT)
set(CMAKE_AUTOUIC ON)
Expand Down
4 changes: 3 additions & 1 deletion include/corewrapper.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ namespace hydra

inline std::string dynlib_get_extension()
{
#if defined(HYDRA_LINUX) || defined(HYDRA_ANDROID) || defined(HYDRA_FREEBSD) || defined(HYDRA_WEB)
#if defined(HYDRA_LINUX) || defined(HYDRA_ANDROID) || defined(HYDRA_FREEBSD)
return ".so";
#elif defined(HYDRA_WEB)
return ".wasm";
#elif defined(HYDRA_MACOS)
return ".dylib";
#elif defined(HYDRA_WINDOWS)
Expand Down
47 changes: 34 additions & 13 deletions src/app.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "SDL_render.h"
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <glad/glad.h>
#include <IconsMaterialDesign.h>
#include <imgui/backends/imgui_impl_opengl3.h>
Expand Down Expand Up @@ -50,6 +51,26 @@ extern unsigned int MaterialIcons_compressed_data[246308 / 4];

std::unique_ptr<MainWindow> main_window;

extern "C" void hydra_drop_file(const char* name, void* data, size_t size)
{
std::filesystem::path file = name;
if (file.extension() == hydra::dynlib_get_extension())
{
std::filesystem::path cores = Settings::Get("core_path");
std::filesystem::path out_path = cores / file;
std::ofstream ofs(out_path, std::ios_base::binary | std::ios_base::out);
ofs.write((const char*)data, size);
}
else
{
std::filesystem::path cache = Settings::GetCachePath();
std::filesystem::path out_path = cache / file;
std::ofstream ofs(out_path, std::ios_base::binary | std::ios_base::out);
ofs.write((const char*)data, size);
}
sync_fs();
}

#ifdef HYDRA_WEB
EM_JS(void, add_drag_drop_listeners, (), {
var canvas = document.getElementById("canvas");
Expand Down Expand Up @@ -80,27 +101,27 @@ EM_JS(void, add_drag_drop_listeners, (), {
e.preventDefault();
e.stopPropagation();
var files = e.dataTransfer.files;
if (files.length > 0)
for (var i = 0, f; f = files[i]; i++)
{
var file = files[0];
var reader = new FileReader();
reader.onload = function(e)
{
var data = e.target.result;
var ptr = Module._malloc(data.byteLength);
Module.HEAPU8.set(new Uint8Array(data), ptr);
var path = allocate(intArrayFromString(file.name), 'i8', ALLOC_STACK);
_hydra_drop_file(ptr, path);
Module._free(ptr);
};
reader.readAsArrayBuffer(file);
reader.onload = (function(file) {
return function(e)
{
var ptr = Module._malloc(file.size);
Module.HEAPU8.set(new Uint8Array(e.target.result), ptr);
Module.ccall('hydra_drop_file', 'void',
[ 'string', 'number', 'number' ],
[ file.name, ptr, file.size ]);
Module._free(ptr);
};
})(f);
reader.readAsArrayBuffer(f);
}
},
false);

});
#endif
// FIXME FINISH THIS ^^^

int imgui_main(int argc, char* argv[])
{
Expand Down
4 changes: 4 additions & 0 deletions src/gamewindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ GLenum GameWindow::get_gl_format(hydra::PixelFormat format)
}
case hydra::PixelFormat::BGRA:
{
#ifdef HYDRA_WEB
return GL_RGBA;
#else
return GL_BGRA;
#endif
}
default:
{
Expand Down
5 changes: 3 additions & 2 deletions src/mainwindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ void MainWindow::draw_games()
{
if (ImGui::Button(ICON_MD_FOLDER " Load ROM"))
{
game_window = std::make_unique<GameWindow>("/home/offtkp/cores/libhydra-core.so",
"/home/offtkp/Roms/GBA/emerald.gba");
Settings::Set("NanoBoyAdvance_bios", "/hydra/cache/gba_bios.bin");
game_window = std::make_unique<GameWindow>("/hydra/cores/libNanoBoyAdvance-hydra.wasm",
"/hydra/cache/emerald.gba");
if (!game_window->isLoaded())
{
game_window.reset();
Expand Down

0 comments on commit 06e2ce1

Please sign in to comment.