mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
RWOP can now work with Music and Sound loading
This commit is contained in:
parent
977721b226
commit
52918909e9
|
@ -1,4 +1,5 @@
|
|||
#include "Music.h"
|
||||
#include "_caster.h"
|
||||
#include "begin_code.h"
|
||||
//private
|
||||
void Music::_set(Mix_Music* p)
|
||||
|
@ -21,6 +22,11 @@ Music::Music(const std::string& Filename)
|
|||
_set(Mix_LoadMUS(Filename.c_str()));
|
||||
}
|
||||
|
||||
Music::Music(const RWOP& rwop,MusicType musicType)
|
||||
{
|
||||
_set(Mix_LoadMUSType_RW(rwop._get(),_internal::getMixMusicTypeFromMusicType(musicType),0));
|
||||
}
|
||||
|
||||
bool Music::isReady() const
|
||||
{
|
||||
return (_get()!=nullptr);
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <string>
|
||||
#include "ErrorViewer.h"
|
||||
#include "Audio.h"
|
||||
#include "RWOP.h"
|
||||
#include "_MusicType.h"
|
||||
#include "__Noncopyable.h"
|
||||
#include "__Plugin.h"
|
||||
#include "begin_code.h"
|
||||
|
@ -13,8 +15,10 @@ class Music
|
|||
public:
|
||||
Music()=default;
|
||||
Music(const std::string& Filename);
|
||||
Music(const RWOP& rwop,MusicType musicType);
|
||||
bool isReady() const;
|
||||
void release();
|
||||
MusicType getType() const;
|
||||
private:
|
||||
std::shared_ptr<Mix_Music> _music;
|
||||
void _set(Mix_Music*);
|
||||
|
|
|
@ -23,6 +23,8 @@ private:
|
|||
void _set(SDL_RWops*);
|
||||
friend class Surface;
|
||||
friend class Renderer;
|
||||
friend class Sound;
|
||||
friend class Music;
|
||||
|
||||
friend class _internal::Plugin;
|
||||
};
|
||||
|
|
|
@ -21,6 +21,11 @@ Sound::Sound(const std::string& WAVFilename)
|
|||
_set(Mix_LoadWAV(WAVFilename.c_str()));
|
||||
}
|
||||
|
||||
Sound::Sound(const RWOP& rwop)
|
||||
{
|
||||
_set(Mix_LoadWAV_RW(rwop._get(),0));
|
||||
}
|
||||
|
||||
bool Sound::isReady() const
|
||||
{
|
||||
return (_get()!=nullptr);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <string>
|
||||
#include "Audio.h"
|
||||
#include "ErrorViewer.h"
|
||||
#include "RWOP.h"
|
||||
#include "__Plugin.h"
|
||||
#include "begin_code.h"
|
||||
class Sound
|
||||
|
@ -11,6 +12,7 @@ class Sound
|
|||
public:
|
||||
Sound() = default;
|
||||
Sound(const std::string& WAVFilename);
|
||||
Sound(const RWOP& rwop);
|
||||
bool isReady() const;
|
||||
void release();
|
||||
private:
|
||||
|
|
8
SDLWrapper/_MusicType.h
Normal file
8
SDLWrapper/_MusicType.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
#include "include.h"
|
||||
#include "begin_code.h"
|
||||
enum class MusicType
|
||||
{
|
||||
None,CMD,WAV,MOD,MID,OGG,MP3,MP3MAD,FLAC,MODPLUG
|
||||
};
|
||||
#include "end_code.h"
|
|
@ -282,5 +282,64 @@ int getIntFromMixInitFlag(MixInitFlag flag)
|
|||
}
|
||||
}
|
||||
|
||||
MusicType getMusicTypeFromMixMusicType(Mix_MusicType type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case MUS_NONE:
|
||||
return MusicType::None;
|
||||
case MUS_CMD:
|
||||
return MusicType::CMD;
|
||||
case MUS_WAV:
|
||||
return MusicType::WAV;
|
||||
case MUS_MOD:
|
||||
return MusicType::MOD;
|
||||
case MUS_MID:
|
||||
return MusicType::MID;
|
||||
case MUS_OGG:
|
||||
return MusicType::OGG;
|
||||
case MUS_MP3:
|
||||
return MusicType::MP3;
|
||||
case MUS_MP3_MAD:
|
||||
return MusicType::MP3MAD;
|
||||
case MUS_FLAC:
|
||||
return MusicType::FLAC;
|
||||
case MUS_MODPLUG:
|
||||
return MusicType::MODPLUG;
|
||||
default:
|
||||
return MusicType::None;
|
||||
}
|
||||
}
|
||||
|
||||
Mix_MusicType getMixMusicTypeFromMusicType(MusicType type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case MusicType::None:
|
||||
return MUS_NONE;
|
||||
case MusicType::CMD:
|
||||
return MUS_CMD;
|
||||
case MusicType::WAV:
|
||||
return MUS_WAV;
|
||||
case MusicType::MOD:
|
||||
return MUS_MOD;
|
||||
case MusicType::MID:
|
||||
return MUS_MID;
|
||||
case MusicType::OGG:
|
||||
return MUS_OGG;
|
||||
case MusicType::MP3:
|
||||
return MUS_MP3;
|
||||
case MusicType::MP3MAD:
|
||||
return MUS_MP3_MAD;
|
||||
case MusicType::FLAC:
|
||||
return MUS_FLAC;
|
||||
case MusicType::MODPLUG:
|
||||
return MUS_MODPLUG;
|
||||
default:
|
||||
return MUS_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}/// End of namespace _internal
|
||||
#include "end_code.h"
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "_SDLInitFlag.h"
|
||||
#include "_IMGInitFlag.h"
|
||||
#include "_MixInitFlag.h"
|
||||
#include "_MusicType.h"
|
||||
#include <vector>
|
||||
#include "begin_code.h"
|
||||
namespace _internal
|
||||
|
@ -24,5 +25,7 @@ SDL_RendererFlip getSDLRendererFlipFromFlipMode(FlipMode mode);
|
|||
Uint32 getUint32FromSDLInitFlag(SDLInitFlag flag);
|
||||
int getIntFromIMGInitFlag(IMGInitFlag flag);
|
||||
int getIntFromMixInitFlag(MixInitFlag flag);
|
||||
MusicType getMusicTypeFromMixMusicType(Mix_MusicType);
|
||||
Mix_MusicType getMixMusicTypeFromMusicType(MusicType);
|
||||
}/// End of namespace _internal
|
||||
#include "end_code.h"
|
||||
|
|
Loading…
Reference in New Issue
Block a user