Skip to content

Commit

Permalink
examples: add additional comments and use short enum identifiers on `…
Browse files Browse the repository at this point in the history
…return`
  • Loading branch information
larpon committed Feb 5, 2025
1 parent 3eddaf7 commit 14caf2b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions examples/ports/renderer/01-clear/clear.v
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn app_init(appstate &voidptr, argc int, argv &&char) sdl.AppResult {
if !sdl.init(sdl.init_video) {
error_msg := unsafe { cstring_to_vstring(sdl.get_error()) }
eprintln('Could not initialize SDL: ${error_msg}')
return sdl.AppResult.failure
return .failure
}
// if (!SDL_CreateWindowAndRenderer("examples/renderer/clear", 640, 480, 0, &window, &renderer)) {
// SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
Expand All @@ -58,10 +58,10 @@ pub fn app_init(appstate &voidptr, argc int, argv &&char) sdl.AppResult {
&app.window, &app.renderer) {
error_msg := unsafe { cstring_to_vstring(sdl.get_error()) }
eprintln('Could not create window/renderer: ${error_msg}')
return sdl.AppResult.failure
return .failure
}
// return SDL_APP_CONTINUE; /* carry on with the program! */
return sdl.AppResult.continue
return .continue
}

// This function runs when a new event (mouse input, keypresses, etc) occurs.
Expand All @@ -73,12 +73,12 @@ pub fn app_event(appstate voidptr, event &sdl.Event) sdl.AppResult {
// }
match event.type {
.quit {
return sdl.AppResult.success
return .success
}
else {}
}
// return SDL_APP_CONTINUE; /* carry on with the program! */
return sdl.AppResult.continue
return .continue
}

// This function runs once per frame, and is the heart of the program.
Expand Down Expand Up @@ -106,7 +106,7 @@ pub fn app_iterate(appstate voidptr) sdl.AppResult {
sdl.render_present(app.renderer)
//
// return SDL_APP_CONTINUE; /* carry on with the program! */
return sdl.AppResult.continue
return .continue
}

// This function runs once at shutdown.
Expand Down
14 changes: 7 additions & 7 deletions examples/ports/renderer/02-primitives/primitives.v
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ pub fn app_init(appstate &voidptr, argc int, argv &&char) sdl.AppResult {
if !sdl.init(sdl.init_video) {
error_msg := unsafe { cstring_to_vstring(sdl.get_error()) }
eprintln('Could not initialize SDL: ${error_msg}')
return sdl.AppResult.failure
return .failure
}

if !sdl.create_window_and_renderer('examples/renderer/primitives'.str, 640, 480, sdl.WindowFlags(0),
&app.window, &app.renderer) {
error_msg := unsafe { cstring_to_vstring(sdl.get_error()) }
eprintln('Could not create window/renderer: ${error_msg}')
return sdl.AppResult.failure
return .failure
}

// set up some random points
Expand All @@ -54,18 +54,18 @@ pub fn app_init(appstate &voidptr, argc int, argv &&char) sdl.AppResult {
app.points[i].y = (sdl.randf() * 280.0) + 100.0
}

return sdl.AppResult.continue // carry on with the program!
return .continue // carry on with the program!
}

// This function runs when a new event (mouse input, keypresses, etc) occurs.
pub fn app_event(appstate voidptr, event &sdl.Event) sdl.AppResult {
match event.type {
.quit {
return sdl.AppResult.success
return .success // end the program, reporting success to the OS.
}
else {}
}
return sdl.AppResult.continue
return .continue // carry on with the program!
}

// This function runs once per frame, and is the heart of the program.
Expand All @@ -76,7 +76,7 @@ pub fn app_iterate(appstate voidptr) sdl.AppResult {

// as you can see from this, rendering draws over whatever was drawn before it.
sdl.set_render_draw_color(app.renderer, 33, 33, 33, sdl.alpha_opaque) // dark gray, full alpha
sdl.render_clear(app.renderer)
sdl.render_clear(app.renderer) // start with a blank canvas.

// draw a filled rectangle in the middle of the canvas.
sdl.set_render_draw_color(app.renderer, 0, 0, 255, sdl.alpha_opaque) // blue, full alpha
Expand All @@ -102,7 +102,7 @@ pub fn app_iterate(appstate voidptr) sdl.AppResult {
sdl.render_line(app.renderer, 0, 0, 640, 480)
sdl.render_line(app.renderer, 0, 480, 640, 0)
sdl.render_present(app.renderer) // put it all on the screen!
return sdl.AppResult.continue
return .continue
}

// This function runs once at shutdown.
Expand Down

0 comments on commit 14caf2b

Please sign in to comment.