get every sign in the world - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html) +--- Thread: get every sign in the world (/thread-2403.html) |
RE: get every sign in the world - NiLSPACE - 03-18-2016 I don't think you should save every fence, but only those in the corners Code: ...x++x x: fence that will be saved RE: get every sign in the world - danny9484 - 03-18-2016 yeah I think that might be possible I will try it tommorow I could edit the trace function because I already saved the move direction in it on every fence I check it would be like if the direction is not the same save the fence RE: get every sign in the world - danny9484 - 03-18-2016 ahh I remember why I didn't do that I wasn't sure how to load every fence again from the database but I have a Idea now I could get one coordinate and try +X after that -X after that +Z after that -Z then 2 + X then 2 - X ... until I reach another point and I repeat this until I get back to the start the first coordinate. But still I would need to create ID's for gardens to do that but I think that's no Problem. or I just use the Gate as start RE: get every sign in the world - xoft - 03-18-2016 It's not only about saving the fences, it's also about deciding whether a point is inside the garden or not, and it's gonna get ugly soon. RE: get every sign in the world - danny9484 - 03-18-2016 the idea is not letting people in it it's not really necessary but I will think later about that and maybe add it as a update RE: get every sign in the world - xoft - 03-18-2016 Ah, I completely misunderstood the protection this plugin implements, sorry. I thought it was meant to protect the complete insides of the garden. The DB should be fast enough for any reasonably sized garden, use prepared statements and transactions to improve the speed. RE: get every sign in the world - danny9484 - 03-18-2016 I think writing only the edges in the database should be enogh but how could I prepare a Database transaction? RE: get every sign in the world - xoft - 03-18-2016 Something like this (didn't test, may need tweaking and definitely needs better error handling): -- walls is an array-table: {{x1, y1, z1}, {x2, y2, z2}, ... } db:exec("BEGIN TRANSACTION") -- Postpone all DB changes into one big step, to save on disk I/O local stmt = db:prepare("INSERT INTO GardenWalls (x, y, z) VALUES (?, ?, ?)") for wall in ipairs(walls) do stmt:bind_values(unpack(wall)) -- insert "wall" values into the statement stmt: step() -- execute the statement (once); the space before S should not be there (forum limit) stmt:reset() -- reset the statement so that the next "wall" values can be inserted end stmt: finalize() DB:exec("COMMIT") -- Now put everything queued so far into the DB file RE: get every sign in the world - danny9484 - 03-18-2016 doesn't look too complicated I will try that thanks RE: get every sign in the world - danny9484 - 03-19-2016 I just tried that prepare and it worked very very well xD local db = sqlite3.open(cPluginManager:Get():GetCurrentPlugin():GetLocalFolder() .. "/storage.sqlite") db:exec("BEGIN TRANSACTION") -- Postpone all DB changes into one big step, to save on disk I/O local stmt, err, errmsg = db:prepare("INSERT INTO marker (X, Y, Z, World, Player_name) VALUES (?, ?, ?, ?, ?)") if (not stmt) then LOG(err .. " " .. errmsg) end for X in pairs(marker_temp) do for Y in pairs(marker_temp[X]) do for Z in pairs(marker_temp[X][Y]) do for World_name in pairs(marker_temp[X][Y][Z]) do for Player_name in pairs(marker_temp[X][Y][Z][World_name]) do LOG("Saving: " .. X .. "X " .. Y .. "Y " .. Z .. "Z " .. World_name .. " " .. Player_name) stmt:bind_names({X, Y, Z, World_name, Player_name}) stmt:step() -- execute the statement (once) stmt:reset() -- reset the statement so that the next "wall" values can be inserted end end end end end stmt:finalize() db:exec("COMMIT") -- Now put everything queued so far into the DB file marker_temp = {}everything is now saving in a second |