Compare commits
	
		
			No commits in common. "6e4dd4da71aefbd7240bc5ea1e35de0c72ae78df" and "ec445d7a442026c418e2ff021cffdab0dba9b9cb" have entirely different histories. 
		
	
	
		
			6e4dd4da71
			...
			ec445d7a44
		
	
		
							
								
								
									
										37
									
								
								build.sh
								
								
								
								
							
							
						
						
									
										37
									
								
								build.sh
								
								
								
								
							|  | @ -1,40 +1,13 @@ | ||||||
| #!/bin/bash |  | ||||||
| 
 |  | ||||||
| if [ -z "$CXX" ]; then |  | ||||||
|     CXX="c++" |  | ||||||
| fi |  | ||||||
| if [ -z "$CXXFLAGS" ]; then |  | ||||||
|     CXXFLAGS="-std=c++20 -Wall" |  | ||||||
| fi |  | ||||||
| CXX_WITH_FLAGS="$CXX $CXXFLAGS" |  | ||||||
| 
 |  | ||||||
| # `.cpp` files in src/lib will be automatically picked up and compiled into dynamic libraries. |  | ||||||
| echo "Building libs..." | echo "Building libs..." | ||||||
| mkdir -pv bin/lib | mkdir -pv bin/lib | ||||||
| for lib in $(find ./src/lib -name "*.cpp"); do | for lib in $(find ./src/lib -name "*.cpp"); do | ||||||
|     COMPILE_COMMAND="$CXX_WITH_FLAGS -shared -o $(sed -e 's/^.\/src/.\/bin/;s/cpp$/so/' <<< $lib) $lib" |     echo "Compiling $lib" | ||||||
|     echo $COMPILE_COMMAND |     c++ -shared -o $(sed -e 's/^.\/src/.\/bin/;s/cpp$/so/' <<< $lib) $lib; | ||||||
|     $COMPILE_COMMAND |  | ||||||
| done | done | ||||||
| 
 | 
 | ||||||
| 
 | echo "Building tools..." | ||||||
|  | mkdir -pv bin/tools | ||||||
| # Commands for every program need to be given individually because we can't | # Commands for every program need to be given individually because we can't | ||||||
| # just add all shared libraries to all programs. | # just add all shared libraries to all programs. | ||||||
| # Or can we? Idk, cba to find out. | # Or can we? Idk, cba to find out. | ||||||
| 
 | c++ src/tools/dumpnbt.cpp -Lbin/lib -lnbt -o bin/tools/dumpnbt | ||||||
| # How to build a tool: Tell the compiler where to find shared libraries and |  | ||||||
| #       which libraries to use. |  | ||||||
| # Example: shared libraries are in bin/lib => -Lbin/lib |  | ||||||
| #       one of the libraries in that directory is libnbt.so |  | ||||||
| #        => use with -lnbt (omit prefix lib and suffix .so) |  | ||||||
| # How to run a tool: specify the library path to use for the dynamic linker |  | ||||||
| #       when running a program |  | ||||||
| # Example: LD_LIBRARY_PATH=bin/lib bin/tools/dumpnbt |  | ||||||
| echo "Building tools..." |  | ||||||
| mkdir -pv bin/tools |  | ||||||
| # add compile commands to this variable |  | ||||||
| COMPILE_COMMANDS=" |  | ||||||
| set -v |  | ||||||
| $CXX_WITH_FLAGS src/tools/dumpnbt.cpp -Lbin/lib -lnbt -o bin/tools/dumpnbt |  | ||||||
| " |  | ||||||
| sh <<< $COMPILE_COMMANDS |  | ||||||
|  |  | ||||||
|  | @ -1,22 +1,3 @@ | ||||||
| #include <bit> | int blob() { | ||||||
| 
 |     return 1; | ||||||
| // This is just an example for how to find out if the system is big endian or little endian. Do not use this.
 |  | ||||||
| int endianness_example() { |  | ||||||
|     if constexpr (std::endian::native == std::endian::big) |  | ||||||
|     { |  | ||||||
|         // Big-endian system
 |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
|     else if constexpr (std::endian::native == std::endian::little) |  | ||||||
|     { |  | ||||||
|         // Little-endian system
 |  | ||||||
|         return 1; |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         // Something else
 |  | ||||||
|         return 2; |  | ||||||
|         // How did we even end up here?
 |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| 
 |  | ||||||
|  |  | ||||||
|  | @ -1,20 +1 @@ | ||||||
| // information taken from https://wiki.vg/NBT
 | int blob(); | ||||||
| // This is an attempt at creating a uniform model for all NBT tags to allow for a uniform interface based on subclassing a single NBT tag super class.
 |  | ||||||
| 
 |  | ||||||
| // NBT tags have a type (signed or unsigned?), optionally a name, optionally content type, optionally a size (signed), and content
 |  | ||||||
| // Whether the type id byte is signed or not is unknown at this point. All other numbers are signed unless specified otherwise.
 |  | ||||||
| // All tag types:
 |  | ||||||
| // generic representation:  Tag(Byte:tag_type, String:name, byte[]:content, Byte:content_type, int32:size)
 |  | ||||||
| // end:                     Tag( 0, "",          None,           0, 0) => used to determine the end of a compound tag, only the type gets stored
 |  | ||||||
| // byte:                    Tag( 1, String:name, byte:content,   1, 1) => a single signed byte, size and content type not stored
 |  | ||||||
| // int16:                   Tag( 2, String:name, int16:content,  2, 2) => big endian signed 16 bit integer, size and content type not stored
 |  | ||||||
| // int32:                   Tag( 3, String:name, int32:content,  3, 4) => big endian signed 32 bit integer, size and content type not stored
 |  | ||||||
| // int64:                   Tag( 4, String:name, int64:content,  4, 8) => big endian signed 64 bit integer, size and content type not stored
 |  | ||||||
| // float32:                 Tag( 5, String:name, float32:content,5, 4) => big endian 32 bit floating point number, size and content type not stored
 |  | ||||||
| // float64:                 Tag( 6, String:name, float64:content,6, 8) => big endian 64 bit floating point number, size and content type not stored
 |  | ||||||
| // byte[]:                  Tag( 7, String:name, byte[]:content, 1, int32:size) => content stored prefixed with size, content type not stored
 |  | ||||||
| // String:                  Tag( 8, String:name, byte[]:content, 8, uint16:size) => Java style modified UTF-8 string, size is unique bc it's 16 bit and unsigned, content stored prefixed with size, content type not stored
 |  | ||||||
| // Tag[] (list):            Tag( 9, String:name, Tag[]:content,  byte:content_type, int32:size) => list of nameless tags of the same type prefixed by (in order) content type and size, no closer specification as to what namelessness entails
 |  | ||||||
| // Tag[] (compound):        Tag(10, String:name, Tag[]:content,  None, int32:size) => list of tags, last tag is always an end tag, size and content type not stored
 |  | ||||||
| // int32[]:                 Tag(11, String:name, int32[]:content,3, int32:size) => list of 32 bit signed integers prefixed with its size, content type not stored, endianness unknown at this point
 |  | ||||||
| // int64[]:                 Tag(12, String:name, int64[]:content,4, int32:size) => list of 64 bit signed integers prefixed with its size, content type not stored, endianness unknown at this point
 |  | ||||||
|  |  | ||||||
|  | @ -1,5 +1,5 @@ | ||||||
| #include "../lib/libnbt.h" | #include "../lib/libnbt.h" | ||||||
| 
 | 
 | ||||||
| int main(int argc, char* argv[]) { | int main(int argc, char* argv[]) { | ||||||
|     return 0; |     return blob(); | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue