]> Dogcows Code - chaz/yoink/blobdiff - src/moof/backend.cc
the massive refactoring effort
[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..6dacfa1
--- /dev/null
@@ -0,0 +1,92 @@
+
+/*]  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 <stdexcept>
+
+#include <SDL/SDL.h>
+#include "fastevents.h"
+
+#include "backend.hh"
+#include "log.hh"
+
+
+namespace moof {
+
+
+struct impl
+{
+       static bool             is_initialized;
+       static int              retain_count;
+};
+
+bool   impl::is_initialized = false;
+int            impl::retain_count = 0;
+
+
+backend::backend()
+{
+       if (impl::retain_count++ == 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
+               {
+                       throw std::runtime_error(SDL_GetError());
+               }
+               else
+               {
+                       char name[128];
+                       SDL_VideoDriverName(name, sizeof(name));
+                       log_info << "initialized SDL; using video driver `"
+                                       << name << "'" << std::endl;
+               }
+
+               if (FE_Init() != 0)
+               {
+                       throw std::runtime_error(FE_GetError());
+               }
+       }
+
+       impl::is_initialized = true;
+}
+
+backend::backend(const backend& backend)
+{
+       ++impl::retain_count;
+}
+
+backend& backend::operator=(const backend& backend)
+{
+       ++impl::retain_count;
+       return *this;
+}
+
+backend::~backend()
+{
+       if (--impl::retain_count == 0)
+       {
+               FE_Quit();
+               SDL_Quit();
+
+               impl::is_initialized = false;
+       }
+}
+
+bool backend::is_initialized()
+{
+       return impl::is_initialized;
+}
+
+
+} // namespace moof
+
This page took 0.02621 seconds and 4 git commands to generate.