automated snapshot

This commit is contained in:
sumi
2025-12-22 00:36:55 -06:00
parent 63fa362060
commit 57e876e40d
4 changed files with 114 additions and 76 deletions

View File

@@ -7,31 +7,37 @@ import (
type Sketch struct {
layerTools map[string]LayerTools
layerToolsOrdered []LayerTools
}
func NewSketch() Sketch {
return Sketch{
layerTools: make(map[string]LayerTools),
layerToolsOrdered: []LayerTools {},
}
}
func (s *Sketch) CreateLayer(name string, layer Layer, sourceWidth int32, sourceHeight int32) {
texture := rl.LoadRenderTexture(sourceWidth, sourceHeight)
s.layerTools[name] = LayerTools{
layerTools := LayerTools {
name: name,
texture: &texture,
layer: layer,
}
s.layerToolsOrdered = append(s.layerToolsOrdered, layerTools)
s.layerTools[name] = layerTools
}
func (s *Sketch) Draw(ctx *RenderCtx) {
// render onto all layer textures
for _, instance := range s.layerTools {
layer := instance.layer
rl.BeginTextureMode(*instance.texture)
rl.ClearBackground(rl.Blank)
layer.Draw(ctx)
rl.EndTextureMode()
for _, instance := range s.layerToolsOrdered {
instance.layer.Update(ctx)
if instance.layer.IsDirty() {
layer := instance.layer
rl.BeginTextureMode(*instance.texture)
layer.Draw(ctx)
rl.EndTextureMode()
}
}
// composite all layers to screen
@@ -45,7 +51,7 @@ func (s *Sketch) Draw(ctx *RenderCtx) {
viewport := s.CalcViewport(ctx)
for _, instance := range s.layerTools {
for _, instance := range s.layerToolsOrdered {
rl.DrawTexturePro(instance.texture.Texture, viewport, screen, rl.Vector2{}, 0, rl.White)
}
@@ -101,20 +107,17 @@ type LayerTools struct {
/** Layer **/
type Layer interface {
Update(ctx *RenderCtx)
Draw(ctx *RenderCtx)
IsDirty() bool
}
type TestPattern struct{}
type TestPattern struct{
dirty bool
}
func DrawGrid(spacing int32, halfExtent int32) {
col := rl.Color{R: 220, G: 220, B: 220, A: 255}
for x := -halfExtent; x <= halfExtent; x += spacing {
rl.DrawLine(x, -halfExtent, x, halfExtent, col)
}
for y := -halfExtent; y <= halfExtent; y += spacing {
rl.DrawLine(-halfExtent, y, halfExtent, y, col)
}
func (tp *TestPattern) Update(ctx *RenderCtx) {
;
}
func (tp *TestPattern) Draw(ctx *RenderCtx) {
@@ -137,6 +140,12 @@ func (tp *TestPattern) Draw(ctx *RenderCtx) {
rl.DrawLine(0, -10000, 0, 10000, rl.Green)
rl.DrawRectangleLines(-50, -50, 100, 100, rl.Magenta)
rl.PopMatrix()
tp.dirty = false
}
func (tp *TestPattern) IsDirty() bool {
return tp.dirty
}
/** Ports **/