2019-05-29 00:52:30 +00:00
|
|
|
#include "common.h"
|
2020-04-17 13:31:11 +00:00
|
|
|
|
2019-05-29 00:52:30 +00:00
|
|
|
#include "AudioScriptObject.h"
|
2020-01-25 10:41:22 +00:00
|
|
|
#include "Pools.h"
|
2020-03-28 14:47:52 +00:00
|
|
|
#include "DMAudio.h"
|
2019-05-29 00:52:30 +00:00
|
|
|
|
2020-08-20 11:47:53 +00:00
|
|
|
cAudioScriptObject::cAudioScriptObject()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
cAudioScriptObject::~cAudioScriptObject()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
};
|
|
|
|
|
2020-01-25 10:41:22 +00:00
|
|
|
void
|
|
|
|
cAudioScriptObject::Reset()
|
2019-05-29 00:52:30 +00:00
|
|
|
{
|
2020-05-16 02:06:51 +00:00
|
|
|
AudioId = SCRIPT_SOUND_INVALID;
|
2020-01-25 10:41:22 +00:00
|
|
|
Posn = CVector(0.0f, 0.0f, 0.0f);
|
|
|
|
AudioEntity = AEHANDLE_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
cAudioScriptObject::operator new(size_t sz)
|
|
|
|
{
|
|
|
|
return CPools::GetAudioScriptObjectPool()->New();
|
|
|
|
}
|
2020-03-31 13:09:18 +00:00
|
|
|
|
2020-01-25 10:41:22 +00:00
|
|
|
void *
|
|
|
|
cAudioScriptObject::operator new(size_t sz, int handle)
|
|
|
|
{
|
|
|
|
return CPools::GetAudioScriptObjectPool()->New(handle);
|
|
|
|
}
|
2020-03-31 13:09:18 +00:00
|
|
|
|
2020-01-25 10:41:22 +00:00
|
|
|
void
|
|
|
|
cAudioScriptObject::operator delete(void *p, size_t sz)
|
|
|
|
{
|
|
|
|
CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject *)p);
|
|
|
|
}
|
2020-03-31 13:09:18 +00:00
|
|
|
|
2020-01-25 10:41:22 +00:00
|
|
|
void
|
|
|
|
cAudioScriptObject::operator delete(void *p, int handle)
|
|
|
|
{
|
|
|
|
CPools::GetAudioScriptObjectPool()->Delete((cAudioScriptObject *)p);
|
|
|
|
}
|
|
|
|
|
2020-03-31 13:09:18 +00:00
|
|
|
void
|
|
|
|
cAudioScriptObject::LoadAllAudioScriptObjects(uint8 *buf, uint32 size)
|
|
|
|
{
|
|
|
|
INITSAVEBUF
|
|
|
|
|
|
|
|
CheckSaveHeader(buf, 'A', 'U', 'D', '\0', size - SAVE_HEADER_SIZE);
|
|
|
|
|
|
|
|
int32 pool_size = ReadSaveBuf<int32>(buf);
|
|
|
|
for (int32 i = 0; i < pool_size; i++) {
|
|
|
|
int handle = ReadSaveBuf<int32>(buf);
|
|
|
|
cAudioScriptObject *p = new(handle) cAudioScriptObject;
|
|
|
|
assert(p != nil);
|
|
|
|
*p = ReadSaveBuf<cAudioScriptObject>(buf);
|
|
|
|
p->AudioEntity = DMAudio.CreateLoopingScriptObject(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
VALIDATESAVEBUF(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cAudioScriptObject::SaveAllAudioScriptObjects(uint8 *buf, uint32 *size)
|
|
|
|
{
|
|
|
|
INITSAVEBUF
|
|
|
|
|
|
|
|
int32 pool_size = CPools::GetAudioScriptObjectPool()->GetNoOfUsedSpaces();
|
2020-04-05 23:01:03 +00:00
|
|
|
*size = SAVE_HEADER_SIZE + sizeof(int32) + pool_size * (sizeof(cAudioScriptObject) + sizeof(int32));
|
2020-03-31 13:09:18 +00:00
|
|
|
WriteSaveHeader(buf, 'A', 'U', 'D', '\0', *size - SAVE_HEADER_SIZE);
|
|
|
|
WriteSaveBuf(buf, pool_size);
|
|
|
|
|
|
|
|
int32 i = CPools::GetAudioScriptObjectPool()->GetSize();
|
|
|
|
while (i--) {
|
|
|
|
cAudioScriptObject *p = CPools::GetAudioScriptObjectPool()->GetSlot(i);
|
|
|
|
if (p != nil) {
|
|
|
|
WriteSaveBuf(buf, CPools::GetAudioScriptObjectPool()->GetIndex(p));
|
|
|
|
WriteSaveBuf(buf, *p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VALIDATESAVEBUF(*size);
|
|
|
|
}
|
|
|
|
|
2020-01-25 10:41:22 +00:00
|
|
|
void
|
|
|
|
PlayOneShotScriptObject(uint8 id, CVector const &pos)
|
|
|
|
{
|
|
|
|
cAudioScriptObject *audioScriptObject = new cAudioScriptObject();
|
|
|
|
audioScriptObject->Posn = pos;
|
|
|
|
audioScriptObject->AudioId = id;
|
|
|
|
audioScriptObject->AudioEntity = AEHANDLE_NONE;
|
|
|
|
DMAudio.CreateOneShotScriptObject(audioScriptObject);
|
|
|
|
}
|