RTS, Fix invalid struct names in type info

This commit is contained in:
Krzosa Karol
2023-04-19 08:09:59 +02:00
parent 56eb7e6de2
commit 597cee5fb8
4 changed files with 38 additions and 17 deletions

View File

@@ -4,6 +4,7 @@ malloc :: #foreign (size: size_t): *void
realloc :: #foreign (ptr: *void, size: size_t): *void realloc :: #foreign (ptr: *void, size: size_t): *void
free :: #foreign (ptr: *void) free :: #foreign (ptr: *void)
memset :: #foreign (ptr: *void, val: int, num: size_t): *void
memcpy :: #foreign (dst: *void, src: *void, size: size_t): *void memcpy :: #foreign (dst: *void, src: *void, size: size_t): *void
memmove :: #foreign (dst: *void, src: *void, size: size_t): *void memmove :: #foreign (dst: *void, src: *void, size: size_t): *void

View File

@@ -60,15 +60,18 @@ Add(&guys, {100, 100})
// //
// Map map = (Map ){.data = (&(map_data[0])), .data = 0x10, .x = 16}; // Map map = (Map ){.data = (&(map_data[0])), .data = 0x10, .x = 16};
// @reproduction // @reproduction Couldn't figure out type of compound expression when variable got declared and separetly
// if Mode == 0 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_RIGHT) ;; GuyP = {x,y}
//
// Error! Couldn't infer type of compound expression
//
// Couldn't figure out type of compound expression when variable got declared and separetly
// got assigned a value // got assigned a value
// //
// Error! Couldn't infer type of compound expression
// if Mode == 0 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_RIGHT) ;; GuyP = {x,y}
// Error! Couldn't infer type of compound expression
// if Mode == 1 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_LEFT) ;; MAP_CurrentMap.actors.data[0].p = {x,y}
// @compiler_todo: It's possible to have 2 definitions with same name. 1 global, 1 local
// Mode := 0
// main :: ()
// if IsKeyPressed(KEY_F1) ;; Mode := 0
#import "raylib.core" #import "raylib.core"
#load "array.core" #load "array.core"
@@ -108,15 +111,16 @@ main :: (): int
MouseY = GetMouseY() MouseY = GetMouseY()
MouseP = GetMousePosition() MouseP = GetMousePosition()
if IsKeyPressed(KEY_F1) ;; Mode := 0 if IsKeyPressed(KEY_F1) ;; Mode = 0
if IsKeyPressed(KEY_F2) ;; Mode := 1 if IsKeyPressed(KEY_F2) ;; Mode = 1
if IsKeyPressed(KEY_F3)
MAP_Reset()
if IsKeyDown(KEY_SPACE) if IsKeyDown(KEY_SPACE)
MAP_PathFindStep() MAP_PathFindStep()
BeginDrawing() BeginDrawing()
ClearBackground(RAYWHITE) ClearBackground(RAYWHITE)
map := &MAP_CurrentMap map := &MAP_CurrentMap
for x := 0, x < map.x, x += 1 for x := 0, x < map.x, x += 1
for y := 0, y < map.y, y += 1 for y := 0, y < map.y, y += 1
@@ -127,6 +131,8 @@ main :: (): int
colliding := CheckCollisionPointRec(MouseP, r) colliding := CheckCollisionPointRec(MouseP, r)
if Mode == 0 && colliding && IsMouseButtonDown(MOUSE_BUTTON_LEFT) ;; *it = 1 if Mode == 0 && colliding && IsMouseButtonDown(MOUSE_BUTTON_LEFT) ;; *it = 1
if Mode == 1 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_LEFT) ;; MAP_CurrentMap.actors.data[0].p = V2I{x,y}
if Mode == 1 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_RIGHT) ;; MAP_CurrentMap.actors.data[0].target_p = V2I{x,y}
color := GREEN color := GREEN
if *it == 1 ;; color = RED if *it == 1 ;; color = RED
@@ -152,7 +158,10 @@ main :: (): int
it := MAP_History.data + i it := MAP_History.data + i
r := Rectangle{it.p.x->F32 * RectX, it.p.y->F32 * RectY, RectX, RectY} r := Rectangle{it.p.x->F32 * RectX, it.p.y->F32 * RectY, RectX, RectY}
DrawRectangleRec(r, BLACK) DrawRectangleRec(r, BLACK)
DrawText("Reached target !", 0, 0, 32, BLACK)
if Mode == 0 ;; DrawText("F1", 0, 0, 32, BLACK)
if Mode == 1 ;; DrawText("F2", 0, 0, 32, BLACK)
EndDrawing() EndDrawing()

