From 79bc598ef93e8ee24ccbeb04325748eea8423dad Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Fri, 18 Feb 2022 16:57:14 -0500 Subject: [PATCH] Fill out web platform backend with a main loop --- platforms/web/CMakeLists.txt | 2 + platforms/web/main.cpp.in | 175 ++++++++++++++++++++++++++++++++++- 2 files changed, 175 insertions(+), 2 deletions(-) diff --git a/platforms/web/CMakeLists.txt b/platforms/web/CMakeLists.txt index f18c40b..3568971 100644 --- a/platforms/web/CMakeLists.txt +++ b/platforms/web/CMakeLists.txt @@ -5,6 +5,8 @@ add_platform( main.cpp.in LINK_LIBRARIES Core + GFXWebGPU + Log ) function(add_platform_commands target) diff --git a/platforms/web/main.cpp.in b/platforms/web/main.cpp.in index 43ada95..25bf403 100644 --- a/platforms/web/main.cpp.in +++ b/platforms/web/main.cpp.in @@ -1,7 +1,178 @@ #include +#include <@APP_INCLUDE@> +#include + +#include "engine.hpp" +#include "platform.hpp" +#include "gfx_webgpu.hpp" +#include "file.hpp" + +@APP_CLASS@* app = nullptr; +GFX* gfx_interface = nullptr; + +EM_BOOL draw(double time, void *userData) { + printf("Draw\n"); + + engine->update(time); + engine->begin_frame(time); + + engine->render((void*)1); + + engine->end_frame(); + + return true; +} int main(int argc, char* argv[]) { - printf("Hello, world!\n"); + engine = new prism::engine(argc, argv); + + app = new @APP_CLASS@(); + engine->set_app(app); + + GFXCreateInfo info = {}; + gfx_interface = new GFXWebGPU(); + if(gfx_interface->initialize(info)) { + engine->set_gfx(gfx_interface); + } else { + return -1; + } + + app_main(engine); + + engine->add_window(nullptr, (void*)1, {100, 100}}); + app->initialize_render(); + + emscripten_request_animation_frame_loop(draw, nullptr); return 0; -} \ No newline at end of file +} + +void platform::capture_mouse(const bool capture) { + +} + +PlatformTheme platform::get_theme() { + return PlatformTheme::Light; +} + +void platform::begin_text_input() { +} + +void platform::end_text_input() { +} + +void* platform::create_native_surface(platform::window_ptr index, void* instance) { + return nullptr; +} + +bool platform::is_main_window(platform::window_ptr index) { + return true; +} + +std::vector platform::get_native_surface_extension() { + return {}; +} + +void platform::show_window(const platform::window_ptr index) { + +} + +bool platform::supports_feature(const PlatformFeature feature) { + return false; +} + +prism::Offset platform::get_cursor_position() { + return {0, 0}; +} + +std::tuple platform::get_right_stick_position() { + return {0, 0}; +} + +std::tuple platform::get_left_stick_position() { + return {0, 0}; +} + +bool platform::get_key_down(InputButton key) { + return false; +} + +platform::window_ptr platform::open_window(const std::string_view title, const prism::Rectangle rect, const WindowFlags flags) { + return (void*)1; +} + +void platform::set_window_title(const platform::window_ptr index, const std::string_view title) { + +} + +bool platform::is_window_focused(const platform::window_ptr index) { + +} + +void platform::set_window_focused(const platform::window_ptr index) { + +} + +prism::Extent platform::get_window_size(const platform::window_ptr index) { + return {100, 100}; +} + +prism::Extent platform::get_window_drawable_size(const platform::window_ptr index) { + return {100, 100}; +} + +prism::Offset platform::get_window_position(const platform::window_ptr index) { + +} + +void platform::set_window_size(const platform::window_ptr index, const prism::Extent extent) { + +} + +void platform::set_window_position(const platform::window_ptr index, const prism::Offset offset) { + +} + +void platform::close_window(const platform::window_ptr index) { + +} + +int platform::get_keycode(const InputButton button) { + return 0; +} + +prism::Rectangle platform::get_monitor_resolution() { + return {0, 0, 100, 100}; +} + +prism::Rectangle platform::get_monitor_work_area() { + return {0, 0, 100, 100}; +} + +prism::Offset platform::get_screen_cursor_position() { + +} + +bool platform::get_mouse_button_down(const int index) { + return false; +} + +float platform::get_monitor_dpi() { + return 1.0f; +} + +std::tuple platform::get_wheel_delta() { + +} + +const char* platform::get_name() { + return "Web"; +} + +void prism::set_domain_path(const prism::domain domain, const prism::path& path) { + +} + +prism::path prism::get_writeable_directory() { + +}