Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/golangci_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Golangci-lint

on:
push

jobs:
test:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6.1.1
with:
version: v1.60
4 changes: 1 addition & 3 deletions archetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ func (world *World) getArchetype(entityRecord EntityRecord) *Archetype {
return &world.archetypes[archetypeId]
}

func (world *World) setArchetype(entityRecord EntityRecord, archetype *Archetype) error {
func (world *World) setArchetype(entityRecord EntityRecord, archetype *Archetype) {
archetype.entities = append(archetype.entities, entityRecord.Id)

entityRecord.key = len(archetype.entities) - 1
entityRecord.archetypeId = archetype.Id
world.Entities[entityRecord.Id] = entityRecord

return nil
}

func (world *World) getArchetypeForComponentsIds(componentsIds ...ComponentId) *Archetype {
Expand Down
2 changes: 1 addition & 1 deletion component.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (world *World) getComponentsIds(components ...ComponentInterface) []Compone

func ConfigureComponent[T ComponentInterface](world *World, conf any) T {
var t T
componentRegistry, _ := world.ComponentsRegistry[t.GetComponentId()]
componentRegistry := world.ComponentsRegistry[t.GetComponentId()]

componentRegistry.builderFn(&t, conf)

Expand Down
48 changes: 30 additions & 18 deletions component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,61 +42,47 @@ func (t testComponent2) GetComponentId() ComponentId {
}

type testComponent3 struct {
testComponent
}

func (t testComponent3) GetComponentId() ComponentId {
return testComponent3Id
}

type testComponent4 struct {
testComponent
}

func (t testComponent4) GetComponentId() ComponentId {
return testComponent4Id
}

type testComponent5 struct {
testComponent
}

func (t testComponent5) GetComponentId() ComponentId {
return testComponent5Id
}

type testComponent6 struct {
testComponent
}

func (t testComponent6) GetComponentId() ComponentId {
return testComponent6Id
}

type testComponent7 struct {
testComponent
}

func (t testComponent7) GetComponentId() ComponentId {
return testComponent7Id
}

type testComponent8 struct {
testComponent
}

func (t testComponent8) GetComponentId() ComponentId {
return testComponent8Id
}

type testComponent9 struct {
testComponent
}

func (t testComponent9) GetComponentId() ComponentId {
return testComponent9Id
}

func TestAddComponent(t *testing.T) {
entities := make([]EntityId, TEST_ENTITY_NUMBER)
world := CreateWorld(1024)
Expand Down Expand Up @@ -126,6 +112,18 @@ func TestAddComponent(t *testing.T) {
}

func TestConfigureComponent(t *testing.T) {
world := CreateWorld(1024)
RegisterComponent[testComponent1](world, &ComponentConfig[testComponent1]{ID: testComponent1Id, BuilderFn: func(component any, configuration any) {
conf := configuration.(testComponent1Configuration)
testTransformComponent := component.(*testComponent1)

testTransformComponent.x = conf.x
}})

component := ConfigureComponent[testComponent1](world, testComponent1Configuration{testComponent{x: 1.0}})
if component.x != 1.0 {
t.Errorf("component was not correctly configured")
}
}

func TestGetComponent(t *testing.T) {
Expand All @@ -137,8 +135,15 @@ func TestGetComponent(t *testing.T) {

for i := 0; i < TEST_ENTITY_NUMBER; i++ {
entities[i] = world.CreateEntity(fmt.Sprint(i))
AddComponent(world, entities[i], testComponent1{})
AddComponent(world, entities[i], testComponent2{})
err := AddComponent(world, entities[i], testComponent1{})
if err != nil {
t.Errorf("%s", err.Error())
}

err = AddComponent(world, entities[i], testComponent2{})
if err != nil {
t.Errorf("%s", err.Error())
}
}

for _, entityId := range entities {
Expand All @@ -159,8 +164,15 @@ func TestRemoveComponent(t *testing.T) {

for i := 0; i < TEST_ENTITY_NUMBER; i++ {
entities[i] = world.CreateEntity(fmt.Sprint(i))
AddComponent(world, entities[i], testComponent1{testComponent{x: i, y: i, z: i}})
AddComponent(world, entities[i], testComponent2{testComponent{x: i, y: i, z: i}})
err := AddComponent(world, entities[i], testComponent1{testComponent{x: i, y: i, z: i}})
if err != nil {
t.Errorf("%s", err.Error())
}

err = AddComponent(world, entities[i], testComponent2{testComponent{x: i, y: i, z: i}})
if err != nil {
t.Errorf("%s", err.Error())
}
}

// Remove the component only on odd entities. Otherwise we empty the archetype, it would not prove the indices in storage are perfectly handled
Expand Down
Loading