Skip to content

Commit d0da209

Browse files
committed
Finish bass implementation
1 parent 01a505a commit d0da209

File tree

8 files changed

+609
-69
lines changed

8 files changed

+609
-69
lines changed

PyLoader/CSoundSystem.cpp

Lines changed: 406 additions & 0 deletions
Large diffs are not rendered by default.

PyLoader/CSoundSystem.h

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Credits:
3+
* This part of the source is taken from the CLEO4 Project
4+
* https://github.com/cleolibrary/CLEO4
5+
*/
6+
#pragma once
7+
#include "pch.h"
8+
#include <set>
9+
#include "depend/bass.h"
10+
11+
class CAudioStream;
12+
class C3DAudioStream;
13+
14+
class CSoundSystem
15+
{
16+
friend class CAudioStream;
17+
friend class C3DAudioStream;
18+
19+
std::set<CAudioStream *> streams;
20+
BASS_INFO SoundDevice;
21+
bool initialized;
22+
int forceDevice;
23+
bool paused;
24+
bool bUseFPAudio;
25+
HWND hwnd;
26+
27+
public:
28+
virtual void Inject();
29+
bool Init(HWND hwnd);
30+
inline bool Initialized() { return initialized; }
31+
32+
CSoundSystem() : initialized(false), forceDevice(-1), paused(false), bUseFPAudio(false)
33+
{
34+
// TODO: give to user an ability to force a sound device to use (ini-file or cmd-lineflog << "
35+
36+
}
37+
38+
~CSoundSystem()
39+
{
40+
flog << "Closing SoundSystem..." << std::endl;
41+
UnloadAllStreams();
42+
if (initialized)
43+
{
44+
flog << "Freeing BASS library" << std::endl;
45+
BASS_Free();
46+
initialized = false;
47+
}
48+
flog << "SoundSystem closed!" << std::endl;
49+
}
50+
51+
CAudioStream * LoadStream(const char *filename, bool in3d = false);
52+
void PauseStreams();
53+
void ResumeStreams();
54+
void UnloadStream(CAudioStream *stream);
55+
void UnloadAllStreams();
56+
void Update();
57+
};
58+
59+
class CAudioStream
60+
{
61+
friend class CSoundSystem;
62+
63+
CAudioStream(const CAudioStream&);
64+
65+
protected:
66+
HSTREAM streamInternal;
67+
enum eStreamState
68+
{
69+
no,
70+
playing,
71+
paused,
72+
stopped,
73+
} state;
74+
bool OK;
75+
CAudioStream();
76+
77+
public:
78+
CAudioStream(const char *src);
79+
virtual ~CAudioStream();
80+
81+
// actions on streams
82+
void Play();
83+
void Pause(bool change_state = true);
84+
void Stop();
85+
void Resume();
86+
DWORD GetLength();
87+
DWORD GetState();
88+
float GetVolume();
89+
void SetVolume(float val);
90+
void Loop(bool enable);
91+
HSTREAM GetInternal();
92+
93+
// overloadable actions
94+
virtual void Set3dPosition(const CVector& pos);
95+
virtual void Link(CPlaceable *placable = nullptr);
96+
virtual void Process();
97+
};
98+
99+
class C3DAudioStream : public CAudioStream
100+
{
101+
friend class CSoundSystem;
102+
103+
C3DAudioStream(const C3DAudioStream&);
104+
105+
protected:
106+
CPlaceable * link;
107+
BASS_3DVECTOR position;
108+
public:
109+
C3DAudioStream(const char *src);
110+
virtual ~C3DAudioStream();
111+
112+
// overloaded actions
113+
virtual void Set3dPosition(const CVector& pos);
114+
virtual void Link(CPlaceable *placable = nullptr);
115+
virtual void Process();
116+
};
117+
118+
extern CSoundSystem SoundSystem;

PyLoader/PyLoader.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
#include "sdk/PyInternal.h"
1313
#include "sdk/PyBass.h"
1414
#include "PyEvents.h"
15+
#include "CSoundSystem.h"
1516

1617
std::ofstream flog("PyLoader.log");
1718
size_t game_ticks = 0;
19+
CSoundSystem SoundSystem;
1820

1921
void PyLoader::LoadPlugins(std::string&& dir_name)
2022
{
@@ -96,7 +98,7 @@ void PyLoader::PluginThread(void* param)
9698
};
9799

98100
flog << "------------------------------\nStarting PyLoader v" << plugin_ver
99-
<< "\nAuthor: Grinch_\nMore info: https:///github.com/user-grinch/PyLoaderSA/" << std::endl;
101+
<< "\nAuthor: Grinch_\nThanks: CLEO4 & PluginSDK devs\nMore info: https:///github.com/user-grinch/PyLoaderSA/" << std::endl;
100102

101103
CheckUpdate();
102104

@@ -125,6 +127,8 @@ void PyLoader::PluginThread(void* param)
125127
PyEval_ReleaseLock();
126128

127129
PyEvents::InitAllEvents();
130+
SoundSystem.Inject();
131+
SoundSystem.Init(RsGlobal.ps->window);
128132

129133
// load scripts
130134
if (dir != INVALID_HANDLE_VALUE)

PyLoader/PyLoader.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<ItemGroup>
9898
<ClCompile Include="depend\jute.cpp" />
9999
<ClCompile Include="DllMain.cpp" />
100+
<ClCompile Include="CSoundSystem.cpp" />
100101
<ClCompile Include="sdk\PyBass.cpp" />
101102
<ClCompile Include="PyEvents.cpp" />
102103
<ClCompile Include="sdk\PyInternal.cpp" />
@@ -111,6 +112,7 @@
111112
<ItemGroup>
112113
<ClInclude Include="depend\bass.h" />
113114
<ClInclude Include="depend\jute.h" />
115+
<ClInclude Include="CSoundSystem.h" />
114116
<ClInclude Include="sdk\PyBass.h" />
115117
<ClInclude Include="PyEvents.h" />
116118
<ClInclude Include="PyEventsInternal.h" />

PyLoader/PyLoader.vcxproj.filters

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<ClCompile Include="PyEvents.cpp" />
1414
<ClCompile Include="depend\jute.cpp" />
1515
<ClCompile Include="sdk\PyBass.cpp" />
16+
<ClCompile Include="CSoundSystem.cpp" />
1617
</ItemGroup>
1718
<ItemGroup>
1819
<ClInclude Include="pch.h" />
@@ -30,6 +31,7 @@
3031
<ClInclude Include="PyEventsInternal.h" />
3132
<ClInclude Include="sdk\PyBass.h" />
3233
<ClInclude Include="depend\bass.h" />
34+
<ClInclude Include="CSoundSystem.h" />
3335
</ItemGroup>
3436
<ItemGroup>
3537
<Library Include="depend\bass.lib" />

PyLoader/pch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
#include <filesystem>
1111

1212
namespace fs = std::filesystem;
13-
constexpr const char* plugin_ver = "0.03";
13+
constexpr const char* plugin_ver = "0.05";
1414
extern size_t game_ticks;
1515
extern std::ofstream flog;

0 commit comments

Comments
 (0)