Skip to content

Instantly share code, notes, and snippets.

View karl-zylinski's full-sized avatar

Karl Zylinski karl-zylinski

View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
struct Color
{
unsigned char r, g, b;
};
@karl-zylinski
karl-zylinski / init_lists.cpp
Last active February 22, 2016 23:14
Using C++11 initializer lists in C-style code to make pretty minimalistic error reporting
struct File
{
uint8* data;
uint32 size;
};
struct LoadedFile
{
bool valid;
File file;
self.health_bar_texture.map(|t| {
Sprite::new_with_texture(t).map(|mut s| {
s.set_position(&Vector2f::new(10.,10.));
window.draw(&s);
});
});
pub fn load_level(&mut self, filename: ~str) -> ~[~Entity] {
let level_json_str = File::open(&Path::new(filename)).read_to_end();
let level_json = match json::from_str(level_json_str.to_str()) {
Ok(json) => json,
Err(e) => fail!("Failed to load level.")
};
let root_json = match level_json { json::Object(~o) => Some(o), _ => None};
let entities_json = root_json.as_ref().map_or(~[], |&j|
j.find(&~"entities").as_ref().map_or(~[], |&e| match e { json::List(l) => l, _ => ~[]})
fn main() {
let mut layers = ~[
~GameLayer::new(&mut resource_store) as ~Layer:,
~GuiLayer::new() as ~Layer
];
while window.is_open() {
let mut new_layers: ~[~Layer:] = ~[];
for layer in layers.iter() {
game_layer.rs:34:6: 34:13 error: cannot pack type `~player::Player`, which does
not fulfill `Send`, as a trait bounded by Send
game_layer.rs:34 ~player as ~Entity,
D:\Dokument\GitHub\rust-sfml\src\rsfml\graphics\render_window.rs:200:32: 200:39
error: instantiating a type parameter with an incompatible type `std::cell::RefC
ell<graphics::view::View>`, which does not fulfill `Freeze`
D:\Dokument\GitHub\rust-sfml\src\rsfml\graphics\render_window.rs:200
let def_view = Rc::new(RefCell::new(Wrappable::wrap(raw_def_view)));
^~~~~~~
D:\Dokument\GitHub\rust-sfml\src\rsfml\graphics\render_window.rs:255:32: 255:39
error: instantiating a type parameter with an incompatible type `std::cell::RefC
ell<graphics::view::View>`, which does not fulfill `Freeze`
pub trait Entity {
// ... some irrelevant functions
}
impl<'a> AnyRefExt<'a> for &'a ~Entity {
#[inline]
fn is<T: 'static>(self) -> bool {
// Get TypeId of the type this function is instantiated with
let t = TypeId::of::<T>();