Quantcast

Moved to chunk-based item scanning

Kevin Lyles [07-20-10 - 17:22]
Moved to chunk-based item scanning
Filename
ItemScanner.lua
diff --git a/ItemScanner.lua b/ItemScanner.lua
index 785c007..d39992f 100644
--- a/ItemScanner.lua
+++ b/ItemScanner.lua
@@ -1,4 +1,4 @@
-local minItem, maxItem = 1, 99999
+local minItem, maxItem, chunkSize = 1, 99999, 20000
 local CONSECUTIVE_INVALID_TO_IGNORE = 5
 local VALID_DELAY = 0.025
 local INVALID_DELAY = 5
@@ -66,13 +66,14 @@ local function OnUpdate(self)
 end

 local function itemParseCoroutine(start)
+	local chunkStart, chunkEnd = chunkSize * math.floor(start / chunkSize), chunkSize * math.floor((start + chunkSize) / chunkSize) - 1
 	IS_status.items.scan_active = true
 	coroutine.yield()
 	local startTime = GetTime()
 	local roundStartTime = startTime
 	local numProcessed, roundNumProcessed, valid, roundValid = 0, 0, 0, 0
 	print(string.format("ItemScanner: starting scan at item %d", start))
-	for i = start, maxItem do
+	for i = start, math.min(chunkEnd, maxItem) do
 		if not IS_status.items.invalid[i] or (type(IS_status.items.invalid[i]) == "number" and IS_status.items.invalid[i] < CONSECUTIVE_INVALID_TO_IGNORE) then
 			IS_status.items.last_scanned = i
 			local itemStartTime = GetTime()
@@ -124,6 +125,14 @@ local function commandHandler(msg)
 			IS_status.items.last_scanned = nil
 			IS_status.items.last_valid = nil
 			return
+		elseif msg == "items next-chunk" then
+			start = IS_status.items.last_valid or IS_status.items.last_scanned or minItem
+			start = chunkSize * math.ceil(start / chunkSize)
+			if start > maxItem then
+				commandHandler("items stop")
+				return
+			end
+			commandHandler("items clear")
 		elseif msg == "items reset" then
 			commandHandler("items clear")
 			commandHandler("items restart")
@@ -132,6 +141,9 @@ local function commandHandler(msg)
 			start = minItem
 			IS_status.items.last_scanned = nil
 			IS_status.items.last_valid = nil
+		elseif msg == "items restart-chunk" then
+			start = (IS_status.items.last_valid or IS_status.items.last_scanned or minItem)
+			start = math.max(chunkSize * math.floor(start / chunkSize), minItem)
 		elseif msg == "items stop" then
 			IS_status.items.scan_active = false
 			return