/src/
- ../
- CMakeLists.txt
- activeobject.h
- ban.cpp
- ban.h
- camera.cpp
- camera.h
- cavegen.cpp
- cavegen.h
- cguittfont
- chat.cpp
- chat.h
- chat_interface.h
- client.cpp
- client.h
- client
- clientiface.cpp
- clientiface.h
- clientmap.cpp
- clientmap.h
- clientmedia.cpp
- clientmedia.h
- clientobject.cpp
- clientobject.h
- clientsimpleobject.h
- clouds.cpp
- clouds.h
- cmake_config.h.in
- cmake_config_githash.h.in
- collision.cpp
- collision.h
- config.h
- constants.h
- content_abm.cpp
- content_abm.h
- content_cao.cpp
- content_cao.h
- content_cso.cpp
- content_cso.h
- content_mapblock.cpp
- content_mapblock.h
- content_mapnode.cpp
- content_mapnode.h
- content_nodemeta.cpp
- content_nodemeta.h
- content_sao.cpp
- content_sao.h
- convert_json.cpp
- convert_json.h
- craftdef.cpp
- craftdef.h
- database-dummy.cpp
- database-dummy.h
- database-leveldb.cpp
- database-leveldb.h
- database-postgresql.cpp
- database-postgresql.h
- database-redis.cpp
- database-redis.h
- database-sqlite3.cpp
- database-sqlite3.h
- database.cpp
- database.h
- daynightratio.h
- debug.cpp
- debug.h
- defaultsettings.cpp
- defaultsettings.h
- drawscene.cpp
- drawscene.h
- dungeongen.cpp
- dungeongen.h
- emerge.cpp
- emerge.h
- environment.cpp
- environment.h
- event.h
- event_manager.h
- exceptions.h
- filecache.cpp
- filecache.h
- filesys.cpp
- filesys.h
- fontengine.cpp
- fontengine.h
- game.cpp
- game.h
- gamedef.h
- gameparams.h
- genericobject.cpp
- genericobject.h
- gettext.cpp
- gettext.h
- gettime.h
- gmp
- guiChatConsole.cpp
- guiChatConsole.h
- guiEngine.cpp
- guiEngine.h
- guiFileSelectMenu.cpp
- guiFileSelectMenu.h
- guiFormSpecMenu.cpp
- guiFormSpecMenu.h
- guiKeyChangeMenu.cpp
- guiKeyChangeMenu.h
- guiMainMenu.h
- guiPasswordChange.cpp
- guiPasswordChange.h
- guiTable.cpp
- guiTable.h
- guiVolumeChange.cpp
- guiVolumeChange.h
- guiscalingfilter.cpp
- guiscalingfilter.h
- httpfetch.cpp
- httpfetch.h
- hud.cpp
- hud.h
- imagefilters.cpp
- imagefilters.h
- intlGUIEditBox.cpp
- intlGUIEditBox.h
- inventory.cpp
- inventory.h
- inventorymanager.cpp
- inventorymanager.h
- irr_aabb3d.h
- irr_v2d.h
- irr_v3d.h
- irrlicht_changes
- irrlichttypes.h
- irrlichttypes_bloated.h
- irrlichttypes_extrabloated.h
- itemdef.cpp
- itemdef.h
- itemgroup.h
- jsoncpp
- keycode.cpp
- keycode.h
- light.cpp
- light.h
- localplayer.cpp
- localplayer.h
- log.cpp
- log.h
- lua
- main.cpp
- mainmenumanager.h
- map.cpp
- map.h
- map_settings_manager.cpp
- map_settings_manager.h
- mapblock.cpp
- mapblock.h
- mapblock_mesh.cpp
- mapblock_mesh.h
- mapgen.cpp
- mapgen.h
- mapgen_flat.cpp
- mapgen_flat.h
- mapgen_fractal.cpp
- mapgen_fractal.h
- mapgen_singlenode.cpp
- mapgen_singlenode.h
- mapgen_v5.cpp
- mapgen_v5.h
- mapgen_v6.cpp
- mapgen_v6.h
- mapgen_v7.cpp
- mapgen_v7.h
- mapgen_valleys.cpp
- mapgen_valleys.h
- mapnode.cpp
- mapnode.h
- mapsector.cpp
- mapsector.h
- mesh.cpp
- mesh.h
- mg_biome.cpp
- mg_biome.h
- mg_decoration.cpp
- mg_decoration.h
- mg_ore.cpp
- mg_ore.h
- mg_schematic.cpp
LuaJobInfo retval;
retval.valid = false;
if (!jobQueue.empty()) {
retval = jobQueue.front();
jobQueue.pop_front();
retval.valid = true;
}
jobQueueMutex.Unlock();
return retval;
}
/******************************************************************************/
void AsyncEngine::putJobResult(LuaJobInfo result)
{
resultQueueMutex.Lock();
resultQueue.push_back(result);
resultQueueMutex.Unlock();
}
/******************************************************************************/
void AsyncEngine::step(lua_State *L, int errorhandler)
{
lua_getglobal(L, "core");
resultQueueMutex.Lock();
while (!resultQueue.empty()) {
LuaJobInfo jobDone = resultQueue.front();
resultQueue.pop_front();
lua_getfield(L, -1, "async_event_handler");
if (lua_isnil(L, -1)) {
assert("Async event handler does not exist!" == 0);
}
luaL_checktype(L, -1, LUA_TFUNCTION);
lua_pushinteger(L, jobDone.id);
lua_pushlstring(L, jobDone.serializedResult.data(),
jobDone.serializedResult.size());
if (lua_pcall(L, 2, 0, errorhandler)) {
script_error(L);
}
}
resultQueueMutex.Unlock();
lua_pop(L, 1); // Pop core
}
/******************************************************************************/
void AsyncEngine::pushFinishedJobs(lua_State* L) {
// Result Table
resultQueueMutex.Lock();
unsigned int index = 1;
lua_createtable(L, resultQueue.size(), 0);
int top = lua_gettop(L);
while (!resultQueue.empty()) {
LuaJobInfo jobDone = resultQueue.front();
resultQueue.pop_front();
lua_createtable(L, 0, 2); // Pre-allocate space for two map fields
int top_lvl2 = lua_gettop(L);
lua_pushstring(L, "jobid");
lua_pushnumber(L, jobDone.id);
lua_settable(L, top_lvl2);
lua_pushstring(L, "retval");
lua_pushlstring(L, jobDone.serializedResult.data(),
jobDone.serializedResult.size());
lua_settable(L, top_lvl2);
lua_rawseti(L, top, index++);
}
resultQueueMutex.Unlock();
}
/******************************************************************************/
void AsyncEngine::prepareEnvironment(lua_State* L, int top)
{
for (std::map<std::string, lua_CFunction>::iterator it = functionList.begin();
it != functionList.end(); it++) {
lua_pushstring(L, it->first.c_str());
lua_pushcfunction(L, it->second);
lua_settable(L, top);
}
}
/******************************************************************************/
AsyncWorkerThread::AsyncWorkerThread(AsyncEngine* jobDispatcher,
unsigned int threadNum) :
ScriptApiBase(),
jobDispatcher(jobDispatcher),
threadnum(threadNum)
{
lua_State *L = getStack();
// Prepare job lua environment
lua_getglobal(L, "core");
int top = lua_gettop(L);
// Push builtin initialization type
lua_pushstring(L, "async");
lua_setglobal(L, "INIT");
jobDispatcher->prepareEnvironment(L, top);
}
/**********