Browse Source

Making testapp a more generic sandbox application

Panagiotis Christopoulos Charitos 9 years ago
parent
commit
137dd0fe8f

+ 3 - 3
CMakeLists.txt

@@ -43,7 +43,7 @@ option(ANKI_DEBUG "Debugging checks" OFF)
 
 option(ANKI_BUILD_TOOLS "Build tools" OFF)
 option(ANKI_BUILD_TESTS "Build unit tests" OFF)
-option(ANKI_BUILD_TESTAPP "Build test application" ON)
+option(ANKI_BUILD_SANDBOX "Build sandbox application" ON)
 option(ANKI_BUILD_BENCH "Build benchmark application" OFF)
 option(ANKI_BUILD_SAMPLES "Build sample applications" ON)
 
@@ -384,8 +384,8 @@ if(ANKI_BUILD_TOOLS)
 	add_subdirectory(tools)
 endif()
 
-if(ANKI_BUILD_TESTAPP)
-	add_subdirectory(testapp)
+if(ANKI_BUILD_SANDBOX)
+	add_subdirectory(sandbox)
 endif()
 
 if(ANKI_BUILD_SAMPLES)

+ 2 - 2
include/anki/core/App.h

@@ -40,7 +40,7 @@ public:
 	App();
 	virtual ~App();
 
