mouse controls, fixed texture loading

This commit is contained in:
2026-04-27 22:33:40 +03:00
parent cbcfdce047
commit 9569555347
31 changed files with 112 additions and 40 deletions

View File

@@ -31,6 +31,11 @@ static void CallKeyEvent( EInputDeviceType eDevice, EInputButton eButton, bool b
g_pHumanDeviceManager->SetButtonUnpressed(eButton);
}
static void CallAxisEvent( EInputDeviceType eDevice, EInputAxis eAxis, float fValue )
{
g_pHumanDeviceManager->AxisEventRelative(eDevice, eAxis, fValue );
}
extern "C" void __cdecl SteamAPIDebug( ESteamNetworkingSocketsDebugOutputType nType, const char *pszMsg )
{
V_printf("STEAM: %s\n", pszMsg);
@@ -88,6 +93,7 @@ extern "C" void FunnyMain( int argc, char **argv )
pWindow = g_pWindowManager->CreateWindow();
pWindow->Init();
pWindow->SetKeyCallback(CallKeyEvent);
pWindow->SetAxisCallback(CallAxisEvent);
g_pRenderContext = (IRenderContext*)pRenderSystemFactory(RENDER_CONTEXT_INTERFACE_VERSION, NULL);
g_pRenderContext->SetMainWindowManager(g_pWindowManager);

View File

@@ -14,6 +14,7 @@ public:
virtual void SetButtonPressed( EInputButton eButton ) override;
virtual void SetButtonUnpressed( EInputButton eButton ) override;
virtual void AxisEventRelative( EInputDeviceType eDevice, EInputAxis eAxis, float fValue ) override;
virtual void WriteUTF8( uint32_t uCode ) override;
@@ -83,6 +84,13 @@ void CHumanDeviceManager::SetButtonUnpressed( EInputButton eButton )
pInput->OnButton(k_EInputDevice_Keyboard, eButton, false);
}
void CHumanDeviceManager::AxisEventRelative( EInputDeviceType eDevice, EInputAxis eAxis, float fValue )
{
IHumanDeviceInput *pInput = GetCurrentInput();
if (pInput)
pInput->OnGameAxisDiff(eDevice, eAxis, fValue);
}
void CHumanDeviceManager::WriteUTF8( uint32_t uCode )
{

2
external/SDL vendored

2
external/cglm vendored

2
external/slang vendored

2
external/stb vendored

2
external/volk vendored

2
external/xtool vendored

View File

@@ -1,5 +1,5 @@
{
"Mesh": "game/core/maps/test/test0.fmesh_c",
"Material": "game/core/materials/cube.fmat",
"Material": "game/core/materials/nerd.fmat",
"Physics": "game/core/maps/test/test0.fpx"
}

View File

@@ -0,0 +1,5 @@
{
"shader": "funny_basic_pbr",
"AlbedoTexture": "game/core/textures/dev/tile64.png",
"AlbedoMultiplier": [1,1,1,1]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 B

View File

@@ -223,7 +223,6 @@ void CAssetManager::LoadMaterialData( CBaseMaterial *pMaterial, IJSONObject *pOb
if ( pValue->GetArray()->GetParameter(3)->GetType()
== JSON_PARAMETER_NUMBER )
data->w = pValue->GetArray()->GetParameter(3)->GetNumberValue();
V_printf("%s %f %f %f %f\n", desc.m_szEditorName, data->x, data->y, data->z, data->w);
break;
}
default:

View File

@@ -11,7 +11,6 @@ public:
virtual void SetUpMesh( MaterialData_t *pData ) override {
pData->m_vAlbedoColor = m_vAlbedo;
pData->m_uAlbedo = m_tAlbedo;
V_printf("SetUpMesh %f\n", pData->m_vAlbedoColor.x);
};

View File

@@ -30,6 +30,9 @@ void C_MOBAPlayer::Think( float fDelta )
vCameraPos.z = 20;
vCameraPos.y+=3;
g_pWorldRenderer->SetCameraPosition(vCameraPos);
Quat vCameraRot;
glm_euler_yxz_quat((vec3){m_fPitch, m_fYaw, 0}, *(versor*)&vCameraRot);
g_pWorldRenderer->SetCameraRotation(vCameraRot);
}
BaseClass::Think(fDelta);
};
@@ -127,3 +130,35 @@ static void IN_LeftUp( int c, char **v ) {
((C_MOBAPlayer*)pPlayer)->m_bIsLeft = false;
}
static ConCommand endleft("-left", IN_LeftUp);
void Game_OnGameAxis( EInputDeviceType eDevice, EInputAxis eAxis, float fValue )
{
}
static ConVar m_pitch("m_pitch", "0.022", FCVAR_CLIENTDLL);
static ConVar m_yaw("m_yaw", "0.022", FCVAR_CLIENTDLL);
static ConVar sens("sens", "3", FCVAR_CLIENTDLL);
void Game_OnGameAxisDiff( EInputDeviceType eDevice, EInputAxis eAxis, float fValue )
{
C_BaseEntity *pPlayer = UTIL_GetLocalPlayer();
if (!pPlayer)
return;
if (!dynamic_cast<C_MOBAPlayer*>(pPlayer))
return;
switch(eAxis)
{
case k_EInputAxis_MouseY:
((C_MOBAPlayer*)pPlayer)->m_fPitch -= glm_rad(fValue * m_pitch.GetFloat() * sens.GetFloat());
break;
case k_EInputAxis_MouseX:
((C_MOBAPlayer*)pPlayer)->m_fYaw -= glm_rad(fValue * m_yaw.GetFloat() * sens.GetFloat());
break;
default:
break;
}
}

