Skip to content

Instantly share code, notes, and snippets.

View jorgenpt's full-sized avatar

Jørgen Tjernø jorgenpt

View GitHub Profile
@jorgenpt
jorgenpt / scope_delete.hh
Last active December 23, 2015 04:09
Automatically `delete' a variable at end of scope. From https://twitter.com/Jonathan_Blow/status/379394775788425216
template <typename T>
struct Scope_Delete_Handler
{
T target;
Scope_Delete_Handler(T _target) :target(_target) {}
~Scope_Delete_Handler() { delete target; }
};
#define Scope_Delete(x) Scope_Delete_Handler <decltype(x)> _##x##_## __LINE__(x)
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (assign) CFMachPortRef tap;
@end
@implementation AppDelegate
#include <SDL.h>
int PollEvents()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
@jorgenpt
jorgenpt / lost_focus_move_event.patch
Created March 1, 2013 19:55
SDL2: Fix for missing movement updates when losing focus.
--- /tmp/tmp.4049.39 2013-03-01 11:53:56.199276885 -0800
+++ src/events/SDL_mouse.c 2013-03-01 11:52:47.390674778 -0800
@@ -33,6 +33,8 @@
/* The mouse state */
static SDL_Mouse SDL_mouse;
+static int
+SDL_PrivateSendMouseMotion(SDL_Window * window, int relative, int x, int y);
/* Public functions */
public <T> Bag<T> register(Class<T extends Node> klass) {
Bag<T> list = (Bag<T>)nodes.get(klass);
if(list == null) {
list = new Bag<T>();
nodes.put(klass, list);
}
return list;
}
interface Component {
public void update(int delta);
public void render();
}
<?xml version="1.0" encoding="utf-8"?>
<jnlp
codebase="https://dl.dropbox.com/u/7722291/"
href="Frogger.jnlp">
<information>
<title>Frogger</title>
<vendor>HollowSpecter</vendor>
<homepage href="https://github.com/hollowspecter/1GAM-Jan-5Frogger"/>
<description>Frogger, January 1GAM entry.</description>
<description kind="short">Frogger.</description>
body->SetTransform(new_position, ball.body->GetAngle());
body->SetLinearVelocity(b2Vec2_zero);
body->ApplyLinearImpulse(new_impulse, body->GetPosition());
- (void)keepAliveHandler:(UIBackgroundTaskIdentifier)bgIdentifier {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSLog(@"Runnin' in the background!");
for (int i = 49; i >= 1; --i) {
NSLog(@"Okay, %i more!", i);
[NSThread sleepForTimeInterval:6];
}
NSLog(@"Phew! Made it through!");
static public Vector3 ParseVector3(string input) {
input = input.TrimStart('(').TrimEnd(')')
string[] components = input.Split(',');
Vector3 output = Vector3.zero;
if (components.Length > 0) {
try { output.x = float.Parse(components[0]); } catch (Exception e) {}
}
if (components.Length > 1) {
try { output.y = float.Parse(components[1]); } catch (Exception e) {}