-	ANKI_USE_RESULT Error create(const ConfigSet& config,
+	ANKI_USE_RESULT Error init(const ConfigSet& config,
 		AllocAlignedCallback allocCb,
 		void* allocCbUserData);
 
@@ -158,7 +158,7 @@ private:
 	String m_cacheDir; ///< This is used as a cache
 	F32 m_timerTick;
 
-	ANKI_USE_RESULT Error createInternal(const ConfigSet& config,
+	ANKI_USE_RESULT Error initInternal(const ConfigSet& config,
 		AllocAlignedCallback allocCb,
 		void* allocCbUserData);
 

+ 3 - 0
sandbox/CMakeLists.txt

@@ -0,0 +1,3 @@
+add_definitions(-UANKI_BUILD)
+add_executable(sandbox Main.cpp)
+target_link_libraries(sandbox anki) 

+ 216 - 0
sandbox/Main.cpp

@@ -0,0 +1,216 @@
+// Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
+// All rights reserved.
+// Code licensed under the BSD License.
+// http://www.anki3d.org/LICENSE
+
+#include <cstdio>
+#include <iostream>
+#include <fstream>
+#include "anki/AnKi.h"
+
+using namespace anki;
+
+#define PLAYER 0
+#define MOUSE 1
+
+class MyApp : public App
+{
+public:
+	Bool m_profile = false;
+
+	Error init(int argc, char* argv[]);
+	Error userMainLoop(Bool& quit) override;
+};
+
+MyApp* app = nullptr;
+
+//==============================================================================
+Error MyApp::init(int argc, char* argv[])
+{
+	if(argc != 3)
+	{
+		ANKI_LOGE("usage: %s /path/to/config.xml relative/path/to/scene.lua",
+			argv[0]);
+		return ErrorCode::USER_DATA;
+	}
+
+	// Config
+	Config config;
+	ANKI_CHECK(config.loadFromFile(argv[1]));
+
+	// Init super class
+	ANKI_CHECK(App::init(config, allocAligned, nullptr));
+
+	// Other init
+	SceneGraph& scene = getSceneGraph();
+	MainRenderer& renderer = getMainRenderer();
+	ResourceManager& resources = getResourceManager();
+
+	renderer.getOffscreenRenderer().getVolumetric().setFog(
+		Vec3(1.0, 0.9, 0.9), 0.7);
+
+	if(getenv("PROFILE"))
+	{
+		m_profile = true;
+		setTimerTick(0.0);
+	}
+
+// Input
+#if MOUSE
+	getInput().lockCursor(true);
+	getInput().hideCursor(true);
+	getInput().moveCursor(Vec2(0.0));
+#endif
+
+	// Load scene
+	ScriptResourcePtr script;
+	ANKI_CHECK(resources.loadResource(argv[2], script));
+	ANKI_CHECK(getScriptManager().evalString(script->getSource()));
+
+	ANKI_CHECK(renderer.getOffscreenRenderer().getPps().loadColorGradingTexture(
+		"textures/adis/dungeon.ankitex"));
+
+	return ErrorCode::NONE;
+}
+
+//==============================================================================
+Error MyApp::userMainLoop(Bool& quit)
+{
+	F32 dist = 0.1;
+	F32 ang = toRad(2.5);
+	F32 scale = 0.01;
+	F32 mouseSensivity = 9.0;
+	quit = false;
+
+	SceneGraph& scene = getSceneGraph();
+	Input& in = getInput();
+	MainRenderer& renderer = getMainRenderer();
+
+	if(in.getKey(KeyCode::ESCAPE))
+	{
+		quit = true;
+		return ErrorCode::NONE;
+	}
+
+	// move the camera
+	static MoveComponent* mover =
+		&scene.getActiveCamera().getComponent<MoveComponent>();
+
+	if(in.getKey(KeyCode::_1))
+	{
+		mover = scene.getActiveCamera().tryGetComponent<MoveComponent>();
+	}
+	if(in.getKey(KeyCode::_2))
+	{
+		mover = &scene.findSceneNode("proxy").getComponent<MoveComponent>();
+	}
+
+	if(in.getKey(KeyCode::L) == 1)
+	{
+		Vec3 origin = mover->getWorldTransform().getOrigin().xyz();
+		printf("%f %f %f\n", origin.x(), origin.y(), origin.z());
+	}
+
+	if(in.getKey(KeyCode::F1) == 1)
+	{
+		renderer.getDbg().setEnabled(!renderer.getDbg().getEnabled());
+	}
+	if(in.getKey(KeyCode::F2) == 1)
+	{
+		renderer.getDbg().flipFlags(DbgFlag::SPATIAL_COMPONENT);
+	}
+	if(in.getKey(KeyCode::F3) == 1)
+	{
+		renderer.getDbg().flipFlags(DbgFlag::PHYSICS);
+	}
+	if(in.getKey(KeyCode::F4) == 1)
+	{
+		renderer.getDbg().flipFlags(DbgFlag::SECTOR_COMPONENT);
+	}
+	if(in.getKey(KeyCode::F6) == 1)
+	{
+		renderer.getDbg().switchDepthTestEnabled();
+	}
+
+#if !PLAYER
+	if(in.getKey(KeyCode::UP))
+		mover->rotateLocalX(ang);
+	if(in.getKey(KeyCode::DOWN))
+		mover->rotateLocalX(-ang);
+	if(in.getKey(KeyCode::LEFT))
+		mover->rotateLocalY(ang);
+	if(in.getKey(KeyCode::RIGHT))
+		mover->rotateLocalY(-ang);
+
+	if(in.getKey(KeyCode::A))
+	{
+		mover->moveLocalX(-dist);
+	}
+	if(in.getKey(KeyCode::D))
+		mover->moveLocalX(dist);
+	if(in.getKey(KeyCode::Z))
+		mover->moveLocalY(dist);
+	if(in.getKey(KeyCode::SPACE))
+		mover->moveLocalY(-dist);
+	if(in.getKey(KeyCode::W))
+		mover->moveLocalZ(-dist);
+	if(in.getKey(KeyCode::S))
+		mover->moveLocalZ(dist);
+	if(in.getKey(KeyCode::Q))
+		mover->rotateLocalZ(ang);
+	if(in.getKey(KeyCode::E))
+		mover->rotateLocalZ(-ang);
+	if(in.getKey(KeyCode::PAGEUP))
+	{
+		mover->scale(scale);
+	}
+	if(in.getKey(KeyCode::PAGEDOWN))
+	{
+		mover->scale(-scale);
+	}
+#endif
+
+#if !PLAYER && MOUSE
+	if(in.getMousePosition() != Vec2(0.0) && !m_profile)
+	{
+		F32 angY = -ang * in.getMousePosition().x() * mouseSensivity
+			* renderer.getAspectRatio();
+
+		mover->rotateLocalY(angY);
+		mover->rotateLocalX(ang * in.getMousePosition().y() * mouseSensivity);
+	}
+#endif
+
+	if(m_profile && getGlobalTimestamp() == 500)
+	{
+		quit = true;
+		return ErrorCode::NONE;
+	}
+
+	return ErrorCode::NONE;
+}
+
+//==============================================================================
+int main(int argc, char* argv[])
+{
+	Error err = ErrorCode::NONE;
+
+	app = new MyApp;
+	err = app->init(argc, argv);
+	if(!err)
+	{
+		err = app->mainLoop();
+	}
+
+	if(err)
+	{
+		ANKI_LOGE("Error reported. See previous messages");
+	}
+	else
+	{
+		delete app;
+		ANKI_LOGI("Bye!!");
+	}
+
+	return 0;
+}

+ 55 - 0
sandbox/config.xml

@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<config>
+	<sm.enabled>1</sm.enabled>
+	<sm.poissonEnabled>0</sm.poissonEnabled>
+	<sm.bilinearEnabled>1</sm.bilinearEnabled>
+	<sm.resolution>512</sm.resolution>
+	<sm.maxLights>16</sm.maxLights>
+	<is.groundLightEnabled>0</is.groundLightEnabled>
+	<is.maxPointLights>384</is.maxPointLights>
+	<is.maxSpotLights>16</is.maxSpotLights>
+	<is.maxSpotTexLights>8</is.maxSpotTexLights>
+	<is.maxLightsPerCluster>8</is.maxLightsPerCluster>
+	<lf.maxSpritesPerFlare>8</lf.maxSpritesPerFlare>
+	<lf.maxFlares>32</lf.maxFlares>
+	<bloom.enabled>1</bloom.enabled>
+	<bloom.renderingQuality>0.500000</bloom.renderingQuality>
+	<bloom.blurringDist>1</bloom.blurringDist>
+	<bloom.samples>17</bloom.samples>
+	<bloom.blurringIterationsCount>1</bloom.blurringIterationsCount>
+	<bloom.threshold>2</bloom.threshold>
+	<bloom.scale>2</bloom.scale>
+	<ssao.enabled>1</ssao.enabled>
+	<ssao.renderingQuality>0.250000</ssao.renderingQuality>
+	<ssao.blurringIterationsCount>1</ssao.blurringIterationsCount>
+	<sslf.enabled>1</sslf.enabled>
+	<pps.enabled>1</pps.enabled>
+	<pps.sharpen>0</pps.sharpen>
+	<pps.gammaCorrection>1</pps.gammaCorrection>
+	<ir.enabled>1</ir.enabled>
+	<ir.rendererSize>64</ir.rendererSize>
+	<ir.cubemapTextureArraySize>32</ir.cubemapTextureArraySize>
+	<sslr.enabled>0</sslr.enabled>
+	<sslr.startRoughnes>0.200000</sslr.startRoughnes>
+	<dbg.enabled>0</dbg.enabled>
+	<tm.enabled>1</tm.enabled>
+	<width>1920</width>
+	<height>1088</height>
+	<renderingQuality>1</renderingQuality>
+	<lodDistance>20</lodDistance>
+	<samples>1</samples>
+	<tessellation>1</tessellation>
+	<clusterSizeZ>32</clusterSizeZ>
+	<imageReflectionMaxDistance>30</imageReflectionMaxDistance>
+	<gr.frameUniformsSize>16777216</gr.frameUniformsSize>
+	<gr.frameStorageSize>16777216</gr.frameStorageSize>
+	<gr.frameVertexSize>2097152</gr.frameVertexSize>
+	<gr.frameTransferSize>33554432</gr.frameTransferSize>
+	<maxTextureSize>1048576</maxTextureSize>
+	<textureAnisotropy>8</textureAnisotropy>
+	<dataPaths>assets:.</dataPaths>
+	<glmajor>4</glmajor>
+	<glminor>5</glminor>
+	<fullscreenDesktopResolution>1</fullscreenDesktopResolution>
+	<debugContext>0</debugContext>
+</config>

+ 3 - 3
src/core/App.cpp

@@ -119,11 +119,11 @@ void App::cleanup()
 }
 
 //==============================================================================
-Error App::create(const ConfigSet& config,
+Error App::init(const ConfigSet& config,
 	AllocAlignedCallback allocCb,
 	void* allocCbUserData)
 {
-	Error err = createInternal(config, allocCb, allocCbUserData);
+	Error err = initInternal(config, allocCb, allocCbUserData);
 	if(err)
 	{
 		cleanup();
@@ -134,7 +134,7 @@ Error App::create(const ConfigSet& config,
 }
 
 //==============================================================================
-Error App::createInternal(const ConfigSet& config_,
+Error App::initInternal(const ConfigSet& config_,
 	AllocAlignedCallback allocCb,
 	void* allocCbUserData)
 {

+ 0 - 2
testapp/CMakeLists.txt

@@ -1,2 +0,0 @@
-ADD_EXECUTABLE(testapp Main.cpp)
-TARGET_LINK_LIBRARIES(testapp anki) 

+ 0 - 310
testapp/Main.cpp

@@ -1,310 +0,0 @@
-#include <stdio.h>
-#include <iostream>
-#include <fstream>
-
-#ifdef ANKI_BUILD
-#undef ANKI_BUILD
-#endif
-
-#include "anki/AnKi.h"
-
-using namespace anki;
-
-#define PLAYER 0
-#define MOUSE 1
-
-class MyApp : public App
-{
-public:
-	Bool m_profile = false;
-
-	Error init();
-	Error userMainLoop(Bool& quit) override;
-};
-
-MyApp* app = nullptr;
-
-//==============================================================================
-Error MyApp::init()
-{
-	Error err = ErrorCode::NONE;
-	ANKI_LOGI("Other init...");
-
-	SceneGraph& scene = app->getSceneGraph();
-	MainRenderer& renderer = app->getMainRenderer();
-	ResourceManager& resources = app->getResourceManager();
-
-	renderer.getOffscreenRenderer().getVolumetric().setFog(
-		Vec3(1.0, 0.9, 0.9), 0.7);
-
-	if(getenv("PROFILE"))
-	{
-		m_profile = true;
-		app->setTimerTick(0.0);
-	}
-
-	{
-		ScriptResourcePtr script;
-
-		ANKI_CHECK(resources.loadResource("maps/hell/scene.lua", script));
-		if(err)
-			return err;
-
-		err = app->getScriptManager().evalString(script->getSource());
-		if(err)
-			return err;
-
-		app->getMainRenderer()
-			.getOffscreenRenderer()
-			.getPps()
-			.loadColorGradingTexture("textures/adis/dungeon.ankitex");
-	}
-
-	return ErrorCode::NONE;
-}
-
-//==============================================================================
-Error MyApp::userMainLoop(Bool& quit)
-{
-	Error err = ErrorCode::NONE;
-	F32 dist = 0.1;
-	F32 ang = toRad(2.5);
-	F32 scale = 0.01;
-	F32 mouseSensivity = 9.0;
-	quit = false;
-
-	SceneGraph& scene = getSceneGraph();
-	Input& in = getInput();
-	MainRenderer& renderer = getMainRenderer();
-
-	if(in.getKey(KeyCode::ESCAPE))
-	{
-		quit = true;
-		return err;
-	}
-
-	// move the camera
-	static MoveComponent* mover =
-		&scene.getActiveCamera().getComponent<MoveComponent>();
-
-	if(in.getKey(KeyCode::_1))
-	{
-		mover = scene.getActiveCamera().tryGetComponent<MoveComponent>();
-	}
-	if(in.getKey(KeyCode::_2))
-	{
-		mover = &scene.findSceneNode("proxy").getComponent<MoveComponent>();
-	}
-	if(in.getKey(KeyCode::_3))
-	{
-		mover = &scene.findSceneNode("spot0").getComponent<MoveComponent>();
-	}
-	if(in.getKey(KeyCode::_4))
-	{
-		mover = &scene.findSceneNode("spot1").getComponent<MoveComponent>();
-	}
-	if(in.getKey(KeyCode::_5))
-	{
-		mover = &scene.findSceneNode("pe").getComponent<MoveComponent>();
-	}
-	if(in.getKey(KeyCode::_6))
-	{
-		mover = &scene.findSceneNode("shape0").getComponent<MoveComponent>();
-	}
-	if(in.getKey(KeyCode::_7))
-	{
-		mover = &scene.findSceneNode("shape1").getComponent<MoveComponent>();
-	}
-
-	if(in.getKey(KeyCode::L) == 1)
-	{
-		Vec3 origin = mover->getWorldTransform().getOrigin().xyz();
-		printf("%f %f %f\n", origin.x(), origin.y(), origin.z());
-	}
-
-	if(in.getKey(KeyCode::F1) == 1)
-	{
-		renderer.getDbg().setEnabled(!renderer.getDbg().getEnabled());
-	}
-	if(in.getKey(KeyCode::F2) == 1)
-	{
-		renderer.getDbg().flipFlags(DbgFlag::SPATIAL_COMPONENT);
-	}
-	if(in.getKey(KeyCode::F3) == 1)
-	{
-		renderer.getDbg().flipFlags(DbgFlag::PHYSICS);
-	}
-	if(in.getKey(KeyCode::F4) == 1)
-	{
-		renderer.getDbg().flipFlags(DbgFlag::SECTOR_COMPONENT);
-	}
-	if(in.getKey(KeyCode::F6) == 1)
-	{
-		renderer.getDbg().switchDepthTestEnabled();
-	}
-	if(in.getKey(KeyCode::F12) == 1)
-	{
-		printf("F12\n");
-		scene.getActiveCamera()
-			.getComponent<FrustumComponent>()
-			.markShapeForUpdate();
-		scene.getActiveCamera()
-			.getComponent<FrustumComponent>()
-			.markTransformForUpdate();
-	}
-
-#if !PLAYER
-	if(in.getKey(KeyCode::UP))
-		mover->rotateLocalX(ang);
-	if(in.getKey(KeyCode::DOWN))
-		mover->rotateLocalX(-ang);
-	if(in.getKey(KeyCode::LEFT))
-		mover->rotateLocalY(ang);
-	if(in.getKey(KeyCode::RIGHT))
-		mover->rotateLocalY(-ang);
-
-	if(in.getKey(KeyCode::A))
-	{
-		mover->moveLocalX(-dist);
-	}
-	if(in.getKey(KeyCode::D))
-		mover->moveLocalX(dist);
-	if(in.getKey(KeyCode::Z))
-		mover->moveLocalY(dist);
-	if(in.getKey(KeyCode::SPACE))
-		mover->moveLocalY(-dist);
-	if(in.getKey(KeyCode::W))
-		mover->moveLocalZ(-dist);
-	if(in.getKey(KeyCode::S))
-		mover->moveLocalZ(dist);
-	if(in.getKey(KeyCode::Q))
-		mover->rotateLocalZ(ang);
-	if(in.getKey(KeyCode::E))
-		mover->rotateLocalZ(-ang);
-	if(in.getKey(KeyCode::PAGEUP))
-	{
-		mover->scale(scale);
-	}
-	if(in.getKey(KeyCode::PAGEDOWN))
-	{
-		mover->scale(-scale);
-	}
-#endif
-
-#if !PLAYER && MOUSE
-	if(in.getMousePosition() != Vec2(0.0) && !m_profile)
-	{
-		// printf("%f %f\n", in.getMousePosition().x(),
-		// in.getMousePosition().y());
-
-		F32 angY = -ang * in.getMousePosition().x() * mouseSensivity
-			* renderer.getAspectRatio();
-
-		mover->rotateLocalY(angY);
-		mover->rotateLocalX(ang * in.getMousePosition().y() * mouseSensivity);
-	}
-#endif
-
-	if(m_profile && getGlobalTimestamp() == 500)
-	{
-		quit = true;
-		return err;
-	}
-
-	return err;
-}
-
-//==============================================================================
-Error init(int argc, char* argv[])
-{
-	Error err = ErrorCode::NONE;
-
-	// Config
-	Config config;
-	config.set("dbg.enabled", false);
-	config.set("sm.bilinearEnabled", true);
-	config.set("is.groundLightEnabled", false);
-	config.set("sm.enabled", true);
-	config.set("sm.maxLights", 16);
-	config.set("sm.poissonEnabled", false);
-	config.set("sm.resolution", 512);
-	config.set("lf.maxFlares", 32);
-	config.set("pps.enabled", true);
-	config.set("bloom.enabled", true);
-	config.set("bloom.renderingQuality", 0.5);
-	config.set("bloom.blurringDist", 1.0);
-	config.set("bloom.blurringIterationsCount", 1);
-	config.set("bloom.threshold", 2.0);
-	config.set("bloom.scale", 2.0);
-	config.set("bloom.samples", 17);
-	config.set("ssao.blurringIterationsCount", 1);
-	config.set("ssao.enabled", true);
-	config.set("ssao.renderingQuality", 0.25);
-	config.set("sslf.enabled", true);
-	config.set("pps.sharpen", false);
-	config.set("renderingQuality", 1.0);
-	config.set("width", 1920);
-	config.set("height", 1088);
-	config.set("lodDistance", 20.0);
-	config.set("samples", 1);
-	config.set("tessellation", true);
-	// config.set("maxTextureSize", 256);
-	config.set("ir.enabled", true);
-	// config.set("ir.clusterSizeZ", 32);
-	config.set("sslr.enabled", false);
-	config.set("ir.rendererSize", 64);
-	config.set("fullscreenDesktopResolution", true);
-	// config.set("clusterSizeZ", 16);
-	config.set("debugContext", false);
-	if(getenv("ANKI_DATA_PATH"))
-	{
-		config.set("dataPaths", getenv("ANKI_DATA_PATH"));
-	}
-	else
-	{
-		config.set("dataPaths", "assets");
-	}
-	// config.set("maxTextureSize", 256);
-	// config.set("lodDistance", 3.0);
-
-	// config.saveToFile("./config.xml");
-	// config.loadFromFile("./config.xml");
-
-	app = new MyApp;
-	ANKI_CHECK(app->create(config, allocAligned, nullptr));
-	ANKI_CHECK(app->init());
-
-// Input
-#if MOUSE
-	app->getInput().lockCursor(true);
-	app->getInput().hideCursor(true);
-	app->getInput().moveCursor(Vec2(0.0));
-#endif
-
-	return err;
-}
-
-//==============================================================================
-int main(int argc, char* argv[])
-{
-	Error err = ErrorCode::NONE;
-
-	err = init(argc, argv);
-
-	if(!err)
-	{
-		err = app->mainLoop();
-	}
-
-	if(err)
-	{
-		ANKI_LOGE("Error reported. See previous messages");
-	}
-	else
-	{
-		delete app;
-		ANKI_LOGI("Bye!!");
-	}
-
-	return 0;
-}

+ 1 - 1
tools/count_lines.sh

@@ -1 +1 @@
-wc -l `find ./src ./include ./tests ./testapp ./tools ./shaders ./samples -name '*.h' -o -name '*.hpp' -o -name '*.c' -o -name '*.cpp' -o -name '*.glsl' -o -name '*.py'`
+wc -l `find ./src ./include ./tests ./sandbox ./tools ./shaders ./samples -name '*.h' -o -name '*.hpp' -o -name '*.c' -o -name '*.cpp' -o -name '*.glsl' -o -name '*.py'`

+ 1 - 1
tools/format_source.sh

@@ -1 +1 @@
-find ./src ./include ./tests ./testapp ./tools ./shaders ./samples -name '*.h' -o -name '*.hpp' -o -name '*.c' -o -name '*.cpp' -o -name '*.glsl' | xargs -I % ./thirdparty/bin/clang-format -sort-includes=false -i %
+find ./src ./include ./tests ./sandbox ./tools ./shaders ./samples -name '*.h' -o -name '*.hpp' -o -name '*.c' -o -name '*.cpp' -o -name '*.glsl' | xargs -I % ./thirdparty/bin/clang-format -sort-includes=false -i %