Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
c0579ee
Use uint8 for colors in Python
ZynoXelek Jul 3, 2024
247b7d2
Use uint8 for colors in C
ZynoXelek Jul 4, 2024
440f107
Adapt old complete map loader to colors as int
ZynoXelek Jul 4, 2024
c8f9048
Add main.c to generate a custom map with user inputs (Lacks seed and …
ZynoXelek Jul 4, 2024
2586e7b
Remove altitude storage in layer after chunk generation
ZynoXelek Jul 7, 2024
27dc019
Remove map altitude storage and add getFullMap() method
ZynoXelek Jul 7, 2024
210a2b4
Frees layers altitude values after chunk generation (C)
ZynoXelek Jul 7, 2024
2072214
Removes altitude array in map structure. Chunks are directly modified.
ZynoXelek Jul 7, 2024
e9d441f
get custom bytes representation for ints and floats
BlueNZ Jul 9, 2024
3f098d7
bytes for numpy uint8
BlueNZ Jul 9, 2024
6176bc6
decoding number from bytes
BlueNZ Jul 9, 2024
07afdf5
debuging float encoding
BlueNZ Jul 10, 2024
b7d2593
grid encoding
BlueNZ Jul 10, 2024
0c39346
gradientGrid as main
BlueNZ Jul 10, 2024
27b33e4
layer encoding and decoding 1st attempt
BlueNZ Jul 10, 2024
ad87bfa
Seems to work
BlueNZ Jul 10, 2024
cb4914f
write chunk
BlueNZ Jul 10, 2024
22b50f3
modularity of layer encoding
BlueNZ Jul 12, 2024
5933e0f
layer modularity encoding testing
BlueNZ Jul 12, 2024
2f6ed54
uninitialised altitude arrays
BlueNZ Jul 12, 2024
6418179
Chunk encoding and decoding
BlueNZ Jul 12, 2024
a1e5929
virtual chunks encoding
BlueNZ Jul 12, 2024
e8f0880
map encoding
BlueNZ Jul 12, 2024
d073420
map encoding testing
BlueNZ Jul 12, 2024
e73d3e1
encoding complete map
BlueNZ Jul 12, 2024
6f5ff19
decoding completemap
BlueNZ Jul 12, 2024
4267737
completeMap encoding testing
BlueNZ Jul 12, 2024
f3d4774
int encoding modularity
BlueNZ Jul 21, 2024
571cbb2
float encoding modularity
BlueNZ Jul 21, 2024
d2050c7
File reading and closing
BlueNZ Jul 21, 2024
484b16a
File writing and reading testing for completemap
BlueNZ Jul 21, 2024
69eec7b
File reading
BlueNZ Jul 21, 2024
d8e53ea
global read function
BlueNZ Jul 24, 2024
6be914e
wrtie global function
BlueNZ Jul 24, 2024
fb56c0e
testing global read and write
BlueNZ Jul 24, 2024
a2a0702
lists encoding
BlueNZ Jul 27, 2024
61688dc
debugging
BlueNZ Jul 27, 2024
7ffc4ae
comments on general functions
BlueNZ Jul 27, 2024
4bc6baa
write func documentation
BlueNZ Jul 27, 2024
70c4259
read func doc
BlueNZ Jul 27, 2024
c82e86c
readAll
BlueNZ Jul 27, 2024
102d7e6
C basic file structure
BlueNZ Jul 27, 2024
be92dbb
C encoding numbers
BlueNZ Jul 27, 2024
cd8cfed
C encoding number headers
BlueNZ Jul 27, 2024
455b5d4
C number decoding
BlueNZ Jul 27, 2024
acc125c
C number encoding testing
BlueNZ Jul 27, 2024
2b95992
C bytes structure
BlueNZ Jul 28, 2024
d78b977
C headers changes
BlueNZ Jul 28, 2024
537beeb
C testing binary number encoding
BlueNZ Jul 28, 2024
4e27585
C decoding ints
BlueNZ Jul 28, 2024
fcafdca
C number decoding
BlueNZ Jul 28, 2024
bb7ef8f
C debugging double decoding
BlueNZ Jul 28, 2024
0151a30
C gradgrid encoding
BlueNZ Jul 28, 2024
7a4d169
C gradgrid decoding
BlueNZ Jul 28, 2024
90a6d11
C testing and debugging grid decoding
BlueNZ Jul 28, 2024
90eeb83
C layer encoding
BlueNZ Jul 28, 2024
25e0b4f
C testing layer encoding
BlueNZ Jul 28, 2024
ae7658e
C decoding layer
BlueNZ Jul 29, 2024
e7f2da4
layer decoding testing
BlueNZ Jul 29, 2024
b809b88
C layer decoding altitude or not
BlueNZ Jul 29, 2024
beef888
C chunk encoding
BlueNZ Jul 29, 2024
297d384
C testing and debugging chunk encoding
BlueNZ Jul 29, 2024
bbee8bd
C chunk decoding
BlueNZ Jul 29, 2024
5d54f3f
C chunk number of layer decoding
BlueNZ Jul 30, 2024
ad97b65
Encoding testing
BlueNZ Jul 30, 2024
b23a89c
C map decoding and testing
BlueNZ Jul 31, 2024
40e2ee9
C ensuring proper functions args in tests
BlueNZ Jul 31, 2024
e360774
C color encoding and decoding + testing
BlueNZ Jul 31, 2024
57c6f45
C completeMap encoding
BlueNZ Jul 31, 2024
c5ac048
C completemap decoding and testing
BlueNZ Jul 31, 2024
939613a
C testing more readable
BlueNZ Jul 31, 2024
2e504b0
C doc encoding
BlueNZ Aug 1, 2024
2c2a480
C doc interpreter functions and structs
BlueNZ Aug 1, 2024
eb4e0d3
C doc decoding functions
BlueNZ Aug 1, 2024
b416bdf
C doc changed functions
BlueNZ Aug 1, 2024
9ecd150
C writes bytes in file
BlueNZ Aug 7, 2024
a635be3
C write bytes inf file func header
BlueNZ Aug 7, 2024
dd56b5b
C write file testing
BlueNZ Aug 7, 2024
fb5302f
C read bytes file
BlueNZ Aug 7, 2024
02b3faa
C test file reading
BlueNZ Aug 7, 2024
5c6af0a
C main file saving
BlueNZ Aug 7, 2024
abd7f7b
C main file saving works
BlueNZ Aug 7, 2024
b1fb93f
Comments
BlueNZ Aug 7, 2024
b67ed35
File doc
BlueNZ Aug 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ MANIFEST
.vscode

# Files saved
saves/
saves/*

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
19 changes: 12 additions & 7 deletions C/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ $(COMP)%.o : $(SRC)%.c
$(CC) -c $< -o $@


# Main --------------------------------------


main: $(COMP)main.o $(COMP)mapGenerator.o $(COMP)map.o $(COMP)chunk.o $(COMP)layer.o $(COMP)gradientGrid.o $(COMP)loadingBar.o $(COMP)interpreter.o
$(CC) $^ -o $(BIN)$@ $(LFLAGS)

# Tests -------------------------------------

Expand All @@ -58,22 +60,25 @@ test_unicode: $(COMP)test_unicode.o
test_loadingBar: $(COMP)test_loadingBar.o $(COMP)loadingBar.o
$(CC) $^ -o $(BIN)$@

test_gradientGrid: $(COMP)test_gradientGrid.o $(COMP)gradientGrid.o $(COMP)loadingBar.o
test_gradientGrid: $(COMP)test_gradientGrid.o $(COMP)gradientGrid.o $(COMP)loadingBar.o $(COMP)interpreter.o
$(CC) $^ -o $(BIN)$@ $(LFLAGS)

test_layer: $(COMP)test_layer.o $(COMP)layer.o $(COMP)gradientGrid.o $(COMP)loadingBar.o
test_layer: $(COMP)test_layer.o $(COMP)layer.o $(COMP)gradientGrid.o $(COMP)loadingBar.o $(COMP)interpreter.o
$(CC) $^ -o $(BIN)$@ $(LFLAGS)

test_chunk: $(COMP)test_chunk.o $(COMP)chunk.o $(COMP)layer.o $(COMP)gradientGrid.o $(COMP)loadingBar.o
test_chunk: $(COMP)test_chunk.o $(COMP)chunk.o $(COMP)layer.o $(COMP)gradientGrid.o $(COMP)loadingBar.o $(COMP)interpreter.o
$(CC) $^ -o $(BIN)$@ $(LFLAGS)

test_map: $(COMP)test_map.o $(COMP)map.o $(COMP)chunk.o $(COMP)layer.o $(COMP)gradientGrid.o $(COMP)loadingBar.o
test_map: $(COMP)test_map.o $(COMP)map.o $(COMP)chunk.o $(COMP)layer.o $(COMP)gradientGrid.o $(COMP)loadingBar.o $(COMP)interpreter.o
$(CC) $^ -o $(BIN)$@ $(LFLAGS)

test_mapGenerator: $(COMP)test_mapGenerator.o $(COMP)mapGenerator.o $(COMP)map.o $(COMP)chunk.o $(COMP)layer.o $(COMP)gradientGrid.o $(COMP)loadingBar.o
test_mapGenerator: $(COMP)test_mapGenerator.o $(COMP)mapGenerator.o $(COMP)map.o $(COMP)chunk.o $(COMP)layer.o $(COMP)gradientGrid.o $(COMP)loadingBar.o $(COMP)interpreter.o
$(CC) $^ -o $(BIN)$@ $(LFLAGS)

test_interpreter: $(COMP)test_interpreter.o $(COMP)interpreter.o $(COMP)mapGenerator.o $(COMP)map.o $(COMP)chunk.o $(COMP)layer.o $(COMP)gradientGrid.o $(COMP)loadingBar.o
$(CC) $^ -o $(BIN)$@ $(LFLAGS)

test_all : test_unicode test_loadingBar test_gradientGrid test_layer test_chunk test_map test_mapGenerator
test_all : test_unicode test_loadingBar test_gradientGrid test_layer test_chunk test_map test_mapGenerator test_interpreter

# Valgrind ----------------------------------

Expand Down
49 changes: 33 additions & 16 deletions C/headers/chunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @file chunk.h
* @author Zyno and BlueNZ
* @brief Header to chunk structure and functions
* @version 0.2
* @date 2024-06-19
* @version 0.3
* @date 2024-07-29
*
*/

Expand Down Expand Up @@ -100,13 +100,22 @@ chunk* initChunk(int width, int height, int number_of_layers, double layers_fact



/**
* @brief Generates a new base altitude to be set to a chunk.
*
* @return double : the base_altitude value.
*/
double generateBaseAltitude();

/**
* @brief Regenerates the given chunk final altitude values from its layers and layers factors.
*
* @param chunk (chunk*) : the pointer to the initialized chunk structure to regenerate the altitude values.
* @param display_loading (unsigned int) : the given value defines the behaviour.
* * If `0` the loading bars won't be printed.
* * If `> 0` the loading bars will be printed with a number of indent equal to `display_loading - 1`.
*
* @note each layer will see its values free'd at this point. They can still be regenerated if needed using the dedicated function.
*/
void regenerateChunk(chunk* chunk, unsigned int display_loading);

Expand Down Expand Up @@ -174,26 +183,17 @@ chunk* newChunkFromGradients(int width, int height, int number_of_layers, gradie
chunk* newChunk(int number_of_layers, int gradGrids_width[number_of_layers], int gradGrids_height[number_of_layers], int size_factors[number_of_layers],
double layers_factors[number_of_layers], unsigned int display_loading);

//TODO ? signature could be changed to avoid passing useless parameters -> `chunk_width` and `chunk_height` instead of `gradGrids_width`, `gradGrids_height` and `size_factors`
/**
* @brief Generates a new virtual chunk structure with the given parameters. It does not possess any altitude values and is used as a way to store
* the data of boundary conditions with its `base_altitude` parameter.
*
* @param number_of_layers (int) : the number of layers passed.
* @param gradGrids_width (int[number_of_layers]) : the array of gradientGrid width to compute the final width this virtual chunk should have.
* @param gradGrids_height (int[number_of_layers]) : the array of gradientGrid height to compute the final height this virtual chunk should have.
* @param size_factors (int[number_of_layers]) : the array of size factors to compute the final dimensions of this virtual chunk.
* @param layers_factors (double[number_of_layers]) : the array of layers factors to be stored in the virtual chunk.
* @return chunk* : the pointer to the newly generated virtual chunk structure.
* @param chunk_width (int) : the width size of the virtuak chunk if it had altitude values.
* @param chunk_height (int) : the height size of the virtuak chunk if it had altitude values.
* @param regenerate (bool) : should the base altitude value be generated.
*
* @warning The `size_factors` array should match the `gradGrids_width` and `gradGrids_height` arrays such that
* `(gradGrid_dimensions - 1) * size_factor = constant`. In case it would not be the case, the chunk structure will still
* be generated but its dimensions will be wrong : it will simply use the first value.
*
* @note The arrays does not need to be dynamically allocated and their content will be copied in the structure.
* @return chunk* : the pointer to the newly generated virtual chunk structure.
*/
chunk* newVirtualChunk(int number_of_layers, int gradGrids_width[number_of_layers], int gradGrids_height[number_of_layers], int size_factors[number_of_layers],
double layers_factors[number_of_layers]);
chunk* newVirtualChunk(int chunk_width, int chunk_height, bool regenerate);


/**
Expand Down Expand Up @@ -223,6 +223,23 @@ chunk* newAdjacentChunk(chunk* north_chunk, chunk* west_chunk, unsigned int disp
chunk* copyChunk(chunk* p_chunk);


/**
* @brief Encodes a chunk struct in a binary format.
*
* @param chk (chunk*) : a pointer to the chunk struct.
* @return bytes : the byte string representing the encoded struct.
*/
bytes bytesChunk(chunk* chk);

/**
* @brief Decodes a chunk struct from a formatted byte string.
*
* @param bytes (bytes) : the formatted byte string.
* @return tuple_obj_bytes : the decoded chunk and the byte string (with the start index updated).
*/
tuple_obj_bytes nextChunk(bytes bytes);



/**
* @brief Writes the chunk structure to a file at the given path.
Expand Down
19 changes: 19 additions & 0 deletions C/headers/gradientGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#ifndef GRADIENT_GRID
#define GRADIENT_GRID

#include "interpreter.h"

// ----- Structure definition -----

/**
Expand Down Expand Up @@ -145,6 +147,23 @@ gradientGrid* readGradientGridFile(char path[]);



/**
* @brief Encodes a gradient grid struct in a binary format.
*
* @param gradGrid (gradientGrid*) : a pointer to the gradient grid struct.
* @return bytes : the byte string representing the encoded struct.
*/
bytes bytesGradientGrid(gradientGrid* grid);

/**
* @brief Decodes a gradient grid struct from a formatted byte string.
*
* @param bytes (bytes) : the formatted byte string.
* @return tuple_obj_bytes : the decoded gradient grid and the byte string (with the start index updated).
*/
tuple_obj_bytes nextGradientGrid(bytes bytes);


/**
* @brief Prints in the terminal the given gradient grid.
*
Expand Down
178 changes: 178 additions & 0 deletions C/headers/interpreter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/**
* @file interpreter.h
* @author BlueNZ
* @brief Header to interpreter functions
* @version 0.1
* @date 2024-07-27
*
*/

#ifndef INTERP
#define INTERP

// ------- Structure definition ------- //

typedef unsigned char byte; //type used as bytes
typedef char* object; //an alias for pointers

/**
* @brief a simple implementation of byte strings
*/
typedef struct bytes {
byte* bytes; // the byte array
int size; // to keep track of the size of the byte array
int start; // where to look for the current byte in the array
} bytes;

/**
* @brief a placeholder to return both an object (a number or a struct) and a byte string (bytes)
*/
typedef struct tuple_obj_bytes {
object object; // a pointer to the object
bytes bytes; // the byte string
} tuple_obj_bytes;


// ------- Constants ------- //

#define BYTE_TRUE (byte) 1
#define BYTE_FALSE (byte) 0
#define INT_BITS_NBR 24 //24 should be a multiple of 8
#define FLOAT_BITS_EXP 5 //5 should be < 8
#define FLOAT_BITS_MANTISS 18
#define FLOAT_BITS_NBR (1 + FLOAT_BITS_EXP + FLOAT_BITS_MANTISS) //24 should be a multiple of 8

#define GRID_ENCODING (byte) 1
#define LAYER_ENCODING (byte) 2
#define CHUNK_ENCODING (byte) 3
#define MAP_ENCODING (byte) 4
#define COMPLETE_MAP_ENCODING (byte) 5

#define BYTES_VERSION (byte) 0



// ------- Functions ------- //

/**
* @brief 'Fast' int powers.
*
* @param nbr (int) : the nbr to be exponantiated
* @param exp (int) : the exponant
* @return int : the result of nbr^exp.
*/
int intpow(int nbr, int exp);



/**
* @brief Deallocates the byte array of a bytes struct
*
* @param b (bytes) : the bytes struct
*/
void freeBytes(bytes b);

/**
* @brief Auxiliary function to print bytes (update a string with the hexadecimal representation of a byte).
*
* @param c (unsigned char) : the byte to print
* @param res (char*) : the string to update
* @return char* : the updated string
*/
char* hex(unsigned char c, char* res);

/**
* @brief Prints a bytes struct
*
* @param bytes (bytes) : the bytes to print
* @param start (char*) : a string to print beforehand
* @param end (char*) : a string to print after ("\n" for instance)
*/
void printBytes(bytes bytes, char* start, char* end);

/**
* @brief Updates a byte string starting from a given index with the values of another byte string
*
* @param b (bytes) : the bytes to update
* @param bb (bytes) : the bytes to use for updating
* @param start (int) : the starting index in b
*/
void concatBytes(bytes b, bytes bb, int start);



/**
* @brief Encodes an unsigned 8bits int.
*
* @param nbr (__uint8_t) : the unsigned int.
* @return bytes : the byte string representing the encoded number.
*/
bytes bytesUint8(__uint8_t nbr);

/**
* @brief Encodes an int.
*
* @param nbr (int) : the int.
* @return bytes : the byte string representing the encoded number.
*/
bytes bytesInt(int nbr);

/**
* @brief Encodes a double.
*
* @param nbr (double) : the double.
* @return bytes : the byte string representing the encoded number.
*/
bytes bytesDouble(double nbr);



/**
* @brief Decodes an encoded unsigned 8bits int.
*
* @param bytes (bytes) : the encoded byte string.
* @return tuple_obj_bytes : the byte string with updated start index and a pointer to the number decoded.
*/
tuple_obj_bytes nextUint8(bytes bytes);

/**
* @brief Decodes an encoded int.
*
* @param bytes (bytes) : the encoded byte string.
* @return tuple_obj_bytes : the byte string with updated start index and a pointer to the number decoded.
*/
tuple_obj_bytes nextInt(bytes bytes);

/**
* @brief Decodes an encoded double.
*
* @param bytes (bytes) : the encoded byte string.
* @return tuple_obj_bytes : the byte string with updated start index and a pointer to the number decoded.
*/
tuple_obj_bytes nextDouble(bytes bytes);



/**
* @brief Writes a bytes string in a specified file
*
* @param bytes (bytes) : the byte string.
* @param path (char*) : the folder path.
* @param name (char*) : the file name (should end with '.data').
*/
void writeBytesFile(bytes bytes, char* path, char* name);

/**
* @brief Read bytes from a specified file
*
* @param path (char*) : the file path.
* @return (bytes) : read bytes
*/
bytes readBytesFile(char* path);






#endif
Loading