Skip to content

Commit

Permalink
Rename ALL getters from get_foo() to foo().
Browse files Browse the repository at this point in the history
See issue ggez#424 for discussion.

So far I rather like this change but it's going to live in its own
branch for a little because it's VERY far-reaching.

I tried having builder structs use `with_foo()` instead of `foo()`
but I find I like that rather less, even if it conflates the
meanings a little.
  • Loading branch information
icefoxen committed Aug 22, 2018
1 parent 998fd04 commit f2e58f3
Show file tree
Hide file tree
Showing 26 changed files with 103 additions and 101 deletions.
6 changes: 3 additions & 3 deletions docs/guides/HelloGgez.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ let state = &mut State { dt: std::time::Duration::new(0, 0) };
```

So now that we have state to update, let's update it in our `update` callback!
We'll use [`timer::get_delta`](https://docs.rs/ggez/0.4.0/ggez/timer/fn.get_delta.html) to get the delta time.
We'll use [`timer::delta`](https://docs.rs/ggez/0.4.0/ggez/timer/fn.delta.html) to get the delta time.
```rust
fn update(&mut self, ctx: &mut Context) -> GameResult<()> {
self.dt = timer::get_delta(ctx);
self.dt = timer::delta(ctx);
Ok(())
}
```
Expand All @@ -243,7 +243,7 @@ fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
}
```
Every frame, print out `Hello ggez! dt = {}ns`. This will print once a frame. Which is going to be a lot.

### ✔ Check Program

