Skip to content

Instantly share code, notes, and snippets.

@jamesu
jamesu / generate_T3D_engineapi_bindings.rb
Created October 5, 2012 21:12
Generates bindings from a Torque3D engineAPI.xml export
#
# Generates engineAPI bindings for Torque3D taken from engineAPI.xml
# Outputs to ext_bindings.h and ext_bindings.cpp
#
# NOTE: Currently the generated code is not meant to be usable,
# and is more of a proof-of-concept. There is also a lot of
# unnecessary duplication.
#
# To export the engineAPI console.xml:
#
// Torque3D example of how to intercept a callback in code.
// Callbacks in Torque3D are declared by the DECLARE_CALLBACK macro, and are implemented by IMPLEMENT_CALLBACK.
// Usually they invoke a function in TorqueScript, but there is also an option to invoke a function via a function pointer which
// can be obtained from mAddress in the relevant EngineFunctionInfo.
//
// You must add the following in EngineFunctionInfo:
//
// void* getAddress() { return mAddress; }
//
@jamesu
jamesu / FTFont.cpp
Created October 9, 2013 16:22
FreeType Font code for Torque2D. Should also work with modifications for Torque3D
//-----------------------------------------------------------------------------
// Copyright(C) 2013 James S Urquhart.
// Derived from code from T2D MIT, Copyright (c) 2013 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@jamesu
jamesu / gist:8182306
Created December 30, 2013 13:51
Convert Notational Velocity notes into tiddywiki tiddlers suitable for inserting into a TiddlyWiki file
note_html = []
Dir["./notes/candidates/*.txt"].each do |file|
ftime = File.mtime(file)
name = file.split("/")[-1]
puts "FILE #{name} CREATED #{ftime}"
File.open(file) do |f|
timestamp = ftime.strftime("%Y%m%d%H%M")
note_html << "<div changecount=\"1\" created=\"#{timestamp}\" modified=\"#{timestamp}\" modifier=\"JamesU\" tags=\"notational\" title=\"#{name}\"><pre>#{f.read}</pre></div>"
end
// An example of how to bind a C++ class in four scripting languages: lua, squirrel, mruby, and angelscript.
// Written by James S Urquhart ( http://www.cuppadev.co.uk/ ). Feel free to experiment!
#include <stdarg.h>
#include <stdio.h>
#include <assert.h>
// Lua includes
extern "C"
{
@jamesu
jamesu / test2.cs
Last active August 29, 2015 13:56
Torque2D-Lua object thunk benchmarking
function bridge1Test()
{
%obj = new SimObject();
%start = getRealTime();
%count = 0;
for (%i=0; %i<1000000; %i++) {
%obj.getId();
}
%end = getRealTime();
//echo("scriptTest3 result: " @ %count);
@jamesu
jamesu / mongodb_poco.cpp
Created February 5, 2014 01:39
An experiment in implementing the mongodb server protocol in poco
// Copyright (C) 2013 James S Urquhart.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@jamesu
jamesu / test_ts.cs
Last active August 29, 2015 14:06
Tests some basic code patching features in TorqueScript
enableWinConsole(true);
setLogMode(2);
$fuck = "ERRR";
echo("TEST EXPRESSION" @ (1 + 2) @ $fuck SPC "SPACE");
for (%i=0; %i<10; %i++)
{
echo("loop" SPC %i);
}
@jamesu
jamesu / viewControllerKeyboard.m
Last active August 29, 2015 14:06
Moving a UIViewController view to line up with the keyboard
// Moves view to be in line with the keyboard
//
// keyboardHeight == value returned from UIKeyboardBoundsUserInfoKey key
// keyboardControlY == place in view the top of the keyboard should line up with
//
- (void)moveViewForKeyboardHeight:(float)keyboardHeight controlOffset:(float)keyboardControlY
{
// Determine what is "up"
CGAffineTransform myTransform = self.transform;
CGPoint upAxis = CGPointApplyAffineTransform(CGPointMake(0, 1), myTransform);
@jamesu
jamesu / engineAPiTemplate.erb
Created November 9, 2014 21:08
Generates engineAPI.h for Torque3D
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//