1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsPrerequisites.h" |
6 | #include "Utility/BsModule.h" |
7 | |
8 | namespace bs |
9 | { |
10 | /** @addtogroup Script-Internal |
11 | * @{ |
12 | */ |
13 | |
14 | /** Abstraction that handles a specific set of script libraries. */ |
15 | class BS_EXPORT ScriptLibrary |
16 | { |
17 | public: |
18 | virtual ~ScriptLibrary() = default; |
19 | |
20 | /** Called when the script system is being activated. */ |
21 | virtual void initialize() = 0; |
22 | |
23 | /** Called once per frame. */ |
24 | virtual void update() { } |
25 | |
26 | /** Called when the script libraries should be reloaded (for example when they are recompiled). */ |
27 | virtual void reload() = 0; |
28 | |
29 | /** Called when the script system is being destroyed. */ |
30 | virtual void destroy() = 0; |
31 | }; |
32 | |
33 | /** Handles initialization of a scripting system. */ |
34 | class BS_EXPORT ScriptManager : public Module<ScriptManager> |
35 | { |
36 | public: |
37 | ScriptManager(); |
38 | ~ScriptManager(); |
39 | |
40 | /** Called once per frame. */ |
41 | void update(); |
42 | |
43 | /** |
44 | * Reloads any scripts in the currently active library. Should be called after some change to the scripts was made |
45 | * (for example project was changed, or scripts were recompiled). |
46 | */ |
47 | void reload(); |
48 | |
49 | /** |
50 | * Sets the active script library that controls what kind and which scripts are loaded. Must be called before |
51 | * the module is started up. |
52 | */ |
53 | static void _setScriptLibrary(const SPtr<ScriptLibrary>& library) { sScriptLibrary = library; } |
54 | |
55 | /** Returns the currently assigned script library. */ |
56 | static const SPtr<ScriptLibrary>& _getScriptLibrary() { return sScriptLibrary; } |
57 | |
58 | private: |
59 | static SPtr<ScriptLibrary> sScriptLibrary; |
60 | }; |
61 | |
62 | /** @} */ |
63 | } |