Skip to content

Instantly share code, notes, and snippets.

View gist:dc58ab1c67f6980d1f301f11ceb06e46
template<class T, class...Ts>
container<T, Ts...> make_container(T value, Ts... values) {
// Print the total number of arguments passed in.
// We'll use the sizeof.. builtin to determine this for
// variadic args and increment once for the single T arg
std::cout << "Total Args: " << (sizeof...(values) + 1) << std::endl;
return container<T, Ts...>(value, values...);
}
View ChunkMesh.cs
public class ChunkMesh {
private List<Vector3> _vertices = new List<Vector3>();
private List<Vector2> _uvs = new List<Vector2>();
private List<Vector3> _normals = new List<Vector3>();
private List<int> _triangles = new List<int>();
private int _triangleCount = 0;
public ChunkMesh() {
View ArrayCustomSort2.as
package {
public class MyObject {
public var alpha:String = "";
public var val:int = 0;
public function MyObject(alpha:String, val:int) {
this.alpha = alpha;
this.val = val;
}
View VectorSort2.as
var vec:Vector.<int> = new <int>[ 1, 2, 3, 4, 5 ];
vec.sort(Array.DESCENDING);
trace(vec);
// Outputs: 5,4,3,2,1
View VectorSort.as
var vec:Vector.<int> = new <int>[ 1, 2, 3, 4, 5 ];
vec.sort(shuffle);
trace(vec);
View ArrayCustomSort.as
// We return -1 if val1 is first, 1 if val2 is first, and 0
// if we don't care - just return a random value between
// -1 and 1
function shuffle(val1:int, val2:int):int {
var random:int = Math.floor(Math.random() * 3) - 1;
return random;
}
var toSort:Array = [ 1, 2, 3, 4, 5 ];
toSort.sort(shuffle);
View VectorConcat4.as
/**
* So, if I want to create a new Vector.<int> that
* appends 3, 2, 1 without modifying the original,
* I need to create *another* new Vector.<int>, just
* to pass the values to concat(). That's one extra
* Vector.<int> instantiation. Three total Vector.<int>
* objects, while only 2 should be needed:
* -- One, the original vec:Vector.<int>.
* -- Two, the new <int>[ 3, 2, 1 ] to pass the concat()
* parameter.
View VectorConcat3.as
var vec:Vector.<int> = new <int>[ 1, 2, 3 ];
var result:Vector.<int> = vec.concat(3, 2, 1);
trace(result);
// Unfortunately, this code ERRORS with: "Type Coercion failed"
// Cannot convert 3 to __AS3__.vec.Vector.<int>."
View ArrayConcat4.as
var arr:Array = [ 1, 2, 3 ];
var arr2:Array = [ 3, 2, 1 ];
var result:Array = arr.concat(arr2, 4, 5, 6);
trace(result);
// Outputs: 1,2,3,3,2,1,4,5,6
View ArrayConcat3.as
var arr:Array = [ 1, 2, 3 ];
var result:Array = arr.concat(3, 2, 1);
trace(result);
// Outputs: 1,2,3,3,2,1
You can’t perform that action at this time.