1 #ifndef UTIL_H_ 2 #define UTIL_H_ 3 4 #include <memory> 5 #include <vector> 6 #include <string> 7 #include <libwap.h> 8 #include <SDL2/SDL.h> 9 #include <SDL2/SDL_mixer.h> 10 11 struct TileCollisionPrototype; 12 struct TileDescription; 13 14 namespace Util 15 { 16 std::string ConvertToThreeDigitsString(int32_t num); 17 18 SDL_Rect WwdRectToSDLRect(WwdRect& rect); 19 20 void ParseCollisionRectanglesFromTile(TileCollisionPrototype* tilePrototype, TileDescription* tileDesc); 21 22 void SplitStringIntoVector(std::string str, std::vector<std::string>& vec); 23 24 void PrintRect(SDL_Rect rect, std::string comment); 25 26 int GetRandomNumber(int fromRange, int toRange); 27 bool RollDice(int chanceToSucceed); 28 29 std::string PlayRandomSoundFromList(const std::vector<std::string>& sounds, int volume = 100); 30 void PlaySimpleSound(const std::string& sound, int volume = 100); 31 32 int GetSoundDurationMs(const std::string& soundPath); 33 int GetSoundDurationMs(Mix_Chunk* pSound); 34 35 SDL_Texture* CreateSDLTextureRect(int width, int height, SDL_Color color, SDL_Renderer* pRenderer); 36 SDL_Texture* CreateSDLTextureRect(int width, int height, SDL_Color color, SDL_Renderer* pRenderer, uint8_t alpha); 37 38 void PlayRandomHitSound(); 39 40 uint32_t CalcCRC32(const char* pData, size_t dataLen); 41 42 template<typename T> GetRandomValueFromVector(const std::vector<T> & container)43 T GetRandomValueFromVector(const std::vector<T>& container) 44 { 45 int randIdx = GetRandomNumber(0, container.size() - 1); 46 return container[randIdx]; 47 } 48 } 49 50 #endif