├── .github └── workflows │ ├── cmake.yml │ └── x │ └── dummy-1920x1080.conf ├── .gitignore ├── .gitmodules ├── .vimspector.json ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake └── FindSDL2.cmake ├── docs ├── basic_game.md ├── framework │ ├── common_components │ │ └── common_components.md │ ├── engine │ │ ├── engine.md │ │ ├── interfaces.md │ │ └── services.md │ ├── filesystem │ │ └── filesystem.md │ ├── logger │ │ └── logger.md │ ├── opengl_primitives │ │ └── opengl_primitives.md │ ├── opengl_renderer │ │ ├── opengl_renderer.md │ │ └── render_tasks │ │ │ ├── blit_fb.md │ │ │ ├── clear.md │ │ │ └── imgui.md │ ├── resource_manager │ │ └── resource_manager.md │ ├── screen_director │ │ └── screen_director.md │ ├── sdl_service │ │ └── sdl_service.md │ └── simple_scene │ │ └── simple_scene.md ├── setup.md └── terminology.md ├── external ├── CMakeLists.txt ├── SquirrelNoise │ ├── CMakeLists.txt │ └── src │ │ └── squirrel_noise │ │ ├── RawNoise.cpp │ │ ├── RawNoise.hpp │ │ ├── SmoothNoise.cpp │ │ └── SmoothNoise.hpp ├── entt.cmake ├── glad-debug │ ├── CMakeLists.txt │ ├── include │ │ ├── KHR │ │ │ └── khrplatform.h │ │ └── glad │ │ │ └── glad.h │ └── src │ │ └── glad.c ├── glm.cmake ├── icon_font_cpp_headers.cmake ├── imgui │ ├── CMakeLists.txt │ ├── imgui_plot_var.cpp │ └── imgui_plot_var.hpp ├── json │ ├── CMakeLists.txt │ ├── LICENSE.MIT │ ├── cmake │ │ ├── config.cmake.in │ │ ├── nlohmann_jsonConfigVersion.cmake.in │ │ └── pkg-config.pc.in │ ├── include │ │ └── nlohmann │ │ │ ├── adl_serializer.hpp │ │ │ ├── byte_container_with_subtype.hpp │ │ │ ├── detail │ │ │ ├── abi_macros.hpp │ │ │ ├── conversions │ │ │ │ ├── from_json.hpp │ │ │ │ ├── to_chars.hpp │ │ │ │ └── to_json.hpp │ │ │ ├── exceptions.hpp │ │ │ ├── hash.hpp │ │ │ ├── input │ │ │ │ ├── binary_reader.hpp │ │ │ │ ├── input_adapters.hpp │ │ │ │ ├── json_sax.hpp │ │ │ │ ├── lexer.hpp │ │ │ │ ├── parser.hpp │ │ │ │ └── position_t.hpp │ │ │ ├── iterators │ │ │ │ ├── internal_iterator.hpp │ │ │ │ ├── iter_impl.hpp │ │ │ │ ├── iteration_proxy.hpp │ │ │ │ ├── iterator_traits.hpp │ │ │ │ ├── json_reverse_iterator.hpp │ │ │ │ └── primitive_iterator.hpp │ │ │ ├── json_custom_base_class.hpp │ │ │ ├── json_pointer.hpp │ │ │ ├── json_ref.hpp │ │ │ ├── macro_scope.hpp │ │ │ ├── macro_unscope.hpp │ │ │ ├── meta │ │ │ │ ├── call_std │ │ │ │ │ ├── begin.hpp │ │ │ │ │ └── end.hpp │ │ │ │ ├── cpp_future.hpp │ │ │ │ ├── detected.hpp │ │ │ │ ├── identity_tag.hpp │ │ │ │ ├── is_sax.hpp │ │ │ │ ├── std_fs.hpp │ │ │ │ ├── type_traits.hpp │ │ │ │ └── void_t.hpp │ │ │ ├── output │ │ │ │ ├── binary_writer.hpp │ │ │ │ ├── output_adapters.hpp │ │ │ │ └── serializer.hpp │ │ │ ├── string_concat.hpp │ │ │ ├── string_escape.hpp │ │ │ ├── string_utils.hpp │ │ │ └── value_t.hpp │ │ │ ├── json.hpp │ │ │ ├── json_fwd.hpp │ │ │ ├── ordered_map.hpp │ │ │ └── thirdparty │ │ │ └── hedley │ │ │ ├── hedley.hpp │ │ │ └── hedley_undef.hpp │ ├── meson.build │ ├── nlohmann_json.natvis │ └── single_include │ │ └── nlohmann │ │ ├── json.hpp │ │ └── json_fwd.hpp ├── physfs │ └── CMakeLists.txt ├── soloud │ └── CMakeLists.txt ├── stb │ ├── CMakeLists.txt │ ├── stb_image.cpp │ ├── stb_image_write.cpp │ ├── stb_perlin.cpp │ └── stb_rect_pack.cpp └── tracy │ └── CMakeLists.txt ├── framework ├── CMakeLists.txt ├── common_components │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ └── components │ │ │ ├── color.hpp │ │ │ ├── name.hpp │ │ │ ├── position2d.hpp │ │ │ ├── position2d_zoffset.hpp │ │ │ ├── position3d.hpp │ │ │ ├── rotation2d.hpp │ │ │ ├── scale2d.hpp │ │ │ ├── serialize │ │ │ ├── json_color.hpp │ │ │ ├── json_glm.hpp │ │ │ ├── json_name.hpp │ │ │ ├── json_position2d.hpp │ │ │ ├── json_position2d_zoffset.hpp │ │ │ ├── json_position3d.hpp │ │ │ ├── json_rotation2d.hpp │ │ │ ├── json_scale2d.hpp │ │ │ ├── json_transform4x4.hpp │ │ │ ├── json_velocity2d_position.hpp │ │ │ ├── json_velocity2d_position_intent.hpp │ │ │ ├── json_velocity2d_rotation.hpp │ │ │ ├── json_view_dir2d.hpp │ │ │ ├── json_view_dir3d.hpp │ │ │ └── s6zer_color.hpp │ │ │ ├── time_delta.hpp │ │ │ ├── transform4x4.hpp │ │ │ ├── velocity2d_position.hpp │ │ │ ├── velocity2d_position_intent.hpp │ │ │ ├── velocity2d_rotation.hpp │ │ │ ├── view_dir2d.hpp │ │ │ └── view_dir3d.hpp │ └── test │ │ ├── CMakeLists.txt │ │ ├── component_json_serialization_test.cpp │ │ └── component_s6zer_serialization_test.cpp ├── engine │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ ├── engine.cpp │ │ │ ├── engine.hpp │ │ │ ├── engine_fwd.hpp │ │ │ ├── services │ │ │ ├── count_down.hpp │ │ │ ├── net_channeled_interface.hpp │ │ │ ├── rich_presence_provider_interface.hpp │ │ │ ├── scene_service_interface.hpp │ │ │ └── service.hpp │ │ │ └── update_strategies │ │ │ ├── dummy.hpp │ │ │ ├── sequential_strategy.cpp │ │ │ ├── sequential_strategy.hpp │ │ │ ├── tasking_utils.hpp │ │ │ └── update_strategy.hpp │ └── test │ │ ├── CMakeLists.txt │ │ ├── default_service_test.cpp │ │ ├── default_us_test.cpp │ │ ├── dependency_check_us_test.cpp │ │ ├── run_test.cpp │ │ ├── service_test.cpp │ │ ├── update_strategy_test.cpp │ │ └── update_test.cpp ├── filesystem │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ ├── fs_const_archiver.cpp │ │ │ ├── fs_const_archiver.hpp │ │ │ ├── path_utils.hpp │ │ │ └── services │ │ │ ├── filesystem.cpp │ │ │ └── filesystem.hpp │ └── test │ │ ├── CMakeLists.txt │ │ ├── filesystem_tests.cpp │ │ └── res │ │ ├── test.zip │ │ ├── test.zip.h │ │ ├── test_file.txt │ │ └── wall_concrete-1_se_0.2.json ├── imgui │ ├── CMakeLists.txt │ ├── res │ │ └── ionicons │ │ │ ├── LICENSE │ │ │ ├── ionicons.ttf │ │ │ ├── ionicons.ttf.base85.h │ │ │ └── ionicons.ttf.h │ ├── src │ │ └── mm │ │ │ ├── imgui │ │ │ ├── file_shader_editor.cpp │ │ │ ├── file_shader_editor.hpp │ │ │ ├── file_text_editor.cpp │ │ │ ├── file_text_editor.hpp │ │ │ ├── fps_overlay.cpp │ │ │ ├── fps_overlay.hpp │ │ │ ├── imgui_entt_entity_editor.hpp │ │ │ ├── sound_info.cpp │ │ │ ├── sound_info.hpp │ │ │ ├── sound_pref.cpp │ │ │ ├── sound_pref.hpp │ │ │ └── widgets │ │ │ │ ├── auto_wrap.hpp │ │ │ │ ├── camera.cpp │ │ │ │ ├── camera.hpp │ │ │ │ ├── components │ │ │ │ ├── color.cpp │ │ │ │ ├── color.hpp │ │ │ │ ├── name.cpp │ │ │ │ ├── name.hpp │ │ │ │ ├── position2d.cpp │ │ │ │ ├── position2d.hpp │ │ │ │ ├── position2d_zoffset.cpp │ │ │ │ ├── position2d_zoffset.hpp │ │ │ │ ├── position3d.cpp │ │ │ │ ├── position3d.hpp │ │ │ │ ├── rotation2d.cpp │ │ │ │ ├── rotation2d.hpp │ │ │ │ ├── scale2d.cpp │ │ │ │ ├── scale2d.hpp │ │ │ │ ├── texture.cpp │ │ │ │ ├── texture.hpp │ │ │ │ ├── tilemap_renderable.cpp │ │ │ │ ├── tilemap_renderable.hpp │ │ │ │ ├── velocity2d_position.cpp │ │ │ │ ├── velocity2d_position.hpp │ │ │ │ ├── velocity2d_rotation.cpp │ │ │ │ ├── velocity2d_rotation.hpp │ │ │ │ ├── view_dir2d.cpp │ │ │ │ ├── view_dir2d.hpp │ │ │ │ ├── view_dir3d.cpp │ │ │ │ └── view_dir3d.hpp │ │ │ │ ├── entity.cpp │ │ │ │ ├── entity.hpp │ │ │ │ ├── filesystem.cpp │ │ │ │ ├── filesystem.hpp │ │ │ │ ├── imgui_json_editor.hpp │ │ │ │ ├── knob.cpp │ │ │ │ ├── knob.hpp │ │ │ │ ├── plot_radar.cpp │ │ │ │ ├── plot_radar.hpp │ │ │ │ ├── scalar_range.cpp │ │ │ │ ├── scalar_range.hpp │ │ │ │ ├── soloud.hpp │ │ │ │ ├── soloud_filter.cpp │ │ │ │ ├── soloud_sfxr.cpp │ │ │ │ ├── spritesheet.cpp │ │ │ │ ├── spritesheet.hpp │ │ │ │ ├── texture.cpp │ │ │ │ ├── texture.hpp │ │ │ │ ├── texture_resource_manager.cpp │ │ │ │ └── texture_resource_manager.hpp │ │ │ └── services │ │ │ ├── engine_tools.cpp │ │ │ ├── engine_tools.hpp │ │ │ ├── imgui_menu_bar.cpp │ │ │ ├── imgui_menu_bar.hpp │ │ │ ├── imgui_s.cpp │ │ │ ├── imgui_s.hpp │ │ │ ├── scene_tools.cpp │ │ │ ├── scene_tools.hpp │ │ │ ├── screen_director_tools.cpp │ │ │ ├── screen_director_tools.hpp │ │ │ ├── sound_tools.cpp │ │ │ └── sound_tools.hpp │ └── test │ │ ├── CMakeLists.txt │ │ ├── engine_tools_test.cpp │ │ ├── json_editor_test.cpp │ │ ├── scene_tools_test.cpp │ │ ├── sound_test.cpp │ │ ├── text_edit_test.cpp │ │ └── widget_test.cpp ├── input │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ └── services │ │ │ ├── input_service.cpp │ │ │ └── input_service.hpp │ └── test │ │ ├── CMakeLists.txt │ │ ├── input_visualizer.cpp │ │ └── start_test.cpp ├── logger │ ├── CMakeLists.txt │ └── src │ │ └── mm │ │ ├── logger.cpp │ │ ├── logger.hpp │ │ └── tracy_sink.hpp ├── opengl_primitives │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ └── opengl │ │ │ ├── buffer.cpp │ │ │ ├── buffer.hpp │ │ │ ├── components │ │ │ └── texture.hpp │ │ │ ├── fbo_builder.cpp │ │ │ ├── fbo_builder.hpp │ │ │ ├── frame_buffer_object.cpp │ │ │ ├── frame_buffer_object.hpp │ │ │ ├── instance_buffer.hpp │ │ │ ├── shader.cpp │ │ │ ├── shader.hpp │ │ │ ├── shader_builder.cpp │ │ │ ├── shader_builder.hpp │ │ │ ├── spritesheet.hpp │ │ │ ├── texture.cpp │ │ │ ├── texture.hpp │ │ │ ├── texture_loader.cpp │ │ │ ├── texture_loader.hpp │ │ │ ├── vertex_array_object.cpp │ │ │ └── vertex_array_object.hpp │ └── test │ │ ├── CMakeLists.txt │ │ └── fbo_test.cpp ├── opengl_renderer │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ ├── opengl │ │ │ ├── bloom.cpp │ │ │ ├── bloom.hpp │ │ │ ├── camera_3d.cpp │ │ │ ├── camera_3d.hpp │ │ │ ├── components │ │ │ │ └── lite_particles2d.hpp │ │ │ ├── lite_particles2d_type.hpp │ │ │ ├── lite_particles2d_type_loader.cpp │ │ │ ├── lite_particles2d_type_loader.hpp │ │ │ ├── render_task.hpp │ │ │ ├── render_tasks │ │ │ │ ├── batched_spritesheet.cpp │ │ │ │ ├── batched_spritesheet.hpp │ │ │ │ ├── blit_fb.cpp │ │ │ │ ├── blit_fb.hpp │ │ │ │ ├── bloom_combine.cpp │ │ │ │ ├── bloom_combine.hpp │ │ │ │ ├── bloom_extraction.cpp │ │ │ │ ├── bloom_extraction.hpp │ │ │ │ ├── blur.cpp │ │ │ │ ├── blur.hpp │ │ │ │ ├── clear.cpp │ │ │ │ ├── clear.hpp │ │ │ │ ├── composition.cpp │ │ │ │ ├── composition.hpp │ │ │ │ ├── copy_to_fb.cpp │ │ │ │ ├── copy_to_fb.hpp │ │ │ │ ├── fast_sky_render_task.cpp │ │ │ │ ├── fast_sky_render_task.hpp │ │ │ │ ├── imgui.cpp │ │ │ │ ├── imgui.hpp │ │ │ │ ├── lite_particles2d.cpp │ │ │ │ ├── lite_particles2d.hpp │ │ │ │ ├── simple_rect.cpp │ │ │ │ ├── simple_rect.hpp │ │ │ │ ├── simple_sprite.cpp │ │ │ │ ├── simple_sprite.hpp │ │ │ │ ├── simple_spritesheet.cpp │ │ │ │ ├── simple_spritesheet.hpp │ │ │ │ ├── spritesheet_renderable.hpp │ │ │ │ ├── tilemap.cpp │ │ │ │ ├── tilemap.hpp │ │ │ │ └── tilemap_renderable.hpp │ │ │ └── res │ │ │ │ ├── default_texture.h │ │ │ │ ├── errig_texture.h │ │ │ │ ├── shaders_builtin.cpp │ │ │ │ └── shaders_builtin.hpp │ │ │ └── services │ │ │ ├── opengl_renderer.cpp │ │ │ ├── opengl_renderer.hpp │ │ │ ├── opengl_renderer_tools.cpp │ │ │ └── opengl_renderer_tools.hpp │ └── test │ │ ├── CMakeLists.txt │ │ ├── batched_spritesheet_render_task_test.cpp │ │ ├── blur_render_task_test.cpp │ │ ├── builtins.cpp │ │ ├── fast_sky_render_task_test.cpp │ │ ├── hdr_bloom_pipeline_example.cpp │ │ ├── imgui_render_task_test.cpp │ │ ├── lite_particles2d.cpp │ │ ├── opengl_renderer_s_test.cpp │ │ ├── res │ │ ├── animation_running-1_ea_0.3.png │ │ ├── animation_standing-1_ea_0.1.png │ │ ├── errig.jpg │ │ ├── test.png │ │ ├── textures.zip │ │ └── textures.zip.h │ │ ├── simple_rect_render_task_test.cpp │ │ ├── simple_sprite_render_task_test.cpp │ │ ├── simple_spritesheet_render_task_test.cpp │ │ └── tilemap_render_task_test.cpp ├── organizer_scene │ ├── CMakeLists.txt │ └── src │ │ └── mm │ │ └── services │ │ ├── organizer_scene.cpp │ │ └── organizer_scene.hpp ├── random │ ├── CMakeLists.txt │ └── src │ │ └── mm │ │ └── random │ │ ├── srng.cpp │ │ └── srng.hpp ├── resource_manager │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ └── resource_manager.hpp │ └── test │ │ ├── CMakeLists.txt │ │ └── resource_test.cpp ├── s6zer │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ └── s6zer │ │ │ ├── serialize.hpp │ │ │ └── stream.hpp │ └── test │ │ ├── CMakeLists.txt │ │ └── test.cpp ├── screen_director │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ └── services │ │ │ ├── screen_director.cpp │ │ │ └── screen_director.hpp │ └── test │ │ ├── CMakeLists.txt │ │ └── sd_test.cpp ├── sdl_service │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ ├── logo-f6c-square.png.h │ │ │ └── services │ │ │ ├── sdl_service.cpp │ │ │ └── sdl_service.hpp │ └── test │ │ ├── CMakeLists.txt │ │ └── start_test.cpp ├── simple_sdl_renderer │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ ├── services │ │ │ ├── simple_sdl_renderer.cpp │ │ │ └── simple_sdl_renderer.hpp │ │ │ └── simple_sdl_renderer │ │ │ └── target.hpp │ └── test │ │ ├── CMakeLists.txt │ │ └── start_test.cpp ├── sound │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ ├── services │ │ │ ├── sound_service.cpp │ │ │ └── sound_service.hpp │ │ │ ├── soloud_filesystem_file_impl.cpp │ │ │ ├── soloud_filesystem_file_impl.hpp │ │ │ ├── soloud_json.cpp │ │ │ ├── soloud_json.hpp │ │ │ ├── sound_loader_sfxr.cpp │ │ │ ├── sound_loader_sfxr.hpp │ │ │ ├── sound_loader_wav.cpp │ │ │ └── sound_loader_wav.hpp │ └── test │ │ ├── CMakeLists.txt │ │ ├── file_test.cpp │ │ ├── loader_test.cpp │ │ ├── res │ │ ├── erik_gun_fx_1.zip │ │ └── erik_gun_fx_1.zip.h │ │ └── start_test.cpp ├── std_utils │ ├── CMakeLists.txt │ ├── src │ │ └── mm │ │ │ ├── permutation.hpp │ │ │ ├── scalar_range2.hpp │ │ │ ├── serialize │ │ │ └── json_scalar_range2.hpp │ │ │ └── string_view_split.hpp │ └── test │ │ ├── CMakeLists.txt │ │ ├── scalar_range2_json_test.cpp │ │ └── scalar_range2_test.cpp └── tilemap │ ├── CMakeLists.txt │ └── src │ └── mm │ ├── tilemap.cpp │ └── tilemap.hpp ├── mm_options_and_defines.cmake ├── res ├── mm2.ico ├── mm_card.png └── mush_machine_logo_1.svg ├── screens ├── CMakeLists.txt └── mm_logo │ ├── CMakeLists.txt │ ├── res │ └── mush_machine_logo_1.svg.png.h │ └── src │ └── mm │ └── screens │ ├── mm_logo_screen.cpp │ └── mm_logo_screen.hpp └── systems ├── CMakeLists.txt ├── fast_sky_sun ├── CMakeLists.txt └── src │ └── mm │ └── systems │ ├── fast_sky_sun_system.cpp │ └── fast_sky_sun_system.hpp ├── player_velocity ├── CMakeLists.txt ├── src │ └── mm │ │ └── systems │ │ ├── player_velocity2d_system.cpp │ │ └── player_velocity2d_system.hpp └── test │ ├── CMakeLists.txt │ └── player_velocity_test.cpp ├── simple_velocity ├── CMakeLists.txt ├── src │ └── mm │ │ └── systems │ │ ├── simple_velocity_system2d.cpp │ │ └── simple_velocity_system2d.hpp └── test │ ├── CMakeLists.txt │ └── simple_velocity_test.cpp └── transform ├── CMakeLists.txt └── src └── mm └── systems ├── transform.cpp └── transform.hpp /.github/workflows/x/dummy-1920x1080.conf: -------------------------------------------------------------------------------- 1 | # https://wiki.archlinux.org/title/Xorg 2 | Section "Monitor" 3 | Identifier "dummy_monitor" 4 | HorizSync 28.0-80.0 5 | VertRefresh 48.0-75.0 6 | Modeline "1920x1080" 172.80 1920 2040 2248 2576 1080 1081 1084 1118 7 | EndSection 8 | 9 | Section "Device" 10 | Identifier "dummy_card" 11 | VideoRam 256000 12 | Driver "dummy" 13 | EndSection 14 | 15 | Section "Screen" 16 | Identifier "dummy_screen" 17 | Device "dummy_card" 18 | Monitor "dummy_monitor" 19 | SubSection "Display" 20 | EndSubSection 21 | EndSection 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | *.o 3 | *.swp 4 | ~* 5 | *~ 6 | .idea/ 7 | cmake-build-debug/ 8 | cmake-build-debugandtest/ 9 | cmake-build-release/ 10 | *.stackdump 11 | *.coredump 12 | compile_commands.json 13 | /build* 14 | .clangd 15 | .cache 16 | 17 | .DS_Store 18 | .AppleDouble 19 | .LSOverride 20 | 21 | CMakeLists.txt.user* 22 | CMakeCache.txt 23 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "external/entt"] 2 | path = external/entt 3 | url = https://github.com/skypjack/entt.git 4 | shallow = true 5 | [submodule "external/glm"] 6 | path = external/glm 7 | url = https://github.com/g-truc/glm.git 8 | shallow = true 9 | [submodule "external/googletest"] 10 | path = external/googletest 11 | url = https://github.com/google/googletest.git 12 | [submodule "external/IconFontCppHeaders"] 13 | path = external/IconFontCppHeaders 14 | url = https://github.com/juliettef/IconFontCppHeaders.git 15 | [submodule "external/imgui/imgui"] 16 | path = external/imgui/imgui 17 | url = https://github.com/ocornut/imgui.git 18 | shallow = true 19 | [submodule "external/soloud/soloud"] 20 | path = external/soloud/soloud 21 | url = https://github.com/jarikomppa/soloud.git 22 | [submodule "external/spdlog"] 23 | path = external/spdlog 24 | url = https://github.com/gabime/spdlog.git 25 | shallow = true 26 | [submodule "external/stb/stb"] 27 | path = external/stb/stb 28 | url = https://github.com/nothings/stb.git 29 | [submodule "external/tracy/tracy"] 30 | path = external/tracy/tracy 31 | url = https://github.com/wolfpld/tracy.git 32 | shallow = true 33 | [submodule "external/physfs/physfs"] 34 | path = external/physfs/physfs 35 | url = https://github.com/icculus/physfs.git 36 | branch = main 37 | -------------------------------------------------------------------------------- /.vimspector.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": { 3 | "run_ctest_native": { 4 | "default": true, 5 | "adapter": "CodeLLDB", 6 | "configuration": { 7 | "request": "launch", 8 | "stopOnEntry": true, 9 | "console": "integratedTerminal", 10 | "program": "ctest", 11 | "cwd": "${workspaceRoot}/build" 12 | } 13 | }, 14 | "run_native": { 15 | "adapter": "CodeLLDB", 16 | "variables": { 17 | "Executable": "s6zer_test" 18 | }, 19 | "configuration": { 20 | "request": "launch", 21 | "stopOnEntry": true, 22 | "console": "integratedTerminal", 23 | "program": "${workspaceRoot}/build/bin/${Executable}", 24 | "cwd": "${workspaceRoot}/build" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The Code is under the following License, if not stated otherwise: 2 | 3 | MIT License 4 | 5 | Copyright (c) 2018-2019 Felix Richter 6 | Copyright (c) 2018-2022 Erik Scholz 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -------------------------------------------------------------------------------- /docs/framework/common_components/common_components.md: -------------------------------------------------------------------------------- 1 | (draft) 2 | # Common Components 3 | 4 | This is a collection of commonly used (ECS) `Components`. 5 | 6 | Json serialization is provided for all `Components`. 7 | 8 | ## Name 9 | 10 | Contains a string. For debugging. 11 | 12 | It's special, since the entity widget will try to get the Name and display it in `ImGui`. 13 | 14 | ## Transform 15 | 16 | Contians Positon, Rotation and Scale. 17 | 2D and 3D variants. 18 | 19 | Might get replaced with a Unity3D style transform system... 20 | 21 | ## Velocity 22 | 23 | Contians Velocity(Position and Rotation). 24 | 2D and 3D variants. 25 | 26 | ## View_Dir 27 | 28 | In almost every Project I had the need for this `Component`, so it's here. 29 | 2D and 3D variants. 30 | 31 | 32 | ## Color 33 | 34 | I use this a lot. I probably shouldn't. 35 | Hase 4 color channels. 36 | 37 | -------------------------------------------------------------------------------- /docs/framework/engine/interfaces.md: -------------------------------------------------------------------------------- 1 | # Default Shipped Interfaces 2 | 3 | ### Index 4 | 5 | * `MM::Services::SceneServiceInterface` 6 | 7 | 8 | ## SceneServiceInterface 9 | 10 | Not very stable. But I use it all over the place. 11 | 12 | It uses [`EnTT`](https://github.com/skypjack/entt). 13 | 14 | ### interface 15 | 16 | Use `.getScene()` to get current `MM::Scene`. 17 | 18 | Use `.changeScene(newScene)` to queue `.changeSceneNow(newScene)`. 19 | 20 | Use `.changeSceneNow(newScene)` to change currently held `MM::Scene`. 21 | 22 | Use `.addSystemToScene(fn)` to add a `MM::System` to the `MM::Scene`. 23 | 24 | -------------------------------------------------------------------------------- /docs/framework/engine/services.md: -------------------------------------------------------------------------------- 1 | # Services 2 | 3 | `MM::Service`s are the Components that get added to the `MM::Engine`. 4 | 5 | They need to extend `MM::Service` (included in ``) and implement the following Interface: 6 | 7 | * Destructor (since it is virtual) 8 | * `bool enable(MM::Engine& engine)` 9 | * `void disable(MM::Engine& engine)` 10 | 11 | and optionally 12 | 13 | * `const char* name(void)` 14 | 15 | Not implementing `name()` does not impact functionality, but it is not good practise. 16 | 17 | Update and FixedUpdate callbacks should only be added in `enable()` and should be removed in `disable()`. 18 | 19 | -------------------------------------------------------------------------------- /docs/framework/filesystem/filesystem.md: -------------------------------------------------------------------------------- 1 | (draft) 2 | # Filesystem 3 | 4 | Provides a Virtual Filesystem. Implemented using [PhysFS](https://icculus.org/physfs/). 5 | 6 | # Usage 7 | 8 | -------------------------------------------------------------------------------- /docs/framework/logger/logger.md: -------------------------------------------------------------------------------- 1 | # Logger 2 | 3 | The Logger is the [`spdlog`](https://github.com/gabime/spdlog) logging library, with some extras. Like a `Sink` for [`Tracy`](https://github.com/wolfpld/tracy) the Profiler. 4 | 5 | # Usage 6 | 7 | Each "Section" is ment to have its own "Logger". 8 | 9 | To Initialize a section logger with its `sink`s, do `MM::Logger::initSectionLogger("MySection");`. 10 | Can be placed in the `.enable()` or even the Constructor of your `Service`s. 11 | 12 | ```cpp 13 | #include // include logger 14 | 15 | // here are the macros 16 | #define LOG_CRIT(...) __LOG_CRIT( "MySection", __VA_ARGS__) 17 | #define LOG_ERROR(...) __LOG_ERROR("MySection", __VA_ARGS__) 18 | #define LOG_WARN(...) __LOG_WARN( "MySection", __VA_ARGS__) 19 | #define LOG_INFO(...) __LOG_INFO( "MySection", __VA_ARGS__) 20 | #define LOG_DEBUG(...) __LOG_DEBUG("MySection", __VA_ARGS__) 21 | #define LOG_TRACE(...) __LOG_TRACE("MySection", __VA_ARGS__) 22 | 23 | // code goes here ...... 24 | 25 | // only if in header 26 | //#undef LOG_CRIT 27 | //#undef LOG_ERROR 28 | //#undef LOG_WARN 29 | //#undef LOG_INFO 30 | //#undef LOG_DEBUG 31 | //#undef LOG_TRACE 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /docs/framework/opengl_primitives/opengl_primitives.md: -------------------------------------------------------------------------------- 1 | (draft) 2 | ## OpenGL Primitives 3 | 4 | Mostly Classes wrapping the OpenGL library. 5 | 6 | -------------------------------------------------------------------------------- /docs/framework/opengl_renderer/opengl_renderer.md: -------------------------------------------------------------------------------- 1 | (draft) 2 | # OpenGL Renderer 3 | 4 | This is a "Renderer" implementation. It hosts a `OpenGL::RenderTask` list, which get executed in order. 5 | 6 | For `OpenGL::RenderTask`s see the [render_tasks folder](render_tasks/). 7 | 8 | -------------------------------------------------------------------------------- /docs/framework/opengl_renderer/render_tasks/blit_fb.md: -------------------------------------------------------------------------------- 1 | # `OpenGL::RenderTask` Blit FB 2 | 3 | This `RenderTask` Blits(copys) the contents of one `FrameBuffer` to another. 4 | 5 | There are options available for source and destination rectangle, color flags and filter mode. 6 | 7 | -------------------------------------------------------------------------------- /docs/framework/opengl_renderer/render_tasks/clear.md: -------------------------------------------------------------------------------- 1 | # `OpenGL::RenderTask` Clear 2 | 3 | This `RenderTask` calles glClear(). 4 | 5 | There are options available for clear color and color mask. 6 | 7 | -------------------------------------------------------------------------------- /docs/framework/opengl_renderer/render_tasks/imgui.md: -------------------------------------------------------------------------------- 1 | # `OpenGL::RenderTask` ImGuiRT 2 | 3 | This `RenderTask` renders the ImGui render data. 4 | 5 | -------------------------------------------------------------------------------- /docs/framework/resource_manager/resource_manager.md: -------------------------------------------------------------------------------- 1 | (draft) 2 | # Resource Manager 3 | 4 | This is nothing more than a glorified Singelton and will be replace in the future. 5 | 6 | Based on https://github.com/skypjack/entt/blob/master/src/entt/resource/cache.hpp. 7 | 8 | -------------------------------------------------------------------------------- /docs/framework/screen_director/screen_director.md: -------------------------------------------------------------------------------- 1 | # Screen Director 2 | 3 | Orchistrates `Screen`s. 4 | 5 | The `Screen Director` lets you define "States"(`Screen`s) which activate/deactivate `MM::Service`s on Entering and Leaving the `Screen`. 6 | 7 | # Usage 8 | 9 | The current implementation is very open and does not really use encapsulation ... 10 | 11 | ## Adding `Screen`s 12 | 13 | Due to the open nature of this implementation, one does access members directly: 14 | ``` 15 | auto& my_screen = screen_director.screens["my_screen"]; 16 | 17 | // filling in start_disable, start_enable, start_provide, end_disable and end_enable 18 | // and optionally start_fn and end_fn which are called upon entering and leaving the screen. 19 | my_screen.start_enable.push_back(engine.type()); 20 | // [...] 21 | ``` 22 | 23 | ## Changing to a Screen 24 | 25 | Changing to a `Screen` can either be done on call with `.changeScreenTo(engine, "my_screen_id")` or qued via `.queueChangeScreenTo("my_screen")`. The former should only be used when the `Engine` is not running or in a `fixedDeferUpdate`. 26 | 27 | ## Service Enablement 28 | 29 | Enabling the ScreenDirector causes a queued `Screen` to be started. 30 | 31 | 32 | -------------------------------------------------------------------------------- /docs/framework/sdl_service/sdl_service.md: -------------------------------------------------------------------------------- 1 | (draft) 2 | ## SDL Service 3 | 4 | This is a `Service` which manages Windows, OpenGL Contexts and Events. 5 | 6 | The current implementation limits it to one Window and OpenGL Context. 7 | 8 | Support for Vulkan is planned. 9 | 10 | -------------------------------------------------------------------------------- /docs/framework/simple_scene/simple_scene.md: -------------------------------------------------------------------------------- 1 | (draft) 2 | # Simple Scene 3 | 4 | This is a simple `MM::SceneServiceInterface` implementation. 5 | 6 | -------------------------------------------------------------------------------- /docs/terminology.md: -------------------------------------------------------------------------------- 1 | # Terminology 2 | 3 | ### Engine 4 | is defined as [`MM::Engine`](framework/engine/engine.md). 5 | 6 | ### Service 7 | is defined as [`MM::Services::Service`](framework/engine/services.md), the Service's base class, which was previously known as `ServiceSystem` and `SubSystem`. 8 | 9 | ### Scene 10 | is defined as a ECS-style EnTT::registry. It contains Entities, Components and Systems. 11 | 12 | ### Entity 13 | is defined as a ECS Entity, see [`EnTT`](https://github.com/skypjack/entt). 14 | 15 | ### System 16 | is defined as a ECS-style System. In this case, it's a free function. 17 | 18 | ### Screen 19 | is defined as a State of enabled and disabled `Service`s. (see [`ScreenDirector`](framework/screen_director/screen_director.md)) 20 | 21 | -------------------------------------------------------------------------------- /external/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | # external libs 4 | 5 | if (BUILD_TESTING) 6 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 7 | add_subdirectory("googletest") 8 | endif() 9 | 10 | add_subdirectory("spdlog") 11 | 12 | #include("${CMAKE_CURRENT_SOURCE_DIR}/tracy.cmake") 13 | add_subdirectory("tracy") 14 | 15 | include("${CMAKE_CURRENT_SOURCE_DIR}/entt.cmake") 16 | include("${CMAKE_CURRENT_SOURCE_DIR}/glm.cmake") 17 | 18 | add_subdirectory("SquirrelNoise") 19 | 20 | set(JSON_BuildTests OFF CACHE INTERNAL "") 21 | set(JSON_MultipleHeaders ON CACHE INTERNAL "") 22 | add_subdirectory("json") # link with "nlohmann_json::nlohmann_json" 23 | 24 | add_subdirectory("physfs") 25 | 26 | if(NOT MM_HEADLESS) 27 | if(NOT EMSCRIPTEN) 28 | # TODO: move into imgui and soload, since they are the one requireing this 29 | if(VCPKG_TARGET_TRIPLET) 30 | find_package(SDL2 CONFIG REQUIRED) 31 | else() # HACK: fix sdl find module 32 | find_package(SDL2 REQUIRED) 33 | endif() 34 | endif() 35 | 36 | if(NOT MM_OPENGL_3_GLES) 37 | # opengl3 loader 38 | add_subdirectory("glad-debug") 39 | endif() 40 | 41 | # stb utilies 42 | add_subdirectory("stb") 43 | 44 | # nice symbol font integration 45 | include("${CMAKE_CURRENT_SOURCE_DIR}/icon_font_cpp_headers.cmake") 46 | 47 | # (debug) gui 48 | add_subdirectory("imgui") 49 | 50 | # sound, uses sdl2-static backend 51 | add_subdirectory("soloud") 52 | endif() 53 | 54 | 55 | -------------------------------------------------------------------------------- /external/SquirrelNoise/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(SquirrelNoise) 4 | 5 | add_library(squirrel_noise 6 | ./src/squirrel_noise/RawNoise.hpp 7 | ./src/squirrel_noise/RawNoise.cpp 8 | 9 | # TODO: seperate smooth? 10 | ./src/squirrel_noise/SmoothNoise.hpp 11 | ./src/squirrel_noise/SmoothNoise.cpp 12 | ) 13 | 14 | target_include_directories(squirrel_noise PUBLIC "src") 15 | 16 | target_link_libraries(squirrel_noise 17 | PRIVATE glm 18 | ) 19 | 20 | -------------------------------------------------------------------------------- /external/SquirrelNoise/src/squirrel_noise/RawNoise.cpp: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------------------------- 2 | // RawNoise.cpp 3 | // 4 | #include "./RawNoise.hpp" 5 | 6 | namespace SquirrelNoise4 { 7 | 8 | //----------------------------------------------------------------------------------------------- 9 | // Fast hash of an int32 into a different (unrecognizable) uint32. 10 | // 11 | // Returns an uint32_t containing 32 reasonably-well-scrambled bits, based on the hash 12 | // of a given (signed) integer input parameter (position/index) and [optional] seed. Kind of 13 | // like looking up a value in an infinitely large table of previously generated random numbers. 14 | // 15 | // The bit-noise constants and bit-shifts were evolved by a genetic algorithm using the 16 | // "BigCrush" test for fitness, and have so far produced excellent test results. 17 | // 18 | // I call this particular approach SquirrelNoise (version 4). 19 | // 20 | uint32_t Get1dNoiseUint32( int32_t positionX, uint32_t seed ) { 21 | const uint32_t BIT_NOISE1 = 0xD2A80A23; // 0b1101'0010'1010'1000'0000'1010'0010'0011; 22 | const uint32_t BIT_NOISE2 = 0xA884F197; // 0b1010'1000'1000'0100'1111'0001'1001'0111; 23 | const uint32_t BIT_NOISE3 = 0x1B56C4E9; // 0b0001'1011'0101'0110'1100'0100'1110'1001; 24 | 25 | uint32_t mangledBits = (uint32_t) positionX; 26 | mangledBits *= BIT_NOISE1; 27 | mangledBits += seed; 28 | mangledBits ^= (mangledBits >> 7); 29 | mangledBits += BIT_NOISE2; 30 | mangledBits ^= (mangledBits >> 8); 31 | mangledBits *= BIT_NOISE3; 32 | mangledBits ^= (mangledBits >> 11); 33 | return mangledBits; 34 | } 35 | 36 | } // SquirrelNoise4 37 | 38 | -------------------------------------------------------------------------------- /external/entt.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | add_library(entt INTERFACE) 3 | target_include_directories(entt INTERFACE "${CMAKE_CURRENT_LIST_DIR}/entt/src") 4 | target_compile_features(entt INTERFACE cxx_std_17) 5 | 6 | -------------------------------------------------------------------------------- /external/glad-debug/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9 FATAL_ERROR) 2 | 3 | project(glad C) 4 | 5 | set(C_FILES 6 | "src/glad.c" 7 | ) 8 | 9 | set(H_FILES 10 | "include/glad/glad.h" 11 | "include/KHR/khrplatform.h" 12 | ) 13 | 14 | add_library(glad ${C_FILES} ${H_FILES}) 15 | 16 | target_include_directories(glad PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") 17 | 18 | if(UNIX) 19 | target_link_libraries(glad dl) 20 | endif() 21 | 22 | -------------------------------------------------------------------------------- /external/glm.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | add_library(glm INTERFACE) 4 | target_include_directories(glm INTERFACE "${CMAKE_CURRENT_LIST_DIR}/glm") 5 | target_compile_definitions(glm INTERFACE GLM_ENABLE_EXPERIMENTAL) 6 | 7 | -------------------------------------------------------------------------------- /external/icon_font_cpp_headers.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | add_library(icon_font_cpp_headers INTERFACE) 3 | target_include_directories(icon_font_cpp_headers INTERFACE "${CMAKE_CURRENT_LIST_DIR}/IconFontCppHeaders/") 4 | 5 | -------------------------------------------------------------------------------- /external/imgui/imgui_plot_var.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imgui/imgui.h" 4 | 5 | // USAGE 6 | // Call once a frame with current value 7 | // ImGui::PlotVar("Speed", current_speed); 8 | 9 | namespace ImGui { 10 | 11 | // Plot value over time 12 | // Pass FLT_MAX value to draw without adding a new value 13 | void PlotVar(const char* label, float value, float scale_min = FLT_MAX, float scale_max = FLT_MAX, int buffer_size = 120); 14 | 15 | // Call this periodically to discard old/unused data 16 | void PlotVarFlushOldEntries(); 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /external/json/LICENSE.MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2013-2025 Niels Lohmann 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /external/json/cmake/config.cmake.in: -------------------------------------------------------------------------------- 1 | include(FindPackageHandleStandardArgs) 2 | set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE}) 3 | find_package_handle_standard_args(@PROJECT_NAME@ CONFIG_MODE) 4 | 5 | if(NOT TARGET @PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@) 6 | include("${CMAKE_CURRENT_LIST_DIR}/@NLOHMANN_JSON_TARGETS_EXPORT_NAME@.cmake") 7 | if((NOT TARGET @NLOHMANN_JSON_TARGET_NAME@) AND 8 | (NOT @PROJECT_NAME@_FIND_VERSION OR 9 | @PROJECT_NAME@_FIND_VERSION VERSION_LESS 3.2.0)) 10 | add_library(@NLOHMANN_JSON_TARGET_NAME@ INTERFACE IMPORTED) 11 | set_target_properties(@NLOHMANN_JSON_TARGET_NAME@ PROPERTIES 12 | INTERFACE_LINK_LIBRARIES @PROJECT_NAME@::@NLOHMANN_JSON_TARGET_NAME@ 13 | ) 14 | endif() 15 | endif() 16 | -------------------------------------------------------------------------------- /external/json/cmake/nlohmann_jsonConfigVersion.cmake.in: -------------------------------------------------------------------------------- 1 | # This is essentially cmake's BasicConfigVersion-SameMajorVersion.cmake.in but 2 | # without the 32/64-bit check. Since json is a header-only library, it doesn't 3 | # matter if it was built on a different platform than what it is used on (see 4 | # https://github.com/nlohmann/json/issues/1697). 5 | set(PACKAGE_VERSION "@PROJECT_VERSION@") 6 | 7 | if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) 8 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 9 | else() 10 | 11 | if(PACKAGE_FIND_VERSION_MAJOR STREQUAL "@PROJECT_VERSION_MAJOR@") 12 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 13 | else() 14 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 15 | endif() 16 | 17 | if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) 18 | set(PACKAGE_VERSION_EXACT TRUE) 19 | endif() 20 | endif() 21 | -------------------------------------------------------------------------------- /external/json/cmake/pkg-config.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 3 | 4 | Name: @PROJECT_NAME@ 5 | Description: JSON for Modern C++ 6 | Version: @PROJECT_VERSION@ 7 | Cflags: -I${includedir} 8 | -------------------------------------------------------------------------------- /external/json/include/nlohmann/detail/input/position_t.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.12.0 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include // size_t 12 | 13 | #include 14 | 15 | NLOHMANN_JSON_NAMESPACE_BEGIN 16 | namespace detail 17 | { 18 | 19 | /// struct to capture the start position of the current token 20 | struct position_t 21 | { 22 | /// the total number of characters read 23 | std::size_t chars_read_total = 0; 24 | /// the number of characters read in the current line 25 | std::size_t chars_read_current_line = 0; 26 | /// the number of lines read 27 | std::size_t lines_read = 0; 28 | 29 | /// conversion to size_t to preserve SAX interface 30 | constexpr operator size_t() const 31 | { 32 | return chars_read_total; 33 | } 34 | }; 35 | 36 | } // namespace detail 37 | NLOHMANN_JSON_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /external/json/include/nlohmann/detail/iterators/internal_iterator.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.12.0 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | NLOHMANN_JSON_NAMESPACE_BEGIN 15 | namespace detail 16 | { 17 | 18 | /*! 19 | @brief an iterator value 20 | 21 | @note This structure could easily be a union, but MSVC currently does not allow 22 | unions members with complex constructors, see https://github.com/nlohmann/json/pull/105. 23 | */ 24 | template struct internal_iterator 25 | { 26 | /// iterator for JSON objects 27 | typename BasicJsonType::object_t::iterator object_iterator {}; 28 | /// iterator for JSON arrays 29 | typename BasicJsonType::array_t::iterator array_iterator {}; 30 | /// generic iterator for all other types 31 | primitive_iterator_t primitive_iterator {}; 32 | }; 33 | 34 | } // namespace detail 35 | NLOHMANN_JSON_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /external/json/include/nlohmann/detail/json_custom_base_class.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.12.0 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include // conditional, is_same 12 | 13 | #include 14 | 15 | NLOHMANN_JSON_NAMESPACE_BEGIN 16 | namespace detail 17 | { 18 | 19 | /*! 20 | @brief Default base class of the @ref basic_json class. 21 | 22 | So that the correct implementations of the copy / move ctors / assign operators 23 | of @ref basic_json do not require complex case distinctions 24 | (no base class / custom base class used as customization point), 25 | @ref basic_json always has a base class. 26 | By default, this class is used because it is empty and thus has no effect 27 | on the behavior of @ref basic_json. 28 | */ 29 | struct json_default_base {}; 30 | 31 | template 32 | using json_base_class = typename std::conditional < 33 | std::is_same::value, 34 | json_default_base, 35 | T 36 | >::type; 37 | 38 | } // namespace detail 39 | NLOHMANN_JSON_NAMESPACE_END 40 | -------------------------------------------------------------------------------- /external/json/include/nlohmann/detail/macro_unscope.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.12.0 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | // restore clang diagnostic settings 12 | #if defined(__clang__) 13 | #pragma clang diagnostic pop 14 | #endif 15 | 16 | // clean up 17 | #undef JSON_ASSERT 18 | #undef JSON_INTERNAL_CATCH 19 | #undef JSON_THROW 20 | #undef JSON_PRIVATE_UNLESS_TESTED 21 | #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION 22 | #undef NLOHMANN_BASIC_JSON_TPL 23 | #undef JSON_EXPLICIT 24 | #undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL 25 | #undef JSON_INLINE_VARIABLE 26 | #undef JSON_NO_UNIQUE_ADDRESS 27 | #undef JSON_DISABLE_ENUM_SERIALIZATION 28 | #undef JSON_USE_GLOBAL_UDLS 29 | 30 | #ifndef JSON_TEST_KEEP_MACROS 31 | #undef JSON_CATCH 32 | #undef JSON_TRY 33 | #undef JSON_HAS_CPP_11 34 | #undef JSON_HAS_CPP_14 35 | #undef JSON_HAS_CPP_17 36 | #undef JSON_HAS_CPP_20 37 | #undef JSON_HAS_CPP_23 38 | #undef JSON_HAS_FILESYSTEM 39 | #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM 40 | #undef JSON_HAS_THREE_WAY_COMPARISON 41 | #undef JSON_HAS_RANGES 42 | #undef JSON_HAS_STATIC_RTTI 43 | #undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 44 | #endif 45 | 46 | #include 47 | -------------------------------------------------------------------------------- /external/json/include/nlohmann/detail/meta/call_std/begin.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.12.0 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | 15 | NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); 16 | 17 | NLOHMANN_JSON_NAMESPACE_END 18 | -------------------------------------------------------------------------------- /external/json/include/nlohmann/detail/meta/call_std/end.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.12.0 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | 15 | NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); 16 | 17 | NLOHMANN_JSON_NAMESPACE_END 18 | -------------------------------------------------------------------------------- /external/json/include/nlohmann/detail/meta/identity_tag.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.12.0 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | namespace detail 15 | { 16 | 17 | // dispatching helper struct 18 | template struct identity_tag {}; 19 | 20 | } // namespace detail 21 | NLOHMANN_JSON_NAMESPACE_END 22 | -------------------------------------------------------------------------------- /external/json/include/nlohmann/detail/meta/std_fs.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.12.0 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | #if JSON_HAS_EXPERIMENTAL_FILESYSTEM 14 | #include 15 | NLOHMANN_JSON_NAMESPACE_BEGIN 16 | namespace detail 17 | { 18 | namespace std_fs = std::experimental::filesystem; 19 | } // namespace detail 20 | NLOHMANN_JSON_NAMESPACE_END 21 | #elif JSON_HAS_FILESYSTEM 22 | #include // NOLINT(build/c++17) 23 | NLOHMANN_JSON_NAMESPACE_BEGIN 24 | namespace detail 25 | { 26 | namespace std_fs = std::filesystem; 27 | } // namespace detail 28 | NLOHMANN_JSON_NAMESPACE_END 29 | #endif 30 | -------------------------------------------------------------------------------- /external/json/include/nlohmann/detail/meta/void_t.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.12.0 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include 12 | 13 | NLOHMANN_JSON_NAMESPACE_BEGIN 14 | namespace detail 15 | { 16 | 17 | template struct make_void 18 | { 19 | using type = void; 20 | }; 21 | template using void_t = typename make_void::type; 22 | 23 | } // namespace detail 24 | NLOHMANN_JSON_NAMESPACE_END 25 | -------------------------------------------------------------------------------- /external/json/include/nlohmann/detail/string_utils.hpp: -------------------------------------------------------------------------------- 1 | // __ _____ _____ _____ 2 | // __| | __| | | | JSON for Modern C++ 3 | // | | |__ | | | | | | version 3.12.0 4 | // |_____|_____|_____|_|___| https://github.com/nlohmann/json 5 | // 6 | // SPDX-FileCopyrightText: 2013 - 2025 Niels Lohmann 7 | // SPDX-License-Identifier: MIT 8 | 9 | #pragma once 10 | 11 | #include // size_t 12 | #include // string, to_string 13 | 14 | #include 15 | 16 | NLOHMANN_JSON_NAMESPACE_BEGIN 17 | namespace detail 18 | { 19 | 20 | template 21 | void int_to_string(StringType& target, std::size_t value) 22 | { 23 | // For ADL 24 | using std::to_string; 25 | target = to_string(value); 26 | } 27 | 28 | template 29 | StringType to_string(std::size_t value) 30 | { 31 | StringType result; 32 | int_to_string(result, value); 33 | return result; 34 | } 35 | 36 | } // namespace detail 37 | NLOHMANN_JSON_NAMESPACE_END 38 | -------------------------------------------------------------------------------- /external/json/meson.build: -------------------------------------------------------------------------------- 1 | project('nlohmann_json', 2 | 'cpp', 3 | version : '3.11.2', 4 | license : 'MIT', 5 | ) 6 | 7 | nlohmann_json_dep = declare_dependency( 8 | include_directories: include_directories('single_include') 9 | ) 10 | 11 | nlohmann_json_multiple_headers = declare_dependency( 12 | include_directories: include_directories('include') 13 | ) 14 | 15 | if not meson.is_subproject() 16 | install_headers('single_include/nlohmann/json.hpp', subdir: 'nlohmann') 17 | install_headers('single_include/nlohmann/json_fwd.hpp', subdir: 'nlohmann') 18 | 19 | pkgc = import('pkgconfig') 20 | pkgc.generate(name: 'nlohmann_json', 21 | version: meson.project_version(), 22 | description: 'JSON for Modern C++' 23 | ) 24 | endif 25 | -------------------------------------------------------------------------------- /external/physfs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | set(PHYSFS_BUILD_SHARED FALSE CACHE INTERNAL "") 4 | set(PHYSFS_BUILD_TEST FALSE CACHE INTERNAL "") 5 | add_subdirectory("physfs") 6 | 7 | -------------------------------------------------------------------------------- /external/stb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(stb CXX) 4 | 5 | add_library(stb INTERFACE) 6 | target_include_directories(stb SYSTEM INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}") 7 | 8 | add_library(stb_image "stb/stb_image.h" "stb_image.cpp") 9 | target_link_libraries(stb_image stb) 10 | 11 | add_library(stb_image_write "stb/stb_image_write.h" "stb_image_write.cpp") 12 | target_link_libraries(stb_image_write stb) 13 | 14 | add_library(stb_perlin "stb/stb_perlin.h" "stb_perlin.cpp") 15 | target_link_libraries(stb_perlin stb) 16 | 17 | add_library(stb_rect_pack "stb/stb_rect_pack.h" "stb_rect_pack.cpp") 18 | target_link_libraries(stb_rect_pack stb) 19 | 20 | -------------------------------------------------------------------------------- /external/stb/stb_image.cpp: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_IMPLEMENTATION 2 | #include "stb/stb_image.h" 3 | 4 | -------------------------------------------------------------------------------- /external/stb/stb_image_write.cpp: -------------------------------------------------------------------------------- 1 | #define STB_IMAGE_WRITE_IMPLEMENTATION 2 | #include "stb/stb_image_write.h" 3 | 4 | -------------------------------------------------------------------------------- /external/stb/stb_perlin.cpp: -------------------------------------------------------------------------------- 1 | #define STB_PERLIN_IMPLEMENTATION 2 | #include "stb/stb_perlin.h" 3 | 4 | -------------------------------------------------------------------------------- /external/stb/stb_rect_pack.cpp: -------------------------------------------------------------------------------- 1 | #define STB_RECT_PACK_IMPLEMENTATION 2 | #include "stb/stb_rect_pack.h" 3 | 4 | -------------------------------------------------------------------------------- /external/tracy/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | if(NOT EMSCRIPTEN) 4 | add_library(tracy_client 5 | "${CMAKE_CURRENT_LIST_DIR}/tracy/public/tracy/Tracy.hpp" 6 | "${CMAKE_CURRENT_LIST_DIR}/tracy/public/tracy/TracyLua.hpp" 7 | "${CMAKE_CURRENT_LIST_DIR}/tracy/public/tracy/TracyVulkan.hpp" 8 | "${CMAKE_CURRENT_LIST_DIR}/tracy/public/tracy/TracyOpenGL.hpp" 9 | 10 | "${CMAKE_CURRENT_LIST_DIR}/tracy/public/TracyClient.cpp" 11 | ) 12 | 13 | option(TRACY_ENABLE "Enable tracy profiling" OFF) 14 | 15 | if(TRACY_ENABLE) 16 | target_compile_definitions(tracy_client PUBLIC TRACY_ENABLE) 17 | #target_compile_definitions(tracy_client PUBLIC TRACY_NO_SYSTEM_TRACING) 18 | message("Enabled TRACY") 19 | endif() 20 | 21 | target_compile_features(tracy_client PUBLIC cxx_std_17) 22 | 23 | target_include_directories(tracy_client PUBLIC "${CMAKE_CURRENT_LIST_DIR}/tracy/public") 24 | 25 | if(UNIX) 26 | target_link_libraries(tracy_client dl) 27 | endif() 28 | 29 | if(WIN32) 30 | target_link_libraries(tracy_client ws2_32 dbghelp) 31 | endif() 32 | else() # EMSCRIPTEN 33 | add_library(tracy_client INTERFACE) 34 | 35 | target_compile_features(tracy_client INTERFACE cxx_std_17) 36 | 37 | target_include_directories(tracy_client INTERFACE "${CMAKE_CURRENT_LIST_DIR}/tracy/public") 38 | endif() 39 | 40 | 41 | -------------------------------------------------------------------------------- /framework/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(framework) 4 | 5 | add_subdirectory(engine) 6 | add_subdirectory(logger) 7 | add_subdirectory(resource_manager) 8 | add_subdirectory(s6zer) 9 | add_subdirectory(common_components) 10 | add_subdirectory(std_utils) 11 | add_subdirectory(random) 12 | add_subdirectory(screen_director) 13 | add_subdirectory(filesystem) 14 | add_subdirectory(organizer_scene) 15 | 16 | if(NOT MM_HEADLESS) 17 | add_subdirectory(sdl_service) 18 | add_subdirectory(simple_sdl_renderer) 19 | add_subdirectory(opengl_primitives) 20 | add_subdirectory(opengl_renderer) 21 | add_subdirectory(imgui) 22 | add_subdirectory(input) 23 | add_subdirectory(sound) 24 | add_subdirectory(tilemap) 25 | endif() 26 | 27 | -------------------------------------------------------------------------------- /framework/common_components/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(common_components CXX) 4 | 5 | add_library(common_components INTERFACE) 6 | 7 | add_library(MM::common_components ALIAS common_components) 8 | 9 | target_include_directories(common_components INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src") 10 | 11 | target_link_libraries(common_components INTERFACE 12 | entt 13 | glm 14 | ) 15 | 16 | ########################## 17 | 18 | add_library(common_components_serialize_s6zer INTERFACE) 19 | 20 | add_library(MM::common_components_serialize_s6zer ALIAS common_components_serialize_s6zer) 21 | 22 | target_include_directories(common_components_serialize_s6zer INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src") 23 | 24 | target_link_libraries(common_components_serialize_s6zer INTERFACE 25 | common_components 26 | s6zer 27 | ) 28 | 29 | ########################## 30 | 31 | add_library(common_components_serialize_json INTERFACE) 32 | 33 | add_library(MM::common_components_serialize_json ALIAS common_components_serialize_json) 34 | 35 | target_include_directories(common_components_serialize_json INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src") 36 | 37 | target_link_libraries(common_components_serialize_json INTERFACE 38 | common_components 39 | nlohmann_json::nlohmann_json 40 | ) 41 | 42 | if(BUILD_TESTING) 43 | add_subdirectory(test) 44 | endif() 45 | 46 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/color.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::Components { 6 | struct Color { 7 | glm::vec4 color {1.f, 1.f, 1.f, 1.f}; 8 | }; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/name.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::Components { 6 | struct Name { 7 | static const size_t max_str_len {64u}; 8 | std::string str; 9 | }; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/position2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::Components { 6 | 7 | struct Position2D { 8 | glm::vec2 pos {0.f, 0.f}; 9 | }; 10 | 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/position2d_zoffset.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MM::Components { 4 | 5 | // used to lift 2D into 3D space. like a z-index in css/svg 6 | struct Position2D_ZOffset { 7 | float z_offset {500.f}; // default camera allows values to be between 0 and 1000 8 | }; 9 | 10 | } // MM::Components 11 | 12 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/position3d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::Components { 6 | 7 | struct Position3D { 8 | glm::vec3 pos {0.f, 0.f, 0.f}; 9 | }; 10 | 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/rotation2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MM::Components { 4 | 5 | struct Rotation2D { 6 | float rot {0.f}; 7 | }; 8 | 9 | } // MM::Components 10 | 11 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/scale2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::Components { 6 | 7 | struct Scale2D { 8 | glm::vec2 scale {1.f, 1.f}; 9 | }; 10 | 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_color.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "./json_glm.hpp" 8 | 9 | namespace MM::Components { 10 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Color, color) 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_glm.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace glm { 11 | 12 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec2, x, y) 13 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec3, x, y, z) 14 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec4, x, y, z, w) 15 | 16 | //NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(mat4x4, [0], y, z, w) 17 | inline void to_json(nlohmann::json& nlohmann_json_j, const mat4x4& nlohmann_json_t) { 18 | // TODO: make 2d array? 19 | nlohmann_json_j = nlohmann::json::array_t{}; 20 | nlohmann_json_j[0] = nlohmann_json_t[0]; 21 | nlohmann_json_j[1] = nlohmann_json_t[1]; 22 | nlohmann_json_j[2] = nlohmann_json_t[2]; 23 | nlohmann_json_j[3] = nlohmann_json_t[3]; 24 | } 25 | inline void from_json(const nlohmann::json& nlohmann_json_j, mat4x4& nlohmann_json_t) { 26 | if (!nlohmann_json_j.is_array()) { 27 | //throw nlohmann::json::type_error::create(0, "", nlohmann_json_j); 28 | assert(false && "expected array"); 29 | return; // TODO: dont fail silently 30 | } 31 | 32 | nlohmann_json_j.at(0).get_to(nlohmann_json_t[0]); 33 | nlohmann_json_j.at(1).get_to(nlohmann_json_t[1]); 34 | nlohmann_json_j.at(2).get_to(nlohmann_json_t[2]); 35 | nlohmann_json_j.at(3).get_to(nlohmann_json_t[3]); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_name.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::Components { 8 | // TODO: manual with str len limit 9 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Name, str) 10 | } // MM::Components 11 | 12 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_position2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "./json_glm.hpp" 8 | 9 | namespace MM::Components { 10 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position2D, pos) 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_position2d_zoffset.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "./json_glm.hpp" 8 | 9 | namespace MM::Components { 10 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position2D_ZOffset, z_offset) 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_position3d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "./json_glm.hpp" 8 | 9 | namespace MM::Components { 10 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position3D, pos) 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_rotation2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "./json_glm.hpp" 8 | 9 | namespace MM::Components { 10 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Rotation2D, rot) 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_scale2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "./json_glm.hpp" 8 | 9 | namespace MM::Components { 10 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Scale2D, scale) 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_transform4x4.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "./json_glm.hpp" 8 | 9 | namespace MM::Components { 10 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Transform4x4, trans) 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_velocity2d_position.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "./json_glm.hpp" 8 | 9 | namespace MM::Components { 10 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DPosition, pos_vel) 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_velocity2d_position_intent.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "./json_glm.hpp" 8 | 9 | namespace MM::Components { 10 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DPositionIntent, intent) 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_velocity2d_rotation.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "./json_glm.hpp" 8 | 9 | namespace MM::Components { 10 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DRotation, rot_vel) 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_view_dir2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::Components { 8 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ViewDir2D, dir) 9 | } // MM::Components 10 | 11 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/json_view_dir3d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::Components { 8 | NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ViewDir3D, yaw, pitch, roll) 9 | } // MM::Components 10 | 11 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/serialize/s6zer_color.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::Components { 8 | 9 | MM_DEFINE_SERIALIZE(Color, 10 | MM_S6ZER_BAIL(stream.serializeFloat(data.color.r)) 11 | MM_S6ZER_BAIL(stream.serializeFloat(data.color.g)) 12 | MM_S6ZER_BAIL(stream.serializeFloat(data.color.b)) 13 | MM_S6ZER_BAIL(stream.serializeFloat(data.color.a)) 14 | ) 15 | 16 | } // MM::Components 17 | 18 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/time_delta.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MM::Components { 4 | 5 | // this is a context-variable / "component-singleton". 6 | // it is used to retirve timing information about the tick. 7 | // it is "read-only" for the systems and filled in by the service 8 | // holding the scene. 9 | struct TimeDelta { 10 | float tickDelta = 1.f/60.f; 11 | 12 | // this is optionally filled in 13 | // it turned out, that sound playback needs the factor 14 | float deltaFactor = 1.f; 15 | }; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/transform4x4.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::Components { 6 | 7 | // tag/flag to track dirty positional data, to reduce computation. 8 | struct DirtyTransformTag {}; 9 | 10 | struct Transform4x4 { 11 | glm::mat4x4 trans {1.f}; 12 | }; 13 | 14 | } // MM::Components 15 | 16 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/velocity2d_position.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::Components { 6 | 7 | struct Velocity2DPosition { 8 | glm::vec2 pos_vel {0.f, 0.f}; 9 | }; 10 | 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/velocity2d_position_intent.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::Components { 6 | 7 | struct Velocity2DPositionIntent { 8 | glm::vec2 intent {0.f, 0.f}; 9 | }; 10 | 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/velocity2d_rotation.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MM::Components { 4 | 5 | struct Velocity2DRotation { 6 | float rot_vel {0.f}; 7 | }; 8 | 9 | } // MM::Components 10 | 11 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/view_dir2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MM::Components { 4 | 5 | struct ViewDir2D { 6 | float dir {0.f}; // rad 7 | }; 8 | 9 | } // MM::Components 10 | 11 | -------------------------------------------------------------------------------- /framework/common_components/src/mm/components/view_dir3d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MM::Components { 4 | 5 | struct ViewDir3D { 6 | float yaw {0.f}; // rad 7 | float pitch {0.f}; // rad 8 | float roll {0.f}; // rad 9 | }; 10 | 11 | } // MM::Components 12 | 13 | -------------------------------------------------------------------------------- /framework/common_components/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(common_component_json_serialization_test 3 | component_json_serialization_test.cpp 4 | ) 5 | 6 | target_include_directories(common_component_json_serialization_test PRIVATE ".") 7 | 8 | target_link_libraries(common_component_json_serialization_test 9 | common_components_serialize_json 10 | 11 | gtest_main 12 | ) 13 | 14 | add_test(NAME common_component_json_serialization_test COMMAND common_component_json_serialization_test) 15 | 16 | ######################################## 17 | 18 | add_executable(common_component_s6zer_serialization_test 19 | component_s6zer_serialization_test.cpp 20 | ) 21 | 22 | target_include_directories(common_component_s6zer_serialization_test PRIVATE ".") 23 | 24 | target_link_libraries(common_component_s6zer_serialization_test 25 | common_components_serialize_s6zer 26 | 27 | gtest_main 28 | ) 29 | 30 | add_test(NAME common_component_s6zer_serialization_test COMMAND common_component_s6zer_serialization_test) 31 | 32 | -------------------------------------------------------------------------------- /framework/engine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(engine CXX) 4 | 5 | add_library(engine 6 | src/mm/engine_fwd.hpp 7 | src/mm/engine.hpp 8 | src/mm/engine.cpp 9 | 10 | src/mm/update_strategies/update_strategy.hpp 11 | src/mm/update_strategies/dummy.hpp 12 | 13 | src/mm/services/service.hpp 14 | 15 | src/mm/update_strategies/sequential_strategy.hpp 16 | src/mm/update_strategies/sequential_strategy.cpp 17 | 18 | src/mm/services/scene_service_interface.hpp 19 | 20 | src/mm/services/net_channeled_interface.hpp 21 | ) 22 | 23 | # find . -type f -exec sed -i 's/simple_scene\/services\/simple_scene_ss.hpp/services\/scene_service_interface.hpp/g' {} \; 24 | 25 | target_include_directories(engine PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 26 | 27 | target_compile_features(engine PUBLIC cxx_std_17) 28 | 29 | target_link_libraries(engine 30 | tracy_client 31 | logger 32 | entt 33 | glm 34 | ) 35 | 36 | if (BUILD_TESTING) 37 | add_subdirectory(test) 38 | endif() 39 | 40 | -------------------------------------------------------------------------------- /framework/engine/src/mm/engine_fwd.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // this is a forwarding header 3 | 4 | #include 5 | 6 | namespace MM { 7 | namespace UpdateStrategies { class UpdateStrategy; } 8 | class Engine; 9 | using Entity = entt::entity; 10 | using Scene = entt::basic_registry; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /framework/engine/src/mm/services/count_down.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::Services { 6 | 7 | // counts X times and stops engine 8 | // useful for automatic testing 9 | class CountDown : public Service { 10 | public: 11 | CountDown(int64_t start) : _counter(start) {} 12 | 13 | const char* name(void) override { return "CountDown"; } 14 | 15 | bool enable(Engine&, std::vector& task_array) override { 16 | // add task 17 | task_array.push_back( 18 | UpdateStrategies::TaskInfo{"CountDown::tick"} 19 | .phase(UpdateStrategies::update_phase_t::POST) 20 | .fn([this](Engine& e) { this->tick(e); }) 21 | ); 22 | 23 | return true; 24 | } 25 | 26 | void disable(Engine&) override {} 27 | 28 | private: 29 | 30 | void tick(Engine& engine) { 31 | _counter--; 32 | if (_counter == 0) { 33 | engine.stop(); 34 | } 35 | } 36 | 37 | private: 38 | int64_t _counter = 0; 39 | 40 | }; 41 | 42 | } // MM::Services 43 | 44 | -------------------------------------------------------------------------------- /framework/engine/src/mm/services/rich_presence_provider_interface.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::Services { 6 | 7 | // provides information for a RichPresenceConsumer 8 | class RichPresenceProviderInterface : public Service { 9 | public: 10 | struct RichPresenceInformation { 11 | std::string app {"mm_app"}; 12 | std::string status {"sleeping..."}; 13 | std::string details {"~.~"}; 14 | }; 15 | 16 | // TODO: do i want this? 17 | //virtual bool infoChanged(void) { return true; } 18 | 19 | // ah yes copy 20 | virtual RichPresenceInformation get(void) = 0; 21 | }; 22 | 23 | } // MM::Services 24 | 25 | -------------------------------------------------------------------------------- /framework/engine/src/mm/services/scene_service_interface.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM { 8 | 9 | using Entity = entt::entity; 10 | using Scene = entt::basic_registry<::MM::Entity>; 11 | using System = std::function; 12 | 13 | } // MM 14 | 15 | namespace MM::Services { 16 | 17 | class SceneServiceInterface : public Service { 18 | public: // Scene stuff 19 | // get current Scene 20 | virtual ::MM::Scene& getScene(void) = 0; 21 | 22 | // enques a new Scene to be put in place 23 | virtual void changeScene(std::unique_ptr<::MM::Scene>&& new_scene) = 0; 24 | 25 | // sets the new Scene to be provided. 26 | // dont use, except for when you know what you are doing! 27 | // be carefull of that one (lol) 28 | virtual void changeSceneNow(std::unique_ptr<::MM::Scene>&& new_scene) = 0; 29 | }; 30 | 31 | } // MM::Services 32 | 33 | -------------------------------------------------------------------------------- /framework/engine/src/mm/services/service.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM { 6 | 7 | class Engine; 8 | namespace UpdateStrategies { 9 | struct TaskInfo; 10 | } 11 | 12 | namespace Services { 13 | 14 | class Service { 15 | public: 16 | virtual ~Service(void) {} 17 | 18 | virtual const char* name(void) = 0; 19 | 20 | // tasks are to be filled in by the service impl 21 | virtual bool enable(Engine& engine, std::vector& task_array) = 0; 22 | virtual void disable(Engine& engine) = 0; 23 | }; 24 | 25 | } // Services 26 | 27 | } // MM 28 | 29 | -------------------------------------------------------------------------------- /framework/engine/src/mm/update_strategies/dummy.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "./update_strategy.hpp" 4 | 5 | // Rezz x Deadmau5 - hypnocurrency 6 | 7 | namespace MM::UpdateStrategies { 8 | 9 | // does nothing, even less then a mock class 10 | // for testing only! 11 | class Dummy : public UpdateStrategy { 12 | public: 13 | ~Dummy(void) {} 14 | 15 | const char* name(void) override { return "Dummy"; } 16 | 17 | protected: // the engine facing interface 18 | bool enableService(const entt::id_type, std::vector&&) override { return true; } 19 | bool disableService(const entt::id_type) override { return true; } 20 | void doUpdate(MM::Engine&) override {} 21 | 22 | public: // the user facing interface 23 | void addDeferred(std::function) override {} 24 | void addAsync(std::function) override {} 25 | }; 26 | 27 | } // MM::UpdateStrategies 28 | 29 | -------------------------------------------------------------------------------- /framework/engine/src/mm/update_strategies/sequential_strategy.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "./update_strategy.hpp" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // HACK: welp 11 | // fwd 12 | namespace MM::Services { 13 | class ImGuiEngineTools; 14 | } 15 | 16 | namespace MM::UpdateStrategies { 17 | 18 | class Sequential : public MM::UpdateStrategies::UpdateStrategy { 19 | friend MM::Services::ImGuiEngineTools; 20 | 21 | private: 22 | std::unordered_map _tasks; 23 | 24 | // the tasks a service has registered 25 | std::unordered_map> _service_tasks; 26 | 27 | std::vector> _deferred_queue; 28 | std::vector> _async_queue; 29 | 30 | private: // utils 31 | void doGraphSequential(MM::Engine& engine, const std::set& tasks); 32 | 33 | public: 34 | Sequential(void) = default; 35 | virtual ~Sequential(void); 36 | 37 | const char* name(void) override { return "Sequential"; } 38 | 39 | protected: // engine facing interface 40 | bool enableService(const entt::id_type s_id, std::vector&& task_array) override; 41 | bool disableService(const entt::id_type s_id) override; 42 | 43 | void doUpdate(MM::Engine& engine) override; 44 | 45 | public: // user facing interface 46 | void addDeferred(std::function function) override; 47 | 48 | void addAsync(std::function function) override; 49 | 50 | size_t _max_async_per_tick = 5; // prevent blocking, this should be finetuned 51 | 52 | protected: // engine tools interface 53 | void forEachTask(std::function fn) override { 54 | for (auto&& t : _tasks) { 55 | if (!fn(t.second)) { 56 | break; 57 | } 58 | } 59 | } 60 | }; 61 | 62 | } // MM::UpdateStrategies 63 | 64 | -------------------------------------------------------------------------------- /framework/engine/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(engine_test 2 | update_strategy_test.cpp 3 | #default_us_test.cpp 4 | 5 | # old: 6 | #update_test.cpp 7 | #run_test.cpp 8 | #service_test.cpp 9 | #default_service_test.cpp 10 | ) 11 | 12 | target_include_directories(engine_test PRIVATE ".") 13 | 14 | target_link_libraries(engine_test 15 | engine 16 | gtest_main 17 | gmock 18 | ) 19 | 20 | add_test(NAME engine_test COMMAND engine_test) 21 | 22 | -------------------------------------------------------------------------------- /framework/engine/test/default_service_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | TEST(engine_default_service_system, add_en_dis) { 7 | 8 | MM::Engine e; 9 | 10 | e.addService(); 11 | ASSERT_TRUE(e.enableService()); 12 | 13 | { 14 | auto* dss = e.tryService(); 15 | ASSERT_NE(dss, nullptr); 16 | } 17 | 18 | e.disableService(); 19 | } 20 | 21 | TEST(engine_default_service_system, tick) { 22 | 23 | MM::Engine e; 24 | 25 | e.addService(); 26 | ASSERT_TRUE(e.enableService()); 27 | 28 | e.update(); 29 | e.fixedUpdate(); 30 | 31 | { 32 | auto* dss = e.tryService(); 33 | ASSERT_NE(dss, nullptr); 34 | } 35 | 36 | e.disableService(); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /framework/engine/test/run_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | TEST(engine_run, test_run) { 7 | MM::Engine engine{std::make_unique}; 8 | 9 | bool run = false; 10 | 11 | auto test_fun = [&run](auto& e) { 12 | run = true; 13 | e.stop(); 14 | }; 15 | 16 | auto handle = engine.addFixedUpdate(test_fun); 17 | ASSERT_NE(handle.lock(), nullptr); 18 | 19 | handle.lock()->priority = 1; 20 | 21 | ASSERT_FALSE(run); 22 | engine.run(); 23 | ASSERT_TRUE(run); 24 | 25 | engine.removeFixedUpdate(handle); 26 | } 27 | 28 | TEST(engine_run, test_mult_run) { 29 | MM::Engine engine; 30 | 31 | bool run = false; 32 | unsigned int fu_count = 0; 33 | unsigned int u_count = 0; 34 | 35 | const unsigned int f_to_do = 4; 36 | 37 | auto test_f_fun = [&](auto& e) { 38 | run = true; 39 | fu_count++; 40 | 41 | if (fu_count >= f_to_do) 42 | e.stop(); 43 | }; 44 | 45 | auto handle_f = engine.addFixedUpdate(test_f_fun); 46 | ASSERT_NE(handle_f.lock(), nullptr); 47 | handle_f.lock()->priority = 1; 48 | 49 | auto handle = engine.addUpdate([&u_count](auto&) { u_count++; }); 50 | ASSERT_NE(handle_f.lock(), nullptr); 51 | handle.lock()->priority = 1; 52 | 53 | ASSERT_FALSE(run); 54 | engine.run(); 55 | ASSERT_TRUE(run); 56 | 57 | EXPECT_GT(u_count, f_to_do) << "expected more update runs than fixed update runs..."; 58 | std::cout << "while performing " << f_to_do << " fixed updates, the engine did " << u_count << " updates.\n"; 59 | 60 | engine.removeFixedUpdate(handle_f); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /framework/filesystem/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(filesystem_service CXX) 4 | 5 | add_library(filesystem_service 6 | src/mm/path_utils.hpp 7 | 8 | src/mm/services/filesystem.hpp 9 | src/mm/services/filesystem.cpp 10 | 11 | src/mm/fs_const_archiver.hpp 12 | src/mm/fs_const_archiver.cpp 13 | ) 14 | 15 | target_include_directories(filesystem_service PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 16 | 17 | target_link_libraries(filesystem_service PUBLIC 18 | engine 19 | logger 20 | entt 21 | nlohmann_json::nlohmann_json 22 | physfs-static # TODO: fix this 23 | std_utils 24 | ) 25 | 26 | if(NOT MM_HEADLESS) 27 | 28 | #if android 29 | #target_link_libraries(filesystem_service SDL) 30 | #endif 31 | 32 | if(EMSCRIPTEN) 33 | target_compile_options(filesystem_service PUBLIC -sUSE_SDL=2) 34 | target_link_libraries(filesystem_service PUBLIC -sUSE_SDL=2) 35 | elseif(VCPKG_TARGET_TRIPLET) 36 | find_package(SDL2 CONFIG REQUIRED) 37 | 38 | target_link_libraries(filesystem_service 39 | PUBLIC 40 | SDL2::SDL2 41 | SDL2::SDL2main 42 | #SDL2::SDL2-static 43 | ) 44 | else() 45 | #if not android or emscripten 46 | find_package(SDL2 REQUIRED) 47 | target_include_directories(filesystem_service PUBLIC "${SDL2_INCLUDE_DIR}") 48 | target_link_libraries(filesystem_service PUBLIC ${SDL2_LIBRARY}) 49 | #endif 50 | endif() 51 | endif() 52 | 53 | if (BUILD_TESTING) 54 | add_subdirectory(test) 55 | endif() 56 | 57 | -------------------------------------------------------------------------------- /framework/filesystem/src/mm/fs_const_archiver.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace MM { 10 | class FSConstArchiver { 11 | private: 12 | static std::unordered_map> _storage; 13 | 14 | private: 15 | // archiver interface 16 | static void* PH_openArchive(PHYSFS_Io* io, const char* name, int forWrite, int* claimed); 17 | static PHYSFS_EnumerateCallbackResult PH_enumerate(void* opaque, const char* dirname, PHYSFS_EnumerateCallback cb, const char* origdir, void* callbackdata); 18 | static PHYSFS_Io* PH_openRead(void* opaque, const char* fnm); 19 | static PHYSFS_Io* PH_openWrite(void* opaque, const char* filename); 20 | static PHYSFS_Io* PH_openAppend(void* opaque, const char* filename); 21 | static int PH_remove(void* opaque, const char* filename); 22 | static int PH_mkdir(void* opaque, const char* filename); 23 | static int PH_stat(void* opaque, const char* fn, PHYSFS_Stat* stat); 24 | static void PH_closeArchive(void* opaque); 25 | 26 | static PHYSFS_Io* createIO(const char* filename, PHYSFS_uint64 pos = 0); 27 | 28 | static bool pathIsDir(const char* path); 29 | 30 | public: 31 | static const PHYSFS_Archiver* getArchiverStruct(void); 32 | 33 | // the archiver is not responsible for memory, you need to keep it around. 34 | static void addFile(const char* path, uint8_t* data, size_t data_size); 35 | }; 36 | } // MM 37 | 38 | #define FS_CONST_MOUNT_FILE(path, x) MM::FSConstArchiver::addFile(path, (uint8_t*)x, sizeof x); 39 | #define FS_CONST_MOUNT_FILE_S(path, x, size) MM::FSConstArchiver::addFile(path, x, size); 40 | 41 | //#define FS_CONST_MOUNT_FILE_STATIC(path, x) struct __internal_fs_const_struct_t { __internal_fs_const_struct_t(void) { FS_CONST_MOUNT_FILE(path, x) } }; static __internal_fs_const_struct_t __internal_fs_const_struct {}; 42 | 43 | -------------------------------------------------------------------------------- /framework/filesystem/src/mm/path_utils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // TODO: test 4 | 5 | #include 6 | 7 | // TODO: make proper namespace 8 | namespace MM { 9 | 10 | // removes './'s and resolves '../' 11 | // returns false if too many .. 12 | inline bool path_shorten(std::string& path) { 13 | auto splits = std_utils::split(path, "/"); 14 | std::vector new_splits; 15 | 16 | for (size_t i = 0; i < splits.size(); i++) { 17 | if (splits[i] == "..") { 18 | if (new_splits.empty()) 19 | return false; 20 | 21 | new_splits.pop_back(); 22 | } else if (splits[i] == ".") { 23 | // skip 24 | } else { 25 | new_splits.emplace_back(splits[i]); 26 | } 27 | } 28 | 29 | std::string new_path; 30 | for (auto& s : new_splits) { 31 | new_path += "/"; 32 | new_path += s; 33 | } 34 | path = new_path; 35 | 36 | return true; 37 | } 38 | 39 | // remove the file name from the path 40 | inline std::string base_path(std::string_view path) { 41 | auto pos = path.find_last_of("/"); 42 | if (pos == path.npos) 43 | return std::string(path); // TODO: make sure there is a '/' 44 | 45 | return std::string(path.substr(0, pos+1)); 46 | } 47 | 48 | } // MM 49 | 50 | -------------------------------------------------------------------------------- /framework/filesystem/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(filesystem_service_test 2 | filesystem_tests.cpp 3 | res/test.zip.h 4 | ) 5 | 6 | target_include_directories(filesystem_service_test PRIVATE ".") 7 | 8 | target_link_libraries(filesystem_service_test 9 | filesystem_service 10 | gtest_main 11 | ) 12 | 13 | add_test(NAME filesystem_service_test COMMAND filesystem_service_test) 14 | 15 | -------------------------------------------------------------------------------- /framework/filesystem/test/res/test.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MadeOfJelly/MushMachine/4ec8f98ab0aab46a3e7f7d7d515280642a70d225/framework/filesystem/test/res/test.zip -------------------------------------------------------------------------------- /framework/filesystem/test/res/test_file.txt: -------------------------------------------------------------------------------- 1 | test :D 2 | -------------------------------------------------------------------------------- /framework/filesystem/test/res/wall_concrete-1_se_0.2.json: -------------------------------------------------------------------------------- 1 | { "columns":11, 2 | "image":"wall_concrete-1_se_0.2.png", 3 | "imageheight":160, 4 | "imagewidth":352, 5 | "margin":0, 6 | "name":"wall_concrete-1_se_0.2", 7 | "spacing":0, 8 | "terrains":[ 9 | { 10 | "name":"solid", 11 | "tile":34 12 | }], 13 | "tilecount":55, 14 | "tiledversion":"1.2.3", 15 | "tileheight":32, 16 | "tiles":[ 17 | { 18 | "id":1, 19 | "terrain":[0, 0, 0, -1] 20 | }, 21 | { 22 | "id":2, 23 | "terrain":[0, 0, -1, 0] 24 | }, 25 | { 26 | "id":12, 27 | "terrain":[0, -1, 0, 0] 28 | }, 29 | { 30 | "id":13, 31 | "terrain":[-1, 0, 0, 0] 32 | }, 33 | { 34 | "id":19, 35 | "terrain":[-1, 0, 0, -1] 36 | }, 37 | { 38 | "id":20, 39 | "terrain":[0, -1, -1, 0] 40 | }, 41 | { 42 | "id":22, 43 | "terrain":[-1, -1, -1, 0] 44 | }, 45 | { 46 | "id":23, 47 | "terrain":[-1, -1, 0, 0] 48 | }, 49 | { 50 | "id":24, 51 | "terrain":[-1, -1, 0, -1] 52 | }, 53 | { 54 | "id":33, 55 | "terrain":[-1, 0, -1, 0] 56 | }, 57 | { 58 | "id":34, 59 | "terrain":[0, 0, 0, 0] 60 | }, 61 | { 62 | "id":35, 63 | "terrain":[0, -1, 0, -1] 64 | }, 65 | { 66 | "id":44, 67 | "terrain":[-1, 0, -1, -1] 68 | }, 69 | { 70 | "id":45, 71 | "terrain":[0, 0, -1, -1] 72 | }, 73 | { 74 | "id":46, 75 | "terrain":[0, -1, -1, -1] 76 | }], 77 | "tilewidth":32, 78 | "type":"tileset", 79 | "version":1.2 80 | } -------------------------------------------------------------------------------- /framework/imgui/res/ionicons/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-present Ionic (http://ionic.io/) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /framework/imgui/res/ionicons/ionicons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MadeOfJelly/MushMachine/4ec8f98ab0aab46a3e7f7d7d515280642a70d225/framework/imgui/res/ionicons/ionicons.ttf -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/file_shader_editor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "./file_text_editor.hpp" 4 | 5 | namespace MM { 6 | 7 | class FileShaderEditor : public FileTextEditor { 8 | protected: 9 | TextEditor::ErrorMarkers _markers; 10 | 11 | protected: 12 | void postSave(void) override; 13 | 14 | void checkErrors(void); 15 | void handleErrorString(const char* msg); 16 | 17 | void handleErrorStringFormat1(const char* msg); 18 | 19 | public: 20 | FileShaderEditor(Engine& engine); 21 | 22 | void renderImGui(void); 23 | 24 | public: 25 | bool checkErrorsOnChange = true; 26 | 27 | uint32_t shaderType; 28 | }; 29 | } // MM 30 | 31 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/file_text_editor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM { 8 | 9 | class FileTextEditor { 10 | protected: 11 | TextEditor _te; 12 | TextEditor::LanguageDefinition _te_lang; 13 | 14 | std::string _file_path; 15 | std::string _tmp_file_path; 16 | 17 | std::string _windowID; 18 | 19 | Services::FilesystemService* _fs_ptr = nullptr; 20 | 21 | protected: 22 | bool open(Services::FilesystemService::fs_file_t file, bool write = true); 23 | 24 | void renderPopups(void); 25 | 26 | virtual void postSave(void) {} 27 | virtual void postOpen(void) {} 28 | 29 | public: 30 | FileTextEditor(Engine& engine); 31 | virtual ~FileTextEditor(void) {} 32 | 33 | void renderImGui(bool* is_open = nullptr); 34 | 35 | void setLanguageDefinition(const TextEditor::LanguageDefinition& lang); 36 | 37 | bool open(const std::string& path, bool write = true); 38 | 39 | bool save(void); 40 | }; 41 | } // MM 42 | 43 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/fps_overlay.cpp: -------------------------------------------------------------------------------- 1 | #include "./fps_overlay.hpp" 2 | 3 | #include 4 | #include 5 | 6 | namespace MM { 7 | 8 | void ImGuiSimpleFPSOverlay::renderImGui(void) { 9 | const float DISTANCE = 10.0f; 10 | 11 | ImVec2 window_pos = ImVec2(DISTANCE, DISTANCE + 15.f); 12 | 13 | ImVec2 window_pos_pivot = ImVec2(0.f, 0.f); 14 | ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always, window_pos_pivot); 15 | 16 | ImGui::SetNextWindowBgAlpha(0.2f); 17 | ImGui::Begin("SimpleFPSOverlay", NULL, 18 | ImGuiWindowFlags_NoMove | 19 | ImGuiWindowFlags_NoTitleBar | 20 | ImGuiWindowFlags_NoResize | 21 | ImGuiWindowFlags_AlwaysAutoResize | 22 | ImGuiWindowFlags_NoSavedSettings | 23 | ImGuiWindowFlags_NoFocusOnAppearing | 24 | ImGuiWindowFlags_NoNav 25 | ); 26 | 27 | ImGui::Text("%.1f FPS", ImGui::GetIO().Framerate); 28 | 29 | if (_show_plot) { 30 | ImGui::Separator(); 31 | ImGui::PlotVar("frame time", ImGui::GetIO().DeltaTime, 0.f, 0.05f, 120); 32 | } 33 | 34 | if (ImGui::BeginPopupContextWindow()) { 35 | if (ImGui::MenuItem("Show Plot", NULL, _show_plot)) { 36 | _show_plot = !_show_plot; 37 | } 38 | 39 | ImGui::EndPopup(); 40 | } 41 | 42 | 43 | ImGui::End(); 44 | 45 | ImGui::PlotVarFlushOldEntries(); 46 | } 47 | 48 | } // namespace MM 49 | 50 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/fps_overlay.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MM { 4 | class ImGuiSimpleFPSOverlay { 5 | private: 6 | bool _show_plot = false; 7 | 8 | public: 9 | void renderImGui(void); 10 | }; 11 | } // namespace MM 12 | 13 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/sound_info.cpp: -------------------------------------------------------------------------------- 1 | #include "./sound_info.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace MM { 10 | 11 | void ImGuiSoundInfo(Engine& engine, bool* show) { 12 | if (ImGui::Begin("Sound Info", show)) { 13 | auto& sound = engine.getService(); 14 | 15 | ImGui::Text("SoLoud v%d", sound.engine.getVersion()); 16 | ImGui::Text("Backend: %s, ch: %d, rate: %d, buffersize: %d", 17 | sound.engine.getBackendString(), 18 | sound.engine.getBackendChannels(), 19 | sound.engine.getBackendSamplerate(), 20 | sound.engine.getBackendBufferSize()); 21 | ImGui::Text("Max Active Voice Count: %d", sound.engine.getMaxActiveVoiceCount()); 22 | 23 | ImGui::Text("Active Voice Count: %d", sound.engine.getActiveVoiceCount()); 24 | 25 | sound.engine.getWave(); 26 | ImGui::PlotLines("##Wave", sound.engine.getWave(), 256, 0, "Wave", -1.f, 1.f, ImVec2(0, 80)); 27 | ImGui::PlotHistogram("##Spectrum", sound.engine.calcFFT(), 256 / 2, 0, "FFT", 0.f, 20.f, ImVec2(0, 80)); 28 | } 29 | ImGui::End(); 30 | } 31 | 32 | } // MM 33 | 34 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/sound_info.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MM { 4 | class Engine; // fwd 5 | 6 | void ImGuiSoundInfo(Engine& engine, bool* show = nullptr); 7 | } // MM 8 | 9 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/sound_pref.cpp: -------------------------------------------------------------------------------- 1 | #include "sound_pref.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM { 8 | 9 | void ImGuiSoundPref(Engine& engine) { 10 | if (ImGui::Begin("Sound Preferences")) { 11 | auto& e = engine.getService().engine; 12 | 13 | auto gvolume = e.getGlobalVolume(); 14 | ImGui::SliderFloat("Global Volume", &gvolume, 0.f, 1.f); 15 | e.setGlobalVolume(gvolume); 16 | } 17 | ImGui::End(); 18 | } 19 | 20 | } // MM 21 | 22 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/sound_pref.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MM { 4 | class Engine; // fwd 5 | 6 | void ImGuiSoundPref(Engine& engine); 7 | } // MM 8 | 9 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/auto_wrap.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::ImGuiWidgets { 8 | 9 | template 10 | void ListWrap(Iterator begin, Iterator end, std::function fn, float item_with) { 11 | ImGuiStyle& style = ImGui::GetStyle(); 12 | 13 | float window_visible_x2 = ImGui::GetWindowPos().x + ImGui::GetWindowContentRegionMax().x; 14 | 15 | for (auto it = begin; it != end; it++) { 16 | //ImGui::PushID(n); 17 | //ImGui::Button("Box", button_sz); 18 | 19 | fn(it); 20 | 21 | float last_item_x2 = ImGui::GetItemRectMax().x; 22 | 23 | float next_item_x2 = last_item_x2 + style.ItemSpacing.x + item_with; // Expected position if next item was on same line 24 | 25 | if (it + 1 != end && next_item_x2 < window_visible_x2) { 26 | ImGui::SameLine(); 27 | } 28 | 29 | //ImGui::PopID(); 30 | } 31 | } 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/camera.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::ImGuiWidgets { 8 | 9 | void Camera3D(MM::Scene& scene); 10 | 11 | } 12 | 13 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/color.cpp: -------------------------------------------------------------------------------- 1 | #include "color.hpp" 2 | 3 | #include 4 | 5 | namespace MM::ImGuiWidgets::Components { 6 | 7 | void Color(MM::Components::Color& c) { 8 | ImGui::ColorEdit4("color##Color", &c.color[0]); 9 | } 10 | 11 | } 12 | 13 | namespace MM { 14 | 15 | template <> 16 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 17 | ImGuiWidgets::Components::Color(reg.get(e)); 18 | } 19 | 20 | } // MM 21 | 22 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/color.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | void Color(MM::Components::Color& c); 9 | } 10 | 11 | namespace MM { 12 | template <> 13 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/name.cpp: -------------------------------------------------------------------------------- 1 | #include "name.hpp" 2 | 3 | #include 4 | #include 5 | 6 | namespace MM::ImGuiWidgets::Components { 7 | 8 | // TODO: make editable 9 | void Name(MM::Components::Name& n) { 10 | if (ImGui::InputText("str##Name", &n.str)) { 11 | n.str = n.str.substr(0, MM::Components::Name::max_str_len); // limit size 12 | } 13 | } 14 | 15 | } 16 | 17 | namespace MM { 18 | 19 | template <> 20 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 21 | ImGuiWidgets::Components::Name(reg.get(e)); 22 | } 23 | 24 | } // MM 25 | 26 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/name.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | void Name(MM::Components::Name& n); 9 | } 10 | 11 | namespace MM { 12 | template <> 13 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/position2d.cpp: -------------------------------------------------------------------------------- 1 | #include "./position2d.hpp" 2 | 3 | #include 4 | 5 | namespace MM::ImGuiWidgets::Components { 6 | 7 | void Position(MM::Components::Position2D& p) { 8 | ImGui::DragFloat2("position (x,y)##Position2D", &p.pos.x, 0.1f); 9 | } 10 | 11 | } // MM::ImGuiWidgets::Components 12 | 13 | namespace MM { 14 | 15 | template <> 16 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 17 | ImGuiWidgets::Components::Position(reg.get(e)); 18 | } 19 | 20 | } // MM 21 | 22 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/position2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | void Position(MM::Components::Position2D& p); 9 | } 10 | 11 | namespace MM { 12 | template <> 13 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/position2d_zoffset.cpp: -------------------------------------------------------------------------------- 1 | #include "./position2d_zoffset.hpp" 2 | 3 | #include 4 | 5 | namespace MM::ImGuiWidgets::Components { 6 | 7 | void Position_ZOffset(MM::Components::Position2D_ZOffset& z) { 8 | ImGui::SliderFloat("zoffset##Position2D_ZOffset", &z.z_offset, 0.f, 1000.f); // TODO: this depends on the camera far and near plane... somewhat 9 | } 10 | 11 | } // MM::ImGuiWidgets::Components 12 | 13 | namespace MM { 14 | 15 | template <> 16 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 17 | ImGuiWidgets::Components::Position_ZOffset(reg.get(e)); 18 | } 19 | 20 | } // MM 21 | 22 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/position2d_zoffset.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | void Position_ZOffset(MM::Components::Position2D_ZOffset& t); 9 | } 10 | 11 | namespace MM { 12 | template <> 13 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/position3d.cpp: -------------------------------------------------------------------------------- 1 | #include "./position3d.hpp" 2 | 3 | #include 4 | 5 | //#include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | 9 | void Transform(MM::Components::Position3D& p) { 10 | //ImGui::DragFloat3("position (x,y,z)##Transform3D", &t.position.x, 0.1f); 11 | ImGui::DragFloat3("position (x,y,z)##Position3D", &p.pos.x, 0.1f); 12 | //ImGui::SliderFloat("rotation##Transform3D", &t.rotation, 0.f, glm::pi() * 2.f); 13 | //ImGui::DragFloat3("scale (x,y,z)##Transform3D", &t.scale.x, 1.f, 0.f); 14 | } 15 | 16 | } // MM::ImGuiWidgets::Components 17 | 18 | namespace MM { 19 | 20 | template <> 21 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 22 | ImGuiWidgets::Components::Transform(reg.get(e)); 23 | } 24 | 25 | } // MM 26 | 27 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/position3d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | void Transform(MM::Components::Position3D& p); 9 | } 10 | 11 | namespace MM { 12 | template <> 13 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/rotation2d.cpp: -------------------------------------------------------------------------------- 1 | #include "./rotation2d.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | 9 | void Rotation(MM::Components::Rotation2D& r) { 10 | ImGui::SliderFloat("rotation##Rotation2D", &r.rot, 0.f, glm::two_pi()); 11 | } 12 | 13 | } // MM::ImGuiWidgets::Components 14 | 15 | namespace MM { 16 | 17 | template <> 18 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 19 | ImGuiWidgets::Components::Rotation(reg.get(e)); 20 | } 21 | 22 | } // MM 23 | 24 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/rotation2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | void Rotation(MM::Components::Rotation2D& r); 9 | } 10 | 11 | namespace MM { 12 | template <> 13 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/scale2d.cpp: -------------------------------------------------------------------------------- 1 | #include "./scale2d.hpp" 2 | 3 | #include 4 | 5 | namespace MM::ImGuiWidgets::Components { 6 | 7 | void Scale(MM::Components::Scale2D& s) { 8 | ImGui::DragFloat2("scale (x,y)##Scale2D", &s.scale.x, 0.01f); 9 | } 10 | 11 | } // MM::ImGuiWidgets::Components 12 | 13 | namespace MM { 14 | 15 | template <> 16 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 17 | ImGuiWidgets::Components::Scale(reg.get(e)); 18 | } 19 | 20 | } // MM 21 | 22 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/scale2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | void Scale(MM::Components::Scale2D& s); 9 | } 10 | 11 | namespace MM { 12 | template <> 13 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/texture.cpp: -------------------------------------------------------------------------------- 1 | #include "texture.hpp" 2 | #include "../texture.hpp" 3 | 4 | #include 5 | 6 | namespace MM::ImGuiWidgets::Components { 7 | 8 | void Texture(MM::Components::OpenGL::Texture& tex) { 9 | LabelTexture("tex##Texture", tex.tex); 10 | } 11 | 12 | } 13 | 14 | namespace MM { 15 | 16 | template <> 17 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 18 | ImGuiWidgets::Components::Texture(reg.get(e)); 19 | } 20 | 21 | } // MM 22 | 23 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/texture.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | 9 | void Texture(MM::Components::OpenGL::Texture& tex); 10 | 11 | } 12 | 13 | namespace MM { 14 | template <> 15 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/tilemap_renderable.cpp: -------------------------------------------------------------------------------- 1 | #include "./tilemap_renderable.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace MM::ImGuiWidgets::Components { 10 | 11 | void TilemapRenderable(MM::OpenGL::TilemapRenderable& tm_r) { 12 | for (size_t i = 0; i < tm_r.sprite_layer.size(); i++) { 13 | ImGui::Separator(); 14 | std::string label = "sprite_sheet##"; 15 | label += std::to_string(i); 16 | MM::ImGuiWidgets::LabelSpriteSheet(label.c_str(), tm_r.sprite_layer[i].sprite_sheet); 17 | } 18 | } 19 | 20 | } // MM::ImGuiWidgets::Components 21 | 22 | namespace MM { 23 | 24 | template <> 25 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 26 | ImGuiWidgets::Components::TilemapRenderable(reg.get(e)); 27 | } 28 | 29 | } // MM 30 | 31 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/tilemap_renderable.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | // fwd 7 | namespace MM::OpenGL { 8 | struct TilemapRenderable; 9 | } 10 | 11 | namespace MM::ImGuiWidgets::Components { 12 | 13 | void TilemapRenderable(MM::OpenGL::TilemapRenderable& tm_r); 14 | 15 | } 16 | 17 | namespace MM { 18 | template <> 19 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/velocity2d_position.cpp: -------------------------------------------------------------------------------- 1 | #include "./velocity2d_position.hpp" 2 | 3 | #include 4 | 5 | namespace MM::ImGuiWidgets::Components { 6 | 7 | void VelocityPosition(MM::Components::Velocity2DPosition& v) { 8 | ImGui::DragFloat2("velocity (x,y)##Velocity2DPosition", &v.pos_vel.x, 0.1f); 9 | } 10 | 11 | } // MM::ImGuiWidgets::Components 12 | 13 | namespace MM { 14 | 15 | template <> 16 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 17 | ImGuiWidgets::Components::VelocityPosition(reg.get(e)); 18 | } 19 | 20 | } // MM 21 | 22 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/velocity2d_position.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | void VelocityPosition(MM::Components::Velocity2DPosition& v); 9 | } 10 | 11 | namespace MM { 12 | template <> 13 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/velocity2d_rotation.cpp: -------------------------------------------------------------------------------- 1 | #include "./velocity2d_rotation.hpp" 2 | 3 | #include 4 | 5 | namespace MM::ImGuiWidgets::Components { 6 | 7 | void VelocityRotation(MM::Components::Velocity2DRotation& v) { 8 | ImGui::DragFloat("rotation##Velocity2DRotation", &v.rot_vel); 9 | } 10 | 11 | } // MM::ImGuiWidgets::Components 12 | 13 | namespace MM { 14 | 15 | template <> 16 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 17 | ImGuiWidgets::Components::VelocityRotation(reg.get(e)); 18 | } 19 | 20 | } // MM 21 | 22 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/velocity2d_rotation.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | void VelocityRotation(MM::Components::Velocity2DRotation& v); 9 | } 10 | 11 | namespace MM { 12 | template <> 13 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/view_dir2d.cpp: -------------------------------------------------------------------------------- 1 | #include "./view_dir2d.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | 9 | void ViewDir(MM::Components::ViewDir2D& vd) { 10 | ImGui::SliderFloat("dir##ViewDir2D", &vd.dir, 0.0f, glm::two_pi()); 11 | } 12 | 13 | } // MM::ImGuiWidgets::Components 14 | 15 | namespace MM { 16 | 17 | template <> 18 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 19 | ImGuiWidgets::Components::ViewDir(reg.get(e)); 20 | } 21 | 22 | } // MM 23 | 24 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/view_dir2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | void ViewDir(MM::Components::ViewDir2D& t); 9 | } 10 | 11 | namespace MM { 12 | template <> 13 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/view_dir3d.cpp: -------------------------------------------------------------------------------- 1 | #include "./view_dir3d.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | 9 | void ViewDir(MM::Components::ViewDir3D& vd) { 10 | ImGui::SliderFloat("yaw##ViewDir3D", &vd.yaw, 0.0f, glm::two_pi()); 11 | ImGui::SliderFloat("pitch##ViewDir3D", &vd.pitch, -glm::half_pi(), glm::half_pi()); 12 | ImGui::SliderFloat("roll##ViewDir3D", &vd.roll, -glm::half_pi(), glm::half_pi()); 13 | } 14 | 15 | } // MM::ImGuiWidgets::Components 16 | 17 | namespace MM { 18 | 19 | template <> 20 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e) { 21 | ImGuiWidgets::Components::ViewDir(reg.get(e)); 22 | } 23 | 24 | } // MM 25 | 26 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/components/view_dir3d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::ImGuiWidgets::Components { 8 | void ViewDir(MM::Components::ViewDir3D& t); 9 | } 10 | 11 | namespace MM { 12 | template <> 13 | void ComponentEditorWidget(MM::Scene& reg, MM::Entity e); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/entity.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::ImGuiWidgets { 8 | 9 | void Entity(MM::Entity& e, MM::Scene& ecs, bool dropTarget = true); 10 | 11 | // just a drop target 12 | void EntityTrashCan(MM::Scene& ecs); 13 | 14 | //void EntityList(MM::Scene& ecs, const std::vector& comps); 15 | 16 | //void EntityListByComponents(MM::Scene& ecs, std::map>& named_comps); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/filesystem.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::ImGuiWidgets { 8 | 9 | //#define IMGUI_PAYLOAD_TYPE_MM_FILE "MM_FILE" 10 | //#define IMGUI_PAYLOAD_TYPE_MM_FILE_PATH "MM_FILE_PATH" 11 | 12 | void FilePicker(const char* label, MM::Services::FilesystemService& fs, std::string& path, bool save = false); 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/knob.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MM::ImGuiWidgets { 4 | 5 | bool KnobFloat(const char* label, float* v, float v_min, float v_max, float step = 0.0f, bool show_tooltip = true); 6 | 7 | } 8 | 9 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/plot_radar.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include 4 | 5 | #include 6 | 7 | namespace MM::ImGuiWidgets { 8 | 9 | void PlotRadar( 10 | const char* label, 11 | const float* values, int values_count, // values offset? 12 | const char** vlabels = nullptr, // list of null-terminated c-strings, same size as values 13 | float scale_min = FLT_MAX, float scale_max = FLT_MAX, 14 | ImVec2 graph_size = {100, 100}, 15 | 16 | bool draw_net_first = false, 17 | 18 | // polygon 19 | const ImVec4& poly_line_color = {0.8f, 0.8f, 0.0f, 1.0f}, 20 | const ImVec4& poly_fill_color = {0.8f, 0.8f, 0.0f, 0.4f}, 21 | const float poly_line_thickness = 2.f, 22 | 23 | // net 24 | const ImVec4& net_line_color = {0.9f, 0.9f, 0.9f, 0.8f}, 25 | const float net_line_thickness = 1.f 26 | 27 | //bool show_tooltip = true 28 | ); 29 | 30 | } // MM::ImGuiWidgets 31 | 32 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/soloud.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // fwd 4 | namespace SoLoud { 5 | class Soloud; 6 | class Sfxr; 7 | struct SfxrParams; 8 | class Filter; 9 | class FilterInstance; 10 | 11 | typedef unsigned int handle; 12 | } 13 | 14 | namespace MM::ImGuiWidgets { 15 | 16 | bool SoLoudSfxrPlain(const char* label, SoLoud::SfxrParams* sfxr_params); 17 | // uses knobs and childs 18 | bool SoLoudSfxrFancy(const char* label, SoLoud::SfxrParams* sfxr_params); 19 | 20 | // calls getParam*() methods 21 | //bool SoLoudFilterLiveParams(const char* label, SoLoud::Filter* filter, SoLoud::FilterInstance* filter_instance); // no access to instance 22 | bool SoLoudFilterLiveParams(const char* label, SoLoud::Soloud* soloud, SoLoud::Filter* filter, unsigned int filter_id, SoLoud::handle voice_handle = 0); 23 | bool SoLoudFilterLiveParamsFancy(const char* label, SoLoud::Soloud* soloud, SoLoud::Filter* filter, unsigned int filter_id, SoLoud::handle voice_handle = 0, bool same_line = false); 24 | 25 | } // MM::ImGuiWidgets 26 | 27 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/spritesheet.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // forward 4 | struct ImVec2; 5 | namespace MM::OpenGL { 6 | struct SpriteSheet; 7 | } 8 | 9 | namespace MM::ImGuiWidgets { 10 | 11 | void SpriteSheetPreview(MM::OpenGL::SpriteSheet& sheet, ImVec2 size); 12 | void SpriteSheet(MM::OpenGL::SpriteSheet& sheet); 13 | void LabelSpriteSheet(const char* label, MM::OpenGL::SpriteSheet& sheet); 14 | void SpriteSheetEditor(MM::OpenGL::SpriteSheet& sheet); 15 | 16 | } // MM::ImGuiWidgets 17 | 18 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/texture.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::ImGuiWidgets { 6 | 7 | #define IMGUI_PAYLOAD_TYPE_MM_REND_TEXTURE "MM_REND_TEXTURE" 8 | 9 | void Texture(MM::OpenGL::Texture::handle_t& texture, bool dropTarget = true); 10 | void LabelTexture(const char* label, MM::OpenGL::Texture::handle_t& texture, bool dropTarget = true); 11 | 12 | } 13 | 14 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/imgui/widgets/texture_resource_manager.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include "./texture.hpp" 7 | 8 | // fwd 9 | namespace MM { 10 | class Engine; 11 | } 12 | 13 | namespace MM::ImGuiWidgets { 14 | 15 | void TextureResourceManagerList(void); 16 | 17 | void TextureResourceManagerLoader(Engine& engine); 18 | 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/services/engine_tools.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "./imgui_menu_bar.hpp" 4 | 5 | namespace MM::Services { 6 | 7 | class ImGuiEngineTools : public Service { 8 | public: 9 | const char* name(void) override { return "ImGuiEngineTools"; } 10 | 11 | bool enable(Engine& engine, std::vector& task_array) override; 12 | void disable(Engine& engine) override; 13 | 14 | private: 15 | bool _show_about = false; 16 | bool _show_services = false; 17 | bool _show_update_stategy = false; 18 | 19 | bool _services_edit_mode = false; 20 | 21 | private: 22 | void renderImGui(Engine& engine); 23 | 24 | void renderAbout(Engine& engine); 25 | void renderServices(Engine& engine); 26 | void renderUpdateStrategy(Engine& engine); 27 | }; 28 | 29 | } // namespace MM::Services 30 | 31 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/services/imgui_menu_bar.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace MM::Services { 10 | 11 | class ImGuiMenuBar : public Service { 12 | public: 13 | const char* name(void) override { return "ImGuiMenuBar"; } 14 | 15 | bool enable(Engine& engine, std::vector& task_array) override; 16 | void disable(Engine& engine) override; 17 | 18 | public: 19 | bool show_menu_bar = true; 20 | 21 | SDL_Keycode toggle_key = SDLK_F2; 22 | 23 | using menu_item_callback_t = std::function; 24 | 25 | using section_t = std::map; 26 | 27 | // menu tree 28 | // section -> section_t -> menu_item_t 29 | // section is stable id key 30 | // menus contain stable id keys 31 | std::map menu_tree; 32 | 33 | std::vector section_order { 34 | "Engine", 35 | }; 36 | 37 | private: 38 | MM::Services::SDLService::EventHandlerHandle _event_handle = nullptr; 39 | 40 | private: 41 | void renderImGui(Engine& engine); 42 | 43 | void renderSection(Engine& engine, const std::string& section_key, section_t& section); 44 | }; 45 | 46 | } // namespace MM::Services 47 | 48 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/services/imgui_s.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace MM::Services { 7 | 8 | // responsable for event handling and setup 9 | // enable requires an open sdl window (and context) 10 | class ImGuiService : public Service { 11 | private: 12 | MM::Services::SDLService::EventHandlerHandle _event_handle = nullptr; 13 | 14 | // new frame needs to start AFTER the events have been processed (and obv bf rendt) 15 | 16 | public: 17 | bool enable(Engine& engine, std::vector& task_array) override; 18 | void disable(Engine& engine) override; 19 | 20 | const char* name(void) override { return "ImGuiService"; } 21 | 22 | private: 23 | void imgui_new_frame(Engine& engine); 24 | 25 | bool handle_sdl_event(const SDL_Event& e); 26 | }; 27 | 28 | } // namespace MM::Services 29 | 30 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/services/scene_tools.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define MM_IEEE_ENTITY_WIDGET ::MM::ImGuiWidgets::Entity // evil 6 | #define MM_IEEE_ASSERT(x) 7 | #include 8 | #include 9 | 10 | //#include 11 | 12 | namespace MM::Services { 13 | 14 | class ImGuiSceneToolsService : public Service { 15 | public: 16 | bool enable(Engine& engine, std::vector& task_array) override; 17 | void disable(Engine& engine) override; 18 | 19 | const char* name(void) override { return "ImGuiSceneToolsService"; } 20 | 21 | private: 22 | bool _show_scene_metrics = false; 23 | bool _show_entity_editor = false; 24 | bool _show_entity_list = true; 25 | bool _show_camera_tool = false; 26 | bool _show_time_delta_ctx = false; 27 | 28 | EntityEditor _entity_editor; 29 | // for list 30 | std::set::ComponentTypeID> _entity_comp_list; 31 | 32 | //std::vector _text_editor_list; 33 | 34 | private: 35 | void renderImGui(Engine& engine); 36 | 37 | public: 38 | EntityEditor& getEntityEditor(void); 39 | Entity _e = entt::null; // entity currently in editor 40 | }; 41 | 42 | } // namespace MM::Services 43 | 44 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/services/screen_director_tools.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "./imgui_menu_bar.hpp" 4 | 5 | namespace MM::Services { 6 | 7 | class ImGuiScreenDirectorTools : public Service { 8 | public: 9 | const char* name(void) override { return "ImGuiScreenDirectorTools"; } 10 | 11 | bool enable(Engine& engine, std::vector& task_array) override; 12 | void disable(Engine& engine) override; 13 | 14 | private: 15 | bool _show_screen_list = false; 16 | 17 | //bool _edit_mode = false; 18 | 19 | private: 20 | void renderImGui(Engine& engine); 21 | 22 | void renderScreenList(Engine& engine); 23 | }; 24 | 25 | } // namespace MM::Services 26 | 27 | -------------------------------------------------------------------------------- /framework/imgui/src/mm/services/sound_tools.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "./imgui_menu_bar.hpp" 4 | 5 | namespace MM::Services { 6 | 7 | class ImGuiSoundTools : public Service { 8 | public: 9 | const char* name(void) override { return "ImGuiSoundTools"; } 10 | 11 | bool enable(Engine& engine, std::vector& task_array) override; 12 | void disable(Engine& engine) override; 13 | 14 | private: 15 | bool _show_info = false; 16 | 17 | private: 18 | void renderImGui(Engine& engine); 19 | }; 20 | 21 | } // namespace MM::Services 22 | 23 | -------------------------------------------------------------------------------- /framework/input/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(input_service CXX) 4 | 5 | add_library(input_service 6 | src/mm/services/input_service.hpp 7 | src/mm/services/input_service.cpp 8 | ) 9 | 10 | target_include_directories(input_service PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 11 | 12 | target_link_libraries(input_service 13 | engine 14 | glm 15 | sdl_service 16 | ) 17 | 18 | #if(NOT EMSCRIPTEN) 19 | #target_include_directories(input_service PUBLIC "${SDL2_INCLUDE_DIR}") 20 | #endif() 21 | 22 | if (BUILD_TESTING) 23 | add_subdirectory(test) 24 | endif() 25 | 26 | -------------------------------------------------------------------------------- /framework/input/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(input_service_test 2 | start_test.cpp 3 | ) 4 | 5 | target_include_directories(input_service_test PRIVATE ".") 6 | 7 | target_link_libraries(input_service_test 8 | input_service 9 | sdl_service 10 | gtest_main 11 | ) 12 | 13 | add_test(NAME input_service_test COMMAND input_service_test) 14 | 15 | ###################### 16 | 17 | add_executable(input_service_visualizer_test 18 | input_visualizer.cpp 19 | ) 20 | 21 | target_include_directories(input_service_visualizer_test PRIVATE ".") 22 | 23 | target_link_libraries(input_service_visualizer_test 24 | input_service 25 | sdl_service 26 | imgui_service 27 | imgui_render_task 28 | imgui_tools 29 | gtest_main 30 | ) 31 | 32 | if(NOT MM_AUTOTEST) 33 | add_test(NAME input_service_visualizer_test COMMAND input_service_visualizer_test) 34 | endif() 35 | 36 | -------------------------------------------------------------------------------- /framework/logger/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(logger CXX) 4 | 5 | file(GLOB_RECURSE CPP_FILES src/*.cpp) 6 | file(GLOB_RECURSE HPP_FILES src/*.hpp) 7 | 8 | add_library(logger ${CPP_FILES} ${HPP_FILES}) 9 | 10 | target_include_directories(logger PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 11 | 12 | #target_compile_definitions(logger PUBLIC SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE) 13 | target_compile_definitions(logger PUBLIC SPDLOG_ACTIVE_LEVEL=0) 14 | 15 | target_link_libraries(logger 16 | spdlog 17 | tracy_client 18 | ) 19 | 20 | #if (BUILD_TESTING) 21 | #add_subdirectory(test) 22 | #endif() 23 | 24 | 25 | -------------------------------------------------------------------------------- /framework/logger/src/mm/tracy_sink.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef TRACY_ENABLE 4 | 5 | #include 6 | #include 7 | 8 | namespace spdlog::sinks { 9 | 10 | static uint32_t level_to_color(spdlog::level::level_enum level) { 11 | switch (level) { 12 | case level::level_enum::trace: return 0xFFFFFF; 13 | case level::level_enum::debug: return 0x1111FF; 14 | case level::level_enum::info: return 0x11FF11; 15 | case level::level_enum::warn: return 0xFFFF11; 16 | case level::level_enum::err: return 0xFF1111; 17 | case level::level_enum::critical: return 0xFF0000; 18 | default: return 0xffffff; 19 | } 20 | } 21 | 22 | template 23 | class tracy_sink : public ::spdlog::sinks::base_sink { 24 | public: 25 | tracy_sink(void) { 26 | this->set_pattern("[%n] [%l] %v"); 27 | } 28 | protected: 29 | void sink_it_(const spdlog::details::log_msg& msg) override { 30 | 31 | // log_msg is a struct containing the log entry info like level, timestamp, thread id etc. 32 | // msg.raw contains pre formatted log 33 | 34 | // If needed (very likely but not mandatory), the sink formats the message before sending it to its final destination: 35 | spdlog::memory_buf_t formatted; 36 | base_sink::formatter_->format(msg, formatted); 37 | auto string = fmt::to_string(formatted); 38 | TracyMessageC(string.data(), string.size(), level_to_color(msg.level)); 39 | } 40 | 41 | void flush_() override { 42 | } 43 | }; 44 | 45 | } // spdlog::sinks 46 | 47 | #include 48 | #include 49 | 50 | namespace spdlog::sinks { 51 | using tracy_sink_mt = tracy_sink; 52 | using tracy_sink_st = tracy_sink; 53 | } // spdlog::sinks 54 | 55 | #endif // TRACY_ENABLE 56 | 57 | -------------------------------------------------------------------------------- /framework/opengl_primitives/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(opengl_primitives CXX) 4 | 5 | add_library(opengl_primitives 6 | src/mm/opengl/buffer.hpp 7 | src/mm/opengl/buffer.cpp 8 | src/mm/opengl/fbo_builder.hpp 9 | src/mm/opengl/fbo_builder.cpp 10 | src/mm/opengl/frame_buffer_object.hpp 11 | src/mm/opengl/frame_buffer_object.cpp 12 | src/mm/opengl/instance_buffer.hpp 13 | src/mm/opengl/shader.hpp 14 | src/mm/opengl/shader.cpp 15 | src/mm/opengl/shader_builder.hpp 16 | src/mm/opengl/shader_builder.cpp 17 | src/mm/opengl/spritesheet.hpp 18 | src/mm/opengl/texture.hpp 19 | src/mm/opengl/texture.cpp 20 | src/mm/opengl/texture_loader.hpp 21 | src/mm/opengl/texture_loader.cpp 22 | src/mm/opengl/vertex_array_object.hpp 23 | src/mm/opengl/vertex_array_object.cpp 24 | 25 | 26 | src/mm/opengl/components/texture.hpp 27 | ) 28 | 29 | target_include_directories(opengl_primitives PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 30 | 31 | target_link_libraries(opengl_primitives PUBLIC 32 | glm 33 | stb_image 34 | #sdl 35 | sdl_service 36 | 37 | logger 38 | resource_manager 39 | filesystem_service 40 | ) 41 | 42 | if(MM_OPENGL_3_GLES) 43 | target_link_libraries(opengl_primitives PUBLIC "GL") # TODO: make more specific 44 | if(EMSCRIPTEN) 45 | # USE_SDL=2 inherited from sdl_service 46 | # TODO: USE_WEBGL2 -> MIN_WEBGL_VERSION=2 maybe 47 | # technically only FULL_ES3 would be needed 48 | target_link_libraries(opengl_primitives PUBLIC -sUSE_WEBGL2=1 -sFULL_ES3=1) 49 | endif() 50 | 51 | else() 52 | target_link_libraries(opengl_primitives PUBLIC glad) 53 | endif() 54 | 55 | if (BUILD_TESTING) 56 | add_subdirectory(test) 57 | endif() 58 | 59 | 60 | -------------------------------------------------------------------------------- /framework/opengl_primitives/src/mm/opengl/buffer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by FlaXxy on 21.05.2018. 3 | // 4 | 5 | #include "./buffer.hpp" 6 | 7 | namespace MM::OpenGL { 8 | 9 | Buffer::Buffer(const void* data, std::size_t size, GLenum usage, GLenum target) : _size(size), _target(target) { 10 | glGenBuffers(1, &_handle); 11 | glBindBuffer(_target, _handle); 12 | glBufferData(_target, size, data, usage); 13 | } 14 | 15 | Buffer::~Buffer(void) { 16 | glDeleteBuffers(1, &_handle); 17 | } 18 | 19 | void Buffer::bind(void) const { 20 | glBindBuffer(_target, _handle); 21 | } 22 | 23 | void Buffer::bind(GLenum target) const { 24 | glBindBuffer(target, _handle); 25 | } 26 | 27 | void Buffer::unbind(void) const { 28 | glBindBuffer(_target, 0); 29 | } 30 | 31 | void Buffer::unbind(GLenum target) const { 32 | glBindBuffer(target, 0); 33 | } 34 | 35 | std::size_t Buffer::getSize(void) const { 36 | return _size; 37 | } 38 | 39 | GLuint Buffer::getHandle(void) const { 40 | return _handle; 41 | } 42 | 43 | } // MM::OpenGL 44 | 45 | -------------------------------------------------------------------------------- /framework/opengl_primitives/src/mm/opengl/buffer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by FlaXxy on 21.05.2018. 3 | // 4 | 5 | #pragma once 6 | 7 | #ifdef MM_OPENGL_3_GLES 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | #include 14 | #include // size_t 15 | 16 | namespace MM::OpenGL { 17 | /** 18 | * A fixed size buffer 19 | */ 20 | class Buffer { 21 | private: 22 | GLuint _handle = 0; 23 | std::size_t _size = 0; 24 | GLenum _target; 25 | 26 | public: 27 | Buffer(const void* data, std::size_t size, GLenum usage, GLenum target = GL_ARRAY_BUFFER); 28 | ~Buffer(void); 29 | 30 | void bind(void) const; 31 | void bind(GLenum target) const; 32 | void unbind(void) const; 33 | void unbind(GLenum target) const; 34 | 35 | std::size_t getSize(void) const; 36 | 37 | GLuint getHandle(void) const; 38 | }; 39 | } // MM::OpenGL 40 | 41 | -------------------------------------------------------------------------------- /framework/opengl_primitives/src/mm/opengl/components/texture.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../texture.hpp" 4 | 5 | namespace MM::Components::OpenGL { 6 | 7 | struct Texture { 8 | MM::OpenGL::Texture::handle_t tex; 9 | }; 10 | 11 | } // MM::Components::OpenGL 12 | 13 | -------------------------------------------------------------------------------- /framework/opengl_primitives/src/mm/opengl/fbo_builder.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "./frame_buffer_object.hpp" 6 | 7 | #include "./texture.hpp" 8 | 9 | namespace MM::OpenGL { 10 | 11 | class FBOBuilder { 12 | private: 13 | std::shared_ptr _fbo; 14 | FrameBufferObject::Target _currTarget = FrameBufferObject::Target::RW; 15 | 16 | private: 17 | FBOBuilder(void); 18 | 19 | public: 20 | ~FBOBuilder(void); 21 | FBOBuilder& operator=(FBOBuilder&) = delete; 22 | 23 | static FBOBuilder start(void); 24 | std::shared_ptr finish(void); 25 | 26 | FBOBuilder& setTarget(FrameBufferObject::Target target); 27 | 28 | FBOBuilder& attachTexture(std::shared_ptr tex, GLuint attachment_type = GL_COLOR_ATTACHMENT0); 29 | FBOBuilder& setResize(bool enable = true); 30 | FBOBuilder& setResizeFactors(float width = 1.f, float height = 1.f); 31 | }; 32 | 33 | } // MM::OpenGL 34 | 35 | -------------------------------------------------------------------------------- /framework/opengl_primitives/src/mm/opengl/frame_buffer_object.cpp: -------------------------------------------------------------------------------- 1 | #include "./frame_buffer_object.hpp" 2 | 3 | namespace MM::OpenGL { 4 | 5 | FrameBufferObject::FrameBufferObject(void) { 6 | glGenFramebuffers(1, &_fboID); 7 | } 8 | 9 | FrameBufferObject::~FrameBufferObject(void) { 10 | glDeleteFramebuffers(1, &_fboID); 11 | } 12 | 13 | void FrameBufferObject::bind(Target target) const { 14 | switch (target) { 15 | case Target::RW: 16 | glBindFramebuffer(GL_FRAMEBUFFER, _fboID); 17 | break; 18 | case Target::R: 19 | glBindFramebuffer(GL_READ_FRAMEBUFFER, _fboID); 20 | break; 21 | case Target::W: 22 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fboID); 23 | break; 24 | } 25 | } 26 | 27 | // TODO: refactor, make depth and stencil set-able 28 | void FrameBufferObject::clear(float r, float g, float b, float a, GLbitfield target_mask) { 29 | bind(FrameBufferObject::RW); 30 | 31 | glClearColor(r, g, b, a); 32 | //glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 33 | glClear(target_mask); 34 | } 35 | 36 | } // MM::OpenGL 37 | 38 | -------------------------------------------------------------------------------- /framework/opengl_primitives/src/mm/opengl/frame_buffer_object.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #ifdef MM_OPENGL_3_GLES 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | namespace MM::Services { 14 | class OpenGLRenderer; 15 | } // fwd 16 | 17 | namespace MM::OpenGL { 18 | 19 | class Texture; 20 | 21 | class FrameBufferObject { 22 | friend class FBOBuilder; 23 | friend class MM::Services::OpenGLRenderer; 24 | 25 | private: 26 | uint32_t _fboID; 27 | 28 | bool _resize = true; 29 | float _resize_factor_width = 1.f; 30 | float _resize_factor_height = 1.f; 31 | 32 | public: 33 | std::vector> _texAttachments; 34 | 35 | private: 36 | FrameBufferObject(void); 37 | 38 | public: 39 | ~FrameBufferObject(void); 40 | 41 | enum Target { 42 | R = 1 << 0, 43 | W = 1 << 1, 44 | RW = R | W 45 | }; 46 | void bind(Target target) const; 47 | //void unbind(void) const; 48 | 49 | void clear(float r, float g, float b, float a, GLbitfield target_mask = GL_COLOR_BUFFER_BIT); 50 | }; 51 | } // MM::OpenGL 52 | 53 | -------------------------------------------------------------------------------- /framework/opengl_primitives/src/mm/opengl/shader_builder.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "./shader.hpp" 4 | 5 | #include 6 | 7 | namespace MM::OpenGL { 8 | 9 | class ShaderBuilder { 10 | private: 11 | ShaderBuilder(void); 12 | 13 | struct stage_t { 14 | uint32_t id = 0; 15 | bool fail = false; 16 | }; 17 | 18 | enum stage_e { 19 | VERTEX = 0, 20 | FRAGMENT, 21 | stage_e_MAX 22 | }; 23 | 24 | stage_t _stages[stage_e_MAX]; 25 | 26 | struct transform_feedback_varying_t { 27 | std::string var; 28 | }; 29 | std::vector _tfs; 30 | 31 | bool _tf_interleaved = false; 32 | 33 | public: 34 | ~ShaderBuilder(void); 35 | ShaderBuilder& operator=(ShaderBuilder&) = delete; 36 | 37 | static ShaderBuilder start(void); 38 | std::shared_ptr finish(void); 39 | 40 | public: 41 | ShaderBuilder& addStageVertex(const std::string& shader_code); 42 | ShaderBuilder& addStageVertexF(MM::Engine& engine, const std::string& file_path); 43 | ShaderBuilder& addStageFragment(const std::string& shader_code); 44 | ShaderBuilder& addStageFragmentF(MM::Engine& engine, const std::string& file_path); 45 | // TODO: geometry and tesselation stages 46 | 47 | ShaderBuilder& addTransformFeedbackVarying(const std::string& var_name); 48 | ShaderBuilder& setTransformFeedbackInterleaved(bool interleaved = true); 49 | }; 50 | 51 | } // MM::OpenGL 52 | 53 | -------------------------------------------------------------------------------- /framework/opengl_primitives/src/mm/opengl/spritesheet.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "./texture.hpp" 4 | 5 | namespace MM::OpenGL { 6 | 7 | // a SpriteSheet is a texture divided evenly into a Grid 8 | struct SpriteSheet { 9 | MM::OpenGL::Texture::handle_t tex = nullptr; 10 | struct { 11 | uint32_t x = 1; 12 | uint32_t y = 1; 13 | } tile_count; 14 | }; 15 | 16 | } // MM::OpenGL 17 | 18 | -------------------------------------------------------------------------------- /framework/opengl_primitives/src/mm/opengl/texture.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::OpenGL { 6 | 7 | struct TextureLoaderFile; 8 | struct TextureLoaderConstBuffer; 9 | struct TextureLoaderSDLSurface; 10 | 11 | class Texture { 12 | private: 13 | uint32_t const _handle; 14 | 15 | private: 16 | friend struct TextureLoaderFile; 17 | friend struct TextureLoaderConstBuffer; 18 | friend struct TextureLoaderSDLSurface; 19 | 20 | Texture( 21 | uint32_t handle, 22 | int32_t width_, int32_t height_, 23 | int32_t internalFormat, int32_t format, int32_t type, 24 | uint32_t samples = 0u 25 | ); 26 | 27 | public: 28 | using handle_t = std::shared_ptr; 29 | 30 | int32_t const width; 31 | int32_t const height; 32 | //int32_t const bpp; // bits per pixel 33 | uint32_t const samples{0u}; // sample count, 0 == off 34 | 35 | private: 36 | int32_t const _internalFormat; 37 | int32_t const _format; 38 | int32_t const _type; 39 | 40 | public: 41 | ~Texture(); 42 | 43 | uint32_t getHandle(void) const; 44 | 45 | void bind(uint32_t slot) const; 46 | void unbind(void) const; 47 | 48 | void resize(int32_t new_width, int32_t new_height); 49 | 50 | static handle_t createEmpty(int32_t internalFormat, int32_t width, int32_t height, int32_t format, int32_t type); 51 | static handle_t createEmptyMultiSampled(int32_t internalFormat, int32_t width, int32_t height, uint32_t samples); 52 | }; 53 | 54 | } // MM::OpenGL 55 | 56 | -------------------------------------------------------------------------------- /framework/opengl_primitives/src/mm/opengl/texture_loader.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "./texture.hpp" 4 | 5 | #include 6 | 7 | // fwd 8 | typedef struct SDL_Surface SDL_Surface; 9 | namespace MM { 10 | class Engine; 11 | } 12 | 13 | namespace MM::OpenGL { 14 | 15 | struct TextureLoaderFile final { 16 | std::shared_ptr load(Engine& engine, const std::string& path) const; 17 | }; 18 | 19 | struct TextureLoaderConstBuffer final { 20 | std::shared_ptr load(const uint8_t* data, size_t size) const; 21 | }; 22 | 23 | struct TextureLoaderSDLSurface final { 24 | std::shared_ptr load(SDL_Surface* surface) const; 25 | }; 26 | 27 | struct TextureLoaderEmpty final { 28 | template 29 | std::shared_ptr load(Args&& ... args) const { 30 | return Texture::createEmpty(std::forward(args)...); 31 | } 32 | }; 33 | 34 | struct TextureLoaderEmptyMultiSampled final { 35 | template 36 | std::shared_ptr load(Args&& ... args) const { 37 | return Texture::createEmptyMultiSampled(std::forward(args)...); 38 | } 39 | }; 40 | 41 | } // MM::OpenGL 42 | 43 | -------------------------------------------------------------------------------- /framework/opengl_primitives/src/mm/opengl/vertex_array_object.cpp: -------------------------------------------------------------------------------- 1 | #include "./vertex_array_object.hpp" 2 | 3 | #ifdef MM_OPENGL_3_GLES 4 | #include 5 | #else 6 | #include 7 | #endif 8 | 9 | namespace MM::OpenGL { 10 | 11 | VertexArrayObject::VertexArrayObject(void) { 12 | glGenVertexArrays(1, &_rendererID); 13 | } 14 | 15 | VertexArrayObject::~VertexArrayObject(void) { 16 | glDeleteVertexArrays(1, &_rendererID); 17 | } 18 | 19 | void VertexArrayObject::bind(void) const { 20 | glBindVertexArray(_rendererID); 21 | } 22 | 23 | void VertexArrayObject::unbind(void) const { 24 | glBindVertexArray(0); 25 | } 26 | 27 | } // MM::OpenGL 28 | 29 | -------------------------------------------------------------------------------- /framework/opengl_primitives/src/mm/opengl/vertex_array_object.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::OpenGL { 6 | 7 | class VertexArrayObject { 8 | private: 9 | uint32_t _rendererID; 10 | 11 | public: 12 | VertexArrayObject(void); 13 | ~VertexArrayObject(void); 14 | 15 | void bind(void) const; 16 | void unbind(void) const; 17 | }; 18 | 19 | } // MM::OpenGL 20 | 21 | -------------------------------------------------------------------------------- /framework/opengl_primitives/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(opengl_fbo_test fbo_test.cpp) 2 | 3 | target_include_directories(opengl_fbo_test PRIVATE ".") 4 | 5 | target_link_libraries(opengl_fbo_test 6 | opengl_primitives 7 | sdl_service 8 | gtest_main 9 | ) 10 | 11 | add_test(NAME opengl_fbo_test COMMAND opengl_fbo_test) 12 | 13 | -------------------------------------------------------------------------------- /framework/opengl_primitives/test/fbo_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | using FBO = MM::OpenGL::FrameBufferObject; 11 | using FBOBuilder = MM::OpenGL::FBOBuilder; 12 | using Texture = MM::OpenGL::Texture; 13 | 14 | class FBOTest : public ::testing::Test { 15 | protected: 16 | MM::Engine engine; 17 | 18 | void SetUp(void) override { 19 | // setup sdl 20 | auto& sdl_s = engine.addService(); 21 | ASSERT_TRUE(engine.enableService()); 22 | 23 | sdl_s.createGLWindow("rendering_fbo_test", 800, 600); 24 | ASSERT_NE(sdl_s.win, nullptr); 25 | } 26 | }; 27 | 28 | TEST_F(FBOTest, builder_fail) { 29 | auto fbo = MM::OpenGL::FBOBuilder::start() 30 | .finish(); 31 | 32 | ASSERT_FALSE(fbo); 33 | } 34 | 35 | TEST_F(FBOTest, builder_basic) { 36 | auto[w, h] = engine.getService().getWindowSize(); 37 | 38 | { 39 | auto tex = Texture::createEmpty(GL_RGB, w, h, GL_RGB, GL_UNSIGNED_BYTE); 40 | ASSERT_TRUE(tex); 41 | 42 | auto fbo = FBOBuilder::start() 43 | .attachTexture(tex) 44 | .finish(); 45 | 46 | ASSERT_TRUE(fbo); 47 | } 48 | { 49 | auto fbo = FBOBuilder::start() 50 | .attachTexture(Texture::createEmpty(GL_RGB, w, h, GL_RGB, GL_UNSIGNED_BYTE)) 51 | .finish(); 52 | 53 | ASSERT_TRUE(fbo); 54 | } 55 | } 56 | 57 | int main(int argc, char** argv) { 58 | ::testing::InitGoogleTest(&argc, argv); 59 | 60 | return RUN_ALL_TESTS(); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/bloom.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "./render_task.hpp" 6 | 7 | namespace MM::OpenGL { 8 | 9 | // helper function to setup a bloom blur and recombine chain 10 | // creates (texture) rendertarget, fbos and rendertasks 11 | // outputs blur to "blur_tmp1" texture 12 | // 13 | // you still need to add the Composition rendertask (or eqv) your self, eg: 14 | // auto& comp = rs.addRenderTask(engine); 15 | // comp.color_tex = "hdr_color"; 16 | // comp.bloom_tex = "blur_tmp1"; 17 | // comp.target_fbo = "display"; 18 | void setup_bloom( 19 | MM::Engine& engine, 20 | const std::string color_src_tex = "hdr_color", // texture to extract color from 21 | const size_t bloom_phases = 5, // number of downsampled blurs (4 prob fine for 720, 5 for 1080) 22 | const float bloom_in_scale = 0.5f, // scale of bloom extraction layer (1 - 0.5 best, lower for more perf) 23 | const float bloom_phase_scale = 0.5f // ammount of scaling per downsampling 24 | ); 25 | 26 | } // MM::OpenGL 27 | 28 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/components/lite_particles2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include // tmp 6 | 7 | namespace MM::Components { 8 | 9 | // not intended to be a component 10 | // see LiteParticles2DUploadQueue 11 | struct LiteParticle2D { 12 | uint32_t type_id {0u}; // entt::hashed_string, ResourceManager 13 | 14 | glm::vec2 pos {0.f, 0.f}; 15 | glm::vec2 vel {0.f, 0.f}; 16 | 17 | float age {0.f}; 18 | }; 19 | 20 | struct LiteParticles2DUploadQueue { 21 | // TODO: vector 22 | std::queue queue; 23 | }; 24 | 25 | } // MM::Components 26 | 27 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/lite_particles2d_type_loader.cpp: -------------------------------------------------------------------------------- 1 | #include "./lite_particles2d_type_loader.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::OpenGL { 8 | 9 | std::shared_ptr LiteParticles2DTypeLoaderJson::load(const nlohmann::json& j) const { 10 | auto new_type = std::make_shared(); 11 | 12 | try { 13 | *new_type = j; 14 | } catch (...) { 15 | SPDLOG_ERROR("failed parsing particle type json:\n{}", j.dump(2)); 16 | return nullptr; 17 | } 18 | 19 | return new_type; 20 | } 21 | 22 | std::shared_ptr LiteParticles2DTypeLoaderFile::load(MM::Engine& engine, const std::string& path) const { 23 | auto* fs = engine.tryService(); 24 | if (fs == nullptr) { 25 | // TODO: error 26 | return nullptr; 27 | } 28 | 29 | auto new_particle = LiteParticles2DTypeLoaderJson{}.load(fs->readJson(path.c_str())); 30 | 31 | if (!new_particle) { 32 | SPDLOG_ERROR("particle type file: '{}'", path); 33 | } 34 | 35 | return new_particle; 36 | } 37 | 38 | } // MM::OpenGL 39 | 40 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/lite_particles2d_type_loader.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "./lite_particles2d_type.hpp" 4 | 5 | #include 6 | 7 | namespace MM::OpenGL { 8 | 9 | struct LiteParticles2DTypeLoaderJson final { 10 | std::shared_ptr load(const nlohmann::json& j) const; 11 | }; 12 | 13 | struct LiteParticles2DTypeLoaderFile final { 14 | std::shared_ptr load(MM::Engine& engine, const std::string& path) const; 15 | }; 16 | 17 | } // MM::OpenGL 18 | 19 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_task.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | // fwd 6 | namespace MM { 7 | class Engine; 8 | namespace Services { 9 | class OpenGLRenderer; 10 | } 11 | } 12 | 13 | #ifdef MM_OPENGL_3_GLES 14 | #define GLSL_VERSION_STRING "#version 300 es\n" 15 | #else 16 | #define GLSL_VERSION_STRING "#version 330 core\n" 17 | #endif 18 | 19 | namespace MM::OpenGL { 20 | 21 | class RenderTask { 22 | public: 23 | virtual ~RenderTask(void) = default; 24 | 25 | virtual const char* name(void) = 0;//{ return "NoName"; }; 26 | 27 | virtual void render(Services::OpenGLRenderer& rs, Engine& engine) = 0; 28 | 29 | // a place to reload/compile shaders etc. 30 | //virtual void reload(void) {} // TODO: remove 31 | //virtual std::vector getShaderPaths(void) {return {};} // TODO: remove 32 | }; 33 | } // MM:OpenGL 34 | 35 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/batched_spritesheet.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../render_task.hpp" 4 | #include 5 | 6 | #include 7 | 8 | //#include 9 | #include 10 | 11 | #include 12 | 13 | // fwd 14 | namespace MM::OpenGL { 15 | class Shader; 16 | class Buffer; 17 | class VertexArrayObject; 18 | } 19 | 20 | 21 | namespace MM::OpenGL::RenderTasks { 22 | 23 | class BatchedSpriteSheet : public RenderTask { 24 | private: 25 | std::shared_ptr _shader; 26 | std::unique_ptr _vertexBuffer; 27 | std::unique_ptr _vao; 28 | 29 | struct gl_instance_data { 30 | glm::mat4 pos_trans; 31 | glm::vec4 color; 32 | uint32_t tile_index; 33 | }; 34 | std::unique_ptr> gl_inst_buffer; 35 | 36 | 37 | public: 38 | glm::vec4 default_color {1.f, 1.f, 1.f, 1.f}; 39 | 40 | BatchedSpriteSheet(Engine& engine); 41 | ~BatchedSpriteSheet(void); 42 | 43 | const char* name(void) override { return "BatchedSpriteSheet"; } 44 | 45 | void render(Services::OpenGLRenderer& rs, Engine& engine) override; 46 | 47 | public: 48 | const char* vertexPath = "shader/batched_spritesheet_render_task/vert.glsl"; 49 | const char* fragmentPath = "shader/batched_spritesheet_render_task/frag.glsl"; 50 | 51 | std::string target_fbo = "display"; 52 | 53 | private: 54 | void setupShaderFiles(void); 55 | }; 56 | 57 | } // MM::OpenGL::RenderTasks 58 | 59 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/blit_fb.cpp: -------------------------------------------------------------------------------- 1 | #include "./blit_fb.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::OpenGL::RenderTasks { 8 | 9 | BlitFB::BlitFB(Engine& engine) { 10 | // assuming fbo textures are the size of the window buffer 11 | auto [x, y] = engine.getService().getWindowSize(); 12 | 13 | srcX1 = x; 14 | srcY1 = y; 15 | 16 | dstX1 = x; 17 | dstY1 = y; 18 | } 19 | 20 | BlitFB::~BlitFB(void) { 21 | } 22 | 23 | void BlitFB::render(Services::OpenGLRenderer& rs, Engine&) { 24 | ZoneScopedN("MM::OpenGL::RenderTasks::BlitFB::render"); 25 | 26 | rs.targets[read_fbo]->bind(FrameBufferObject::R); 27 | rs.targets[write_fbo]->bind(FrameBufferObject::W); 28 | 29 | glBlitFramebuffer( 30 | srcX0, srcY0, 31 | srcX1, srcY1, 32 | dstX0, dstY0, 33 | dstX1, dstY1, 34 | mask, 35 | filter 36 | ); 37 | } 38 | 39 | } // MM::OpenGL::RenderTasks 40 | 41 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/blit_fb.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../render_task.hpp" 4 | 5 | #include 6 | 7 | namespace MM::OpenGL::RenderTasks { 8 | 9 | class BlitFB : public RenderTask { 10 | public: 11 | BlitFB(Engine& engine); 12 | ~BlitFB(void); 13 | 14 | const char* name(void) override { return "BlitFB"; } 15 | 16 | void render(Services::OpenGLRenderer& rs, Engine& engine) override; 17 | 18 | public: 19 | std::string read_fbo = "game_view"; 20 | std::string write_fbo = "display"; 21 | 22 | // blit params 23 | GLint srcX0 = 0; 24 | GLint srcY0 = 0; 25 | GLint srcX1 = 0; // u will want to set this 26 | GLint srcY1 = 0; // u will want to set this 27 | 28 | GLint dstX0 = 0; 29 | GLint dstY0 = 0; 30 | GLint dstX1 = 0; // u will want to set this 31 | GLint dstY1 = 0; // u will want to set this 32 | 33 | GLbitfield mask = GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT; 34 | GLenum filter = GL_NEAREST; 35 | }; 36 | 37 | } // MM::OpenGL::RenderTasks 38 | 39 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/bloom_combine.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace MM::OpenGL::RenderTasks { 9 | 10 | class BloomCombine : public RenderTask { 11 | private: 12 | std::shared_ptr _shader; 13 | std::unique_ptr _vertexBuffer; 14 | std::unique_ptr _vao; 15 | 16 | public: 17 | BloomCombine(Engine& engine); 18 | ~BloomCombine(void); 19 | 20 | const char* name(void) override { return "BloomCombine"; } 21 | 22 | void render(Services::OpenGLRenderer& rs, Engine& engine) override; 23 | 24 | public: 25 | const char* vertexPath {"shader/combine_render_task/vert.glsl"}; 26 | const char* fragmentPath {"shader/combine_render_task/frag.glsl"}; 27 | 28 | std::string target_fbo {"display"}; 29 | 30 | std::string tex0 {"tex0"}; // lower res 31 | std::string tex1 {"tex1"}; 32 | 33 | void reloadShaders(Engine& engine); 34 | 35 | private: 36 | void setupShaderFiles(void); 37 | }; 38 | 39 | } // MM::OpenGL::RenderTasks 40 | 41 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/bloom_extraction.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace MM::OpenGL::RenderTasks { 9 | 10 | class BloomExtraction : public RenderTask { 11 | private: 12 | std::shared_ptr _shader; 13 | std::unique_ptr _vertexBuffer; 14 | std::unique_ptr _vao; 15 | 16 | public: 17 | BloomExtraction(Engine& engine); 18 | ~BloomExtraction(void); 19 | 20 | const char* name(void) override { return "BloomExtraction"; } 21 | 22 | void render(Services::OpenGLRenderer& rs, Engine& engine) override; 23 | 24 | public: 25 | const char* vertexPath {"shader/bloom_extraction_render_task/vert.glsl"}; 26 | const char* fragmentPath {"shader/bloom_extraction_render_task/frag.glsl"}; 27 | 28 | std::string target_fbo {"display"}; 29 | 30 | std::string src_tex {"hdr_color"}; 31 | 32 | void reloadShaders(Engine& engine); 33 | 34 | private: 35 | void setupShaderFiles(void); 36 | }; 37 | 38 | } // MM::OpenGL::RenderTasks 39 | 40 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/blur.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../render_task.hpp" 4 | #include 5 | 6 | #include 7 | 8 | // fwd 9 | namespace MM::OpenGL { 10 | class Shader; 11 | class Buffer; 12 | class VertexArrayObject; 13 | } 14 | 15 | namespace MM::OpenGL::RenderTasks { 16 | 17 | // this task expects to read and write to textures 18 | class Blur : public RenderTask { 19 | private: 20 | std::shared_ptr _shader; 21 | std::unique_ptr _vertexBuffer; 22 | std::unique_ptr _vao; 23 | 24 | public: 25 | Blur(Engine& engine); 26 | ~Blur(void); 27 | 28 | const char* name(void) override { return "Blur"; } 29 | 30 | void render(Services::OpenGLRenderer& rs, Engine& engine) override; 31 | 32 | public: 33 | const char* vertexPath {"shader/blur_render_task/vert.glsl"}; 34 | const char* fragmentPath {"shader/blur_render_task/frag_h.glsl"}; 35 | 36 | std::string out_fbo {"blur_io"}; 37 | std::string temp_fbo {"blur_temp"}; 38 | 39 | // bc of it beeing a 2 pass, we need to flipflop 40 | std::string in_tex {"blur_io"}; 41 | std::string out_tex {"blur_io"}; 42 | std::string temp_tex {"blur_temp"}; 43 | 44 | // kernel lookup offset factor 45 | glm::vec2 tex_offset_factor {1.f, 1.f}; 46 | 47 | private: 48 | void setupShaderFiles(void); 49 | }; 50 | 51 | } // MM::OpenGL::RenderTasks 52 | 53 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/clear.cpp: -------------------------------------------------------------------------------- 1 | #include "./clear.hpp" 2 | 3 | //#include 4 | 5 | namespace MM::OpenGL::RenderTasks { 6 | 7 | Clear::Clear(Engine&) { 8 | } 9 | 10 | Clear::~Clear(void) { 11 | } 12 | 13 | void Clear::render(Services::OpenGLRenderer& rs, Engine&) { 14 | //ZoneScopedN("MM::OpenGL::RenderTasks::Clear::render"); 15 | rs.targets[target_fbo]->clear(r,g,b,a,mask); 16 | } 17 | 18 | } // MM::OpenGL::RenderTasks 19 | 20 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/clear.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::OpenGL::RenderTasks { 6 | 7 | class Clear : public RenderTask { 8 | public: 9 | Clear(Engine& engine); 10 | ~Clear(void); 11 | 12 | const char* name(void) override { return "Clear"; } 13 | 14 | void render(Services::OpenGLRenderer& rs, Engine& engine) override; 15 | 16 | public: 17 | std::string target_fbo = "display"; 18 | 19 | float r = 0.f; 20 | float g = 0.f; 21 | float b = 0.f; 22 | float a = 1.f; 23 | 24 | GLbitfield mask = GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT; 25 | }; 26 | 27 | } // MM::OpenGL::RenderTasks 28 | 29 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/composition.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace MM::OpenGL::RenderTasks { 9 | 10 | class Composition : public MM::OpenGL::RenderTask { 11 | private: 12 | std::shared_ptr _shader; 13 | std::unique_ptr _vertexBuffer; 14 | std::unique_ptr _vao; 15 | 16 | public: 17 | Composition(MM::Engine& engine); 18 | ~Composition(void); 19 | 20 | const char* name(void) override { return "Composition"; } 21 | 22 | void render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) override; 23 | 24 | public: 25 | const char* vertexPath {"shader/composition_render_task/vert.glsl"}; 26 | const char* fragmentPath {"shader/composition_render_task/frag.glsl"}; 27 | 28 | std::string target_fbo {"display"}; 29 | 30 | std::string color_tex {"hdr_color"}; 31 | std::string bloom_tex {"bloom"}; 32 | 33 | float bloom_factor {0.8f}; 34 | 35 | void reloadShaders(MM::Engine& engine); 36 | 37 | private: 38 | void setupShaderFiles(void); 39 | }; 40 | 41 | } // MM::OpenGL::RenderTasks 42 | 43 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/copy_to_fb.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../render_task.hpp" 4 | #include 5 | 6 | // fwd 7 | namespace MM::OpenGL { 8 | class Shader; 9 | class Buffer; 10 | class VertexArrayObject; 11 | } 12 | 13 | namespace MM::OpenGL::RenderTasks { 14 | 15 | class CopyToFB : public RenderTask { 16 | private: 17 | std::shared_ptr _shader; 18 | std::unique_ptr _vertexBuffer; 19 | std::unique_ptr _vao; 20 | 21 | public: 22 | CopyToFB(Engine& engine); 23 | ~CopyToFB(void); 24 | 25 | const char* name(void) override { return "CopyToFB"; } 26 | 27 | void render(Services::OpenGLRenderer& rs, Engine& engine) override; 28 | 29 | public: 30 | const char* vertexPath = "shader/copy_to_fb_render_task/vert.glsl"; 31 | const char* fragmentPath = "shader/copy_to_fb_render_task/frag.glsl"; 32 | 33 | std::string target_fbo = "display"; 34 | std::string src_tex = "game_view"; 35 | 36 | void reloadShaders(Engine& engine); 37 | 38 | private: 39 | void setupShaderFiles(void); 40 | }; 41 | 42 | } // MM::OpenGL::RenderTasks 43 | 44 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/fast_sky_render_task.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | // fwd 8 | namespace MM::OpenGL { 9 | class Shader; 10 | class Buffer; 11 | class VertexArrayObject; 12 | 13 | namespace RenderTasks { 14 | 15 | struct FastSkyContext { 16 | float time = 0.f; 17 | 18 | float cirrus = 0.4f; 19 | float cumulus = 0.8f; 20 | 21 | glm::vec3 fsun {0,0,1}; 22 | }; 23 | 24 | class FastSky : public MM::OpenGL::RenderTask { 25 | private: 26 | std::shared_ptr _shader; 27 | std::unique_ptr _vertexBuffer; 28 | std::unique_ptr _vao; 29 | 30 | FastSkyContext _default_context; 31 | 32 | public: 33 | FastSky(MM::Engine& engine); 34 | ~FastSky(void); 35 | 36 | const char* name(void) override { return "FastSky"; } 37 | 38 | void render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) override; 39 | 40 | public: 41 | const char* vertexPath = "shader/fast_sky_render_task/vert.glsl"; 42 | const char* fragmentPath = "shader/fast_sky_render_task/frag.glsl"; 43 | 44 | std::string target_fbo = "display"; 45 | 46 | void reloadShaders(MM::Engine& engine); 47 | 48 | private: 49 | void setupShaderFiles(void); 50 | }; 51 | 52 | } // RenderTasks 53 | 54 | } // MM::OpenGL 55 | 56 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/imgui.cpp: -------------------------------------------------------------------------------- 1 | #include // bc imgui.hpp is overused 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #ifndef MM_OPENGL_3_GLES 10 | #include 11 | #else 12 | #define TracyGpuContext 13 | #define TracyGpuCollect 14 | #define TracyGpuZone(...) 15 | #endif 16 | 17 | namespace MM::OpenGL::RenderTasks { 18 | 19 | ImGuiRT::ImGuiRT(Engine&) { 20 | assert(ImGui::GetCurrentContext()); 21 | } 22 | 23 | ImGuiRT::~ImGuiRT(void) { 24 | } 25 | 26 | void ImGuiRT::render(Services::OpenGLRenderer& rs, Engine&) { 27 | ZoneScopedN("MM::OpenGL::RenderTasks::ImGuiRT::render"); 28 | TracyGpuZone("MM::OpenGL::RenderTasks::ImGuiRT::render"); 29 | 30 | rs.targets[target_fbo]->bind(FrameBufferObject::W); 31 | 32 | // render 33 | ImGui::Render(); 34 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); 35 | } 36 | 37 | } // MM::OpenGL::RenderTasks 38 | 39 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/imgui.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../render_task.hpp" 4 | #include 5 | 6 | namespace MM::OpenGL::RenderTasks { 7 | 8 | // RT to avoid name collisons 9 | class ImGuiRT : public RenderTask { 10 | public: 11 | ImGuiRT(Engine& engine); 12 | ~ImGuiRT(void); 13 | 14 | const char* name(void) override { return "ImGuiRT"; } 15 | 16 | void render(Services::OpenGLRenderer& rs, Engine& engine) override; 17 | 18 | public: 19 | std::string target_fbo = "display"; 20 | }; 21 | 22 | } // MM::OpenGL::RenderTasks 23 | 24 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/simple_rect.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../render_task.hpp" 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | // fwd 11 | namespace MM::OpenGL { 12 | class Shader; 13 | class Buffer; 14 | class VertexArrayObject; 15 | } 16 | 17 | namespace MM::OpenGL::RenderTasks { 18 | 19 | class SimpleRect : public RenderTask { 20 | private: 21 | std::shared_ptr _shader; 22 | std::unique_ptr _vertexBuffer; 23 | std::unique_ptr _vao; 24 | 25 | public: 26 | glm::vec4 default_color {1,1,1,1}; 27 | 28 | SimpleRect(Engine& engine); 29 | ~SimpleRect(void); 30 | 31 | const char* name(void) override { return "SimpleRect"; } 32 | 33 | void render(Services::OpenGLRenderer& rs, Engine& engine) override; 34 | 35 | public: 36 | const char* vertexPath = "shader/simple_rect_render_task/vert.glsl"; 37 | const char* fragmentPath = "shader/simple_rect_render_task/frag.glsl"; 38 | 39 | std::string target_fbo = "display"; 40 | 41 | private: 42 | void setupShaderFiles(void); 43 | }; 44 | 45 | } // MM::OpenGL::RenderTasks 46 | 47 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/simple_sprite.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../render_task.hpp" 4 | #include 5 | 6 | #include 7 | 8 | //#include 9 | #include 10 | 11 | // fwd 12 | namespace MM::OpenGL { 13 | class Shader; 14 | class Buffer; 15 | class VertexArrayObject; 16 | } 17 | 18 | namespace MM::OpenGL::RenderTasks { 19 | 20 | class SimpleSprite : public RenderTask { 21 | private: 22 | std::shared_ptr _shader; 23 | std::unique_ptr _vertexBuffer; 24 | std::unique_ptr _vao; 25 | 26 | public: 27 | glm::vec4 default_color {1,1,1,1}; 28 | 29 | SimpleSprite(Engine& engine); 30 | ~SimpleSprite(void); 31 | 32 | const char* name(void) override { return "SimpleSprite"; } 33 | 34 | void render(Services::OpenGLRenderer& rs, Engine& engine) override; 35 | 36 | public: 37 | const char* vertexPath = "shader/simple_sprite_render_task/vert.glsl"; 38 | const char* fragmentPath = "shader/simple_sprite_render_task/frag.glsl"; 39 | 40 | std::string target_fbo = "display"; 41 | 42 | private: 43 | void setupShaderFiles(void); 44 | }; 45 | 46 | } // MM::OpenGL::RenderTasks 47 | 48 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/simple_spritesheet.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../render_task.hpp" 4 | #include 5 | 6 | #include 7 | 8 | //#include 9 | #include 10 | 11 | // fwd 12 | namespace MM::OpenGL { 13 | class Shader; 14 | class Buffer; 15 | class VertexArrayObject; 16 | } 17 | 18 | namespace MM::OpenGL::RenderTasks { 19 | 20 | class SimpleSpriteSheet : public RenderTask { 21 | private: 22 | std::shared_ptr _shader; 23 | std::unique_ptr _vertexBuffer; 24 | std::unique_ptr _vao; 25 | 26 | public: 27 | glm::vec4 default_color {1.f, 1.f, 1.f, 1.f}; 28 | 29 | SimpleSpriteSheet(Engine& engine); 30 | ~SimpleSpriteSheet(void); 31 | 32 | const char* name(void) override { return "SimpleSpriteSheet"; } 33 | 34 | void render(Services::OpenGLRenderer& rs, Engine& engine) override; 35 | 36 | public: 37 | const char* vertexPath = "shader/simple_spritesheet_render_task/vert.glsl"; 38 | const char* fragmentPath = "shader/simple_spritesheet_render_task/frag.glsl"; 39 | 40 | std::string target_fbo = "display"; 41 | 42 | private: 43 | void setupShaderFiles(void); 44 | }; 45 | 46 | } // MM::OpenGL::RenderTasks 47 | 48 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/spritesheet_renderable.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::OpenGL { 6 | 7 | struct SpriteSheetRenderable { 8 | SpriteSheet sp; 9 | 10 | uint32_t tile_index = 0; 11 | }; 12 | 13 | } // MM::OpenGL 14 | 15 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/tilemap.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | //#include 7 | #include 8 | 9 | // fwd 10 | namespace MM::OpenGL { 11 | class Shader; 12 | class Buffer; 13 | class VertexArrayObject; 14 | } 15 | 16 | namespace MM::OpenGL::RenderTasks { 17 | 18 | class Tilemap : public RenderTask { 19 | private: 20 | std::shared_ptr _shader; 21 | std::unique_ptr _vertexBuffer; 22 | std::unique_ptr _vao; 23 | 24 | public: 25 | Tilemap(MM::Engine& engine); 26 | ~Tilemap(void); 27 | 28 | const char* name(void) override { return "Tilemap"; } 29 | 30 | void render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) override; 31 | 32 | public: 33 | const char* vertexPath = "shader/tilemap_render_task/vert.glsl"; 34 | const char* fragmentPath = "shader/tilemap_render_task/frag.glsl"; 35 | 36 | std::string target_fbo = "display"; 37 | 38 | glm::vec3 ambient_color {1.f, 1.f, 1.f}; 39 | 40 | private: 41 | void setupShaderFiles(void); 42 | }; 43 | 44 | } // MM::OpenGL::RenderTasks 45 | 46 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/render_tasks/tilemap_renderable.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace MM::OpenGL { 14 | 15 | struct TilemapRenderable { 16 | struct Tile { 17 | float pos[2]; 18 | uint32_t sprite_sheet_index; 19 | //float color[3] = {1.f, 1.f, 1.f}; 20 | 21 | static void setupGLBindings(void) { 22 | static_assert(std::is_standard_layout::value); // check if offsetof() is usable 23 | 24 | glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Tile), (void*) offsetof(Tile, pos)); 25 | glVertexAttribIPointer(2, 1, GL_UNSIGNED_INT, sizeof(Tile), (void*) offsetof(Tile, sprite_sheet_index)); 26 | //glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Tile), (void*) offsetof(Tile, color)); 27 | } 28 | } /*__attribute__((packed))*/; 29 | 30 | struct SpriteLayer { 31 | MM::OpenGL::SpriteSheet sprite_sheet; 32 | 33 | std::vector map; // TODO: move this to tilemap 34 | std::shared_ptr> map_buffer = std::make_shared>(); 35 | 36 | void syncMapBuffer(void) { 37 | auto* arr = map_buffer->map(map.size(), GL_STATIC_DRAW); 38 | std::memcpy(arr, map.data(), map.size() * sizeof(Tile)); 39 | 40 | map_buffer->unmap(); 41 | } 42 | }; 43 | 44 | std::vector sprite_layer; 45 | //float z = 0.f; // TODO: use Components::Position2D_ZOffset instead 46 | }; 47 | 48 | } // MM::OpenGL 49 | 50 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/res/default_texture.h: -------------------------------------------------------------------------------- 1 | unsigned char default_png[] = { 2 | 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 3 | 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 4 | 0x08, 0x06, 0x00, 0x00, 0x00, 0x73, 0x7a, 0x7a, 0xf4, 0x00, 0x00, 0x00, 5 | 0x78, 0x49, 0x44, 0x41, 0x54, 0x58, 0x85, 0xed, 0x96, 0xb1, 0x11, 0x80, 6 | 0x30, 0x0c, 0x03, 0x65, 0x46, 0x33, 0x25, 0x6b, 0xa4, 0x0d, 0xc3, 0x24, 7 | 0x2d, 0x3b, 0x50, 0x51, 0xe2, 0xd5, 0xc2, 0x06, 0x72, 0x87, 0x1b, 0xb9, 8 | 0xfd, 0x3b, 0xdf, 0x9f, 0x0a, 0xd9, 0x36, 0xd0, 0x16, 0xc8, 0x74, 0x1c, 9 | 0x0c, 0x63, 0xf7, 0x49, 0x79, 0x44, 0x50, 0xbe, 0x51, 0xfa, 0xc3, 0x48, 10 | 0x40, 0x02, 0x12, 0xb0, 0x85, 0x9b, 0xf6, 0xc0, 0xc4, 0x43, 0x17, 0x9c, 11 | 0xb8, 0x28, 0x77, 0x77, 0xca, 0xcb, 0x13, 0x90, 0x80, 0x04, 0x24, 0x60, 12 | 0xee, 0x4e, 0x7b, 0x20, 0xbb, 0xe7, 0x03, 0x8d, 0xf2, 0xec, 0x9f, 0x28, 13 | 0x4f, 0x40, 0x02, 0x12, 0x90, 0x80, 0x01, 0xa0, 0x3d, 0x90, 0xdd, 0xf3, 14 | 0x37, 0x3a, 0xe5, 0xd9, 0x3f, 0x51, 0x9e, 0x80, 0x04, 0x24, 0x20, 0x81, 15 | 0x0f, 0x49, 0xf4, 0x16, 0xa3, 0xb7, 0xbf, 0xe8, 0xa6, 0x00, 0x00, 0x00, 16 | 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82 17 | }; 18 | unsigned int default_png_len = 177; 19 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/opengl/res/shaders_builtin.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MM::OpenGL { 4 | 5 | // loads glsl files into const fs at "/shaders/builtin/" 6 | // file list: 7 | // - sampling.glsl 8 | // - tonemapping.glsl 9 | // - hashing.glsl 10 | // - noise.glsl 11 | void load_builtin_shaders_fs(void); 12 | 13 | } // MM::OpenGL 14 | 15 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/services/opengl_renderer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace MM::Services { 13 | 14 | class OpenGLRenderer : public Service { 15 | public: 16 | OpenGLRenderer(void); 17 | ~OpenGLRenderer(void); 18 | 19 | public: 20 | std::vector> render_tasks; 21 | std::unordered_map> targets; 22 | 23 | // add rendertask helper 24 | // TODO: forward args 25 | template 26 | RT_T& addRenderTask(::MM::Engine& engine) { 27 | return *(RT_T*)render_tasks.emplace_back(std::make_unique(engine)).get(); 28 | } 29 | 30 | private: 31 | SDLService::EventHandlerHandle _sdl_event_handle = nullptr; 32 | 33 | public: 34 | bool enable(Engine& engine, std::vector& task_array) override; 35 | void disable(Engine& engine) override; 36 | 37 | const char* name(void) override { return "OpenGLRendererService"; } 38 | 39 | private: 40 | void render(Engine& engine); 41 | }; 42 | 43 | } // namespace MM::Services 44 | 45 | -------------------------------------------------------------------------------- /framework/opengl_renderer/src/mm/services/opengl_renderer_tools.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::Services { 6 | 7 | class ImGuiOpenGLRendererTools : public Service { 8 | public: 9 | const char* name(void) override { return "ImGuiOpenGLRendererTools"; } 10 | 11 | bool enable(Engine& engine, std::vector& task_array) override; 12 | void disable(Engine& engine) override; 13 | 14 | private: 15 | bool _show_render_tasks = false; 16 | bool _show_texture_cache_legacy = false; 17 | 18 | private: 19 | void renderImGui(Engine& engine); 20 | 21 | void renderRenderTasks(Engine& engine); 22 | void renderTextureCacheLegacy(Engine& engine); 23 | }; 24 | 25 | } // namespace MM::Services 26 | 27 | -------------------------------------------------------------------------------- /framework/opengl_renderer/test/builtins.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | //#include 9 | 10 | #include 11 | #include 12 | 13 | #include // include only works on files rn 14 | 15 | static const char* argv0 = ""; 16 | 17 | TEST(builtins, all) { 18 | MM::Engine engine; 19 | 20 | engine.addService(argv0); 21 | ASSERT_TRUE(engine.enableService()); 22 | 23 | engine.addService(); 24 | ASSERT_TRUE(engine.enableService()); 25 | 26 | engine.addService(); 27 | ASSERT_TRUE(engine.enableService()); // adds builtins 28 | 29 | engine.update(); 30 | 31 | FS_CONST_MOUNT_FILE("/shaders/test_frag.glsl", 32 | GLSL_VERSION_STRING 33 | R"( 34 | #ifdef GL_ES 35 | precision mediump float; 36 | #endif 37 | 38 | #include "/shaders/builtin/sampling.glsl" 39 | #include "/shaders/builtin/tonemapping.glsl" 40 | #include "/shaders/builtin/hashing.glsl" 41 | #include "/shaders/builtin/noise.glsl" 42 | 43 | void main() { 44 | } 45 | )"); 46 | 47 | auto sb = MM::OpenGL::ShaderBuilder::start(); 48 | sb.addStageVertex("void main() { gl_Position = vec4(0.0); }"); 49 | sb.addStageFragmentF(engine, "/shaders/test_frag.glsl"); 50 | auto shader = sb.finish(); 51 | ASSERT_TRUE(shader); 52 | } 53 | 54 | int main(int argc, char** argv) { 55 | argv0 = argv[0]; 56 | 57 | ::testing::InitGoogleTest(&argc, argv); 58 | 59 | return RUN_ALL_TESTS(); 60 | } 61 | 62 | -------------------------------------------------------------------------------- /framework/opengl_renderer/test/opengl_renderer_s_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | TEST(opengl_renderer_s, basic) { 8 | MM::Engine engine; 9 | 10 | engine.addService(); 11 | ASSERT_TRUE(engine.enableService()); 12 | 13 | engine.addService(); 14 | ASSERT_TRUE(engine.enableService()); 15 | 16 | engine.update(); 17 | } 18 | 19 | int main(int argc, char** argv) { 20 | //argv0 = argv[0]; 21 | 22 | ::testing::InitGoogleTest(&argc, argv); 23 | 24 | return RUN_ALL_TESTS(); 25 | } 26 | 27 | -------------------------------------------------------------------------------- /framework/opengl_renderer/test/res/animation_running-1_ea_0.3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MadeOfJelly/MushMachine/4ec8f98ab0aab46a3e7f7d7d515280642a70d225/framework/opengl_renderer/test/res/animation_running-1_ea_0.3.png -------------------------------------------------------------------------------- /framework/opengl_renderer/test/res/animation_standing-1_ea_0.1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MadeOfJelly/MushMachine/4ec8f98ab0aab46a3e7f7d7d515280642a70d225/framework/opengl_renderer/test/res/animation_standing-1_ea_0.1.png -------------------------------------------------------------------------------- /framework/opengl_renderer/test/res/errig.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MadeOfJelly/MushMachine/4ec8f98ab0aab46a3e7f7d7d515280642a70d225/framework/opengl_renderer/test/res/errig.jpg -------------------------------------------------------------------------------- /framework/opengl_renderer/test/res/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MadeOfJelly/MushMachine/4ec8f98ab0aab46a3e7f7d7d515280642a70d225/framework/opengl_renderer/test/res/test.png -------------------------------------------------------------------------------- /framework/opengl_renderer/test/res/textures.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MadeOfJelly/MushMachine/4ec8f98ab0aab46a3e7f7d7d515280642a70d225/framework/opengl_renderer/test/res/textures.zip -------------------------------------------------------------------------------- /framework/organizer_scene/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(organizer_scene CXX) 4 | 5 | add_library(organizer_scene 6 | src/mm/services/organizer_scene.hpp 7 | src/mm/services/organizer_scene.cpp 8 | ) 9 | 10 | target_include_directories(organizer_scene PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 11 | 12 | target_link_libraries(organizer_scene 13 | engine 14 | common_components 15 | ) 16 | 17 | if (BUILD_TESTING) 18 | #add_subdirectory(test) 19 | endif() 20 | 21 | -------------------------------------------------------------------------------- /framework/organizer_scene/src/mm/services/organizer_scene.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::Services { 8 | 9 | // provides an ~implementation for SceneServiceInterface 10 | // !! IMPORTANT: relies on entt::organizer. Use it to add systems! 11 | class OrganizerSceneService : public SceneServiceInterface { 12 | private: 13 | std::unique_ptr _scene; 14 | std::unique_ptr _next_scene; // enqueued next scene 15 | 16 | using clock = std::chrono::steady_clock; 17 | double _accumulator = 0.0; 18 | std::chrono::time_point _last_time; 19 | 20 | public: 21 | const float f_delta; 22 | 23 | float initial_delta_factor = 1.f; 24 | 25 | public: // service 26 | explicit OrganizerSceneService(const float update_delta = 1.f/60.f) : f_delta(update_delta) {} 27 | 28 | const char* name(void) override { return "OrganizerSceneService"; } 29 | 30 | bool enable(Engine& engine, std::vector& task_array) override; 31 | void disable(Engine& engine) override; 32 | 33 | public: // scene interface 34 | Scene& getScene(void) override { return *_scene; } 35 | 36 | void changeScene(std::unique_ptr&& new_scene) override; 37 | 38 | // be carefull of that one 39 | void changeSceneNow(std::unique_ptr&& new_scene) override; 40 | 41 | public: 42 | void sceneFixedUpdate(Engine& engine); 43 | void changeSceneFixedUpdate(Engine& engine); 44 | 45 | void updateOrganizerVertices(Scene& scene); 46 | 47 | void resetTime(void); 48 | }; 49 | 50 | } // MM::Services 51 | 52 | -------------------------------------------------------------------------------- /framework/random/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(random CXX) 4 | 5 | add_library(random 6 | ./src/mm/random/srng.hpp 7 | ./src/mm/random/srng.cpp 8 | ) 9 | 10 | target_include_directories(random PUBLIC "src") 11 | 12 | target_compile_features(random PUBLIC cxx_std_17) 13 | 14 | target_link_libraries(random 15 | PUBLIC 16 | squirrel_noise 17 | std_utils 18 | ) 19 | 20 | ############################## 21 | 22 | #if (BUILD_TESTING) 23 | #add_subdirectory(test) 24 | #endif() 25 | 26 | -------------------------------------------------------------------------------- /framework/random/src/mm/random/srng.cpp: -------------------------------------------------------------------------------- 1 | #include "./srng.hpp" 2 | 3 | namespace MM::Random { 4 | 5 | template<> 6 | double SRNG::range(const ScalarRange2& range) { 7 | return zeroToOne() * (range.max() - range.min()) + range.min(); 8 | } 9 | 10 | template<> 11 | float SRNG::range(const ScalarRange2& range) { 12 | return zeroToOne() * (range.max() - range.min()) + range.min(); 13 | } 14 | 15 | } // MM::Random 16 | 17 | -------------------------------------------------------------------------------- /framework/random/src/mm/random/srng.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace MM::Random { 7 | 8 | // Seeded (Pseudo-) Random Number Generator 9 | struct SRNG { 10 | // make shuffle compat 11 | // TODO: add more type info 12 | using result_type = uint32_t; 13 | 14 | uint32_t seed = 1337; 15 | int32_t pos = 0; 16 | 17 | // basic 18 | 19 | uint32_t getNext(void) { 20 | return SquirrelNoise4::Get1dNoiseUint32(pos++, seed); 21 | } 22 | 23 | float zeroToOne(void) { 24 | return SquirrelNoise4::Get1dNoiseZeroToOne(pos++, seed); 25 | } 26 | 27 | float negOneToOne(void) { 28 | return SquirrelNoise4::Get1dNoiseNegOneToOne(pos++, seed); 29 | } 30 | 31 | // advanced 32 | 33 | uint32_t minMax(uint32_t min, uint32_t max) { 34 | return (getNext() % ((max - min) + 1)) + min; 35 | } 36 | 37 | bool roll(float prob) { 38 | return zeroToOne() <= prob; // TODO: just < ? 39 | } 40 | 41 | // more advanced 42 | 43 | // inclusive 44 | template 45 | T range(const ScalarRange2& range) { 46 | return (getNext() % ((range.max() - range.min()) + 1)) + range.min(); 47 | } 48 | 49 | // for conviniece 50 | uint32_t operator()(void) { 51 | return getNext(); 52 | } 53 | 54 | bool operator()(float prob) { 55 | return roll(prob); 56 | } 57 | 58 | // std:: distributions need those 59 | constexpr static uint32_t min(void) { 60 | return 0; 61 | } 62 | 63 | constexpr static uint32_t max(void) { 64 | return 0xffffffff; 65 | } 66 | }; 67 | 68 | template<> 69 | double SRNG::range(const ScalarRange2& range); 70 | 71 | template<> 72 | float SRNG::range(const ScalarRange2& range); 73 | 74 | } // MM::Random 75 | 76 | -------------------------------------------------------------------------------- /framework/resource_manager/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(resource_manager CXX) 4 | 5 | add_library(resource_manager INTERFACE) 6 | 7 | target_include_directories(resource_manager INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src") 8 | 9 | target_link_libraries(resource_manager INTERFACE 10 | entt 11 | logger 12 | ) 13 | 14 | if (BUILD_TESTING) 15 | add_subdirectory(test) 16 | endif() 17 | 18 | 19 | -------------------------------------------------------------------------------- /framework/resource_manager/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(resource_test 2 | resource_test.cpp 3 | ) 4 | 5 | target_include_directories(resource_test PRIVATE ".") 6 | 7 | target_link_libraries(resource_test 8 | #engine 9 | resource_manager 10 | gtest_main 11 | ) 12 | 13 | add_test(NAME resource_test COMMAND resource_test) 14 | 15 | -------------------------------------------------------------------------------- /framework/s6zer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(s6zer CXX) 4 | 5 | add_library(s6zer INTERFACE 6 | #./src/s6zer/stream.hpp 7 | #./src/s6zer/serialize.hpp 8 | ) 9 | 10 | add_library(MM::s6zer ALIAS s6zer) 11 | 12 | target_include_directories(s6zer INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src") 13 | 14 | target_compile_features(s6zer INTERFACE cxx_std_17) 15 | 16 | #target_link_libraries(s6zer 17 | #INTERFACE 18 | #) 19 | 20 | if (BUILD_TESTING) 21 | add_subdirectory(test) 22 | endif() 23 | 24 | -------------------------------------------------------------------------------- /framework/s6zer/src/mm/s6zer/serialize.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "./stream.hpp" 4 | 5 | namespace MM::s6zer { 6 | 7 | // serialize macros 8 | 9 | // TODO: make use of ADL, like nlohmann::json does. 10 | 11 | /* 12 | defines mm_serialize functions for you. 13 | a "stream" object is in scope (StreamWriter/StreamReader), 14 | as well as the object of Type called "data". 15 | eg: 16 | MM_DEFINE_SERIALIZE(Test1, 17 | MM_S6ZER_BAIL(stream.serializeBits(data.seq, 16)) 18 | MM_S6ZER_BAIL(stream.serializeBits(data.data1, 8)) 19 | ) 20 | */ 21 | // TODO: refine, so we dont have to do MM_S6ZER_BAIL() everytime 22 | #define MM_DEFINE_SERIALIZE(Type, ...) \ 23 | inline bool mm_serialize(MM::s6zer::StreamWriter& stream, const Type& data) { \ 24 | __VA_ARGS__ \ 25 | return true; \ 26 | } \ 27 | inline bool mm_serialize(MM::s6zer::StreamReader& stream, Type& data) { \ 28 | __VA_ARGS__ \ 29 | return true; \ 30 | } 31 | 32 | } // MM::s6zer 33 | 34 | -------------------------------------------------------------------------------- /framework/s6zer/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(s6zer_test 2 | test.cpp 3 | ) 4 | 5 | target_include_directories(s6zer_test PRIVATE ".") 6 | 7 | target_compile_features(s6zer_test PRIVATE cxx_std_17) 8 | 9 | target_link_libraries(s6zer_test 10 | gtest_main 11 | 12 | s6zer 13 | 14 | random 15 | ) 16 | 17 | add_test(NAME s6zer_test COMMAND s6zer_test) 18 | 19 | -------------------------------------------------------------------------------- /framework/screen_director/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(screen_director CXX) 4 | 5 | add_library(screen_director 6 | src/mm/services/screen_director.hpp 7 | src/mm/services/screen_director.cpp 8 | ) 9 | 10 | target_include_directories(screen_director PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 11 | 12 | target_link_libraries(screen_director 13 | engine 14 | logger 15 | entt 16 | ) 17 | 18 | if (BUILD_TESTING) 19 | add_subdirectory(test) 20 | endif() 21 | 22 | -------------------------------------------------------------------------------- /framework/screen_director/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(screen_director_test 2 | sd_test.cpp 3 | ) 4 | 5 | target_include_directories(screen_director_test PRIVATE ".") 6 | 7 | target_link_libraries(screen_director_test 8 | screen_director 9 | gtest_main 10 | ) 11 | 12 | add_test(NAME screen_director_test COMMAND screen_director_test) 13 | 14 | -------------------------------------------------------------------------------- /framework/sdl_service/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(sdl_service CXX) 4 | 5 | add_library(sdl_service 6 | src/mm/logo-f6c-square.png.h 7 | 8 | src/mm/services/sdl_service.hpp 9 | src/mm/services/sdl_service.cpp 10 | ) 11 | 12 | target_include_directories(sdl_service PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 13 | target_include_directories(sdl_service PUBLIC "${SDL2_INCLUDE_DIR}") 14 | 15 | target_link_libraries(sdl_service PUBLIC 16 | entt 17 | logger 18 | #glm 19 | engine 20 | ) 21 | 22 | 23 | #if android 24 | #target_link_libraries(sdl_service SDL) 25 | #endif 26 | 27 | if(EMSCRIPTEN) 28 | target_compile_options(sdl_service PUBLIC -sUSE_SDL=2) 29 | target_link_libraries(sdl_service PUBLIC -sUSE_SDL=2) 30 | elseif(VCPKG_TARGET_TRIPLET) 31 | find_package(SDL2 CONFIG REQUIRED) 32 | 33 | target_link_libraries(sdl_service 34 | PUBLIC 35 | SDL2::SDL2 36 | SDL2::SDL2main 37 | #SDL2::SDL2-static 38 | ) 39 | else() 40 | #if not android or emscripten 41 | find_package(SDL2 REQUIRED) 42 | target_include_directories(sdl_service PUBLIC "${SDL2_INCLUDE_DIR}") 43 | target_link_libraries(sdl_service PUBLIC ${SDL2_LIBRARY}) 44 | #endif 45 | endif() 46 | 47 | if(MM_OPENGL_3_GLES) 48 | target_link_libraries(sdl_service PRIVATE "GL") # TODO: make more specific 49 | else() 50 | target_link_libraries(sdl_service PRIVATE glad) 51 | endif() 52 | 53 | if(BUILD_TESTING) 54 | add_subdirectory(test) 55 | endif() 56 | 57 | -------------------------------------------------------------------------------- /framework/sdl_service/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(sdl_service_test start_test.cpp) 2 | 3 | target_include_directories(sdl_service_test PRIVATE ".") 4 | 5 | target_link_libraries(sdl_service_test 6 | sdl_service 7 | gtest_main 8 | ) 9 | 10 | add_test(NAME sdl_service_test COMMAND sdl_service_test) 11 | 12 | -------------------------------------------------------------------------------- /framework/simple_sdl_renderer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(simple_sdl_renderer_service CXX) 4 | 5 | add_library(simple_sdl_renderer_service 6 | src/mm/simple_sdl_renderer/target.hpp 7 | 8 | src/mm/services/simple_sdl_renderer.hpp 9 | src/mm/services/simple_sdl_renderer.cpp 10 | ) 11 | 12 | target_include_directories(simple_sdl_renderer_service PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 13 | target_include_directories(simple_sdl_renderer_service PUBLIC "${SDL2_INCLUDE_DIR}") 14 | 15 | target_link_libraries(simple_sdl_renderer_service 16 | engine 17 | glm 18 | sdl_service 19 | ) 20 | 21 | if (BUILD_TESTING) 22 | add_subdirectory(test) 23 | endif() 24 | 25 | -------------------------------------------------------------------------------- /framework/simple_sdl_renderer/src/mm/services/simple_sdl_renderer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace MM::Services { 12 | 13 | class SimpleSDLRendererService : public Service { 14 | public: 15 | SimpleSDLRendererService(void); 16 | ~SimpleSDLRendererService(void); 17 | 18 | SDL_Renderer* renderer = nullptr; 19 | 20 | std::unordered_map targets; 21 | 22 | std::vector> processors; 23 | 24 | 25 | public: 26 | bool enable(Engine& engine, std::vector& task_array) override; 27 | void disable(Engine& engine) override; 28 | 29 | const char* name(void) override { return "SimpleSDLServiceSystem"; }; 30 | 31 | private: 32 | void render(Engine& engine); 33 | }; 34 | 35 | } // namespace MM::Services 36 | 37 | -------------------------------------------------------------------------------- /framework/simple_sdl_renderer/src/mm/simple_sdl_renderer/target.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::SimpleSDLRenderer { 6 | 7 | struct Target { 8 | SDL_Texture* texture = nullptr; 9 | 10 | ~Target(void) { 11 | SDL_DestroyTexture(texture); 12 | } 13 | 14 | void reset(SDL_Renderer* ren, int width, int height) { 15 | if (texture) 16 | SDL_DestroyTexture(texture); 17 | 18 | texture = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, width, height); 19 | } 20 | 21 | void clear(SDL_Renderer* ren, SDL_Color col = {0,0,0,255}) { 22 | set(ren); 23 | SDL_SetRenderDrawColor(ren, col.r, col.g, col.b, col.a); 24 | SDL_RenderClear(ren); 25 | } 26 | 27 | void set(SDL_Renderer* ren) { 28 | SDL_SetRenderTarget(ren, texture); 29 | } 30 | }; 31 | 32 | } // MM::SimpleSDLRenderer 33 | 34 | -------------------------------------------------------------------------------- /framework/simple_sdl_renderer/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(simple_sdl_renderer_service_test 2 | start_test.cpp 3 | ) 4 | 5 | target_include_directories(simple_sdl_renderer_service_test PRIVATE ".") 6 | 7 | target_link_libraries(simple_sdl_renderer_service_test 8 | simple_sdl_renderer_service 9 | sdl_service 10 | gtest_main 11 | ) 12 | 13 | add_test(NAME simple_sdl_renderer_service_test COMMAND simple_sdl_renderer_service_test) 14 | 15 | -------------------------------------------------------------------------------- /framework/simple_sdl_renderer/test/start_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | TEST(simple_sdl_renderer, basic) { 11 | srand(1); 12 | MM::Engine engine; 13 | 14 | // sdl dep 15 | { 16 | engine.addService(); 17 | ASSERT_TRUE(engine.enableService()); 18 | } 19 | 20 | auto& ren = engine.addService(); 21 | ASSERT_TRUE(engine.enableService()); 22 | 23 | ren.processors.emplace_back([](auto& r, auto&) { 24 | r.targets["display"].set(r.renderer); 25 | 26 | SDL_Rect rect { 27 | rand() % 700, 28 | rand() % 500, 29 | 100, 30 | 100 31 | }; 32 | 33 | SDL_SetRenderDrawColor(r.renderer, 255, 0, 0, 255); 34 | SDL_RenderFillRect(r.renderer, &rect); 35 | } 36 | ); 37 | 38 | #ifdef MM_AUTOTEST 39 | engine.addService(50); // 50 frames 40 | ASSERT_TRUE(engine.enableService()); 41 | #endif 42 | 43 | engine.run(); 44 | } 45 | 46 | int main(int argc, char** argv) { 47 | ::testing::InitGoogleTest(&argc, argv); 48 | return RUN_ALL_TESTS(); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /framework/sound/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(sound_service CXX) 4 | 5 | add_library(sound_service 6 | src/mm/services/sound_service.hpp 7 | src/mm/services/sound_service.cpp 8 | ) 9 | 10 | target_include_directories(sound_service PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 11 | #target_include_directories(service_sound PUBLIC "${SDL2_INCLUDE_DIR}") 12 | 13 | target_link_libraries(sound_service 14 | #entt 15 | soloud 16 | logger 17 | engine 18 | ) 19 | 20 | ############################### 21 | 22 | add_library(soloud_json 23 | ./src/mm/soloud_json.hpp 24 | ./src/mm/soloud_json.cpp 25 | ) 26 | 27 | target_include_directories(soloud_json PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 28 | 29 | target_link_libraries(soloud_json 30 | soloud 31 | nlohmann_json::nlohmann_json 32 | ) 33 | 34 | ############################### 35 | 36 | add_library(filesystem_soloud_file 37 | ./src/mm/soloud_filesystem_file_impl.hpp 38 | ./src/mm/soloud_filesystem_file_impl.cpp 39 | 40 | ./src/mm/sound_loader_wav.hpp 41 | ./src/mm/sound_loader_wav.cpp 42 | ./src/mm/sound_loader_sfxr.hpp 43 | ./src/mm/sound_loader_sfxr.cpp 44 | ) 45 | 46 | target_link_libraries(filesystem_soloud_file 47 | filesystem_service 48 | soloud 49 | soloud_json 50 | ) 51 | 52 | if (BUILD_TESTING) 53 | add_subdirectory(test) 54 | endif() 55 | 56 | -------------------------------------------------------------------------------- /framework/sound/src/mm/services/sound_service.cpp: -------------------------------------------------------------------------------- 1 | #include "./sound_service.hpp" 2 | 3 | #include 4 | 5 | #include 6 | #define LOG_CRIT(...) __LOG_CRIT( "Sound", __VA_ARGS__) 7 | #define LOG_ERROR(...) __LOG_ERROR("Sound", __VA_ARGS__) 8 | #define LOG_WARN(...) __LOG_WARN( "Sound", __VA_ARGS__) 9 | #define LOG_INFO(...) __LOG_INFO( "Sound", __VA_ARGS__) 10 | #define LOG_DEBUG(...) __LOG_DEBUG("Sound", __VA_ARGS__) 11 | #define LOG_TRACE(...) __LOG_TRACE("Sound", __VA_ARGS__) 12 | 13 | namespace MM::Services { 14 | 15 | SoundService::SoundService(void) : engine() { 16 | MM::Logger::initSectionLogger("Sound"); 17 | } 18 | 19 | SoundService::~SoundService(void) { 20 | } 21 | 22 | bool SoundService::enable(Engine&, std::vector&) { 23 | unsigned int flags = SoLoud::Soloud::CLIP_ROUNDOFF; 24 | auto r = engine.init(flags); 25 | if (r != 0) { 26 | LOG_ERROR("SoLoud initialization failed: {}", r); 27 | return false; 28 | } 29 | 30 | LOG_INFO("SoLoud v{} backend: {}", engine.getVersion(), engine.getBackendString()); 31 | 32 | return true; 33 | } 34 | 35 | void SoundService::disable(Engine&) { 36 | engine.deinit(); 37 | } 38 | 39 | void SoundService::printErrorString(SoLoud::result errorCode) { 40 | LOG_ERROR("error string: {}", engine.getErrorString(errorCode)); 41 | } 42 | 43 | } // MM::Services 44 | 45 | -------------------------------------------------------------------------------- /framework/sound/src/mm/services/sound_service.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::Services { 8 | 9 | class SoundService : public Service { 10 | public: 11 | SoLoud::Soloud engine; 12 | 13 | public: 14 | bool enable(Engine&, std::vector&) override; 15 | void disable(Engine&) override; 16 | 17 | const char* name(void) override { return "SoundService"; } 18 | 19 | public: 20 | SoundService(void); 21 | ~SoundService(void); 22 | 23 | void printErrorString(SoLoud::result errorCode); 24 | }; 25 | 26 | } // MM::Services 27 | 28 | -------------------------------------------------------------------------------- /framework/sound/src/mm/soloud_filesystem_file_impl.cpp: -------------------------------------------------------------------------------- 1 | #include "soloud_filesystem_file_impl.hpp" 2 | 3 | #include 4 | #define LOGSLF(x) LOG("SoLoudFilesystemFile", x) 5 | 6 | namespace MM::SoLoud { 7 | 8 | FilesystemFile::FilesystemFile(Services::FilesystemService::fs_file_t file, Engine& engine) 9 | : _file_handle(file), 10 | _fs_ptr(engine.tryService()) { 11 | 12 | if (!_fs_ptr) { 13 | LOGSLF("error: engine has no FilesystemService!"); 14 | } 15 | 16 | if (!_file_handle) { 17 | LOGSLF("error: created with invalid file handle!"); 18 | return; 19 | } 20 | } 21 | 22 | FilesystemFile::~FilesystemFile(void) { 23 | } 24 | 25 | int FilesystemFile::eof(void) { 26 | if (!_file_handle) { 27 | LOGSLF("error: invalid file handle!"); 28 | return 0; 29 | } 30 | 31 | return _fs_ptr->eof(_file_handle); 32 | } 33 | 34 | unsigned int FilesystemFile::read(unsigned char* aDst, unsigned int aBytes) { 35 | if (!_file_handle) { 36 | LOGSLF("error: invalid file handle!"); 37 | return 0; 38 | } 39 | 40 | return _fs_ptr->read(_file_handle, aDst, aBytes); 41 | } 42 | 43 | unsigned int FilesystemFile::length(void) { 44 | if (!_file_handle) { 45 | LOGSLF("error: invalid file handle!"); 46 | return 0; 47 | } 48 | 49 | return _fs_ptr->length(_file_handle); 50 | } 51 | 52 | void FilesystemFile::seek(int aOffset) { 53 | if (!_file_handle) { 54 | LOGSLF("error: invalid file handle!"); 55 | return; 56 | } 57 | 58 | _fs_ptr->seek(_file_handle, aOffset); 59 | } 60 | 61 | unsigned int FilesystemFile::pos(void) { 62 | if (!_file_handle) { 63 | LOGSLF("error: invalid file handle!"); 64 | return 0; 65 | } 66 | 67 | return _fs_ptr->tell(_file_handle); 68 | } 69 | 70 | } // MM::SoLoud 71 | 72 | -------------------------------------------------------------------------------- /framework/sound/src/mm/soloud_filesystem_file_impl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::SoLoud { 8 | 9 | class FilesystemFile : public ::SoLoud::File { 10 | private: 11 | Services::FilesystemService::fs_file_t _file_handle; 12 | Services::FilesystemService* _fs_ptr; // convinience 13 | 14 | public: 15 | FilesystemFile(void) = delete; 16 | FilesystemFile(Services::FilesystemService::fs_file_t file, Engine& engine); 17 | FilesystemFile(const char* file_path, Engine& engine); 18 | 19 | ~FilesystemFile(void); 20 | 21 | // soloud api 22 | public: 23 | int eof(void) override; 24 | unsigned int read(unsigned char* aDst, unsigned int aBytes) override; 25 | unsigned int length(void) override; 26 | void seek(int aOffset) override; 27 | unsigned int pos(void) override; 28 | 29 | }; 30 | 31 | } // MM 32 | 33 | -------------------------------------------------------------------------------- /framework/sound/src/mm/soloud_json.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace SoLoud { 8 | 9 | //SoLoud::Sfxr 10 | void to_json(nlohmann::json& j, const Sfxr& sfxr); 11 | void from_json(const nlohmann::json& j, Sfxr& sfxr); 12 | 13 | } // SoLoud 14 | 15 | -------------------------------------------------------------------------------- /framework/sound/src/mm/sound_loader_sfxr.cpp: -------------------------------------------------------------------------------- 1 | #include "./sound_loader_sfxr.hpp" 2 | 3 | #include 4 | 5 | #include "./soloud_json.hpp" 6 | 7 | #include 8 | 9 | 10 | namespace MM { 11 | 12 | std::shared_ptr<::SoLoud::Sfxr> SoundLoaderSfxrPreset::load(const ::SoLoud::Sfxr::SFXR_PRESETS preset, const int seed) const { 13 | auto sfxr = std::make_shared<::SoLoud::Sfxr>(); 14 | sfxr->loadPreset(preset, seed); 15 | return sfxr; 16 | } 17 | 18 | std::shared_ptr<::SoLoud::Sfxr> SoundLoaderSfxrJson::load(const nlohmann::json& j) const { 19 | auto sfxr = std::make_shared<::SoLoud::Sfxr>(); 20 | *sfxr = j; 21 | return sfxr; 22 | } 23 | 24 | std::shared_ptr<::SoLoud::Sfxr> SoundLoaderSfxrFile::load(const std::string& path, MM::Engine& engine) const { 25 | auto& fs = engine.getService(); 26 | 27 | if (!fs.isFile(path.c_str())) { 28 | // TODO: log error 29 | return nullptr; 30 | } 31 | 32 | auto j = fs.readJson(path.c_str()); 33 | 34 | return SoundLoaderSfxrJson{}.load(j); 35 | } 36 | 37 | } // MM 38 | 39 | -------------------------------------------------------------------------------- /framework/sound/src/mm/sound_loader_sfxr.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | namespace MM { 11 | 12 | // fwd 13 | class Engine; 14 | 15 | struct SoundLoaderSfxrPreset { 16 | std::shared_ptr<::SoLoud::Sfxr> load(const ::SoLoud::Sfxr::SFXR_PRESETS preset, const int seed) const; 17 | }; 18 | 19 | struct SoundLoaderSfxrJson { 20 | std::shared_ptr<::SoLoud::Sfxr> load(const nlohmann::json& j) const; 21 | }; 22 | 23 | struct SoundLoaderSfxrFile { 24 | std::shared_ptr<::SoLoud::Sfxr> load(const std::string& path, MM::Engine& engine) const; 25 | }; 26 | 27 | } // MM 28 | 29 | -------------------------------------------------------------------------------- /framework/sound/src/mm/sound_loader_wav.cpp: -------------------------------------------------------------------------------- 1 | #include "./sound_loader_wav.hpp" 2 | 3 | #include "./soloud_filesystem_file_impl.hpp" 4 | 5 | #include 6 | 7 | namespace MM { 8 | 9 | std::shared_ptr<::SoLoud::Wav> SoundLoaderWavFile::load(const std::string& path, Engine& engine) const { 10 | auto& fs = engine.getService(); 11 | 12 | if (!fs.isFile(path.c_str())) { 13 | // TODO: log error 14 | return nullptr; 15 | } 16 | 17 | auto h = fs.open(path.c_str()); 18 | 19 | MM::SoLoud::FilesystemFile sl_f(h, engine); 20 | 21 | auto ptr = std::make_shared<::SoLoud::Wav>(); 22 | auto r = ptr->loadFile(&sl_f); 23 | if (r != ::SoLoud::SO_NO_ERROR) { 24 | // TODO: log error 25 | return nullptr; 26 | } 27 | 28 | return ptr; 29 | } 30 | 31 | } // MM 32 | 33 | -------------------------------------------------------------------------------- /framework/sound/src/mm/sound_loader_wav.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace MM { 9 | 10 | class Engine; 11 | 12 | struct SoundLoaderWavFile { 13 | std::shared_ptr<::SoLoud::Wav> load(const std::string& path, Engine& engine) const; 14 | }; 15 | 16 | } // MM 17 | 18 | -------------------------------------------------------------------------------- /framework/sound/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(sound_service_test start_test.cpp) 2 | target_include_directories(sound_service_test PRIVATE ".") 3 | target_link_libraries(sound_service_test 4 | sound_service 5 | gtest_main 6 | ) 7 | add_test(NAME sound_service_test COMMAND sound_service_test) 8 | 9 | add_executable(filesystem_soloud_file_test file_test.cpp loader_test.cpp) 10 | target_link_libraries(filesystem_soloud_file_test 11 | resource_manager 12 | sound_service 13 | filesystem_service 14 | gtest_main 15 | 16 | filesystem_soloud_file 17 | ) 18 | add_test(NAME filesystem_soloud_file_test COMMAND filesystem_soloud_file_test) 19 | 20 | -------------------------------------------------------------------------------- /framework/sound/test/file_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include // SDL_main 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | char* argv0; 16 | 17 | TEST(soloud_fs_file, basic) { 18 | MM::Engine engine; 19 | 20 | // setup 21 | auto& sound = engine.addService(); 22 | ASSERT_TRUE(engine.enableService()); 23 | 24 | auto& fs = engine.addService(argv0, "soloud_filesystem_file_test"); 25 | ASSERT_TRUE(engine.enableService()); 26 | 27 | sound.engine.setGlobalVolume(0.4f); 28 | 29 | { 30 | const char* file_path = "does_not_exist.wav"; 31 | ASSERT_FALSE(fs.exists(file_path)); 32 | MM::SoLoud::FilesystemFile sl_f(fs.open(file_path), engine); 33 | 34 | SoLoud::Wav w; 35 | ASSERT_EQ(w.loadFile(&sl_f), SoLoud::SOLOUD_ERRORS::FILE_LOAD_FAILED); 36 | } 37 | 38 | while (sound.engine.getActiveVoiceCount()) { 39 | } 40 | } 41 | 42 | int main(int argc, char** argv) { 43 | argv0 = argv[0]; 44 | 45 | ::testing::InitGoogleTest(&argc, argv); 46 | return RUN_ALL_TESTS(); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /framework/sound/test/res/erik_gun_fx_1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MadeOfJelly/MushMachine/4ec8f98ab0aab46a3e7f7d7d515280642a70d225/framework/sound/test/res/erik_gun_fx_1.zip -------------------------------------------------------------------------------- /framework/std_utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(std_utils CXX) 4 | 5 | add_library(std_utils INTERFACE) 6 | 7 | target_include_directories(std_utils INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src") 8 | 9 | target_compile_features(std_utils INTERFACE cxx_std_17) 10 | 11 | ############################## 12 | 13 | # curr only scalar_range 14 | add_library(std_utils_serialize INTERFACE) 15 | 16 | target_include_directories(std_utils_serialize INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src") 17 | 18 | target_compile_features(std_utils_serialize INTERFACE cxx_std_17) 19 | 20 | target_link_libraries(std_utils_serialize INTERFACE 21 | nlohmann_json::nlohmann_json 22 | ) 23 | 24 | ############################## 25 | 26 | if (BUILD_TESTING) 27 | add_subdirectory(test) 28 | endif() 29 | 30 | -------------------------------------------------------------------------------- /framework/std_utils/src/mm/permutation.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace MM::std_utils { 8 | 9 | // TODO: move to some lib in engine 10 | // TODO: determain the ideal sort 11 | // uses std::sort rn 12 | template 13 | std::vector generate_sort_permutation(size_t size, F&& sort_fn) { 14 | std::vector index_mapping; 15 | 16 | index_mapping.resize(size); 17 | std::iota(index_mapping.begin(), index_mapping.end(), 0); 18 | 19 | std::sort(index_mapping.begin(), index_mapping.end(), sort_fn); 20 | 21 | return index_mapping; 22 | } 23 | 24 | // TODO: reimplement, this naive solution is kind of costly 25 | template 26 | void apply_permutation(ContainerType& vec, const std::vector& perm) { 27 | ContainerType new_vec(vec.size()); 28 | 29 | for (size_t i = 0; i < vec.size(); i++) { 30 | new_vec[i] = vec[perm[i]]; // thx ec and random guy 31 | } 32 | 33 | vec = std::move(new_vec); 34 | } 35 | 36 | } // MM::std_utils 37 | 38 | -------------------------------------------------------------------------------- /framework/std_utils/src/mm/scalar_range2.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace MM { 4 | 5 | template 6 | struct ScalarRange2 { 7 | T v_min {}; 8 | T v_max {}; 9 | 10 | constexpr ScalarRange2(void) = default; 11 | 12 | constexpr ScalarRange2(const T& both) noexcept { 13 | v_min = both; 14 | v_max = both; 15 | } 16 | 17 | constexpr ScalarRange2(const T& min, const T& max) noexcept { 18 | if (min <= max) { 19 | v_min = min; 20 | v_max = max; 21 | } else { 22 | v_min = max; 23 | v_max = min; 24 | } 25 | } 26 | 27 | constexpr bool operator==(const ScalarRange2& rhs) const { 28 | return min() == rhs.min() && max() == rhs.max(); 29 | } 30 | 31 | constexpr bool operator!=(const ScalarRange2& rhs) const { 32 | return !(*this == rhs); 33 | } 34 | 35 | [[nodiscard]] constexpr T& min(void) { return v_min; } 36 | [[nodiscard]] constexpr T& max(void) { return v_max; } 37 | 38 | [[nodiscard]] constexpr const T& min(void) const { return v_min; } 39 | [[nodiscard]] constexpr const T& max(void) const { return v_max; } 40 | 41 | void setMin(const T& new_min) { 42 | min() = new_min; 43 | max() = max() < new_min ? new_min : max(); 44 | } 45 | 46 | void setMax(const T& new_max) { 47 | max() = new_max; 48 | min() = min() > new_max ? new_max : min(); 49 | } 50 | 51 | void sanitize(void) { 52 | if (min() > max()) { 53 | // TODO: is copy ok? 54 | T tmp = min(); 55 | min() = max(); 56 | max() = tmp; 57 | } 58 | } 59 | 60 | [[nodiscard]] constexpr bool inRange(T&& value) const { 61 | return value >= min() && value <= max(); 62 | } 63 | 64 | // lerp between min and max 65 | [[nodiscard]] constexpr T map(const float a) const { 66 | return min() * (1.f-a) + max() * a; 67 | } 68 | 69 | // reverse map 70 | [[nodiscard]] constexpr float unmap(const T& v) const { 71 | return (v - min()) / static_cast(max() - min()); 72 | } 73 | }; 74 | 75 | } // MM 76 | 77 | -------------------------------------------------------------------------------- /framework/std_utils/src/mm/serialize/json_scalar_range2.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../scalar_range2.hpp" 6 | 7 | namespace MM { 8 | 9 | template 10 | void to_json(nlohmann::json& j, const ScalarRange2& r) { 11 | j = nlohmann::json{ 12 | {"min", r.min()}, 13 | {"max", r.max()} 14 | }; 15 | } 16 | 17 | template 18 | void from_json(const nlohmann::json& j, ScalarRange2& r) { 19 | j.at("min").get_to(r.min()); 20 | j.at("max").get_to(r.max()); 21 | 22 | r.sanitize(); 23 | } 24 | 25 | } // MM 26 | 27 | -------------------------------------------------------------------------------- /framework/std_utils/src/mm/string_view_split.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace MM::std_utils { 7 | 8 | inline std::string_view trim_prefix(std::string_view sv) { 9 | while (!sv.empty() && std::isspace(sv.front())) { 10 | sv.remove_prefix(1); 11 | } 12 | 13 | return sv; 14 | } 15 | 16 | inline std::string_view trim_suffix(std::string_view sv) { 17 | while (!sv.empty() && std::isspace(sv.back())) { 18 | sv.remove_suffix(1); 19 | } 20 | 21 | return sv; 22 | } 23 | 24 | inline std::string_view trim(std::string_view sv) { 25 | return trim_suffix(trim_prefix(sv)); 26 | } 27 | 28 | // src : https://marcoarena.wordpress.com/2017/01/03/string_view-odi-et-amo/ 29 | inline std::vector split(std::string_view str, const char* delims) { 30 | std::vector ret; 31 | 32 | std::string_view::size_type start = 0; 33 | auto pos = str.find_first_of(delims, start); 34 | while (pos != std::string_view::npos) { 35 | if (pos != start) { 36 | ret.push_back(str.substr(start, pos - start)); 37 | } 38 | start = pos + 1; 39 | pos = str.find_first_of(delims, start); 40 | } 41 | if (start < str.length()) 42 | ret.push_back(str.substr(start, str.length() - start)); 43 | 44 | return ret; 45 | } 46 | 47 | } // MM::std_utils 48 | 49 | -------------------------------------------------------------------------------- /framework/std_utils/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(std_utils_test 2 | scalar_range2_test.cpp 3 | scalar_range2_json_test.cpp 4 | ) 5 | 6 | target_include_directories(std_utils_test PRIVATE ".") 7 | 8 | target_link_libraries(std_utils_test 9 | gtest_main 10 | gmock 11 | 12 | std_utils 13 | std_utils_serialize 14 | ) 15 | 16 | add_test(NAME std_utils_test COMMAND std_utils_test) 17 | 18 | -------------------------------------------------------------------------------- /framework/std_utils/test/scalar_range2_json_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | TEST(std_utils_scalar_range2_json, signed_integer) { 9 | MM::ScalarRange2 r8 {-4, 100}; 10 | 11 | nlohmann::json j = r8; 12 | ASSERT_EQ(j["min"], -4); 13 | ASSERT_EQ(j["max"], 100); 14 | 15 | MM::ScalarRange2 r8_2 = j; 16 | ASSERT_EQ(r8_2.min(), -4); 17 | ASSERT_EQ(r8_2.max(), 100); 18 | } 19 | 20 | TEST(std_utils_scalar_range2_json, unsigned_integer) { 21 | MM::ScalarRange2 r8 {4, 100}; 22 | 23 | nlohmann::json j = r8; 24 | ASSERT_EQ(j["min"], 4); 25 | ASSERT_EQ(j["max"], 100); 26 | 27 | MM::ScalarRange2 r8_2 = j; 28 | ASSERT_EQ(r8_2.min(), 4); 29 | ASSERT_EQ(r8_2.max(), 100); 30 | } 31 | 32 | TEST(std_utils_scalar_range2_json, floating) { 33 | MM::ScalarRange2 r {-4.3f, 100.f}; 34 | 35 | nlohmann::json j = r; 36 | ASSERT_EQ(j["min"], -4.3f); 37 | ASSERT_EQ(j["max"], 100.f); 38 | 39 | MM::ScalarRange2 r_2 = j; 40 | ASSERT_EQ(r_2.min(), -4.3f); 41 | ASSERT_EQ(r_2.max(), 100.f); 42 | } 43 | 44 | -------------------------------------------------------------------------------- /framework/tilemap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(tilemap CXX) 4 | 5 | add_library(tilemap 6 | ./src/mm/tilemap.hpp 7 | ./src/mm/tilemap.cpp 8 | ) 9 | 10 | target_include_directories(tilemap PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 11 | 12 | target_link_libraries(tilemap 13 | filesystem_service 14 | tilemap_render_task 15 | ) 16 | 17 | ########################## 18 | 19 | # TODO: test!! 20 | #if (BUILD_TESTING) 21 | #add_subdirectory(test) 22 | #endif() 23 | 24 | 25 | -------------------------------------------------------------------------------- /mm_options_and_defines.cmake: -------------------------------------------------------------------------------- 1 | 2 | # include guard 3 | if(NOT MM_INTERNAL_OPTIONS) 4 | set(MM_INTERNAL_OPTIONS TRUE) 5 | 6 | # MM options 7 | option(BUILD_TESTING "Enable testing with ctest." OFF) 8 | option(MM_AUTOTEST "Quits tests after some frames. for ci." ON) 9 | option(MM_HEADLESS "Headless mode for MM, disables all kind of rendering stuff." OFF) 10 | option(MM_NETWORKING "control networking implementations for MM." OFF) 11 | 12 | if(NOT MM_HEADLESS) 13 | option(MM_OPENGL_3 "use the MM opengl 3 implementations (opengl 3.3 or opengl es 3.0 (webgl 2)" ON) 14 | option(MM_OPENGL_3_GLES "use gles over gl" OFF) 15 | if(NOT MM_OPENGL_3 AND MM_OPENGL_3_GLES) 16 | message(WARN "MM_OPENGL_3_GLES on, but MM_OPENGL_3 off, ignoring") 17 | set(MM_OPENGL_3_GLES OFF) 18 | endif() 19 | endif() 20 | 21 | # MM options defines 22 | macro(GEN_COMPILE_DEFINITION OPTION_NAME) 23 | if(${OPTION_NAME}) 24 | add_definitions("-D${OPTION_NAME}") 25 | #set_property(GLOBAL PROPERTY COMPILE_DEFINITIONS "-D${OPTION_NAME}") 26 | endif() 27 | endmacro() 28 | 29 | gen_compile_definition(MM_AUTOTEST) 30 | gen_compile_definition(MM_HEADLESS) 31 | gen_compile_definition(MM_NETWORKING) 32 | gen_compile_definition(MM_OPENGL_3) 33 | gen_compile_definition(MM_OPENGL_3_GLES) 34 | endif() 35 | 36 | -------------------------------------------------------------------------------- /res/mm2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MadeOfJelly/MushMachine/4ec8f98ab0aab46a3e7f7d7d515280642a70d225/res/mm2.ico -------------------------------------------------------------------------------- /res/mm_card.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MadeOfJelly/MushMachine/4ec8f98ab0aab46a3e7f7d7d515280642a70d225/res/mm_card.png -------------------------------------------------------------------------------- /screens/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(screens) 4 | 5 | if(NOT MM_HEADLESS) 6 | add_subdirectory(mm_logo) 7 | endif() 8 | 9 | -------------------------------------------------------------------------------- /screens/mm_logo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(mm_logo_screen CXX) 4 | 5 | add_library(mm_logo_screen 6 | res/mush_machine_logo_1.svg.png.h 7 | 8 | src/mm/screens/mm_logo_screen.hpp 9 | src/mm/screens/mm_logo_screen.cpp 10 | ) 11 | 12 | target_include_directories(mm_logo_screen PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 13 | 14 | target_link_libraries(mm_logo_screen 15 | entt 16 | glm 17 | engine 18 | screen_director 19 | organizer_scene 20 | 21 | opengl_renderer_s 22 | simple_sprite_render_task 23 | 24 | common_components 25 | transform_system 26 | 27 | random 28 | ) 29 | 30 | #if (BUILD_TESTING) 31 | #add_subdirectory(test) 32 | #endif() 33 | 34 | 35 | -------------------------------------------------------------------------------- /screens/mm_logo/src/mm/screens/mm_logo_screen.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace MM::Screens { 6 | 7 | void create_mm_logo(MM::Engine& engine, MM::Services::ScreenDirector::Screen& screen, const std::string next_screen = "menu", float anim_duration = 2.f, float screen_duration = 2.f); 8 | 9 | } // MM::Screens 10 | 11 | -------------------------------------------------------------------------------- /systems/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(systems) 4 | 5 | add_subdirectory(transform) 6 | add_subdirectory(simple_velocity) 7 | 8 | if(NOT MM_HEADLESS) 9 | add_subdirectory(player_velocity) 10 | add_subdirectory(fast_sky_sun) 11 | endif() 12 | 13 | -------------------------------------------------------------------------------- /systems/fast_sky_sun/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(fast_sky_sun_system CXX) 4 | 5 | add_library(fast_sky_sun_system 6 | src/mm/systems/fast_sky_sun_system.hpp 7 | src/mm/systems/fast_sky_sun_system.cpp 8 | ) 9 | 10 | target_include_directories(fast_sky_sun_system PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 11 | 12 | target_link_libraries(fast_sky_sun_system 13 | engine 14 | fast_sky_render_task 15 | common_components 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /systems/fast_sky_sun/src/mm/systems/fast_sky_sun_system.cpp: -------------------------------------------------------------------------------- 1 | #include "./fast_sky_sun_system.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | 13 | namespace MM::Systems { 14 | 15 | void fast_sky_sun(MM::OpenGL::RenderTasks::FastSkyContext& sky_ctx, const MM::Components::TimeDelta& delta) { 16 | sky_ctx.time += delta.tickDelta * 0.2f; 17 | 18 | sky_ctx.fsun.y = glm::sin(sky_ctx.time * 0.01f); 19 | sky_ctx.fsun.z = glm::cos(sky_ctx.time * 0.01f); 20 | } 21 | 22 | } // MM::Systems 23 | 24 | -------------------------------------------------------------------------------- /systems/fast_sky_sun/src/mm/systems/fast_sky_sun_system.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | // fwd 6 | namespace MM::OpenGL::RenderTasks { 7 | struct FastSkyContext; 8 | } 9 | namespace MM::Components { 10 | struct TimeDelta; 11 | } 12 | 13 | namespace MM::Systems { 14 | 15 | // this system updates time and sun depending on time with the time delta 16 | void fast_sky_sun(MM::OpenGL::RenderTasks::FastSkyContext& c, const MM::Components::TimeDelta& delta); 17 | 18 | } // MM::Systems 19 | 20 | -------------------------------------------------------------------------------- /systems/player_velocity/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(player_velocity_system CXX) 4 | 5 | add_library(player_velocity_system 6 | src/mm/systems/player_velocity2d_system.hpp 7 | src/mm/systems/player_velocity2d_system.cpp 8 | ) 9 | 10 | target_include_directories(player_velocity_system PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 11 | 12 | target_link_libraries(player_velocity_system 13 | entt 14 | glm 15 | engine 16 | common_components 17 | input_service 18 | ) 19 | 20 | if (BUILD_TESTING) 21 | add_subdirectory(test) 22 | endif() 23 | 24 | 25 | -------------------------------------------------------------------------------- /systems/player_velocity/src/mm/systems/player_velocity2d_system.cpp: -------------------------------------------------------------------------------- 1 | #include "./player_velocity2d_system.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::Systems { 8 | 9 | void player_velocity2d(entt::view> view, MM::Engine& engine) { 10 | ZoneScopedN("MM::Systems::PlayerVelocity2D"); 11 | 12 | auto& input_ss = engine.getService(); 13 | 14 | view.each([&input_ss](const MM::Input::PlayerID p_id, MM::Components::Velocity2DPositionIntent& v) { 15 | v.intent = input_ss.getMoveVec(p_id); 16 | }); 17 | } 18 | 19 | } // MM::Systems 20 | 21 | -------------------------------------------------------------------------------- /systems/player_velocity/src/mm/systems/player_velocity2d_system.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace MM::Systems { 10 | 11 | // this system transforms the input from the input_service into velocity intent 12 | void player_velocity2d(entt::view> view, MM::Engine& engine); 13 | 14 | } // MM::Systems 15 | 16 | -------------------------------------------------------------------------------- /systems/player_velocity/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(player_velocity_test 2 | player_velocity_test.cpp 3 | ) 4 | 5 | target_include_directories(player_velocity_test PRIVATE ".") 6 | 7 | target_link_libraries(player_velocity_test 8 | player_velocity_system 9 | organizer_scene 10 | gtest_main 11 | ) 12 | 13 | add_test(NAME player_velocity_test COMMAND player_velocity_test) 14 | 15 | -------------------------------------------------------------------------------- /systems/simple_velocity/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(simple_velocity_system CXX) 4 | 5 | add_library(simple_velocity_system 6 | src/mm/systems/simple_velocity_system2d.hpp 7 | src/mm/systems/simple_velocity_system2d.cpp 8 | ) 9 | 10 | target_include_directories(simple_velocity_system PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 11 | 12 | target_link_libraries(simple_velocity_system 13 | entt 14 | glm 15 | engine 16 | common_components 17 | ) 18 | 19 | if (BUILD_TESTING) 20 | add_subdirectory(test) 21 | endif() 22 | 23 | 24 | -------------------------------------------------------------------------------- /systems/simple_velocity/src/mm/systems/simple_velocity_system2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace MM::Systems { 13 | 14 | // non patching (on_update()) 15 | void simple_positional_velocity( 16 | entt::view> view, 20 | const Components::TimeDelta& td 21 | ); 22 | 23 | // patching (on_update()) 24 | void simple_positional_velocity_patching( 25 | entt::registry& scene, 26 | entt::view> view, 30 | const Components::TimeDelta& td 31 | ); 32 | 33 | // non patching (on_update()) 34 | void simple_rotational_velocity( 35 | entt::view> view, 39 | const Components::TimeDelta& td 40 | ); 41 | 42 | // patching (on_update()) 43 | void simple_rotational_velocity_patching( 44 | entt::registry& scene, 45 | entt::view> view, 49 | const Components::TimeDelta& td 50 | ); 51 | 52 | } // MM::Systems 53 | 54 | -------------------------------------------------------------------------------- /systems/simple_velocity/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(simple_velocity_test 2 | simple_velocity_test.cpp 3 | ) 4 | 5 | target_include_directories(simple_velocity_test PRIVATE ".") 6 | 7 | target_link_libraries(simple_velocity_test 8 | simple_velocity_system 9 | gtest_main 10 | ) 11 | 12 | add_test(NAME simple_velocity_test COMMAND simple_velocity_test) 13 | 14 | -------------------------------------------------------------------------------- /systems/simple_velocity/test/simple_velocity_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | TEST(simple_velocity_2d, basic_run) { 11 | MM::Scene scene; 12 | 13 | // setup v system 14 | auto& org = scene.ctx().emplace(); 15 | org.emplace<&MM::Systems::simple_positional_velocity>("simple_positional_velocity"); 16 | org.emplace<&MM::Systems::simple_rotational_velocity>("simple_rotational_velocity"); 17 | auto graph = org.graph(); 18 | 19 | // setup delta 20 | auto& time_ctx = scene.ctx().emplace(1.f/60.f, 1.f); 21 | time_ctx.tickDelta = 1.f/60.f * time_ctx.deltaFactor; 22 | 23 | // setup test entity 24 | auto e = scene.create(); 25 | auto& p = scene.emplace(e); 26 | auto& r = scene.emplace(e); 27 | auto& vp = scene.emplace(e); 28 | auto& vr = scene.emplace(e); 29 | p.pos = { 0.f, 0.f }; 30 | r.rot = 0.f; 31 | 32 | vp.pos_vel = { 1.f, 1.f }; 33 | vr.rot_vel = 0.f; 34 | 35 | // run all systems 36 | for (auto&& vert : graph) { 37 | vert.callback()(vert.data(), scene); 38 | } 39 | 40 | ASSERT_EQ(p.pos.x, 1.f * 1.f/60.f); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /systems/transform/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9...3.16 FATAL_ERROR) 2 | 3 | project(transfrom_system CXX) 4 | 5 | add_library(transform_system 6 | src/mm/systems/transform.hpp 7 | src/mm/systems/transform.cpp 8 | ) 9 | 10 | target_include_directories(transform_system PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src") 11 | 12 | target_link_libraries(transform_system 13 | entt 14 | glm 15 | engine 16 | common_components 17 | tracy_client 18 | ) 19 | 20 | #if (BUILD_TESTING) 21 | #add_subdirectory(test) 22 | #endif() 23 | 24 | 25 | -------------------------------------------------------------------------------- /systems/transform/src/mm/systems/transform.cpp: -------------------------------------------------------------------------------- 1 | #include "./transform.hpp" 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace MM::Systems { 8 | 9 | void position3d_from_2d(entt::view> view) { 10 | ZoneScoped; 11 | view.each([](const Components::Position2D& pos2, const Components::Position2D_ZOffset& zoff, Components::Position3D& pos3) { 12 | pos3.pos = glm::vec3(pos2.pos, zoff.z_offset + pos2.pos.y/10.f); 13 | }); 14 | } 15 | 16 | void transform3d_translate(entt::view> view) { 17 | ZoneScoped; 18 | view.each([](const Components::Position3D& pos, Components::Transform4x4& trans) { 19 | trans.trans = glm::translate(glm::mat4x4{1.f}, pos.pos); 20 | }); 21 | } 22 | 23 | void transform3d_rotate2d(entt::view> view) { 24 | ZoneScoped; 25 | view.each([](const Components::Rotation2D& rot, Components::Transform4x4& trans) { 26 | trans.trans = glm::rotate(trans.trans, rot.rot, glm::vec3(0.f, 0.f, 1.f)); 27 | }); 28 | } 29 | 30 | void transform3d_scale2d(entt::view> view) { 31 | ZoneScoped; 32 | view.each([](const Components::Scale2D& scale, Components::Transform4x4& trans) { 33 | trans.trans = glm::scale(trans.trans, glm::vec3(scale.scale, 1.f)); 34 | }); 35 | } 36 | 37 | void transform_clear_dirty(entt::registry& scene, entt::view> view) { 38 | ZoneScoped; 39 | scene.remove(view.begin(), view.end()); 40 | } 41 | 42 | } // MM::Systems 43 | 44 | --------------------------------------------------------------------------------