Skip to content

Commit

Permalink
만Name 기반 ID
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnjiwoo committed Oct 1, 2024
1 parent 1af48ff commit df7e828
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 5 deletions.
1 change: 0 additions & 1 deletion MyD3DFramework/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Component
inline static uint32 sComponentIDCounter = 0;
uint32 m_cmpID = 0;

std::wstring m_name = {};
size_t m_index = UINT64_MAX; //설계상 Component에는 포함시키지 않는게 맞음, 이는 현재 설계상 충분히 분리할 수 있음

CM::TypeID m_typeID = {};
Expand Down
3 changes: 2 additions & 1 deletion MyD3DFramework/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class GameObject
inline static uint64 sObjectIDCounter = 0;
uint64 m_objectID = 0;

//컴포넌트를 저정하는 컨테이너

/* 컴포넌트 관련 */
constexpr inline static size_t sReserveCapacity = 16;
std::unordered_map<CM::TypeID, std::vector<std::unique_ptr<Component>>> m_compRepo;
std::vector<CBehavior*> m_updateCompRepo;
Expand Down
2 changes: 2 additions & 0 deletions MyD3DFramework/MyD3DFramework.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
<ClInclude Include="Material.h" />
<ClInclude Include="Mesh.h" />
<ClInclude Include="CMeshRenderer.h" />
<ClInclude Include="Name.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="Renderer.h" />
<ClInclude Include="RenderState.h" />
Expand Down Expand Up @@ -224,6 +225,7 @@
<ClCompile Include="Material.cpp" />
<ClCompile Include="Mesh.cpp" />
<ClCompile Include="CMeshRenderer.cpp" />
<ClCompile Include="Name.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">pch.h</PrecompiledHeaderFile>
Expand Down
6 changes: 6 additions & 0 deletions MyD3DFramework/MyD3DFramework.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
<ClInclude Include="FastCompVector.h">
<Filter>99.Headers\Utility\Container</Filter>
</ClInclude>
<ClInclude Include="Name.h">
<Filter>99.Headers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="MyD3DFramework.ico">
Expand Down Expand Up @@ -361,6 +364,9 @@
<ClCompile Include="FastCompVector.cpp">
<Filter>99.Headers\Utility\Container</Filter>
</ClCompile>
<ClCompile Include="Name.cpp">
<Filter>99.Headers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="MyD3DFramework.rc">
Expand Down
2 changes: 2 additions & 0 deletions MyD3DFramework/Name.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "pch.h"
#include "Name.h"
71 changes: 71 additions & 0 deletions MyD3DFramework/Name.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#pragma once

namespace CM
{
class Name
{
friend struct std::hash<Name>;
public:
inline static std::unordered_map<std::string, size_t> sNamePool;

inline Name(const std::string& InString, size_t InNumber = 0);
inline bool operator==(const Name& Other) const;

inline std::string_view ToString() const;

private:
inline static size_t FindOrAddName(const std::string& inName);

private:
std::string_view m_string;

size_t m_nameID;
size_t m_additionalNumber;
};
}

namespace std
{
template <>
struct hash<CM::Name>
{
size_t operator()(const CM::Name& inItem) const
{
size_t hashValue = std::hash<size_t>()(inItem.m_nameID);
hashValue ^= std::hash<size_t>()(inItem.m_additionalNumber) + 0x9e3779b9 + (hashValue << 6) + (hashValue >> 2);
return hashValue;
}
};
}

inline CM::Name::Name(const std::string& inString, size_t inAdditionalNumber)
{
m_nameID = FindOrAddName(inString);
m_additionalNumber = inAdditionalNumber;
m_string = inString;
}

inline bool CM::Name::operator==(const Name& Other) const
{
return m_nameID == Other.m_nameID && m_additionalNumber == Other.m_additionalNumber;
}

inline std::string_view CM::Name::ToString() const
{
return m_string;
}

inline size_t CM::Name::FindOrAddName(const std::string& Name)
{
for (const auto& pair : sNamePool)
{
if (pair.first == Name)
{
return pair.second;
}
}
std::string nameCopy(Name);
size_t newIndex = sNamePool.size();
sNamePool[nameCopy] = newIndex;
return newIndex;
}
1 change: 1 addition & 0 deletions MyD3DFramework/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ using namespace DirectX::SimpleMath;
#include "Algorithm.h"
#include "SimpleMathAdv.h"
#include "TypeTrait.h"
#include "Name.h"

