Coder Social home page Coder Social logo

jadpole.github.io's People

Contributors

aj-n avatar alondero avatar azmr avatar coryalder avatar dermetfan avatar gcatlin avatar jadpole avatar jespino avatar ryanatkn avatar ryman avatar stingray-jpelletier avatar tandrial avatar tbelaire avatar whipsch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jadpole.github.io's Issues

Apply for translation permission

Hi jadpole:
I'm a Rust developer in China,and I want to translte your rust series articles into Chinese, they are brief and easy to learn.
So, Shall I do it ?

Section 1.6 Utility methods broken

At the end of the section you have some utility methods that should be implemented but the types in the function signatures are wrong and your code doesn't have them either. What is the purpose them?

Example code broken

Hey,

In chapter 2. Event Handling, the last example code is broken. Now there is:

// Initialize SDL2
let mut sdl_context = sdl2::init().video()
    .build().unwrap();

// Create the window
let window = sdl_context.window("ArcadeRS Shooter", 800, 600)
    .position_centered().opengl()
    .build().unwrap();

But it should be:

// Initialize SDL2
let sdl_context = sdl2::init().unwrap();
let video = sdl_context.video().unwrap();

// Create the window
let window = video.window("ArcadeRS Shooter", 800, 600)
    .position_centered().opengl()
    .build().unwrap();

Otherwise the code won't compile.

Lesson 1.9 ::sdl2_ttf::Font::from_file() Deprecated?

Hello there,

I've been following your tutorial and it's been great so far. There was a version mismatch in one of the earlier lessons so I've been following along while trying to update everything that's changed from the SDL versions at the same time. I've finally ran into a problem I can't seem to solve.

This code:

        ::sdl2_ttf::Font::from_file(Path::new(font_path), size).ok()
            .and_then(|font| {
                self.cached_fonts.insert((font_path, size), font);
                self.ttf_str_sprite(text, font_path, size, color)
            })

within ttf_str_sprite() of Phi no longer works. Specifically, the from_file() function no longer exists in sdl2_ttf::Font (as of sdl2_ttf version 0.14 I believe). From what I've gathered, the only way to load fonts from here on out is directly from the sdl2_ttf context:

impl Sdl2TtfContext {
    /// Loads a font from the given file with the given size in points.
    pub fn load_font<'a>(&'a self, path: &'a Path, point_size: u16) -> Result<Font, String> {
        internal_load_font(path, point_size)
    }

    // ...
}

That's from the implementation for sdl2_ttf v0.25. I've tried to hobble together a solution that passes along the context created in spawn() by attaching it to the Phi struct:

pub struct Phi<'window> {
    pub events: Events,
    pub renderer: Renderer<'window>,
    pub ttf_context: ::sdl2_ttf::Sdl2TtfContext,

    cached_fonts: HashMap<(&'static str, i32), ::sdl2_ttf::Font<'window>>
}

Then doing this in the ttf_str_sprite() function:

    pub fn ttf_str_sprite(&mut self, text: &str, font_path: &'static str, size: i32, color: Color) -> Option<Sprite> {
        if let Some(font) = self.cached_fonts.get(&(font_path, size)) {
            return font.render(text).blended(color).ok()
                .and_then(|surface| self.renderer.create_texture_from_surface(&surface).ok())
                .map(Sprite::new)
        }
        //::sdl2_ttf::Font::from_file(Path::new(font_path), size).ok()
        self.ttf_context.load_font(Path::new(font_path), size as u16).ok()
            .and_then(|font| {
                self.cached_fonts.insert((font_path, size), font);
                self.ttf_str_sprite(text, font_path, size, color)
        })
    }

Which gives me all sorts of problems with lifetime conflicts on the load_font() function. I suspect I'm going about this all wrong. Do you have any idea on how to update this method so it works with sdl2_ttf v0.25?

Sorry for the long winded post!

1.5 doesn't declare `timer` or `get_ticks()`

While I noticed the call to timer() when building the sdl_context, I can't figure out how to actually use the frame timing code. I guessed that it was added to src/main.rs, but that isn't completely obvious, either.

What do I declare to make the third code example work?

Section 1.6/7/8 - Type mismatch

Note: This is fixed in 1.9

Checking out and compiling as-is gives:

phi/mod.rs:33:10: 33:18 error: mismatched types:
 expected `u32`,
    found `f64`
(expected u32,
    found f64) [E0308]
src\phi/mod.rs:33         (w as f64, h as f64)
                           ^~~~~~~~
src\phi/mod.rs:33:10: 33:18 help: run `rustc --explain E0308` to see a detailed explanation
src\phi/mod.rs:33:20: 33:28 error: mismatched types:
 expected `u32`,
    found `f64`
