Skip to content

Commit

Permalink
style: fix inconsistent project formatting (#144)
Browse files Browse the repository at this point in the history
Closes #138
  • Loading branch information
christopher-buss authored Oct 12, 2024
1 parent 1b50fa3 commit 0eb288e
Show file tree
Hide file tree
Showing 45 changed files with 3,163 additions and 3,151 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Run Stylua
uses: JohnnyMorganz/stylua-action@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest # NOTE: we recommend pinning to a specific version in case of formatting changes
# CLI arguments
args: ./src
token: ${{ secrets.GITHUB_TOKEN }}
version: latest # NOTE: we recommend pinning to a specific version in case of formatting changes
# CLI arguments
args: --check ./src
33 changes: 16 additions & 17 deletions benches/cached.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

local jecs = require("@jecs")
local mirror = require("../mirror/init")

Expand Down Expand Up @@ -39,36 +38,36 @@ do

if flip() then
combination ..= "B"
ecs:set(entity, D2, {value = true})
ecs:set(entity, D2, { value = true })
end
if flip() then
combination ..= "C"
ecs:set(entity, D3, {value = true})
ecs:set(entity, D3, { value = true })
end
if flip() then
combination ..= "D"
ecs:set(entity, D4, {value = true})
ecs:set(entity, D4, { value = true })
end
if flip() then
combination ..= "E"
ecs:set(entity, D5, {value = true})
ecs:set(entity, D5, { value = true })
end
if flip() then
combination ..= "F"
ecs:set(entity, D6, {value = true})
ecs:set(entity, D6, { value = true })
end
if flip() then
combination ..= "G"
ecs:set(entity, D7, {value = true})
ecs:set(entity, D7, { value = true })
end
if flip() then
combination ..= "H"
ecs:set(entity, D8, {value = true})
ecs:set(entity, D8, { value = true })
end

if #combination == 7 then
added += 1
ecs:set(entity, D1, {value = true})
ecs:set(entity, D1, { value = true })
end
archetypes[combination] = true
end
Expand Down Expand Up @@ -117,36 +116,36 @@ do

if flip() then
combination ..= "B"
ecs:set(entity, D2, {value = true})
ecs:set(entity, D2, { value = true })
end
if flip() then
combination ..= "C"
ecs:set(entity, D3, {value = true})
ecs:set(entity, D3, { value = true })
end
if flip() then
combination ..= "D"
ecs:set(entity, D4, {value = true})
ecs:set(entity, D4, { value = true })
end
if flip() then
combination ..= "E"
ecs:set(entity, D5, {value = true})
ecs:set(entity, D5, { value = true })
end
if flip() then
combination ..= "F"
ecs:set(entity, D6, {value = true})
ecs:set(entity, D6, { value = true })
end
if flip() then
combination ..= "G"
ecs:set(entity, D7, {value = true})
ecs:set(entity, D7, { value = true })
end
if flip() then
combination ..= "H"
ecs:set(entity, D8, {value = true})
ecs:set(entity, D8, { value = true })
end

if #combination == 7 then
added += 1
ecs:set(entity, D1, {value = true})
ecs:set(entity, D1, { value = true })
end
archetypes[combination] = true
end
Expand Down
35 changes: 18 additions & 17 deletions benches/general.luau
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ local function TITLE(s: string)
print(testkit.color.white(s))
end

local N = 2^17
local N = 2 ^ 17

local pair = jecs.pair

do TITLE "create"
do
TITLE("create")
local world = jecs.World.new()

BENCH("entity", function()
Expand All @@ -22,17 +23,17 @@ do TITLE "create"
end)

local A = world:component()
local B = world:component()
local B = world:component()

BENCH("pair", function()
for i = 1, START(N) do
jecs.pair(A, B)
end
end)

end

do TITLE "set"
do
TITLE("set")

local world = jecs.World.new()
local A = world:entity()
Expand Down Expand Up @@ -65,7 +66,8 @@ end
-- we have a separate benchmark for relationships.
-- this is due to that relationships have a very high id compared to normal
-- components, which cause them to get added into the hashmap portion.
do TITLE "set relationship"
do
TITLE("set relationship")

local world = jecs.World.new()
local A = world:entity()
Expand Down Expand Up @@ -98,7 +100,8 @@ do TITLE "set relationship"
end)
end

do TITLE "get"
do
TITLE("get")

local world = jecs.World.new()
local A = world:component()
Expand Down Expand Up @@ -140,7 +143,8 @@ do TITLE "get"
end)
end

do TITLE "target"
do
TITLE("target")

BENCH("1st target", function()
local world = jecs.World.new()
Expand All @@ -164,14 +168,14 @@ do TITLE "target"
world:target(entities[i], A, 0)
end
end)

end

--- this benchmark is used to view how fragmentation affects query performance
--- we use this by determining how many entities should fit per arcehtype, instead
--- of creating x amount of archetypes. this would scale better with any amount of
--- entities.
do TITLE(`query {N} entities`)
do
TITLE(`query {N} entities`)

