Game Development Community

Easy to Reproduce Lag Issue (FPS RTS hybrid)

by Vijay Myneni · in RTS Starter Kit · 11/28/2004 (9:39 pm) · 92 replies

Okay, this might not actually be an issue, but it's driving me crazy. Hopefully, someone can try this out and let me know if I'm just seeing things. It's fairly quick to set up and try. This post also doubles as a good set of instructions for the basics of getting the FPS player into your RTS game (I want to ultimately make this a resource combined with instructions for setting up clean switching between RTS and FPS control).

1. Start with a clean RTS Engine build, and a clean starter.RTS project. Also have a starter.fps directory around to grab files from.
2. Grab the server/scripts/player.cs file from starter.fps and copy it to server/scripts/avatars/fpsPlayer.cs in starter.RTS.
3. Grab the data/shapes/player directory from starter.fps and copy it to data/shapes/fpsPlayer in starter.RTS.
4. In server/scripts/avatars/fpsPlayer.cs, change the very first exec line to point to your new data directory:
exec("~/data/shapes/fpsPlayer/player.cs");
5. In server/init.cs, add a line to exec your new fpsPlayer.cs script:
exec("./scripts/avatars/fpsPlayer.cs");
.
6. Repeat step 5 in your server/scripts/core/game.cs file. My understanding is that the exec's should happen in the same order in both these files. I have mine happening right after player.cs gets exec'd. Also, I had to ultimately add a line for scripts/fx/environment.cs into my game.cs, so that it matched up with init.cs. If I don't do this, the game crashes during datablock transfer.
7. In server/scripts/core/gameConnection.cs, replace the existing onClientEnterGame with this:
function GameConnection::onClientEnterGame(%this)
{
   commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);

   %clientIndex = %this.getClientIndex();
   %this.setTeam(%clientIndex);

   %offset = ((%this.getTeam()-1) * (%unitsPerDir + 5));

   // Create a new camera object.
   %this.camera = new Camera() {
      dataBlock = Observer;
   };
   MissionCleanup.add( %this.camera );
   %this.camera.scopeToClient(%this);

   // Setup game parameters, the onConnect method currently starts
   // everyone with a 0 score.
   %this.score = 0;

   // Create a player object.
   %this.createFPSPlayer((%offset*5) SPC (%offset*5) SPC "250");
}

8. Also in gameConnection.cs, add the following function:
function GameConnection::createFPSPlayer(%this, %spawnPoint)

{
   if (%this.player > 0)  {
      // The client should not have a player currently
      // assigned.  Assigning a new one could result in 
      // a player ghost.
      error( "Attempting to create an angus ghost!" );
   }

   // Create the player object
   %player = new Player() {
      dataBlock = PlayerBody;
      client = %this;
   };
   MissionCleanup.add(%player);

   // Player setup...
   %player.setTransform(%spawnPoint);
   %player.setShapeName(%this.name);
   
   // Starting equipment
   %player.setInventory(Crossbow,1);
   %player.setInventory(CrossbowAmmo,10);
   %player.mountImage(CrossbowImage,0);

   // Update the camera to start with the player
   %this.camera.setTransform(%player.getEyeTransform());

   // Give the client control of the player
   %this.player = %player;
   %this.setControlObject(%player);
}

Continued...
#21
12/28/2004 (8:40 am)
Vijay,
Thank you, that should be enough rope to do the job :-)
I appreciate the effort.
John
#22
12/30/2004 (8:38 am)
Just finally got into trying to do this today and just a caveat to anyone else who attempts this...if you're getting weird green highlights on the terrain instead of a nice clean selection circle go look in terrData.cc around line 801 or so....

mSelectionTexture = TextureHandle("starter.RTS/client/ui/ring_white", BitmapTexture, true);

Now while this had me scratching my head for about an hour, I can see how this would drive the grep impaired to utter madness. Fortunately it's the only hardcoded path I can see in the RTS kit that looks in /starter.RTS and changing the value to point to your own project will allow the selection circles to be displayed.

However, for sanity's sake I highly recommend using:

mSelectionTexture = TextureHandle("common/ui/ring_white", BitmapTexture, true);

..and move the ring_white.png into that directory so it matters not what you decide to call your project.
#23
12/30/2004 (8:40 am)
Yes, this was one of the gotchas we initially had an issue with as well. IIRC, there may be one or two more paths like that in the engine, but Greg nailed them down pretty quickly, so it shouldn't take too much to find.
#24
12/30/2004 (9:02 am)
James, thanks for that info. I did see green sheets flickering over the tarrain after I copied the starter.RTS folder to a new name. Most of the images used in the UI were lost. I found out that the name of the folder "starter.RTS" was hard coded into the source and into the cs scripts. You have to change all those names and recompile if you want to change the name to something more appropriate. Would have been nicer if it was all relative. John
#25
12/30/2004 (9:18 am)
No problem, it does seem to be the only path hardcoded into the engine proper, but yes there are many scripts where the path is hardcoded as well. None of that stuff threw me off though since I expected that to be the case in the scripts. I did not, however, expect to find this in the C++ code so it took me awhile to get to the point where I did a grep on the whole project rather than just in starter.RTS folder. And presto! Figured I'd save some people the headache ;)

Now onto the drag-select. Woo. It doesn't work. I can point/click my AIPlayers just fine (since that's how I've modded the selections to work) but I can't get that bloody drag-select box. My first guess is that it wants an RTSConnection rather than GameConnection to yak with but I'm not entirely sure ;)

So, on that note. Onwards and upwards! I'm working with both a clean copy of the RTSKit and Torque 1.3 for this btw, so if/when I get this all cleanly (or relatively cleanly) done I'll post it up in the Resources section.
#26
12/30/2004 (9:21 am)
Are you using RTSTSCtrl.cc as your base control? IIRC, the rendering and handling of the drag-select boxes are there.

I'm not positive on this, but I think that all the selection (drag-select, etc) is done client side only, so the connection type shouldn't matter...the only thing that goes across the wire is the selection itself.
#27
12/30/2004 (9:47 am)
Ah! Fair enough, paint me clueless ;) Makes sense that it'd be client side only.

As for am I using RTSTSCtrl.cc as my base control? Uh, do you mean guiRTSTSCtrl being called in Playgui.gui? If so, yes. If not, then I'm not entirely sure as yet where I should be setting up the control.
#28
12/30/2004 (11:34 am)
I had a problem with drag-select too. My problem was that drag-selection wouldn't work because my initial click would get stopped by the GUI elements that were there on the screen (but usually invisible). If you can get the select box to show up by clicking on parts of the screen, but not most of the screen, this is probably your problem too. (Try clicking everywhere)

Unfortunately, I can't for the life of me remember how I fixed this problem. It was a really easy fix once I figured it out. Ack. Maybe it will come to me. Hopefully this points you in the right direction.
#29
04/13/2005 (7:40 pm)
Hows it going with that Vijay? what would you reccomend I take to add this feature? Thanks for any help.
#30
04/14/2005 (12:44 am)
Which feature are you referring to Robert? The mouse selection? And what are you trying to add it to?
#31
04/14/2005 (7:08 am)
No sorry, I'am trying to add FPS to my RTS. I have done what you origanlly did, and it works good. But I cant add RTSUnits in the same map as Players, or vice versa. How do I fix that? So Iwas wondering how you got around that. From what I read you copied the RTS to the TGE and went from there. Does it work good? any lag issues? Thanks for replying

NOTE: Please ReRead I made a edit.

EDIT: Okay im good, Although I may come back for help later. Thanks
#32
04/17/2005 (8:55 am)
Ok all is working but what I did to make that happen was remove debugbreak(); from platform.cc I think. Anything wrong with this?
#33
04/19/2005 (10:41 am)
Hmm...not sure. someone else probably has a definite answer to that. in answer to your earlier questions, yes, i added RTS elements to the TGE, and ya, it all worked out pretty good. no lag issues. the original design of my game has changed to the point where i'm not using that much RTS stuff anymore though. i'm guessing other people have pounded on this much more than i have at this point.
#34
04/22/2005 (8:59 am)
Hm so vijay i am planning something simmilar for my project but i want the user to be able to switch by pressing a button. how does your switch work?
#35
04/25/2005 (11:10 am)
I have switching enabled with the TAB key. I basically detect the character that the camera is most directly looking at, and when the user presses the TAB key, the camera "jumps into" that character and then the user is controlling him. If he wants to jump out again, he presses shift-TAB. If he wants to jump into someone else, he just looks at that person and hits TAB. And I let the camera smoothly interpolate over so it isn't too jarring a jump. All in all, it's working pretty well. Some pointers:

