mirror of
https://github.com/veden/Rampant.git
synced 2025-09-16 09:16:43 +02:00
finished basic visualizer
This commit is contained in:
32
control.lua
32
control.lua
@@ -255,28 +255,28 @@ local function onTick(event)
|
|||||||
processPendingChunks(natives, regionMap, surface, pendingChunks, tick)
|
processPendingChunks(natives, regionMap, surface, pendingChunks, tick)
|
||||||
scanMap(regionMap, surface, natives)
|
scanMap(regionMap, surface, natives)
|
||||||
|
|
||||||
-- if (tick == regionMap.logicTick) then
|
if (tick == regionMap.logicTick) then
|
||||||
-- regionMap.logicTick = regionMap.logicTick + INTERVAL_LOGIC
|
regionMap.logicTick = regionMap.logicTick + INTERVAL_LOGIC
|
||||||
|
|
||||||
-- local players = gameRef.players
|
local players = gameRef.players
|
||||||
|
|
||||||
-- planning(natives,
|
planning(natives,
|
||||||
-- gameRef.forces.enemy.evolution_factor,
|
gameRef.forces.enemy.evolution_factor,
|
||||||
-- tick,
|
tick,
|
||||||
-- surface)
|
surface)
|
||||||
|
|
||||||
-- cleanSquads(natives)
|
cleanSquads(natives)
|
||||||
-- regroupSquads(natives)
|
regroupSquads(natives)
|
||||||
|
|
||||||
-- processPlayers(players, regionMap, surface, natives, tick)
|
processPlayers(players, regionMap, surface, natives, tick)
|
||||||
|
|
||||||
-- if natives.useCustomAI then
|
if natives.useCustomAI then
|
||||||
-- processBases(regionMap, surface, natives, tick)
|
processBases(regionMap, surface, natives, tick)
|
||||||
-- end
|
end
|
||||||
|
|
||||||
-- squadsBeginAttack(natives, players)
|
squadsBeginAttack(natives, players)
|
||||||
-- squadsAttack(regionMap, surface, natives)
|
squadsAttack(regionMap, surface, natives)
|
||||||
-- end
|
end
|
||||||
|
|
||||||
processMap(regionMap, surface, natives, tick)
|
processMap(regionMap, surface, natives, tick)
|
||||||
end
|
end
|
||||||
|
@@ -161,6 +161,7 @@ function mapUtils.positionFromDirectionAndChunk(direction, startPosition, endPos
|
|||||||
endPosition.x = startPosition.x + CHUNK_SIZE * scaling
|
endPosition.x = startPosition.x + CHUNK_SIZE * scaling
|
||||||
endPosition.y = startPosition.y + CHUNK_SIZE * scaling
|
endPosition.y = startPosition.y + CHUNK_SIZE * scaling
|
||||||
end
|
end
|
||||||
|
return endPosition
|
||||||
end
|
end
|
||||||
|
|
||||||
return mapUtils
|
return mapUtils
|
||||||
|
143
visual.rkt
143
visual.rkt
@@ -6,10 +6,15 @@
|
|||||||
|
|
||||||
(define CHUNK_SIZE 32)
|
(define CHUNK_SIZE 32)
|
||||||
|
|
||||||
|
(define INVALID_CHUNK (Chunk -1 -1 0 0 0 0 0 0 0))
|
||||||
|
|
||||||
|
(define windowX 500)
|
||||||
|
(define windowY 0)
|
||||||
(define windowWidth 1024)
|
(define windowWidth 1024)
|
||||||
(define windowHeight 1024)
|
(define windowHeight 1024)
|
||||||
|
|
||||||
(define INVALID_CHUNK (Chunk -1 -1 0 0 0 0 0 0 0))
|
(define activeHighlight null)
|
||||||
|
(define activeLayer "movement")
|
||||||
|
|
||||||
(define (normalize v low high)
|
(define (normalize v low high)
|
||||||
(/ (- v low)
|
(/ (- v low)
|
||||||
@@ -19,77 +24,7 @@
|
|||||||
(* (floor (/ x digits))
|
(* (floor (/ x digits))
|
||||||
digits))
|
digits))
|
||||||
|
|
||||||
|
(define (showVisual aiState)
|
||||||
(define (refresh dc)
|
|
||||||
(drawFrame dc))
|
|
||||||
|
|
||||||
(define frameWithEvents% (class frame%
|
|
||||||
(define/override (on-subwindow-char r event)
|
|
||||||
(when (eq? (send event get-key-code) #\c)
|
|
||||||
(exit))
|
|
||||||
(super on-subwindow-char r event))
|
|
||||||
(super-new)))
|
|
||||||
|
|
||||||
(define (findChunk chunkLookups x y)
|
|
||||||
(hash-ref chunkLookups (list x y) INVALID_CHUNK))
|
|
||||||
|
|
||||||
|
|
||||||
(define (chunkX->screenX x minX maxX tileWidth)
|
|
||||||
(roundTo (* (normalize x minX maxX)
|
|
||||||
windowWidth)
|
|
||||||
tileWidth))
|
|
||||||
|
|
||||||
(define (chunkY->screenY y minY maxY tileHeight)
|
|
||||||
(roundTo (+ (- windowHeight
|
|
||||||
(* (normalize y minY maxY)
|
|
||||||
windowHeight)))
|
|
||||||
tileHeight))
|
|
||||||
|
|
||||||
(define (screenX->chunkX x minX tileWidth)
|
|
||||||
(+ (* (ceiling (/ x tileWidth))
|
|
||||||
CHUNK_SIZE)
|
|
||||||
minX))
|
|
||||||
|
|
||||||
(define (screenY->chunkY y maxY tileHeight)
|
|
||||||
(- maxY
|
|
||||||
(* (floor (/ y tileHeight))
|
|
||||||
CHUNK_SIZE)))
|
|
||||||
|
|
||||||
(define (displayHighlight dc x y)
|
|
||||||
;; (print (list x y))
|
|
||||||
;; (display "\n")
|
|
||||||
;; (print (list (screenX->chunkX x) (screenY->chunkY y)))
|
|
||||||
;; (display "\n---\n")
|
|
||||||
(let ((chunk (findChunk (screenX->chunkX x)
|
|
||||||
(screenY->chunkY y))))
|
|
||||||
(set! activeHighlight chunk))
|
|
||||||
(refresh dc))
|
|
||||||
|
|
||||||
(define canvasWithEvents% (class canvas%
|
|
||||||
(define/override (on-event event)
|
|
||||||
(match (send event get-event-type)
|
|
||||||
((== 'motion) (displayChunk (send event get-x) (send event get-y)))
|
|
||||||
((== 'left-down) (displayHighlight (send event get-x) (send event get-y)))
|
|
||||||
((== 'right-down) (begin (set! activeHighlight null)
|
|
||||||
(refresh )
|
|
||||||
))
|
|
||||||
(_ #t)))
|
|
||||||
(super-new)))
|
|
||||||
|
|
||||||
(define (newFrame width height x y [label ""])
|
|
||||||
(new frameWithEvents%
|
|
||||||
[label label]
|
|
||||||
[width width]
|
|
||||||
[height height]
|
|
||||||
[x x]
|
|
||||||
[y y]))
|
|
||||||
|
|
||||||
|
|
||||||
(define activeHighlight null)
|
|
||||||
(define activeLayer "movement")
|
|
||||||
|
|
||||||
|
|
||||||
(define (showVisual aiState windowX windowY windowWidth windowHeight)
|
|
||||||
(match-let* (((AiState chunks chunkLookups chunkMinMaxes) aiState)
|
(match-let* (((AiState chunks chunkLookups chunkMinMaxes) aiState)
|
||||||
((ChunkRange (MinMax minX maxX)
|
((ChunkRange (MinMax minX maxX)
|
||||||
(MinMax minY maxY)
|
(MinMax minY maxY)
|
||||||
@@ -104,6 +39,31 @@
|
|||||||
;; (pretty-display aiState)
|
;; (pretty-display aiState)
|
||||||
;; (display "\n")
|
;; (display "\n")
|
||||||
|
|
||||||
|
(define frameWithEvents% (class frame%
|
||||||
|
(define/override (on-subwindow-char r event)
|
||||||
|
(when (eq? (send event get-key-code) #\c)
|
||||||
|
(exit))
|
||||||
|
(super on-subwindow-char r event))
|
||||||
|
(super-new)))
|
||||||
|
|
||||||
|
(define canvasWithEvents% (class canvas%
|
||||||
|
(define/override (on-event event)
|
||||||
|
(match (send event get-event-type)
|
||||||
|
((== 'motion) (displayChunk (send event get-x) (send event get-y)))
|
||||||
|
((== 'left-down) (displayHighlight (send event get-x) (send event get-y)))
|
||||||
|
((== 'right-down) (begin (set! activeHighlight null)
|
||||||
|
(refresh)))
|
||||||
|
(_ #t)))
|
||||||
|
(super-new)))
|
||||||
|
|
||||||
|
(define (newFrame width height x y [label ""])
|
||||||
|
(new frameWithEvents%
|
||||||
|
[label label]
|
||||||
|
[width width]
|
||||||
|
[height height]
|
||||||
|
[x x]
|
||||||
|
[y y]))
|
||||||
|
|
||||||
(define templates (list '(250 500 0 0 "controls")
|
(define templates (list '(250 500 0 0 "controls")
|
||||||
(list windowWidth windowHeight windowX windowY "map")))
|
(list windowWidth windowHeight windowX windowY "map")))
|
||||||
(define frames (map (lambda (frame)
|
(define frames (map (lambda (frame)
|
||||||
@@ -135,7 +95,26 @@
|
|||||||
;; (exact->inexact tileHeight)))
|
;; (exact->inexact tileHeight)))
|
||||||
;; (display "\n")
|
;; (display "\n")
|
||||||
|
|
||||||
|
(define (chunkX->screenX x)
|
||||||
|
(roundTo (* (normalize x minX maxX)
|
||||||
|
windowWidth)
|
||||||
|
tileWidth))
|
||||||
|
|
||||||
|
(define (chunkY->screenY y)
|
||||||
|
(roundTo (+ (- windowHeight
|
||||||
|
(* (normalize y minY maxY)
|
||||||
|
windowHeight)))
|
||||||
|
tileHeight))
|
||||||
|
|
||||||
|
(define (screenX->chunkX x)
|
||||||
|
(+ (* (ceiling (/ x tileWidth))
|
||||||
|
CHUNK_SIZE)
|
||||||
|
minX))
|
||||||
|
|
||||||
|
(define (screenY->chunkY y)
|
||||||
|
(- maxY
|
||||||
|
(* (floor (/ y tileHeight))
|
||||||
|
CHUNK_SIZE)))
|
||||||
|
|
||||||
(define (drawFrame context)
|
(define (drawFrame context)
|
||||||
(send context suspend-flush)
|
(send context suspend-flush)
|
||||||
@@ -156,14 +135,26 @@
|
|||||||
chunks))
|
chunks))
|
||||||
(send context resume-flush))
|
(send context resume-flush))
|
||||||
|
|
||||||
|
(define (refresh)
|
||||||
|
(drawFrame dcMap))
|
||||||
|
|
||||||
|
(define (findChunk x y)
|
||||||
|
(hash-ref chunkLookups (list x y) INVALID_CHUNK))
|
||||||
|
|
||||||
(define (displayChunk x y)
|
(define (displayChunk x y)
|
||||||
(send siteBox set-label
|
(send siteBox set-label
|
||||||
(chunk->string (findChunk (screenX->chunkX x)
|
(chunk->string (findChunk (screenX->chunkX x)
|
||||||
(screenY->chunkY y)))))
|
(screenY->chunkY y)))))
|
||||||
|
|
||||||
|
(define (displayHighlight x y)
|
||||||
|
;; (print (list x y))
|
||||||
|
;; (display "\n")
|
||||||
|
;; (print (list (screenX->chunkX x) (screenY->chunkY y)))
|
||||||
|
;; (display "\n---\n")
|
||||||
|
(let ((chunk (findChunk (screenX->chunkX x)
|
||||||
|
(screenY->chunkY y))))
|
||||||
|
(set! activeHighlight chunk))
|
||||||
|
(refresh))
|
||||||
|
|
||||||
(define (scaleColor dc value low high)
|
(define (scaleColor dc value low high)
|
||||||
(define v (/ (- value low)
|
(define v (/ (- value low)
|
||||||
@@ -218,8 +209,4 @@
|
|||||||
'showing))
|
'showing))
|
||||||
|
|
||||||
(define (test)
|
(define (test)
|
||||||
(showVisual (readState "/data/games/factorio/script-output/rampantState.txt")
|
(showVisual (readState "/data/games/factorio/script-output/rampantState.txt"))))
|
||||||
500
|
|
||||||
0
|
|
||||||
1024
|
|
||||||
1024)))
|
|
||||||
|
Reference in New Issue
Block a user