Fabioxps Posted October 27, 2014 Share Posted October 27, 2014 load XML files without causing a crash on the server, I am carrying a map. this is only possible with php? for i,par in ipairs(xmlNodeGetChildren(arquivoMap)) do local objectType = xmlNodeGetName(par) if objectType == "object" then _indexInto.obj = {insertType = objectType, model = tonumber(xmlNodeGetAttribute(p,"model")), pX = tonumber(xmlNodeGetAttribute(p,"posX")), pY = tonumber(xmlNodeGetAttribute(p,"posY")), pZ = tonumber(xmlNodeGetAttribute(p,"posZ")), rX = tonumber(xmlNodeGetAttribute(p,"rotX")), rY = tonumber(xmlNodeGetAttribute(p,"rotY")), rZ = tonumber(xmlNodeGetAttribute(p,"rotZ")) or tonumber(xmlNodeGetAttribute(p, "rotation"))} end end _indexIntoTable[#_indexIntoTable+1] = _indexInto.obj Link to comment
Moderators IIYAMA Posted October 28, 2014 Moderators Share Posted October 28, 2014 XML is slow, you should load it slowly. "without" without what to be exact? Link to comment
Fabioxps Posted October 28, 2014 Author Share Posted October 28, 2014 can you show me how to load slowly perhaps an example with my code? I am very grateful if you or someone can help me. Link to comment
Moderators IIYAMA Posted October 28, 2014 Moderators Share Posted October 28, 2014 My version, not tested. local slowLoopTable = {} local maxItemsPerLoop = 30 local slowLoopFunction = function (theTable) local tableData = slowLoopTable[theTable] if tableData then local startValue = tableData["startValue"] local endValue = tableData["endValue"] local processFunction = tableData["processFunction"] for i=startValue, endValue do tableData["processFunction"](i,theTable[i]) end local maxItemsPerLoop = (theTable["maxItemsPerLoop"] or maxItemsPerLoop) local newStartValue = endValue+1 if newStartValue <= #theTable then tableData["startValue"] = newStartValue local newEndValue = newStartValue+maxItemsPerLoop if newEndValue > #theTable then tableData["endValue"] = #theTable else tableData["endValue"] = newEndValue end --tableData["timer"] = setTimer(slowLoopFunction,400,1,theTable) resetTimer (tableData["timer"]) else slowLoopTable[theTable] = nil end end end function startSlowLoop (theTable,processFunction,itemsPerLoop) local slowLoopTimer = setTimer(slowLoopFunction,400,1,theTable) if slowLoopTimer then local maxItemsPerLoop = tonumber(itemsPerLoop) or maxItemsPerLoop -- protect the variable against overwrite if maxItemsPerLoop > #theTable then maxItemsPerLoop = #theTable end slowLoopTable[theTable]= { ["timer"]= slowLoopTimer, -- can be useful for a quick abort and reset. ["startValue"]= 1, ["endValue"]= maxItemsPerLoop, ["maxItemsPerLoop"]= maxItemsPerLoop, ["processFunction"]= processFunction } end end --[[ supports multiply tables ----------------------------- ]] syntrax startSlowLoop ( theTable, processFunction [, itemsPerLoop = 30] ) Send to process function. ( index, par ) Link to comment
Fabioxps Posted October 29, 2014 Author Share Posted October 29, 2014 I'm sorry I'm lost in your code how can I call this function with my code Please do not judge me my sincere apologies. Link to comment
Moderators IIYAMA Posted October 29, 2014 Moderators Share Posted October 29, 2014 look at the syntax. Function is second argument. If you want to know when the process is completed, you can call your finished function between line: 30 and 31. Example/test run: local theTable = {3,5,36,547,36,3,8,9,3,6,7,8,5,4,7,8,4,8,5,2,2,1} function executeProcess (index, par) outputChatBox(tostring(index) .. " " .. tostring(par)) -- do your stuff here -- end startSlowLoop ( theTable, executeProcess, 5) Afaik you need the code, then you test it. Go ahead. Link to comment
Fabioxps Posted November 27, 2014 Author Share Posted November 27, 2014 excuse the inconvenience but I do not know how to deploy it in my code. Link to comment
Moderators IIYAMA Posted November 27, 2014 Moderators Share Posted November 27, 2014 Seriously, replying on this 1 month later..... The slowLoopCode. local slowLoopTable = {} local maxItemsPerLoop = 30 local slowLoopFunction = function (theTable) local tableData = slowLoopTable[theTable] if tableData then local startValue = tableData["startValue"] local endValue = tableData["endValue"] local processFunction = tableData["processFunction"] for i=startValue, endValue do tableData["processFunction"](i,theTable[i]) end local maxItemsPerLoop = (theTable["maxItemsPerLoop"] or maxItemsPerLoop) local newStartValue = endValue+1 if newStartValue <= #theTable then tableData["startValue"] = newStartValue local newEndValue = newStartValue+maxItemsPerLoop if newEndValue > #theTable then tableData["endValue"] = #theTable else tableData["endValue"] = newEndValue end --tableData["timer"] = setTimer(slowLoopFunction,400,1,theTable) resetTimer (tableData["timer"]) else slowLoopTable[theTable] = nil end end end function startSlowLoop (theTable,processFunction,itemsPerLoop) local slowLoopTimer = setTimer(slowLoopFunction,400,1,theTable) if slowLoopTimer then local maxItemsPerLoop = tonumber(itemsPerLoop) or maxItemsPerLoop -- protect the variable against overwrite if maxItemsPerLoop > #theTable then maxItemsPerLoop = #theTable end slowLoopTable[theTable]= { ["timer"]= slowLoopTimer, -- can be useful for a quick abort and reset. ["startValue"]= 1, ["endValue"]= maxItemsPerLoop, ["maxItemsPerLoop"]= maxItemsPerLoop, ["processFunction"]= processFunction } end end --[[ supports multiply tables ----------------------------- ]] Example how to execute it. local theTable = {3,5,36,547,36,3,8,9,3,6,7,8,5,4,7,8,4,8,5,2,2,1} function executeProcess (index, par) outputChatBox(tostring(index) .. " " .. tostring(par)) -- do your stuff here -- end startSlowLoop ( theTable, executeProcess, 5) Put them both in one of your scripts and execute it. Then you will know what it does.(if I didn't made a mistake) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now