1 /* 2 ** sndinfo.h 3 ** 4 **--------------------------------------------------------------------------- 5 ** Copyright 2011 Braden Obrzut 6 ** All rights reserved. 7 ** 8 ** Redistribution and use in source and binary forms, with or without 9 ** modification, are permitted provided that the following conditions 10 ** are met: 11 ** 12 ** 1. Redistributions of source code must retain the above copyright 13 ** notice, this list of conditions and the following disclaimer. 14 ** 2. Redistributions in binary form must reproduce the above copyright 15 ** notice, this list of conditions and the following disclaimer in the 16 ** documentation and/or other materials provided with the distribution. 17 ** 3. The name of the author may not be used to endorse or promote products 18 ** derived from this software without specific prior written permission. 19 ** 20 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 **--------------------------------------------------------------------------- 31 ** 32 ** 33 */ 34 35 #ifndef __SNDINFO_H__ 36 #define __SNDINFO_H__ 37 38 #include "tarray.h" 39 #include "name.h" 40 #include "zstring.h" 41 42 class SoundInformation; 43 44 class SoundIndex 45 { 46 public: index(index)47 SoundIndex(int index = 0) : index(index) {} 48 SoundIndex(const char* logical); 49 50 operator int() const { return index; } 51 private: 52 int index; 53 }; 54 55 class SoundData 56 { 57 public: 58 enum Type 59 { 60 DIGITAL, 61 ADLIB, 62 PCSPEAKER 63 }; 64 65 SoundData(); 66 SoundData(const SoundData &other); 67 ~SoundData(); 68 69 byte* GetData(Type type=ADLIB) const { return data[type]; } GetPriority()70 unsigned short GetPriority() const { return priority; } 71 bool HasType(Type type=ADLIB) const { return lump[type] != -1; } IsNull()72 bool IsNull() const { return lump[0] == -1 && lump[1] == -1 && lump[2] == -1 && !isAlias; } 73 74 const SoundData &operator= (const SoundData &other); 75 protected: 76 FString logicalName; 77 SoundIndex index; 78 byte* data[3]; 79 int lump[3]; 80 unsigned int length[3]; 81 unsigned short priority; 82 83 bool isAlias; 84 TArray<SoundIndex> aliasLinks; 85 86 friend class SoundInformation; 87 }; 88 89 class SoundInformation 90 { 91 public: 92 SoundInformation(); 93 ~SoundInformation(); 94 95 SoundIndex FindSound(const char* logical) const; 96 void Init(); 97 const SoundData &operator[] (const char* logical) const { return operator[](FindSound(logical)); } 98 const SoundData &operator[] (const SoundIndex &index) const; GetLastPlayTick(const SoundData & sound)99 uint32_t GetLastPlayTick(const SoundData &sound) const { return lastPlayTicks[sound.index]; } SetLastPlayTick(const SoundData & sound,uint32_t value)100 void SetLastPlayTick(const SoundData &sound, uint32_t value) const { lastPlayTicks[sound.index] = value; } 101 102 protected: 103 SoundData &AddSound(const char* logical); 104 void CreateHashTable(); 105 void ParseSoundInformation(int lumpNum); 106 107 private: 108 SoundData nullIndex; 109 TArray<SoundData> sounds; 110 TArray<uint32_t> lastPlayTicks; 111 112 struct HashIndex; 113 HashIndex* hashTable; 114 }; 115 extern SoundInformation SoundInfo; 116 117 #endif 118