-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit, project assets, makefile build setup
- Loading branch information
0 parents
commit f4266ba
Showing
26 changed files
with
2,674 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
main.c | ||
valgrind-out.txt | ||
VLC.sh | ||
output.txt | ||
*.a | ||
*.dll | ||
SDL2/ | ||
build-win/ | ||
build-linux/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
CC=gcc | ||
CCWIN=x86_64-w64-mingw32-gcc | ||
WINFLAGS=-lmingw32 | ||
CFLAGS=-lSDL2main -lSDL2 -lSDL2_ttf -lSDL2_image -lm | ||
CDEBUGFLAGS=-Wall -g | ||
WINLIBS=-ISDL2/include/ -LSDL2/lib/ | ||
ENTRYPOINT=main.c | ||
FILES=cflags.h cflags.c systems.h systems.c asciiEsc.h entities.h entities.c hashMap.h hashMap.c vector.h vector.c memarena.h memarena.c bitmasks.h bitmasks.c graphicsutils.c graphicsutils.h inpututils.c inpututils.h mathutils.c mathutils.h sdlfileutils.c sdlfileutils.h | ||
OUT=xiprog | ||
BUILDWIN=build-win/ | ||
BUILDLINUX=build-linux/ | ||
|
||
compile-linux: | ||
rm -rf $(BUILDLINUX) | ||
mkdir $(BUILDLINUX) | ||
$(CC) $(ENTRYPOINT) $(FILES) $(CFLAGS) -o $(OUT) | ||
mv $(OUT) $(BUILDLINUX) | ||
|
||
debug-linux: | ||
rm -rf $(BUILDLINUX) | ||
mkdir $(BUILDLINUX) | ||
$(CC) $(ENTRYPOINT) $(FILES) $(CFLAGS) $(CDEBUGFLAGS) -o $(OUT)-debug | ||
mv $(OUT)-debug $(BUILDLINUX) | ||
|
||
compile-win: | ||
rm -rf $(BUILDWIN) | ||
mkdir $(BUILDWIN) | ||
$(CCWIN) $(ENTRYPOINT) $(FILES) $(WINLIBS) $(WINFLAGS) $(CFLAGS) -o $(OUT).exe | ||
mv $(OUT).exe $(BUILDWIN) | ||
cp SDL2_image.dll $(BUILDWIN) | ||
cp SDL2.dll $(BUILDWIN) | ||
cp SDL2_ttf.dll $(BUILDWIN) | ||
|
||
debug-win: | ||
rm -rf $(BUILDWIN) | ||
mkdir $(BUILDWIN) | ||
$(CCWIN) $(ENTRYPOINT) $(FILES) $(WINLIBS) $(WINFLAGS) $(CFLAGS) $(CDEBUGFLAGS) -o $(OUT)-debug.exe | ||
mv $(OUT)-debug.exe $(BUILDWIN) | ||
cp SDL2_image.dll $(BUILDWIN) | ||
cp SDL2.dll $(BUILDWIN) | ||
cp SDL2_ttf.dll $(BUILDWIN) | ||
|
||
compile-all: | ||
make compile-linux | ||
make compile-win | ||
|
||
debug-all: | ||
make debug-linux | ||
make debug-win | ||
|
||
clean: | ||
rm -rf $(BUILDWIN) | ||
rm -rf $(BUILDLINUX) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#ifndef ASCII_ESC_H | ||
#define ASCII_ESC_H | ||
|
||
// TOKEN_BASED | ||
|
||
#define A_ESC "\033" | ||
#define A_ESC_CSI "\033[" | ||
|
||
#define A_RETURN "\r" | ||
#define A_BACK "\b" | ||
#define A_ENDL "\n" | ||
|
||
#define A_CURSOR_HOME "\033[H" | ||
#define A_COORDS "f" | ||
|
||
#define A_UP_ONE "\033[M" | ||
#define A_UP_HERE "A" | ||
#define A_UP_FRONT "F" | ||
#define A_DOWN_HERE "B" | ||
#define A_DOWN_FRONT "E" | ||
#define A_RIGHT "C" | ||
#define A_LEFT "D" | ||
|
||
#define A_GOTO_C "G" | ||
#define A_SAVE_DEC "\033 7" | ||
#define A_SAVE_SCO "\033[s" | ||
#define A_LOAD_DEC "\033 8" | ||
#define A_LOAD_SCO "\033[u" | ||
|
||
|
||
#define A_ERASE_TO_EOF "\033[0J" | ||
#define A_ERASE_TO_SOF "\033[1J" | ||
#define A_ERASE_SCREEN "\033[2J" | ||
#define A_ERASE_SAVED "\033[3J" | ||
|
||
#define A_ERASE_TO_EOL "\033[0K" | ||
#define A_ERASE_TO_SOL "\033[1K" | ||
#define A_ERASE_LINE "\033[2K" | ||
|
||
#define A_BOLD "\033[1m" | ||
#define A_BOLD_OFF "\033[22m" | ||
#define A_UNDERLINE "\033[4m" | ||
#define A_UNDERLINE_OFF "\033[24m" | ||
#define A_ITALICS "\033[3m" | ||
#define A_ITALICS_OFF "\033[23m" | ||
#define A_BLINK "\033[5m" | ||
#define A_BLINK_OFF "\033[25m" | ||
#define A_DIM "\033[2m" | ||
#define A_DIM_OFF "\033[22m" | ||
#define A_INVERT "\033[7m" | ||
#define A_INVERT_OFF "\033[27m" | ||
#define A_HIDE "\033[8m" | ||
#define A_HIDE_OFF "\033[28m" | ||
#define A_STRIKETHROUGH "\033[9m" | ||
#define A_STRIKETHROUGH_OFF "\033[29m" | ||
#define A_DOUBLE_UNDERLINE "\033[21m" | ||
#define A_DOUBLE_UNDERLINE_OFF "\033[24m" | ||
|
||
#define A_BLACK_F "\033[30m" | ||
#define A_RED_F "\033[31m" | ||
#define A_GREEN_F "\033[32m" | ||
#define A_YELLOW_F "\033[33m" | ||
#define A_BLUE_F "\033[34m" | ||
#define A_MAGENTA_F "\033[35m" | ||
#define A_CYAN_F "\033[36m" | ||
#define A_WHITE_F "\033[37m" | ||
#define A_DEFAULT_F "\033[39m" | ||
|
||
#define A_BLACK_B "\033[40m" | ||
#define A_RED_B "\033[41m" | ||
#define A_GREEN_B "\033[42m" | ||
#define A_YELLOW_B "\033[43m" | ||
#define A_BLUE_B "\033[44m" | ||
#define A_MAGENTA_B "\033[45m" | ||
#define A_CYAN_B "\033[46m" | ||
#define A_WHITE_B "\033[47m" | ||
#define A_DEFAULT_B "\033[49m" | ||
|
||
#define A_RESET "\033[0m" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
#include "bitmasks.h" | ||
#include <stdio.h> | ||
#include <stddef.h> | ||
#include <stdlib.h> | ||
#include <stdarg.h> | ||
|
||
VECTOR_SOURCE(vu64_t, uint64_t) | ||
VECTOR_SOURCE(vu32_t, uint32_t) | ||
|
||
uint8_t maskCompare(vu64_t* reference, vu64_t* candidate){ | ||
uint32_t i; | ||
if (reference->size > candidate->size){ | ||
return 0; | ||
} | ||
uint64_t referenceChunk, candidateChunk; | ||
for (i = 0;i<reference->size;++i){ | ||
referenceChunk = vu64_tGet(reference, i); | ||
candidateChunk = vu64_tGet(candidate, i); | ||
if ((referenceChunk & candidateChunk) != referenceChunk){ | ||
return 0; | ||
} | ||
} | ||
return 1; | ||
} | ||
|
||
uint8_t maskEquals(vu64_t* a, vu64_t* b){ | ||
uint32_t i; | ||
if (a->size != b->size){ | ||
return 0; | ||
} | ||
uint64_t referenceChunk, candidateChunk; | ||
for (i = 0;i<a->size;++i){ | ||
referenceChunk = vu64_tGet(a, i); | ||
candidateChunk = vu64_tGet(b, i); | ||
if (referenceChunk!=candidateChunk){ | ||
return 0; | ||
} | ||
} | ||
return 1; | ||
} | ||
|
||
uint8_t maskContainsBit(vu64_t* mask, uint32_t bit){ | ||
uint32_t chunk; | ||
uint32_t pos = bit; | ||
reduceMaskBitPair(&chunk, &pos); | ||
if (chunk >= mask->size){ | ||
return 0; | ||
} | ||
uint64_t seg = vu64_tGet(mask, chunk); | ||
return (seg | (1<<pos)) == seg; | ||
} | ||
|
||
void maskRemoveBit(vu64_t* mask, uint32_t bit){ | ||
uint32_t chunk; | ||
reduceMaskBitPair(&chunk, &bit); | ||
uint64_t* seg = vu64_tRef(mask, chunk); | ||
*seg &= ~(1<<bit); | ||
} | ||
|
||
void maskAddBit(vu64_t* mask, uint32_t bit){ | ||
uint32_t chunk; | ||
reduceMaskBitPair(&chunk, &bit); | ||
while (chunk >= mask->size){ | ||
vu64_tPushBack(mask, 0); | ||
} | ||
uint64_t* seg = vu64_tRef(mask, chunk); | ||
*seg |= (1<<bit); | ||
} | ||
|
||
void reduceMaskBitPair(uint32_t* index, uint32_t* pos){ | ||
*index = (*pos)/64; | ||
*pos %= 64; | ||
} | ||
|
||
vu64_t createMask(uint32_t n, ...){ | ||
vu32_t bits = vu32_tInit(); | ||
vu32_tReserve(&bits, n); | ||
va_list v; | ||
va_start(v, n); | ||
uint32_t i; | ||
uint32_t maxBit = 0; | ||
for(i = 0;i<n;++i){ | ||
uint32_t bit = va_arg(v, uint32_t); | ||
vu32_tPushBack(&bits, bit); | ||
if (bit > maxBit){ | ||
maxBit = bit; | ||
} | ||
} | ||
va_end(v); | ||
maxBit /= 64; | ||
uint64_t* tempMask = calloc(maxBit+1, sizeof(uint64_t)); | ||
for (i = 0;i<bits.size;++i){ | ||
uint32_t pos = vu32_tGet(&bits, i); | ||
uint32_t index = 0; | ||
reduceMaskBitPair(&index, &pos); | ||
tempMask[index] |= 1<<pos; | ||
} | ||
vu64_t mask = vu64_tInit(); | ||
for(i = 0;i<maxBit+1;++i){ | ||
vu64_tPushBack(&mask, tempMask[i]); | ||
} | ||
vu32_tFree(&bits); | ||
free(tempMask); | ||
tempMask = NULL; | ||
return mask; | ||
} | ||
|
||
vu64_t maskCopy(vu64_t* mask){ | ||
uint32_t i; | ||
vu64_t newMask = vu64_tInit(); | ||
for (i = 0;i<mask->size;++i){ | ||
vu64_tPushBack(&newMask, vu64_tGet(mask, i)); | ||
} | ||
return newMask; | ||
} | ||
|
||
void maskChunkDisplay(uint64_t chunk){ | ||
if (chunk == 0){ | ||
printf(" 0 "); | ||
} | ||
while (chunk > 0){ | ||
printf("%lu",(chunk%2)); | ||
chunk /= 2; | ||
} | ||
} | ||
|
||
void maskDisplay(vu64_t* mask){ | ||
uint32_t i; | ||
for (i = 0;i<mask->size;++i){ | ||
uint64_t chunk = vu64_tGet(mask, i); | ||
maskChunkDisplay(chunk); | ||
} | ||
printf("\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef BITMASKS_H | ||
#define BITMASKS_H | ||
|
||
#include "vector.h" | ||
#include <inttypes.h> | ||
|
||
VECTOR(vu64_t, uint64_t) | ||
VECTOR(vu32_t, uint32_t) | ||
|
||
uint8_t maskContainsBit(vu64_t* mask, uint32_t bit); | ||
uint8_t maskCompare(vu64_t* reference, vu64_t* candidate); | ||
uint8_t maskEquals(vu64_t* a, vu64_t* b); | ||
void maskRemoveBit(vu64_t* mask, uint32_t bit); | ||
void maskAddBit(vu64_t* mask, uint32_t bit); | ||
void reduceMaskBitPair(uint32_t* index, uint32_t* pos); | ||
vu64_t createMask(uint32_t n, ...); | ||
vu64_t maskCopy(vu64_t* mask); | ||
void maskDisplay(vu64_t* mask); | ||
void maskChunkDisplay(uint64_t chunk); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "cflags.h" | ||
#include <stdio.h> | ||
|
||
uint64_t bit_flip(uint64_t flag, uint8_t bit){ | ||
return flag ^ (1<<(bit-1)); | ||
} | ||
|
||
uint64_t bit_off(uint64_t flag, uint8_t bit){ | ||
return flag & ~(1<<(bit-1)); | ||
} | ||
|
||
uint64_t bit_on(uint64_t flag, uint8_t bit){ | ||
return flag | (1<<(bit-1)); | ||
} | ||
|
||
uint8_t bit_check(uint64_t flag, uint8_t bit){ | ||
return (flag & (1<<(bit-1)))!=0; | ||
} | ||
|
||
uint64_t bit_set(uint64_t flag, uint8_t pos, uint8_t bit){ | ||
return ((flag & ~(1<<(pos-1))) | (bit << (pos-1))); | ||
} | ||
|
||
uint8_t bit_count(uint64_t flag){ | ||
uint8_t count = 0; | ||
while (flag){ | ||
flag &= (flag-1); | ||
count++; | ||
} | ||
return count; | ||
} | ||
|
||
void printflag64(uint64_t flag){ | ||
int8_t i; | ||
for (i = FOB_64;i>0;--i){ | ||
printf("%u",bit_check(flag, i)); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
void printflag32(uint32_t flag){ | ||
int8_t i; | ||
for (i = FOB_32;i>0;--i){ | ||
printf("%u",bit_check(flag, i)); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
void printflag16(uint16_t flag){ | ||
int8_t i; | ||
for (i = FOB_16;i>0;--i){ | ||
printf("%u",bit_check(flag, i)); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
void printflag8(uint8_t flag){ | ||
int8_t i; | ||
for (i = FOB_8;i>0;--i){ | ||
printf("%u",bit_check(flag, i)); | ||
} | ||
printf("\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef C_FLAGS_H | ||
#define C_FLAGS_H | ||
|
||
#include <stdint.h> | ||
|
||
#define FOB_64 64 | ||
#define FOB_32 32 | ||
#define FOB_16 16 | ||
#define FOB_8 8 | ||
|
||
uint64_t bit_flip(uint64_t flag, uint8_t bit); | ||
uint64_t bit_off(uint64_t flag, uint8_t bit); | ||
uint64_t bit_on(uint64_t flag, uint8_t bit); | ||
uint8_t bit_check(uint64_t flag, uint8_t bit); | ||
uint64_t bit_set(uint64_t flag, uint8_t pos, uint8_t bit); | ||
|
||
uint8_t bit_count(uint64_t flag); | ||
|
||
void printflag64(uint64_t flag); | ||
void printflag32(uint32_t flag); | ||
void printflag16(uint16_t flag); | ||
void printflag8(uint8_t flag); | ||
|
||
#endif | ||
|
Oops, something went wrong.