-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
186abc6
commit 9afbcf7
Showing
17 changed files
with
334 additions
and
25 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 |
---|---|---|
@@ -1,5 +1,37 @@ | ||
var nextActorGuid = 0; | ||
export default class Actor { | ||
constructor() { | ||
|
||
this.parent = null; | ||
this.id = nextActorGuid++; | ||
this.components = {}; | ||
this.children = []; | ||
this.eventManager = null; | ||
} | ||
|
||
addComponent(component) { | ||
component.setActor(this); | ||
this.components[component.type] = component; | ||
} | ||
|
||
getComponent(type) { | ||
return this.components[type] | ||
} | ||
|
||
removeComponent() { | ||
|
||
} | ||
|
||
addChild() { | ||
|
||
} | ||
|
||
setEventManager(eventManager) { | ||
this.eventManager = eventManager; | ||
} | ||
|
||
removeChild() { | ||
|
||
} | ||
|
||
|
||
} |
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,9 @@ | ||
import Actor from "./Actor"; | ||
import Transform3D from "./Transform3D"; | ||
|
||
export default class Actor3D extends Actor { | ||
constructor() { | ||
super(); | ||
this.addComponent(new Transform3D()); | ||
} | ||
} |
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,10 @@ | ||
export default class Component { | ||
constructor(type) { | ||
this.type = type; | ||
this.actor = null; | ||
} | ||
|
||
setActor(actor) { | ||
this.actor = actor; | ||
} | ||
} |
Empty file.
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,36 @@ | ||
/* | ||
var STATES = { | ||
UNINITIALIZED : 0, | ||
RUNNING : 1, | ||
SUCCEDED : 2, | ||
FAILED : 3 | ||
}*/ | ||
|
||
export default class Process { | ||
constructor(){ | ||
this.state = "UNINITIALIZED"; | ||
this.children = []; | ||
} | ||
|
||
initialize(){ | ||
this.state = "RUNNING"; | ||
} | ||
|
||
succeed(){ | ||
this.state = "SUCCEDED"; | ||
} | ||
|
||
succeed(){ | ||
this.state = "FAILED"; | ||
} | ||
|
||
addChild(child) { | ||
this.children.push(child); | ||
} | ||
|
||
update(deltaMs){ | ||
|
||
} | ||
} | ||
|
||
export {states} |
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,26 @@ | ||
export default class ProcessManager { | ||
constructor(){ | ||
this.processes = []; | ||
} | ||
|
||
addChild(proc) { | ||
this.processes.push(proc); | ||
} | ||
|
||
update(deltaMs){ | ||
for(let proc of this.processes){ | ||
if(proc.state === "UNINITIALIZED"){ | ||
proc.initialize(); | ||
} | ||
|
||
if(proc.state === "RUNNING"){ | ||
proc.update(deltaMs); | ||
} | ||
|
||
if(proc.state === "SUCCEEDED"){ | ||
proc.succeed(); | ||
this.processes.push(...this.children); | ||
} | ||
} | ||
} | ||
} |
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,13 @@ | ||
import Actor3D from "./Actor3D"; | ||
|
||
export default class Scene3D extends Actor3D { | ||
constructor() { | ||
super(); | ||
this.actors = {}; | ||
} | ||
|
||
addChild(child){ | ||
super.addChild(child); | ||
this.actors[child.id] = child; | ||
} | ||
} |
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,42 @@ | ||
import Component from "./Component.js"; | ||
|
||
|
||
export default class Transform3D extends Component { | ||
constructor() { | ||
super("transform"); | ||
|
||
this._position = vec3.create(); | ||
this._rotation = vec3.create(); | ||
|
||
this.toWorld = mat4.create(); | ||
mat4.identity(this.toWorld); | ||
} | ||
|
||
get position () { | ||
return vec3.clone(this._position); | ||
} | ||
|
||
set position (position) { | ||
this._position = position; | ||
this.updateMatrix(); | ||
eventManager.emit("actor:move", this.actor); | ||
} | ||
|
||
get rotation () { | ||
return vec3.clone(this._rotation); | ||
} | ||
|
||
set rotation (rotation) { | ||
this._rotation = rotation; | ||
this.updateMatrix(); | ||
eventManager.emit("actor:move", this.actor); | ||
} | ||
|
||
updateMatrix() { | ||
//set matrix according to values in rotation/position; | ||
//TODO assume this works fine. | ||
for(let child of this.actor.children){ | ||
child.updateMatrix(); | ||
} | ||
} | ||
} |
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,21 @@ | ||
|
||
|
||
var request = (type, url, progress, data) => { | ||
return new Promise((resolve, reject) => { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener("progress", progress); | ||
xhr.addEventListener("load", resolve); | ||
xhr.addEventListener("error", reject); | ||
xhr.open(type, url); | ||
xhr.send(data); | ||
}) | ||
} | ||
|
||
var get = (url, async, progress) => { | ||
return request("GET", url, progress, null); | ||
} | ||
var post = (url, async, progress, data) => { | ||
return request("POST", url, progress, data); | ||
} | ||
|
||
export {get, post, request}; |
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,33 @@ | ||
var createShader = (gl, type, src) => { | ||
var shader = gl.createShader(type); | ||
gl.shaderSource(shader, src); | ||
gl.compileShader(shader); | ||
if(!gl.getShaderParameter(shader, gl.COMPILE_STATUS)){ | ||
console.log(gl.getShaderInfoLog(shader)); | ||
return null;//or somthing else? | ||
} | ||
} | ||
|
||
var createProgram = (gl, vSrc, fSrc) => { | ||
var program = gl.createProgram(); | ||
gl.attachShader(createShader(gl.VERTEX_SHASDER, vSrc)); | ||
gl.attachShader(createShader(gl.FRAGMENT_SHADER, fSrc)); | ||
gl.linkProgram(); | ||
if(!gl.getProgramParameter(program, gl.LINK_STATUS)) { | ||
console.log("FAILED TO COMPILE SHADER"); | ||
return null; | ||
} | ||
return program; | ||
} | ||
|
||
var createTexture = () => { | ||
|
||
} | ||
|
||
var createBufferWithData = (gl, type, data, usage) => { | ||
var buffer = gl.createBuffer(); | ||
gl.bindBuffer(type, usage); | ||
gl.bufferData(type, data, usage); | ||
gl.bindBuffer(type, null); | ||
return buffer; | ||
} |
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 @@ | ||
{"test":12} |
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,19 @@ | ||
import Process from "engine/core/Process" | ||
|
||
export default class TimerProcess extends Process { | ||
constructor(delay, cb) { | ||
super(); | ||
this.cb = cb; | ||
this.delay = delay; | ||
this.reference = Date.now();//@TODO change this to some uniform game clock; | ||
} | ||
|
||
update() { | ||
var now = Date.now(); | ||
var dif = now - this.reference; | ||
if(dif > this.delay) { | ||
this.reference += this.delay; | ||
this.cb(); | ||
} | ||
} | ||
} |
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,5 +1,50 @@ | ||
import asad from "./js/test" | ||
import Actor from "engine/core/Actor" | ||
import Cache from "engine/core/Cache" | ||
import asad from "./js/test"; | ||
import Actor from "engine/core/Actor"; | ||
import Cache from "engine/core/Cache"; | ||
import {getEventManager} from "engine/core/EventManager"; | ||
import Actor3D from "engine/core/Actor3D"; | ||
import Scene3D from "engine/core/Scene3D"; | ||
import EventEmitter from "events"; | ||
import ProcessManager from "engine/core/ProcessManager"; | ||
import TimerProcess from "./js/TimerProcess" | ||
|
||
console.log(Actor, Cache) | ||
|
||
eventManager = new EventEmitter(); | ||
processManager = new ProcessManager(); | ||
scene = new Scene3D(); | ||
cache = new Cache(); | ||
|
||
//test actor | ||
var actor = new Actor3D(); | ||
eventManager.on("actor:move", (actor) => { | ||
console.log("Actor : " + actor.id + " Moved!") | ||
}) | ||
|
||
|
||
//test cache | ||
cache.get("assets/test.json").then((data)=>{ | ||
console.log(data) | ||
}, (err) => { | ||
console.log(err) | ||
}) | ||
|
||
//test processes | ||
processManager.addChild(new TimerProcess(1000, ()=>{ | ||
var pos = vec3.create(); | ||
actor.getComponent("transform").position = pos; | ||
})) | ||
|
||
|
||
|
||
//game loop thingy (not using req anim frame because reasons) | ||
|
||
|
||
var last = Date.now(); | ||
setInterval( () => { | ||
var now = Date.now(); | ||
var deltaMs = now - last; | ||
last = now; | ||
|
||
|
||
processManager.update(deltaMs); | ||
}, 17) |
Oops, something went wrong.