local function view_bench(n: number)
BENCH(`{n} entities per archetype`, function()
Expand All @@ -194,14 +198,13 @@ do TITLE(`query {N} entities`)
end
end


START()
for id in world:query(A, B, C, D) do
end
end)

BENCH(`inlined query`, function()
local world = jecs.World.new()
local world = jecs.World.new()
local A = world:component()
local B = world:component()
local C = world:component()
Expand All @@ -219,23 +222,21 @@ do TITLE(`query {N} entities`)
end
end


START()
for _, archetype in world:query(A, B, C, D):archetypes() do
local columns, records = archetype.columns, archetype.records
local columns, records = archetype.columns, archetype.records
local a = columns[records[A].column]
local b = columns[records[B].column]
local c = columns[records[C].column]
local d = columns[records[D].column]
for row in archetype.entities do
for row in archetype.entities do
local _1, _2, _3, _4 = a[row], b[row], c[row], d[row]
end
end
end)
end

for i = 13, 0, -1 do
view_bench(2^i)
view_bench(2 ^ i)
end

end
34 changes: 17 additions & 17 deletions benches/query.luau
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ do
TITLE("one component in common")

local function view_bench(world: jecs.World, A: i53, B: i53, C: i53, D: i53, E: i53, F: i53, G: i53, H: i53)
BENCH("1 component", function()
BENCH("1 component", function()
for _ in world:query(A) do
end
end)
Expand Down Expand Up @@ -86,36 +86,36 @@ do

if flip() then
combination ..= "B"
ecs:set(entity, D2, {value = true})
ecs:set(entity, D2, { value = true })
end
if flip() then
combination ..= "C"
ecs:set(entity, D3, {value = true})
ecs:set(entity, D3, { value = true })
end
if flip() then
combination ..= "D"
ecs:set(entity, D4, {value = true})
ecs:set(entity, D4, { value = true })
end
if flip() then
combination ..= "E"
ecs:set(entity, D5, {value = true})
ecs:set(entity, D5, { value = true })
end
if flip() then
combination ..= "F"
ecs:set(entity, D6, {value = true})
ecs:set(entity, D6, { value = true })
end
if flip() then
combination ..= "G"
ecs:set(entity, D7, {value = true})
ecs:set(entity, D7, { value = true })
end
if flip() then
combination ..= "H"
ecs:set(entity, D8, {value = true})
ecs:set(entity, D8, { value = true })
end

if #combination == 7 then
added += 1
ecs:set(entity, D1, {value = true})
ecs:set(entity, D1, { value = true })
end
archetypes[combination] = true
end
Expand Down Expand Up @@ -202,36 +202,36 @@ do

if flip() then
combination ..= "B"
ecs:set(entity, D2, {value = true})
ecs:set(entity, D2, { value = true })
end
if flip() then
combination ..= "C"
ecs:set(entity, D3, {value = true})
ecs:set(entity, D3, { value = true })
end
if flip() then
combination ..= "D"
ecs:set(entity, D4, {value = true})
ecs:set(entity, D4, { value = true })
end
if flip() then
combination ..= "E"
ecs:set(entity, D5, {value = true})
ecs:set(entity, D5, { value = true })
end
if flip() then
combination ..= "F"
ecs:set(entity, D6, {value = true})
ecs:set(entity, D6, { value = true })
end
if flip() then
combination ..= "G"
ecs:set(entity, D7, {value = true})
ecs:set(entity, D7, { value = true })
end
if flip() then
combination ..= "H"
ecs:set(entity, D8, {value = true})
ecs:set(entity, D8, { value = true })
end

if #combination == 7 then
added += 1
ecs:set(entity, D1, {value = true})
ecs:set(entity, D1, { value = true })
end
archetypes[combination] = true
end
Expand Down
46 changes: 22 additions & 24 deletions benches/visual/despawn.bench.luau
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,35 @@ local ecs = jecs.World.new()
local A, B = Matter.component(), Matter.component()
local C, D = ecs:component(), ecs:component()


return {
ParameterGenerator = function()
local matter_entities = {}
local jecs_entities = {}
local entities = {
matter = matter_entities,
jecs = jecs_entities
}
for i = 1, 1000 do
table.insert(matter_entities, newWorld:spawn(A(), B()))
local e = ecs:entity()
ecs:set(e, C, {})
ecs:set(e, D, {})
table.insert(jecs_entities, e)
end
return entities
end;
local matter_entities = {}
local jecs_entities = {}
local entities = {
matter = matter_entities,
jecs = jecs_entities,
}
for i = 1, 1000 do
table.insert(matter_entities, newWorld:spawn(A(), B()))
local e = ecs:entity()
ecs:set(e, C, {})
ecs:set(e, D, {})
table.insert(jecs_entities, e)
end
return entities
end,

Functions = {
Matter = function(_, entities)
for _, entity in entities.matter do
newWorld:despawn(entity)
end
end;

for _, entity in entities.matter do
newWorld:despawn(entity)
end
end,

Jecs = function(_, entities)
for _, entity in entities.jecs do
for _, entity in entities.jecs do
ecs:delete(entity)
end
end;
};
end,
},
}
Loading

0 comments on commit 0eb288e

Please sign in to comment.