Compiler game work + enable cast from pointer to int
This commit is contained in:
@@ -3,7 +3,7 @@ call "..\misc\compile_setup.bat"
|
||||
|
||||
rem bld --dont_compile_core
|
||||
cd build
|
||||
core_main.exe examples/game2d.core
|
||||
rem bld --dont_compile_core --link=vendor/raylib/windows/raylibdll.lib
|
||||
core_main.exe rtsgame/main.core
|
||||
bld --dont_compile_core --link=vendor/raylib/windows/raylibdll.lib
|
||||
rem build\generated_main.exe
|
||||
cd ..
|
||||
|
||||
@@ -40,3 +40,11 @@ PushSize :: (a: *Arena, size: Base.SizeU): *void
|
||||
|
||||
Release :: (a: *Arena)
|
||||
OS.Release(&a.memory)
|
||||
|
||||
PushArray :: (a: *Arena, count: int, $T: Type): *T
|
||||
result := PushSize(a, SizeOf(T) * count->U64)
|
||||
return result->*T
|
||||
|
||||
PushStruct :: (a: *Arena, $T: Type): *T
|
||||
result := PushSize(a, SizeOf(T))
|
||||
return result->*T
|
||||
@@ -1,10 +1,12 @@
|
||||
size_t :: U64 // @todo(Krzosa): Need this type
|
||||
long :: #strict int // @todo(Krzosa): Need this type
|
||||
|
||||
malloc :: #foreign (size: size_t): *void
|
||||
realloc :: #foreign (ptr: *void, size: size_t): *void
|
||||
free :: #foreign (ptr: *void)
|
||||
|
||||
memcpy :: #foreign (dst: *void, src: *void, size: size_t): *void
|
||||
memmove :: #foreign (dst: *void, src: *void, size: size_t): *void
|
||||
|
||||
FILE :: #strict U64 // Doesnt matter the type just handle
|
||||
fopen :: #foreign (file: *char, mode: *char): *FILE
|
||||
fclose :: #foreign (file: *FILE): int
|
||||
@@ -15,8 +17,3 @@ fread :: #foreign (buffer: *void, element_size: size_t, element_count: size_t, s
|
||||
SEEK_CUR :: 1
|
||||
SEEK_END :: 2
|
||||
SEEK_SET :: 0
|
||||
|
||||
Triple :: struct($A: Type, $B: Type, $C: Type)
|
||||
a: A
|
||||
b: B
|
||||
c: C
|
||||
@@ -643,10 +643,10 @@ SetGamepadMappings :: #foreign (mappings: *char): int /
|
||||
|
||||
// Input-related functions: mouse
|
||||
|
||||
IsMouseButtonPressed :: #foreign (button: MouseButton): bool // Detect if a mouse button has been pressed once
|
||||
IsMouseButtonDown :: #foreign (button: MouseButton): bool // Detect if a mouse button is being pressed
|
||||
IsMouseButtonReleased :: #foreign (button: MouseButton): bool // Detect if a mouse button has been released once
|
||||
IsMouseButtonUp :: #foreign (button: MouseButton): bool // Detect if a mouse button is NOT being pressed
|
||||
IsMouseButtonPressed :: #foreign (button: int): bool // Detect if a mouse button has been pressed once
|
||||
IsMouseButtonDown :: #foreign (button: int): bool // Detect if a mouse button is being pressed
|
||||
IsMouseButtonReleased :: #foreign (button: int): bool // Detect if a mouse button has been released once
|
||||
IsMouseButtonUp :: #foreign (button: int): bool // Detect if a mouse button is NOT being pressed
|
||||
GetMouseX :: #foreign (): int // Returns mouse position X
|
||||
GetMouseY :: #foreign (): int // Returns mouse position Y
|
||||
GetMousePosition :: #foreign (): Vector2 // Returns mouse position XY
|
||||
|
||||
@@ -5,11 +5,70 @@ Array :: struct($T: Type)
|
||||
len: int
|
||||
cap: int
|
||||
|
||||
Add :: (a: *Array($T), item: T)
|
||||
Pop :: (a: *Array($T)): T
|
||||
if a.len > 0
|
||||
a.len -= 1
|
||||
return a.data[a.len]
|
||||
// @reproduction: c compile error, probably because of compound expression (Array){}
|
||||
// return {}
|
||||
|
||||
result: T
|
||||
return result
|
||||
|
||||
Contains :: (a: *Array($T), item: *T): bool
|
||||
result := item >= a.data && item < a.data + a.len
|
||||
return result
|
||||
|
||||
Free :: (a: *Array($T))
|
||||
free(a.data)
|
||||
a.cap = 0; a.len = 0; a.data = 0
|
||||
|
||||
Reset :: (a: *Array($T))
|
||||
a.len = 0
|
||||
|
||||
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
|
||||
|
||||
UnorderedRemove :: (a: *Array($T), item: *T)
|
||||
Assert(a.len > 0)
|
||||
Assert(item >= a.data && item < a.data + a.len)
|
||||
|
||||
*item = a.data[--a.len]
|
||||
|
||||
OrderedRemove :: (a: *Array($T), item: *T)
|
||||
index := GetIndex(a, item)
|
||||
if index == a.len - 1
|
||||
Pop(a)
|
||||
return
|
||||
|
||||
length_right_of_item := (a.len - index - 1)->size_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
|
||||
a.data = malloc(SizeOf(T) * a.cap->U64)
|
||||
a.data = malloc(SizeOf(T) * a.cap->size_t)
|
||||
if a.len + 1 > a.cap
|
||||
a.cap *= 2
|
||||
a.data = realloc(a.data, SizeOf(T) * a.cap->U64)
|
||||
a.data = realloc(a.data, SizeOf(T) * a.cap->size_t)
|
||||
|
||||
|
||||
Add :: (a: *Array($T), item: T)
|
||||
TryGrowing(a)
|
||||
a.data[a.len++] = item
|
||||
|
||||
Reserve :: (a: *Array($T), size: int)
|
||||
Assert(size > a.cap)
|
||||
a.cap = size
|
||||
p := realloc(a.data, SizeOf(T) * a.cap->size_t)
|
||||
Assert(p != 0)
|
||||
a.data = p
|
||||
@@ -1,6 +1,3 @@
|
||||
#import "raylib.core"
|
||||
|
||||
#load "array.core"
|
||||
|
||||
/*@feature_idea: labeled block
|
||||
|
||||
@@ -63,9 +60,23 @@ 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
|
||||
// got assigned a value
|
||||
//
|
||||
|
||||
Guy :: struct
|
||||
pos: Vector2
|
||||
|
||||
#import "raylib.core"
|
||||
MA :: #import "Arena.core"
|
||||
#load "array.core"
|
||||
|
||||
V2I :: struct
|
||||
x: int
|
||||
y: int
|
||||
|
||||
Map_Tile :: int
|
||||
Map :: struct
|
||||
@@ -73,54 +84,85 @@ Map :: struct
|
||||
x: int
|
||||
y: int
|
||||
|
||||
SCR_X := 1280
|
||||
SCR_Y := 720
|
||||
Actor :: struct
|
||||
p: V2I
|
||||
target_p: V2I
|
||||
|
||||
M_X := 0
|
||||
M_Y := 0
|
||||
M_P: Vector2
|
||||
WinX := 1280
|
||||
WinY := 720
|
||||
|
||||
MouseX := 0
|
||||
MouseY := 0
|
||||
MouseP: Vector2
|
||||
|
||||
Mode := 0
|
||||
RectX :: 16
|
||||
RectY :: 16
|
||||
|
||||
GuyP: V2I
|
||||
|
||||
main :: (): int
|
||||
guys: Array(Guy)
|
||||
Add(&guys, {pos = {100, 100}})
|
||||
|
||||
|
||||
map_data: [16*16]int
|
||||
map: Map = {data = &map_data[0], x = 16, y = 16}
|
||||
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}
|
||||
|
||||
InitWindow(SCR_X, SCR_Y, "Testing")
|
||||
SetTargetFPS(60)
|
||||
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)
|
||||
|
||||
// InitAudioDevice()
|
||||
// sound := LoadSound("catune - Pass the town, and to the C.mp3")
|
||||
// SetMasterVolume(0.01)
|
||||
// PlaySound(sound)
|
||||
|
||||
InitWindow(WinX, WinY, "Testing")
|
||||
SetTargetFPS(60)
|
||||
|
||||
for !WindowShouldClose()
|
||||
SCR_X = GetScreenWidth()
|
||||
SCR_Y = GetScreenHeight()
|
||||
M_X = GetMouseX()
|
||||
M_Y = GetMouseY()
|
||||
M_P = GetMousePosition()
|
||||
WinX = GetScreenWidth()
|
||||
WinY = GetScreenHeight()
|
||||
MouseX = GetMouseX()
|
||||
MouseY = GetMouseY()
|
||||
MouseP = GetMousePosition()
|
||||
|
||||
if IsKeyPressed(KEY_F1) ;; Mode := 0
|
||||
if IsKeyPressed(KEY_F2) ;; Mode := 1
|
||||
|
||||
BeginDrawing()
|
||||
ClearBackground(RAYWHITE)
|
||||
|
||||
RX := 16
|
||||
RY := 16
|
||||
for x := 0, x < 16, x += 1
|
||||
for y := 0, y < 16, y += 1
|
||||
it := map.data[x + y*map.x]
|
||||
r: Rectangle = {(x * RX)->F32, (y * RY)->F32, RX->F32, RY->F32}
|
||||
for x := 0, x < map.x, x += 1
|
||||
for y := 0, y < map.y, y += 1
|
||||
it := map.data + (x + y*map.x)
|
||||
r: Rectangle = {x->F32 * RectX, y->F32 * RectY, RectX, RectY}
|
||||
r2: Rectangle = {r.x + 1, r.y + 1, r.width - 2, r.height - 2}
|
||||
|
||||
color := RED
|
||||
if it == 1 ;; color = GREEN
|
||||
if CheckCollisionPointRec(M_P, r) ;; color = BLUE
|
||||
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}
|
||||
|
||||
color := GREEN
|
||||
if *it == 1 ;; color = RED
|
||||
if colliding == true ;; color = MAROON
|
||||
|
||||
DrawRectangleRec(r2, color)
|
||||
|
||||
for i := 0, i < actors.len, i += 1
|
||||
it := 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}
|
||||
|
||||
DrawRectangleRec(r, YELLOW)
|
||||
DrawRectangleRec(target_r, PURPLE)
|
||||
|
||||
|
||||
// DrawFPS(0, 0)
|
||||
// DrawText(TextFormat("Testing %d", 32), 100, 100, 20, MAROON)
|
||||
|
||||
@@ -984,6 +984,8 @@ resolve_cast(Ast_Binary *node) {
|
||||
case TYPE_POINTER: {
|
||||
if (is_pointer(type))
|
||||
expr = operand_rvalue(type);
|
||||
else if (is_int(type))
|
||||
expr = operand_rvalue(type);
|
||||
else goto failure;
|
||||
} break;
|
||||
CASE_UNTYPED : {
|
||||
|
||||
Reference in New Issue
Block a user