HumanView.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. //========================================================================
  3. // HumanView.h : Defines the HumanView class of the GameCode4 application
  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 "../GameCode4/interfaces.h"
  40. #include "../EventManager/Events.h"
  41. #include "../Graphics3D/SceneNodes.h"
  42. #include "../Graphics3D/MovementController.h"
  43. #include "UserInterface.h"
  44. //
  45. // class HumanView - Chapter 10, page 272
  46. //
  47. // This is a view onto the game - which includes anything visual or audible.
  48. // It gets messages about the changes in game state.
  49. //
  50. class HumanView : public IGameView
  51. {
  52. friend class GameCodeApp;
  53. protected:
  54. GameViewId m_ViewId;
  55. ActorId m_ActorId;
  56. uint64_t m_currTick; // time right now
  57. uint64_t m_lastDraw; // last time the game rendered
  58. bool m_runFullSpeed; // set to true if you want to run full speed
  59. BaseGameState m_BaseGameState; // Added post-press - what is the current game state
  60. virtual void VRenderText() { };
  61. public:
  62. bool LoadGame(TiXmlElement* pLevelData);
  63. protected:
  64. virtual bool VLoadGameDelegate(TiXmlElement* pLevelData) { VPushElement(m_pScene); return true; }
  65. public:
  66. // Implement the IGameView interface, except for the VOnRender() method, which is renderer specific
  67. virtual int VOnRestore();
  68. // virtual HRESULT VOnLostDevice();
  69. virtual void VOnRender(double fTime, float fElapsedTime);
  70. virtual GameViewType VGetType() { return GameView_Human; }
  71. virtual GameViewId VGetId() const { return m_ViewId; }
  72. virtual void VOnAttach(GameViewId vid, ActorId aid)
  73. {
  74. m_ViewId = vid;
  75. m_ActorId = aid;
  76. }
  77. virtual int VOnMsgProc( SDL_Event &e );
  78. virtual void VOnUpdate(const int deltaMilliseconds );
  79. // Virtual methods to control the layering of interface elements
  80. virtual void VPushElement(std::shared_ptr<IScreenElement> pElement);
  81. virtual void VRemoveElement(std::shared_ptr<IScreenElement> pElement);
  82. virtual ~HumanView();
  83. HumanView(std::shared_ptr<IRenderer> renderer);
  84. ScreenElementList m_ScreenElements; // a game screen entity
  85. // Interface sensitive objects
  86. std::shared_ptr<IPointerHandler> m_PointerHandler;
  87. int m_PointerRadius;
  88. std::shared_ptr<IKeyboardHandler> m_KeyboardHandler;
  89. // Added post press
  90. std::shared_ptr<ScreenElementScene> m_pScene;
  91. std::shared_ptr<CameraNode> m_pCamera;
  92. // Added post press - this helps the network system attach views to the right actor.
  93. virtual void VSetControlledActor(ActorId actorId) { m_ActorId = actorId; }
  94. // Event delegates
  95. void PlaySoundDelegate(IEventDataPtr pEventData);
  96. void GameStateDelegate(IEventDataPtr pEventData);
  97. private:
  98. void RegisterAllDelegates(void);
  99. void RemoveAllDelegates(void);
  100. };