ScriptEvent.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Scene/Events/Event.h>
  7. #include <AnKi/Resource/Forward.h>
  8. #include <AnKi/Script/ScriptEnvironment.h>
  9. namespace anki
  10. {
  11. /// @addtogroup scene
  12. /// @{
  13. /// A generic event that uses scripts. The script should contain something like this:
  14. /// @code
  15. /// function update(event, prevTime, crntTime)
  16. /// -- Do something
  17. /// return 1
  18. /// end
  19. ///
  20. /// function onKilled(event, prevTime, crntTime)
  21. /// -- Do something
  22. /// return 1
  23. /// end
  24. /// @endcode
  25. class ScriptEvent : public Event
  26. {
  27. public:
  28. ScriptEvent(EventManager* manager);
  29. ~ScriptEvent();
  30. /// @param script It's a script or a filename to a script.
  31. ANKI_USE_RESULT Error init(Second startTime, Second duration, CString script);
  32. ANKI_USE_RESULT Error update(Second prevUpdateTime, Second crntTime) override;
  33. ANKI_USE_RESULT Error onKilled(Second prevUpdateTime, Second crntTime) override;
  34. private:
  35. ScriptResourcePtr m_scriptRsrc;
  36. String m_script;
  37. ScriptEnvironment m_env;
  38. };
  39. /// @}
  40. } // end namespace anki