Core Compiler: Fix type incomplete polymorph, work on RTS
This commit is contained in:
@@ -26,12 +26,27 @@ Free :: (a: *Array($T))
|
||||
Reset :: (a: *Array($T))
|
||||
a.len = 0
|
||||
|
||||
Insert :: (a: *Array($T), item: T, index: int)
|
||||
if index == a.len
|
||||
Add(a, item)
|
||||
return
|
||||
|
||||
Assert(index < a.len)
|
||||
Assert(index >= 0)
|
||||
|
||||
TryGrowing(a)
|
||||
right_len := (a.len - index)->size_t
|
||||
memmove(a.data + index + 1, a.data + index, SizeOf(T) * right_len)
|
||||
a.data[index] = item
|
||||
a.len += 1
|
||||
|
||||
GetIndex :: (a: *Array($T), item: *T): int
|
||||
Assert(a.len > 0)
|
||||
Assert(item >= a.data && item < a.data + a.len)
|
||||
|
||||
// @reproduction: compiler hangs
|
||||
// index := (item - a.data)->*void->size_t
|
||||
|
||||
index := (item - a.data)->int
|
||||
Assert(index >= 0 && index < a.len)
|
||||
return index
|
||||
@@ -52,7 +67,6 @@ OrderedRemove :: (a: *Array($T), item: *T)
|
||||
memmove(a.data + index, a.data + index + 1, length_right_of_item * SizeOf(T))
|
||||
a.len -= 1
|
||||
|
||||
|
||||
TryGrowing :: (a: *Array($T))
|
||||
if a.cap == 0
|
||||
a.cap = 16
|
||||
@@ -61,11 +75,25 @@ TryGrowing :: (a: *Array($T))
|
||||
a.cap *= 2
|
||||
a.data = realloc(a.data, SizeOf(T) * a.cap->size_t)
|
||||
|
||||
|
||||
Add :: (a: *Array($T), item: T)
|
||||
TryGrowing(a)
|
||||
a.data[a.len++] = item
|
||||
|
||||
BoundedAdd :: (a: *Array($T), item: T)
|
||||
Assert(a.len + 1 <= a.cap)
|
||||
Add(a, item)
|
||||
|
||||
InsertSortedDecreasing :: (a: *Array($T), item: T)
|
||||
insert_index := -1
|
||||
for i := 0, i < a.len, i += 1
|
||||
it := a.data + i
|
||||
if it.value_to_sort_by <= item.value_to_sort_by
|
||||
Insert(a, item, i)
|
||||
break
|
||||
|
||||
if insert_index == -1
|
||||
Add(a, item)
|
||||
|
||||
Reserve :: (a: *Array($T), size: int)
|
||||
Assert(size > a.cap)
|
||||
a.cap = size
|
||||
|
||||
@@ -71,51 +71,24 @@ Add(&guys, {100, 100})
|
||||
|
||||
|
||||
#import "raylib.core"
|
||||
MA :: #import "Arena.core"
|
||||
#load "array.core"
|
||||
#load "map.core"
|
||||
|
||||
V2I :: struct
|
||||
x: int
|
||||
y: int
|
||||
|
||||
Map_Tile :: int
|
||||
Map :: struct
|
||||
data: *Map_Tile
|
||||
x: int
|
||||
y: int
|
||||
|
||||
Actor :: struct
|
||||
p: V2I
|
||||
target_p: V2I
|
||||
|
||||
WinX := 1280
|
||||
WinY := 720
|
||||
|
||||
MouseX := 0
|
||||
MouseY := 0
|
||||
MouseP: Vector2
|
||||
|
||||
Mode := 0
|
||||
RectX :: 16
|
||||
RectY :: 16
|
||||
|
||||
GuyP: V2I
|
||||
|
||||
main :: (): int
|
||||
|
||||
|
||||
MAP_X :: 60
|
||||
MAP_Y :: 40
|
||||
map_data: [MAP_X*MAP_Y]int
|
||||
map: Map = {data = &map_data[0], x = MAP_X, y = MAP_Y}
|
||||
|
||||
actors: Array(Actor)
|
||||
Reserve(&actors, 4)
|
||||
|
||||
Add(&actors, {{4, 4}, {8, 8}})
|
||||
Assert(Contains(&actors, actors.data) == true)
|
||||
OrderedRemove(&actors, actors.data)
|
||||
Assert(Contains(&actors, actors.data) == false)
|
||||
MAP_Init()
|
||||
|
||||
// InitAudioDevice()
|
||||
// sound := LoadSound("catune - Pass the town, and to the C.mp3")
|
||||
@@ -138,6 +111,8 @@ main :: (): int
|
||||
BeginDrawing()
|
||||
ClearBackground(RAYWHITE)
|
||||
|
||||
|
||||
map := &MAP_CurrentMap
|
||||
for x := 0, x < map.x, x += 1
|
||||
for y := 0, y < map.y, y += 1
|
||||
it := map.data + (x + y*map.x)
|
||||
@@ -147,7 +122,7 @@ main :: (): int
|
||||
colliding := CheckCollisionPointRec(MouseP, r)
|
||||
|
||||
if Mode == 0 && colliding && IsMouseButtonDown(MOUSE_BUTTON_LEFT) ;; *it = 1
|
||||
if Mode == 0 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_RIGHT) ;; GuyP = V2I{x,y}
|
||||
// if Mode == 0 && colliding && IsMouseButtonPressed(MOUSE_BUTTON_RIGHT) ;; GuyP = V2I{x,y}
|
||||
|
||||
color := GREEN
|
||||
if *it == 1 ;; color = RED
|
||||
@@ -155,8 +130,8 @@ main :: (): int
|
||||
|
||||
DrawRectangleRec(r2, color)
|
||||
|
||||
for i := 0, i < actors.len, i += 1
|
||||
it := actors.data + i
|
||||
for i := 0, i < map.actors.len, i += 1
|
||||
it := map.actors.data + i
|
||||
r := Rectangle{it.p.x->F32 * RectX, it.p.y->F32 * RectY, RectX, RectY}
|
||||
target_r := Rectangle{it.target_p.x->F32 * RectX, it.target_p.y->F32 * RectY, RectX, RectY}
|
||||
|
||||
|
||||
24
build/rtsgame/map.core
Normal file
24
build/rtsgame/map.core
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
MAP_CurrentMap: MAP_Map
|
||||
|
||||
|
||||
MAP_Tile :: int
|
||||
MAP_Map :: struct
|
||||
data: *MAP_Tile
|
||||
x: int
|
||||
y: int
|
||||
actors: Array(Actor)
|
||||
|
||||
Actor :: struct
|
||||
p: V2I
|
||||
target_p: V2I
|
||||
|
||||
|
||||
MAP_Init :: ()
|
||||
MAP_X :: 60
|
||||
MAP_Y :: 40
|
||||
|
||||
map_data: [MAP_X*MAP_Y]int
|
||||
MAP_CurrentMap = MAP_Map{data = &map_data[0], x = MAP_X, y = MAP_Y}
|
||||
Add(&MAP_CurrentMap.actors, {{4, 4}, {8, 8}})
|
||||
|
||||
Reference in New Issue
Block a user