source: trunk/src/sample.cpp @ 259

Last change on this file since 259 was 259, checked in by sam, 10 years ago

Slightly change the ...Data initialisation in classes.

  • Property svn:keywords set to Id
File size: 1.0 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 <cmath>
17
18#include <SDL_mixer.h>
19
20#include "core.h"
21
22/*
23 * Sample implementation class
24 */
25
26class SampleData
27{
28    friend class Sample;
29
30private:
31    char *name;
32    Mix_Chunk *chunk;
33};
34
35/*
36 * Public Sample class
37 */
38
39Sample::Sample(char const *path)
40  : data(new SampleData())
41{
42    data->name = strdup(path);
43    data->chunk = Mix_LoadWAV(path);
44}
45
46Sample::~Sample()
47{
48    Mix_FreeChunk(data->chunk);
49    free(data->name);
50    delete data;
51}
52
53void Sample::TickGame(float deltams)
54{
55    Entity::TickGame(deltams);
56}
57
58char const *Sample::GetName()
59{
60    return data->name;
61}
62
63void Sample::Play()
64{
65    Mix_PlayChannel(-1, data->chunk, 0);
66}
67
Note: See TracBrowser for help on using the repository browser.