source: trunk/src/sample.cpp @ 658

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

Get rid of the SHADER_CRAP macro and use LOL_EXPERIMENTAL instead,
together with the --enable-experimental flag. Use LOL_DEBUG and
LOL_RELEASE instead of the previous values.

  • Property svn:keywords set to Id
File size: 1.3 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.h>
19#include <SDL_mixer.h>
20
21#include "core.h"
22
23/*
24 * Sample implementation class
25 */
26
27class SampleData
28{
29    friend class Sample;
30
31private:
32    char *name, *path;
33    Mix_Chunk *chunk;
34};
35
36/*
37 * Public Sample class
38 */
39
40Sample::Sample(char const *path)
41  : data(new SampleData())
42{
43    data->name = (char *)malloc(9 + strlen(path) + 1);
44    data->path = data->name + 9;
45    sprintf(data->name, "<sample> %s", path);
46
47    data->chunk = Mix_LoadWAV(path);
48    if (!data->chunk)
49    {
50#if !LOL_RELEASE
51        fprintf(stderr, "ERROR: could not load %s\n", path);
52#endif
53        SDL_Quit();
54        exit(1);
55    }
56}
57
58Sample::~Sample()
59{
60    Mix_FreeChunk(data->chunk);
61    free(data->name);
62    delete data;
63}
64
65void Sample::TickGame(float deltams)
66{
67    Entity::TickGame(deltams);
68}
69
70char const *Sample::GetName()
71{
72    return data->name;
73}
74
75void Sample::Play()
76{
77    Mix_PlayChannel(-1, data->chunk, 0);
78}
79
Note: See TracBrowser for help on using the repository browser.