Small cleanup with new run machine proc.
This commit is contained in:
+26
-31
@@ -7,16 +7,16 @@ import rl "vendor:raylib"
|
|||||||
WINDOW_WIDTH :: 1920
|
WINDOW_WIDTH :: 1920
|
||||||
WINDOW_HEIGHT :: 1080
|
WINDOW_HEIGHT :: 1080
|
||||||
|
|
||||||
// TODO: If this grows lets move it into its own file
|
// @TODO: If this grows lets move it into its own file
|
||||||
SIDEBAR_PERCENT :: 0.20
|
SIDEBAR_PERCENT :: 0.20
|
||||||
DISPLAY_PERCENT :: 0.30
|
DISPLAY_PERCENT :: 0.30
|
||||||
CONTROLBAR_PERCENT :: 0.05
|
CONTROLBAR_PERCENT :: 0.05
|
||||||
|
|
||||||
Layout :: struct {
|
Layout :: struct {
|
||||||
left_panel : rl.Rectangle,
|
|
||||||
right_panel : rl.Rectangle,
|
|
||||||
display : rl.Rectangle,
|
|
||||||
control_bar : rl.Rectangle,
|
control_bar : rl.Rectangle,
|
||||||
|
left_panel : rl.Rectangle,
|
||||||
|
display : rl.Rectangle,
|
||||||
|
right_panel : rl.Rectangle,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize main the gui 'window'
|
// Initialize main the gui 'window'
|
||||||
@@ -34,20 +34,16 @@ init_gui :: proc(s: ^m.System) {
|
|||||||
screen_height := f32(rl.GetScreenHeight())
|
screen_height := f32(rl.GetScreenHeight())
|
||||||
sidebar_width := screen_width * 0.20
|
sidebar_width := screen_width * 0.20
|
||||||
|
|
||||||
|
// set all the layout structs dynamically with the screen size
|
||||||
layout := calc_layout(screen_width, screen_height)
|
layout := calc_layout(screen_width, screen_height)
|
||||||
|
|
||||||
rl.BeginDrawing()
|
rl.BeginDrawing()
|
||||||
rl.ClearBackground(rl.BLACK)
|
rl.ClearBackground(rl.BLACK)
|
||||||
|
|
||||||
// TODO: move this out / make better
|
// Cycle the machine to update memory etc
|
||||||
// --------------------------------------
|
m.run_machine(s)
|
||||||
// CPU cycles
|
|
||||||
for _ in 0..<12 {
|
|
||||||
m.handle_input(s)
|
|
||||||
m.cycle(s)
|
|
||||||
}
|
|
||||||
// --------------------------------------
|
|
||||||
|
|
||||||
|
// Now draw the update data
|
||||||
gui_left_panel(layout.left_panel, s)
|
gui_left_panel(layout.left_panel, s)
|
||||||
gui_right_panel(layout.right_panel, s)
|
gui_right_panel(layout.right_panel, s)
|
||||||
gui_screen(layout.display, s)
|
gui_screen(layout.display, s)
|
||||||
@@ -60,38 +56,37 @@ init_gui :: proc(s: ^m.System) {
|
|||||||
rl.CloseWindow()
|
rl.CloseWindow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: If this grows lets move it into its own file
|
// @TODO: If this grows lets move it into its own file
|
||||||
calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout {
|
calc_layout :: proc(screen_width: f32, screen_height: f32) -> Layout {
|
||||||
|
control_bar_height := screen_height * CONTROLBAR_PERCENT
|
||||||
sidebar_width := screen_width * SIDEBAR_PERCENT
|
sidebar_width := screen_width * SIDEBAR_PERCENT
|
||||||
display_height := screen_height * DISPLAY_PERCENT
|
sidebar_height := screen_height - control_bar_height
|
||||||
|
display_height := screen_height * DISPLAY_PERCENT - control_bar_height
|
||||||
|
|
||||||
return Layout {
|
return Layout {
|
||||||
left_panel = rl.Rectangle {
|
control_bar = rl.Rectangle {
|
||||||
x = 0,
|
x = 0,
|
||||||
y = 0,
|
y = 0,
|
||||||
width = sidebar_width,
|
width = screen_width,
|
||||||
height = screen_height
|
height = control_bar_height
|
||||||
},
|
},
|
||||||
|
left_panel = rl.Rectangle {
|
||||||
right_panel = rl.Rectangle {
|
x = 0,
|
||||||
x = screen_width - sidebar_width,
|
y = control_bar_height,
|
||||||
y = 0,
|
|
||||||
width = sidebar_width,
|
width = sidebar_width,
|
||||||
height = screen_height
|
height = sidebar_height
|
||||||
},
|
},
|
||||||
|
|
||||||
display = rl.Rectangle {
|
display = rl.Rectangle {
|
||||||
x = sidebar_width,
|
x = sidebar_width,
|
||||||
y = 0,
|
y = control_bar_height,
|
||||||
width = screen_width - (sidebar_width * 2),
|
width = screen_width - (sidebar_width * 2),
|
||||||
height = display_height
|
height = display_height
|
||||||
},
|
},
|
||||||
|
right_panel = rl.Rectangle {
|
||||||
control_bar = rl.Rectangle {
|
x = screen_width - sidebar_width,
|
||||||
x = sidebar_width,
|
y = control_bar_height,
|
||||||
y = display_height,
|
width = sidebar_width,
|
||||||
width = screen_width - (sidebar_width * 2),
|
height = sidebar_height
|
||||||
height = (screen_height * 0.05)
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -333,5 +333,4 @@ op_mem_get :: proc(s: ^System, vx_idx: u16) {
|
|||||||
for loop_idx in 0..=vx_idx {
|
for loop_idx in 0..=vx_idx {
|
||||||
s.v[loop_idx] = s.memory[s.i + loop_idx]
|
s.v[loop_idx] = s.memory[s.i + loop_idx]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,3 +60,11 @@ init :: proc() -> System {
|
|||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_machine :: proc(s: ^System) {
|
||||||
|
// CPU cycles
|
||||||
|
for _ in 0..<12 {
|
||||||
|
handle_input(s)
|
||||||
|
cycle(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user