Skip to content

Instantly share code, notes, and snippets.

View YellowAfterlife's full-sized avatar

Vadym Diachenko YellowAfterlife

View GitHub Profile
@YellowAfterlife
YellowAfterlife / ds_map_iter.gml
Created September 9, 2015 19:47
Comparing various methods of iterating over ds_map
var map = ds_map_create();
var keys = ds_list_create();
var values = ds_list_create();
var num = 10000;
var t, k, v;
for (var i = 0; i < num; i++) {
k = i * 2 + 1;
v = irandom(10);
ds_list_add(keys, k);
ds_list_add(values, v);
repeat (10000) {
instance_create(0, 0, obj_some); // (blank)
}
var t, r, this;
r = ds_list_create();
this = 1000;
//
t = current_time;
with (all) if (id != this) ds_list_add(r, id);
show_debug_message(string(current_time - t) + "ms"); // 4ms
@YellowAfterlife
YellowAfterlife / haxe.php
Created August 11, 2015 08:35
A Haxe syntax highlighter for GeSHi (http://qbnz.com/highlighter/)
<?php
$language_data = array (
'LANG_NAME' => 'Haxe',
'COMMENT_SINGLE' => array(1 => '//'),
'COMMENT_MULTI' => array('/*' => '*/'),
'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE,
'QUOTEMARKS' => array("'", '"'),
'ESCAPE_CHAR' => '\\',
'KEYWORDS' => array(
1 => array(
using System;
using System.IO;
using System.Collections.Generic;
using System.Threading;
namespace CSCoTest {
class Part {
public const int PT_TEXT = 0;
public const int PT_META = 1;
public String text;
package;
import Pico.*;
class Test {
static inline function main() {
var co = new Collection<Entity>();
co.add(new Man("John"));
co.add(new Dog("Dogmeat"));
for (entity in co) entity.talk();
}
}
@YellowAfterlife
YellowAfterlife / trifill.hx
Created July 27, 2015 22:16
An attempt of porting a triangle rasterizer (http://forum.devmaster.net/t/advanced-rasterization/6145) to pico-8
static function trifill(x1:Fixed, y1:Fixed, x2:Fixed, y2:Fixed, x3:Fixed, y3:Fixed) {
var dx12 = x1 - x2;
var dx23 = x2 - x3;
var dx31 = x3 - x1;
//
var dy12 = y1 - y2;
var dy23 = y2 - y3;
var dy31 = y3 - y1;
//
var minx = min(x1, min(x2, x3));
@YellowAfterlife
YellowAfterlife / ItemConf.cs
Last active February 15, 2016 00:20
A TerraPatcher plugin for tweaking item stats.
using System;
using System.Collections.Generic;
using PluginLoader;
using Terraria;
/// Updated July 24, 2015
/// Updates: https://gist.github.com/YellowAfterlife/1edaa4060191823ee366
namespace YellowAfterlifePlugins {
/// Item modification rules are defined as following:
/// [item3507]
//{ keyboard_key
#define keyboard_key_get_code
/// keyboard_key_get_code(name:string):int
var r = keyboard_key_codes[?string_lower(argument[0])];
if (!is_undefined(r)) return r;
return -1;
#define keyboard_key_get_name
/// keyboard_key_get_name(code:int):string
var code = argument[0];
var r = keyboard_key_names[?code];
@YellowAfterlife
YellowAfterlife / Player.hx
Last active May 26, 2024 07:37
Terraria 1.3 character file format implementation in Haxe
package terra;
import openfl.Lib;
import openfl.utils.ByteArray;
import openfl.utils.Endian;
import Ext.cfor;
using utils.ByteArrayTools;
/**
* ...
@YellowAfterlife
YellowAfterlife / Ext.hx
Created June 25, 2015 20:30
Quite another C-style for-loop macros for Haxe.
class Ext {
/// C-style for-loop. Uses @pleclech's idea but on macros level.
public static macro function cf(init, cond, post, expr) {
#if !display
var func = null;
func = function(expr:haxe.macro.Expr) {
return switch (expr) {
case macro continue: macro { $post; $expr; }
default: haxe.macro.ExprTools.map(expr, func);
}