Skip to content

Commit

Permalink
Add functionality to trigger bHaptics from scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
fholger committed Sep 3, 2023
1 parent e6748a5 commit 926ccfe
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 15 deletions.
30 changes: 15 additions & 15 deletions Sources/CryGame C++/Solution1/CryGame/CryGame.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\STLPORT\stlport;..\CryCommon;..\..\..\ThirdParty\dxvk\src\d3d9;..\..\..\ThirdParty\dxvk\include\vulkan\include;..\..\..\ThirdParty\minhook\include;..\..\..\ThirdParty\openvr\headers;..\..\..\ThirdParty\ffmpeg\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\STLPORT\stlport;..\CryCommon;..\..\..\ThirdParty\dxvk\src\d3d9;..\..\..\ThirdParty\dxvk\include\vulkan\include;..\..\..\ThirdParty\minhook\include;..\..\..\ThirdParty\openvr\headers;..\..\..\ThirdParty\ffmpeg\include;..\..\..\ThirdParty\bhaptics\include\shared;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_DEBUG;WIN32;_WINDOWS;_USRDLL;CRYGAME_EXPORTS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
Expand All @@ -136,9 +136,9 @@
</ClCompile>
<Link>
<AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d9.lib;dsound.lib;openvr_api.lib;avcodec.lib;avformat.lib;avutil.lib;swscale.lib;swresample.lib;Shlwapi.lib;wininet.lib;Wsock32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>d3d9.lib;dsound.lib;openvr_api.lib;avcodec.lib;avformat.lib;avutil.lib;swscale.lib;swresample.lib;haptic_library.lib;Shlwapi.lib;wininet.lib;Wsock32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>..\..\..\ThirdParty\dxvk\lib;..\..\..\ThirdParty\openvr\lib\win32;..\..\..\ThirdParty\ffmpeg\lib;..\BinkSDK;..\CryNetwork\Debug;.\..\ubisoft.com\GSServices\sdks/gs-sdk-regserver/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-msclient/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-common/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-base/lib_win32;..\ubisoft.com\GSServices\sdks\gs-sdk-cdkey\lib_win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>..\..\..\ThirdParty\dxvk\lib;..\..\..\ThirdParty\openvr\lib\win32;..\..\..\ThirdParty\bhaptics\bin\win32;..\..\..\ThirdParty\ffmpeg\lib;..\BinkSDK;..\CryNetwork\Debug;.\..\ubisoft.com\GSServices\sdks/gs-sdk-regserver/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-msclient/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-common/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-base/lib_win32;..\ubisoft.com\GSServices\sdks\gs-sdk-cdkey\lib_win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>libcmt.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
Expand Down Expand Up @@ -167,7 +167,7 @@
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
<AdditionalIncludeDirectories>..\STLPORT\stlport;..\CryCommon;..\..\..\ThirdParty\dxvk\src\d3d9;..\..\..\ThirdParty\dxvk\include\vulkan\include;..\..\..\ThirdParty\minhook\include;..\..\..\ThirdParty\openvr\headers;..\..\..\ThirdParty\ffmpeg\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\STLPORT\stlport;..\CryCommon;..\..\..\ThirdParty\dxvk\src\d3d9;..\..\..\ThirdParty\dxvk\include\vulkan\include;..\..\..\ThirdParty\minhook\include;..\..\..\ThirdParty\openvr\headers;..\..\..\ThirdParty\ffmpeg\include;..\..\..\ThirdParty\bhaptics\include\shared;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_RELEASE;NDEBUG;USE_GAME_DLL;WIN32;_WINDOWS;_USRDLL;CRYGAME_EXPORTS;_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
Expand All @@ -190,10 +190,10 @@
</ClCompile>
<Link>
<AdditionalOptions>/MACHINE:I386 %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d9.lib;dsound.lib;openvr_api.lib;avcodec.lib;avformat.lib;avutil.lib;swscale.lib;swresample.lib;Shlwapi.lib;wininet.lib;Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>d3d9.lib;dsound.lib;openvr_api.lib;avcodec.lib;avformat.lib;avutil.lib;swscale.lib;swresample.lib;haptic_library.lib;Shlwapi.lib;wininet.lib;Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>.\Release/CryGame.dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>..\..\..\ThirdParty\dxvk\lib;..\..\..\ThirdParty\openvr\lib\win32;..\..\..\ThirdParty\ffmpeg\lib;..\BinkSDK;..\CryNetwork\Release;.\..\ubisoft.com\GSServices\sdks/gs-sdk-regserver/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-msclient/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-common/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-base/lib_win32;..\ubisoft.com\GSServices\sdks\gs-sdk-cdkey\lib_win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>..\..\..\ThirdParty\dxvk\lib;..\..\..\ThirdParty\openvr\lib\win32;..\..\..\ThirdParty\bhaptics\bin\win32;..\..\..\ThirdParty\ffmpeg\lib;..\BinkSDK;..\CryNetwork\Release;.\..\ubisoft.com\GSServices\sdks/gs-sdk-regserver/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-msclient/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-common/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-base/lib_win32;..\ubisoft.com\GSServices\sdks\gs-sdk-cdkey\lib_win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ProgramDatabaseFile>.\Release/CryGame.pdb</ProgramDatabaseFile>
<ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
Expand Down Expand Up @@ -221,7 +221,7 @@
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
<AdditionalIncludeDirectories>..\STLPORT\stlport;..\CryCommon;..\..\..\ThirdParty\dxvk\src\d3d9;..\..\..\ThirdParty\dxvk\include\vulkan\include;..\..\..\ThirdParty\minhook\include;..\..\..\ThirdParty\openvr\headers;..\..\..\ThirdParty\ffmpeg\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\STLPORT\stlport;..\CryCommon;..\..\..\ThirdParty\dxvk\src\d3d9;..\..\..\ThirdParty\dxvk\include\vulkan\include;..\..\..\ThirdParty\minhook\include;..\..\..\ThirdParty\openvr\headers;..\..\..\ThirdParty\ffmpeg\include;..\..\..\ThirdParty\bhaptics\include\shared;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>NDEBUG;USE_GAME_DLL;WIN32;_WINDOWS;_USRDLL;CRYGAME_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
Expand All @@ -243,9 +243,9 @@
</ClCompile>
<Link>
<AdditionalOptions>/MACHINE:I386 /OPT:ref,icf %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d9.lib;dsound.lib;openvr_api.lib;avcodec.lib;avformat.lib;avutil.lib;swscale.lib;swresample.lib;Shlwapi.lib;wininet.lib;Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>d3d9.lib;dsound.lib;openvr_api.lib;avcodec.lib;avformat.lib;avutil.lib;swscale.lib;swresample.lib;haptic_library.lib;Shlwapi.lib;wininet.lib;Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>..\..\..\ThirdParty\dxvk\lib;..\..\..\ThirdParty\openvr\lib\win32;..\..\..\ThirdParty\ffmpeg\lib;..\BinkSDK;..\CryNetwork\Release;.\..\ubisoft.com\GSServices\sdks/gs-sdk-regserver/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-msclient/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-result/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-cdkey/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-common/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-base/lib_win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>..\..\..\ThirdParty\dxvk\lib;..\..\..\ThirdParty\openvr\lib\win32;..\..\..\ThirdParty\bhaptics\bin\win32;..\..\..\ThirdParty\ffmpeg\lib;..\BinkSDK;..\CryNetwork\Release;.\..\ubisoft.com\GSServices\sdks/gs-sdk-regserver/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-msclient/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-result/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-cdkey/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-common/lib_win32;.\..\ubisoft.com\GSServices\sdks/gs-sdk-base/lib_win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
<GenerateMapFile>true</GenerateMapFile>
Expand All @@ -270,7 +270,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug64|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\STLPORT\stlport;..\CryCommon;..\..\..\ThirdParty\dxvk\src\d3d9;..\..\..\ThirdParty\dxvk\include\vulkan\include;..\..\..\ThirdParty\minhook\include;..\..\..\ThirdParty\openvr\headers;..\..\..\ThirdParty\ffmpeg\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\STLPORT\stlport;..\CryCommon;..\..\..\ThirdParty\dxvk\src\d3d9;..\..\..\ThirdParty\dxvk\include\vulkan\include;..\..\..\ThirdParty\minhook\include;..\..\..\ThirdParty\openvr\headers;..\..\..\ThirdParty\ffmpeg\include;..\..\..\ThirdParty\bhaptics\include\shared;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_AMD64_;_DEBUG;WIN64;WIN32;_WINDOWS;_USRDLL;CRYGAME_EXPORTS;DIVX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
Expand All @@ -290,15 +290,15 @@
</ClCompile>
<Link>
<AdditionalOptions>/MACHINE:AMD64 %(AdditionalOptions)</AdditionalOptions>
<AdditionalDependencies>d3d9.lib;dsound.lib;openvr_api.lib;avcodec.lib;avformat.lib;avutil.lib;swscale.lib;swresample.lib;Shlwapi.lib;wininet.lib;Ws2_32.lib;../CryCommon/fSinCos64.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>d3d9.lib;dsound.lib;openvr_api.lib;avcodec.lib;avformat.lib;avutil.lib;swscale.lib;swresample.lib;haptic_library.lib;Shlwapi.lib;wininet.lib;Ws2_32.lib;../CryCommon/fSinCos64.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<IgnoreSpecificDefaultLibraries>libcmt.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(OutDir)$(ProjectName).pdb</ProgramDatabaseFile>
<LargeAddressAware>true</LargeAddressAware>
<ImportLibrary>$(OutDir)$(ProjectName).lib</ImportLibrary>
<AdditionalLibraryDirectories>..\..\..\ThirdParty\dxvk\lib;..\..\..\ThirdParty\openvr\lib\win32;..\..\..\ThirdParty\ffmpeg\lib;</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>..\..\..\ThirdParty\dxvk\lib;..\..\..\ThirdParty\openvr\lib\win32;..\..\..\ThirdParty\bhaptics\bin\win32;..\..\..\ThirdParty\ffmpeg\lib;</AdditionalLibraryDirectories>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
<Midl>
Expand All @@ -323,7 +323,7 @@
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<AdditionalIncludeDirectories>..\STLPORT\stlport;..\CryCommon;..\..\..\ThirdParty\dxvk\src\d3d9;..\..\..\ThirdParty\dxvk\include\vulkan\include;..\..\..\ThirdParty\minhook\include;..\..\..\ThirdParty\openvr\headers;..\..\..\ThirdParty\ffmpeg\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\STLPORT\stlport;..\CryCommon;..\..\..\ThirdParty\dxvk\src\d3d9;..\..\..\ThirdParty\dxvk\include\vulkan\include;..\..\..\ThirdParty\minhook\include;..\..\..\ThirdParty\openvr\headers;..\..\..\ThirdParty\ffmpeg\include;..\..\..\ThirdParty\bhaptics\include\shared;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_RELEASE;NDEBUG;WIN64;WIN32;_AMD64_;_WINDOWS;_USRDLL;CRYGAME_EXPORTS;DIVX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
Expand All @@ -341,15 +341,15 @@
<CompileAs>Default</CompileAs>
</ClCompile>
<Link>
<AdditionalDependencies>d3d9.lib;dsound.lib;openvr_api.lib;avcodec.lib;avformat.lib;avutil.lib;swscale.lib;swresample.lib;Shlwapi.lib;wininet.lib;Ws2_32.lib;../CryCommon/fSinCos64.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>d3d9.lib;dsound.lib;openvr_api.lib;avcodec.lib;avformat.lib;avutil.lib;swscale.lib;swresample.lib;haptic_library.lib;Shlwapi.lib;wininet.lib;Ws2_32.lib;../CryCommon/fSinCos64.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>$(OutDir)$(ProjectName).dll</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<IgnoreSpecificDefaultLibraries>libcmt.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>$(OutDir)$(ProjectName).pdb</ProgramDatabaseFile>
<LargeAddressAware>true</LargeAddressAware>
<ImportLibrary>$(OutDir)$(ProjectName).lib</ImportLibrary>
<AdditionalLibraryDirectories>..\..\..\ThirdParty\dxvk\lib;..\..\..\ThirdParty\openvr\lib\win32;..\..\..\ThirdParty\ffmpeg\lib;</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>..\..\..\ThirdParty\dxvk\lib;..\..\..\ThirdParty\openvr\lib\win32;..\..\..\ThirdParty\bhaptics\bin\win32;..\..\..\ThirdParty\ffmpeg\lib;</AdditionalLibraryDirectories>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
</Link>
<Midl>
Expand Down
15 changes: 15 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/ScriptObjectGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ void CScriptObjectGame::InitializeTemplate(IScriptSystem *pSS)
REG_FUNC(CScriptObjectGame,IsStopVideoRequested);
REG_FUNC(CScriptObjectGame, CreateHapticsEffectFlat);
REG_FUNC(CScriptObjectGame, CreateHapticsEffectCustom);
REG_FUNC(CScriptObjectGame, RegisterBHapticsEffect);
}

