ScriptEvent.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. /// @addtogroup scene
  11. /// @{
  12. /// A generic event that uses scripts. The script should contain something like this:
  13. /// @code
  14. /// function update(event, prevTime, crntTime)
  15. /// -- Do something
  16. /// return 1
  17. /// end
  18. ///
  19. /// function onKilled(event, prevTime, crntTime)
  20. /// -- Do something
  21. /// return 1
  22. /// end
  23. /// @endcode
  24. class ScriptEvent : public Event
  25. {
  26. public:
  27. ScriptEvent(EventManager* manager);
  28. ~ScriptEvent();
  29. /// @param script It's a script or a filename to a script.
  30. ANKI_USE_RESULT Error init(Second startTime, Second duration, CString script);
  31. ANKI_USE_RESULT Error update(Second prevUpdateTime, Second crntTime) override;
  32. ANKI_USE_RESULT Error onKilled(Second prevUpdateTime, Second crntTime) override;
  33. private:
  34. ScriptResourcePtr m_scriptRsrc;
  35. String m_script;
  36. ScriptEnvironment m_env;
  37. };
  38. /// @}
  39. } // end namespace anki