autogica / atgc

My side project, a game written in javascript. The "blog" is in the /issues
GNU General Public License v3.0
1 stars 0 forks source link

general: use event emitter instead of direct, global calls to methods #6

Open jbilcke opened 9 years ago

jbilcke commented 9 years ago

this kind of call:

var foo = window.app.assets['atgc-part-tactical-javelot'].launch()

is dangerous, needs dependencies to be loaded in the correct order, can be broken during migration and upgrades

it should be replaced with an asynchronous, message passing system like an event-emitter or actor system.

jbilcke commented 9 years ago

still need to be done

I think we need something closer to a message board and realtime issue tracker rather than a message queue, because we want the ability to run thousand of queues in parallel, each with different priorities, and also we want some messages to stay without time limit, like a loop

maybe it will be something like this: https://github.com/autogica/gunfire/blob/master/src/client/utils.coffee#L318

it is a prototype of an issue/message system that uses multiples indexes and sorts to dispatch messages. For now, it is oriented toward a simple request/proposal model, and uses a vocabulary inspired by economy:

an entity (a real human player, or a robot) in the game needs something, for instance a laser weapon, or a drone, and is ready to "pay" for it (using energy, for instance collected by mining).

It posts the issue, under a given topic (or keywords) and other entity that provides services or products will watch the topic, and answer to the original entity with an offer. If both parties agree then this is a deal. Tho whole thing should take less than a few asynchronous function calls.

Asynchronous communication is necessary because it allows us to introduce a few things in the model: