Game Development Community

Objects appearing slowly after creating many at once.

by CEMA, Monash University · in Torque Game Engine · 03/21/2006 (11:44 pm) · 11 replies

I'm running some code like this:

for(%i = 0; %i < 300; %i += 30) {
      for(%j = 0; %j < 600; %j += 30) {
            
         %pos = %i @ " " @ %j @ " " @ 
         
         %obj = new TSStatic(Tree) { 
            position = %i SPC %j SPC getTerrainHeight(%i SPC %j);
            shapeName = "gds/data/shapes/tree/tree.dts";
         };
      }
   }

As you can see, this makes a nice neat "forest" of about 100 trees or so. What's interesting is that the trees don't all appear at the same time - in fact they appear "a couple at a time" over about 5 seconds.

Why is this? I'd like the trees to appear instantly. Can this be done?

I'm running this code in "single-player mode", i.e., when my client and server are the same program.

Nick

#1
03/22/2006 (2:21 am)
That's a lot of trees! my guess would be you're maxing out the packetsize as these are being ghosted to the client- I think this still applies even when you're running in "single player mode"
#2
03/22/2006 (4:04 am)
Its actually 200 trees.
#3
03/22/2006 (6:15 am)
Hi Nick

Take a look at the replicators instead of adding things manually. They work fantastic for exactly what you do.

I would also do a little plug of my replicator blocker ressource, that you then can use to carve paths or similar into a replicated area.

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6467
#4
03/22/2006 (7:17 am)
The way I cna think of making them appear instantly is perhaps making them invisible upon creation and then turning them on or waiting to start the mission until they are all created. I'm not to clear on how to go about the invisible method though. Or you could use the replicators. Or check out the forest pack which is in the making http://www.garagegames.com/blogs/8863/9817.
#5
03/22/2006 (9:47 am)
Yes, use the replicator unless you were looking to create them in a procedural pattern, which I doubt, but in that case you would DEFINITELY be wanteing to use a StaticShape as a base instead of TSStatic objects. And I never saw that resource of yours Thomas, that looks awesome!
#6
03/22/2006 (6:39 pm)
Thanks for the comments, guys.

The code I posted was more of an experiment. It's not my actual game code. My game creates and deletes trees continually in an essentially unpredicatble way throughout the life of the game. (I'm working on what you might call a "procedural world builder".) Thus the replicators are not much help to me.

I'm only going to run Torque single-player, so I would have thought I don't need to worry about network usage when creating lots of objects. As Sam says, there is probably some built-in Torque networking limit at play here. Is this a script-exposed setting, or do I have to modify the engine here?

Paul, I'd be interested to know the difference between StaticShape and TSStatic, and why it's a good idea to use the former in my case.

Thanks,
Nick.
#7
03/22/2006 (8:21 pm)
I can't say if it will help with the gradual loading of the trees, but working from a StaticShape will give you the advantage of working from a single instanced object(s) instead of creating a new object every time, it'll save big on memory. And if you're only doing this on a mission's start up, a cheap little way to get around the trees popping up as they load in, is to just black out the clients screen for a few second once they load, and then they'll never see it.
#8
03/22/2006 (10:53 pm)
The settings you'd want to modify would be $Pref::Net::PacketSize and $Pref::Net::PacketRateToClient. The default values for those settings are 200 and 10 respectively, but can only go to 450 and 32 maximum respectively.

Perhaps try setting them to their maximums (and ensure that they are set properly with echo($Pref::Net::PacketSize); as there are a few places to change them) and see if that fixes the problem. If it helps the problem but doesn't completely eliminate it, you may have to delve into code and change void NetConnection::checkMaxRate() to remove the caps.

Let us know if that helps your situation!

Stephane
#9
03/22/2006 (11:44 pm)
You can change the max sizes for PacketSize and the others by hacking the engine.

Somewhere in the forums (sorry - no time to do the search for you - go to work in 2 mins) there was a discussion on how to get loading done faster in single player games. In there they reference some good values to set the max to. I've tried that and it did wonders for single player games.
#10
03/23/2006 (9:45 pm)
Stephane,

Awesome! Those variables are exactly what I was looking for. My magical forest now appears in something like 1 second, not 5. Thanks.

Thomas,
I'll have a search for the engine hacking stuff. Thanks for the heads up.
#11
03/23/2006 (10:53 pm)
Http://www.garagegames.com/mg/forums/result.thread.php?qt=23589