Skip to content

Commit 4b58f32

Browse files
committed
Adding documentation for asset database & drawign
1 parent 09b474f commit 4b58f32

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

src/engine/assets/database.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,43 @@
3636

3737
package assets
3838

39+
// Database defines the contract for asset storage back‑ends used by the engine.
40+
// Implementations may store assets on disk, in memory, inside an archive, or
41+
// provide a debug view of the file system. The interface abstracts common
42+
// operations required by the engine and editor.
3943
type Database interface {
44+
// PostWindowCreate is a hook that is called after a window has been
45+
// created. Implementations can use the provided handle to perform any
46+
// platform‑specific initialisation. Most implementations are no‑ops.
4047
PostWindowCreate(windowHandle PostWindowCreateHandle) error
48+
49+
// Cache stores the raw byte slice `data` under `key` for fast subsequent
50+
// reads. Implementations may choose to ignore this (e.g. DebugContentDatabase)
51+
// or provide a real cache (e.g. FileDatabase).
4152
Cache(key string, data []byte)
53+
54+
// CacheRemove removes a cached entry identified by `key`. If the
55+
// implementation does not maintain a cache this is a no‑op.
4256
CacheRemove(key string)
57+
58+
// CacheClear clears all cached entries. Implementations without a cache
59+
// should simply return.
4360
CacheClear()
61+
62+
// Read returns the raw bytes for the asset identified by `key`. An error is
63+
// returned if the asset cannot be found or read.
4464
Read(key string) ([]byte, error)
65+
66+
// ReadText is a convenience wrapper around Read that returns the asset as a
67+
// string. It returns any error from Read.
4568
ReadText(key string) (string, error)
69+
70+
// Exists reports whether an asset with the given `key` is available in the
71+
// underlying storage. Implementations should check both the cache and the
72+
// backing store.
4673
Exists(key string) bool
74+
75+
// Close releases any resources held by the implementation. Implementations
76+
// that have no resources may implement this as a no‑op.
4777
Close()
4878
}

src/engine/ui/panel.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737
package ui
3838

3939
import (
40+
"log/slog"
41+
4042
"kaijuengine.com/engine/assets"
4143
"kaijuengine.com/engine/systems/events"
4244
"kaijuengine.com/matrix"
4345
"kaijuengine.com/platform/profiler/tracing"
4446
"kaijuengine.com/rendering"
45-
"log/slog"
4647
)
4748

4849
type PanelScrollDirection = int32
@@ -389,10 +390,8 @@ func (p *Panel) updateShaderVisibility() {
389390
if !p.entity.IsActive() {
390391
return
391392
}
392-
393393
// Retrieve the current scissor rectangle from the root UI.
394394
scissor := p.Base().selfScissor()
395-
396395
// Compute the panel's world‑space bounds.
397396
pos := p.entity.Transform.WorldPosition()
398397
size := p.layout.PixelSize()
@@ -401,7 +400,6 @@ func (p *Panel) updateShaderVisibility() {
401400
right := pos.X() + half.X()
402401
bottom := pos.Y() - half.Y()
403402
top := pos.Y() + half.Y()
404-
405403
// If the panel is completely outside the scissor, deactivate its shader data.
406404
if right < scissor.X() || left > scissor.Z() || top < scissor.Y() || bottom > scissor.W() {
407405
p.shaderData.Deactivate()

src/rendering/drawing.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,35 @@
3737
package rendering
3838

3939
import (
40+
"sort"
41+
"sync"
42+
4043
"kaijuengine.com/klib"
4144
"kaijuengine.com/matrix"
4245
"kaijuengine.com/platform/profiler/tracing"
43-
"sort"
44-
"sync"
4546
)
4647

48+
// Drawing represents a renderable entity in the engine. It bundles together
49+
// the material, mesh, shader instance data, transform, sorting order, and an
50+
// optional view culler used during rendering.
4751
type Drawing struct {
48-
Material *Material
49-
Mesh *Mesh
52+
// Material defines the visual appearance and render pass for the drawing.
53+
Material *Material
54+
// Mesh contains the geometry to be rendered.
55+
Mesh *Mesh
56+
// ShaderData holds per‑instance data for the shader (e.g., uniforms).
5057
ShaderData DrawInstance
51-
Transform *matrix.Transform
52-
Sort int
58+
// Transform specifies the transform this drawing follows.
59+
Transform *matrix.Transform
60+
// Sort determines the draw order within a render pass.
61+
Sort int
62+
// ViewCuller optionally culls the drawing based on the view frustum.
5363
ViewCuller ViewCuller
5464
}
5565

66+
// IsValid reports whether the Drawing is properly configured for rendering.
67+
// A Drawing is considered valid if it has a non-nil Material. This check is
68+
// used before submitting the drawing to the render pipeline.
5669
func (d *Drawing) IsValid() bool {
5770
return d.Material != nil
5871
}

0 commit comments

Comments
 (0)