]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Engine.cc
extreme refactoring
[chaz/yoink] / src / Moof / Engine.cc
similarity index 61%
rename from src/engine.cc
rename to src/Moof/Engine.cc
index 7284799343a1f144d136ac65705f94c0ff54ad67..bcc336c1244f1f8b0a8ed041507c4b5f3e0f7834 100644 (file)
 
 *******************************************************************************/
 
-#include <iostream>
 #include <cstdlib>                     // exit
-#include <string>
+#include <iostream>
 #include <stdexcept>
+#include <string>
 
 #include <SDL/SDL.h>
 #include "fastevents.h"
 
-#include "random.hh"
-#include "timer.hh"
-#include "video.hh"
-#include "settings.hh"
-#include "dispatcher.hh"
-
-#include "engine.hh"
+#include "Dispatcher.hh"
+#include "Engine.hh"
+#include "Random.hh"
+#include "Settings.hh"
+#include "Timer.hh"
+#include "Video.hh"
 
 
-namespace dc {
+namespace Mf {
 
 
-class engine::engine_impl
+class Engine::EngineImpl
 {
 public:
-       engine_impl(const std::string& name, int argc, char* argv[],
-                       const std::string& configFile, engine* outer) :
-               config(argc, argv),
+       EngineImpl(const std::string& name, int argc, char* argv[],
+                       const std::string& configFile, Engine* outer) :
+               settings(argc, argv),
                interface(outer)
        {
                if (SDL_Init(SDL_INIT_EVERYTHING | SDL_INIT_EVENTTHREAD) != 0)
@@ -63,29 +62,29 @@ public:
                        throw std::runtime_error(FE_GetError());
                }
 
-               rng::seed();
+               setSeed();
 
-               config.loadFromFile(configFile);
+               settings.loadFromFile(configFile);
 
-               screen = video_ptr(new video(name));
-               screen->makeActive();
+               video = VideoPtr(new Video(name));
+               video->makeActive();
 
                double ts = 0.01;
-               config.get("engine.timestep", ts);
-               timestep = scalar(ts);
+               settings.get("engine.timestep", ts);
+               timestep = Scalar(ts);
 
-               long maxfps = 40;
-               config.getNumber("video.maxfps", maxfps);
-               drawrate = 1.0 / scalar(maxfps);
+               long maxFps = 40;
+               settings.getNumber("video.maxfps", maxFps);
+               drawRate = 1.0 / Scalar(maxFps);
 
-               printfps = false;
-               config.get("video.printfps", printfps);
+               printFps = false;
+               settings.get("video.printfps", printFps);
        }
 
-       ~engine_impl()
+       ~EngineImpl()
        {
                // The video object must be destroyed before we can shutdown SDL.
-               screen.reset();
+               video.reset();
 
                FE_Quit();
                SDL_Quit();
@@ -101,15 +100,15 @@ public:
 
        int run()
        {
-               scalar ticksNow = ticks();
+               Scalar ticksNow = getTicks();
 
-               scalar nextStep = ticksNow;
-               scalar nextDraw = ticksNow;
-               scalar nextFPSUpdate = ticksNow + 1.0;
+               Scalar nextStep = ticksNow;
+               Scalar nextDraw = ticksNow;
+               Scalar nextFpsUpdate = ticksNow + 1.0;
 
-               scalar totalTime = 0.0;
-               scalar deltaTime = 0.0;
-               scalar accumulator = timestep;
+               Scalar totalTime = 0.0;
+               Scalar deltaTime = 0.0;
+               Scalar accumulator = timestep;
 
                fps = 0;
                int frameAccum = 0;
@@ -117,7 +116,7 @@ public:
                running = true;
                do
                {
-                       scalar newTicks = ticks();
+                       Scalar newTicks = getTicks();
                        deltaTime = newTicks - ticksNow;
                        ticksNow = newTicks;
 
@@ -139,31 +138,31 @@ public:
                        {
                                frameAccum++;
 
-                               if (ticksNow >= nextFPSUpdate) // determine the actual fps
+                               if (ticksNow >= nextFpsUpdate) // determine the actual fps
                                {
                                        fps = frameAccum;
                                        frameAccum = 0;
 
-                                       nextFPSUpdate += 1.0;
-                                       if (ticksNow >= nextFPSUpdate)
+                                       nextFpsUpdate += 1.0;
+                                       if (ticksNow >= nextFpsUpdate)
                                        {
-                                               nextFPSUpdate = ticksNow + 1.0;
+                                               nextFpsUpdate = ticksNow + 1.0;
                                        }
 
-                                       if (printfps)
+                                       if (printFps)
                                        {
                                                std::cout << "FPS: " << fps << std::endl;
                                        }
                                }
 
                                interface->draw(accumulator / timestep);
-                               screen->swap();
+                               video->swap();
 
-                               nextDraw += drawrate;
+                               nextDraw += drawRate;
                                if (ticksNow >= nextDraw)
                                {
                                        // we missed some scheduled draws, so reset the schedule
-                                       nextDraw = ticksNow + drawrate;
+                                       nextDraw = ticksNow + drawRate;
                                }
                        }
 
@@ -178,14 +177,14 @@ public:
 
        void dispatchEvents()
        {
-               SDL_Event e;
+               SDL_Event event;
 
-               while (FE_PollEvent(&e) == 1)
+               while (FE_PollEvent(&event) == 1)
                {
-                       switch (e.type)
+                       switch (event.type)
                        {
                                case SDL_KEYDOWN:
-                                       if (e.key.keysym.sym == SDLK_ESCAPE &&
+                                       if (event.key.keysym.sym == SDLK_ESCAPE &&
                                                        (SDL_GetModState() & KMOD_CTRL) )
                                        {
                                           exit(0);
@@ -193,87 +192,87 @@ public:
                                        break;
 
                                case SDL_VIDEORESIZE:
-                                       screen->resize(e.resize.w, e.resize.h);
+                                       video->resize(event.resize.w, event.resize.h);
                                        break;
                        }
 
-                       interface->handleEvent(e);
+                       interface->handleEvent(event);
                }
        }
 
 
-       settings config;
-       dispatcher relay;
-       video_ptr screen;
+       Settings        settings;
+       Dispatcher      dispatcher;
+       VideoPtr        video;
 
-       bool running;
+       bool            running;
 
-       scalar timestep;
-       scalar drawrate;
+       Scalar          timestep;
+       Scalar          drawRate;
 
-       long fps;
-       bool printfps;
+       long            fps;
+       bool            printFps;
 
-       engine* interface;
+       Engine*         interface;
 };
 
 
-engine::engine(const std::string& name, int argc, char* argv[],
+Engine::Engine(const std::string& name, int argc, char* argv[],
                const std::string& configFile) :
-       impl(new engine::engine_impl(name, argc, argv, configFile, this)) {}
+       impl_(new Engine::EngineImpl(name, argc, argv, configFile, this)) {}
 
-engine::~engine() {}
+Engine::~Engine() {}
 
 
-int engine::run()
+int Engine::run()
 {
-       return impl->run();
+       return impl_->run();
 }
 
-void engine::stop()
+void Engine::stop()
 {
-       impl->running = false;
+       impl_->running = false;
 }
 
 
-void engine::setTimestep(scalar ts)
+void Engine::setTimestep(Scalar ts)
 {
-       impl->timestep = ts;
+       impl_->timestep = ts;
 }
 
-scalar engine::getTimestep()
+Scalar Engine::getTimestep()
 {
-       return impl->timestep;
+       return impl_->timestep;
 }
 
-void engine::setMaxFPS(long maxfps)
+void Engine::setMaxFrameRate(long maxFps)
 {
-       impl->drawrate = 1.0 / scalar(maxfps);
+       impl_->drawRate = 1.0 / Scalar(maxFps);
 }
 
-long engine::getMaxFPS()
+long Engine::getMaxFrameRate()
 {
-       return long(1.0 / impl->drawrate);
+       return long(1.0 / impl_->drawRate);
 }
 
 
-video& engine::getVideo()
+Video& Engine::getVideo()
 {
-       return *impl->screen;
+       return *impl_->video;
 }
 
-long engine::getFPS()
+long Engine::getFrameRate()
 {
-       return impl->fps;
+       return impl_->fps;
 }
 
 
-void engine::update(scalar t, scalar dt) {}
-void engine::draw(scalar alpha) {}
-void engine::handleEvent(const SDL_Event& e) {}
+void Engine::update(Scalar t, Scalar dt) {}
+void Engine::draw(Scalar alpha) {}
+void Engine::handleEvent(const Event& event) {}
 
 
-} // namespace dc
+} // namespace Mf
 
 /** vim: set ts=4 sw=4 tw=80: *************************************************/
 
This page took 0.031385 seconds and 4 git commands to generate.