]> Dogcows Code - chaz/yoink/blob - src/Moof/Backend.cc
95f4dc3415c777f1cd0ba676bf102edca26282af
[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 <SDL/SDL.h>
13 #include "fastevents.h"
14
15 #include "Backend.hh"
16 #include "Error.hh"
17 #include "Log.hh"
18
19
20 namespace Mf {
21
22
23 struct Impl
24 {
25 static Error error;
26 static int retainCount;
27 };
28
29 Error Impl::error(Error::UNINITIALIZED);
30 int Impl::retainCount = 0;
31
32
33 Backend::Backend()
34 {
35 if (Impl::retainCount++ == 0)
36 {
37 #if defined(_WIN32)
38 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
39 #else
40 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) != 0)
41 #endif
42 {
43 const char* error = SDL_GetError();
44 Impl::error.init(Error::SDL_INIT, error);
45 return; // fatal
46 }
47 else
48 {
49 char name[128];
50 SDL_VideoDriverName(name, sizeof(name));
51 logInfo << "initialized SDL; using video driver `"
52 << name << "'" << std::endl;
53 }
54
55 if (FE_Init() != 0)
56 {
57 const char* error = FE_GetError();
58 Impl::error.init(Error::FASTEVENTS_INIT, error);
59 return; // fatal
60 }
61
62 Impl::error.init(Error::NONE);
63 }
64 }
65
66 Backend::Backend(const Backend& backend)
67 {
68 ++Impl::retainCount;
69 }
70
71 Backend::~Backend()
72 {
73 if (--Impl::retainCount == 0)
74 {
75 FE_Quit();
76 SDL_Quit();
77
78 Impl::error.reset();
79 }
80 }
81
82 bool Backend::isInitialized()
83 {
84 return Impl::error.code() == Error::NONE;
85 }
86
87 const Error& Backend::getError()
88 {
89 return Impl::error;
90 }
91
92
93 } // namespace Mf
94
This page took 0.033941 seconds and 3 git commands to generate.