Skip to content

Commit

Permalink
make upgrade and go fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
unitoftime committed Jan 4, 2025
1 parent cbc837e commit a5879be
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 26 deletions.
5 changes: 3 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func NewApp() *App {
// scheduler.SetFixedTimeStep(4 * time.Millisecond)

app := &App{
world: world,
scheduler: scheduler,
world: world,
scheduler: scheduler,
}

return app
Expand All @@ -43,6 +43,7 @@ func (a *App) Run() {
type Plugin interface {
Initialize(world *ecs.World)
}

func (a *App) AddPlugin(plugin Plugin) {
plugin.Initialize(a.world)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/ungerik/go3d v0.0.0-20240502073936-1137f6adf7e9
github.com/unitoftime/beep v0.0.0-20241026233918-b83e337289e8
github.com/unitoftime/ecs v0.0.4-0.20250104145201-4bbe9d72f60c
github.com/unitoftime/glitch v0.0.0-20241226152421-0e5863c2be1d
github.com/unitoftime/glitch v0.0.0-20250104145909-ad673646faaf
github.com/unitoftime/gotiny v0.0.0-20240915162236-e7a35021e769
github.com/unitoftime/intmap v0.0.0-20231203115433-9505126f7096
github.com/unitoftime/packer v0.0.0-20230818221437-1f2c1b1e4275
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ github.com/unitoftime/cod v0.0.0-20241228160133-efe666697475 h1:m0K71y86gw7kbyQS
github.com/unitoftime/cod v0.0.0-20241228160133-efe666697475/go.mod h1:Iufibv9gn5GJb4Qzkf8e8xaXOV77OgkrB5kkBZTEN+M=
github.com/unitoftime/ecs v0.0.4-0.20250104145201-4bbe9d72f60c h1:Hn3mekxfD7p3zqZN2LzT8MeemfRMZRzdKy7+1yeCGkM=
github.com/unitoftime/ecs v0.0.4-0.20250104145201-4bbe9d72f60c/go.mod h1:YmsHdpPA1CcSd7i6o2W3NgTwFJYI8G68GeGqKimMb3c=
github.com/unitoftime/glitch v0.0.0-20241226152421-0e5863c2be1d h1:ujKNn8QSdGXE4CVHTUH4Di309HuuIlXGl+yk0ugVQ68=
github.com/unitoftime/glitch v0.0.0-20241226152421-0e5863c2be1d/go.mod h1:8QQX+VRTfxdixHCn5bWXYWDrmRzGlEY964ERh3/YIF8=
github.com/unitoftime/glitch v0.0.0-20250104145909-ad673646faaf h1:trqN6GqPkGOF6QnsPfp9RX87earQ05A7YUcOmRDpUG8=
github.com/unitoftime/glitch v0.0.0-20250104145909-ad673646faaf/go.mod h1:PNiytmW1wtVkCpOSzHWopTHbGI5JLBUESNwn9jl9uuU=
github.com/unitoftime/gotiny v0.0.0-20240915162236-e7a35021e769 h1:SjK7DZ+RQcLLZwuz9bOLPW59fAZfadztDFDVg3nSiCE=
github.com/unitoftime/gotiny v0.0.0-20240915162236-e7a35021e769/go.mod h1:iq4kY4pPC8ZKztyei1pln4Fkk0BxQbyM1hICubHxoCo=
github.com/unitoftime/intmap v0.0.0-20231203115433-9505126f7096 h1:ietNpHDGnFAyabqzzinz8zJW2rjx/0DLslU4hU4wNbU=
Expand Down
4 changes: 1 addition & 3 deletions render/camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Camera2DBundle struct {
func (c Camera2DBundle) CompWrite(w ecs.W) {
cam := NewCamera2D(glm.CR(0), 0, 0)
target := Target{
draw: c.target,
draw: c.target,
batch: c.target,
}
visionList := NewVisionList()
Expand All @@ -28,8 +28,6 @@ func (c Camera2DBundle) CompWrite(w ecs.W) {
visionList.CompWrite(w)
}



//cod:component
type Camera struct {
Camera glitch.CameraOrtho
Expand Down
7 changes: 4 additions & 3 deletions render/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (p DefaultPlugin) Initialize(world *ecs.World) {
type VisionList struct {
List []ecs.Id
}

func NewVisionList() VisionList {
return VisionList{
List: make([]ecs.Id, 0),
Expand All @@ -48,7 +49,6 @@ func (vl *VisionList) Clear() {
vl.List = vl.List[:0]
}


//cod:component
type Window struct {
*glitch.Window
Expand All @@ -58,19 +58,20 @@ type Window struct {
type Sprite struct {
Sprite *glitch.Sprite
}

func (s Sprite) Bounds() glm.Rect {
return s.Sprite.Bounds()
}

//cod:component
type Target struct {
draw RenderTarget
draw RenderTarget
batch glitch.BatchTarget // TODO: Indexed?
}

//cod:component
type Visibility struct {
Hide bool // If set true, the entity will always be calculated as invisible
Hide bool // If set true, the entity will always be calculated as invisible
Calculated bool
}

Expand Down
31 changes: 17 additions & 14 deletions render/pass.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func CalculateVisibilitySystem(dt time.Duration, camQuery *ecs.View2[Camera, Vis

query.MapId(func(id ecs.Id, gt *transform.Global, sprite *Sprite, vis *Visibility) {
vis.Calculated = false
if vis.Hide { return }
if vis.Hide {
return
}

mat := gt.Mat4()
shape := spatial.Rect(sprite.Bounds(), mat)
Expand All @@ -64,7 +66,6 @@ func CalculateVisibilitySystem(dt time.Duration, camQuery *ecs.View2[Camera, Vis
})
})


// TODO: Optimization if there are a lot of cameras: Preconfigure a spatial hash
// chunkSize := [2]int{1024/8, 1024/8}
// visionMap := spatial.NewHashmap[ecs.Id](chunkSize, 8)
Expand Down Expand Up @@ -92,35 +93,34 @@ func (l *RenderPassList) Clear() {
l.List = l.List[:0]
}

type RenderTarget interface{
type RenderTarget interface {
glitch.Target
glitch.BatchTarget
Bounds() glm.Rect
}

type RenderPass struct {
batchTarget glitch.BatchTarget
drawTarget RenderTarget
clearColor glm.RGBA
camera Camera // TODO: I feel like there could/should support multiple?
visionList VisionList
drawTarget RenderTarget
clearColor glm.RGBA
camera Camera // TODO: I feel like there could/should support multiple?
visionList VisionList
}

func CalculateRenderPasses(dt time.Duration, passes *RenderPassList, query *ecs.View3[Camera, Target, VisionList]) {
passes.Clear()
query.MapId(func(id ecs.Id, camera *Camera, target *Target, visionList *VisionList) {
passes.Add(RenderPass{
drawTarget: target.draw,
drawTarget: target.draw,
batchTarget: target.batch,
camera: *camera,
visionList: *visionList,
camera: *camera,
visionList: *visionList,
})
})

// TODO: Sort somehow? Priority? Order added?
}


func ExecuteRenderPass(dt time.Duration, passes *RenderPassList, query *ecs.View2[transform.Global, Sprite]) {
for _, pass := range passes.List {
glitch.Clear(pass.drawTarget, pass.clearColor)
Expand All @@ -130,16 +130,19 @@ func ExecuteRenderPass(dt time.Duration, passes *RenderPassList, query *ecs.View

for _, id := range pass.visionList.List {
gt, sprite := query.Read(id)
if gt == nil { continue }
if sprite == nil { continue }
if gt == nil {
continue
}
if sprite == nil {
continue
}

mat := gt.Mat4()
sprite.Sprite.DrawColorMask(pass.batchTarget, mat, glm.White)
}
}
}


func RenderingFlushSystem(dt time.Duration, query *ecs.View1[Window]) {
query.MapId(func(_ ecs.Id, win *Window) {
win.Update()
Expand Down
4 changes: 3 additions & 1 deletion transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ func ResolveHeirarchySystem(world *ecs.World) ecs.System {
global.Transform = local.Transform
}

if children == nil { return }
if children == nil {
return
}
resolveTransform(query, children, global)
})
})
Expand Down

0 comments on commit a5879be

Please sign in to comment.