Game Development Community

Solution for setting Player ControlObject to same object

by Scott Zarnke · in Torque X 2D · 06/17/2009 (9:25 am) · 9 replies

In some other posts, some people have commented on how if you assign an object to a Player's ControlObject which is the same as the one already set, it cease controlling it. I've looked at the ControlObject property and realized it was a simple oversight by the writer.

***EDIT*** For those who don't have access to the TX source code, you can fix this by creating a new InputMap for the player and assigning that to the PlayerManager's player:
// Get input map for this player and configure it  
inputMap = new InputMap();  
PlayerManager.Instance.GetPlayer(playerIndex).InputMap = inputMap;
Afterwards, you may set the inputMap as usual. Thanks to Tony Pitman for this fix.
**********

The original Sim.PlayerManager.Player.ControlObject code:
set
{
    if (_controlObject != null)
        ProcessList.Instance.ClearMoveManager(_controlObject);
    if (value != null)
        ProcessList.Instance.SetMoveManager(value, _moveManager);
    _controlObject = value;
}

Changing to the following fixes the problem:
set
{
    if (value == _controlObject)
        return;
    if (_controlObject != null)
    {
        ProcessList.Instance.ClearMoveManager(_controlObject);
        _moveManager._Consumer = null;
    }
    if (value != null)
        ProcessList.Instance.SetMoveManager(value, _moveManager);
    _controlObject = value;
}

The main fix is to set _moveManager._Consumer = null since it is not cleared by ClearMoveManager(), and inside SetMoveManager() if it detects that _moveManager._Consumer is equal to value, it does nothing and so does not set it the second time. With _moveManager._Consumer null, the move manager is set as it should be.

The line if (value == _controlObject) was added to reduce redundancy, since otherwise when assigning the same value, it would be cleared and then set again, which is unnecessary. This equality test by itself would also fix the problem, but if value is null after previously setting ControlObject to an object, without the line explicitly setting _moveManager._Consumer = null, it would remain referencing an object, when it really should be null. It also would have a small redundancy inside SetMoveManager() as the cookie is cleared after having already been cleared by ClearMoveManager().


***EDIT*** Sorry for the double threads; I realized after posting this it should have gone in Bug Submissions.

#1
06/17/2009 (10:16 am)
Added link to this post in Community Links.

Brian
#2
06/17/2009 (4:44 pm)
Cool!

Thanks for the info. I had a local fix in my own codebase for this, but I didn't have enough time to thoroughly test it so I didn't feel like giving out a potential fix :)

By the way, I think it might be a good idea to put some of the common bug fixes somewhere under the TDN.

Might be a good idea to throw up the GUISceneView RenderMask issue Scott mentions here.

Also, I've proposed a fix some time ago with a memory leak inside the GUI framework here.

I haven't been around that long, but those are the last ones that come to mind.
#3
07/21/2009 (1:32 pm)
I must have this bug but the fix didn't work for me

www.danpascal.com/GreenRobotBug.ccgame
(needs xbox360 gamepad)
on the first respawn it loses control of the player object
2nd spawn it comes back, sometimes

@Scott do you want to debug this for me?
#4
07/21/2009 (5:16 pm)
I took a look at the game you posted and I see what you mean, though without the source it's tough to say. Would you be alright with posting the VS solution in a zip file? If you do, you can delete everything in the debug and release folders since they can be rebuilt; that way the file's a little smaller.

Looks pretty cool, anyway.

Also, one thing I noticed was in the sounds folder there were a lot of xnb files. When I build, there is only the three files: xgs, xsb, and xwb. I wonder what your settings are for the sound files?
#5
07/21/2009 (5:24 pm)
Scott, what's your email address?
#6
07/21/2009 (5:27 pm)
[removed by poster]
#7
07/21/2009 (11:39 pm)
@Dan:
Your problem was indeed the ControlObject issue. To fix without changing the TorqueX source, you can change your one line in the SetupInputMap method inside MovementComponent to the following so that it recreates the InputMap:
// Get input map for this player and configure it
inputMap = new InputMap();
PlayerManager.Instance.GetPlayer(playerIndex).InputMap = inputMap;
This was found out by Tony Pitman on this thread. Not sure why that fixes it, but I confirmed that it works for your game.

Btw, it looks cool and and is pretty fun, though difficult till I got the hang of strafing. Very creative visually. Did you do the art yourself? It is a little concerning how big your images are. I got warnings about the ones that are 4000 pixels wide. They could be reworked to be 2000 x 1600 instead, to be in line with graphics cards that only allow up to 2048 on a side for textures.
#8
07/22/2009 (7:17 am)
THANKYOU!!

#9
07/22/2009 (7:46 am)
picture sizes: ya im surprized they work, even on a laptop with 2gig shared video memory...
sounds: I thought the sounds needed to be in that folder when compiling

game: it's going to be a downloadable tutorial kit, with lots of videos explaining-

that spider isn't mine, the owner hasn't gotten back to me so I'm going to have to recreate/replace it

can you beat the game?
hold the right bumper in while running backwards