#ifndef HEADER_EFFECT_DATABASE_H #define HEADER_EFFECT_DATABASE_H #include "stdafx.h" #include "Lib/audio/Soundtypes.hpp" #include "Lib/audio/audioloader.hpp" #include #include #include #include "Lib/std/CRC.hpp" #include "crtdbg.h" #include #include #pragma warning(disable:4786) void __cdecl dprintf(char* str,...); #pragma pack(push,1) //********************************************************************************************* struct SEffect // prefix: eff { CString cstrID; CString cstrFilename; uint32 u4Hash; SSampleFile* psfFile; float fPlayTime; float fAttenuation; float fMasterVolume; CString cstrFilenameUsed; // used only while saving bool bLangFound; bool bProcessed; }; //********************************************************************************************* struct SMaterialListElement // prefix: mle { CString cstrID; uint32 u4Hash; }; //********************************************************************************************* struct SCollisionSample // prefix: csm { TSoundMaterial u4SampleID; SSoundTransfer stTransfer; }; //********************************************************************************************* struct SCollision // prefix: col { uint64 u8Key; uint8 u1Samples; float fMinTimeDelay; SCollisionSample csmList[2]; SCollisionSample csmSlide; void SetMinimumDelay(float f_delay) { fMinTimeDelay = f_delay; } float fGetMinDelay() { return fMinTimeDelay; } void RemoveSlide() { u1Samples &= 0x7f; csmSlide.u4SampleID = 0; } void RemoveCollision() { u1Samples &= 0xfc; fMinTimeDelay = 0.0f; csmList[0].u4SampleID = 0; csmList[1].u4SampleID = 0; } bool bSlide() { return ((u1Samples & 0x80) != 0); } bool bCollision() { return ((u1Samples & 0x03) != 0); } void SetNumSamples(uint32 u4_count) { Assert(u4_count<=2); u1Samples &= 0xfc; u1Samples |= (uint8)u4_count; } uint32 u4Samples() { return (uint32)(u1Samples & 0x03); } void SetCollisionDefaults(uint32 u4_col, uint32 u4_hash) { Assert(u4_col<2); csmList[u4_col].u4SampleID = u4_hash; csmList[u4_col].stTransfer.fVolMin = 0.0f; csmList[u4_col].stTransfer.fVolMax = 1.0f; csmList[u4_col].stTransfer.fVolSlope = 1.0f; csmList[u4_col].stTransfer.fVolInt = 0.0f; csmList[u4_col].stTransfer.fPitchMin = -1.0f; csmList[u4_col].stTransfer.fPitchMax = 1.0f; csmList[u4_col].stTransfer.fPitchSlope = 0.0f; csmList[u4_col].stTransfer.fPitchInt = 0.0f; csmList[u4_col].stTransfer.fAttenuate = 1.0f; csmList[u4_col].stTransfer.fMinVelocity = 0.0f; } void EnableSlide() { u1Samples |= 0x80; } void SetSlideDefaults(uint32 u4_hash) { csmSlide.u4SampleID = u4_hash; csmSlide.stTransfer.fVolMin = 0.0f; csmSlide.stTransfer.fVolMax = 1.0f; csmSlide.stTransfer.fVolSlope = 1.0f; csmSlide.stTransfer.fVolInt = 0.0f; csmSlide.stTransfer.fPitchMin = -1.0f; csmSlide.stTransfer.fPitchMax = 1.0f; csmSlide.stTransfer.fPitchSlope = 0.0f; csmSlide.stTransfer.fPitchInt = 0.0f; csmSlide.stTransfer.fAttenuate = 1.0f; csmSlide.stTransfer.fMinVelocity = 0.0f; } }; #pragma pack (pop) typedef std::vector TEffectVector; // prefix ev typedef std::vector TMaterialVector; // prefix mv typedef std::map > TFilePosHash; // prefix fph typedef std::map > TCollisionMap; // prefix cm #define fPACKED_AUDIO_TEXT_VERSION ((float)3.00f) //********************************************************************************************* class CEffectDatabase { public: static CCRC* pcrcHash; TEffectVector evEffects; TMaterialVector mvMaterials; TCollisionMap cmCollisions; //***************************************************************************************** CEffectDatabase(); ~CEffectDatabase(); //***************************************************************************************** void SaveBinary(const char* str_filename, int i_lang); //***************************************************************************************** void SaveText(const char* str_filename); //***************************************************************************************** bool LoadText(const char* str_filename); //***************************************************************************************** void Reset(); //***************************************************************************************** void SaveTextTransfer(std::ofstream& file, SCollisionSample& csm); //***************************************************************************************** uint32 u4Hash(const char* str) { char str_local[1024]; char* pstr = str_local; Assert(str); Assert(strlen(str) > 0); Assert(strlen(str) < 1024); // Remove case sensitivity and forward/backward slash sensitivity. while (*str) { if (*str == '\\') *pstr = '/'; else { *pstr = tolower(*str); } str++; pstr++; } *pstr = 0; pstr++; // hash the result return u4HashBlock(str_local,strlen(str_local)); } //***************************************************************************************** static uint32 u4HashBlock(const void* pv, int i_size) { pcrcHash->Reset(); pcrcHash->CRCBlock(pv, i_size); return (*pcrcHash)(); } //***************************************************************************************** bool bNewEffect(CString& cstr_id, CString& cstr_filename, float f_vol = 0.0f, float f_atten = 0.0f) { SEffect eff; if (cstr_id == "") return false; if (cstr_filename == "") return false; eff.cstrID = cstr_id; eff.cstrFilename = cstr_filename; eff.u4Hash = u4Hash(cstr_id); eff.psfFile = NULL; eff.fPlayTime = 0.0f; eff.fAttenuation = f_atten; eff.fMasterVolume = f_vol; evEffects.push_back(eff); return true; } //***************************************************************************************** bool bFindEffectID(CString& cstr_id) { Assert(cstr_id != ""); uint32 u4_hash = u4Hash(cstr_id); for (TEffectVector::iterator i = evEffects.begin(); i