[Add] 유닛 추가

[Fix] FSM
This commit is contained in:
hyunbin14
2025-11-17 21:22:13 +09:00
parent 388cb99e23
commit 01f4ee5f74
46 changed files with 1105 additions and 376 deletions
+1 -1
View File
@@ -164,7 +164,7 @@ void CChannel::Update_TransformationMatirx(const vector<CBone*>& Bones, _float f
_float dy = XMVectorGetY(vDeltaAdjusted);
_float dz = XMVectorGetZ(vDeltaAdjusted);
_vector vDeltaWorld = vRight * dx + vUp * dz + vLook * dy;
_vector vDeltaWorld = vRight * dx + (-vUp * dz) + vLook * dy;
vDeltaWorld *= 0.01f;
+36 -2
View File
@@ -27,12 +27,15 @@ HRESULT CFSM::Initialize(void* pArg)
void CFSM::Add_State(_uint iIndex, CState* state)
{
m_States[iIndex] = state;
m_States[iIndex]->Set_State(iIndex);
m_States[iIndex]->Set_Owner(m_pOwner);
m_States[iIndex]->Set_Component();
}
void CFSM::Change_State(_uint iIndex)
{
m_pPrevious = m_pCurrent;
if (m_pCurrent)
m_pCurrent->Exit();
@@ -44,10 +47,40 @@ void CFSM::Change_State(_uint iIndex)
void CFSM::Update(_float fTimeDelta)
{
if (m_pCurrent)
m_pCurrent->Update(fTimeDelta);
vector<CState*> States;
CState* pCurrent = m_pCurrent;
while (pCurrent)
{
States.push_back(pCurrent);
pCurrent = pCurrent->Get_Parent();
}
for (_int i = (_int)States.size() - 1; i >= 0; --i) {
States[i]->Update(fTimeDelta);
}
}
_uint CFSM::Get_CurrState()
{
return m_pCurrent->Get_State();
}
_uint CFSM::Get_PrevState()
{
return m_pPrevious->Get_State();
}
void CFSM::Set_Parent(FSMSTATE::ESTATE Child, FSMSTATE::ESTATE Parent)
{
CState* pChild = m_States[Child];
CState* pParent = m_States[Parent];
if (pChild && pParent)
pChild->Set_Parent(pParent);
}
CFSM* CFSM::Create(ID3D11Device* pDevice, ID3D11DeviceContext* pContext)
{
CFSM* pInstance = new CFSM(pDevice, pContext);
@@ -79,6 +112,7 @@ void CFSM::Free()
__super::Free();
SAFE_RELEASE(m_pCurrent);
SAFE_RELEASE(m_pPrevious);
for (auto& states : m_States)
{
@@ -164,6 +164,11 @@ void CGameInstance::BillBoard(CTransform* pTransform)
_matrix BillBoardMatrix = Get_Transform_Matrix(D3DTS::VIEW_INV);
for (_uint i = 0; i < 3; ++i)
{
BillBoardMatrix.r[i] = XMVector3Normalize(BillBoardMatrix.r[i]);
}
_float3 vScale = pTransform->Get_Scale();
_vector vPosition = pTransform->Get_State(STATE::POSITION);
@@ -175,8 +180,6 @@ void CGameInstance::BillBoard(CTransform* pTransform)
BillBoardMatrix.r[3] = vPosition;
pTransform->Set_WorldMatrix(ScaleMatrix * RotationMatrix * BillBoardMatrix);
}
+1
View File
@@ -42,6 +42,7 @@ void CState::Free()
__super::Free();
SAFE_RELEASE(m_pGameInstance);
SAFE_RELEASE(m_pParent);
}
void CState::Describe_Entity()
+62
View File
@@ -46,6 +46,68 @@ HRESULT CUnit::Render()
return S_OK;
}
void CUnit::Load_KeyFrame()
{
FILE* fp = nullptr;
_string Path = {};
for (_uint i = 0; i < m_pGameInstance->BinaryModelFilePathCount(); i++)
{
const _char* szCategory = m_pGameInstance->Load_BinaryModelFilePath(i);
_char szDir[MAX_PATH] = {};
_char szName[MAX_PATH] = {};
_splitpath_s(szCategory, nullptr, 0, szDir, MAX_PATH, szName, MAX_PATH, nullptr, 0);
if (strstr(CMyTools::ToString(m_strModelPrototypeTag).c_str(), szName))
{
Path = _string(szDir) + "KeyFrame.bin";
fopen_s(&fp, Path.c_str(), "rb");
if (!fp) return;
_uint KeyFrameSize = 0;
fread(&KeyFrameSize, sizeof(_uint), 1, fp);
for (size_t i = 0; i < KeyFrameSize; i++)
{
float fKey = 0.f;
fread(&fKey, sizeof(float), 1, fp);
_uint EventLen = 0;
fread(&EventLen, sizeof(_uint), 1, fp);
_string str;
str.resize(EventLen);
fread(str.data(), sizeof(_char), EventLen, fp);
m_KeyFrames.emplace(str, fKey);
}
fclose(fp);
}
}
}
_float CUnit::Get_KeyFrame(_string FrameName)
{
auto iter = m_KeyFrames.find(FrameName);
if (iter == m_KeyFrames.end())
return 0;
return iter->second;
}
_bool CUnit::IsCurrentKeyFrame(_string FrameName)
{
if (m_pModelCom->Get_CurrentTrackPosition() >= Get_KeyFrame(FrameName))
{
return true;
}
return false;
}
HRESULT CUnit::Ready_Components(void *pArg)
{
__super::Ready_Components(pArg);
+9 -6
View File
@@ -4,12 +4,11 @@ NS_BEGIN(FSMSTATE)
enum ESTATE
{
IDLE,
WALK,WALK_FWD, WALK_BWD,
JOG,
SPRINT,
MOVE, WALK, WALK_FWD, WALK_BWD, JOG, SPRINT,
JUMP,
LAND,
DODGE,
ATTACK,
COMBAT, LIGHT_ATTACK, CAST, SKILL,
END
};
NS_END
@@ -31,9 +30,13 @@ class ENGINE_DLL CFSM final : public CComponent
void Change_State(_uint iIndex);
void Update(_float fTimeDelta);
_uint Get_CurrState();
_uint Get_PrevState();
void Set_Parent(FSMSTATE::ESTATE Child, FSMSTATE::ESTATE Parent);
private:
vector<CState*> m_States;
CState* m_pCurrent = { nullptr };
vector<CState*> m_States;
CState* m_pCurrent = { nullptr };
CState* m_pPrevious = { nullptr };
private:
virtual HRESULT Initialize_Prototype() override;
+9
View File
@@ -20,11 +20,20 @@ class ENGINE_DLL CState abstract : public CBase
void Set_Owner(class CGameObject* pOwner);
virtual void Set_Component();
void Set_State(_uint State) { m_eState = State; }
_uint Get_State() { return m_eState; }
void Set_Parent(CState* State) { m_pParent = State; }
CState* Get_Parent() { return m_pParent; }
protected:
CUnit* m_pOwner = { nullptr };
CModel* m_pModel = { nullptr };
CFSM* m_pFSM = { nullptr };
CState* m_pParent = { nullptr };
CGameInstance* m_pGameInstance = { nullptr };
_uint m_eState = {};
public:
virtual void Free() override;
+23 -14
View File
@@ -28,29 +28,38 @@ class ENGINE_DLL CUnit abstract : public CGameObject
virtual void Late_Update(_float fTimeDelta) override;
virtual HRESULT Render() override;
_wstring& Get_PrototypeTag() { return m_strModelPrototypeTag; }
void Load_KeyFrame();
public:
#pragma region STATE
pair<_uint, _bool> Get_AnimInfo(_uint iIndex) { return m_Animation[iIndex]; }
virtual _bool Check(FSMSTATE::ESTATE state) { return false; }
virtual _bool IsWalking() { return false; }
virtual _bool IsDodge() { return false; }
virtual _bool IsSprint() { return false; }
virtual _bool IsJump() { return false; }
void Reset_LightCombo() { m_iLightCombo = 0; }
_uint Next_LightCombo() { return ++m_iLightCombo; }
void Set_LightCombo(_uint LightCombo) { m_iLightCombo = LightCombo; }
_float Get_KeyFrame(_string FrameName);
_bool IsCurrentKeyFrame(_string FrameName);
#pragma endregion
protected:
CShader* m_pShaderCom = { nullptr };
CModel* m_pModelCom = { nullptr };
CFSM* m_pFSM = { nullptr };
_wstring m_strModelPrototypeTag;
_bool m_bRimLight = { true };
_float m_fRimLightPower = { 3.2f };
_float m_fRimLightStrength = { 3.04f };
_float3 m_vRimLightColor = { 69.f / 255.f, 5.f / 255.f, 10.f / 255.f };
CShader* m_pShaderCom = { nullptr };
CModel* m_pModelCom = { nullptr };
CFSM* m_pFSM = { nullptr };
_wstring m_strModelPrototypeTag;
_bool m_bRimLight = { true };
_float m_fRimLightPower = { 3.2f };
_float m_fRimLightStrength = { 3.04f };
_float3 m_vRimLightColor = { 69.f / 255.f, 5.f / 255.f, 10.f / 255.f };
_uint m_iLightCombo = { 0 };
map<_string, _float> m_KeyFrames;
vector<pair<_uint, _bool>> m_Animation;
vector<pair<_uint,_bool>> m_Animation;
private:
virtual void Add_FSM() {};
virtual void Set_FSM() {};
virtual void Set_Anim() {};
protected: