Skip to content

Commit

Permalink
Minor cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TCA166 committed Jul 21, 2023
1 parent fe64eb5 commit 34234aa
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 41 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,9 @@
"binaryArgs": ["region", "0", "0"]
}
],
"C_Cpp.default.compilerPath": "C:\\msys64\\mingw64\\bin\\gcc.exe"
"C_Cpp.default.compilerPath": "/usr/bin/gcc",
"C_Cpp.codeAnalysis.clangTidy.checks.disabled": [
"clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling",
"clang-analyzer-security.insecureAPI.strcpy"
]
}
26 changes: 1 addition & 25 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc-11 build active file",
"command": "/usr/bin/gcc-11",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-lz"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build"
},
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: make",
"command": "make",
"args": [
"all",
"CFLAGS='-g -Wall -Wpedantic'"
"debug"
],
"options": {
"cwd": "${fileDirname}"
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ ifneq (,$(findstring MSYS,$(UNAME)))
SUBUNIT =
endif

all: CFLAGS := -O3
all: radiusGenerator modelGenerator chunkExtractor regionFileReader

debug: CFLAGS := -Wall -Werror -Wpedantic
debug: radiusGenerator modelGenerator chunkExtractor regionFileReader

cNBT.o:
gcc cNBT/buffer.c -o cNBT/buffer.o -c $(CFLAGS)
gcc cNBT/nbt_parsing.c -o cNBT/nbt_parsing.o -c $(CFLAGS)
Expand Down Expand Up @@ -69,10 +73,10 @@ model.ow: model.c
x86_64-w64-mingw32-gcc-win32 model.c -o model.ow -c $(CFLAGS)

regionFileReader.exe: regionParser.ow regionFileReader.c
x86_64-w64-mingw32-gcc-win32 regionFileReader.c regionParser.ow -o regionFileReader.exe Wl,-Bstatic -lz -Wl,-Bdynamic $(CFLAGS)
x86_64-w64-mingw32-gcc-win32 regionFileReader.c regionParser.ow -o regionFileReader.exe -lz -static $(CFLAGS)

chunkExtractor.exe: regionParser.ow chunkExtractor.c
x86_64-w64-mingw32-gcc-win32 chunkExtractor.c regionParser.ow -o chunkExtractor.exe Wl,-Bstatic -lz -Wl,-Bdynamic $(CFLAGS)
x86_64-w64-mingw32-gcc-win32 chunkExtractor.c regionParser.ow -o chunkExtractor.exe -lz -static $(CFLAGS)

generator.ow: generator.c
x86_64-w64-mingw32-gcc-win32 generator.c -o generator.ow -c $(CFLAGS)
Expand All @@ -81,7 +85,7 @@ modelGenerator.exe: generator.ow model.ow chunkParser.ow hTable.ow cNBT.ow model
x86_64-w64-mingw32-gcc-win32 modelGenerator.c generator.ow model.ow chunkParser.ow hTable.ow cNBT.ow -o modelGenerator.exe -lm $(CFLAGS)

radiusGenerator.exe: model.ow generator.ow hTable.ow chunkParser.ow regionParser.ow cNBT.ow radiusGenerator.c
x86_64-w64-mingw32-gcc-win32 radiusGenerator.c generator.ow model.ow regionParser.ow hTable.ow chunkParser.ow cNBT.ow Wl,-Bstatic -lz -Wl,-Bdynamic -lm -o radiusGenerator.exe $(CFLAGS)
x86_64-w64-mingw32-gcc-win32 radiusGenerator.c generator.ow model.ow regionParser.ow hTable.ow chunkParser.ow cNBT.ow -lm -static -lz -o radiusGenerator.exe $(CFLAGS)

windows: modelGenerator.exe chunkExtractor.exe regionFileReader.exe radiusGenerator.exe

Expand Down
8 changes: 4 additions & 4 deletions chunkParser.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int getSections(unsigned char* nbtFileData, long sz, struct section* sections){
nbtTagError("sections");
}
struct nbt_list* sectionsList = sectionsNode->payload.tag_list;
struct list_head* pos = &sectionsList->entry;
struct list_head* pos;
int n = 0;
//foreach section
list_for_each(pos, &sectionsList->entry){
Expand All @@ -77,7 +77,7 @@ int getSections(unsigned char* nbtFileData, long sz, struct section* sections){
//get the individual block data
nbt_node* blockData = nbt_find_by_name(blockNode, "data");
if(blockData != NULL){
newSection.blockData = malloc(blockData->payload.tag_long_array.length * sizeof(int64_t));
newSection.blockData = (uint64_t*)malloc(blockData->payload.tag_long_array.length * sizeof(uint64_t));
memcpy(newSection.blockData, blockData->payload.tag_long_array.data, blockData->payload.tag_long_array.length * sizeof(int64_t));
newSection.blockDataLen = blockData->payload.tag_long_array.length;
}
Expand All @@ -93,7 +93,7 @@ int getSections(unsigned char* nbtFileData, long sz, struct section* sections){
//const struct list_head* paletteHead = &palette->payload.tag_list->entry;
char** blockPalette = malloc(1 * sizeof(char*));
int i = 0;
struct list_head* paletteCur = &palette->payload.tag_list->entry;
struct list_head* paletteCur;
//foreach element in palette
list_for_each(paletteCur, &palette->payload.tag_list->entry){
//get the list entry
Expand Down Expand Up @@ -252,7 +252,7 @@ bool contains(char** arr, char* str, int arrLen){

//this code feels wrong to write in C ngl...
char** createGlobalPalette(struct section* sections, int len, int* outLen, bool freeSectionPalettes){
char** globalPalette = malloc(0);
char** globalPalette = NULL;
int j = 0;
for(int i = 0; i < len; i++){
for(int n = 0; n < sections[i].paletteLen; n++){
Expand Down
6 changes: 2 additions & 4 deletions chunkParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

//16x16x16 big section of a chunk
struct section{
short y;

//we ignore the biomes because we don't need that data

uint64_t* blockData; //raw nbt file block data
int blockDataLen; //the length of blockData in bytes
char** blockPalette;
int blockDataLen; //the length of blockData in bytes
int paletteLen;
short y;
};

//A block structure with it's own coordinates and a string containing it's type
Expand Down
12 changes: 8 additions & 4 deletions model.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ struct object deCubeObject(struct cube* c){
result.y = objCoordCorrect(c, y, dist);
result.z = objCoordCorrect(c, z, dist);
result.faceCount = 0;
result.faces = malloc(0);
result.faces = NULL;
for(int i = 0; i < 6; i++){
if(c->faces[i] != NULL){
result.faces = realloc(result.faces, (result.faceCount + 1) * sizeof(struct objFace));
Expand Down Expand Up @@ -436,6 +436,8 @@ hashTable* getMaterials(char* filename){
hashTable* result = initHashTable(objCount);
char* token = strtok(bytes, "\n");
struct material newMaterial;
newMaterial.name = NULL;
newMaterial.d = 0;
while(token != NULL){ //foreach line
int len = strlen(token);
if(len > 7){
Expand Down Expand Up @@ -497,6 +499,8 @@ hashTable* readWavefront(char* filename, hashTable* materials, int side){
newObject.x = -1;
newObject.y = -1;
newObject.z = -1;
newObject.vertexCount = 0;
newObject.faceCount = 0;
struct material* nextM = NULL;
while(token != NULL){
switch(token[0]){
Expand All @@ -520,10 +524,10 @@ hashTable* readWavefront(char* filename, hashTable* materials, int side){
//this should 'reset' the newObject
newObject.faceCount = 0;
//free(newObject.faces);
newObject.faces = malloc(0);
newObject.faces = NULL;
newObject.vertexCount = 0;
//free(newObject.vertices);
newObject.vertices = malloc(0);
newObject.vertices = NULL;
if(nextM != NULL){
newObject.m = nextM;
nextM = NULL;
Expand Down Expand Up @@ -552,7 +556,7 @@ hashTable* readWavefront(char* filename, hashTable* materials, int side){
newObject.vertexCount++;
break;
case 'f':;
int* vertices = malloc(0);
int* vertices = NULL;
char* num = calloc(1, 1);
num[0] = '\0';
int n = 0;
Expand Down
1 change: 1 addition & 0 deletions radiusGenerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,5 +386,6 @@ int main(int argc, char** argv){
FILE* outFile = fopen(outFilename, "w");
fwrite(result, currentSize, 1, outFile);
fclose(outFile);
free(result);
return EXIT_SUCCESS;
}

0 comments on commit 34234aa

Please sign in to comment.