BaseScriptComponent.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. //========================================================================
  3. // BaseScriptComponent.h - Component for exposing actors to Lua
  4. //
  5. // Part of the GameCode4 Application
  6. //
  7. // GameCode4 is the sample application that encapsulates much of the source code
  8. // discussed in "Game Coding Complete - 4th Edition" by Mike McShaffry and David
  9. // "Rez" Graham, published by Charles River Media.
  10. // ISBN-10: 1133776574 | ISBN-13: 978-1133776574
  11. //
  12. // If this source code has found it's way to you, and you think it has helped you
  13. // in any way, do the authors a favor and buy a new copy of the book - there are
  14. // detailed explanations in it that compliment this code well. Buy a copy at Amazon.com
  15. // by clicking here:
  16. // http://www.amazon.com/gp/product/1133776574/ref=olp_product_details?ie=UTF8&me=&seller=
  17. //
  18. // There's a companion web site at http://www.mcshaffry.com/GameCode/
  19. //
  20. // The source code is managed and maintained through Google Code:
  21. // http://code.google.com/p/gamecode4/
  22. //
  23. // (c) Copyright 2012 Michael L. McShaffry and David Graham
  24. //
  25. // This program is free software; you can redistribute it and/or
  26. // modify it under the terms of the GNU Lesser GPL v3
  27. // as published by the Free Software Foundation.
  28. //
  29. // This program is distributed in the hope that it will be useful,
  30. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  31. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  32. // http://www.gnu.org/licenses/lgpl-3.0.txt for more details.
  33. //
  34. // You should have received a copy of the GNU Lesser GPL v3
  35. // along with this program; if not, write to the Free Software
  36. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  37. //
  38. //========================================================================
  39. #include"ScriptComponentInterface.h"
  40. #include <sol/sol.hpp>
  41. //---------------------------------------------------------------------------------------------------------------------
  42. // BaseScriptComponent class
  43. // Chapter 12, page 337
  44. //---------------------------------------------------------------------------------------------------------------------
  45. class BaseScriptComponent : public ScriptComponentInterface
  46. {
  47. std::string m_scriptObjectName;
  48. std::string m_constructorName;
  49. std::string m_destructorName;
  50. sol::object m_scriptObject;
  51. sol::protected_function m_scriptConstructor;
  52. sol::function m_scriptDestructor;
  53. public:
  54. static const char* g_Name;
  55. virtual const char* VGetName() const { return g_Name; }
  56. BaseScriptComponent(void);
  57. ~BaseScriptComponent(void);
  58. virtual bool VInit(TiXmlElement* pData);
  59. virtual void VPostInit(void);
  60. virtual TiXmlElement* VGenerateXml(void);
  61. static void RegisterScriptFunctions(void);
  62. private:
  63. void CreateScriptObject(void);
  64. // component script functions
  65. ActorId GetActorId(void);
  66. };