Entity network Spawning
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Entity network Spawning
Okay so I am a bit lost on the whole server to client setup. The engine does it completely different than what i am use to.
I am using the mouse multiplayer example and I have created an entity but where in the world do you spawn the entity and then tell the clients it was done. Normally I would just run a function the server that would handle when and where to spawn the entity then shoot a message to all clients to spawn that entity there but I am not seeing where to do this at on either side. I am confused by what all these classes are doing. I am assuming the server and client are speaking to each other via clientnetworkevents.js and servernetworkevents.js but I am not understanding how the server is handling this.
I am using the mouse multiplayer example and I have created an entity but where in the world do you spawn the entity and then tell the clients it was done. Normally I would just run a function the server that would handle when and where to spawn the entity then shoot a message to all clients to spawn that entity there but I am not seeing where to do this at on either side. I am confused by what all these classes are doing. I am assuming the server and client are speaking to each other via clientnetworkevents.js and servernetworkevents.js but I am not understanding how the server is handling this.
-
- Posts: 10
- Joined: Wed Apr 11, 2012 9:09 pm
Re: Entity network Spawning
Check out lines 123-130 of client.js in that example. I believe it's the "streaming" approach that you (and me both!) are not used to.
- coolbloke1324
- Posts: 181
- Joined: Mon Jan 23, 2012 5:20 pm
Re: Entity network Spawning
Hey ya!hallsofvallhalla wrote:Okay so I am a bit lost on the whole server to client setup. The engine does it completely different than what i am use to.
I am using the mouse multiplayer example and I have created an entity but where in the world do you spawn the entity and then tell the clients it was done. Normally I would just run a function the server that would handle when and where to spawn the entity then shoot a message to all clients to spawn that entity there but I am not seeing where to do this at on either side. I am confused by what all these classes are doing. I am assuming the server and client are speaking to each other via clientnetworkevents.js and servernetworkevents.js but I am not understanding how the server is handling this.
So the engine's networking system is modelled on a triple-A game engine (Source Engine by Valve) and has a network "stream". The stream basically allows you to create an entity on the server and it will automatically exist on all connected clients.
To make an entity exist on all clients simply set the streamMode(1) e.g:
Code: Select all
var ent = new IgeEntity()
.streamMode(1);
You have a game like pacman, so you have 3 types of entities:
1) Ghosts
2) Dots
3) Player
Ghosts can be different colours, dots are always just basic dots that pacman can eat, and the player is pacman.
Ghosts and Player have animations when they are moving.
In this case you need to set up three classes. The ghost class is a good example because it will show you how you can set a colour of the ghost on the server and then have that custom setting automatically "streamed" to all the clients when the ghost is created client-side.
Code: Select all
var Ghost = IgeEntity.extend({
classId: 'Ghost',
init: function (data) {
// If we were given a colour, set it now
if (data.colour) {
this.colour(data.colour);
}
},
// This is called by the stream system on the server to ask
// for the data that will be sent along with the initial entity
// create on the client. The object returned will be passed as
// the first parameter in the init() method when the ghost
// is instantiated client-side, allowing you to send along
// custom data for the entity automatically when a client is
// being told about the entity's existence.
streamCreateData: function () {
return {colour: this._colour};
},
colour: function (val) {
if (val !== undefined) {
this._colour = val;
return this;
}
return this._colour;
}
});
Code: Select all
init: function (data) {
// If we were given a colour, set it now
if (data.colour) {
this.colour(data.colour);
}
if (!ige.isServer) {
this.texture(myTextures.ghostAnimation);
this.addComponent(IgeAnimationComponent);
// Define an animation called "walk" that loops frames 1 to 8
// at 25 frames per second indefinitely
this.animation.define('walk', [1, 2, 3, 4, 5, 6, 7, 8], 25, -1);
}
},
You can get more information in the docs on the site, and it would also be good to read up on how Source Engine from Valve works as Isogenic's networking is very similar: https://developer.valvesoftware.com/wik ... Networking
I've seen a lot of people assume that Isogenic just has socket.io installed and then called "multiplayer" but there is a LOT more to it than that!

Re: Entity network Spawning
This is really interesting to read, this is exactly the reason I've looked to implement IGE for my game.
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Entity network Spawning
Its truly amazing work. Just got to get my head wrapped around it
So in the ghost example I see how to set the client side up but how then does the server instantiate the ghost on all clients and track it? I mean in which file is this happening?
So for instance, level loads, server tells all clients to spawn ghosts, now I setup up functions on the client side ghost class to move the ghosts. Is there a special way i call the ghosts movements from the server?

