diff --git a/configure.ac b/configure.ac index 5791c8cb..920b5329 100644 --- a/configure.ac +++ b/configure.ac @@ -48,23 +48,24 @@ CXXFLAGS="${CXXFLAGS} -Wall -Wextra -Wpointer-arith -Wcast-align -Wcast-qual -Ws AC_CHECK_LIB(m, sin, MATH_LIBS="${MATH_LIBS} -lm") # Use SDL? -ac_cv_my_have_sdl="no" +ac_cv_my_have_sdl="yes" save_CPPFLAGS="${CPPFLAGS}" AC_PATH_PROG(SDL_CONFIG, sdl-config, no) if test "${SDL_CONFIG}" != "no"; then CPPFLAGS="${CPPFLAGS} `sdl-config --cflags`" fi AC_CHECK_HEADERS(SDL_image.h, - [ac_cv_my_have_sdl="yes"], - [ac_cv_my_have_sdl="no"]) + [:],[ac_cv_my_have_sdl="no"]) +AC_CHECK_HEADERS(SDL_mixer.h, + [:],[ac_cv_my_have_sdl="no"]) CPPFLAGS="${save_CPPFLAGS}" if test "${ac_cv_my_have_sdl}" != "no"; then AC_DEFINE(USE_SDL, 1, Define to 1 to use SDL_image) fi AM_CONDITIONAL(USE_SDL, test "${ac_cv_my_have_sdl}" = "yes") -if test "${ac_cv_my_have_sdl}" = "no" -a "${ac_cv_my_have_imlib2}" = "no"; then - AC_MSG_ERROR([[cannot find SDL_Image or GTK+, please install one of them]]) +if test "${ac_cv_my_have_sdl}" = "no"; then + AC_MSG_ERROR([[One of SDL, SDL_Image or SDL_Mixer not found]]) fi @@ -88,7 +89,7 @@ AM_CONDITIONAL(USE_PIPI, test "${ac_cv_my_have_pipi}" != "no") # How to use the Lol Engine inside this tree LOL_CFLAGS="-I \$(top_srcdir)/src `pkg-config --cflags sdl gl SDL_image`" -LOL_LIBS="`pkg-config --libs sdl gl SDL_image`" +LOL_LIBS="`pkg-config --libs sdl gl SDL_image` -lSDL_mixer" if test "${enable_release}" = "yes"; then AC_DEFINE(FINAL_RELEASE, 1, Define to 1 to activate final release) diff --git a/src/Makefile.am b/src/Makefile.am index 44895639..d72a6630 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,7 +2,7 @@ noinst_LIBRARIES = liblol.a liblol_a_SOURCES = \ - core.h matrix.h tiler.cpp tiler.h dict.cpp dict.h \ + core.h matrix.h tiler.cpp tiler.h dict.cpp dict.h audio.cpp audio.h \ scene.cpp scene.h font.cpp font.h layer.cpp layer.h map.cpp map.h \ entity.cpp entity.h ticker.cpp ticker.h tileset.cpp tileset.h \ forge.cpp forge.h video.cpp video.h timer.cpp timer.h bitfield.h \ diff --git a/src/audio.cpp b/src/audio.cpp new file mode 100644 index 00000000..15c194e6 --- /dev/null +++ b/src/audio.cpp @@ -0,0 +1,29 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include + +#include "core.h" + +/* + * Public Audio class + */ + +void Audio::Setup(int channels) +{ + Mix_OpenAudio(22050, AUDIO_S16, channels, 4096); +} + diff --git a/src/audio.h b/src/audio.h new file mode 100644 index 00000000..de5b0ba1 --- /dev/null +++ b/src/audio.h @@ -0,0 +1,29 @@ +// +// Lol Engine +// +// Copyright: (c) 2010-2011 Sam Hocevar +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://sam.zoy.org/projects/COPYING.WTFPL for more details. +// + +// +// The Audio interface +// ------------------- +// Helper functions to set up the audio device. +// + +#if !defined __DH_AUDIO_H__ +#define __DH_AUDIO_H__ + +#include + +class Audio +{ +public: + static void Setup(int channels); +}; + +#endif // __DH_AUDIO_H__ + diff --git a/src/core.h b/src/core.h index 7845eb15..903057cc 100644 --- a/src/core.h +++ b/src/core.h @@ -22,6 +22,7 @@ // Static classes #include "video.h" +#include "audio.h" #include "scene.h" #include "input.h" #include "profiler.h" diff --git a/src/sample.cpp b/src/sample.cpp index 1b7380e8..20feb8c7 100644 --- a/src/sample.cpp +++ b/src/sample.cpp @@ -15,7 +15,7 @@ #include #include -#include +#include #include "core.h" @@ -29,6 +29,7 @@ class SampleData private: char *name; + Mix_Chunk *chunk; }; /* @@ -39,10 +40,12 @@ Sample::Sample(char const *path) { data = new SampleData(); data->name = strdup(path); + data->chunk = Mix_LoadWAV(path); } Sample::~Sample() { + Mix_FreeChunk(data->chunk); free(data->name); delete data; } @@ -59,5 +62,6 @@ char const *Sample::GetName() void Sample::Play() { + Mix_PlayChannel(-1, data->chunk, 0); } diff --git a/src/sampler.cpp b/src/sampler.cpp index a6d5a005..a7494de3 100644 --- a/src/sampler.cpp +++ b/src/sampler.cpp @@ -53,7 +53,7 @@ void Sampler::Deregister(int id) void Sampler::PlaySample(int id) { - Sample *sample = (Sample *)data->samples.GetEntity(id); + Sample *sample = (Sample *)data->samples.GetEntity(id - 1); sample->Play(); } diff --git a/win32/deushax.vcxproj b/win32/deushax.vcxproj index 56ed6fa2..85622117 100644 --- a/win32/deushax.vcxproj +++ b/win32/deushax.vcxproj @@ -13,6 +13,7 @@ + @@ -43,6 +44,7 @@ + diff --git a/win32/monsterz.vcxproj b/win32/monsterz.vcxproj index 30cdaf68..95ff7635 100644 --- a/win32/monsterz.vcxproj +++ b/win32/monsterz.vcxproj @@ -14,6 +14,7 @@ + @@ -45,6 +46,7 @@ +