]> git.lizzy.rs Git - dragonfireclient.git/blob - src/script/scripting_mainmenu.cpp
d79864a9544330ad53383203098d7b86d791efc9
[dragonfireclient.git] / src / script / scripting_mainmenu.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "scripting_mainmenu.h"
21 #include "mods.h"
22 #include "cpp_api/s_internal.h"
23 #include "lua_api/l_base.h"
24 #include "lua_api/l_mainmenu.h"
25 #include "lua_api/l_sound.h"
26 #include "lua_api/l_util.h"
27 #include "lua_api/l_settings.h"
28
29 extern "C" {
30 #include "lualib.h"
31 }
32
33 #define MAINMENU_NUM_ASYNC_THREADS 4
34
35
36 MainMenuScripting::MainMenuScripting(GUIEngine* guiengine)
37 {
38         setGuiEngine(guiengine);
39
40         SCRIPTAPI_PRECHECKHEADER
41
42         lua_getglobal(L, "core");
43         int top = lua_gettop(L);
44
45         lua_newtable(L);
46         lua_setglobal(L, "gamedata");
47
48         // Initialize our lua_api modules
49         initializeModApi(L, top);
50         lua_pop(L, 1);
51
52         // Push builtin initialization type
53         lua_pushstring(L, "mainmenu");
54         lua_setglobal(L, "INIT");
55
56         infostream << "SCRIPTAPI: Initialized main menu modules" << std::endl;
57 }
58
59 /******************************************************************************/
60 void MainMenuScripting::initializeModApi(lua_State *L, int top)
61 {
62         // Initialize mod API modules
63         ModApiMainMenu::Initialize(L, top);
64         ModApiUtil::Initialize(L, top);
65         ModApiSound::Initialize(L, top);
66
67         // Register reference classes (userdata)
68         LuaSettings::Register(L);
69
70         // Register functions to async environment
71         ModApiMainMenu::InitializeAsync(asyncEngine);
72         ModApiUtil::InitializeAsync(asyncEngine);
73
74         // Initialize async environment
75         //TODO possibly make number of async threads configurable
76         asyncEngine.initialize(MAINMENU_NUM_ASYNC_THREADS);
77 }
78
79 /******************************************************************************/
80 void MainMenuScripting::step()
81 {
82         asyncEngine.step(getStack());
83 }
84
85 /******************************************************************************/
86 unsigned int MainMenuScripting::queueAsync(const std::string &serialized_func,
87                 const std::string &serialized_param)
88 {
89         return asyncEngine.queueAsyncJob(serialized_func, serialized_param);
90 }
91