So in the ghost example I see how to set the client side up but how then does the server instantiate the ghost on all clients and track it? I mean in which file is this happening?
So for instance, level loads, server tells all clients to spawn ghosts, now I setup up functions on the client side ghost class to move the ghosts. Is there a special way i call the ghosts movements from the server?
- coolbloke1324
- Posts: 181
- Joined: Mon Jan 23, 2012 5:20 pm
Re: Entity network Spawning
First thing is to realise that the Ghost class (and mostly all classes) are both client AND server.hallsofvallhalla wrote:Its truly amazing work. Just got to get my head wrapped around it![]()
So in the ghost example I see how to set the client side up but how then does the server instantiate the ghost on all clients and track it? I mean in which file is this happening?
So for instance, level loads, server tells all clients to spawn ghosts, now I setup up functions on the client side ghost class to move the ghosts. Is there a special way i call the ghosts movements from the server?
This means that on the server when you instantiate ghost, it is running the same code that the ghost on the client-side will be running. That is also why all classes have a "classId" property so that the server knows the name of the variable that the class is stored in and can instruct clients to instantiate entities with a class by its name.
All movement occurs server-side. No movement is done on the clients at all. You can set up paths for the ghost to traverse server-side and as the ghost moves along the path in the server, the updated transformations are streamed to all the clients. This is in fact how most AAA engines handle networking by keeping the simulation server-side and then allowing clients to interpolate between transformation update packets. Basically you can think of clients as dumb terminals that simply output the rendered graphics of the simulation that is running server-side, and also handle sending input from the client to the server.
On to your question about movement, the server-side engine API is exactly the same as the client-side one so to move an entity you can use a number of different approaches such as direct translation, path traversal, velocity and also box2d physics.
At this point you might think, "If all my client AND server code is in the same class file, can't the client players just read the server code as well?" and the answer is no. The engine has a built-in deployment system to generate a final client-side build of a game with all of the server code stripped from the classes. In order to faciliate this process you must "mark" your server-side code via a /* CEXCLUDE */ (client-exclude) tag e.g:
Code: Select all
init: function () {
/* CEXCLUDE */
if (ige.isServer) {
// This code will only run on the server
}
/* CEXCLUDE */
if (!ige.isServer) {
// This code will only run on the client
}
}
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Entity network Spawning
now that makes sense. Thanks for great explanation.
-
- Posts: 53
- Joined: Mon Aug 26, 2013 1:54 am
Re: Entity network Spawning
Hi coolbloke,
Well i have one question to ask. In example 24.5-multiplayer-isometric-mouse, how can i set the type of the character to be random? From the example, setType is call from the characterContainer class which is if i generate random value everytime a client connect to the server the character type is not the same. That because from my understanding the characterContainer class will be call every time a client connect to the server. I try to put it inside serverNetworkEvents when initate the _onPlayerEntity but with no luck. The ige.server.players[clientId] has no method of setType although i see ige.server.players[clientId] is created from the characterContainer. So how should i set character type to be random?
Regards,
Zachz
Well i have one question to ask. In example 24.5-multiplayer-isometric-mouse, how can i set the type of the character to be random? From the example, setType is call from the characterContainer class which is if i generate random value everytime a client connect to the server the character type is not the same. That because from my understanding the characterContainer class will be call every time a client connect to the server. I try to put it inside serverNetworkEvents when initate the _onPlayerEntity but with no luck. The ige.server.players[clientId] has no method of setType although i see ige.server.players[clientId] is created from the characterContainer. So how should i set character type to be random?
Regards,
Zachz
zachz
Programmer
compass-interactive
Programmer
compass-interactive
- coolbloke1324
- Posts: 181
- Joined: Mon Jan 23, 2012 5:20 pm
Re: Entity network Spawning
If you take a look at my comment above where I talk about setting the colour of a ghost based on the colour setup on the server, the principal is the same. You set some streamCreateData return value.zaquanishak wrote:Hi coolbloke,
Well i have one question to ask. In example 24.5-multiplayer-isometric-mouse, how can i set the type of the character to be random? From the example, setType is call from the characterContainer class which is if i generate random value everytime a client connect to the server the character type is not the same. That because from my understanding the characterContainer class will be call every time a client connect to the server. I try to put it inside serverNetworkEvents when initate the _onPlayerEntity but with no luck. The ige.server.players[clientId] has no method of setType although i see ige.server.players[clientId] is created from the characterContainer. So how should i set character type to be random?
Regards,
Zachz
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Entity network Spawning
Okay so in the single player I can get things setup and playing no problem however in the multiplayer there is still this piece that is stumping. I probably look like a moron but I cannot get my head wrapped around spawning an entity. It keeps giving me errors and I do not see any examples anywhere on how to do it.
So lets say I want to spawn a Goblin onto the iso multiplayer example 24.5
I create the Goblin class, now how and where do I spawn it on the board? It seems like a simple enough thing to do but it has frustrated me as i must be missing a concept somewhere.
So lets say I want to spawn a Goblin onto the iso multiplayer example 24.5
I create the Goblin class, now how and where do I spawn it on the board? It seems like a simple enough thing to do but it has frustrated me as i must be missing a concept somewhere.
