Skip to content

Instantly share code, notes, and snippets.

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
@jsimmons
jsimmons / packs.rs
Last active September 4, 2017 21:37
Does it Pack
#[derive(Copy, Clone, Debug)]
struct Tile {
/// A - B - C
/// | |
/// H D
/// | |
/// G - F - E
///
/// A = 0
@jsimmons
jsimmons / main.rs
Created August 28, 2017 13:38
How to use dGPU in Optimus systems via Rust
#![feature(link_args)]
// Don't try and do this via cargo it's a huge disaster,
// just ignore the ominous warnings about link_args being
// broken. (requires nightly, too, hurray)
#[cfg(target_os="windows")]
#[link_args="/EXPORT:NvOptimusEnablement"]
extern {}
#[allow(non_upper_case_globals)]
@jsimmons
jsimmons / TASK.md
Last active August 21, 2017 14:04
Thoughts on a task system
  • WORK ITEM:

    • Work closure
    • pointer to TASK
  • TASK:

    • WORK ITEMs Array
    • Atomic num_open_work_items counter - init to number of WORK ITEMs
    • Permits pointer to TASK which depends on this one
  • WORKER

@jsimmons
jsimmons / link_map.c
Last active February 26, 2023 08:22
Linking The Hard Way
@jsimmons
jsimmons / skip.rs
Created August 12, 2017 07:31
Whitespace skipper approach one
#[inline(force)]
let cur = |data: &[u8], pos| -> usize {
unsafe { *data.get_unchecked(pos) as usize }
};
#[inline(force)]
let skip_whitespace = |data, pos| -> usize {
let mut ws = 0;
'outer: while PARSE_FLAGS[cur(data, pos + ws)] & PARSE_FLAG_WS != 0 {
'skip_ws: loop {
@jsimmons
jsimmons / shaders.rs
Created August 10, 2017 17:25
Compiling shaders to SPIR-V in a Rust macro is neato
fn main() {
static TEST_VS: &'static [u8] = glsl_vs!{r#"
#version 400
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (location = 0) in vec4 pos;
layout (location = 1) in vec4 color;
@jsimmons
jsimmons / main.rs
Last active August 10, 2017 12:24
The winit event loop API has weird consequences with borrow checker
use winit;
struct Game {
window: winit::Window,
ev: winit::EventLoop
}
impl Game {
fn new() -> Game {
let ev = winit::EventsLoop::new();