(expected u32,
    found f64) [E0308]
src\phi/mod.rs:33         (w as f64, h as f64)
                                     ^~~~~~~~
src\phi/mod.rs:33:20: 33:28 help: run `rustc --explain E0308` to see a detailed explanation
src\views/mod.rs:74:16: 74:42 error: the trait `core::ops::Mul<_>` is not implemented for the type `u32` [E0277]
src\views/mod.rs:74             w: phi.output_size().0 * 0.70,
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~
src\views/mod.rs:74:16: 74:42 help: run `rustc --explain E0277` to see a detailed explanation
src\views/mod.rs:74:16: 74:42 error: the trait `core::ops::Mul<_>` is not implemented for the type `u32` [E0277]
src\views/mod.rs:74             w: phi.output_size().0 * 0.70,
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~
src\views/mod.rs:74:16: 74:42 help: run `rustc --explain E0277` to see a detailed explanation
src\views/mod.rs:75:16: 75:35 error: mismatched types:
 expected `f64`,
    found `u32`
(expected f64,
    found u32) [E0308]
src\views/mod.rs:75             h: phi.output_size().1,
                                   ^~~~~~~~~~~~~~~~~~~
src\views/mod.rs:75:16: 75:35 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to 5 previous errors
Could not compile `arcade-rs`.

Code from Chapter 1 just fails

As the title says the code from chapter 1 just fails on Windows 7, Rust 1.14 nightly (098d22845 2016-10.13) with:
"error: process didn't exit successfully: 'target\debug\arcade-rs.exe' (exit code: 3221225781)".
I tried this code with both the sdl2 version specified in the article (0.13) and the newest one (0.24).
I also tried these both possibilities with the gl-rs bindings downloaded as the code had some mention of using opengl in the creation of window variable binding.
Am I missing something, like having to download something other than the SDL2 libraries from libsdl.org which I downloaded and put in the right directory already?

Lesson 1.7: Rectangle.to_sdl() method needs to return Option

Currently, the code in the lesson looks like this:

//  ~/src/phi/data.rs
// ...
pub fn to_sdl(self) -> Option<SdlRect> {
    assert!(self.w >= 0.0 && self.h >= 0.0);
    SdlRect::new(
        self.x as i32, self.y as i32, self.w as u32, self.h as u32
    )
}

With newer version of sdl2(v0.24.0 specifically) this will fail at the compile step as Renderer.copy() expects 2 Option<Rect>'s as arguments. I'm fairly new to Rust, but I fixed the issue by changing the code to the following:

pub fn to_sdl(self) -> Option<SdlRect> {
    assert!(self.w >= 0.0 && self.h >= 0.0);
    Some(SdlRect::new(
        self.x as i32, self.y as i32, self.w as u32, self.h as u32
    ))
}

Let me know if you think this a good solution.

Some minor issues

I enjoyed the series a lot! A few things I noticed while reading parts 1-11:

  • use paths are always relative to the crate root. You can omit all leading :: in them, which gets rid of some visual clutter.
  • The section about the "old" EventPump with a lifetime threw me off, since I didn't read the disclaimer properly. Maybe add a comment to the code block itself // note: does not compile anymore?
  • thread::sleep_ms is deprecated
  • ImmediateEvents could get a Default derive, which gets rid of the impl ImmediateEvents
  • I saw some comparison x == true which is unneeded.
  • The Rectangle utility methods, as introduced in 1.6, don't compile.
  • The initial code in 1.7, heading "Frames", does not compile (multiplying float*int).
  • In 1.7, function region() (when explaining struct update syntax), the "rect would be made invalid" wouldn't matter since it's consumed by the function anyway.
  • The "next" link from 1.10 leads to 1.10.
  • In 1.11, using mem::replace and direct reassignment make the bullet update code much shorter:
        let old_bullets = mem::replace(&mut self.bullets, vec![]);
        self.bullets = old_bullets.into_iter().filter_map(|b| b.update(phi, elapsed)).collect();

Keep up the great work!!

I don't have a problem... except that I want your tutorial to continue! You have good pacing and teach through experience, which is the best way to learn IMO. Anyway, keep doing what you're doing!

sdl2_image 1.0.0 unavailable?

I'm getting this error trying to install the 1.0.0 version of sdl2_image you've referenced.

no matching package named `sdl2_image` found (required by `arcade-rs`)
location searched: registry https://github.com/rust-lang/crates.io-index
version required: ^1.0.0
versions found: 0.16.0, 0.7.0, 0.6.0, ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.