View File

@@ -1,4 +1,3 @@
MAP_CurrentMap: MAP_Map MAP_CurrentMap: MAP_Map
MAP_OpenPaths: Array(MAP_Path) MAP_OpenPaths: Array(MAP_Path)
MAP_ClosePaths: Array(MAP_Path) MAP_ClosePaths: Array(MAP_Path)
@@ -23,11 +22,25 @@ MAP_Path :: struct
p: V2I p: V2I
came_from: V2I came_from: V2I
MAP_Reset :: ()
bytes := SizeOf(MAP_Tile) * MAP_CurrentMap.x->U64 * MAP_CurrentMap.y->U64
Reset(&MAP_CurrentMap.actors)
Reset(&MAP_OpenPaths)
Reset(&MAP_ClosePaths)
Reset(&MAP_History)
MAP_ReachedTarget = false
memset(MAP_CurrentMap.data, 0, bytes)
Add(&MAP_CurrentMap.actors, {{4, 4}, {8, 8}})
MAP_PathFindStart(MAP_CurrentMap.actors.data + 0)
MAP_Init :: () MAP_Init :: ()
MAP_CurrentMap.x = 60 MAP_CurrentMap.x = 60
MAP_CurrentMap.y = 40 MAP_CurrentMap.y = 40
MAP_CurrentMap.data = malloc(SizeOf(MAP_Tile) * MAP_CurrentMap.x->U64 * MAP_CurrentMap.y->U64) bytes := SizeOf(MAP_Tile) * MAP_CurrentMap.x->U64 * MAP_CurrentMap.y->U64
Add(&MAP_CurrentMap.actors, {{4, 4}, {8, 8}}) MAP_CurrentMap.data = malloc(bytes)
MAP_Reset()
MAP_InsertOpenPath :: (p: V2I, target_p: V2I, came_from: V2I) MAP_InsertOpenPath :: (p: V2I, target_p: V2I, came_from: V2I)
if p.x < 0 || p.x >= MAP_CurrentMap.x ;; return if p.x < 0 || p.x >= MAP_CurrentMap.x ;; return

View File

@@ -41,13 +41,12 @@ gen_last_line() {
} }
} }
global String prefixed_string_type;
CORE_Static const char * CORE_Static const char *
get_ctype_name_for_type(Ast_Type *type) { get_ctype_name_for_type(Ast_Type *type) {
switch (type->kind) { switch (type->kind) {
case TYPE_VOID: return "void"; case TYPE_VOID: return "void";
case TYPE_BOOL: return "bool"; case TYPE_BOOL: return "bool";
case TYPE_STRING: return (char *)prefixed_string_type.str; case TYPE_STRING: return "String";
case TYPE_F32: return "float"; case TYPE_F32: return "float";
case TYPE_F64: return "double"; case TYPE_F64: return "double";
@@ -816,7 +815,6 @@ CORE_Static String
compile_to_c_code() { compile_to_c_code() {
pctx->time.code_generation = os_time(); pctx->time.code_generation = os_time();
prefixed_string_type = string_fmt(pctx->perm, "String");
if (pctx->single_header_library_mode) { if (pctx->single_header_library_mode) {
gen(R"( gen(R"(
/* /*
@@ -993,7 +991,7 @@ compile_to_c_code() {
genln(".struct_members.data = (Type_Info_Struct_Member[%d]){", t->agg.members.len); genln(".struct_members.data = (Type_Info_Struct_Member[%d]){", t->agg.members.len);
global_indent += 1; global_indent += 1;
For2(t->agg.members, m) { For2(t->agg.members, m) {
genln("{.name = {(uint8_t *)\"%Q\", %d}, .type = %d, .offset = %d}, ", prefixed_string_type, m.name, m.name.len, m.type->type_id, m.offset); genln("{.name = {(uint8_t *)\"%Q\", %d}, .type = %d, .offset = %d}, ", m.name, m.name.len, m.type->type_id, m.offset);
} }
global_indent -= 1; global_indent -= 1;
genln("}"); genln("}");