diff --git a/dotscape b/dotscape index 0b1faee..42651f6 100755 Binary files a/dotscape and b/dotscape differ diff --git a/fcore/app-init.sml b/fcore/app-init.sml index dd80bf3..c0635a1 100644 --- a/fcore/app-init.sml +++ b/fcore/app-init.sml @@ -24,7 +24,7 @@ struct val maxPoints = Int.max (canvasWidth, canvasHeight) val squares = Vector.tabulate (maxPoints, fn _ => - Vector.tabulate (maxPoints, fn _ => 0)) + Vector.tabulate (maxPoints, fn _ => {r = 0, g = 0, b = 0, a = 0})) in { mode = AppType.NORMAL_MODE , squares = squares @@ -43,10 +43,10 @@ struct , openFilePath = "" , fileBrowser = Vector.fromList [] , fileBrowserIdx = 0 - , r = 0.0 - , g = 0.0 - , b = 0.0 - , a = 1.0 + , r = 0 + , g = 0 + , b = 0 + , a = 1 , modalNum = 0 } end diff --git a/fcore/app-type.sml b/fcore/app-type.sml index 48e8b16..bb4d0eb 100644 --- a/fcore/app-type.sml +++ b/fcore/app-type.sml @@ -4,9 +4,11 @@ struct datatype file_browser_item = IS_FILE of string | IS_FOLDER of string + type square = {r: int, g: int, b: int, a: int} + type app_type = { mode: app_mode - , squares: int vector vector + , squares: square vector vector , canvasWidth: int , canvasHeight: int , windowWidth: int @@ -27,10 +29,10 @@ struct , openFilePath: string , fileBrowser: file_browser_item vector , fileBrowserIdx: int - , r: Real32.real - , g: Real32.real - , b: Real32.real - , a: Real32.real + , r: int + , g: int + , b: int + , a: int , modalNum: int } end diff --git a/fcore/app-with.sml b/fcore/app-with.sml index af22f78..349d74d 100644 --- a/fcore/app-with.sml +++ b/fcore/app-with.sml @@ -33,7 +33,10 @@ struct Vector.mapi (fn (idx, el) => if idx = newX then - Vector.mapi (fn (iidx, iel) => if iidx = newY then 1 else iel) el + Vector.mapi + (fn (iidx, iel) => + if iidx = newY then {r = r, g = g, b = b, a = a} else iel) + el else el) squares in @@ -534,8 +537,6 @@ struct } end - fun modalNumToFloat num = Real32.fromInt num / 255.0 - fun r (app: app_type) : app_type = let val @@ -563,7 +564,7 @@ struct , modalNum } = app - val r = modalNumToFloat modalNum + val r = modalNum in { mode = mode , mouseX = mouseX @@ -586,7 +587,7 @@ struct , g = g , b = b , a = a - , modalNum = modalNum + , modalNum = 0 } end @@ -617,7 +618,7 @@ struct , modalNum } = app - val g = modalNumToFloat modalNum + val g = modalNum in { mode = mode , mouseX = mouseX @@ -640,7 +641,7 @@ struct , g = g , b = b , a = a - , modalNum = modalNum + , modalNum = 0 } end @@ -671,7 +672,7 @@ struct , modalNum } = app - val b = modalNumToFloat modalNum + val b = modalNum in { mode = mode , mouseX = mouseX @@ -694,7 +695,7 @@ struct , g = g , b = b , a = a - , modalNum = modalNum + , modalNum = 0 } end @@ -725,7 +726,7 @@ struct , modalNum } = app - val a = modalNumToFloat modalNum + val a = modalNum in { mode = mode , mouseX = mouseX @@ -748,7 +749,7 @@ struct , g = g , b = b , a = a - , modalNum = modalNum + , modalNum = 0 } end diff --git a/fcore/quad-tree.sml b/fcore/quad-tree.sml index 07852aa..4d03872 100644 --- a/fcore/quad-tree.sml +++ b/fcore/quad-tree.sml @@ -99,10 +99,7 @@ end structure CollisionTree = struct - (* ignoreData = any data we find in grid but which doesn't concern us - * so we omit from tree, to reduce number of items in tree, - * and therefore decrease the constant in O(n) *) - val ignoreData = 0 + fun shouldIgnoreData {a, r = _, g = _, b = _} = a = 0 local fun loopYAxis (x, y, eX, eY, yAxis, col) = @@ -147,7 +144,7 @@ struct val yAxis = Vector.sub (grid, x) val data = Vector.sub (yAxis, y) in - if data = ignoreData then + if shouldIgnoreData data then bintree else let @@ -218,8 +215,14 @@ struct val endX = Ndc.fromPixelX (ex, windowWidth, windowHeight) val startY = Ndc.fromPixelY (y, windowWidth, windowHeight) val endY = Ndc.fromPixelY (ey, windowWidth, windowHeight) + + val {r, g, b, a} = data + val r = Real32.fromInt r / 255.0 + val g = Real32.fromInt g / 255.0 + val b = Real32.fromInt b / 255.0 + val a = Real32.fromInt a / 255.0 in - Ndc.ltrbToVertexRgb (startX, startY, endX, endY, 0.0, 0.0, 0.0) :: acc + Ndc.ltrbToVertexRgb (startX, startY, endX, endY, r, g, b) :: acc end fun toTriangles @@ -250,7 +253,7 @@ struct (* building and querying quad tree, plus compression *) datatype quad_tree = - LEAF of {x: int, y: int, ex: int, ey: int, data: int} + LEAF of {x: int, y: int, ex: int, ey: int, data: AppType.square} | NODE of {tl: quad_tree, tr: quad_tree, bl: quad_tree, br: quad_tree} | EMPTY @@ -278,7 +281,7 @@ struct val yAxis = Vector.sub (grid, x) val data = Vector.sub (yAxis, y) in - if data = ignoreData then + if shouldIgnoreData data then EMPTY else let