1. you can use the fpsShapeNameHud as a good place to do the detection for who the camera is most directly looking at, and then pass it along to the camera for storing (seems like overkill to do it every frame, but i need to cause i also highlight this person's name to make it clear that he is the target)
2. when the user hits TAB, you can pass along this info to the server
3. the server can then validate and perform the switch
#36
04/25/2005 (2:19 pm)
Thanks 1 Follow up Query... I am planning to have boss battles in my RTS in the "Action Mode of the game". I am planning to have this as a standard 3rd person action mode with controls and such that are standard to action. The other mode is strategy which is the standard point and click stuff thats supported by the SK. The other mode I am planning is a branch off of the 'action mode' but instead of being at fps level the player will control his selected unit from the top dwon view. So basically the action mode is a straight FPS player script. I may plan if possible to have different unit attributes for each mode. (For example the rate of fire is faster in Action mode to allow for a more arcade feel) Should i have 1 fps player script to handle the player's capabilities (Jumping, strafing and the like) in Action Mode and another script to handle the player's capabilities in RTS mode (IE free camera movement and unit clicking) when the player is in Unit Or Strategy mode? Is this the most efficient way? or should I simply have one script file that contains each units attributes in the strategy and action modes respectively?
#37
04/27/2005 (4:30 pm)
Marvin,

If I'm understanding your questions right, you're asking whether or not your code should be in one file or in several. I don't think it really matters. It's all about how you want to organize it. It probably does make sense to separate out the different functionality into different files just so you can find stuff easier. Or maybe "packages" would be helpful to you (although I haven't explored that aspect of torqueScript yet). Personally, I suppose I have a lot of functions that handle both modes of my game, and just use a global boolean to determine which mode to do). Some tips:

1. might be easier to use different players with different datablocks for your different modes. then, when you switch, get rid of one and swap in the other one
2. could be helpful to use different bindings (action maps) for the mouse and keyboard and push and pop them as needed for the different modes. i'm actually not doing this, i just use one default map and have a bunch of global booleans to control behaviour. but it probably would have been cleaner the other way.

Remember to keep both the client and the server in-synch when it comes to which mode of gameplay the game is in. Most of the bugs I had with game mode switching related to this.
#38
05/03/2005 (8:05 am)
Integrating RTS back into FPS....

Anyone having problems with teams? I got most of the code put back together... but now RTS players crash FPS players. Here's the situation:

1) If I start a server and connect a few RTS players, when I connect a FPS player the FPS player's game crashes.

2) If I start a server with a few FPS players, when I connect a RTS player ALL the FPS players crash.

3) all crashes are on "getTeam" in RTSConnection.

The game runs prefectly if only clients of the sme type are connected. I use RTSConnection for RTS players and GameConnection for FPS players so I am not sure why it would even be using RTSConnection on the FPS clients. Are the RTS clients asking the FPS clients for information they don't have (mTeam)? Should I be adding mTeam into player and gameconnection?

I have a feeling I may be missing something obvious.... Thanks in advance for any help!
#39
05/03/2005 (3:28 pm)
If you do figure it out please post the solution.
#40
05/25/2005 (7:12 am)
Hi Vijay

I tried to replicate to create this situation last night but when I loaded it after changing the code, the example mission was still the same. It had the same units and everything (no orc) so after that I added an exec line for scripts/fx/environment.cs in the game.cs like you recommended. Now when I ran the rts example again it attempted to load everything but the loading screen got stuck when it was 'loading objects". The little progress bar ran the length of the progress box which i guess indicated that the process was complete but after waiting for about ten minutes or so, the level never loaded.

Did you experience this problem at all during your expirement?

I will check my code to make sure it matches yours code as your wrote it above but is there another step I may be missing?

Do i have to change anything in the example mission?