source: trunk/src/sample.cpp @ 280

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

Print error reports before panicking when asset loads fail.

  • Property svn:keywords set to Id
File size: 1.2 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;
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 = strdup(path);
44    data->chunk = Mix_LoadWAV(path);
45    if (!data->chunk)
46    {
47#if !FINAL_RELEASE
48        fprintf(stderr, "ERROR: could not load %s\n", path);
49#endif
50        SDL_Quit();
51        exit(1);
52    }
53}
54
55Sample::~Sample()
56{
57    Mix_FreeChunk(data->chunk);
58    free(data->name);
59    delete data;
60}
61
62void Sample::TickGame(float deltams)
63{
64    Entity::TickGame(deltams);
65}
66
67char const *Sample::GetName()
68{
69    return data->name;
70}
71
72void Sample::Play()
73{
74    Mix_PlayChannel(-1, data->chunk, 0);
75}
76
Note: See TracBrowser for help on using the repository browser.