Skip to content

Commit

Permalink
fixup! Consistent variables naming in Audio_Demo example script.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Oct 10, 2024
1 parent b8ee8c3 commit 1209945
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 94 deletions.
102 changes: 48 additions & 54 deletions cleo_plugins/Audio/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
#include "CTheScripts.h"
#include "CSoundSystem.h"
#include "CAudioStream.h"
#include "StreamHandle.h"

using namespace CLEO;
using namespace plugin;

#define OPCODE_READ_PARAM_STREAM_HANDLE(_varName) StreamHandle _varName(_readParam(thread).dwParam); \
#define OPCODE_READ_PARAM_STREAM(_varName) auto _varName = (CAudioStream*)_readParam(thread).pParam; \
if (!_paramWasInt()) { SHOW_ERROR("Input argument %s expected to be integer, got %s in script %s\nScript suspended.", GetParamInfo().c_str(), CLEO::ToKindStr(_lastParamType, _lastParamArrayType), CLEO::ScriptInfoStr(thread).c_str()); return thread->Suspend(); } \
else if (!soundSystem.HasStream(_varName.GetStream())) { SHOW_ERROR("Invalid or already closed '0x%X' audio stream handle param in script %s \nScript suspended.", _paramsArray[0].dwParam, GetParamInfo().c_str(), ScriptInfoStr(thread).c_str()); return thread->Suspend(); }
else if (!soundSystem.HasStream(_varName)) { SHOW_ERROR("Invalid or already closed '0x%X' audio stream handle param in script %s \nScript suspended.", _varName, GetParamInfo().c_str(), ScriptInfoStr(thread).c_str()); return thread->Suspend(); }

class Audio
{
Expand Down Expand Up @@ -129,20 +128,17 @@ class Audio
ptr->SetType(CLEO::CSoundSystem::LegacyModeDefaultStreamType);
}

auto handle = StreamHandle(ptr);

OPCODE_WRITE_PARAM_UINT(handle.GetValue());
OPCODE_WRITE_PARAM_UINT(ptr);
OPCODE_CONDITION_RESULT(ptr != nullptr);
return OR_CONTINUE;
}

//0AAD=2,set_audiostream %1d% perform_action %2d%
static OpcodeResult __stdcall opcode_0AAD(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
auto action = OPCODE_READ_PARAM_INT();

auto stream = handle.GetStream();
switch (action)
{
case eStreamAction::Stop: stream->Stop(); break;
Expand All @@ -159,19 +155,19 @@ class Audio
//0AAE=1,release_audiostream %1d%
static OpcodeResult __stdcall opcode_0AAE(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);

soundSystem.DestroyStream(handle.GetStream());
soundSystem.DestroyStream(stream);

return OR_CONTINUE;
}

//0AAF=2,%2d% = get_audiostream_length %1d%
static OpcodeResult __stdcall opcode_0AAF(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);

auto length = handle.GetStream()->GetLength();
auto length = stream->GetLength();

OPCODE_WRITE_PARAM_INT((int)length);
return OR_CONTINUE;
Expand All @@ -180,9 +176,9 @@ class Audio
//0AB9=2,get_audio_stream_state %1d% store_to %2d%
static OpcodeResult __stdcall opcode_0AB9(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);

auto state = handle.GetStream()->GetState();
auto state = stream->GetState();

OPCODE_WRITE_PARAM_INT(state);
return OR_CONTINUE;
Expand All @@ -191,9 +187,9 @@ class Audio
//0ABB=2,%2d% = get_audio_stream_volume %1d%
static OpcodeResult __stdcall opcode_0ABB(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);

auto volume = handle.GetStream()->GetVolume();
auto volume = stream->GetVolume();

OPCODE_WRITE_PARAM_FLOAT(volume);
return OR_CONTINUE;
Expand All @@ -202,21 +198,21 @@ class Audio
//0ABC=2,set_audiostream %1d% volume %2d%
static OpcodeResult __stdcall opcode_0ABC(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
auto volume = OPCODE_READ_PARAM_FLOAT();

handle.GetStream()->SetVolume(volume);
stream->SetVolume(volume);

return OR_CONTINUE;
}

//0AC0=2,loop_audiostream %1d% flag %2d%
static OpcodeResult __stdcall opcode_0AC0(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
auto loop = OPCODE_READ_PARAM_BOOL();

handle.GetStream()->SetLooping(loop);
stream->SetLooping(loop);

return OR_CONTINUE;
}
Expand All @@ -236,69 +232,67 @@ class Audio
ptr->SetType(CLEO::CSoundSystem::LegacyModeDefaultStreamType);
}

