Skip to content

Commit

Permalink
Fix regions rendering in AWT via reordering drawing operations - move…
Browse files Browse the repository at this point in the history
…To/lineTo functions rendered with latest transform, not with a transform that was active on invocation.
  • Loading branch information
IKupriyanov-HORIS committed Jul 23, 2021
1 parent 8479efd commit f756b4a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ open class Diagnostics {
private val dirtyLayers: List<Int>,
private val schedulerSystem: SchedulerSystem,
private val debugService: MetricsService,
uiService: UiService,
private val uiService: UiService,
private val registry: EcsComponentManager
) : Diagnostics() {

Expand Down Expand Up @@ -100,13 +100,16 @@ open class Diagnostics {
debugService.setValue(TIMER_TICK, "Timer tick: $deltaTime")
debugService.setValue(
SYSTEMS_UPDATE_TIME,
"Systems update: ${formatDouble(debugService.totalUpdateTime, 1)}"
"Systems update: ${debugService.totalUpdateTime}"
)
debugService.setValue(ENTITIES_COUNT, "Entities count: ${registry.entitiesCount}")

diagnostics.forEach(Diagnostic::update)

metrics.text = debugService.values
if (metrics.text != debugService.values) {
metrics.text = debugService.values
uiService.repaint()
}
}

internal inner class FreezingSystemDiagnostic : Diagnostic {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MetricsService (private val mySystemTime: SystemTime) {

private var myBeginTime: Long = 0

var totalUpdateTime = 0.0
var totalUpdateTime = 0L
private set

private val myValuesMap = HashMap<String, String>()
Expand All @@ -38,7 +38,7 @@ class MetricsService (private val mySystemTime: SystemTime) {

fun reset() {
myMeasures.clear()
totalUpdateTime = 0.0
totalUpdateTime = 0L
}

fun slowestSystem(): Pair<EcsSystem, Double>? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import jetbrains.livemap.core.ecs.EcsEntity
import jetbrains.livemap.geometry.ScreenGeometryComponent
import jetbrains.livemap.placement.ScreenLoopComponent
import jetbrains.livemap.rendering.Renderer
import jetbrains.livemap.rendering.Renderers
import jetbrains.livemap.rendering.Utils
import jetbrains.livemap.rendering.Renderers.drawLines
import jetbrains.livemap.rendering.StyleComponent
import jetbrains.livemap.scaling.ScaleComponent

class RegionRenderer : Renderer {
Expand All @@ -28,9 +28,11 @@ class RegionRenderer : Renderer {
}
}

Utils.apply(entity.get(), ctx)

ctx.beginPath()
entity.get<StyleComponent>().apply {
ctx.setFillStyle(fillColor)
ctx.setStrokeStyle(strokeColor)
ctx.setLineWidth(strokeWidth)
}

val scale = fragments.first().get<ScaleComponent>().scale

Expand All @@ -42,16 +44,10 @@ class RegionRenderer : Renderer {
ctx.save()
ctx.translate(origin.x, origin.y)
ctx.scale(scale, scale)
Renderers.drawLines(
screenGeometry.geometry,
ctx
) { nop() }
ctx.beginPath()
drawLines(screenGeometry.geometry, ctx, afterPolygon = Context2d::fill)
ctx.restore()
}
}

ctx.fill()
}

private fun nop() {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import kotlin.math.sqrt

object Utils {

fun apply(styleComponent: StyleComponent, ctx: Context2d) {
ctx.setFillStyle(styleComponent.fillColor)
ctx.setStrokeStyle(styleComponent.strokeColor)
ctx.setLineWidth(styleComponent.strokeWidth)
}

internal fun drawPath(ctx: Context2d, radius: Double, shape: Int) {
when (shape) {
0 -> square(ctx, radius)
Expand Down

0 comments on commit f756b4a

Please sign in to comment.