From 79b3462799c28af8ba586349bd671b1b56e72353 Mon Sep 17 00:00:00 2001 From: Jason Maskell Date: Mon, 9 May 2016 10:39:54 +0200 Subject: Initial commit with PS4 and XBone stuff trimmed. --- test/testing_src/testing.h | 188 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 test/testing_src/testing.h (limited to 'test/testing_src/testing.h') diff --git a/test/testing_src/testing.h b/test/testing_src/testing.h new file mode 100644 index 0000000..3537d3e --- /dev/null +++ b/test/testing_src/testing.h @@ -0,0 +1,188 @@ +#ifndef TESTING_H +#define TESTING_H + +#include +#include +#include "..\include\GFSDK_WaveWorks_Types.h" +#include "..\include\GFSDK_WaveWorks.h" +#include + +struct Utility +{ + static void split(const std::string& s, char c, std::vector& v) + { + using namespace std; + + string::size_type i = 0; + string::size_type j = s.find(c); + + while (j != string::npos) + { + v.push_back(s.substr(i, j-i)); + i = ++j; + j = s.find(c, j); + + if (j == string::npos) + { + v.push_back(s.substr(i, s.length( ))); + } + } + } + + static bool writeTGAFile(const char *filename, int width, int height, unsigned char *imageData) + { + FILE* f = fopen(filename, "wb"); + + if (!f) return false; + + unsigned char TGAheader[12] = {0,0,2,0,0,0,0,0,0,0,0,0}; + unsigned char header[6] = {((unsigned char)(width%256)), ((unsigned char)(width/256)), ((unsigned char)(height%256)), ((unsigned char)(height/256)),24,0}; + + fwrite(TGAheader, sizeof(unsigned char), 12, f); + fwrite(header, sizeof(unsigned char), 6, f); + fwrite(imageData, sizeof(unsigned char), width*height*3, f); + + fclose(f); + + return true; + } +}; + +struct TestParams +{ + bool UseReadbacks; + GFSDK_WaveWorks_Simulation_DetailLevel QualityMode; + std::string ScreenshotDirectory; + + explicit TestParams(std::string strCommandLine) + : UseReadbacks(false) + , QualityMode( GFSDK_WaveWorks_Simulation_DetailLevel_Normal ) + + , m_hOceanSimulation(NULL) + , m_isTestingComplete(false) + , m_shouldTakeScreen(false) + , m_allowAA(true) + , m_frameIndex(0) + , m_windowStart(-1) + , m_windowEnd(-1) + , m_sliceFrame(-1) + { + using namespace std; + + // First split command line by into argument groups (- delimited). + vector args; + Utility::split( strCommandLine, '-', args ); + + const unsigned int iArgStart = 1; + for( unsigned int iArg = iArgStart; iArg < args.size() ; iArg++ ) + { + // Split single argument into parameters (space delimited) + vector keyValuePair; + Utility::split( args[iArg], ' ', keyValuePair ); + + if(keyValuePair.size() != 0) + { + // Handle flag args + if( keyValuePair[0] == "readback" ) + { + UseReadbacks = stoi( keyValuePair[1] ) == 0 ? false : true; + } + else if( keyValuePair[0] == "quality" ) + { + QualityMode = (GFSDK_WaveWorks_Simulation_DetailLevel)(stoi( keyValuePair[1] )); + } + else if( keyValuePair[0] == "startframe" ) + { + m_windowStart = stoi( keyValuePair[1] ); + } + else if( keyValuePair[0] == "endframe" ) + { + m_windowEnd = stoi( keyValuePair[1] ); + } + else if( keyValuePair[0] == "sliceframe" ) + { + m_sliceFrame = stoi( keyValuePair[1] ); + } + else if( keyValuePair[0] == "screenshot" ) + { + m_shouldTakeScreen = true; + ScreenshotDirectory = std::string(keyValuePair[1]); + } + else if( keyValuePair[0] == "noaa" ) + { + m_allowAA = false; + } + } + } + + m_isTestingComplete = m_frameIndex > m_sliceFrame && m_frameIndex > m_windowStart && m_frameIndex > m_windowEnd; + } + + void HookSimulation(GFSDK_WaveWorks_SimulationHandle handle) + { + m_hOceanSimulation = handle; + } + + bool IsTestingComplete() const { return m_isTestingComplete; } + bool ShouldTakeScreenshot() const { return m_shouldTakeScreen; } + bool AllowAA() const { return m_allowAA; } + + void Tick() + { + bool withinAverageWindow = (m_windowStart!=-1) && (m_windowEnd!=-1) && (m_frameIndex>=m_windowStart) && (m_frameIndex m_sliceFrame && m_frameIndex > m_windowStart && m_frameIndex > m_windowEnd; + + ++m_frameIndex; + } + +private: + GFSDK_WaveWorks_SimulationHandle m_hOceanSimulation; + + GFSDK_WaveWorks_Simulation_Stats m_sliceStats; + GFSDK_WaveWorks_Simulation_Stats m_averageStats; + + bool m_isTestingComplete; + bool m_shouldTakeScreen; + bool m_allowAA; + + int m_frameIndex; + int m_windowStart; + int m_windowEnd; + int m_sliceFrame; + +}; + +#endif // TESTING_H \ No newline at end of file -- cgit v1.2.3