Skip to content

Instantly share code, notes, and snippets.

use std::{
ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign},
time::{Duration, Instant},
};
use sdl2::{event::Event, rect::Rect, render::WindowCanvas, Sdl};
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub struct Vec2 {
pub x: i32,
use sdl2::{event::Event, keyboard::Keycode};
use slappy::{Colour, Draw, Input, Loop, TickState, Vec2};
#[derive(Default)]
struct PongInput {
player_1_up: bool,
player_1_down: bool,
player_2_up: bool,
player_2_down: bool,
}
@jsimmons
jsimmons / spinlock.rs
Created January 4, 2020 22:31
Dont use this please
use std::cell::UnsafeCell;
use std::sync::atomic::{spin_loop_hint, AtomicBool, AtomicU32, Ordering};
use std::sync::{Barrier, Mutex};
use std::ops::{Deref, DerefMut};
use std::thread;
use parking_lot;
struct LockInner(AtomicBool);
const LOCKED: bool = true;
@jsimmons
jsimmons / ring-buffer.c
Created May 31, 2011 12:08
Didn't want to loose this to the depths of my projects folder. Note to self, comment your damn implementation too.
#include "ring-buffer.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
RingBuffer *rb_new(size_t size)
{
RingBuffer *buf = malloc(sizeof(*buf));
assert(buf != NULL);
#include <elfutils/libdwfl.h>
#define UNW_LOCAL_ONLY
#include <libunwind.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
@jsimmons
jsimmons / rays.rs
Created August 11, 2019 23:16
Rays on a Plane
use std::fs::File;
use std::io::BufWriter;
use std::io::Write as IoWrite;
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use std::path::Path;
use rand::{Rng, SeedableRng};
use rand_distr::{Distribution, UnitDisc, UnitSphere};
use rand_pcg;
let mapleader=","
" Specify a directory for plugins
" - For Neovim: ~/.local/share/nvim/plugged
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.local/share/nvim/plugged')
Plug 'godlygeek/tabular'
Plug 'rust-lang/rust.vim'
Plug 'ctrlpvim/ctrlp.vim'
local sdl = require 'SDL'
local image = require 'SDL.image'
local ttf = require 'SDL.ttf'
local table, math, string = table, math, string
local status, err = sdl.init {
sdl.flags.Video
}
if not status then
local sdl = require 'SDL'
local image = require 'SDL.image'
local ttf = require 'SDL.ttf'
local table, math, string = table, math, string
local status, err = sdl.init {
sdl.flags.Video
}
if not status then
local function clear_tile_teams()
for i = 1, conf_map_num do
local tile = g_map[i]
local tile_type = tile.tile_type
if tile_type ~= 'water' and
tile_type ~= 'bridge' and
tile_type ~= 'rocks' and
tile_type ~= 'building' then
tile.team = nil
end