diff --git a/.gitignore b/.gitignore index 05511a424..322375a54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +screenshot*.png *.o *~ data diff --git a/game/mwinput/inputmanager.hpp b/game/mwinput/inputmanager.hpp index 94b0c915f..8fa8c6ad2 100644 --- a/game/mwinput/inputmanager.hpp +++ b/game/mwinput/inputmanager.hpp @@ -6,6 +6,7 @@ #include "input/poller.hpp" #include "boost/bind.hpp" #include "game/mwrender/playerpos.hpp" +#include "platform/strings.h" namespace MWInput { @@ -13,6 +14,8 @@ namespace MWInput { A_Quit, // Exit the program + A_Screenshot, // Take a screenshot + A_MoveLeft, // Move player left / right A_MoveRight, A_MoveUp, // Move up / down @@ -29,27 +32,45 @@ namespace MWInput // Note: the order here is important. The OISManager must be // initialized before poller and listener. Input::Dispatcher disp; + Render::OgreRenderer &ogre; Input::OISManager input; Input::Poller poller; Input::InputListener listener; MWRender::PlayerPos &player; + // Count screenshots. TODO: We should move this functionality to + // OgreRender or somewhere else. + int shotCount; + + // Write screenshot to file. + void screenshot() + { + // TODO: add persistent counting so we don't overwrite shots + // from previous runs. + char buf[50]; + snprintf(buf,50, "screenshot%d.png", shotCount++); + ogre.screenshot(buf); + } + public: - MWInputManager(Render::OgreRenderer &ogre, + MWInputManager(Render::OgreRenderer &_ogre, MWRender::PlayerPos &_player) : disp(A_LAST), - input(ogre), + ogre(_ogre), + input(_ogre), poller(input), - listener(ogre, input, disp), - player(_player) + listener(_ogre, input, disp), + player(_player), + shotCount(0) { using namespace Input; using namespace OIS; // Bind MW-specific functions - disp.funcs.bind(A_Quit, - boost::bind(&InputListener::exitNow, &listener), + disp.funcs.bind(A_Quit, boost::bind(&InputListener::exitNow, &listener), "Quit program"); + disp.funcs.bind(A_Screenshot, boost::bind(&MWInputManager::screenshot, this), + "Screenshot"); // Add ourselves as a frame listener, to catch movement keys ogre.getRoot()->addFrameListener(this); @@ -60,6 +81,7 @@ namespace MWInput // Key bindings disp.bind(KC_Q, A_Quit); disp.bind(KC_ESCAPE, A_Quit); + disp.bind(KC_SYSRQ, A_Screenshot); // Key bindings for polled keys diff --git a/nifogre/ogre_nif_loader.cpp b/nifogre/ogre_nif_loader.cpp index d362f4392..de00b443f 100644 --- a/nifogre/ogre_nif_loader.cpp +++ b/nifogre/ogre_nif_loader.cpp @@ -30,6 +30,7 @@ #include "nif/node.hpp" #include "nif/data.hpp" #include "nif/property.hpp" +#include "platform/strings.h" // For warning messages #include @@ -252,10 +253,6 @@ static void createMaterial(const String &name, // make sure that all materials are given unique names. static String getUniqueName(const String &input) { -#ifdef WIN32 -#define snprintf _snprintf -#endif - static int addon = 0; static char buf[8]; snprintf(buf, 8, "_%d", addon++); diff --git a/ogre/renderer.cpp b/ogre/renderer.cpp index a7998596d..61e2478eb 100644 --- a/ogre/renderer.cpp +++ b/ogre/renderer.cpp @@ -15,6 +15,11 @@ void OgreRenderer::cleanup() mRoot = NULL; } +void OgreRenderer::screenshot(const std::string &file) +{ + mWindow->writeContentsToFile(file); +} + bool OgreRenderer::configure(bool showConfig, const std::string &pluginCfg, bool _logging) diff --git a/ogre/renderer.hpp b/ogre/renderer.hpp index 0739aa05a..9f8069ca6 100644 --- a/ogre/renderer.hpp +++ b/ogre/renderer.hpp @@ -42,6 +42,9 @@ namespace Render /// Start the main rendering loop void start() { mRoot->startRendering(); } + /// Write a screenshot to file + void screenshot(const std::string &file); + /// Get the Root Ogre::Root *getRoot() { return mRoot; } diff --git a/old_d_version/ogre/cpp_framelistener.cpp b/old_d_version/ogre/cpp_framelistener.cpp index 864153ccb..0419c0f7e 100644 --- a/old_d_version/ogre/cpp_framelistener.cpp +++ b/old_d_version/ogre/cpp_framelistener.cpp @@ -92,14 +92,6 @@ public: MorroFrameListener mFrameListener; InputListener mInput; -// Functions called from D during event handling - -// Dump screen contents to file -extern "C" void ogre_screenshot(char* filename) -{ - mWindow->writeContentsToFile(filename); -} - // Get current camera orientation, in the form of 'front' and 'up' // vectors. extern "C" void ogre_getCameraOrientation(float *fx, float *fy, float *fz, diff --git a/platform/strings.h b/platform/strings.h index b81af023c..1fb2822a6 100644 --- a/platform/strings.h +++ b/platform/strings.h @@ -2,8 +2,10 @@ #ifndef _STRINGS_WRAPPER_H #define _STRINGS_WRAPPER_H +#ifdef WIN32 #pragma warning(disable: 4996) - #define strcasecmp stricmp +#define snprintf _snprintf +#endif #endif