Skip to content

Commit

Permalink
rename project to cruft, eliminate dependencies in core/ classes, beg…
Browse files Browse the repository at this point in the history
…in documentation on core classes
  • Loading branch information
Squeakrats committed Feb 25, 2016
1 parent ca1072d commit ea8f54c
Show file tree
Hide file tree
Showing 51 changed files with 189 additions and 158 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"parser": "babel-eslint",
"env": {
"browser": true,
"node": true
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 12 additions & 26 deletions engine/core/Actor.js → cruft/core/Actor.js
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand All @@ -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]
}
Expand All @@ -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);
Expand All @@ -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;

}
}
}

//memory.delete(recursive)
15 changes: 3 additions & 12 deletions engine/core/ActorFactory.js → cruft/core/ActorFactory.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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;
Expand Down
File renamed without changes.
8 changes: 3 additions & 5 deletions engine/core/Component.js → cruft/core/Component.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,7 +14,7 @@ export default class Component extends Referenceable {
console.warn(`${this.type}:setFromJSON has not been implemented`);
}

update(deltaMs) {
update(now, deltaMs) {

}

Expand Down
File renamed without changes.
48 changes: 48 additions & 0 deletions cruft/core/MemoryManager.js
Original file line number Diff line number Diff line change
@@ -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);
}
}
File renamed without changes.
File renamed without changes.
37 changes: 17 additions & 20 deletions engine/engine.js → cruft/engine.js
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -18,8 +17,6 @@ export class Engine extends EventEmitter {
}
}

var engine = new Engine();

var initialize;
var initialized = new Promise((resolve, reject) => {
initialize = (config) => {
Expand Down Expand Up @@ -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;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
86 changes: 86 additions & 0 deletions docs/engine/core/Actor.md
Original file line number Diff line number Diff line change
@@ -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
```
14 changes: 8 additions & 6 deletions docs/engine/math/vec2.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,25 @@ let a = new vec2(1, 2);


## Static Methods

### zero()
Constructs the zero vector.

```javascript
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);
let b = new vec2(3, 4);

let c = vec2.add(a, b);
```



##Methods

6 changes: 3 additions & 3 deletions docs/primitives.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions engine/cache.js

This file was deleted.

Loading

0 comments on commit ea8f54c

Please sign in to comment.