Full ECS discussion gist: https://gist.github.com/LearnCocos2D/77f0ced228292676689f
foreach entity in allEntities do
foreach component in entity.components do
component.update()
end
end
| /* | |
| Swift classes implementing the GKMinmaxStrategizer protocols, without any logic. | |
| You can use these as a template, copy & paste them into your project and start working. ;) | |
| This gist is provided by http://tilemapkit.com and released into public domain. | |
| Here's my tutorial about GKMinmaxStrategist: http://tilemapkit.com/2015/07/gkminmaxstrategist-build-tictactoe-ai/ | |
| */ | |
| class TheGameModel: NSObject, NSCopying, GKGameModel { |
Full ECS discussion gist: https://gist.github.com/LearnCocos2D/77f0ced228292676689f
foreach entity in allEntities do
foreach component in entity.components do
component.update()
end
end
For background and further references see: Entity Component Systems on Wikipedia
entity = class: no logic + no data OR at most small set of frequently used data (ie position)component = class: logic + dataforeach entity in allEntities do
foreach component in entity.components do
| -(void) draw:(CCRenderer *)renderer transform:(const GLKMatrix4 *)transform | |
| { | |
| // Drawing the triangle fan. Simple explanation of how a triangle fan is drawn: | |
| // http://stackoverflow.com/questions/8043923/gl-triangle-fan-explanation | |
| // in a triangle fan the first 3 vertices form one triangle, then each additional vertex forms another triangle | |
| // thus number of triangles is number of vertices minus the initial 2 vertices for the first triangle | |
| int numTriangles = _numVertices - 2; | |
| CCRenderBuffer buffer = [renderer enqueueTriangles:numTriangles | |
| andVertexes:_numVertices |
| #if TARGET_OS_IPHONE | |
| id context = [EAGLContext currentContext]; | |
| #else | |
| id context = [NSOpenGLContext currentContext]; | |
| #endif |
| // | |
| // TilemapWithBorderViewController.m | |
| // _Feature-Demo-Template_ | |
| // | |
| // Created by Steffen Itterheim on 19.03.13. | |
| // Copyright 2013 __MyCompanyName__. All rights reserved. | |
| // | |
| #import "TilemapWithBorderSceneViewController.h" |
| // | |
| // PhysicsCollisionSceneViewController.m | |
| // _Feature-Demo-Template_ | |
| // | |
| // Created by Steffen Itterheim on 01.05.13. | |
| // Copyright 2013 __MyCompanyName__. All rights reserved. | |
| // | |
| #import "PhysicsCollisionSceneViewController.h" |
| # | |
| # Uncrustify Configuration File | |
| # File Created With UncrustifyX 0.4.1 (229) | |
| # | |
| # Alignment | |
| # --------- | |
| ## Alignment |
| bool foo(char* p1, int* p2) | |
| { | |
| // local variable declaration | |
| bool bRet = false; // init all local variables here, assume everything is wrong | |
| int* ptr = NULL; | |
| PROFILER_START(); | |
| // check input params | |
| if (p1 && p2) |
| // set menu options with the initializer object | |
| KTTextMenu* textMenu = [KTTextMenu menuWithTextMenuItems:[NSArray arrayWithObjects:item1, item2, nil]]; | |
| textMenu.fontName = @"Arial"; | |
| textMenu.fontSize = 48; | |
| textMenu.padding = 16; | |
| // init the menu with the initializer object | |
| KTMenuViewController* menuViewController = [KTMenuViewController menuControllerWithTextMenu:textMenu]; | |
| [self addSubController:menuViewController]; |