X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2FMoof%2FBackend.cc;fp=src%2FMoof%2FBackend.cc;h=95f4dc3415c777f1cd0ba676bf102edca26282af;hb=e0c0a3b5e7337cde55e520801d2e59e03dc97d9c;hp=0000000000000000000000000000000000000000;hpb=ed5fcf5f1357fc42749408f705e9ec55531ff006;p=chaz%2Fyoink diff --git a/src/Moof/Backend.cc b/src/Moof/Backend.cc new file mode 100644 index 0000000..95f4dc3 --- /dev/null +++ b/src/Moof/Backend.cc @@ -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 +#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 +