Browse Source

Explained files and buffers in the documentation.

David Piuva 3 years ago
parent
commit
ee6763346b

+ 49 - 0
Doc/Buffers.html

@@ -0,0 +1,49 @@
+<!DOCTYPE html> <HTML lang=en> <HEAD> <STYLE>
+body { background-color: #EEFFEE;  font-size: 1.0rem; font-family: Arial; max-width: 60rem;
+      color: #000000; margin: 0px;
+      padding-left:  0px; padding-right:  0px; padding-top:  0px; padding-bottom:  0px; }
+H1 {  padding-left: 10px; padding-right:  0px; padding-top: 10px; padding-bottom: 10px; font-size: 1.4rem; }
+H2 {  padding-left: 10px; padding-right:  0px; padding-top: 10px; padding-bottom:  0px; font-size: 1.2rem; }
+blockquote {
+  tab-size: 3rem;
+  color: #FFFFFF; background: #000000;
+  font-size: 1.2rem; font-family: monospace;
+  padding-left: 5px; padding-right: 5px;
+  padding-top: 5px; padding-bottom: 5px;
+}
+P {   padding-left: 20px; padding-right:  0px; padding-top:  0px; padding-bottom:  0px; }
+IMG { padding-left:  0px; padding-right:  0px; padding-top:  2px; padding-bottom:  0px;
+      max-width: 100%; }
+A { display: inline; border-radius: 4px;
+    font-size: 1.0rem; font-family: Arial; color: #000044; text-decoration: none;
+    padding-left: 4px; padding-right: 4px; padding-top: 4px; padding-bottom: 4px; }
+A:hover { color: #FFFF00; background: #000044; }
+A:active { color: #FFFFFF; background: #444444; }
+</STYLE> </HEAD> <BODY>
+<IMG SRC="Images/Title.png" ALT="Images/Title.png">
+<P>
+<A href="Manual.html">Back to main page</A>
+</P><P>
+</P><H1> Buffers</H1><P>Every file that is saved or loaded in the framework will pass through a Buffer.
+Buffers can not refer to each other in cycles and are automatically reference counted and deleted, so that you don't have to worry about memory leaks from them unless you explicitly call buffer_replaceDestructor.
+They store a fixed size allocation of 128-bit padded and aligned memory to work well with 128-bit SIMD intrinsics for realtime software rendering.
+
+</P><P>
+</P><IMG SRC="Images/Border.png"><P>
+</P><H2> Construction</H2><P>
+</P><P>
+The default constructor creates an empty handle, so dsr::Buffer() can be treated as null and checked using the buffer_exists function.
+Returning an empty buffer handle is common when something went wrong with an operation.
+
+</P><P>
+To create a buffer that actually stores something, call buffer_create with the number of bytes to contain as the only argument.
+The memory always start initialized to zero, which prevents random bugs.
+</P><IMG SRC="Images/Border.png"><P>
+</P><H2> Read and write data access</H2><P>
+</P><P>
+Trying to get the pointer of a non-existing Buffer will safely return a null pointer, no matter if you use buffer_getSafeData<type>(buffer, "Buffer name") or buffer_dangerous_getUnsafeData(buffer).
+You access the data by getting a SafePointer, which can later be sliced into smaller parts.
+Sometimes you can't use the SafePointer because an operating system wants a regular C pointer.
+</P><IMG SRC="Images/Border.png"><P>
+</P>
+</BODY> </HTML>

+ 89 - 0
Doc/Files.html

@@ -0,0 +1,89 @@
+<!DOCTYPE html> <HTML lang=en> <HEAD> <STYLE>
+body { background-color: #EEFFEE;  font-size: 1.0rem; font-family: Arial; max-width: 60rem;
+      color: #000000; margin: 0px;
+      padding-left:  0px; padding-right:  0px; padding-top:  0px; padding-bottom:  0px; }
+H1 {  padding-left: 10px; padding-right:  0px; padding-top: 10px; padding-bottom: 10px; font-size: 1.4rem; }
+H2 {  padding-left: 10px; padding-right:  0px; padding-top: 10px; padding-bottom:  0px; font-size: 1.2rem; }
+blockquote {
+  tab-size: 3rem;
+  color: #FFFFFF; background: #000000;
+  font-size: 1.2rem; font-family: monospace;
+  padding-left: 5px; padding-right: 5px;
+  padding-top: 5px; padding-bottom: 5px;
+}
+P {   padding-left: 20px; padding-right:  0px; padding-top:  0px; padding-bottom:  0px; }
+IMG { padding-left:  0px; padding-right:  0px; padding-top:  2px; padding-bottom:  0px;
+      max-width: 100%; }
+A { display: inline; border-radius: 4px;
+    font-size: 1.0rem; font-family: Arial; color: #000044; text-decoration: none;
+    padding-left: 4px; padding-right: 4px; padding-top: 4px; padding-bottom: 4px; }
+A:hover { color: #FFFF00; background: #000044; }
+A:active { color: #FFFFFF; background: #444444; }
+</STYLE> </HEAD> <BODY>
+<IMG SRC="Images/Title.png" ALT="Images/Title.png">
+<P>
+<A href="Manual.html">Back to main page</A>
+</P><P>
+</P><H1> Files</H1><P>The file API handles all saving and loading of data in the framework using Buffer objects.
+This makes sure that anything that can be saved to a file can be embedded into the application's binary, encrypted, compressed, sent over a network, merged into an archive with other assets, or whatever you want to do with it.
+
+</P><P>
+</P><IMG SRC="Images/Border.png"><P>
+</P><H2> Paths and current directory</H2><P>All file operations that send a file path to the operating system have the file_optimizePath function cleaning up the path for you, so it might accept a path that is actually invalid on the system if entered outside of the framework.
+Before saving a path to a file, make sure to apply file_optimizePath on the path yourself to get the absolute path that is actually used by the operating system based on the current path.
+file_optimizePath will remove following ./, collapse folder/../, reduce redundant separators and replace incorrect separators with the local system's standard, so that you can write a hardcoded relative path that works on both Windows and Posix systems.
+It can however not add or remove drive letters, so relative paths are portable paths.
+file_optimizePath can also be used to reformat slashes for another system by specifying the platform using the pathSyntax argument.
+
+</P><P>
+On Windows, you can have a path beginning with:
+
+</P><P>
+* A drive letter, such as C:\
+
+</P><P>
+* An implicit current drive root, written as \
+
+</P><P>
+* A relative path beginning from the current directory, such as folder\files\document.txt
+
+</P><P>
+On Posix, you can have a path beginning with:
+
+</P><P>
+* The logical system root on top of all physical drives and partitions, written as /
+
+</P><P>
+* The current user's home directory using ~ to replace /home/username
+
+</P><P>
+* A relative path beginning from the current directory, such as folder/files/document.txt
+</P><IMG SRC="Images/Border.png"><P>
+</P><H2> Saving and loading</H2><P>
+</P><P>
+file_loadBuffer and file_saveBuffer are the main functions for saving and loading buffers of binary data.
+
+</P><P>
+Both the string API and the image API calls these for the functions saving and loading to string, and offer alternatives directly against the Buffer objects.
+string_save also has string_saveToMemory for saving the encoded string with byte order marks and unicode code points into a Buffer.
+string_load also has string_loadFromMemory for loading a text document as if the Buffer was a file.
+image_save also has image_encode to store a PNG, Jpeg, Targa or BMP image into a Buffer.
+image_load_RgbaU8 also has image_decode_RgbaU8 to decompress the image back from the buffer.
+
+</P><P>
+</P><IMG SRC="Images/Border.png"><P>
+</P><H2> An easier alternative to std::filesystem</H2><P>
+</P><P>
+* Instead of exposing each platform's native string encoding, DSR's file API has one unified UTF-32 string format for cross-platform Unicode support in filenames.
+
+</P><P>
+* Instead of demanding the use of C++17, the static library calls the system's C API directly when needed to support C++14.
+
+</P><P>
+* Instead of using dangerous iterators (which are unprotected raw pointers) to seek through a folder, file_getFolderContent will give safe lambda callbacks for each entry.
+
+</P><P>
+Maybe std::filesystem will live longer than the Posix standard, but in that case it would be relatively easy to wrap this API on top of STD, because they have very similar functionality.
+</P><IMG SRC="Images/Border.png"><P>
+</P>
+</BODY> </HTML>

+ 22 - 0
Doc/Generator/Input/Buffers.txt

@@ -0,0 +1,22 @@
+<- Manual.html | Back to main page
+
+Title: Buffers
+Every file that is saved or loaded in the framework will pass through a Buffer.
+Buffers can not refer to each other in cycles and are automatically reference counted and deleted, so that you don't have to worry about memory leaks from them unless you explicitly call buffer_replaceDestructor.
+They store a fixed size allocation of 128-bit padded and aligned memory to work well with 128-bit SIMD intrinsics for realtime software rendering.
+
+---
+Title2: Construction
+
+The default constructor creates an empty handle, so dsr::Buffer() can be treated as null and checked using the buffer_exists function.
+Returning an empty buffer handle is common when something went wrong with an operation.
+
+To create a buffer that actually stores something, call buffer_create with the number of bytes to contain as the only argument.
+The memory always start initialized to zero, which prevents random bugs.
+---
+Title2: Read and write data access
+
+Trying to get the pointer of a non-existing Buffer will safely return a null pointer, no matter if you use buffer_getSafeData<type>(buffer, "Buffer name") or buffer_dangerous_getUnsafeData(buffer).
+You access the data by getting a SafePointer, which can later be sliced into smaller parts.
+Sometimes you can't use the SafePointer because an operating system wants a regular C pointer.
+---

+ 51 - 0
Doc/Generator/Input/Files.txt

@@ -0,0 +1,51 @@
+<- Manual.html | Back to main page
+
+Title: Files
+The file API handles all saving and loading of data in the framework using Buffer objects.
+This makes sure that anything that can be saved to a file can be embedded into the application's binary, encrypted, compressed, sent over a network, merged into an archive with other assets, or whatever you want to do with it.
+
+---
+Title2: Paths and current directory
+All file operations that send a file path to the operating system have the file_optimizePath function cleaning up the path for you, so it might accept a path that is actually invalid on the system if entered outside of the framework.
+Before saving a path to a file, make sure to apply file_optimizePath on the path yourself to get the absolute path that is actually used by the operating system based on the current path.
+file_optimizePath will remove following ./, collapse folder/../, reduce redundant separators and replace incorrect separators with the local system's standard, so that you can write a hardcoded relative path that works on both Windows and Posix systems.
+It can however not add or remove drive letters, so relative paths are portable paths.
+file_optimizePath can also be used to reformat slashes for another system by specifying the platform using the pathSyntax argument.
+
+On Windows, you can have a path beginning with:
+
+* A drive letter, such as C:\
+
+* An implicit current drive root, written as \
+
+* A relative path beginning from the current directory, such as folder\files\document.txt
+
+On Posix, you can have a path beginning with:
+
+* The logical system root on top of all physical drives and partitions, written as /
+
+* The current user's home directory using ~ to replace /home/username
+
+* A relative path beginning from the current directory, such as folder/files/document.txt
+---
+Title2: Saving and loading
+
+file_loadBuffer and file_saveBuffer are the main functions for saving and loading buffers of binary data.
+
+Both the string API and the image API calls these for the functions saving and loading to string, and offer alternatives directly against the Buffer objects.
+string_save also has string_saveToMemory for saving the encoded string with byte order marks and unicode code points into a Buffer.
+string_load also has string_loadFromMemory for loading a text document as if the Buffer was a file.
+image_save also has image_encode to store a PNG, Jpeg, Targa or BMP image into a Buffer.
+image_load_RgbaU8 also has image_decode_RgbaU8 to decompress the image back from the buffer.
+
+---
+Title2: An easier alternative to std::filesystem
+
+* Instead of exposing each platform's native string encoding, DSR's file API has one unified UTF-32 string format for cross-platform Unicode support in filenames.
+
+* Instead of demanding the use of C++17, the static library calls the system's C API directly when needed to support C++14.
+
+* Instead of using dangerous iterators (which are unprotected raw pointers) to seek through a folder, file_getFolderContent will give safe lambda callbacks for each entry.
+
+Maybe std::filesystem will live longer than the Posix standard, but in that case it would be relatively easy to wrap this API on top of STD, because they have very similar functionality.
+---

+ 6 - 0
Doc/Generator/Input/Manual.txt

@@ -14,6 +14,12 @@ Title2: APIs
 *
 <- Strings.html | String API
 
+*
+<- Buffers.html | Buffer API
+
+*
+<- Files.html | File API
+
 *
 <- Images.html | Image API
 

+ 2 - 0
Doc/Generator/Input/Starting.txt

@@ -71,6 +71,8 @@ Path=/pathToProgram
 Terminal=false
 StartupNotify=false
 CodeEnd:
+
+You can also begin your main function with file_setCurrentPath(file_getApplicationFolder()); to move into the application's folder automatically, which is supported on both Windows and Linux, but not guaranteed to work on all Posix systems because the symbolic link /proc/self/exe is not a part of the Posix standard.
 ---
 Title2: Compiling a project on Microsoft Windows
 

+ 1 - 1
Doc/Generator/Input/StyleGuide.txt

@@ -22,7 +22,7 @@ C++ style is for things that are abstracted on a higher level.
 C style is for when a byte is just a byte and you just want to manipulate it in a specific way.
 ---
 7. Don't call member methods with "this" set to nullptr.
-This would be undefined behaviour and may randomly crash.
+This would be undefined behavior and may randomly crash.
 Use global functions instead. They allow checking pointers for null
 because they are explicit arguments declared by the programmer.
 ---

+ 6 - 0
Doc/Manual.html

@@ -40,6 +40,12 @@ When you just want to code in your own pace without worrying about API deprecati
 <A href="Strings.html">String API</A>
 </P><P>
 <IMG SRC="Images/SmallDot.png">
+<A href="Buffers.html">Buffer API</A>
+</P><P>
+<IMG SRC="Images/SmallDot.png">
+<A href="Files.html">File API</A>
+</P><P>
+<IMG SRC="Images/SmallDot.png">
 <A href="Images.html">Image API</A>
 </P><P>
 </P><IMG SRC="Images/Border.png"><P>

+ 4 - 1
Doc/Starting.html

@@ -106,7 +106,10 @@ Icon=theProgramsIcon
 Path=/pathToProgram
 Terminal=false
 StartupNotify=false
-</BLOCKQUOTE></PRE></P><IMG SRC="Images/Border.png"><P>
+</BLOCKQUOTE></PRE>
+</P><P>
+You can also begin your main function with file_setCurrentPath(file_getApplicationFolder()); to move into the application's folder automatically, which is supported on both Windows and Linux, but not guaranteed to work on all Posix systems because the symbolic link /proc/self/exe is not a part of the Posix standard.
+</P><IMG SRC="Images/Border.png"><P>
 </P><H2> Compiling a project on Microsoft Windows</H2><P>
 </P><P>
 Create a project from existing code:

+ 1 - 1
Doc/StyleGuide.html

@@ -46,7 +46,7 @@ C++ style is for things that are abstracted on a higher level.
 C style is for when a byte is just a byte and you just want to manipulate it in a specific way.
 </P><IMG SRC="Images/Border.png"><P>
 7. Don't call member methods with "this" set to nullptr.
-This would be undefined behaviour and may randomly crash.
+This would be undefined behavior and may randomly crash.
 Use global functions instead. They allow checking pointers for null
 because they are explicit arguments declared by the programmer.
 </P><IMG SRC="Images/Border.png"><P>

+ 5 - 5
Source/DFPSR/api/bufferAPI.h

@@ -55,11 +55,11 @@ namespace dsr {
 	}
 
 	// Returns a clone of the buffer.
-	// Giving an empty handle returns an empty handle
+	// Giving an empty handle returns an empty handle.
 	Buffer buffer_clone(const Buffer &buffer);
 
-	// Returns the buffer's size in bytes, as given when allocating it excluding allocation padding
-	// Returns zero if buffer doesn't exist
+	// Returns the buffer's size in bytes, as given when allocating it excluding allocation padding.
+	// Returns zero if buffer doesn't exist.
 	int64_t buffer_getSize(const Buffer &buffer);
 
 	// Returns the number of reference counted handles to the buffer, or 0 if the buffer does not exist.
@@ -83,8 +83,8 @@ namespace dsr {
 		}
 	}
 
-	// Set all bytes to the same value
-	// Pre-condition: buffer exists
+	// Set all bytes to the same value.
+	// Pre-condition: buffer exists, or else an exception is thrown to warn you.
 	void buffer_setBytes(const Buffer &buffer, uint8_t value);
 }