Browse Source

Upgraded template projects.

David Piuva 3 years ago
parent
commit
209fa1b157

+ 4 - 1
Source/DFPSR/api/fileAPI.h

@@ -97,8 +97,11 @@ namespace dsr {
 	// Returns true iff path contains a root, according to the local path syntax.
 	bool file_hasRoot(const ReadableString &path);
 
-	// A convenient wrapper for getting input arguments as a list of portable Unicode strings.
+	// DSR_MAIN_CALLER is a convenient wrapper for getting input arguments as a list of portable Unicode strings.
 	//   The actual main function gets placed in DSR_MAIN_CALLER, which calls the given function.
+	// When a regular function replaces the main function, it will not return zero by default.
+	//   Returning something else than zero tells that something went wrong and it must skip cleanup in order to get out.
+	//   Then the window and other resources held as global variables might not close.
 	// Example:
 	//   DSR_MAIN_CALLER(dsrMain)
 	//   int dsrMain(List<String> args) {

+ 1 - 1
Source/templates/basic3D/build.sh

@@ -13,7 +13,7 @@ WINDOW_MANAGER=X11
 # Select safe debug mode or fast release mode
 #MODE=-DDEBUG #Debug mode
 MODE=-DNDEBUG #Release mode
-COMPILER_FLAGS="${MODE} -std=c++17 -O2"
+COMPILER_FLAGS="${MODE} -std=c++14 -O2"
 # Select external libraries
 LINKER_FLAGS=""
 

+ 5 - 11
Source/templates/basic3D/main.cpp

@@ -4,16 +4,6 @@
 
 using namespace dsr;
 
-// Having a media folder requires keeping track of its location.
-// * You can start the program from its own folder and use a relative path. (Simple and works when developing)
-// * You can give a command line argument with the media folder's location. (Good for modifications using multiple folders)
-// * You can try to find the application's relative path using argv[0]. (Often works but not guaranteed by the C++ standard)
-// * You can use system specific API calls to find the applications location. (Increases long-term maintenance)
-// * You can link binary files into your application. (Hard to create modifications without access to source code)
-
-//const String mediaPath = string_combine(U"media", file_separator());
-//static BasicResourcePool pool(mediaPath);
-
 // Global variables
 bool running = true;
 
@@ -70,7 +60,8 @@ Model createCubeModel(const FVector3D &min, const FVector3D &max) {
 	return result;
 }
 
-int main(int argn, char **argv) {
+DSR_MAIN_CALLER(dsrMain)
+int dsrMain(List<String> args) {
 	// Create a window
 	window = window_create(U"Basic 3D template", 1600, 900);
 
@@ -130,4 +121,7 @@ int main(int argn, char **argv) {
 
 		window_showCanvas(window);
 	}
+
+	// When the DSR_MAIN_CALLER wrapper is used over the real main function, returning zero is no longer implicit.
+	return 0;
 }

+ 1 - 1
Source/templates/basicCLI/build.sh

@@ -13,7 +13,7 @@ WINDOW_MANAGER=NONE
 # Select safe debug mode or fast release mode
 #MODE=-DDEBUG #Debug mode
 MODE=-DNDEBUG #Release mode
-COMPILER_FLAGS="${MODE} -std=c++17 -O2"
+COMPILER_FLAGS="${MODE} -std=c++14 -O2"
 # Select external libraries
 LINKER_FLAGS=""
 

+ 6 - 1
Source/templates/basicCLI/main.cpp

@@ -3,6 +3,11 @@
 
 using namespace dsr;
 
-int main(int argn, char **argv) {
+DSR_MAIN_CALLER(dsrMain)
+int dsrMain(List<String> args) {
+	// Printing some text to the terminal.
 	printText(U"Hello world\n");
+
+	// When the DSR_MAIN_CALLER wrapper is used over the real main function, returning zero is no longer implicit.
+	return 0;
 }

+ 1 - 1
Source/templates/basicGUI/build.sh

@@ -13,7 +13,7 @@ WINDOW_MANAGER=X11
 # Select safe debug mode or fast release mode
 #MODE=-DDEBUG #Debug mode
 MODE=-DNDEBUG #Release mode
-COMPILER_FLAGS="${MODE} -std=c++17 -O2"
+COMPILER_FLAGS="${MODE} -std=c++14 -O2"
 # Select external libraries
 LINKER_FLAGS=""
 

+ 5 - 1
Source/templates/basicGUI/main.cpp

@@ -20,7 +20,8 @@ bool running = true;
 // GUI handles
 Window window;
 
-int main(int argn, char **argv) {
+DSR_MAIN_CALLER(dsrMain)
+int dsrMain(List<String> args) {
 	// Create a window
 	window = window_create(U"GUI template", 1000, 700);
 
@@ -53,4 +54,7 @@ int main(int argn, char **argv) {
 		// Show the final image
 		window_showCanvas(window);
 	}
+
+	// When the DSR_MAIN_CALLER wrapper is used over the real main function, returning zero is no longer implicit.
+	return 0;
 }