-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
312 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = false | ||
insert_final_newline = false | ||
|
||
[*.ts] | ||
indent_size = 2 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,53 @@ | ||
|
||
function filterComponentInfos(infos: ComponentInfo[], prefix: string): string[] { | ||
return infos | ||
.filter(info => info.name.startsWith(prefix)) | ||
.map(info => info.name.replace(prefix, "")); | ||
} | ||
|
||
|
||
let firstIteration = true; | ||
let i = 0; | ||
function run() { | ||
if (firstIteration) { | ||
firstIteration = false; | ||
|
||
info("Components: " + filterComponentInfos(world.components, "bevy_transform::")); | ||
info("Resources: " + filterComponentInfos(world.resources, "breakout::").join(", ")); | ||
class Debug implements BevyScript { | ||
firstIteration = true; | ||
i = 0; | ||
update() { | ||
if (this.firstIteration) { | ||
this.firstIteration = false; | ||
|
||
info( | ||
"Components: " + | ||
filterComponentInfos(world.components, "bevy_transform::") | ||
); | ||
info( | ||
"Resources: " + | ||
filterComponentInfos(world.resources, "breakout::").join(", ") | ||
); | ||
} | ||
|
||
|
||
i++; | ||
if (i % 60 == 0) { | ||
let ballId = world.components.find(info => info.name == "breakout::Ball").id; | ||
let velocityId = world.components.find(info => info.name == "breakout::Velocity").id; | ||
let transformId = world.components.find(info => info.name == "bevy_transform::components::transform::Transform").id; | ||
|
||
const ballQuery = world.query({ | ||
components: [ballId, transformId, velocityId], | ||
}); | ||
for (const item of ballQuery) { | ||
let [ball, transform, velocity] = item.components; | ||
velocity = velocity[0]; | ||
|
||
info(velocity.toString()); | ||
} | ||
this.i++; | ||
if (this.i % 60 == 0) { | ||
let ballId = world.components.find( | ||
(info) => info.name == "breakout::Ball" | ||
).id; | ||
let velocityId = world.components.find( | ||
(info) => info.name == "breakout::Velocity" | ||
).id; | ||
let transformId = world.components.find( | ||
(info) => | ||
info.name == "bevy_transform::components::transform::Transform" | ||
).id; | ||
|
||
const ballQuery = world.query({ | ||
components: [ballId, transformId, velocityId], | ||
}); | ||
for (const item of ballQuery) { | ||
let [ball, transform, velocity] = item.components; | ||
velocity = velocity[0]; | ||
|
||
info(velocity.toString()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function init() { | ||
return { | ||
update: run, | ||
}; | ||
export default new Debug(); | ||
|
||
function filterComponentInfos( | ||
infos: ComponentInfo[], | ||
prefix: string | ||
): string[] { | ||
return infos | ||
.filter((info) => info.name.startsWith(prefix)) | ||
.map((info) => info.name.replace(prefix, "")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,49 @@ | ||
function filterComponentInfos(infos: ComponentInfo[], prefix: string): string[] { | ||
return infos | ||
.filter(info => info.name.startsWith(prefix)) | ||
.map(info => info.name.replace(prefix, "")); | ||
} | ||
|
||
function componentId(name) { | ||
let id = world.components.find(info => info.name === name); | ||
if (!id) throw new Error(`component id for ${name} not found`); | ||
return id.id; | ||
|
||
} | ||
|
||
let firstIteration = true; | ||
function run() { | ||
if (firstIteration) { | ||
firstIteration = false; | ||
|
||
// info("Components: " + world.components.map(info => info.name).join(", ")); | ||
// info("Resources:"); | ||
// info(world.resources.map(info => info.name)); | ||
// info("Resources (headless): " + filterComponentInfos(world.resources, "headless::").join(", ")); | ||
// info("Entitites: " + (world.entities.map(entity => `Entity(${entity.id}v${entity.generation})`).join(", "))); | ||
info("----------"); | ||
|
||
let transformId = componentId("bevy_transform::components::transform::Transform"); | ||
|
||
|
||
let query = world.query({ | ||
components: [transformId] | ||
}); | ||
let [transform1, transform2] = query.map(item => item.components[0]); | ||
let [translation1, translation2] = [transform1.translation, transform2.translation]; | ||
|
||
for (const s of [0.0, 0.25, 0.5, 0.75, 1.0]) { | ||
info(translation1.lerp(translation2, s).toString()); | ||
} | ||
export default { | ||
update() { | ||
if (firstIteration) { | ||
firstIteration = false; | ||
|
||
info("Components: " + world.components.map(info => info.name).join(", ")); | ||
info("Resources:"); | ||
info(world.resources.map(info => info.name)); | ||
info("Resources (headless): " + filterComponentInfos(world.resources, "headless::").join(", ")); | ||
info("Entitites: " + (world.entities.map(entity => `Entity(${entity.id}v${entity.generation})`).join(", "))); | ||
|
||
info("----------"); | ||
|
||
let transformId = componentId( | ||
"bevy_transform::components::transform::Transform" | ||
); | ||
|
||
let query = world.query({ | ||
components: [transformId], | ||
}); | ||
let [transform1, transform2] = query.map((item) => item.components[0]); | ||
let [translation1, translation2] = [ | ||
transform1.translation, | ||
transform2.translation, | ||
]; | ||
|
||
for (const s of [0.0, 0.25, 0.5, 0.75, 1.0]) { | ||
info(translation1.lerp(translation2, s).toString()); | ||
} | ||
} | ||
}, | ||
}; | ||
|
||
function componentId(name: string) { | ||
let id = world.components.find((info) => info.name === name); | ||
if (!id) throw new Error(`component id for ${name} not found`); | ||
return id.id; | ||
} | ||
|
||
function init() { | ||
return { | ||
update: run, | ||
} | ||
} | ||
function filterComponentInfos( | ||
infos: ComponentInfo[], | ||
prefix: string | ||
): string[] { | ||
return infos | ||
.filter((info) => info.name.startsWith(prefix)) | ||
.map((info) => info.name.replace(prefix, "")); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// log.s | ||
declare function trace(val: any): void; | ||
declare function debug(val: any): void; | ||
declare function info(val: any): void; | ||
declare function warn(val: any): void; | ||
declare function error(val: any): void; | ||
|
||
// ecs.js | ||
declare interface BevyScript { | ||
first?: () => void; | ||
pre_update?: () => void; | ||
update?: () => void; | ||
post_update?: () => void; | ||
last?: () => void; | ||
} | ||
|
||
declare class ComponentId { | ||
index: number; | ||
} | ||
declare class Entity { | ||
id: number; | ||
generation: number; | ||
} | ||
|
||
declare interface ComponentInfo { | ||
id: ComponentId; | ||
name: string; | ||
size: number; | ||
} | ||
|
||
declare interface QueryDescriptor { | ||
components: ComponentId[]; | ||
} | ||
|
||
declare interface QueryItem { | ||
entity: Entity; | ||
components: any[]; | ||
} | ||
|
||
declare type Primitive = number | string | boolean; | ||
declare interface Value { | ||
[path: string | number]: Value | Primitive | undefined; | ||
} | ||
|
||
declare class World { | ||
get components(): ComponentInfo[]; | ||
get resources(): ComponentInfo[]; | ||
get entities(): Entity[]; | ||
|
||
query(descriptor: QueryDescriptor): QueryItem[]; | ||
} | ||
|
||
declare const world: World; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.