Skip to content

Instantly share code, notes, and snippets.

View FlyingJester's full-sized avatar

Martin McDonough FlyingJester

View GitHub Profile
function TS_Line(integer x1, integer y1, integer x2, integer y2, Color){
integer w = absolute_value(x1-x2);
integer h = absolute_value(y1-y2);
integer sx;
integer sy;
if (x1<x2){
sx = 1;
}
function BodyPart.draw(spritex, spritey){
//this.color should be updated to an appropriate color whenever the bodypart takes damage.
//alternatively, if could be calculated at the start of this function.
integer number_of_nodes = this.nodes.length;
integer i = 0;
//this line handles the wraparound from the last to the first node.
void TS_BMPFont::addline(const char **textlines, int *readylines, char *linebuffer){
(*readylines)++;
textlines = (const char **)realloc(textlines, (*readylines)*sizeof(const char *));
textlines[(*readylines)-1] = strdup(linebuffer);
linebuffer = (char *)realloc(linebuffer, 1);
template <class TSim>
TS_Texture getTextureFromImage(TSim *a) {
return a->texture;
}
v8Function spritebatcherAddImage(V8ARGS){
if(args.Length()==0){
THROWERROR(" Error: Called with fewer than one argument.");
}
@FlyingJester
FlyingJester / gist:8383600
Created January 12, 2014 11:39
A C++ function that calls any other function. As you may have guessed from its name, it's for a threading abstraction library.
#include <iostream>
using namespace std;
#include <functional>
#include <cstring>
void (*function1)(int , int);
template<typename R, typename ...A>int CreateThread(R(*ThreadFunc)(A...), A ...args){
std::function<R(A...)>func(ThreadFunc);
@FlyingJester
FlyingJester / gist:8384427
Created January 12, 2014 13:13
You can't pass function pointers as void pointers. But you CAN pass function pointer pointers as void pointers.
void CallFuncPP(void *r){
void **d = (void **)r;
void(**e)(void) = (voidFunc *)d;
e[0]();
}
/////
//Example
///////////////////////////////////////////////////////////////////////////////
/*
TurboSphere Plugin SDK
Copyright (c) 2012-2014 Martin McDonough.
All rights reserved.
@FlyingJester
FlyingJester / randomize_background.py
Last active January 15, 2022 05:13
A script that uses `feh` to randomly set the desktop background, changing it every 5 minutes, and not repeating any image twice.
# Calls Feh, puts a randomized image on the background, and changes
# the image every 5 minutes.
import os
import glob
import subprocess
import time
import random
images = glob.glob('images/*')
@FlyingJester
FlyingJester / StringifyNumber.py
Last active August 29, 2015 13:56
[Python] Create a string that, when written to a binary file, represents a number. Also contains null-padding function for fixed-width representation.
def StringifyKeepingValue(s):
stringy = ""
while s:
digit = s %256
s-= s%256
s = s/256
stringy+=chr(digit)
return stringy
def PadString(val, s, l):
///////////////////////////////////////////////////////////////////////////////
/*
TurboSphere Plugin SDK
Copyright (c) 2012-2014 Martin McDonough.
All rights reserved.