source: trunk/src/sample.cpp @ 1513

Last change on this file since 1513 was 1513, checked in by sam, 8 years ago

core: replace usage of sin() or std::sin() with lol::sin() where appropriate.

  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2012 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 <cstring>
18
19#if defined USE_SDL_MIXER
20#   include <SDL.h>
21#   include <SDL_mixer.h>
22#endif
23
24#include "core.h"
25
26using namespace std;
27
28namespace lol
29{
30
31/*
32 * Sample implementation class
33 */
34
35class SampleData
36{
37    friend class Sample;
38
39private:
40    char *name, *path;
41#if defined USE_SDL_MIXER
42    Mix_Chunk *chunk;
43#endif
44};
45
46/*
47 * Public Sample class
48 */
49
50Sample::Sample(char const *path)
51  : data(new SampleData())
52{
53    data->name = (char *)malloc(9 + strlen(path) + 1);
54    data->path = data->name + 9;
55    sprintf(data->name, "<sample> %s", path);
56
57#if defined USE_SDL_MIXER
58    data->chunk = Mix_LoadWAV(path);
59    if (!data->chunk)
60    {
61#if !LOL_RELEASE
62        Log::Error("could not load %s\n", path);
63#endif
64        SDL_Quit();
65        exit(1);
66    }
67#endif
68}
69
70Sample::~Sample()
71{
72#if defined USE_SDL_MIXER
73    Mix_FreeChunk(data->chunk);
74#endif
75    free(data->name);
76    delete data;
77}
78
79void Sample::TickGame(float seconds)
80{
81    Entity::TickGame(seconds);
82}
83
84char const *Sample::GetName()
85{
86    return data->name;
87}
88
89void Sample::Play()
90{
91#if defined USE_SDL_MIXER
92    Mix_PlayChannel(-1, data->chunk, 0);
93#endif
94}
95
96} /* namespace lol */
97
Note: See TracBrowser for help on using the repository browser.