Page 1 of 1

New Stream Methods September 2015

PostPosted: Fri Sep 18, 2015 2:35 pm
by rob
Hi folks,

Some new methods have been added to IgeEntity to allow easier streaming of data.

streamSectionsPush(sectionName) - Allows you to add a new stream section to the existing list of streaming sections.
streamSectionsPull(sectionName) - Allows you to remove a stream section from the existing list of streaming sections.

streamProperty(propName, propVal) - Allows you to get / set a streaming property for an entity. This allows you to easily stream custom properties for an entity without having to add separate custom sections for your custom values. In order to stream these, make sure you call...

Code: Select all
this.streamSectionsPush('props');


...during your entity init. Here is an excerpt from one of my entities that uses streamProperty:

Code: Select all
var Ship = IgeEntityBox2d.extend({
   classId: 'Ship',

   init: function () {
      IgeEntityBox2d.prototype.init.call(this);

      var self = this;
      
      self._ordinance = {};
      self.streamProperty('thrusting', false);
      self.streamProperty('mining', false);


Then, whenever you want to update a property you just call streamProperty() again with the new value. It will be sent to clients in the next stream tick automatically :) e.g.

Code: Select all
self.streamProperty('thrusting', true);

Re: New Stream Methods September 2015

PostPosted: Sun Oct 04, 2015 9:52 pm
by Epsilon
Hi Rob

Due to custom format of frames sending through websockets which is comma-delimited data, it looks like we can't transfer data with comma inside of it . Also, I found that we should to split(',') a value of `data` variable inside of streamSectionData() method in order to get processable array of data.

Last notice is only valid for sections which are arrays of data.

Btw, why you don't use nice couple of JSON.stringify() and JSON.parse() to send and receive data? For processing speed reason I guess?