auto handle = StreamHandle(ptr);

OPCODE_WRITE_PARAM_UINT(handle.GetValue());
OPCODE_WRITE_PARAM_UINT(ptr);
OPCODE_CONDITION_RESULT(ptr != nullptr);
return OR_CONTINUE;
}

//0AC2=4,set_3d_audiostream %1d% position %2d% %3d% %4d%
static OpcodeResult __stdcall opcode_0AC2(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
CVector pos;
pos.x = OPCODE_READ_PARAM_FLOAT();
pos.y = OPCODE_READ_PARAM_FLOAT();
pos.z = OPCODE_READ_PARAM_FLOAT();

handle.GetStream()->Set3dPosition(pos);
stream->Set3dPosition(pos);

return OR_CONTINUE;
}

//0AC3=2,link_3d_audiostream %1d% to_object %2d%
static OpcodeResult __stdcall opcode_0AC3(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
auto objHandle = OPCODE_READ_PARAM_OBJECT_HANDLE();

auto object = CPools::GetObject(objHandle);
handle.GetStream()->Link(object);
stream->Link(object);

return OR_CONTINUE;
}

//0AC4=2,link_3d_audiostream %1d% to_actor %2d%
static OpcodeResult __stdcall opcode_0AC4(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
auto pedHandle = OPCODE_READ_PARAM_PED_HANDLE();

auto ped = CPools::GetPed(pedHandle);
handle.GetStream()->Link(ped);
stream->Link(ped);

return OR_CONTINUE;
}

//0AC5=2,link_3d_audiostream %1d% to_vehicle %2d%
static OpcodeResult __stdcall opcode_0AC5(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
auto vehHandle = OPCODE_READ_PARAM_VEHICLE_HANDLE();

auto vehicle = CPools::GetVehicle(vehHandle);
handle.GetStream()->Link(vehicle);
stream->Link(vehicle);

return OR_CONTINUE;
}

//2500=1, is_audio_stream_playing %1d%
static OpcodeResult __stdcall opcode_2500(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);

auto state = handle.GetStream()->GetState();
auto state = stream->GetState();

OPCODE_CONDITION_RESULT(state == CAudioStream::eStreamState::Playing);
return OR_CONTINUE;
Expand All @@ -307,11 +301,11 @@ class Audio
//2501=2,%2d% = get_audiostream_duration %1d%
static OpcodeResult __stdcall opcode_2501(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);

auto length = handle.GetStream()->GetLength();
auto length = stream->GetLength();

auto speed = handle.GetStream()->GetSpeed();
auto speed = stream->GetSpeed();
if (speed <= 0.0f)
length = FLT_MAX; // it would take forever to play paused
else
Expand All @@ -324,9 +318,9 @@ class Audio
//2502=2,get_audio_stream_speed %1d% store_to %2d%
static OpcodeResult __stdcall opcode_2502(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);

auto speed = handle.GetStream()->GetSpeed();
auto speed = stream->GetSpeed();

OPCODE_WRITE_PARAM_FLOAT(speed);
return OR_CONTINUE;
Expand All @@ -335,55 +329,55 @@ class Audio
//2503=2,set_audio_stream_speed %1d% speed %2d%
static OpcodeResult __stdcall opcode_2503(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
auto speed = OPCODE_READ_PARAM_FLOAT();

handle.GetStream()->SetSpeed(speed);
stream->SetSpeed(speed);

return OR_CONTINUE;
}

