Game Development Community

Flashlight problems over network

by Brandon Smith · in Torque Game Engine · 04/06/2005 (6:51 pm) · 6 replies

I've implemented the flashlight from the resource by Robert Brower. What it does is mounts a flashligh effect to your weapon by adding a light via the lightManager. But the problem I am having is that the flashlight will not show up over a network on any of the client's sides, only on the servers side. Well, it will show up if I equip the people with the flashlight to begine with, but otherwise it will not. Clients can turn their flashlights on and off, and the server will see it, but they will not.

Does anyone that has experience with the network coding of this engine have any ideas on what might be the possible cause of this problem? Thanks!

#1
04/14/2005 (9:22 am)
I looked into this a little more.

The problem doesn't seem to be unique to the Flashlight, it applies for all mounted lights like ConstantLights and PulsingLights. It seems the registerLights function for the mounted lights gets called only once on the client side when the game loads. That means the only way you'll see the mounted light on the client side is if you start out with the light on you. You won't see it if the light is something you switch to later on.

I'll work on trying to get this registerLights function called whenever you mount a weapon, but if anyone knows an easy way to do this I'd appreciate it! Thanks!
#2
04/14/2005 (9:25 am)
Just a thought but how hard would be it to just implement a command to client to just turn the thing on and off clientside?
#3
04/14/2005 (11:36 am)
I've tried turning it on and off client side, I think. It's a weapon that has a flashlight mounted on to it, so the only way I know to turn the flashlight on and off is to swap weapons. So the code is run wherever weapons are swapped.
#4
04/15/2005 (9:38 pm)
Okay I apparently didn't realize something about the registerLights functions. So this is a function that is being called every frame? I had previously thought that registerLights was something that was called just once at the very beggining, but I guess I was wrong.

So then that really confuses me, why wouldn't these lights be showing up for clients if the function IS being called continously?

And here's one that I'd really appreciate an answer to. As a server, if I start out with a image light, then the light shows up at double intensity, like it's being "registered" twice. But if the image light is on a weapon I switch to later on it shows up normally. Why would this happen? What goes on at the start when the player spawns that does this? Thank you!

EDIT:: I think the problem might be that the imageLights aren't getting added to the list of lights to be registered, but I can't test that right now. I'll let you guys know if I find anything out.
#5
04/16/2005 (10:26 am)
The problem was that the image lights weren't being added to the SceneGraph as lights to be registered.

As a quick fix, in ShapeBase.cc and ShapeImage.cc you can comment out the check where it asks if the light is of "NoLight" or not, like this

if (imageData != NULL /*&& imageData->lightType != ShapeBaseImageData::NoLight*/)
         {
            Sim::getLightSet()->addObject(this);
            break;
         }

But I'll try and post a complete solution later when I get the time.
#6
04/17/2005 (9:14 am)
Okay, here is my solution to getting the image lights to work in multiplayer.

First do what I said just one post up. Then in ShapeImage.ccc in the registerLights function remove the corresponding check for the light type

for (S32 i = 0; i < MaxMountedImages; i++)
   {       
      ShapeBaseImageData* imageData = mMountedImageList[i].dataBlock;

      if (imageData != NULL /*&& imageData->lightType != ShapeBaseImageData::NoLight*/)
      {

Then to fix the double light problem, in the mountImage() function get rid of where the imageLight is added to the SceneGraph
//   if (imageData->lightType != ShapeBaseImageData::NoLight)
//   {
//	   Sim::getLightSet()->addObject(this);
//   }

The best solution would probably be to figure out why the lightType isn't going across the network but this workse for me. Hope it helps someone else in their flashlight adding endeavors.