Remove sandbox example
This commit is contained in:
@@ -45,7 +45,6 @@ S8_String RaylibDLL;
|
||||
#include "examples/add_dynamic_array_macro/build.cpp"
|
||||
#include "examples/text_editor/build.cpp"
|
||||
#include "examples/hello_world/build.cpp"
|
||||
#include "examples/sandbox/build.cpp"
|
||||
#include "examples/create_raylib_window/build.cpp"
|
||||
#include "examples/add_instrumentation/build.cpp"
|
||||
#include "examples/use_as_data_format_with_typechecking/build.cpp"
|
||||
@@ -166,12 +165,6 @@ int main(int argc, char **argv) {
|
||||
else IO_Printf("%-50s - ERROR\n", "hello_world");
|
||||
}
|
||||
|
||||
if (ShouldRun("sandbox")) {
|
||||
bool result = sandbox();
|
||||
if (result) IO_Printf("%-50s - OK\n", "sandbox");
|
||||
else IO_Printf("%-50s - ERROR\n", "sandbox");
|
||||
}
|
||||
|
||||
if (ShouldRun("create_raylib_window")) {
|
||||
bool result = create_raylib_window();
|
||||
if (result) IO_Printf("%-50s - OK\n", "create_raylib_window");
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
import "std_types";
|
||||
import libc "libc";
|
||||
|
||||
PAGE_SIZE :: 4096;
|
||||
|
||||
Arena :: struct {
|
||||
data: *u8;
|
||||
len: usize;
|
||||
commit: usize;
|
||||
reserve: usize;
|
||||
alignment: usize;
|
||||
}
|
||||
|
||||
GetAlignOffset :: proc(size: usize, align: usize): usize {
|
||||
mask: usize = align - 1;
|
||||
val: usize = size & mask;
|
||||
if val {
|
||||
val = align - val;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
AlignUp :: proc(size: usize, align: usize): usize {
|
||||
result := size + GetAlignOffset(size, align);
|
||||
return result;
|
||||
}
|
||||
|
||||
InitArena :: proc(arena: *Arena, reserve: usize) {
|
||||
aligned_reserve := AlignUp(reserve, PAGE_SIZE);
|
||||
data := VReserve(aligned_reserve);
|
||||
libc.assert(data != nil);
|
||||
|
||||
if data {
|
||||
arena.data = data;
|
||||
arena.reserve = aligned_reserve;
|
||||
arena.alignment = 8;
|
||||
}
|
||||
}
|
||||
|
||||
PushSize :: proc(arena: *Arena, size: usize): *void {
|
||||
libc.assert(arena.data != nil);
|
||||
|
||||
pointer := :usize(arena.data) + arena.len + size;
|
||||
align := GetAlignOffset(pointer, arena.alignment);
|
||||
aligned_size := size + align;
|
||||
|
||||
a := arena.len + aligned_size;
|
||||
if a > arena.commit {
|
||||
diff := a - arena.commit;
|
||||
commit_size := AlignUp(diff, PAGE_SIZE*4);
|
||||
libc.assert(commit_size + arena.commit <= arena.reserve);
|
||||
|
||||
if VCommit(&arena.data[arena.commit], commit_size) {
|
||||
arena.commit += commit_size;
|
||||
} else {
|
||||
libc.assert(false && "commit failed"[0]);
|
||||
}
|
||||
}
|
||||
|
||||
arena.len += align;
|
||||
result: *void = &arena.data[arena.len];
|
||||
arena.len += size;
|
||||
return result;
|
||||
}
|
||||
|
||||
TestArena :: proc() {
|
||||
arena: Arena;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#build_if(LC_OS == OS_WINDOWS);
|
||||
|
||||
DWORD :: typedef u32;
|
||||
SIZE_T :: typedef uintptr;
|
||||
BOOL :: typedef int;
|
||||
|
||||
MEM_RESERVE :: 0x00002000;
|
||||
MEM_COMMIT :: 0x00001000;
|
||||
PAGE_READWRITE :: 0x04;
|
||||
VirtualAlloc :: proc(lpAddress: *void, dwSize: SIZE_T, flAllocationType: DWORD, flProtect: DWORD): *void; @api
|
||||
|
||||
MEM_RELEASE :: 0x00008000;
|
||||
MEM_DECOMMIT :: 0x00004000;
|
||||
VirtualFree :: proc(lpAddress: *void, dwSize: SIZE_T, dwFreeType: DWORD): BOOL; @api
|
||||
|
||||
VReserve :: proc(size: usize): *void {
|
||||
result := VirtualAlloc(nil, :SIZE_T(size), MEM_RESERVE, PAGE_READWRITE);
|
||||
return result;
|
||||
}
|
||||
|
||||
VCommit :: proc(p: *void, size: usize): bool {
|
||||
result := VirtualAlloc(p, :SIZE_T(size), MEM_COMMIT, PAGE_READWRITE) != 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
VRelease :: proc(p: *void) {
|
||||
VirtualFree(p, 0, MEM_RELEASE);
|
||||
}
|
||||
@@ -1,122 +0,0 @@
|
||||
namespace Sandbox {
|
||||
Array<LC_Intern> TypesToGen;
|
||||
|
||||
void RegisterMarkedTypes(LC_AST *n) {
|
||||
if (n->kind == LC_ASTKind_TypespecIdent) {
|
||||
S8_String name = S8_MakeFromChar((char *)n->eident.name);
|
||||
S8_String array_of = "ArrayOf";
|
||||
if (S8_StartsWith(name, array_of)) {
|
||||
if (name == "ArrayOfName") return;
|
||||
|
||||
name = S8_Skip(name, array_of.len);
|
||||
LC_Intern intern = LC_InternStrLen(name.str, (int)name.len);
|
||||
|
||||
bool exists = false;
|
||||
For(TypesToGen) {
|
||||
if (intern == it) {
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exists) {
|
||||
TypesToGen.add(intern);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WalkAndRename(LC_ASTWalker *ctx, LC_AST *n) {
|
||||
LC_Intern *p = NULL;
|
||||
if (n->kind == LC_ASTKind_TypespecIdent || n->kind == LC_ASTKind_ExprIdent) {
|
||||
p = &n->eident.name;
|
||||
}
|
||||
if (LC_IsDecl(n)) {
|
||||
p = &n->dbase.name;
|
||||
}
|
||||
|
||||
if (p) {
|
||||
LC_Intern user = *(LC_Intern *)ctx->user_data;
|
||||
S8_String p8 = S8_MakeFromChar((char *)*p);
|
||||
|
||||
if (S8_Seek(p8, "Name")) {
|
||||
S8_String new_name = S8_ReplaceAll(L->arena, p8, "Name", S8_MakeFromChar((char *)user));
|
||||
*p = LC_InternStrLen(new_name.str, (int)new_name.len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BeforeCallArgsResolved(LC_AST *n, LC_Type *type) {
|
||||
}
|
||||
|
||||
} // namespace Sandbox
|
||||
|
||||
bool sandbox() {
|
||||
using namespace Sandbox;
|
||||
|
||||
LC_Lang *lang = LC_LangAlloc();
|
||||
lang->use_colored_terminal_output = UseColoredIO;
|
||||
lang->breakpoint_on_error = BreakpointOnError;
|
||||
lang->on_typespec_parsed = RegisterMarkedTypes;
|
||||
lang->before_call_args_resolved = BeforeCallArgsResolved;
|
||||
LC_LangBegin(lang);
|
||||
|
||||
LC_RegisterPackageDir("../pkgs");
|
||||
LC_RegisterPackageDir("../examples");
|
||||
|
||||
LC_Intern name = LC_ILit("sandbox");
|
||||
LC_ParsePackagesPass(name);
|
||||
LC_BuildIfPass();
|
||||
if (L->errors) {
|
||||
LC_LangEnd(lang);
|
||||
return false;
|
||||
}
|
||||
|
||||
TypesToGen.allocator = MA_GetAllocator(lang->arena);
|
||||
|
||||
//
|
||||
// Remove dynamic array file
|
||||
//
|
||||
LC_AST *package = LC_GetPackageByName(name);
|
||||
LC_AST *dynamic_array_file = NULL;
|
||||
LC_ASTFor(it, package->apackage.ffile) {
|
||||
S8_String path = S8_MakeFromChar((char *)it->afile.x->file);
|
||||
if (S8_EndsWith(path, "dynamic_array.lc")) {
|
||||
dynamic_array_file = it;
|
||||
DLL_QUEUE_REMOVE(package->apackage.ffile, package->apackage.lfile, it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate copies
|
||||
LC_ASTWalker walker = LC_GetDefaultWalker(L->arena, WalkAndRename);
|
||||
For(TypesToGen) {
|
||||
LC_AST *new_array_file = LC_CopyAST(L->arena, dynamic_array_file);
|
||||
|
||||
walker.user_data = (void *)⁢
|
||||
LC_WalkAST(&walker, new_array_file);
|
||||
LC_DLLAdd(package->apackage.ffile, package->apackage.lfile, new_array_file);
|
||||
}
|
||||
|
||||
LC_OrderAndResolveTopLevelPass(name);
|
||||
LC_ResolveProcBodiesPass();
|
||||
if (L->errors) {
|
||||
LC_LangEnd(lang);
|
||||
return false;
|
||||
}
|
||||
|
||||
LC_String code = LC_GenerateUnityBuild();
|
||||
S8_String path = "examples/sandbox/sandbox.c";
|
||||
|
||||
OS_MakeDir("examples/sandbox");
|
||||
OS_WriteFile(path, code);
|
||||
LC_LangEnd(lang);
|
||||
|
||||
if (UseCL) {
|
||||
OS_CopyFile(RaylibDLL, "examples/sandbox/raylib.dll", true);
|
||||
S8_String cmd = Fmt("cl %.*s -Zi -std:c11 -nologo -FC -Fd:examples/sandbox/a.pdb -Fe:examples/sandbox/sandbox.exe %.*s", S8_Expand(path), S8_Expand(RaylibLIB));
|
||||
int errcode = Run(cmd);
|
||||
if (errcode != 0) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
FloatMin :: proc(a: float, b: float): float {
|
||||
if (a > b) return b;
|
||||
return a;
|
||||
}
|
||||
|
||||
FloatMax :: proc(a: float, b: float): float {
|
||||
if (a > b) return a;
|
||||
return a;
|
||||
}
|
||||
|
||||
FloatClamp :: proc(val: float, min: float, max: float): float {
|
||||
if (val > max) return max;
|
||||
if (val < min) return min;
|
||||
return val;
|
||||
}
|
||||
|
||||
IntMin :: proc(a: int, b: int): int {
|
||||
if (a > b) return b;
|
||||
return a;
|
||||
}
|
||||
|
||||
IntMax :: proc(a: int, b: int): int {
|
||||
if (a > b) return a;
|
||||
return a;
|
||||
}
|
||||
|
||||
IntClamp :: proc(val: int, min: int, max: int): int {
|
||||
if (val > max) return max;
|
||||
if (val < min) return min;
|
||||
return val;
|
||||
}
|
||||
|
||||
Rect2 :: struct {
|
||||
min: Vector2;
|
||||
max: Vector2;
|
||||
}
|
||||
|
||||
CutLeft :: proc(r: *Rect2, value: float): Rect2 {
|
||||
minx := r.min.x;
|
||||
r.min.x = FloatMin(r.max.x, r.min.x + value);
|
||||
return :Rect2{
|
||||
{ minx, r.min.y},
|
||||
{r.min.x, r.max.y},
|
||||
};
|
||||
}
|
||||
|
||||
CutRight :: proc(r: *Rect2, value: float): Rect2 {
|
||||
maxx := r.max.x;
|
||||
r.max.x = FloatMax(r.max.x - value, r.min.x);
|
||||
return :Rect2{
|
||||
{r.max.x, r.min.y},
|
||||
{ maxx, r.max.y},
|
||||
};
|
||||
}
|
||||
|
||||
CutBottom :: proc(r: *Rect2, value: float): Rect2 { // Y is down
|
||||
maxy := r.max.y;
|
||||
r.max.y = FloatMax(r.min.y, r.max.y - value);
|
||||
return :Rect2{
|
||||
{r.min.x, r.max.y},
|
||||
{r.max.x, maxy},
|
||||
};
|
||||
}
|
||||
|
||||
CutTop :: proc(r: *Rect2, value: float): Rect2 { // Y is down
|
||||
miny := r.min.y;
|
||||
r.min.y = FloatMin(r.min.y + value, r.max.y);
|
||||
return :Rect2{
|
||||
{r.min.x, miny},
|
||||
{r.max.x, r.min.y},
|
||||
};
|
||||
}
|
||||
|
||||
Shrink :: proc(r: Rect2, value: float): Rect2 {
|
||||
r.min.x += value;
|
||||
r.max.x -= value;
|
||||
r.min.y += value;
|
||||
r.max.y -= value;
|
||||
return r;
|
||||
}
|
||||
|
||||
RectFromSize :: proc(pos: Vector2, size: Vector2): Rect2 {
|
||||
result: Rect2 = {pos, Vector2Add(pos, size)};
|
||||
return result;
|
||||
}
|
||||
|
||||
GetRectSize :: proc(rect: Rect2): Vector2 {
|
||||
result: Vector2 = {rect.max.x - rect.min.x, rect.max.y - rect.min.y};
|
||||
return result;
|
||||
}
|
||||
|
||||
RectToRectangle :: proc(rect: Rect2): Rectangle {
|
||||
size := GetRectSize(rect);
|
||||
result: Rectangle = {rect.min.x, rect.min.y, size.x, size.y};
|
||||
return result;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
ArrayOfName :: struct {
|
||||
data: *Name;
|
||||
len: int;
|
||||
cap: int;
|
||||
}
|
||||
|
||||
TryGrowingNameArray :: proc(arr: *ArrayOfName) {
|
||||
if (arr.len + 1 > arr.cap) {
|
||||
cap := arr.cap * 2;
|
||||
if (cap == 0) cap = 16;
|
||||
|
||||
arr.data = libc.realloc(arr.data, sizeof(arr.data[0]) * :libc.size_t(cap));
|
||||
arr.cap = cap;
|
||||
}
|
||||
}
|
||||
|
||||
AddName :: proc(arr: *ArrayOfName, item: Name) {
|
||||
TryGrowingNameArray(arr);
|
||||
arr.data[arr.len] = item;
|
||||
arr.len += 1;
|
||||
}
|
||||
|
||||
InsertName :: proc(a: *ArrayOfName, item: Name, index: int) {
|
||||
if index == a.len {
|
||||
AddName(a, item);
|
||||
return;
|
||||
}
|
||||
|
||||
libc.assert(index < a.len);
|
||||
libc.assert(index >= 0);
|
||||
|
||||
TryGrowingNameArray(a);
|
||||
right_len := :libc.size_t(a.len - index);
|
||||
libc.memmove(&a.data[index + 1], &a.data[index], sizeof(a.data[0]) * right_len);
|
||||
a.data[index] = item;
|
||||
a.len += 1;
|
||||
}
|
||||
|
||||
GetLastName :: proc(a: ArrayOfName): *Name {
|
||||
libc.assert(a.len > 0);
|
||||
result := &a.data[a.len - 1];
|
||||
return result;
|
||||
}
|
||||
|
||||
PopName :: proc(a: *ArrayOfName): Name {
|
||||
a.len -= 1;
|
||||
result := a.data[a.len];
|
||||
return result;
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
import "raylib";
|
||||
|
||||
Tile :: struct {
|
||||
value: int;
|
||||
}
|
||||
|
||||
Map :: struct {
|
||||
tiles: *Tile;
|
||||
x: int;
|
||||
y: int;
|
||||
}
|
||||
|
||||
CreateMap :: proc(x: int, y: int, map: *int): Map {
|
||||
result: Map = {x = x, y = y};
|
||||
result.tiles = MemAlloc(:uint(x*y) * sizeof(:Tile));
|
||||
|
||||
for i := 0; i < x*y; i += 1 {
|
||||
result.tiles[i].value = map[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
main :: proc(): int {
|
||||
TestArena();
|
||||
return 0;
|
||||
InitWindow(800, 600, "Thing");
|
||||
SetTargetFPS(60);
|
||||
|
||||
XPIX :: 32;
|
||||
YPIX :: 32;
|
||||
|
||||
camera: Camera2D = {
|
||||
zoom = 1.0,
|
||||
};
|
||||
|
||||
_map_x :: 8;
|
||||
_map_y :: 8;
|
||||
map := CreateMap(_map_x, _map_y, &:[_map_x * _map_y]int{
|
||||
1,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
1,0,0,0,0,0,0,1,
|
||||
0,0,0,0,1,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,
|
||||
}[0]);
|
||||
|
||||
for !WindowShouldClose() {
|
||||
if IsMouseButtonDown(MOUSE_BUTTON_LEFT) {
|
||||
delta := GetMouseDelta();
|
||||
camera.offset = Vector2Add(camera.offset, delta);
|
||||
}
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
BeginMode2D(camera);
|
||||
for y_it := 0; y_it < map.y; y_it += 1 {
|
||||
for x_it := 0; x_it < map.x; x_it += 1 {
|
||||
tile := &map.tiles[x_it + y_it * map.x];
|
||||
original_rect := RectFromSize({XPIX * :float(x_it), YPIX * :float(y_it)}, {XPIX, YPIX});
|
||||
rect := Shrink(original_rect, 2);
|
||||
|
||||
r := RectToRectangle(rect);
|
||||
|
||||
min_screen := GetWorldToScreen2D(original_rect.min, camera);
|
||||
size := GetRectSize(original_rect);
|
||||
|
||||
screen_rect: Rectangle = {min_screen.x, min_screen.y, size.x, size.y};
|
||||
mouse_p := GetMousePosition();
|
||||
|
||||
if tile.value == 1 {
|
||||
DrawRectangleRec(r, RED);
|
||||
} else {
|
||||
DrawRectangleRec(r, GREEN);
|
||||
}
|
||||
|
||||
if CheckCollisionPointRec(mouse_p, screen_rect) {
|
||||
DrawRectangleRec(r, BLUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
EndMode2D();
|
||||
|
||||
// DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user