//2504=3,set_audio_stream_volume_with_transition %1d% volume %2d% time_ms %2d%
static OpcodeResult __stdcall opcode_2504(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
auto volume = OPCODE_READ_PARAM_FLOAT();
auto time = OPCODE_READ_PARAM_INT();

handle.GetStream()->SetVolume(volume, 0.001f * time);
stream->SetVolume(volume, 0.001f * time);

return OR_CONTINUE;
}

//2505=3,set_audio_stream_speed_with_transition %1d% speed %2d% time_ms %2d%
static OpcodeResult __stdcall opcode_2505(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
auto speed = OPCODE_READ_PARAM_FLOAT();
auto time = OPCODE_READ_PARAM_INT();

handle.GetStream()->SetSpeed(speed, 0.001f * time);
stream->SetSpeed(speed, 0.001f * time);

return OR_CONTINUE;
}

//2506=2,set_audio_stream_source_size %1d% radius %2d%
static OpcodeResult __stdcall opcode_2506(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
auto radius = OPCODE_READ_PARAM_FLOAT();

handle.GetStream()->Set3dSourceSize(radius);
stream->Set3dSourceSize(radius);

return OR_CONTINUE;
}

//2507=2,get_audio_stream_progress %1d% store_to %2d%
static OpcodeResult __stdcall opcode_2507(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);

auto progress = handle.GetStream()->GetProgress();
auto progress = stream->GetProgress();

OPCODE_WRITE_PARAM_FLOAT(progress);
return OR_CONTINUE;
Expand All @@ -392,20 +386,20 @@ class Audio
//2508=2,set_audio_stream_progress %1d% speed %2d%
static OpcodeResult __stdcall opcode_2508(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
auto speed = OPCODE_READ_PARAM_FLOAT();

handle.GetStream()->SetProgress(speed);
stream->SetProgress(speed);

return OR_CONTINUE;
}

//2509=2,get_audio_stream_type %1d% store_to %2d%
static OpcodeResult __stdcall opcode_2509(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);

auto type = handle.GetStream()->GetType();
auto type = stream->GetType();

OPCODE_WRITE_PARAM_INT(type);
return OR_CONTINUE;
Expand All @@ -414,10 +408,10 @@ class Audio
//250A=2,set_audio_stream_type %1d% type %2d%
static OpcodeResult __stdcall opcode_250A(CScriptThread* thread)
{
OPCODE_READ_PARAM_STREAM_HANDLE(handle);
OPCODE_READ_PARAM_STREAM(stream);
auto type = OPCODE_READ_PARAM_INT();

handle.GetStream()->SetType((eStreamType)type);
stream->SetType((eStreamType)type);

return OR_CONTINUE;
}
Expand Down
1 change: 0 additions & 1 deletion cleo_plugins/Audio/Audio.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ xcopy /Y "$(OutDir)$(TargetName).*" "$(GTA_SA_DIR)\cleo\cleo_plugins\" </Command
<ClInclude Include="C3DAudioStream.h" />
<ClInclude Include="CAudioStream.h" />
<ClInclude Include="CSoundSystem.h" />
<ClInclude Include="StreamHandle.h" />
</ItemGroup>
<ItemGroup>
<None Include="SA.Audio.ini" />
Expand Down
1 change: 0 additions & 1 deletion cleo_plugins/Audio/Audio.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
</ClInclude>
<ClInclude Include="CAudioStream.h" />
<ClInclude Include="C3DAudioStream.h" />
<ClInclude Include="StreamHandle.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="plugin_sdk">
Expand Down
9 changes: 8 additions & 1 deletion cleo_plugins/Audio/CAudioStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@

namespace CLEO
{
class CAudioStream
// in CLEO4 CAudioStream was extending VInjectible
// this dummy parent keeps offset of CAudioStream::streamInternal unchanged
class Dummy
{
virtual void dummy() {};
};

class CAudioStream : Dummy
{
public:
enum eStreamState
Expand Down
36 changes: 0 additions & 36 deletions cleo_plugins/Audio/StreamHandle.h

This file was deleted.

Loading

0 comments on commit 1209945

Please sign in to comment.