Commit 1e8a0d1d by William Bundy

Did a little opt pass, mostly working on fixing up stuff with metaprogramming tool

parent 5b420e76
......@@ -2,7 +2,9 @@
SET msvcdir=C:\Program Files^ (x86)\Microsoft^ Visual^ Studio^ 14.0\VC\
if not defined DevEnvDir call "%msvcdir%vcvarsall.bat" amd64
SET MAINFILE=src\rituals_main.cpp
SET MAINFILEBASE=rituals_main
SET MAINFILE=src\%MAINFILEBASE%.cpp
SET PPC_OUT=%MAINFILEBASE%.i
SET BASENAME=Rituals.exe
SET OUTPUT=bin\Rituals.exe
SET PDBOUT=bin\Rituals.pdb
......@@ -26,6 +28,16 @@ SET LIBS=SDL2.lib ^
start python autogit.py
cl ^
/P ^
/I %INCLUDES% ^
%MAINFILE% ^
/DPREPROCESSOR
metaprogram -m %PPC_OUT% > src\rituals_reflection.cpp
metaprogram -t -p %PPC_OUT% > src\rituals_types.cpp
taskkill /IM %BASENAME%
ctime -begin rituals.ctm
if "%~1"=="" goto DEBUG_BUILD
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Rect2{0 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{12 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{24 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{36 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{48 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{60 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{72 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{84 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{96 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{108 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{120 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{132 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{144 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{156 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{168 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{180 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{192 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{204 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{216 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{228 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{240 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{252 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{264 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{276 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{288 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{300 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{312 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{324 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{336 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{348 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{360 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{372 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{384 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{396 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{408 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{420 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{432 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{444 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{456 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{468 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{480 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{492 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{504 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{516 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{528 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{540 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{552 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{564 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{576 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{588 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{600 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{612 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{624 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{636 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{648 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{660 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{672 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{684 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{696 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{708 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{720 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{732 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{744 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{756 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{768 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{780 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{792 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{804 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{816 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{828 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{840 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{852 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{864 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{876 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{888 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{900 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{912 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{924 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{936 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{948 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{960 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{972 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{984 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{996 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{1008 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{1020 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{1032 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{1044 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{1056 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{1068 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{1080 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{1092 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{1104 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{1116 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14},
Rect2{1128 + _glyph_offset_x, 0 + _glyph_offset_y, 8, 14}
......@@ -82,6 +82,7 @@ typedef size_t usize;
struct Metaprogram_Core
{
bool verbose;
Memory_Arena base_arena;
Memory_Arena work_arena;
Memory_Arena temp_arena;
......@@ -117,6 +118,8 @@ char* load_file(char* filename, isize* size_out, Memory_Arena* arena)
#include "metaprogram_parser.cpp"
#define myprint(x) printf(x)
int main(int argc, char** argv)
{
//Core + arena initialization
......@@ -138,8 +141,8 @@ int main(int argc, char** argv)
// -t --typedefs
// -s --structs
// -m --metadata
bool pflag, tflag, sflag, mflag;
pflag = tflag = sflag = false;
bool pflag, tflag, sflag, mflag, vflag;
pflag = tflag = sflag = mflag = vflag = false;
char* file = NULL;
for(isize i = 0; i < argc; ++i) {
if(argv[i][0] == '-') {
......@@ -153,6 +156,9 @@ int main(int argc, char** argv)
case 's':
sflag = true;
break;
case 'v':
vflag = true;
break;
case 'm':
mflag = true;
break;
......@@ -178,6 +184,7 @@ int main(int argc, char** argv)
return 1;
}
Metaprogram->verbose = vflag;
if(file != NULL && istherework) {
//char* str = load_file("src/rituals_game.cpp", NULL, Work_Arena);
//char* file = load_file(filename, NULL, Work_Arena);
......@@ -210,7 +217,7 @@ int main(int argc, char** argv)
Proc_Prototype* p = find_proc_prototypes(&lex, start, Work_Arena);
Struct_Def* structdef = find_struct_defs(&lex, start, Work_Arena);
fprintf(stderr, "Found %d procedures, %d structs \n",
if(Metaprogram->verbose) fprintf(stderr, "Found %d procedures, %d structs \n\n",
lex.procedures_count, lex.structs_count);
Struct_Def* s_head = structdef;
......@@ -253,7 +260,7 @@ int main(int argc, char** argv)
Hash structhash = hash_literal("struct");
Hash unionhash = hash_literal("union");
do {
head = parse_dollarsign_instructions(head);
head = parse_metaprogram_directive(head);
if(head->hash == typedefhash) {
Token* tdef = head;
Token* end = NULL;
......@@ -340,7 +347,6 @@ int main(int argc, char** argv)
Struct_Def** all_structs = arena_push_array(Work_Arena,
Struct_Def*, lex.structs_count + meta_index_counter + 16);
isize num_structs = meta_index_counter;
fprintf(stderr, "Meta flag set: [%d] \n", mflag);
if(mflag) {
//Print Meta_Type enum
s_head = structdef;
......@@ -393,27 +399,9 @@ int main(int argc, char** argv)
printf("\t\"%s\",\n", type_head->name);
} while(type_head = type_head->next);
printf("};\n");
// Print type_of overloads
#if 1
s_head = structdef;
/*s_head = structdef;
type_start = unique_type_start;
type_head = type_start;
do {
if(type_head->name == NULL) continue;
printf("static inline Meta_Type type_of(const %s* object) { return Meta_Type_%s; }\n", type_head->name, type_head->name);
} while(type_head = type_head->next);
do {
if(s_head == NULL) break;
if(s_head->name == NULL) continue;
printf("static inline Meta_Type type_of(const %s* object) { return Meta_Type_%s; }\n", s_head->name, s_head->name);
} while(s_head = s_head->next);
#endif
type_head = type_start;*/
}
......@@ -440,14 +428,6 @@ int main(int argc, char** argv)
printf("};\n\n");
print_metaprogram_get_struct_info_proc();
for(isize i = 0; i < num_structs; ++i) {
Struct_Def* def = all_structs[i];
if(def->is_anon_member) continue;
printf("static inline const Meta_Struct_Info* get_struct_info(%s* object) { return get_struct_info(%s); } \n",
def->name, def->meta_type_name);
}
}
......
......@@ -53,6 +53,7 @@ enum Token_Kind
Token_LessThan,
Token_CompilerDirective,
Token_MetaprogramDirective,
Token_Char,
Token_String,
Token_Number,
......@@ -137,7 +138,7 @@ void init_lexer_file(Lexer_File* file, char* filename, char* prev_path, isize pr
}
Hash exthash = hash_string(filename_copy + extlen, len - extlen);
if(exthash != hash_literal(".i") && exthash != hash_literal(".c") && exthash != hash_literal(".cpp") && exthash != hash_literal(".h")) {
fprintf(stderr, "Hit invalid file suffix: %d %d %d %.*s\n", len, extlen, len - extlen, len - extlen, filename_copy + extlen);
if(Metaprogram->verbose) fprintf(stderr, "Skipping %s\n", filename_copy);
file->pathlen = pathlen;
file->filename = filename_copy;
file->start = NULL;
......@@ -308,9 +309,63 @@ bool lexer_get_token(Lexer* lexer, Lexer_File* f, Token* t)
}
t->len = f->head - t->start;
break;
case '$':
t->kind = Token_DollarSign;
break;
case '$': {
char* oldhead = f->head;
nextchar;
while(valid) {
if(is_space(f->head[0])) {
nextchar;
} else if(f->head[0] == '/') {
if(f->head[1] == '*') {
nextchar;
nextchar;
while(valid && !(f->head[0] == '*' &&
f->head[1] == '/')) {
nextchar;
}
nextchar;
nextchar;
} else if(f->head[1] == '/') {
nextchar;
nextchar;
if(f->head[0] == '\\') {
nextchar;
}
while(valid && (f->head[0] != '\n')) {
nextchar;
}
nextchar;
} else {
break;
}
} else {
break;
}
}
if(f->head[0] == '(') {
t->kind = Token_MetaprogramDirective;
nextchar;
t->start = f->head;
t->location = f->location;
int brace_depth = 0;
while(brace_depth >= 0) {
nextchar;
if(f->head[0] == '(') {
brace_depth++;
} else if (f->head[0] == ')') {
brace_depth--;
}
if(!valid) {
break;
}
}
t->len = f->head - t->start;
} else {
t->kind = Token_DollarSign;
}
} break;
case '%':
t->kind = Token_Modulo;
break;
......@@ -528,8 +583,29 @@ void parse_include_directive(Lexer* lex, Token* directive)
}
Token* parse_dollarsign_instructions(Token* t)
Token* parse_metaprogram_directive(Token* t)
{
if(t->kind != Token_MetaprogramDirective) return t;
Token* head = t;
Hash excludehash = hash_literal("exclude");
Hash endhash = hash_literal("end");
if(t->hash == excludehash) {
do {
if(head->kind == Token_MetaprogramDirective) {
if(head->hash == endhash) {
head = head->next;
break;
}
}
} while(head = head->next);
}
/*
if(t->kind != Token_DollarSign) return t;
Token* next = t->next->next;
Token* head = t;
......@@ -546,6 +622,7 @@ Token* parse_dollarsign_instructions(Token* t)
}
} while(next = next->next);
}
*/
return head;
}
......@@ -554,7 +631,7 @@ void parse_tokens(Lexer* lex, Token* start)
Token* head = start;
do {
head = parse_dollarsign_instructions(head);
head = parse_metaprogram_directive(head);
if(head->kind == Token_CompilerDirective && head->start[0] == 'i') {
parse_include_directive(lex, head);
}
......@@ -566,7 +643,7 @@ void parse_tokens(Lexer* lex, Token* start)
Token* next;
switch(head->kind) {
case Token_DollarSign:
head = parse_dollarsign_instructions(head);
head = parse_metaprogram_directive(head);
break;
case Token_Ampersand:
next = head->next;
......@@ -660,14 +737,6 @@ void parse_tokens(Lexer* lex, Token* start)
}
void parse_sing(Token* t, int32 brace_level)
{
if(t->hash == hash_literal("sing")) {
fprintf(stderr, "[%d]", brace_level);
}
}
struct Proc_Arg
{
char** terms;
......@@ -753,7 +822,7 @@ Proc_Prototype* find_proc_prototypes(Lexer* lex, Token* start, Memory_Arena* are
Proc_Prototype* proc_head = proc_start;
do {
head = parse_dollarsign_instructions(head);
head = parse_metaprogram_directive(head);
if (head->kind == Token_Identifier) {
if(head->hash != structhash && head->hash != enumhash) {
//pattern:
......@@ -780,7 +849,7 @@ Proc_Prototype* find_proc_prototypes(Lexer* lex, Token* start, Memory_Arena* are
mode = -1;
break;
}
sub_head = parse_dollarsign_instructions(sub_head);
sub_head = parse_metaprogram_directive(sub_head);
switch(mode) {
case 0:
if (sub_head->kind == Token_Identifier) {
......@@ -1127,7 +1196,7 @@ Token* parse_struct_member(Lexer* lex, Struct_Def* parent, Token* start, Memory_
return head;
} else {
fprintf(stderr, "ERROR: wanted identifier, got %d:[%.*s] \n",
if(Metaprogram->verbose) fprintf(stderr, "ERROR: wanted identifier, got %d:[%.*s] \n",
head->kind, head->len, head->start);
}
} else {
......@@ -1253,54 +1322,36 @@ Struct_Def* find_struct_defs(Lexer* lex, Token* start, Memory_Arena* arena)
int32 brace_depth = 0;
Token* last_open, *last_closed;
last_open = last_closed = NULL;
//fprintf(stderr, "\n");
do {
if(head->kind == Token_DollarSign) {
next = head->next->next;
parse_sing(next, brace_depth);
}
//head = parse_dollarsign_instructions(head);
parse_metaprogram_directive(head);
if(head->kind == Token_OpenBrace) {
brace_depth++;
last_open = head;
#if 0
fprintf(stderr, "\n");
for(isize qq = 0; qq < brace_depth; ++qq) {
fprintf(stderr, ".");
}
fprintf(stderr, "{");
#endif
} else if(head->kind == Token_CloseBrace) {
brace_depth--;
last_closed = head;
#if 0
fprintf(stderr, "}");
#endif
}
if(brace_depth < 0) {
//j fprintf(stderr, " %d ", brace_depth);
#if 1
fprintf(stderr, ">>> Brace Depth went negative at: %s line %d col %d \n", lex->files[head->location.file].filename, head->location.line, head->location.offset);
if(last_open == NULL) {
fprintf(stderr, ">>> No previous opening brace");
} else {
fprintf(stderr, ">>> Last Open Brace: %s line %d col %d \n", lex->files[last_open->location.file].filename, last_open->location.line, last_open->location.offset);
fprintf(stderr, ">>> %.*s \n", last_open->len + 32, last_open->start);
}
if(Metaprogram->verbose) {
fprintf(stderr, ">>> Brace Depth went negative at: %s line %d col %d \n", lex->files[head->location.file].filename, head->location.line, head->location.offset);
if(last_open == NULL) {
fprintf(stderr, ">>> No previous opening brace");
} else {
fprintf(stderr, ">>> Last Open Brace: %s line %d col %d \n", lex->files[last_open->location.file].filename, last_open->location.line, last_open->location.offset);
fprintf(stderr, ">>> %.*s \n", last_open->len + 32, last_open->start);
}
if(last_closed == NULL) {
fprintf(stderr, ">>> No previous closing brace");
} else {
fprintf(stderr, ">>> Last Closing Brace: %s line %d col %d \n", lex->files[last_closed->location.file].filename, last_closed->location.line, last_closed->location.offset);
fprintf(stderr, ">>> %.*s \n", last_open->len + 32, last_open->start - 32);
if(last_closed == NULL) {
fprintf(stderr, ">>> No previous closing brace");
} else {
fprintf(stderr, ">>> Last Closing Brace: %s line %d col %d \n", lex->files[last_closed->location.file].filename, last_closed->location.line, last_closed->location.offset);
fprintf(stderr, ">>> %.*s \n", last_open->len + 32, last_open->start - 32);
}
}
brace_depth = 0;
#endif
}
if(head->hash == typedefhash) {
......@@ -1350,7 +1401,7 @@ Struct_Def* find_struct_defs(Lexer* lex, Token* start, Memory_Arena* arena)
def_head = def_head->next;
}
} while(head = head->next);
fprintf(stderr, "\n");
if(Metaprogram->verbose)fprintf(stderr, "\n");
return def_start;
}
......
......@@ -289,9 +289,9 @@ void rituals_walk_entities(Entity* entities, isize count, World_Area* area, Worl
break;
}
}
if(e->walk_impulse.x < 0.001f) {
if(e->walk_impulse.x < -1.0f) {
e->facing = -1;
} else if (e->walk_impulse.x > 0.001f) {
} else if (e->walk_impulse.x > 1.0f) {
e->facing = 1;
}
......@@ -305,6 +305,8 @@ void rituals_animate_entities(Entity* entities, isize count, World_Area* area, W
shadow.flags = Anchor_Center;
shadow.texture = rect2(96, 16, 32, 16);
shadow.color.w = 0.3f;
real render_distance = Game->size.x + 256;
render_distance *= render_distance;
for(isize i = 0; i < count; ++i) {
Entity* e = entities + i;
......@@ -333,6 +335,14 @@ void rituals_animate_entities(Entity* entities, isize count, World_Area* area, W
}
}
}
Vec2 dv_player = area->player->sprite.position - e->sprite.position;
real dist_player = v2_dot(dv_player, dv_player);
if(dist_player >
(render_distance + e->sprite.size.x * e->sprite.size.x)) {
continue;
}
shadow.position = e->sprite.position;
Sprite s = e->sprite;
......
......@@ -108,6 +108,8 @@ struct Game_Main
//Debug_Log* log;
Game_Input* input;
uint64 last_frame_time;
};
Game_Main* Game;
......
......@@ -16,6 +16,15 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
#define AsciiPrintableEnd (128)
#define AsciiPrintableCount (128-32)
#define _glyph_offset_x (2048-1142)
#define _glyph_offset_y 0
$(exclude)
const Rect2 Gohufont_Glyphs[] = {
#include "gohufont.glyphs"
};
$(end)
struct Spritefont
{
int32 line_padding;
......@@ -23,16 +32,18 @@ struct Spritefont
int32 tab_size;
int32 glyph_width, glyph_height;
Rect2* glyphs;
const Rect2* glyphs;
Vec4 color;
};
void init_spritefont(Spritefont* font)
void init_spritefont(Spritefont* font, const Rect2* glyphs)
{
font->line_padding = 0;
font->character_padding = 0;
font->tab_size = 4; // * space width?
font->glyphs = NULL;
font->glyphs = glyphs;
font->glyph_width = glyphs[1].w;
font->glyph_height = glyphs[1].h;
font->color = v4(1, 1, 1, 1);
}
......@@ -50,86 +61,6 @@ static inline bool _isnt_spritefont_separator(char c)
return (c != ' ') && (c != '\n') && (c != '\0');
}
Rect2* parse_spritefont_rectangles(char* glyphs_file, Memory_Arena* arena, int32 offsetx, int32 offsety, int32* w, int32* h)
{
Rect2* glyphs = arena_push_array(arena, Rect2, AsciiPrintableCount);
isize file_len = strlen(glyphs_file);
isize start = 0, len = 0;
for(isize i = 0; i < file_len; ++i) {
char c = glyphs_file[i++];
Rect2* r;
if(c > AsciiPrintableStart && c <= AsciiPrintableEnd) {
r = &glyphs[c - AsciiPrintableStart];
} else {
while(glyphs_file[i] != '\n') i++;
continue;
}
i++;
start = i;
while(_isnt_spritefont_separator(glyphs_file[i])) i++;
len = i - start;
r->x = dec_str_to_int(glyphs_file + start, len) + offsetx;
i++;
start = i;
while(_isnt_spritefont_separator(glyphs_file[i])) i++;
len = i - start;
r->y = dec_str_to_int(glyphs_file + start, len) + offsety - 1;
i++;
start = i;
while(_isnt_spritefont_separator(glyphs_file[i])) i++;
len = i - start;
r->w = dec_str_to_int(glyphs_file + start, len);
*w = r->w;
i++;
start = i;
while(_isnt_spritefont_separator(glyphs_file[i])) i++;
len = i - start;
r->h = dec_str_to_int(glyphs_file + start, len) + 2;
*h = r->h;
i++;
}
return glyphs;
}
void load_spritefont(Spritefont* font, char* file_path_in, Vec2i offset)
{
init_spritefont(font);
char file_path[FilePathMaxLength];
isize len = snprintf(file_path, FilePathMaxLength, "%s%s", Game->base_path, file_path_in);
char* str = NULL;
FILE* fp = fopen(file_path, "r");
if(fp != NULL) {
start_temp_arena(Game->temp_arena);
fseek(fp, 0L, SEEK_END);
isize size = ftell(fp);
rewind(fp);
str = arena_push_array(Game->temp_arena, char, size + 1);
fread(str, sizeof(char), size, fp);
str[size] = '\0';
fclose(fp);
font->glyphs = parse_spritefont_rectangles(str, Game->asset_arena,
offset.x, offset.y, &font->glyph_width, &font->glyph_height);
end_temp_arena(Game->temp_arena);
} else {
Log_Error("Could not find font glyphs file");
Log_Error(file_path);
}
}
Spritefont* load_spritefont(char* filepath, Vec2i offset)
{
Spritefont* font = arena_push_struct(Game->asset_arena, Spritefont);
load_spritefont(font, filepath, offset);
return font;
}
Vec2 spritefont_size_text(Spritefont* font, char* text, isize len)
{
Vec2 position = v2(0, font->glyph_height);
......
......@@ -12,108 +12,19 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
* rituals_main.cpp
*/
/* TODO(will) features
* - Big Projects
* - Massive refactoring
* - Programmable ini replacement
* - Memory dumps, logging
* - Reflection/introspection metaprogramming system
* - For use with serialization
* - Can save versioned type layouts, then do its best to load from/to
* - Modding with packages
* - requires a lot of sorting per package id.
* - Graphics
* - Texture atlas stitching
* - able to combine pow2 squares into one big atlas
* - Release as lightweight spriting library
* - Physics
* - Static and dynamic friction
* - Multithreading/SIMD body processing?
* - More sophisticated spacial partitioning?
* - Hierarchical grids, quadtrees, k-d trees
* - Current grid system works, but rather inflexible and memory-hungry
* - UI
* - Needs to be reworked
* - Play
* - Entity inspector
* - Another art pass
* TODO(will) Refactoring
* - rituals_animations.cpp
* - To store animations in the registry?
* - Have a way to pre-build animaition dictionaries
* - Animated_Sprite isn't a sprite.
* - rituals_entity_events.cpp
* - Possibly a more sophisticated sorting method for entities?
* - Better typing support for entity userdata
* - rituals_game.cpp
* - Use generated structs/procedures for Game_States
* - rituals_game_info.cpp & rituals_game_registry.cpp
* - No meaningful distinction right now between these files?
* - Supposedly the "types" of things go in info and the registry system
* belongs in registry, but due to C's declaration syntax, you can't mix them.
* - All the game's definitions end up in registry when they should be in info
* - rituals_gui.cpp
* - Gui components need reworking.
* - rituals_inventory.cpp
* - This... just isn't done, and the project isn't quite ready for it.
* - rituals_main.cpp
* - Needs Main_Menu stuff taken out, possibly want to clean up includes/defines too.
* - rituals_math.cpp
* - Remove unused stuff
* - Complete operator overloading for the whole type matrix
* - rituals_memory.cpp
* - Need more allocator types
* - Free-list/Bucket Array?
* - Pool allocator?
* - I implement a lot of these inline, but it'd be nice to pull some out