├── .gitignore ├── .gitmodules ├── Engine └── src │ ├── AI │ ├── BehaviorTree.cpp │ ├── BehaviorTree.h │ ├── BehaviorTreeNodes.cpp │ └── BehaviorTreeNodes.h │ ├── Actors │ ├── Actor.cpp │ ├── Actor.h │ ├── Character.cpp │ ├── Character.h │ ├── FX_BaseEffectActor.cpp │ ├── FX_BaseEffectActor.h │ ├── UIActor.cpp │ └── UIActor.h │ ├── Animation │ ├── AnimNotify.h │ ├── Animation.h │ ├── AnimationBase.cpp │ ├── AnimationBase.h │ ├── AnimationState.h │ ├── AnimationStateMachine.cpp │ ├── AnimationStateMachine.h │ ├── BlendSpace2D.cpp │ ├── BlendSpace2D.h │ └── Transition.h │ ├── Components │ ├── Components.cpp │ └── Components.h │ ├── Core │ ├── DX11App.cpp │ ├── DX11App.h │ ├── DXStates.cpp │ ├── DXStates.h │ ├── Engine.cpp │ └── Engine.h │ ├── DataTypes │ ├── ConstantBuffer.h │ ├── Effect.h │ ├── Skeleton.h │ ├── Socket.h │ ├── Sound.h │ ├── StructuredBuffer.cpp │ ├── StructuredBuffer.h │ ├── UI.h │ └── Vertex.h │ ├── Engine_include.h │ ├── Event │ ├── EventMgr.cpp │ ├── EventMgr.h │ ├── Events.cpp │ └── Events.h │ ├── Headers │ ├── DllMacro.h │ ├── GlobalFunctions.h │ ├── entt.hpp │ ├── stdafx.cpp │ └── stdafx.h │ ├── Input │ ├── InputEventMgr.cpp │ ├── InputEventMgr.h │ ├── InputMgr.cpp │ └── InputMgr.h │ ├── Managers │ ├── EffectMgr.cpp │ ├── EffectMgr.h │ ├── RenderTargetMgr.cpp │ ├── RenderTargetMgr.h │ ├── ResourceMgr.cpp │ ├── ResourceMgr.h │ ├── TimeMgr.cpp │ └── TimeMgr.h │ ├── Physics │ ├── Collision.cpp │ ├── Collision.h │ ├── QuadTreeMgr.cpp │ ├── QuadTreeMgr.h │ ├── Shape.cpp │ └── Shape.h │ ├── ResourceTypes │ ├── Material.cpp │ ├── Material.h │ ├── Mesh.cpp │ ├── Mesh.h │ ├── Shader.cpp │ ├── Shader.h │ ├── Texture.cpp │ └── Texture.h │ ├── Scene │ ├── Scene.cpp │ ├── Scene.h │ ├── SceneMgr.cpp │ └── SceneMgr.h │ ├── Sound │ ├── FmodMgr.cpp │ └── FmodMgr.h │ ├── Systems │ ├── AnimationSystem.cpp │ ├── AnimationSystem.h │ ├── CameraSystem.cpp │ ├── CameraSystem.h │ ├── ComponentSystem.cpp │ ├── ComponentSystem.h │ ├── EffectSystem.cpp │ ├── EffectSystem.h │ ├── LightingSystem.cpp │ ├── LightingSystem.h │ ├── MovementSystem.cpp │ ├── MovementSystem.h │ ├── PhysicsSystem.cpp │ ├── PhysicsSystem.h │ ├── RenderSystem.cpp │ ├── RenderSystem.h │ ├── SoundSystem.cpp │ ├── SoundSystem.h │ ├── System.cpp │ ├── System.h │ ├── UISystem.cpp │ └── UISystem.h │ ├── Tools │ ├── DataTableMgr.cpp │ ├── DataTableMgr.h │ ├── FbxLoader.cpp │ ├── FbxLoader.h │ ├── FbxMgr.cpp │ ├── FbxMgr.h │ ├── FbxOutData.cpp │ ├── FbxOutData.h │ ├── FileTransfer.cpp │ ├── FileTransfer.h │ ├── GUIMgr.cpp │ └── GUIMgr.h │ ├── UI │ ├── UIBase.cpp │ ├── UIBase.h │ ├── UI_Button.cpp │ ├── UI_Button.h │ ├── UI_Image.cpp │ ├── UI_Image.h │ ├── UI_Listbox.cpp │ ├── UI_Listbox.h │ ├── UI_Slider.cpp │ ├── UI_Slider.h │ ├── UI_Sprite.cpp │ ├── UI_Sprite.h │ ├── UI_Text.cpp │ ├── UI_Text.h │ ├── WriteMgr.cpp │ └── WriteMgr.h │ └── World │ ├── DistanceFog.cpp │ ├── DistanceFog.h │ ├── Environment.cpp │ ├── Environment.h │ ├── GuideLine.cpp │ ├── GuideLine.h │ ├── InstancedObject.cpp │ ├── InstancedObject.h │ ├── Level.cpp │ ├── Level.h │ ├── SkySphere.cpp │ ├── SkySphere.h │ ├── StaticMeshLevel.cpp │ ├── StaticMeshLevel.h │ ├── StaticShadows.cpp │ └── StaticShadows.h ├── ProjectGenerator.bat ├── README.md ├── premake5.lua └── vendor └── premake ├── LICENSE.txt └── premake5.exe /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Microsoft Azure ApplicationInsights config file 170 | ApplicationInsights.config 171 | 172 | # Windows Store app package directory 173 | AppPackages/ 174 | BundleArtifacts/ 175 | 176 | # Visual Studio cache files 177 | # files ending in .cache can be ignored 178 | *.[Cc]ache 179 | # but keep track of directories ending in .cache 180 | !*.[Cc]ache/ 181 | 182 | # Others 183 | ClientBin/ 184 | [Ss]tyle[Cc]op.* 185 | ~$* 186 | *~ 187 | *.dbmdl 188 | *.dbproj.schemaview 189 | *.pfx 190 | *.publishsettings 191 | node_modules/ 192 | orleans.codegen.cs 193 | 194 | # RIA/Silverlight projects 195 | Generated_Code/ 196 | 197 | # Backup & report files from converting an old project file 198 | # to a newer Visual Studio version. Backup files are not needed, 199 | # because we have git ;-) 200 | _UpgradeReport_Files/ 201 | Backup*/ 202 | UpgradeLog*.XML 203 | UpgradeLog*.htm 204 | 205 | # SQL Server files 206 | *.mdf 207 | *.ldf 208 | 209 | # Business Intelligence projects 210 | *.rdl.data 211 | *.bim.layout 212 | *.bim_*.settings 213 | 214 | # Microsoft Fakes 215 | FakesAssemblies/ 216 | 217 | # GhostDoc plugin setting file 218 | *.GhostDoc.xml 219 | 220 | # Node.js Tools for Visual Studio 221 | .ntvs_analysis.dat 222 | 223 | # Visual Studio 6 build log 224 | *.plg 225 | 226 | # Visual Studio 6 workspace options file 227 | *.opt 228 | 229 | # Visual Studio LightSwitch build output 230 | **/*.HTMLClient/GeneratedArtifacts 231 | **/*.DesktopClient/GeneratedArtifacts 232 | **/*.DesktopClient/ModelManifest.xml 233 | **/*.Server/GeneratedArtifacts 234 | **/*.Server/ModelManifest.xml 235 | _Pvt_Extensions 236 | 237 | # LightSwitch generated files 238 | GeneratedArtifacts/ 239 | ModelManifest.xml 240 | 241 | # Paket dependency manager 242 | .paket/paket.exe 243 | 244 | # FAKE - F# Make 245 | .fake/ 246 | /TestGame/Resource 247 | /TestGame/Shader/SkinningVS.cso 248 | /TestGame/Shader/SkinningPS.cso 249 | /TestGame/Shader/BasicShapeVS.cso 250 | /TestGame/Shader/BasicShapePS.cso 251 | /Engine/src/dev.txt 252 | /TestGame/imgui.ini 253 | /CharacterTool 254 | *.vcxproj 255 | *.filters 256 | *.sln 257 | /Engine/src/Engine/Log.cpp 258 | /Engine/src/Engine/Log.h 259 | /Engine/src/Engine/Log.cpp 260 | /Engine/src/Engine/Log.h 261 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Engine/vendor/spdlog"] 2 | path = Engine/vendor/spdlog 3 | url = https://github.com/gabime/spdlog 4 | -------------------------------------------------------------------------------- /Engine/src/AI/BehaviorTree.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "BehaviorTree.h" 3 | 4 | namespace reality { 5 | void BehaviorTree::Update() 6 | { 7 | if (root_ == nullptr) { 8 | return; 9 | } 10 | 11 | root_->Execute(); 12 | 13 | BehaviorStatus root_status = root_->GetStatus(); 14 | 15 | if (root_status == BehaviorStatus::FAILURE || 16 | root_status == BehaviorStatus::SUCCESS) { 17 | root_->ResetNodes(); 18 | } 19 | } 20 | 21 | BehaviorNode* BehaviorTree::GetRootNode() 22 | { 23 | return root_.get(); 24 | } 25 | } -------------------------------------------------------------------------------- /Engine/src/AI/BehaviorTree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "BehaviorTreeNodes.h" 3 | 4 | namespace reality { 5 | class DLL_API BehaviorTree 6 | { 7 | public: 8 | template 9 | void SetRootNode(Args&&...); 10 | void Update(); 11 | BehaviorNode* GetRootNode(); 12 | 13 | private: 14 | shared_ptr root_ = nullptr; 15 | }; 16 | 17 | template 18 | inline void BehaviorTree::SetRootNode(Args && ... args) 19 | { 20 | root_ = make_shared(args...); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Engine/src/Actors/Actor.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Actor.h" 3 | 4 | void reality::Actor::OnInit(entt::registry& registry) 5 | { 6 | entity_id_ = registry.create(); 7 | reg_scene_ = ®istry; 8 | } 9 | 10 | void reality::Actor::OnUpdate() 11 | { 12 | 13 | } 14 | 15 | entt::entity reality::Actor::GetEntityId() 16 | { 17 | return entity_id_; 18 | } 19 | 20 | XMVECTOR reality::Actor::GetCurPosition() 21 | { 22 | return cur_position_; 23 | } 24 | 25 | void reality::Actor::ApplyMovement(XMVECTOR translation_vector) 26 | { 27 | cur_position_ = translation_vector; 28 | transform_tree_.root_node->Translate(*reg_scene_, entity_id_, XMMatrixTranslationFromVector(cur_position_)); 29 | } -------------------------------------------------------------------------------- /Engine/src/Actors/Actor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ComponentSystem.h" 3 | 4 | namespace reality 5 | { 6 | class DLL_API Actor 7 | { 8 | protected: 9 | XMVECTOR cur_position_ = { 0.0f, 0.0f, 0.0f, 0.0f }; 10 | public: 11 | entt::entity entity_id_; 12 | TransformTree transform_tree_; 13 | int node_num_; 14 | entt::registry* reg_scene_; 15 | string tag; 16 | 17 | bool visible = true; 18 | 19 | public: 20 | virtual void OnInit(entt::registry& registry); 21 | virtual void OnUpdate(); 22 | 23 | public: 24 | entt::entity GetEntityId(); 25 | virtual void ApplyMovement(XMVECTOR trnaslation_vector); 26 | XMVECTOR GetCurPosition(); 27 | }; 28 | } -------------------------------------------------------------------------------- /Engine/src/Actors/Character.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Character.h" 3 | #include "TimeMgr.h" 4 | #include "SceneMgr.h" 5 | void reality::Character::OnInit(entt::registry& registry) 6 | { 7 | Actor::OnInit(registry); 8 | registry.emplace_or_replace(entity_id_, &transform_tree_); 9 | } 10 | 11 | void reality::Character::OnUpdate() 12 | { 13 | if (rotate_enable_) 14 | { 15 | front_ = XMVector3Transform(XMVECTOR{ 0.0f, 0.0f, 1.0f, 0.0f }, rotation_); 16 | right_ = XMVector3Transform(XMVECTOR{ 1.0f, 0.0f, 0.0f, 0.0f }, rotation_); 17 | transform_tree_.root_node->Rotate(*reg_scene_, entity_id_, cur_position_, rotation_); 18 | } 19 | } 20 | 21 | reality::C_Movement* reality::Character::GetMovementComponent() 22 | { 23 | return reg_scene_->try_get(entity_id_); 24 | } 25 | 26 | void reality::Character::CancelMovement() 27 | { 28 | GetMovementComponent()->velocity.m128_f32[0] = 0; 29 | GetMovementComponent()->velocity.m128_f32[2] = 0; 30 | } 31 | 32 | void reality::Character::SetPos(const XMVECTOR& position) 33 | { 34 | cur_position_ = position; 35 | transform_tree_.root_node->Translate(*reg_scene_, entity_id_, XMMatrixTranslationFromVector(cur_position_)); 36 | } 37 | 38 | XMMATRIX reality::Character::GetRotation() 39 | { 40 | return rotation_; 41 | } 42 | 43 | reality::C_CapsuleCollision* reality::Character::GetCapsuleComponent() 44 | { 45 | return reg_scene_->try_get(entity_id_); 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Engine/src/Actors/Character.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Actor.h" 3 | 4 | namespace reality 5 | { 6 | enum class MovementState 7 | { 8 | FALL, 9 | WALK, 10 | }; 11 | 12 | class DLL_API Character : public Actor 13 | { 14 | protected: 15 | XMVECTOR front_ = { 0, 0, 1, 0 }; 16 | XMVECTOR right_ = { 1, 0, 0, 0 }; 17 | XMVECTOR fall_ = { 0, -1, 0, 0 }; 18 | XMVECTOR jump_ = { 0, 1, 0, 0 }; 19 | 20 | public: 21 | XMMATRIX rotation_ = XMMatrixIdentity(); 22 | 23 | public: 24 | XMFLOAT3 floor_position = {0, 0, 0}; 25 | MovementState movement_state_; 26 | XMFLOAT4 blocking_planes_[4]; 27 | 28 | public: 29 | void OnInit(entt::registry& registry) override; 30 | void OnUpdate() override; 31 | 32 | public: 33 | C_Movement* GetMovementComponent(); 34 | C_CapsuleCollision* GetCapsuleComponent(); 35 | 36 | void SetPos(const XMVECTOR& position); 37 | XMMATRIX GetRotation(); 38 | XMVECTOR GetFront() { return front_; }; 39 | public: 40 | void CancelMovement(); 41 | bool rotate_enable_ = true; 42 | }; 43 | } -------------------------------------------------------------------------------- /Engine/src/Actors/FX_BaseEffectActor.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "FX_BaseEffectActor.h" 3 | #include "ResourceMgr.h" 4 | 5 | using namespace reality; 6 | 7 | void FX_BaseEffectActor::OnInit(entt::registry& registry) 8 | { 9 | Actor::OnInit(registry); 10 | 11 | auto& transform = registry.emplace(entity_id_); 12 | transform.world = XMMatrixIdentity(); 13 | transform.local = XMMatrixIdentity(); 14 | 15 | transform_tree_.root_node = make_shared(TYPE_ID(reality::C_Transform)); 16 | transform_tree_.root_node->OnUpdate(registry, entity_id_); 17 | } 18 | 19 | void FX_BaseEffectActor::Spawn(XMVECTOR pos, XMVECTOR rotation_q, XMVECTOR scale) 20 | { 21 | auto& transform_comp = reg_scene_->get(GetEntityId()); 22 | XMMATRIX S, R, T; 23 | S = XMMatrixScalingFromVector(scale); 24 | R = XMMatrixRotationQuaternion(rotation_q); 25 | T = XMMatrixTranslationFromVector(pos); 26 | transform_comp.world = S * R * T; 27 | 28 | transform_tree_.root_node->OnUpdate(*reg_scene_, entity_id_, transform_comp.world); 29 | } 30 | 31 | void FX_BaseEffectActor::AddEffectComponent(string effect_name, float lifetime) 32 | { 33 | auto& effect_comp = reg_scene_->emplace(entity_id_); 34 | effect_comp.local = XMMatrixIdentity(); 35 | effect_comp.effect_id = effect_name; 36 | auto effect = RESOURCE->UseResource(effect_name); 37 | if(effect) 38 | effect_comp.effect = *effect; 39 | // lifetime = -1.0 -> Infinite Lifetime 40 | effect_comp.effect_lifetime = lifetime; 41 | effect_comp.effect_timer = 0.0f; 42 | 43 | transform_tree_.AddNodeToNode(TYPE_ID(reality::C_Transform), TYPE_ID(reality::C_Effect)); 44 | transform_tree_.root_node->OnUpdate(*reg_scene_, entity_id_); 45 | } 46 | 47 | void FX_BaseEffectActor::AddSoundGeneratorComponent() 48 | { 49 | auto& sound_gen_comp = reg_scene_->emplace(GetEntityId()); 50 | sound_gen_comp.local = XMMatrixIdentity(); 51 | 52 | transform_tree_.AddNodeToNode(TYPE_ID(reality::C_Transform), TYPE_ID(reality::C_SoundGenerator)); 53 | transform_tree_.root_node->OnUpdate(*reg_scene_, entity_id_); 54 | } 55 | 56 | void FX_BaseEffectActor::AddPointLightComponent(string pointlight_name, float lifetime = -1.0f) 57 | { 58 | auto& pointlight_comp = reg_scene_->emplace(entity_id_); 59 | pointlight_comp.point_light_id = pointlight_name; 60 | pointlight_comp.point_light = *(PointLight*)RESOURCE->UseResource(pointlight_name); 61 | pointlight_comp.local = XMMatrixIdentity(); 62 | pointlight_comp.lifetime = lifetime; 63 | pointlight_comp.timer = 0.0f; 64 | 65 | transform_tree_.AddNodeToNode(TYPE_ID(reality::C_Transform), TYPE_ID(reality::C_PointLight)); 66 | transform_tree_.root_node->OnUpdate(*reg_scene_, entity_id_); 67 | } 68 | 69 | void FX_BaseEffectActor::AddSpotLightComponent(string spotlight_name, float lifetime) 70 | { 71 | auto& spotlight_comp = reg_scene_->emplace(entity_id_); 72 | spotlight_comp.spot_light_id = spotlight_name; 73 | spotlight_comp.spot_light = *(SpotLight*)RESOURCE->UseResource(spotlight_name); 74 | spotlight_comp.local = XMMatrixIdentity(); 75 | spotlight_comp.lifetime = lifetime; 76 | spotlight_comp.timer = 0.0f; 77 | 78 | transform_tree_.AddNodeToNode(TYPE_ID(reality::C_Transform), TYPE_ID(reality::C_SpotLight)); 79 | transform_tree_.root_node->OnUpdate(*reg_scene_, entity_id_); 80 | } 81 | 82 | // Only Used for Tool 83 | void FX_BaseEffectActor::AddEffect(map& emitter_list) 84 | { 85 | auto& effect_comp = reg_scene_->get_or_emplace(entity_id_); 86 | effect_comp.effect.emitters = emitter_list; 87 | } 88 | 89 | void FX_BaseEffectActor::ResetEmitter() 90 | { 91 | auto& effect_comp = reg_scene_->get_or_emplace(entity_id_); 92 | effect_comp.effect.emitters.clear(); 93 | } -------------------------------------------------------------------------------- /Engine/src/Actors/FX_BaseEffectActor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Actor.h" 3 | 4 | namespace reality 5 | { 6 | class DLL_API FX_BaseEffectActor : public Actor 7 | { 8 | public: 9 | virtual void OnInit(entt::registry& registry) override; 10 | 11 | public: 12 | void Spawn(XMVECTOR pos, XMVECTOR rotation_q = XMQuaternionIdentity(), XMVECTOR scale = XMVectorSet(1.0f, 1.0f, 1.0f, 1.0f)); 13 | protected: 14 | void AddEffectComponent(string effect_name, float lifetime = -1.0f); 15 | void AddSoundGeneratorComponent(); 16 | void AddPointLightComponent(string pointlight_name, float lifetime); 17 | void AddSpotLightComponent(string spotlight_name, float lifetime); 18 | 19 | public: 20 | // Only Used for Tool 21 | void AddEffect(map& emitter_list); 22 | void ResetEmitter(); 23 | }; 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /Engine/src/Actors/UIActor.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "UIActor.h" 3 | 4 | void reality::UIActor::OnInit(entt::registry& registry) 5 | { 6 | Actor::OnInit(registry); 7 | 8 | C_UI ui_comp; 9 | registry.emplace(entity_id_, ui_comp); 10 | } 11 | 12 | void reality::UIActor::OnUpdate() 13 | { 14 | } 15 | -------------------------------------------------------------------------------- /Engine/src/Actors/UIActor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Actor.h" 3 | #include "UI_Image.h" 4 | #include "UI_Text.h" 5 | #include "UI_Button.h" 6 | #include "UI_Slider.h" 7 | namespace reality 8 | { 9 | class DLL_API UIActor : public Actor 10 | { 11 | public: 12 | virtual void OnInit(entt::registry& registry); 13 | virtual void OnUpdate(); 14 | }; 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Engine/src/Animation/AnimNotify.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | namespace reality { 5 | 6 | class Event; 7 | 8 | struct DLL_API AnimNotify { 9 | float frame; 10 | std::shared_ptr event; 11 | bool is_managed = false; 12 | }; 13 | } -------------------------------------------------------------------------------- /Engine/src/Animation/Animation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | #include "AnimNotify.h" 4 | 5 | namespace reality { 6 | struct DLL_API Animation { 7 | unordered_map animation_matrices; 8 | unordered_map prev_animation_matrices; 9 | unordered_map bone_id_to_weight_; 10 | float range_; 11 | string cur_anim_id_ = ""; 12 | float start_frame_ = 0.0f; 13 | float end_frame_ = 0.0f; 14 | float blend_time_ = 0.0f; 15 | float cur_animation_time_ = 0.0f; 16 | float cur_frame_ = 0.0f; 17 | vector notifies_; 18 | bool loop_; 19 | }; 20 | } -------------------------------------------------------------------------------- /Engine/src/Animation/AnimationBase.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "AnimationBase.h" 3 | #include "TimeMgr.h" 4 | #include "ResourceMgr.h" 5 | #include "EventMgr.h" 6 | 7 | reality::AnimationBase::AnimationBase(string skeletal_mesh_id, int range, string bone_name) 8 | { 9 | SkeletalMesh* skeletal_mesh = RESOURCE->UseResource(skeletal_mesh_id); 10 | // base slot 11 | if (bone_name == "") { 12 | const auto& id_bone_map = skeletal_mesh->skeleton.id_bone_map; 13 | 14 | for (const auto& id_bone_pair : id_bone_map) { 15 | const int& bone_id = id_bone_pair.first; 16 | animation_.bone_id_to_weight_.insert({ bone_id , 1.0f }); 17 | } 18 | } 19 | else { 20 | animation_.bone_id_to_weight_ = skeletal_mesh->skeleton.GetSubBonesOf(bone_name, range); 21 | animation_.range_ = range * 2; 22 | } 23 | } 24 | 25 | void reality::AnimationBase::AnimationUpdate() 26 | { 27 | animation_.cur_animation_time_ += TM_DELTATIME; 28 | 29 | animation_.cur_frame_ += 60.0f / TM_FPS; 30 | 31 | if (animation_.cur_frame_ >= animation_.end_frame_) { 32 | animation_ended_ = true; 33 | animation_.cur_frame_ = animation_.start_frame_; 34 | 35 | if (animation_.loop_ == false) { 36 | SetAnimation("", 0.2f, true); 37 | } 38 | 39 | for (auto& cur_notify : animation_.notifies_) { 40 | cur_notify.is_managed = false; 41 | } 42 | } 43 | 44 | for (auto& cur_notify : animation_.notifies_) { 45 | if (cur_notify.is_managed == true) { 46 | continue; 47 | } 48 | 49 | if (cur_notify.frame <= animation_.cur_frame_) { 50 | EVENT->PushEvent(cur_notify.event); 51 | cur_notify.is_managed = true; 52 | } 53 | } 54 | 55 | OnUpdate(); 56 | 57 | animation_ended_ = false; 58 | 59 | OutAnimData* cur_animation_resource = RESOURCE->UseResource(animation_.cur_anim_id_); 60 | if (cur_animation_resource == nullptr) { 61 | return; 62 | } 63 | 64 | for (const auto& bone_id_weight_pair : animation_.bone_id_to_weight_) { 65 | const UINT& bone_id = bone_id_weight_pair.first; 66 | animation_.animation_matrices[bone_id] = cur_animation_resource->animation_matrices[bone_id][animation_.cur_frame_]; 67 | } 68 | } 69 | string reality::AnimationBase::GetCurAnimationId() 70 | { 71 | return animation_.cur_anim_id_; 72 | } 73 | float reality::AnimationBase::GetCurAnimTime() 74 | { 75 | return animation_.cur_animation_time_; 76 | } 77 | 78 | float reality::AnimationBase::GetCurFrame() 79 | { 80 | return animation_.cur_frame_; 81 | } 82 | 83 | float reality::AnimationBase::GetBlendTime() 84 | { 85 | return animation_.blend_time_; 86 | } 87 | 88 | float reality::AnimationBase::GetRange() 89 | { 90 | return animation_.range_; 91 | } 92 | 93 | unordered_map* reality::AnimationBase::GetAnimationMatrices() 94 | { 95 | return &animation_.animation_matrices; 96 | } 97 | 98 | unordered_map* reality::AnimationBase::GetPrevAnimationMatrices() 99 | { 100 | return &animation_.prev_animation_matrices; 101 | } 102 | 103 | unordered_map* reality::AnimationBase::GetWeights() 104 | { 105 | return &animation_.bone_id_to_weight_; 106 | } 107 | 108 | reality::ANIM_STATE reality::AnimationBase::GetCurAnimState() 109 | { 110 | return cur_anim_state_; 111 | } 112 | 113 | void reality::AnimationBase::SetAnimation(string animation_id, float blend_time, bool loop, vector notifies) 114 | { 115 | OutAnimData* anim_resource = RESOURCE->UseResource(animation_id); 116 | OutAnimData* prev_anim_resource = RESOURCE->UseResource(animation_.cur_anim_id_); 117 | 118 | string prev_animation_id = animation_.cur_anim_id_; 119 | float prev_anim_last_frame = animation_.cur_frame_; 120 | 121 | if (anim_resource != nullptr) { 122 | animation_.start_frame_ = anim_resource->start_frame; 123 | animation_.end_frame_ = anim_resource->end_frame; 124 | animation_.cur_frame_ = anim_resource->start_frame; 125 | } 126 | 127 | if (prev_anim_resource != nullptr) { 128 | for (const auto& bone_id_weight_pair : animation_.bone_id_to_weight_) { 129 | const UINT& bone_id = bone_id_weight_pair.first; 130 | animation_.prev_animation_matrices[bone_id] = prev_anim_resource->animation_matrices[bone_id][prev_anim_last_frame]; 131 | } 132 | } 133 | 134 | animation_.cur_anim_id_ = animation_id; 135 | animation_.cur_animation_time_ = 0.0f; 136 | animation_.blend_time_ = blend_time; 137 | 138 | if (prev_anim_resource == nullptr && anim_resource == nullptr) { 139 | cur_anim_state_ = ANIM_STATE::ANIM_STATE_NONE; 140 | } 141 | else if (prev_anim_resource == nullptr) { 142 | cur_anim_state_ = ANIM_STATE::ANIM_STATE_CUR_ONLY; 143 | } 144 | else if (anim_resource == nullptr) { 145 | cur_anim_state_ = ANIM_STATE::ANIM_STATE_PREV_ONLY; 146 | } 147 | else { 148 | cur_anim_state_ = ANIM_STATE::ANIM_STATE_CUR_PREV; 149 | } 150 | 151 | animation_.notifies_ = notifies; 152 | 153 | animation_.loop_ = loop; 154 | } 155 | -------------------------------------------------------------------------------- /Engine/src/Animation/AnimationBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Animation.h" 3 | 4 | namespace reality { 5 | 6 | class Event; 7 | 8 | enum class ANIM_STATE { 9 | ANIM_STATE_NONE, 10 | ANIM_STATE_CUR_ONLY, 11 | ANIM_STATE_PREV_ONLY, 12 | ANIM_STATE_CUR_PREV, 13 | }; 14 | 15 | class DLL_API AnimationBase { 16 | public: 17 | AnimationBase(string skeletal_mesh_id, int range, string bone_name = ""); 18 | 19 | public: 20 | Animation GetCurAnimation() { 21 | return animation_; 22 | } 23 | 24 | public: 25 | virtual void AnimationUpdate(); 26 | virtual void OnInit() {}; 27 | 28 | protected: 29 | virtual void OnUpdate() {}; 30 | 31 | public: 32 | bool IsAnimationEnded() { 33 | return animation_ended_; 34 | } 35 | 36 | public: 37 | string GetCurAnimationId(); 38 | float GetCurAnimTime(); 39 | float GetCurFrame(); 40 | float GetBlendTime(); 41 | float GetRange(); 42 | 43 | public: 44 | unordered_map* GetAnimationMatrices(); 45 | unordered_map* GetPrevAnimationMatrices(); 46 | unordered_map* GetWeights(); 47 | 48 | public: 49 | ANIM_STATE GetCurAnimState(); 50 | 51 | public: 52 | virtual void SetAnimation(string animation_id, float blend_time, bool loop, vector notifies = vector()); 53 | 54 | protected: 55 | Animation animation_; 56 | ANIM_STATE cur_anim_state_ = ANIM_STATE::ANIM_STATE_NONE; 57 | bool animation_ended_ = false; 58 | }; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /Engine/src/Animation/AnimationState.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "AnimationStateMachine.h" 3 | 4 | namespace reality { 5 | class DLL_API AnimationState 6 | { 7 | private: 8 | int id_; 9 | 10 | public: 11 | AnimationState(int id) : id_(id) {}; 12 | 13 | public: 14 | virtual void Enter(AnimationStateMachine* animation) {} 15 | virtual void Exit(AnimationStateMachine* animation) {} 16 | virtual void OnUpdate(AnimationStateMachine* animation) {} 17 | 18 | public: 19 | int GetId() { 20 | return id_; 21 | } 22 | }; 23 | } -------------------------------------------------------------------------------- /Engine/src/Animation/AnimationStateMachine.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "AnimationState.h" 3 | 4 | namespace reality { 5 | void AnimationStateMachine::OnInit() 6 | { 7 | } 8 | void AnimationStateMachine::OnUpdate() 9 | { 10 | cur_state_->OnUpdate(this); 11 | 12 | auto range = transitions_.equal_range(cur_state_->GetId()); 13 | for (auto it = range.first; it != range.second; ++it) 14 | { 15 | if (it->second.condition_(this)) 16 | { 17 | cur_state_->Exit(this); 18 | cur_state_ = states_[it->second.to_state_id_]; 19 | cur_state_->Enter(this); 20 | break; 21 | } 22 | } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Engine/src/Animation/AnimationStateMachine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Transition.h" 3 | #include "AnimationBase.h" 4 | 5 | namespace reality { 6 | class AnimationState; 7 | 8 | class DLL_API AnimationStateMachine : public AnimationBase 9 | { 10 | public: 11 | AnimationStateMachine(entt::entity owner_id, string skeletal_mesh_id, int range, string bone_name = "") : 12 | owner_id_(owner_id), 13 | AnimationBase(skeletal_mesh_id, range, bone_name) {} 14 | 15 | public: 16 | virtual void OnInit() override; 17 | virtual void OnUpdate() override; 18 | 19 | public: 20 | entt::entity GetOwnerId() const { 21 | return owner_id_; 22 | } 23 | 24 | public: 25 | AnimationState* GetCurrentAnimationState() { 26 | return cur_state_.get(); 27 | } 28 | 29 | protected: 30 | std::unordered_map> states_; 31 | std::multimap transitions_; 32 | shared_ptr cur_state_ = nullptr; 33 | 34 | protected: 35 | entt::entity owner_id_; 36 | }; 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /Engine/src/Animation/BlendSpace2D.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "BlendSpace2D.h" 3 | #include "ResourceMgr.h" 4 | 5 | namespace reality { 6 | AnimationClip::AnimationClip(float x, float y, bool is_valid, string animation_id) : 7 | x_(x), y_(y), is_valid_(is_valid), animation_id_(animation_id) 8 | { 9 | RESOURCE->UseResource(animation_id)->animation_matrices; 10 | } 11 | 12 | void BlendSpace2D::OnUpdate() 13 | { 14 | float clamped_x = max(x_min_, min(x_, x_max_)); 15 | float clamped_y = max(y_min_, min(y_, y_max_)); 16 | 17 | AnimationClip clips[4]; 18 | 19 | clips[0] = GetClip(clamped_x, clamped_y, BLEND_DIRECTION::H_X_H_Y); 20 | clips[1] = GetClip(clamped_x, clamped_y, BLEND_DIRECTION::H_X_L_Y); 21 | clips[2] = GetClip(clamped_x, clamped_y, BLEND_DIRECTION::L_X_H_Y); 22 | clips[3] = GetClip(clamped_x, clamped_y, BLEND_DIRECTION::L_X_L_Y); 23 | 24 | float dists[4]; 25 | float weights[4]; 26 | float total_dist = 0.0f; 27 | for (int i = 0;i < 4;i++) { 28 | if (clips[i].is_valid_ == false) { 29 | continue; 30 | } 31 | dists[i] = (clamped_x - clips[i].x_) * (clamped_x - clips[i].x_) + (clamped_y - clips[i].y_) * (clamped_y - clips[i].y_); 32 | total_dist += dists[i]; 33 | } 34 | 35 | for (int i = 0;i < 4;i++) { 36 | if (clips[i].is_valid_ == false) { 37 | weights[i] = 0.0f; 38 | } 39 | else { 40 | weights[i] = dists[i] / total_dist; 41 | } 42 | } 43 | 44 | unordered_map> applied_animations; 45 | 46 | for (int i = 0;i < 4;i++) { 47 | if (applied_animations.find(clips[i].animation_id_) == applied_animations.end()) { 48 | OutAnimData* anim_resource = RESOURCE->UseResource(clips[i].animation_id_); 49 | if (anim_resource == nullptr) { 50 | continue; 51 | } 52 | std::map>& animation_matrices = anim_resource->animation_matrices; 53 | 54 | anim_resource->animation_matrices; 55 | applied_animations.insert({ clips[i].animation_id_, {} }); 56 | for (const auto& bone_id_weight_pair : animation_.bone_id_to_weight_) { 57 | UINT bone_id = bone_id_weight_pair.first; 58 | applied_animations[clips[i].animation_id_].insert({ bone_id, animation_matrices[bone_id][animation_.cur_frame_] }); 59 | } 60 | } 61 | } 62 | 63 | for (const auto& bone_id_weight_pair : animation_.bone_id_to_weight_) { 64 | UINT bone_id = bone_id_weight_pair.first; 65 | 66 | XMMATRIX& anim_matrix1 = applied_animations[clips[0].animation_id_][bone_id]; 67 | XMMATRIX& anim_matrix2 = applied_animations[clips[1].animation_id_][bone_id]; 68 | XMMATRIX& anim_matrix3 = applied_animations[clips[2].animation_id_][bone_id]; 69 | XMMATRIX& anim_matrix4 = applied_animations[clips[3].animation_id_][bone_id]; 70 | 71 | animation_.animation_matrices[bone_id] = anim_matrix1 * weights[0] + anim_matrix2 * weights[1] + anim_matrix3 * weights[2] + anim_matrix4 * weights[3]; 72 | } 73 | } 74 | 75 | AnimationClip BlendSpace2D::GetClip(int x, int y, BLEND_DIRECTION blend_direction) 76 | { 77 | float min_dist = FLT_MAX; 78 | AnimationClip closest_clip; 79 | 80 | for (const auto& clip : animation_clips_) 81 | { 82 | switch (blend_direction) { 83 | case BLEND_DIRECTION::H_X_H_Y: 84 | if (clip.x_ < x || clip.y_ < y) 85 | continue; 86 | break; 87 | case BLEND_DIRECTION::H_X_L_Y: 88 | if (clip.x_ < x || clip.y_ > y) 89 | continue; 90 | break; 91 | case BLEND_DIRECTION::L_X_H_Y: 92 | if (clip.x_ > x || clip.y_ < y) 93 | continue; 94 | break; 95 | case BLEND_DIRECTION::L_X_L_Y: 96 | if (clip.x_ > x || clip.y_ > y) 97 | continue; 98 | break; 99 | } 100 | 101 | float dist = (clip.x_ - x) * (clip.x_ - x) + (clip.y_ - y) * (clip.y_ - y); 102 | if (dist < min_dist) 103 | { 104 | min_dist = dist; 105 | closest_clip = clip; 106 | } 107 | } 108 | 109 | return closest_clip; 110 | } 111 | 112 | 113 | void BlendSpace2D::AddClip(float x, float y, string animation_id) 114 | { 115 | float x_range = x_max_ - x_min_; 116 | float y_range = y_max_ - y_min_; 117 | 118 | int row = static_cast((y - y_min_) / y_range * BLENDSPACE2D_ROW); 119 | int col = static_cast((x - x_min_) / x_range * BLENDSPACE2D_COL); 120 | 121 | row = max(0, min(row, BLENDSPACE2D_ROW - 1)); 122 | col = max(0, min(col, BLENDSPACE2D_COL - 1)); 123 | 124 | AnimationClip animation_clip(x, y, true, animation_id); 125 | animation_clips_.push_back(animation_clip); 126 | } 127 | } -------------------------------------------------------------------------------- /Engine/src/Animation/BlendSpace2D.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "AnimationBase.h" 3 | 4 | namespace reality { 5 | #define BLENDSPACE2D_ROW 50 6 | #define BLENDSPACE2D_COL 50 7 | 8 | struct DLL_API AnimationClip { 9 | public: 10 | AnimationClip() {}; 11 | AnimationClip(float x, float y, bool is_valid, string animation_id); 12 | 13 | public: 14 | float x_; 15 | float y_; 16 | 17 | public: 18 | bool is_valid_ = false; 19 | 20 | public: 21 | string animation_id_; 22 | }; 23 | 24 | enum class BLEND_DIRECTION { 25 | H_X_H_Y, 26 | H_X_L_Y, 27 | L_X_H_Y, 28 | L_X_L_Y, 29 | }; 30 | 31 | class DLL_API BlendSpace2D : public AnimationBase { 32 | public: 33 | BlendSpace2D(const float& x, const float& y, float x_min, float x_max, float y_min, float y_max, float start_frame, float end_frame, entt::entity owner_id, string skeletal_mesh_id, int range, string bone_name = "") 34 | : x_(x), y_(y), x_min_(x_min), x_max_(x_max), y_min_(y_min), y_max_(y_max), owner_id_(owner_id), 35 | AnimationBase(skeletal_mesh_id, range, bone_name) 36 | { 37 | animation_.start_frame_ = start_frame; 38 | animation_.end_frame_ = end_frame; 39 | cur_anim_state_ = ANIM_STATE::ANIM_STATE_CUR_ONLY; 40 | } 41 | 42 | protected: 43 | void OnUpdate() override; 44 | 45 | private: 46 | AnimationClip GetClip(int x, int y, BLEND_DIRECTION blend_direction); 47 | 48 | public: 49 | void AddClip(float x, float y, string animation_id); 50 | 51 | private: 52 | std::vector animation_clips_; 53 | const float& x_; 54 | const float& y_; 55 | float x_min_; 56 | float x_max_; 57 | float y_min_; 58 | float y_max_; 59 | entt::entity owner_id_; 60 | }; 61 | } -------------------------------------------------------------------------------- /Engine/src/Animation/Transition.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | namespace reality { 5 | class AnimationStateMachine; 6 | 7 | struct DLL_API Transition { 8 | Transition(int to_state_id, function condition) 9 | : to_state_id_(to_state_id), 10 | condition_(condition) 11 | { 12 | 13 | } 14 | int to_state_id_; 15 | function condition_; 16 | }; 17 | } -------------------------------------------------------------------------------- /Engine/src/Core/DX11App.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reality-soft/Game-Engine/3e539944ccfbea2be4b24d2c1a1e26cb338e9ea5/Engine/src/Core/DX11App.cpp -------------------------------------------------------------------------------- /Engine/src/Core/DX11App.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reality-soft/Game-Engine/3e539944ccfbea2be4b24d2c1a1e26cb338e9ea5/Engine/src/Core/DX11App.h -------------------------------------------------------------------------------- /Engine/src/Core/DXStates.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reality-soft/Game-Engine/3e539944ccfbea2be4b24d2c1a1e26cb338e9ea5/Engine/src/Core/DXStates.cpp -------------------------------------------------------------------------------- /Engine/src/Core/DXStates.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace reality 4 | { 5 | class DLL_API DXStates 6 | { 7 | public: 8 | static ID3D11BlendState* bs_default(); 9 | static ID3D11BlendState* bs_alpha_blending(); 10 | static ID3D11BlendState* bs_alpha_to_coverage_enable(); 11 | static ID3D11BlendState* bs_dual_source_blend(); 12 | static ID3D11BlendState* bs_blend_higher_rgb(); 13 | 14 | 15 | static ID3D11DepthStencilState* ds_defalut(); 16 | static ID3D11DepthStencilState* ds_depth_enable_no_write(); 17 | static ID3D11DepthStencilState* ds_depth_disable(); 18 | 19 | 20 | static ID3D11RasterizerState* rs_solid_cull_none(); 21 | static ID3D11RasterizerState* rs_solid_cull_back(); 22 | static ID3D11RasterizerState* rs_solid_cull_front(); 23 | static ID3D11RasterizerState* rs_wireframe_cull_none(); 24 | static ID3D11RasterizerState* rs_wireframe_cull_back(); 25 | static ID3D11RasterizerState* rs_wireframe_cull_front(); 26 | 27 | 28 | static ID3D11SamplerState* ss_defalut(); 29 | }; 30 | } 31 | 32 | 33 | -------------------------------------------------------------------------------- /Engine/src/Core/Engine.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Engine.h" 3 | #include "ResourceMgr.h" 4 | #include "GUIMgr.h" 5 | #include "EventMgr.h" 6 | #include "InputEventMgr.h" 7 | #include "SceneMgr.h" 8 | #include "FmodMgr.h" 9 | #include "WriteMgr.h" 10 | 11 | #ifdef _DEBUG 12 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 13 | #endif 14 | 15 | LRESULT CALLBACK WindowProc( 16 | HWND hWnd, 17 | UINT msg, 18 | WPARAM wParam, 19 | LPARAM lParam) 20 | { 21 | #ifdef _DEBUG 22 | if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam)) 23 | return true; 24 | #endif 25 | 26 | switch (msg) 27 | { 28 | case WM_DESTROY: 29 | PostQuitMessage(0); 30 | return 0; 31 | 32 | case WM_SIZE: 33 | //ENGINE->OnResized(); 34 | break; 35 | 36 | #ifdef _DEBUG 37 | case WM_DPICHANGED: 38 | if (ImGui::GetCurrentContext() != nullptr && ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_DpiEnableScaleViewports) 39 | { 40 | //const int dpi = HIWORD(wParam); 41 | //printf("WM_DPICHANGED to %d (%.0f%%)\n", dpi, (float)dpi / 96.0f * 100.0f); 42 | const RECT* suggested_rect = (RECT*)lParam; 43 | ::SetWindowPos(hWnd, NULL, suggested_rect->left, suggested_rect->top, suggested_rect->right - suggested_rect->left, suggested_rect->bottom - suggested_rect->top, SWP_NOZORDER | SWP_NOACTIVATE); 44 | } 45 | break; 46 | #endif 47 | } 48 | return DefWindowProc(hWnd, msg, wParam, lParam); 49 | } 50 | 51 | namespace reality { 52 | bool Engine::OnInit(HINSTANCE hinstance, LPCWSTR title, E_Resolution resolution, bool titlebar) 53 | { 54 | POINT screen_size = { 0, 0 }; 55 | 56 | current_resolution = resolution; 57 | 58 | screen_size = E_Resolution_Size[resolution]; 59 | 60 | // À©µµ¿ì ÃʱâÈ­ 61 | if (InitWindow(hinstance, title, screen_size, titlebar) == false) 62 | return false; 63 | 64 | // DX ÃʱâÈ­ 65 | if (DX11APP->OnInit(screen_size, hwnd) == false) 66 | return false; 67 | 68 | #ifdef _DEBUG 69 | GUI->Init(ENGINE->GetWindowHandle(), DX11APP->GetDevice(), DX11APP->GetDeviceContext()); 70 | #endif 71 | DINPUT->Init(); 72 | TIMER->Init(); 73 | FMOD_MGR->Init(); 74 | WRITER->Init(); 75 | 76 | return true; 77 | } 78 | 79 | void Engine::Run() 80 | { 81 | bool done = false; 82 | while (!done) 83 | { 84 | MSG msg; 85 | while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) 86 | { 87 | ::TranslateMessage(&msg); 88 | ::DispatchMessage(&msg); 89 | if (msg.message == WM_QUIT) 90 | done = true; 91 | } 92 | if (done) 93 | break; 94 | 95 | // Updates 96 | TIMER->Update(); 97 | DINPUT->Update(); 98 | INPUT_EVENT->PollEvents(); 99 | SCENE_MGR->OnUpdate(); 100 | EVENT->ProcessEvents(); 101 | FMOD_MGR->Update(); 102 | 103 | // Render Here 104 | DX11APP->PreRender(true, true, true); 105 | 106 | SCENE_MGR->OnRender(); 107 | 108 | DX11APP->PostRender(false); 109 | } 110 | } 111 | 112 | void Engine::OnResized() 113 | { 114 | RECT new_rc; 115 | GetClientRect(hwnd, &new_rc); 116 | wnd_size.x = new_rc.right - new_rc.left; 117 | wnd_size.y = new_rc.bottom - new_rc.top; 118 | 119 | DX11APP->Resize(wnd_size.x, wnd_size.y); 120 | } 121 | 122 | void Engine::OnRelease() 123 | { 124 | FMOD_MGR->Release(); 125 | DX11APP->OnRelease(); 126 | } 127 | 128 | void Engine::Resize(E_Resolution new_resolution) 129 | { 130 | current_resolution = new_resolution; 131 | 132 | POINT screen_size = E_Resolution_Size[new_resolution]; 133 | 134 | int x = GetSystemMetrics(SM_CXSCREEN) / 2 - screen_size.x / 2; 135 | int y = GetSystemMetrics(SM_CYSCREEN) / 2 - screen_size.y / 2; 136 | 137 | SetWindowPos(hwnd, NULL, x, y, screen_size.x, screen_size.y, SWP_NOZORDER | SWP_FRAMECHANGED); 138 | 139 | RECT new_rc; 140 | GetClientRect(hwnd, &new_rc); 141 | wnd_size.x = new_rc.right - new_rc.left; 142 | wnd_size.y = new_rc.bottom - new_rc.top; 143 | 144 | DX11APP->Resize(wnd_size.x, wnd_size.y); 145 | 146 | } 147 | 148 | bool Engine::InitWindow(HINSTANCE hinstance, LPCWSTR title, POINT screen_size, bool titlebar) 149 | { 150 | this->hinstance = hinstance; 151 | this->title = title; 152 | 153 | auto style = titlebar ? WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME : WS_POPUP; 154 | 155 | RECT rc = { 0, 0, screen_size.x, screen_size.y }; 156 | AdjustWindowRect(&rc, style, false); 157 | this->wnd_size.x = rc.right - rc.left; 158 | this->wnd_size.y = rc.bottom - rc.top; 159 | 160 | WNDCLASS window_class; 161 | ZeroMemory(&window_class, sizeof(window_class)); 162 | 163 | window_class.hInstance = hinstance; 164 | window_class.lpszClassName = title; 165 | window_class.hIcon = LoadIcon(nullptr, IDI_APPLICATION); 166 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); 167 | window_class.style = CS_HREDRAW | CS_VREDRAW; 168 | window_class.lpfnWndProc = WindowProc; 169 | 170 | if (RegisterClass(&window_class) == false) 171 | return false; 172 | 173 | hwnd = CreateWindow( 174 | window_class.lpszClassName, 175 | title, 176 | style, 177 | GetSystemMetrics(SM_CXSCREEN) / 2 - wnd_size.x / 2, 178 | GetSystemMetrics(SM_CYSCREEN) / 2 - wnd_size.y / 2, 179 | wnd_size.x, wnd_size.y, 180 | NULL, NULL, 181 | hinstance, 182 | NULL); 183 | 184 | if (hwnd == nullptr) 185 | return false; 186 | 187 | ShowWindow(hwnd, SW_SHOW); 188 | UpdateWindow(hwnd); 189 | 190 | return true; 191 | } 192 | } 193 | 194 | -------------------------------------------------------------------------------- /Engine/src/Core/Engine.h: -------------------------------------------------------------------------------- 1 | #include "DX11App.h" 2 | 3 | namespace reality { 4 | 5 | enum E_Resolution 6 | { 7 | RPOP = 0, 8 | R1920x1080 = 1, 9 | R1280x720 = 2, 10 | RESOLUTION_COUNT, 11 | }; 12 | 13 | static const string E_Resolution_String[] = { "POP", "1920 X 1080", "1280 X 720" }; 14 | static POINT E_Resolution_Size[] = { { 600, 400 }, { 1920, 1080 }, { 1280, 720 } }; 15 | static const float E_Resolution_Multiply[] = { 1.0f, 1.0f, 2.0f / 3.0f }; 16 | 17 | class DLL_API Engine 18 | { 19 | SINGLETON(Engine) 20 | #define ENGINE reality::Engine::GetInst() 21 | 22 | public: 23 | bool OnInit(HINSTANCE hinstance, LPCWSTR title, E_Resolution resolution, bool titlebar); 24 | void Run(); 25 | void OnResized(); 26 | void OnRelease(); 27 | void Resize(E_Resolution new_resolution); 28 | 29 | private: 30 | HINSTANCE hinstance; 31 | LPCWSTR title; 32 | HWND hwnd; 33 | POINT wnd_size; 34 | E_Resolution current_resolution; 35 | 36 | public: 37 | POINT GetWindowSize() { return wnd_size; } 38 | HINSTANCE GetInstanceHandle() { return hinstance; } 39 | HWND GetWindowHandle() { return hwnd; } 40 | E_Resolution GetWindowResolution() { return current_resolution; } 41 | private: 42 | bool InitWindow(HINSTANCE hinstance, LPCWSTR title, POINT screen_size, bool titlebar); 43 | }; 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /Engine/src/DataTypes/ConstantBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | namespace reality 5 | { 6 | struct SocketTransform { 7 | XMMATRIX owner_local = XMMatrixIdentity(); 8 | XMMATRIX local_offset = XMMatrixIdentity(); 9 | XMMATRIX animation_matrix = XMMatrixIdentity(); 10 | }; 11 | 12 | struct CbTransform 13 | { 14 | CbTransform() 15 | { 16 | data.transform_matrix = XMMatrixIdentity(); 17 | } 18 | CbTransform(const CbTransform& other) 19 | { 20 | data = other.data; 21 | other.buffer.CopyTo(buffer.GetAddressOf()); 22 | } 23 | struct Data 24 | { 25 | XMMATRIX transform_matrix; 26 | } data; 27 | 28 | ComPtr buffer; 29 | }; 30 | 31 | struct CbStaticMesh 32 | { 33 | CbStaticMesh() = default; 34 | CbStaticMesh(const CbStaticMesh& other) 35 | { 36 | data = other.data; 37 | other.buffer.CopyTo(buffer.GetAddressOf()); 38 | } 39 | struct Data 40 | { 41 | XMMATRIX transform_matrix; 42 | XMMATRIX socket_matrix; 43 | } data; 44 | ComPtr buffer; 45 | }; 46 | 47 | 48 | struct CbSkeletalMesh 49 | { 50 | CbSkeletalMesh() = default; 51 | CbSkeletalMesh(const CbSkeletalMesh& other) 52 | { 53 | data = other.data; 54 | other.buffer.CopyTo(buffer.GetAddressOf()); 55 | } 56 | struct Data 57 | { 58 | XMMATRIX transform_matrix; 59 | XMMATRIX animation[128]; 60 | } data; 61 | ComPtr buffer; 62 | }; 63 | 64 | struct CbCameraInfo 65 | { 66 | CbCameraInfo() 67 | { 68 | data.view_proj_matrix = XMMatrixIdentity(); 69 | data.camera_translation = XMMatrixIdentity(); 70 | data.camera_position = XMVectorZero(); 71 | data.camera_look = XMVectorZero(); 72 | } 73 | CbCameraInfo(const CbCameraInfo& other) 74 | { 75 | data = other.data; 76 | other.buffer.CopyTo(buffer.GetAddressOf()); 77 | } 78 | struct Data 79 | { 80 | XMMATRIX view_proj_matrix; 81 | XMMATRIX camera_translation; 82 | XMVECTOR camera_position; 83 | XMVECTOR camera_look; 84 | } data; 85 | ComPtr buffer; 86 | }; 87 | 88 | struct CbCameraEffect 89 | { 90 | CbCameraEffect() 91 | { 92 | data.main_billboard = XMMatrixIdentity(); 93 | } 94 | CbCameraEffect(const CbCameraEffect& other) 95 | { 96 | data = other.data; 97 | other.buffer.CopyTo(buffer.GetAddressOf()); 98 | } 99 | struct Data 100 | { 101 | XMMATRIX view_matrix; 102 | XMMATRIX projection_matrix; 103 | XMMATRIX main_billboard; 104 | XMMATRIX x_billboard; 105 | XMMATRIX y_billboard; 106 | } data; 107 | ComPtr buffer; 108 | }; 109 | 110 | struct CbSkySphere 111 | { 112 | CbSkySphere() 113 | { 114 | data.sky_color = { 0, 0, 0, 0 }; 115 | data.gradation = { 0, 0, 0, 0 }; 116 | } 117 | struct Data 118 | { 119 | XMFLOAT4 sky_color; 120 | XMFLOAT4 gradation; 121 | } data; 122 | 123 | ComPtr buffer; 124 | }; 125 | 126 | struct CbFog 127 | { 128 | CbFog() 129 | { 130 | data.fog_color = { 1, 1, 1, 1 }; 131 | data.fog_start = { 0, 0, 0 }; 132 | data.distance = 5000; 133 | } 134 | struct Data 135 | { 136 | XMFLOAT4 fog_color; 137 | XMFLOAT3 fog_start; 138 | float distance; 139 | } data; 140 | 141 | ComPtr buffer; 142 | }; 143 | 144 | struct CbGlobalLight 145 | { 146 | CbGlobalLight() 147 | { 148 | data.position = XMFLOAT4(5000, 5000, -5000, 0); 149 | data.light_color = XMFLOAT4(1, 1, 1, 1); 150 | 151 | data.direction = XMFLOAT3((-1.0f * XMVector3Normalize(XMLoadFloat4(&data.position))).m128_f32); 152 | data.specular_strength = 1.0f; 153 | 154 | data.ambient_up = XMLoadFloat3(&data.direction) * 0.8; 155 | data.ambient_down = XMLoadFloat3(&data.direction) * 0.2f; 156 | data.ambient_range = Vector3Length(data.ambient_up - data.ambient_down); 157 | } 158 | CbGlobalLight(const CbGlobalLight& other) 159 | { 160 | data = other.data; 161 | other.buffer.CopyTo(buffer.GetAddressOf()); 162 | } 163 | struct Data 164 | { 165 | XMFLOAT4 position; 166 | XMFLOAT4 light_color; 167 | 168 | XMFLOAT3 direction; 169 | float specular_strength; 170 | 171 | XMVECTOR ambient_up; 172 | XMVECTOR ambient_down; 173 | float ambient_range; 174 | } data; 175 | 176 | ComPtr buffer; 177 | }; 178 | 179 | struct CbPointLight 180 | { 181 | struct Data 182 | { 183 | XMFLOAT4 light_color; 184 | 185 | XMFLOAT3 position; 186 | float range; 187 | XMFLOAT3 attenuation; 188 | float specular; 189 | } data[64]; 190 | 191 | ComPtr buffer; 192 | 193 | CbPointLight() 194 | { 195 | ZeroMemory(data, sizeof(Data) * 64); 196 | } 197 | 198 | }; 199 | 200 | struct CbSpotLight 201 | { 202 | struct Data 203 | { 204 | XMFLOAT4 light_color; 205 | 206 | XMFLOAT3 position; 207 | float range; 208 | XMFLOAT3 attenuation; 209 | float specular; 210 | XMFLOAT3 direction; 211 | float spot; 212 | } data[64]; 213 | 214 | ComPtr buffer; 215 | 216 | CbSpotLight() 217 | { 218 | ZeroMemory(data, sizeof(Data) * 64); 219 | } 220 | }; 221 | 222 | } -------------------------------------------------------------------------------- /Engine/src/DataTypes/Skeleton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | namespace reality { 5 | struct Bone { 6 | UINT bone_id; 7 | UINT parent_bone_id = -1; 8 | vector child_bone_ids; 9 | }; 10 | 11 | struct Skeleton 12 | { 13 | Skeleton() = default; 14 | Skeleton(const Skeleton& other); 15 | 16 | map bind_pose_matrices; 17 | map id_bone_map; 18 | map bone_name_id_map; 19 | 20 | unordered_map GetSubBonesOf(string bone_name, int range) { 21 | unordered_map out_id_weight_map; 22 | 23 | queue> cur_bone_ids; 24 | 25 | UINT center_bone_id = bone_name_id_map[bone_name]; 26 | 27 | cur_bone_ids.push({ 0, center_bone_id }); 28 | while (true) { 29 | if (cur_bone_ids.empty()) { 30 | break; 31 | } 32 | 33 | int cur_bone_depth = cur_bone_ids.front().first; 34 | UINT cur_bone_id = cur_bone_ids.front().second; 35 | cur_bone_ids.pop(); 36 | 37 | if (id_bone_map.find(cur_bone_id) == id_bone_map.end()) { 38 | continue; 39 | } 40 | for (const auto& child_bone_id : id_bone_map[cur_bone_id].child_bone_ids) { 41 | int child_bone_depth = cur_bone_depth + 1; 42 | cur_bone_ids.push({ child_bone_depth, child_bone_id }); 43 | 44 | child_bone_depth = min(child_bone_depth, range); 45 | out_id_weight_map.insert({ child_bone_id, child_bone_depth + range }); 46 | } 47 | } 48 | 49 | UINT cur_bone_id = id_bone_map[center_bone_id].parent_bone_id; 50 | for (int i = 1;i < range;i++) { 51 | if (cur_bone_id == -1) { 52 | break; 53 | } 54 | out_id_weight_map.insert({ cur_bone_id, 0 - i + range }); 55 | cur_bone_id = id_bone_map[cur_bone_id].parent_bone_id; 56 | } 57 | 58 | return out_id_weight_map; 59 | } 60 | }; 61 | } -------------------------------------------------------------------------------- /Engine/src/DataTypes/Socket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | struct Socket { 5 | public: 6 | Socket(UINT bone_id, XMMATRIX owner_local, XMMATRIX local_offset = XMMatrixIdentity()) : 7 | bone_id(bone_id), 8 | owner_local(owner_local), 9 | local_offset(local_offset) {}; 10 | Socket() {}; 11 | 12 | public: 13 | int bone_id; 14 | XMMATRIX owner_local; 15 | XMMATRIX local_offset; 16 | XMMATRIX animation_matrix; 17 | }; -------------------------------------------------------------------------------- /Engine/src/DataTypes/Sound.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | namespace reality 5 | { 6 | // Sound 7 | 8 | enum SoundType 9 | { 10 | SFX, 11 | MUSIC, 12 | }; 13 | 14 | struct Sound 15 | { 16 | string sound_filename; 17 | SoundType type; 18 | bool looping; 19 | FMOD::Channel* channel; 20 | FMOD::Sound* sound; 21 | UINT total_time; 22 | UINT current_time; 23 | float constant_volume; 24 | public: 25 | Sound() : sound_filename(""), channel(nullptr), sound(nullptr), total_time(0), current_time(0) { } 26 | Sound(Sound& sound) = default; 27 | }; 28 | 29 | struct SoundQueue 30 | { 31 | string sound_filename; 32 | SoundType sound_type; 33 | float sound_volume; 34 | bool is_looping; 35 | }; 36 | } -------------------------------------------------------------------------------- /Engine/src/DataTypes/StructuredBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "DX11App.h" 3 | #include "StructuredBuffer.h" 4 | 5 | 6 | using namespace reality; 7 | 8 | bool reality::StructuredSRV::Create(void* p_data) 9 | { 10 | HRESULT hr = S_OK; 11 | 12 | D3D11_BUFFER_DESC buffer_desc; 13 | D3D11_SUBRESOURCE_DATA subdata; 14 | 15 | ZeroMemory(&buffer_desc, sizeof(buffer_desc)); 16 | ZeroMemory(&subdata, sizeof(subdata)); 17 | buffer_desc.ByteWidth = byte_width; 18 | buffer_desc.Usage = D3D11_USAGE_DEFAULT; 19 | buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 20 | buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; 21 | buffer_desc.StructureByteStride = byte_stride; 22 | 23 | subdata.pSysMem = p_data; 24 | subdata.SysMemPitch = 0; 25 | subdata.SysMemSlicePitch = 0; 26 | 27 | hr = DX11APP->GetDevice()->CreateBuffer(&buffer_desc, &subdata, buffer.GetAddressOf()); 28 | if (FAILED(hr)) 29 | return false; 30 | 31 | D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc; 32 | ZeroMemory(&srv_desc, sizeof(srv_desc)); 33 | 34 | srv_desc.Format = DXGI_FORMAT_UNKNOWN; 35 | srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; 36 | srv_desc.Buffer.ElementWidth = byte_stride; 37 | srv_desc.Buffer.NumElements = byte_width / byte_stride; 38 | 39 | hr = DX11APP->GetDevice()->CreateShaderResourceView(buffer.Get(), &srv_desc, srv.GetAddressOf()); 40 | if (FAILED(hr)) 41 | return false; 42 | 43 | return true; 44 | } 45 | 46 | bool reality::StructuredUAV::Create(void* p_data) 47 | { 48 | HRESULT hr = S_OK; 49 | 50 | D3D11_BUFFER_DESC buffer_desc; 51 | D3D11_SUBRESOURCE_DATA subdata; 52 | 53 | ZeroMemory(&buffer_desc, sizeof(buffer_desc)); 54 | ZeroMemory(&subdata, sizeof(subdata)); 55 | buffer_desc.ByteWidth = byte_width; 56 | buffer_desc.Usage = D3D11_USAGE_DEFAULT; 57 | buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS; 58 | buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; 59 | buffer_desc.StructureByteStride = byte_stride; 60 | 61 | subdata.pSysMem = p_data; 62 | subdata.SysMemPitch = 0; 63 | subdata.SysMemSlicePitch = 0; 64 | 65 | hr = DX11APP->GetDevice()->CreateBuffer(&buffer_desc, &subdata, buffer.GetAddressOf()); 66 | if (FAILED(hr)) 67 | return false; 68 | 69 | D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc; 70 | ZeroMemory(&uav_desc, sizeof(uav_desc)); 71 | 72 | uav_desc.Format = DXGI_FORMAT_UNKNOWN; 73 | uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER; 74 | uav_desc.Buffer.NumElements = byte_width / byte_stride; 75 | 76 | hr = DX11APP->GetDevice()->CreateUnorderedAccessView(buffer.Get(), &uav_desc, uav.GetAddressOf()); 77 | if (FAILED(hr)) 78 | return false; 79 | 80 | return true; 81 | } 82 | 83 | void reality::SbTriangleCollision::SetElementArraySize(UINT size) 84 | { 85 | elements.resize(size); 86 | 87 | for (auto& e : elements) 88 | { 89 | e.including_node = 0; 90 | e.normal = { 0, 0, 0 }; 91 | e.vertex0 = { 0, 0, 0 }; 92 | e.vertex1 = { 0, 0, 0 }; 93 | e.vertex2 = { 0, 0, 0 }; 94 | } 95 | 96 | byte_stride = sizeof(SbTriangleCollision::Data); 97 | byte_width = elements.size() * byte_stride; 98 | } 99 | 100 | void reality::SbCapsuleCollision::SetElementArraySize(UINT size) 101 | { 102 | elements.resize(size); 103 | 104 | for (auto& e : elements) 105 | { 106 | e.radius = 0; 107 | e.point_a = { 0 ,0, 0 }; 108 | e.point_b = { 0, 0, 0 }; 109 | } 110 | 111 | byte_stride = sizeof(SbCapsuleCollision::Data); 112 | byte_width = elements.size() * byte_stride; 113 | } 114 | 115 | void reality::SbSphereCollision::SetElementArraySize(UINT size) 116 | { 117 | elements.resize(size); 118 | 119 | for (auto& e : elements) 120 | { 121 | e.radius = 0; 122 | e.center = { 0 ,0, 0 }; 123 | } 124 | 125 | byte_stride = sizeof(SbSphereCollision::Data); 126 | byte_width = elements.size() * byte_stride; 127 | } 128 | 129 | 130 | void reality::SbCollisionResult::SetElementArraySize(UINT size) 131 | { 132 | elements.resize(size); 133 | 134 | for (auto& e : elements) 135 | { 136 | e.capsule_result.entity = 0; 137 | e.capsule_result.collide_type = 0; 138 | e.capsule_result.floor_position = { 0, 0, 0 }; 139 | ZeroMemory(&e.capsule_result.wall_planes, sizeof(e.capsule_result.wall_planes)); 140 | 141 | e.sphere_result.entity = 0; 142 | e.sphere_result.tri_normal = { 0, 0, 0 }; 143 | } 144 | 145 | byte_stride = sizeof(SbCollisionResult::Data); 146 | byte_width = elements.size() * byte_stride; 147 | } -------------------------------------------------------------------------------- /Engine/src/DataTypes/StructuredBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace reality 4 | { 5 | class StructuredSRV 6 | { 7 | public: 8 | virtual bool Create(void* p_data); 9 | 10 | public: 11 | size_t byte_stride = 0; 12 | size_t byte_width = 0; 13 | 14 | ComPtr buffer; 15 | ComPtr srv; 16 | }; 17 | 18 | class StructuredUAV 19 | { 20 | public: 21 | virtual bool Create(void* p_data); 22 | 23 | public: 24 | size_t byte_stride = 0; 25 | size_t byte_width = 0; 26 | 27 | ComPtr buffer; 28 | ComPtr uav; 29 | }; 30 | 31 | class SbTriangleCollision : public StructuredSRV 32 | { 33 | public: 34 | struct Data 35 | { 36 | UINT including_node; 37 | XMFLOAT3 normal; 38 | XMFLOAT3 vertex0, vertex1, vertex2; 39 | }; 40 | 41 | public: 42 | void SetElementArraySize(UINT size); 43 | vector elements; 44 | }; 45 | 46 | class SbCapsuleCollision : public StructuredSRV 47 | { 48 | public: 49 | struct Data 50 | { 51 | float radius; 52 | XMFLOAT3 point_a; 53 | XMFLOAT3 point_b; 54 | int entity; 55 | int node_numbers[4]; 56 | }; 57 | 58 | public: 59 | void SetElementArraySize(UINT size); 60 | vector elements; 61 | }; 62 | 63 | class SbSphereCollision : public StructuredSRV 64 | { 65 | public: 66 | struct Data 67 | { 68 | float radius; 69 | XMFLOAT3 center; 70 | int entity; 71 | int node_numbers[4]; 72 | }; 73 | 74 | public: 75 | void SetElementArraySize(UINT size); 76 | vector elements; 77 | }; 78 | 79 | class SbCollisionResult : public StructuredUAV 80 | { 81 | public: 82 | struct Data 83 | { 84 | struct CapsuleResult 85 | { 86 | int entity; 87 | int collide_type; 88 | 89 | XMFLOAT3 floor_position; 90 | XMFLOAT4 wall_planes[4]; 91 | } capsule_result; 92 | 93 | struct SphereResult 94 | { 95 | int entity; 96 | int is_collide; 97 | XMFLOAT3 tri_normal; 98 | } sphere_result; 99 | 100 | }; 101 | 102 | public: 103 | void SetElementArraySize(UINT size); 104 | vector elements; 105 | }; 106 | } -------------------------------------------------------------------------------- /Engine/src/DataTypes/UI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | #include "Vertex.h" 4 | 5 | namespace reality 6 | { 7 | // UI 8 | enum class E_UIState 9 | { 10 | UI_NORMAL = 0, 11 | UI_HOVER = 1, 12 | UI_PUSH = 2, 13 | UI_SELECT = 3, 14 | UI_DISABLED = 4, 15 | }; 16 | 17 | struct Rect 18 | { 19 | XMFLOAT2 min; 20 | XMFLOAT2 max; 21 | XMFLOAT2 center; 22 | float width; 23 | float height; 24 | void SetRectByMin(XMFLOAT2 min, float width, float height) 25 | { 26 | this->min = min; 27 | this->width = width; 28 | this->height = height; 29 | this->max = { min.x + width, min.y + height }; 30 | this->center = { min.x + width / 2.0f, min.y + height / 2.0f }; 31 | } 32 | 33 | void SetRectByMax(XMFLOAT2 max, float width, float height) 34 | { 35 | this->max = max; 36 | this->width = width; 37 | this->height = height; 38 | this->min = { max.x - width, max.y - height }; 39 | this->center = { max.x - width / 2.0f, max.y - height / 2.0f }; 40 | } 41 | 42 | void SetRectByCenter(XMFLOAT2 center, float width, float height) 43 | { 44 | this->center = center; 45 | this->width = width; 46 | this->height = height; 47 | this->min = { center.x - width / 2.0f, center.y - width / 2.0f }; 48 | this->max = { center.x + width / 2.0f, center.y + width / 2.0f }; 49 | } 50 | 51 | void SetRectByMinMax(XMFLOAT2 min, XMFLOAT2 max) 52 | { 53 | this->min = min; 54 | this->max = max; 55 | this->width = max.x - min.x; 56 | this->height = max.y - min.y; 57 | this->center = { min.x + (this->width / 2.0f), min.y + (this->height / 2.0f) }; 58 | } 59 | }; 60 | 61 | struct CbUI 62 | { 63 | __declspec(align(16)) struct Data 64 | { 65 | XMMATRIX world; 66 | } data; 67 | ComPtr buffer; 68 | }; 69 | 70 | struct RectTransform 71 | { 72 | Rect world_rect; 73 | Rect local_rect; 74 | XMMATRIX local_matrix; 75 | XMMATRIX world_matrix; 76 | }; 77 | 78 | struct RectRenderData 79 | { 80 | string vs_id; 81 | string ps_id; 82 | string tex_id; 83 | vector vertex_list; 84 | ComPtr vertex_buffer; 85 | vector index_list; 86 | ComPtr index_buffer; 87 | }; 88 | } -------------------------------------------------------------------------------- /Engine/src/DataTypes/Vertex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | 4 | namespace reality 5 | { 6 | struct Vertex 7 | { 8 | XMFLOAT3 p; 9 | XMFLOAT3 n; 10 | XMFLOAT2 t; 11 | }; 12 | 13 | struct SkinnedVertex 14 | { 15 | XMFLOAT3 p; 16 | XMFLOAT3 n; 17 | XMFLOAT4 c; 18 | XMFLOAT2 t; 19 | XMFLOAT4 i; 20 | XMFLOAT4 w; 21 | 22 | SkinnedVertex operator =(const Vertex& vertex) 23 | { 24 | this->p = vertex.p; 25 | this->n = vertex.n; 26 | this->t = vertex.t; 27 | 28 | return *this; 29 | } 30 | }; 31 | 32 | struct EffectVertex 33 | { 34 | XMFLOAT3 p; 35 | XMFLOAT4 c; 36 | XMFLOAT2 t; 37 | }; 38 | 39 | struct UIVertex 40 | { 41 | XMFLOAT2 p; 42 | XMFLOAT4 c; 43 | XMFLOAT2 t; 44 | }; 45 | } -------------------------------------------------------------------------------- /Engine/src/Engine_include.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Managers/ResourceMgr.h" 4 | #include "Managers/EffectMgr.h" 5 | #include "Scene/SceneMgr.h" 6 | #include "Event/EventMgr.h" 7 | #include "Input/InputEventMgr.h" 8 | #include "Input/InputMgr.h" 9 | #include "Sound/FmodMgr.h" 10 | #include "Core/Engine.h" 11 | 12 | #include "AI/BehaviorTree.h" 13 | #include "AI/BehaviorTreeNodes.h" 14 | 15 | #include "Systems/AnimationSystem.h" 16 | #include "Systems/RenderSystem.h" 17 | #include "Systems/CameraSystem.h" 18 | #include "Systems/SoundSystem.h" 19 | #include "Systems/LightingSystem.h" 20 | #include "Systems/EffectSystem.h" 21 | #include "Systems/MovementSystem.h" 22 | #include "Systems/UISystem.h" 23 | 24 | #include "Tools/GUIMgr.h" 25 | #include "Physics/QuadTreeMgr.h" 26 | 27 | #include "Actors/Actor.h" 28 | #include "Actors/Character.h" 29 | #include "Actors/FX_BaseEffectActor.h" 30 | #include "Actors/UIActor.h" 31 | 32 | #include "World/Level.h" 33 | #include "World/Environment.h" 34 | #include "World/StaticMeshLevel.h" 35 | 36 | #include "UI/WriteMgr.h" 37 | -------------------------------------------------------------------------------- /Engine/src/Event/EventMgr.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "EventMgr.h" 3 | 4 | void reality::EventMgr::ProcessEvents() 5 | { 6 | while (!event_queue_.empty()) { 7 | Event* cur_event = event_queue_.front().get(); 8 | 9 | cur_event->Process(); 10 | 11 | event_queue_.pop(); 12 | } 13 | } -------------------------------------------------------------------------------- /Engine/src/Event/EventMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Events.h" 3 | 4 | namespace reality { 5 | class DLL_API EventMgr 6 | { 7 | SINGLETON(EventMgr) 8 | #define EVENT EventMgr::GetInst() 9 | queue> event_queue_; 10 | 11 | public: 12 | void ProcessEvents(); 13 | public: 14 | template 15 | void PushEvent(Args&&...args) 16 | { 17 | event_queue_.push(make_shared(args...)); 18 | } 19 | void PushEvent(shared_ptr event) 20 | { 21 | event_queue_.push(event); 22 | } 23 | }; 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /Engine/src/Event/Events.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Events.h" 3 | -------------------------------------------------------------------------------- /Engine/src/Event/Events.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SceneMgr.h" 4 | #include "Character.h" 5 | 6 | namespace reality { 7 | class DLL_API Event 8 | { 9 | public: 10 | Event() {}; 11 | virtual void Process() {}; 12 | }; 13 | 14 | class DLL_API MovementEvent : public Event { 15 | public: 16 | MovementEvent(XMVECTOR movement_vector, entt::entity actor_id) { 17 | movement_vector_ = movement_vector; 18 | actor_id_ = actor_id; 19 | } 20 | 21 | virtual void Process() override { 22 | }; 23 | private: 24 | XMVECTOR movement_vector_; 25 | entt::entity actor_id_; 26 | }; 27 | 28 | class DLL_API DeleteActorEvent : public Event { 29 | public: 30 | DeleteActorEvent(entt::entity actor_id) { 31 | actor_id_ = actor_id; 32 | } 33 | 34 | virtual void Process() override { 35 | SCENE_MGR->DestroyActor(actor_id_); 36 | }; 37 | private: 38 | entt::entity actor_id_; 39 | }; 40 | 41 | class DLL_API CameraShakeEvent : public Event { 42 | public: 43 | CameraShakeEvent(entt::entity actor_id, float shake_time, float magnitude, float frequency) 44 | { 45 | actor_id_ = actor_id; 46 | shake_time_ = shake_time; 47 | magnitude_ = magnitude; 48 | frequency_ = frequency; 49 | } 50 | 51 | virtual void Process() override { 52 | auto camera = SCENE_MGR->GetRegistry().try_get(actor_id_); 53 | 54 | if (camera == nullptr) 55 | return; 56 | 57 | camera->is_shaking = true; 58 | camera->shaking_timer = 0.0f; 59 | camera->shake_time = shake_time_; 60 | camera->shake_magnitude = magnitude_; 61 | camera->shake_frequency = frequency_; 62 | } 63 | private: 64 | entt::entity actor_id_; 65 | float shake_time_; 66 | float magnitude_; 67 | float frequency_; 68 | }; 69 | } 70 | -------------------------------------------------------------------------------- /Engine/src/Headers/DllMacro.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef PLATFORM_WINDOWS 4 | #ifdef BUILD_DLL 5 | #define DLL_API __declspec(dllexport) 6 | #else 7 | #define DLL_API __declspec(dllimport) 8 | #endif 9 | #else 10 | #error only supports Windows 11 | #endif -------------------------------------------------------------------------------- /Engine/src/Headers/stdafx.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" -------------------------------------------------------------------------------- /Engine/src/Headers/stdafx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma warning(disable : 4275) 3 | #pragma warning(disable : 4819) 4 | #pragma warning(disable : 4267) 5 | #pragma warning(disable : 4101) 6 | #pragma warning(disable : 4251) 7 | #pragma warning(disable : 4244) 8 | #pragma warning(disable : 4099) 9 | #pragma warning(disable : 26495) 10 | #pragma warning(disable : 26451) 11 | 12 | #ifdef _DEBUG 13 | #include 14 | #endif 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #define _USE_MATH_DEFINES 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include "GlobalFunctions.h" 50 | #include "DllMacro.h" 51 | 52 | using namespace Microsoft::WRL; 53 | using namespace DirectX; 54 | using namespace std; 55 | 56 | #define SINGLETON(type)\ 57 | public:\ 58 | static type* GetInst()\ 59 | {\ 60 | static type mgr;\ 61 | return &mgr;\ 62 | }\ 63 | private:\ 64 | type() {}\ 65 | ~type() {}\ 66 | type(const type&) = delete;\ 67 | type& operator=(const type&) = delete; 68 | 69 | #define RGB_TO_FLOAT(r, g, b) XMFLOAT4(r / 256.f, g / 256.f, b / 256.f, 1.f) 70 | #define RGBA_TO_FLOAT(r, g, b, a) XMFLOAT4(r / 256.f, g / 256.f, b / 256.f, a / 256.f) 71 | 72 | #define _XMFLOAT4(xmvector) (DirectX::XMFLOAT4(xmvector.m128_f32)) 73 | #define _XMFLOAT3(xmvector) (DirectX::XMFLOAT3(xmvector.m128_f32)) 74 | #define _XMFLOAT2(xmvector) (DirectX::XMFLOAT2(xmvector.m128_f32)) 75 | 76 | #define _XMVECTOR4(xmfloat) (DirectX::XMLoadFloat4(&xmfloat)) 77 | #define _XMVECTOR3(xmfloat) (DirectX::XMLoadFloat3(&xmfloat)) 78 | #define _XMVECTOR2(xmfloat) (DirectX::XMLoadFloat2(&xmfloat)) 79 | 80 | #define TO_RAD(degree) (DirectX::XMConvertToRadians(degree)) 81 | -------------------------------------------------------------------------------- /Engine/src/Input/InputEventMgr.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "InputEventMgr.h" 3 | 4 | void reality::InputEventMgr::PollEvents() 5 | { 6 | for (auto& [key, callbacks] : push_subscribers_) { 7 | DWORD key_state = DINPUT->GetKeyState(key); 8 | if (key_state == reality::KEY_PUSH) { 9 | for (auto& callback : callbacks) { 10 | callback(); 11 | } 12 | } 13 | } 14 | 15 | for (auto& [key, callbacks] : free_subscribers_) { 16 | DWORD key_state = DINPUT->GetKeyState(key); 17 | if (key_state == reality::KEY_FREE) { 18 | for (auto& callback : callbacks) { 19 | callback(); 20 | } 21 | } 22 | } 23 | 24 | for (auto& [key, callbacks] : hold_subscribers_) { 25 | DWORD key_state = DINPUT->GetKeyState(key); 26 | if (key_state == reality::KEY_HOLD) { 27 | for (auto& callback : callbacks) { 28 | callback(); 29 | } 30 | } 31 | } 32 | 33 | for (auto& [key, callbacks] : up_subscribers_) { 34 | DWORD key_state = DINPUT->GetKeyState(key); 35 | if (key_state == reality::KEY_UP) { 36 | for (auto& callback : callbacks) { 37 | callback(); 38 | } 39 | } 40 | } 41 | 42 | for (auto& [key, callbacks] : mouse_push_subscribers_) { 43 | DWORD key_state = DINPUT->GetMouseState(key); 44 | if (key_state == reality::KEY_PUSH) { 45 | for (auto& callback : callbacks) { 46 | callback(); 47 | } 48 | } 49 | } 50 | 51 | for (auto& [key, callbacks] : mouse_free_subscribers_) { 52 | DWORD key_state = DINPUT->GetMouseState(key); 53 | if (key_state == reality::KEY_FREE) { 54 | for (auto& callback : callbacks) { 55 | callback(); 56 | } 57 | } 58 | } 59 | 60 | for (auto& [key, callbacks] : mouse_hold_subscribers_) { 61 | DWORD key_state = DINPUT->GetKeyState(key); 62 | if (key_state == reality::KEY_HOLD) { 63 | for (auto& callback : callbacks) { 64 | callback(); 65 | } 66 | } 67 | } 68 | 69 | for (auto& [key, callbacks] : mouse_up_subscribers_) { 70 | DWORD key_state = DINPUT->GetMouseState(static_cast(key)); 71 | if (key_state == reality::KEY_UP) { 72 | for (auto& callback : callbacks) { 73 | callback(); 74 | } 75 | } 76 | } 77 | } 78 | 79 | void reality::InputEventMgr::SubscribeKeyEvent(int key, std::function callback, DWORD key_state) 80 | { 81 | switch (key_state) { 82 | case reality::KEY_PUSH: 83 | push_subscribers_[key].push_back(callback); 84 | break; 85 | case reality::KEY_FREE: 86 | free_subscribers_[key].push_back(callback); 87 | break; 88 | case reality::KEY_HOLD: 89 | hold_subscribers_[key].push_back(callback); 90 | break; 91 | case reality::KEY_UP: 92 | up_subscribers_[key].push_back(callback); 93 | break; 94 | } 95 | } 96 | 97 | void reality::InputEventMgr::SubscribeMouseEvent(MouseButton key, const std::function& callback, DWORD key_state) 98 | { 99 | switch (key_state) { 100 | case reality::KEY_PUSH: 101 | mouse_push_subscribers_[key].push_back(callback); 102 | break; 103 | case reality::KEY_FREE: 104 | mouse_free_subscribers_[key].push_back(callback); 105 | break; 106 | case reality::KEY_HOLD: 107 | mouse_hold_subscribers_[key].push_back(callback); 108 | break; 109 | case reality::KEY_UP: 110 | mouse_up_subscribers_[key].push_back(callback); 111 | break; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Engine/src/Input/InputEventMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "InputMgr.h" 3 | 4 | namespace reality { 5 | class DLL_API InputEventMgr 6 | { 7 | SINGLETON(InputEventMgr) 8 | #define INPUT_EVENT InputEventMgr::GetInst() 9 | private: 10 | std::unordered_map>> push_subscribers_; 11 | std::unordered_map>> hold_subscribers_; 12 | std::unordered_map>> free_subscribers_; 13 | std::unordered_map>> up_subscribers_; 14 | 15 | private: 16 | std::unordered_map>> mouse_push_subscribers_; 17 | std::unordered_map>> mouse_hold_subscribers_; 18 | std::unordered_map>> mouse_free_subscribers_; 19 | std::unordered_map>> mouse_up_subscribers_; 20 | public: 21 | void PollEvents(); 22 | void SubscribeKeyEvent(int key, std::function callback, DWORD key_state); 23 | void SubscribeMouseEvent(MouseButton key, const std::function& callback, DWORD key_state); 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /Engine/src/Input/InputMgr.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "InputMgr.h" 3 | #include "Engine.h" 4 | 5 | using namespace reality; 6 | 7 | bool InputMgr::Init() 8 | { 9 | HRESULT hr; 10 | hr = DirectInput8Create(ENGINE->GetInstanceHandle(), DIRECTINPUT_HEADER_VERSION, IID_IDirectInput8, (void**)dinput.GetAddressOf(), nullptr); 11 | 12 | hr = dinput.Get()->CreateDevice(GUID_SysKeyboard, di_keyboard.GetAddressOf(), nullptr); 13 | hr = di_keyboard.Get()->SetDataFormat(&c_dfDIKeyboard); 14 | hr = di_keyboard.Get()->SetCooperativeLevel(ENGINE->GetWindowHandle(), DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); 15 | hr = di_keyboard.Get()->Acquire(); 16 | 17 | hr = dinput.Get()->CreateDevice(GUID_SysMouse, di_mouse.GetAddressOf(), nullptr); 18 | hr = di_mouse.Get()->SetDataFormat(&c_dfDIMouse); 19 | hr = di_mouse.Get()->SetCooperativeLevel(ENGINE->GetWindowHandle(), DISCL_FOREGROUND | DISCL_NONEXCLUSIVE); 20 | hr = di_mouse.Get()->Acquire(); 21 | 22 | for (int i = 0; i < 256; i++) { 23 | prev_keyboard_state[i] = KEY_FREE; 24 | } 25 | 26 | for (int i = 0; i < 4; i++) { 27 | prev_rgb_buttons[i] = KEY_FREE; 28 | } 29 | 30 | return true; 31 | } 32 | 33 | bool InputMgr::Update() 34 | { 35 | if (is_active == false) 36 | { 37 | di_keyboard->Unacquire(); 38 | di_mouse->Unacquire(); 39 | return false; 40 | } 41 | 42 | HRESULT hr = di_keyboard.Get()->GetDeviceState(sizeof(keyboard_state), (LPVOID)&keyboard_state); 43 | if (FAILED(hr)) 44 | { 45 | if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) 46 | di_keyboard->Acquire(); 47 | else 48 | return false; 49 | } 50 | 51 | for (int i = 0; i < 256; i++) { 52 | if (keyboard_state[i] & 0x80) { 53 | if (prev_keyboard_state[i] == KEY_FREE || prev_keyboard_state[i] == KEY_UP) { 54 | prev_keyboard_state[i] = KEY_PUSH; 55 | } 56 | else { 57 | prev_keyboard_state[i] = KEY_HOLD; 58 | } 59 | } 60 | else { 61 | if (prev_keyboard_state[i] == KEY_HOLD || prev_keyboard_state[i] == KEY_PUSH) { 62 | prev_keyboard_state[i] = KEY_UP; 63 | } 64 | else { 65 | prev_keyboard_state[i] = KEY_FREE; 66 | } 67 | } 68 | } 69 | 70 | hr = di_mouse.Get()->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouse_state); 71 | if (FAILED(hr)) 72 | { 73 | if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) 74 | di_mouse->Acquire(); 75 | else 76 | return false; 77 | } 78 | 79 | for (int i = 0; i < 4; i++) { 80 | if (mouse_state.rgbButtons[i] & 0x80) { 81 | if (prev_rgb_buttons[i] == KEY_FREE || prev_rgb_buttons[i] == KEY_UP) { 82 | prev_rgb_buttons[i] = KEY_PUSH; 83 | } 84 | else { 85 | prev_rgb_buttons[i] = KEY_HOLD; 86 | } 87 | } 88 | else { 89 | if (prev_rgb_buttons[i] == KEY_HOLD || prev_rgb_buttons[i] == KEY_PUSH) { 90 | prev_rgb_buttons[i] = KEY_UP; 91 | } 92 | else { 93 | prev_rgb_buttons[i] = KEY_FREE; 94 | } 95 | } 96 | } 97 | 98 | ::GetCursorPos(¤t_mousepos); 99 | ::ScreenToClient(ENGINE->GetWindowHandle(), ¤t_mousepos); 100 | 101 | return true; 102 | } 103 | 104 | KeyState reality::InputMgr::GetKeyState(DWORD input_key) 105 | { 106 | return prev_keyboard_state[input_key]; 107 | } 108 | 109 | KeyState reality::InputMgr::GetMouseState(MouseButton input_key) 110 | { 111 | return prev_rgb_buttons[input_key]; 112 | } 113 | 114 | POINT InputMgr::GetMousePosition() 115 | { 116 | return current_mousepos; 117 | } 118 | 119 | XMFLOAT2 InputMgr::GetMouseVelocity() 120 | { 121 | return XMFLOAT2(mouse_state.lX, mouse_state.lY); 122 | } 123 | 124 | int InputMgr::GetMouseWheel() 125 | { 126 | if (is_active == false) 127 | return mouse_state.lZ = 0; 128 | 129 | return mouse_state.lZ; 130 | } 131 | 132 | int reality::InputMgr::GetDeltaX() 133 | { 134 | return mouse_state.lX; 135 | } 136 | 137 | int reality::InputMgr::GetDeltaY() 138 | { 139 | return mouse_state.lY; 140 | } 141 | 142 | void reality::InputMgr::Active(bool shoud_active) 143 | { 144 | is_active = shoud_active; 145 | } 146 | -------------------------------------------------------------------------------- /Engine/src/Input/InputMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace reality 4 | { 5 | enum KeyState 6 | { 7 | KEY_FREE = 0, 8 | KEY_UP, 9 | KEY_PUSH, 10 | KEY_HOLD, 11 | }; 12 | 13 | enum MouseButton 14 | { 15 | L_BUTTON, 16 | R_BUTTON, 17 | M_BUTTON, 18 | EXTRA_BUTTON, 19 | NUM_MOUSE_BUTTON 20 | }; 21 | 22 | class DLL_API InputMgr 23 | { 24 | SINGLETON(InputMgr); 25 | #define DINPUT reality::InputMgr::GetInst() 26 | public: 27 | bool Init(); 28 | bool Update(); 29 | 30 | KeyState GetKeyState(DWORD input_key); 31 | KeyState GetMouseState(MouseButton input_key); 32 | 33 | POINT GetMousePosition(); 34 | XMFLOAT2 GetMouseVelocity(); 35 | int GetMouseWheel(); 36 | int GetDeltaX(); 37 | int GetDeltaY(); 38 | 39 | void Active(bool shoud_active); 40 | 41 | bool is_active = true; 42 | 43 | private: 44 | ComPtr dinput; 45 | ComPtr di_keyboard; 46 | ComPtr di_mouse; 47 | 48 | UCHAR keyboard_state[256]; 49 | KeyState prev_keyboard_state[256]; 50 | 51 | DIMOUSESTATE mouse_state; 52 | KeyState prev_rgb_buttons[4]; 53 | 54 | POINT current_mousepos; 55 | 56 | }; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Engine/src/Managers/EffectMgr.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "EffectMgr.h" 3 | 4 | using namespace reality; 5 | -------------------------------------------------------------------------------- /Engine/src/Managers/EffectMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Components.h" 3 | #include "SceneMgr.h" 4 | 5 | namespace reality 6 | { 7 | class DLL_API EffectMgr 8 | { 9 | SINGLETON(EffectMgr) 10 | #define EFFECT_MGR EffectMgr::GetInst() 11 | private: 12 | template 13 | EffectActorClass* MakeEffectActor() 14 | { 15 | auto entity = SCENE_MGR->AddActor(); 16 | return SCENE_MGR->GetActor(entity); 17 | } 18 | template 19 | EffectActorClass* MakeEffectActor(E_SceneType type) 20 | { 21 | auto entity = SCENE_MGR->GetScene(type)->AddActor(); 22 | return SCENE_MGR->GetScene(type)->GetActor(entity); 23 | } 24 | 25 | public: 26 | // Effect 27 | template 28 | entt::entity SpawnEffect(XMVECTOR pos, XMVECTOR rot_q = XMQuaternionIdentity(), XMVECTOR scale = XMVectorSet(1.0f, 1.0f, 1.0f, 1.0f)) 29 | { 30 | EffectActorClass* effect_actor = MakeEffectActor(); 31 | effect_actor->Spawn(pos, rot_q, scale); 32 | return effect_actor->entity_id_; 33 | } 34 | template 35 | entt::entity SpawnEffectFromNormal(XMVECTOR pos, XMVECTOR normal, XMVECTOR scale = XMVectorSet(1.0f, 1.0f, 1.0f, 1.0f)) 36 | { 37 | EffectActorClass* effect_actor = MakeEffectActor(); 38 | 39 | XMVECTOR base = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); 40 | XMVECTOR axis = XMVector3Cross(base, normal); 41 | XMVECTOR rot_q = XMQuaternionIdentity(); 42 | if (!XMVector3Equal(axis, XMVectorZero())) 43 | { 44 | float angle = acosf(XMVectorGetX(XMVector3Dot(base, normal))); 45 | rot_q = XMQuaternionRotationAxis(axis, angle); 46 | } 47 | 48 | effect_actor->Spawn(pos, rot_q, scale); 49 | return effect_actor->entity_id_; 50 | } 51 | template 52 | entt::entity SpawnEffect(E_SceneType type, XMVECTOR pos, XMVECTOR rot_q = XMQuaternionIdentity(), XMVECTOR scale = XMVectorSet(1.0f, 1.0f, 1.0f, 1.0f)) 53 | { 54 | EffectActorClass* effect_actor = MakeEffectActor(type); 55 | effect_actor->Spawn(pos, rot_q, scale); 56 | return effect_actor->entity_id_; 57 | } 58 | template 59 | entt::entity SpawnEffectFromNormal(E_SceneType type, XMVECTOR pos, XMVECTOR normal, XMVECTOR scale = XMVectorSet(1.0f, 1.0f, 1.0f, 1.0f)) 60 | { 61 | EffectActorClass* effect_actor = MakeEffectActor(type); 62 | 63 | XMVECTOR base = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); 64 | XMVECTOR axis = XMVector3Cross(base, normal); 65 | XMVECTOR rot_q = XMQuaternionIdentity(); 66 | if (!XMVector3Equal(axis, XMVectorZero())) 67 | { 68 | float angle = acosf(XMVectorGetX(XMVector3Dot(base, normal))); 69 | rot_q = XMQuaternionRotationAxis(axis, angle); 70 | } 71 | 72 | effect_actor->Spawn(pos, rot_q, scale); 73 | return effect_actor->entity_id_; 74 | } 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /Engine/src/Managers/RenderTargetMgr.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reality-soft/Game-Engine/3e539944ccfbea2be4b24d2c1a1e26cb338e9ea5/Engine/src/Managers/RenderTargetMgr.cpp -------------------------------------------------------------------------------- /Engine/src/Managers/RenderTargetMgr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reality-soft/Game-Engine/3e539944ccfbea2be4b24d2c1a1e26cb338e9ea5/Engine/src/Managers/RenderTargetMgr.h -------------------------------------------------------------------------------- /Engine/src/Managers/TimeMgr.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "TimeMgr.h" 3 | 4 | using namespace reality; 5 | 6 | void TimeMgr::Init() 7 | { 8 | QueryPerformanceFrequency((LARGE_INTEGER*)&period_frequency); 9 | QueryPerformanceCounter((LARGE_INTEGER*)&last_time); 10 | delta_time = 0; 11 | fps = 0; 12 | game_time = 0; 13 | } 14 | 15 | void TimeMgr::Update() 16 | { 17 | QueryPerformanceCounter((LARGE_INTEGER*)&cur_time); 18 | delta_time = ((double)cur_time.QuadPart - (double)last_time.QuadPart) / (double)period_frequency.QuadPart; 19 | 20 | static int fps_ = 0; 21 | if (deltas < 1.0f) 22 | { 23 | deltas += delta_time; 24 | fps_++; 25 | } 26 | else 27 | { 28 | deltas = 0.0f; 29 | fps = fps_; 30 | fps_ = 0; 31 | } 32 | //fps = 0; 33 | //for (double i = 0; i < 1.0; i += delta_time) 34 | //{ 35 | // fps++; 36 | //} 37 | 38 | game_time += delta_time; 39 | last_time = cur_time; 40 | } 41 | 42 | double TimeMgr::GetDeltaTime() 43 | { 44 | return delta_time; 45 | } 46 | 47 | int TimeMgr::GetFPS() 48 | { 49 | return fps; 50 | } 51 | 52 | float TimeMgr::GetGameTime() 53 | { 54 | return game_time; 55 | } 56 | -------------------------------------------------------------------------------- /Engine/src/Managers/TimeMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace reality 4 | { 5 | class DLL_API TimeMgr 6 | { 7 | SINGLETON(TimeMgr); 8 | 9 | public: 10 | LARGE_INTEGER period_frequency; 11 | LARGE_INTEGER last_time; 12 | LARGE_INTEGER cur_time; 13 | 14 | double delta_time = 0; 15 | double deltas = 0; 16 | int fps = 0; 17 | float game_time = 0; 18 | 19 | void Init(); 20 | void Update(); 21 | 22 | double GetDeltaTime(); 23 | int GetFPS(); 24 | float GetGameTime(); 25 | }; 26 | } 27 | #define TIMER reality::TimeMgr::GetInst() 28 | #define TM_GAMETIME reality::TimeMgr::GetInst()->GetGameTime() 29 | #define TM_DELTATIME reality::TimeMgr::GetInst()->GetDeltaTime() 30 | #define TM_FPS reality::TimeMgr::GetInst()->GetFPS() 31 | 32 | -------------------------------------------------------------------------------- /Engine/src/Physics/Collision.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Shape.h" 3 | #include "SimpleMath.h" 4 | 5 | namespace reality { 6 | struct RayCallback 7 | { 8 | RayCallback() 9 | { 10 | success = false; 11 | is_actor = false; 12 | 13 | distance = 0.0f; 14 | point = XMVectorZero(); 15 | normal = XMVectorZero(); 16 | } 17 | bool success; 18 | bool is_actor; 19 | entt::entity ent; 20 | UINT tri_index; 21 | 22 | float distance; 23 | XMVECTOR point; 24 | XMVECTOR normal; 25 | }; 26 | 27 | enum class CollideType 28 | { 29 | OUTSIDE, 30 | INTERSECT, 31 | INSIDE, 32 | }; 33 | 34 | struct CapsuleCallback 35 | { 36 | CapsuleCallback() 37 | { 38 | reaction = NONE; 39 | floor_pos = XMVectorZero(); 40 | } 41 | enum 42 | { 43 | FLOOR, 44 | WALL, 45 | NONE 46 | } reaction; 47 | XMVECTOR floor_pos; 48 | 49 | }; 50 | 51 | // CollisionTest 52 | 53 | bool DLL_API SameSide(XMVECTOR p1, XMVECTOR p2, XMVECTOR a, XMVECTOR b); 54 | 55 | bool DLL_API PointInTriangle(const XMVECTOR& p, const TriangleShape& tri); 56 | 57 | bool DLL_API RayToAABB(const RayShape& ray, const AABBShape& aabb); 58 | 59 | RayCallback DLL_API RayToTriangle(const RayShape& ray, const TriangleShape& tri); 60 | 61 | RayCallback DLL_API RayToCapsule(const RayShape& ray, const CapsuleShape& cap); 62 | 63 | CollideType DLL_API AABBtoAABB(const AABBShape& aabb1, const AABBShape& aabb2); 64 | 65 | CollideType DLL_API CapsuleToAABB(const AABBShape& aabb, const CapsuleShape& capsule); 66 | 67 | CollideType DLL_API SphereToAABB(const SphereShape& sphere, const AABBShape& aabb); 68 | 69 | CollideType DLL_API CapsuleToCapsule(const CapsuleShape& cap1, const CapsuleShape& cap2); 70 | 71 | CollideType DLL_API CapsuleToSphere(const CapsuleShape& cap, const SphereShape& sphere); 72 | 73 | CollideType DLL_API AABBToTriagnle(const AABBShape& aabb, const TriangleShape& triangle); 74 | 75 | CapsuleCallback DLL_API CapsuleToTriangle(const CapsuleShape& cap, const TriangleShape& triangle); 76 | 77 | XMVECTOR DLL_API PointRaySegment(const RayShape& ray, const XMVECTOR& point); 78 | 79 | // Converter 80 | 81 | XMVECTOR DLL_API GetRayDirection(const RayShape& ray); 82 | 83 | array DLL_API GetEdgeRays(const TriangleShape& tri); 84 | XMVECTOR DLL_API GetMinXZ(const TriangleShape& tri); 85 | XMVECTOR DLL_API GetMaxXZ(const TriangleShape& tri); 86 | 87 | array DLL_API GetTriangles(const AABBShape& aabb); 88 | array DLL_API GetCorners(const AABBShape& aabb); 89 | array DLL_API GetYAxisRay(const AABBShape& aabb); 90 | 91 | array DLL_API GetTipBaseAB(const CapsuleShape& capsule); 92 | 93 | 94 | AABBShape DLL_API CapsuleConvertAABB(const CapsuleShape& capsule); 95 | SphereShape DLL_API AABBTConvertSphere(const AABBShape& aabb); 96 | } -------------------------------------------------------------------------------- /Engine/src/Physics/QuadTreeMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Collision.h" 3 | #include "StaticMeshLevel.h" 4 | #include "CameraSystem.h" 5 | #include "StructuredBuffer.h" 6 | #include "Character.h" 7 | 8 | #define MIN_HEIGHT -10000.f 9 | #define MAX_HEIGHT 10000.f 10 | 11 | namespace reality { 12 | 13 | class DLL_API SpaceNode 14 | { 15 | public: 16 | SpaceNode(UINT num, UINT depth); 17 | ~SpaceNode(); 18 | 19 | public: 20 | void SetNode(float min_x, float min_z, float max_x, float max_z); 21 | void SetVisible(bool _visible); 22 | 23 | public: 24 | bool is_leaf = false; 25 | bool visible = false; 26 | UINT node_num; 27 | UINT node_depth; 28 | 29 | public: 30 | SpaceNode* child_node_[4] = { 0, }; 31 | SpaceNode* parent_node = nullptr; 32 | UINT parent_node_index = 0; 33 | UINT child_node_index[4] = { 0, 0, 0, 0 }; 34 | public: 35 | AABBShape area; 36 | BoundingBox culling_aabb; 37 | vector static_triangles; 38 | //list static_actors; 39 | }; 40 | 41 | class DLL_API QuadTreeMgr 42 | { 43 | SINGLETON(QuadTreeMgr) 44 | #define QUADTREE QuadTreeMgr::GetInst() 45 | 46 | private: 47 | entt::registry* registry_; 48 | float accmulator = 1.0f / 60.0f; 49 | float time_bound = 0.0f; 50 | public: 51 | void Init(StaticMeshLevel* level_to_devide, entt::registry& reg); 52 | 53 | void CreateQuadTreeData(int max_depth); 54 | void ImportQuadTreeData(string mapdat_file); 55 | bool CreatePhysicsCS(); 56 | 57 | void Frame(CameraSystem* applied_camera); 58 | void UpdatePhysics(); 59 | 60 | void Release(); 61 | public: 62 | void SetSpaceHeight(float min_y, float max_y); 63 | 64 | RayCallback Raycast(const RayShape& ray, entt::entity owner_ent); 65 | RayCallback RaycastActorOnly(const RayShape& ray, entt::entity owner_ent); 66 | RayCallback RaycastCarOnly(const RayShape& ray); 67 | RayCallback RaycastActorTargeted(const RayShape& ray, entt::entity target_ent); 68 | 69 | SbTriangleCollision triangle_stbuffer; 70 | SbCapsuleCollision capsule_stbuffer; 71 | SbSphereCollision sphere_stbuffer; 72 | SbCollisionResult result_stbuffer; 73 | 74 | ComPtr staging_buffer_; 75 | array collision_result_pool_; 76 | array empty_pool_; 77 | 78 | CbTransform capsule_mesh_transform; 79 | bool InitCollisionMeshes(); 80 | void RenderCollisionMeshes(); 81 | bool view_collisions_ = false; 82 | 83 | const map& GetLeafNodes(); 84 | public: 85 | UINT visible_nodes = 0; 86 | UINT raycast_calculated = 0; 87 | XMMATRIX camera_rotation_; 88 | // Physics Tree 89 | private: 90 | void RunPhysicsCS(string cs_id); 91 | void MovementByPhysicsCS(); 92 | void SphereUpdateByPhysicsCS(); 93 | void CapsuleImpulse(entt::entity ent, C_CapsuleCollision& c_capsule); 94 | 95 | SpaceNode* ParentNodeQuery(C_CapsuleCollision& c_capsule, SpaceNode* node); 96 | SpaceNode* ParentNodeQuery(C_SphereCollision& c_sphere, SpaceNode* node); 97 | bool LeafNodeQuery(C_CapsuleCollision& c_capsule, SpaceNode* node, vector& out_nodes); 98 | bool LeafNodeQuery(C_SphereCollision& c_sphere, SpaceNode* node, vector& out_nodes); 99 | bool IncludingNodeQuery(C_SphereCollision& c_sphere, SpaceNode* node, vector& out_nodes); 100 | void RaycastNodeQuery(const RayShape& ray, SpaceNode* node, map& callbacks); 101 | void NodeCulling(SpaceNode* node); 102 | 103 | UINT max_depth; 104 | UINT node_count = 0; 105 | 106 | SpaceNode* root_node_ = nullptr; 107 | map total_nodes_; 108 | map leaf_nodes_; 109 | 110 | private: 111 | SpaceNode* BuildPhysicsTree(UINT depth, float min_x, float min_z, float max_x, float max_z); 112 | void SetStaticTriangles(SpaceNode* node); 113 | void AddStaticTriangles(const vector& triangles); 114 | 115 | public: 116 | StaticMeshLevel* deviding_level_ = nullptr; 117 | BoundingFrustum camera_frustum_; 118 | bool wire_frame = false; 119 | void ExportQuadTreeData(string filename); 120 | 121 | private: 122 | void InitImported(); 123 | 124 | // GuideLine 125 | public: 126 | void ImportGuideLines(string mapdat_file, GuideType guide_type); 127 | vector* GetGuideLines(string name); 128 | 129 | vector& GetCarTriangles(); 130 | vector car_triagnles_; 131 | 132 | void SetBlockingFields(string name); 133 | vector blocking_fields_; 134 | XMVECTOR player_start_; 135 | 136 | private: 137 | map> guide_lines_; 138 | string mapdata_dir = "../../Contents/BinaryPackage/"; 139 | }; 140 | } -------------------------------------------------------------------------------- /Engine/src/Physics/Shape.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Shape.h" 3 | 4 | reality::RayShape::RayShape() 5 | { 6 | start = {0, 0, 0}; 7 | end = {0, 0, 0}; 8 | } 9 | 10 | reality::RayShape::RayShape(const XMVECTOR& _start, const XMVECTOR& _end) 11 | { 12 | start = _XMFLOAT3(_start); 13 | end = _XMFLOAT3(_end); 14 | } 15 | 16 | reality::RayShape::RayShape(const XMFLOAT3& _start, const XMFLOAT3& _end) 17 | { 18 | start = _start; 19 | end = _end; 20 | } 21 | 22 | reality::TriangleShape::TriangleShape() 23 | { 24 | vertex0 = _XMFLOAT3(XMVectorZero()); 25 | vertex1 = _XMFLOAT3(XMVectorZero()); 26 | vertex2 = _XMFLOAT3(XMVectorZero()); 27 | } 28 | 29 | reality::TriangleShape::TriangleShape(const XMFLOAT3& v0, const XMFLOAT3& v1, const XMFLOAT3& v2) 30 | { 31 | vertex0 = _XMFLOAT3(XMLoadFloat3(&v0)); 32 | vertex1 = _XMFLOAT3(XMLoadFloat3(&v1)); 33 | vertex2 = _XMFLOAT3(XMLoadFloat3(&v2)); 34 | 35 | XMVECTOR edge1 = _XMVECTOR3(vertex1) - _XMVECTOR3(vertex0); 36 | XMVECTOR edge2 = _XMVECTOR3(vertex2) - _XMVECTOR3(vertex0); 37 | 38 | normal = _XMFLOAT3(XMVector3Normalize(XMVector3Cross(edge1, edge2))); 39 | } 40 | 41 | reality::AABBShape::AABBShape(const XMFLOAT3& _min, const XMFLOAT3& _max) 42 | { 43 | min = _min; 44 | max = _max; 45 | center = _XMFLOAT3((_XMVECTOR3(_min) + _XMVECTOR3(_max) / 2)); 46 | } 47 | 48 | reality::AABBShape::AABBShape(const XMFLOAT3& _center, const float& scale) 49 | { 50 | center = _center; 51 | min = _XMFLOAT3((_XMVECTOR3(center) - XMVectorSet(scale / 2, scale / 2, scale / 2, 0))); 52 | max = _XMFLOAT3((_XMVECTOR3(center) + XMVectorSet(scale / 2, scale / 2, scale / 2, 0))); 53 | } 54 | 55 | reality::SphereShape::SphereShape(const XMFLOAT3& _center, const float& _radius) 56 | { 57 | center = _center; 58 | radius = _radius; 59 | } 60 | 61 | reality::SphereShape::SphereShape(const AABBShape& _aabb) 62 | { 63 | center = _XMFLOAT3(((_XMVECTOR3(_aabb.min) + _XMVECTOR3(_aabb.max)) / 2)); 64 | radius = Vector3Length((_XMVECTOR3(_aabb.max) - _XMVECTOR3(center))); 65 | } 66 | 67 | reality::CapsuleShape::CapsuleShape() 68 | { 69 | base = _XMFLOAT3(XMVectorZero()); 70 | height = 0.0f; 71 | radius = 0.0f; 72 | } 73 | 74 | reality::CapsuleShape::CapsuleShape(const XMFLOAT3& _base, const float& _height, const float& _radius) 75 | { 76 | base = _base; 77 | height = _height; 78 | radius = _radius; 79 | } 80 | 81 | reality::PlaneShape::PlaneShape(XMVECTOR vec0, XMVECTOR vec1, XMVECTOR vec2) 82 | { 83 | XMVECTOR e1 = vec1 - vec0; 84 | XMVECTOR e2 = vec2 - vec0; 85 | normal = XMVector3Normalize(XMVector3Cross(e1, e2)); 86 | 87 | XMVECTOR plane = XMPlaneFromPoints(vec0, vec1, vec2); 88 | 89 | a = plane.m128_f32[0]; 90 | b = plane.m128_f32[1]; 91 | c = plane.m128_f32[2]; 92 | d = plane.m128_f32[3]; 93 | } 94 | 95 | reality::Frustum::Frustum(const XMMATRIX& mat_view_proj) 96 | { 97 | XMMATRIX mat_vp = XMMatrixInverse(nullptr, mat_view_proj); 98 | 99 | // near plane 100 | frustum_vertex[0] = XMVectorSet(-1.0f, -1.0f, 0.0f, 0); 101 | frustum_vertex[1] = XMVectorSet(-1.0f, 1.0f, 0.0f, 0); 102 | frustum_vertex[2] = XMVectorSet(1.0f, 1.0f, 0.0f, 0); 103 | frustum_vertex[3] = XMVectorSet(1.0f, -1.0f, 0.0f, 0); 104 | 105 | // far plane 106 | frustum_vertex[4] = XMVectorSet(-1.0f, -1.0f, 1.0f, 0); 107 | frustum_vertex[5] = XMVectorSet(-1.0f, 1.0f, 1.0f, 0); 108 | frustum_vertex[6] = XMVectorSet(1.0f, 1.0f, 1.0f, 0); 109 | frustum_vertex[7] = XMVectorSet(1.0f, -1.0f, 1.0f, 0); 110 | 111 | for (int i = 0; i < 8; ++i) 112 | { 113 | frustum_vertex[i] = XMVector3TransformCoord(frustum_vertex[i], mat_vp); 114 | } 115 | 116 | frustum_plane[0] = PlaneShape(frustum_vertex[1], frustum_vertex[5], frustum_vertex[0]); 117 | frustum_plane[1] = PlaneShape(frustum_vertex[3], frustum_vertex[6], frustum_vertex[2]); 118 | frustum_plane[2] = PlaneShape(frustum_vertex[5], frustum_vertex[2], frustum_vertex[6]); 119 | frustum_plane[3] = PlaneShape(frustum_vertex[0], frustum_vertex[7], frustum_vertex[3]); 120 | frustum_plane[4] = PlaneShape(frustum_vertex[1], frustum_vertex[3], frustum_vertex[2]); 121 | frustum_plane[5] = PlaneShape(frustum_vertex[6], frustum_vertex[4], frustum_vertex[5]); 122 | 123 | topbottom_tries[0] = TriangleShape(_XMFLOAT3(frustum_vertex[5]), _XMFLOAT3(frustum_vertex[6]), _XMFLOAT3(frustum_vertex[1])); 124 | topbottom_tries[1] = TriangleShape(_XMFLOAT3(frustum_vertex[1]), _XMFLOAT3(frustum_vertex[6]), _XMFLOAT3(frustum_vertex[2])); 125 | topbottom_tries[2] = TriangleShape(_XMFLOAT3(frustum_vertex[0]), _XMFLOAT3(frustum_vertex[3]), _XMFLOAT3(frustum_vertex[4])); 126 | topbottom_tries[3] = TriangleShape(_XMFLOAT3(frustum_vertex[4]), _XMFLOAT3(frustum_vertex[3]), _XMFLOAT3(frustum_vertex[7])); 127 | } 128 | 129 | void reality::ConvertToTrianlgeShapes(vector& out, const SingleMesh& mesh) 130 | { 131 | UINT num_triangle = mesh.vertices.size() / 3; 132 | UINT index = 0; 133 | for (UINT t = 0; t < num_triangle; t++) 134 | { 135 | TriangleShape tri_plane = TriangleShape( 136 | mesh.vertices[index + 0].p, 137 | mesh.vertices[index + 2].p, 138 | mesh.vertices[index + 1].p 139 | ); 140 | 141 | tri_plane.index = t; 142 | 143 | out.push_back(tri_plane); 144 | index += 3; 145 | } 146 | 147 | } 148 | 149 | void reality::ConvertToAABBShape(AABBShape& out, const SingleMesh& mesh) 150 | { 151 | XMFLOAT3 aabb_min = {0, 0, 0}; 152 | XMFLOAT3 aabb_max = {0, 0, 0}; 153 | 154 | for (const auto vertex : mesh.vertices) 155 | { 156 | aabb_min.x = min(aabb_min.x, vertex.p.x); 157 | aabb_min.y = min(aabb_min.y, vertex.p.y); 158 | aabb_min.y = min(aabb_min.z, vertex.p.z); 159 | 160 | aabb_max.x = max(aabb_max.x, vertex.p.x); 161 | aabb_max.y = max(aabb_max.y, vertex.p.y); 162 | aabb_max.y = max(aabb_max.z, vertex.p.z); 163 | } 164 | 165 | out = AABBShape(aabb_min, aabb_max); 166 | } 167 | -------------------------------------------------------------------------------- /Engine/src/Physics/Shape.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define EPSILON 0.00001f 3 | #include "Mesh.h" 4 | 5 | namespace reality { 6 | 7 | struct DLL_API RayShape 8 | { 9 | RayShape(); 10 | RayShape(const XMVECTOR& _start, const XMVECTOR& _end); 11 | RayShape(const XMFLOAT3& _start, const XMFLOAT3& _end); 12 | 13 | XMFLOAT3 start, end; 14 | }; 15 | 16 | struct DLL_API TriangleShape 17 | { 18 | TriangleShape(); 19 | TriangleShape(const XMFLOAT3& v0, const XMFLOAT3& v1, const XMFLOAT3& v2); 20 | 21 | UINT index; 22 | XMFLOAT3 normal; 23 | XMFLOAT3 vertex0, vertex1, vertex2; 24 | }; 25 | 26 | struct DLL_API AABBShape 27 | { 28 | AABBShape() {} 29 | AABBShape(const XMFLOAT3& _min, const XMFLOAT3& _max); 30 | AABBShape(const XMFLOAT3& _center, const float& scale); 31 | 32 | XMFLOAT3 min, max, center; 33 | }; 34 | 35 | struct DLL_API SphereShape 36 | { 37 | SphereShape() {} 38 | SphereShape(const XMFLOAT3& _center, const float& _radius); 39 | SphereShape(const AABBShape& _aabb); 40 | 41 | float radius; 42 | XMFLOAT3 center; 43 | }; 44 | 45 | struct DLL_API CapsuleShape 46 | { 47 | CapsuleShape(); 48 | CapsuleShape(const XMFLOAT3& _base, const float& _height, const float& _radius); 49 | 50 | float height; 51 | float radius; 52 | XMFLOAT3 base; 53 | }; 54 | 55 | struct DLL_API PlaneShape 56 | { 57 | PlaneShape() {} 58 | PlaneShape(XMVECTOR vec0, XMVECTOR vec1, XMVECTOR vec2); 59 | 60 | FLOAT a, b, c, d; 61 | XMVECTOR normal; 62 | }; 63 | 64 | struct DLL_API Frustum 65 | { 66 | Frustum() {} 67 | Frustum(const XMMATRIX& mat_view_proj); 68 | 69 | XMVECTOR frustum_vertex[8]; 70 | PlaneShape frustum_plane[6]; 71 | TriangleShape topbottom_tries[4]; 72 | }; 73 | 74 | void ConvertToTrianlgeShapes(vector& out, const SingleMesh& mesh); 75 | void ConvertToAABBShape(AABBShape& out, const SingleMesh& mesh); 76 | } -------------------------------------------------------------------------------- /Engine/src/ResourceTypes/Material.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Material.h" 3 | #include "FileTransfer.h" 4 | #include "ResourceMgr.h" 5 | #include 6 | 7 | reality::Material::Material() 8 | { 9 | for (int i = 0; i < 7; ++i) 10 | textures[i] = nullptr; 11 | 12 | pixel_shader = nullptr; 13 | sampler = nullptr; 14 | } 15 | 16 | void reality::Material::SaveEmpty(string filename) 17 | { 18 | if (_access(filename.c_str(), 0) != -1) 19 | { 20 | return; 21 | } 22 | 23 | TextFileTransfer file_trans(filename, WRITE); 24 | 25 | file_trans.WriteText("diffuse", "null"); 26 | file_trans.WriteText("normalmap", "null"); 27 | file_trans.WriteText("metalic", "null"); 28 | file_trans.WriteText("roughness", "null"); 29 | file_trans.WriteText("specular", "null"); 30 | file_trans.WriteText("ambient", "null"); 31 | file_trans.WriteText("opacity", "null"); 32 | file_trans.WriteText("shader", "null"); 33 | 34 | file_trans.Close(); 35 | } 36 | 37 | void reality::Material::Create() 38 | { 39 | Texture* dif = RESOURCE->UseResource(diffuse); 40 | Texture* nor = RESOURCE->UseResource(normalmap); 41 | Texture* met = RESOURCE->UseResource(metalic); 42 | Texture* rou = RESOURCE->UseResource(roughness); 43 | Texture* spe = RESOURCE->UseResource(specular); 44 | Texture* amb = RESOURCE->UseResource(ambient); 45 | Texture* opa = RESOURCE->UseResource(opacity); 46 | PixelShader* ps = RESOURCE->UseResource(shader); 47 | 48 | if (dif) 49 | textures[0] = dif->srv.Get(); 50 | 51 | if (nor) 52 | textures[1] = nor->srv.Get(); 53 | 54 | if (met) 55 | textures[2] = met->srv.Get(); 56 | 57 | if (rou) 58 | textures[3] = rou->srv.Get(); 59 | 60 | if (spe) 61 | textures[4] = spe->srv.Get(); 62 | 63 | if (amb) 64 | textures[5] = amb->srv.Get(); 65 | 66 | if (opa) 67 | textures[6] = opa->srv.Get(); 68 | 69 | if (ps) 70 | pixel_shader = ps->Get(); 71 | 72 | sampler = DX11APP->GetCommonStates()->LinearClamp(); 73 | } 74 | 75 | void reality::Material::Save(string filename) 76 | { 77 | TextFileTransfer file_trans(filename, WRITE); 78 | 79 | file_trans.WriteText("diffuse", diffuse); 80 | file_trans.WriteText("normalmap", normalmap); 81 | file_trans.WriteText("metalic", metalic); 82 | file_trans.WriteText("roughness", roughness); 83 | file_trans.WriteText("specular", specular); 84 | file_trans.WriteText("ambient", ambient); 85 | file_trans.WriteText("opacity", opacity); 86 | file_trans.WriteText("shader", shader); 87 | 88 | file_trans.Close(); 89 | } 90 | 91 | void reality::Material::Set() 92 | { 93 | if (pixel_shader) 94 | DX11APP->GetDeviceContext()->PSSetShader(pixel_shader, 0, 0); 95 | 96 | 97 | DX11APP->GetDeviceContext()->PSSetSamplers(0, 1, &sampler); 98 | DX11APP->GetDeviceContext()->PSSetShaderResources(0, 7, textures); 99 | } 100 | 101 | void reality::Material::LoadAndCreate(string filename) 102 | { 103 | TextFileTransfer file_trans(filename, READ); 104 | 105 | diffuse = file_trans.ReadText("diffuse"); 106 | normalmap = file_trans.ReadText("normalmap"); 107 | metalic = file_trans.ReadText("metalic"); 108 | roughness = file_trans.ReadText("roughness"); 109 | specular = file_trans.ReadText("specular"); 110 | ambient = file_trans.ReadText("ambient"); 111 | opacity = file_trans.ReadText("opacity"); 112 | shader = file_trans.ReadText("shader"); 113 | 114 | file_trans.Close(); 115 | 116 | Create(); 117 | } -------------------------------------------------------------------------------- /Engine/src/ResourceTypes/Material.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Shader.h" 3 | 4 | namespace reality 5 | { 6 | class DLL_API Material 7 | { 8 | public: 9 | Material(); 10 | ~Material() = default; 11 | 12 | public: 13 | string diffuse; 14 | string normalmap; 15 | string metalic; 16 | string roughness; 17 | string specular; 18 | string ambient; 19 | string opacity; 20 | string shader = "MeshSurfacePS.cso"; 21 | 22 | ID3D11ShaderResourceView* textures[7]; 23 | ID3D11PixelShader* pixel_shader; 24 | ID3D11SamplerState* sampler; 25 | 26 | void SaveEmpty(string filename); 27 | void Create(); 28 | void Save(string filename); 29 | void Set(); 30 | void LoadAndCreate(string filename); 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /Engine/src/ResourceTypes/Mesh.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Mesh.h" 3 | 4 | using namespace reality; 5 | 6 | Skeleton::Skeleton(const Skeleton& other) 7 | { 8 | bind_pose_matrices = other.bind_pose_matrices; 9 | } 10 | 11 | SkeletalMesh::SkeletalMesh(const SkeletalMesh& other) 12 | { 13 | meshes.resize(other.meshes.size()); 14 | meshes = other.meshes; 15 | 16 | skeleton = other.skeleton; 17 | } 18 | 19 | StaticMesh::StaticMesh(const StaticMesh& other) 20 | { 21 | meshes.resize(other.meshes.size()); 22 | meshes = other.meshes; 23 | } -------------------------------------------------------------------------------- /Engine/src/ResourceTypes/Mesh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "DX11App.h" 3 | #include "Vertex.h" 4 | #include "Skeleton.h" 5 | 6 | namespace reality 7 | { 8 | template 9 | struct SingleMesh 10 | { 11 | SingleMesh() = default; 12 | SingleMesh(const SingleMesh& other) 13 | { 14 | mesh_name = other.mesh_name; 15 | 16 | vertices.resize(other.vertices.size()); 17 | vertices = other.vertices; 18 | 19 | indices.resize(other.indices.size()); 20 | indices = other.indices; 21 | 22 | other.vertex_buffer.CopyTo(vertex_buffer.GetAddressOf()); 23 | other.index_buffer.CopyTo(index_buffer.GetAddressOf()); 24 | } 25 | ~SingleMesh() 26 | { 27 | 28 | vertices.clear(); 29 | indices.clear(); 30 | vertex_buffer.ReleaseAndGetAddressOf(); 31 | index_buffer.ReleaseAndGetAddressOf(); 32 | } 33 | 34 | string mesh_name; 35 | 36 | vector vertices; 37 | ComPtr vertex_buffer; 38 | 39 | vector indices; 40 | ComPtr index_buffer; 41 | }; 42 | 43 | struct SkeletalMesh 44 | { 45 | SkeletalMesh() = default; 46 | SkeletalMesh(const SkeletalMesh& other); 47 | 48 | vector> meshes; 49 | Skeleton skeleton; 50 | }; 51 | 52 | struct StaticMesh 53 | { 54 | StaticMesh() = default; 55 | StaticMesh(const StaticMesh& other); 56 | 57 | vector> meshes; 58 | }; 59 | 60 | template 61 | static XMFLOAT3 GetMaxVertex(const MeshType& mesh) 62 | { 63 | XMFLOAT3 max_xyz = { 0, 0, 0 }; 64 | for (auto& single_mesh : mesh.meshes) 65 | { 66 | for (auto vertex : single_mesh.vertices) 67 | { 68 | max_xyz.x = max(max_xyz.x, vertex.p.x); 69 | max_xyz.y = max(max_xyz.y, vertex.p.y); 70 | max_xyz.z = max(max_xyz.z, vertex.p.z); 71 | } 72 | } 73 | return max_xyz; 74 | } 75 | 76 | static bool CreateVertexBuffer(SingleMesh& single_mesh) 77 | { 78 | single_mesh.vertex_buffer.ReleaseAndGetAddressOf(); 79 | single_mesh.vertex_buffer = nullptr; 80 | 81 | HRESULT hr; 82 | 83 | // VertexBuffer 84 | D3D11_BUFFER_DESC desc; 85 | D3D11_SUBRESOURCE_DATA subdata; 86 | 87 | ZeroMemory(&desc, sizeof(desc)); 88 | ZeroMemory(&subdata, sizeof(subdata)); 89 | 90 | desc.ByteWidth = sizeof(Vertex) * single_mesh.vertices.size(); 91 | desc.Usage = D3D11_USAGE_DEFAULT; 92 | desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; 93 | subdata.pSysMem = single_mesh.vertices.data(); 94 | 95 | hr = DX11APP->GetDevice()->CreateBuffer(&desc, &subdata, single_mesh.vertex_buffer.GetAddressOf()); 96 | if (FAILED(hr)) 97 | return false; 98 | 99 | return true; 100 | } 101 | } 102 | 103 | -------------------------------------------------------------------------------- /Engine/src/ResourceTypes/Shader.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Shader.h" 3 | 4 | using namespace reality; 5 | 6 | bool VertexShader::LoadCompiled(wstring cso_file) 7 | { 8 | HRESULT hr; 9 | ID3DBlob* blob = nullptr; 10 | 11 | hr = D3DReadFileToBlob(cso_file.c_str(), &blob); 12 | 13 | hr = DX11APP->GetDevice()->CreateVertexShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, vs.GetAddressOf()); 14 | 15 | ID3D11ShaderReflection* reflection = nullptr; 16 | hr = D3DReflect(blob->GetBufferPointer(), blob->GetBufferSize(), IID_ID3D11ShaderReflection, (void**)&reflection); 17 | 18 | D3D11_SHADER_DESC shader_desc; 19 | hr = reflection->GetDesc(&shader_desc); 20 | 21 | vector ied; 22 | UINT byte_offset = 0; 23 | 24 | for (UINT i = 0; i < shader_desc.InputParameters; i++) 25 | { 26 | D3D11_INPUT_ELEMENT_DESC input_desc; 27 | ZeroMemory(&input_desc, sizeof(input_desc)); 28 | 29 | D3D11_SIGNATURE_PARAMETER_DESC param_desc; 30 | hr = reflection->GetInputParameterDesc(i, ¶m_desc); 31 | if (SUCCEEDED(hr)) 32 | { 33 | input_desc.SemanticName = param_desc.SemanticName; 34 | input_desc.SemanticIndex = param_desc.SemanticIndex; 35 | input_desc.AlignedByteOffset = byte_offset; 36 | 37 | if (string(param_desc.SemanticName).find("F2") != string::npos) 38 | { 39 | input_desc.Format = DXGI_FORMAT_R32G32_FLOAT; 40 | byte_offset += 8; 41 | } 42 | 43 | else if (string(param_desc.SemanticName).find("F3") != string::npos) 44 | { 45 | input_desc.Format = DXGI_FORMAT_R32G32B32_FLOAT; 46 | byte_offset += 12; 47 | } 48 | 49 | else if (string(param_desc.SemanticName).find("F4") != string::npos) 50 | { 51 | input_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; 52 | byte_offset += 16; 53 | } 54 | 55 | else if (string(param_desc.SemanticName).find("SV_InstanceID") != string::npos) 56 | { 57 | input_desc.Format = DXGI_FORMAT_R32_UINT; 58 | input_desc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; 59 | byte_offset += 4; 60 | } 61 | 62 | ied.push_back(input_desc); 63 | } 64 | } 65 | 66 | hr = DX11APP->GetDevice()->CreateInputLayout(ied.data(), ied.size(), blob->GetBufferPointer(), blob->GetBufferSize(), input_layout.GetAddressOf()); 67 | 68 | blob->Release(); 69 | blob = nullptr; 70 | 71 | return true; 72 | } 73 | 74 | ID3D11VertexShader* VertexShader::Get() 75 | { 76 | return vs.Get(); 77 | } 78 | 79 | ID3D11InputLayout* VertexShader::InputLayout() 80 | { 81 | return input_layout.Get(); 82 | } 83 | 84 | bool PixelShader::LoadCompiled(wstring cso_file) 85 | { 86 | HRESULT hr = S_OK; 87 | 88 | ID3DBlob* blob = nullptr; 89 | hr = D3DReadFileToBlob(cso_file.c_str(), &blob); 90 | 91 | hr = DX11APP->GetDevice()->CreatePixelShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, ps.GetAddressOf()); 92 | 93 | blob->Release(); 94 | blob = nullptr; 95 | 96 | return true; 97 | } 98 | 99 | ID3D11PixelShader* PixelShader::Get() 100 | { 101 | return ps.Get(); 102 | } 103 | 104 | bool GeometryShader::LoadCompiled(wstring cso_file) 105 | { 106 | HRESULT hr = S_OK; 107 | ID3DBlob* blob = nullptr; 108 | hr = D3DReadFileToBlob(cso_file.c_str(), &blob); 109 | 110 | D3D11_SO_DECLARATION_ENTRY ied[] = 111 | { 112 | { 0, "SV_POSITION", 0, 0, 4, 0 }, 113 | { 0, "POSITION", 0, 0, 3, 0 }, 114 | { 0, "NORMAL", 0, 0, 3, 0 }, 115 | { 0, "COLOR", 0, 0, 4, 0 }, 116 | { 0, "TEXCOORD", 0, 0, 2, 0 }, 117 | { 0, "TEXCOORD", 1, 0, 2, 0 }, 118 | }; 119 | 120 | hr = DX11APP->GetDevice()->CreateGeometryShaderWithStreamOutput(blob->GetBufferPointer(), blob->GetBufferSize(), ied, ARRAYSIZE(ied), 0, 0, 0, 0, stream_out_gs.GetAddressOf()); 121 | 122 | hr = DX11APP->GetDevice()->CreateGeometryShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, default_gs.GetAddressOf()); 123 | 124 | blob->Release(); 125 | blob = nullptr; 126 | 127 | return true; 128 | } 129 | 130 | ID3D11GeometryShader* GeometryShader::GetStreamOutGS() 131 | { 132 | return stream_out_gs.Get(); 133 | } 134 | 135 | ID3D11GeometryShader* GeometryShader::GetDefaultGS() 136 | { 137 | return default_gs.Get(); 138 | } 139 | 140 | bool reality::ComputeShader::LoadCompiled(wstring cso_file) 141 | { 142 | HRESULT hr; 143 | 144 | ID3DBlob* blob = nullptr; 145 | hr = D3DReadFileToBlob(cso_file.c_str(), &blob); 146 | 147 | hr = DX11APP->GetDevice()->CreateComputeShader(blob->GetBufferPointer(), blob->GetBufferSize(), nullptr, cs.GetAddressOf()); 148 | 149 | blob->Release(); 150 | blob = nullptr; 151 | 152 | if (FAILED(hr)) 153 | return false; 154 | 155 | return true; 156 | } 157 | 158 | ID3D11ComputeShader* reality::ComputeShader::Get() 159 | { 160 | return cs.Get(); 161 | } 162 | -------------------------------------------------------------------------------- /Engine/src/ResourceTypes/Shader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "DX11App.h" 3 | 4 | namespace reality 5 | { 6 | class DLL_API VertexShader 7 | { 8 | public: 9 | virtual bool LoadCompiled(wstring cso_file); 10 | ID3D11VertexShader* Get(); 11 | ID3D11InputLayout* InputLayout(); 12 | protected: 13 | ComPtr vs; 14 | ComPtr input_layout; 15 | }; 16 | 17 | class DLL_API PixelShader 18 | { 19 | public: 20 | bool LoadCompiled(wstring cso_file); 21 | ID3D11PixelShader* Get(); 22 | private: 23 | ComPtr ps; 24 | }; 25 | 26 | class DLL_API GeometryShader 27 | { 28 | public: 29 | bool LoadCompiled(wstring cso_file); 30 | ID3D11GeometryShader* GetStreamOutGS(); 31 | ID3D11GeometryShader* GetDefaultGS(); 32 | private: 33 | ComPtr stream_out_gs; 34 | ComPtr default_gs; 35 | }; 36 | 37 | class DLL_API ComputeShader 38 | { 39 | public: 40 | bool LoadCompiled(wstring cso_file); 41 | ID3D11ComputeShader* Get(); 42 | private: 43 | ComPtr cs; 44 | }; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Engine/src/ResourceTypes/Texture.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Texture.h" 3 | #include "DX11App.h" 4 | 5 | bool reality::Texture::LoadTextureWIC(wstring filepath) 6 | { 7 | HRESULT hr; 8 | 9 | hr = CreateWICTextureFromFile( 10 | DX11APP->GetDevice(), 11 | DX11APP->GetDeviceContext(), 12 | filepath.c_str(), 13 | (ID3D11Resource**)texture.GetAddressOf(), srv.GetAddressOf()); 14 | 15 | if (FAILED(hr)) 16 | return false; 17 | 18 | texture.Get()->QueryInterface(&texture); 19 | if (texture) 20 | texture->GetDesc(&texture_desc); 21 | 22 | texture->Release(); 23 | 24 | return true; 25 | } 26 | 27 | bool reality::Texture::LoadTextureDDS(wstring filepath) 28 | { 29 | ID3D11Resource* resource = nullptr; 30 | HRESULT hr = CreateDDSTextureFromFile(DX11APP->GetDevice(), filepath.c_str(), &resource, srv.GetAddressOf()); 31 | if (FAILED(hr)) 32 | return false; 33 | 34 | ID3D11Texture2D* texture; 35 | resource->QueryInterface(&texture); 36 | if (texture) 37 | texture->GetDesc(&texture_desc); 38 | 39 | texture->Release(); 40 | 41 | return true; 42 | } 43 | 44 | bool reality::AlphaTexLayer::CreateAlphaTexture(int pixels, int _texel_per_vertex) 45 | { 46 | pixel_size = pixels; 47 | texel_per_vertex = _texel_per_vertex; 48 | alpha_data.resize(pixels * pixels); 49 | ZeroMemory(alpha_data.data(), sizeof(alpha_data)); 50 | 51 | HRESULT hr; 52 | 53 | D3D11_TEXTURE2D_DESC tex_desc; 54 | D3D11_SUBRESOURCE_DATA subdata; 55 | ZeroMemory(&tex_desc, sizeof(tex_desc)); 56 | ZeroMemory(&subdata, sizeof(subdata)); 57 | 58 | tex_desc.Width = pixel_size; 59 | tex_desc.Height = pixel_size; 60 | tex_desc.MipLevels = tex_desc.ArraySize = 1; 61 | tex_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; 62 | tex_desc.SampleDesc.Count = 1; 63 | tex_desc.Usage = D3D11_USAGE_DEFAULT; 64 | tex_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 65 | tex_desc.CPUAccessFlags = 0; 66 | tex_desc.MiscFlags = 0; 67 | 68 | subdata.pSysMem = alpha_data.data(); 69 | subdata.SysMemPitch = sizeof(XMFLOAT4) * pixels; 70 | 71 | hr = DX11APP->GetDevice()->CreateTexture2D(&tex_desc, &subdata, alpha_texture.GetAddressOf()); 72 | if (FAILED(hr)) 73 | return false; 74 | 75 | D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc; 76 | ZeroMemory(&srv_desc, sizeof(srv_desc)); 77 | srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; 78 | srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; 79 | srv_desc.Texture2D.MipLevels = 1; 80 | 81 | hr = DX11APP->GetDevice()->CreateShaderResourceView(alpha_texture.Get(), &srv_desc, alpha_srv.GetAddressOf()); 82 | if (FAILED(hr)) 83 | return false; 84 | 85 | return true; 86 | } 87 | 88 | void reality::AlphaTexLayer::SetTexelAt(const XMVECTOR& pos, float radius, int current_layer, bool paint_mode) 89 | { 90 | XMFLOAT2 texel_coord; 91 | 92 | texel_coord.x = (pos.m128_f32[0] / 1.5 + 64) * 8; 93 | texel_coord.y = fabs((pos.m128_f32[2] / 1.5 - 64)) * 8; 94 | 95 | for (int i = 0; i < pixel_size; ++i) 96 | { 97 | for (int j = 0; j < pixel_size; ++j) 98 | { 99 | float distance = Distance(XMVectorSet(i, 0, j, 0), XMVectorSet(texel_coord.x, 0, texel_coord.y, 0)); 100 | float strength = 1.0f - (distance / (radius * 8)); 101 | 102 | if (paint_mode == false) 103 | strength *= -1.0f; 104 | 105 | if (distance <= radius * 8) 106 | { 107 | switch (current_layer) 108 | { 109 | case 1: 110 | alpha_data[j * pixel_size + i].x += strength; 111 | alpha_data[j * pixel_size + i].x = min(alpha_data[j * pixel_size + i].x, 1.0f); 112 | alpha_data[j * pixel_size + i].x = max(alpha_data[j * pixel_size + i].x, 0.0f); 113 | break; 114 | 115 | case 2: 116 | alpha_data[j * pixel_size + i].y += strength; 117 | alpha_data[j * pixel_size + i].y = min(alpha_data[j * pixel_size + i].y, 1.0f); 118 | alpha_data[j * pixel_size + i].y = max(alpha_data[j * pixel_size + i].y, 0.0f); 119 | break; 120 | 121 | case 3: 122 | alpha_data[j * pixel_size + i].z += strength; 123 | alpha_data[j * pixel_size + i].z = min(alpha_data[j * pixel_size + i].z, 1.0f); 124 | alpha_data[j * pixel_size + i].z = max(alpha_data[j * pixel_size + i].z, 0.0f); 125 | break; 126 | 127 | case 4: 128 | alpha_data[j * pixel_size + i].w += strength; 129 | alpha_data[j * pixel_size + i].w = min(alpha_data[j * pixel_size + i].w, 1.0f); 130 | alpha_data[j * pixel_size + i].w = max(alpha_data[j * pixel_size + i].w, 0.0f); 131 | break; 132 | } 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | } 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Engine/src/ResourceTypes/Texture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "WICTextureLoader.h" 3 | #include "DDSTextureLoader.h" 4 | 5 | namespace reality 6 | { 7 | class DLL_API Texture 8 | { 9 | public: 10 | Texture() = default; 11 | ~Texture() = default; 12 | 13 | public: 14 | bool LoadTextureWIC(wstring filepath); 15 | bool LoadTextureDDS(wstring filepath); 16 | ComPtr srv; 17 | ComPtr texture; 18 | D3D11_TEXTURE2D_DESC texture_desc; 19 | }; 20 | 21 | class DLL_API AlphaTexLayer 22 | { 23 | public: 24 | ComPtr alpha_texture; 25 | ComPtr alpha_srv; 26 | vector alpha_data; 27 | 28 | int pixel_size; 29 | int texel_per_vertex; 30 | bool CreateAlphaTexture(int pixels, int _texel_per_vertex); 31 | bool ImportAlphaTexture(string filename); 32 | bool ExportAlphaTexture(string filename); 33 | 34 | void SetTexelAt(const XMVECTOR& pos, float radius, int current_layer, bool paint_mode); 35 | }; 36 | } -------------------------------------------------------------------------------- /Engine/src/Scene/Scene.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Scene.h" 3 | #include "Actor.h" 4 | #include "SceneMgr.h" 5 | 6 | void reality::Scene::OnBaseUpdate() 7 | { 8 | OnUpdate(); 9 | 10 | for (const auto& actor : actors_) { 11 | actor.second->OnUpdate(); 12 | } 13 | } 14 | 15 | vector& reality::Scene::GetPlayers() 16 | { 17 | return players_; 18 | } 19 | 20 | unordered_map>& reality::Scene::GetActors() 21 | { 22 | return actors_; 23 | } 24 | -------------------------------------------------------------------------------- /Engine/src/Scene/Scene.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "TimeMgr.h" 3 | #include "InputMgr.h" 4 | #include "Actor.h" 5 | 6 | namespace reality { 7 | class DLL_API Scene 8 | { 9 | public: 10 | Scene() = default; 11 | ~Scene() = default; 12 | 13 | virtual void OnInit() = 0; 14 | virtual void OnBaseUpdate(); 15 | virtual void OnUpdate() = 0; 16 | 17 | virtual void OnRender() = 0; 18 | virtual void OnRelease() = 0; 19 | public: 20 | entt::registry& GetRegistryRef() { 21 | return reg_scene_; 22 | } 23 | protected: 24 | entt::registry reg_scene_; 25 | private: 26 | vector players_; 27 | unordered_map> actors_; 28 | public: 29 | vector& GetPlayers(); 30 | unordered_map>& GetActors(); 31 | public: 32 | template 33 | ActorClass* GetActor(entt::entity actor_id); 34 | template 35 | entt::entity AddActor(Args&&...args); 36 | template 37 | ActorClass* GetPlayer(int player_num); 38 | template 39 | entt::entity AddPlayer(Args&&...args); 40 | }; 41 | 42 | template 43 | inline ActorClass* Scene::GetActor(entt::entity actor_id) 44 | { 45 | if (actors_.find(actor_id) == actors_.end()) 46 | return nullptr; 47 | 48 | return dynamic_cast(weak_ptr(actors_.at(actor_id)).lock().get()); 49 | } 50 | 51 | template 52 | inline entt::entity Scene::AddActor(Args&&...args) 53 | { 54 | shared_ptr cur_actor = dynamic_pointer_cast(make_shared(args...)); 55 | if (cur_actor == nullptr) { 56 | return entt::null; 57 | } 58 | 59 | cur_actor->OnInit(reg_scene_); 60 | entt::entity cur_entity_id = cur_actor->GetEntityId(); 61 | actors_.insert({ cur_entity_id, move(cur_actor) }); 62 | 63 | return cur_entity_id; 64 | } 65 | 66 | template 67 | inline ActorClass* Scene::GetPlayer(int player_num) 68 | { 69 | if (player_num >= players_.size()) { 70 | return nullptr; 71 | } 72 | 73 | return dynamic_cast(weak_ptr(actors_.at(players_[player_num])).lock().get()); 74 | } 75 | template 76 | inline entt::entity Scene::AddPlayer(Args&&...args) 77 | { 78 | shared_ptr player = dynamic_pointer_cast(make_shared(args...)); 79 | if (player == nullptr) { 80 | return entt::null; 81 | } 82 | 83 | player->OnInit(reg_scene_); 84 | players_.push_back(player->GetEntityId()); 85 | entt::entity cur_entity_id = player->GetEntityId(); 86 | actors_.insert({ cur_entity_id, move(player) }); 87 | return cur_entity_id; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Engine/src/Scene/SceneMgr.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SceneMgr.h" 3 | 4 | namespace reality{ 5 | entt::registry& SceneMgr::GetRegistry() 6 | { 7 | return cur_scene_.get()->GetRegistryRef(); 8 | } 9 | weak_ptr SceneMgr::GetCurScene() 10 | { 11 | return weak_ptr(cur_scene_); 12 | } 13 | shared_ptr SceneMgr::GetScene(E_SceneType type) 14 | { 15 | if (scenes.find(type) == scenes.end()) 16 | return NULL; 17 | else 18 | return scenes[type]; 19 | } 20 | void SceneMgr::ChangeScene(E_SceneType scene_type) 21 | { 22 | scene_to_change_ = scene_type; 23 | } 24 | bool SceneMgr::DestroyActor(entt::entity actor_id) 25 | { 26 | if (cur_scene_->GetActors().find(actor_id) == cur_scene_->GetActors().end()) 27 | return false; 28 | GetRegistry().destroy(actor_id); 29 | cur_scene_->GetActors().erase(actor_id); 30 | return true; 31 | } 32 | void SceneMgr::InternalChangeScene() 33 | { 34 | if (scenes.find(scene_to_change_) != scenes.end()) 35 | { 36 | if (cur_scene_ != nullptr) 37 | { 38 | cur_scene_->OnRelease(); 39 | } 40 | 41 | cur_scene_ = scenes[scene_to_change_]; 42 | COMPONENT->OnInit(cur_scene_->GetRegistryRef()); 43 | } 44 | scene_to_change_ = E_SceneType::SCENE_NONE; 45 | } 46 | void SceneMgr::OnInit() 47 | { 48 | if (cur_scene_.get() != nullptr) { 49 | cur_scene_->OnInit(); 50 | COMPONENT->OnInit(cur_scene_->GetRegistryRef()); 51 | } 52 | } 53 | 54 | void SceneMgr::OnUpdate() 55 | { 56 | if (cur_scene_.get() != nullptr) { 57 | cur_scene_->OnBaseUpdate(); 58 | } 59 | 60 | if (scene_to_change_ != E_SceneType::SCENE_NONE) 61 | { 62 | InternalChangeScene(); 63 | } 64 | } 65 | 66 | void SceneMgr::OnRender() 67 | { 68 | if (cur_scene_.get() != nullptr) { 69 | cur_scene_->OnRender(); 70 | } 71 | } 72 | 73 | void SceneMgr::OnRelease() 74 | { 75 | if (cur_scene_.get() != nullptr) { 76 | cur_scene_->OnRelease(); 77 | } 78 | } 79 | 80 | int SceneMgr::GetNumOfActor() { 81 | return cur_scene_->GetActors().size(); 82 | } 83 | 84 | int SceneMgr::GetNumOfActor(string tag) 85 | { 86 | int num = 0; 87 | auto actors = cur_scene_->GetActors(); 88 | for (const auto& actor : actors) 89 | { 90 | if (actor.second->tag == tag) 91 | num++; 92 | } 93 | 94 | 95 | return num; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Engine/src/Scene/SceneMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Scene.h" 3 | 4 | namespace reality { 5 | 6 | enum E_SceneType 7 | { 8 | SCENE_NONE = 0, 9 | POP = 1, 10 | START = 2, 11 | INGAME = 3, 12 | ENDING = 4, 13 | }; 14 | 15 | class DLL_API SceneMgr { 16 | SINGLETON(SceneMgr) 17 | #define SCENE_MGR SceneMgr::GetInst() 18 | public: 19 | void OnInit(); 20 | void OnUpdate(); 21 | void OnRender(); 22 | void OnRelease(); 23 | public: 24 | entt::registry& GetRegistry(); 25 | weak_ptr GetCurScene(); 26 | public: 27 | template 28 | ActorClass* GetActor(entt::entity actor_id); 29 | template 30 | entt::entity AddActor(Args&&...args); 31 | template 32 | ActorClass* GetPlayer(int player_num); 33 | template 34 | entt::entity AddPlayer(Args&&...args); 35 | template 36 | void SetScene(); 37 | template 38 | void AddScene(E_SceneType type); 39 | shared_ptr GetScene(E_SceneType type); 40 | void ChangeScene(E_SceneType scene_type); 41 | bool DestroyActor(entt::entity actor_id); 42 | private: 43 | void InternalChangeScene(); 44 | public: 45 | int GetNumOfActor(); 46 | int GetNumOfActor(string tag); 47 | private: 48 | E_SceneType scene_to_change_; 49 | shared_ptr cur_scene_; 50 | unordered_map> scenes; 51 | }; 52 | 53 | template 54 | inline ActorClass* SceneMgr::GetActor(entt::entity actor_id) 55 | { 56 | return cur_scene_->GetActor(actor_id); 57 | } 58 | 59 | template 60 | inline entt::entity SceneMgr::AddActor(Args&&...args) 61 | { 62 | return cur_scene_->AddActor(args...); 63 | } 64 | 65 | template 66 | inline ActorClass* SceneMgr::GetPlayer(int player_num) 67 | { 68 | return cur_scene_->GetPlayer(player_num); 69 | } 70 | 71 | template 72 | inline entt::entity SceneMgr::AddPlayer(Args&&...args) 73 | { 74 | return cur_scene_->AddPlayer(args...); 75 | } 76 | 77 | template 78 | inline void SceneMgr::SetScene() 79 | { 80 | cur_scene_ = make_shared(); 81 | OnInit(); 82 | } 83 | 84 | template 85 | inline void SceneMgr::AddScene(E_SceneType type) 86 | { 87 | auto new_scene = make_shared(); 88 | scenes.insert({ type, new_scene }); 89 | new_scene->OnInit(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Engine/src/Sound/FmodMgr.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reality-soft/Game-Engine/3e539944ccfbea2be4b24d2c1a1e26cb338e9ea5/Engine/src/Sound/FmodMgr.cpp -------------------------------------------------------------------------------- /Engine/src/Sound/FmodMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Sound.h" 3 | 4 | #define CHANNEL_MAX_COUNT 1000 5 | #define POOL_SIZE 10 6 | 7 | namespace reality 8 | { 9 | class DLL_API FmodMgr 10 | { 11 | SINGLETON(FmodMgr) 12 | #define FMOD_MGR FmodMgr::GetInst() 13 | private: 14 | FMOD::System* fmod_system_; 15 | FMOD::ChannelGroup* sfx_channel_group_; 16 | FMOD::ChannelGroup* music_channel_group_; 17 | float sfx_volume_; 18 | float music_volume_; 19 | float min_distance_ = 0.0f; 20 | float max_distance_ = 30000.0f; 21 | private: 22 | list sound_play_list; 23 | queue sound_pool; 24 | public: 25 | FMOD::System* fmod_system() { 26 | return fmod_system_; 27 | } 28 | FMOD::ChannelGroup* sfx_channel_group() { 29 | return sfx_channel_group_; 30 | } 31 | FMOD::ChannelGroup* music_channel_group() { 32 | return music_channel_group_; 33 | } 34 | public: 35 | bool Init(); 36 | int Update(); 37 | void Release(); 38 | private: 39 | void CreateFmodSystem(); 40 | void CheckPlayingPool(); 41 | void SetPlayingSoundVolume(); 42 | 43 | void CreateSoundPool(); 44 | void ReturnToSoundPool(Sound* sound); 45 | Sound* LoadSoundFromPool(); 46 | public: 47 | void CreateFmodChannelGroup(); 48 | void Play(string sound_name, SoundType sound_type, bool looping, float volume, FXMVECTOR generate_pos); 49 | void PlayBackground(string sound_name, bool looping, float fade_in, float volume); 50 | void Stop(string sound_name); 51 | bool FadeOutDelete(string sound_name, float fade_out); 52 | public: 53 | float GetMusicVolume(); 54 | float GetSFXVolume(); 55 | void SetMusicVolume(float volume); 56 | void SetSFXVolume(float volume); 57 | }; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /Engine/src/Systems/AnimationSystem.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "AnimationSystem.h" 3 | #include "SceneMgr.h" 4 | 5 | void reality::AnimationSystem::OnCreate(entt::registry& reg) 6 | { 7 | } 8 | 9 | void reality::AnimationSystem::OnUpdate(entt::registry& reg) 10 | { 11 | const auto& view_anim = reg.view(); 12 | 13 | for (auto ent : view_anim) 14 | { 15 | if (SCENE_MGR->GetActor(ent)->visible) { 16 | auto* animation_component = reg.try_get(ent); 17 | 18 | animation_component->OnUpdate(); 19 | 20 | auto* socket_component = reg.try_get(ent); 21 | if (socket_component != nullptr) { 22 | for (auto& socket_pair : socket_component->sockets) { 23 | auto& socket = socket_pair.second; 24 | socket.animation_matrix = animation_component->GetCurAnimMatirixOfBone(socket.bone_id); 25 | } 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Engine/src/Systems/AnimationSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "System.h" 3 | 4 | namespace reality { 5 | class DLL_API AnimationSystem : public System 6 | { 7 | public: 8 | virtual void OnCreate(entt::registry& reg) override; 9 | virtual void OnUpdate(entt::registry& reg) override; 10 | }; 11 | 12 | } 13 | 14 | -------------------------------------------------------------------------------- /Engine/src/Systems/CameraSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "System.h" 3 | #include "ConstantBuffer.h" 4 | 5 | struct SequenceInfo 6 | { 7 | XMVECTOR sequence_start; 8 | XMVECTOR sequence_end; 9 | XMVECTOR target_start; 10 | XMVECTOR target_end; 11 | float play_time; 12 | float acceler; 13 | float decceler; 14 | int reverse = 0; 15 | }; 16 | 17 | namespace reality 18 | { 19 | class DLL_API CameraSystem : public System 20 | { 21 | public: 22 | CameraSystem(); 23 | ~CameraSystem(); 24 | 25 | void TargetTag(entt::registry& reg, string tag); 26 | virtual void OnCreate(entt::registry& reg); 27 | virtual void OnUpdate(entt::registry& reg); 28 | 29 | 30 | RayShape CreateMouseRay(); 31 | RayShape CreateFrontRay(); 32 | C_Camera* GetCamera(); 33 | XMMATRIX GetViewProj(); 34 | void SetSpeed(float speed) { this->speed = speed; }; 35 | void SetFov(float dgree) { camera->fov = XMConvertToRadians(dgree); }; 36 | void SetFarZ(float z) { camera->far_z = z; }; 37 | void SetNearZ(float z) { camera->near_z = z; }; 38 | XMFLOAT2 ndc; 39 | 40 | void CreateFrustum(); 41 | BoundingFrustum frustum; 42 | XMMATRIX rotation_matrix; 43 | XMMATRIX world_matrix; 44 | XMMATRIX view_matrix; 45 | XMMATRIX projection_matrix; 46 | float mouse_sensivity = 0.5f; 47 | 48 | bool enable_control = true; 49 | bool is_sequence_playing = false; 50 | bool PlaySequence(SequenceInfo seq_info, float reverse_after); 51 | bool ZoomToTarget(XMVECTOR target_pos, XMVECTOR zoom_pos, float play_time, float return_after); 52 | 53 | private: 54 | void DebugCameraMovement(); 55 | void PlayerCameraMovement(); 56 | 57 | void CameraAction(); 58 | void CreateMatrix(); 59 | 60 | private: 61 | C_Camera* camera = nullptr; 62 | D3D11_VIEWPORT* viewport; 63 | 64 | CbCameraInfo cb_camera_info; 65 | CbCameraEffect cb_effect; 66 | 67 | SequenceInfo current_seq_info_; 68 | XMVECTOR current_target_pos_; 69 | XMVECTOR current_sequence_pos_; 70 | 71 | float speed = 30; 72 | }; 73 | } 74 | -------------------------------------------------------------------------------- /Engine/src/Systems/ComponentSystem.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "ComponentSystem.h" 3 | -------------------------------------------------------------------------------- /Engine/src/Systems/ComponentSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Components.h" 3 | 4 | namespace reality { 5 | class DLL_API ComponentSystem 6 | { 7 | SINGLETON(ComponentSystem) 8 | #define COMPONENT ComponentSystem::GetInst() 9 | public: 10 | bool OnInit(entt::registry& registry) { 11 | registry.on_construct().connect<&ComponentSystem::OnConstruct>(this); 12 | registry.on_construct().connect<&ComponentSystem::OnConstruct>(this); 13 | registry.on_construct().connect<&ComponentSystem::OnConstruct>(this); 14 | registry.on_construct().connect<&ComponentSystem::OnConstruct>(this); 15 | registry.on_construct().connect<&ComponentSystem::OnConstruct>(this); 16 | registry.on_construct().connect<&ComponentSystem::OnConstruct>(this); 17 | registry.on_update().connect<&ComponentSystem::OnUpdate>(this); 18 | //registry.on_update().connect<&ComponentSystem::OnUpdate>(this); 19 | 20 | return true; 21 | } 22 | template 23 | void OnConstruct(entt::registry& registry, entt::entity entity) { 24 | registry.get(entity).OnConstruct(); 25 | } 26 | 27 | template 28 | void OnUpdate(entt::registry& registry, entt::entity entity) { 29 | registry.get(entity).OnUpdate(); 30 | } 31 | }; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Engine/src/Systems/EffectSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "System.h" 3 | #include "Effect.h" 4 | 5 | namespace reality 6 | { 7 | class DLL_API EffectSystem : public System 8 | { 9 | public: 10 | virtual void OnCreate(entt::registry& reg); 11 | virtual void OnUpdate(entt::registry& reg); 12 | public: 13 | void UpdateParticles(Emitter* emitter); 14 | void EmitParticles(Emitter* emitter); 15 | void EmitParticle(Emitter* emitter); 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /Engine/src/Systems/LightingSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "System.h" 3 | #include "SkySphere.h" 4 | 5 | namespace reality 6 | { 7 | class DLL_API LightingSystem : public System 8 | { 9 | public: 10 | LightingSystem(); 11 | ~LightingSystem(); 12 | public: 13 | void OnCreate(entt::registry& reg) override; 14 | void OnUpdate(entt::registry& reg) override; 15 | void UpdateGlobalLight(float specular, XMFLOAT4 color); 16 | CbGlobalLight::Data GetGlobalLightData(); 17 | void SetGlobalLightPos(XMFLOAT4 position); 18 | 19 | private: 20 | HRESULT CreateSunCB(); 21 | HRESULT CreatePointLightsCB(); 22 | HRESULT CreateSpotLightsCB(); 23 | 24 | void UpdatePointLights(entt::registry& reg); 25 | void UpdateSpotLights(entt::registry& reg); 26 | 27 | CbGlobalLight global_light; 28 | CbPointLight point_lights; 29 | CbSpotLight spot_lights; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /Engine/src/Systems/MovementSystem.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "TimeMgr.h" 3 | #include "QuadTreeMgr.h" 4 | #include "MovementSystem.h" 5 | #include "EventMgr.h" 6 | 7 | void reality::MovementSystem::OnCreate(entt::registry& reg) 8 | { 9 | } 10 | 11 | void reality::MovementSystem::OnUpdate(entt::registry& reg) 12 | { 13 | auto view_movement = reg.view(); 14 | 15 | for (auto entity_id : view_movement) 16 | { 17 | auto character = SCENE_MGR->GetActor(entity_id); 18 | auto movement_component = character->GetMovementComponent(); 19 | auto c_capsule = SCENE_MGR->GetRegistry().try_get(character->GetEntityId()); 20 | 21 | if (character == nullptr || movement_component == nullptr || c_capsule == nullptr) 22 | return; 23 | 24 | 25 | float cur_y_axis_speed = movement_component->velocity.m128_f32[1]; 26 | 27 | movement_component->velocity.m128_f32[1] = 0.0f; 28 | movement_component->velocity.m128_f32[0] += movement_component->accelaration_vector[0] * movement_component->acceleration * TM_DELTATIME; 29 | movement_component->velocity.m128_f32[2] += movement_component->accelaration_vector[2] * movement_component->acceleration * TM_DELTATIME; 30 | 31 | // deceleration 32 | if (movement_component->accelaration_vector[0] == 0 && 0 <= movement_component->velocity.m128_f32[0]) { 33 | movement_component->velocity.m128_f32[0] -= movement_component->acceleration * 3 * TM_DELTATIME; 34 | movement_component->velocity.m128_f32[0] = max(0.0f, movement_component->velocity.m128_f32[0]); 35 | } 36 | if (movement_component->accelaration_vector[0] == 0 && 0 >= movement_component->velocity.m128_f32[0]) { 37 | movement_component->velocity.m128_f32[0] += movement_component->acceleration * 3 * TM_DELTATIME; 38 | movement_component->velocity.m128_f32[0] = min(0.0f, movement_component->velocity.m128_f32[0]); 39 | } 40 | if (movement_component->accelaration_vector[2] == 0 && 0 <= movement_component->velocity.m128_f32[2]) { 41 | movement_component->velocity.m128_f32[2] -= movement_component->acceleration * 3 * TM_DELTATIME; 42 | movement_component->velocity.m128_f32[2] = max(0.0f, movement_component->velocity.m128_f32[2]); 43 | } 44 | if (movement_component->accelaration_vector[2] == 0 && 0 >= movement_component->velocity.m128_f32[2]) { 45 | movement_component->velocity.m128_f32[2] += movement_component->acceleration * 3 * TM_DELTATIME; 46 | movement_component->velocity.m128_f32[2] = min(0.0f, movement_component->velocity.m128_f32[2]); 47 | } 48 | 49 | movement_component->speed = XMVector3Length(movement_component->velocity).m128_f32[0]; 50 | if (movement_component->speed >= movement_component->max_speed) { 51 | movement_component->velocity = XMVector3Normalize(movement_component->velocity); 52 | movement_component->velocity *= movement_component->max_speed; 53 | movement_component->speed = movement_component->max_speed; 54 | } 55 | 56 | cur_y_axis_speed += movement_component->jump_pulse - movement_component->gravity_pulse * TM_DELTATIME; 57 | movement_component->velocity.m128_f32[1] = cur_y_axis_speed; 58 | XMVECTOR cur_velocity = XMVector3Transform(movement_component->velocity, character->GetRotation()); 59 | 60 | 61 | for (int i = 0; i < 4; ++i) 62 | { 63 | auto plane = character->blocking_planes_[i]; 64 | 65 | if (Vector3Length(_XMVECTOR4(plane)) <= 0.1f) 66 | continue; 67 | 68 | XMVECTOR plane_normal = XMVectorSet(plane.x, plane.y, plane.z, 0); 69 | 70 | if (XMVectorGetX(XMVector3Dot(plane_normal, cur_velocity)) < 0.0f) 71 | cur_velocity = VectorProjectPlane(cur_velocity, plane_normal); 72 | } 73 | for (const auto& block_ray : QUADTREE->blocking_fields_) 74 | { 75 | RayShape ray = block_ray; 76 | ray.start.y = 0.0f; 77 | ray.end.y = 0.0f; 78 | XMVECTOR position = _XMVECTOR3(c_capsule->capsule.base); position.m128_f32[1] = 0.0f; 79 | XMVECTOR segment = PointRaySegment(ray, position); 80 | float distance = Distance(position, segment); 81 | //float distance = XMVector3LinePointDistance(line_start, line_end, position).m128_f32[0]; 82 | if (distance <= c_capsule->capsule.radius) 83 | { 84 | XMVECTOR plane_normal = -1.0f * XMPlaneFromPoints(_XMVECTOR3(ray.start), _XMVECTOR3(ray.start) + XMVectorSet(0, 10000, 0, 0), _XMVECTOR3(ray.end)); 85 | plane_normal.m128_f32[3] = 0.0f; 86 | 87 | if (XMVectorGetX(XMVector3Dot(plane_normal, cur_velocity)) < 0.0f) 88 | cur_velocity = VectorProjectPlane(cur_velocity, plane_normal); 89 | } 90 | } 91 | 92 | XMVECTOR character_cur_postion = character->GetCurPosition(); 93 | character_cur_postion += cur_velocity * TM_DELTATIME; 94 | 95 | if (movement_component->jump_pulse <= 0) 96 | { 97 | if (character->movement_state_ == MovementState::WALK) 98 | character_cur_postion.m128_f32[1] = character->floor_position.y; 99 | } 100 | 101 | character->ApplyMovement(character_cur_postion); 102 | 103 | movement_component->accelaration_vector[0] = 0; 104 | movement_component->accelaration_vector[1] = 0; 105 | movement_component->accelaration_vector[2] = 0; 106 | movement_component->jump_pulse = 0; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /Engine/src/Systems/MovementSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "System.h" 3 | 4 | namespace reality 5 | { 6 | class DLL_API MovementSystem : public System 7 | { 8 | public: 9 | MovementSystem() = default; 10 | ~MovementSystem() = default; 11 | 12 | virtual void OnCreate(entt::registry& reg) override; 13 | virtual void OnUpdate(entt::registry& reg) override; 14 | 15 | XMFLOAT2 ndc; 16 | private: 17 | 18 | 19 | 20 | private: 21 | 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /Engine/src/Systems/PhysicsSystem.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "PhysicsSystem.h" 3 | 4 | using namespace reality; 5 | 6 | void PhysicsSystem::OnCreate(entt::registry& reg) 7 | { 8 | } 9 | 10 | void PhysicsSystem::OnUpdate(entt::registry& reg) 11 | { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Engine/src/Systems/PhysicsSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "System.h" 3 | 4 | namespace reality 5 | { 6 | class DLL_API PhysicsSystem : public System 7 | { 8 | virtual void OnCreate(entt::registry& reg); 9 | virtual void OnUpdate(entt::registry& reg); 10 | }; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /Engine/src/Systems/RenderSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "System.h" 3 | #include "FbxOutData.h" 4 | #include "ConstantBuffer.h" 5 | #include "Mesh.h" 6 | #include "Effect.h" 7 | 8 | namespace reality 9 | { 10 | class DLL_API RenderSystem : public System 11 | { 12 | public: 13 | RenderSystem(); 14 | ~RenderSystem(); 15 | 16 | public: 17 | virtual void OnCreate(entt::registry& reg); 18 | virtual void OnUpdate(entt::registry& reg); 19 | 20 | void PlayAnimation(const Skeleton& skeleton, const C_Animation* const animation_component); 21 | void RenderStaticMesh(const C_StaticMesh* const static_mesh); 22 | void RenderSkeletalMesh(const C_SkeletalMesh* const skeletal_mesh_components, C_Animation* const animation_component); 23 | 24 | // Effect Rendering 25 | void CreateEffectCB(); 26 | void CreateEffectBuffer(); 27 | 28 | void RenderBoxShape(entt::registry& reg); 29 | void RenderEffects(entt::registry& reg); 30 | 31 | public: 32 | void SetEffectCB(Effect& effect, XMMATRIX& world); 33 | void SetEmitterCB(Emitter& emitter); 34 | void SetShaderAndMaterial(Emitter& emitter); 35 | void SetStates(Emitter& emitter); 36 | void SetParticleCB(Particle& particle); 37 | 38 | public: 39 | 40 | private: 41 | ID3D11Device* device_ = nullptr; 42 | ID3D11DeviceContext* device_context_ = nullptr; 43 | 44 | private: 45 | CbTransform cb_transform_; 46 | CbStaticMesh cb_static_mesh_; 47 | CbSkeletalMesh cb_skeletal_mesh_; 48 | 49 | // Effect 50 | EffectVertex effect_vertex_; 51 | ComPtr vertex_buffer_; 52 | CbEffect cb_effect_; 53 | CbEmitter cb_emitter_; 54 | CbParticle cb_particle_; 55 | }; 56 | } 57 | -------------------------------------------------------------------------------- /Engine/src/Systems/SoundSystem.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "TimeMgr.h" 3 | #include "SoundSystem.h" 4 | #include "ResourceMgr.h" 5 | #include "FmodMgr.h" 6 | #include 7 | 8 | using namespace reality; 9 | 10 | void SoundSystem::OnUpdate(entt::registry& reg) 11 | { 12 | CheckGenerators(reg); 13 | } 14 | 15 | void SoundSystem::PlayBackground(string sound_name, bool looping, float fade_in, float volume) 16 | { 17 | FMOD_MGR->PlayBackground(sound_name, looping, fade_in, volume); 18 | } 19 | 20 | bool SoundSystem::FadeOutDelete(string sound_name, float fade_out) 21 | { 22 | return FMOD_MGR->FadeOutDelete(sound_name, fade_out); 23 | } 24 | 25 | void SoundSystem::CheckGenerators(entt::registry& reg) 26 | { 27 | // 업데이트에서는 사운드 제너레이터 컴포넌트를 가지고 있는 엔티티들이 사운드 큐를 가지고 있으면 사운드를 재생한다. 28 | auto generators = reg.view(); 29 | for (auto entity : generators) 30 | { 31 | auto& generator = generators.get(entity); 32 | while (generator.sound_queue_list.size() != 0) 33 | { 34 | auto queue = generator.sound_queue_list.front(); 35 | 36 | // 리스너 컴포넌트를 가지고 있는 엔티티들에 대해 3D 벡터 계산 후 사운드 설정 37 | auto listeners = reg.view(); 38 | for (auto entity2 : listeners) 39 | { 40 | auto& listener_transform = reg.get(entity2); 41 | XMVECTOR listener_position = listener_transform.world.r[3]; 42 | XMVECTOR generator_position; 43 | 44 | auto transform = reg.try_get(entity); 45 | auto capsule_collision = reg.try_get(entity); 46 | auto sphere_collision = reg.try_get(entity); 47 | if (transform) 48 | generator_position = transform->world.r[3]; 49 | else if(capsule_collision) 50 | generator_position = capsule_collision->world.r[3]; 51 | else if (sphere_collision) 52 | generator_position = sphere_collision->world.r[3]; 53 | 54 | XMVECTOR pos = generator_position - listener_position; 55 | FMOD_MGR->Play(queue.sound_filename, queue.sound_type, queue.is_looping, queue.sound_volume, pos); 56 | } 57 | 58 | // 재생했다면 큐에서 제거 59 | generator.sound_queue_list.pop(); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Engine/src/Systems/SoundSystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "System.h" 3 | 4 | 5 | namespace reality { 6 | class DLL_API SoundSystem : public System 7 | { 8 | public: 9 | virtual void OnCreate(entt::registry& reg) {} 10 | virtual void OnUpdate(entt::registry& reg); 11 | 12 | private: 13 | void CheckGenerators(entt::registry& reg); 14 | public: 15 | void PlayBackground(string sound_name, bool looping, float fade_in, float volume); 16 | bool FadeOutDelete(string sound_name, float fade_out); 17 | }; 18 | } 19 | 20 | 21 | -------------------------------------------------------------------------------- /Engine/src/Systems/System.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "System.h" 3 | -------------------------------------------------------------------------------- /Engine/src/Systems/System.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Components.h" 3 | 4 | namespace reality 5 | { 6 | class System 7 | { 8 | public: 9 | System() = default; 10 | ~System() = default; 11 | 12 | virtual void OnCreate(entt::registry& reg) = 0; 13 | virtual void OnUpdate(entt::registry& reg) = 0; 14 | }; 15 | } -------------------------------------------------------------------------------- /Engine/src/Systems/UISystem.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reality-soft/Game-Engine/3e539944ccfbea2be4b24d2c1a1e26cb338e9ea5/Engine/src/Systems/UISystem.cpp -------------------------------------------------------------------------------- /Engine/src/Systems/UISystem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "System.h" 3 | #include "RenderTargetMgr.h" 4 | 5 | namespace reality 6 | { 7 | class DLL_API UISystem : public System 8 | { 9 | public: 10 | static CbUI cb_UI; 11 | public: 12 | static void SetCbData(XMMATRIX world); 13 | public: 14 | shared_ptr render_target_; 15 | public: 16 | virtual void OnCreate(entt::registry& reg); 17 | virtual void OnUpdate(entt::registry& reg); 18 | 19 | }; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Engine/src/Tools/DataTableMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace reality 4 | { 5 | struct DataItem 6 | { 7 | public: 8 | string item_name; 9 | public: 10 | map values; 11 | public: 12 | string GetValue(string category) 13 | { 14 | return values.find(category) != values.end() ? values[category] : ""; 15 | } 16 | bool SetValue(string category, string value) 17 | { 18 | if (values.find(category) == values.end()) 19 | return false; 20 | 21 | 22 | 23 | values[category] = value; 24 | return true; 25 | } 26 | }; 27 | 28 | struct DataTable 29 | { 30 | public: 31 | string sheet_name; 32 | public: 33 | std::vector categories; 34 | std::map> resdic_item; 35 | public: 36 | shared_ptr LoadItem(string item) 37 | { 38 | if (resdic_item.find(item) != resdic_item.end()) 39 | return resdic_item[item]; 40 | else 41 | return NULL; 42 | } 43 | shared_ptr AddItem(string item_name) 44 | { 45 | if (resdic_item.find(item_name) != resdic_item.end()) 46 | return resdic_item[item_name]; 47 | 48 | auto newItem = make_shared(); 49 | 50 | newItem->item_name = item_name; 51 | 52 | for (auto category : categories) 53 | newItem->values.insert({ category, "" }); 54 | 55 | newItem->values["Name"] = item_name; 56 | 57 | resdic_item.insert({ item_name, newItem }); 58 | 59 | return resdic_item[item_name]; 60 | } 61 | bool AddCategory(string category_name, string setting_value = "") 62 | { 63 | 64 | if (find(categories.begin(), categories.end(), category_name) != categories.end()) 65 | return false; 66 | 67 | categories.push_back(category_name); 68 | 69 | for (auto pair : resdic_item) 70 | pair.second->values.insert({ category_name, setting_value }); 71 | 72 | } 73 | bool SetItemName(string origin_name, string name_to_be_changed) 74 | { 75 | if (resdic_item.find(origin_name) == resdic_item.end() || resdic_item.find(name_to_be_changed) != resdic_item.end()) 76 | return false; 77 | 78 | auto item = resdic_item[origin_name]; 79 | resdic_item.erase(origin_name); 80 | item->item_name = name_to_be_changed; 81 | item->values["Name"] = item->item_name; 82 | resdic_item.insert({ item->item_name, item }); 83 | } 84 | }; 85 | 86 | 87 | 88 | class DLL_API DataTableMgr 89 | { 90 | SINGLETON(DataTableMgr) 91 | #define DATA DataTableMgr::GetInst() 92 | private: 93 | string directory_; 94 | public: 95 | string directory() { return directory_; } 96 | void set_directory(string dir) { directory_ = dir; } 97 | private: 98 | std::map> resdic_sheet; 99 | public: 100 | bool Init(string directory); 101 | void Release(); 102 | public: 103 | shared_ptr AddNewSheet(string sheet_name); 104 | shared_ptr LoadSheet(string sheet_name); 105 | public: 106 | std::vector GetAllDataSheetID(); 107 | public: 108 | void LoadAllData(); 109 | void LoadDir(string path); 110 | void LoadSheetFile(string fileName); 111 | void SaveSheetFile(string sheetName); 112 | void SaveSheetFileAs(string sheetName, string fileName); 113 | void SaveSprite(string sheetName); 114 | void SaveEffect(string sheetName); 115 | void SaveAll(); 116 | }; 117 | 118 | } -------------------------------------------------------------------------------- /Engine/src/Tools/FbxLoader.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reality-soft/Game-Engine/3e539944ccfbea2be4b24d2c1a1e26cb338e9ea5/Engine/src/Tools/FbxLoader.cpp -------------------------------------------------------------------------------- /Engine/src/Tools/FbxLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "FbxOutData.h" 3 | #include "DllMacro.h" 4 | 5 | #ifdef _DEBUG 6 | namespace reality { 7 | struct FbxImportOption 8 | { 9 | float import_scale = 1.0f; 10 | FbxVector4 import_rotation = { 0.0f, 0.0f, 0.0f, 1.0f }; 11 | bool recalculate_normal = false; 12 | }; 13 | 14 | enum class FbxVertexOption 15 | { 16 | BY_CONTROL_POINT, 17 | BY_POLYGON_VERTEX 18 | }; 19 | 20 | class DLL_API FbxLoader 21 | { 22 | public: 23 | FbxLoader() = default; 24 | ~FbxLoader() = default; 25 | 26 | public: 27 | vector out_mesh_list; 28 | map out_anim_map; 29 | FbxImportOption import_options; 30 | 31 | public: 32 | bool LoadFromFbxFile(string filename); 33 | void LoadAnimation(FbxTime::EMode time_mode, const string& filename); 34 | void Destroy(); 35 | 36 | private: 37 | FbxManager* fbx_manager = nullptr; 38 | FbxImporter* fbx_importer = nullptr; 39 | FbxScene* fbx_scene = nullptr; 40 | FbxNode* root_node = nullptr; 41 | 42 | map out_mesh_map; 43 | unordered_map skeleton_bone_map; 44 | unordered_map skeleton_name_map; 45 | map node_id_map; 46 | vector node_list; 47 | 48 | FbxAMatrix import_transform; 49 | FbxAMatrix local_matrix; 50 | private: 51 | void PreProcess(FbxNode* fbx_node); 52 | void ParseMesh(FbxMesh* fbx_mesh, OutMeshData* out_mesh); 53 | bool ParseMeshSkinning(FbxMesh* fbx_mesh, OutMeshData* out_mesh); 54 | AnimFrame InitAnimation(int stack_index, FbxTime::EMode time_mode, string& anim_name); 55 | 56 | FbxVector2 ReadUV(FbxMesh* fbx_mesh, FbxLayerElementUV* vertex_uv_set, int pos_index, int uv_index); 57 | FbxColor ReadColor(FbxMesh* fbx_mesh, FbxLayerElementVertexColor* vertex_color_set, int pos_index, int color_index); 58 | FbxVector4 ReadNormal(FbxMesh* fbx_mesh, FbxLayerElementNormal* vertex_normal_set, int pos_index, int color_index); 59 | 60 | XMMATRIX FbxToDxConvert(FbxAMatrix& fbx_matrix); 61 | void CreateMaterialFile(string mesh_name); 62 | void RefineMeshName(string& mesh_name); 63 | }; 64 | 65 | } 66 | #endif -------------------------------------------------------------------------------- /Engine/src/Tools/FbxMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "FbxLoader.h" 3 | #include "Mesh.h" 4 | 5 | namespace reality { 6 | 7 | class DLL_API FbxMgr 8 | { 9 | SINGLETON(FbxMgr) 10 | #define FBX FbxMgr::GetInst() 11 | 12 | public: 13 | #ifdef _DEBUG 14 | bool ImportAndSaveFbx(string filename, FbxImportOption options = FbxImportOption(), FbxVertexOption vertex_option = FbxVertexOption::BY_CONTROL_POINT); 15 | #endif 16 | 17 | private: 18 | void SaveStaticMesh(const StaticMesh& static_mesh, string filename); 19 | void SaveSkeletalMesh(const SkeletalMesh& skeletal_mesh, string filename); 20 | void SaveAnimation(const map& animation); 21 | 22 | public: 23 | StaticMesh LoadStaticMesh(string filename); 24 | SkeletalMesh LoadSkeletalMesh(string filename); 25 | reality::OutAnimData LoadAnimation(string filename); 26 | 27 | private: 28 | bool CreateBuffers(SingleMesh& mesh); 29 | bool CreateBuffers(SingleMesh& mesh); 30 | #ifdef _DEBUG 31 | void ReCalculateNormal(StaticMesh& static_mesh, FbxVertexOption vertex_option); 32 | void ReCalculateNormal(SkeletalMesh& skeletal_mesh, FbxVertexOption vertex_option); 33 | #endif 34 | }; 35 | } 36 | 37 | 38 | -------------------------------------------------------------------------------- /Engine/src/Tools/FbxOutData.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "FbxOutData.h" 3 | 4 | namespace reality 5 | { 6 | void IndexWeight::insert(int index_, float weight_) 7 | { 8 | for (int i = 0; i < 8; i++) 9 | { 10 | if (weight_ > weight[i]) 11 | { 12 | for (int j = 7; j > i; --j) 13 | { 14 | index[j] = index[j - 1]; 15 | weight[j] = weight[j - 1]; 16 | } 17 | index[i] = index_; 18 | weight[i] = weight_; 19 | break; 20 | } 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Engine/src/Tools/FbxOutData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vertex.h" 3 | #include "Skeleton.h" 4 | 5 | namespace reality 6 | { 7 | struct AnimTrack 8 | { 9 | UINT frame; 10 | XMMATRIX anim_mat; 11 | XMVECTOR translation_vec; 12 | XMVECTOR rotation_vec; 13 | XMVECTOR scaling_vec; 14 | }; 15 | 16 | struct AnimFrame 17 | { 18 | ULONG64 start; 19 | ULONG64 end; 20 | }; 21 | 22 | struct IndexWeight 23 | { 24 | int index[8] = { 0, }; 25 | float weight[8] = { 0, }; 26 | 27 | void insert(int index_, float weight_); 28 | }; 29 | 30 | struct OutMeshData 31 | { 32 | bool is_skinned = false; 33 | 34 | std::string mesh_name; 35 | std::string material_name; 36 | std::vector vertices_by_control_point; 37 | std::vector vertices_by_polygon_vertex; 38 | std::vector skinned_vertices_by_control_point; 39 | std::vector skinned_vertices_by_polygon_vertex; 40 | std::vector indices; 41 | std::vector index_weight; 42 | std::map bind_poses; 43 | std::map name_bone_map; 44 | }; 45 | 46 | struct OutAnimData 47 | { 48 | std::map> animation_matrices; 49 | UINT start_frame = 0; 50 | UINT end_frame = 0; 51 | }; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Engine/src/Tools/FileTransfer.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "FileTransfer.h" 3 | 4 | using namespace reality; 5 | 6 | TextFileTransfer::TextFileTransfer(string dirname, ReadOrWrite mode) 7 | { 8 | switch (mode) 9 | { 10 | case READ: in_stream.open(dirname); break; 11 | case WRITE: out_stream.open(dirname); break; 12 | } 13 | } 14 | 15 | TextFileTransfer::~TextFileTransfer() 16 | { 17 | Close(); 18 | } 19 | 20 | bool TextFileTransfer::WriteText(string tag, string text) 21 | { 22 | if (!out_stream.is_open()) 23 | return false; 24 | 25 | out_stream << string(tag + " : " + text) << endl; 26 | 27 | return true; 28 | } 29 | 30 | string TextFileTransfer::ReadText(string tag) 31 | { 32 | if (!in_stream.is_open()) 33 | return string(); 34 | 35 | char buffer[128]; 36 | while (in_stream.getline(buffer, sizeof(buffer))) 37 | { 38 | if (string(buffer).find(tag) != string::npos) 39 | break; 40 | } 41 | 42 | vector splited = split(string(buffer), ' : '); 43 | 44 | return splited.back(); 45 | } 46 | 47 | void TextFileTransfer::Close() 48 | { 49 | if (in_stream.is_open()) 50 | in_stream.close(); 51 | 52 | if (out_stream.is_open()) 53 | in_stream.close(); 54 | } 55 | -------------------------------------------------------------------------------- /Engine/src/Tools/FileTransfer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace reality 3 | { 4 | enum 5 | { 6 | READ, WRITE 7 | } typedef ReadOrWrite; 8 | 9 | class DLL_API TextFileTransfer 10 | { 11 | public: 12 | TextFileTransfer(string dirname, ReadOrWrite mode); 13 | ~TextFileTransfer(); 14 | 15 | public: 16 | bool WriteText(string tag, string text); 17 | string ReadText(string tag); 18 | 19 | public: 20 | void Close(); 21 | 22 | private: 23 | ofstream out_stream; 24 | ifstream in_stream; 25 | string file_dirname; 26 | }; 27 | 28 | class DLL_API FileTransfer 29 | { 30 | public: 31 | FileTransfer(string dirname, ReadOrWrite mode) 32 | { 33 | file_dirname = dirname; 34 | if (mode == WRITE) 35 | errno_t error = fopen_s(&file_ptr, dirname.c_str(), "wb"); 36 | else if (mode == READ) 37 | errno_t error = fopen_s(&file_ptr, dirname.c_str(), "rb"); 38 | } 39 | ~FileTransfer() 40 | { 41 | Close(); 42 | } 43 | public: 44 | template 45 | bool WriteBinary(T* data, size_t size); 46 | 47 | template 48 | void ReadBinary(vector& buffer); 49 | 50 | template 51 | void ReadBinary(T& single); 52 | 53 | template 54 | bool WriteBinaryWithoutSize(T* data, size_t size); 55 | 56 | template 57 | vector ReadBinaryWithoutSize(size_t size); 58 | 59 | void Close() 60 | { 61 | if (file_ptr) 62 | fclose(file_ptr); 63 | } 64 | 65 | private: 66 | FILE* file_ptr = nullptr; 67 | string file_dirname; 68 | string seiral; 69 | }; 70 | 71 | template 72 | inline bool FileTransfer::WriteBinaryWithoutSize(T* data, size_t size) 73 | { 74 | if (file_ptr == nullptr) 75 | return false; 76 | 77 | size_t write_size = fwrite(data, sizeof(T), size, file_ptr); 78 | 79 | if (write_size <= 0) 80 | return false; 81 | 82 | return true; 83 | } 84 | 85 | template 86 | inline vector FileTransfer::ReadBinaryWithoutSize(size_t size) 87 | { 88 | vector read_data; 89 | 90 | read_data.resize(size); 91 | 92 | size_t read_size = fread(read_data.data(), sizeof(T), size, file_ptr); 93 | 94 | return read_data; 95 | } 96 | 97 | template 98 | inline void FileTransfer::ReadBinary(vector& buffer) 99 | { 100 | size_t size = 0; 101 | fread(&size, sizeof(size_t), 1, file_ptr); 102 | buffer.resize(size); 103 | 104 | size_t read_size = fread(buffer.data(), sizeof(T), size, file_ptr); 105 | } 106 | 107 | template 108 | inline void FileTransfer::ReadBinary(T& single) 109 | { 110 | size_t size = 0; 111 | fread(&size, sizeof(size_t), 1, file_ptr); 112 | if (size == 1) 113 | { 114 | size_t read_size = fread(&single, sizeof(T), 1, file_ptr); 115 | } 116 | } 117 | 118 | template 119 | inline bool FileTransfer::WriteBinary(T* data, size_t size) 120 | { 121 | if (file_ptr == nullptr) 122 | return false; 123 | 124 | fwrite(&size, sizeof(size_t), 1, file_ptr); 125 | size_t write_size = fwrite(data, sizeof(T), size, file_ptr); 126 | 127 | if (write_size <= 0) 128 | return false; 129 | 130 | return true; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /Engine/src/Tools/GUIMgr.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "GUIMgr.h" 3 | 4 | #ifdef _DEBUG 5 | using namespace reality; 6 | 7 | void GUIMgr::Init(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* context) 8 | { 9 | IMGUI_CHECKVERSION(); 10 | ImGui::CreateContext(); 11 | ImGuiIO& io = ImGui::GetIO(); (void)io; 12 | 13 | io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; 14 | io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; 15 | io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; 16 | 17 | ImGui::StyleColorsDark(); 18 | 19 | ImGuiStyle& style = ImGui::GetStyle(); 20 | if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) 21 | { 22 | style.WindowRounding = 0.0f; 23 | style.Colors[ImGuiCol_WindowBg].w = 1.0f; 24 | } 25 | 26 | ImGui_ImplWin32_Init(hwnd); 27 | ImGui_ImplDX11_Init(device, context); 28 | 29 | 30 | // Create an ImFontConfig object 31 | ImFontConfig fontConfig; 32 | fontConfig.SizePixels = 1.f; 33 | 34 | // store context instance 35 | this->context = ImGui::GetCurrentContext(); 36 | } 37 | 38 | void GUIMgr::RenderWidgets() 39 | { 40 | ImGui_ImplDX11_NewFrame(); 41 | ImGui_ImplWin32_NewFrame(); 42 | ImGui::NewFrame(); 43 | 44 | for (auto& widget : widgets) 45 | { 46 | widget.second->WidgetRender(); 47 | } 48 | 49 | ImGui::Render(); 50 | ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); 51 | if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) 52 | { 53 | ImGui::UpdatePlatformWindows(); 54 | ImGui::RenderPlatformWindowsDefault(); 55 | } 56 | ImGui::EndFrame(); 57 | } 58 | 59 | ImGuiContext* reality::GUIMgr::GetContext() 60 | { 61 | return context; 62 | } 63 | 64 | ImFont* reality::GUIMgr::AddFont(string font_name, LPCSTR ttf_file, float font_size) 65 | { 66 | ImFont* new_font; 67 | 68 | if (ttf_file == nullptr) 69 | { 70 | new_font = ImGui::GetIO().Fonts->AddFontFromFileTTF(base_font_file, font_size, nullptr); 71 | } 72 | else 73 | { 74 | new_font = ImGui::GetIO().Fonts->AddFontFromFileTTF(ttf_file, font_size, nullptr); 75 | } 76 | 77 | font_map.insert(make_pair(font_name, new_font)); 78 | 79 | return new_font; 80 | } 81 | #endif -------------------------------------------------------------------------------- /Engine/src/Tools/GUIMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifdef _DEBUG 3 | #include "stdafx.h" 4 | #include "DllMacro.h" 5 | #include "DX11App.h" 6 | 7 | #include "imgui.h" 8 | #include "imgui_impl_win32.h" 9 | #include "imgui_impl_dx11.h" 10 | #include "imgui_internal.h" 11 | #include "imfilebrowser.h" 12 | 13 | namespace reality 14 | { 15 | class DLL_API GuiWidget 16 | { 17 | public: 18 | GuiWidget() = default; 19 | ~GuiWidget() = default; 20 | 21 | public: 22 | bool open_ = true; 23 | virtual void Init() {}; 24 | virtual void Update() = 0; 25 | virtual void Render() = 0; 26 | void WidgetRender() { 27 | if (open_ == false) { 28 | return; 29 | } 30 | Update(); 31 | Render(); 32 | } 33 | void InvertOpen() { 34 | open_ = !open_; 35 | } 36 | }; 37 | 38 | class DLL_API GUIMgr 39 | { 40 | SINGLETON(GUIMgr); 41 | #define GUI GUIMgr::GetInst() 42 | 43 | public: 44 | void Init(HWND hwnd, ID3D11Device* device, ID3D11DeviceContext* context); 45 | void RenderWidgets(); 46 | 47 | 48 | template 49 | void AddWidget(string widget_name, Args&&...args); 50 | 51 | template 52 | WidgetType* FindWidget(string widget_name); 53 | 54 | ImGuiContext* GetContext(); 55 | LPCSTR base_font_file; 56 | map font_map; 57 | ImFont* AddFont(string font_name, LPCSTR ttf_file, float font_size); 58 | private: 59 | ImGuiContext* context; 60 | unordered_map> widgets; 61 | }; 62 | 63 | template 64 | void GUIMgr::AddWidget(string widget_name, Args&&...args) 65 | { 66 | if (FindWidget(widget_name) != nullptr) 67 | return; 68 | 69 | shared_ptr widget = dynamic_pointer_cast(make_shared(args...)); 70 | widget->Init(); 71 | 72 | widgets.insert(make_pair(widget_name, widget)); 73 | } 74 | 75 | template 76 | WidgetType* GUIMgr::FindWidget(string widget_name) 77 | { 78 | auto iter = widgets.find(widget_name); 79 | if (iter == widgets.end()) 80 | return nullptr; 81 | 82 | return dynamic_cast(iter->second.get()); 83 | } 84 | } 85 | #endif -------------------------------------------------------------------------------- /Engine/src/UI/UIBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UI.h" 3 | 4 | namespace reality 5 | { 6 | enum E_Resolution; 7 | 8 | class DLL_API UIBase 9 | { 10 | protected: 11 | bool onoff_; 12 | E_UIState current_state_; 13 | public: 14 | UIBase* parent_ui_; 15 | map> child_ui_list_; 16 | public: 17 | vector rect_transform_; 18 | RectRenderData render_data_; 19 | protected: 20 | virtual void Init(); 21 | public: 22 | virtual void Update(); 23 | virtual void Render(); 24 | private: 25 | void CreateRenderData(); 26 | protected: 27 | virtual void UpdateThisUI(); 28 | virtual void RenderThisUI(); 29 | public: 30 | void AddChildUI(string name, shared_ptr child_ui); 31 | void DeleteChildUI(string name); 32 | E_UIState GetCurrentState(); 33 | void SetCurrentState(E_UIState state); 34 | void UpdateRectTransform(); 35 | public: 36 | bool GetOnOff(); 37 | void On(); 38 | void Off(); 39 | void SetAlpha(float alpha); 40 | void UpdateRenderCB(); 41 | public: 42 | virtual void SetLocalRectByMin(XMFLOAT2 min, float width, float height); 43 | virtual void SetLocalRectByMax(XMFLOAT2 max, float width, float height); 44 | virtual void SetLocalRectByCenter(XMFLOAT2 center, float width, float height); 45 | virtual void SetLocalRectByMinMax(XMFLOAT2 min, XMFLOAT2 max); 46 | private: 47 | virtual void ComputeLocalRectByMin(E_Resolution resolution, XMFLOAT2 min, float width, float height); 48 | virtual void ComputeLocalRectByMax(E_Resolution resolution, XMFLOAT2 max, float width, float height); 49 | virtual void ComputeLocalRectByCenter(E_Resolution resolution, XMFLOAT2 center, float width, float height); 50 | virtual void ComputeLocalRectByMinMax(E_Resolution resolution, XMFLOAT2 min, XMFLOAT2 max); 51 | }; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Engine/src/UI/UI_Button.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "UI_Button.h" 3 | #include "Engine.h" 4 | #include "InputMgr.h" 5 | #include "FmodMgr.h" 6 | 7 | using namespace reality; 8 | 9 | 10 | void UI_Button::InitButton(string normal, string hover, string push, string select, string disable) 11 | { 12 | UIBase::Init(); 13 | button_texture_list[E_UIState::UI_NORMAL] = normal; 14 | button_texture_list[E_UIState::UI_HOVER] = hover; 15 | button_texture_list[E_UIState::UI_PUSH] = push; 16 | button_texture_list[E_UIState::UI_SELECT] = select; 17 | button_texture_list[E_UIState::UI_DISABLED] = disable; 18 | 19 | last_state_ = current_state_; 20 | } 21 | 22 | void reality::UI_Button::SetButtonSound(string hover, string push, string select) 23 | { 24 | hover_sound_ = hover; 25 | push_sound_ = push; 26 | select_sound_ = select; 27 | } 28 | 29 | void UI_Button::Update() 30 | { 31 | UIBase::Update(); 32 | 33 | UpdateButtonState(); 34 | 35 | UpdateButtonTexture(); 36 | } 37 | 38 | bool UI_Button::MouseOnButton(const Rect& button_rect, const POINT& mouse_point) 39 | { 40 | if ((button_rect.min.x <= mouse_point.x && mouse_point.x <= button_rect.max.x)) 41 | { 42 | if ((button_rect.min.y <= mouse_point.y && mouse_point.y <= button_rect.max.y)) 43 | { 44 | return true; 45 | } 46 | } 47 | return false; 48 | } 49 | 50 | void UI_Button::UpdateButtonState() 51 | { 52 | if (!onoff_) 53 | return; 54 | auto resolution = ENGINE->GetWindowResolution(); 55 | if (MouseOnButton(rect_transform_[resolution].world_rect, DINPUT->GetMousePosition())) 56 | { 57 | if (DINPUT->GetMouseState(L_BUTTON) == KeyState::KEY_PUSH || DINPUT->GetMouseState(L_BUTTON) == KeyState::KEY_HOLD) 58 | { 59 | current_state_ = E_UIState::UI_PUSH; 60 | if(last_state_ != E_UIState::UI_PUSH && push_sound_ != "") 61 | FMOD_MGR->Play(push_sound_, SFX, false, 1.0f, {}); 62 | 63 | } 64 | else if (DINPUT->GetMouseState(L_BUTTON) == KeyState::KEY_UP) 65 | { 66 | current_state_ = E_UIState::UI_SELECT; 67 | if (last_state_ != E_UIState::UI_SELECT && select_sound_ != "") 68 | FMOD_MGR->Play(select_sound_, SFX, false, 1.0f, {}); 69 | } 70 | else 71 | { 72 | current_state_ = E_UIState::UI_HOVER; 73 | if (last_state_ != E_UIState::UI_HOVER && hover_sound_ != "") 74 | FMOD_MGR->Play(hover_sound_, SFX, false, 1.0f, {}); 75 | } 76 | } 77 | else if (current_state_ == E_UIState::UI_PUSH && DINPUT->GetMouseState(L_BUTTON) == KeyState::KEY_HOLD) 78 | { 79 | current_state_ = E_UIState::UI_PUSH; 80 | if (last_state_ != E_UIState::UI_PUSH && select_sound_ != "") 81 | FMOD_MGR->Play(push_sound_, SFX, false, 1.0f, {}); 82 | } 83 | else 84 | { 85 | current_state_ = E_UIState::UI_NORMAL; 86 | } 87 | 88 | last_state_ = current_state_; 89 | //OutputDebugString(to_wstring((int)last_state_).c_str()); 90 | } 91 | 92 | void UI_Button::UpdateButtonTexture() 93 | { 94 | if (button_texture_list[current_state_] == "") 95 | { 96 | render_data_.tex_id = button_texture_list[E_UIState::UI_NORMAL]; 97 | } 98 | else 99 | { 100 | render_data_.tex_id = button_texture_list[current_state_]; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /Engine/src/UI/UI_Button.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIBase.h" 3 | 4 | namespace reality 5 | { 6 | class DLL_API UI_Button : public UIBase 7 | { 8 | private: 9 | map button_texture_list; 10 | E_UIState last_state_; 11 | string hover_sound_; 12 | string push_sound_; 13 | string select_sound_; 14 | public: 15 | void InitButton(string normal, string hover, string push = "", string select = "", string disable = ""); 16 | void SetButtonSound(string hover, string push, string select); 17 | virtual void Update() override; 18 | 19 | private: 20 | bool MouseOnButton(const Rect& button_rect, const POINT& mouse_point); 21 | void UpdateButtonState(); 22 | void UpdateButtonTexture(); 23 | }; 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /Engine/src/UI/UI_Image.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "UI_Image.h" 3 | 4 | using namespace reality; 5 | 6 | void UI_Image::InitImage(string tex_id) 7 | { 8 | UIBase::Init(); 9 | render_data_.tex_id = tex_id; 10 | } 11 | 12 | void UI_Image::SetImage(string tex_id) 13 | { 14 | render_data_.tex_id = tex_id; 15 | } 16 | -------------------------------------------------------------------------------- /Engine/src/UI/UI_Image.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIBase.h" 3 | 4 | namespace reality 5 | { 6 | class DLL_API UI_Image : public UIBase 7 | { 8 | public: 9 | void InitImage(string tex_id); 10 | void SetImage(string tex_id); 11 | }; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /Engine/src/UI/UI_Listbox.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UI_Image.h" 3 | #include "UI_Button.h" 4 | #include "UI_Text.h" 5 | 6 | namespace reality 7 | { 8 | class DLL_API UI_Listbox : public UI_Button 9 | { 10 | private: 11 | unordered_map list_button_textures; 12 | private: 13 | unordered_map item_button_textures; 14 | XMFLOAT2 item_button_min_; 15 | float item_button_width_; 16 | float item_button_height_; 17 | float item_button_height_space_; 18 | int selected_item_num_; 19 | private: 20 | bool open_ = false; 21 | private: 22 | vector item_list_; 23 | vector> item_button_list_; 24 | private: 25 | shared_ptr open_panel_; 26 | shared_ptr current_item_text_; 27 | public: 28 | void InitListBox(string open_panel, string closed_normal, string opened_normal, 29 | string closed_hover = "", string opened_hover = "", 30 | string closed_push = "", string opened_push = "", 31 | string closed_select = "", string opened_select = "", 32 | string closed_disable = "", string opened_disable = ""); 33 | 34 | void InitItemButton(XMFLOAT2 min, float width, float height, float height_space, string normal, string hover, string push =" ", string select = "", string disable = ""); 35 | void SetItemButtonSound(string hover, string push, string select); 36 | 37 | void SetOpenPanelLocalRectByMin (XMFLOAT2 min, float width, float height); 38 | void SetOpenPanelLocalRectByMax (XMFLOAT2 max, float width, float height); 39 | void SetOpenPanelLocalRectByCenter(XMFLOAT2 center, float width, float height); 40 | void SetOpenPanelLocalRectByMinMax(XMFLOAT2 min, XMFLOAT2 max); 41 | public: 42 | virtual void Update() override; 43 | public: 44 | void AddItem(string value); 45 | string GetCurrentItem(); 46 | int GetCurrentIndex(); 47 | string GetItem(int index); 48 | string GetItem(string value); 49 | void SetItemSelected(int index); 50 | void SetItemSelected(string value); 51 | private: 52 | void OpenListBox(); 53 | void CloseListBox(); 54 | void SetListBoxText(string text); 55 | }; 56 | } 57 | 58 | 59 | -------------------------------------------------------------------------------- /Engine/src/UI/UI_Slider.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "UI_Slider.h" 3 | #include "Engine.h" 4 | #include "InputMgr.h" 5 | 6 | using namespace reality; 7 | 8 | 9 | void UI_Slider::InitSlider(string background, string normal, string hover, string push, string select, string disable) 10 | { 11 | UIBase::Init(); 12 | 13 | render_data_.tex_id = background; 14 | slider_ = make_shared(); 15 | slider_->InitButton(normal, hover, push, select, disable); 16 | AddChildUI("1_Slider", slider_); 17 | value_ = 50.0f; 18 | last_value_ = 50.0f; 19 | } 20 | 21 | void UI_Slider::Update() 22 | { 23 | UIBase::Update(); 24 | 25 | UpdateSliderPos(); 26 | 27 | if (value_ != last_value_) 28 | is_changed_ = true; 29 | else 30 | is_changed_ = false; 31 | 32 | last_value_ = value_; 33 | } 34 | 35 | void UI_Slider::UpdateSliderPos() 36 | { 37 | if (slider_->GetCurrentState() == E_UIState::UI_PUSH) 38 | { 39 | auto resolution = ENGINE->GetWindowResolution(); 40 | float x = (float)DINPUT->GetMousePosition().x - rect_transform_[resolution].world_rect.min.x; 41 | x = max(x, 0.0f); 42 | x = min(x, rect_transform_[resolution].world_rect.width); 43 | slider_->SetLocalRectByCenter({ x * 1.0f / E_Resolution_Multiply[resolution], rect_transform_[E_Resolution::R1920x1080].world_rect.height / 2.0f}, 44 | slider_->rect_transform_[E_Resolution::R1920x1080].world_rect.width, slider_->rect_transform_[E_Resolution::R1920x1080].world_rect.height); 45 | 46 | value_ = 100.0f * x / rect_transform_[resolution].world_rect.width; 47 | } 48 | } 49 | 50 | float UI_Slider::GetValue() 51 | { 52 | return value_; 53 | } 54 | 55 | void UI_Slider::SetSliderLocalRect(float width, float height) 56 | { 57 | slider_->SetLocalRectByCenter({ rect_transform_[E_Resolution::R1920x1080].world_rect.width / 2.0f, rect_transform_[E_Resolution::R1920x1080].world_rect.height / 2.0f }, width, height); 58 | } 59 | -------------------------------------------------------------------------------- /Engine/src/UI/UI_Slider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UI_Image.h" 3 | #include "UI_Button.h" 4 | 5 | namespace reality 6 | { 7 | class DLL_API UI_Slider : public UI_Image 8 | { 9 | private: 10 | float value_; 11 | float last_value_; 12 | bool is_changed_; 13 | shared_ptr slider_; 14 | public: 15 | void InitSlider(string background, string normal, string hover, string push = "", string select = "", string disable = ""); 16 | void SetSliderLocalRect(float width, float height); 17 | virtual void Update() override; 18 | void UpdateSliderPos(); 19 | float GetValue(); 20 | bool GetIsChanged() { return is_changed_; }; 21 | }; 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /Engine/src/UI/UI_Sprite.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "UI_Sprite.h" 3 | #include "ResourceMgr.h" 4 | #include "TimeMgr.h" 5 | 6 | using namespace reality; 7 | 8 | void UI_Sprite::InitSprite(string sprite_id, float speed, bool looping) 9 | { 10 | UIBase::Init(); 11 | sprite_id_ = sprite_id; 12 | sprite_data_ = (TextureSprite*)RESOURCE->UseResource(sprite_id_); 13 | speed_ = speed; 14 | looping_ = looping; 15 | current_frame_ = 0; 16 | } 17 | 18 | void reality::UI_Sprite::UpdateThisUI() 19 | { 20 | if (sprite_data_ == nullptr) 21 | return; 22 | 23 | if (current_frame_ < sprite_data_->tex_id_list.size()) 24 | current_frame_ += speed_ * TIMER->GetDeltaTime(); 25 | else if (looping_) 26 | current_frame_ = 0; 27 | else 28 | current_frame_ = sprite_data_->tex_id_list.size() - 1; 29 | 30 | render_data_.tex_id = sprite_data_->tex_id_list[current_frame_]; 31 | } 32 | -------------------------------------------------------------------------------- /Engine/src/UI/UI_Sprite.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIBase.h" 3 | #include "Effect.h" 4 | 5 | namespace reality 6 | { 7 | class DLL_API UI_Sprite : public UIBase 8 | { 9 | public: 10 | void InitSprite(string sprite_id, float speed, bool looping); 11 | public: 12 | virtual void UpdateThisUI() override; 13 | private: 14 | TextureSprite* sprite_data_; 15 | string sprite_id_; 16 | float speed_; 17 | bool looping_; 18 | private: 19 | int current_frame_; 20 | }; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /Engine/src/UI/UI_Text.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "UI_Text.h" 3 | #include "Engine.h" 4 | 5 | using namespace reality; 6 | 7 | void UI_Text::InitText(string text, E_Font font, XMFLOAT2 pos, float size, XMFLOAT4 color) 8 | { 9 | UIBase::Init(); 10 | text_ = text; 11 | font_ = font; 12 | SetLocalRectByMin(pos, 100.0f, 100.0f); 13 | size_ = size; 14 | color_ = color; 15 | } 16 | 17 | void UI_Text::SetText(string text) 18 | { 19 | text_ = text; 20 | } 21 | 22 | void UI_Text::SetFont(E_Font font) 23 | { 24 | font_ = font; 25 | } 26 | 27 | void UI_Text::RenderThisUI() 28 | { 29 | auto resolution = ENGINE->GetWindowResolution(); 30 | WRITER->Draw(text_, font_, rect_transform_[resolution].world_rect.min, size_ * E_Resolution_Multiply[resolution], color_); 31 | } 32 | -------------------------------------------------------------------------------- /Engine/src/UI/UI_Text.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "UIBase.h" 3 | #include "WriteMgr.h" 4 | 5 | namespace reality 6 | { 7 | class DLL_API UI_Text : public UIBase 8 | { 9 | private: 10 | string text_; 11 | E_Font font_; 12 | float size_; 13 | XMFLOAT4 color_; 14 | public: 15 | void InitText(string text, E_Font font, XMFLOAT2 pos = {0.0f, 0.0f}, float size = 1.0f, XMFLOAT4 color = { 1.0f, 1.0f, 1.0f, 1.0f }); 16 | void SetText(string text); 17 | void SetFont(E_Font font); 18 | string GetText() { return text_; } 19 | private: 20 | virtual void RenderThisUI() override; 21 | }; 22 | } 23 | 24 | 25 | -------------------------------------------------------------------------------- /Engine/src/UI/WriteMgr.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "WriteMgr.h" 3 | #include "DX11App.h" 4 | using namespace reality; 5 | 6 | void WriteMgr::Init() 7 | { 8 | sprite_batch_ = std::make_unique(DX11APP->GetDeviceContext()); 9 | sprite_font_basic_ = std::make_unique(DX11APP->GetDevice(), L"../../Contents/SpriteFont/Basic.spritefont"); 10 | sprite_font_rotunda_ = std::make_unique(DX11APP->GetDevice(), L"../../Contents/SpriteFont/BerryRotunda.spritefont"); 11 | sprite_font_eurocine_ = std::make_unique(DX11APP->GetDevice(), L"../../Contents/SpriteFont/Eurocine.spritefont"); 12 | sprite_font_altone_ = std::make_unique(DX11APP->GetDevice(), L"../../Contents/SpriteFont/Altone.spritefont"); 13 | sprite_font_renogare_ = std::make_unique(DX11APP->GetDevice(), L"../../Contents/SpriteFont/Renogare.spritefont"); 14 | sprite_font_roboto_ = std::make_unique(DX11APP->GetDevice(), L"../../Contents/SpriteFont/Roboto.spritefont"); 15 | } 16 | 17 | void WriteMgr::Draw(string text, E_Font font, XMFLOAT2 coord, float size, XMFLOAT4 color) 18 | { 19 | sprite_batch_->Begin(); 20 | switch (font) 21 | { 22 | case BASIC: 23 | sprite_font_basic_->DrawString(sprite_batch_.get(), to_mw(text).c_str(), coord, XMLoadFloat4(&color), 0, {}, size); 24 | break; 25 | case ROTUNDA: 26 | sprite_font_rotunda_->DrawString(sprite_batch_.get(), to_mw(text).c_str(), coord, XMLoadFloat4(&color), 0, {}, size); 27 | break; 28 | case EUROCINE: 29 | sprite_font_eurocine_->DrawString(sprite_batch_.get(), to_mw(text).c_str(), coord, XMLoadFloat4(&color), 0, {}, size); 30 | break; 31 | case ALTONE: 32 | sprite_font_altone_->DrawString(sprite_batch_.get(), to_mw(text).c_str(), coord, XMLoadFloat4(&color), 0, {}, size); 33 | break; 34 | case RENOGARE: 35 | sprite_font_renogare_->DrawString(sprite_batch_.get(), to_mw(text).c_str(), coord, XMLoadFloat4(&color), 0, {}, size); 36 | break; 37 | case ROBOTO: 38 | sprite_font_roboto_->DrawString(sprite_batch_.get(), to_mw(text).c_str(), coord, XMLoadFloat4(&color), 0, {}, size); 39 | break; 40 | } 41 | sprite_batch_->End(); 42 | } 43 | -------------------------------------------------------------------------------- /Engine/src/UI/WriteMgr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "stdafx.h" 3 | #include "DllMacro.h" 4 | #include "DX11App.h" 5 | 6 | #include 7 | 8 | 9 | 10 | namespace reality 11 | { 12 | enum E_Font 13 | { 14 | BASIC = 0, 15 | ROTUNDA = 1, 16 | EUROCINE = 2, 17 | ALTONE = 3, 18 | RENOGARE = 4, 19 | ROBOTO = 5, 20 | }; 21 | 22 | class DLL_API WriteMgr 23 | { 24 | SINGLETON(WriteMgr); 25 | #define WRITER WriteMgr::GetInst() 26 | 27 | private: 28 | unique_ptr sprite_batch_; 29 | unique_ptr sprite_font_basic_; 30 | unique_ptr sprite_font_rotunda_; 31 | unique_ptr sprite_font_eurocine_; 32 | unique_ptr sprite_font_altone_; 33 | unique_ptr sprite_font_renogare_; 34 | unique_ptr sprite_font_roboto_; 35 | public: 36 | void Init(); 37 | 38 | void Draw(string text, E_Font font, XMFLOAT2 coord = { 0.0f, 0.0f }, float size = 1.0f, XMFLOAT4 color = { 1.0f, 1.0f, 1.0f, 1.0f }); 39 | }; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /Engine/src/World/DistanceFog.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "DistanceFog.h" 3 | #include "DX11App.h" 4 | 5 | bool reality::DistanceFog::CreateDistacneFog() 6 | { 7 | HRESULT hr; 8 | 9 | D3D11_BUFFER_DESC desc; 10 | D3D11_SUBRESOURCE_DATA subresource; 11 | ZeroMemory(&desc, sizeof(desc)); 12 | ZeroMemory(&subresource, sizeof(subresource)); 13 | 14 | desc.ByteWidth = sizeof(CbFog::Data); 15 | desc.Usage = D3D11_USAGE_DEFAULT; 16 | desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 17 | subresource.pSysMem = &cb_fog_.data; 18 | 19 | hr = DX11APP->GetDevice()->CreateBuffer(&desc, &subresource, cb_fog_.buffer.GetAddressOf()); 20 | if (FAILED(hr)) 21 | return false; 22 | 23 | DX11APP->GetDeviceContext()->UpdateSubresource(cb_fog_.buffer.Get(), 0, 0, &cb_fog_.data, 0, 0); 24 | DX11APP->GetDeviceContext()->PSSetConstantBuffers(4, 1, cb_fog_.buffer.GetAddressOf()); 25 | 26 | return true; 27 | } 28 | 29 | void reality::DistanceFog::SetMaxMinDistance(float max, float min) 30 | { 31 | max_distance_ = max; 32 | min_distance_ = min; 33 | } 34 | 35 | void reality::DistanceFog::UpdateFogStart(XMVECTOR fog_start) 36 | { 37 | cb_fog_.data.fog_start = XMFLOAT3(fog_start.m128_f32); 38 | } 39 | 40 | void reality::DistanceFog::UpdateFogColor(XMFLOAT4 color) 41 | { 42 | cb_fog_.data.fog_color = color; 43 | } 44 | 45 | void reality::DistanceFog::Update(float lerp_value) 46 | { 47 | cb_fog_.data.distance = min_distance_ + (max_distance_ - min_distance_) * lerp_value; 48 | } 49 | 50 | void reality::DistanceFog::Render() 51 | { 52 | DX11APP->GetDeviceContext()->UpdateSubresource(cb_fog_.buffer.Get(), 0, 0, &cb_fog_.data, 0, 0); 53 | DX11APP->GetDeviceContext()->PSSetConstantBuffers(4, 1, cb_fog_.buffer.GetAddressOf()); 54 | } 55 | -------------------------------------------------------------------------------- /Engine/src/World/DistanceFog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ConstantBuffer.h" 3 | 4 | namespace reality 5 | { 6 | class DLL_API DistanceFog 7 | { 8 | public: 9 | bool CreateDistacneFog(); 10 | void SetMaxMinDistance(float max, float min); 11 | 12 | void UpdateFogStart(XMVECTOR fog_start); 13 | void UpdateFogColor(XMFLOAT4 color); 14 | 15 | void Update(float lerp_value); 16 | void Render(); 17 | 18 | private: 19 | CbFog cb_fog_; 20 | float max_distance_; 21 | float min_distance_; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /Engine/src/World/Environment.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Environment.h" 3 | #include "TimeMgr.h" 4 | 5 | bool reality::Environment::CreateEnvironment() 6 | { 7 | if (sky_sphere_.CreateSphere() == false) 8 | return false; 9 | 10 | if (distance_fog_.CreateDistacneFog() == false) 11 | return false; 12 | 13 | return true; 14 | } 15 | 16 | void reality::Environment::SetWorldTime(float noon_time, float night_time) 17 | { 18 | time_limits.x = noon_time / 2; 19 | time_limits.y = -night_time / 2; 20 | 21 | current_time_ = 0.0f; 22 | time_routin_ = TimeRoutin::NIGHT_TO_NOON; 23 | current_day_ = Day::eNoon; 24 | } 25 | 26 | void reality::Environment::SetSkyColorByTime(XMFLOAT4 start_color, XMFLOAT4 end_color) 27 | { 28 | sky_sphere_.SetNoonColor(start_color); 29 | sky_sphere_.SetNightColor(end_color); 30 | } 31 | 32 | void reality::Environment::SetFogDistanceByTime(float start_distance, float end_distance) 33 | { 34 | distance_fog_.SetMaxMinDistance(start_distance, end_distance); 35 | } 36 | 37 | void reality::Environment::SetLightProperty(XMFLOAT4 _noon_light_color, XMFLOAT4 _night_light_color, float min_spec, float max_spec) 38 | { 39 | this->noon_light_color_ = _noon_light_color; 40 | this->night_light_color_ = _night_light_color; 41 | this->min_specular_ = min_spec; 42 | this->max_specular_ = max_spec; 43 | } 44 | 45 | void reality::Environment::Update(XMVECTOR camera_pos, LightingSystem* sys_lighting) 46 | { 47 | switch (time_routin_) 48 | { 49 | case TimeRoutin::NOON_TO_NIGHT: 50 | current_time_ -= TM_DELTATIME; 51 | break; 52 | 53 | case TimeRoutin::NIGHT_TO_NOON: 54 | current_time_ += TM_DELTATIME; 55 | break; 56 | } 57 | 58 | if (current_time_ >= time_limits.x) 59 | time_routin_ = TimeRoutin::NOON_TO_NIGHT; 60 | 61 | 62 | else if (current_time_ <= time_limits.y) 63 | time_routin_ = TimeRoutin::NIGHT_TO_NOON; 64 | 65 | if (current_time_ > 0) 66 | current_day_ = Day::eNoon; 67 | 68 | else 69 | current_day_ = Day::eNight; 70 | 71 | float lerp_value = max(0, current_time_ / time_limits.x); 72 | 73 | sky_sphere_.Update(lerp_value); 74 | distance_fog_.Update(lerp_value); 75 | 76 | 77 | sys_lighting->UpdateGlobalLight(min_specular_ + (max_specular_ - min_specular_) * lerp_value, _XMFLOAT4(XMVectorLerp(_XMVECTOR4(night_light_color_), _XMVECTOR4(noon_light_color_), lerp_value))); 78 | distance_fog_.UpdateFogStart(camera_pos); 79 | distance_fog_.UpdateFogColor(sky_sphere_.GetSkyColor()); 80 | 81 | } 82 | 83 | void reality::Environment::Render() 84 | { 85 | DX11APP->GetDeviceContext()->OMSetBlendState(DX11APP->GetCommonStates()->Opaque(), 0, -1); 86 | sky_sphere_.Render(); 87 | distance_fog_.Render(); 88 | } 89 | 90 | reality::DistanceFog* reality::Environment::GetDistanceFog() 91 | { 92 | return &distance_fog_; 93 | } 94 | 95 | reality::SkySphere* reality::Environment::GetSkySphere() 96 | { 97 | return &sky_sphere_; 98 | } 99 | 100 | float reality::Environment::GetCountingTime() 101 | { 102 | return current_time_; 103 | } 104 | 105 | XMFLOAT2 reality::Environment::GetTimeLimits() 106 | { 107 | return time_limits; 108 | } 109 | 110 | bool reality::Environment::IsDayChanged() 111 | { 112 | static Day last_day = current_day_; 113 | if (current_day_ != last_day) 114 | { 115 | last_day = current_day_; 116 | return true; 117 | } 118 | 119 | return false; 120 | } 121 | 122 | reality::Day reality::Environment::GetCurrentDay() 123 | { 124 | return current_day_; 125 | } 126 | -------------------------------------------------------------------------------- /Engine/src/World/Environment.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "CameraSystem.h" 3 | #include "LightingSystem.h" 4 | #include "SkySphere.h" 5 | #include "DistanceFog.h" 6 | 7 | class CameraSystem; 8 | 9 | namespace reality 10 | { 11 | enum class TimeRoutin 12 | { 13 | NOON_TO_NIGHT, 14 | NIGHT_TO_NOON 15 | }; 16 | 17 | enum class Day 18 | { 19 | eNoon, 20 | eNight, 21 | NONE, 22 | }; 23 | 24 | class DLL_API Environment 25 | { 26 | public: 27 | bool CreateEnvironment(); 28 | void SetWorldTime(float noon_time, float night_time); 29 | void SetSkyColorByTime(XMFLOAT4 start_color, XMFLOAT4 end_color); 30 | void SetFogDistanceByTime(float start_distance, float end_distance); 31 | void SetLightProperty(XMFLOAT4 _noon_light_color, XMFLOAT4 _night_light_color, float min_spec, float max_spec); 32 | 33 | void Update(XMVECTOR camera_pos, LightingSystem* sys_lighting); 34 | void Render(); 35 | 36 | public: 37 | DistanceFog* GetDistanceFog(); 38 | SkySphere* GetSkySphere(); 39 | float GetCountingTime(); 40 | XMFLOAT2 GetTimeLimits(); 41 | bool IsDayChanged(); 42 | Day GetCurrentDay(); 43 | 44 | private: 45 | TimeRoutin time_routin_; 46 | Day current_day_; 47 | 48 | float current_time_; 49 | XMFLOAT2 time_limits; 50 | 51 | // Light Property 52 | XMFLOAT4 noon_light_color_; 53 | XMFLOAT4 night_light_color_; 54 | float min_specular_; 55 | float max_specular_; 56 | 57 | DistanceFog distance_fog_; 58 | SkySphere sky_sphere_; 59 | }; 60 | } 61 | -------------------------------------------------------------------------------- /Engine/src/World/GuideLine.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "GuideLine.h" 3 | #include "FileTransfer.h" 4 | 5 | void reality::GuideLine::Init(GuideType guide_type) 6 | { 7 | guide_type_ = guide_type; 8 | } 9 | 10 | void reality::GuideLine::AddNode(XMVECTOR node_pos) 11 | { 12 | UINT index = line_nodes.size(); 13 | line_nodes.insert(make_pair(index, node_pos)); 14 | } 15 | 16 | void reality::GuideLine::DeleteNode(UINT index) 17 | { 18 | line_nodes.erase(line_nodes.find(index)); 19 | } 20 | 21 | void reality::GuideLine::UpdateLines() 22 | { 23 | if (line_nodes.size() < 2) 24 | return; 25 | 26 | line_vectors.clear(); 27 | for (UINT i = 1; i < line_nodes.size(); ++i) 28 | { 29 | XMVECTOR vector = line_nodes.at(i) - line_nodes.at(i - 1); 30 | line_vectors.push_back(vector); 31 | } 32 | } 33 | 34 | void reality::GuideLine::Import(string mapdat_file, GuideType type) 35 | { 36 | FileTransfer in_mapdata(mapdata_dir + mapdat_file, READ); 37 | 38 | vector new_guide_lines_; 39 | 40 | UINT num_guide_lines = 0; 41 | in_mapdata.ReadBinary(num_guide_lines); 42 | for (UINT i = 0; i < num_guide_lines; ++i) 43 | { 44 | GuideLine new_guide_line; 45 | new_guide_line.guide_type_ = type; 46 | 47 | UINT num_nodes = 0; 48 | in_mapdata.ReadBinary(num_nodes); 49 | 50 | for (UINT j = 0; j < num_nodes; ++j) 51 | { 52 | UINT node_number; 53 | XMVECTOR node_pos; 54 | in_mapdata.ReadBinary(node_number); 55 | in_mapdata.ReadBinary(node_pos); 56 | 57 | new_guide_line.AddNode(node_pos); 58 | } 59 | 60 | new_guide_lines_.push_back(new_guide_line); 61 | } 62 | 63 | if (new_guide_lines_.empty() == false) 64 | *this = new_guide_lines_.front(); 65 | } 66 | -------------------------------------------------------------------------------- /Engine/src/World/GuideLine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace reality 4 | { 5 | enum class GuideType 6 | { 7 | eBlocking, 8 | eNpcTrack, 9 | eSpawnPoint, 10 | }; 11 | 12 | class DLL_API GuideLine 13 | { 14 | public: 15 | GuideType guide_type_; 16 | void Init(GuideType guide_type); 17 | void AddNode(XMVECTOR node_pos); 18 | void DeleteNode(UINT index); 19 | void UpdateLines(); 20 | void Import(string mapdat_file, GuideType type); 21 | 22 | string mapdata_dir = "../../Contents/BinaryPackage/"; 23 | map line_nodes; 24 | vector line_vectors; 25 | }; 26 | } 27 | 28 | 29 | -------------------------------------------------------------------------------- /Engine/src/World/InstancedObject.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "InstancedObject.h" 3 | #include "ResourceMgr.h" 4 | 5 | using namespace reality; 6 | 7 | InstancedObject::InstancedObject() 8 | { 9 | } 10 | 11 | InstancedObject::~InstancedObject() 12 | { 13 | } 14 | 15 | bool InstancedObject::Init(string stmesh_id, string vs_id, string mat_id) 16 | { 17 | static_mesh = shared_ptr(RESOURCE->UseResource(stmesh_id)); 18 | vertex_shader = shared_ptr(RESOURCE->UseResource(vs_id)); 19 | material = shared_ptr(RESOURCE->UseResource(mat_id)); 20 | 21 | if (static_mesh.get() == nullptr) 22 | return false; 23 | 24 | if (vertex_shader.get() == nullptr) 25 | return false; 26 | 27 | if (material.get() == nullptr) 28 | return false; 29 | 30 | object_name = split(stmesh_id, '.')[0]; 31 | 32 | return true; 33 | } 34 | 35 | void InstancedObject::Frame() 36 | { 37 | if (instance_pool.empty()) 38 | return; 39 | 40 | UpdateInstance(); 41 | 42 | DX11APP->GetDeviceContext()->VSSetShader(nullptr, 0, 0); 43 | DX11APP->GetDeviceContext()->GSSetShader(nullptr, 0, 0); 44 | DX11APP->GetDeviceContext()->PSSetShader(nullptr, 0, 0); 45 | DX11APP->GetDeviceContext()->IASetInputLayout(vertex_shader.get()->InputLayout()); 46 | DX11APP->GetDeviceContext()->VSSetShader(vertex_shader.get()->Get(), 0, 0); 47 | 48 | if (inst_srv.Get()) 49 | DX11APP->GetDeviceContext()->VSSetShaderResources(0, 1, inst_srv.GetAddressOf()); 50 | } 51 | 52 | void InstancedObject::Render() 53 | { 54 | if (instance_pool.empty()) 55 | return; 56 | 57 | unsigned int stride = sizeof(Vertex); 58 | unsigned int offset = 0; 59 | 60 | for (auto& mesh : static_mesh->meshes) 61 | { 62 | material->Set(); 63 | 64 | DX11APP->GetDeviceContext()->IASetVertexBuffers(0, 1, mesh.vertex_buffer.GetAddressOf(), &stride, &offset); 65 | DX11APP->GetDeviceContext()->IASetIndexBuffer(mesh.index_buffer.Get(), DXGI_FORMAT_R32_UINT, 0); 66 | DX11APP->GetDeviceContext()->DrawIndexedInstanced(mesh.indices.size(), instance_pool.size(), 0, 0, 0); 67 | } 68 | } 69 | 70 | void InstancedObject::Release() 71 | { 72 | for (auto& inst : instance_pool) 73 | { 74 | delete inst.second; 75 | inst.second = nullptr; 76 | } 77 | } 78 | 79 | bool reality::InstancedObject::CreateInstanceBuffer() 80 | { 81 | auto data_array = GetCDataArray(); 82 | if (data_array.size() <= 0) 83 | return false; 84 | 85 | inst_buffer.ReleaseAndGetAddressOf(); 86 | inst_srv.ReleaseAndGetAddressOf(); 87 | 88 | HRESULT hr; 89 | 90 | D3D11_BUFFER_DESC desc; 91 | desc.ByteWidth = sizeof(InstanceData::CData) * data_array.size(); 92 | desc.Usage = D3D11_USAGE_DYNAMIC; 93 | desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; 94 | desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 95 | desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; 96 | desc.StructureByteStride = sizeof(InstanceData::CData); 97 | 98 | D3D11_SUBRESOURCE_DATA subdata; 99 | subdata.pSysMem = data_array.data(); 100 | subdata.SysMemPitch = 0; 101 | subdata.SysMemSlicePitch = 0; 102 | 103 | hr = DX11APP->GetDevice()->CreateBuffer(&desc, &subdata, inst_buffer.GetAddressOf()); 104 | if (FAILED(hr)) 105 | return false; 106 | 107 | D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc; 108 | srv_desc.Format = DXGI_FORMAT_UNKNOWN; 109 | srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; 110 | srv_desc.Buffer.FirstElement = 0; 111 | srv_desc.Buffer.NumElements = data_array.size(); 112 | 113 | hr = DX11APP->GetDevice()->CreateShaderResourceView(inst_buffer.Get(), &srv_desc, inst_srv.GetAddressOf()); 114 | if (FAILED(hr)) 115 | return false; 116 | 117 | return true; 118 | } 119 | 120 | vector reality::InstancedObject::GetCDataArray() 121 | { 122 | vector data_array; 123 | for (auto data : instance_pool) 124 | { 125 | data_array.push_back(data.second->cdata); 126 | } 127 | 128 | return data_array; 129 | } 130 | 131 | InstanceData* reality::InstancedObject::SelectInstance(UINT index) 132 | { 133 | const auto& found = instance_pool.find(index); 134 | if (found == instance_pool.end()) 135 | return nullptr; 136 | 137 | selected_instance = found->second; 138 | return selected_instance; 139 | } 140 | 141 | void reality::InstancedObject::SetInstanceScale(UINT index, XMFLOAT3 S) 142 | { 143 | auto found = instance_pool.find(index); 144 | if (found != instance_pool.end()) 145 | { 146 | found->second->S = S; 147 | } 148 | } 149 | 150 | void reality::InstancedObject::SetInstanceRotation(UINT index, XMFLOAT3 R) 151 | { 152 | auto found = instance_pool.find(index); 153 | if (found != instance_pool.end()) 154 | { 155 | found->second->R = R; 156 | } 157 | } 158 | 159 | void reality::InstancedObject::SetInstanceTranslation(UINT index, XMFLOAT3 T) 160 | { 161 | auto found = instance_pool.find(index); 162 | if (found != instance_pool.end()) 163 | { 164 | found->second->T = T; 165 | } 166 | } 167 | 168 | InstanceData* InstancedObject::AddNewInstance(string name) 169 | { 170 | UINT index = instance_pool.size(); 171 | InstanceData* data = new InstanceData(name, index); 172 | 173 | instance_pool.insert(make_pair(index, data)); 174 | 175 | auto current = instance_pool.find(index)->second; 176 | selected_instance = current; 177 | 178 | CreateInstanceBuffer(); 179 | 180 | return data; 181 | } 182 | 183 | bool reality::InstancedObject::UpdateInstance() 184 | { 185 | for (auto instance : instance_pool) 186 | { 187 | XMMATRIX transform = XMMatrixIdentity(); 188 | transform *= TransformS(instance.second->S); 189 | transform *= TransformR(instance.second->R); 190 | transform *= TransformT(instance.second->T); 191 | 192 | instance.second->cdata.world_matrix = XMMatrixTranspose(transform); 193 | } 194 | 195 | auto data_array = GetCDataArray(); 196 | 197 | HRESULT hr; 198 | 199 | D3D11_MAPPED_SUBRESOURCE mapped_resource; 200 | hr = DX11APP->GetDeviceContext()->Map(inst_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped_resource); 201 | if (FAILED(hr)) 202 | return false; 203 | 204 | size_t buffer_size = data_array.size() * sizeof(InstanceData::CData); 205 | memcpy_s(mapped_resource.pData, buffer_size, data_array.data(), buffer_size); 206 | 207 | DX11APP->GetDeviceContext()->Unmap(inst_buffer.Get(), 0); 208 | 209 | return true; 210 | } -------------------------------------------------------------------------------- /Engine/src/World/InstancedObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Material.h" 3 | #include "Mesh.h" 4 | 5 | namespace reality 6 | { 7 | struct InstanceData 8 | { 9 | InstanceData(string obj_name, UINT index) 10 | { 11 | instance_id = obj_name + "_" + to_string(index); 12 | this->index = index; 13 | 14 | S = { 1 ,1, 1 }; 15 | R = { 0 ,0, 0 }; 16 | T = { 0 ,0, 0 }; 17 | 18 | cdata.world_matrix = XMMatrixIdentity(); 19 | } 20 | 21 | UINT index; 22 | string instance_id; 23 | XMFLOAT3 S; 24 | XMFLOAT3 R; 25 | XMFLOAT3 T; 26 | 27 | struct CData 28 | { 29 | XMMATRIX world_matrix; 30 | } cdata; 31 | }; 32 | 33 | class DLL_API InstancedObject 34 | { 35 | public: 36 | InstancedObject(); 37 | ~InstancedObject(); 38 | 39 | public: 40 | bool Init(string mesh_id, string vs_id, string mat_id); 41 | void Frame(); 42 | void Render(); 43 | void Release(); 44 | 45 | InstanceData* selected_instance = nullptr; 46 | map instance_pool; 47 | string object_name; 48 | 49 | public: 50 | InstanceData* AddNewInstance(string name); 51 | vector GetCDataArray(); 52 | InstanceData* SelectInstance(UINT index); 53 | void SetInstanceScale(UINT index, XMFLOAT3 S); 54 | void SetInstanceRotation(UINT index, XMFLOAT3 R); 55 | void SetInstanceTranslation(UINT index, XMFLOAT3 T); 56 | 57 | private: 58 | bool UpdateInstance(); 59 | bool CreateInstanceBuffer(); 60 | 61 | 62 | private: 63 | shared_ptr static_mesh; 64 | shared_ptr vertex_shader; 65 | shared_ptr material; 66 | 67 | ComPtr inst_buffer; 68 | ComPtr inst_srv; 69 | 70 | public: 71 | StaticMesh* GetStaticMesh() { return static_mesh.get(); } 72 | VertexShader* GetVertexShader() { return vertex_shader.get(); } 73 | 74 | ID3D11Buffer* GetInstanceBuffer() { return inst_buffer.Get(); } 75 | ID3D11ShaderResourceView* GetInstanceSRV() { return inst_srv.Get(); } 76 | 77 | }; 78 | } 79 | 80 | -------------------------------------------------------------------------------- /Engine/src/World/Level.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Components.h" 3 | #include "InstancedObject.h" 4 | 5 | #define LerpByTan(start, end, tan) (start - (start * tan) + (end * tan)) 6 | 7 | namespace reality 8 | { 9 | class DLL_API Level 10 | { 11 | public: 12 | Level(); 13 | ~Level(); 14 | 15 | public: 16 | // Import 17 | bool ImportFromFile(string filepath); 18 | 19 | public: 20 | // Create 21 | bool CreateLevel(UINT _max_lod, UINT _cell_scale, UINT _uv_scale, XMINT2 _row_col_blocks); 22 | void SetCamera(C_Camera* _camera); 23 | void Update(); 24 | void Render(bool culling); 25 | 26 | public: 27 | // Getter 28 | float GetHeightAt(float x, float y); 29 | XMVECTOR GetNormalAt(float x, float y); 30 | XMINT2 GetWorldSize(); 31 | XMINT2 GetBlocks(); 32 | UINT MaxLod(); 33 | vector GetLevelVertex() { return level_mesh_.vertices; } 34 | vector GetLevelIndex() { return level_mesh_.indices; } 35 | 36 | public: 37 | string vs_id_; 38 | string ps_id_; 39 | vector texture_id; 40 | C_Camera* camera = nullptr; 41 | 42 | public: 43 | void SetTextures(); 44 | 45 | public: 46 | ID3D11ShaderResourceView* texture_layers[5] = {0,}; 47 | AlphaTexLayer alpha_layer; 48 | vector inst_objects; 49 | 50 | protected: 51 | void GenVertexNormal(); 52 | void GetHeightList(); 53 | XMFLOAT2 GetMinMaxHeight(); 54 | XMFLOAT3 GetNormal(UINT i0, UINT i1, UINT i2); 55 | bool CreateBuffers(); 56 | 57 | void RenderObjects(); 58 | 59 | protected: 60 | SingleMesh level_mesh_; 61 | vector height_list_; 62 | 63 | UINT num_row_vertex_; 64 | UINT num_col_vertex_; 65 | float cell_distance_; 66 | float uv_scale_; 67 | 68 | UINT max_lod_; 69 | UINT cell_scale_; 70 | XMINT2 row_col_blocks_; 71 | }; 72 | } -------------------------------------------------------------------------------- /Engine/src/World/SkySphere.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "SkySphere.h" 3 | #include "ResourceMgr.h" 4 | #include "TimeMgr.h" 5 | 6 | reality::SkySphere::SkySphere() 7 | { 8 | } 9 | 10 | reality::SkySphere::~SkySphere() 11 | { 12 | } 13 | 14 | bool reality::SkySphere::CreateSphere() 15 | { 16 | sphere_mesh = shared_ptr(RESOURCE->UseResource("SkySphere.stmesh")); 17 | vs = shared_ptr(RESOURCE->UseResource("SkySphereVS.cso")); 18 | 19 | if (sphere_mesh.get() == nullptr) 20 | return false; 21 | 22 | if (vs.get() == nullptr) 23 | return false; 24 | 25 | HRESULT hr; 26 | 27 | D3D11_BUFFER_DESC desc; 28 | D3D11_SUBRESOURCE_DATA subresource; 29 | 30 | ZeroMemory(&desc, sizeof(desc)); 31 | ZeroMemory(&subresource, sizeof(subresource)); 32 | 33 | desc.ByteWidth = sizeof(CbSkySphere::Data); 34 | desc.Usage = D3D11_USAGE_DEFAULT; 35 | desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 36 | subresource.pSysMem = &cb_sky.data; 37 | 38 | hr = DX11APP->GetDevice()->CreateBuffer(&desc, &subresource, cb_sky.buffer.GetAddressOf()); 39 | if (FAILED(hr)) 40 | return false; 41 | 42 | return true; 43 | } 44 | 45 | void reality::SkySphere::Update(float lerp_value) 46 | { 47 | DX11APP->GetDeviceContext()->VSSetShader(nullptr, 0, 0); 48 | DX11APP->GetDeviceContext()->GSSetShader(nullptr, 0, 0); 49 | DX11APP->GetDeviceContext()->PSSetShader(nullptr, 0, 0); 50 | 51 | DX11APP->GetDeviceContext()->IASetInputLayout(vs.get()->InputLayout()); 52 | DX11APP->GetDeviceContext()->VSSetShader(vs.get()->Get(), 0, 0); 53 | 54 | cb_sky.data.sky_color = LerpColor(skycolor_night, skycolor_noon, lerp_value); 55 | 56 | DX11APP->GetDeviceContext()->UpdateSubresource(cb_sky.buffer.Get(), 0, 0, &cb_sky.data, 0, 0); 57 | DX11APP->GetDeviceContext()->PSSetConstantBuffers(1, 1, cb_sky.buffer.GetAddressOf()); 58 | } 59 | 60 | void reality::SkySphere::Render() 61 | { 62 | unsigned int stride = sizeof(Vertex); 63 | unsigned int offset = 0; 64 | 65 | for (auto& mesh : sphere_mesh.get()->meshes) 66 | { 67 | reality::Material* material = RESOURCE->UseResource("BackgroundSky.mat"); 68 | if (material) 69 | material->Set(); 70 | 71 | DX11APP->GetDeviceContext()->IASetVertexBuffers(0, 1, mesh.vertex_buffer.GetAddressOf(), &stride, &offset); 72 | DX11APP->GetDeviceContext()->IASetIndexBuffer(mesh.index_buffer.Get(), DXGI_FORMAT_R32_UINT, 0); 73 | DX11APP->GetDeviceContext()->DrawIndexed(mesh.indices.size(), 0, 0); 74 | } 75 | } 76 | 77 | void reality::SkySphere::SetNoonColor(XMFLOAT4 _color) 78 | { 79 | skycolor_noon = _color; 80 | } 81 | 82 | void reality::SkySphere::SetNightColor(XMFLOAT4 _color) 83 | { 84 | skycolor_night = _color; 85 | } 86 | 87 | XMFLOAT4 reality::SkySphere::GetSkyColor() 88 | { 89 | return cb_sky.data.sky_color; 90 | } 91 | -------------------------------------------------------------------------------- /Engine/src/World/SkySphere.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Components.h" 3 | #include "Mesh.h" 4 | #include "ConstantBuffer.h" 5 | 6 | namespace reality 7 | { 8 | class DLL_API SkySphere 9 | { 10 | public: 11 | SkySphere(); 12 | ~SkySphere(); 13 | 14 | public: 15 | bool CreateSphere(); 16 | void Update(float lerp_value); 17 | void Render(); 18 | 19 | void SetNoonColor(XMFLOAT4 _color); 20 | void SetNightColor(XMFLOAT4 _color); 21 | XMFLOAT4 GetSkyColor(); 22 | 23 | private: 24 | XMFLOAT4 skycolor_night; 25 | XMFLOAT4 skycolor_noon; 26 | CbSkySphere cb_sky; 27 | 28 | private: 29 | shared_ptr sphere_mesh; 30 | shared_ptr vs; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /Engine/src/World/StaticMeshLevel.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "DXStates.h" 3 | #include "StaticMeshLevel.h" 4 | #include "Components.h" 5 | #include "FileTransfer.h" 6 | #include "InputEventMgr.h" 7 | 8 | using namespace reality; 9 | 10 | reality::StaticMeshLevel::StaticMeshLevel() 11 | { 12 | } 13 | 14 | reality::StaticMeshLevel::~StaticMeshLevel() 15 | { 16 | } 17 | 18 | bool reality::StaticMeshLevel::Create(string mesh_id, string vs_id) 19 | { 20 | level_mesh = shared_ptr(RESOURCE->UseResource(mesh_id)); 21 | if (level_mesh.get() == nullptr) 22 | return false; 23 | 24 | vertex_shader = shared_ptr(RESOURCE->UseResource(vs_id)); 25 | if (vertex_shader.get() == nullptr) 26 | return false; 27 | 28 | // Create Collision 29 | 30 | for (const auto& mesh : level_mesh.get()->meshes) 31 | { 32 | if (mesh.mesh_name == "Collision") 33 | ConvertToTrianlgeShapes(level_triangles, mesh); 34 | } 35 | 36 | clipping_rs = DXStates::rs_solid_cull_front(); 37 | 38 | return true; 39 | } 40 | 41 | void reality::StaticMeshLevel::Update() 42 | { 43 | DX11APP->GetDeviceContext()->VSSetShader(nullptr, nullptr, 0); 44 | DX11APP->GetDeviceContext()->GSSetShader(nullptr, nullptr, 0); 45 | DX11APP->GetDeviceContext()->PSSetShader(nullptr, nullptr, 0); 46 | } 47 | 48 | void reality::StaticMeshLevel::Render() 49 | { 50 | DX11APP->GetDeviceContext()->OMSetBlendState(DX11APP->GetCommonStates()->Opaque(), 0, -1); 51 | DX11APP->GetDeviceContext()->RSSetState(clipping_rs); 52 | 53 | DX11APP->GetDeviceContext()->IASetInputLayout(vertex_shader.get()->InputLayout()); 54 | DX11APP->GetDeviceContext()->VSSetShader(vertex_shader.get()->Get(), nullptr, 0); 55 | 56 | for (auto& mesh : level_mesh.get()->meshes) 57 | { 58 | if (mesh.mesh_name == "Collision") 59 | { 60 | continue; 61 | } 62 | 63 | Material* material = RESOURCE->UseResource(mesh.mesh_name + ".mat"); 64 | if (material) 65 | material->Set(); 66 | 67 | UINT stride = sizeof(Vertex); 68 | UINT offset = 0; 69 | 70 | DX11APP->GetDeviceContext()->IASetVertexBuffers(0, 1, mesh.vertex_buffer.GetAddressOf(), &stride, &offset); 71 | DX11APP->GetDeviceContext()->Draw(mesh.vertices.size(), 0); 72 | } 73 | 74 | DX11APP->GetDeviceContext()->RSSetState(DX11APP->GetCommonStates()->CullNone()); 75 | } 76 | 77 | void reality::StaticMeshLevel::Destroy() 78 | { 79 | } 80 | 81 | StaticMesh* reality::StaticMeshLevel::GetLevelMesh() 82 | { 83 | return level_mesh.get(); 84 | } 85 | 86 | VertexShader* reality::StaticMeshLevel::GetVertexShader() 87 | { 88 | return vertex_shader.get(); 89 | } 90 | 91 | void reality::StaticMeshLevel::RenderCollisionMesh() 92 | { 93 | DX11APP->GetDeviceContext()->VSSetShader(nullptr, nullptr, 0); 94 | DX11APP->GetDeviceContext()->GSSetShader(nullptr, nullptr, 0); 95 | DX11APP->GetDeviceContext()->PSSetShader(nullptr, nullptr, 0); 96 | 97 | DX11APP->GetDeviceContext()->IASetInputLayout(vertex_shader.get()->InputLayout()); 98 | DX11APP->GetDeviceContext()->VSSetShader(vertex_shader.get()->Get(), nullptr, 0); 99 | 100 | for (auto& mesh : level_mesh.get()->meshes) 101 | { 102 | if (mesh.mesh_name == "Collision") 103 | { 104 | Material* material = RESOURCE->UseResource(mesh.mesh_name + ".mat"); 105 | if (material) 106 | material->Set(); 107 | 108 | UINT stride = sizeof(Vertex); 109 | UINT offset = 0; 110 | 111 | DX11APP->GetDeviceContext()->IASetVertexBuffers(0, 1, mesh.vertex_buffer.GetAddressOf(), &stride, &offset); 112 | DX11APP->GetDeviceContext()->Draw(mesh.vertices.size(), 0); 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /Engine/src/World/StaticMeshLevel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Components.h" 3 | #include "Mesh.h" 4 | #include "ConstantBuffer.h" 5 | #include "GuideLine.h" 6 | 7 | namespace reality 8 | { 9 | class DLL_API StaticMeshLevel 10 | { 11 | public: 12 | StaticMeshLevel(); 13 | ~StaticMeshLevel(); 14 | 15 | public: 16 | bool Create(string mesh_id, string vs_id); 17 | void Update(); 18 | void Render(); 19 | void Destroy(); 20 | 21 | void RenderCollisionMesh(); 22 | StaticMesh* GetLevelMesh(); 23 | VertexShader* GetVertexShader(); 24 | public: 25 | CbTransform level_transform; 26 | vector level_triangles; 27 | 28 | private: 29 | shared_ptr level_mesh; 30 | shared_ptr vertex_shader; 31 | ID3D11RasterizerState* clipping_rs = nullptr; 32 | }; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Engine/src/World/StaticShadows.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ScreenGrab.h" 3 | #include "RenderTargetMgr.h" 4 | #include "StaticMeshLevel.h" 5 | namespace reality 6 | { 7 | bool DLL_API CreateDepthBiasRS(int DepthBias, float SlopeScaledDepthBias, float DepthBiasClamp, ID3D11RasterizerState** rs); 8 | 9 | struct CbProjectionShadow 10 | { 11 | CbProjectionShadow() 12 | { 13 | data.shadow_view_proj = XMMatrixIdentity(); 14 | } 15 | struct Data 16 | { 17 | XMMATRIX shadow_view_proj; 18 | } data; 19 | 20 | ComPtr buffer; 21 | }; 22 | 23 | struct CbCubeMapShadow 24 | { 25 | CbCubeMapShadow() 26 | { 27 | for (int i = 0; i < 6; ++i) 28 | data.shadow_view_proj[i] = XMMatrixIdentity(); 29 | } 30 | struct Data 31 | { 32 | XMMATRIX shadow_view_proj[6]; 33 | } data; 34 | 35 | ComPtr buffer; 36 | }; 37 | 38 | class DLL_API ProjectionShadow 39 | { 40 | public: 41 | bool Init(XMFLOAT2 near_far, XMFLOAT2 dmap_size, string dmap_vs); 42 | bool CreateDepthMap(StaticMeshLevel* level_to_render, XMVECTOR light_pos, XMVECTOR light_look); 43 | void SetDepthMapSRV(); 44 | ID3D11ShaderResourceView* GetDepthMapSRV(); 45 | 46 | private: 47 | XMFLOAT2 projection_near_far_; 48 | XMFLOAT2 depth_map_size_; 49 | 50 | RenderTarget* depth_map_rt_ = nullptr; 51 | VertexShader* depth_map_vs_ = nullptr; 52 | ID3D11RasterizerState* depth_bias_rs_ = nullptr; 53 | 54 | ID3D11SamplerState* sampler_clamp_ = nullptr; 55 | CbProjectionShadow cb_shadow_; 56 | }; 57 | 58 | class DLL_API CubemapShadow 59 | { 60 | public: 61 | bool Init(XMFLOAT2 near_far, XMFLOAT2 dmap_size, string dmap_vs); 62 | bool CreateDepthMap(StaticMeshLevel* level_to_render, XMVECTOR light_pos); 63 | void CreateTextureFile(); 64 | void SetDepthMapSRV(int slot); 65 | 66 | ID3D11ShaderResourceView* depth_srvs[6] = {0,}; 67 | ID3D11RasterizerState* depth_bias_rs_ = nullptr; 68 | private: 69 | XMFLOAT2 projection_near_far_; 70 | XMFLOAT2 depth_map_size_; 71 | 72 | ComPtr cubemap_rt_; 73 | RenderTarget* depth_map_rts_[6]; 74 | VertexShader* depth_map_vs_ = nullptr; 75 | 76 | ID3D11SamplerState* sampler_clamp_ = nullptr; 77 | CbCubeMapShadow cb_cubemap_shadow_; 78 | 79 | CbProjectionShadow cb_shadow_[6]; 80 | }; 81 | } -------------------------------------------------------------------------------- /ProjectGenerator.bat: -------------------------------------------------------------------------------- 1 | call vendor\premake\premake5.exe vs2019 2 | PAUSE -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 소스파일 분류 2 | ### 새로운 폴더 (Engine/src/) 3 | 1. Actor/ 4 | - Enity를 갖고 씬에 할당되는 오브젝트들을 분류하였습니다. 5 | 6 | 2. Components/ 7 | - Enity에 할당되는 컴포넌트들을 분류하였습니다. 8 | 3. Core/ 9 | - 엔진과 더불어 엔진 내부에서 주로 돌아가는 DX, 이벤트, Fmod, 인풋, 리소스매니저, 씬, 타임매니저들을 분류하였습니다. 10 | 4. DataTypes/ 11 | - 기존 DateTypes.h에 모여있던 구조체들을 5가지 헤더로 분류하였습니다. 12 | 5. Headers/ 13 | - DllMacro, entt.hpp, GolobalFunctions 등 stdafx와 함께 묶을 헤더들을 분류하였습니다. 14 | 6. Physics/ 15 | - 쿼드트리와 충돌체, 충돌로직 소스들을 분류하였습니다. 16 | 7. ResourceTypes/ 17 | - 머터리얼, 메쉬, 쉐이더, 텍스처들을 분류하였습니다. 18 | 8. Systems/ 19 | - ECS 기반 시스템 클래스들을 분류하였습니다. 20 | 9. Tools/ 21 | - 파일입출력, ImGui 등 에디터 기능 클래스들을 분류하였습니다. 22 | 10. UI/ 23 | - UI 관련 객체 클래스와 RenderTargetMgr 및 WriteMgr를 분류하였습니다. 24 | 11. World/ 25 | - 레벨, 스카이스피어 등의 클래스들을 분류하였습니다. 26 | -------------------------------------------------------------------------------- /premake5.lua: -------------------------------------------------------------------------------- 1 | workspace "Game-Engine" 2 | architecture "x86_64" 3 | toolset "v143" 4 | cppdialect "C++20" 5 | configurations 6 | { 7 | "Debug", 8 | "Release", 9 | "Dist" 10 | } 11 | 12 | outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}" 13 | 14 | project "Engine" 15 | location "Engine" 16 | kind "SharedLib" 17 | language "C++" 18 | 19 | targetdir("../output/bin/" .. outputdir .. "/%{prj.name}") 20 | objdir("../output/bin-int/" .. outputdir .. "/%{prj.name}") 21 | 22 | pchheader "stdafx.h" 23 | pchsource "Engine/src/Headers/stdafx.cpp" 24 | 25 | files 26 | { 27 | "%{prj.name}/src/**.h", 28 | "%{prj.name}/src/**.cpp", 29 | "%{prj.name}/src/**.hpp", 30 | "premake5.lua" 31 | } 32 | 33 | includedirs 34 | { 35 | "%{prj.name}/src/Actors", 36 | "%{prj.name}/src/Animation", 37 | "%{prj.name}/src/Components", 38 | "%{prj.name}/src/Core", 39 | "%{prj.name}/src/DataTypes", 40 | "%{prj.name}/src/Headers", 41 | "%{prj.name}/src/Physics", 42 | "%{prj.name}/src/ResourceTypes", 43 | "%{prj.name}/src/Systems", 44 | "%{prj.name}/src/Tools", 45 | "%{prj.name}/src/UI", 46 | "%{prj.name}/src/World", 47 | "%{prj.name}/src/Event", 48 | "%{prj.name}/src/Scene", 49 | "%{prj.name}/src/Sound", 50 | "%{prj.name}/src/Input", 51 | "%{prj.name}/src/Managers", 52 | "%{prj.name}/vendor/spdlog/include", 53 | "../SDK/DirectXTK/include", 54 | "../SDK/FBXSDK/include", 55 | "../SDK/FMOD/include", 56 | "../SDK/IMGUI/include", 57 | } 58 | 59 | libdirs 60 | { 61 | "../SDK/DirectXTK/lib", 62 | "../SDK/IMGUI/lib" 63 | } 64 | 65 | links 66 | { 67 | "d3d11", 68 | "d3dcompiler", 69 | "dxgi", 70 | "dinput8", 71 | "dxguid", 72 | "fmod_vc", 73 | "fmodL_vc", 74 | } 75 | 76 | filter "system:windows" 77 | staticruntime "off" 78 | systemversion "latest" 79 | 80 | filter "configurations:Debug" 81 | defines "_DEBUG" 82 | staticruntime "off" 83 | symbols "On" 84 | runtime "Debug" 85 | 86 | defines 87 | { 88 | "PLATFORM_WINDOWS", 89 | "BUILD_DLL", 90 | "_ITERATOR__DEBUGLEVEL=2" 91 | } 92 | 93 | libdirs 94 | { 95 | "../SDK/FBXSDK/lib/debug", 96 | "../SDK/FMOD/lib/debug", 97 | } 98 | 99 | links 100 | { 101 | "DirectXTK_D", 102 | "libfbxsdk-md", 103 | "libxml2-md", 104 | "zlib-md", 105 | "ImGui_Win32_Dx11_D", 106 | } 107 | 108 | filter "configurations:Release" 109 | defines "_RELEASE" 110 | staticruntime "off" 111 | optimize "On" 112 | runtime "Release" 113 | 114 | 115 | defines 116 | { 117 | "PLATFORM_WINDOWS", 118 | "BUILD_DLL", 119 | "_ITERATOR__DEBUGLEVEL=0" 120 | } 121 | 122 | 123 | libdirs 124 | { 125 | "../SDK/FBXSDK/lib/release", 126 | "../SDK/FMOD/lib/release", 127 | } 128 | 129 | links 130 | { 131 | "DirectXTK" 132 | } 133 | 134 | filter "configurations:Dist" 135 | defines "_DIST" 136 | staticruntime "off" 137 | optimize "On" 138 | runtime "Release" 139 | 140 | libdirs 141 | { 142 | "../SDK/FBXSDK/lib/release", 143 | "../SDK/FMOD/lib/release", 144 | } 145 | 146 | links 147 | { 148 | "DirectXTK" 149 | } -------------------------------------------------------------------------------- /vendor/premake/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2003-2022 Jason Perkins and individual contributors. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | 3. Neither the name of Premake nor the names of its contributors may be 15 | used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/premake/premake5.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reality-soft/Game-Engine/3e539944ccfbea2be4b24d2c1a1e26cb338e9ea5/vendor/premake/premake5.exe --------------------------------------------------------------------------------