controllers done i guess

This commit is contained in:
2026-06-15 16:11:55 +03:00
parent c51080a903
commit 900b12a6a6
14 changed files with 206 additions and 48 deletions

View File

@@ -40,9 +40,9 @@ public:
return u;
}
}
for ( auto &m: m_objects)
for ( uint32_t u = 1; u < nCount; u++ )
{
if (m.m_pObject == NULL)
if (m_objects[u].m_pObject == NULL)
break;
uFoundIndex++;
}
@@ -57,6 +57,8 @@ public:
{
if (uIndex >= nCount)
return 0;
if (uIndex == 0)
return 0;
return m_objects[uIndex].m_pObject;
}
void UnrefObject( uint32_t uIndex )
@@ -135,6 +137,7 @@ FunnyMesh_t *CAssetManager::GetMeshByIndex( uint32_t uIndex )
uint32_t CAssetManager::LoadModel( const char *szName )
{
V_printf("LOADING %s\n", szName);
bool bHasBeenCreated = false;
HFunnyModel hModel = m_models.GetOrCreateObject(szName, &bHasBeenCreated);
if (!bHasBeenCreated)
@@ -170,7 +173,6 @@ uint32_t CAssetManager::LoadModel( const char *szName )
IJSONValue *pMesh = pMainObject->GetValue("Mesh");
IJSONValue *pMaterial = pMainObject->GetValue("Material");
IJSONValue *pPhysics = pMainObject->GetValue("Physics");
V_printf("%s\n", pMaterial->GetStringValue());
if (pMesh)
pModel->m_hMesh = LoadMesh(pMesh->GetStringValue());
if (pMaterial)
@@ -294,7 +296,7 @@ void CAssetManager::UnrefMaterial( uint32_t uIndex )
HFunnyMesh CAssetManager::LoadMesh( const char *szName )
{
V_printf("LOADING %s\n", szName);
bool bHasBeenCreated = false;
HFunnyMesh hAsset = m_meshes.GetOrCreateObject(szName, &bHasBeenCreated);
if (!bHasBeenCreated)
@@ -308,6 +310,7 @@ HFunnyMesh CAssetManager::LoadMesh( const char *szName )
m_meshes.UnrefObject(hAsset);
return 0;
}
V_printf("V_LOADING %s %llu\n", szName, filesystem->Size(hMesh));
IVertexBuffer *pVertexBuffer = g_pRenderContext->CreateVertexBuffer(filesystem->Size(hMesh));
pVertexBuffer->Lock();

View File

@@ -325,6 +325,13 @@ C_BaseEntity **CEntitySystem::GetEntities()
return m_pEntities;
};
C_BaseEntity *CEntitySystem::GetEntityByIndex( int idx )
{
if (idx < 0 || idx >= MAX_EDICTS)
return NULL;
return m_pEntities[idx];
}
C_BaseEntity *UTIL_GetLocalPlayer()
{
return s_pLocalEntity;

View File

@@ -14,6 +14,7 @@ class IEntityFactory;
class C_BaseEntity;
#define MAX_EDICTS 8192
#define EDICT_INDEX_UNDEFINED (-1U)
class CEntitySystem
{
@@ -35,6 +36,8 @@ public:
virtual void NetSendThink( INetworkBase *pBase );
virtual C_BaseEntity **GetEntities();
virtual C_BaseEntity *GetEntityByIndex( int idx );
private:
C_BaseEntity *m_pEntities[MAX_EDICTS];
int m_nEntityCount;

View File

@@ -108,6 +108,7 @@ void CFunnyGameBridge::Init()
for ( uint32_t i = 0; i < pHeadSet->GetControllerCount(); i++ )
{
pHeadSet->GetController(i)->SetInputCallback(XRInputCallback);
V_printf("callback set on %p\n", pHeadSet->GetController(i));
}
}
@@ -161,7 +162,6 @@ void CFunnyGameBridge::Frame( float fDelta )
if (pHeadSet) {
XRRenderSurface_t s = pHeadSet->GetSurface(0);
g_pWorldRenderer->SetCameraPosition(s.m_vPosition);
V_printf("%f\n", s.m_vPosition.y);
g_pWorldRenderer->SetCameraRotation(s.m_vRotation);
}

View File

@@ -26,10 +26,9 @@ void C_MOBAPlayer::Think( float fDelta )
if (pPlayerEntity == this)
{
}
m_pLeftHand = (C_MOBAPlayerHandController*)EntitySystem()->GetEntities()[m_leftHandId];
m_pRightHand = (C_MOBAPlayerHandController*)EntitySystem()->GetEntities()[m_rightHandId];
m_pLeftHand = (C_MOBAPlayerHandController*)EntitySystem()->GetEntityByIndex(m_leftHandId);
m_pRightHand = (C_MOBAPlayerHandController*)EntitySystem()->GetEntityByIndex(m_rightHandId);
BaseClass::Think(fDelta);
V_printf("device: %p %p\n", m_pLeftHand, m_pRightHand );
};
LINK_ENTITY_TO_CLASS(player, C_MOBAPlayer)
@@ -161,6 +160,14 @@ void Game_OnGameAxisDiff( EInputDeviceType eDevice, EInputAxis eAxis, float fVal
void C_MOBAPlayerHandController::Precache()
{
m_hNormal = g_pAssetManager->LoadModel("game/core/models/hand.fmdl");
m_pNormalModel = g_pAssetManager->GetModelByIndex(m_hNormal);
m_hSqueezed = g_pAssetManager->LoadModel("game/core/models/sphere.fmdl");
m_pSqueezedModel = g_pAssetManager->GetModelByIndex(m_hSqueezed);
m_pModel = m_pNormalModel;
m_pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh)->m_pMesh;
m_pInstance = g_pWorldRenderer->CreateInstance(m_pMesh);
}
@@ -172,10 +179,45 @@ void C_MOBAPlayerHandController::Spawn()
void C_MOBAPlayerHandController::Think( float fDelta )
{
V_printf("controller: %p %f %f %f\n", this, m_vDesiredHandPosition.x, m_vDesiredHandPosition.y, m_vDesiredHandPosition.z );
SetAbsOrigin(m_vDesiredHandPosition);
BaseClass::Think(fDelta);
};
if (m_fSqueeze != m_fPreviousSqueeze)
{
if (m_fSqueeze > 0.5 && m_fPreviousSqueeze > 0.5)
goto draw;
if (m_fSqueeze <= 0.5 && m_fPreviousSqueeze <= 0.5)
goto draw;
if (m_pInstance)
g_pWorldRenderer->DestroyMeshInstance(m_pMesh, m_pInstance);
if (m_fSqueeze > 0.5)
m_pModel = m_pSqueezedModel;
else
m_pModel = m_pNormalModel;
m_pMesh = g_pAssetManager->GetMeshByIndex(m_pModel->m_hMesh)->m_pMesh;
m_pInstance = g_pWorldRenderer->CreateInstance(m_pMesh);
}
draw:
if (m_pInstance)
{
CBaseMaterial *pMat = g_pAssetManager->GetMaterialByIndex(m_pModel->m_hMaterial)->m_pLayout;
m_pInstance->SetPosition(m_vDesiredHandPosition);
m_pInstance->SetRotation(m_vDesiredHandRotation);
m_pInstance->SetScale({0.025, 0.025, 0.025});
m_pInstance->SetMaterial(pMat);
}
m_fPreviousSqueeze = m_fSqueeze;
}
C_MOBAPlayerHandController::~C_MOBAPlayerHandController()
{
if (m_pInstance)
g_pWorldRenderer->DestroyMeshInstance(m_pMesh, m_pInstance);
g_pAssetManager->UnrefModel(m_hNormal);
g_pAssetManager->UnrefModel(m_hSqueezed);
}
LINK_ENTITY_TO_CLASS(player_hand_controller, C_MOBAPlayerHandController)
@@ -208,11 +250,19 @@ void XRInputCallback( IXRController *pController, EXRInputType_t eType, const ch
if (pCon == NULL)
return;
switch (action)
{
case k_EXRInputAction_Pose:
pCon->m_vDesiredHandPosition = value.pose.pos;
V_printf("callback: %p %f %f %f\n", pCon, pCon->m_vDesiredHandPosition.x, pCon->m_vDesiredHandPosition.y, pCon->m_vDesiredHandPosition.z );
switch (eType) {
case k_EXRInput_Grip:
if (action == k_EXRInputAction_Pose)
{
pCon->m_vDesiredHandPosition = value.pose.pos;
pCon->m_vDesiredHandRotation = value.pose.rot;
}
break;
case k_EXRInput_Squeeze:
if (action == k_EXRInputAction_Value)
{
pCon->m_fSqueeze = value.f32.value;
}
break;
default:
break;

View File

@@ -3,19 +3,32 @@
#define MILMOBA_PLAYER_H
#include "basemodelentity.h"
class C_MOBAPlayerHandController: public C_BaseModelEntity
class C_MOBAPlayerHandController: public C_BaseEntity
{
public:
DECLARE_CLASS(C_MOBAPlayerHandController, C_BaseModelEntity);
DECLARE_CLASS(C_MOBAPlayerHandController, C_BaseEntity);
DECLARE_DATADESC();
DECLARE_CLIENTCLASS();
virtual void Precache ( void ) override;
virtual void Spawn( void ) override;
void Think( float fDelta );
virtual ~C_MOBAPlayerHandController() override;
Vector m_vDesiredHandPosition = {};
Quat m_vDesiredHandRotation = {};
float m_fPreviousSqueeze = 0;
float m_fSqueeze = 0;
HFunnyModel m_hNormal = NULL;
FunnyModel_t *m_pNormalModel = NULL;
HFunnyModel m_hSqueezed = NULL;
FunnyModel_t *m_pSqueezedModel = NULL;
FunnyModel_t *m_pModel = NULL;
IMesh *m_pMesh = NULL;
IMeshInstance *m_pInstance = NULL;
};
class C_MOBAPlayer: public C_BaseModelEntity
@@ -45,10 +58,10 @@ public:
Vector m_vLocalMovementVector;
Vector vCameraPos;
C_MOBAPlayerHandController *m_pLeftHand;
int m_leftHandId = 0;
C_MOBAPlayerHandController *m_pRightHand;
int m_rightHandId = 0;
C_MOBAPlayerHandController *m_pLeftHand = NULL;
int m_leftHandId = EDICT_INDEX_UNDEFINED;
C_MOBAPlayerHandController *m_pRightHand = NULL;
int m_rightHandId = EDICT_INDEX_UNDEFINED;
};

View File

@@ -105,13 +105,6 @@ void CFunnyMeshInstance::Frame()
v[2] = m_vScale.z;
glm_scale_make(m, v);
glm_mat4_mul(m_data.m_matTranslation, m, m_data.m_matTranslation);
/*
V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[0][0], m_data.m_matTranslation[0][1], m_data.m_matTranslation[0][2], m_data.m_matTranslation[0][3]);
V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[1][0], m_data.m_matTranslation[1][1], m_data.m_matTranslation[1][2], m_data.m_matTranslation[1][3]);
V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[2][0], m_data.m_matTranslation[2][1], m_data.m_matTranslation[2][2], m_data.m_matTranslation[2][3]);
V_printf("AAAAA %f %f %f %f\n", m_data.m_matTranslation[3][0], m_data.m_matTranslation[3][1], m_data.m_matTranslation[3][2], m_data.m_matTranslation[3][3]);
*/
}
void CFunnyMeshInstance::SetMaterial( CBaseMaterial *pMaterial )