Skip to content

Instantly share code, notes, and snippets.

@mzaks
mzaks / simple_ref.fbs
Created May 26, 2016 09:43
FBS table referencing another tabe
table A {
ref : B;
}
table B {
i : int;
}
root_type A;
@mzaks
mzaks / simple_person.fbs
Last active May 26, 2016 09:58
Simple recursive FBS
table Person {
name : string;
friends : [Person];
}
root_type Person;
@mzaks
mzaks / ArrayBackedEntity.swift
Last active July 6, 2016 14:19
Sketch for ECS with emphasise on data locality
struct ComponentManager {
var positions : [(x:Int, y:Int)]
var nextOpenPosition : Set<UInt8>
var names : [String]
var nextOpenName : Set<UInt8>
init(numberOfPositions : UInt8, numberOfNames : UInt8){
positions = [(x:Int, y:Int)](count: Int(numberOfPositions), repeatedValue: (x:0, y:0))
nextOpenPosition = Set(0..<numberOfPositions)
names = [String](count: Int(numberOfNames), repeatedValue: "")
@mzaks
mzaks / Entitas-BT.cs
Last active September 5, 2022 11:55
Sketch for Entitas-CSharp Behaviour Tree implementation
// Based on http://www.gamasutra.com/blogs/ChrisSimpson/20140717/221339/Behavior_trees_for_AI_How_they_work.php
public enum NodeStatus
{
Success, Failure, Running
}
public interface IBehaviorNode
{
NodeStatus Execute(Entity entity);
@mzaks
mzaks / example1.ecs
Last active August 11, 2016 13:43
Example1 for ECS-Lang
platform = unity_csharp, swift
alias int { unity_csharp : int, swift : Int }
alias boolean { unity_csharp : bool, swift : Bool }
alias string { unity_csharp : string, swift : String }
comp Position { x : int, y : int }
@mzaks
mzaks / README.md
Last active November 26, 2016 19:17
ECS-Lang walk through

Language syntax and semantics walk through. [LAST_UPDATE 26th November 2016]

This language is higher order language which, defines the data and the transformations for an entity component system architecture library. The concepts are based on Entitas, but it should be posible to implement code generators for other ECS implementations.

All definitions can be split in to multiple ecs files. This is why all definitions are optional. The order is however mandatory

platform entitas_csharp_light
struct GoodMorning : Action {
func execute(data: String, callback: @escaping (DataType, BehaviourResult) -> ()) {
let hour = Calendar.current.component(.hour, from: Date())
if hour >= 6 && hour < 12 {
print("Good morningn \(data)")
callback(data, .succeeded)
} else {
callback(data, .failed)
}
}
struct AskingForUsersName : Action {
func execute(data: String, callback: @escaping (DataType, BehaviourResult) -> ()) {
print("Who am I talking to?")
let name = readLine()
if let name = name, name.utf8.count > 0{
callback(name, .succeeded)
} else {
callback(data, .failed)
}
}
struct HaveYoutriedToTurnItOffAndOnAgain : Action {
func execute(data: String, callback: @escaping (DataType, BehaviourResult) -> ()) {
print("Have you tried to turn it off and on again?")
callback(data, .succeeded)
}
}
struct IsItPlugedIn : Action {
var counter = Counter()
func execute(data: String, callback: @escaping (DataType, BehaviourResult) -> ()) {
let realy = [String](repeating: " realy", count: counter.count).joined(separator: ",")
print("Is it\(realy) plugged in?")
counter.increase()
callback(data, .succeeded)
}
}