//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3901,6 +3902,20 @@ int CScriptObjectGame::CreateHapticsEffectCustom(IFunctionHandler* pH)
return pH->EndFunction();
}

int CScriptObjectGame::RegisterBHapticsEffect(IFunctionHandler* pH)
{
CHECK_PARAMETERS(2);
const char* key = nullptr;
const char* fileName = nullptr;
pH->GetParam(1, key);
pH->GetParam(2, fileName);

if (key != nullptr && fileName != nullptr)
gVR->GetHaptics()->RegisterBHapticsEffect(key, fileName);

return pH->EndFunction();
}

//////////////////////////////////////////////////////////////////////////
int CScriptObjectGame::EnableQuicksave(IFunctionHandler * pH)
{
Expand Down
2 changes: 2 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/ScriptObjectGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ public _ScriptableEx<CScriptObjectGame>
int CreateHapticsEffectFlat(IFunctionHandler* pH);
int CreateHapticsEffectCustom(IFunctionHandler* pH);

int RegisterBHapticsEffect(IFunctionHandler* pH);

private:

CXGame * m_pGame;
Expand Down
26 changes: 26 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/ScriptObjectPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ void CScriptObjectPlayer::InitializeTemplate(IScriptSystem *pSS)
REG_FUNC(CScriptObjectPlayer,SetSmoothInput);
REG_FUNC(CScriptObjectPlayer, TriggerWeaponHapticEffect);
REG_FUNC(CScriptObjectPlayer, TriggerHapticEffect);
REG_FUNC(CScriptObjectPlayer, TriggerBHapticsEffect);

pSS->SetGlobalValue("BITMASK_PLAYER",BITMASK_PLAYER);
pSS->SetGlobalValue("BITMASK_WEAPON",BITMASK_WEAPON);
Expand Down Expand Up @@ -2150,6 +2151,31 @@ int CScriptObjectPlayer::TriggerHapticEffect(IFunctionHandler* pH)
return pH->EndFunction();
}