And yet again, run `cargo run`.
Expand Down
10 changes: 5 additions & 5 deletions examples/canvas_subframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl MainState {
graphics::clear(ctx, graphics::WHITE);

// Freeze the animation so things are easier to see.
// let time = (timer::duration_to_f64(timer::get_time_since_start(ctx)) * 1000.0) as u32;
// let time = (timer::duration_to_f64(timer::time_since_start(ctx)) * 1000.0) as u32;
let time = 2000;
let cycle = 10_000;
for x in 0..150 {
Expand Down Expand Up @@ -88,13 +88,13 @@ impl MainState {

impl event::EventHandler for MainState {
fn update(&mut self, ctx: &mut Context) -> GameResult {
if timer::get_ticks(ctx) % 100 == 0 {
println!("Delta frame time: {:?} ", timer::get_delta(ctx));
println!("Average FPS: {}", timer::get_fps(ctx));
if timer::ticks(ctx) % 100 == 0 {
println!("Delta frame time: {:?} ", timer::delta(ctx));
println!("Average FPS: {}", timer::fps(ctx));
}

// Bounce the rect if necessary
let (w, h) = graphics::get_size(ctx);
let (w, h) = graphics::size(ctx);
if self.draw_pt.x + (w as f32 / 2.0) > (w as f32) || self.draw_pt.x < 0.0 {
self.draw_vec.x *= -1.0;
}
Expand Down
10 changes: 5 additions & 5 deletions examples/cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ struct MainState {

impl MainState {
fn new(ctx: &mut Context) -> Self {
let color_view = graphics::get_screen_render_target(ctx);
let depth_view = graphics::get_depth_view(ctx);
let factory = graphics::get_factory(ctx);
let color_view = graphics::screen_render_target(ctx);
let depth_view = graphics::depth_view(ctx);
let factory = graphics::factory(ctx);

// Shaders.
let vs = br#"#version 150 core
Expand Down Expand Up @@ -212,7 +212,7 @@ impl event::EventHandler for MainState {
// Do gfx-rs drawing
{
let (_factory, device, encoder, _depthview, _colorview) =
graphics::get_gfx_objects(ctx);
graphics::gfx_objects(ctx);
encoder.clear(&self.data.out_color, [0.1, 0.1, 0.1, 1.0]);

let rotation = na::Matrix4::from_scaled_axis(na::Vector3::z() * self.rotation);
Expand Down Expand Up @@ -250,7 +250,7 @@ impl event::EventHandler for MainState {
graphics::present(ctx)?;
self.frames += 1;
if (self.frames % 10) == 0 {
println!("FPS: {}", ggez::timer::get_fps(ctx));
println!("FPS: {}", ggez::timer::fps(ctx));
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn main() -> GameResult {

let (ctx, events_loop) = &mut cb.build()?;

println!("{}", graphics::get_renderer_info(ctx)?);
println!("{}", graphics::renderer_info(ctx)?);
let state = &mut MainState::new(ctx).unwrap();
event::run(ctx, events_loop, state)
}
9 changes: 5 additions & 4 deletions examples/graphics_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl event::EventHandler for MainState {

/*
if self.window_settings.window_size_toggle {
let resolutions = ggez::graphics::get_fullscreen_modes(ctx, 0)?;
let resolutions = ggez::graphics::fullscreen_modes(ctx, 0)?;
let (width, height) = resolutions[self.window_settings.resolution_index];
ggez::graphics::set_resolution(ctx, width, height)?;
Expand All @@ -83,13 +83,14 @@ impl event::EventHandler for MainState {

fn draw(&mut self, ctx: &mut Context) -> GameResult {
graphics::clear(ctx, graphics::BLACK);
let rotation = timer::get_ticks(ctx) % 1000;
let rotation = timer::ticks(ctx) % 1000;
let circle = graphics::Mesh::new_circle(
ctx,
DrawMode::Line(3.0),
Point2::new(0.0, 0.0),
100.0,
4.0,
graphics::WHITE
)?;
graphics::draw(
ctx,
Expand Down Expand Up @@ -160,15 +161,15 @@ impl event::EventHandler for MainState {
KeyCode::Up => {
self.zoom += 0.1;
println!("Zoom is now {}", self.zoom);
let (w, h) = graphics::get_size(ctx);
let (w, h) = graphics::size(ctx);
let new_rect =
graphics::Rect::new(0.0, 0.0, w as f32 * self.zoom, h as f32 * self.zoom);
graphics::set_screen_coordinates(ctx, new_rect).unwrap();
}
KeyCode::Down => {
self.zoom -= 0.1;
println!("Zoom is now {}", self.zoom);
let (w, h) = graphics::get_size(ctx);
let (w, h) = graphics::size(ctx);
let new_rect =
graphics::Rect::new(0.0, 0.0, w as f32 * self.zoom, h as f32 * self.zoom);
graphics::set_screen_coordinates(ctx, new_rect).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl event::EventHandler for MainState {
// Drawables are drawn from their top-left corner.
self.frames += 1;
if (self.frames % 100) == 0 {
println!("FPS: {}", ggez::timer::get_fps(ctx));
println!("FPS: {}", ggez::timer::fps(ctx));
}

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl event::EventHandler for MainState {

self.frames += 1;
if (self.frames % 100) == 0 {
println!("FPS: {}", ggez::timer::get_fps(ctx));
println!("FPS: {}", ggez::timer::fps(ctx));
}

Ok(())
Expand Down Expand Up @@ -81,7 +81,7 @@ pub fn main() -> GameResult {
;
let (ctx, event_loop) = &mut cb.build()?;

println!("HIDPI: {}", graphics::get_hidpi_factor(ctx));
println!("HIDPI: {}", graphics::hidpi_factor(ctx));

let state = &mut MainState::new(ctx)?;
event::run(ctx, event_loop, state)
Expand Down
4 changes: 2 additions & 2 deletions examples/imageview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ impl event::EventHandler for MainState {
if self.a > 250 || self.a <= 0 {
self.direction *= -1;

println!("Delta frame time: {:?} ", timer::get_delta(ctx));
println!("Average FPS: {}", timer::get_fps(ctx));
println!("Delta frame time: {:?} ", timer::delta(ctx));
println!("Average FPS: {}", timer::fps(ctx));
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion examples/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl FileLogger {
debug!(
"Created log file {:?} in {:?}",
path,
filesystem::get_user_config_dir(ctx)
filesystem::user_config_dir(ctx)
);
Ok(FileLogger { file, receiver })
}
Expand Down
2 changes: 1 addition & 1 deletion examples/render_to_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl event::EventHandler for MainState {

// now lets render our scene once in the top right and in the bottom
// right
let window_size = graphics::get_size(ctx);
let window_size = graphics::size(ctx);
let scale = Vector2::new(
0.5 * window_size.0 as f32 / self.canvas.image().width() as f32,
0.5 * window_size.1 as f32 / self.canvas.image().height() as f32,
Expand Down
2 changes: 1 addition & 1 deletion examples/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl MainState {

impl event::EventHandler for MainState {
fn update(&mut self, ctx: &mut Context) -> GameResult {
self.dim.rate = 0.5 + (((timer::get_ticks(ctx) as f32) / 100.0).cos() / 2.0);
self.dim.rate = 0.5 + (((timer::ticks(ctx) as f32) / 100.0).cos() / 2.0);
Ok(())
}

Expand Down
20 changes: 10 additions & 10 deletions examples/shadows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl MainState {
graphics::Text::new(("SHADOWS...", font, 48.0))
};
let screen_size = {
let size = graphics::get_drawable_size(ctx);
let size = graphics::drawable_size(ctx);
[size.0 as f32, size.1 as f32]
};
let torch = Light {
Expand All @@ -214,7 +214,7 @@ impl MainState {
glow: 0.0,
strength: LIGHT_STRENGTH,
};
let (w, h) = graphics::get_size(ctx);
let (w, h) = graphics::size(ctx);
let (x, y) = (100.0 / w as f32, 1.0 - 75.0 / h as f32);
let static_light = Light {
pos: [x, y],
Expand Down Expand Up @@ -279,7 +279,7 @@ impl MainState {
origin: DrawParam,
canvas_origin: DrawParam,
) -> GameResult {
let size = graphics::get_size(ctx);
let size = graphics::size(ctx);
// Now we want to run the occlusions shader to calculate our 1D shadow
// distances into the `occlusions` canvas.
graphics::set_canvas(ctx, Some(&self.occlusions));
Expand Down Expand Up @@ -321,23 +321,23 @@ impl MainState {

impl event::EventHandler for MainState {
fn update(&mut self, ctx: &mut Context) -> GameResult {
if timer::get_ticks(ctx) % 100 == 0 {
println!("Average FPS: {}", timer::get_fps(ctx));
if timer::ticks(ctx) % 100 == 0 {
println!("Average FPS: {}", timer::fps(ctx));
}

self.torch.glow =
LIGHT_GLOW_FACTOR * ((timer::get_ticks(ctx) as f32) / LIGHT_GLOW_RATE).cos();
LIGHT_GLOW_FACTOR * ((timer::ticks(ctx) as f32) / LIGHT_GLOW_RATE).cos();
self.static_light.glow =
LIGHT_GLOW_FACTOR * ((timer::get_ticks(ctx) as f32) / LIGHT_GLOW_RATE * 0.75).sin();
LIGHT_GLOW_FACTOR * ((timer::ticks(ctx) as f32) / LIGHT_GLOW_RATE * 0.75).sin();
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult {
let size = graphics::get_size(ctx);
let size = graphics::size(ctx);
let origin = DrawParam::new().dest(Point2::new(0.0, 0.0));
// for re-rendering canvases, we need to take the DPI into account
let dpiscale = {
let dsize = graphics::get_drawable_size(ctx);
let dsize = graphics::drawable_size(ctx);
Vector2::new(
size.0 as f32 / dsize.0 as f32,
size.1 as f32 / dsize.1 as f32,
Expand Down Expand Up @@ -409,7 +409,7 @@ impl event::EventHandler for MainState {
}

fn mouse_motion_event(&mut self, ctx: &mut Context, x: f32, y: f32, _xrel: f32, _yrel: f32) {
let (w, h) = graphics::get_size(ctx);
let (w, h) = graphics::size(ctx);
let (x, y) = (x / w as f32, 1.0 - y / h as f32);
self.torch.pos = [x, y];
}
Expand Down
8 changes: 4 additions & 4 deletions examples/spritebatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ impl MainState {

impl event::EventHandler for MainState {
fn update(&mut self, ctx: &mut Context) -> GameResult {
if timer::get_ticks(ctx) % 100 == 0 {
println!("Delta frame time: {:?} ", timer::get_delta(ctx));
println!("Average FPS: {}", timer::get_fps(ctx));
if timer::ticks(ctx) % 100 == 0 {
println!("Delta frame time: {:?} ", timer::delta(ctx));
println!("Average FPS: {}", timer::fps(ctx));
}
Ok(())
}

fn draw(&mut self, ctx: &mut Context) -> GameResult {
graphics::clear(ctx, graphics::BLACK);

let time = (timer::duration_to_f64(timer::get_time_since_start(ctx)) * 1000.0) as u32;
let time = (timer::duration_to_f64(timer::time_since_start(ctx)) * 1000.0) as u32;
let cycle = 10_000;
for x in 0..150 {
for y in 0..150 {
Expand Down
2 changes: 1 addition & 1 deletion examples/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl event::EventHandler for App {
// `Text` can be used in "immediate mode", but it's slightly less efficient
// in most cases, and horrifically less efficient in a few select ones
// (using `.width()` or `.height()`, for example).
let fps = timer::get_fps(ctx);
let fps = timer::fps(ctx);
let fps_display = Text::new(format!("FPS: {}", fps));
// When drawing through these calls, `DrawParam` will work as they are documented.
graphics::draw(
Expand Down
2 changes: 1 addition & 1 deletion examples/transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl MainState {
for y in 0..Self::GRID_SIZE {
let point = na::Point2::new(x as f32 * Self::GRID_INTERVAL, y as f32 * Self::GRID_INTERVAL);
gridmesh_builder
.circle(DrawMode::Fill, point, Self::GRID_POINT_RADIUS, 2.0);
.circle(DrawMode::Fill, point, Self::GRID_POINT_RADIUS, 2.0, graphics::WHITE);
}
}
let gridmesh = gridmesh_builder.build(ctx)?;
Expand Down
6 changes: 3 additions & 3 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ where
button,
..
} => {
let position = mouse::get_position(ctx);
let position = mouse::position(ctx);
match element_state {
ElementState::Pressed => {
state.mouse_button_down_event(ctx, button, position.x, position.y)
Expand All @@ -215,8 +215,8 @@ where
}
}
WindowEvent::CursorMoved { .. } => {
let position = mouse::get_position(ctx);
let delta = mouse::get_delta(ctx);
let position = mouse::position(ctx);
let delta = mouse::delta(ctx);
state.mouse_motion_event(ctx, position.x, position.y, delta.x, delta.y);
}
x => {
Expand Down
6 changes: 3 additions & 3 deletions src/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,18 +384,18 @@ pub fn is_dir<P: AsRef<path::Path>>(ctx: &Context, path: P) -> bool {
}

/// Return the full path to the user data directory
pub fn get_user_data_dir(ctx: &Context) -> &path::Path {
pub fn user_data_dir(ctx: &Context) -> &path::Path {
&ctx.filesystem.user_data_path
}

/// Return the full path to the user config directory
pub fn get_user_config_dir(ctx: &Context) -> &path::Path {
pub fn user_config_dir(ctx: &Context) -> &path::Path {
&ctx.filesystem.user_config_path
}

/// Returns the full path to the resource directory
/// (even if it doesn't exist)
pub fn get_resources_dir(ctx: &Context) -> &path::Path {
pub fn resources_dir(ctx: &Context) -> &path::Path {
&ctx.filesystem.resources_path
}

Expand Down
2 changes: 1 addition & 1 deletion src/graphics/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Canvas {
/// Create a new canvas with the current window dimensions.
pub fn with_window_size(ctx: &mut Context) -> GameResult<Canvas> {
use graphics;
let (w, h) = graphics::get_drawable_size(ctx);
let (w, h) = graphics::drawable_size(ctx);
// Default to no multisampling
// TODO: Use winit's into() to translate f64's more accurately
Canvas::new(ctx, w as u16, h as u16, conf::NumSamples::One)
Expand Down
5 changes: 3 additions & 2 deletions src/graphics/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ pub use self::t::{FillOptions, FillRule, LineCap, LineJoin, StrokeOptions};
/// na::Point2::new(0.0, 0.0),
/// ],
/// 1.0,
/// graphics::WHITE,
/// )
/// // Add vertices for an exclamation mark!
/// .ellipse(DrawMode::Fill, na::Point2::new(0.0, 25.0), 2.0, 15.0, 2.0)
/// .circle(DrawMode::Fill, na::Point2::new(0.0, 45.0), 2.0, 2.0)
/// .ellipse(DrawMode::Fill, na::Point2::new(0.0, 25.0), 2.0, 15.0, 2.0, graphics::WHITE,)
/// .circle(DrawMode::Fill, na::Point2::new(0.0, 45.0), 2.0, 2.0, graphics::WHITE,)
/// // Finalize then unwrap. Unwrapping via `?` operator either yields the final `Mesh`,
/// // or propagates the error (note return type).
/// .build(ctx)?;
Expand Down
Loading

0 comments on commit f2e58f3

Please sign in to comment.