Client / Server Folders and Client, ServerObjects
by Cinder Games · in Torque Game Engine · 06/21/2006 (8:13 pm) · 4 replies
Alright i'm working on my single player RPG project... and i think i noticed something.
When i first started this project, i just threw all my files in the /server folder. Everything has worked just fine... but now i'm hacking away into the source more and more(currently sceneobject) and i would like this questions answered a bit.
Are objects created from files in the /client/ folder created as ghosted objects?
And the reverse, are all the object created in the /server/ foldered being created as NetObjects?
Example.
$player = new Player()
if i do this in a server file, will $player == the server side version if i echo it into the console?
I'm currently echoing the Id's of my player objects in .setRenderTransform() and the numbers are NOT the same numbers shown in the world editor.
My guess is that i'm correct in my assumption. And if seems like it would make pefect sense. But i figured i'd ask the experts.
I hope someone can maybe shed some light on this.
When i first started this project, i just threw all my files in the /server folder. Everything has worked just fine... but now i'm hacking away into the source more and more(currently sceneobject) and i would like this questions answered a bit.
Are objects created from files in the /client/ folder created as ghosted objects?
And the reverse, are all the object created in the /server/ foldered being created as NetObjects?
Example.
$player = new Player()
if i do this in a server file, will $player == the server side version if i echo it into the console?
I'm currently echoing the Id's of my player objects in .setRenderTransform() and the numbers are NOT the same numbers shown in the world editor.
My guess is that i'm correct in my assumption. And if seems like it would make pefect sense. But i figured i'd ask the experts.
I hope someone can maybe shed some light on this.
#2
06/22/2006 (3:15 am)
Adding to what Stephen said; The folder which the script lives in does not affect whether it's ghosted or not, it's just that the default behaviour of TGE works that way. It all depends how you execute the script, and from where.
#3
In the starter.fps mod, when you execute Torque, a script function called initClient() is called, which executes all scripts in the client folder.
When you start a game, you "create" a server. Actually, no "server" is created. First a simgroup called "serverGroup" is created, then the .mis file is executed, and the missionGroup is added to the serverGroup.
Creating simObject-derived objects using new() in script will always put them on the "server". This simply means they are created, flagged as server objects and added to the server scenegraph.
After all objects in the mission file have been created, the incoming connections are opened, and it waits for clients to connect. The client who "created" the server then creates a gameConnection and tell it to "connectLocal". A dummy hardwired connection is created, and ghosts can be created.
So Torque doesn't really create a server. It becomes a server, and creates a client, which is only an internal pipe through which ghosts can be created into the client scenegraph group.
This is why the script execution is "shared" during local connections. You can freely call methods on server-side objects directly from GUI buttoms if you want to, because both actually exist in the same "space". Since new'ed simObjects are always created as server objects, you can create them from GUIs if you so want.
While this is OK during your first single-player Torque projects, I highly recommend you gradually clean up your code in further projects so they obey they client-server separation. There are 3 reasons for this:
1) The enforced client/server organization forces you to write cleaner code.
2) Your scripts become more in synch with the Torque's internal client/server working, avoiding strange bugs that can happen when things become highly hackish (I've done that myself, and it can be nasty).
3) You will have less code to change if you ever need to build a multiplayer game, or even add a multiplayer mode to the current game.
Even if it doesn't look like it when you're starting with Torque, the client/server stuff is good for single player games too, since it forces a separation of the simulation and the input/display/feedback processes.
06/22/2006 (4:40 am)
To clarify a bit more.In the starter.fps mod, when you execute Torque, a script function called initClient() is called, which executes all scripts in the client folder.
When you start a game, you "create" a server. Actually, no "server" is created. First a simgroup called "serverGroup" is created, then the .mis file is executed, and the missionGroup is added to the serverGroup.
Creating simObject-derived objects using new() in script will always put them on the "server". This simply means they are created, flagged as server objects and added to the server scenegraph.
After all objects in the mission file have been created, the incoming connections are opened, and it waits for clients to connect. The client who "created" the server then creates a gameConnection and tell it to "connectLocal". A dummy hardwired connection is created, and ghosts can be created.
So Torque doesn't really create a server. It becomes a server, and creates a client, which is only an internal pipe through which ghosts can be created into the client scenegraph group.
This is why the script execution is "shared" during local connections. You can freely call methods on server-side objects directly from GUI buttoms if you want to, because both actually exist in the same "space". Since new'ed simObjects are always created as server objects, you can create them from GUIs if you so want.
While this is OK during your first single-player Torque projects, I highly recommend you gradually clean up your code in further projects so they obey they client-server separation. There are 3 reasons for this:
1) The enforced client/server organization forces you to write cleaner code.
2) Your scripts become more in synch with the Torque's internal client/server working, avoiding strange bugs that can happen when things become highly hackish (I've done that myself, and it can be nasty).
3) You will have less code to change if you ever need to build a multiplayer game, or even add a multiplayer mode to the current game.
Even if it doesn't look like it when you're starting with Torque, the client/server stuff is good for single player games too, since it forces a separation of the simulation and the input/display/feedback processes.
#4
06/22/2006 (3:42 pm)
Good information everyone. I'm slowly learning more and more about how torque's networking works. :)
Torque 3D Owner Stephen Zepp
If you create an object in a /server side script, and it's a ghostable object, and in scope of at least 1 client, it will be networked to that client, and a client side ghost object (with its own GhostId for that client only) will be created and updated from the server.