Core: Brought back named loads which are a bit counter intuitive

This commit is contained in:
Krzosa Karol
2023-04-21 08:28:44 +02:00
parent d5c4caf725
commit ada87e6adf
4 changed files with 94 additions and 97 deletions

View File

@@ -19,10 +19,6 @@ thing := 1
:goto_block: for
@language_todo: Bring back named loads
A :: #load "array.core"
@reproduction:
This kills the compiler due to referencing slice data
@@ -68,7 +64,7 @@ Add(&guys, {100, 100})
// 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}
// 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
@@ -77,7 +73,7 @@ Add(&guys, {100, 100})
#import "raylib.core"
#load "array.core"
#load "map.core"
MAP :: #load "map.core"
sqrtf :: #foreign (value: F32): F32
@@ -104,10 +100,10 @@ ANI_SetTiles: Array(ANI_SetTile)
MouseSelecting := false
MouseSelectionPivot: Vector2
MouseSelectionBox: Rectangle
MouseSelectedActors: Array(*MAP_Actor) // @todo: ids
MouseSelectedActors: Array(*MAP.Actor) // @todo: ids
main :: (): int
MAP_Init()
MAP.Init()
// InitAudioDevice()
// sound := LoadSound("catune - Pass the town, and to the C.mp3")
@@ -140,7 +136,7 @@ main :: (): int
MouseY = GetMouseY()
MouseP = GetMousePosition()
Dt = GetFrameTime()
map := &MAP_CurrentMap
map := &MAP.CurrentMap
MouseSelecting = false
if IsMouseButtonDown(MOUSE_BUTTON_LEFT)
@@ -170,11 +166,11 @@ main :: (): int
if IsKeyPressed(KEY_F3)
for i := 0, i < map.actors.len, i += 1
it := map.actors.data + i
MAP_MoveTowardsTarget(it)
MAP_PathFindUpdate(map)
MAP.MoveTowardsTarget(it)
MAP.PathFindUpdate(map)
if IsKeyPressed(KEY_F4)
MAP_RandomizeActors()
MAP.RandomizeActors()
BeginDrawing()
@@ -227,8 +223,8 @@ main :: (): int
if tile_it.t > 1
map_tile := map.data + (tile_it.p.x + tile_it.p.y*map.x)
if tile_it.set ;; *map_tile |= MAP_TILE_BLOCKER
else ;; *map_tile &= ~MAP_TILE_BLOCKER
if tile_it.set ;; *map_tile |= MAP.TILE_BLOCKER
else ;; *map_tile &= ~MAP.TILE_BLOCKER
remove = true
tile_it.t += Dt*8
@@ -238,36 +234,36 @@ main :: (): int
for i := 0, i < map.actors.len, i += 1
actor_it := map.actors.data + i
target_r := MAP_Rectangle(actor_it.target_p)
target_r := MAP.Rect(actor_it.target_p)
main_p := MAP_Circle(actor_it.p)
main_p := MAP.Circle(actor_it.p)
DrawCircleV(main_p, RectX/2, actor_color)
DrawRectangleRec(target_r, target_color)
smaller_the_further: F32 = 0
for tile_i := actor_it.tiles_visited.len - 1, tile_i >= 0, tile_i -= 1
tile_it := actor_it.tiles_visited.data + tile_i
p := MAP_Circle({tile_it.x, tile_it.y})
p := MAP.Circle({tile_it.x, tile_it.y})
DrawCircleV(p, RectX/2 - smaller_the_further, past_actor_color)
smaller_the_further += 0.5
for path_i := 0, path_i < actor_it.open_paths.len, path_i += 1
path_it := actor_it.open_paths.data + path_i
path_r := MAP_Rectangle(path_it.p)
path_r := MAP.Rect(path_it.p)
DrawRectangleRec(path_r, orange)
s := TextFormat("%d", sqrtf(path_it.value_to_sort_by->F32)->int)
DrawText(s, path_r.x->int, path_r.y->int, 1, RAYWHITE)
for path_i := 0, path_i < actor_it.close_paths.len, path_i += 1
path_it := actor_it.close_paths.data + path_i
path_r := MAP_Rectangle(path_it.p)
path_r := MAP.Rect(path_it.p)
DrawRectangleRec(path_r, brown)
for path_i := 0, path_i < actor_it.history.len, path_i += 1
path_it := actor_it.history.data + path_i
p0 := MAP_Circle(path_it.came_from)
p1 := MAP_Circle(path_it.p)
p0 := MAP.Circle(path_it.came_from)
p1 := MAP.Circle(path_it.p)
DrawLineEx(p0, p1, 5, LIGHTGRAY)
DrawCircleV(p0, 4, LIGHTGRAY)
@@ -276,12 +272,12 @@ main :: (): int
if Mode == 1
for actor_i := 0, actor_i < MouseSelectedActors.len, actor_i += 1
actor_it := MouseSelectedActors.data[actor_i]
actor_box := MAP_Rectangle(actor_it.p)
actor_box := MAP.Rect(actor_it.p)
DrawRectangleRec(actor_box, GREEN)
if IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)
p := MAP_ScreenToMap(MouseP)
MAP_SetTargetP(actor_it, p)
p := MAP.ScreenToMap(MouseP)
MAP.SetTargetP(actor_it, p)
if MouseSelecting
Reset(&MouseSelectedActors)
@@ -290,7 +286,7 @@ main :: (): int
for actor_i := 0, actor_i < map.actors.len, actor_i += 1
actor_it := map.actors.data + actor_i
actor_box := MAP_Rectangle(actor_it.p)
actor_box := MAP.Rect(actor_it.p)
if CheckCollisionRecs(actor_box, MouseSelectionBox)
Add(&MouseSelectedActors, actor_it)