├── .ci └── check_format.py ├── .clang-format ├── .clang-tidy ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── task.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── Dockerfile ├── LICENSE ├── Readme.md ├── azure-pipelines.yml ├── cmake ├── ClangFormat.cmake └── ClangTidy.cmake ├── core ├── CMakeLists.txt ├── src │ ├── AutoGeneratedCoreWrapper.cpp │ ├── BaseObject.cpp │ ├── BaseObject.h │ ├── CMakeLists.txt │ ├── Common │ │ ├── Array.h │ │ ├── Assertion.h │ │ ├── BinaryReader.h │ │ ├── BinaryWriter.h │ │ ├── HashHelper.h │ │ ├── PlatformIncludes.h │ │ ├── Profiler.cpp │ │ ├── Profiler.h │ │ ├── Resource.h │ │ ├── ResourceContainer.h │ │ ├── Resources.cpp │ │ ├── Resources.h │ │ ├── StringHelper.h │ │ └── ThreadSafeMap.h │ ├── Configuration.cpp │ ├── Configuration.h │ ├── Core.cpp │ ├── Core.h │ ├── FPS.cpp │ ├── FPS.h │ ├── Graphics │ │ ├── BatchRenderer.cpp │ │ ├── BatchRenderer.h │ │ ├── Buffer.cpp │ │ ├── Buffer.h │ │ ├── BuiltinShader.cpp │ │ ├── BuiltinShader.h │ │ ├── Color.cpp │ │ ├── Color.h │ │ ├── CommandList.cpp │ │ ├── CommandList.h │ │ ├── ComputePipelineState.cpp │ │ ├── ComputePipelineState.h │ │ ├── Font.cpp │ │ ├── Font.h │ │ ├── FrameDebugger.cpp │ │ ├── FrameDebugger.h │ │ ├── Graphics.cpp │ │ ├── Graphics.h │ │ ├── ImageFont.cpp │ │ ├── ImageFont.h │ │ ├── LLGIWindow.cpp │ │ ├── LLGIWindow.h │ │ ├── Material.cpp │ │ ├── Material.h │ │ ├── PostEffect │ │ │ ├── Downsample_PS.h │ │ │ ├── GaussianBlur_PS.h │ │ │ ├── GrayScale_PS.h │ │ │ ├── HighLuminance_PS.h │ │ │ ├── LightBloom_PS.h │ │ │ ├── Sepia_PS.h │ │ │ └── TextureMix_PS.h │ │ ├── RenderTexture.cpp │ │ ├── RenderTexture.h │ │ ├── Renderer │ │ │ ├── CullingSystem.cpp │ │ │ ├── CullingSystem.h │ │ │ ├── Rendered.cpp │ │ │ ├── Rendered.h │ │ │ ├── RenderedCamera.cpp │ │ │ ├── RenderedCamera.h │ │ │ ├── RenderedPolygon.cpp │ │ │ ├── RenderedPolygon.h │ │ │ ├── RenderedSprite.cpp │ │ │ ├── RenderedSprite.h │ │ │ ├── RenderedText.cpp │ │ │ ├── RenderedText.h │ │ │ ├── Renderer.cpp │ │ │ └── Renderer.h │ │ ├── Shader.cpp │ │ ├── Shader.h │ │ ├── ShaderCompiler │ │ │ ├── ShaderCompiler.cpp │ │ │ └── ShaderCompiler.h │ │ ├── Texture2D.cpp │ │ ├── Texture2D.h │ │ ├── TextureBase.cpp │ │ └── TextureBase.h │ ├── IO │ │ ├── BaseFileReader.cpp │ │ ├── BaseFileReader.h │ │ ├── File.cpp │ │ ├── File.h │ │ ├── FileRoot.cpp │ │ ├── FileRoot.h │ │ ├── PackFile.cpp │ │ ├── PackFile.h │ │ ├── PackFileReader.cpp │ │ ├── PackFileReader.h │ │ ├── StaticFile.cpp │ │ ├── StaticFile.h │ │ ├── StreamFile.cpp │ │ └── StreamFile.h │ ├── Input │ │ ├── ButtonState.h │ │ ├── Cursor.cpp │ │ ├── Cursor.h │ │ ├── Joystick.cpp │ │ ├── Joystick.h │ │ ├── Keyboard.cpp │ │ ├── Keyboard.h │ │ ├── Mouse.cpp │ │ └── Mouse.h │ ├── Logger │ │ ├── Log.cpp │ │ └── Log.h │ ├── Math │ │ ├── Easing.cpp │ │ ├── Easing.h │ │ ├── MathTemplate.h │ │ ├── Matrix33F.cpp │ │ ├── Matrix33F.h │ │ ├── Matrix33I.cpp │ │ ├── Matrix33I.h │ │ ├── Matrix44F.cpp │ │ ├── Matrix44F.h │ │ ├── Matrix44I.cpp │ │ ├── Matrix44I.h │ │ ├── RectF.cpp │ │ ├── RectF.h │ │ ├── RectI.cpp │ │ ├── RectI.h │ │ ├── Vector2F.cpp │ │ ├── Vector2F.h │ │ ├── Vector2I.cpp │ │ ├── Vector2I.h │ │ ├── Vector3F.cpp │ │ ├── Vector3F.h │ │ ├── Vector3I.cpp │ │ ├── Vector3I.h │ │ ├── Vector4F.cpp │ │ ├── Vector4F.h │ │ ├── Vector4I.cpp │ │ └── Vector4I.h │ ├── Media │ │ ├── MediaPlayer.cpp │ │ ├── MediaPlayer.h │ │ └── Platform │ │ │ ├── MediaPlayer_AVF.h │ │ │ ├── MediaPlayer_AVF.mm │ │ │ ├── MediaPlayer_FFmpeg.cpp │ │ │ ├── MediaPlayer_FFmpeg.h │ │ │ ├── MediaPlayer_Impl.h │ │ │ ├── MediaPlayer_WMF.cpp │ │ │ └── MediaPlayer_WMF.h │ ├── Physics │ │ └── Collider │ │ │ ├── Box2DHelper.cpp │ │ │ ├── Box2DHelper.h │ │ │ ├── CircleCollider.cpp │ │ │ ├── CircleCollider.h │ │ │ ├── Collider.cpp │ │ │ ├── Collider.h │ │ │ ├── EdgeCollider.cpp │ │ │ ├── EdgeCollider.h │ │ │ ├── PolygonCollider.cpp │ │ │ ├── PolygonCollider.h │ │ │ ├── ShapeCollider.cpp │ │ │ └── ShapeCollider.h │ ├── Platform │ │ ├── FileSystem.h │ │ ├── FileSystemLinux.cpp │ │ ├── FileSystemMac.cpp │ │ └── FileSystemWin.cpp │ ├── Sound │ │ ├── Sound.cpp │ │ ├── Sound.h │ │ ├── SoundMixer.cpp │ │ └── SoundMixer.h │ ├── StdIntCBG.h │ ├── System │ │ ├── SynchronizationContext.cpp │ │ └── SynchronizationContext.h │ ├── Tool │ │ ├── AutoGenerateTool.cpp │ │ ├── Platform │ │ │ ├── ImGuiPlatform.h │ │ │ ├── ImGuiPlatformDX12.h │ │ │ ├── ImGuiPlatformMetal.h │ │ │ ├── ImGuiPlatformMetal.mm │ │ │ ├── ImGuiPlatformVulkan.cpp │ │ │ └── ImGuiPlatformVulkan.h │ │ ├── Tool.cpp │ │ └── Tool.h │ └── Window │ │ ├── Window.cpp │ │ └── Window.h └── test │ ├── BaseObject.cpp │ ├── CMakeLists.txt │ ├── ComputeShader.cpp │ ├── Configuration.cpp │ ├── Core.cpp │ ├── FPS.cpp │ ├── File.cpp │ ├── FileSystem.cpp │ ├── Font.cpp │ ├── Graphics.cpp │ ├── Joystick.cpp │ ├── Keyboard.cpp │ ├── Log.cpp │ ├── Mouse.cpp │ ├── Movie.cpp │ ├── Physics.cpp │ ├── PostEffect.cpp │ ├── Profiler.cpp │ ├── ShaderCompiler.cpp │ ├── Sound.cpp │ ├── TestHelper.cpp │ ├── TestHelper.h │ ├── Texture2D.cpp │ ├── Tool.cpp │ ├── Window.cpp │ └── main.cpp ├── docker-compose.yml ├── documents └── development │ ├── CoreCodingRule_Ja.md │ ├── HowToBuild_Ja.md │ ├── HowToConvertVideo.md │ ├── HowToDevelop_Ja.md │ ├── LibraryAndTools_Ja.md │ └── MeetingFlow_Ja.md ├── scripts ├── GenerateProjects.bat ├── GenerateProjects_ClangFormat.bat ├── GenerateProjects_ClangFormat_Linux.sh ├── GenerateProjects_ClangFormat_Mac.sh ├── GenerateProjects_ClangTidy.sh ├── GenerateProjects_Linux.sh ├── GenerateProjects_Mac.sh ├── GenerateProjects_Sanitizer_MSVC.bat ├── GenerateProjects_Sanitizer_MSVC.py ├── Pull.bat ├── UpdateCBG.bat ├── UpdateLLGI.bat ├── UpdateSubmodules.sh ├── bindings │ ├── __init__.py │ ├── auto_generate_define.py │ ├── common.json │ ├── common.py │ ├── core.json │ ├── define.py │ ├── desc.json │ ├── desc_media.json │ ├── desc_profiler.json │ ├── graphics.json │ ├── graphics.py │ ├── input.json │ ├── io.json │ ├── logger.json │ ├── logger.py │ ├── math.py │ ├── physics.json │ ├── profiler.json │ ├── sound.json │ ├── sound.py │ └── window.json ├── docker-entrypoint.sh ├── encode_to_utf8sig.py ├── generate_cbg_definition.py ├── generate_tool.py ├── generate_wrapper.py ├── requirements.txt ├── setup.py ├── temp.h └── update_all_submodules.py └── thirdparty ├── CFlagOverrides.cmake ├── CMakeLists.txt ├── hidapi ├── CMakeLists.txt ├── LICENSE-bsd.txt ├── LICENSE-gpl3.txt ├── LICENSE-orig.txt ├── LICENSE.txt ├── README.md ├── README.txt ├── hidapi │ └── hidapi.h ├── linux │ └── hid.c ├── mac │ └── hid.c └── windows │ └── hid.c ├── imgui ├── CMakeLists.txt ├── imconfig.h ├── imgui.cpp ├── imgui.h ├── imgui_demo.cpp ├── imgui_draw.cpp ├── imgui_impl_dx12.cpp ├── imgui_impl_dx12.h ├── imgui_impl_glfw.cpp ├── imgui_impl_glfw.h ├── imgui_impl_metal.h ├── imgui_impl_metal.mm ├── imgui_impl_vulkan.cpp ├── imgui_impl_vulkan.h ├── imgui_internal.h ├── imgui_widgets.cpp ├── imstb_rectpack.h ├── imstb_textedit.h └── imstb_truetype.h └── stb ├── stb_image.h ├── stb_image_write.h └── stb_truetype.h /.ci/check_format.py: -------------------------------------------------------------------------------- 1 | import glob 2 | import subprocess 3 | import chardet 4 | import difflib 5 | 6 | hs = glob.glob('../core/**/*.h', recursive=True) 7 | cpps = glob.glob('../core/**/*.cpp', recursive=True) 8 | # mm = glob.glob('../core/**/*.mm', recursive=True) 9 | 10 | # targets = hs + cpps + mm 11 | 12 | targets = hs + cpps 13 | 14 | errors = [] 15 | 16 | for p in targets: 17 | # special case 18 | if 'AutoGeneratedCoreWrapper.cpp' in p: 19 | continue 20 | if 'Tool.h' in p: 21 | continue 22 | if 'AutoGenerateTool.cpp' in p: 23 | continue 24 | 25 | try: 26 | formatted = subprocess.check_output( 27 | ['clang-format', '-style=file', p]).decode().replace('\ufeff', '') 28 | except Exception as e: 29 | errors.append([p, e]) 30 | continue 31 | 32 | with open(p, 'rb') as f: 33 | enc = chardet.detect(f.read())['encoding'] 34 | 35 | f = open(p, 'r', encoding=enc) 36 | original = f.read() 37 | f.close() 38 | 39 | original = original.replace('\r', '') 40 | formatted = formatted.replace('\r', '') 41 | 42 | if(formatted != original): 43 | d = difflib.Differ() 44 | diff = d.compare(original.split('\n'), formatted.split('\n')) 45 | errors.append([p, 'difference(s) detected:'+('\n'.join(diff))]) 46 | 47 | for m in errors: 48 | print('################################################') 49 | print('Error on {}'.format(m[0])) 50 | print('################################################') 51 | print(m[1]) 52 | print('\n\n') 53 | 54 | if len(errors) != 0: 55 | raise Exception 56 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: Google 3 | AccessModifierOffset: -4 4 | ColumnLimit: 0 5 | IndentWidth: 4 6 | DerivePointerAlignment: false 7 | PointerAlignment: Left 8 | 9 | AlignAfterOpenBracket: AlwaysBreak 10 | AlignTrailingComments: false 11 | BinPackArguments: false 12 | BinPackParameters: false 13 | ContinuationIndentWidth: 8 -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | --- 2 | Checks: 'readability-identifier-naming' 3 | 4 | HeaderFilterRegex: '.*' 5 | 6 | CheckOptions: 7 | - key: readability-identifier-naming.PublicMemberCase 8 | value: CamelBack 9 | - key: readability-identifier-naming.ProtectedMemberCase 10 | value: camelBack 11 | - key: readability-identifier-naming.ProtectedMemberSuffix 12 | value: _ 13 | - key: readability-identifier-naming.ClassCase 14 | value: CamelCase 15 | - key: readability-identifier-naming.PrivateMemberCase 16 | value: camelBack 17 | - key: readability-identifier-naming.PrivateMemberSuffix 18 | value: _ 19 | 20 | FormatStyle: file 21 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.bat text eol=crlf 4 | 5 | *.cpp text eol=lf 6 | *.h text eol=lf 7 | *.sh text eol=lf 8 | 9 | *.md text eol=lf 10 | CMakeLists.txt text eol=lf 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: バグ報告 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Describe the bug/概要 11 | 12 | 13 | ## Environment/環境 14 | - OS: 15 | 16 | 17 | - Graphics: 18 | 19 | 20 | - Altseed2 version: 21 | 22 | 23 | 24 | 25 | ## To Reproduce/再現手順 26 | 1. 27 | 1. 28 | 1. 29 | 30 | 31 | ## Expected behavior/期待される動作 32 | 33 | 34 | 35 | ## Screenshots/スクリーンショット 36 | 37 | 38 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: 機能提案 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Describe the feature/機能の概要 11 | 12 | 13 | ## Context/文脈 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/task.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Task 3 | about: 新規タスクを作成する際の汎用テンプレ 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## About/概要 11 | 12 | 13 | ## Related Tasks/関連タスク 14 | - 15 | - 16 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Changes/変更内容 2 | 3 | 4 | 5 | 6 | 7 | 8 | ## Issue 9 | 10 | 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | build_sanitizer 3 | build_clang_format 4 | .ionide 5 | .vs 6 | .vscode 7 | 8 | # Prerequisites 9 | *.d 10 | 11 | # Compiled Object files 12 | *.slo 13 | *.lo 14 | *.o 15 | *.obj 16 | 17 | # Precompiled Headers 18 | *.gch 19 | *.pch 20 | 21 | # Compiled Dynamic libraries 22 | *.so 23 | *.dylib 24 | *.dll 25 | 26 | # Fortran module files 27 | *.mod 28 | *.smod 29 | 30 | # Compiled Static libraries 31 | *.lai 32 | *.la 33 | *.a 34 | *.lib 35 | 36 | # Executables 37 | *.exe 38 | *.out 39 | *.app 40 | 41 | # Mac 42 | .DS_Store 43 | 44 | #Python 45 | __pycache__ 46 | *.pyc 47 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "thirdparty/googletest"] 2 | path = thirdparty/googletest 3 | url = https://github.com/google/googletest.git 4 | [submodule "thirdparty/glfw"] 5 | path = thirdparty/glfw 6 | url = https://github.com/altseed/glfw.git 7 | branch = altseed2 8 | [submodule "thirdparty/spdlog"] 9 | path = thirdparty/spdlog 10 | url = https://github.com/gabime/spdlog.git 11 | [submodule "thirdparty/LLGI"] 12 | path = thirdparty/LLGI 13 | url = https://github.com/altseed/LLGI 14 | [submodule "thirdparty/zlib"] 15 | path = thirdparty/zlib 16 | url = https://github.com/madler/zlib 17 | [submodule "thirdparty/libzip"] 18 | path = thirdparty/libzip 19 | url = https://github.com/nih-at/libzip.git 20 | [submodule "TestData"] 21 | path = TestData 22 | url = https://github.com/altseed/TestData.git 23 | [submodule "scripts/bindings/CppBindingGenerator"] 24 | path = scripts/bindings/CppBindingGenerator 25 | url = https://github.com/altseed/CppBindingGenerator.git 26 | [submodule "thirdparty/OpenSoundMixer"] 27 | path = thirdparty/OpenSoundMixer 28 | url = https://github.com/altseed/OpenSoundMixer.git 29 | [submodule "thirdparty/box2d"] 30 | path = thirdparty/box2d 31 | url = https://github.com/erincatto/box2d.git 32 | [submodule "thirdparty/nativefiledialog"] 33 | path = thirdparty/nativefiledialog 34 | url = https://github.com/altseed/nativefiledialog.git 35 | [submodule "thirdparty/freetype"] 36 | path = thirdparty/freetype 37 | url = https://github.com/altseed/freetype.git 38 | branch = altseed2 39 | [submodule "thirdparty/msdfgen"] 40 | path = thirdparty/msdfgen 41 | url = https://github.com/altseed/msdfgen.git 42 | branch = altseed2 43 | [submodule "thirdparty/easy_profiler"] 44 | path = thirdparty/easy_profiler 45 | url = https://github.com/yse/easy_profiler.git 46 | [submodule "thirdparty/harfbuzz"] 47 | path = thirdparty/harfbuzz 48 | url = https://github.com/harfbuzz/harfbuzz.git 49 | [submodule "thirdparty/tiny-process-library"] 50 | path = thirdparty/tiny-process-library 51 | url = https://gitlab.com/eidheim/tiny-process-library.git 52 | [submodule "thirdparty/libpng"] 53 | path = thirdparty/libpng 54 | url = https://github.com/altseed/libpng 55 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3 2 | 3 | RUN apt-get update 4 | 5 | RUN apt install -y clang clang-format 6 | RUN pip install --upgrade pip 7 | RUN pip install --upgrade setuptools 8 | 9 | WORKDIR /home/src 10 | 11 | COPY . /home/src 12 | RUN pip install -r scripts/requirements.txt 13 | 14 | EXPOSE 3000 15 | 16 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Altseed2 2 | 3 | [Altseed](https://github.com/altseed/Altseed)の後継となるべく開発しているゲームエンジンです。 4 | 5 | Core(本リポジトリ)とEngineに分かれています。 6 | ユーザの方はEngineのREADMEをご覧ください。 7 | 8 | ## 関連リポジトリ 9 | * [altseed/LLGI](https://github.com/altseed/LLGI): C++による各種描画APIの抽象化 10 | * [altseed/Altseed2](https://github.com/altseed/Altseed2): C++による内部実装(Core) 11 | * [altseed/CppBindingGenerator](https://github.com/altseed/CppBindingGenerator): エンジンからCoreを呼び出すためのバインディングコードを自動生成するツール 12 | * [altseed/Altseed2-csharp](https://github.com/altseed/Altseed2-csharp): C#エンジン 13 | * [altseed/Altseed2-rust](https://github.com/altseed/Altseed2-rust): Rustエンジン 14 | * [altseed/Altseed2-document](https://github.com/altseed/Altseed2-document): ウェブサイト用ドキュメント 15 | 16 | ## ドキュメントリンク 17 | 18 | * [ビルド手順](documents/development/HowToBuild_Ja.md) 19 | * [開発方法について](documents/development/HowToDevelop_Ja.md) 20 | * [ツールやライブラリについて](documents/development/LibraryAndTools_Ja.md) 21 | -------------------------------------------------------------------------------- /cmake/ClangFormat.cmake: -------------------------------------------------------------------------------- 1 | # Based on https://qiita.com/tenmyo/items/f8548ee9bab78f18cd25 2 | 3 | option(CLANG_FORMAT_ENABLED "Specifies whether clang-format is automatically applied." OFF) 4 | find_program(CLANG_FORMAT_EXE clang-format) 5 | 6 | function(clang_format target) 7 | if(CLANG_FORMAT_EXE AND CLANG_FORMAT_ENABLED) 8 | message(STATUS "Enable Clang-Format ${target}") 9 | get_target_property(MY_SOURCES ${target} SOURCES) 10 | add_custom_target( 11 | "${target}_format-with-clang-format" 12 | COMMAND "${CLANG_FORMAT_EXE}" -i -style=file ${MY_SOURCES} 13 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 14 | ) 15 | add_dependencies(${target} "${target}_format-with-clang-format") 16 | endif() 17 | endfunction() -------------------------------------------------------------------------------- /cmake/ClangTidy.cmake: -------------------------------------------------------------------------------- 1 | # Based on https://qiita.com/tenmyo/items/f8548ee9bab78f18cd25 2 | 3 | cmake_minimum_required(VERSION 3.6) 4 | option(CLANG_TIDY_ENABLED "Specifies whether clang-tidy is automatically applied." OFF) 5 | find_program(CLANG_TIDY_EXE clang-tidy) 6 | 7 | function(clang_tidy target) 8 | if(CLANG_TIDY_ENABLED) 9 | if(CLANG_TIDY_EXE) 10 | message(STATUS "Enable Clang-Tidy ${target}") 11 | set_target_properties(${target} PROPERTIES 12 | C_CLANG_TIDY "${CLANG_TIDY_EXE};-header-filter=${CMAKE_CURRENT_SOURCE_DIR}/*" 13 | CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-header-filter=${CMAKE_CURRENT_SOURCE_DIR}*") 14 | else() 15 | message(STATUS "Clang-tidy is not found.") 16 | endif() 17 | endif() 18 | endfunction() 19 | -------------------------------------------------------------------------------- /core/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | # add directories 3 | add_subdirectory(src) 4 | 5 | if(BUILD_TEST) 6 | add_subdirectory(test) 7 | endif() 8 | -------------------------------------------------------------------------------- /core/src/BaseObject.cpp: -------------------------------------------------------------------------------- 1 | #include "BaseObject.h" 2 | 3 | #include "Common/StringHelper.h" 4 | #include "Core.h" 5 | 6 | namespace Altseed2 { 7 | 8 | BaseObject::BaseObject() : reference_(1) { 9 | core_ = Core::GetInstance(); 10 | 11 | // for Core 12 | if (core_ != nullptr) { 13 | id_ = core_->Register(this); 14 | } 15 | } 16 | 17 | #ifdef NDEBUG 18 | BaseObject::~BaseObject() { 19 | #else 20 | BaseObject::~BaseObject() noexcept(false) { 21 | #endif 22 | // for Core 23 | if (core_ != nullptr) { 24 | core_->Unregister(this); 25 | core_ = nullptr; 26 | } 27 | 28 | ASD_ASSERT(reference_ == 0, std::string("BaseObject ") + utf16_to_utf8(instanceName_) + std::string(" must be deleted by Release")); 29 | } 30 | 31 | int32_t BaseObject::AddRef() { 32 | auto before = std::atomic_fetch_add_explicit(&reference_, 1, std::memory_order_consume); 33 | ASD_ASSERT(before != 0, std::string("BaseObject ") + utf16_to_utf8(instanceName_) + std::string(" invalid AddRef")); 34 | 35 | return reference_; 36 | } 37 | 38 | int32_t BaseObject::Release() { 39 | auto old = std::atomic_fetch_sub_explicit(&reference_, 1, std::memory_order_consume); 40 | 41 | if (old == 1) { 42 | delete this; 43 | return 0; 44 | } 45 | 46 | return reference_; 47 | } 48 | 49 | const char16_t* BaseObject::GetInstanceName() const { return instanceName_.c_str(); } 50 | 51 | void BaseObject::SetInstanceName(const std::u16string& instanceName) { instanceName_ = instanceName; } 52 | 53 | void BaseObject::SetInstanceName(const char* instanceName) { SetInstanceName(utf8_to_utf16(instanceName)); } 54 | 55 | bool BaseObject::GetIsTerminateingEnabled() const { 56 | return terminateingEnabled_; 57 | } 58 | 59 | void BaseObject::SetIsTerminateingEnabled(bool value) { 60 | terminateingEnabled_ = value; 61 | } 62 | 63 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Common/Assertion.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifdef NDEBUG 11 | #define ASD_ASSERT_FORCE(message) 12 | #define ASD_ASSERT(x, message) 13 | #else 14 | #define ASD_ASSERT_FORCE(message) \ 15 | { \ 16 | auto msg = \ 17 | (std::string("Assert : ") + std::string(__FILE__) + " : " + std::to_string(__LINE__) + std::string(" : ") + \ 18 | std::string(message)); \ 19 | std::cout << msg << std::endl; \ 20 | throw std::runtime_error(msg.c_str()); \ 21 | } 22 | #define ASD_ASSERT(x, message) \ 23 | if (!(x)) ASD_ASSERT_FORCE(message) 24 | #endif 25 | 26 | #define ASD_VERIFY(x, message) \ 27 | if (!(x)) { \ 28 | auto msg = \ 29 | (std::string("Verify : ") + std::string(__FILE__) + " : " + std::to_string(__LINE__) + std::string(" : ") + \ 30 | std::string(message)); \ 31 | std::cout << msg << std::endl; \ 32 | throw std::runtime_error(msg.c_str()); \ 33 | } 34 | -------------------------------------------------------------------------------- /core/src/Common/HashHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Altseed2 { 4 | static inline void hash_combine(std::size_t& seed) {} 5 | 6 | template 7 | static inline void hash_combine(std::size_t& seed, const T& v, Rest... rest) { 8 | std::hash hasher; 9 | seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 10 | hash_combine(seed, rest...); 11 | } 12 | 13 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Common/PlatformIncludes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | #define GLFW_EXPOSE_NATIVE_WIN32 1 5 | #endif 6 | 7 | #ifdef __APPLE__ 8 | #define GLFW_EXPOSE_NATIVE_COCOA 1 9 | #endif 10 | 11 | #ifdef __linux__ 12 | #define GLFW_EXPOSE_NATIVE_X11 1 13 | #undef Always 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | #ifdef __linux__ 20 | #undef Always 21 | #undef None 22 | #undef Bool 23 | #endif -------------------------------------------------------------------------------- /core/src/Common/Profiler.cpp: -------------------------------------------------------------------------------- 1 | #include "Profiler.h" 2 | 3 | namespace Altseed2 { 4 | 5 | ProfilerBlock::ProfilerBlock(const ::profiler::BaseBlockDescriptor* descriptor, const char* name) : descriptor_(descriptor), name_(name) {} 6 | 7 | std::shared_ptr Profiler::instance_; 8 | 9 | std::shared_ptr& Profiler::GetInstance() { 10 | return instance_; 11 | } 12 | 13 | bool Profiler::Initialize() { 14 | instance_ = MakeAsdShared(); 15 | 16 | return true; 17 | } 18 | 19 | void Profiler::Terminate() { 20 | instance_.reset(); 21 | } 22 | 23 | std::shared_ptr Profiler::CreateBlock(const char* name, const char* _filename, int _line, const Color& color) { 24 | uint32_t c = 0xff << 24; 25 | c += (color.R << 16); 26 | c += (color.G << 8); 27 | c += (color.B << 0); 28 | 29 | auto desc = ::profiler::registerDescription(profiler::EasyBlockStatus::ON, name, name, _filename, _line, ::profiler::BlockType::Block, c, true); 30 | return MakeAsdShared(desc, name); 31 | }; 32 | 33 | void Profiler::BeginBlock(const char16_t* name, const char16_t* _filename, int _line, const Color& color) { 34 | auto uniqueName = std::string(utf16_to_utf8(name)) + ":" + std::to_string(_line); 35 | auto it = blocks_.find(uniqueName); 36 | if (it != blocks_.end()) { 37 | ::profiler::beginNonScopedBlock(it->second->GetDescriptor(), it->second->GetName().c_str()); 38 | } else { 39 | auto block = CreateBlock(utf16_to_utf8(name).c_str(), utf16_to_utf8(_filename).c_str(), _line, color); 40 | blocks_.emplace(uniqueName, block); 41 | ::profiler::beginNonScopedBlock(block->GetDescriptor(), block->GetName().c_str()); 42 | } 43 | } 44 | 45 | void Profiler::EndBlock() { 46 | ::profiler::endBlock(); 47 | } 48 | 49 | void Profiler::StartCapture() { 50 | ::profiler::setEnabled(true); 51 | isProfilerRunning_ = true; 52 | } 53 | 54 | void Profiler::StopCapture() { 55 | ::profiler::setEnabled(false); 56 | isProfilerRunning_ = false; 57 | } 58 | 59 | void Profiler::StartListen(int port) { 60 | ::profiler::startListen(port); 61 | } 62 | 63 | void Profiler::DumpToFileAndStopCapture(const char16_t* path) { 64 | ::profiler::dumpBlocksToFile(utf16_to_utf8(path).c_str()); 65 | isProfilerRunning_ = false; 66 | } 67 | 68 | bool Profiler::GetIsProfilerRunning() const { 69 | return isProfilerRunning_; 70 | } 71 | 72 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Common/Profiler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define EASY_PROFILER_STATIC 4 | #include 5 | 6 | #include "../BaseObject.h" 7 | #include "../Graphics/Color.h" 8 | #include "StringHelper.h" 9 | 10 | namespace Altseed2 { 11 | 12 | #if !USE_CBG 13 | 14 | class ProfilerBlock : public BaseObject { 15 | const ::profiler::BaseBlockDescriptor* descriptor_; 16 | std::string name_; 17 | Color color_; 18 | 19 | public: 20 | ProfilerBlock(const ::profiler::BaseBlockDescriptor* descriptor, const char* name); 21 | virtual ~ProfilerBlock() = default; 22 | std::string& GetName() { return name_; } 23 | const ::profiler::BaseBlockDescriptor* GetDescriptor() const { return descriptor_; } 24 | }; 25 | 26 | #endif 27 | 28 | class Profiler : public BaseObject { 29 | private: 30 | static std::shared_ptr instance_; 31 | bool isProfilerRunning_ = false; 32 | std::unordered_map> blocks_; 33 | static std::shared_ptr CreateBlock(const char* name, const char* _filename, int _line, const Color& color); 34 | 35 | public: 36 | static std::shared_ptr& GetInstance(); 37 | 38 | #if !USE_CBG 39 | static bool Initialize(); 40 | 41 | static void Terminate(); 42 | #endif 43 | 44 | void BeginBlock(const char16_t* name, const char16_t* _filename, int _line, const Color& color); 45 | 46 | void EndBlock(); 47 | 48 | void StartCapture(); 49 | 50 | void StopCapture(); 51 | 52 | void StartListen(int port); 53 | 54 | void DumpToFileAndStopCapture(const char16_t* path); 55 | 56 | bool GetIsProfilerRunning() const; 57 | }; 58 | 59 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Common/Resource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../BaseObject.h" 4 | 5 | #if !USE_CBG 6 | 7 | namespace Altseed2 { 8 | 9 | class Resource : public BaseObject { 10 | public: 11 | Resource() = default; 12 | virtual ~Resource() = default; 13 | virtual bool Reload() = 0; 14 | }; 15 | 16 | } // namespace Altseed2 17 | 18 | #endif -------------------------------------------------------------------------------- /core/src/Common/Resources.cpp: -------------------------------------------------------------------------------- 1 | #include "Resources.h" 2 | 3 | namespace Altseed2 { 4 | 5 | std::shared_ptr Resources::instance = nullptr; 6 | 7 | bool Resources::Initialize() { 8 | instance = MakeAsdShared(); 9 | for (int32_t i = 0; i < (int32_t)ResourceType::MAX; i++) { 10 | instance->m_containers[(ResourceType)i] = std::make_shared(); 11 | } 12 | return true; 13 | } 14 | 15 | void Resources::Terminate() { instance = nullptr; } 16 | 17 | std::shared_ptr& Resources::GetInstance() { return instance; } 18 | 19 | const std::shared_ptr& Resources::GetResourceContainer(ResourceType type) { return m_containers[type]; } 20 | 21 | const int32_t Resources::GetResourcesCount(ResourceType type) { return m_containers[type]->GetAllResouces().size(); } 22 | 23 | void Resources::Clear() { 24 | for (int32_t i = 0; i < (int32_t)ResourceType::MAX; i++) { 25 | m_containers[(ResourceType)i]->Clear(); 26 | } 27 | } 28 | 29 | void Resources::Reload() { 30 | for (int32_t i = 0; i < (int32_t)ResourceType::MAX; i++) { 31 | m_containers[(ResourceType)i]->Reload(); 32 | } 33 | } 34 | 35 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Common/Resources.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../BaseObject.h" 7 | #include "../StdIntCBG.h" 8 | #include "ResourceContainer.h" 9 | 10 | namespace Altseed2 { 11 | 12 | enum class ResourceType : int32_t { StaticFile, 13 | StreamFile, 14 | Texture2D, 15 | Font, 16 | Sound, 17 | MAX }; 18 | 19 | class Resources : public BaseObject { 20 | private: 21 | static std::shared_ptr instance; 22 | 23 | std::map> m_containers; 24 | 25 | public: 26 | #if !USE_CBG 27 | static bool Initialize(); 28 | 29 | static void Terminate(); 30 | #endif 31 | 32 | static std::shared_ptr& GetInstance(); 33 | 34 | #if !USE_CBG 35 | 36 | const std::shared_ptr& GetResourceContainer(ResourceType type); 37 | 38 | #endif 39 | 40 | const int32_t GetResourcesCount(ResourceType type); 41 | 42 | void Clear(); 43 | 44 | void Reload(); 45 | }; 46 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Common/ThreadSafeMap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../BaseObject.h" 9 | 10 | namespace Altseed2 { 11 | 12 | template 13 | class Lockable; 14 | 15 | template 16 | class Locked { 17 | private: 18 | Lockable& lockable_; 19 | std::lock_guard lock; 20 | 21 | public: 22 | Locked(Lockable& lockable) : lockable_(lockable), lock(std::lock_guard(lockable.valueMtx_)) {} 23 | 24 | T& Get() { return lockable_.value_; } 25 | }; 26 | 27 | template 28 | class Lockable { 29 | friend class Locked; 30 | 31 | private: 32 | T value_; 33 | std::mutex valueMtx_; 34 | 35 | public: 36 | Locked Lock() { return Locked(*this); } 37 | }; 38 | 39 | template 40 | class ThreadSafeMap { 41 | private: 42 | std::map> map_; 43 | std::mutex mapMutex_; 44 | 45 | public: 46 | Lockable& operator[](T key) { 47 | std::lock_guard lock(mapMutex_); 48 | return map_[key]; 49 | } 50 | }; 51 | 52 | } // namespace Altseed2 53 | -------------------------------------------------------------------------------- /core/src/Configuration.cpp: -------------------------------------------------------------------------------- 1 | #include "Configuration.h" 2 | 3 | #include "BaseObject.h" 4 | 5 | namespace Altseed2 { 6 | 7 | bool CoreModulesHasBit(CoreModules a, CoreModules b) { 8 | return (static_cast(a) & static_cast(b)) != 0; 9 | } 10 | 11 | CoreModules operator|(CoreModules a, CoreModules b) { 12 | return static_cast(static_cast(a) | static_cast(b)); 13 | } 14 | 15 | std::shared_ptr Configuration::Create() { 16 | auto res = MakeAsdShared(); 17 | return res; 18 | } 19 | 20 | Configuration::Configuration() {} 21 | Configuration::~Configuration() {} 22 | 23 | bool Configuration::GetIsFullscreen() const { return isFullscreen_; } 24 | 25 | void Configuration::SetIsFullscreen(bool isFullscreenMode) { isFullscreen_ = isFullscreenMode; } 26 | 27 | bool Configuration::GetIsResizable() const { return isResizable_; } 28 | 29 | void Configuration::SetIsResizable(bool isResizable) { isResizable_ = isResizable; } 30 | 31 | GraphicsDeviceType Configuration::GetDeviceType() const { return deviceType_; } 32 | 33 | void Configuration::SetDeviceType(GraphicsDeviceType deviceType) { deviceType_ = deviceType; } 34 | 35 | bool Configuration::GetWaitVSync() const { return waitVSync_; } 36 | 37 | void Configuration::SetWaitVSync(bool waitVSync) { waitVSync_ = waitVSync; } 38 | 39 | CoreModules Configuration::GetEnabledCoreModules() const { return coreModules_; } 40 | 41 | void Configuration::SetEnabledCoreModules(CoreModules coreModules) { coreModules_ = coreModules; } 42 | 43 | bool Configuration::GetConsoleLoggingEnabled() const { return consoleLoggingEnabled_; } 44 | 45 | void Configuration::SetConsoleLoggingEnabled(bool consoleLoggingEnabled) { consoleLoggingEnabled_ = consoleLoggingEnabled; } 46 | 47 | bool Configuration::GetFileLoggingEnabled() const { return fileLoggingEnabled_; } 48 | 49 | void Configuration::SetFileLoggingEnabled(bool fileLoggingEnabled) { fileLoggingEnabled_ = fileLoggingEnabled; } 50 | 51 | const char16_t* Configuration::GetLogFileName() const { return logFileName_.c_str(); } 52 | 53 | void Configuration::SetLogFileName(const char16_t* logFilename) { 54 | logFileName_ = logFilename == nullptr ? u"" : std::u16string(logFilename); 55 | } 56 | 57 | const char16_t* Configuration::GetToolSettingFileName() const { return toolSettingFileName_.c_str(); } 58 | void Configuration::SetToolSettingFileName(const char16_t* toolSettingFileName) { 59 | toolSettingFileName_ = toolSettingFileName == nullptr ? u"" : std::u16string(toolSettingFileName); 60 | } 61 | 62 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Configuration.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseObject.h" 4 | #include "Graphics/Graphics.h" 5 | 6 | namespace Altseed2 { 7 | enum class CoreModules : int32_t { 8 | None = 0, 9 | Window = 1, 10 | File = 1 << 1, 11 | Keyboard = 1 << 2, 12 | Mouse = 1 << 3, 13 | Joystick = 1 << 4, 14 | Graphics = 1 << 5, 15 | Tool = 1 << 6, 16 | Sound = 1 << 7, 17 | Default = Window | File | Keyboard | Mouse | Joystick | Joystick | Graphics | Sound, 18 | // internal 19 | RequireGraphics = Graphics | Tool, 20 | // internal 21 | RequireFile = File | Sound | RequireGraphics, 22 | // internal 23 | RequireWindow = Window | Keyboard | Mouse | Joystick | RequireGraphics, 24 | }; 25 | 26 | CoreModules operator|(CoreModules a, CoreModules b); 27 | bool CoreModulesHasBit(CoreModules a, CoreModules b); 28 | 29 | class Configuration : public BaseObject { 30 | private: 31 | bool isFullscreen_ = false; 32 | bool isResizable_ = false; 33 | GraphicsDeviceType deviceType_ = GraphicsDeviceType::Default; 34 | bool waitVSync_ = false; 35 | 36 | CoreModules coreModules_ = CoreModules::Default; 37 | 38 | bool consoleLoggingEnabled_ = false; 39 | bool fileLoggingEnabled_ = false; 40 | 41 | std::u16string logFileName_ = u"Log.txt"; 42 | 43 | std::u16string toolSettingFileName_ = u"imgui.ini"; 44 | 45 | public: 46 | Configuration(); 47 | ~Configuration(); 48 | static std::shared_ptr Create(); 49 | 50 | bool GetIsFullscreen() const; 51 | void SetIsFullscreen(bool isFullscreen); 52 | 53 | bool GetIsResizable() const; 54 | void SetIsResizable(bool isResizable); 55 | 56 | GraphicsDeviceType GetDeviceType() const; 57 | void SetDeviceType(GraphicsDeviceType deviceType); 58 | 59 | bool GetWaitVSync() const; 60 | void SetWaitVSync(bool waitVSync); 61 | 62 | CoreModules GetEnabledCoreModules() const; 63 | void SetEnabledCoreModules(CoreModules modules); 64 | 65 | bool GetConsoleLoggingEnabled() const; 66 | void SetConsoleLoggingEnabled(bool fileLoggingEnabled); 67 | 68 | bool GetFileLoggingEnabled() const; 69 | void SetFileLoggingEnabled(bool enabeldFileLogging); 70 | 71 | const char16_t* GetLogFileName() const; 72 | void SetLogFileName(const char16_t* logFileName); 73 | 74 | const char16_t* GetToolSettingFileName() const; 75 | void SetToolSettingFileName(const char16_t* toolSettingFileName); 76 | }; 77 | 78 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Core.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "BaseObject.h" 11 | #include "Configuration.h" 12 | #include "FPS.h" 13 | 14 | namespace Altseed2 { 15 | 16 | #if !USE_CBG 17 | class BaseObject; 18 | #endif 19 | 20 | class Core : public BaseObject { 21 | private: 22 | static std::shared_ptr instance; 23 | 24 | //! mutex for a list of baseObjects 25 | std::mutex baseObjectMtx_; 26 | 27 | //! list of baseObjects 28 | std::set baseObjects_; 29 | 30 | std::unique_ptr fps_; 31 | 32 | std::shared_ptr config_; 33 | 34 | int32_t maxBaseObjectId_; 35 | 36 | public: 37 | #if !USE_CBG 38 | 39 | //! register a base object 40 | int32_t Register(BaseObject* o); 41 | 42 | //! unregister a base object 43 | void Unregister(BaseObject* o); 44 | 45 | #endif 46 | 47 | //! get the number of base objects 48 | int32_t GetBaseObjectCount(); 49 | 50 | //! print all object's name 51 | void PrintAllBaseObjectName(); 52 | 53 | //! Initialize core and create a singleton 54 | static bool Initialize(const char16_t* title, int32_t width, int32_t height, std::shared_ptr config); 55 | 56 | #if !USE_CBG 57 | static bool Initialize(int32_t width, int32_t height); 58 | #endif 59 | 60 | //! Terminate core and dispose the singleton 61 | static void Terminate(); 62 | 63 | //! Get instance 64 | static std::shared_ptr& GetInstance(); 65 | 66 | Core(); 67 | 68 | bool DoEvent(); 69 | 70 | const float GetDeltaSecond(); 71 | 72 | const float GetCurrentFPS(); 73 | 74 | const int32_t GetTargetFPS(); 75 | void SetTargetFPS(int32_t fps); 76 | 77 | const FramerateMode GetFramerateMode(); 78 | void SetFramerateMode(FramerateMode framerateMode); 79 | }; 80 | } // namespace Altseed2 81 | -------------------------------------------------------------------------------- /core/src/FPS.cpp: -------------------------------------------------------------------------------- 1 | #include "FPS.h" 2 | 3 | #include 4 | 5 | #include "Common/Assertion.h" 6 | #include "Logger/Log.h" 7 | 8 | #ifdef _WIN32 9 | #pragma comment(lib, "Winmm.lib") 10 | #include 11 | #endif 12 | 13 | namespace Altseed2 { 14 | 15 | FPS::FPS() { 16 | previousTime_ = std::chrono::system_clock::now(); 17 | SetTarget(60); 18 | 19 | #ifdef _WIN32 20 | timeBeginPeriod(1); 21 | #endif 22 | } 23 | 24 | FPS::~FPS() { 25 | #ifdef _WIN32 26 | timeEndPeriod(1); 27 | #endif 28 | } 29 | 30 | void FPS::Update() { 31 | auto currentTime = std::chrono::system_clock::now(); 32 | auto deltans = std::chrono::duration_cast(currentTime - previousTime_); 33 | 34 | // 更新時間に余裕がある時は待機処理をする 35 | if (deltans < framens_) { 36 | auto sleepns = ((previousTime_ + framens_) - currentTime); 37 | 38 | // milliseconds単位でsleepする 39 | std::this_thread::sleep_for(std::chrono::milliseconds((sleepns.count() / 1000000) - 1)); 40 | 41 | // busy loopで調整 42 | do { 43 | currentTime = std::chrono::system_clock::now(); 44 | deltans = std::chrono::duration_cast(currentTime - previousTime_); 45 | } while (deltans < framens_); 46 | } 47 | 48 | // 計測処理を行う 49 | if (framerateMode_ == FramerateMode::Constant) { 50 | // 固定FPSでは経過時間は一定として扱う 51 | deltaSecond_ = 1.0f / targetFPS_; 52 | } else { 53 | deltaSecond_ = static_cast(deltans.count()) / nano; 54 | } 55 | 56 | currentFPS_ = 1.0f / deltaSecond_; 57 | 58 | previousTime_ = currentTime; 59 | } 60 | 61 | float FPS::GetDeltaSecond() const { return deltaSecond_; } 62 | float FPS::GetCurrentFPS() const { return currentFPS_; } 63 | 64 | int32_t FPS::GetTargetFPS() const { return targetFPS_; } 65 | void FPS::SetTarget(int32_t fps) { 66 | if (fps <= 0) { 67 | Log::GetInstance()->Error(LogCategory::Core, u"FPS::SetTarget: Target FPS should be larger than zero"); 68 | return; 69 | } 70 | 71 | targetFPS_ = fps; 72 | framens_ = std::chrono::nanoseconds(nano / fps); 73 | } 74 | 75 | FramerateMode FPS::GetFramerateMode() const { return framerateMode_; } 76 | void FPS::SetFramerateMode(FramerateMode framerateMode) { framerateMode_ = framerateMode; } 77 | 78 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/FPS.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "BaseObject.h" 5 | 6 | namespace Altseed2 { 7 | 8 | enum class FramerateMode : int32_t { 9 | Variable, 10 | Constant, 11 | }; 12 | 13 | #if !USE_CBG 14 | class FPS { 15 | private: 16 | float currentFPS_ = 0.0f; 17 | int32_t targetFPS_; 18 | float deltaSecond_ = 0.0f; 19 | FramerateMode framerateMode_ = FramerateMode::Variable; 20 | 21 | std::chrono::system_clock::time_point previousTime_; 22 | std::chrono::nanoseconds framens_; 23 | 24 | static const int64_t nano = std::chrono::duration_cast(std::chrono::seconds(1)).count(); 25 | 26 | public: 27 | FPS(); 28 | ~FPS(); 29 | void Update(); 30 | 31 | float GetDeltaSecond() const; 32 | float GetCurrentFPS() const; 33 | 34 | int32_t GetTargetFPS() const; 35 | void SetTarget(int32_t fps); 36 | 37 | FramerateMode GetFramerateMode() const; 38 | void SetFramerateMode(FramerateMode framerateMode); 39 | }; 40 | 41 | #endif 42 | 43 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Buffer.cpp: -------------------------------------------------------------------------------- 1 | #include "Buffer.h" 2 | 3 | #include "../Logger/Log.h" 4 | #include "Graphics.h" 5 | 6 | namespace Altseed2 { 7 | 8 | Buffer::Buffer(std::shared_ptr buffer) { 9 | buffer_ = buffer; 10 | } 11 | 12 | // ユーザーがRead,Writeを指定できるようにすべきかも 13 | std::shared_ptr Buffer::Create(BufferUsageType usage, int32_t size) { 14 | auto graphics = Graphics::GetInstance(); 15 | if (graphics == nullptr) { 16 | Log::GetInstance()->Error(LogCategory::Core, u"Graphics is not initialized."); 17 | return nullptr; 18 | } 19 | 20 | auto buffer = graphics->CreateBuffer((LLGI::BufferUsageType)usage, size); 21 | 22 | if (buffer == nullptr) { 23 | Log::GetInstance()->Error(LogCategory::Core, u"Buffer::Create: Failed to create buffer"); 24 | return nullptr; 25 | } 26 | 27 | return MakeAsdShared(buffer); 28 | } 29 | 30 | void* Buffer::Lock() { 31 | return buffer_->Lock(); 32 | } 33 | 34 | void Buffer::Unlock() { 35 | buffer_->Unlock(); 36 | } 37 | 38 | int32_t Buffer::GetSize() { 39 | return buffer_->GetSize(); 40 | } 41 | 42 | BufferUsageType Buffer::GetBufferUsage() { 43 | return (BufferUsageType)buffer_->GetBufferUsage(); 44 | } 45 | 46 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Buffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../BaseObject.h" 6 | #include "../StdIntCBG.h" 7 | 8 | namespace Altseed2 { 9 | 10 | enum class BufferUsageType : int32_t { 11 | Index = 1 << 0, 12 | Vertex = 1 << 1, 13 | Constant = 1 << 2, 14 | Compute = 1 << 3, 15 | MapRead = 1 << 4, 16 | MapWrite = 1 << 5, 17 | CopySrc = 1 << 6, 18 | CopyDst = 1 << 7, 19 | }; 20 | 21 | inline BufferUsageType operator|(BufferUsageType lhs, BufferUsageType rhs) { 22 | return static_cast(static_cast(lhs) | static_cast(rhs)); 23 | } 24 | 25 | inline BufferUsageType operator&(BufferUsageType lhs, BufferUsageType rhs) { 26 | return static_cast(static_cast(lhs) & static_cast(rhs)); 27 | } 28 | 29 | class Buffer : public BaseObject { 30 | private: 31 | std::shared_ptr buffer_ = nullptr; 32 | 33 | public: 34 | Buffer(std::shared_ptr buffer); 35 | 36 | static std::shared_ptr Create(BufferUsageType usage, int32_t size); 37 | 38 | void* Lock(); 39 | void Unlock(); 40 | 41 | int32_t GetSize(); 42 | 43 | BufferUsageType GetBufferUsage(); 44 | 45 | #if !USE_CBG 46 | std::shared_ptr GetLL() { return buffer_; } 47 | #endif 48 | }; 49 | 50 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/BuiltinShader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "../BaseObject.h" 5 | #include "../Common/StringHelper.h" 6 | #include "PostEffect/Downsample_PS.h" 7 | #include "PostEffect/GaussianBlur_PS.h" 8 | #include "PostEffect/GrayScale_PS.h" 9 | #include "PostEffect/HighLuminance_PS.h" 10 | #include "PostEffect/LightBloom_PS.h" 11 | #include "PostEffect/Sepia_PS.h" 12 | #include "PostEffect/TextureMix_PS.h" 13 | 14 | namespace Altseed2 { 15 | 16 | class Shader; 17 | 18 | enum class BuiltinShaderType : int32_t { 19 | SpriteUnlitVS, 20 | SpriteUnlitPS, 21 | FontUnlitPS, 22 | }; 23 | 24 | class BuiltinShader : public BaseObject { 25 | private: 26 | std::map> shaders_; 27 | 28 | public: 29 | std::shared_ptr Create(BuiltinShaderType type); 30 | 31 | const char16_t* GetDownsampleShader() const { return downsample_ps; } 32 | const char16_t* GetSepiaShader() const { return sepia_ps; } 33 | const char16_t* GetGrayScaleShader() const { return grayscale_ps; } 34 | const char16_t* GetGaussianBlurShader() const { return gaussianblur_ps; } 35 | const char16_t* GetHighLuminanceShader() const { return highluminance_ps; } 36 | const char16_t* GetLightBloomShader() const { return lightbloom_ps; } 37 | const char16_t* GetTextureMixShader() const { return texturemix_ps; } 38 | }; 39 | 40 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Color.cpp: -------------------------------------------------------------------------------- 1 | #include "Color.h" 2 | 3 | #include "Graphics.h" 4 | 5 | namespace Altseed2 { 6 | Color::Color() : A(TextureDefaultColor), R(TextureDefaultColor), G(TextureDefaultColor), B(TextureDefaultColor) {} 7 | 8 | Color::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a) : A(a), R(r), G(g), B(b) {} 9 | 10 | Color Color::operator*(const Color& right) { 11 | return Color( 12 | R * right.R / TextureDefaultColor, 13 | G * right.G / TextureDefaultColor, 14 | B * right.B / TextureDefaultColor, 15 | A * right.A / TextureDefaultColor); 16 | } 17 | 18 | Color& Color::operator*=(const Color& right) { 19 | R = R * right.R / TextureDefaultColor; 20 | G = G * right.G / TextureDefaultColor; 21 | B = B * right.B / TextureDefaultColor; 22 | A = A * right.A / TextureDefaultColor; 23 | return *this; 24 | } 25 | 26 | bool Color::operator==(const Color& right) { return R == right.R && G == right.G && B == right.B && A == right.A; } 27 | 28 | Color::operator Color_C() const { return Color_C{R, G, B, A}; } 29 | 30 | Color_C::operator Color() const { return Color(R, G, B, A); } 31 | 32 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Color.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace Altseed2 { 7 | 8 | struct Color_C; 9 | 10 | struct Color { 11 | public: 12 | uint8_t R; 13 | uint8_t G; 14 | uint8_t B; 15 | uint8_t A; 16 | 17 | Color(); 18 | Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a); 19 | 20 | Color operator*(const Color& right); 21 | Color& operator*=(const Color& right); 22 | bool operator==(const Color& right); 23 | 24 | operator Color_C() const; 25 | 26 | LLGI::Color8 ToLL() const { return LLGI::Color8(R, G, B, A); } 27 | }; 28 | 29 | struct Color_C { 30 | public: 31 | uint8_t R; 32 | uint8_t G; 33 | uint8_t B; 34 | uint8_t A; 35 | 36 | operator Color() const; 37 | }; 38 | 39 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/ComputePipelineState.cpp: -------------------------------------------------------------------------------- 1 | #include "ComputePipelineState.h" 2 | 3 | #include "../Logger/Log.h" 4 | 5 | namespace Altseed2 { 6 | 7 | ComputePipelineState::ComputePipelineState() { 8 | propertyBlock_ = MakeAsdShared(); 9 | computeShader_ = nullptr; 10 | pipelineState_ = nullptr; 11 | } 12 | 13 | std::shared_ptr ComputePipelineState::Create() { 14 | return MakeAsdShared(); 15 | } 16 | 17 | Vector4F ComputePipelineState::GetVector4F(const char16_t* key) const { 18 | return propertyBlock_->GetVector4F(key); 19 | } 20 | 21 | void ComputePipelineState::SetVector4F(const char16_t* key, const Vector4F& value) { 22 | propertyBlock_->SetVector4F(key, value); 23 | } 24 | 25 | Matrix44F ComputePipelineState::GetMatrix44F(const char16_t* key) const { 26 | return propertyBlock_->GetMatrix44F(key); 27 | } 28 | 29 | void ComputePipelineState::SetMatrix44F(const char16_t* key, const Matrix44F& value) { 30 | propertyBlock_->SetMatrix44F(key, value); 31 | } 32 | 33 | void ComputePipelineState::SetShader(std::shared_ptr shader) { 34 | computeShader_ = shader; 35 | requireCompile = true; 36 | } 37 | 38 | std::shared_ptr ComputePipelineState::GetShader() { 39 | return computeShader_; 40 | } 41 | 42 | std::shared_ptr ComputePipelineState::GetPropertyBlock() const { 43 | return propertyBlock_; 44 | } 45 | 46 | std::shared_ptr ComputePipelineState::GetPipelineState() { 47 | if (pipelineState_ != nullptr && !requireCompile) { 48 | return pipelineState_; 49 | } 50 | 51 | auto g = Graphics::GetInstance()->GetGraphicsLLGI(); 52 | 53 | pipelineState_ = LLGI::CreateSharedPtr(g->CreatePiplineState()); 54 | 55 | pipelineState_->SetShader(LLGI::ShaderStageType::Compute, computeShader_->Get()); 56 | 57 | pipelineState_->Compile(); 58 | requireCompile = false; 59 | 60 | return pipelineState_; 61 | } 62 | 63 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/ComputePipelineState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../BaseObject.h" 6 | #include "Shader.h" 7 | 8 | namespace Altseed2 { 9 | 10 | enum class VertexLayoutFormat { 11 | R32G32B32_FLOAT, 12 | R32G32B32A32_FLOAT, 13 | R8G8B8A8_UNORM, 14 | R8G8B8A8_UINT, 15 | R32G32_FLOAT, 16 | R32_FLOAT, 17 | }; 18 | 19 | class ComputePipelineState : public BaseObject { 20 | private: 21 | std::shared_ptr computeShader_; 22 | std::shared_ptr pipelineState_ = nullptr; 23 | 24 | std::shared_ptr propertyBlock_; 25 | 26 | bool requireCompile = true; 27 | 28 | public: 29 | ComputePipelineState(); 30 | 31 | static std::shared_ptr Create(); 32 | 33 | Vector4F GetVector4F(const char16_t* key) const; 34 | void SetVector4F(const char16_t* key, const Vector4F& value); 35 | 36 | Matrix44F GetMatrix44F(const char16_t* key) const; 37 | void SetMatrix44F(const char16_t* key, const Matrix44F& value); 38 | 39 | void SetShader(std::shared_ptr shader); 40 | std::shared_ptr GetShader(); 41 | 42 | std::shared_ptr GetPropertyBlock() const; 43 | 44 | #if !USE_CBG 45 | std::shared_ptr GetPipelineState(); 46 | #endif 47 | }; 48 | 49 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/ImageFont.cpp: -------------------------------------------------------------------------------- 1 | #include "ImageFont.h" 2 | 3 | #include 4 | 5 | #include "../IO/File.h" 6 | #include "../Logger/Log.h" 7 | #include "Graphics.h" 8 | 9 | namespace Altseed2 { 10 | ImageFont::ImageFont(std::shared_ptr baseFont) : baseFont_(baseFont), Font(u"") {} 11 | 12 | void ImageFont::AddImageGlyph(const int32_t character, std::shared_ptr texture) { imageGlyphs_[character] = texture; } 13 | std::shared_ptr ImageFont::GetImageGlyph(const int32_t character) { 14 | if (imageGlyphs_.count(character) > 0) return imageGlyphs_[character]; 15 | return nullptr; 16 | } 17 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/ImageFont.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../Common/Resource.h" 8 | #include "../IO/StaticFile.h" 9 | #include "../Math/Vector2F.h" 10 | #include "../Math/Vector2I.h" 11 | #include "Color.h" 12 | #include "Font.h" 13 | #include "Texture2D.h" 14 | 15 | namespace Altseed2 { 16 | 17 | class ImageFont : public Font { 18 | private: 19 | std::map> imageGlyphs_; 20 | std::shared_ptr baseFont_; 21 | 22 | public: 23 | ImageFont(std::shared_ptr baseFont); 24 | 25 | int32_t GetSamplingSize() override { return baseFont_->GetSamplingSize(); } 26 | float GetAscent() override { return baseFont_->GetAscent(); } 27 | float GetDescent() override { return baseFont_->GetDescent(); } 28 | float GetLineGap() override { return baseFont_->GetLineGap(); } 29 | float GetEmSize() override { return baseFont_->GetEmSize(); } 30 | 31 | bool GetIsStaticFont() override { return baseFont_->GetIsStaticFont(); } 32 | 33 | std::shared_ptr GetGlyph(const int32_t character) override { return baseFont_->GetGlyph(character); } 34 | std::shared_ptr GetFontTexture(int32_t index) override { return baseFont_->GetFontTexture(index); } 35 | 36 | int32_t GetKerning(const int32_t c1, const int32_t c2) override { return baseFont_->GetKerning(c1, c2); } 37 | 38 | void AddImageGlyph(const int32_t character, std::shared_ptr texture) override; 39 | std::shared_ptr GetImageGlyph(const int32_t character) override; 40 | }; 41 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/LLGIWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "LLGIWindow.h" 2 | 3 | namespace Altseed2 { 4 | 5 | LLGIWindow::LLGIWindow(GLFWwindow* glfwWindow_) : glfwWindow(glfwWindow_) {} 6 | 7 | void* LLGIWindow::GetNativePtr(int32_t index) { 8 | #ifdef _WIN32 9 | if (index == 0) { 10 | return glfwGetWin32Window(glfwWindow); 11 | } 12 | 13 | return GetModuleHandle(0); 14 | #endif 15 | 16 | #ifdef __APPLE__ 17 | return glfwGetCocoaWindow(glfwWindow); 18 | #endif 19 | 20 | #ifdef __linux__ 21 | if (index == 0) { 22 | return glfwGetX11Display(); 23 | } 24 | 25 | return reinterpret_cast(glfwGetX11Window(glfwWindow)); 26 | #endif 27 | } 28 | 29 | LLGI::Vec2I LLGIWindow::GetWindowSize() const { 30 | int w, h; 31 | glfwGetWindowSize(glfwWindow, &w, &h); 32 | return LLGI::Vec2I(w, h); 33 | } 34 | 35 | LLGI::Vec2I LLGIWindow::GetFrameBufferSize() const { 36 | int w, h; 37 | glfwGetFramebufferSize(glfwWindow, &w, &h); 38 | return LLGI::Vec2I(w, h); 39 | } 40 | 41 | } // namespace Altseed2 42 | -------------------------------------------------------------------------------- /core/src/Graphics/LLGIWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Common/PlatformIncludes.h" 4 | #include "LLGI.Base.h" 5 | 6 | #if !USE_CBG 7 | 8 | namespace Altseed2 { 9 | class LLGIWindow : public LLGI::Window { 10 | private: 11 | GLFWwindow* glfwWindow; 12 | 13 | public: 14 | LLGIWindow(GLFWwindow* glfwWindow_); 15 | void* GetNativePtr(int32_t index) override; 16 | LLGI::Vec2I GetWindowSize() const override; 17 | GLFWwindow* GetGlfwWindow() const { return glfwWindow; } 18 | 19 | LLGI::Vec2I GetFrameBufferSize() const override; 20 | 21 | bool OnNewFrame() override { return glfwWindowShouldClose(glfwWindow) == GL_FALSE; } 22 | }; 23 | 24 | } // namespace Altseed2 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /core/src/Graphics/PostEffect/Downsample_PS.h: -------------------------------------------------------------------------------- 1 | static const char16_t* downsample_ps = 2 | uR"( 3 | 4 | Texture2D mainTex : register(t0); 5 | SamplerState mainSamp : register(s0); 6 | 7 | struct PS_INPUT 8 | { 9 | float4 Position : SV_POSITION; 10 | float4 Color : COLOR0; 11 | float2 UV1 : UV0; 12 | float2 UV2 : UV1; 13 | }; 14 | 15 | cbuffer Consts : register(b1) 16 | { 17 | float4 imageSize; 18 | } 19 | 20 | float4 main(PS_INPUT input) : SV_TARGET 21 | { 22 | float4 color1 = mainTex.Sample(mainSamp, input.UV1 + float2(-0.5, -0.5) / imageSize); 23 | float4 color2 = mainTex.Sample(mainSamp, input.UV1 + float2(+0.5, -0.5) / imageSize); 24 | float4 color3 = mainTex.Sample(mainSamp, input.UV1 + float2(-0.5, +0.5) / imageSize); 25 | float4 color4 = mainTex.Sample(mainSamp, input.UV1 + float2(+0.5, +0.5) / imageSize); 26 | return (color1 + color2 + color3 + color4) * 0.25; 27 | } 28 | 29 | )"; -------------------------------------------------------------------------------- /core/src/Graphics/PostEffect/GaussianBlur_PS.h: -------------------------------------------------------------------------------- 1 | static const char16_t* gaussianblur_ps = 2 | uR"( 3 | Texture2D mainTex : register(t0); 4 | SamplerState mainSamp : register(s0); 5 | 6 | cbuffer Consts : register(b1) 7 | { 8 | float4 weight; 9 | }; 10 | 11 | uint2 GetTextureSize(Texture2D texture_){ 12 | uint width, height; 13 | texture_.GetDimensions(width, height); 14 | return uint2(width, height); 15 | } 16 | 17 | struct PS_INPUT 18 | { 19 | float4 Position : SV_POSITION; 20 | float4 Color : COLOR0; 21 | float2 UV1 : UV0; 22 | float2 UV2 : UV1; 23 | }; 24 | 25 | float4 main(PS_INPUT input ) : SV_TARGET 26 | { 27 | uint2 texSize = GetTextureSize(mainTex); 28 | 29 | #ifdef BLUR_X 30 | float2 accum = float2(1.0 / texSize.x, 0.0); 31 | float2 half_ = float2(0.5 / texSize.x, 0.0); 32 | float2 adder = float2(2.0 / texSize.x, 0.0); 33 | #endif 34 | 35 | #ifdef BLUR_Y 36 | float2 accum = float2(0.0, 1.0 / texSize.y); 37 | float2 half_ = float2(0.0, 0.5 / texSize.y); 38 | float2 adder = float2(0.0, 2.0 / texSize.y); 39 | #endif 40 | 41 | float4 output_ = (mainTex.Sample(mainSamp, input.UV1 + half_ + accum) + 42 | mainTex.Sample(mainSamp, input.UV1 + half_ - accum)) * 43 | weight.x; 44 | if(output_.a == 0.0f) discard; 45 | accum += adder; 46 | output_ += (mainTex.Sample(mainSamp, input.UV1 + half_ + accum) + 47 | mainTex.Sample(mainSamp, input.UV1 + half_ - accum)) * 48 | weight.y; 49 | accum += adder; 50 | output_ += (mainTex.Sample(mainSamp, input.UV1 + half_ + accum) + 51 | mainTex.Sample(mainSamp, input.UV1 + half_ - accum)) * 52 | weight.z; 53 | 54 | output_.a = 1.0; 55 | 56 | return output_; 57 | } 58 | )"; -------------------------------------------------------------------------------- /core/src/Graphics/PostEffect/GrayScale_PS.h: -------------------------------------------------------------------------------- 1 | static const char16_t* grayscale_ps = 2 | uR"( 3 | Texture2D mainTex : register(t0); 4 | SamplerState mainSamp : register(s0); 5 | 6 | struct PS_INPUT 7 | { 8 | float4 Position : SV_POSITION; 9 | float4 Color : COLOR0; 10 | float2 UV1 : UV0; 11 | float2 UV2 : UV1; 12 | }; 13 | 14 | float4 main(PS_INPUT input ) : SV_TARGET 15 | { 16 | float4 outputedColor = mainTex.Sample(mainSamp, input.UV1); 17 | if(outputedColor.a == 0.0f) discard; 18 | float y = outputedColor.r * 0.298912f + outputedColor.g * 0.586611f + outputedColor.b * 0.114478f; 19 | outputedColor.rgb = y; 20 | return outputedColor; 21 | } 22 | )"; -------------------------------------------------------------------------------- /core/src/Graphics/PostEffect/HighLuminance_PS.h: -------------------------------------------------------------------------------- 1 | static const char16_t* highluminance_ps = 2 | uR"( 3 | 4 | struct PS_INPUT 5 | { 6 | float4 Position : SV_POSITION; 7 | float4 Color : COLOR0; 8 | float2 UV1 : UV0; 9 | float2 UV2 : UV1; 10 | }; 11 | 12 | cbuffer Consts : register(b1) 13 | { 14 | float4 exposure; 15 | float4 threshold; 16 | }; 17 | 18 | Texture2D mainTex : register(t0); 19 | SamplerState mainSamp : register(s0); 20 | 21 | float3 getLuminance(float3 color) 22 | { 23 | return float3(1, 1, 1) * (color.x * 0.300000 + color.y * 0.590000 + color.z * 0.110000); 24 | } 25 | 26 | float4 main(PS_INPUT input) : SV_TARGET 27 | { 28 | float4 color = mainTex.Sample(mainSamp, input.UV1); 29 | color.xyz = saturate(color.xyz); 30 | 31 | #ifdef LUM_MODE 32 | float3 lum = getLuminance(color.xyz); 33 | float3 bloomedLum = max(0.0, lum - threshold) * exposure; 34 | float3 bloomedPower = min(max(bloomedLum / 2.0, 0.0), 1.0); 35 | color.xyz *= bloomedPower; 36 | #else 37 | float3 bloomedLum = max(0.0, color - threshold) * exposure; 38 | bloomedLum = saturate(bloomedLum); 39 | color.xyz = bloomedLum; 40 | #endif 41 | 42 | return color; 43 | } 44 | 45 | )"; -------------------------------------------------------------------------------- /core/src/Graphics/PostEffect/LightBloom_PS.h: -------------------------------------------------------------------------------- 1 | static const char16_t* lightbloom_ps = 2 | uR"( 3 | 4 | struct PS_INPUT 5 | { 6 | float4 Position : SV_POSITION; 7 | float4 Color : COLOR0; 8 | float2 UV1 : UV0; 9 | float2 UV2 : UV1; 10 | }; 11 | 12 | cbuffer Consts : register(b1) 13 | { 14 | float4 imageSize; 15 | float4 intensity; 16 | }; 17 | 18 | Texture2D mainTex : register(t0); 19 | SamplerState mainSamp : register(s0); 20 | 21 | static float weight[4]; 22 | 23 | float gauss(float x, float sigma) 24 | { 25 | return exp(- 0.5 * (x * x) / (sigma * sigma)); 26 | } 27 | 28 | float4 getGaussianBlur(float2 uv) 29 | { 30 | float weightTotal = 0; 31 | for(int i = 0; i < 4; ++i) 32 | { 33 | weight[i] = gauss(i + 0.5, intensity.x); 34 | weightTotal += weight[i] * 2.0; 35 | } 36 | 37 | float4 outputColor = float4(0.0, 0.0, 0.0, 0.0); 38 | 39 | for(int i = 0; i < 4; ++i) 40 | { 41 | #ifdef BLUR_X 42 | float2 nShiftedUV = uv + float2(-(i + 0.5) / imageSize.x, 0.0); 43 | float2 pShiftedUV = uv + float2(+(i + 0.5) / imageSize.x, 0.0); 44 | #endif 45 | #ifdef BLUR_Y 46 | float2 nShiftedUV = uv + float2(0.0, -(i + 0.5) / imageSize.y); 47 | float2 pShiftedUV = uv + float2(0.0, +(i + 0.5) / imageSize.y); 48 | #endif 49 | outputColor += mainTex.Sample(mainSamp, nShiftedUV) * weight[i] / weightTotal; 50 | outputColor += mainTex.Sample(mainSamp, pShiftedUV) * weight[i] / weightTotal; 51 | } 52 | 53 | return outputColor; 54 | } 55 | 56 | float4 main(PS_INPUT input) : SV_TARGET 57 | { 58 | return getGaussianBlur(input.UV1); 59 | } 60 | 61 | )"; -------------------------------------------------------------------------------- /core/src/Graphics/PostEffect/Sepia_PS.h: -------------------------------------------------------------------------------- 1 | static const char16_t* sepia_ps = 2 | uR"( 3 | Texture2D mainTex : register(t0); 4 | SamplerState mainSamp : register(s0); 5 | 6 | struct PS_INPUT 7 | { 8 | float4 Position : SV_POSITION; 9 | float4 Color : COLOR0; 10 | float2 UV1 : UV0; 11 | float2 UV2 : UV1; 12 | }; 13 | 14 | float4 main(PS_INPUT input) : SV_TARGET 15 | { 16 | float4 outputedColor = mainTex.Sample(mainSamp, input.UV1); 17 | if(outputedColor.a == 0.0f) discard; 18 | float y = outputedColor.r * 0.298912f + outputedColor.g * 0.586611f + outputedColor.b * 0.114478f; 19 | outputedColor.rgb = y; 20 | outputedColor.r *= 1.332249; 21 | outputedColor.r = outputedColor.r > 1.0f? 1.0f: outputedColor.r; 22 | outputedColor.g *= 0.921369f; 23 | outputedColor.b *= 0.535390f; 24 | return outputedColor; 25 | } 26 | 27 | )"; -------------------------------------------------------------------------------- /core/src/Graphics/PostEffect/TextureMix_PS.h: -------------------------------------------------------------------------------- 1 | static const char16_t* texturemix_ps = 2 | uR"( 3 | 4 | struct PS_INPUT 5 | { 6 | float4 Position : SV_POSITION; 7 | float4 Color : COLOR0; 8 | float2 UV1 : UV0; 9 | float2 UV2 : UV1; 10 | }; 11 | 12 | cbuffer Consts : register(b1) 13 | { 14 | float4 weight; 15 | }; 16 | 17 | Texture2D mainTex1 : register(t0); 18 | SamplerState mainSamp1 : register(s0); 19 | 20 | Texture2D mainTex2 : register(t1); 21 | SamplerState mainSamp2 : register(s1); 22 | 23 | float4 main(PS_INPUT input) : SV_TARGET 24 | { 25 | float4 color1 = mainTex1.Sample(mainSamp1, input.UV1); 26 | float4 color2 = mainTex2.Sample(mainSamp2, input.UV1); 27 | return color1 + color2 * weight; 28 | } 29 | 30 | )"; -------------------------------------------------------------------------------- /core/src/Graphics/RenderTexture.cpp: -------------------------------------------------------------------------------- 1 | #include "RenderTexture.h" 2 | 3 | #include "../Logger/Log.h" 4 | #include "CommandList.h" 5 | #include "Graphics.h" 6 | #include "Texture2D.h" 7 | 8 | namespace Altseed2 { 9 | 10 | RenderTexture::RenderTexture(const std::shared_ptr& texture) 11 | : TextureBase(texture) { 12 | SetInstanceName(__FILE__); 13 | } 14 | 15 | RenderTexture::~RenderTexture() {} 16 | 17 | std::shared_ptr RenderTexture::Create(Vector2I size, TextureFormatType format) { 18 | auto graphics = Graphics::GetInstance(); 19 | if (graphics == nullptr) { 20 | Log::GetInstance()->Error(LogCategory::Core, u"Graphics is not initialized."); 21 | return nullptr; 22 | } 23 | 24 | auto texture = graphics->CreateRenderTexture(size.X, size.Y, format); 25 | 26 | if (texture == nullptr) { 27 | Log::GetInstance()->Error(LogCategory::Core, u"RenderTexture::Create: Failed to CreateTexture"); 28 | return nullptr; 29 | } 30 | 31 | return MakeAsdShared(texture); 32 | } 33 | 34 | bool RenderTexture::Save(const char16_t* path) { 35 | RETURN_IF_NULL(path, false); 36 | Graphics::GetInstance()->GetCommandList()->SaveRenderTexture(path, CreateAndAddSharedPtr(this)); 37 | return true; 38 | } 39 | 40 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/RenderTexture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "../Common/Resource.h" 13 | #include "../Common/Resources.h" 14 | #include "../Math/Vector2I.h" 15 | #include "Graphics.h" 16 | #include "TextureBase.h" 17 | 18 | namespace Altseed2 { 19 | class RenderTexture : public TextureBase { 20 | public: 21 | RenderTexture(const std::shared_ptr& texture); 22 | virtual ~RenderTexture(); 23 | 24 | static std::shared_ptr Create(Vector2I size, TextureFormatType format = TextureFormatType::R8G8B8A8_UNORM); 25 | 26 | bool Save(const char16_t* path) override; 27 | 28 | bool Reload() override { 29 | assert(false); 30 | return false; 31 | }; 32 | }; 33 | 34 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Renderer/CullingSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "../../BaseObject.h" 11 | #include "../../Common/Array.h" 12 | #include "../../Math/RectF.h" 13 | 14 | namespace Altseed2 { 15 | class Rendered; 16 | class CullingSystem : public BaseObject { 17 | private: 18 | static std::shared_ptr instance_; 19 | 20 | std::mutex mtx_; 21 | b2DynamicTree dynamicTree_; 22 | std::map proxyIdRenderedMap_; 23 | std::map renderedProxyIdMap_; 24 | std::map proxyIdAABBMap_; 25 | 26 | std::set updateIds_; 27 | 28 | std::shared_ptr drawingRenderedIds_; 29 | 30 | public: 31 | CullingSystem(); 32 | virtual ~CullingSystem(); 33 | 34 | static std::shared_ptr& GetInstance(); 35 | 36 | static bool Initialize(); 37 | 38 | static void Terminate(); 39 | 40 | #if !USE_CBG 41 | //! for Core only 42 | void RequestUpdateAABB(Rendered* rendered); 43 | bool GetIsExists(Rendered* rendered); 44 | #endif 45 | 46 | void Register(std::shared_ptr rendered); 47 | void UpdateAABB(); 48 | void Cull(RectF rect); 49 | void Unregister(std::shared_ptr rendered); 50 | 51 | int32_t GetDrawingRenderedCount(); 52 | std::shared_ptr GetDrawingRenderedIds(); 53 | 54 | #if !USE_CBG 55 | //! Don't call from external 56 | bool QueryCallback(int32_t id); 57 | #endif 58 | }; 59 | 60 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Renderer/Rendered.cpp: -------------------------------------------------------------------------------- 1 | #include "Rendered.h" 2 | 3 | #include "CullingSystem.h" 4 | 5 | namespace Altseed2 { 6 | Rendered::Rendered() : cullingSystem_(CullingSystem::GetInstance()) {} 7 | Rendered::~Rendered() { 8 | if (cullingSystem_ != nullptr) { 9 | auto exists = cullingSystem_->GetIsExists(this); 10 | ASD_ASSERT(!exists, "Rendered must be unregisterd from culling system."); 11 | } 12 | } 13 | 14 | const Matrix44F& Rendered::GetTransform() const { return transform_; } 15 | 16 | void Rendered::SetTransform(const Matrix44F& transform) { 17 | transform_ = transform; 18 | cullingSystem_->RequestUpdateAABB(this); 19 | } 20 | 21 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Renderer/Rendered.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../../BaseObject.h" 6 | #include "../../Math/Matrix44F.h" 7 | #include "../Color.h" 8 | 9 | namespace Altseed2 { 10 | class CullingSystem; 11 | class Rendered : public BaseObject { 12 | protected: 13 | Matrix44F transform_; 14 | std::shared_ptr cullingSystem_; 15 | 16 | public: 17 | Rendered(); 18 | virtual ~Rendered(); 19 | 20 | const Matrix44F& GetTransform() const; 21 | void SetTransform(const Matrix44F& transform); 22 | 23 | #if !USE_CBG 24 | 25 | virtual b2AABB GetAABB() { return b2AABB(); } 26 | 27 | #endif 28 | }; 29 | 30 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Renderer/RenderedCamera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Math/Matrix44F.h" 4 | #include "../../Math/Vector2F.h" 5 | #include "../CommandList.h" 6 | #include "Rendered.h" 7 | 8 | namespace Altseed2 { 9 | 10 | class RenderTexture; 11 | 12 | class RenderedCamera : public BaseObject { 13 | std::shared_ptr targetTexture_; 14 | RenderPassParameter renderPassParameter_; 15 | 16 | Matrix44F matProjection_; 17 | Matrix44F matView_; 18 | 19 | public: 20 | RenderedCamera(); 21 | 22 | static std::shared_ptr Create(); 23 | 24 | std::shared_ptr GetTargetTexture(); 25 | void SetTargetTexture(const std::shared_ptr& renderPassParameter); 26 | 27 | RenderPassParameter GetRenderPassParameter() const; 28 | void SetRenderPassParameter(const RenderPassParameter targetTexture); 29 | 30 | Matrix44F GetProjectionMatrix() const; 31 | 32 | Matrix44F GetViewMatrix() const; 33 | void SetViewMatrix(Matrix44F matrix); 34 | 35 | #if !USE_CBG 36 | 37 | b2AABB GetAABB(); 38 | 39 | #endif 40 | }; 41 | 42 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Renderer/RenderedPolygon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include "../../Common/Array.h" 9 | #include "../../Math/RectF.h" 10 | #include "../Color.h" 11 | #include "../Material.h" 12 | #include "../Texture2D.h" 13 | #include "Rendered.h" 14 | 15 | namespace Altseed2 { 16 | 17 | class RenderedPolygon : public Rendered { 18 | private: 19 | AlphaBlend alphaBlend_; 20 | std::shared_ptr buffers_; 21 | std::shared_ptr vertexes_; 22 | std::shared_ptr texture_; 23 | std::shared_ptr material_; 24 | RectF src_; 25 | 26 | public: 27 | static std::shared_ptr Create(); 28 | 29 | AlphaBlend GetAlphaBlend() const { return alphaBlend_; } 30 | void SetAlphaBlend(AlphaBlend alphaBlend) { alphaBlend_ = alphaBlend; } 31 | 32 | std::shared_ptr GetBuffers() const { return buffers_; } 33 | void SetBuffers(const std::shared_ptr buffers) { buffers_ = buffers; } 34 | 35 | std::shared_ptr GetVertexes(); 36 | void SetVertexes(std::shared_ptr vertexes); 37 | 38 | void CreateVertexesByVector2F(std::shared_ptr vectors); 39 | void OverwriteVertexesColor(Color color); 40 | 41 | RectF GetSrc() const; 42 | void SetSrc(const RectF& src); 43 | 44 | std::shared_ptr GetTexture() const; 45 | void SetTexture(const std::shared_ptr& texture); 46 | 47 | std::shared_ptr GetMaterial() const; 48 | void SetMaterial(const std::shared_ptr& material); 49 | 50 | void SetDefaultIndexBuffer(); 51 | 52 | #if !USE_CBG 53 | b2AABB GetAABB() override; 54 | #endif 55 | }; 56 | 57 | } // namespace Altseed2 58 | -------------------------------------------------------------------------------- /core/src/Graphics/Renderer/RenderedSprite.cpp: -------------------------------------------------------------------------------- 1 | #include "RenderedSprite.h" 2 | 3 | #include "../../Common/Array.h" 4 | #include "../Material.h" 5 | #include "CullingSystem.h" 6 | 7 | namespace Altseed2 { 8 | 9 | std::shared_ptr RenderedSprite::Create() { 10 | auto s = MakeAsdShared(); 11 | s->SetAlphaBlend(AlphaBlend::Normal()); 12 | s->texture_ = nullptr; 13 | s->material_ = nullptr; 14 | return s; 15 | } 16 | 17 | RectF RenderedSprite::GetSrc() const { return src_; } 18 | 19 | void RenderedSprite::SetSrc(const RectF& src) { 20 | src_ = src; 21 | cullingSystem_->RequestUpdateAABB(this); 22 | } 23 | 24 | std::shared_ptr RenderedSprite::GetTexture() const { return texture_; } 25 | 26 | void RenderedSprite::SetTexture(const std::shared_ptr& texture) { texture_ = texture; } 27 | 28 | std::shared_ptr RenderedSprite::GetMaterial() const { return material_; } 29 | 30 | void RenderedSprite::SetMaterial(const std::shared_ptr& material) { material_ = material; } 31 | 32 | b2AABB RenderedSprite::GetAABB() { 33 | b2AABB res; 34 | auto vertexes = std::array(); 35 | auto src = GetSrc(); 36 | vertexes[0] = Vector3F(0, 0, 0); 37 | vertexes[1] = Vector3F(src.Width, 0, 0); 38 | vertexes[2] = Vector3F(src.Width, src.Height, 0); 39 | vertexes[3] = Vector3F(0, src.Height, 0); 40 | 41 | res.lowerBound = b2Vec2(FLT_MAX, FLT_MAX); 42 | res.upperBound = b2Vec2(-FLT_MAX, -FLT_MAX); 43 | for (auto&& _v : vertexes) { 44 | auto v = transform_.Transform3D(_v); 45 | res.lowerBound = b2Vec2(res.lowerBound.x > v.X ? v.X : res.lowerBound.x, res.lowerBound.y > v.Y ? v.Y : res.lowerBound.y); 46 | res.upperBound = b2Vec2(res.upperBound.x < v.X ? v.X : res.upperBound.x, res.upperBound.y < v.Y ? v.Y : res.upperBound.y); 47 | } 48 | return res; 49 | } 50 | 51 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Renderer/RenderedSprite.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "../../Math/RectF.h" 8 | #include "../Color.h" 9 | #include "../Material.h" 10 | #include "../TextureBase.h" 11 | #include "Rendered.h" 12 | 13 | namespace Altseed2 { 14 | 15 | class TextureBase; 16 | 17 | class RenderedSprite : public Rendered { 18 | private: 19 | AlphaBlend alphaBlend_; 20 | std::shared_ptr texture_; 21 | std::shared_ptr material_; 22 | RectF src_; 23 | Color color_; 24 | 25 | public: 26 | static std::shared_ptr Create(); 27 | 28 | AlphaBlend GetAlphaBlend() const { return alphaBlend_; } 29 | void SetAlphaBlend(AlphaBlend alphaBlend) { alphaBlend_ = alphaBlend; } 30 | 31 | RectF GetSrc() const; 32 | void SetSrc(const RectF& src); 33 | 34 | Color GetColor() const { return color_; } 35 | void SetColor(const Color color) { color_ = color; } 36 | 37 | std::shared_ptr GetTexture() const; 38 | void SetTexture(const std::shared_ptr& texture); 39 | 40 | std::shared_ptr GetMaterial() const; 41 | void SetMaterial(const std::shared_ptr& material); 42 | 43 | #if !USE_CBG 44 | 45 | b2AABB GetAABB() override; 46 | 47 | #endif 48 | }; 49 | 50 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Renderer/Renderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "../../Common/Array.h" 8 | #include "../BatchRenderer.h" 9 | #include "Rendered.h" 10 | 11 | #ifdef _WIN32 12 | #undef DrawText 13 | #endif 14 | 15 | namespace Altseed2 { 16 | 17 | class Texture2D; 18 | class RenderedSprite; 19 | class RenderedText; 20 | class RenderedPolygon; 21 | class RenderedCamera; 22 | class CommandList; 23 | class Window; 24 | 25 | class Renderer : public BaseObject { 26 | private: 27 | static std::shared_ptr instance_; 28 | std::shared_ptr window_; 29 | std::shared_ptr graphics_; 30 | std::shared_ptr batchRenderer_; 31 | std::shared_ptr cullingSystem_; 32 | std::vector> cameras_; 33 | std::shared_ptr currentCamera_; 34 | 35 | public: 36 | Renderer(std::shared_ptr window, std::shared_ptr graphics, std::shared_ptr cullingSystem); 37 | virtual ~Renderer(); 38 | 39 | static std::shared_ptr& GetInstance(); 40 | 41 | static bool Initialize( 42 | std::shared_ptr window, std::shared_ptr graphics, std::shared_ptr cullingSystem); 43 | static void Terminate(); 44 | 45 | void DrawPolygon(std::shared_ptr polygon); 46 | void DrawSprite(std::shared_ptr sprite); 47 | void DrawText(std::shared_ptr text); 48 | 49 | void Render(); 50 | 51 | void SetCamera(std::shared_ptr camera); 52 | void ResetCamera(); 53 | }; 54 | 55 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Shader.cpp: -------------------------------------------------------------------------------- 1 | #include "Shader.h" 2 | 3 | #include "../Logger/Log.h" 4 | #include "ShaderCompiler/ShaderCompiler.h" 5 | namespace Altseed2 { 6 | 7 | Shader::Shader( 8 | std::u16string code, 9 | std::u16string name, 10 | const std::vector& textures, 11 | const std::vector& uniforms, 12 | Vector3I numThreads, 13 | std::shared_ptr shader, 14 | ShaderStageType stage) 15 | : code_(code), name_(name), textures_(textures), uniforms_(uniforms), shader_(shader), numThreads_(numThreads), stage_(stage) { 16 | for (const auto& u : uniforms_) { 17 | uniformSize_ = std::max(u.Offset + u.Size, uniformSize_); 18 | } 19 | } 20 | 21 | std::shared_ptr Shader::Compile(const char16_t* name, const char16_t* code, ShaderStageType shaderStage) { 22 | RETURN_IF_NULL(name, MakeAsdShared(nullptr, u"name is null")); 23 | RETURN_IF_NULL(code, MakeAsdShared(nullptr, u"code is null")); 24 | 25 | auto shaderCompiler = ShaderCompiler::GetInstance(); 26 | if (shaderCompiler == nullptr) { 27 | Log::GetInstance()->Error(LogCategory::Core, u"Graphics is not initialized."); 28 | return nullptr; 29 | } 30 | 31 | return shaderCompiler->Compile("", utf16_to_utf8(name).c_str(), utf16_to_utf8(code).c_str(), shaderStage); 32 | } 33 | 34 | std::shared_ptr Shader::CompileFromFile(const char16_t* name, const char16_t* path, ShaderStageType shaderStage) { 35 | RETURN_IF_NULL(name, MakeAsdShared(nullptr, u"name is null")); 36 | RETURN_IF_NULL(path, MakeAsdShared(nullptr, u"path is null")); 37 | 38 | auto shaderCompiler = ShaderCompiler::GetInstance(); 39 | if (shaderCompiler == nullptr) { 40 | Log::GetInstance()->Error(LogCategory::Core, u"Graphics is not initialized."); 41 | return nullptr; 42 | } 43 | 44 | return shaderCompiler->Compile(utf16_to_utf8(path).c_str(), utf16_to_utf8(name).c_str(), shaderStage); 45 | } 46 | 47 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Shader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../BaseObject.h" 6 | #include "../Common/StringHelper.h" 7 | #include "Graphics.h" 8 | 9 | namespace Altseed2 { 10 | 11 | class ShaderCompileResult; 12 | 13 | enum class ShaderStageType { 14 | Vertex, 15 | Pixel, 16 | Compute, 17 | }; 18 | 19 | struct ShaderReflectionUniform { 20 | std::u16string Name; 21 | int32_t Offset = 0; 22 | int32_t Size = 0; 23 | }; 24 | 25 | struct ShaderReflectionTexture { 26 | std::u16string Name; 27 | int32_t Offset = 0; 28 | }; 29 | 30 | class Shader : public BaseObject { 31 | private: 32 | std::u16string code_; 33 | std::u16string name_; 34 | std::vector textures_; 35 | std::vector uniforms_; 36 | Vector3I numThreads_; 37 | int32_t uniformSize_ = 0; 38 | 39 | std::shared_ptr shader_ = nullptr; 40 | ShaderStageType stage_; 41 | 42 | public: 43 | virtual ~Shader() {} 44 | 45 | /** 46 | @brief constructor 47 | @note 48 | please use ShaderCompiler to generate a shader 49 | */ 50 | Shader(std::u16string code, 51 | std::u16string name, 52 | const std::vector& textures, 53 | const std::vector& uniforms, 54 | Vector3I numThreads, 55 | std::shared_ptr shader, 56 | ShaderStageType stage); 57 | 58 | int32_t GetUniformSize() const { return uniformSize_; } 59 | 60 | #if !USE_CBG 61 | 62 | const std::vector& GetReflectionTextures() const { return textures_; } 63 | const std::vector& GetReflectionUniforms() const { return uniforms_; } 64 | LLGI::Shader* Get() const { return shader_.get(); } 65 | 66 | #endif 67 | 68 | const Vector3I GetNumThreads() { return numThreads_; } 69 | 70 | static std::shared_ptr Compile(const char16_t* name, const char16_t* code, ShaderStageType shaderStage); 71 | 72 | static std::shared_ptr CompileFromFile(const char16_t* name, const char16_t* path, ShaderStageType shaderStage); 73 | 74 | const char16_t* GetCode() const { return code_.c_str(); } 75 | 76 | const char16_t* GetName() const { return name_.c_str(); } 77 | 78 | ShaderStageType GetStageType() const { return stage_; } 79 | }; 80 | 81 | } // namespace Altseed2 82 | -------------------------------------------------------------------------------- /core/src/Graphics/ShaderCompiler/ShaderCompiler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "../../BaseObject.h" 7 | #include "../Graphics.h" 8 | 9 | namespace Altseed2 { 10 | 11 | class Graphics; 12 | class Shader; 13 | class File; 14 | 15 | class ShaderCompileResult : public BaseObject { 16 | private: 17 | std::shared_ptr value_; 18 | std::u16string message_; 19 | 20 | public: 21 | ShaderCompileResult(const std::shared_ptr value, const std::u16string message); 22 | 23 | std::shared_ptr GetValue() const { return value_; } 24 | const char16_t* GetMessage() const { return message_.c_str(); } 25 | }; 26 | 27 | class ShaderCompiler : public BaseObject { 28 | private: 29 | static std::shared_ptr instance_; 30 | std::shared_ptr graphics_; 31 | std::shared_ptr file_; 32 | 33 | std::shared_ptr compiler_; 34 | std::shared_ptr spirvGenerator_; 35 | std::shared_ptr spirvTranspiler_; 36 | std::shared_ptr spirvReflection_; 37 | 38 | public: 39 | static std::shared_ptr& GetInstance(); 40 | 41 | static bool Initialize(std::shared_ptr& graphics, std::shared_ptr& file); 42 | 43 | static void Terminate(); 44 | 45 | ShaderCompiler(std::shared_ptr& graphics, std::shared_ptr& file); 46 | ~ShaderCompiler(); 47 | 48 | std::shared_ptr Compile(const char* path, const char* name, const char* code, ShaderStageType shaderStage); 49 | 50 | #if !USE_CBG 51 | std::shared_ptr Compile(const char* path, const char* name, ShaderStageType shaderStage); 52 | #endif 53 | }; 54 | 55 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Graphics/Texture2D.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "../Common/Resource.h" 12 | #include "../Common/Resources.h" 13 | #include "../Common/ThreadSafeMap.h" 14 | #include "../Math/Vector2I.h" 15 | #include "TextureBase.h" 16 | 17 | namespace Altseed2 { 18 | class Texture2D : public TextureBase { 19 | private: 20 | static std::mutex mtx; 21 | 22 | std::u16string sourcePath_; 23 | std::shared_ptr resources_ = nullptr; 24 | 25 | public: 26 | Texture2D(const std::shared_ptr& resources, const std::shared_ptr& texture, const std::u16string& sourcePath); 27 | virtual ~Texture2D(); 28 | 29 | bool Reload() override; 30 | static std::shared_ptr Load(const char16_t* path); 31 | static std::shared_ptr Create(Vector2I size); 32 | const char16_t* GetPath() const; 33 | }; 34 | } // namespace Altseed2 35 | -------------------------------------------------------------------------------- /core/src/Graphics/TextureBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "../Common/Resource.h" 12 | #include "../Common/Resources.h" 13 | #include "../Common/ThreadSafeMap.h" 14 | #include "../Math/Vector2I.h" 15 | 16 | namespace Altseed2 { 17 | 18 | enum class TextureWrapMode : int32_t { 19 | Clamp, 20 | Repeat, 21 | }; 22 | 23 | enum class TextureFilterType : int32_t { 24 | Nearest, 25 | Linear, 26 | }; 27 | 28 | enum class TextureFormatType : int32_t { 29 | R8G8B8A8_UNORM = 0, 30 | R16G16B16A16_FLOAT = 1, 31 | R32G32B32A32_FLOAT = 2, 32 | R8G8B8A8_UNORM_SRGB = 3, 33 | R16G16_FLOAT = 4, 34 | R8_UNORM = 5, 35 | // BC1 = 6, 36 | // BC2 = 7, 37 | // BC3 = 8, 38 | // BC1_SRGB = 9, 39 | // BC2_SRGB = 10, 40 | // BC3_SRGB = 11, 41 | D32 = 12, 42 | D32S8 = 13, 43 | D24S8 = 14, 44 | }; 45 | 46 | LLGI::TextureFormatType textureFormatToLLGI(const TextureFormatType& format); 47 | TextureFormatType textureFormatFromLLGI(const LLGI::TextureFormatType& format); 48 | 49 | class TextureBase : public Resource { 50 | private: 51 | static ThreadSafeMap mtxs; 52 | std::shared_ptr texture_ = nullptr; 53 | Vector2I size_; 54 | TextureWrapMode wrapMode_; 55 | TextureFilterType filterMode_; 56 | TextureFormatType format_; 57 | 58 | public: 59 | TextureBase(const std::shared_ptr& texture); 60 | virtual ~TextureBase(); 61 | 62 | Vector2I GetSize() const; 63 | 64 | TextureWrapMode GetWrapMode() const; 65 | void SetWrapMode(TextureWrapMode wrapMode); 66 | 67 | TextureFilterType GetFilterType() const; 68 | void SetFilterType(TextureFilterType filterMode); 69 | 70 | TextureFormatType GetFormat() const; 71 | 72 | virtual bool Save(const char16_t* path); 73 | 74 | #if !USE_CBG 75 | 76 | std::shared_ptr& GetNativeTexture() { return texture_; } 77 | 78 | #endif 79 | }; 80 | } // namespace Altseed2 81 | -------------------------------------------------------------------------------- /core/src/IO/BaseFileReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../BaseObject.h" 10 | 11 | #if !USE_CBG 12 | 13 | namespace Altseed2 { 14 | 15 | enum class SeekOrigin { Begin, 16 | Current, 17 | End }; 18 | 19 | class BaseFileReader : public BaseObject { 20 | private: 21 | std::shared_ptr file_; 22 | 23 | protected: 24 | int64_t position_; 25 | int64_t length_; 26 | std::u16string path_; 27 | std::recursive_mutex readerMtx_; 28 | 29 | //! for PackFileReader 30 | BaseFileReader(const std::u16string& path); 31 | 32 | public: 33 | BaseFileReader(std::shared_ptr& file, const std::u16string& path); 34 | virtual ~BaseFileReader(); 35 | 36 | int64_t GetPosition() const { return position_; } 37 | const std::u16string& GetFullPath() const { return path_; } 38 | 39 | virtual int64_t GetSize(); 40 | 41 | virtual void ReadBytes(std::vector& buffer, const int64_t count); 42 | uint32_t ReadUInt32(); 43 | uint64_t ReadUInt64(); 44 | void ReadAllBytes(std::vector& buffer); 45 | 46 | virtual void Seek(const int64_t offset, const SeekOrigin origin = SeekOrigin::Begin); 47 | 48 | virtual bool GetIsInPackage() const; 49 | 50 | //! for core 51 | void Close(); 52 | }; 53 | } // namespace Altseed2 54 | 55 | #endif -------------------------------------------------------------------------------- /core/src/IO/File.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../Common/ResourceContainer.h" 9 | #include "../Common/Resources.h" 10 | #include "FileRoot.h" 11 | #include "StaticFile.h" 12 | #include "StreamFile.h" 13 | 14 | namespace Altseed2 { 15 | 16 | class File : public BaseObject { 17 | private: 18 | static std::shared_ptr instance; 19 | 20 | std::shared_ptr m_resources; 21 | 22 | std::vector> m_roots; 23 | 24 | std::mutex m_rootMtx; 25 | std::mutex streamMtx_; 26 | 27 | public: 28 | #if !USE_CBG 29 | static bool Initialize(std::shared_ptr resources); 30 | 31 | static void Terminate(); 32 | #endif 33 | 34 | static std::shared_ptr& GetInstance(); 35 | 36 | #if !USE_CBG 37 | std::shared_ptr CreateFileReader(const char16_t* path); 38 | #endif 39 | 40 | bool AddRootDirectory(const char16_t* path); 41 | 42 | bool AddRootPackageWithPassword(const char16_t* path, const char16_t* password); 43 | 44 | bool AddRootPackage(const char16_t* path); 45 | 46 | void ClearRootDirectories(); 47 | 48 | bool Exists(const char16_t* path) const; 49 | 50 | bool Pack(const char16_t* srcPath, const char16_t* dstPath) const; 51 | 52 | bool PackWithPassword(const char16_t* srcPath, const char16_t* dstPath, const char16_t* password) const; 53 | 54 | #if !USE_CBG 55 | 56 | //! for core 57 | std::shared_ptr GetStream(const std::u16string& path); 58 | 59 | #endif 60 | 61 | private: 62 | bool MakePackage(zip_t* zipPtr, const std::u16string& path, bool isEncrypt = false) const; 63 | }; 64 | 65 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/IO/FileRoot.cpp: -------------------------------------------------------------------------------- 1 | #include "FileRoot.h" 2 | namespace Altseed2 { 3 | FileRoot::FileRoot(const std::u16string& path) : m_packFile(nullptr), m_path(path) { 4 | if (m_path.back() != u'\\' && m_path.back() != u'/') m_path += u'/'; 5 | } 6 | FileRoot::FileRoot(const std::u16string& path, std::shared_ptr packFile) : m_packFile(packFile), m_path(path) {} 7 | FileRoot::~FileRoot() {} 8 | std::u16string& FileRoot::GetPath() { return m_path; } 9 | std::shared_ptr FileRoot::GetPackFile() { return m_packFile; } 10 | bool FileRoot::IsPack() { return m_packFile != nullptr; } 11 | } // namespace Altseed2 12 | -------------------------------------------------------------------------------- /core/src/IO/FileRoot.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "PackFile.h" 7 | 8 | #if !USE_CBG 9 | 10 | namespace Altseed2 { 11 | class FileRoot { 12 | private: 13 | std::shared_ptr m_packFile; 14 | std::u16string m_path; 15 | 16 | public: 17 | FileRoot(const std::u16string& path); 18 | FileRoot(const std::u16string& path, std::shared_ptr packFile); 19 | ~FileRoot(); 20 | 21 | std::u16string& GetPath(); 22 | std::shared_ptr GetPackFile(); 23 | bool IsPack(); 24 | }; 25 | } // namespace Altseed2 26 | 27 | #endif -------------------------------------------------------------------------------- /core/src/IO/PackFile.cpp: -------------------------------------------------------------------------------- 1 | #include "PackFile.h" 2 | 3 | #include "../Common/StringHelper.h" 4 | 5 | namespace Altseed2 { 6 | 7 | PackFile::PackFile(zip_t* zipPtr, bool isUsePassword) : m_zip(zipPtr), m_isUsePassword(isUsePassword) {} 8 | 9 | PackFile::~PackFile() { zip_close(m_zip); } 10 | 11 | zip_file_t* PackFile::Load(const std::u16string& path) { return zip_fopen(m_zip, utf16_to_utf8(path).c_str(), ZIP_FL_UNCHANGED); } 12 | 13 | bool PackFile::Exists(const std::u16string& path) { return zip_name_locate(m_zip, utf16_to_utf8(path).c_str(), ZIP_FL_ENC_GUESS) != -1; } 14 | 15 | zip_stat_t* PackFile::GetZipStat(const std::u16string& path) { 16 | zip_stat_t* res = new zip_stat_t(); 17 | if (zip_stat(m_zip, utf16_to_utf8(path).c_str(), ZIP_FL_UNCHANGED, res) == -1) { 18 | delete res; 19 | return nullptr; 20 | } 21 | return res; 22 | } 23 | 24 | bool PackFile::GetIsUsePassword() { return m_isUsePassword; } 25 | 26 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/IO/PackFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "../BaseObject.h" 8 | 9 | #if !USE_CBG 10 | 11 | namespace Altseed2 { 12 | class PackFile : public BaseObject { 13 | private: 14 | zip_t* m_zip; 15 | bool m_isUsePassword; 16 | 17 | public: 18 | PackFile(zip_t* zipPtr, bool isUsePassword = false); 19 | virtual ~PackFile(); 20 | 21 | zip_file_t* Load(const std::u16string& path); 22 | bool Exists(const std::u16string& path); 23 | zip_stat_t* GetZipStat(const std::u16string& path); 24 | bool GetIsUsePassword(); 25 | }; 26 | } // namespace Altseed2 27 | 28 | #endif -------------------------------------------------------------------------------- /core/src/IO/PackFileReader.cpp: -------------------------------------------------------------------------------- 1 | #include "PackFileReader.h" 2 | 3 | #include 4 | #include 5 | 6 | namespace Altseed2 { 7 | PackFileReader::PackFileReader(zip_file* zipFile, const std::u16string& path, const zip_stat_t* stat) 8 | : BaseFileReader(path), m_zipFile(zipFile), m_isUseBuffer(false) { 9 | if (stat != nullptr) { 10 | std::unique_lock lock(readerMtx_); 11 | 12 | length_ = stat->size; 13 | m_buffer.resize(length_); 14 | zip_fread(m_zipFile, reinterpret_cast(&m_buffer[0]), length_); 15 | m_isUseBuffer = true; 16 | delete stat; 17 | } 18 | } 19 | 20 | PackFileReader::~PackFileReader() { zip_fclose(m_zipFile); } 21 | 22 | int64_t PackFileReader::GetSize() { 23 | if (length_ < 0) { 24 | std::unique_lock lock(readerMtx_); 25 | 26 | zip_fseek(m_zipFile, 0, SEEK_END); 27 | length_ = zip_ftell(m_zipFile); 28 | 29 | zip_fseek(m_zipFile, position_, SEEK_SET); 30 | } 31 | 32 | return length_; 33 | } 34 | 35 | void PackFileReader::ReadBytes(std::vector& buffer, const int64_t count) { 36 | std::unique_lock lock(readerMtx_); 37 | 38 | if (position_ + count > GetSize() || count < 0) { 39 | buffer.resize(0); 40 | buffer.clear(); 41 | return; 42 | } 43 | 44 | if (m_isUseBuffer) 45 | std::copy(m_buffer.begin() + position_, m_buffer.begin() + position_ + count, std::back_inserter(buffer)); 46 | else { 47 | buffer.resize(count); 48 | zip_fread(m_zipFile, reinterpret_cast(&buffer[0]), count); 49 | } 50 | 51 | position_ += count; 52 | } 53 | 54 | void PackFileReader::Seek(const int64_t offset, const SeekOrigin origin) { 55 | std::unique_lock lock(readerMtx_); 56 | 57 | switch (origin) { 58 | case SeekOrigin::Begin: 59 | if (!m_isUseBuffer) zip_fseek(m_zipFile, offset, SEEK_SET); 60 | position_ = offset; 61 | break; 62 | case SeekOrigin::Current: 63 | if (!m_isUseBuffer) zip_fseek(m_zipFile, offset, SEEK_CUR); 64 | position_ += offset; 65 | break; 66 | case SeekOrigin::End: 67 | if (!m_isUseBuffer) zip_fseek(m_zipFile, offset, SEEK_CUR); 68 | position_ = GetSize(); 69 | break; 70 | default: 71 | break; 72 | } 73 | } 74 | 75 | bool PackFileReader::GetIsInPackage() const { return true; } 76 | 77 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/IO/PackFileReader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "BaseFileReader.h" 6 | 7 | #if !USE_CBG 8 | 9 | namespace Altseed2 { 10 | 11 | class PackFileReader : public BaseFileReader { 12 | private: 13 | zip_file* m_zipFile; 14 | 15 | // ! libzip can not zip_ftell and zip_fseek to packed file with password 16 | std::vector m_buffer; 17 | bool m_isUseBuffer; 18 | 19 | public: 20 | PackFileReader(zip_file* zipFile, const std::u16string& path, const zip_stat_t* stat = nullptr); 21 | virtual ~PackFileReader(); 22 | 23 | int64_t GetSize() override; 24 | 25 | void ReadBytes(std::vector& buffer, const int64_t count) override; 26 | 27 | void Seek(const int64_t offset, const SeekOrigin origin = SeekOrigin::Begin) override; 28 | 29 | bool GetIsInPackage() const override; 30 | }; 31 | } // namespace Altseed2 32 | 33 | #endif -------------------------------------------------------------------------------- /core/src/IO/StaticFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../BaseObject.h" 6 | #include "../Common/Array.h" 7 | #include "../Common/Resources.h" 8 | #include "BaseFileReader.h" 9 | 10 | namespace Altseed2 { 11 | 12 | class File; 13 | 14 | class StaticFile : public Resource { 15 | private: 16 | std::shared_ptr resources_; 17 | 18 | std::shared_ptr m_buffer; 19 | 20 | std::u16string path_; 21 | std::u16string sourcePath_; 22 | int32_t size_; 23 | bool isInPackage_; 24 | 25 | static std::mutex m_staticFileMtx; 26 | 27 | public: 28 | StaticFile(std::shared_ptr reader, std::shared_ptr& resources, std::u16string path); 29 | virtual ~StaticFile(); 30 | 31 | static std::shared_ptr Create(const char16_t* path); 32 | 33 | const std::shared_ptr& GetInt8ArrayBuffer() const; 34 | 35 | const char16_t* GetPath() const; 36 | 37 | #if !USE_CBG 38 | 39 | const void* GetData() const; 40 | 41 | #endif 42 | 43 | int32_t GetSize(); 44 | 45 | bool GetIsInPackage() const; 46 | 47 | bool Reload() override; 48 | }; 49 | 50 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/IO/StreamFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../BaseObject.h" 6 | #include "../Common/Array.h" 7 | #include "../Common/Resources.h" 8 | #include "BaseFileReader.h" 9 | 10 | namespace Altseed2 { 11 | class File; 12 | 13 | class StreamFile : public Resource { 14 | private: 15 | std::shared_ptr resources_; 16 | 17 | std::shared_ptr m_buffer; 18 | std::shared_ptr m_fileReader; 19 | 20 | std::u16string sourcePath_; 21 | 22 | static std::mutex m_streamFileMtx; 23 | 24 | public: 25 | StreamFile(std::shared_ptr reader, std::shared_ptr& resources, std::u16string path); 26 | virtual ~StreamFile(); 27 | 28 | static std::shared_ptr Create(const char16_t* path); 29 | 30 | int32_t GetSize() const; 31 | 32 | int32_t GetCurrentPosition() const; 33 | 34 | int32_t Read(int32_t size); 35 | 36 | std::shared_ptr& GetInt8ArrayTempBuffer(); 37 | 38 | int32_t GetTempBufferSize(); 39 | 40 | bool GetIsInPackage() const; 41 | 42 | bool Reload() override; 43 | 44 | const char16_t* GetPath() const; 45 | }; 46 | 47 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Input/ButtonState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Altseed2 { 4 | 5 | enum class ButtonState : int32_t { 6 | Free = 0b00, 7 | Push = 0b01, 8 | Hold = 0b11, 9 | Release = 0b10, 10 | }; 11 | } 12 | -------------------------------------------------------------------------------- /core/src/Input/Cursor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include "../IO/StaticFile.h" 10 | #include "../Math/Vector2I.h" 11 | #include "../Window/Window.h" 12 | #include "ButtonState.h" 13 | 14 | namespace Altseed2 { 15 | class Cursor : public BaseObject { 16 | private: 17 | // std::shared_ptr 18 | GLFWcursor* native_; 19 | 20 | static bool LoadPNGImage( 21 | void* data, 22 | int32_t size, 23 | bool rev, 24 | int32_t& imagewidth, 25 | int32_t& imageheight, 26 | ::std::vector& imagedst, 27 | const char16_t* path); 28 | 29 | public: 30 | Cursor(GLFWcursor* cursor); 31 | 32 | ~Cursor(); 33 | 34 | #if !USE_CBG 35 | GLFWcursor* GetNative() const { return native_; }; 36 | 37 | #endif 38 | 39 | static std::shared_ptr Create(const char16_t* path, Vector2I hot); 40 | }; 41 | 42 | } // namespace Altseed2 43 | -------------------------------------------------------------------------------- /core/src/Input/Mouse.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #include "../IO/StaticFile.h" 8 | #include "../Math/Vector2F.h" 9 | #include "../Window/Window.h" 10 | #include "ButtonState.h" 11 | #include "Cursor.h" 12 | 13 | namespace Altseed2 { 14 | enum class MouseButton : int32_t { 15 | /** 16 | @brief 左ボタン 17 | */ 18 | ButtonLeft = 0, 19 | 20 | /** 21 | @brief 右ボタン 22 | */ 23 | ButtonRight = 1, 24 | 25 | /** 26 | @brief 中央ボタン 27 | */ 28 | ButtonMiddle = 2, 29 | 30 | /** 31 | @brief サブボタン1 32 | */ 33 | SubButton1 = 3, 34 | 35 | /** 36 | @brief サブボタン2 37 | */ 38 | SubButton2 = 4, 39 | 40 | /** 41 | @brief サブボタン3 42 | */ 43 | SubButton3 = 5, 44 | 45 | /** 46 | @brief サブボタン4 47 | */ 48 | SubButton4 = 6, 49 | 50 | /** 51 | @brief サブボタン5 52 | */ 53 | SubButton5 = 7, 54 | }; 55 | 56 | enum class CursorMode : int32_t { 57 | //カーソルを常に表示。 58 | Normal = 0x00034001, 59 | //ウィンドウ上のカーソルを非表示。 60 | Hidden = 0x00034002, 61 | //カーソルを常に非表示 62 | Disable = 0x00034003, 63 | }; 64 | 65 | class Mouse : public BaseObject { 66 | private: 67 | static std::shared_ptr instance_; 68 | std::shared_ptr window_; 69 | 70 | static const int KEY_NUM = 8; 71 | static const int ModeCodes[3]; 72 | 73 | std::array currentState_; 74 | std::array oldState_; 75 | 76 | float wheel_ = 0; 77 | 78 | public: 79 | #if !USE_CBG 80 | static bool Initialize(std::shared_ptr& window); 81 | 82 | static void Terminate() { instance_ = nullptr; } 83 | #endif 84 | 85 | static std::shared_ptr& GetInstance(); 86 | 87 | void RefreshInputState(); 88 | 89 | void SetPosition(Vector2F vec); 90 | 91 | Vector2F GetPosition(); 92 | 93 | #if !USE_CBG 94 | 95 | void SetWheelCallback(std::function func); 96 | 97 | #endif 98 | 99 | float GetWheel() const; 100 | 101 | ButtonState GetMouseButtonState(MouseButton button) const; 102 | 103 | void SetMouseButtonState(MouseButton button, ButtonState state); 104 | 105 | void SetCursorMode(CursorMode mode); 106 | 107 | void SetCursorImage(std::shared_ptr cursor); 108 | 109 | CursorMode GetCursorMode() const; 110 | }; 111 | 112 | } // namespace Altseed2 113 | -------------------------------------------------------------------------------- /core/src/Math/Easing.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../BaseObject.h" 3 | 4 | namespace Altseed2 { 5 | 6 | #if !USE_CBG 7 | 8 | enum class EasingType : int32_t { 9 | Linear, 10 | InSine, 11 | OutSine, 12 | InOutSine, 13 | InQuad, 14 | OutQuad, 15 | InOutQuad, 16 | InCubic, 17 | OutCubic, 18 | InOutCubic, 19 | InQuart, 20 | OutQuart, 21 | InOutQuart, 22 | InQuint, 23 | OutQuint, 24 | InOutQuint, 25 | InExpo, 26 | OutExpo, 27 | InOutExpo, 28 | InCirc, 29 | OutCirc, 30 | InOutCirc, 31 | InBack, 32 | OutBack, 33 | InOutBack, 34 | InElastic, 35 | OutElastic, 36 | InOutElastic, 37 | InBounce, 38 | OutBounce, 39 | InOutBounce, 40 | }; 41 | 42 | class Easing { 43 | public: 44 | static float GetEasing(EasingType easing, float t); 45 | 46 | // pseudo method for binding 47 | int32_t Release(); 48 | }; 49 | 50 | #endif 51 | 52 | } // namespace Altseed2 53 | -------------------------------------------------------------------------------- /core/src/Math/MathTemplate.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace Altseed2 { 9 | 10 | extern "C" { 11 | struct Vector2F; 12 | } 13 | struct Vector2I; 14 | struct Vector3F; 15 | struct Vector3I; 16 | struct Vector4F; 17 | struct Vector4I; 18 | struct Matrix33F; 19 | struct Matrix44F; 20 | struct RectF; 21 | struct RectI; 22 | 23 | inline float NormalizeAngle(float angle) { 24 | int32_t ofs = (*(int32_t*)&angle & 0x80000000) | 0x3F000000; 25 | return (angle - ((int)(angle * 0.159154943f + *(float*)&ofs) * 6.283185307f)); 26 | } 27 | 28 | inline void SinCos(float x, float& s, float& c) { 29 | x = NormalizeAngle(x); 30 | float x2 = x * x; 31 | float x4 = x2 * x2; 32 | float x6 = x2 * x4; 33 | float x8 = x4 * x4; 34 | float x10 = x2 * x8; 35 | s = x * (1.0f - x2 / 6.0f + x4 / 120.0f - x6 / 5040.0f + x8 / 362880.0f - x10 / 39916800.0f); 36 | c = 1.0f - x2 / 2.0f + x4 / 24.0f - x6 / 720.0f + x8 / 40320.0f - x10 / 3628800.0f; 37 | } 38 | 39 | const float PI = 3.14159265358979f; 40 | 41 | static float DegreeToRadian(float degree) { return degree / 180.0f * PI; } 42 | 43 | static float RadianToDegree(float radian) { return radian / PI * 180.0f; } 44 | } // namespace Altseed2 45 | -------------------------------------------------------------------------------- /core/src/Math/Matrix33F.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vector2F.h" 3 | #include "Vector3F.h" 4 | 5 | namespace Altseed2 { 6 | /** 7 | @brief 3×3行列を表す構造体。 8 | @note 9 | [0,0][0,1] 10 | [1,0][1,1] 11 | */ 12 | struct Matrix33F_C; 13 | 14 | struct Matrix33F { 15 | public: 16 | Matrix33F(); 17 | 18 | float Values[3][3]; 19 | 20 | Matrix33F& SetIdentity(); 21 | 22 | /** 23 | @brief 転置行列を設定する。 24 | @return このインスタンスへの参照 25 | */ 26 | Matrix33F& SetTransposed(); 27 | 28 | /** 29 | @brief 逆行列を設定する。 30 | @return このインスタンスへの参照 31 | */ 32 | Matrix33F& SetInverted(); 33 | 34 | /** 35 | @brief 逆行列を取得する。 36 | @return 逆行列 37 | */ 38 | Matrix33F GetInverted() const; 39 | 40 | Matrix33F& SetTranslation(float x, float y); 41 | 42 | Matrix33F& SetRotation(float angle); 43 | 44 | Matrix33F& SetScale(float x, float y); 45 | 46 | /** 47 | @brief 行列でベクトルを変形させる。 48 | @param in 変形前ベクトル 49 | @return 変形後ベクトル 50 | */ 51 | Vector2F Transform2D(const Vector2F& in) const; 52 | 53 | /** 54 | @brief 行列でベクトルを変形させる。 55 | @param in 変形前ベクトル 56 | @return 変形後ベクトル 57 | */ 58 | Vector3F Transform3D(const Vector3F& in) const; 59 | 60 | Matrix33F operator*(const Matrix33F& right) const; 61 | 62 | Vector3F operator*(const Vector3F& right) const; 63 | 64 | operator Matrix33F_C() const; 65 | }; 66 | 67 | struct Matrix33F_C { 68 | float Values[3][3]; 69 | 70 | operator Matrix33F() const; 71 | }; 72 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Math/Matrix33I.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vector2I.h" 3 | #include "Vector3I.h" 4 | 5 | namespace Altseed2 { 6 | /** 7 | @brief 3×3行列を表す構造体。 8 | @note 9 | [0,0][0,1] 10 | [1,0][1,1] 11 | */ 12 | struct Matrix33I_C; 13 | 14 | struct Matrix33I { 15 | public: 16 | Matrix33I(); 17 | 18 | int32_t Values[3][3]; 19 | 20 | Matrix33I& SetIdentity(); 21 | 22 | /** 23 | @brief 転置行列を設定する。 24 | @return このインスタンスへの参照 25 | */ 26 | Matrix33I& SetTransposed(); 27 | 28 | /** 29 | @brief 逆行列を設定する。 30 | @return このインスタンスへの参照 31 | */ 32 | Matrix33I& SetInverted(); 33 | 34 | /** 35 | @brief 逆行列を取得する。 36 | @return 逆行列 37 | */ 38 | Matrix33I GetInverted(); 39 | 40 | Matrix33I& SetTranslation(int32_t x, int32_t y); 41 | 42 | Matrix33I& SetScale(int32_t x, int32_t y); 43 | 44 | /** 45 | @brief 行列でベクトルを変形させる。 46 | @param in 変形前ベクトル 47 | @return 変形後ベクトル 48 | */ 49 | Vector2I Transform2D(const Vector2I& in) const; 50 | 51 | /** 52 | @brief 行列でベクトルを変形させる。 53 | @param in 変形前ベクトル 54 | @return 変形後ベクトル 55 | */ 56 | Vector3I Transform3D(const Vector3I& in) const; 57 | 58 | Matrix33I operator*(const Matrix33I& right) const; 59 | 60 | Vector3I operator*(const Vector3I& right) const; 61 | 62 | operator Matrix33I_C() const; 63 | }; 64 | 65 | struct Matrix33I_C { 66 | int32_t Values[3][3]; 67 | 68 | operator Matrix33I() const; 69 | }; 70 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Math/Matrix44I.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //---------------------------------------------------------------------------------- 4 | // Include 5 | //---------------------------------------------------------------------------------- 6 | #include "MathTemplate.h" 7 | #include "Vector4I.h" 8 | 9 | namespace Altseed2 { 10 | 11 | /** 12 | @brief 4×4行列を表す構造体 13 | @note 14 | M * V[x,y,z,1] の形
15 | [0,0][0,1][0,2][0,3] 16 | [1,0][1,1][1,2][1,3] 17 | [2,0][2,1][2,2][2,3] 18 | [3,0][3,1][3,2][3,3] 19 | */ 20 | 21 | struct Matrix44I_C; 22 | 23 | struct Matrix44I { 24 | private: 25 | public: 26 | Matrix44I(); 27 | 28 | int32_t Values[4][4]; 29 | 30 | /** 31 | @brief 単位行列を設定する。 32 | @return このインスタンスへの参照 33 | */ 34 | Matrix44I& SetIdentity(); 35 | 36 | /** 37 | @brief 転置行列を設定する。 38 | @return このインスタンスへの参照 39 | */ 40 | Matrix44I& SetTransposed(); 41 | 42 | /** 43 | @brief 並行移動行列を設定する。 44 | @param x X方向移動量 45 | @param y Y方向移動量 46 | @param z Z方向移動量 47 | @return このインスタンスへの参照 48 | */ 49 | Matrix44I& SetTranslation(int32_t x, int32_t y, int32_t z); 50 | 51 | /** 52 | @brief クオータニオンを元に回転行列(右手)を設定する。 53 | @param x クオータニオン 54 | @param y クオータニオン 55 | @param z クオータニオン 56 | @param w クオータニオン 57 | @return このインスタンスへの参照 58 | */ 59 | Matrix44I& SetQuaternion(int32_t x, int32_t y, int32_t z, int32_t w); 60 | 61 | /** 62 | @brief 拡大行列を設定する。 63 | @param x X方向拡大率 64 | @param y Y方向拡大率 65 | @param z Z方向拡大率 66 | @return このインスタンスへの参照 67 | */ 68 | Matrix44I& SetScale(int32_t x, int32_t y, int32_t z); 69 | 70 | /** 71 | @brief 行列でベクトルを変形させる。 72 | @param in 変形前ベクトル 73 | @return 変形後ベクトル 74 | */ 75 | Vector4I Transform4D(const Vector4I& in) const; 76 | 77 | Matrix44I operator*(const Matrix44I& right) const; 78 | 79 | Vector4I operator*(const Vector4I& right) const; 80 | 81 | /** 82 | @brief 乗算を行う。 83 | @param o 出力先 84 | @param in1 行列1 85 | @param in2 行列2 86 | @return 出力先の参照z 87 | */ 88 | static Matrix44I& Mul(Matrix44I& o, const Matrix44I& in1, const Matrix44I& in2); 89 | 90 | operator Matrix44I_C() const; 91 | }; 92 | 93 | struct Matrix44I_C { 94 | int32_t Values[4][4]; 95 | 96 | operator Matrix44I() const; 97 | }; 98 | 99 | } // namespace Altseed2 100 | -------------------------------------------------------------------------------- /core/src/Math/RectF.cpp: -------------------------------------------------------------------------------- 1 | #include "RectF.h" 2 | 3 | #include "RectI.h" 4 | #include "Vector2F.h" 5 | 6 | using namespace std; 7 | 8 | namespace Altseed2 { 9 | RectF::RectF() : X(0), Y(0), Width(0), Height(0) {} 10 | 11 | RectF::RectF(float x, float y, float width, float height) : X(x), Y(y), Width(width), Height(height) {} 12 | 13 | RectF::RectF(Vector2F position, Vector2F size) : X(position.X), Y(position.Y), Width(size.X), Height(size.Y) {} 14 | 15 | Vector2F RectF::GetPosition() const { return Vector2F(X, Y); } 16 | 17 | Vector2F RectF::GetSize() const { return Vector2F(Width, Height); } 18 | 19 | array RectF::GetVertexes() const { 20 | array ret; 21 | 22 | ret[0] = Vector2F(X, Y); 23 | ret[1] = Vector2F(X + Width, Y); 24 | ret[2] = Vector2F(X + Width, Y + Height); 25 | ret[3] = Vector2F(X, Y + Height); 26 | 27 | return ret; 28 | } 29 | 30 | bool RectF::operator!=(const RectF& right) { return X != right.X || Y != right.Y || Width != right.Width || Height != right.Height; } 31 | 32 | RectI RectF::ToI() const { return RectI((int32_t)X, (int32_t)Y, (int32_t)Width, (int32_t)Height); } 33 | 34 | RectF::operator RectF_C() const { return RectF_C{X, Y, Width, Height}; } 35 | 36 | RectF_C::operator RectF() const { return RectF(X, Y, Width, Height); } 37 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Math/RectF.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "MathTemplate.h" 6 | #include "Vector2F.h" 7 | 8 | namespace Altseed2 { 9 | 10 | struct RectF_C; 11 | 12 | struct RectF { 13 | public: 14 | float X; 15 | 16 | float Y; 17 | 18 | float Width; 19 | 20 | float Height; 21 | 22 | RectF(); 23 | 24 | RectF(float x, float y, float width, float height); 25 | 26 | RectF(Vector2F position, Vector2F size); 27 | 28 | Vector2F GetPosition() const; 29 | 30 | Vector2F GetSize() const; 31 | 32 | std::array GetVertexes() const; 33 | 34 | bool operator!=(const RectF& right); 35 | 36 | RectI ToI() const; 37 | operator RectF_C() const; 38 | }; 39 | 40 | struct RectF_C { 41 | float X; 42 | 43 | float Y; 44 | 45 | float Width; 46 | 47 | float Height; 48 | 49 | operator RectF() const; 50 | }; 51 | 52 | } // namespace Altseed2 53 | -------------------------------------------------------------------------------- /core/src/Math/RectI.cpp: -------------------------------------------------------------------------------- 1 | #include "RectI.h" 2 | 3 | #include "RectF.h" 4 | #include "Vector2I.h" 5 | 6 | using namespace std; 7 | 8 | namespace Altseed2 { 9 | RectI::RectI() : X(0), Y(0), Width(0), Height(0) {} 10 | 11 | RectI::RectI(int x, int y, int width, int height) : X(x), Y(y), Width(width), Height(height) {} 12 | 13 | RectI::RectI(Vector2I position, Vector2I size) : X(position.X), Y(position.Y), Width(size.X), Height(size.Y) {} 14 | 15 | Vector2I RectI::GetPosition() const { return Vector2I(X, Y); } 16 | 17 | Vector2I RectI::GetSize() const { return Vector2I(Width, Height); } 18 | 19 | array RectI::GetVertexes() const { 20 | array ret; 21 | 22 | ret[0] = Vector2I(X, Y); 23 | ret[1] = Vector2I(X + Width, Y); 24 | ret[2] = Vector2I(X + Width, Y + Height); 25 | ret[3] = Vector2I(X, Y + Height); 26 | 27 | return ret; 28 | } 29 | 30 | bool RectI::operator==(const RectI& other) const { return X == other.X && Y == other.Y && Width == other.Width && Height == other.Height; } 31 | 32 | RectF RectI::ToF() const { return RectF(X, Y, Width, Height); } 33 | 34 | RectI::operator RectI_C() const { return RectI_C{X, Y, Width, Height}; } 35 | 36 | RectI_C::operator RectI() const { return RectI(X, Y, Width, Height); } 37 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Math/RectI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "MathTemplate.h" 6 | #include "Vector2I.h" 7 | 8 | namespace Altseed2 { 9 | 10 | struct RectI_C; 11 | 12 | struct RectI { 13 | public: 14 | int X; 15 | 16 | int Y; 17 | 18 | int Width; 19 | 20 | int Height; 21 | 22 | RectI(); 23 | 24 | RectI(int x, int y, int width, int height); 25 | 26 | RectI(Vector2I position, Vector2I size); 27 | 28 | Vector2I GetPosition() const; 29 | 30 | Vector2I GetSize() const; 31 | 32 | std::array GetVertexes() const; 33 | 34 | bool operator==(const RectI& other) const; 35 | 36 | RectF ToF() const; 37 | operator RectI_C() const; 38 | }; 39 | 40 | struct RectI_C { 41 | int X; 42 | 43 | int Y; 44 | 45 | int Width; 46 | 47 | int Height; 48 | 49 | operator RectI() const; 50 | }; 51 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Math/Vector2F.cpp: -------------------------------------------------------------------------------- 1 | #include "Vector2F.h" 2 | 3 | #include "Vector2I.h" 4 | 5 | namespace Altseed2 { 6 | Vector2F::Vector2F() : X(0.0f), Y(0.0f) {} 7 | 8 | Vector2F::Vector2F(float x, float y) : X(x), Y(y) {} 9 | 10 | bool Vector2F::operator==(const Vector2F& right) const { return X == right.X && Y == right.Y; } 11 | 12 | bool Vector2F::operator!=(const Vector2F& right) const { return X != right.X || Y != right.Y; } 13 | 14 | bool Vector2F::operator>(const Vector2F& o) const { 15 | if (X != o.X) return X > o.X; 16 | if (Y != o.Y) return Y > o.Y; 17 | return false; 18 | } 19 | 20 | bool Vector2F::operator<(const Vector2F& o) const { 21 | if (X != o.X) return X < o.X; 22 | if (Y != o.Y) return Y < o.Y; 23 | return false; 24 | } 25 | 26 | Vector2F Vector2F::operator-() const { return Vector2F(-X, -Y); } 27 | 28 | Vector2F Vector2F::operator+(const Vector2F& right) const { return Vector2F(X + right.X, Y + right.Y); } 29 | 30 | Vector2F Vector2F::operator-(const Vector2F& right) const { return Vector2F(X - right.X, Y - right.Y); } 31 | 32 | Vector2F Vector2F::operator*(const Vector2F& right) const { return Vector2F(X * right.X, Y * right.Y); } 33 | 34 | Vector2F Vector2F::operator/(const Vector2F& right) const { return Vector2F(X / right.X, Y / right.Y); } 35 | 36 | Vector2F Vector2F::operator*(float right) const { return Vector2F(X * right, Y * right); } 37 | 38 | Vector2F Vector2F::operator/(float right) const { return Vector2F(X / right, Y / right); } 39 | 40 | Vector2F& Vector2F::operator+=(const Vector2F& right) { 41 | X += right.X; 42 | Y += right.Y; 43 | return *this; 44 | } 45 | 46 | Vector2F& Vector2F::operator-=(const Vector2F& right) { 47 | X -= right.X; 48 | Y -= right.Y; 49 | return *this; 50 | } 51 | 52 | Vector2F& Vector2F::operator*=(const Vector2F& right) { 53 | X *= right.X; 54 | Y *= right.Y; 55 | return *this; 56 | } 57 | 58 | Vector2F& Vector2F::operator/=(const Vector2F& right) { 59 | X /= right.X; 60 | Y /= right.Y; 61 | return *this; 62 | } 63 | 64 | Vector2F& Vector2F::operator*=(float right) { 65 | X *= right; 66 | Y *= right; 67 | return *this; 68 | } 69 | 70 | Vector2F& Vector2F::operator/=(float right) { 71 | X /= right; 72 | Y /= right; 73 | return *this; 74 | } 75 | 76 | Vector2I Vector2F::To2I() const { return Vector2I((int32_t)X, (int32_t)Y); } 77 | 78 | Vector2F::operator Vector2F_C() const { return Vector2F_C{X, Y}; } 79 | 80 | Vector2F_C::operator Vector2F() const { return Vector2F(X, Y); } 81 | 82 | } // namespace Altseed2 83 | -------------------------------------------------------------------------------- /core/src/Math/Vector2I.cpp: -------------------------------------------------------------------------------- 1 | #include "Vector2I.h" 2 | 3 | #include "Vector2F.h" 4 | 5 | namespace Altseed2 { 6 | Vector2I::Vector2I() : X(0), Y(0) {} 7 | 8 | Vector2I::Vector2I(int32_t x, int32_t y) : X(x), Y(y) {} 9 | 10 | bool Vector2I::operator==(const Vector2I& right) const { return X == right.X && Y == right.Y; } 11 | 12 | bool Vector2I::operator!=(const Vector2I& right) const { return X != right.X || Y != right.Y; } 13 | 14 | Vector2I Vector2I::operator-() const { return Vector2I(-X, -Y); } 15 | 16 | Vector2I Vector2I::operator+(const Vector2I& right) const { return Vector2I(X + right.X, Y + right.Y); } 17 | 18 | Vector2I Vector2I::operator-(const Vector2I& right) const { return Vector2I(X - right.X, Y - right.Y); } 19 | 20 | Vector2I Vector2I::operator*(const Vector2I& right) const { return Vector2I(X * right.X, Y * right.Y); } 21 | 22 | Vector2I Vector2I::operator/(const Vector2I& right) const { return Vector2I(X / right.X, Y / right.Y); } 23 | 24 | Vector2I Vector2I::operator*(int32_t right) const { return Vector2I(X * right, Y * right); } 25 | 26 | Vector2I Vector2I::operator/(int32_t right) const { return Vector2I(X / right, Y / right); } 27 | 28 | Vector2I& Vector2I::operator+=(const Vector2I& right) { 29 | X += right.X; 30 | Y += right.Y; 31 | return *this; 32 | } 33 | 34 | Vector2I& Vector2I::operator-=(const Vector2I& right) { 35 | X -= right.X; 36 | Y -= right.Y; 37 | return *this; 38 | } 39 | 40 | Vector2I& Vector2I::operator*=(const Vector2I& right) { 41 | X *= right.X; 42 | Y *= right.Y; 43 | return *this; 44 | } 45 | 46 | Vector2I& Vector2I::operator/=(const Vector2I& right) { 47 | X /= right.X; 48 | Y /= right.Y; 49 | return *this; 50 | } 51 | 52 | Vector2I& Vector2I::operator*=(int32_t right) { 53 | X *= right; 54 | Y *= right; 55 | return *this; 56 | } 57 | 58 | Vector2I& Vector2I::operator/=(int32_t right) { 59 | X /= right; 60 | Y /= right; 61 | return *this; 62 | } 63 | Vector2F Vector2I::To2F() const { return Vector2F(X, Y); } 64 | 65 | Vector2I::operator Vector2I_C() const { return Vector2I_C{X, Y}; } 66 | 67 | Vector2I_C::operator Vector2I() const { return Vector2I(X, Y); } 68 | } // namespace Altseed2 69 | -------------------------------------------------------------------------------- /core/src/Math/Vector2I.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MathTemplate.h" 4 | 5 | namespace Altseed2 { 6 | 7 | struct Vector2I_C; 8 | 9 | struct Vector2I { 10 | public: 11 | int32_t X; 12 | 13 | int32_t Y; 14 | 15 | Vector2I(); 16 | 17 | Vector2I(int32_t x, int32_t y); 18 | 19 | bool operator==(const Vector2I& o) const; 20 | 21 | bool operator!=(const Vector2I& o) const; 22 | 23 | Vector2I operator-() const; 24 | 25 | Vector2I operator+(const Vector2I& right) const; 26 | 27 | Vector2I operator-(const Vector2I& right) const; 28 | 29 | Vector2I operator*(const Vector2I& right) const; 30 | 31 | Vector2I operator/(const Vector2I& right) const; 32 | 33 | Vector2I operator*(int32_t right) const; 34 | 35 | Vector2I operator/(int32_t right) const; 36 | 37 | Vector2I& operator+=(const Vector2I& right); 38 | 39 | Vector2I& operator-=(const Vector2I& right); 40 | 41 | Vector2I& operator*=(const Vector2I& right); 42 | 43 | Vector2I& operator/=(const Vector2I& right); 44 | 45 | Vector2I& operator*=(int32_t right); 46 | 47 | Vector2I& operator/=(int32_t right); 48 | 49 | Vector2F To2F() const; 50 | 51 | operator Vector2I_C() const; 52 | }; 53 | 54 | struct Vector2I_C { 55 | int32_t X; 56 | int32_t Y; 57 | 58 | operator Vector2I() const; 59 | }; 60 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Math/Vector3F.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MathTemplate.h" 4 | #include "Vector3I.h" 5 | 6 | namespace Altseed2 { 7 | 8 | struct Vector3F_C; 9 | 10 | struct Vector3F { 11 | public: 12 | float X; 13 | 14 | float Y; 15 | 16 | float Z; 17 | 18 | Vector3F(); 19 | Vector3F(float x, float y, float z); 20 | 21 | bool operator==(const Vector3F& o) const; 22 | bool operator!=(const Vector3F& o) const; 23 | bool operator>(const Vector3F& o) const; 24 | bool operator<(const Vector3F& o) const; 25 | 26 | Vector3F operator-() const; 27 | 28 | Vector3F operator+(const Vector3F& o) const; 29 | 30 | Vector3F operator-(const Vector3F& o) const; 31 | 32 | Vector3F operator*(const Vector3F& o) const; 33 | 34 | Vector3F operator/(const Vector3F& o) const; 35 | 36 | Vector3F operator*(const float& o) const; 37 | 38 | Vector3F operator/(const float& o) const; 39 | 40 | Vector3F& operator+=(const Vector3F& o); 41 | 42 | Vector3F& operator-=(const Vector3F& o); 43 | 44 | Vector3F& operator*=(const Vector3F& o); 45 | 46 | Vector3F& operator/=(const Vector3F& o); 47 | 48 | Vector3F& operator*=(const float& o); 49 | 50 | Vector3F& operator/=(const float& o); 51 | 52 | float GetLength() const { return sqrt(GetSquaredLength()); } 53 | 54 | float GetSquaredLength() const { return X * X + Y * Y + Z * Z; } 55 | 56 | void SetLength(float value) { 57 | float length = GetLength(); 58 | (*this) *= (value / length); 59 | } 60 | 61 | Vector3F GetNormal() const { 62 | float length = GetLength(); 63 | return Vector3F(X / length, Y / length, Z / length); 64 | } 65 | 66 | void Normalize() { 67 | float length = GetLength(); 68 | (*this) /= length; 69 | } 70 | 71 | static float Dot(const Vector3F& v1, const Vector3F& v2); 72 | static Vector3F Cross(const Vector3F& v1, const Vector3F& v2); 73 | 74 | static float Distance(const Vector3F& v1, const Vector3F& v2); 75 | 76 | Vector3I To3I() const; 77 | 78 | operator Vector3F_C() const; 79 | }; 80 | 81 | struct Vector3F_C { 82 | public: 83 | float X; 84 | 85 | float Y; 86 | 87 | float Z; 88 | 89 | operator Vector3F() const; 90 | }; 91 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Math/Vector3I.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MathTemplate.h" 4 | #include "Vector3F.h" 5 | 6 | namespace Altseed2 { 7 | 8 | struct Vector3I_C; 9 | 10 | struct Vector3I { 11 | public: 12 | int32_t X; 13 | 14 | int32_t Y; 15 | 16 | int32_t Z; 17 | 18 | Vector3I(); 19 | Vector3I(int32_t x, int32_t y, int32_t z); 20 | 21 | bool operator==(const Vector3I& o) const; 22 | bool operator!=(const Vector3I& o) const; 23 | bool operator>(const Vector3I& o) const; 24 | bool operator<(const Vector3I& o) const; 25 | 26 | Vector3I operator-() const; 27 | 28 | Vector3I operator+(const Vector3I& o) const; 29 | 30 | Vector3I operator-(const Vector3I& o) const; 31 | 32 | Vector3I operator*(const Vector3I& o) const; 33 | 34 | Vector3I operator/(const Vector3I& o) const; 35 | 36 | Vector3I operator*(const int32_t& o) const; 37 | 38 | Vector3I operator/(const int32_t& o) const; 39 | 40 | Vector3I& operator+=(const Vector3I& o); 41 | 42 | Vector3I& operator-=(const Vector3I& o); 43 | 44 | Vector3I& operator*=(const Vector3I& o); 45 | 46 | Vector3I& operator/=(const Vector3I& o); 47 | 48 | Vector3I& operator*=(const int32_t& o); 49 | 50 | Vector3I& operator/=(const int32_t& o); 51 | 52 | float GetLength() const { return sqrt(static_cast(GetSquaredLength())); } 53 | 54 | int32_t GetSquaredLength() const { return X * X + Y * Y + Z * Z; } 55 | static int32_t Dot(const Vector3I& v1, const Vector3I& v2); 56 | static Vector3I Cross(const Vector3I& v1, const Vector3I& v2); 57 | static Vector3I Add(Vector3I v1, Vector3I v2) { return Vector3I(v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z); } 58 | static Vector3I Subtract(Vector3I v1, Vector3I v2) { return Vector3I(v1.X - v2.X, v1.Y - v2.Y, v1.Z - v2.Z); } 59 | static Vector3I Divide(const Vector3I& v1, const Vector3I& v2) { return Vector3I(v1.X / v2.X, v1.Y / v2.Y, v1.Z / v2.Z); } 60 | static Vector3I DivideByScalar(const Vector3I& v1, float v2) { return Vector3I(v1.X / v2, v1.Y / v2, v1.Z / v2); } 61 | static float Distance(const Vector3I& v1, const Vector3I& v2); 62 | 63 | Vector3F To3F() const; 64 | operator Vector3I_C() const; 65 | }; 66 | 67 | struct Vector3I_C { 68 | public: 69 | int32_t X; 70 | 71 | int32_t Y; 72 | 73 | int32_t Z; 74 | 75 | operator Vector3I() const; 76 | }; 77 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Math/Vector4F.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include "Vector4F.h" 3 | 4 | namespace Altseed2 { 5 | 6 | Vector4F::Vector4F() : X(0), Y(0), Z(0), W(0) {} 7 | 8 | Vector4F::Vector4F(float x, float y, float z, float w) : X(x), Y(y), Z(z), W(w) {} 9 | 10 | bool Vector4F::operator==(const Vector4F& o) const { return X == o.X && Y == o.Y && Z == o.Z && W == o.W; } 11 | 12 | bool Vector4F::operator!=(const Vector4F& o) const { return !(X == o.X && Y == o.Y && Z == o.Z && W == o.W); } 13 | 14 | Vector4F Vector4F::operator-() const { return Vector4F(-X, -Y, -Z, -W); } 15 | 16 | Vector4F Vector4F::operator+(const Vector4F& o) const { return Vector4F(X + o.X, Y + o.Y, Z + o.Z, W + o.W); } 17 | 18 | Vector4F Vector4F::operator-(const Vector4F& o) const { return Vector4F(X - o.X, Y - o.Y, Z - o.Z, W - o.W); } 19 | 20 | Vector4F Vector4F::operator*(const Vector4F& o) const { return Vector4F(X * o.X, Y * o.Y, Z * o.Z, W * o.W); } 21 | 22 | Vector4F Vector4F::operator/(const Vector4F& o) const { return Vector4F(X / o.X, Y / o.Y, Z / o.Z, W / o.W); } 23 | 24 | Vector4F Vector4F::operator*(const float& o) const { return Vector4F(X * o, Y * o, Z * o, W * o); } 25 | 26 | Vector4F Vector4F::operator/(const float& o) const { return Vector4F(X / o, Y / o, Z * o, W * o); } 27 | 28 | float Vector4F::Dot(const Vector4F& v1, const Vector4F& v2) { return v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z + v1.W * v2.W; } 29 | 30 | float Vector4F::Distance(const Vector4F& v1, const Vector4F& v2) { 31 | float dx = v1.X - v2.X; 32 | float dy = v1.Y - v2.Y; 33 | float dz = v1.Z - v2.Z; 34 | float dw = v1.W - v2.W; 35 | return sqrt(dx * dx + dy * dy + dz * dz + dw * dw); 36 | } 37 | 38 | Vector4I Vector4F::To4I() const { return Vector4I((int32_t)X, (int32_t)Y, (int32_t)Z, (int32_t)W); } 39 | 40 | Vector4F::operator Vector4F_C() const { return Vector4F_C{X, Y, Z, W}; } 41 | 42 | Vector4F_C::operator Vector4F() const { return Vector4F(X, Y, Z, W); } 43 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Math/Vector4F.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MathTemplate.h" 4 | #include "Vector4I.h" 5 | 6 | namespace Altseed2 { 7 | 8 | struct Vector4F_C; 9 | 10 | struct Vector4F { 11 | public: 12 | float X; 13 | float Y; 14 | float Z; 15 | float W; 16 | 17 | Vector4F(); 18 | Vector4F(float x, float y, float z, float w); 19 | 20 | float GetLength() const { return sqrt(GetSquaredLength()); } 21 | float GetSquaredLength() const { return X * X + Y * Y + Z * Z + W * W; } 22 | void SetLength(float value) { 23 | float length = GetLength(); 24 | (*this) *= (value / length); 25 | } 26 | 27 | Vector4F GetNormal() const { 28 | float length = GetLength(); 29 | return Vector4F(X / length, Y / length, Z / length, W / length); 30 | } 31 | void Normalize() { 32 | float length = GetLength(); 33 | (*this) /= length; 34 | } 35 | 36 | bool operator==(const Vector4F& o) const; 37 | bool operator!=(const Vector4F& o) const; 38 | 39 | Vector4F operator-() const; 40 | Vector4F operator+(const Vector4F& o) const; 41 | Vector4F operator-(const Vector4F& o) const; 42 | Vector4F operator*(const Vector4F& o) const; 43 | Vector4F operator/(const Vector4F& o) const; 44 | Vector4F operator*(const float& o) const; 45 | Vector4F operator/(const float& o) const; 46 | Vector4F& operator+=(const Vector4F& o); 47 | Vector4F& operator-=(const Vector4F& o); 48 | Vector4F& operator*=(const Vector4F& o); 49 | Vector4F& operator/=(const Vector4F& o); 50 | Vector4F& operator*=(const float& o); 51 | Vector4F& operator/=(const float& o); 52 | 53 | static float Dot(const Vector4F& v1, const Vector4F& v2); 54 | static float Distance(const Vector4F& v1, const Vector4F& v2); 55 | 56 | Vector4I To4I() const; 57 | 58 | operator Vector4F_C() const; 59 | }; 60 | 61 | struct Vector4F_C { 62 | public: 63 | float X; 64 | float Y; 65 | float Z; 66 | float W; 67 | 68 | operator Vector4F() const; 69 | }; 70 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Math/Vector4I.cpp: -------------------------------------------------------------------------------- 1 | #include "Vector4I.h" 2 | 3 | namespace Altseed2 { 4 | Vector4I::Vector4I() : X(0), Y(0), Z(0), W(0) {} 5 | 6 | Vector4I::Vector4I(int32_t x, int32_t y, int32_t z, int32_t w) : X(x), Y(y), Z(z), W(w) {} 7 | 8 | bool Vector4I::operator==(const Vector4I& o) const { return X == o.X && Y == o.Y && Z == o.Z && W == o.W; } 9 | 10 | bool Vector4I::operator!=(const Vector4I& o) const { return !(X == o.X && Y == o.Y && Z == o.Z && W == o.W); } 11 | 12 | Vector4I Vector4I::operator-() const { return Vector4I(-X, -Y, -Z, -W); } 13 | 14 | Vector4I Vector4I::operator+(const Vector4I& o) const { return Vector4I(X + o.X, Y + o.Y, Z + o.Z, W + o.W); } 15 | 16 | Vector4I Vector4I::operator-(const Vector4I& o) const { return Vector4I(X - o.X, Y - o.Y, Z - o.Z, W - o.W); } 17 | 18 | Vector4I Vector4I::operator*(const Vector4I& o) const { return Vector4I(X * o.X, Y * o.Y, Z * o.Z, W * o.W); } 19 | 20 | Vector4I Vector4I::operator/(const Vector4I& o) const { return Vector4I(X / o.X, Y / o.Y, Z / o.Z, W / o.W); } 21 | 22 | Vector4I Vector4I::operator*(const int32_t& o) const { return Vector4I(X * o, Y * o, Z * o, W * o); } 23 | 24 | Vector4I Vector4I::operator/(const int32_t& o) const { return Vector4I(X / o, Y / o, Z * o, W * o); } 25 | 26 | int32_t Vector4I::Dot(const Vector4I& v1, const Vector4I& v2) { return v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z + v1.W * v2.W; } 27 | 28 | float Vector4I::Distance(const Vector4I& v1, const Vector4I& v2) { 29 | int32_t dx = v1.X - v2.X; 30 | int32_t dy = v1.Y - v2.Y; 31 | int32_t dz = v1.Z - v2.Z; 32 | int32_t dw = v1.W - v2.W; 33 | return sqrt(dx * dx + dy * dy + dz * dz + dw * dw); 34 | } 35 | 36 | Vector4F Vector4I::To4F() const { return Vector4F(X, Y, Z, W); } 37 | 38 | Vector4I::operator Vector4I_C() const { return Vector4I_C{X, Y, Z, W}; } 39 | 40 | Vector4I_C::operator Vector4I() const { return Vector4I(X, Y, Z, W); } 41 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Math/Vector4I.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MathTemplate.h" 4 | #include "Vector4F.h" 5 | 6 | namespace Altseed2 { 7 | 8 | struct Vector4I_C; 9 | 10 | struct Vector4I { 11 | public: 12 | int32_t X; 13 | int32_t Y; 14 | int32_t Z; 15 | int32_t W; 16 | 17 | Vector4I(); 18 | Vector4I(int32_t x, int32_t y, int32_t z, int32_t w); 19 | 20 | float GetLength() const { return sqrt(static_cast(GetSquaredLength())); } 21 | 22 | int32_t GetSquaredLength() const { return X * X + Y * Y + Z * Z + W * W; } 23 | 24 | bool operator==(const Vector4I& o) const; 25 | bool operator!=(const Vector4I& o) const; 26 | 27 | Vector4I operator-() const; 28 | Vector4I operator+(const Vector4I& o) const; 29 | Vector4I operator-(const Vector4I& o) const; 30 | Vector4I operator*(const Vector4I& o) const; 31 | Vector4I operator/(const Vector4I& o) const; 32 | Vector4I operator*(const int32_t& o) const; 33 | Vector4I operator/(const int32_t& o) const; 34 | Vector4I& operator+=(const Vector4I& o); 35 | Vector4I& operator-=(const Vector4I& o); 36 | Vector4I& operator*=(const Vector4I& o); 37 | Vector4I& operator/=(const Vector4I& o); 38 | Vector4I& operator*=(const int32_t& o); 39 | Vector4I& operator/=(const int32_t& o); 40 | 41 | static int32_t Dot(const Vector4I& v1, const Vector4I& v2); 42 | static float Distance(const Vector4I& v1, const Vector4I& v2); 43 | 44 | Vector4F To4F() const; 45 | operator Vector4I_C() const; 46 | }; 47 | 48 | struct Vector4I_C { 49 | public: 50 | int32_t X; 51 | int32_t Y; 52 | int32_t Z; 53 | int32_t W; 54 | 55 | operator Vector4I() const; 56 | }; 57 | 58 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Media/MediaPlayer.cpp: -------------------------------------------------------------------------------- 1 | #include "MediaPlayer.h" 2 | 3 | #include "Platform/MediaPlayer_FFmpeg.h" 4 | #include "Platform/MediaPlayer_Impl.h" 5 | 6 | #ifdef _WIN32 7 | #include "Platform/MediaPlayer_WMF.h" 8 | #endif 9 | 10 | #ifdef __APPLE__ 11 | #include "Platform/MediaPlayer_AVF.h" 12 | #endif 13 | 14 | namespace Altseed2 { 15 | 16 | MediaPlayer::MediaPlayer() { 17 | #ifdef _WIN32 18 | impl_ = std::make_shared(); 19 | #elif defined(__APPLE__) 20 | impl_ = std::make_shared(); 21 | #else 22 | impl_ = std::make_shared(); 23 | #endif 24 | } 25 | 26 | bool MediaPlayer::Play(bool isLoopingMode) { 27 | return impl_->Play(isLoopingMode); 28 | } 29 | 30 | bool MediaPlayer::WriteToRenderTexture(std::shared_ptr target) { 31 | return impl_->WriteToRenderTexture(target); 32 | } 33 | 34 | Vector2I MediaPlayer::GetSize() const { 35 | return impl_->GetSize(); 36 | } 37 | 38 | int32_t MediaPlayer::GetCurrentFrame() const { 39 | return impl_->GetCurrentFrame(); 40 | } 41 | 42 | std::shared_ptr MediaPlayer::Load(const char16_t* path) { 43 | auto ret = MakeAsdShared(); 44 | if (ret->impl_->SetSourceFromPath(path)) { 45 | return ret; 46 | } 47 | 48 | return nullptr; 49 | } 50 | 51 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Media/MediaPlayer.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | 6 | #include "../Graphics/RenderTexture.h" 7 | #include "../Math/Vector2I.h" 8 | 9 | namespace Altseed2 { 10 | 11 | class MediaPlayer_Impl; 12 | 13 | class MediaPlayer 14 | : public BaseObject { 15 | private: 16 | std::shared_ptr impl_; 17 | 18 | public: 19 | MediaPlayer(); 20 | virtual ~MediaPlayer() = default; 21 | 22 | bool Play(bool isLoopingMode); 23 | 24 | bool WriteToRenderTexture(std::shared_ptr target); 25 | 26 | Vector2I GetSize() const; 27 | 28 | int32_t GetCurrentFrame() const; 29 | 30 | static std::shared_ptr Load(const char16_t* path); 31 | }; 32 | 33 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Media/Platform/MediaPlayer_AVF.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "MediaPlayer_Impl.h" 8 | 9 | namespace Altseed2 { 10 | 11 | class MediaPlayer_AVF : public MediaPlayer_Impl { 12 | private: 13 | class Impl; 14 | std::shared_ptr impl_; 15 | 16 | public: 17 | MediaPlayer_AVF(); 18 | ~MediaPlayer_AVF(); 19 | 20 | bool Play(bool isLoopingMode) override; 21 | 22 | bool SetSourceFromPath(const char16_t* path) override; 23 | 24 | Vector2I GetSize() const override; 25 | 26 | int32_t GetCurrentFrame() const override; 27 | 28 | bool WriteToRenderTexture(std::shared_ptr target) override; 29 | }; 30 | 31 | } // namespace Altseed2 32 | -------------------------------------------------------------------------------- /core/src/Media/Platform/MediaPlayer_FFmpeg.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "MediaPlayer_Impl.h" 9 | 10 | namespace Altseed2 { 11 | 12 | class MediaPlayer_FFmpeg : public MediaPlayer_Impl { 13 | std::mutex mtx_; 14 | std::thread thread_; 15 | Vector2I size_; 16 | float fps_ = 0; 17 | std::string filePath_; 18 | bool isLoopingMode_ = false; 19 | std::vector internalBuffer_; 20 | 21 | bool isPlaying_ = false; 22 | bool isThreadRequiredToJoin_ = false; 23 | 24 | int32_t currentFrame_ = 0; 25 | std::chrono::system_clock::time_point startTime_; 26 | std::shared_ptr process_; 27 | 28 | void ThreadLoop(); 29 | 30 | public: 31 | MediaPlayer_FFmpeg(); 32 | ~MediaPlayer_FFmpeg(); 33 | 34 | bool Play(bool isLoopingMode) override; 35 | 36 | bool SetSourceFromPath(const char16_t* path) override; 37 | 38 | Vector2I GetSize() const override; 39 | 40 | int32_t GetCurrentFrame() const override; 41 | 42 | bool WriteToRenderTexture(std::shared_ptr target) override; 43 | }; 44 | 45 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Media/Platform/MediaPlayer_Impl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Graphics/Graphics.h" 4 | #include "../../Graphics/RenderTexture.h" 5 | #include "../../Math/Vector2I.h" 6 | 7 | namespace Altseed2 { 8 | 9 | class MediaPlayer_Impl { 10 | public: 11 | virtual bool Play(bool isLoopingMode) = 0; 12 | 13 | virtual bool SetSourceFromPath(const char16_t* path) = 0; 14 | 15 | virtual Vector2I GetSize() const = 0; 16 | 17 | virtual int32_t GetCurrentFrame() const = 0; 18 | 19 | virtual bool WriteToRenderTexture(std::shared_ptr target) = 0; 20 | }; 21 | 22 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Media/Platform/MediaPlayer_WMF.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include "MediaPlayer_Impl.h" 13 | 14 | namespace Altseed2 { 15 | 16 | class MediaPlayer_WMF : public MediaPlayer_Impl { 17 | std::mutex mtx; 18 | std::thread thread_; 19 | Vector2I size_; 20 | float fps = 0; 21 | bool isLoopingMode_ = false; 22 | std::vector internalBufferYUY; 23 | std::vector internalBuffer; 24 | std::vector internalBufferEditing; 25 | 26 | bool isPlaying = false; 27 | bool isThreadRequiredToJoin = false; 28 | 29 | int32_t currentFrame = 0; 30 | std::chrono::system_clock::time_point startTime; 31 | 32 | IMFSourceReader* reader = nullptr; 33 | 34 | void ThreadLoop(); 35 | 36 | public: 37 | MediaPlayer_WMF(); 38 | ~MediaPlayer_WMF(); 39 | 40 | bool Play(bool isLoopingMode) override; 41 | 42 | bool SetSourceFromPath(const char16_t* path) override; 43 | 44 | Vector2I GetSize() const override; 45 | 46 | int32_t GetCurrentFrame() const override; 47 | 48 | bool WriteToRenderTexture(std::shared_ptr target) override; 49 | }; 50 | 51 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Physics/Collider/Box2DHelper.cpp: -------------------------------------------------------------------------------- 1 | #include "Box2DHelper.h" 2 | 3 | namespace Altseed2 { 4 | 5 | void Box2DHelper::SetMat(b2Transform& transform, const Matrix44F& mat) { 6 | Matrix44F rotation; 7 | Vector2F position; 8 | Vector2F scale; 9 | Matrix44F::CalcFromTransform2D(mat, rotation, position, scale); 10 | transform.p = ToBox2D_Vec(position); 11 | transform.q = ToBox2D_Rot(rotation); 12 | } 13 | 14 | b2Transform Box2DHelper::ToBox2D_Mat(const Matrix44F& transform) { 15 | b2Transform ret; 16 | SetMat(ret, transform); 17 | return ret; 18 | } 19 | 20 | Matrix44F Box2DHelper::ToAsd_Mat(const b2Transform& transform) { 21 | Matrix44F pos; 22 | for (int i = 0; i < 4; i++) pos.Values[i][i] = 1; 23 | pos.Values[0][3] = transform.p.x; 24 | pos.Values[1][3] = transform.p.y; 25 | return pos * ToAsd_Rot(transform.q); 26 | } 27 | 28 | b2Vec2 Box2DHelper::ToBox2D_Vec(const Vector2F& vector) { return b2Vec2(vector.X, vector.Y); } 29 | b2Vec3 Box2DHelper::ToBox2D_Vec(const Vector3F& vector) { return b2Vec3(vector.X, vector.Y, vector.Z); } 30 | 31 | Vector2F Box2DHelper::ToAsd_Vec(const b2Vec2& vector) { return Vector2F(vector.x, vector.y); } 32 | Vector3F Box2DHelper::ToAsd_Vec(const b2Vec3& vector) { return Vector3F(vector.x, vector.y, vector.z); } 33 | 34 | b2Rot Box2DHelper::ToBox2D_Rot(const Matrix44F& rotation) { 35 | b2Rot ret; 36 | ret.c = rotation.Values[0][0]; 37 | ret.s = rotation.Values[1][0]; 38 | return ret; 39 | } 40 | 41 | Matrix44F Box2DHelper::ToAsd_Rot(const b2Rot& rotation) { 42 | Matrix44F ret; 43 | for (int i = 0; i < 4; i++) ret.Values[i][i] = 1; 44 | ret.Values[0][0] = rotation.c; 45 | ret.Values[1][0] = rotation.s; 46 | ret.Values[0][1] = -rotation.s; 47 | ret.Values[1][1] = rotation.c; 48 | return ret; 49 | } 50 | 51 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Physics/Collider/Box2DHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../../Math/Matrix44F.h" 6 | #include "../../Math/Vector2F.h" 7 | #include "../../Math/Vector3F.h" 8 | 9 | #if !USE_CBG 10 | 11 | namespace Altseed2 { 12 | 13 | class Box2DHelper { 14 | public: 15 | /** 16 | @brief 変形行列をb2Transformにset 17 | @param transform 対象のb2transform 18 | @param mat 変形行列 19 | */ 20 | static void SetMat(b2Transform& transform, const Matrix44F& mat); 21 | 22 | /** 23 | @brief 変形行列をAltseed2->Box2Dに変換 24 | @param transform 変換したいAltseed2の変形行列 25 | @return Box2Dの変形行列 26 | */ 27 | static b2Transform ToBox2D_Mat(const Matrix44F& transform); 28 | 29 | /** 30 | @brief 変形行列をBox2D->Altseed2に変換 31 | @param transform 変換したいBox2Dの変形行列 32 | @return Altseed2の変形行列 33 | */ 34 | static Matrix44F ToAsd_Mat(const b2Transform& transform); 35 | 36 | /** 37 | @brief 2次元ベクトルをAltseed2->Box2Dに変換 38 | @param vector 変換したいAltseed2の2次元ベクトル 39 | @return Box2Dの2次元ベクトル 40 | */ 41 | static b2Vec2 ToBox2D_Vec(const Vector2F& vector); 42 | 43 | /** 44 | @brief 3次元ベクトルをAltseed2->Box2Dに変換 45 | @param vector 変換したいAltseed2の3次元ベクトル 46 | @return Box2Dの3次元ベクトル 47 | */ 48 | static b2Vec3 ToBox2D_Vec(const Vector3F& vector); 49 | 50 | /** 51 | @brief 2次元ベクトルをBox2D->Altseed2に変換 52 | @param vector 変換したいAltseed2の2次元ベクトル 53 | @return Box2Dの2次元ベクトル 54 | */ 55 | static Vector2F ToAsd_Vec(const b2Vec2& vector); 56 | 57 | /** 58 | @brief 3次元ベクトルをBox2D->Altseed2に変換 59 | @param vector 変換したいAltseed3の2次元ベクトル 60 | @return Box2Dの3次元ベクトル 61 | */ 62 | static Vector3F ToAsd_Vec(const b2Vec3& vector); 63 | 64 | /** 65 | @brief 3回転行列をAltseed2->Box2Dに変換 66 | @param rotation 変換したいAltseed2の回転行列 67 | @return Box2Dの回転を表すオブジェクト 68 | */ 69 | static b2Rot ToBox2D_Rot(const Matrix44F& rotation); 70 | 71 | /** 72 | @brief 3回転行列をBox2D->Altseed2に変換 73 | @param rotation 変換したいBox2Dの回転を表すオブジェクト 74 | @return Altseed2の回転行列 75 | */ 76 | static Matrix44F ToAsd_Rot(const b2Rot& rotation); 77 | }; 78 | 79 | } // namespace Altseed2 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /core/src/Physics/Collider/CircleCollider.cpp: -------------------------------------------------------------------------------- 1 | #include "CircleCollider.h" 2 | 3 | namespace Altseed2 { 4 | 5 | CircleCollider::CircleCollider() { 6 | position_ = Vector2F(0, 0); 7 | radius_ = 0; 8 | 9 | shape_.m_p = b2Vec2_zero; 10 | shape_.m_radius = 0; 11 | shapesBuffer_.emplace_back(&shape_); 12 | } 13 | 14 | std::shared_ptr CircleCollider::Create() { return MakeAsdShared(); } 15 | 16 | float CircleCollider::GetRadius() const { return radius_; } 17 | void CircleCollider::SetRadius(float radius) { 18 | radius_ = radius; 19 | shape_.m_radius = radius; 20 | } 21 | 22 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Physics/Collider/CircleCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Math/Vector2F.h" 4 | #include "Collider.h" 5 | #include "EdgeCollider.h" 6 | #include "PolygonCollider.h" 7 | #include "ShapeCollider.h" 8 | 9 | namespace Altseed2 { 10 | 11 | class CircleCollider : public Collider { 12 | private: 13 | b2CircleShape shape_; 14 | float radius_; 15 | 16 | protected: 17 | const std::vector& GetB2Shapes() override { 18 | return shapesBuffer_; 19 | } 20 | 21 | public: 22 | CircleCollider(); 23 | 24 | static std::shared_ptr Create(); 25 | 26 | // 半径 27 | float GetRadius() const; 28 | void SetRadius(float radius); 29 | }; 30 | 31 | } // namespace Altseed2 32 | -------------------------------------------------------------------------------- /core/src/Physics/Collider/Collider.cpp: -------------------------------------------------------------------------------- 1 | #include "Collider.h" 2 | 3 | #include "../../Logger/Log.h" 4 | #include "Box2DHelper.h" 5 | 6 | namespace Altseed2 { 7 | 8 | Collider::Collider() { 9 | transform_.SetIdentity(); 10 | transformMatrix_.SetIdentity(); 11 | } 12 | 13 | Vector2F Collider::GetPosition() const { return position_; } 14 | void Collider::SetPosition(Vector2F position) { 15 | position_ = position; 16 | transform_.p = b2Vec2(position.X, position.Y); 17 | Matrix44F t, r; 18 | t.SetTranslation(position.X, position.Y, 1); 19 | r.SetRotationZ(rotation_); 20 | transformMatrix_ = t * r; 21 | } 22 | 23 | float Collider::GetRotation() const { return rotation_; } 24 | void Collider::SetRotation(float rotation) { 25 | rotation_ = rotation; 26 | transform_.q = b2Rot(rotation); 27 | Matrix44F t, r; 28 | t.SetTranslation(position_.X, position_.Y, 1); 29 | r.SetRotationZ(rotation); 30 | transformMatrix_ = t * r; 31 | } 32 | 33 | Matrix44F Collider::GetTransform() const { return transformMatrix_; } 34 | void Collider::SetTransform(const Matrix44F& transform) { 35 | Box2DHelper::SetMat(transform_, transform); 36 | transformMatrix_ = transform; 37 | double r; 38 | Vector2F p, s; 39 | Matrix44F::CalcFromTransform2D(transform, r, p, s); 40 | position_ = p; 41 | rotation_ = r; 42 | } 43 | 44 | bool Collider::GetIsCollidedWith(const std::shared_ptr& collider) { 45 | RETURN_IF_NULL(collider, false); 46 | 47 | auto selfShapes = GetB2Shapes(); 48 | auto otherShapes = collider->GetB2Shapes(); 49 | 50 | for (auto s1 : selfShapes) { 51 | for (auto s2 : otherShapes) { 52 | if (b2TestOverlap(s1, 0, s2, 0, transform_, collider->transform_)) { 53 | return true; 54 | } 55 | } 56 | } 57 | 58 | return false; 59 | } 60 | 61 | } // namespace Altseed2 62 | -------------------------------------------------------------------------------- /core/src/Physics/Collider/Collider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include "../../BaseObject.h" 9 | #include "../../Math/Matrix44F.h" 10 | #include "../../Math/Vector2F.h" 11 | 12 | namespace Altseed2 { 13 | 14 | class Collider : public BaseObject { 15 | protected: 16 | b2Transform transform_; 17 | Matrix44F transformMatrix_; 18 | 19 | Vector2F position_; 20 | float rotation_; 21 | 22 | std::vector shapesBuffer_; 23 | 24 | virtual const std::vector& GetB2Shapes() { throw "Not implemented."; } 25 | 26 | public: 27 | Collider(); 28 | bool GetIsCollidedWith(const std::shared_ptr& collider); 29 | 30 | // 位置 31 | Vector2F GetPosition() const; 32 | void SetPosition(Vector2F position); 33 | 34 | // 回転 35 | float GetRotation() const; 36 | void SetRotation(float rotation); 37 | 38 | // 変形行列 39 | Matrix44F GetTransform() const; 40 | void SetTransform(const Matrix44F& transform); 41 | }; 42 | 43 | } // namespace Altseed2 44 | -------------------------------------------------------------------------------- /core/src/Physics/Collider/EdgeCollider.cpp: -------------------------------------------------------------------------------- 1 | #include "EdgeCollider.h" 2 | 3 | #include "Box2DHelper.h" 4 | 5 | namespace Altseed2 { 6 | 7 | EdgeCollider::EdgeCollider() { 8 | point1_ = Vector2F(); 9 | point2_ = Vector2F(); 10 | shape_.m_vertex1 = b2Vec2_zero; 11 | shape_.m_vertex2 = b2Vec2_zero; 12 | shapesBuffer_.emplace_back(&shape_); 13 | } 14 | 15 | std::shared_ptr EdgeCollider::Create() { return MakeAsdShared(); } 16 | 17 | Vector2F EdgeCollider::GetPoint1() const { return point1_; } 18 | void EdgeCollider::SetPoint1(const Vector2F& point) { 19 | point1_ = point; 20 | shape_.m_vertex1 = Box2DHelper::ToBox2D_Vec(point); 21 | } 22 | 23 | Vector2F EdgeCollider::GetPoint2() const { return point2_; } 24 | void EdgeCollider::SetPoint2(const Vector2F& point) { 25 | point2_ = point; 26 | shape_.m_vertex2 = Box2DHelper::ToBox2D_Vec(point); 27 | } 28 | 29 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Physics/Collider/EdgeCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Math/Vector2F.h" 4 | #include "CircleCollider.h" 5 | #include "Collider.h" 6 | #include "PolygonCollider.h" 7 | #include "ShapeCollider.h" 8 | 9 | namespace Altseed2 { 10 | 11 | class EdgeCollider : public Collider { 12 | private: 13 | b2EdgeShape shape_; 14 | Vector2F point1_; 15 | Vector2F point2_; 16 | 17 | protected: 18 | const std::vector& GetB2Shapes() override { 19 | return shapesBuffer_; 20 | } 21 | 22 | public: 23 | EdgeCollider(); 24 | 25 | Vector2F GetPoint1() const; 26 | void SetPoint1(const Vector2F& point); 27 | 28 | Vector2F GetPoint2() const; 29 | void SetPoint2(const Vector2F& point); 30 | 31 | static std::shared_ptr Create(); 32 | }; 33 | 34 | } // namespace Altseed2 35 | -------------------------------------------------------------------------------- /core/src/Physics/Collider/PolygonCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Common/Array.h" 4 | #include "../../Math/Vector2F.h" 5 | #include "CircleCollider.h" 6 | #include "Collider.h" 7 | #include "EdgeCollider.h" 8 | #include "ShapeCollider.h" 9 | 10 | namespace Altseed2 { 11 | 12 | class PolygonCollider : public Collider { 13 | private: 14 | std::shared_ptr buffers_; 15 | 16 | std::vector triangles_; 17 | 18 | std::shared_ptr vertexes_; 19 | 20 | void UpdateTriangles(); 21 | 22 | bool updatedTriangles_; 23 | 24 | protected: 25 | const std::vector& GetB2Shapes() override { 26 | if (updatedTriangles_) { 27 | shapesBuffer_.clear(); 28 | for (int i = 0; i < triangles_.size(); i++) { 29 | shapesBuffer_.emplace_back(&triangles_[i]); 30 | } 31 | updatedTriangles_ = false; 32 | } 33 | return shapesBuffer_; 34 | } 35 | 36 | public: 37 | PolygonCollider(); 38 | 39 | static std::shared_ptr Create(); 40 | 41 | // IB 42 | std::shared_ptr GetBuffers() const; 43 | void SetBuffers(const std::shared_ptr buffers); 44 | 45 | // 頂点 46 | std::shared_ptr GetVertexes() const; 47 | void SetVertexes(std::shared_ptr vertexes); 48 | 49 | void SetDefaultIndexBuffer(); 50 | }; 51 | 52 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Physics/Collider/ShapeCollider.cpp: -------------------------------------------------------------------------------- 1 | #include "ShapeCollider.h" 2 | 3 | #include "../../Logger/Log.h" 4 | #include "Box2DHelper.h" 5 | 6 | namespace Altseed2 { 7 | 8 | ShapeCollider::ShapeCollider() { 9 | position_ = Vector2F(0, 0); 10 | rotation_ = 0; 11 | vertexes_ = Vector2FArray::Create(0); 12 | shape_.m_count = 0; 13 | shapesBuffer_.emplace_back(&shape_); 14 | } 15 | 16 | std::shared_ptr ShapeCollider::Create() { return MakeAsdShared(); } 17 | 18 | std::shared_ptr ShapeCollider::GetVertexes() const { return vertexes_; } 19 | void ShapeCollider::SetVertexes(const std::shared_ptr& vertexes) { 20 | if (vertexes->GetVector().size() > b2_maxPolygonVertices) { 21 | Log::GetInstance()->Error(LogCategory::Core, u"頂点数は8つまでです"); 22 | return; 23 | } 24 | vertexes_ = vertexes; 25 | shape_.m_count = vertexes->GetVector().size(); 26 | for (int i = 0; i < vertexes->GetVector().size(); i++) shape_.m_vertices[i] = Box2DHelper::ToBox2D_Vec(vertexes_->GetVector()[i]); 27 | } 28 | 29 | } // namespace Altseed2 30 | -------------------------------------------------------------------------------- /core/src/Physics/Collider/ShapeCollider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Common/Array.h" 4 | #include "CircleCollider.h" 5 | #include "Collider.h" 6 | #include "EdgeCollider.h" 7 | #include "PolygonCollider.h" 8 | 9 | namespace Altseed2 { 10 | 11 | class ShapeCollider : public Collider { 12 | private: 13 | b2PolygonShape shape_; 14 | std::shared_ptr vertexes_; 15 | 16 | protected: 17 | const std::vector& GetB2Shapes() override { 18 | return shapesBuffer_; 19 | } 20 | 21 | public: 22 | ShapeCollider(); 23 | 24 | static std::shared_ptr Create(); 25 | 26 | std::shared_ptr GetVertexes() const; 27 | void SetVertexes(const std::shared_ptr& vertexes); 28 | }; 29 | 30 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Platform/FileSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #ifdef _WIN32 8 | #undef CreateDirectory 9 | #endif 10 | 11 | #if !USE_CBG 12 | 13 | namespace Altseed2 { 14 | class FileSystem { 15 | public: 16 | static bool GetIsFile(const std::u16string& path); 17 | static bool GetIsDirectory(const std::u16string& path); 18 | static int32_t GetLastWriteTime(const std::u16string& path); 19 | static void GetChildPaths(const std::u16string& path, std::vector& childPaths); 20 | static int32_t GetFileSize(const std::u16string& path); 21 | static bool CreateDirectory(const std::u16string& path); 22 | static std::u16string GetParentPath(const std::u16string& path); 23 | static std::u16string GetAbusolutePath(const std::u16string& path); 24 | static bool GetIsAbsolutePath(const std::u16string& path); 25 | static std::u16string NormalizePath(const std::u16string& path); 26 | static std::u16string GetFileName(const std::u16string& path, bool withExtension = true); 27 | }; 28 | } // namespace Altseed2 29 | 30 | #endif -------------------------------------------------------------------------------- /core/src/Platform/FileSystemLinux.cpp: -------------------------------------------------------------------------------- 1 | #if __GNUC__ >= 8 2 | #include 3 | namespace fs = std::filesystem; 4 | #else 5 | #include 6 | namespace fs = std::experimental::filesystem; 7 | #endif 8 | 9 | #include 10 | 11 | #include "FileSystem.h" 12 | 13 | namespace Altseed2 { 14 | bool FileSystem::GetIsFile(const std::u16string& path) { return fs::is_regular_file(path); } 15 | 16 | bool FileSystem::GetIsDirectory(const std::u16string& path) { return fs::is_directory(path); } 17 | 18 | int32_t FileSystem::GetLastWriteTime(const std::u16string& path) { 19 | std::error_code ec; 20 | return fs::last_write_time(path, ec).time_since_epoch().count(); 21 | } 22 | 23 | void FileSystem::GetChildPaths(const std::u16string& path, std::vector& childPaths) { 24 | childPaths.clear(); 25 | for (const fs::directory_entry& i : fs::directory_iterator(path)) { 26 | childPaths.push_back(i.path().generic_u16string()); 27 | } 28 | } 29 | 30 | int32_t FileSystem::GetFileSize(const std::u16string& path) { return fs::file_size(path); } 31 | 32 | bool FileSystem::CreateDirectory(const std::u16string& path) { return fs::create_directory(path); } 33 | 34 | std::u16string FileSystem::GetParentPath(const std::u16string& path) { return fs::path(path).parent_path().u16string(); } 35 | 36 | std::u16string FileSystem::GetAbusolutePath(const std::u16string& path) { return fs::absolute(path).u16string(); } 37 | 38 | bool FileSystem::GetIsAbsolutePath(const std::u16string& path) { 39 | return fs::path(path).is_absolute(); 40 | } 41 | 42 | std::u16string FileSystem::NormalizePath(const std::u16string& path) { 43 | std::u16string res = path; 44 | std::replace(res.begin(), res.end(), u'\\', u'/'); 45 | return res; 46 | } 47 | 48 | std::u16string FileSystem::GetFileName(const std::u16string& path, bool withExtension) { 49 | const fs::path pathObj(path); 50 | if (withExtension) { 51 | return pathObj.filename().u16string(); 52 | } else { 53 | if (pathObj.has_stem()) { 54 | return pathObj.stem().u16string(); 55 | } else { 56 | return u""; 57 | } 58 | } 59 | } 60 | 61 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Platform/FileSystemWin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace fs = std::filesystem; 3 | 4 | #include "FileSystem.h" 5 | 6 | namespace Altseed2 { 7 | bool FileSystem::GetIsFile(const std::u16string& path) { return fs::is_regular_file(path); } 8 | 9 | bool FileSystem::GetIsDirectory(const std::u16string& path) { return fs::is_directory(path); } 10 | 11 | int32_t FileSystem::GetLastWriteTime(const std::u16string& path) { 12 | std::error_code ec; 13 | return fs::last_write_time(path, ec).time_since_epoch().count(); 14 | } 15 | 16 | void FileSystem::GetChildPaths(const std::u16string& path, std::vector& childPaths) { 17 | childPaths.clear(); 18 | for (const fs::directory_entry& i : fs::directory_iterator(path)) { 19 | childPaths.push_back(i.path().generic_u16string()); 20 | } 21 | } 22 | 23 | int32_t FileSystem::GetFileSize(const std::u16string& path) { return fs::file_size(path); } 24 | 25 | bool FileSystem::CreateDirectory(const std::u16string& path) { return fs::create_directory(path); } 26 | 27 | std::u16string FileSystem::GetParentPath(const std::u16string& path) { return fs::path(path).parent_path().u16string(); } 28 | 29 | std::u16string FileSystem::GetAbusolutePath(const std::u16string& path) { return fs::absolute(path).u16string(); } 30 | 31 | bool FileSystem::GetIsAbsolutePath(const std::u16string& path) { 32 | return fs::path(path).is_absolute(); 33 | } 34 | 35 | std::u16string FileSystem::NormalizePath(const std::u16string& path) { 36 | return path; 37 | } 38 | 39 | std::u16string FileSystem::GetFileName(const std::u16string& path, bool withExtension) { 40 | const fs::path pathObj(path); 41 | if (withExtension) { 42 | return pathObj.filename().u16string(); 43 | } else { 44 | if (pathObj.has_stem()) { 45 | return pathObj.stem().u16string(); 46 | } else { 47 | return u""; 48 | } 49 | } 50 | } 51 | 52 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/Sound/Sound.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "../Common/Resources.h" 6 | #include "../Common/ThreadSafeMap.h" 7 | #include "SoundMixer.h" 8 | 9 | namespace Altseed2 { 10 | 11 | class SoundMixer; 12 | class Resources; 13 | 14 | /** 15 | @brief 音源のクラス 16 | */ 17 | class Sound : public Resource { 18 | private: 19 | std::shared_ptr m_sound; 20 | 21 | std::u16string m_filePath; 22 | const bool m_isDecompressed; 23 | 24 | std::shared_ptr resources_; 25 | 26 | static std::mutex mtx; 27 | 28 | public: 29 | Sound(std::u16string filePath, std::shared_ptr sound, bool isDecompressed, std::shared_ptr resources); 30 | virtual ~Sound(); 31 | 32 | /** 33 | @brief 音を読み込む 34 | @param path 音源のファイルパス 35 | @param isDecompressed 音源情報を解凍するか? 36 | @return 音源 37 | */ 38 | static std::shared_ptr Load(const char16_t* path, bool isDecompressed); 39 | 40 | /** 41 | @brief ループポイントの開始地点(秒)を取得する 42 | @return 開始地点(秒) 43 | */ 44 | float GetLoopStartingPoint() const; 45 | 46 | /** 47 | @brief ループポイントの開始地点(秒)を設定する 48 | @param startingPoint 開始地点(秒) 49 | */ 50 | void SetLoopStartingPoint(float startingPoint) const; 51 | 52 | /** 53 | @brief ループポイントの終了地点(秒)を取得する 54 | @return 終了地点(秒) 55 | */ 56 | float GetLoopEndPoint() const; 57 | 58 | /** 59 | @brief ループポイントの終了地点(秒)を設定する 60 | @param endPoint 終了地点(秒) 61 | */ 62 | void SetLoopEndPoint(float endPoint) const; 63 | 64 | /** 65 | @brief ループするかを取得する 66 | @return ループするか? 67 | */ 68 | bool GetIsLoopingMode() const; 69 | 70 | /** 71 | @brief ループするかを設定する 72 | @param isLoopingMode ループするか? 73 | */ 74 | void SetIsLoopingMode(bool isLoopingMode); 75 | 76 | /** 77 | @brief 音の長さを取得する 78 | @return 長さ(秒) 79 | */ 80 | float GetLength(); 81 | 82 | const char16_t* GetPath() const; 83 | 84 | bool GetIsDecompressed() const; 85 | 86 | #if !USE_CBG 87 | 88 | std::shared_ptr GetSound() { return m_sound; } 89 | 90 | #endif 91 | bool Reload() override; 92 | }; 93 | 94 | } // namespace Altseed2 95 | -------------------------------------------------------------------------------- /core/src/StdIntCBG.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #if defined(USE_CBG) 3 | namespace Altseed2 { 4 | using int8_t = char; 5 | using int32_t = int; 6 | using uint32_t = unsigned int; 7 | } // namespace Altseed2 8 | #endif -------------------------------------------------------------------------------- /core/src/System/SynchronizationContext.cpp: -------------------------------------------------------------------------------- 1 | #include "SynchronizationContext.h" 2 | 3 | namespace Altseed2 { 4 | 5 | std::shared_ptr SynchronizationContext::instance_; 6 | 7 | void SynchronizationContext::AddEvent(const std::function& f) { 8 | auto e = std::make_unique(); 9 | e->f = f; 10 | events_.push_back(std::move(e)); 11 | } 12 | 13 | void SynchronizationContext::Run() { 14 | for (auto& e : events_) { 15 | e->Call(); 16 | } 17 | 18 | events_.clear(); 19 | } 20 | 21 | void SynchronizationContext::Initialize() { instance_ = MakeAsdShared(); } 22 | 23 | void SynchronizationContext::Terminate() { instance_.reset(); } 24 | 25 | std::shared_ptr& SynchronizationContext::GetInstance() { return instance_; } 26 | 27 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/src/System/SynchronizationContext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../BaseObject.h" 9 | 10 | #if !USE_CBG 11 | 12 | namespace Altseed2 { 13 | 14 | class SynchronizationContext : public BaseObject { 15 | private: 16 | static std::shared_ptr instance_; 17 | 18 | struct Event { 19 | std::function f; 20 | 21 | void Call() { f(); } 22 | }; 23 | 24 | std::vector> events_; 25 | 26 | public: 27 | void AddEvent(const std::function& f); 28 | 29 | void Run(); 30 | 31 | static void Initialize(); 32 | 33 | static void Terminate(); 34 | 35 | static std::shared_ptr& GetInstance(); 36 | }; 37 | 38 | } // namespace Altseed2 39 | 40 | #endif -------------------------------------------------------------------------------- /core/src/Tool/Platform/ImGuiPlatform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #if !USE_CBG 9 | 10 | #undef CreateFont 11 | 12 | class ImguiPlatform { 13 | public: 14 | ImguiPlatform() = default; 15 | virtual ~ImguiPlatform() = default; 16 | 17 | virtual void NewFrame(LLGI::RenderPass* renderPass) = 0; 18 | 19 | virtual void RenderDrawData(ImDrawData* draw_data, LLGI::CommandList* commandList) = 0; 20 | 21 | virtual ImTextureID GetTextureIDToRender(LLGI::Texture* texture, LLGI::CommandList* commandList) { return nullptr; } 22 | 23 | virtual void CreateFont() {} 24 | 25 | virtual void DisposeFont() {} 26 | }; 27 | 28 | #endif -------------------------------------------------------------------------------- /core/src/Tool/Platform/ImGuiPlatformMetal.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | 6 | #include "ImGuiPlatform.h" 7 | 8 | class ImguiPlatformMetal_Impl; 9 | 10 | #if !USE_CBG 11 | 12 | class ImguiPlatformMetal : public ImguiPlatform { 13 | ImguiPlatformMetal_Impl* impl = nullptr; 14 | std::unordered_set> textures_; 15 | 16 | public: 17 | ImguiPlatformMetal(LLGI::Graphics* g); 18 | 19 | virtual ~ImguiPlatformMetal(); 20 | 21 | void NewFrame(LLGI::RenderPass* renderPass) override; 22 | 23 | void RenderDrawData(ImDrawData* draw_data, LLGI::CommandList* commandList) override; 24 | 25 | ImTextureID GetTextureIDToRender(LLGI::Texture* texture, LLGI::CommandList* commandList) override; 26 | 27 | void CreateFont() override; 28 | 29 | void DisposeFont() override; 30 | }; 31 | 32 | #endif -------------------------------------------------------------------------------- /core/src/Tool/Platform/ImGuiPlatformMetal.mm: -------------------------------------------------------------------------------- 1 | #include "ImGuiPlatformMetal.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class ImguiPlatformMetal_Impl { 12 | public: 13 | LLGI::GraphicsMetal* g_ = nullptr; 14 | 15 | ImguiPlatformMetal_Impl(LLGI::Graphics* g) : g_(static_cast(g)) { ImGui_ImplMetal_Init(g_->GetDevice()); } 16 | 17 | virtual ~ImguiPlatformMetal_Impl() { ImGui_ImplMetal_Shutdown(); } 18 | 19 | void NewFrame(LLGI::RenderPass* renderPass) { 20 | auto rp = (LLGI::RenderPassMetal*)renderPass; 21 | ImGui_ImplMetal_NewFrame(rp->GetRenderPassDescriptor()); 22 | } 23 | 24 | void RenderDrawData(ImDrawData* draw_data, LLGI::CommandList* commandList) { 25 | auto cl = static_cast(commandList); 26 | ImGui_ImplMetal_RenderDrawData( 27 | ImGui::GetDrawData(), cl->GetCommandBuffer(), cl->GetRenderCommandEncorder()); 28 | } 29 | }; 30 | 31 | ImguiPlatformMetal::ImguiPlatformMetal(LLGI::Graphics* g) { 32 | impl = new ImguiPlatformMetal_Impl(g); 33 | } 34 | 35 | ImguiPlatformMetal::~ImguiPlatformMetal() { 36 | delete impl; 37 | } 38 | 39 | void ImguiPlatformMetal::NewFrame(LLGI::RenderPass* renderPass) { 40 | textures_.clear(); 41 | impl->NewFrame(renderPass); 42 | } 43 | 44 | void ImguiPlatformMetal::RenderDrawData(ImDrawData* draw_data, LLGI::CommandList* commandList) { 45 | impl->RenderDrawData(draw_data, commandList); 46 | } 47 | 48 | ImTextureID ImguiPlatformMetal::GetTextureIDToRender(LLGI::Texture* texture, LLGI::CommandList* commandList) { 49 | LLGI::SafeAddRef(texture); 50 | auto texturePtr = LLGI::CreateSharedPtr(texture); 51 | textures_.insert(texturePtr); 52 | 53 | auto t = static_cast(texture); 54 | return (__bridge void*)(t->GetTexture()); 55 | } 56 | 57 | void ImguiPlatformMetal::CreateFont() { 58 | ImGui_ImplMetal_CreateFontsTexture(impl->g_->GetDevice()); 59 | } 60 | 61 | void ImguiPlatformMetal::DisposeFont() { 62 | ImGui_ImplMetal_DestroyFontsTexture(); 63 | } 64 | -------------------------------------------------------------------------------- /core/src/Tool/Platform/ImGuiPlatformVulkan.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #ifdef _WIN32 5 | #define VK_PROTOTYPES 6 | #define VK_USE_PLATFORM_WIN32_KHR 7 | #else 8 | #define VK_PROTOTYPES 9 | #define VK_USE_PLATFORM_XCB_KHR 10 | #endif 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include "ImGuiPlatform.h" 22 | 23 | #if !USE_CBG 24 | 25 | class ImguiPlatformVulkan : public ImguiPlatform { 26 | private: 27 | struct TextureHolder { 28 | std::shared_ptr texture; 29 | int32_t life; 30 | ImTextureID id; 31 | }; 32 | 33 | LLGI::GraphicsVulkan* g_ = nullptr; 34 | LLGI::PlatformVulkan* p_ = nullptr; 35 | LLGI::RenderPassPipelineStateVulkan* ps_ = nullptr; 36 | 37 | VkDescriptorPool descriptorPool_ = VK_NULL_HANDLE; 38 | 39 | std::unordered_map textures_; 40 | 41 | public: 42 | ImguiPlatformVulkan(LLGI::Graphics* g, LLGI::Platform* p); 43 | 44 | virtual ~ImguiPlatformVulkan(); 45 | 46 | void NewFrame(LLGI::RenderPass* renderPass) override; 47 | 48 | void RenderDrawData(ImDrawData* draw_data, LLGI::CommandList* commandList) override { 49 | auto cl = static_cast(commandList); 50 | ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cl->GetCommandBuffer()); 51 | } 52 | 53 | ImTextureID GetTextureIDToRender(LLGI::Texture* texture, LLGI::CommandList* commandList) override; 54 | 55 | void CreateFont() override; 56 | 57 | void DisposeFont() override; 58 | }; 59 | 60 | #endif -------------------------------------------------------------------------------- /core/src/Window/Window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../BaseObject.h" 9 | #include "../Common/PlatformIncludes.h" 10 | #include "../Math/Vector2I.h" 11 | 12 | namespace Altseed2 { 13 | 14 | struct WindowInitializationParameter { 15 | std::u16string Title; 16 | int32_t WindowWidth = 0; 17 | int32_t WindowHeight = 0; 18 | bool IsFullscreenMode = false; 19 | bool IsResizable = false; 20 | }; 21 | 22 | class Window : public BaseObject { 23 | private: 24 | static std::shared_ptr instance_; 25 | 26 | GLFWwindow* mainWindow_; 27 | std::vector subWindows; 28 | 29 | std::u16string title_; 30 | 31 | std::mutex terminatingMtx_; 32 | 33 | public: 34 | Window(); 35 | ~Window() override; 36 | 37 | #if !USE_CBG 38 | static bool Initialize(const WindowInitializationParameter& parameter); 39 | 40 | static void Terminate(); 41 | 42 | void OnTerminating() override; 43 | #endif 44 | 45 | static std::shared_ptr& GetInstance(); 46 | 47 | void SetTitle(const char16_t* title); 48 | 49 | const char16_t* GetTitle() const; 50 | 51 | #if !USE_CBG 52 | void SetSize(int32_t width, int32_t height); 53 | 54 | void GetSize(int32_t& width, int32_t& height) const; 55 | 56 | #endif 57 | void SetSize(Vector2I_C value); 58 | 59 | Vector2I GetSize() const; 60 | 61 | bool DoEvent(); 62 | 63 | #if !USE_CBG 64 | GLFWwindow* GetNativeWindow() const; 65 | 66 | void GetMonitorSize(int32_t& width, int32_t& height); 67 | 68 | #endif 69 | }; 70 | 71 | } // namespace Altseed2 -------------------------------------------------------------------------------- /core/test/BaseObject.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "TestHelper.h" 8 | 9 | TEST(BaseObject, Basic) { 10 | auto config = Altseed2TestConfig(Altseed2::CoreModules::None); 11 | EXPECT_TRUE(config != nullptr); 12 | 13 | EXPECT_TRUE(Altseed2::Core::Initialize(u"test", 640, 480, config)); 14 | auto defaultObjectCount = Altseed2::Core::GetInstance()->GetBaseObjectCount(); 15 | 16 | auto baseObject = new Altseed2::BaseObject(); 17 | EXPECT_EQ(Altseed2::Core::GetInstance()->GetBaseObjectCount(), defaultObjectCount + 1); 18 | 19 | int32_t coreRef = 0; 20 | 21 | EXPECT_EQ(baseObject->GetRef(), 1 + coreRef); 22 | baseObject->AddRef(); 23 | EXPECT_EQ(baseObject->GetRef(), 2 + coreRef); 24 | baseObject->Release(); 25 | EXPECT_EQ(baseObject->GetRef(), 1 + coreRef); 26 | baseObject->Release(); 27 | 28 | // call gc 29 | Altseed2::Core::GetInstance()->DoEvent(); 30 | 31 | EXPECT_EQ(Altseed2::Core::GetInstance()->GetBaseObjectCount(), defaultObjectCount); 32 | 33 | Altseed2::Core::Terminate(); 34 | } 35 | 36 | TEST(BaseObject, Async) { 37 | auto config = Altseed2TestConfig(Altseed2::CoreModules::None); 38 | EXPECT_TRUE(config != nullptr); 39 | EXPECT_TRUE(Altseed2::Core::Initialize(u"test", 640, 480, config)); 40 | 41 | auto baseObject = new Altseed2::BaseObject(); 42 | 43 | std::thread thread1([baseObject]() -> void { 44 | for (int i = 0; i < 5000; i++) { 45 | baseObject->AddRef(); 46 | } 47 | }); 48 | 49 | std::thread thread2([baseObject]() -> void { 50 | for (int i = 0; i < 5000; i++) { 51 | baseObject->AddRef(); 52 | } 53 | }); 54 | 55 | thread1.join(); 56 | thread2.join(); 57 | 58 | int32_t coreRef = 0; 59 | 60 | EXPECT_EQ(baseObject->GetRef(), 10001 + coreRef); 61 | 62 | for (int i = 0; i < 10001; i++) { 63 | baseObject->Release(); 64 | } 65 | 66 | // call gc 67 | Altseed2::Core::GetInstance()->DoEvent(); 68 | 69 | Altseed2::Core::Terminate(); 70 | } 71 | 72 | TEST(BaseObject, DisposeInOtherThreadAfterTerminate) { 73 | auto config = Altseed2TestConfig(Altseed2::CoreModules::None); 74 | EXPECT_TRUE(config != nullptr); 75 | EXPECT_TRUE(Altseed2::Core::Initialize(u"test", 640, 480, config)); 76 | 77 | auto baseObject = new Altseed2::BaseObject(); 78 | 79 | Altseed2::Core::Terminate(); 80 | 81 | std::thread thread1([baseObject]() -> void { baseObject->Release(); }); 82 | 83 | thread1.join(); 84 | } 85 | -------------------------------------------------------------------------------- /core/test/Core.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "TestHelper.h" 5 | 6 | TEST(Core, Initialize) { 7 | auto coreModules = Altseed2::CoreModules::Window | Altseed2::CoreModules::File | Altseed2::CoreModules::Keyboard | Altseed2::CoreModules::Mouse | Altseed2::CoreModules::Joystick | Altseed2::CoreModules::Joystick | Altseed2::CoreModules::Graphics; 8 | auto config = Altseed2TestConfig(coreModules); 9 | EXPECT_TRUE(config != nullptr); 10 | 11 | EXPECT_TRUE(Altseed2::Core::Initialize(u"test", 640, 480, config)); 12 | Altseed2::Core::Terminate(); 13 | } 14 | -------------------------------------------------------------------------------- /core/test/FileSystem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | TEST(FileSystem, Directory) { 5 | if (!Altseed2::FileSystem::GetIsDirectory(u"FileSystemTestDirectory")) { 6 | EXPECT_TRUE(Altseed2::FileSystem::CreateDirectory(u"FileSystemTestDirectory")); 7 | } 8 | 9 | if (!Altseed2::FileSystem::GetIsDirectory(u"TestData/FileSystemTestDirectory")) { 10 | EXPECT_TRUE(Altseed2::FileSystem::CreateDirectory(u"TestData/FileSystemTestDirectory")); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /core/test/Keyboard.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "TestHelper.h" 8 | 9 | #define STR(var) #var 10 | 11 | using namespace std::string_literals; 12 | 13 | /* 14 | TEST(Keyboard, Initialize) { 15 | char16_t s16[] = u"test"; 16 | 17 | EXPECT_TRUE(Altseed2::Core::Initialize(s16, 640, 480, Altseed2::Configuration::Create())); 18 | 19 | int i = 0; 20 | 21 | while (i < (int)Altseed2::Key::MAX) { 22 | Altseed2::Keyboard::GetInstance()->RefleshKeyStates(); 23 | 24 | Altseed2::ButtonState state = Altseed2::Keyboard::GetInstance()->GetKeyState(static_cast(i)); 25 | EXPECT_EQ(Altseed2::ButtonState::Free, state); 26 | 27 | i++; 28 | } 29 | 30 | Altseed2::Core::Terminate(); 31 | } 32 | */ 33 | 34 | TEST(Keyboard, GetKeyState) { 35 | auto config = Altseed2TestConfig(Altseed2::CoreModules::Keyboard); 36 | EXPECT_TRUE(config != nullptr); 37 | 38 | EXPECT_TRUE(Altseed2::Core::Initialize(u"Keyboard", 640, 480, config)); 39 | 40 | for (int count = 0; Altseed2::Core::GetInstance()->DoEvent() && count < 60; count++) { 41 | for (int i = 0; i < static_cast(Altseed2::Key::MAX); i++) { 42 | auto bs = Altseed2::Keyboard::GetInstance()->GetKeyState((Altseed2::Key)i); 43 | if (bs != Altseed2::ButtonState::Free) std::cout << i; 44 | } 45 | std::cout << std::endl; 46 | } 47 | 48 | Altseed2::Core::Terminate(); 49 | } 50 | -------------------------------------------------------------------------------- /core/test/Movie.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #include "TestHelper.h" 13 | 14 | TEST(Movie, Basic) { 15 | auto config = Altseed2TestConfig(Altseed2::CoreModules::Graphics); 16 | EXPECT_TRUE(config != nullptr); 17 | 18 | EXPECT_TRUE(Altseed2::Core::Initialize(u"Movie.Basic", 1280, 720, config)); 19 | 20 | int count = 0; 21 | 22 | auto instance = Altseed2::Graphics::GetInstance(); 23 | 24 | auto t1 = Altseed2::RenderTexture::Create({640, 480}); 25 | 26 | auto movie = Altseed2::MediaPlayer::Load(u"TestData/Movie/Test1.mp4"); 27 | 28 | ASSERT_TRUE(t1 != nullptr); 29 | ASSERT_TRUE(movie != nullptr); 30 | 31 | auto s1 = Altseed2::RenderedSprite::Create(); 32 | 33 | Altseed2::CullingSystem::GetInstance()->Register(s1); 34 | s1->SetTexture(t1); 35 | s1->SetSrc(Altseed2::RectF(0, 0, 640, 480)); 36 | movie->Play(false); 37 | 38 | while (count++ < 50 && instance->DoEvents() && Altseed2::Core::GetInstance()->DoEvent()) { 39 | movie->WriteToRenderTexture(t1); 40 | 41 | Altseed2::CullingSystem::GetInstance()->UpdateAABB(); 42 | Altseed2::CullingSystem::GetInstance()->Cull(Altseed2::RectF(Altseed2::Vector2F(), Altseed2::Window::GetInstance()->GetSize().To2F())); 43 | 44 | Altseed2::RenderPassParameter renderPassParameter; 45 | renderPassParameter.ClearColor = Altseed2::Color(50, 50, 50, 255); 46 | renderPassParameter.IsColorCleared = true; 47 | renderPassParameter.IsDepthCleared = true; 48 | EXPECT_TRUE(instance->BeginFrame(renderPassParameter)); 49 | 50 | Altseed2::Renderer::GetInstance()->DrawSprite(s1); 51 | 52 | Altseed2::Renderer::GetInstance()->Render(); 53 | 54 | EXPECT_TRUE(instance->EndFrame()); 55 | 56 | // Take a screenshot 57 | if (count == 49) { 58 | Altseed2::Graphics::GetInstance()->SaveScreenshot(u"Movie.Basic.png"); 59 | } 60 | } 61 | 62 | Altseed2::CullingSystem::GetInstance()->Unregister(s1); 63 | Altseed2::Core::Terminate(); 64 | } 65 | -------------------------------------------------------------------------------- /core/test/Profiler.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | #define _U(x) Altseed2::utf8_to_utf16(x).c_str() 8 | 9 | TEST(Profiler, Basic) { 10 | Altseed2::Profiler::Initialize(); 11 | 12 | Altseed2::Profiler::GetInstance()->StartCapture(); 13 | 14 | Altseed2::Profiler::GetInstance()->BeginBlock(u"Basic1", _U(__FILE__), __LINE__, Altseed2::Color(255, 0, 0, 255)); 15 | 16 | std::this_thread::sleep_for(std::chrono::milliseconds(500)); 17 | 18 | Altseed2::Profiler::GetInstance()->BeginBlock(u"Basic2", _U(__FILE__), __LINE__, Altseed2::Color(0, 0, 255, 255)); 19 | 20 | std::this_thread::sleep_for(std::chrono::milliseconds(500)); 21 | 22 | Altseed2::Profiler::GetInstance()->EndBlock(); 23 | 24 | std::this_thread::sleep_for(std::chrono::milliseconds(500)); 25 | 26 | Altseed2::Profiler::GetInstance()->EndBlock(); 27 | 28 | Altseed2::Profiler::GetInstance()->DumpToFileAndStopCapture(u"Profiler.prof"); 29 | 30 | Altseed2::Profiler::Terminate(); 31 | } 32 | -------------------------------------------------------------------------------- /core/test/TestHelper.cpp: -------------------------------------------------------------------------------- 1 | #include "TestHelper.h" 2 | 3 | std::shared_ptr Altseed2TestConfig(Altseed2::CoreModules coreModules) { 4 | auto config = Altseed2::Configuration::Create(); 5 | if (config == nullptr) return nullptr; 6 | config->SetConsoleLoggingEnabled(true); 7 | config->SetEnabledCoreModules(coreModules); 8 | return config; 9 | } 10 | -------------------------------------------------------------------------------- /core/test/TestHelper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | std::shared_ptr Altseed2TestConfig(Altseed2::CoreModules coreModules); 5 | -------------------------------------------------------------------------------- /core/test/Window.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "TestHelper.h" 8 | 9 | TEST(Window, Base) { 10 | auto config = Altseed2TestConfig(Altseed2::CoreModules::Window); 11 | EXPECT_TRUE(Altseed2::Core::Initialize(u"test", 150, 150, config)); 12 | 13 | int i = 0; 14 | while (Altseed2::Window::GetInstance()->DoEvent() && i < 16) { 15 | Altseed2::Window::GetInstance()->SetSize(150 + i / 2, 150 + i / 3); 16 | 17 | for (int l = 0; l < 10; l++) Altseed2::Window::GetInstance()->DoEvent(); 18 | 19 | int32_t w, h; 20 | Altseed2::Window::GetInstance()->GetSize(w, h); 21 | 22 | #ifdef __linux__ 23 | ASSERT_NEAR(w, 150 + i / 2, 2); 24 | ASSERT_NEAR(h, 150 + i / 3, 2); 25 | #else 26 | EXPECT_EQ(w, 150 + i / 2); 27 | EXPECT_EQ(h, 150 + i / 3); 28 | #endif 29 | 30 | std::u16string title = u"Test"; 31 | Altseed2::Window::GetInstance()->SetTitle(title.c_str()); 32 | Altseed2::Window::GetInstance()->DoEvent(); 33 | 34 | EXPECT_EQ(std::u16string(Altseed2::Window::GetInstance()->GetTitle()), title); 35 | 36 | i++; 37 | } 38 | 39 | Altseed2::Core::Terminate(); 40 | } 41 | -------------------------------------------------------------------------------- /core/test/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if _WIN32 4 | 5 | #define _CRTDBG_MAP_ALLOC 6 | #include 7 | #include 8 | 9 | #endif 10 | 11 | int main(int argc, char** argv) { 12 | #if _WIN32 13 | _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); 14 | #endif 15 | 16 | ::testing::InitGoogleTest(&argc, argv); 17 | return RUN_ALL_TESTS(); 18 | } -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.1' 2 | 3 | services: 4 | altseed2: 5 | build: . 6 | command: ./scripts/docker-entrypoint.sh 7 | volumes: 8 | - .:/home/src 9 | ports: 10 | - 3000:3000 -------------------------------------------------------------------------------- /documents/development/CoreCodingRule_Ja.md: -------------------------------------------------------------------------------- 1 | # Core の記述について 2 | 3 | ## **自動整形・ビルド通してからコミットしましょう** 4 | * Clang-Format による自動整形が効くプロジェクトファイルを生成できるのでそちらを使用し、必ずビルドして整形してからコミットするようにしましょう。 5 | * 差分に無意味な変更が混ざってしまうので後で見づらくなります。 6 | 7 | ## クラス 8 | * 基本すべてのクラスは BaseObject を継承する。 9 | * 生ポインタで管理せずshared_ptr を用いる。 10 | * 生成は std::make_shared ではなく AsdmakeShared を用いる。 11 | * ~~メソッドのオーバーロードは使わない~~ 12 | * ヘンな suffix のついた似たようなメソッドが生えるくらいならオーバーロードしたほうがシンプル 13 | * CBG は オーバーロード対応済み 14 | * 今後もしオーバーロード非対応な言語の Engine を作る場合は Binding Generator 側でヘンな suffix を付ける 15 | * そもそもCore側にある実装をすべてEngineを通してユーザに見せる必要はない 16 | 17 | 18 | ## 命名規則 19 | 20 | | 種類 | 規則 | 21 | | ---- | ---- | 22 | |クラス
public メソッド |UpperCamelCase| 23 | |public なプロパティ|UpperCamelCase
Get〜/Set〜(bool 型ならさらに Is〜など)| 24 | |private なフィールド|lowerCamelCase_ (末尾にアンダバー)| 25 | |ローカル変数|lowerCamelCase| 26 | -------------------------------------------------------------------------------- /documents/development/HowToBuild_Ja.md: -------------------------------------------------------------------------------- 1 | # ビルド手順 2 | 3 | ## 必須 4 | 5 | ### 共通 6 | 7 | - cmake(3.15以上) 8 | - git 9 | - python3.x 10 | 11 | ### Windows 12 | 13 | - VisualStudio(2019以降) 14 | 15 | ### Linux 16 | 17 | - gcc 18 | 19 | #### Ubuntu 20 | 21 | ``` 22 | libudev-dev 23 | libssl-dev # to save and load a package with a password 24 | ``` 25 | 26 | ## サブモジュール取得 27 | 28 | スクリプト `scripts/Pull.bat` を実行します。 29 | 30 | もしくは下記のコマンドを実行します。 31 | 32 | ``` 33 | git pull 34 | git submodule update --init 35 | 36 | cd thirdparty/LLGI 37 | git submodule update --init 38 | ``` 39 | 40 | ## プロジェクト生成 41 | 42 | スクリプトを実行します。 43 | 下記のスクリプトでは Clang-Format が有効になったプロジェクトを生成します。 44 | ビルド時にコードの自動整形が実行されるため、通常Altseed2 の開発を行う際はこちらを使用してください。 45 | 46 | - Windows の場合: `scripts/GenerateProjects_ClangFormat.bat` 47 | - macOS の場合: `scripts/GenerateProjects_ClangFormat_Mac.sh` 48 | - Linux の場合: `scripts/GenerateProjects_ClangFormat_Linux.sh` 49 | 50 | 開発を行わない、もしくは何らかの事情によりClang-Format による自動成型が有効でないプロジェクトを生成するには下記のスクリプトを実行します。 51 | 52 | - Windows の場合: `scripts/GenerateProjects.bat` 53 | - macOS の場合: `scripts/GenerateProjects_Mac.sh` 54 | - Linux の場合: `scripts/GenerateProjects_Linux.sh` 55 | 56 | ## Wrapper生成 57 | 58 | ### Dockerを使用する(推奨) 59 | 60 | `docker` と `docker-compose`をインストールしてください. 61 | 62 | 以下コマンドを実行します. 63 | ``` 64 | docker-compose build 65 | docker-compose up 66 | ``` 67 | 68 | ### Dockerを使用しない 69 | 70 | まず、ヘッダファイルからCBG定義を出力するために 下記のコマンドを実行します。 71 | 72 | ``` 73 | python scripts/generate_cbg_definition.py --clang "C:\Program Files\LLVM\bin" 74 | ``` 75 | 76 | また、実行するときには LLVMとpythonパッケージ `clang`で、LLVMのbinディレクトリを指定する必要があります。 77 | 78 | 次にスクリプト `python scripts/generate_wrapper.py` を実行します。 79 | 80 | ## ビルド 81 | 82 | ### Windows 83 | 84 | `build\Altseed_Core.sln` (もしくは `build_clang_format\Altseed_Core.sln`) を開き、ソリューションをビルドします。プロジェクト `Altseed_Core_Test` を実行し、テストが走ったら成功です。 85 | -------------------------------------------------------------------------------- /documents/development/HowToConvertVideo.md: -------------------------------------------------------------------------------- 1 | # Webサイトなどに貼り付ける動画の変換について 2 | 3 | ## 必要なもの 4 | 5 | - 適当なスクリーンキャプチャソフト 6 | - Windows 10 の場合はゲームバーのキャプチャ機能でおk 7 | - ffmpeg 8 | - 一部 OS ではコーデックの扱いがややこしそうなので Windows 用ビルド済みバイナリでやるの推奨 9 | - https://github.com/BtbN/FFmpeg-Builds/releases 10 | 11 | ## 撮影する 12 | 13 | - 適当ななスクリーンキャプチャソフトで撮影する 14 | - 後でクロップできるので、ウインドウ全体など広めに撮影しても問題なし 15 | 16 | ## ffmpeg で Web 用に変換する 17 | 18 | - Web 用なのでなるべく軽くしたい 19 | - 画質設定よりもフレームレート、解像度、時間で対応 20 | - ビットレート不足が画が汚くなるので 21 | - 動画のファイルサイズは 100 KiB 程度にする 22 | - ブラウザによって再生できる動画コーデックが違うので複数種類用意する。 23 | - H.264 24 | - WebM 25 | - png (動画ではないがどちらも再生できなかった時のため。あとロード中はこれを表示できる) 26 | 27 | 28 | ## ffmpeg のパラメータ 29 | 30 | > ffmpeg -i {入力ファイル名} {クロップなどの設定} {加工の設定} -an {出力ファイル名} 31 | 32 | `-an` は音声を削除する指定 33 | 34 | ### 加工の設定 35 | 36 | 省略可能 37 | 38 | #### クロップ 39 | 40 | > -vf crop={出力動画の幅}:{出力動画の高さ}:{左上のX座標}:{左上のY座標} 41 | 42 | 43 | #### フレームレート 44 | 45 | 25 くらいでおk 46 | 47 | > -r {フレームレート} 48 | 49 | #### 時間切り出しの設定はいろいろ出来るのでリンク参照 50 | 51 | https://nico-lab.net/cutting_ffmpeg/ 52 | 53 | 54 | ### コーデックの設定 55 | 56 | 画質は整数値で指定(小さいほどキレイ)。デフォルトは23。 57 | 58 | #### H.264 で出力 59 | 60 | > -c:v libx264 -crf {画質} -preset veryslow -movflags +faststart 61 | 62 | #### WebM で出力 63 | 64 | > -c:v libvpx-vp9 -crf {画質} -preset veryslow -movflags +faststart 65 | 66 | #### PNG で出力 67 | 68 | 連番画像が全部出てくるので出力ファイル名は `Hoge%d.png` などフォーマット指定子を入れる。 69 | 好きなフレームの画像を採用 70 | 71 | > -c:v png 72 | 73 | 74 | ## 要するに 75 | 76 | > ffmpeg -i captured.mp4 -vf crop=640:480:100:200 -r 25 -c:v libx264 -crf 20 -preset veryslow -movflags +faststart -an converted.mp4 77 | 78 | > ffmpeg -i captured.mp4 -vf crop=640:480:100:200 -r 25 -c:v libvpx-vp9 -crf 20 -preset veryslow -movflags +faststart -an converted.webm 79 | 80 | > ffmpeg -i captured.mp4 -vf crop=640:480:100:200 -r 25 -c:v png converted_%03d.png 81 | 82 | などする。 83 | ビットレートやフレームレート切り出し位置・時間は微調整がんばる。 -------------------------------------------------------------------------------- /documents/development/HowToDevelop_Ja.md: -------------------------------------------------------------------------------- 1 |  2 | # 開発方法について 3 | 4 | ## ビルド方法とツールについて 5 | 6 | [HowToBuild](HowToBuild_Ja.md) 7 | 8 | ## 開発手順 9 | 10 | ### C++のソースコードの追加 11 | 12 | [CoreCodingRule](CoreCodingRule_Ja.md) 13 | 14 | 新しいファイルを追加した場合は `core/src/CMakeFile.txt` もしくは `core/test/CMakeFile.txt` にファイル名を追記する。 15 | 16 | ### バインディングの設定の記述 17 | 18 | * `scripts\bindings` 以下の `py` ファイルに記述します。 19 | 20 | 1. `input.py` や `io.py` など機能ごとのファイル(場合によってはファイルを追加)に各クラスの情報(どのようなプロパティがあるか、基底クラスはなにか、静的クラスかなど)やメソッドの情報(戻り値は何型か、引数は何型かなど)を記述します。 21 | 22 | 2. `define.py` 内に上で追加したクラスや列挙体などの append を追加します。 23 | 24 | 詳細は [CBG の HowToUse](https://github.com/altseed/CppBindingGenerator/blob/master/docs/HowToUse.md) 25 | 26 | 3. `scripts/generate_wrapper.py`を実行し、再度コアをビルドします。この時エラーが出ず正常にビルドできることを確認します。 27 | 28 | #### 自動生成ファイルについて 29 | 30 | これらの設定はC++のファイルとJsonファイルから自動生成することもできます。 31 | 32 | clangのpythonバインディングをインストールします。 33 | 34 | ``` 35 | pip install clang 36 | ``` 37 | 38 | Windowsの場合、Clangをインストールします。Macの場合、XCodeをインストールします。 39 | 40 | [clang(LLVM)](https://releases.llvm.org/download.html) 41 | 42 | そして、下記のコマンドで生成します。 43 | 44 | Windowsの場合、 45 | 46 | ``` 47 | cd scripts 48 | python generate_cbg_definition.py --clang (libclang.dllが存在するディレクトリ) 49 | ``` 50 | 51 | ただしLLVMをデフォルトのディレクトリにインストールした場合は引数は必要ありません。 52 | 53 | Macの場合、 54 | 55 | ``` 56 | cd scripts 57 | python generate_cbg_definition.py --xcode (xcodeが存在するディレクトリ) 58 | ``` 59 | 60 | ただしxcodeをApplication/にインストールした場合は引数は必要ありません。 61 | 62 | 新しくC++のファイルの増やした場合は、``` generate_cbg_definition.py ``` を編集する必要があります。 63 | 64 | ### ドキュメント 65 | 66 | TODO: Core 部分に関する開発者向けの仕様解説ドキュメントを用意 67 | 68 | ### サンプル 69 | 70 | 71 | ## PRについて 72 | 73 | コメントが1行の場合、先頭は大文字の命令形の英語が好ましいです。 74 | 理由は、Linusがそう推奨したからです。 75 | 76 | ~~慣れている人は、git の rebase を使用しましょう。~~ 77 | 無意味なコミットが大量に生成されるのを抑制する場合を除いて、 merge するようにします。どのような変更をしたか、どのように変更を打ち消したかをすべて記録し、それぞれの状態に戻せるようにしておくことがバージョン管理です。とくに誤って作成してしまった変更をもみ消す(パスワードなど秘匿すべき情報を混入させてしまったなどの場合は除く)目的での merge は厳禁。 78 | 79 | ## コメントについて 80 | 81 | * ~~英語が望ましいです。苦手な人はGoogle翻訳を使用しても問題ありません。~~ 82 | コメントは日本語でおk。(今後必要そうなら Google 翻訳なりを使って英語コメントを追加挿入するようなスクリプトを使う)。 ただしちゃんと UTF-8 で保存すること。 83 | 84 | * もしくは、コメントが必要がないほど綺麗なコードを書きましょう。 85 | 86 | -------------------------------------------------------------------------------- /documents/development/LibraryAndTools_Ja.md: -------------------------------------------------------------------------------- 1 | 2 | # ツール 3 | 4 | ## clang-format 5 | 6 | C++のソースコード自動整形ツールです。 7 | 指定したフォーマットに沿ってC++のソースコードを整形してくれます。 8 | .clang-formatに設定ファイルを記述します。 9 | ターミナルから使用しますが、VisualStudio では `Ctrl+K, Ctrl+D` で自動的に整形してくれます。 10 | 11 | ## cmake 12 | 13 | C++/C# のプロジェクトを生成するツールです。 14 | CMakeLists.txt の設定をもとにVisualStudio、XCode のプロジェクトや makefile 等を生成します。 15 | バージョンアップするごとに近代化が進んでいるので、可能な限り最新版の機能を使いましょう。 16 | 17 | ディレクトリ名に記号等が含まれている失敗することがあります。わかりやすいディレクトリに配置しましょう。 18 | 19 | VisualStudio、VSCode等には専用のサポートツールが存在します。それらを使用すると便利になります。 20 | 21 | # ライブラリ(開発者向け) 22 | 23 | ## GoogleTest 24 | 25 | C++用の単体テストライブラリです。 26 | 27 | ``` 28 | --gtest_filter=Foo.* 29 | ``` 30 | 31 | といった引数により、起動するテストを選択できますが、VisualStudio、VSCode等には専用のサポートツールが存在します。 32 | 33 | VisualStudio では `テストエクスプローラー` を使用することで特定のテストのみを実行したり、各テストの合否やエラー箇所を確認したりすることができます。 -------------------------------------------------------------------------------- /documents/development/MeetingFlow_Ja.md: -------------------------------------------------------------------------------- 1 | 2 | # ミーティングの流れ 3 | 4 | ## 先週の進捗報告 5 | 6 | 1. 各自の先週の進捗を報告します。 7 | 8 | 2. 各自の進捗を生むうえで発生した問題点・疑問点について話し合い解決を図ります。 9 | 10 | 3. Issueの整理(完了しているものをCloseしたりアサインの調整をする) 11 | 12 | [About label](https://github.com/altseed/Altseed2/blob/master/documents/development/HowToDevelop_Ja.md) 13 | 14 | [Issue](https://github.com/altseed/Altseed2/issues) 15 | -------------------------------------------------------------------------------- /scripts/GenerateProjects.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | mkdir ..\build 5 | 6 | cd /d ..\build 7 | 8 | cmake -A x64 -D BUILD_TEST=ON ../ 9 | 10 | pause -------------------------------------------------------------------------------- /scripts/GenerateProjects_ClangFormat.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | mkdir ..\build_clang_format 5 | 6 | cd /d ..\build_clang_format 7 | 8 | cmake -D BUILD_TEST=ON -D CLANG_FORMAT_ENABLED=ON ../ 9 | -------------------------------------------------------------------------------- /scripts/GenerateProjects_ClangFormat_Linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo set current directory 4 | cd `dirname $0` 5 | 6 | mkdir ../build_clang_format 7 | 8 | cd ../build_clang_format 9 | 10 | cmake -D BUILD_TEST=ON -D CLANG_FORMAT_ENABLED=ON ../ 11 | -------------------------------------------------------------------------------- /scripts/GenerateProjects_ClangFormat_Mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo set current directory 4 | cd `dirname $0` 5 | 6 | mkdir ../build_clang_format 7 | 8 | cd ../build_clang_format 9 | 10 | cmake -D BUILD_TEST=ON -D CLANG_FORMAT_ENABLED=ON ../ -G "Xcode" 11 | -------------------------------------------------------------------------------- /scripts/GenerateProjects_ClangTidy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo set current directory 4 | cd `dirname $0` 5 | 6 | mkdir ../build_clang_tidy 7 | 8 | cd ../build_clang_tidy 9 | 10 | cmake -D BUILD_TEST=ON -D CLANG_TIDY_ENABLED=ON ../ 11 | -------------------------------------------------------------------------------- /scripts/GenerateProjects_Linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo set current directory 4 | cd `dirname $0` 5 | 6 | mkdir ../build 7 | 8 | cd ../build 9 | 10 | cmake -D BUILD_TEST=ON ../ -------------------------------------------------------------------------------- /scripts/GenerateProjects_Mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo set current directory 4 | cd `dirname $0` 5 | 6 | mkdir ../build 7 | 8 | cd ../build 9 | 10 | cmake -D BUILD_TEST=ON ../ -G "Xcode" -T buildsystem=1 11 | -------------------------------------------------------------------------------- /scripts/GenerateProjects_Sanitizer_MSVC.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | mkdir ..\build_sanitizer 5 | 6 | cd /d ..\build_sanitizer 7 | 8 | cmake -A Win32 -D BUILD_TEST=ON -D MSVC_SANITIZE_ENABLED=ON ../ 9 | 10 | cd /d %~dp0 11 | 12 | python GenerateProjects_Sanitizer_MSVC.py 13 | 14 | pause -------------------------------------------------------------------------------- /scripts/GenerateProjects_Sanitizer_MSVC.py: -------------------------------------------------------------------------------- 1 | import glob 2 | 3 | projs = glob.glob('../build_sanitizer/**/*.vcxproj', recursive=True) 4 | 5 | for p in projs: 6 | f = open(p, 'r', encoding="utf_8_sig") 7 | proj_str = f.read() 8 | 9 | proj_str = proj_str.replace('v142','v142true') 10 | 11 | f = open(p, 'w', encoding="utf_8_sig") 12 | f.write(proj_str) 13 | -------------------------------------------------------------------------------- /scripts/Pull.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | cd .. 5 | git pull 6 | git submodule update --init 7 | 8 | cd thirdparty\LLGI 9 | git submodule update --init 10 | 11 | pause -------------------------------------------------------------------------------- /scripts/UpdateCBG.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | cd .. 5 | git pull 6 | git submodule update --init 7 | git submodule update --init --remote -- "scripts/bindings/CppBindingGenerator" 8 | 9 | cd scripts/bindings/CppBindingGenerator 10 | git submodule update --init 11 | pause -------------------------------------------------------------------------------- /scripts/UpdateLLGI.bat: -------------------------------------------------------------------------------- 1 | echo set current directory 2 | cd /d %~dp0 3 | 4 | cd .. 5 | git pull 6 | git submodule update --init 7 | git submodule update --init --remote -- "thirdparty/LLGI" 8 | 9 | cd thirdparty/LLGI 10 | git submodule update --init 11 | pause -------------------------------------------------------------------------------- /scripts/UpdateSubmodules.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo set current directory 4 | cd `dirname $0` 5 | 6 | git submodule update --init bindings/CppBindingGenerator 7 | 8 | git submodule update --init ../TestData 9 | git submodule update --init ../thirdparty/SPIRV-Cross 10 | git submodule update --init ../thirdparty/glfw 11 | git submodule update --init ../thirdparty/glslang 12 | git submodule update --init ../thirdparty/googletest 13 | git submodule update --init ../thirdparty/libpng 14 | git submodule update --init ../thirdparty/libzip 15 | git submodule update --init ../thirdparty/spdlog 16 | git submodule update --init ../thirdparty/zlib 17 | 18 | echo finished 19 | -------------------------------------------------------------------------------- /scripts/bindings/__init__.py: -------------------------------------------------------------------------------- 1 | from .define import define -------------------------------------------------------------------------------- /scripts/bindings/common.json: -------------------------------------------------------------------------------- 1 | { 2 | "enums": { 3 | 4 | }, 5 | "classes": { 6 | "Resources": { 7 | "is_public": false, 8 | "is_Sealed": true, 9 | "properties": { 10 | }, 11 | "methods": { 12 | "GetInstance": { 13 | "is_public": false, 14 | "is_static": true 15 | }, 16 | "GetResourcesCount": { 17 | "is_public": false 18 | }, 19 | "Clear": { 20 | "is_public": false 21 | }, 22 | "Reload": { 23 | "is_public": false 24 | } 25 | } 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /scripts/bindings/define.py: -------------------------------------------------------------------------------- 1 | from . import CppBindingGenerator as cbg 2 | import ctypes 3 | import sys 4 | 5 | from .graphics import * 6 | from .sound import * 7 | from .math import * 8 | from .logger import * 9 | 10 | # サポートされない型 11 | # u16string は const char16_t* として扱われることになる 12 | # int64_t, int8_t などは int32_t として扱われることになる 13 | # int8_t*, vector に対しては仮に Bytes クラスとおいている 14 | # void* に対しては仮に VoidPtr クラスとおいている 15 | # double; Mouse; floatとして扱われる 16 | # double& 引数; Mouse 17 | # std::function; Mouse 18 | # フィールドはサポートされない; Graphics 19 | # std::vector>; Graphics 20 | # LLGI::DeviceType; Graphics 21 | # std::array; Sprite 22 | # LLGI::Vec2F; Sprite 23 | # std::tuple; Texture2D 24 | # shared_ptrを使わずポインタで直接インスタンスを受け渡している場所 25 | 26 | # define 27 | define = cbg.Define() 28 | 29 | # math 30 | define.structs.append(Vector2I) 31 | define.structs.append(Vector2F) 32 | define.structs.append(Vector3I) 33 | define.structs.append(Vector3F) 34 | define.structs.append(Vector4I) 35 | define.structs.append(Vector4F) 36 | define.structs.append(RectI) 37 | define.structs.append(RectF) 38 | define.structs.append(Matrix44I) 39 | define.structs.append(Matrix44F) 40 | 41 | # common 42 | define.classes.append(Int8Array) 43 | define.classes.append(Int32Array) 44 | define.classes.append(VertexArray) 45 | define.classes.append(FloatArray) 46 | define.classes.append(Vector2FArray) 47 | 48 | # graphics 49 | 50 | define.structs.append(AlphaBlend) 51 | define.structs.append(BatchVertex) 52 | define.structs.append(Color) 53 | 54 | define.structs.append(RenderPassParameter) 55 | 56 | # sound 57 | define.enums.append(FFTWindow) 58 | 59 | # Logger 60 | define.enums.append(LogLevel) 61 | define.enums.append(LogCategory) 62 | define.classes.append(Log) 63 | -------------------------------------------------------------------------------- /scripts/bindings/desc_media.json: -------------------------------------------------------------------------------- 1 | { 2 | "ja": { 3 | "MediaPlayer": { 4 | "@brief": "映像を再生するクラス", 5 | "Play": { 6 | "@brief": "映像を再生します。", 7 | "isLoopingMode": { 8 | "@brief": "ループ再生するか?" 9 | } 10 | }, 11 | "WriteToRenderTexture": { 12 | "@brief": "現在の映像のフレームをテクスチャに書き込みます。映像とテクスチャは同じサイズである必要があります。", 13 | "target": { 14 | "@brief": "テクスチャ" 15 | } 16 | }, 17 | "Load": { 18 | "@brief": "映像を読み込みます。", 19 | "path": { 20 | "@brief": "パス(パッケージ内の映像は読み込めません。)" 21 | } 22 | }, 23 | "Size": { 24 | "@brief": "映像の大きさを取得します。" 25 | }, 26 | "CurrentFrame": { 27 | "@brief": "映像の現在のフレーム番号を取得します。" 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /scripts/bindings/desc_profiler.json: -------------------------------------------------------------------------------- 1 | { 2 | "ja": { 3 | "Profiler": { 4 | "@brief": "プロファイラのクラス", 5 | "GetInstance": { 6 | "@brief": "インスタンスを取得します。" 7 | }, 8 | "BeginBlock": { 9 | "@brief": "測定するブロックを開始します。", 10 | "name": { 11 | "@brief": "ブロックの名称" 12 | }, 13 | "_filename": { 14 | "@brief": "ブロックが位置するファイル名" 15 | }, 16 | "_line": { 17 | "@brief": "ブロックが位置する行数" 18 | }, 19 | "color": { 20 | "@brief": "ブロックの色" 21 | } 22 | }, 23 | "EndBlock": { 24 | "@brief": "測定するブロックを終了します。" 25 | }, 26 | "StartCapture": { 27 | "@brief": "測定を開始します。" 28 | }, 29 | "StopCapture": { 30 | "@brief": "測定を終了します。" 31 | }, 32 | "StartListen": { 33 | "@brief": "リモートから状態を監視します。", 34 | "port": { 35 | "@brief": "通信に使用するポート" 36 | } 37 | }, 38 | "DumpToFileAndStopCapture": { 39 | "@brief": "測定を終了し、結果を出力します。", 40 | "path": { 41 | "@brief": "出力先" 42 | } 43 | } 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /scripts/bindings/graphics.py: -------------------------------------------------------------------------------- 1 | from . import CppBindingGenerator as cbg 2 | import ctypes 3 | 4 | from .common import * 5 | from .math import * 6 | 7 | AlphaBlend = cbg.Struct('Altseed2', 'AlphaBlend_C', 'AlphaBlend') 8 | 9 | RenderPassParameter = cbg.Struct( 10 | 'Altseed2', 'RenderPassParameter_C', 'RenderPassParameter') 11 | -------------------------------------------------------------------------------- /scripts/bindings/logger.json: -------------------------------------------------------------------------------- 1 | { 2 | "enums": { 3 | }, 4 | "classes": { 5 | } 6 | } -------------------------------------------------------------------------------- /scripts/bindings/math.py: -------------------------------------------------------------------------------- 1 | from . import CppBindingGenerator as cbg 2 | import ctypes 3 | import sys 4 | 5 | # from .common import * 6 | 7 | Vector2I = cbg.Struct('Altseed2', 'Vector2I_C', 'Vector2I') 8 | Vector2F = cbg.Struct('Altseed2', 'Vector2F_C', 'Vector2F') 9 | Vector3I = cbg.Struct('Altseed2', 'Vector3I_C', 'Vector3I') 10 | Vector3F = cbg.Struct('Altseed2', 'Vector3F_C', 'Vector3F') 11 | Vector4I = cbg.Struct('Altseed2', 'Vector4I_C', 'Vector4I') 12 | Vector4F = cbg.Struct('Altseed2', 'Vector4F_C', 'Vector4F') 13 | RectI = cbg.Struct('Altseed2', 'RectI_C', 'RectI') 14 | RectF = cbg.Struct('Altseed2', 'RectF_C', 'RectF') 15 | Matrix44I = cbg.Struct('Altseed2', 'Matrix44I_C', 'Matrix44I') 16 | Matrix44F = cbg.Struct('Altseed2', 'Matrix44F_C', 'Matrix44F') 17 | BatchVertex = cbg.Struct('Altseed2', 'BatchVertex', 'Vertex') 18 | Color = cbg.Struct('Altseed2', 'Color_C', 'Color') -------------------------------------------------------------------------------- /scripts/bindings/profiler.json: -------------------------------------------------------------------------------- 1 | { 2 | "enums": {}, 3 | "classes": { 4 | "Profiler": { 5 | "is_Sealed": true, 6 | "properties": {}, 7 | "methods": { 8 | "GetInstance": { 9 | "is_public": false, 10 | "is_static": true 11 | } 12 | } 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /scripts/bindings/sound.json: -------------------------------------------------------------------------------- 1 | { 2 | "enums": { 3 | 4 | }, 5 | "classes": { 6 | "Sound": { 7 | "SerializeType": "Interface", 8 | "chace_mode": "ThreadSafeCache", 9 | "is_Sealed": true, 10 | "properties": { 11 | "LoopStartingPoint": { 12 | "serialized": true 13 | }, 14 | "LoopEndPoint": { 15 | "serialized": true 16 | }, 17 | "IsLoopingMode": { 18 | "serialized": true 19 | }, 20 | "Path": { 21 | "is_public": false, 22 | "serialized": true, 23 | "null_deserialized": false 24 | }, 25 | "IsDecompressed": { 26 | "is_public": true, 27 | "serialized": true 28 | } 29 | }, 30 | "methods": { 31 | "Load": { 32 | "is_static": true, 33 | "params": { 34 | "path": { 35 | "nullable": false 36 | } 37 | } 38 | } 39 | } 40 | }, 41 | "SoundMixer": { 42 | "is_Sealed": true, 43 | "properties": { 44 | }, 45 | "methods": { 46 | "GetInstance": { 47 | "is_public": false, 48 | "is_static": true 49 | }, 50 | "Play": { 51 | "params": { 52 | "sound": { 53 | "nullable": false 54 | } 55 | } 56 | }, 57 | "GetSpectrum": { 58 | "is_public": false, 59 | "params": { 60 | "window": { 61 | "type": "FFTWindow" 62 | } 63 | } 64 | } 65 | } 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /scripts/bindings/sound.py: -------------------------------------------------------------------------------- 1 | from . import CppBindingGenerator as cbg 2 | import ctypes 3 | 4 | from .common import * 5 | 6 | FFTWindow = cbg.Enum('Altseed2', 'FFTWindow') 7 | with FFTWindow as enum: 8 | enum.brief = cbg.Description() 9 | enum.brief.add('ja', '音のスペクトル解析に使用する窓関数') 10 | enum.add('Rectangular') 11 | enum.add('Triangle') 12 | enum.add('Hamming') 13 | enum.add('Hanning') 14 | enum.add('Blackman') 15 | enum.add('BlackmanHarris') 16 | -------------------------------------------------------------------------------- /scripts/bindings/window.json: -------------------------------------------------------------------------------- 1 | { 2 | "enums": { 3 | 4 | }, 5 | "classes": { 6 | "Window": { 7 | "is_public": false, 8 | "is_Sealed": true, 9 | "properties": { 10 | "Title": { 11 | "is_public": false, 12 | "nullable": false 13 | }, 14 | "Size": { 15 | "is_public": false 16 | } 17 | }, 18 | "methods": { 19 | "GetInstance": { 20 | "is_public": false, 21 | "is_static": true 22 | } 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /scripts/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo set current directory 4 | cd `dirname $0` 5 | 6 | python3 generate_tool.py --clang-file /usr/lib/llvm-11/lib/libclang-11.so.1 7 | echo done python3 generate_tool.py 8 | 9 | python3 generate_cbg_definition.py --clang-file /usr/lib/llvm-11/lib/libclang-11.so.1 10 | echo done python3 generate_cbg_definition.py 11 | 12 | python3 generate_wrapper.py 13 | echo done python3 generate_wrapper.py 14 | 15 | cd ../.ci/ 16 | 17 | python3 check_format.py 18 | echo done python3 check_format.py 19 | -------------------------------------------------------------------------------- /scripts/encode_to_utf8sig.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | 4 | import glob 5 | import chardet 6 | 7 | os.chdir(os.path.dirname(__file__)) 8 | 9 | root = "../core/src" 10 | if len(sys.argv) == 2: 11 | root = sys.argv[1] 12 | if root[(len(root) - 1):len(root)] != "/": 13 | root += "/" 14 | 15 | extensions = [ "cpp", "h" ] 16 | for ext in extensions: 17 | for path in glob.glob(root + "**/*." + ext, recursive=True): 18 | text = "" 19 | with open(path, mode="rb") as ifile: 20 | buffer = ifile.read() 21 | encode = chardet.detect(buffer)["encoding"] 22 | if encode == "utf-8-sig": 23 | continue 24 | 25 | try: 26 | text = buffer.decode(encode) 27 | except UnicodeDecodeError as e: 28 | print("decode error: " + path) 29 | print(e.reason) 30 | print("(ditect encode: " + encode + ")") 31 | continue 32 | 33 | with open(path, mode="wt", encoding="utf-8-sig") as ofile: 34 | ofile.write(text) 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /scripts/generate_wrapper.py: -------------------------------------------------------------------------------- 1 | import ctypes 2 | import sys 3 | import os 4 | 5 | from bindings import define 6 | from bindings import auto_generate_define 7 | from bindings import CppBindingGenerator as cbg 8 | 9 | os.chdir(os.path.dirname(__file__)) 10 | 11 | if __name__ == '__main__': 12 | 13 | # generate 14 | sharedObjectGenerator = cbg.SharedObjectGenerator(define, []) 15 | 16 | sharedObjectGenerator.header = ''' 17 | #include "BaseObject.h" 18 | #include "Common/Array.h" 19 | #include "Common/Resource.h" 20 | #include "Common/ResourceContainer.h" 21 | #include "Common/Resources.h" 22 | #include "Common/Profiler.h" 23 | #include "Core.h" 24 | #include "Graphics/BuiltinShader.h" 25 | #include "Graphics/CommandList.h" 26 | #include "Graphics/Font.h" 27 | #include "Graphics/Graphics.h" 28 | #include "Graphics/ImageFont.h" 29 | #include "Graphics/Renderer/RenderedText.h" 30 | #include "Graphics/Renderer/RenderedCamera.h" 31 | #include "Graphics/Renderer/RenderedSprite.h" 32 | #include "Graphics/Renderer/RenderedPolygon.h" 33 | #include "Graphics/Renderer/Renderer.h" 34 | #include "Graphics/RenderTexture.h" 35 | #include "Graphics/ShaderCompiler/ShaderCompiler.h" 36 | #include "Graphics/Texture2D.h" 37 | #include "IO/BaseFileReader.h" 38 | #include "IO/File.h" 39 | #include "IO/FileRoot.h" 40 | #include "IO/PackFile.h" 41 | #include "IO/PackFileReader.h" 42 | #include "IO/StaticFile.h" 43 | #include "IO/StreamFile.h" 44 | #include "Input/ButtonState.h" 45 | #include "Input/Joystick.h" 46 | #include "Input/Keyboard.h" 47 | #include "Input/Mouse.h" 48 | #include "Logger/Log.h" 49 | #include "Media/MediaPlayer.h" 50 | #include "Physics/Collider/Collider.h" 51 | #include "Physics/Collider/CircleCollider.h" 52 | #include "Physics/Collider/EdgeCollider.h" 53 | #include "Physics/Collider/PolygonCollider.h" 54 | #include "Physics/Collider/ShapeCollider.h" 55 | #include "Sound/Sound.h" 56 | #include "Sound/SoundMixer.h" 57 | #include "Tool/Tool.h" 58 | #include "Window/Window.h" 59 | ''' 60 | 61 | sharedObjectGenerator.func_name_create_and_add_shared_ptr = 'Altseed2::CreateAndAddSharedPtr' 62 | sharedObjectGenerator.func_name_add_and_get_shared_ptr = 'Altseed2::AddAndGetSharedPtr' 63 | 64 | sharedObjectGenerator.output_path = '../core/src/AutoGeneratedCoreWrapper.cpp' 65 | sharedObjectGenerator.generate() 66 | -------------------------------------------------------------------------------- /scripts/requirements.txt: -------------------------------------------------------------------------------- 1 | clang == 11.0 2 | chardet -------------------------------------------------------------------------------- /scripts/setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import shutil 4 | argvs = sys.argv 5 | 6 | if len(argvs) < 3: 7 | print('please specify a destination path.') 8 | sys.exit() 9 | 10 | os.chdir(os.path.dirname(os.path.abspath(__file__))) 11 | 12 | if os.path.exists(argvs[2] + '/TestData'): 13 | shutil.rmtree(argvs[2] + '/TestData') 14 | 15 | shutil.copytree(argvs[1], argvs[2] + '/TestData', ignore=shutil.ignore_patterns(".git")) -------------------------------------------------------------------------------- /scripts/update_all_submodules.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | import subprocess 4 | 5 | def cd(path): 6 | os.chdir(os.path.abspath(path)) 7 | 8 | class CurrentDir: 9 | def __init__(self, path): 10 | self.prev = os.getcwd() 11 | self.path = path 12 | 13 | def __enter__(self): 14 | cd(self.path) 15 | return self 16 | 17 | def __exit__(self, type, value, traceback): 18 | cd(self.prev) 19 | 20 | def update_submodule(): 21 | subprocess.call(["git", "submodule", "update"]) 22 | 23 | if not os.path.exists(".gitmodules"): 24 | return 25 | 26 | with open(".gitmodules", "r") as file: 27 | pattern = re.compile(r"\tpath = (.*)") 28 | for line in file.readlines(): 29 | result = pattern.match(line) 30 | if result: 31 | path = result.group(1) 32 | print(path) 33 | 34 | with CurrentDir(path): 35 | update_submodule() 36 | 37 | cd(os.path.dirname(__file__) + "/..") 38 | 39 | update_submodule() 40 | -------------------------------------------------------------------------------- /thirdparty/CFlagOverrides.cmake: -------------------------------------------------------------------------------- 1 | 2 | if (MSVC AND NOT USE_MSVC_RUNTIME_LIBRARY_DLL) 3 | foreach (flag CMAKE_C_FLAGS_DEBUG_INIT CMAKE_C_FLAGS_MINSIZEREL_INIT CMAKE_C_FLAGS_RELEASE_INIT CMAKE_C_FLAGS_RELWITHDEBINFO_INIT CMAKE_CXX_FLAGS_DEBUG_INIT CMAKE_CXX_FLAGS_MINSIZEREL_INIT CMAKE_CXX_FLAGS_RELEASE_INIT CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT) 4 | if (${flag} MATCHES "/MD") 5 | string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}") 6 | endif() 7 | if (${flag} MATCHES "/MDd") 8 | string(REGEX REPLACE "/MDd" "/MTd" ${flag} "${${flag}}") 9 | endif() 10 | endforeach() 11 | foreach (flag CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE) 12 | if (${flag} MATCHES "/MD") 13 | string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}") 14 | endif() 15 | if (${flag} MATCHES "/MDd") 16 | string(REGEX REPLACE "/MDd" "/MTd" ${flag} "${${flag}}") 17 | endif() 18 | endforeach() 19 | elseif (MSVC AND USE_MSVC_RUNTIME_LIBRARY_DLL) 20 | foreach (flag CMAKE_C_FLAGS_DEBUG_INIT CMAKE_C_FLAGS_MINSIZEREL_INIT CMAKE_C_FLAGS_RELEASE_INIT CMAKE_C_FLAGS_RELWITHDEBINFO_INIT CMAKE_CXX_FLAGS_DEBUG_INIT CMAKE_CXX_FLAGS_MINSIZEREL_INIT CMAKE_CXX_FLAGS_RELEASE_INIT CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT) 21 | if (${flag} MATCHES "/MT") 22 | string(REGEX REPLACE "/MT" "/MD" ${flag} "${${flag}}") 23 | endif() 24 | if (${flag} MATCHES "/MTd") 25 | string(REGEX REPLACE "/MTd" "/MDd" ${flag} "${${flag}}") 26 | endif() 27 | endforeach() 28 | foreach (flag CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE) 29 | if (${flag} MATCHES "/MT") 30 | string(REGEX REPLACE "/MT" "/MD" ${flag} "${${flag}}") 31 | endif() 32 | if (${flag} MATCHES "/MTd") 33 | string(REGEX REPLACE "/MTd" "/MDd" ${flag} "${${flag}}") 34 | endif() 35 | endforeach() 36 | endif() -------------------------------------------------------------------------------- /thirdparty/hidapi/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | 3 | # solution name 4 | project(hidapi) 5 | 6 | if(WIN32) 7 | add_library(hidapi STATIC 8 | windows/hid.c 9 | ) 10 | 11 | target_link_libraries( 12 | hidapi 13 | PRIVATE 14 | SetupAPI 15 | ) 16 | 17 | elseif(APPLE) 18 | add_library(hidapi STATIC 19 | mac/hid.c 20 | ) 21 | else() 22 | add_library(hidapi STATIC 23 | linux/hid.c 24 | ) 25 | endif() 26 | 27 | target_include_directories( 28 | hidapi 29 | PUBLIC 30 | ${CMAKE_CURRENT_SOURCE_DIR}/hidapi 31 | ) 32 | 33 | if(UNIX AND NOT APPLE) 34 | target_link_libraries( 35 | hidapi 36 | PUBLIC 37 | udev 38 | ) 39 | endif() 40 | 41 | 42 | set_target_properties(hidapi PROPERTIES POSITION_INDEPENDENT_CODE ON) -------------------------------------------------------------------------------- /thirdparty/hidapi/LICENSE-bsd.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, Alan Ott, Signal 11 Software 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of Signal 11 Software nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /thirdparty/hidapi/LICENSE-orig.txt: -------------------------------------------------------------------------------- 1 | HIDAPI - Multi-Platform library for 2 | communication with HID devices. 3 | 4 | Copyright 2009, Alan Ott, Signal 11 Software. 5 | All Rights Reserved. 6 | 7 | This software may be used by anyone for any reason so 8 | long as the copyright notice in the source files 9 | remains intact. 10 | -------------------------------------------------------------------------------- /thirdparty/hidapi/LICENSE.txt: -------------------------------------------------------------------------------- 1 | HIDAPI can be used under one of three licenses. 2 | 3 | 1. The GNU General Public License, version 3.0, in LICENSE-gpl3.txt 4 | 2. A BSD-Style License, in LICENSE-bsd.txt. 5 | 3. The more liberal original HIDAPI license. LICENSE-orig.txt 6 | 7 | The license chosen is at the discretion of the user of HIDAPI. For example: 8 | 1. An author of GPL software would likely use HIDAPI under the terms of the 9 | GPL. 10 | 11 | 2. An author of commercial closed-source software would likely use HIDAPI 12 | under the terms of the BSD-style license or the original HIDAPI license. 13 | 14 | -------------------------------------------------------------------------------- /thirdparty/hidapi/README.md: -------------------------------------------------------------------------------- 1 | This project is based on https://github.com/signal11/hidapi -------------------------------------------------------------------------------- /thirdparty/imgui/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | enable_language(CXX) 3 | 4 | # imgui 5 | list(APPEND srcs 6 | imgui.h 7 | imgui_impl_glfw.h 8 | imgui.cpp 9 | imgui_demo.cpp 10 | imgui_draw.cpp 11 | imgui_widgets.cpp 12 | imgui_impl_glfw.cpp 13 | ) 14 | 15 | if(WIN32) 16 | list(APPEND 17 | srcs 18 | imgui_impl_dx12.cpp) 19 | 20 | elseif(APPLE) 21 | list(APPEND 22 | srcs 23 | imgui_impl_metal.mm) 24 | endif() 25 | 26 | if(BUILD_VULKAN) 27 | list(APPEND 28 | srcs 29 | imgui_impl_vulkan.cpp) 30 | endif() 31 | 32 | add_library(imgui STATIC ${srcs}) 33 | 34 | target_include_directories( 35 | imgui 36 | PRIVATE 37 | ../glfw/include 38 | ) 39 | 40 | set_property(TARGET imgui PROPERTY POSITION_INDEPENDENT_CODE ON) 41 | 42 | if(APPLE) 43 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc") 44 | set_target_properties(imgui PROPERTIES XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC "YES") 45 | endif() 46 | -------------------------------------------------------------------------------- /thirdparty/imgui/imgui_impl_dx12.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer for DirectX12 2 | // This needs to be used along with a Platform Binding (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Multi-viewport support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 7 | // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. 8 | 9 | // Important: to compile on 32-bit systems, this back-end requires code to be compiled with '#define ImTextureID ImU64'. 10 | // This is because we need ImTextureID to carry a 64-bit value and by default ImTextureID is defined as void*. 11 | // This define is done in the example .vcxproj file and need to be replicated in your app (by e.g. editing imconfig.h) 12 | 13 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 14 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 15 | // https://github.com/ocornut/imgui 16 | 17 | #pragma once 18 | #include "imgui.h" // IMGUI_IMPL_API 19 | 20 | enum DXGI_FORMAT; 21 | struct ID3D12Device; 22 | struct ID3D12DescriptorHeap; 23 | struct ID3D12GraphicsCommandList; 24 | struct D3D12_CPU_DESCRIPTOR_HANDLE; 25 | struct D3D12_GPU_DESCRIPTOR_HANDLE; 26 | 27 | // cmd_list is the command list that the implementation will use to render imgui draw lists. 28 | // Before calling the render function, caller must prepare cmd_list by resetting it and setting the appropriate 29 | // render target and descriptor heap that contains font_srv_cpu_desc_handle/font_srv_gpu_desc_handle. 30 | // font_srv_cpu_desc_handle and font_srv_gpu_desc_handle are handles to a single SRV descriptor to use for the internal font texture. 31 | IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap, 32 | D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle); 33 | IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown(); 34 | IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame(); 35 | IMGUI_IMPL_API void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* graphics_command_list); 36 | 37 | // Use if you want to reset your rendering device without losing Dear ImGui state. 38 | IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects(); 39 | IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects(); 40 | -------------------------------------------------------------------------------- /thirdparty/imgui/imgui_impl_metal.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer for Metal 2 | // This needs to be used along with a Platform Binding (e.g. OSX) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'MTLTexture' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. 7 | // Missing features: 8 | // [ ] Renderer: Multi-viewport / platform windows. 9 | 10 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 11 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 12 | // https://github.com/ocornut/imgui 13 | 14 | #include "imgui.h" // IMGUI_IMPL_API 15 | 16 | @class MTLRenderPassDescriptor; 17 | @protocol MTLDevice, MTLCommandBuffer, MTLRenderCommandEncoder; 18 | 19 | IMGUI_IMPL_API bool ImGui_ImplMetal_Init(id device); 20 | IMGUI_IMPL_API void ImGui_ImplMetal_Shutdown(); 21 | IMGUI_IMPL_API void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor* renderPassDescriptor); 22 | IMGUI_IMPL_API void ImGui_ImplMetal_RenderDrawData(ImDrawData* draw_data, 23 | id commandBuffer, 24 | id commandEncoder); 25 | 26 | // Called by Init/NewFrame/Shutdown 27 | IMGUI_IMPL_API bool ImGui_ImplMetal_CreateFontsTexture(id device); 28 | IMGUI_IMPL_API void ImGui_ImplMetal_DestroyFontsTexture(); 29 | IMGUI_IMPL_API bool ImGui_ImplMetal_CreateDeviceObjects(id device); 30 | IMGUI_IMPL_API void ImGui_ImplMetal_DestroyDeviceObjects(); 31 | --------------------------------------------------------------------------------