Commit 7ea429bd by William Bundy

Working on stuff

parent 1e8a0d1d
......@@ -4,7 +4,8 @@ if not defined DevEnvDir call "%msvcdir%vcvarsall.bat" amd64
SET MAINFILEBASE=rituals_main
SET MAINFILE=src\%MAINFILEBASE%.cpp
SET PPC_OUT=%MAINFILEBASE%.i
SET PPC_OUT_RAW=%MAINFILEBASE%.i
SET PPC_OUT=rituals_ppc.cpp
SET BASENAME=Rituals.exe
SET OUTPUT=bin\Rituals.exe
SET PDBOUT=bin\Rituals.pdb
......@@ -35,8 +36,11 @@ cl ^
%MAINFILE% ^
/DPREPROCESSOR
del %PPC_OUT%
ren %PPC_OUT_RAW% %PPC_OUT%
metaprogram -m %PPC_OUT% > src\rituals_reflection.cpp
metaprogram -t -p %PPC_OUT% > src\rituals_types.cpp
metaprogram -t -s -p %PPC_OUT% > src\rituals_types.cpp
taskkill /IM %BASENAME%
ctime -begin rituals.ctm
......@@ -115,7 +119,6 @@ cl ^
/NOLOGO ^
/INCREMENTAL:NO
pushd bin
ReM del *.pdb
GOTO END
:END
......
This source diff could not be displayed because it is too large. You can view the blob instead.
R"glyphs( 0 0 8 14
! 12 0 8 14
" 24 0 8 14
# 36 0 8 14
$ 48 0 8 14
% 60 0 8 14
& 72 0 8 14
' 84 0 8 14
( 96 0 8 14
) 108 0 8 14
* 120 0 8 14
+ 132 0 8 14
, 144 0 8 14
- 156 0 8 14
. 168 0 8 14
/ 180 0 8 14
0 192 0 8 14
1 204 0 8 14
2 216 0 8 14
3 228 0 8 14
4 240 0 8 14
5 252 0 8 14
6 264 0 8 14
7 276 0 8 14
8 288 0 8 14
9 300 0 8 14
: 312 0 8 14
; 324 0 8 14
< 336 0 8 14
= 348 0 8 14
> 360 0 8 14
? 372 0 8 14
@ 384 0 8 14
A 396 0 8 14
B 408 0 8 14
C 420 0 8 14
D 432 0 8 14
E 444 0 8 14
F 456 0 8 14
G 468 0 8 14
H 480 0 8 14
I 492 0 8 14
J 504 0 8 14
K 516 0 8 14
L 528 0 8 14
M 540 0 8 14
N 552 0 8 14
O 564 0 8 14
P 576 0 8 14
Q 588 0 8 14
R 600 0 8 14
S 612 0 8 14
T 624 0 8 14
U 636 0 8 14
V 648 0 8 14
W 660 0 8 14
X 672 0 8 14
Y 684 0 8 14
Z 696 0 8 14
[ 708 0 8 14
\ 720 0 8 14
] 732 0 8 14
^ 744 0 8 14
_ 756 0 8 14
` 768 0 8 14
a 780 0 8 14
b 792 0 8 14
c 804 0 8 14
d 816 0 8 14
e 828 0 8 14
f 840 0 8 14
g 852 0 8 14
h 864 0 8 14
i 876 0 8 14
j 888 0 8 14
k 900 0 8 14
l 912 0 8 14
m 924 0 8 14
n 936 0 8 14
o 948 0 8 14
p 960 0 8 14
q 972 0 8 14
r 984 0 8 14
s 996 0 8 14
t 1008 0 8 14
u 1020 0 8 14
v 1032 0 8 14
w 1044 0 8 14
x 1056 0 8 14
y 1068 0 8 14
z 1080 0 8 14
{ 1092 0 8 14
| 1104 0 8 14
} 1116 0 8 14
~ 1128 0 8 14 )glyphs"
......@@ -76,6 +76,7 @@ typedef size_t usize;
#define Gigabytes(b) (Megabytes(b) * UINT64_C(1024))
#define Log_Error(ii) printf("%s \n", (ii));
#define assert(cond) do { if(!cond) { char *p = 0; p = NULL; *p = 100; } } while(0)
#include "../rituals_memory.cpp"
#include "../rituals_sort_macros.cpp"
......
......@@ -975,6 +975,7 @@ typedef union Struct_Member Struct_Member;
struct Struct_Def
{
char* name;
char* parentname;
Struct_Kind kind;
isize meta_index;
......@@ -982,6 +983,7 @@ struct Struct_Def
Hash namehash;
bool is_anon_member;
bool is_named_child;
Struct_Member* members;
Struct_Kind* member_kinds;
......@@ -1083,6 +1085,17 @@ void print_struct_names(Struct_Def* def, isize index, char* prefix, isize prefix
for(isize i = 0; i < def->member_count; ++i) {
if(def->member_kinds[i] != StructKind_Member) {
auto var = &def->members[i].anon_struct;
if(def->name[0] != '\0') {
if(def->is_named_child) {
var->def.parentname = def->parentname;
} else {
var->def.parentname = def->name;
}
} else {
var->def.parentname = def->parentname;
}
print_struct_names(&var->def, subcount++, new_prefix, chars, suffix, all_structs, counter, arena);
}
}
......@@ -1134,7 +1147,6 @@ void print_struct(Struct_Def* def, bool as_member_struct = false, int32 indent =
printf(";\n");
}
}
indent--;
print_indent(indent);
......@@ -1150,7 +1162,6 @@ void print_struct(Struct_Def* def, bool as_member_struct = false, int32 indent =
}
// unsigned short**** thinga[400], **thingb, **thingc, a, b, c, d[3], e[44][55], f[44][22][44];
Token* parse_struct_member(Lexer* lex, Struct_Def* parent, Token* start, Memory_Arena* arena)
{
......@@ -1189,11 +1200,13 @@ Token* parse_struct_member(Lexer* lex, Struct_Def* parent, Token* start, Memory_
if(head->kind != Token_Identifier) {
if(head->kind == Token_Semicolon) {
def.name = "";
def.is_anon_member = true;
var->def = def;
var->array_levels = 0;
var->array_sizes = NULL;
parent->member_count++;
return head;
} else {
if(Metaprogram->verbose) fprintf(stderr, "ERROR: wanted identifier, got %d:[%.*s] \n",
......@@ -1206,6 +1219,7 @@ Token* parse_struct_member(Lexer* lex, Struct_Def* parent, Token* start, Memory_
next = head->next;
buf[len] = '\0';
def.name = buf;
def.is_named_child = true;
def.namehash = head->hash;
}
head = head->next;
......@@ -1323,7 +1337,7 @@ Struct_Def* find_struct_defs(Lexer* lex, Token* start, Memory_Arena* arena)
Token* last_open, *last_closed;
last_open = last_closed = NULL;
do {
parse_metaprogram_directive(head);
head = parse_metaprogram_directive(head);
if(head->kind == Token_OpenBrace) {
brace_depth++;
last_open = head;
......@@ -1520,14 +1534,35 @@ struct Meta_Member
void print_meta_member(Meta_Member* member, char* prefix, char* suffix)
{
printf("%sMeta_Member{%d, Meta_Type_%s, %d, \"%s\", (uint64)&((%s*)NULL)->%s}%s",
char* name;
char* parentname;
if(member->name[0] == '\0') {
name = "null";
parentname = "_empty";
} else {
name = member->name;
parentname = member->parentname;
}
isize namelen = Min(strlen("Meta_Type_"), strlen(member->type_name));
bool is_toplevel = false;
for(isize i = 0; i < namelen; ++i) {
if(member->type_name[i] != "Meta_Type_"[i]) {
is_toplevel = true;
break;
}
}
printf("%sMeta_Member{%d, %s%s, %d, \"%s\", offsetof(%s, %s)}%s",
prefix,
member->flags,
is_toplevel ? "Meta_Type_" : "",
member->type_name,
member->pointer_depth,
member->name,
member->parentname,
member->name,
parentname,
name,
suffix);
}
......@@ -1551,7 +1586,13 @@ void print_reflection_data(Struct_Def* def)
Meta_Member m = {
0
};
m.parentname = def->name;
if(def->name[0] != '\0')
if(def->is_named_child)
m.parentname = def->parentname;
else
m.parentname = def->name;
else
m.parentname = def->parentname;
if(def->member_kinds[i] == StructKind_Member) {
auto var = &def->members[i].member_var;
Meta_Type* meta = var->type;
......@@ -1581,7 +1622,8 @@ void print_reflection_data(Struct_Def* def)
m.flags = MetaFlag_IsArray;
}
}
print_meta_member(&m, "\t", ",\n");
char* suffix = i == def->member_count - 1 ? "\n" : ",\n";
print_meta_member(&m, "\t", suffix);
}
printf("};\n\n");
}
......@@ -1589,6 +1631,10 @@ void print_reflection_data(Struct_Def* def)
void print_metaprogram_types()
{
printf(R"foo(
struct _empty
{
int null;
};
struct Meta_Member
{
uint64 flags;
......
......@@ -13,6 +13,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
*/
#ifndef REFLECTED
struct Animation_Frame
{
Vec3 position;
......@@ -22,6 +24,7 @@ struct Animation_Frame
Rect2 texture;
real sort_offset;
};
#endif
void init_animation_frame(Animation_Frame* fr)
{
......@@ -33,6 +36,7 @@ void init_animation_frame(Animation_Frame* fr)
fr->sort_offset = 0;
}
#ifndef REFLECTED
struct Animation
{
isize id;
......@@ -42,6 +46,7 @@ struct Animation
real inv_fps;
bool looping;
};
#endif
void init_animation(Animation* a, real fps, isize capacity, Memory_Arena* arena)
{
......@@ -71,6 +76,7 @@ Animation* make_animaiton_from_strip(Memory_Arena* arena, real fps, Rect2 frame,
return anim;
}
#ifndef REFLECTED
struct Animated_Sprite
{
Animation** animations;
......@@ -79,6 +85,7 @@ struct Animated_Sprite
bool running;
real timer;
};
#endif
void init_animated_sprite(Animated_Sprite* s, isize capacity, Memory_Arena* arena)
{
......
/*
Copyright (c) 2016 William Bundy
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef float real32;
typedef double real64;
#define RITUALS_USE_FLOAT32
#ifdef RITUALS_USE_FLOAT32
typedef real32 real;
#else
$(exclude)
typedef real64 real;
$(end)
#endif
typedef int32 integer;
typedef real32 real;
//Some defines
//TODO(will): use this as all floating point sizes
typedef ptrdiff_t isize;
typedef size_t usize;
#define Math_Sqrt2 1.414213f
#define Math_InvSqrt2 0.7071067f
#define Math_Pi 3.141592f
#define Math_Tau 6.283185f
#define Math_RadToDeg 57.29577f
#define Math_DegToRad 0.01745329f
#define Allocate(type, count) ((type*)calloc(sizeof(type), count))
#define StackAlloc(type, count) ((type*)_alloca(sizeof(type) * count))
#define isizeof(t) ((isize)sizeof(t))
#define isz(t) (isizeof(t))
#define MixerNumberOfChannels 64
#define FilePathMaxLength 4096
#define PathSeparator ("\\")
#define PathSeparatorChar ('\\')
#define Backspace ('\b')
#define BackspaceStr ("\b")
#define Min(x,y) ((x<y)?x:y)
#define Max(x,y) ((x>y)?x:y)
#define Flag(x) (1 << x)
#define Has_Flag(x, y) (x & y)
#define Enable_Flag(x, y) (x |= y)
#define Disable_Flag(x, y) (x &= ~y)
#define Kilobytes(b) (b * UINT64_C(1024))
#define Megabytes(b) (Kilobytes(b) * UINT64_C(1024))
#define Gigabytes(b) (Megabytes(b) * UINT64_C(1024))
#define _check(s1, s2, state) ((Input->scancodes[SDL_SCANCODE_##s1] == state) || (Input->scancodes[SDL_SCANCODE_##s2] == state))
#define _scancode(s1) ((Input->scancodes[SDL_SCANCODE_##s1]))
......@@ -167,9 +167,9 @@ bool rituals_frametick_entities(Entity* entities, isize count, World_Area* area,
}
if(e->health <= 0) {
play_state->delete_world_on_stop = true;
play_state->save_world_on_stop = false;
switch_state(Game_State_Menu);
Game->Play->delete_world_on_stop = true;
Game->Play->save_world_on_stop = false;
game_switch_state(Game_State_Menu);
return true;
}
}
......@@ -184,8 +184,6 @@ void rituals_slowtick_entities(Entity* entities, isize count, World_Area* area,
}
}
#define _check(s1, s2, state) ((Input->scancodes[SDL_SCANCODE_##s1] == state) || (Input->scancodes[SDL_SCANCODE_##s2] == state))
#define _scancode(s1) ((Input->scancodes[SDL_SCANCODE_##s1]))
void rituals_walk_entities(Entity* entities, isize count, World_Area* area, World* world)
{
for(isize i = 0; i < count; ++i) {
......
......@@ -24,6 +24,7 @@ typedef EntityOnActivateDecl((*Entity_On_Activate));
typedef int32 Tile;
#ifndef REFLECTED
struct Tile_Info
{
isize id;
......@@ -58,6 +59,7 @@ struct Tile_State
isize id;
int32 damage;
};
#endif
void init_tile_state(Tile_State* state, isize id)
{
......@@ -78,6 +80,7 @@ enum Item_Info_Types
Item_Info_Types_Count
};
#ifndef REFLECTED
struct Item_Info
{
isize id;
......@@ -87,6 +90,7 @@ struct Item_Info
Rect2 texture;
};
#endif
enum Entity_Event_Type
{
......@@ -128,69 +132,81 @@ enum Rituals_Pickup_Kind
PickupKind_Health
};
#ifndef REFLECTED
struct Rituals_Bat_Userdata
{
Vec2 perch;
};
struct Rituals_Snake_Userdata
{
real chase_speed_modifier;
};
struct Rituals_Goblin_Knight_Userdata
{
Vec2 patrol_start;
Vec2 patrol_end;
};
struct Rituals_Enemy_Userdata
{
isize kind;
isize mode;
real speed;
real alert_dist;
real follow_dist;
union {
Rituals_Bat_Userdata bat;
Rituals_Snake_Userdata snake;
Rituals_Goblin_Knight_Userdata goblin_knight;
};
};
struct Rituals_Player_Userdata {
isize held_entity_id;
real heal_cooldown;
real heal_timer;
int32 heal_rate;
int32 heal_to_interval;
};
struct Rituals_Prop_Userdata {
Rituals_Entity_Kinds contains;
isize subtype;
isize amount;
isize quality;
};
struct Rituals_Item_Pickup_Userdata
{
isize id, count;
};
struct Rituals_Health_Pickup_Userdata
{
isize amount;
};
struct Rituals_Pickup_Userdata
{
isize kind;
Rituals_Item_Pickup_Userdata item;
Rituals_Health_Pickup_Userdata health;
};
struct Unknown_Userdata {
void* ptr;
isize size;
};
union Rituals_Entity_Userdata
{
struct {
Rituals_Entity_Kinds contains;
isize subtype;
isize amount;
isize quality;
} prop;
struct {
isize held_entity_id;
real heal_cooldown;
real heal_timer;
int32 heal_rate;
int32 heal_to_interval;
} player;
struct {
isize kind;
isize mode;
real speed;
real alert_dist;
real follow_dist;
union {
struct {
Vec2 perch;
} bat;
struct {
real chase_speed_modifier;
} snake;
struct {
Vec2 patrol_start;
Vec2 patrol_end;
} goblin_knight;
};
} enemy;
struct {
isize kind;
union {
struct {
isize id, count;
} item;
struct {
isize amount;
} health;
};
} pickup;
struct {
void* ptr;
isize size;
} unknown;
};
union MyUnion
{
struct {
real x, y, z, w;
};
struct {
uint32 aa, bb, cc, dd;
};
struct {
char* p, *q, *r, *s;
};
Rituals_Prop_Userdata prop;
Rituals_Player_Userdata player;
Rituals_Enemy_Userdata enemy;
Rituals_Pickup_Userdata pickup;
Unknown_Userdata unknown;
};
#endif
......@@ -23,6 +23,9 @@ usize hash_str(const char* str)
return hash;
}
#ifndef REFLECTED
struct Game_Registry
{
Tile_Info* tiles;
......@@ -32,22 +35,17 @@ struct Game_Registry
Item_Info* items;
usize* items_hash;
isize items_count;
};
Game_Registry* Registry;
#endif
#define MaxRegistryInfoEntries (256)
void init_game_registry(Game_Registry* registry, Memory_Arena* arena)
{
$(exclude)
#define _set_registry_arrays(type, base_name) do { \
registry->base_name = arena_push_array(arena, type, MaxRegistryInfoEntries); \
registry->base_name##_hash = arena_push_array(arena, usize, MaxRegistryInfoEntries); \
registry->base_name##_count = 0; \
} while(0)
$(end)
_set_registry_arrays(Tile_Info, tiles);
_set_registry_arrays(Item_Info, items);
......@@ -55,7 +53,6 @@ $(end)
$(exclude)
#define _game_registry__key_macro(t) (t.k)
#define _generate_registry_lookup(lookup_func_name, sort_func_name , return_type, array_base_name) \
return_type* lookup_func_name(const char* name) \
......@@ -64,7 +61,7 @@ return_type* lookup_func_name(const char* name) \
isize index = usize_search(hash, Registry->array_base_name##_hash, Registry->array_base_name##_count); \
return Registry->array_base_name + index; \
} \
struct _game_registry__##return_type##_pair { return_type v; usize k; }; \
struct _game_registry__##return_type##_pair { return_type v; usize k; }; \
GenerateIntrosortForType(_game_registry__##return_type##_pair_sort, _game_registry__##return_type##_pair, 12, _game_registry__key_macro) \
void sort_func_name() \
{ \
......@@ -86,11 +83,16 @@ void sort_func_name() \
Registry->array_base_name[i].id = i; \
} \
}
$(end)
$(exclude)
_generate_registry_lookup(lookup_tile, sort_registered_tiles, Tile_Info, tiles)
_generate_registry_lookup(lookup_item, sort_registered_items, Item_Info, items)
$(end)
isize Tile_Void = 0;
isize Tile_Sand = 0;
isize Tile_Grass = 0;
......
/*
Copyright (c) 2016 William Bundy
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef REFLECTED
struct None_State
{
int32 error;
};
#endif
void game_init_None_state()
{
}
void game_start_None_state()
{
}
void game_update_None_state()
{
}
void game_stop_None_state()
{
}
void game_free_None_state()
{
}
#ifndef REFLECTED
struct Menu_State
{
int32 error;
char save_dir[FilePathMaxLength];
isize save_dir_len;
tinydir_dir saves;
bool saves_dirty;
Gui_Text_Input_Handle handle;
isize delete_index;
};
#endif
void game_init_Menu_state()
{
Menu_State* menu_state = Game->Menu;
init_text_input_handle(&menu_state->handle, 256, Game->game_arena);
menu_state->delete_index = -1;
menu_state->save_dir_len = snprintf(menu_state->save_dir, FilePathMaxLength, "%ssave", Game->base_path);
check_dir(menu_state->save_dir);