BVB Source Codes

CRYENGINE Show ScriptBind_ActorSystem.cpp Source code

Return Download CRYENGINE: download ScriptBind_ActorSystem.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.  
  8.    -------------------------------------------------------------------------
  9.    History:
  10.    - 21:9:2004   3:00 : Created by Mathieu Pinard
  11.  
  12. *************************************************************************/
  13. #include "StdAfx.h"
  14. #include "ActorSystem.h"
  15. #include <CryGame/IGameFramework.h>
  16. #include "ScriptBind_ActorSystem.h"
  17.  
  18. //------------------------------------------------------------------------
  19. CScriptBind_ActorSystem::CScriptBind_ActorSystem(ISystem* pSystem, IGameFramework* pGameFW)
  20. {
  21.         m_pSystem = pSystem;
  22.         //m_pActorSystem = pActorSystem;
  23.         m_pGameFW = pGameFW;
  24.  
  25.         Init(pSystem->GetIScriptSystem(), m_pSystem);
  26.         SetGlobalName("Actor");
  27.  
  28.         RegisterGlobals();
  29.         RegisterMethods();
  30. }
  31.  
  32. //------------------------------------------------------------------------
  33. CScriptBind_ActorSystem::~CScriptBind_ActorSystem()
  34. {
  35. }
  36.  
  37. //------------------------------------------------------------------------
  38. void CScriptBind_ActorSystem::RegisterGlobals()
  39. {
  40. }
  41.  
  42. //------------------------------------------------------------------------
  43. void CScriptBind_ActorSystem::RegisterMethods()
  44. {
  45. #undef SCRIPT_REG_CLASSNAME
  46. #define SCRIPT_REG_CLASSNAME &CScriptBind_ActorSystem::
  47.  
  48.         SCRIPT_REG_TEMPLFUNC(CreateActor, "channelId, actorParams");
  49. }
  50.  
  51. //------------------------------------------------------------------------
  52. // Example on how to use this function:
  53. //
  54. // local params =
  55. // {
  56. //   name     = "dude",
  57. //   class    = "CSpectator",
  58. //   position = {x=0, y=0, z=0},
  59. //   rotation = {x=0, y=0, z=0},
  60. //   scale    = {x=1, y=1, z=1}
  61. // }
  62. //
  63. // Actor.CreateActor( channelId, params );
  64. //
  65. int CScriptBind_ActorSystem::CreateActor(IFunctionHandler* pH, int channelId, SmartScriptTable actorParams)
  66. {
  67.         CRY_ASSERT(m_pGameFW->GetIActorSystem() != NULL);
  68.         const char* name;
  69.         const char* className;
  70.         Vec3 position;
  71.         Vec3 scale;
  72.         Vec3 rotation;
  73.  
  74. #define GET_VALUE_FROM_CHAIN(valName, val, chain)                                                                       \
  75.   if (!chain.GetValue(valName, val))                                                                                    \
  76.   {                                                                                                                     \
  77.     CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "CreateActor failed because <%s> field not specified", valName); \
  78.     bFailed = true;                                                                                                     \
  79.   }
  80.  
  81.         // The following code had to be enclosed in a bracket because
  82.         // CScriptSetGetChain needs to be declared statically and also needs to
  83.         // be destructed before EndFunction
  84.         bool bFailed = false;
  85.         do
  86.         {
  87.                 CScriptSetGetChain actorChain(actorParams);
  88.                 GET_VALUE_FROM_CHAIN("name", name, actorChain);
  89.                 GET_VALUE_FROM_CHAIN("class", className, actorChain);
  90.                 GET_VALUE_FROM_CHAIN("position", position, actorChain);
  91.                 GET_VALUE_FROM_CHAIN("rotation", rotation, actorChain);
  92.                 GET_VALUE_FROM_CHAIN("scale", scale, actorChain);
  93.         }
  94.         while (false);
  95.  
  96.         if (bFailed)
  97.                 return pH->EndFunction(false);
  98.  
  99.         Quat q;
  100.         q.SetRotationXYZ(Ang3(rotation));
  101.         IActor* pActor = m_pGameFW->GetIActorSystem()->CreateActor(channelId, name, className, position, q, scale);
  102.  
  103.         if (pActor == NULL)
  104.                 return pH->EndFunction();
  105.         else
  106.                 return pH->EndFunction(pActor->GetEntity()->GetScriptTable());
  107. }
  108.  
downloadScriptBind_ActorSystem.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top