//MyContainer
#include "SortedVector.h"
Expand Down
Binary file modified MyD3DFramework/x64/Debug/CMeshRenderer.obj
Binary file not shown.
Binary file modified MyD3DFramework/x64/Debug/Effect.obj
Binary file not shown.
Binary file modified MyD3DFramework/x64/Debug/Engine.obj
Binary file not shown.
Binary file modified MyD3DFramework/x64/Debug/FastCompVector.obj
Binary file not shown.
8 changes: 5 additions & 3 deletions MyD3DFramework/x64/Debug/MyD3DFramework.log
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ C:\Users\alsxm\Desktop\dev\MyDX3DFramework\MyD3DFramework\CMeshRenderer.h(5,7):
C:\Users\alsxm\Desktop\dev\MyDX3DFramework\MyD3DFramework\Material.h(3,8):
'Material' 선언을 참조하십시오.

Name.cpp
C:\Users\alsxm\Desktop\dev\MyDX3DFramework\MyD3DFramework\Name.h(16,9): error C2059: 구문 오류: '}'
(소스 파일 '/Name.cpp'을(를) 컴파일하는 중)

Renderer.cpp
C:\Users\alsxm\Desktop\dev\MyDX3DFramework\MyD3DFramework\CMeshRenderer.h(5,7): warning C4099: 'Material': 처음에는 'struct'을(를) 사용하여 형식 이름을 표시했는데 이제는 'class'을(를) 사용하여 표시합니다.
(소스 파일 '/Renderer.cpp'을(를) 컴파일하는 중)
Expand All @@ -40,7 +44,6 @@ C:\Users\alsxm\Desktop\dev\MyDX3DFramework\MyD3DFramework\CMeshRenderer.h(5,7):
C:\Users\alsxm\Desktop\dev\MyDX3DFramework\MyD3DFramework\Material.h(3,8):
'Material' 선언을 참조하십시오.

Scene.cpp
WindowsApp.cpp
C:\Users\alsxm\Desktop\dev\MyDX3DFramework\MyD3DFramework\CMeshRenderer.h(5,7): warning C4099: 'Material': 처음에는 'struct'을(를) 사용하여 형식 이름을 표시했는데 이제는 'class'을(를) 사용하여 표시합니다.
(소스 파일 '/WindowsApp.cpp'을(를) 컴파일하는 중)
Expand All @@ -57,5 +60,4 @@ C:\Users\alsxm\Desktop\dev\MyDX3DFramework\MyD3DFramework\WindowsApp.cpp(114,12)
(소스 파일 '/WindowsApp.cpp'을(를) 컴파일하는 중)

코드를 생성하고 있습니다...
C:\Users\alsxm\Desktop\dev\MyDX3DFramework\MyD3DFramework\Renderer.h(202,1): warning C4715: 'Renderer::GetFeatureLevelToString': 모든 제어 경로에서 값을 반환하지는 않습니다.
MyD3DFramework.vcxproj -> C:\Users\alsxm\Desktop\dev\MyDX3DFramework\Binaries\Debug\MyD3DFramework.exe
C:\Users\alsxm\Desktop\dev\MyDX3DFramework\MyD3DFramework\Renderer.h(195,1): warning C4715: 'Renderer::GetFeatureLevelToString': 모든 제어 경로에서 값을 반환하지는 않습니다.
Binary file modified MyD3DFramework/x64/Debug/MyD3DFramework.tlog/CL.command.1.tlog
Binary file not shown.
Binary file modified MyD3DFramework/x64/Debug/MyD3DFramework.tlog/CL.read.1.tlog
Binary file not shown.
Binary file modified MyD3DFramework/x64/Debug/MyD3DFramework.tlog/CL.write.1.tlog
Binary file not shown.
Empty file.
Binary file modified MyD3DFramework/x64/Debug/Renderer.obj
Binary file not shown.
Binary file modified MyD3DFramework/x64/Debug/ResourceManager.obj
Binary file not shown.
Binary file modified MyD3DFramework/x64/Debug/WindowsApp.obj
Binary file not shown.
Binary file modified MyD3DFramework/x64/Debug/vc143.idb
Binary file not shown.
Binary file modified MyD3DFramework/x64/Debug/vc143.pdb
Binary file not shown.

0 comments on commit df7e828

Please sign in to comment.