Browse Source

Make the samples execution a bit easier

Panagiotis Christopoulos Charitos 5 years ago
parent
commit
b59c8d4960
4 changed files with 24 additions and 13 deletions
  1. 12 6
      README.md
  2. 10 6
      samples/common/Framework.cpp
  3. 1 1
      samples/physics_playground/Main.cpp
  4. 1 0
      src/anki/Config.h.cmake

+ 12 - 6
README.md

@@ -7,8 +7,8 @@ AnKi 3D engine is a Linux and Windows opensource game engine that runs on Vulkan
 1 License
 =========
 
-AnKi's license is BSD. This practically means that you can use the source or parts of the source on proprietary and non
-proprietary products as long as you follow the conditions of the license.
+AnKi's license is `BSD`. This practically means that you can use the source or parts of the source on proprietary and
+non proprietary products as long as you follow the conditions of the license.
 
 See `LICENSE` file for more info.
 
@@ -84,11 +84,17 @@ Alternatively, recent Visual Studio versions support building CMake projects fro
 3 Next steps
 ============
 
-Try to build with `samples` enabled (search for the `ANKI_BUILD_SAMPLES=ON` option in your CMake GUI) and try running
-the sponza executable. Then you will be able to see sponza running in AnKi. All samples must run from within their
+This code repository contains **3 sample projects** that are built by default (`ANKI_BUILD_SAMPLES` CMake option):
+
+- `sponza`: The Crytek's Sponza scene
+- `simple_scene`: A simple scene
+- `physics_playground`: A scene with programmer's art and some physics interactions
+
+You can try running them and interacting with them. To run sponza, for example, execute the binary from any working
 directory.
 
-	$cd path/to/anki/samples/sponza
+On Linux:
+
 	$./path/to/build/bin/sponza
 
-More samples will follow.
+On Windows just find the `sponza.exe` and execute it.

+ 10 - 6
samples/common/Framework.cpp

@@ -9,19 +9,23 @@ using namespace anki;
 
 Error SampleApp::init(int argc, char** argv, CString sampleName)
 {
-	if(!directoryExists("assets"))
+	HeapAllocator<U32> alloc(allocAligned, nullptr);
+	StringAuto mainDataPath(alloc, ANKI_SOURCE_DIRECTORY);
+	StringAuto assetsDataPath(alloc);
+	assetsDataPath.sprintf("%s/samples/%s", ANKI_SOURCE_DIRECTORY, sampleName.cstr());
+
+	if(!directoryExists(assetsDataPath))
 	{
-		ANKI_LOGE("Cannot find directory \"assets\". YOU ARE RUNNING THE SAMPLE FROM THE WRONG DIRECTORY. "
-				  "To run %s you have to navigate to the /path/to/anki/samples/%s and then execute it",
-			argv[0],
-			&sampleName[0]);
+		ANKI_LOGE("Cannot find directory \"%s\". Have you moved the clone of the repository?", assetsDataPath.cstr());
 		return Error::USER_DATA;
 	}
 
+	printf("%s\n", StringAuto(alloc).sprintf("%s:%s", mainDataPath.cstr(), assetsDataPath.cstr()).cstr());
+
 	// Init the super class
 	ConfigSet config = DefaultConfigSet::get();
 	config.set("window_fullscreen", true);
-	config.set("rsrc_dataPaths", ".:../..");
+	config.set("rsrc_dataPaths", StringAuto(alloc).sprintf("%s:%s", mainDataPath.cstr(), assetsDataPath.cstr()));
 	config.set("gr_debugContext", 0);
 	ANKI_CHECK(config.setFromCommandLineArguments(argc, argv));
 	ANKI_CHECK(App::init(config, allocAligned, nullptr));

+ 1 - 1
samples/physics_playground/Main.cpp

@@ -348,7 +348,7 @@ int main(int argc, char* argv[])
 	Error err = Error::NONE;
 
 	MyApp* app = new MyApp;
-	err = app->init(argc, argv, argv[0]);
+	err = app->init(argc, argv, "physics_playground");
 	if(!err)
 	{
 		err = app->mainLoop();

+ 1 - 0
src/anki/Config.h.cmake

@@ -22,6 +22,7 @@
 #define ANKI_OPTIMIZE ${ANKI_OPTIMIZE}
 #define ANKI_TESTS ${ANKI_TESTS}
 #define ANKI_ENABLE_TRACE ${_ANKI_ENABLE_TRACE}
+#define ANKI_SOURCE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
 
 // Compiler
 #if defined(__clang__)