Add support for loading sound assets from iw4 zones

This commit is contained in:
Jan 2020-09-08 12:11:16 +02:00
parent 79848b4631
commit d35560ccd7
8 changed files with 246 additions and 37 deletions

View File

@ -12,9 +12,9 @@ ZoneCode.Assets = {
"MaterialVertexDeclaration",
"MaterialTechniqueSet",
"GfxImage",
-- "snd_alias_list_t",
-- "SndCurve",
-- "LoadedSound",
"snd_alias_list_t",
"SndCurve",
"LoadedSound",
-- "clipMap_t",
-- "ComWorld",
-- "GameWorldSp",

View File

@ -12,9 +12,9 @@ asset MaterialVertexShader ASSET_TYPE_VERTEXSHADER;
asset MaterialVertexDeclaration ASSET_TYPE_VERTEXDECL;
asset MaterialTechniqueSet ASSET_TYPE_TECHNIQUE_SET;
asset GfxImage ASSET_TYPE_IMAGE;
// asset snd_alias_list_t ASSET_TYPE_SOUND;
// asset SndCurve ASSET_TYPE_SOUND_CURVE;
// asset LoadedSound ASSET_TYPE_LOADED_SOUND;
asset snd_alias_list_t ASSET_TYPE_SOUND;
asset SndCurve ASSET_TYPE_SOUND_CURVE;
asset LoadedSound ASSET_TYPE_LOADED_SOUND;
// asset clipMap_t ASSET_TYPE_CLIPMAP_MP;
// asset ComWorld ASSET_TYPE_COMWORLD;
// asset GameWorldSp ASSET_TYPE_GAMEWORLD_SP;
@ -346,6 +346,59 @@ use GfxImageLoadDef;
set action LoadImageData(GfxImageLoadDef, GfxImage);
set arraysize data resourceSize;
// =========================================
// snd_alias_list_t
// =========================================
use snd_alias_list_t;
set string aliasName;
set name aliasName;
set reusable head;
set count head count;
// snd_alias_t
use snd_alias_t;
set string aliasName;
set string subtitle;
set string secondaryAliasName;
set string chainAliasName;
set string mixerGroup;
set reusable soundFile;
set reusable speakerMap;
// SoundFile
set condition SoundFile::u::loadSnd type == SAT_LOADED;
// SpeakerMap
set string SpeakerMap::name;
// StreamedSound
use StreamedSound;
set string dir;
set string name;
// =========================================
// SndCurve
// =========================================
use SndCurve;
set string filename;
set name filename;
// =========================================
// LoadedSound
// =========================================
use LoadedSound;
set string name;
set name name;
// MssSound
use MssSound;
set block data XFILE_BLOCK_TEMP;
set reusable data;
set count data info::data_len;
set condition info::data_ptr never;
set condition info::initial_ptr never;
set action SetSoundData(MssSound);
// =========================================
// RawFile
// =========================================

View File

@ -113,9 +113,9 @@ GameAssetPoolIW4::GameAssetPoolIW4(const int priority)
m_material_vertex_decl = nullptr;
m_technique_set = nullptr;
m_image = nullptr;
// m_sound = nullptr;
// m_sound_curve = nullptr;
// m_loaded_sound = nullptr;
m_sound = nullptr;
m_sound_curve = nullptr;
m_loaded_sound = nullptr;
// m_clip_map = nullptr;
// m_com_world = nullptr;
// m_game_world_sp = nullptr;
@ -165,9 +165,9 @@ void GameAssetPoolIW4::InitPoolStatic(const asset_type_t type, const size_t capa
CASE_INIT_POOL_STATIC(ASSET_TYPE_VERTEXDECL, m_material_vertex_decl, MaterialVertexDeclaration);
CASE_INIT_POOL_STATIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set, MaterialTechniqueSet);
CASE_INIT_POOL_STATIC(ASSET_TYPE_IMAGE, m_image, GfxImage);
// CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND, m_sound, snd_alias_list_t);
// CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND_CURVE, m_sound_curve, SndCurve);
// CASE_INIT_POOL_STATIC(ASSET_TYPE_LOADED_SOUND, m_loaded_sound, LoadedSound);
CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND, m_sound, snd_alias_list_t);
CASE_INIT_POOL_STATIC(ASSET_TYPE_SOUND_CURVE, m_sound_curve, SndCurve);
CASE_INIT_POOL_STATIC(ASSET_TYPE_LOADED_SOUND, m_loaded_sound, LoadedSound);
// CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP_SP, m_clip_map, clipMap_t);
// CASE_INIT_POOL_STATIC(ASSET_TYPE_CLIPMAP_MP, m_clip_map, clipMap_t);
// CASE_INIT_POOL_STATIC(ASSET_TYPE_COMWORLD, m_com_world, ComWorld);
@ -225,9 +225,9 @@ void GameAssetPoolIW4::InitPoolDynamic(const asset_type_t type)
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_VERTEXDECL, m_material_vertex_decl, MaterialVertexDeclaration);
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_TECHNIQUE_SET, m_technique_set, MaterialTechniqueSet);
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_IMAGE, m_image, GfxImage);
// CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND, m_sound, snd_alias_list_t);
// CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND_CURVE, m_sound_curve, SndCurve);
// CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LOADED_SOUND, m_loaded_sound, LoadedSound);
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND, m_sound, snd_alias_list_t);
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_SOUND_CURVE, m_sound_curve, SndCurve);
CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_LOADED_SOUND, m_loaded_sound, LoadedSound);
// CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP_SP, m_clip_map, clipMap_t);
// CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_CLIPMAP_MP, m_clip_map, clipMap_t);
// CASE_INIT_POOL_DYNAMIC(ASSET_TYPE_COMWORLD, m_com_world, ComWorld);
@ -294,9 +294,9 @@ XAssetInfoGeneric* GameAssetPoolIW4::AddAsset(asset_type_t type, std::string nam
CASE_ADD_TO_POOL(ASSET_TYPE_VERTEXDECL, m_material_vertex_decl, vertexDecl);
CASE_ADD_TO_POOL(ASSET_TYPE_TECHNIQUE_SET, m_technique_set, techniqueSet);
CASE_ADD_TO_POOL(ASSET_TYPE_IMAGE, m_image, image);
// CASE_ADD_TO_POOL(ASSET_TYPE_SOUND, m_sound, sound);
// CASE_ADD_TO_POOL(ASSET_TYPE_SOUND_CURVE, m_sound_curve, sndCurve);
// CASE_ADD_TO_POOL(ASSET_TYPE_LOADED_SOUND, m_loaded_sound, loadSnd);
CASE_ADD_TO_POOL(ASSET_TYPE_SOUND, m_sound, sound);
CASE_ADD_TO_POOL(ASSET_TYPE_SOUND_CURVE, m_sound_curve, sndCurve);
CASE_ADD_TO_POOL(ASSET_TYPE_LOADED_SOUND, m_loaded_sound, loadSnd);
// CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP_SP, m_clip_map, clipMap);
// CASE_ADD_TO_POOL(ASSET_TYPE_CLIPMAP_MP, m_clip_map, clipMap);
// CASE_ADD_TO_POOL(ASSET_TYPE_COMWORLD, m_com_world, comWorld);
@ -354,9 +354,9 @@ XAssetInfoGeneric* GameAssetPoolIW4::GetAsset(const asset_type_t type, std::stri
CASE_GET_ASSET(ASSET_TYPE_VERTEXDECL, m_material_vertex_decl);
CASE_GET_ASSET(ASSET_TYPE_TECHNIQUE_SET, m_technique_set);
CASE_GET_ASSET(ASSET_TYPE_IMAGE, m_image);
// CASE_GET_ASSET(ASSET_TYPE_SOUND, m_sound);
// CASE_GET_ASSET(ASSET_TYPE_SOUND_CURVE, m_sound_curve);
// CASE_GET_ASSET(ASSET_TYPE_LOADED_SOUND, m_loaded_sound);
CASE_GET_ASSET(ASSET_TYPE_SOUND, m_sound);
CASE_GET_ASSET(ASSET_TYPE_SOUND_CURVE, m_sound_curve);
CASE_GET_ASSET(ASSET_TYPE_LOADED_SOUND, m_loaded_sound);
// CASE_GET_ASSET(ASSET_TYPE_CLIPMAP_SP, m_clip_map);
// CASE_GET_ASSET(ASSET_TYPE_CLIPMAP_MP, m_clip_map);
// CASE_GET_ASSET(ASSET_TYPE_COMWORLD, m_com_world);

View File

@ -25,9 +25,9 @@ public:
std::unique_ptr<AssetPool<IW4::MaterialVertexDeclaration>> m_material_vertex_decl;
std::unique_ptr<AssetPool<IW4::MaterialTechniqueSet>> m_technique_set;
std::unique_ptr<AssetPool<IW4::GfxImage>> m_image;
// std::unique_ptr<AssetPool<IW4::snd_alias_list_t>> m_sound;
// std::unique_ptr<AssetPool<IW4::SndCurve>> m_sound_curve;
// std::unique_ptr<AssetPool<IW4::LoadedSound>> m_loaded_sound;
std::unique_ptr<AssetPool<IW4::snd_alias_list_t>> m_sound;
std::unique_ptr<AssetPool<IW4::SndCurve>> m_sound_curve;
std::unique_ptr<AssetPool<IW4::LoadedSound>> m_loaded_sound;
// std::unique_ptr<AssetPool<IW4::clipMap_t>> m_clip_map;
// std::unique_ptr<AssetPool<IW4::ComWorld>> m_com_world;
// std::unique_ptr<AssetPool<IW4::GameWorldSp>> m_game_world_sp;

View File

@ -84,9 +84,9 @@ namespace IW4
struct MaterialVertexDeclaration;
struct MaterialTechniqueSet;
struct GfxImage;
// struct snd_alias_list_t;
// struct SndCurve;
// struct LoadedSound;
struct snd_alias_list_t;
struct SndCurve;
struct LoadedSound;
// struct clipMap_t;
// struct ComWorld;
// struct GameWorldSp;
@ -105,7 +105,6 @@ namespace IW4
// struct FxImpactTable;
struct RawFile;
struct StringTable;
// struct LeaderboardDef;
// struct StructuredDataDefSet;
// struct TracerDef;
@ -125,9 +124,9 @@ namespace IW4
MaterialVertexDeclaration* vertexDecl;
MaterialTechniqueSet* techniqueSet;
GfxImage* image;
// snd_alias_list_t* sound;
// SndCurve* sndCurve;
// LoadedSound* loadSnd;
snd_alias_list_t* sound;
SndCurve* sndCurve;
LoadedSound* loadSnd;
// clipMap_t* clipMap;
// ComWorld* comWorld;
// GameWorldSp* gameWorldSp;
@ -852,6 +851,126 @@ namespace IW4
StringTableCell* values;
};
struct _AILSOUNDINFO
{
int format;
const void* data_ptr;
unsigned int data_len;
unsigned int rate;
int bits;
int channels;
unsigned int samples;
unsigned int block_size;
const void* initial_ptr;
};
struct MssSound
{
_AILSOUNDINFO info;
char* data;
};
struct LoadedSound
{
const char* name;
MssSound sound;
};
struct StreamedSound
{
const char* dir;
const char* name;
};
union SoundFileRef
{
LoadedSound* loadSnd;
StreamedSound streamSnd;
};
enum snd_alias_type_t : char
{
SAT_UNKNOWN = 0x0,
SAT_LOADED = 0x1,
SAT_STREAMED = 0x2,
SAT_VOICED = 0x3,
SAT_COUNT,
};
struct SoundFile
{
snd_alias_type_t type;
char exists;
SoundFileRef u;
};
struct MSSSpeakerLevels
{
int speaker;
int numLevels;
float levels[2];
};
struct MSSChannelMap
{
int speakerCount;
MSSSpeakerLevels speakers[6];
};
struct SpeakerMap
{
bool isDefault;
const char* name;
MSSChannelMap channelMaps[2][2];
};
struct snd_alias_t
{
const char* aliasName;
const char* subtitle;
const char* secondaryAliasName;
const char* chainAliasName;
const char* mixerGroup;
SoundFile* soundFile;
int sequence;
float volMin;
float volMax;
float pitchMin;
float pitchMax;
float distMin;
float distMax;
float velocityMin;
int flags;
union
{
float slavePercentage;
float masterPercentage;
};
float probability;
float lfePercentage;
float centerPercentage;
int startDelay;
SndCurve* volumeFalloffCurve;
float envelopMin;
float envelopMax;
float envelopPercentage;
SpeakerMap* speakerMap;
};
struct snd_alias_list_t
{
const char* aliasName;
snd_alias_t* head;
int count;
};
struct SndCurve
{
const char* filename;
unsigned __int16 knotCount;
float knots[16][2];
};
#ifndef __zonecodegenerator
}
#endif

