Commit 47a5c52f authored by Ilya Prokhorov's avatar Ilya Prokhorov

FlameSteelBattleHorn refactored as shared library

parent 864d7a73
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
CMakeFiles
cmake_install.cmake
CMakeCache.txt
install_manifest.txt
libFlameSteelBattleHorn.so
Makefile
cmake_minimum_required(VERSION 3.5)
project (FlameSteelEngineBattleHorn)
set(CMAKE_BUILD_TYPE Release)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src include /usr/local/include/FlameSteelFramework)
file(GLOB_RECURSE SOURCE_FILES
"src/FlameSteelBattleHorn/*.cpp"
)
add_library(FlameSteelBattleHorn SHARED ${SOURCE_FILES})
install(DIRECTORY "${CMAKE_SOURCE_DIR}/src/FlameSteelBattleHorn"
DESTINATION include/FlameSteelFramework
FILES_MATCHING
PATTERN "*.h"
)
install(TARGETS FlameSteelBattleHorn DESTINATION lib)
#include <FlameSteelBattleHorn/Music.h>
#include <iostream>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
using namespace FlameSteelBattleHorn;
using namespace FlameSteelCore::Utils;
Music::Music(shared_ptr<string> path) {
#ifndef __EMSCRIPTEN__
music = Mix_LoadMUS(path->c_str());
if (music == nullptr) {
//cout << "Can't load music " << Mix_GetError() << endl;
throwRuntimeException(string("Can't load music"));
}
#else
this->path = path;
#endif
}
void Music::play() {
#ifndef __EMSCRIPTEN__
if (music) {
if (Mix_PlayMusic(music, -1) == -1) {
throwRuntimeException(string("Can't play music"));
}
}
else {
throwRuntimeException(string("Can't play music - music is null"));
}
#else
if (path.get() != nullptr) {
//cout << "play sound through javascript" << endl;
EM_ASM_({
var audioPath = UTF8ToString($0);
audioPath += ".mp3";
FlameSteelBattleHorn_music_global = new Audio(audioPath);
FlameSteelBattleHorn_music_global.loop = true;
FlameSteelBattleHorn_music_global.play();
}, path->c_str());
}
else {
//cout << "can't play sound - path is null" << endl;
}
#endif
}
void Music::stop() {
#ifndef __EMSCRIPTEN__
#else
if (path.get() != nullptr) {
//cout << "play sound through javascript" << endl;
EM_ASM({
if (FlameSteelBattleHorn_music_global != null) {
FlameSteelBattleHorn_music_global.pause();
}
});
}
else {
//cout << "can't play sound - path is null" << endl;
}
#endif
}
Music::~Music() {
#ifndef __EMSCRIPTEN__
if (music) {
Mix_FreeMusic(music);
}
#endif
}
\ No newline at end of file
{
"name": "FlameSteelBattleHorn"
}
#include <FlameSteelBattleHorn/Sound.h>
#include <iostream>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
using namespace FlameSteelCore::Utils;
using namespace FlameSteelBattleHorn;
void Sound::initializeSoundSystem() {
#ifndef __EMSCRIPTEN__
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1 ) {
throwRuntimeException(string("Can't initialize sound system"));
}
int flags = MIX_INIT_OGG;
int initted = Mix_Init(flags);
//cout << flags << endl;
//cout << initted << endl;
if ((initted & flags) != flags) {
printf("Mix_Init: Failed to init required ogg and mod support!\n");
printf("Mix_Init: %s\n", Mix_GetError());
throwRuntimeException(string("Can't initialize SDL_Mixer properly"));
}
else {
//cout << "SDL_MIXER initialized correctly" << endl;
}
#endif
}
Sound::Sound(shared_ptr<string> path) {
#ifndef __EMSCRIPTEN__
chunk = Mix_LoadWAV(path->c_str());
if (chunk == nullptr) {
//cout << "Can't load sound " << Mix_GetError() << endl;
throwRuntimeException(string("Can't load sound"));
}
#else
this->path = path;
#endif
}
void Sound::play() {
#ifndef __EMSCRIPTEN__
if (chunk) {
if (Mix_PlayChannel(-1, chunk, 0)==-1) {
printf("Mix_PlayChannel: %s\n",Mix_GetError());
}
}
#else
if (path.get() != nullptr) {
//cout << "play sound through javascript" << endl;
EM_ASM_({
var audioPath = UTF8ToString($0);
audioPath += ".mp3";
var audio = new Audio(audioPath);
audio.play();
}, path->c_str());
}
else {
//cout << "can't play sound - path is null" << endl;
}
#endif
}
void Sound::stop() {
}
Sound::~Sound() {
#ifndef __EMSCRIPTEN__
if (chunk) {
Mix_FreeChunk(chunk);
}
#endif
}
\ No newline at end of file
#include <FlameSteelBattleHorn/Music.h>
#include <iostream>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
using namespace FlameSteelBattleHorn;
using namespace FlameSteelCore::Utils;
Music::Music(shared_ptr<string> path)
{
#ifndef __EMSCRIPTEN__
music = Mix_LoadMUS(path->c_str());
if (music == nullptr)
{
//cout << "Can't load music " << Mix_GetError() << endl;
throwRuntimeException(string("Can't load music"));
}
#else
this->path = path;
#endif
}
void Music::play()
{
#ifndef __EMSCRIPTEN__
if (music)
{
if (Mix_PlayMusic(music, -1) == -1)
{
throwRuntimeException(string("Can't play music"));
}
}
else
{
throwRuntimeException(string("Can't play music - music is null"));
}
#else
if (path.get() != nullptr)
{
//cout << "play sound through javascript" << endl;
EM_ASM_(
{
var audioPath = UTF8ToString($0);
audioPath += ".mp3";
FlameSteelBattleHorn_music_global = new Audio(audioPath);
FlameSteelBattleHorn_music_global.loop = true;
FlameSteelBattleHorn_music_global.play();
}, path->c_str());
}
else
{
//cout << "can't play sound - path is null" << endl;
}
#endif
}
void Music::stop()
{
#ifndef __EMSCRIPTEN__
#else
if (path.get() != nullptr)
{
//cout << "play sound through javascript" << endl;
EM_ASM(
{
if (FlameSteelBattleHorn_music_global != null)
{
FlameSteelBattleHorn_music_global.pause();
}
});
}
else
{
//cout << "can't play sound - path is null" << endl;
}
#endif
}
Music::~Music()
{
#ifndef __EMSCRIPTEN__
if (music)
{
Mix_FreeMusic(music);
}
#endif
}
\ No newline at end of file
......@@ -12,21 +12,23 @@
using namespace std;
namespace FlameSteelBattleHorn {
namespace FlameSteelBattleHorn
{
class Music: public Playable {
class Music: public Playable
{
public:
Music(shared_ptr<string> path);
void play();
void stop();
virtual ~Music();
Music(shared_ptr<string> path);
void play();
void stop();
virtual ~Music();
private:
#ifndef __EMSCRIPTEN__
Mix_Music *music = nullptr;
Mix_Music *music = nullptr;
#else
shared_ptr<string> path;
shared_ptr<string> path;
#endif
};
......
......@@ -7,12 +7,20 @@
using namespace std;
using namespace FlameSteelCore::Utils;
namespace FlameSteelBattleHorn {
class Playable {
namespace FlameSteelBattleHorn
{
class Playable
{
public:
virtual void play() { throwRuntimeException(string("Call to not overriden method play, playable abstract class")); };
virtual void stop() { throwRuntimeException(string("Call to not overriden method stop, playable abstract class")); };
virtual void play()
{
throwRuntimeException(string("Call to not overriden method play, playable abstract class"));
};
virtual void stop()
{
throwRuntimeException(string("Call to not overriden method stop, playable abstract class"));
};
};
};
......
#include <FlameSteelBattleHorn/Sound.h>
#include <iostream>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif
using namespace FlameSteelCore::Utils;
using namespace FlameSteelBattleHorn;
void Sound::initializeSoundSystem()
{
#ifndef __EMSCRIPTEN__
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1 )
{
throwRuntimeException(string("Can't initialize sound system"));
}
int flags = MIX_INIT_OGG;
int initted = Mix_Init(flags);
//cout << flags << endl;
//cout << initted << endl;
if ((initted & flags) != flags)
{
printf("Mix_Init: Failed to init required ogg and mod support!\n");
printf("Mix_Init: %s\n", Mix_GetError());
throwRuntimeException(string("Can't initialize SDL_Mixer properly"));
}
else
{
//cout << "SDL_MIXER initialized correctly" << endl;
}
#endif
}
Sound::Sound(shared_ptr<string> path)
{
#ifndef __EMSCRIPTEN__
chunk = Mix_LoadWAV(path->c_str());
if (chunk == nullptr)
{
//cout << "Can't load sound " << Mix_GetError() << endl;
throwRuntimeException(string("Can't load sound"));
}
#else
this->path = path;
#endif
}
void Sound::play()
{
#ifndef __EMSCRIPTEN__
if (chunk)
{
if (Mix_PlayChannel(-1, chunk, 0)==-1)
{
printf("Mix_PlayChannel: %s\n",Mix_GetError());
}
}
#else
if (path.get() != nullptr)
{
//cout << "play sound through javascript" << endl;
EM_ASM_(
{
var audioPath = UTF8ToString($0);
audioPath += ".mp3";
var audio = new Audio(audioPath);
audio.play();
}, path->c_str());
}
else
{
//cout << "can't play sound - path is null" << endl;
}
#endif
}
void Sound::stop()
{
}
Sound::~Sound()
{
#ifndef __EMSCRIPTEN__
if (chunk)
{
Mix_FreeChunk(chunk);
}
#endif
}
\ No newline at end of file
......@@ -13,22 +13,24 @@
using namespace std;
using namespace FlameSteelBattleHorn;
namespace FlameSteelBattleHorn {
namespace FlameSteelBattleHorn
{
class Sound: public Playable {
class Sound: public Playable
{
public:
static void initializeSoundSystem();
Sound(shared_ptr<string> path);
void play();
void stop();
virtual ~Sound();
static void initializeSoundSystem();
Sound(shared_ptr<string> path);
void play();
void stop();
virtual ~Sound();
private:
#ifndef __EMSCRIPTEN__
Mix_Chunk *chunk = nullptr;
Mix_Chunk *chunk = nullptr;
#else
shared_ptr<string> path;
shared_ptr<string> path;
#endif
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment