]> Dogcows Code - chaz/yoink/blob - src/moof/backend.cc
begin cleaning up resource management
[chaz/yoink] / src / moof / backend.cc
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #include <stdexcept>
13
14 #include <SDL/SDL.h>
15 #include "fastevents.h"
16
17 #include "backend.hh"
18 #include "log.hh"
19
20
21 namespace moof {
22
23
24 struct impl
25 {
26 static bool is_initialized;
27 static int retain_count;
28 };
29
30 bool impl::is_initialized = false;
31 int impl::retain_count = 0;
32
33
34 backend::backend()
35 {
36 if (impl::retain_count++ == 0)
37 {
38 #if defined(_WIN32)
39 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
40 #else
41 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) != 0)
42 #endif
43 {
44 throw std::runtime_error(SDL_GetError());
45 }
46 else
47 {
48 char name[128];
49 SDL_VideoDriverName(name, sizeof(name));
50 log_info << "initialized SDL; using video driver `"
51 << name << "'" << std::endl;
52 }
53
54 if (FE_Init() != 0)
55 {
56 throw std::runtime_error(FE_GetError());
57 }
58 }
59
60 impl::is_initialized = true;
61 }
62
63 backend::backend(const backend& backend)
64 {
65 ++impl::retain_count;
66 }
67
68 backend& backend::operator=(const backend& backend)
69 {
70 ++impl::retain_count;
71 return *this;
72 }
73
74 backend::~backend()
75 {
76 if (--impl::retain_count == 0)
77 {
78 FE_Quit();
79 SDL_Quit();
80
81 impl::is_initialized = false;
82 }
83 }
84
85 bool backend::is_initialized()
86 {
87 return impl::is_initialized;
88 }
89
90
91 } // namespace moof
92
This page took 0.033012 seconds and 4 git commands to generate.