int CScriptObjectPlayer::TriggerBHapticsEffect(IFunctionHandler* pH)
{
const char* keyRight = nullptr;
const char* keyLeft = nullptr;
float intensity = 1.0f;
float offsetAngleX = 0;
float offsetY = 0;
if (pH->GetParamCount() >= 2)
{
pH->GetParam(1, keyRight);
pH->GetParam(2, keyLeft);
}
if (pH->GetParamCount() >= 3)
pH->GetParam(3, intensity);
if (pH->GetParamCount() >= 4)
pH->GetParam(4, offsetAngleX);
if (pH->GetParamCount() >= 5)
pH->GetParam(5, offsetY);

if (keyRight != nullptr && keyLeft != nullptr)
m_pPlayer->TriggerBHapticsEffect(keyRight, keyLeft, intensity, offsetAngleX, offsetY);

return pH->EndFunction();
}

//////////////////////////////////////////////////////////////////////
IEntityRender * CScriptObjectPlayer::GetIEntityRender(const pe_params_foreign_data & fd)
{
Expand Down
1 change: 1 addition & 0 deletions Sources/CryGame C++/Solution1/CryGame/ScriptObjectPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public IScriptObjectSink
// controller haptics
int TriggerWeaponHapticEffect(IFunctionHandler* pH);
int TriggerHapticEffect(IFunctionHandler* pH);
int TriggerBHapticsEffect(IFunctionHandler* pH);

private:

Expand Down
44 changes: 44 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/VRHaptics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
#include "VRInput.h"
#include "VRManager.h"

#include <HapticLibrary.h>

#include "ICryPak.h"


void VRHaptics::Init(CXGame* game, VRInput* vrInput)
{
m_pGame = game;
m_vrInput = vrInput;
InitialiseSync("farcryvr", "Far Cry VR");
InitEffects();
}

Expand Down Expand Up @@ -45,6 +50,33 @@ void VRHaptics::Update()
}
}

