Elaztek Developer Hub
Blamite Game Engine - blam!  00398.09.22.23.2015.blamite
The core library for the Blamite Game Engine.
UnitTesting.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-present Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef _Demo_UnitTesting_H_
30 #define _Demo_UnitTesting_H_
31 
32 #include "OGRE/OgrePrerequisites.h"
33 
35 
36 #include "OGRE/OgreQuaternion.h"
37 #include "OGRE/OgreStringVector.h"
38 #include "OGRE/OgreVector3.h"
39 
40 #include <stdint.h>
41 
42 namespace Demo
43 {
44  class GraphicsSystem;
45  class KeyboardListener;
46 
59  class UnitTest : public KeyboardListener, public MouseListener
60  {
61  struct KeyStroke
62  {
63  int32_t keycode; // SDL_Keycode
64  uint16_t scancode; // SDL_Scancode
65  bool bReleased;
66  KeyStroke();
67  };
68 
69  struct FrameActivity
70  {
71  uint32_t frameId;
72  Ogre::Vector3 cameraPos;
73  Ogre::Quaternion cameraRot;
74  std::vector<KeyStroke> keyStrokes;
75  bool screenshotRenderWindow;
76  Ogre::StringVector targetsToScreenshot;
77  FrameActivity( uint32_t _frameId );
78  };
79 
80  public:
81  struct Params
82  {
83  bool bRecord;
85  bool bSkipDump; // Useful for debugging a record showing something that is broken
86  std::string recordPath;
87  std::string outputPath;
88  Params();
89 
90  bool isRecording() const;
91  bool isPlayback() const;
92  };
93 
94  protected:
95  double mFrametime;
100 
101  std::vector<FrameActivity> mFrameActivity;
102 
105 
106  inline static void flushLwString( Ogre::LwString &jsonStr, std::string &outJson );
107 
108  void exportFrameActivity( const FrameActivity &frameActivity, Ogre::LwString &jsonStr,
109  std::string &outJson );
110  void saveToJsonStr( std::string &outJson );
111 
112  static bool shouldRecordKey( const SDL_KeyboardEvent &arg );
113  static Ogre::Vector3 getCameraRecordPosition( Ogre::Camera *camera );
114 
115  public:
116  UnitTest();
117 
118  void parseCmdLine( int nargs, const char *const *argv );
119 
120  const Params &getParams( void ) const { return mParams; }
121 
122  void startRecording( Demo::GraphicsSystem *graphicsSystem );
123  void notifyRecordingNewFrame( Demo::GraphicsSystem *graphicsSystem );
124 
133  void saveToJson( const char *fullpath, const bool bCompressDuration );
134 
135  virtual void keyPressed( const SDL_KeyboardEvent &arg );
136  virtual void keyReleased( const SDL_KeyboardEvent &arg );
137  virtual void mouseMoved( const SDL_Event &arg );
138  virtual void mousePressed( const SDL_MouseButtonEvent &arg, Ogre::uint8 id );
139  virtual void mouseReleased( const SDL_MouseButtonEvent &arg, Ogre::uint8 id );
140 
144  int loadFromJson( const char *fullpath, const Ogre::String &outputFolder );
145 
146  protected:
147  int runLoop( Ogre::String outputFolder );
148  };
149 } // namespace Demo
150 
151 #endif
Demo::MainEntryPoints::getWindowTitle
static const char * getWindowTitle(void)
Demo::LogicSystem::finishFrameParallel
void finishFrameParallel(void)
Definition: LogicSystem.cpp:44
Demo::BaseSystem::createScene02
virtual void createScene02(void)
Definition: BaseSystem.cpp:40
SDL_KeyboardEvent
Keyboard button event structure (event.key.
Definition: SdlEmulationLayer.h:676
Demo::GraphicsSystem::getRenderWindow
Ogre::Window * getRenderWindow(void) const
Definition: GraphicsSystem.h:145
InputListeners.h
Demo::MouseListener
Definition: InputListeners.h:18
hInst
HINSTANCE hInst
Application instance handle.
Definition: main.cpp:69
Demo::YieldTimer
Definition: YieldTimer.h:9
Demo::UnitTest
Usage: To record: Start app with –ut_record=/home/username/Ogre/pbs.json –ut_compress Move around and...
Definition: UnitTesting.h:59
Document
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
Definition: document.h:2873
SDL_SCANCODE_PAGEUP
@ SDL_SCANCODE_PAGEUP
Definition: SdlEmulationLayer.h:151
Demo::UnitTest::Params::bCompressDuration
bool bCompressDuration
Definition: UnitTesting.h:84
Demo::UnitTest::mouseReleased
virtual void mouseReleased(const SDL_MouseButtonEvent &arg, Ogre::uint8 id)
Definition: UnitTesting.cpp:374
Demo::UnitTest::shouldRecordKey
static bool shouldRecordKey(const SDL_KeyboardEvent &arg)
Definition: UnitTesting.cpp:294
SDL_Scancode
SDL_Scancode
The SDL keyboard scancode representation.
Definition: SdlEmulationLayer.h:22
Demo::UnitTest::Params::isRecording
bool isRecording() const
Definition: UnitTesting.cpp:64
Demo::MainEntryPoints::createSystems
static void createSystems(GameState **outGraphicsGameState, GraphicsSystem **outGraphicsSystem, GameState **outLogicGameState, LogicSystem **outLogicSystem)
Creates the system for the helper functions in Common framework to use in mainAppVarible & co.
Demo::UnitTest::notifyRecordingNewFrame
void notifyRecordingNewFrame(Demo::GraphicsSystem *graphicsSystem)
Definition: UnitTesting.cpp:237
SDL_Keysym::scancode
SDL_Scancode scancode
SDL physical key code - see SDL_Scancode for details.
Definition: SdlEmulationLayer.h:667
SDL_SCANCODE_W
@ SDL_SCANCODE_W
Definition: SdlEmulationLayer.h:55
Demo::UnitTest::mNumFrames
uint32_t mNumFrames
Definition: UnitTesting.h:97
document.h
Demo::UnitTest::Params::isPlayback
bool isPlayback() const
Definition: UnitTesting.cpp:66
THREAD_DECLARE
THREAD_DECLARE(renderThread)
SDLK_F12
@ SDLK_F12
Definition: SdlEmulationLayer.h:471
Demo::UnitTest::exportFrameActivity
void exportFrameActivity(const FrameActivity &frameActivity, Ogre::LwString &jsonStr, std::string &outJson)
Definition: UnitTesting.cpp:86
Demo::UnitTest::saveToJson
void saveToJson(const char *fullpath, const bool bCompressDuration)
Saves the current recording to JSON, for later playback.
Definition: UnitTesting.cpp:260
UnitTesting.h
Demo::BaseSystem::update
void update(float timeSinceLast)
Definition: BaseSystem.cpp:64
Demo::UnitTest::saveToJsonStr
void saveToJsonStr(std::string &outJson)
Definition: UnitTesting.cpp:142
Demo::KeyboardListener::keyReleased
virtual void keyReleased(const SDL_KeyboardEvent &arg)
Definition: InputListeners.h:33
Demo::MouseListener::mouseReleased
virtual void mouseReleased(const SDL_MouseButtonEvent &arg, Ogre::uint8 id)
Definition: InputListeners.h:24
Demo
Definition: BaseSystem.cpp:5
Demo::MainEntryPoints::mainAppSingleThreaded
static INT WINAPI mainAppSingleThreaded(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR strCmdLine, INT nCmdShow)
Definition: MainLoopSingleThreaded.cpp:49
Demo::UnitTest::mBlockInputForwarding
bool mBlockInputForwarding
Definition: UnitTesting.h:104
Demo::UnitTest::Params::outputPath
std::string outputPath
Definition: UnitTesting.h:87
Demo::UnitTest::Params::bSkipDump
bool bSkipDump
Definition: UnitTesting.h:85
ThreadData::barrier
Ogre::Barrier * barrier
Definition: MainLoopMultiThreaded.cpp:60
renderThread
unsigned long renderThread(Ogre::ThreadHandle *threadHandle)
Definition: MainLoopMultiThreaded.cpp:166
Demo::MouseListener::mousePressed
virtual void mousePressed(const SDL_MouseButtonEvent &arg, Ogre::uint8 id)
Definition: InputListeners.h:23
NULL
Add a fourth parameter to bake specific font ranges NULL
Definition: README.txt:57
Blam::Globals::String
@ String
Represents a std::string.
Definition: globals.h:48
Demo::GameState
Definition: GameState.h:9
MainEntryPoints.h
Demo::UnitTest::mousePressed
virtual void mousePressed(const SDL_MouseButtonEvent &arg, Ogre::uint8 id)
Definition: UnitTesting.cpp:368
Demo::UnitTest::mFrameIdx
uint32_t mFrameIdx
Definition: UnitTesting.h:96
int32_t
int int32_t
Definition: stdint.h:13
Demo::KeyboardListener
Definition: InputListeners.h:27
GameState.h
Demo::UnitTest::parseCmdLine
void parseCmdLine(int nargs, const char *const *argv)
Definition: UnitTesting.cpp:200
GetParseError_En
const RAPIDJSON_NAMESPACE_BEGIN RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
Definition: en.h:36
logicThread
unsigned long logicThread(Ogre::ThreadHandle *threadHandle)
Definition: MainLoopMultiThreaded.cpp:190
SDL_SCANCODE_S
@ SDL_SCANCODE_S
Definition: SdlEmulationLayer.h:51
Demo::UnitTest::loadFromJson
int loadFromJson(const char *fullpath, const Ogre::String &outputFolder)
Loads JSON from fullpath and plays it back, saving the results to outputFolder Return value is the re...
Definition: UnitTesting.cpp:380
Demo::KeyboardListener::keyPressed
virtual void keyPressed(const SDL_KeyboardEvent &arg)
Definition: InputListeners.h:32
Demo::GraphicsSystem::getCamera
Ogre::Camera * getCamera(void) const
Definition: GraphicsSystem.h:147
Demo::LogicSystem
Definition: LogicSystem.h:14
ThreadData::logicSystem
LogicSystem * logicSystem
Definition: MainLoopMultiThreaded.cpp:59
SDL_Event::key
SDL_KeyboardEvent key
Keyboard event data.
Definition: SdlEmulationLayer.h:738
Demo::MainEntryPoints::Frametime
static double Frametime
Time in seconds a frame should last in fixed timestep (e.g.
Definition: MainEntryPoints.h:111
Demo::GameEntityManager
Definition: GameEntityManager.h:13
SDL_KeyboardEvent::type
Ogre::uint32 type
::SDL_KEYDOWN or ::SDL_KEYUP
Definition: SdlEmulationLayer.h:678
Value
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2470
uint32_t
unsigned int uint32_t
Definition: stdint.h:17
Demo::BaseSystem::destroyScene
virtual void destroyScene(void)
Definition: BaseSystem.cpp:48
Demo::BaseSystem::deinitialize
virtual void deinitialize(void)
Definition: BaseSystem.cpp:24
Demo::GraphicsSystem::deinitialize
void deinitialize(void)
Definition: GraphicsSystem.cpp:494
renderThreadApp
unsigned long renderThreadApp(Ogre::ThreadHandle *threadHandle)
Definition: MainLoopMultiThreaded.cpp:100
ThreadData
Definition: MainLoopMultiThreaded.cpp:56
ThreadData::graphicsSystem
GraphicsSystem * graphicsSystem
Definition: MainLoopMultiThreaded.cpp:58
Demo::UnitTest::runLoop
int runLoop(Ogre::String outputFolder)
Definition: UnitTesting.cpp:532
Demo::UnitTest::Params::Params
Params()
Definition: UnitTesting.cpp:62
SDL_SCANCODE_PAGEDOWN
@ SDL_SCANCODE_PAGEDOWN
Definition: SdlEmulationLayer.h:154
Demo::MainEntryPoints::mainAppMultiThreaded
static INT WINAPI mainAppMultiThreaded(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR strCmdLine, INT nCmdShow)
Definition: MainLoopMultiThreaded.cpp:64
Demo::UnitTest::keyReleased
virtual void keyReleased(const SDL_KeyboardEvent &arg)
Definition: UnitTesting.cpp:331
Demo::BaseSystem::finishFrame
void finishFrame(void)
Definition: BaseSystem.cpp:82
renderWindow
Ogre::Window * renderWindow
Definition: ogre.cpp:52
Demo::UnitTest::UnitTest
UnitTest()
Definition: UnitTesting.cpp:70
YieldTimer.h
Demo::GraphicsSystem::setAlwaysAskForConfig
void setAlwaysAskForConfig(bool alwaysAskForConfig)
Definition: GraphicsSystem.cpp:1031
SDLK_PRINTSCREEN
@ SDLK_PRINTSCREEN
Definition: SdlEmulationLayer.h:473
camera
BlamDirector * camera
Definition: director.cpp:3
timeSinceLast
double timeSinceLast
Definition: ogre.cpp:57
Demo::MainEntryPoints::destroySystems
static void destroySystems(GameState *graphicsGameState, GraphicsSystem *graphicsSystem, GameState *logicGameState, LogicSystem *logicSystem)
Destroys the systems created via createSystems. Implementation should check for null pointers.
GraphicsSystem.h
Demo::GraphicsSystem
Definition: GraphicsSystem.h:26
SdlInputHandler.h
Demo::UnitTest::startRecording
void startRecording(Demo::GraphicsSystem *graphicsSystem)
Definition: UnitTesting.cpp:230
Demo::GraphicsSystem::update
void update(float timeSinceLast)
Definition: GraphicsSystem.cpp:528
SDL_Keysym::sym
SDL_Keycode sym
SDL virtual key code - see SDL_Keycode for details.
Definition: SdlEmulationLayer.h:668
Demo::UnitTest::mouseMoved
virtual void mouseMoved(const SDL_Event &arg)
Definition: UnitTesting.cpp:362
Demo::UnitTest::mRealKeyboardListener
KeyboardListener * mRealKeyboardListener
Definition: UnitTesting.h:98
Demo::GraphicsSystem::getQuit
bool getQuit(void) const
Definition: GraphicsSystem.h:140
timer
Ogre::Timer timer
Definition: ogre.cpp:56
en.h
Demo::MouseListener::mouseMoved
virtual void mouseMoved(const SDL_Event &arg)
Definition: InputListeners.h:22
Demo::BaseSystem::createScene01
virtual void createScene01(void)
Definition: BaseSystem.cpp:32
SDL_Event::type
Ogre::uint32 type
Event type, shared with all events.
Definition: SdlEmulationLayer.h:737
startTime
Ogre::uint64 startTime
Definition: ogre.cpp:58
Ogre
Definition: ogre2_imgui_manager.h:18
Demo::GraphicsSystem::initialize
void initialize(const Ogre::String &windowTitle)
Definition: GraphicsSystem.cpp:120
Demo::BaseSystem::initialize
virtual void initialize(void)
Definition: BaseSystem.cpp:16
GenericMemberIterator
(Constant) member iterator for a JSON object value
Definition: document.h:186
BlamTagFieldType::Vector3
@ Vector3
Indicates that the field is a vector3.
Demo::UnitTest::getCameraRecordPosition
static Ogre::Vector3 getCameraRecordPosition(Ogre::Camera *camera)
SDL_Event
Definition: SdlEmulationLayer.h:735
Demo::UnitTest::getParams
const Params & getParams(void) const
Definition: UnitTesting.h:120
Demo::UnitTest::Params::bRecord
bool bRecord
Definition: UnitTesting.h:83
SDL_SCANCODE_D
@ SDL_SCANCODE_D
Definition: SdlEmulationLayer.h:36
Demo::UnitTest::flushLwString
static void flushLwString(Ogre::LwString &jsonStr, std::string &outJson)
Definition: UnitTesting.cpp:80
Demo::GraphicsSystem::getRoot
Ogre::Root * getRoot(void) const
Definition: GraphicsSystem.h:144
LogicSystem.h
uint16_t
unsigned short uint16_t
Definition: stdint.h:16
SDL_MouseButtonEvent
Mouse button event structure (event.button.
Definition: SdlEmulationLayer.h:707
Demo::UnitTest::Params::recordPath
std::string recordPath
Definition: UnitTesting.h:86
Demo::UnitTest::mFrametime
double mFrametime
Definition: UnitTesting.h:95
SDL_KeyboardEvent::keysym
SDL_Keysym keysym
The key that was pressed or released.
Definition: SdlEmulationLayer.h:685
Demo::UnitTest::mRealMouseListener
MouseListener * mRealMouseListener
Definition: UnitTesting.h:99
Demo::BaseSystem::beginFrameParallel
void beginFrameParallel(void)
Definition: BaseSystem.cpp:56
Demo::UnitTest::mFrameActivity
std::vector< FrameActivity > mFrameActivity
Definition: UnitTesting.h:101
Demo::UnitTest::keyPressed
virtual void keyPressed(const SDL_KeyboardEvent &arg)
Definition: UnitTesting.cpp:303
Demo::UnitTest::mParams
Params mParams
Definition: UnitTesting.h:103
Demo::BaseSystem::finishFrameParallel
void finishFrameParallel(void)
Definition: BaseSystem.cpp:72
Demo::UnitTest::Params
Definition: UnitTesting.h:81
SDL_SCANCODE_A
@ SDL_SCANCODE_A
Definition: SdlEmulationLayer.h:33
Demo::YieldTimer::yield
Ogre::uint64 yield(double frameTime, Ogre::uint64 startTime)
Definition: YieldTimer.h:19