Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # kajacx_rotator.crpl
- # Created on: 5/2/2019 10:58:05 PM
- # ------------------------------------------
- $MaxRange:20 # maximum range ever use
- $Range:20 # range for this specific rotator
- $Interval:3 # rotate every N frames
- $RotationSpeed:0.08726646259 # rotatble by X radians (0.08726646259 = 5 degrees)
- $CenterX:67
- $CenterY:48
- $DebugImages:1
- $ImageSquare:"Custom0pp"
- once
- ShowTraceLog
- ClearTraceLog
- #HideTraceLog
- "Start" Trace
- @InitializeRings
- "Init done" Trace
- <-CenterX <-CenterY <-Range @SaveTerrain ->Terrain
- "Save done" Trace
- <-Interval SetTimer0
- 0 ->angle
- Self RemoveImages
- <-DebugImages if
- :DrawDebugImages
- endif
- endonce
- GetTimer0 eq0 if
- <-angle <-RotationSpeed add ->angle
- "Pasting at angle" <-angle Trace2
- <-CenterX <-CenterY <-Range <-Terrain <-angle @PasteTerrain
- <-Interval SetTimer0
- endif
- :InitializeRings # [ - ] call at start or when MaxRange changes
- # Rings - index is length from start
- <-MaxRange 1 add CreateListStartingSize ->RingsX
- <-MaxRange 1 add CreateListStartingSize ->RingsY
- <-MaxRange 1 add 0 do
- <-RingsX I CreateList SetListElement
- <-RingsY I CreateList SetListElement
- loop
- "Rings done" Trace
- #assign cells into rings
- <-MaxRange 1 add <-MaxRange neg do # J = Y
- <-MaxRange 1 add <-MaxRange neg do # I = X
- I J 0 0 Distance 0 Round asint ->IR_Distance
- <-IR_Distance <-MaxRange lte if
- <-RingsX <-IR_Distance GetListElement I AppendToList
- <-RingsY <-IR_Distance GetListElement J AppendToList
- endif
- loop
- loop
- "assign done" Trace
- 1 Delay # quick and dirty way t oavoid the 1000000 overflow
- #sort cells in rings by their angle
- 0 ->DEBUG_Comparisons
- <-MaxRange 1 add 0 do
- <-RingsX I GetListElement ->IR_RsX
- <-RingsY I GetListElement ->IR_RsY
- <-IR_RsX GetListCount 0 do # use insertion sort
- # find smallest element in the remaining list
- 0 ->IR_LowIndex
- 1000000 ->IR_LowValue
- <-IR_RsX GetListCount I do
- <-IR_RsY I GetListElement <-IR_RsX I GetListElement atan2 6.28318530718 add 6.28318530718 mod ->IR_Value
- <-IR_Value <-IR_LowValue lt if
- <-IR_Value ->IR_LowValue
- I ->IR_LowIndex
- endif
- <-DEBUG_Comparisons 1 add ->DEBUG_Comparisons
- loop
- #now switch values around
- <-IR_RsX I GetListElement ->IR_OldX
- <-IR_RsY I GetListElement ->IR_OldY
- <-IR_RsX I SetListElement(<-IR_RsX <-IR_LowIndex GetListElement)
- <-IR_RsY I SetListElement(<-IR_RsY <-IR_LowIndex GetListElement)
- <-IR_RsX <-IR_LowIndex SetListElement(<-IR_OldX)
- <-IR_RsY <-IR_LowIndex SetListElement(<-IR_OldY)
- loop
- ### This takes way to many isstructions, it would be better to precompute in a separate program and paste the completed data
- "Processed" I "ring, comparisions:" <-DEBUG_Comparisons Trace4
- 1 Delay
- loop
- "sort done" Trace
- # aaand done
- :SaveTerrain # [ X Y Range - List] saves terrain to a list
- ->ST_Range
- ->ST_Y
- ->ST_X
- CreateList ->ST_Terrain
- <-ST_Range 1 add 0 do # go over avaliable rings
- <-RingsX I GetListElement ->ST_RsX
- <-RingsY I GetListElement ->ST_RsY
- <-ST_RsX GetListCount 0 do
- # save the terrain height in order of the rings
- <-ST_Terrain # keep the list
- <-ST_RsX I GetListElement <-ST_X add # x coord
- <-ST_RsY I GetListElement <-ST_Y add # x coord
- GetTerrain
- AppendToList # save to ST_Terrain
- loop
- loop
- #<-ST_Range 2 mul 1 add ->ST_Offset
- #
- #<-ST_Offset <-ST_Offset mul CreateListStartingSize ->ST_Terrain
- #
- #<-ST_Range 1 add <-ST_Range neg do # J = Y
- # <-ST_Range 1 add <-ST_Range neg do # I = X
- # #I J 0 0 Distance 0 Round asint ->ST_Distance
- # #<-ST_Distance <-ST_Range lte if
- # # save terrain always - space will be waster but it is better than the alternative
- # # or is it? maybe it would be more efficient to store terrain in the same order as the rings...
- # <-ST_Terrain J <-ST_Offset mul I add I J GetTerrain SetListElement
- # #endif
- # loop
- #loop
- <-ST_Terrain return
- :PasteTerrain # [ X Y Range List Angle - ] pastes the terrain into the world, at the given CCW angle in radians
- ->PT_Angle
- ->PT_Terrain
- ->PT_Range
- ->PT_Y
- ->PT_X
- <-PT_Terrain Trace
- 0 ->PT_Index # index from the terrain list, in order of the rings
- <-PT_Range 1 add 0 do # go over avaliable rings
- <-RingsX I GetListElement ->PT_RsX
- <-RingsY I GetListElement ->PT_RsY
- <-PT_RsX GetListCount ->PT_Count
- <-PT_Angle 6.28318530718 div <-PT_Count mul 0 Round asint ->PT_Offset
- "Ring" I "Offset" <-PT_Offset Trace4
- <-PT_Count 0 do
- # at I+Offset position, set terrain from I, that way it will be a counter-clockwise rotation
- I <-PT_Offset add <-PT_Count mod ->PT_Target
- <-PT_RsX <-PT_Target GetListElement <-PT_X add #x target coordinate
- <-PT_RsY <-PT_Target GetListElement <-PT_Y add #y target coordinate
- <-PT_Terrain <-PT_Index GetListElement # saved terrain heights are ordered by the ring order already
- #Trace3
- SetTerrain
- <-PT_Index 1 add ->PT_Index
- loop
- loop
- # aaand done?
- :DrawDebugImages
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement