]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Backend.cc
destroyed global classes; view hierarchy instead
[chaz/yoink] / src / Moof / Backend.cc
diff --git a/src/Moof/Backend.cc b/src/Moof/Backend.cc
new file mode 100644 (file)
index 0000000..95f4dc3
--- /dev/null
@@ -0,0 +1,94 @@
+
+/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
+**]  All rights reserved.
+*
+* vi:ts=4 sw=4 tw=75
+*
+* Distributable under the terms and conditions of the 2-clause BSD license;
+* see the file COPYING for a complete text of the license.
+*
+**************************************************************************/
+
+#include <SDL/SDL.h>
+#include "fastevents.h"
+
+#include "Backend.hh"
+#include "Error.hh"
+#include "Log.hh"
+
+
+namespace Mf {
+
+
+struct Impl
+{
+       static Error    error;
+       static int              retainCount;
+};
+
+Error  Impl::error(Error::UNINITIALIZED);
+int            Impl::retainCount = 0;
+
+
+Backend::Backend()
+{
+       if (Impl::retainCount++ == 0)
+       {
+#if defined(_WIN32)
+               if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
+#else
+               if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) != 0)
+#endif
+               {
+                       const char* error = SDL_GetError();
+                       Impl::error.init(Error::SDL_INIT, error);
+                       return; // fatal
+               }
+               else
+               {
+                       char name[128];
+                       SDL_VideoDriverName(name, sizeof(name));
+                       logInfo << "initialized SDL; using video driver `"
+                                       << name << "'" << std::endl;
+               }
+
+               if (FE_Init() != 0)
+               {
+                       const char* error = FE_GetError();
+                       Impl::error.init(Error::FASTEVENTS_INIT, error);
+                       return; // fatal
+               }
+
+               Impl::error.init(Error::NONE);
+       }
+}
+
+Backend::Backend(const Backend& backend)
+{
+       ++Impl::retainCount;
+}
+
+Backend::~Backend()
+{
+       if (--Impl::retainCount == 0)
+       {
+               FE_Quit();
+               SDL_Quit();
+
+               Impl::error.reset();
+       }
+}
+
+bool Backend::isInitialized()
+{
+       return Impl::error.code() == Error::NONE;
+}
+
+const Error& Backend::getError()
+{
+       return Impl::error;
+}
+
+
+} // namespace Mf
+
This page took 0.027652 seconds and 4 git commands to generate.