From ea8f54c5fd2bdfbf1959ffb13ea7a1037143a8d4 Mon Sep 17 00:00:00 2001 From: Yusef Sohail Date: Thu, 25 Feb 2016 00:27:40 -0600 Subject: [PATCH] rename project to cruft, eliminate dependencies in core/ classes, begin documentation on core classes --- .eslintrc | 7 ++ {engine => cruft}/README.md | 0 {engine => cruft}/components/Lifetime.js | 0 {engine => cruft}/components/Sprite.js | 0 {engine => cruft}/components/Synchronizer.js | 0 {engine => cruft}/components/Transform2D.js | 0 {engine => cruft}/core/Actor.js | 38 +++----- {engine => cruft}/core/ActorFactory.js | 15 +--- {engine => cruft}/core/Cache.js | 0 {engine => cruft}/core/Component.js | 8 +- {engine => cruft}/core/Emitter.js | 0 cruft/core/MemoryManager.js | 48 +++++++++++ {engine => cruft}/core/Process.js | 0 {engine => cruft}/core/Scheduler.js | 0 {engine => cruft}/engine.js | 37 ++++---- {engine => cruft}/graphics/Camera2D.js | 0 {engine => cruft}/graphics/Program.js | 0 {engine => cruft}/graphics/ProgramManager.js | 0 {engine => cruft}/graphics/README.md | 0 {engine => cruft}/graphics/Renderer.js | 0 {engine => cruft}/graphics/RendererPlugin.js | 0 .../graphics/plugins/SpriteRenderer.js | 0 {engine => cruft}/graphics/util.js | 0 {engine => cruft}/lib/gl-matrix.js | 0 {engine => cruft}/lib/uuid.js | 0 {engine => cruft}/math/mat3.js | 0 {engine => cruft}/math/mat4.js | 0 {engine => cruft}/math/random.js | 0 {engine => cruft}/math/vec2.js | 0 {engine => cruft}/math/vec3.js | 0 {engine => cruft}/math/vec4.js | 0 {engine => cruft}/net/Connection.js | 0 {engine => cruft}/net/Network.js | 0 {engine => cruft}/net/Session.js | 0 {engine => cruft}/net/http.js | 0 {engine => cruft}/processes/Delay.js | 0 {engine => cruft}/processes/Interval.js | 0 {engine => cruft}/processes/Script.js | 0 {engine => cruft}/util/setIntervalMs.js | 0 docs/engine/core/Actor.md | 86 +++++++++++++++++++ docs/engine/math/vec2.md | 14 +-- docs/primitives.md | 6 +- engine/cache.js | 2 - engine/core/MemoryManager.js | 20 ----- engine/core/Referenceable.js | 18 ---- engine/factory.js | 2 - engine/memory.js | 26 ------ engine/network.js | 2 - engine/scheduler.js | 2 - gulpfile.js | 2 +- package.json | 14 +-- 51 files changed, 189 insertions(+), 158 deletions(-) create mode 100644 .eslintrc rename {engine => cruft}/README.md (100%) rename {engine => cruft}/components/Lifetime.js (100%) rename {engine => cruft}/components/Sprite.js (100%) rename {engine => cruft}/components/Synchronizer.js (100%) rename {engine => cruft}/components/Transform2D.js (100%) rename {engine => cruft}/core/Actor.js (65%) rename {engine => cruft}/core/ActorFactory.js (76%) rename {engine => cruft}/core/Cache.js (100%) rename {engine => cruft}/core/Component.js (60%) rename {engine => cruft}/core/Emitter.js (100%) create mode 100644 cruft/core/MemoryManager.js rename {engine => cruft}/core/Process.js (100%) rename {engine => cruft}/core/Scheduler.js (100%) rename {engine => cruft}/engine.js (73%) rename {engine => cruft}/graphics/Camera2D.js (100%) rename {engine => cruft}/graphics/Program.js (100%) rename {engine => cruft}/graphics/ProgramManager.js (100%) rename {engine => cruft}/graphics/README.md (100%) rename {engine => cruft}/graphics/Renderer.js (100%) rename {engine => cruft}/graphics/RendererPlugin.js (100%) rename {engine => cruft}/graphics/plugins/SpriteRenderer.js (100%) rename {engine => cruft}/graphics/util.js (100%) rename {engine => cruft}/lib/gl-matrix.js (100%) rename {engine => cruft}/lib/uuid.js (100%) rename {engine => cruft}/math/mat3.js (100%) rename {engine => cruft}/math/mat4.js (100%) rename {engine => cruft}/math/random.js (100%) rename {engine => cruft}/math/vec2.js (100%) rename {engine => cruft}/math/vec3.js (100%) rename {engine => cruft}/math/vec4.js (100%) rename {engine => cruft}/net/Connection.js (100%) rename {engine => cruft}/net/Network.js (100%) rename {engine => cruft}/net/Session.js (100%) rename {engine => cruft}/net/http.js (100%) rename {engine => cruft}/processes/Delay.js (100%) rename {engine => cruft}/processes/Interval.js (100%) rename {engine => cruft}/processes/Script.js (100%) rename {engine => cruft}/util/setIntervalMs.js (100%) delete mode 100644 engine/cache.js delete mode 100644 engine/core/MemoryManager.js delete mode 100644 engine/core/Referenceable.js delete mode 100644 engine/factory.js delete mode 100644 engine/memory.js delete mode 100644 engine/network.js delete mode 100644 engine/scheduler.js diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..358e775 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,7 @@ +{ + "parser": "babel-eslint", + "env": { + "browser": true, + "node": true + } +} \ No newline at end of file diff --git a/engine/README.md b/cruft/README.md similarity index 100% rename from engine/README.md rename to cruft/README.md diff --git a/engine/components/Lifetime.js b/cruft/components/Lifetime.js similarity index 100% rename from engine/components/Lifetime.js rename to cruft/components/Lifetime.js diff --git a/engine/components/Sprite.js b/cruft/components/Sprite.js similarity index 100% rename from engine/components/Sprite.js rename to cruft/components/Sprite.js diff --git a/engine/components/Synchronizer.js b/cruft/components/Synchronizer.js similarity index 100% rename from engine/components/Synchronizer.js rename to cruft/components/Synchronizer.js diff --git a/engine/components/Transform2D.js b/cruft/components/Transform2D.js similarity index 100% rename from engine/components/Transform2D.js rename to cruft/components/Transform2D.js diff --git a/engine/core/Actor.js b/cruft/core/Actor.js similarity index 65% rename from engine/core/Actor.js rename to cruft/core/Actor.js index 9e9647a..b4b625d 100644 --- a/engine/core/Actor.js +++ b/cruft/core/Actor.js @@ -1,9 +1,10 @@ -import Referenceable from "./Referenceable"; +import EventEmitter from "events"; -export default class Actor extends Referenceable { +export default class Actor { constructor(guid) { - super(guid); + super(); + this.guid = guid || uuid.create().toString(); this.parent = null; this.components = {}; this.children = {}; @@ -23,14 +24,6 @@ export default class Actor extends Referenceable { this.emit("removeComponent", component); } - destroyComponent(type) { - var component = this.components[type]; - if(!component) return; - component.destroy(); - delete this.components[type]; - this.emit("destroyComponent", com) - } - getComponent(type) { return this.components[type] } @@ -56,19 +49,18 @@ export default class Actor extends Referenceable { this.emit("removeChild", child); } - update(deltaMs) { + update(now, deltaMs) { for(let key in this.components) { - this.components[key].update(deltaMs); + this.components[key].update(now, deltaMs); } for(let id in this.children) { - this.children[id].update(deltaMs); + this.children[id].update(now, deltaMs); } } - destroy(recursive) { - super.destroy(); + destroy() { if(this.parent){ this.parent.removeChild(this); @@ -78,15 +70,9 @@ export default class Actor extends Referenceable { this.components[key].destroy(); } - if(recursive){ - for(let id in this.children) { - this.children[id].destroy(recursive); - } - } - - - this.components = null; - this.children = null; + } -} \ No newline at end of file +} + +//memory.delete(recursive) \ No newline at end of file diff --git a/engine/core/ActorFactory.js b/cruft/core/ActorFactory.js similarity index 76% rename from engine/core/ActorFactory.js rename to cruft/core/ActorFactory.js index 5a0dc4b..4e931c8 100644 --- a/engine/core/ActorFactory.js +++ b/cruft/core/ActorFactory.js @@ -1,4 +1,4 @@ -import cache from "engine/cache"; +import Actor from "./Actor"; export default class ActorFactory { //def move this to core at some point @@ -27,18 +27,9 @@ export default class ActorFactory { //def move this to core at some point } } - loadSkeletons(skeletons) { - return cache.getAll(Object.keys(skeletons)).then((assets)=>{ - for(var url in skeletons) { - this.skeletons[skeletons[url]] = assets[url]; - } - return assets; - }) - } - - create(base, type, config) {//right now can only have config code for things in a skeleton + create(type, config) {//right now can only have config code for things in a skeleton var guid = (config)? config.guid : null; - var actor = new base(guid); + var actor = new Actor(guid); var skeleton = this.skeletons[type]; var components = this.components; diff --git a/engine/core/Cache.js b/cruft/core/Cache.js similarity index 100% rename from engine/core/Cache.js rename to cruft/core/Cache.js diff --git a/engine/core/Component.js b/cruft/core/Component.js similarity index 60% rename from engine/core/Component.js rename to cruft/core/Component.js index 179c26e..152d5c5 100644 --- a/engine/core/Component.js +++ b/cruft/core/Component.js @@ -1,8 +1,6 @@ -import Referenceable from "./Referenceable"; - -export default class Component extends Referenceable { +export default class Component { - constructor(type,guid) { + constructor(type, guid) { super(guid); this.type = type; this.actor = null; @@ -16,7 +14,7 @@ export default class Component extends Referenceable { console.warn(`${this.type}:setFromJSON has not been implemented`); } - update(deltaMs) { + update(now, deltaMs) { } diff --git a/engine/core/Emitter.js b/cruft/core/Emitter.js similarity index 100% rename from engine/core/Emitter.js rename to cruft/core/Emitter.js diff --git a/cruft/core/MemoryManager.js b/cruft/core/MemoryManager.js new file mode 100644 index 0000000..5cf9c90 --- /dev/null +++ b/cruft/core/MemoryManager.js @@ -0,0 +1,48 @@ +export default class MemoryManager { + + constructor() { + this.references = {}; + } + + add(actor) { + this.references[actor.guid] = actor; + } + + destroy(actor, recursive = false) { + if(!actor) return; + delete this.references[actor.guid] + actor.destroy(); + for(var id in actor.children) { + destroy(actor.children[id], recursive); + } + } + + get(guid) { + return this.references[guid] || null; + } + + ptr(actor) { + return new Ptr(actor.guid, this); + } + +} + +class Ptr { + + constructor(guid, manager) { + this.guid = guid; + this.manager = manager; + } + + reset(actor) { + this.guid = actor.guid; + } + + get() { + return this.manager.get(this.guid); + } + + destroy(recursive = false) { + this.manager.destroy(this.get(), recursive); + } +} \ No newline at end of file diff --git a/engine/core/Process.js b/cruft/core/Process.js similarity index 100% rename from engine/core/Process.js rename to cruft/core/Process.js diff --git a/engine/core/Scheduler.js b/cruft/core/Scheduler.js similarity index 100% rename from engine/core/Scheduler.js rename to cruft/core/Scheduler.js diff --git a/engine/engine.js b/cruft/engine.js similarity index 73% rename from engine/engine.js rename to cruft/engine.js index 9499e4b..f039671 100644 --- a/engine/engine.js +++ b/cruft/engine.js @@ -1,13 +1,12 @@ import EventEmitter from "events"; - -import cache from "./cache"; -import factory from "./factory"; -import network from "./network"; -import scheduler from "./scheduler"; -import memory from "./memory" - import Script from "engine/processes/Script"; import Actor from "engine/core/Actor"; +import Cache from "./core/Cache"; +import Factory from "./core/Factory"; +import Network from "./core/Network"; +import Scheduler from "./core/Scheduler"; +import MemoryManager from "./core/MemoryManager" + export class Engine extends EventEmitter { @@ -18,8 +17,6 @@ export class Engine extends EventEmitter { } } -var engine = new Engine(); - var initialize; var initialized = new Promise((resolve, reject) => { initialize = (config) => { @@ -65,23 +62,23 @@ var initialized = new Promise((resolve, reject) => { var instantiate = (type, config) => { var actor = factory.create(Actor, type, config); memory.add(actor); - for(var key in actor.components){ - memory.add(actor.components[key]); - } return actor.toPointer(); } -var instantiateBase = (base, type, config) => { - var actor = factory.create(base, type, config); - memory.add(actor); - for(var key in actor.components){ - memory.add(actor.components[key]); - } - return actor.toPointer(); +var destroy = (actor, recursive = false) => { + memory.destroy(actor, recursive); } +var cruft = new Engine(); +var cache = new Cache(); +var factory = new Factory(); +var network = new Network(); +var scheduler = new Scheduler(); +var memory = new MemoryManager(); + + export default engine;//for now export raw factory. prob wont do that always. -export {cache, factory, network, scheduler, initialize, initialized, instantiate , instantiateBase }; +export {cache, factory, network, scheduler, memory, initialize, initialized, instantiate, destroy }; //****DEBUG****// window.engine = engine; diff --git a/engine/graphics/Camera2D.js b/cruft/graphics/Camera2D.js similarity index 100% rename from engine/graphics/Camera2D.js rename to cruft/graphics/Camera2D.js diff --git a/engine/graphics/Program.js b/cruft/graphics/Program.js similarity index 100% rename from engine/graphics/Program.js rename to cruft/graphics/Program.js diff --git a/engine/graphics/ProgramManager.js b/cruft/graphics/ProgramManager.js similarity index 100% rename from engine/graphics/ProgramManager.js rename to cruft/graphics/ProgramManager.js diff --git a/engine/graphics/README.md b/cruft/graphics/README.md similarity index 100% rename from engine/graphics/README.md rename to cruft/graphics/README.md diff --git a/engine/graphics/Renderer.js b/cruft/graphics/Renderer.js similarity index 100% rename from engine/graphics/Renderer.js rename to cruft/graphics/Renderer.js diff --git a/engine/graphics/RendererPlugin.js b/cruft/graphics/RendererPlugin.js similarity index 100% rename from engine/graphics/RendererPlugin.js rename to cruft/graphics/RendererPlugin.js diff --git a/engine/graphics/plugins/SpriteRenderer.js b/cruft/graphics/plugins/SpriteRenderer.js similarity index 100% rename from engine/graphics/plugins/SpriteRenderer.js rename to cruft/graphics/plugins/SpriteRenderer.js diff --git a/engine/graphics/util.js b/cruft/graphics/util.js similarity index 100% rename from engine/graphics/util.js rename to cruft/graphics/util.js diff --git a/engine/lib/gl-matrix.js b/cruft/lib/gl-matrix.js similarity index 100% rename from engine/lib/gl-matrix.js rename to cruft/lib/gl-matrix.js diff --git a/engine/lib/uuid.js b/cruft/lib/uuid.js similarity index 100% rename from engine/lib/uuid.js rename to cruft/lib/uuid.js diff --git a/engine/math/mat3.js b/cruft/math/mat3.js similarity index 100% rename from engine/math/mat3.js rename to cruft/math/mat3.js diff --git a/engine/math/mat4.js b/cruft/math/mat4.js similarity index 100% rename from engine/math/mat4.js rename to cruft/math/mat4.js diff --git a/engine/math/random.js b/cruft/math/random.js similarity index 100% rename from engine/math/random.js rename to cruft/math/random.js diff --git a/engine/math/vec2.js b/cruft/math/vec2.js similarity index 100% rename from engine/math/vec2.js rename to cruft/math/vec2.js diff --git a/engine/math/vec3.js b/cruft/math/vec3.js similarity index 100% rename from engine/math/vec3.js rename to cruft/math/vec3.js diff --git a/engine/math/vec4.js b/cruft/math/vec4.js similarity index 100% rename from engine/math/vec4.js rename to cruft/math/vec4.js diff --git a/engine/net/Connection.js b/cruft/net/Connection.js similarity index 100% rename from engine/net/Connection.js rename to cruft/net/Connection.js diff --git a/engine/net/Network.js b/cruft/net/Network.js similarity index 100% rename from engine/net/Network.js rename to cruft/net/Network.js diff --git a/engine/net/Session.js b/cruft/net/Session.js similarity index 100% rename from engine/net/Session.js rename to cruft/net/Session.js diff --git a/engine/net/http.js b/cruft/net/http.js similarity index 100% rename from engine/net/http.js rename to cruft/net/http.js diff --git a/engine/processes/Delay.js b/cruft/processes/Delay.js similarity index 100% rename from engine/processes/Delay.js rename to cruft/processes/Delay.js diff --git a/engine/processes/Interval.js b/cruft/processes/Interval.js similarity index 100% rename from engine/processes/Interval.js rename to cruft/processes/Interval.js diff --git a/engine/processes/Script.js b/cruft/processes/Script.js similarity index 100% rename from engine/processes/Script.js rename to cruft/processes/Script.js diff --git a/engine/util/setIntervalMs.js b/cruft/util/setIntervalMs.js similarity index 100% rename from engine/util/setIntervalMs.js rename to cruft/util/setIntervalMs.js diff --git a/docs/engine/core/Actor.md b/docs/engine/core/Actor.md index e69de29..5fdb2d7 100644 --- a/docs/engine/core/Actor.md +++ b/docs/engine/core/Actor.md @@ -0,0 +1,86 @@ +#Actor extends [Referenceable](Referenceable.js) +[engine/core/Actor.js](https://github.com/mjneil/CruftEngine/blob/master/engine/core/Actor.js) +This class defines an Actor. + +## Constructors + +### Actor( [ [guid](/primitives.md#number) ] ) +[guid](/primitives.md#number) - guid of super class [Referenceable](Referenceable.js) + +```javascript +let actor = new Actor(); +//or +let actor2 = new Actor(12); +``` + + + +## Properties +.[parent](Actor.md) - Strong reference to parent actor. +.[components](/primitives.md#object) - Object containing strong references to the actor's components. +.[children](/primitives.md#object) - Object containing strong references to the actor's children. + + +##Methods + + +### addComponent( ) +DESC + +```javascript +//example +``` + + +### removeComponent( ) +DESC + +```javascript +//example +``` + + +### getComponent( ) +DESC + +```javascript +//example +``` + +### addChild( ) +DESC + +```javascript +//example +``` + +### removeChild( ) +DESC + +```javascript +//example +``` + + +### setParent( ) +DESC + +```javascript +//example +``` + + +### update( ) +DESC + +```javascript +//example +``` + + +### destroy( ) +DESC + +```javascript +//example +``` diff --git a/docs/engine/math/vec2.md b/docs/engine/math/vec2.md index 51a3db5..dab80c3 100644 --- a/docs/engine/math/vec2.md +++ b/docs/engine/math/vec2.md @@ -21,6 +21,7 @@ let a = new vec2(1, 2); ## Static Methods + ### zero() Constructs the zero vector. @@ -28,12 +29,8 @@ Constructs the zero vector. let a = vec2.zero(); ``` - - -##Methods - -### static add( a, b ) -Adds vector a and b, returning the result. +### add( [a](/engine/math/vec2.md), [b](/engine/math/vec2.md) ) +Adds a and b, returning the result. ```javascript let a = new vec2(1, 2); @@ -41,3 +38,8 @@ let b = new vec2(3, 4); let c = vec2.add(a, b); ``` + + + +##Methods + diff --git a/docs/primitives.md b/docs/primitives.md index 11974b7..a354a27 100644 --- a/docs/primitives.md +++ b/docs/primitives.md @@ -11,9 +11,9 @@ let c = a + b; //c = 2.23456 ### Boolean ```javascript -let a = 1; -let b = 1.23456; -let c = a + b; //c = 2.23456 +let a = true; +let b = false; +let c = !b && a; //c = true ``` ### String diff --git a/engine/cache.js b/engine/cache.js deleted file mode 100644 index a7e0d5e..0000000 --- a/engine/cache.js +++ /dev/null @@ -1,2 +0,0 @@ -import Cache from "engine/core/Cache" -export default new Cache(); \ No newline at end of file diff --git a/engine/core/MemoryManager.js b/engine/core/MemoryManager.js deleted file mode 100644 index 5d17683..0000000 --- a/engine/core/MemoryManager.js +++ /dev/null @@ -1,20 +0,0 @@ -import Pointer from "./Pointer"; - -export default class MemoryManager { - - constructor() { - this.references = {}; - } - - add(referenceable) { - this.references[referenceable.guid] = referenceable; - referenceable.on("destroy", () => {//does this callback keep the actor alive? I dont think so. - delete this.references[referenceable.id]; - }) - } - - get(guid) { - return this.references[guid] || null; - } - -} \ No newline at end of file diff --git a/engine/core/Referenceable.js b/engine/core/Referenceable.js deleted file mode 100644 index f162b38..0000000 --- a/engine/core/Referenceable.js +++ /dev/null @@ -1,18 +0,0 @@ -import uuid from "engine/lib/uuid"; -import EventEmitter from "events"; -import {Pointer} from "engine/memory";//seems misleading to allow this - -export default class Referenceable extends EventEmitter { - constructor(guid) { - super(); - this.guid = guid || uuid.create().toString(); - } - - destroy() { - this.emit("destroy", this); - } - - toPointer() { - return new Pointer(this); - } -} \ No newline at end of file diff --git a/engine/factory.js b/engine/factory.js deleted file mode 100644 index 3d319b8..0000000 --- a/engine/factory.js +++ /dev/null @@ -1,2 +0,0 @@ -import ActorFactory from "engine/core/ActorFactory" -export default new ActorFactory(); \ No newline at end of file diff --git a/engine/memory.js b/engine/memory.js deleted file mode 100644 index e194bbb..0000000 --- a/engine/memory.js +++ /dev/null @@ -1,26 +0,0 @@ -import MemoryManager from "engine/core/MemoryManager"; - -var memory = new MemoryManager(); - -export default class Pointer { - - constructor(referenceable) { - this.guid = referenceable.guid; - } - - get() { - return memory.get(this.guid); - } - - isValid() { - return memory.get(this.guid) !== null; - } - - reset(referenceable) { - this.guid = referenceable.guid; - } - -} - -export default memory; -export {Pointer} \ No newline at end of file diff --git a/engine/network.js b/engine/network.js deleted file mode 100644 index 7b17d51..0000000 --- a/engine/network.js +++ /dev/null @@ -1,2 +0,0 @@ -import Network from "engine/net/Network" -export default new Network(); \ No newline at end of file diff --git a/engine/scheduler.js b/engine/scheduler.js deleted file mode 100644 index 78e8a49..0000000 --- a/engine/scheduler.js +++ /dev/null @@ -1,2 +0,0 @@ -import Scheduler from "engine/core/Scheduler" -export default new Scheduler(); \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index 36406d2..89650c7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,4 +7,4 @@ gulp.task('test:single', function (done) { configFile: __dirname + '/karma.conf.js', singleRun: true }, done).start(); -}); +}); \ No newline at end of file diff --git a/package.json b/package.json index e64f5b3..48ad837 100755 --- a/package.json +++ b/package.json @@ -19,15 +19,7 @@ "url": "https://github.com/mjneil/CruftEngine/issues" }, "devDependencies": { - "browserify": "~13.0.0", - "del": "~2.2.0", - "es6ify": "^1.6.0", - "express": "~4.13.4", "gulp": "~3.9.0", - "gulp-cached": "~1.1.0", - "gulp-concat": "~2.6.0", - "gulp-live-server": "0.0.29", - "gulp-traceur": "~0.17.2", "jasmine-core": "^2.4.1", "karma": "^0.13.21", "karma-browserify": "^5.0.1", @@ -37,10 +29,6 @@ "karma-requirejs": "^0.2.5", "karma-traceur-preprocessor": "^0.4.0", "phantomjs-prebuilt": "^2.1.4", - "requirejs": "^2.1.22", - "run-sequence": "~1.1.5", - "traceur": "0.0.102", - "vinyl-source-stream": "~1.1.0", - "watchify": "^3.7.0" + "traceur": "0.0.102" } }