diff --git a/build/modules/LibC.core b/build/modules/LibC.core index 0fe387f..3a3a7b0 100644 --- a/build/modules/LibC.core +++ b/build/modules/LibC.core @@ -4,6 +4,7 @@ malloc :: #foreign (size: size_t): *void realloc :: #foreign (ptr: *void, size: size_t): *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 memmove :: #foreign (dst: *void, src: *void, size: size_t): *void diff --git a/build/rtsgame/main.core b/build/rtsgame/main.core index 04eaecb..3b89baf 100644 --- a/build/rtsgame/main.core +++ b/build/rtsgame/main.core @@ -60,15 +60,18 @@ Add(&guys, {100, 100}) // // Map map = (Map ){.data = (&(map_data[0])), .data = 0x10, .x = 16}; -// @reproduction -// 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 +// @reproduction Couldn't figure out type of compound expression when variable got declared and separetly // 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" #load "array.core" @@ -108,15 +111,16 @@ main :: (): int MouseY = GetMouseY() MouseP = GetMousePosition() - if IsKeyPressed(KEY_F1) ;; Mode := 0 - if IsKeyPressed(KEY_F2) ;; Mode := 1 + if IsKeyPressed(KEY_F1) ;; Mode = 0 + if IsKeyPressed(KEY_F2) ;; Mode = 1 + if IsKeyPressed(KEY_F3) + MAP_Reset() if IsKeyDown(KEY_SPACE) MAP_PathFindStep() BeginDrawing() ClearBackground(RAYWHITE) - map := &MAP_CurrentMap for x := 0, x < map.x, x += 1 for y := 0, y < map.y, y += 1 @@ -127,6 +131,8 @@ main :: (): int colliding := CheckCollisionPointRec(MouseP, r) 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 if *it == 1 ;; color = RED @@ -152,7 +158,10 @@ main :: (): int it := MAP_History.data + i r := Rectangle{it.p.x->F32 * RectX, it.p.y->F32 * RectY, RectX, RectY} 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() diff --git a/build/rtsgame/map.core b/build/rtsgame/map.core index feb559e..2a4b8ed 100644 --- a/build/rtsgame/map.core +++ b/build/rtsgame/map.core @@ -1,4 +1,3 @@ - MAP_CurrentMap: MAP_Map MAP_OpenPaths: Array(MAP_Path) MAP_ClosePaths: Array(MAP_Path) @@ -23,11 +22,25 @@ MAP_Path :: struct p: 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_CurrentMap.x = 60 MAP_CurrentMap.y = 40 - MAP_CurrentMap.data = malloc(SizeOf(MAP_Tile) * MAP_CurrentMap.x->U64 * MAP_CurrentMap.y->U64) - Add(&MAP_CurrentMap.actors, {{4, 4}, {8, 8}}) + bytes := SizeOf(MAP_Tile) * MAP_CurrentMap.x->U64 * MAP_CurrentMap.y->U64 + MAP_CurrentMap.data = malloc(bytes) + MAP_Reset() MAP_InsertOpenPath :: (p: V2I, target_p: V2I, came_from: V2I) if p.x < 0 || p.x >= MAP_CurrentMap.x ;; return diff --git a/core_codegen_c_language.cpp b/core_codegen_c_language.cpp index 353283b..c6a53fb 100644 --- a/core_codegen_c_language.cpp +++ b/core_codegen_c_language.cpp @@ -41,13 +41,12 @@ gen_last_line() { } } -global String prefixed_string_type; CORE_Static const char * get_ctype_name_for_type(Ast_Type *type) { switch (type->kind) { case TYPE_VOID: return "void"; 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_F64: return "double"; @@ -816,7 +815,6 @@ CORE_Static String compile_to_c_code() { pctx->time.code_generation = os_time(); - prefixed_string_type = string_fmt(pctx->perm, "String"); if (pctx->single_header_library_mode) { gen(R"( /* @@ -993,7 +991,7 @@ compile_to_c_code() { genln(".struct_members.data = (Type_Info_Struct_Member[%d]){", t->agg.members.len); global_indent += 1; 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; genln("}");