Game Development Community

Waiting for RC1: ScatterSky Sun not updating elevation position

by Ron Lindsey · in Torque 3D Professional · 08/03/2009 (10:49 am) · 10 replies

Since I have written my own Time Manager, I am not using the TimeOfDay object. So I need to automate the ScatterSky sun elevation position in real time. However, as the elevation variable changes, the position of the sun is not updating.

Here is my Server code...

// Minutes
if ($time.CurrentSecond >= $time.SettingSecondsInMinute) {
   $time.CurrentSecond = 0;
   $time.CurrentMinute++;
 
   %SunElevation = (360 / ($time.SettingHoursInDay * $time.SettingMinutesInHour)) * (($time.CurrentHour * $time.SettingMinutesInHour) + $time.CurrentMinute);
   // Inform the clients of new sun elevation
   for(%clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++)
   {
       %cl = ClientGroup.getObject(%clientIndex);
       commandToClient(%cl,'EnviromentClient',%SunElevation);
   }
}

Here is my client code...
function clientCmdEnviromentClient($SunElevation)
{
   ScatterSky.elevation = $SunElevation;
   GUICurrentSunElevation.text = ScatterSky.elevation;
}

I know that clientCmdEnviromentClient is getting called because GUICurrentSunElevation.text is updated on my debug panel.

Here is the ScatterSky object code...
new ScatterSky(ScatterSky) {
   skyBrightness = "25";
   mieScattering = "0.0045";
   rayleighScattering = "0.0035";
   sunScale = "1 1 1 1";
   ambientScale = "1 1 1 1";
   exposure = "1";
   interpolationStart = "182";
   interpolationEnd = "192";
   azimuth = "57.2958";
   elevation = "79.75";
   castShadows = "1";
   brightness = "1";
   flareType = "ScatterskyFlareExample";
   flareScale = "1";
   nightColor = "0.0196078 0.0117647 0.109804 1";
   moonEnabled = "1";
   moonTexture = "art/skies/night/moon_wglow";
   moonScale = "0.3";
   moonTint = "0.192157 0.192157 0.192157 1";
   useNightCubemap = "1";
   nightCubemap = "StarryCubemap";
   attenuationRatio = "0 1 1";
   shadowType = "PSSM";
   texSize = "512";
   overDarkFactor = "2000 1000 500 100";
   shadowDistance = "400";
   shadowSoftness = "0.15";
   numSplits = "4";
   logWeight = "0.91";
   fadeStartDistance = "0";
   lastSplitTerrainOnly = "0";
   splitFadeDistances = "10 20 30 40";
   representedInLightmap = "1";
   shadowDarkenColor = "0 0 0 -1";
   includeLightmappedGeometryInShadow = "1";
   position = "-201.845 -119.221 186.099";
   rotation = "1 0 0 0";
   scale = "1 1 1";
   canSaveDynamicFields = "1";
      locked = "1";
      setIsSelected = "1";
      sunBrightness = "25";
};

I know there is something I am missing. Any suggestions?

Thanks!
Ron Lindsey

#1
08/03/2009 (4:56 pm)
I have done more testing and still no luck.

I noticed that if I click on the various properties of my ScatterSky object in the Object Editor, the sun position will update.

Also, I know that the elevation property is being updated because I am writing the elevation value to a text box in real time. (GUICurrentSunElevation.text = ScatterSky.elevation;)

??

Ron
#2
08/05/2009 (10:12 pm)
Anyone?
#3
08/07/2009 (1:26 am)
The ScatterSky is already setup to send updates to clients when the serverside elevation changes so you should be able to do "ScatterSky.elevation = value;" right there on the server.
#4
08/07/2009 (1:48 am)
Actually, looks like this needs to be fixed...

In the meantime you could change it on the server as recommended previously and add a new console method to ScatterSky that calls inspectPostApply (which is what gets calls and makes it work from the WorldEditor).
#5
08/07/2009 (5:57 am)
This is your problem(s):
function clientCmdEnviromentClient($SunElevation)
{
   ScatterSky.elevation = $SunElevation;
   GUICurrentSunElevation.text = ScatterSky.elevation;
}

First of all, your object is named ScatterSky, which is the same as the class name. This is bad, and I'm surprised it's working at all. Rename it to something else.

Second, parameters ($SunElevation) are supposed to be local variables (%), not global ones ($).

Third, ghosted objects don't have names. So when you set ScatterSky.elevation, you're changing the value on the server-side object if you're on a local connection or on a non-existent object if you're on a remote connection.

In the server, you need to get the ghost ID for the ScatterSky object for each client and them send that ID. The clients will convert the ghost ID into real object ID (which will point to their ghost copy of the ScatterSky) and then you can set values there.

Here's your modified server code:
// Minutes
if ($time.CurrentSecond >= $time.SettingSecondsInMinute) {
   $time.CurrentSecond = 0;
   $time.CurrentMinute++;
 
   %SunElevation = (360 / ($time.SettingHoursInDay * $time.SettingMinutesInHour)) * (($time.CurrentHour * $time.SettingMinutesInHour) + $time.CurrentMinute);

   %scatterSkyObj = ScatterSky.getId();
   
   // Inform the clients of new sun elevation
   for(%clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++)
   {
       %cl = ClientGroup.getObject(%clientIndex);
       %ghostId = %cl.getGhostId(%scatterSkyObj);
       commandToClient(%cl,'EnviromentClient',%ghostId,%SunElevation);
   }
}

And the client code:
function clientCmdEnviromentClient(%ghostID, %SunElevation)
{
   %scatterSkyObj = ServerConnection.resolveGhostID( %ghostId );
   %scatterSkyObj.elevation = %SunElevation;
   GUICurrentSunElevation.text = %SunElevation;
}
#6
08/07/2009 (6:14 am)
Thanks for the responses!

@James: I will run some test to see if the server updates the clients. Is this the design of the object? How would the clients all stay in sync this way?

@Manoel: Very well worded response. I need to review my Torque books again on ghost objects. I will update my code and run test.

Results to come...

Ron
#7
08/07/2009 (10:17 am)
At this time it the ScatterSky does not know to "setMaskBits" which triggers sending an update to the client(s) in response to the elevation field being changed. This is the normal way that NetObject derived classes work and networking in general in torque.
#8
08/07/2009 (10:47 am)
@James: When will the ScatterSky object being able to trigger updates? RC1?
#9
08/08/2009 (12:56 pm)
Yes, I think RC1 (it was too late to make more changes to Beta5).
#10
08/10/2009 (2:04 pm)
Resolved for RC1.

Elevation and azimuth are now networked automatically.
If the user wishes to change the other fields and have them networked they may call applyChanges which will cause a full update.