Procházet zdrojové kódy

Adjustments to allow Entities/Components to act as cameras and control objects.

Areloch před 9 roky
rodič
revize
38c18870d3
1 změnil soubory, kde provedl 61 přidání a 2 odebrání
  1. 61 2
      Engine/source/T3D/gameBase/gameConnection.cpp

+ 61 - 2
Engine/source/T3D/gameBase/gameConnection.cpp

@@ -38,6 +38,8 @@
 #include "T3D/gameBase/gameConnectionEvents.h"
 #include "console/engineAPI.h"
 #include "math/mTransform.h"
+#include "T3D/Entity.h"
+#include "T3D/Components/coreInterfaces.h"
 
 #ifdef TORQUE_HIFI_NET
    #include "T3D/gameBase/hifi/hifiMoveList.h"
@@ -551,7 +553,9 @@ void GameConnection::setControlObject(GameBase *obj)
       obj->setControllingClient(this);
 
       // Update the camera's FOV to match the new control object
-      setControlCameraFov( obj->getCameraFov() );
+      //but only if we don't have a specific camera object
+      if (!mCameraObject)
+         setControlCameraFov(obj->getCameraFov());
    }
 
    // Okay, set our control object.
@@ -729,7 +733,17 @@ bool GameConnection::getControlCameraFov(F32 * fov)
    }
    if (cObj)
    {
+      if (Entity* ent = dynamic_cast<Entity*>(cObj))
+      {
+         if (CameraInterface* camInterface = ent->getComponent<CameraInterface>())
+         {
+            *fov = camInterface->getCameraFov();
+         }
+      }
+      else
+      {
       *fov = cObj->getCameraFov();
+      }
       return(true);
    }
 
@@ -747,7 +761,22 @@ bool GameConnection::isValidControlCameraFov(F32 fov)
       obj = obj->getControlObject();
    }
 
-   return cObj ? cObj->isValidCameraFov(fov) : NULL;
+   if (cObj)
+   {
+      if (Entity* ent = dynamic_cast<Entity*>(cObj))
+      {
+         if (CameraInterface* camInterface = ent->getComponent<CameraInterface>())
+         {
+            return camInterface->isValidCameraFov(fov);
+         }
+      }
+      else
+      {
+         return cObj->isValidCameraFov(fov);
+      }
+   }
+
+   return NULL;
 }
 
 bool GameConnection::setControlCameraFov(F32 fov)
@@ -762,9 +791,25 @@ bool GameConnection::setControlCameraFov(F32 fov)
    }
    if (cObj)
    {
+      F32 newFov = 90.f;
+      if (Entity* ent = dynamic_cast<Entity*>(cObj))
+      {
+         if (CameraInterface* camInterface = ent->getComponent<CameraInterface>())
+         {
+            camInterface->setCameraFov(mClampF(fov, MinCameraFov, MaxCameraFov));
+            newFov = camInterface->getCameraFov();
+         }
+         else
+         {
+            Con::errorf("Attempted to setControlCameraFov, but we don't have a camera!");
+         }
+      }
+      else
+      {
       // allow shapebase to clamp fov to its datablock values
       cObj->setCameraFov(mClampF(fov, MinCameraFov, MaxCameraFov));
       F32 newFov = cObj->getCameraFov();
+      }
 
       // server fov of client has 1degree resolution
       if( S32(newFov) != S32(mCameraFov) || newFov != fov )
@@ -1147,10 +1192,17 @@ void GameConnection::readPacket(BitStream *bstream)
 
       if (bstream->readFlag())
       {
+         bool callScript = false;
+         if (mCameraObject.isNull())
+            callScript = true;
+
          S32 gIndex = bstream->readInt(NetConnection::GhostIdBitSize);
          GameBase* obj = dynamic_cast<GameBase*>(resolveGhost(gIndex));
          setCameraObject(obj);
          obj->readPacketData(this, bstream);
+
+         if (callScript)
+            initialControlSet_callback();
       }
       else
          setCameraObject(0);
@@ -1727,6 +1779,13 @@ DefineEngineMethod( GameConnection, transmitDataBlocks, void, (S32 sequence),,
             // Ensure that the client knows that the datablock send is done...
             object->sendConnectionMessage(GameConnection::DataBlocksDone, object->getDataBlockSequence());
         }
+
+        if (iCount == 0)
+        {
+           //if we have no datablocks to send, we still need to be able to complete the level load process
+           //so fire off our callback anyways
+           object->sendConnectionMessage(GameConnection::DataBlocksDone, object->getDataBlockSequence());
+        }
     } 
     else
     {