-
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
304 additions
and
88 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, "")); | ||
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(); |
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, "")); | ||
class Headless implements BevyScript { | ||
firstIteration = true; | ||
update() { | ||
if (this.firstIteration) { | ||
this.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) { | ||
let id = world.components.find(info => info.name === name); | ||
if (!id) throw new Error(`component id for ${name} not found`); | ||
return id.id; | ||
|
||
function componentId(name: string): ComponentId { | ||
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()); | ||
} | ||
} | ||
function filterComponentInfos( | ||
infos: ComponentInfo[], | ||
prefix: string | ||
): string[] { | ||
return infos | ||
.filter((info) => info.name.startsWith(prefix)) | ||
.map((info) => info.name.replace(prefix, "")); | ||
} | ||
|
||
function init() { | ||
return { | ||
update: run, | ||
} | ||
} | ||
export default new Headless(); |
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
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,72 @@ | ||
"use strict"; | ||
|
||
((window) => { | ||
|
||
class ComponentId { | ||
index; | ||
} | ||
|
||
class Entity { | ||
#bits; | ||
id; | ||
generation; | ||
} | ||
|
||
class World { | ||
get #rid() { return 0 } | ||
|
||
toString() { | ||
return Deno.core.opSync("op_world_tostring", this.rid); | ||
} | ||
|
||
get components() { | ||
return Deno.core.opSync("op_world_components", this.rid); | ||
} | ||
|
||
get resources() { | ||
return Deno.core.opSync("op_world_resources", this.rid); | ||
} | ||
|
||
get entities() { | ||
return Deno.core.opSync("op_world_entities", this.rid); | ||
} | ||
|
||
query(descriptor) { | ||
return Deno.core.opSync("op_world_query", this.rid, descriptor) | ||
.map(({ entity, components }) => ({ | ||
entity, | ||
components: components.map(wrapValueRef), | ||
})); | ||
} | ||
} | ||
|
||
|
||
const VALUE_REF_GET_INNER = Symbol("value_ref_get_inner"); | ||
function wrapValueRef(valueRef) { | ||
// leaf primitives | ||
if (typeof valueRef !== "object") { return valueRef }; | ||
const proxy = new Proxy(valueRef, { | ||
ownKeys: (target) => { | ||
return Deno.core.opSync("op_value_ref_keys", world.rid, target); | ||
}, | ||
get: (target, p, receiver) => { | ||
switch (p) { | ||
case VALUE_REF_GET_INNER: | ||
return target; | ||
case "toString": | ||
return () => Deno.core.opSync("op_value_ref_to_string", world.rid, target); | ||
default: | ||
let valueRef = Deno.core.opSync("op_value_ref_get", world.rid, target, "." + p); | ||
return wrapValueRef(valueRef); | ||
} | ||
}, | ||
set: (target, p, value) => { | ||
Deno.core.opSync("op_value_ref_set", world.rid, target, "." + p, value); | ||
} | ||
}); | ||
return proxy; | ||
} | ||
|
||
const world = new World(); | ||
window.world = world; | ||
})(globalThis); |
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,19 @@ | ||
"use strict"; | ||
|
||
((window) => { | ||
window.trace = function (val) { | ||
Deno.core.opSync("op_log", "trace", val); | ||
} | ||
window.debug = function (val) { | ||
Deno.core.opSync("op_log", "debug", val) | ||
} | ||
window.info = function (val) { | ||
Deno.core.opSync("op_log", "info", val) | ||
} | ||
window.warn = function (val) { | ||
Deno.core.opSync("op_log", "warn", val) | ||
} | ||
window.error = function (val) { | ||
Deno.core.opSync("op_log", "error", val) | ||
} | ||
})(globalThis); |
Oops, something went wrong.