Torque3D Documentation / _generateds / gameFunctions.cpp

gameFunctions.cpp

Engine/source/T3D/gameFunctions.cpp

More...

Namespaces:

namespace

Camera and FOV info.

Public Functions

ConsoleFunctionGroupBegin(Containers , "Spatial query functions. <<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a91b64995742fd30063314f12340b4b5a">b</a>>Server side only!</<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a91b64995742fd30063314f12340b4b5a">b</a>>" )
DefineEngineFunction(containerFindFirst , const char * , (U32 typeMask, Point3F origin, Point3F size) , "(int mask, <a href="/coding/class/classpoint3f/">Point3F</a> point, float x, float y, float z)" "@brief Find objects matching the bitmask type within <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> box centered at point, with extents x, y , <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">z.\n\n</a>" " @returns The first object found, or an empty string <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> nothing was found. Thereafter, you can get more " "results using containerFindNext()." " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">containerFindNext\n</a>" " @ingroup Game" )
DefineEngineFunction(containerFindNext , const char * , () , "()" "@brief Get more results from <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> previous call <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> containerFindFirst().\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@note You must call containerFindFirst() <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> begin the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">search.\n</a>" "@returns The next object found, or an empty string <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> nothing else was <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">found.\n</a>" " @see containerFindFirst()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @ingroup Game" )
DefineEngineFunction(setDefaultFov , void , (F32 defaultFOV) , "@brief Set the default FOV <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">camera.\n</a>" "@param defaultFOV The default field of view in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">degrees\n</a>" "@ingroup CameraSystem" )
DefineEngineFunction(setFov , void , (F32 FOV) , "@brief Set the FOV of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">camera.\n</a>" "@param FOV The camera's <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> FOV in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">degrees\n</a>" "@ingroup CameraSystem" )
DefineEngineFunction(setZoomSpeed , void , (S32 speed) , "@brief Set the zoom speed of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">camera.\n</a>" "This affects how quickly the camera changes from one field of view " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">another.\n</a>" "@param speed The camera's zoom speed in ms per 90deg FOV <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">change\n</a>" "@ingroup CameraSystem" )

Gets the camera field of view angle.

bool

Gets the position, rotation, and velocity of the camera.

bool

Does the same thing as GameGetCameraTransform, but fills in other data including information about the far and near clipping planes.

Actually renders the world.

Sets the field of view angle of the camera.

Sets where the camera fov will be change to.

Update the camera fov to be closer to the target fov.

renderFrame(GFXTextureTargetRef * target, MatrixF transform, Frustum frustum, U32 typeMask, ColorI canvasClearColor)

Does a full, top-to-bottom call to render a frame.

Detailed Description

Public Variables

S32 gEaseBack 
S32 gEaseBounce 
S32 gEaseCircular 
S32 gEaseCubic 
S32 gEaseElastic 
S32 gEaseExponential 
S32 gEaseIn 
S32 gEaseInOut 
S32 gEaseLinear 
S32 gEaseOut 
S32 gEaseQuadratic 
S32 gEaseQuartic 
S32 gEaseQuintic 
S32 gEaseSinusoidal 
bool gEditingMission 

For frame signal.

 MODULE_END 
 MODULE_INIT 
 MODULE_SHUTDOWN 
U32 sgServerQueryIndex 
SimpleQueryList sgServerQueryList 

Public Functions

ConsoleFunctionGroupBegin(Containers , "Spatial query functions. <<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a91b64995742fd30063314f12340b4b5a">b</a>>Server side only!</<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a91b64995742fd30063314f12340b4b5a">b</a>>" )

ConsoleFunctionGroupEnd(Containers )

DefineEngineFunction(containerFindFirst , const char * , (U32 typeMask, Point3F origin, Point3F size) , "(int mask, <a href="/coding/class/classpoint3f/">Point3F</a> point, float x, float y, float z)" "@brief Find objects matching the bitmask type within <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> box centered at point, with extents x, y , <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">z.\n\n</a>" " @returns The first object found, or an empty string <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> nothing was found. Thereafter, you can get more " "results using containerFindNext()." " @see <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">containerFindNext\n</a>" " @ingroup Game" )

DefineEngineFunction(containerFindNext , const char * , () , "()" "@brief Get more results from <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> previous call <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> containerFindFirst().\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "@note You must call containerFindFirst() <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> begin the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">search.\n</a>" "@returns The next object found, or an empty string <a href="/coding/file/tsmeshintrinsics_8cpp/#tsmeshintrinsics_8cpp_1a4e4fa7e3399708e0777b5308db01278c">if</a> nothing else was <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">found.\n</a>" " @see containerFindFirst()\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n</a>" " @ingroup Game" )

DefineEngineFunction(setDefaultFov , void , (F32 defaultFOV) , "@brief Set the default FOV <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">camera.\n</a>" "@param defaultFOV The default field of view in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">degrees\n</a>" "@ingroup CameraSystem" )

DefineEngineFunction(setFov , void , (F32 FOV) , "@brief Set the FOV of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">camera.\n</a>" "@param FOV The camera's <a href="/coding/file/tmm__on_8h/#tmm__on_8h_1a1ac41480eb2e4aadd52252ee550b630a">new</a> FOV in <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">degrees\n</a>" "@ingroup CameraSystem" )

DefineEngineFunction(setZoomSpeed , void , (S32 speed) , "@brief Set the zoom speed of the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">camera.\n</a>" "This affects how quickly the camera changes from one field of view " "<a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">another.\n</a>" "@param speed The camera's zoom speed in ms per 90deg FOV <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">change\n</a>" "@ingroup CameraSystem" )

GameGetCameraFov()

Gets the camera field of view angle.

GameGetCameraTransform(MatrixF * mat, Point3F * velocity)

Gets the position, rotation, and velocity of the camera.

GameProcessCameraQuery(CameraQuery * query)

Does the same thing as GameGetCameraTransform, but fills in other data including information about the far and near clipping planes.

GameRenderWorld()

Actually renders the world.

This is the function that will render the scene ONLY - new guis, no damage flashes.

GameSetCameraFov(F32 fov)

Sets the field of view angle of the camera.

GameSetCameraTargetFov(F32 fov)

Sets where the camera fov will be change to.

This is for non-instantaneous zooms/retractions.

GameUpdateCameraFov()

Update the camera fov to be closer to the target fov.

notify(GameSetCameraFov )

Process3D()

RegisterGameFunctions()

renderFrame(GFXTextureTargetRef * target, MatrixF transform, Frustum frustum, U32 typeMask, ColorI canvasClearColor)

Does a full, top-to-bottom call to render a frame.

This does all the setup to make a render happen Allowing setting of a intended render target, a view transform, the view frustum, resolution, objects-to-render typemask, and the clear color

ShowInit()

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "platform/platform.h"
 25#include "T3D/gameFunctions.h"
 26#include "T3D/gameBase/gameConnection.h"
 27#include "T3D/camera.h"
 28#include "T3D/sfx/sfx3DWorld.h"
 29#include "console/consoleTypes.h"
 30#include "gui/3d/guiTSControl.h"
 31#include "core/util/journal/process.h"
 32#include "materials/materialManager.h"
 33#include "math/mEase.h"
 34#include "core/module.h"
 35#include "console/engineAPI.h"
 36#include "platform/output/IDisplayDevice.h"
 37#include "postFx/postEffectManager.h"
 38#include "gfx/gfxTransformSaver.h"
 39
 40static void RegisterGameFunctions();
 41static void Process3D();
 42
 43MODULE_BEGIN( 3D )
 44
 45   MODULE_INIT_AFTER( Process )
 46   MODULE_INIT_AFTER( Scene )
 47   
 48   MODULE_SHUTDOWN_BEFORE( Process )
 49   MODULE_SHUTDOWN_BEFORE( Sim )
 50   MODULE_SHUTDOWN_AFTER( Scene )
 51   
 52   MODULE_INIT
 53   {
 54      Process::notify(Process3D, PROCESS_TIME_ORDER);
 55
 56      GameConnection::smFovUpdate.notify(GameSetCameraFov);
 57
 58      RegisterGameFunctions();
 59   }
 60   
 61   MODULE_SHUTDOWN
 62   {
 63      GameConnection::smFovUpdate.remove(GameSetCameraFov);
 64
 65      Process::remove(Process3D);
 66   }
 67
 68MODULE_END;
 69
 70
 71static S32 gEaseInOut = Ease::InOut;
 72static S32 gEaseIn = Ease::In;
 73static S32 gEaseOut = Ease::Out;
 74
 75static S32 gEaseLinear = Ease::Linear;
 76static S32 gEaseQuadratic= Ease::Quadratic;
 77static S32 gEaseCubic= Ease::Cubic;
 78static S32 gEaseQuartic = Ease::Quartic;
 79static S32 gEaseQuintic = Ease::Quintic;
 80static S32 gEaseSinusoidal= Ease::Sinusoidal;
 81static S32 gEaseExponential = Ease::Exponential;
 82static S32 gEaseCircular = Ease::Circular;
 83static S32 gEaseElastic = Ease::Elastic;
 84static S32 gEaseBack = Ease::Back;
 85static S32 gEaseBounce = Ease::Bounce; 
 86
 87
 88extern bool gEditingMission;
 89
 90extern void ShowInit();
 91
 92//------------------------------------------------------------------------------
 93/// Camera and FOV info
 94namespace CameraAndFOV{
 95
 96   const  U32 MaxZoomSpeed             = 2000;     ///< max number of ms to reach target FOV
 97
 98   static F32 sConsoleCameraFov        = 90.f;     ///< updated to camera FOV each frame
 99   static F32 sDefaultFov              = 90.f;     ///< normal FOV
100   static F32 sCameraFov               = 90.f;     ///< current camera FOV
101   static F32 sTargetFov               = 90.f;     ///< the desired FOV
102   static F32 sLastCameraUpdateTime    = 0;        ///< last time camera was updated
103   static S32 sZoomSpeed               = 500;      ///< ms per 90deg fov change
104
105   /// A scale to apply to the normal visible distance
106   /// typically used for tuning performance.
107   static F32 sVisDistanceScale = 1.0f;
108
109} // namespace {}
110
111// query
112static SimpleQueryList sgServerQueryList;
113static U32 sgServerQueryIndex = 0;
114
115//SERVER FUNCTIONS ONLY
116ConsoleFunctionGroupBegin( Containers, "Spatial query functions. <b>Server side only!</b>");
117
118DefineEngineFunction( containerFindFirst, const char*, (U32 typeMask, Point3F origin, Point3F size), , "(int mask, Point3F point, float x, float y, float z)"
119   "@brief Find objects matching the bitmask type within a box centered at point, with extents x, y, z.\n\n"
120   "@returns The first object found, or an empty string if nothing was found.  Thereafter, you can get more "
121   "results using containerFindNext()."
122   "@see containerFindNext\n"
123   "@ingroup Game")
124{
125   //find out what we're looking for
126
127   //build the container volume
128   Box3F queryBox;
129   queryBox.minExtents = origin;
130   queryBox.maxExtents = origin;
131   queryBox.minExtents -= size;
132   queryBox.maxExtents += size;
133
134   //initialize the list, and do the query
135   sgServerQueryList.mList.clear();
136   gServerContainer.findObjects(queryBox, typeMask, SimpleQueryList::insertionCallback, &sgServerQueryList);
137
138   //return the first element
139   sgServerQueryIndex = 0;
140   static const U32 bufSize = 100;
141   char *buff = Con::getReturnBuffer(bufSize);
142   if (sgServerQueryList.mList.size())
143      dSprintf(buff, bufSize, "%d", sgServerQueryList.mList[sgServerQueryIndex++]->getId());
144   else
145      buff[0] = '\0';
146
147   return buff;
148}
149
150DefineEngineFunction( containerFindNext, const char*, (), , "()"
151   "@brief Get more results from a previous call to containerFindFirst().\n\n"
152   "@note You must call containerFindFirst() to begin the search.\n"
153   "@returns The next object found, or an empty string if nothing else was found.\n"
154   "@see containerFindFirst()\n"
155   "@ingroup Game")
156{
157   //return the next element
158   static const U32 bufSize = 100;
159   char *buff = Con::getReturnBuffer(bufSize);
160   if (sgServerQueryIndex < sgServerQueryList.mList.size())
161      dSprintf(buff, bufSize, "%d", sgServerQueryList.mList[sgServerQueryIndex++]->getId());
162   else
163      buff[0] = '\0';
164
165   return buff;
166}
167
168ConsoleFunctionGroupEnd( Containers );
169
170//------------------------------------------------------------------------------
171
172bool GameGetCameraTransform(MatrixF *mat, Point3F *velocity)
173{
174   // Return the position and velocity of the control object
175   GameConnection* connection = GameConnection::getConnectionToServer();
176   return connection && connection->getControlCameraTransform(0, mat) &&
177      connection->getControlCameraVelocity(velocity);
178}
179
180//------------------------------------------------------------------------------
181DefineEngineFunction( setDefaultFov, void, ( F32 defaultFOV ),,
182            "@brief Set the default FOV for a camera.\n"
183            "@param defaultFOV The default field of view in degrees\n"
184            "@ingroup CameraSystem")
185{
186   CameraAndFOV::sDefaultFov = mClampF(defaultFOV, MinCameraFov, MaxCameraFov);
187   if(CameraAndFOV::sCameraFov == CameraAndFOV::sTargetFov)
188      CameraAndFOV::sTargetFov = CameraAndFOV::sDefaultFov;
189}
190
191DefineEngineFunction( setZoomSpeed, void, ( S32 speed ),,
192            "@brief Set the zoom speed of the camera.\n"
193            "This affects how quickly the camera changes from one field of view "
194            "to another.\n"
195            "@param speed The camera's zoom speed in ms per 90deg FOV change\n"
196            "@ingroup CameraSystem")
197{
198   CameraAndFOV::sZoomSpeed = mClamp(speed, 0, CameraAndFOV::MaxZoomSpeed);
199}
200
201DefineEngineFunction( setFov, void, ( F32 FOV ),,
202            "@brief Set the FOV of the camera.\n"
203            "@param FOV The camera's new FOV in degrees\n"
204            "@ingroup CameraSystem")
205{
206   CameraAndFOV::sTargetFov = mClampF(FOV, MinCameraFov, MaxCameraFov);
207}
208
209F32 GameGetCameraFov()
210{
211   return(CameraAndFOV::sCameraFov);
212}
213
214void GameSetCameraFov(F32 fov)
215{
216   CameraAndFOV::sTargetFov = CameraAndFOV::sCameraFov = fov;
217}
218
219void GameSetCameraTargetFov(F32 fov)
220{
221   CameraAndFOV::sTargetFov = fov;
222}
223
224void GameUpdateCameraFov()
225{
226   F32 time = F32(Platform::getVirtualMilliseconds());
227
228   // need to update fov?
229   if(CameraAndFOV::sTargetFov != CameraAndFOV::sCameraFov)
230   {
231      F32 delta = time - CameraAndFOV::sLastCameraUpdateTime;
232
233      // snap zoom?
234      if((CameraAndFOV::sZoomSpeed == 0) || (delta <= 0.0f))
235         CameraAndFOV::sCameraFov = CameraAndFOV::sTargetFov;
236      else
237      {
238         // gZoomSpeed is time in ms to zoom 90deg
239         F32 step = 90.f * (delta / F32(CameraAndFOV::sZoomSpeed));
240
241         if(CameraAndFOV::sCameraFov > CameraAndFOV::sTargetFov)
242         {
243            CameraAndFOV::sCameraFov -= step;
244            if(CameraAndFOV::sCameraFov < CameraAndFOV::sTargetFov)
245               CameraAndFOV::sCameraFov = CameraAndFOV::sTargetFov;
246         }
247         else
248         {
249            CameraAndFOV::sCameraFov += step;
250            if(CameraAndFOV::sCameraFov > CameraAndFOV::sTargetFov)
251               CameraAndFOV::sCameraFov = CameraAndFOV::sTargetFov;
252         }
253      }
254   }
255
256   // the game connection controls the vertical and the horizontal
257   GameConnection * connection = GameConnection::getConnectionToServer();
258   if(connection)
259   {
260      // check if fov is valid on control object
261      if(connection->isValidControlCameraFov(CameraAndFOV::sCameraFov))
262         connection->setControlCameraFov(CameraAndFOV::sCameraFov);
263      else
264      {
265         // will set to the closest fov (fails only on invalid control object)
266         if(connection->setControlCameraFov(CameraAndFOV::sCameraFov))
267         {
268            F32 setFov = CameraAndFOV::sCameraFov;
269            connection->getControlCameraFov(&setFov);
270            CameraAndFOV::sTargetFov =CameraAndFOV::sCameraFov = setFov;
271         }
272      }
273   }
274
275   // update the console variable
276   CameraAndFOV::sConsoleCameraFov = CameraAndFOV::sCameraFov;
277   CameraAndFOV::sLastCameraUpdateTime = time;
278}
279//--------------------------------------------------------------------------
280
281#ifdef TORQUE_DEBUG
282// ConsoleFunction(dumpTSShapes, void, 1, 1, "dumpTSShapes();")
283// {
284//    argc, argv;
285
286//    FindMatch match("*.dts", 4096);
287//    gResourceManager->findMatches(&match);
288
289//    for (U32 i = 0; i < match.numMatches(); i++)
290//    {
291//       U32 j;
292//       Resource<TSShape> shape = ResourceManager::get().load(match.matchList[i]);
293//       if (bool(shape) == false)
294//          Con::errorf(" aaa Couldn't load: %s", match.matchList[i]);
295
296//       U32 numMeshes = 0, numSkins = 0;
297//       for (j = 0; j < shape->meshes.size(); j++)
298//          if (shape->meshes[j])
299//             numMeshes++;
300//       for (j = 0; j < shape->skins.size(); j++)
301//          if (shape->skins[j])
302//             numSkins++;
303
304//      Con::printf(" aaa Shape: %s (%d meshes, %d skins)", match.matchList[i], numMeshes, numSkins);
305//       Con::printf(" aaa   Meshes");
306//       for (j = 0; j < shape->meshes.size(); j++)
307//       {
308//          if (shape->meshes[j])
309//             Con::printf(" aaa     %d -> nf: %d, nmf: %d, nvpf: %d (%d, %d, %d, %d, %d)",
310//                         shape->meshes[j]->meshType & TSMesh::TypeMask,
311//                         shape->meshes[j]->numFrames,
312//                         shape->meshes[j]->numMatFrames,
313//                         shape->meshes[j]->vertsPerFrame,
314//                         shape->meshes[j]->verts.size(),
315//                         shape->meshes[j]->norms.size(),
316//                         shape->meshes[j]->tverts.size(),
317//                         shape->meshes[j]->primitives.size(),
318//                         shape->meshes[j]->indices.size());
319//       }
320//       Con::printf(" aaa   Skins");
321//       for (j = 0; j < shape->skins.size(); j++)
322//       {
323//          if (shape->skins[j])
324//             Con::printf(" aaa     %d -> nf: %d, nmf: %d, nvpf: %d (%d, %d, %d, %d, %d)",
325//                         shape->skins[j]->meshType & TSMesh::TypeMask,
326//                         shape->skins[j]->numFrames,
327//                         shape->skins[j]->numMatFrames,
328//                         shape->skins[j]->vertsPerFrame,
329//                         shape->skins[j]->verts.size(),
330//                         shape->skins[j]->norms.size(),
331//                         shape->skins[j]->tverts.size(),
332//                         shape->skins[j]->primitives.size(),
333//                         shape->skins[j]->indices.size());
334//       }
335//    }
336// }
337#endif
338
339bool GameProcessCameraQuery(CameraQuery *query)
340{
341   GameConnection* connection = GameConnection::getConnectionToServer();
342
343   if (connection && connection->getControlCameraTransform(0.032f, &query->cameraMatrix))
344   {
345      query->object = dynamic_cast<GameBase*>(connection->getCameraObject());
346      query->nearPlane = gClientSceneGraph->getNearClip();
347
348      // Scale the normal visible distance by the performance 
349      // tuning scale which we never let over 1.
350      CameraAndFOV::sVisDistanceScale = mClampF( CameraAndFOV::sVisDistanceScale, 0.01f, 1.0f );
351      query->farPlane = gClientSceneGraph->getVisibleDistance() * CameraAndFOV::sVisDistanceScale;
352
353      // Provide some default values
354      query->stereoTargets[0] = 0;
355      query->stereoTargets[1] = 0;
356      query->eyeOffset[0] = Point3F::Zero;
357      query->eyeOffset[1] = Point3F::Zero;
358      query->hasFovPort = false;
359      query->hasStereoTargets = false;
360      query->displayDevice = NULL;
361      
362      F32 cameraFov = 0.0f;
363      bool fovSet = false;
364
365      // Try to use the connection's display deivce, if any, but only if the editor
366      // is not open
367      if(!gEditingMission && connection->hasDisplayDevice())
368      {
369         IDisplayDevice* display = connection->getDisplayDevice();
370
371         query->displayDevice = display;
372
373         // Note: all eye values are invalid until this is called
374         display->setDrawCanvas(query->drawCanvas);
375
376         display->setCurrentConnection(connection);
377
378         // Display may activate AFTER so we need to call this again just in case
379         display->onStartFrame();
380
381         // The connection's display device may want to set the eye offset
382         if(display->providesEyeOffsets())
383         {
384            display->getEyeOffsets(query->eyeOffset);
385         }
386
387         // Grab field of view for both eyes
388         if (display->providesFovPorts())
389         {
390            display->getFovPorts(query->fovPort);
391            fovSet = true;
392            query->hasFovPort = true;
393         }
394         
395         // Grab the latest overriding render view transforms
396         connection->getControlCameraEyeTransforms(display, query->eyeTransforms);
397         connection->getControlCameraHeadTransform(display, &query->headMatrix);
398
399         display->getStereoViewports(query->stereoViewports);
400         display->getStereoTargets(query->stereoTargets);
401         query->hasStereoTargets = true;
402      }
403      else
404      {
405         query->eyeTransforms[0] = query->cameraMatrix;
406         query->eyeTransforms[1] = query->cameraMatrix;
407         query->headMatrix = query->cameraMatrix;
408      }
409
410      // Use the connection's FOV settings if requried
411      if(!connection->getControlCameraFov(&cameraFov))
412      {
413         return false;
414      }
415
416      query->fov = mDegToRad(cameraFov);
417      return true;
418   }
419   return false;
420}
421
422void GameRenderWorld()
423{
424   PROFILE_START(GameRenderWorld);
425   FrameAllocator::setWaterMark(0);
426
427   gClientSceneGraph->renderScene( SPT_Diffuse );
428
429   // renderScene leaves some states dirty, which causes problems if GameTSCtrl is the last Gui object rendered
430   GFX->updateStates();
431
432   AssertFatal(FrameAllocator::getWaterMark() == 0,
433      "Error, someone didn't reset the water mark on the frame allocator!");
434   FrameAllocator::setWaterMark(0);
435   PROFILE_END();
436}
437
438//================================================================================================
439//Render a full frame from a given transform and frustum, and render out to a target
440//================================================================================================
441void renderFrame(GFXTextureTargetRef* target, MatrixF transform, Frustum frustum, U32 typeMask, ColorI canvasClearColor)
442{
443   if (!GFX->allowRender() || GFX->canCurrentlyRender())
444      return;
445
446   PROFILE_START(GameFunctions_RenderFrame);
447
448   GFX->setActiveRenderTarget(*target);
449   if (!GFX->getActiveRenderTarget())
450      return;
451
452   GFXTarget* renderTarget = GFX->getActiveRenderTarget();
453   if (renderTarget == NULL)
454      return;
455
456   // Make sure the root control is the size of the canvas.
457   Point2I size = renderTarget->getSize();
458   if (size.x == 0 || size.y == 0)
459      return;
460
461   //Now, getting to the meat of it!
462#ifdef TORQUE_GFX_STATE_DEBUG
463   GFX->getDebugStateManager()->startFrame();
464#endif
465   RectI targetRect(0, 0, size.x, size.y);
466
467   // Signal the interested parties.
468   GuiCanvas::getGuiCanvasFrameSignal().trigger(true);
469
470   GFXTransformSaver saver;
471
472   // Gross hack to make sure we don't end up with advanced lighting and msaa 
473   // at the same time, which causes artifacts. At the same time we don't 
474   // want to just throw the settings the user has chosen if the light manager 
475   // changes at a later time.
476   /*GFXVideoMode mode = mPlatformWindow->getVideoMode();
477   if (dStricmp(LIGHTMGR->getId(), "ADVLM") == 0 && mode.antialiasLevel > 0)
478   {
479      const char *pref = Con::getVariable("$pref::Video::mode");
480      mode.parseFromString(pref);
481      mode.antialiasLevel = 0;
482      mPlatformWindow->setVideoMode(mode);
483
484      Con::printf("AntiAliasing has been disabled; it is not compatible with AdvancedLighting.");
485   }
486   else if (dStricmp(LIGHTMGR->getId(), "BLM") == 0)
487   {
488      const char *pref = Con::getVariable("$pref::Video::mode");
489
490      U32 prefAA = dAtoi(StringUnit::getUnit(pref, 5, " "));
491      if (prefAA != mode.antialiasLevel)
492      {
493         mode.parseFromString(pref);
494         mPlatformWindow->setVideoMode(mode);
495
496         Con::printf("AntiAliasing has been enabled while running BasicLighting.");
497      }
498   }*/
499
500   // Begin GFX
501   PROFILE_START(GameFunctions_RenderFrame_GFXBeginScene);
502   bool beginSceneRes = GFX->beginScene();
503   PROFILE_END();
504
505   PROFILE_START(GameFunctions_RenderFrame_OffscreenCanvases);
506
507   // Render all offscreen canvas objects here since we may need them in the render loop
508   if (GuiOffscreenCanvas::sList.size() != 0)
509   {
510      // Reset the entire state since oculus shit will have barfed it.
511      GFX->updateStates(true);
512
513      for (Vector<GuiOffscreenCanvas*>::iterator itr = GuiOffscreenCanvas::sList.begin(); itr != GuiOffscreenCanvas::sList.end(); itr++)
514      {
515         (*itr)->renderFrame(false, false);
516      }
517
518      GFX->setActiveRenderTarget(renderTarget);
519   }
520
521   PROFILE_END();
522
523   // Can't render if waiting for device to reset.   
524   if (!beginSceneRes)
525   {
526      // Since we already triggered the signal once for begin-of-frame,
527      // we should be consistent and trigger it again for end-of-frame.
528      GuiCanvas::getGuiCanvasFrameSignal().trigger(false);
529
530      return;
531   }
532
533   // Clear the current viewport area
534   GFX->setViewport(targetRect);
535   GFX->clear(GFXClearZBuffer | GFXClearStencil | GFXClearTarget, canvasClearColor, 1.0f, 0);
536
537   // Make sure we have a clean matrix state 
538   // before we start rendering anything!   
539   GFX->setWorldMatrix(MatrixF::Identity);
540   GFX->setViewMatrix(MatrixF::Identity);
541   GFX->setProjectionMatrix(MatrixF::Identity);
542
543   {
544      GFXStateBlockDesc d;
545
546      d.cullDefined = true;
547      d.cullMode = GFXCullNone;
548      d.zDefined = true;
549      d.zEnable = false;
550
551      GFXStateBlockRef mDefaultGuiSB = GFX->createStateBlock(d);
552
553      GFX->setClipRect(targetRect);
554      GFX->setStateBlock(mDefaultGuiSB);
555
556      GFXTargetRef origTarget = GFX->getActiveRenderTarget();
557
558      // Clear the zBuffer so GUI doesn't hose object rendering accidentally
559      GFX->clear(GFXClearZBuffer, ColorI(20, 20, 20), 1.0f, 0);
560
561      GFX->setFrustum(frustum);
562      MatrixF mSaveProjection = GFX->getProjectionMatrix();
563      
564      // We're going to be displaying this render at size of this control in
565      // pixels - let the scene know so that it can calculate e.g. reflections
566      // correctly for that final display result.
567      gClientSceneGraph->setDisplayTargetResolution(size);
568
569      // Set the GFX world matrix to the world-to-camera transform, but don't 
570      // change the cameraMatrix in mLastCameraQuery. This is because 
571      // mLastCameraQuery.cameraMatrix is supposed to contain the camera-to-world
572      // transform. In-place invert would save a copy but mess up any GUIs that
573      // depend on that value.
574      CameraQuery camera;
575      GameProcessCameraQuery(&camera);
576
577      MatrixF worldToCamera = transform;
578
579      RotationF tranRot = RotationF(transform);
580      EulerF trf = tranRot.asEulerF(RotationF::Degrees);
581      Point3F pos = transform.getPosition();
582
583      GFX->setWorldMatrix(worldToCamera);
584
585      mSaveProjection = GFX->getProjectionMatrix();
586      MatrixF mSaveModelview = GFX->getWorldMatrix();
587
588      Point2F mSaveWorldToScreenScale = GFX->getWorldToScreenScale();
589      Frustum mSaveFrustum = GFX->getFrustum();
590      mSaveFrustum.setTransform(transform);
591
592      // Set the default non-clip projection as some 
593      // objects depend on this even in non-reflect cases.
594      gClientSceneGraph->setNonClipProjection(mSaveProjection);
595
596      // Give the post effect manager the worldToCamera, and cameraToScreen matrices
597      PFXMGR->setFrameMatrices(mSaveModelview, mSaveProjection);
598
599      //renderWorld(guiViewport);
600      PROFILE_START(GameFunctions_RenderFrame_RenderWorld);
601      FrameAllocator::setWaterMark(0);
602
603      gClientSceneGraph->renderScene(SPT_Reflect, typeMask);
604
605      // renderScene leaves some states dirty, which causes problems if GameTSCtrl is the last Gui object rendered
606      GFX->updateStates();
607
608      AssertFatal(FrameAllocator::getWaterMark() == 0,
609         "Error, someone didn't reset the water mark on the frame allocator!");
610      FrameAllocator::setWaterMark(0);
611      PROFILE_END();
612   }
613
614   PROFILE_START(GameFunctions_RenderFrame_GFXEndScene);
615   GFX->endScene();
616   PROFILE_END();
617
618#ifdef TORQUE_GFX_STATE_DEBUG
619   GFX->getDebugStateManager()->endFrame();
620#endif
621
622   saver.restore();
623
624   PROFILE_END();
625}
626
627//================================================================================================
628static void Process3D()
629{
630   MATMGR->updateTime();
631   
632   // Update the SFX world, if there is one.
633   
634   if( gSFX3DWorld )
635      gSFX3DWorld->update();
636}
637
638static void RegisterGameFunctions()
639{
640   Con::addVariable( "$pref::Camera::distanceScale", TypeF32, &CameraAndFOV::sVisDistanceScale, 
641      "A scale to apply to the normal visible distance, typically used for tuning performance.\n"
642      "@ingroup Game");
643   Con::addVariable( "$cameraFov", TypeF32, &CameraAndFOV::sConsoleCameraFov, 
644      "The camera's Field of View.\n\n"
645      "@ingroup Game" );
646
647   // Stuff game types into the console
648   Con::setIntVariable("$TypeMasks::StaticObjectType",         StaticObjectType);
649   Con::setIntVariable("$TypeMasks::EnvironmentObjectType",    EnvironmentObjectType);
650   Con::setIntVariable("$TypeMasks::TerrainObjectType",        TerrainObjectType);
651   Con::setIntVariable("$TypeMasks::WaterObjectType",          WaterObjectType);
652   Con::setIntVariable("$TypeMasks::TriggerObjectType",        TriggerObjectType);
653   Con::setIntVariable("$TypeMasks::MarkerObjectType",         MarkerObjectType);
654   Con::setIntVariable("$TypeMasks::GameBaseObjectType",       GameBaseObjectType);
655   Con::setIntVariable("$TypeMasks::ShapeBaseObjectType",      ShapeBaseObjectType);
656   Con::setIntVariable("$TypeMasks::CameraObjectType",         CameraObjectType);
657   Con::setIntVariable("$TypeMasks::StaticShapeObjectType",    StaticShapeObjectType);
658   Con::setIntVariable("$TypeMasks::DynamicShapeObjectType",   DynamicShapeObjectType);
659   Con::setIntVariable("$TypeMasks::PlayerObjectType",         PlayerObjectType);
660   Con::setIntVariable("$TypeMasks::ItemObjectType",           ItemObjectType);
661   Con::setIntVariable("$TypeMasks::VehicleObjectType",        VehicleObjectType);
662   Con::setIntVariable("$TypeMasks::VehicleBlockerObjectType", VehicleBlockerObjectType);
663   Con::setIntVariable("$TypeMasks::ProjectileObjectType",     ProjectileObjectType);
664   Con::setIntVariable("$TypeMasks::ExplosionObjectType",      ExplosionObjectType);
665   Con::setIntVariable("$TypeMasks::CorpseObjectType",         CorpseObjectType);
666   Con::setIntVariable("$TypeMasks::DebrisObjectType",         DebrisObjectType);
667   Con::setIntVariable("$TypeMasks::PhysicalZoneObjectType",   PhysicalZoneObjectType);
668   Con::setIntVariable("$TypeMasks::LightObjectType",          LightObjectType);
669// PATHSHAPE
670   Con::setIntVariable("$TypeMasks::PathShapeObjectType",     PathShapeObjectType);
671// PATHSHAPE END
672
673   Con::addVariable("Ease::InOut", TypeS32, &gEaseInOut, 
674      "InOut ease for curve movement.\n"
675      "@ingroup Game");
676   Con::addVariable("Ease::In", TypeS32, &gEaseIn, 
677      "In ease for curve movement.\n"
678      "@ingroup Game");
679   Con::addVariable("Ease::Out", TypeS32, &gEaseOut, 
680      "Out ease for curve movement.\n"
681      "@ingroup Game");
682
683   Con::addVariable("Ease::Linear", TypeS32, &gEaseLinear, 
684      "Linear ease for curve movement.\n"
685      "@ingroup Game");
686   Con::addVariable("Ease::Quadratic", TypeS32, &gEaseQuadratic, 
687      "Quadratic ease for curve movement.\n"
688      "@ingroup Game");
689   Con::addVariable("Ease::Cubic", TypeS32, &gEaseCubic, 
690      "Cubic ease for curve movement.\n"
691      "@ingroup Game");
692   Con::addVariable("Ease::Quartic", TypeS32, &gEaseQuartic, 
693      "Quartic ease for curve movement.\n"
694      "@ingroup Game");
695   Con::addVariable("Ease::Quintic", TypeS32, &gEaseQuintic, 
696      "Quintic ease for curve movement.\n"
697      "@ingroup Game");
698   Con::addVariable("Ease::Sinusoidal", TypeS32, &gEaseSinusoidal, 
699      "Sinusoidal ease for curve movement.\n"
700      "@ingroup Game");
701   Con::addVariable("Ease::Exponential", TypeS32, &gEaseExponential, 
702      "Exponential ease for curve movement.\n"
703      "@ingroup Game");
704   Con::addVariable("Ease::Circular", TypeS32, &gEaseCircular, 
705      "Circular ease for curve movement.\n"
706      "@ingroup Game");
707   Con::addVariable("Ease::Elastic", TypeS32, &gEaseElastic, 
708      "Elastic ease for curve movement.\n"
709      "@ingroup Game");
710   Con::addVariable("Ease::Back", TypeS32, &gEaseBack, 
711      "Backwards ease for curve movement.\n"
712      "@ingroup Game");
713   Con::addVariable("Ease::Bounce", TypeS32, &gEaseBounce, 
714      "Bounce ease for curve movement.\n"
715      "@ingroup Game");
716}
717