View File

@@ -24,6 +24,9 @@ public:
float m_fFBWalkingDirection;
float m_fLRWalkingDirection;
float m_fPitch= 0;
float m_fYaw = 0;
Vector m_vMovementVector;
Vector m_vLocalMovementVector;
Vector vCameraPos;

View File

@@ -1,6 +1,7 @@
#include "userinput.h"
#include "tier1/utlstring.h"
#include "game.h"
#include "baseentity.h"
class CFunnyInput: public IHumanDeviceInput
{
@@ -48,12 +49,20 @@ void CFunnyInput::OnGameButton( EInputDeviceType eDevice, EInputButton eScancode
}
}
void Game_OnGameAxis( EInputDeviceType eDevice, EInputAxis eAxis, float fValue );
void Game_OnGameAxisDiff( EInputDeviceType eDevice, EInputAxis eAxis, float fValue );
void CFunnyInput::OnGameAxis( EInputDeviceType eDevice, EInputAxis eAxis, float fValue)
{
Game_OnGameAxis(eDevice, eAxis, fValue);
}
void CFunnyInput::OnGameAxisDiff( EInputDeviceType eDevice, EInputAxis eAxis, float fValue )
{
Game_OnGameAxisDiff(eDevice, eAxis, fValue);
}

View File

@@ -241,6 +241,7 @@ void CFunnyWorldRenderer::Frame( float fDelta )
glm_mat4_identity(matCamera);
glm_mat4_identity(matCamera2);
glm_translate(matCamera2, m_vPos);
glm_quat_rotate(matCamera2, m_vRot, matCamera2);
glm_mat4_inv(matCamera2, matCamera2);
glm_perspective(glm_rad(75), uWidth/(float)uHeight, 0.01, 10000, matCamera);
glm_mul(matCamera, matCamera2, matCamera);

View File

