Need help with WritePacket on multiple objects
by Manoel Neto · in Torque Game Engine · 01/27/2006 (3:02 pm) · 12 replies
In the last 3 days I've implementing split screen support in TGE 1.4.
First I got the multiple cameras working, allowing a GameTSCtrl to render the world through a different object view. Since I use AdvancedCameras, that required me to add support to multiple cameraObjects in gameConnection, otherwise the cameras wouldn't update properly (no writePacket). That done, I could view the game from each of my bots
Then I went to add support for "extra" control objects in the gameConnection class. That was a bit trickier than the cameras. I added a mSlaveObject array to GameConnection, and setSlaveObject(obj, index) and getSlaveObject(index) methods. The number of slave objects is specified in a #define.
I went in every functions that dealt with updating the controlObject, and added code to update the slave objects too, and I got them to get properly sent through the network. Lastly, I had to get multiple moves to be generated, and passed down to each specific slave object. It was rather painfull, but I got it working eventually. I can play 4 players split screen, using a keyboard and some joypads.
But there's only one final problem: the 4th player shows no problems, but players 1-3 are a bit jumpy (actually, they shake a bit while moving). The shaking gets worse when they get far from player #4, and eventually the pilots disappear when far enough (it's a racing game). I'll fight against this bug this weekend, but I thought it would be a good idea to post about it here, so maybe someone can help me a bit.
BTW, I intend creaint a resource for the multiple cameras (it's different than the fxGuiSnooper) and the single-machine multiplayer (it doesn't need the multiple cameras to work - you could do a game for multiple players with a single camera, like a sports game or a Gauntlet-style game).
First I got the multiple cameras working, allowing a GameTSCtrl to render the world through a different object view. Since I use AdvancedCameras, that required me to add support to multiple cameraObjects in gameConnection, otherwise the cameras wouldn't update properly (no writePacket). That done, I could view the game from each of my bots
Then I went to add support for "extra" control objects in the gameConnection class. That was a bit trickier than the cameras. I added a mSlaveObject array to GameConnection, and setSlaveObject(obj, index) and getSlaveObject(index) methods. The number of slave objects is specified in a #define.
I went in every functions that dealt with updating the controlObject, and added code to update the slave objects too, and I got them to get properly sent through the network. Lastly, I had to get multiple moves to be generated, and passed down to each specific slave object. It was rather painfull, but I got it working eventually. I can play 4 players split screen, using a keyboard and some joypads.
But there's only one final problem: the 4th player shows no problems, but players 1-3 are a bit jumpy (actually, they shake a bit while moving). The shaking gets worse when they get far from player #4, and eventually the pilots disappear when far enough (it's a racing game). I'll fight against this bug this weekend, but I thought it would be a good idea to post about it here, so maybe someone can help me a bit.
BTW, I intend creaint a resource for the multiple cameras (it's different than the fxGuiSnooper) and the single-machine multiplayer (it doesn't need the multiple cameras to work - you could do a game for multiple players with a single camera, like a sports game or a Gauntlet-style game).
About the author
Recent Threads
#2
01/30/2006 (1:13 pm)
Manoel. You are on the ball. We were going to implement such a scheme for Marble Blast Ultra but ran out of time. Your solution is just what we were planning. Re: the scope object, you can probably just re-write the scoping functions (getUpdatePriority and onCameraScopeQuery) to deal with your slave objects properly.
#3
The code supports as many players as the Torque network pipe can handle (the max number of players is defined at compile time) without breaking any of the existing functionality. The code changes are pretty straightforward , but can be tiresome to do, since there are lots of places to change. At least only 3 or 4 files need changes, so it's pretty condensed.
As for the scoping... well... since I blew up the stimated time for this in almost two days (I estimated it do take 3 days to do, it took me almost five), I took the cheap route to save time. In ShapeBase::onCameraScopeQuery, I replaced this:
By this:
Shame on me!
The changes also depend a bit on the "separate camera object" resource, since we use advancedCameras for nearly everything.
01/30/2006 (1:52 pm)
Maybe someone could help me creating a resource out of this? I'm sure it would be useful for others, moreso now that Torque is getting more console-space (and local multiplayer is a must in any console). All changes are comment-tagged, and while not having the nicest comments, it's possible to identify all changes without a diff tool.The code supports as many players as the Torque network pipe can handle (the max number of players is defined at compile time) without breaking any of the existing functionality. The code changes are pretty straightforward , but can be tiresome to do, since there are lots of places to change. At least only 3 or 4 files need changes, so it's pretty condensed.
As for the scoping... well... since I blew up the stimated time for this in almost two days (I estimated it do take 3 days to do, it took me almost five), I took the cheap route to save time. In ShapeBase::onCameraScopeQuery, I replaced this:
if (mSceneManager == NULL)
{
// Scope everything...
gServerContainer.findObjects(0xFFFFFFFF,scopeCallback,cr);
return;By this:
if (mSceneManager == NULL || Con::getBoolVariable("$Server::scopeEverything")) //if (mSceneManager == NULL)
{
// Scope everything...
gServerContainer.findObjects(0xFFFFFFFF,scopeCallback,cr);
return;Shame on me!
The changes also depend a bit on the "separate camera object" resource, since we use advancedCameras for nearly everything.
#4
03/06/2006 (10:31 pm)
Hi Manoel. Your single-machine multiplayer stuff would be very useful in my game (fixed-position advanced camera, two players). Let me know if you want help creating the resource.
#5
The relevant files are full of other changes, either from other resources or from our own. I'm out of time to filter everything else out and create files with only the required changes. All changes are tag-commented in some way, so it's possible to figure out what changes to keep.
If you're willing to help, I can e-mail the modified files.
03/07/2006 (8:42 am)
I'd use some help in creating a resource. The relevant files are full of other changes, either from other resources or from our own. I'm out of time to filter everything else out and create files with only the required changes. All changes are tag-commented in some way, so it's possible to figure out what changes to keep.
If you're willing to help, I can e-mail the modified files.
#6
03/07/2006 (9:13 am)
Sure, send 'em my way and I'll start sifting through the changes. I have a clean TGE 1.4 install with only the advanced camera resource implemented, which I could use as a starting point for this resource.
#7
03/08/2006 (12:31 pm)
I sent them to your profile's e-mail.
#8
03/08/2006 (5:26 pm)
Thanks, I'll start dissecting them and let you know when I've got something for you to post as resource.
#9
That DRL is so awesome I *had* to stick it into our new project. :)
03/15/2006 (5:58 am)
Drop me a note when you get it done, since I just got a new resource that derives from it: the changes required to make the newly released TLK 1.4 DRL compatible with split screen.That DRL is so awesome I *had* to stick it into our new project. :)
#10
03/15/2006 (9:47 am)
Cool! I'll let you know when I get it done.
#11
04/02/2006 (10:19 pm)
Manoel, I just e-mailed you the files for the single screen local multiplayer resource. I hope to have the split screen version finished within the next couple of weeks.
#12
04/04/2006 (7:14 am)
I submited the resource. It should be up after being reviewed.
Associate Manoel Neto
Default Studio Name
Alright, 4-players split screen TGE is working, all I need is do something about the scope issue... one of the players got registered as the scope object, and when it is far enough, some objects start disappearing around the other players.