private static void RunLoop(IConsoleBackend term, IContainer <GameState> ecs) { const int msPerFrame = 20; var width = term.WindowWidth; var height = term.WindowHeight; var state = new GameState(msPerFrame / 1000f, width, height, term); // initialize ecs.InitializeSystems(state); // run while (true) { // Note - in a real game update and rendering logic // is often separated - there is no requirement // for putting the rendering logic inside ECS - // since it's a DI container, you can freely // resolve needed components and systems from // external code and use them in any other way ecs.ExecuteSystems(state); Thread.Sleep(20); if (term.KeyAvailable) { break; // exit on any key press } } }
private static void SpawnEntities(IContainer <GameState> ecs, IConsoleBackend term) { for (var i = 0; i < 50; i++) { SpawnRandomEntity(ecs, term); } }
public GameState(float deltaSeconds, int screenWidth, int screenHeight, IConsoleBackend backend) { DeltaSeconds = deltaSeconds; ScreenWidth = screenWidth; ScreenHeight = screenHeight; Backend = backend; }
private static int SpawnRandomEntity(IContainer <GameState> ecs, IConsoleBackend term) { var em = ecs.EntityManager; var id = em.Create(); // create an entity ID var screenSize = new Vector2(term.WindowWidth, term.WindowHeight); var maxSpeed = new Vector2(10f); // add physics component var position = RandomVector(Vector2.Zero, screenSize); var velocity = RandomVector(-maxSpeed, maxSpeed); ecs.AddComponent(id, new PhysicsObject(position, velocity)); // add drawable component var symbol = RandomElement(s_symbols); var color = RandomEnumValue <Color16>(); ecs.AddComponent(id, new Drawable(symbol, color)); return(id); }
void InitConsole(SimpleConsoleData data, Mesh mesh) { IConsoleBackend backend = null; int w = data.Width; int h = data.Height; backend = new SimpleMeshBackend(w, h, mesh); //switch(data.Backend) //{ // default: // backend = new SimpleMeshBackend(w, h, filter.sharedMesh); // break; //} _console = new SimpleConsole( w, h, backend, Allocator.Persistent); }
public DefaultConsole(IConsoleBackend console, ICommandOptions options) { _console = console; _global = new Lazy <GlobalCommand>(options.GetOptions <GlobalCommand>); }