Can easily separate CPU-bound services into their own processes and scale them independently with minimal code changes (swap out the message dispatch strategy). You incur I/O overhead, but free up frontline dispatch loops.\n\n\n
Catan world and Churchill
Catan WorldGrant GoodaleDean HudsonMason Browne August 23, 2012 #gamedevjs
Front-End Architecture Ignore the Single Responsibility Principle At Your Peril
Game EntitiesManage positionManage velocityManage collision / point intersectionRespond to update() calls
Rendering Primitives Implement draw speciﬁcs Separate draw calls for different renderers (visitor pattern) Delegated to by GameEntity for calls that require per pixel information (image hit detection, etc.)
Entity ManagerKeep track of entities in the gameInterface for adding, deleting, and retrieving entitiesProvides component interfaceDispatches update calls and normalized events
Multiple RenderersPluggable renderers, adhering to a common interfaceAllows canvas/DOM speciﬁc caching, double buffering,etc.Builds render queueMakes draw calls to rects
Core LoopWrap it all togetherDispatch queued server/UI eventsMake update callsBuild render queueCall renderer.render()
Embracing ConstraintsUsing all canvas rendering in Catan World
Why?Excessive DOM manipulation is slow and prone toperformance/memory issuesMore consistent support for mobile wrappersBecause we can.
Sage Advice”Establish & Embrace Constraints” - @kevmoo (or something to that effect)
On Node, Not Of NodeChurchill clients and services are pure.Your JS engine is your runtime (V8, Nitro,SpiderMonkey)Node and browsers are platforms (runtime + features)All code should run in all supported runtimes
Be Modular!Factor out platform-speciﬁc feature functionality intomodules: File I/O, Network I/O, DB accessSupporting a given platform just means having thesupporting feature modules
Use Channels!Discrete message & event channelsAbstraction lends itself well to composition andchainingIn turn makes transport-agnostic message passingeasySupport for TCP socket, in-memory (direct dispatch),and socket.io (WebSocket, XHR, etc) transport
Emergent Properties!Can run multiple, independent services in the sameruntimeMakes service composition a sane design decision No I/O overhead incurred for in-memory (direct dispatch) between services in the same runtime Scale!