void VRHaptics::RegisterBHapticsEffect(const char* key, const char* file)
{
if (IsFeedbackRegistered(key))
{
CryLogAlways("BHaptics effect already registered: %s", key);
return;
}

ICryPak* pak = m_pGame->GetSystem()->GetIPak();
FILE* f = pak->FOpen(file, "rb");
if (!f)
{
CryLogAlways("BHaptics effect file not found: %s", file);
return;
}
pak->FSeek(f, 0, SEEK_END);
int size = pak->FTell(f);
pak->FSeek(f, 0, SEEK_SET);

char* buffer = new char[size];
pak->FRead(buffer, size, 1, f);
pak->FClose(f);

RegisterFeedbackFromTactFile(key, buffer);
delete[] buffer;
}

void VRHaptics::TriggerEffect(int hand, const char* effectName, float amplitudeModifier)
{
if (m_activeEffects[hand].size() >= 20)
Expand All @@ -60,12 +92,24 @@ void VRHaptics::TriggerEffect(int hand, const char* effectName, float amplitudeM
m_activeEffects[hand].push_back(ActiveHapticEffect{ &it->second, 0, amplitudeModifier });
}

void VRHaptics::TriggerBHapticsEffect(const char* key, float intensity, float offsetAngleX, float offsetY)
{
SubmitRegisteredWithOption(key, key, intensity, 1.0f, offsetAngleX, offsetY);
}

void VRHaptics::StopEffects(int hand)
{
m_activeEffects[hand].clear();
m_vrInput->TriggerHaptics(hand, 0, 0, 0);
}

void VRHaptics::StopAllEffects()
{
StopEffects(0);
StopEffects(1);
TurnOff();
}

void VRHaptics::CreateFlatEffect(const char* effectName, float duration, float amplitude, float easeInTime, float easeOutTime)
{
HapticEffect& effect = m_effects[effectName];
Expand Down
4 changes: 4 additions & 0 deletions Sources/CryGame C++/Solution1/CryGame/VRHaptics.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ class VRHaptics
void Init(CXGame* game, VRInput* vrInput);
void Update();

void RegisterBHapticsEffect(const char* key, const char* file);

void TriggerEffect(int hand, const char* effectName, float amplitudeModifier = 1.0f);
void TriggerBHapticsEffect(const char* key, float intensity = 1.0f, float offsetAngleX = 0, float offsetY = 0);
void StopEffects(int hand);
void StopAllEffects();

void CreateFlatEffect(const char* effectName, float duration, float amplitude, float easeInTime = 0.0f, float easeOutTime = 0.0f);
void CreateCustomEffect(const char* effectName, float* amplitudes, int count);
Expand Down
Loading

0 comments on commit 926ccfe

Please sign in to comment.