Added globals and refactor for wasm.
This commit is contained in:
+27
-19
@@ -3,9 +3,6 @@ package simulator
|
||||
import emu "../machine"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
// Globals
|
||||
run: bool
|
||||
|
||||
// Window
|
||||
WINDOW_WIDTH :: 1920
|
||||
WINDOW_HEIGHT :: 1080
|
||||
@@ -42,21 +39,30 @@ Layout :: struct {
|
||||
}
|
||||
|
||||
init :: proc(sim: ^Simulator) {
|
||||
run = true
|
||||
_sim = sim
|
||||
|
||||
// desktop
|
||||
when ODIN_OS != .JS {
|
||||
rl.SetConfigFlags({.WINDOW_RESIZABLE})
|
||||
rl.SetTargetFPS(60)
|
||||
}
|
||||
|
||||
// web
|
||||
when ODIN_OS == .JS {
|
||||
rl.SetConfigFlags({.VSYNC_HINT})
|
||||
}
|
||||
|
||||
rl.SetConfigFlags({.WINDOW_RESIZABLE})
|
||||
rl.InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Octal Cookie - Chip 8 Simulator")
|
||||
rl.InitAudioDevice()
|
||||
rl.SetTargetFPS(60)
|
||||
|
||||
// Load sound
|
||||
beep := rl.LoadSound("./assets/sounds/beep.wav")
|
||||
sim.sound = beep
|
||||
_sim.sound = beep
|
||||
|
||||
// Load fonts
|
||||
font := rl.LoadFontEx("./assets/fonts/Inter_18pt-Regular.ttf", 18, nil, 0)
|
||||
rl.SetTextureFilter(font.texture, .BILINEAR)
|
||||
sim.font = font
|
||||
_sim.font = font
|
||||
|
||||
rl.GuiLoadStyleDefault()
|
||||
rl.GuiLoadStyle("./assets/raygui_styles/genesis.rgs")
|
||||
@@ -65,7 +71,9 @@ init :: proc(sim: ^Simulator) {
|
||||
rl.GuiSetStyle(.DEFAULT, i32(rl.GuiDefaultProperty.TEXT_SIZE), 18)
|
||||
}
|
||||
|
||||
update :: proc(sim: ^Simulator) {
|
||||
update :: proc() {
|
||||
sim := _sim
|
||||
|
||||
// Recalculate layout each frame based on current window size
|
||||
// Pass these down to gui functions so they can setup their sizes?
|
||||
screen_width := f32(rl.GetScreenWidth())
|
||||
@@ -98,7 +106,7 @@ update :: proc(sim: ^Simulator) {
|
||||
|
||||
// Left
|
||||
// ------------------------------------------
|
||||
gui_file_loader(layout.file_loader, sim)
|
||||
when ODIN_OS != .JS { gui_file_loader(layout.file_loader, sim)}
|
||||
gui_key_pad(layout.keypad, sim.machine.keypad, sim.font)
|
||||
|
||||
// Center
|
||||
@@ -119,9 +127,11 @@ update :: proc(sim: ^Simulator) {
|
||||
gui_info_box(layout.info_box, sim, screen_width, screen_height)
|
||||
|
||||
rl.EndDrawing()
|
||||
free_all(context.temp_allocator)
|
||||
}
|
||||
|
||||
shutdown :: proc(sim: ^Simulator) {
|
||||
shutdown :: proc() {
|
||||
sim := _sim
|
||||
rl.UnloadFont(sim.font)
|
||||
rl.UnloadSound(sim.sound)
|
||||
rl.CloseAudioDevice()
|
||||
@@ -129,13 +139,10 @@ shutdown :: proc(sim: ^Simulator) {
|
||||
}
|
||||
|
||||
should_run :: proc() -> bool {
|
||||
when ODIN_OS != .JS {
|
||||
if rl.WindowShouldClose() {
|
||||
run = false
|
||||
}
|
||||
}
|
||||
|
||||
return run
|
||||
when ODIN_OS != .JS {
|
||||
return !rl.WindowShouldClose()
|
||||
}
|
||||
return true // web loop is controlled by JS requestAnimationFrame
|
||||
}
|
||||
|
||||
tick_timers :: proc(sim: ^Simulator) {
|
||||
@@ -146,7 +153,8 @@ tick_timers :: proc(sim: ^Simulator) {
|
||||
sim.machine.sound_timer -= 1
|
||||
if !rl.IsSoundPlaying(beep) do rl.PlaySound(beep)
|
||||
} else {
|
||||
rl.StopSound(beep)
|
||||
// only stop if actually playing
|
||||
if rl.IsSoundPlaying(beep) do rl.StopSound(beep)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ package simulator
|
||||
import emu "../machine"
|
||||
import rl "vendor:raylib"
|
||||
|
||||
@(private="package")
|
||||
_sim: ^Simulator
|
||||
|
||||
// Embed roms
|
||||
roms := #load_directory("../roms")
|
||||
|
||||
@@ -43,19 +46,3 @@ Simulator :: struct {
|
||||
disasm_count: int,
|
||||
disasm_scroll: rl.Vector2,
|
||||
}
|
||||
|
||||
// Requires an initilized emulatore System Struct
|
||||
/*
|
||||
run_simulator :: proc(s: ^emu.System) {
|
||||
sim := Simulator {
|
||||
machine = s,
|
||||
rom_loaded = false,
|
||||
paused = true,
|
||||
step = false,
|
||||
cpu_hz = 700,
|
||||
disasm_follow = true,
|
||||
}
|
||||
|
||||
run_gui(&sim)
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user