Skip to content

Commit

Permalink
Merge pull request #45 from yohamta/develop
Browse files Browse the repository at this point in the history
add Entry.String()
  • Loading branch information
yohamta authored Oct 18, 2022
2 parents 8f4ef7e + f765a2c commit 7289120
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
14 changes: 14 additions & 0 deletions entry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package donburi

import (
"bytes"
"fmt"
"unsafe"

"github.com/yohamta/donburi/internal/component"
Expand Down Expand Up @@ -131,3 +133,15 @@ func (e *Entry) Archetype() *storage.Archetype {
func (e *Entry) HasComponent(componentType *component.ComponentType) bool {
return e.Archetype().Layout().HasComponent(componentType)
}

func (e *Entry) String() string {
var out bytes.Buffer
out.WriteString("Entry: {")
out.WriteString(e.Entity().String())
out.WriteString(", ")
out.WriteString(e.Archetype().Layout().String())
out.WriteString(", Valid: ")
out.WriteString(fmt.Sprintf("%v", e.Valid()))
out.WriteString("}")
return out.String()
}
6 changes: 6 additions & 0 deletions internal/entity/entity.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package entity

import "fmt"

// Entity is identifier of an entity.
// The first 32 bits are the entity id.
// The last 32 bits are the version.
Expand Down Expand Up @@ -36,3 +38,7 @@ func (e Entity) Version() uint32 {
func (e Entity) IncVersion() Entity {
return e&idMask | ((e + 1) & versionMask)
}

func (e Entity) String() string {
return fmt.Sprintf("Entity: {id: %d, version: %d}", e.Id(), e.Version())
}
20 changes: 19 additions & 1 deletion internal/storage/layout.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package storage

import "github.com/yohamta/donburi/internal/component"
import (
"bytes"
"fmt"

"github.com/yohamta/donburi/internal/component"
)

// Layout represents a layout of components.
type Layout struct {
Expand Down Expand Up @@ -39,3 +44,16 @@ func (l *Layout) HasComponent(componentType *component.ComponentType) bool {
}
return false
}

func (l *Layout) String() string {
var out bytes.Buffer
out.WriteString("Layout: {")
for i, ct := range l.componentTypes {
if i != 0 {
out.WriteString(", ")
}
out.WriteString(fmt.Sprintf("%s", ct))
}
out.WriteString("}")
return out.String()
}

0 comments on commit 7289120

Please sign in to comment.