simEvent.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SIM_EVENT_H_
  23. #define _SIM_EVENT_H_
  24. #ifndef _PLATFORM_H_
  25. #include "platform/platform.h"
  26. #endif
  27. //---------------------------------------------------------------------------
  28. class SimObject;
  29. typedef U32 SimTime;
  30. //---------------------------------------------------------------------------
  31. /// Represents a queued event in the sim.
  32. ///
  33. /// Sim provides an event queue for your convenience, which
  34. /// can be used to schedule events. A few things which use
  35. /// this event queue:
  36. ///
  37. /// - The scene lighting system. In order to keep the game
  38. /// responsive while scene lighting occurs, the lighting
  39. /// process is divided into little chunks. In implementation
  40. /// terms, there is a subclass of SimEvent called
  41. /// SceneLightingProcessEvent. The process method of this
  42. /// subclass calls into the lighting code, telling it to
  43. /// perform the next chunk of lighting calculations.
  44. /// - The schedule() console function uses a subclass of
  45. /// SimEvent called SimConsoleEvent to keep track of
  46. /// scheduled events.
  47. class SimEvent
  48. {
  49. public:
  50. SimEvent *nextEvent; ///< Linked list details - pointer to next item in the list.
  51. SimTime startTime; ///< When the event was posted.
  52. SimTime time; ///< When the event is scheduled to occur.
  53. U32 sequenceCount; ///< Unique ID. These are assigned sequentially based on order
  54. /// of addition to the list.
  55. SimObject *destObject; ///< Object on which this event will be applied.
  56. SimEvent() { destObject = NULL; }
  57. virtual ~SimEvent() {} ///< Destructor
  58. ///
  59. /// A dummy virtual destructor is required
  60. /// so that subclasses can be deleted properly
  61. /// Function called when event occurs.
  62. ///
  63. /// This is where the meat of your event's implementation goes.
  64. ///
  65. /// See any of the subclasses for ideas of what goes in here.
  66. ///
  67. /// The event is deleted immediately after processing. If the
  68. /// object referenced in destObject is deleted, then the event
  69. /// is not called. The even will be executed unconditionally if
  70. /// the object referenced is NULL.
  71. ///
  72. /// @param object Object stored in destObject.
  73. virtual void process(SimObject *object)=0;
  74. };
  75. #endif // _SIM_EVENT_H_