source: trunk/src/sample.cpp @ 950

Last change on this file since 950 was 950, checked in by sam, 12 years ago

build: fix Win64 compilation with mingw64, using an updated SDL build.

  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdlib>
16#include <cstdio>
17#include <cmath>
18#include <cstring>
19
20#if defined USE_SDL_MIXER
21#   include <SDL.h>
22#   include <SDL_mixer.h>
23#endif
24
25#include "core.h"
26
27using namespace std;
28
29namespace lol
30{
31
32/*
33 * Sample implementation class
34 */
35
36class SampleData
37{
38    friend class Sample;
39
40private:
41    char *name, *path;
42#if defined USE_SDL_MIXER
43    Mix_Chunk *chunk;
44#endif
45};
46
47/*
48 * Public Sample class
49 */
50
51Sample::Sample(char const *path)
52  : data(new SampleData())
53{
54    data->name = (char *)malloc(9 + strlen(path) + 1);
55    data->path = data->name + 9;
56    sprintf(data->name, "<sample> %s", path);
57
58#if defined USE_SDL_MIXER
59    data->chunk = Mix_LoadWAV(path);
60    if (!data->chunk)
61    {
62#if !LOL_RELEASE
63        Log::Error("could not load %s\n", path);
64#endif
65        SDL_Quit();
66        exit(1);
67    }
68#endif
69}
70
71Sample::~Sample()
72{
73#if defined USE_SDL_MIXER
74    Mix_FreeChunk(data->chunk);
75#endif
76    free(data->name);
77    delete data;
78}
79
80void Sample::TickGame(float deltams)
81{
82    Entity::TickGame(deltams);
83}
84
85char const *Sample::GetName()
86{
87    return data->name;
88}
89
90void Sample::Play()
91{
92#if defined USE_SDL_MIXER
93    Mix_PlayChannel(-1, data->chunk, 0);
94#endif
95}
96
97} /* namespace lol */
98
Note: See TracBrowser for help on using the repository browser.