Browse Source

Add preliminary support for sound samples. Implement click.

legacy
Sam Hocevar sam 14 years ago
parent
commit
640735731a
9 changed files with 77 additions and 9 deletions
  1. +7
    -6
      configure.ac
  2. +1
    -1
      src/Makefile.am
  3. +29
    -0
      src/audio.cpp
  4. +29
    -0
      src/audio.h
  5. +1
    -0
      src/core.h
  6. +5
    -1
      src/sample.cpp
  7. +1
    -1
      src/sampler.cpp
  8. +2
    -0
      win32/deushax.vcxproj
  9. +2
    -0
      win32/monsterz.vcxproj

+ 7
- 6
configure.ac View File

@@ -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)


+ 1
- 1
src/Makefile.am View File

@@ -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 \


+ 29
- 0
src/audio.cpp View File

@@ -0,0 +1,29 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// 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 <cmath>

#include <SDL_mixer.h>

#include "core.h"

/*
* Public Audio class
*/

void Audio::Setup(int channels)
{
Mix_OpenAudio(22050, AUDIO_S16, channels, 4096);
}


+ 29
- 0
src/audio.h View File

@@ -0,0 +1,29 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// 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 <stdint.h>

class Audio
{
public:
static void Setup(int channels);
};

#endif // __DH_AUDIO_H__


+ 1
- 0
src/core.h View File

@@ -22,6 +22,7 @@

// Static classes
#include "video.h"
#include "audio.h"
#include "scene.h"
#include "input.h"
#include "profiler.h"


+ 5
- 1
src/sample.cpp View File

@@ -15,7 +15,7 @@
#include <cstdlib>
#include <cmath>

#include <SDL.h>
#include <SDL_mixer.h>

#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);
}


+ 1
- 1
src/sampler.cpp View File

@@ -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();
}


+ 2
- 0
win32/deushax.vcxproj View File

@@ -13,6 +13,7 @@
<ItemGroup>
<ClInclude Include="..\deushax\debugsprite.h" />
<ClInclude Include="..\deushax\game.h" />
<ClInclude Include="..\src\audio.h" />
<ClInclude Include="..\src\bitfield.h" />
<ClInclude Include="..\src\core.h" />
<ClInclude Include="..\src\debugfps.h" />
@@ -43,6 +44,7 @@
<ClCompile Include="..\deushax\debugsprite.cpp" />
<ClCompile Include="..\deushax\deushax.cpp" />
<ClCompile Include="..\deushax\game.cpp" />
<ClCompile Include="..\src\audio.cpp" />
<ClCompile Include="..\src\debugfps.cpp" />
<ClCompile Include="..\src\debugrecord.cpp" />
<ClCompile Include="..\src\debugsphere.cpp" />


+ 2
- 0
win32/monsterz.vcxproj View File

@@ -14,6 +14,7 @@
<ClInclude Include="..\monsterz\board.h" />
<ClInclude Include="..\monsterz\game.h" />
<ClInclude Include="..\monsterz\piece.h" />
<ClInclude Include="..\src\audio.h" />
<ClInclude Include="..\src\bitfield.h" />
<ClInclude Include="..\src\core.h" />
<ClInclude Include="..\src\debugfps.h" />
@@ -45,6 +46,7 @@
<ClCompile Include="..\monsterz\game.cpp" />
<ClCompile Include="..\monsterz\monsterz.cpp" />
<ClCompile Include="..\monsterz\piece.cpp" />
<ClCompile Include="..\src\audio.cpp" />
<ClCompile Include="..\src\debugfps.cpp" />
<ClCompile Include="..\src\debugrecord.cpp" />
<ClCompile Include="..\src\debugsphere.cpp" />


Loading…
Cancel
Save