@@ -33,8 +33,8 @@ public:
SDL_WindowID WindowID();
KeyCallbackFn m_fnKeyCallback;
AxisCallbackFn m_fnAxisCallback;
KeyCallbackFn m_fnKeyCallback = NULL;
AxisCallbackFn m_fnAxisCallback = NULL;
bool m_bWindowSizeUpdated;
uint32_t m_uRenderWidth;
@@ -55,6 +55,7 @@ void CSDLGameWindow::Init()
Plat_FatalErrorFunc("SDL_CreateWindow: %s\n", SDL_GetError());
m_uRenderWidth = 1280;
m_uRenderHeight = 720;
SDL_SetWindowRelativeMouseMode(m_pWindow, true);
}
void CSDLGameWindow::Shutdown()
@@ -231,43 +232,40 @@ void CSDLGameWindowManager::Frame( float fDelta )
}
while (SDL_PollEvent(&event))
{
for (auto a: m_pWindows)
{
if (a->WindowID() != event.window.windowID)
break;
pWindow = a;
break;
}
switch (event.type)
{
case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED:
for (auto a: m_pWindows)
{
if (a->WindowID() != event.window.windowID)
break;
pWindow = a;
break;
}
pWindow->m_bWindowSizeUpdated = true;
pWindow->m_uRenderWidth = event.window.data1;
pWindow->m_uRenderHeight = event.window.data2;
break;
case SDL_EVENT_KEY_UP:
for (auto a: m_pWindows)
{
if (a->WindowID() != event.window.windowID)
break;
pWindow = a;
break;
}
if (pWindow->m_fnKeyCallback)
pWindow->m_fnKeyCallback(k_EInputDevice_Keyboard, GetKeyButton(event.key.key), false);
break;
case SDL_EVENT_KEY_DOWN:
for (auto a: m_pWindows)
{
if (a->WindowID() != event.window.windowID)
break;
pWindow = a;
break;
}
if (pWindow->m_fnKeyCallback)
pWindow->m_fnKeyCallback(k_EInputDevice_Keyboard, GetKeyButton(event.key.key), true);
break;
case SDL_EVENT_MOUSE_MOTION:
if (pWindow->m_fnAxisCallback)
{
pWindow->m_fnAxisCallback(k_EInputDevice_Mouse, k_EInputAxis_MouseX, event.motion.xrel);
pWindow->m_fnAxisCallback(k_EInputDevice_Mouse, k_EInputAxis_MouseY, event.motion.yrel);
}
break;
case SDL_EVENT_QUIT:
Plat_Exit(0);
break;

View File

@@ -142,6 +142,7 @@ void CVkMaterial::SetShaderResource( uint32_t uRegister, uint32_t uSet, IRenderi
writes[1].descriptorCount = 128;
writes[1].pImageInfo = stWrites;
vkUpdateDescriptorSets(m_pVkShader->m_hDevice, 2, writes, 0, 0);
m_pTextureArray = pArray;
}
}

View File

@@ -109,6 +109,10 @@ void CVkRenderCommandList::SetMaterial( IMaterial *pMaterial )
CVkSetShaderDataCommand *pSetShaderData = CREATE_COMMAND(m_pCommandBufferManager, SetShaderData);
pSetShaderData->pShaderData = pMaterial;
{
CVkTextureArray *pArray = (CVkTextureArray*)((CVkMaterial*)pMaterial)->m_pTextureArray;
}
m_pCurrentMaterialBuffer->AddCommand(pSetShaderData);
CVkSetScissorsCommand *pScissorsCommand = CREATE_COMMAND(m_pCommandBufferManager, SetScissors);

View File

@@ -397,11 +397,11 @@ uint32_t CVkTextureArray::CreateTexture( uint32_t i, const char *szPath )
IBuffer *pBuffer = m_pRenderContext->CreateStorageBuffer(uWidth*uHeight*4);
pBuffer->Lock();
void *pData = pBuffer->Map();
V_memcpy(pData, pImg, uWidth*uHeight*uChannels);
V_memcpy(pData, pImg, uWidth*uHeight*4);
pBuffer->Unmap();
pBuffer->Unlock();
vkDeviceWaitIdle(s_vkDevice);
IImage *pImage = m_pRenderContext->CreateTexture(uWidth, uHeight, IMAGE_FORMAT_RGBA8_UNORM, MULTISAMPLE_TYPE_NONE);
IImage *pCompressedImage = m_pRenderContext->CreateTexture(uWidth, uHeight, IMAGE_FORMAT_BC1, MULTISAMPLE_TYPE_NONE);
m_pImages[i] = (CVkImage*)pImage;
stbi_image_free(pImg);

View File

@@ -338,6 +338,7 @@ private:
};
CUtlVector<ShaderBinding_t> m_callableShaders = {};
};
#define MAX_TEXTURES 4096
class CVkTextureArray: public ITextureArray
{
@@ -357,7 +358,7 @@ public:
IRenderContext *m_pRenderContext;
IVkCommandBufferManager *m_pCommandBufferManager;
VkSampler m_hSampler;
CVkImage *m_pImages[128];
CVkImage *m_pImages[MAX_TEXTURES];
};
class CVkMaterial: public IMaterial
@@ -377,6 +378,7 @@ public:
CVkShader *m_pVkShader;
CUtlVector<VkDescriptorSet> m_hSets;
ITextureArray *m_pTextureArray;
private:
VkDescriptorPool m_hPool;
CUtlVector<VkWriteDescriptorSet> m_writes = {};

View File

@@ -106,6 +106,7 @@ inline ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags,
m_szName = pName;
m_flags = flags;
SetValue(pDefaultValue);
Console()->RegisterVar(this);
}
inline bool ConVar::IsFlagSet( int flag )

View File

@@ -33,6 +33,7 @@ public:
virtual void SetButtonPressed( EInputButton eButton ) = 0;
virtual void SetButtonUnpressed( EInputButton eButton ) = 0;
virtual void AxisEventRelative( EInputDeviceType eDevice, EInputAxis eAxis, float fValue ) = 0;
virtual void WriteUTF8( uint32_t uCode ) = 0;
};