View File

@ -17,7 +17,7 @@
//#include "Game/IW4/XAssets/gfxlightdef/gfxlightdef_load_db.h"
//#include "Game/IW4/XAssets/gfxworld/gfxworld_load_db.h"
//#include "Game/IW4/XAssets/leaderboarddef/leaderboarddef_load_db.h"
//#include "Game/IW4/XAssets/loadedsound/loadedsound_load_db.h"
#include "Game/IW4/XAssets/loadedsound/loadedsound_load_db.h"
//#include "Game/IW4/XAssets/localizeentry/localizeentry_load_db.h"
//#include "Game/IW4/XAssets/mapents/mapents_load_db.h"
#include "Game/IW4/XAssets/material/material_load_db.h"
@ -30,8 +30,8 @@
#include "Game/IW4/XAssets/physcollmap/physcollmap_load_db.h"
#include "Game/IW4/XAssets/physpreset/physpreset_load_db.h"
#include "Game/IW4/XAssets/rawfile/rawfile_load_db.h"
//#include "Game/IW4/XAssets/snd_alias_list_t/snd_alias_list_t_load_db.h"
//#include "Game/IW4/XAssets/sndcurve/sndcurve_load_db.h"
#include "Game/IW4/XAssets/snd_alias_list_t/snd_alias_list_t_load_db.h"
#include "Game/IW4/XAssets/sndcurve/sndcurve_load_db.h"
//#include "Game/IW4/XAssets/snddriverglobals/snddriverglobals_load_db.h"
#include "Game/IW4/XAssets/stringtable/stringtable_load_db.h"
//#include "Game/IW4/XAssets/structureddatadefset/structureddatadefset_load_db.h"
@ -110,9 +110,9 @@ void ContentLoaderIW4::LoadXAsset(const bool atStreamStart)
LOAD_ASSET(ASSET_TYPE_VERTEXDECL, MaterialVertexDeclaration, vertexDecl);
LOAD_ASSET(ASSET_TYPE_TECHNIQUE_SET, MaterialTechniqueSet, techniqueSet);
LOAD_ASSET(ASSET_TYPE_IMAGE, GfxImage, image);
// LOAD_ASSET(ASSET_TYPE_SOUND, snd_alias_list_t, sound);
// LOAD_ASSET(ASSET_TYPE_SOUND_CURVE, SndCurve, sndCurve);
// LOAD_ASSET(ASSET_TYPE_LOADED_SOUND, LoadedSound, loadSnd);
LOAD_ASSET(ASSET_TYPE_SOUND, snd_alias_list_t, sound);
LOAD_ASSET(ASSET_TYPE_SOUND_CURVE, SndCurve, sndCurve);
LOAD_ASSET(ASSET_TYPE_LOADED_SOUND, LoadedSound, loadSnd);
// LOAD_ASSET(ASSET_TYPE_CLIPMAP_SP, clipMap_t, clipMap);
// LOAD_ASSET(ASSET_TYPE_CLIPMAP_MP, clipMap_t, clipMap);
// LOAD_ASSET(ASSET_TYPE_COMWORLD, ComWorld, comWorld);

View File

@ -0,0 +1,22 @@
#include "loadedsound_actions.h"
using namespace IW4;
Actions_LoadedSound::Actions_LoadedSound(Zone* zone)
: AssetLoadingActions(zone)
{
}
void Actions_LoadedSound::SetSoundData(MssSound* sound) const
{
if (sound->info.data_len > 0)
{
char* tempData = sound->data;
sound->data = static_cast<char*>(m_zone->GetMemory()->Alloc(sound->info.data_len));
memcpy(sound->data, tempData, sound->info.data_len);
}
else
{
sound->data = nullptr;
}
}

View File

@ -0,0 +1,15 @@
#pragma once
#include "Loading/AssetLoadingActions.h"
#include "Game/IW4/IW4.h"
namespace IW4
{
class Actions_LoadedSound final : public AssetLoadingActions
{
public:
explicit Actions_LoadedSound(Zone* zone);
void SetSoundData(MssSound* sound) const;
};
}