]> Dogcows Code - chaz/yoink/blob - src/moof/backend.cc
2dd199d216c846d11b0517f87c4e9a9fcc762d46
[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 log_info("shutting down SDL...");
79 FE_Quit();
80 SDL_Quit();
81
82 impl::is_initialized = false;
83 }
84 }
85
86 bool backend::is_initialized()
87 {
88 return impl::is_initialized;
89 }
90
91
92 } // namespace moof
93
This page took 0.038739 seconds and 3 git commands to generate.