Skip to content

Commit

Permalink
maze
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawSumma committed Jun 23, 2024
1 parent 18de731 commit 224d010
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 4 deletions.
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MAC_RAYLIB_OBJS = $(RAYLIB_DIR)/rcore.o $(RAYLIB_DIR)/rglfw.o $(RAYLIB_DIR)/rsha

mac: .dummy
$(PRE) make -Bj$(J) -C vendor/raylib/src CC="$(CC)" LDFLAGS="$(OPT)" CFLAGS="-w $(OPT) $(CLFAGS) -DPLATFORM_DESKTOP" PLATFORM=PLATFORM_DESKTOP
$(PRE) make -Bj$(J) -f tool/core.mak $(TARGET) OS=MAC CC="$(CC)" EXE= TEST_LUA="$(TEST_LUA)" CFLAGS="-DVM_USE_RAYLIB $(CFLAGS)" LDFLAGS="$(MAC_RAYLIB_OBJS) -framework Cocoa -framework OpenGL -framework IOKit $(LDFLAGS)"
$(PRE) make -Bj$(J) -f tool/core.mak $(TARGET) OS=MAC CC="$(CC)" EXE= TEST_LUA="$(TEST_LUA)" CFLAGS="-DVM_USE_RAYLIB -DVM_NO_GC $(CFLAGS)" LDFLAGS="$(MAC_RAYLIB_OBJS) -framework Cocoa -framework OpenGL -framework IOKit $(LDFLAGS)"

windows: .dummy
$(PRE) make -Bj$(J) -f tool/core.mak $(TARGET) OS=WINDOWS CC="$(CC)" EXE=.exe TEST_LUA="$(TEST_LUA)"
Expand Down
1 change: 0 additions & 1 deletion test/app/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function Color.new(red, green, blue)
}
end


Color.RED = Color.new(255, 0, 0)
Color.ORANGE = Color.new(255, 127, 0)
Color.YELLOW = Color.new(255, 255, 0)
Expand Down
130 changes: 130 additions & 0 deletions test/app/maze.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@

local gui = vm.import("test/app/gui.lua")

local debug = false

local s = 20

local xs = 2 * s + 3
local ys = 2 * s + 3

local grid = gui.Grid.new(xs, ys)

local dir = {
root = 0
nx = 1,
px = 2,
ny = 3,
py = 4,
}

local maze = {}

for x=1, s do
maze[x] = {}
for y=1, s do
if y ~= 1 then
maze[x][y] = dir.ny
elseif x ~= 1 then
maze[x][y] = dir.nx
else
maze[x][y] = dir.root
end
end
end

local seed = {
seed1 = 0
}

local function random(n)
seed.seed1 = (3301 * seed.seed1 + 4993) % 6121
return (seed.seed1) % n
end

local function frame()
for x=1, xs do
for y=1, ys do
grid[x][y] = gui.Rectangle.BLACK
end
end

for x=1, #maze do
for y=1, #maze[x] do
local px = x*2 + 1
local py = y*2 + 1
local ent = maze[x][y]
grid[px][py] = gui.Rectangle.ORANGE
if ent == dir.root then
grid[px][py] = gui.Rectangle.RED
end
if ent == dir.nx then
grid[px-1][py] = gui.Rectangle.YELLOW
end
if ent == dir.px then
grid[px+1][py] = gui.Rectangle.YELLOW
end
if ent == dir.ny then
grid[px][py-1] = gui.Rectangle.YELLOW
end
if ent == dir.py then
grid[px][py+1] = gui.Rectangle.YELLOW
end
end
end
end

local function maze_iter()
for x=1, #maze do
for y=1, #maze[x] do
local ent = maze[x][y]
if ent == dir.root then
local more = true
while more do
local v = random(4) + 1
maze[x][y] = v
if v == dir.nx and x ~= 1 then
maze[x-1][y] = dir.root
more = false
end
if v == dir.px and x ~= #maze then
maze[x+1][y] = dir.root
more = false
end
if v == dir.ny and y ~= 1 then
maze[x][y-1] = dir.root
more = false
end
if v == dir.py and y ~= #maze[x] then
maze[x][y+1] = dir.root
more = false
end
end
end
end
end
end

local function rep(n)
return function()
for i=1, n do
maze_iter()
end
end
end

local code = gui.Code.new(frame)

draw = {}
draw.code = code
draw.grid = grid
draw.keys = {}
draw.keys.one = gui.Key.pressed("ONE", rep(1))
draw.keys.two = gui.Key.pressed("TWO", rep(8))
draw.keys.three = gui.Key.pressed("THREE", rep(64))
draw.keys.four = gui.Key.pressed("FOUR", rep(512))
draw.keys.five = gui.Key.pressed("FIVE", rep(2048))
draw.keys.six = gui.Key.pressed("SIX", rep(16386))
draw.window = gui.Window.new(600, 600)

app()
2 changes: 1 addition & 1 deletion vendor/bdwgc
17 changes: 16 additions & 1 deletion vm/backend/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,23 @@ vm_std_value_t vm_run_repl(vm_t *vm, vm_block_t *block) {
};
vm_std_value_t *next_regs = &regs[block->nregs];

// {
// vm_io_buffer_t *buf = vm_io_buffer_new();
// vm_io_format_block(buf, block);
// printf("func%s\n", buf->buf);
// }
goto new_block_no_print;

new_block:;


// {
// vm_io_buffer_t *buf = vm_io_buffer_new();
// vm_io_format_block(buf, block);
// printf("%s\n", buf->buf);
// }

new_block_no_print:;

uint8_t *code = block->code;
if (block->code == NULL) {
code = vm_interp_renumber_block(vm, &ptrs[0], block);
Expand Down

0 comments on commit 224d010

Please sign in to comment.