diff --git a/data/systemData.js b/data/systemData.js
index c7f0cbc..4c62d88 100644
--- a/data/systemData.js
+++ b/data/systemData.js
@@ -94,6 +94,7 @@ systemData = {
ships:[
{
type:"frigate",
+ id: 0,
subtype:"cruiser",
position:{
x:2780,
@@ -109,6 +110,7 @@ systemData = {
{
type:"frigate",
subtype:"cruiser",
+ id: 1,
position:{
x:2820,
y:50,
@@ -123,6 +125,7 @@ systemData = {
{
type:"frigate",
subtype:"cruiser",
+ id: 2,
position:{
x:2800,
y:50,
diff --git a/index.html b/index.html
index 0255a8a..709da10 100644
--- a/index.html
+++ b/index.html
@@ -66,7 +66,7 @@
-
+
diff --git a/js/app/EventLoop.js b/js/app/EventLoop.js
index 3a8c9c0..98bb782 100644
--- a/js/app/EventLoop.js
+++ b/js/app/EventLoop.js
@@ -13,27 +13,36 @@
};
EventLoop.prototype._getEventLoop = function() {
+
+ var x = 2780;
+ var y = 50;
+ var z = 50;
+
var self = this;
return function() {
+ x -= 1;
+ y -= 1;
+ z -= 1;
+
var tasks = self.sockets.recv();
self.sockets.flush();
+ tasks.push({
+ id: 0,
+ task: {
+ unitId: 0,
+ order: 0,
+ pos: {
+ x: x,
+ y: y,
+ z: z
+ }
+ }
+
+ });
//route the tasks
-
- for(var i = 0, len = tasks.length; i < len; ++i) {
- var task = tasks[i];
-
- if (task.id === 0 || task.id === 1) {
- self._webglController.handleUnitUpdates(task);
- } else if (task.id === 2) {
- self._webglController.handlePlayerUpdates(task);
- } else if (task.id === 3) {
- self._webglController.handlePrivateChat(task);
- } else if (task.id === 4) {
- self._webglController.handleAllianceChat(task);
- }
- }
+ self._webglController.routeUpdateEvents(tasks);
};
};
@@ -57,7 +66,7 @@ tasks: [
id: 0,
task: {
order: 0
- destinaion: {
+ pos: {
x:
y:
z:
diff --git a/js/app/controlers.app.js b/js/app/controlers.app.js
index 0778fc8..f01df2a 100644
--- a/js/app/controlers.app.js
+++ b/js/app/controlers.app.js
@@ -3,7 +3,7 @@
App.Controllers.App = function() {
var webglController = new App.Controllers.Webgl($('.gs-viewport'));
- var eventLoop = new App.eventLoop(webglController);
+ var eventLoop = new App.EventLoop(webglController);
eventLoop.start();
diff --git a/js/app/controlers.webgl.js b/js/app/controlers.webgl.js
index 2c9c4c5..8f081b4 100644
--- a/js/app/controlers.webgl.js
+++ b/js/app/controlers.webgl.js
@@ -117,22 +117,51 @@
};
- Webgl.prototype.handleUnitUpdates = function() {
-
+
+
+/*
+
+ task ids:
+
+ 0 - unit movement
+ 1 - unit position update
+ 2 - player/infrustrcuture updates
+ 3 - private chat
+ 4 - alliance chat
+
+*/
+ Webgl.prototype.routeUpdateEvents = function(tasks) {
+ for(var i = 0, len = tasks.length; i < len; ++i) {
+ var task = tasks[i];
+
+ if (task.id === 0 || task.id === 1) {
+ this.currentStage.handleUnitUpdates(task.task);
+ } else if (task.id === 2) {
+ this.currentStage.handlePlayerUpdates(task.task);
+ } else if (task.id === 3) {
+ this.currentStage.handlePrivateChat(task.task);
+ } else if (task.id === 4) {
+ this.currentStage.handleAllianceChat(task.task);
+ }
+ }
};
+ Webgl.prototype.handleUnitUpdates = function(data) {
+ this.currentStage.handleUnitUpdates(data);
+ };
- Webgl.prototype.handlePlayerUpdates = function() {
-
+
+ Webgl.prototype.handlePlayerUpdates = function(data) {
+ this.currentStage.handlePlayerUpdates(data);
};
- Webgl.prototype.handlePrivateChat = function() {
-
+ Webgl.prototype.handlePrivateChat = function(data) {
+ this.currentStage.handlePrivateChat(data);
};
- Webgl.prototype.handleAllianceChat = function() {
-
+ Webgl.prototype.handleAllianceChat = function(data) {
+ this.currentStage.handleAllianceChat(data);
};
})();
diff --git a/js/app/stage.starsystem.js b/js/app/stage.starsystem.js
index 05a7fd1..5edbee3 100644
--- a/js/app/stage.starsystem.js
+++ b/js/app/stage.starsystem.js
@@ -1,5 +1,5 @@
(function() {
- "use strict";
+ 'use strict';
var StarSystem = App.Stages.StarSystem = function(webglController) {
this._controller = webglController;
this.scene;
@@ -22,6 +22,7 @@
//ships and planets arrays
this.ships = [];
+
this.fighterPool = new App.Utilities.Pool(App.Units.Ships.Fighter);
this.carrierPool = new App.Utilities.Pool(App.Units.Ships.Carrier);
this.frigatePool = new App.Utilities.Pool(App.Units.Ships.Frigate);
@@ -37,6 +38,7 @@
'mousemove': 'onMouseMove'
};
+
// Initialize camera
this.camera = new THREE.PerspectiveCamera( 45, this._controller.$viewport.width() / this._controller.$viewport.height(), 1, 999999 );
//camera control
@@ -57,17 +59,22 @@
this.loadShips(systemData);
};
+
+
StarSystem.prototype.onDoubleClick = function(event){
var clickedPosition = this._controller.getIntersectionWithYPlane(this.camera,this.mouse,0);
new TWEEN.Tween( this.cameraLookTarget)
.to(clickedPosition, 1500)
.start()
- }
+ };
+
+
StarSystem.prototype._initializeHelpers = function(){
this.planetSelector = new THREE.Mesh( App.Res.geometries.sphere, App.Res.materials.etc.selector );
this.planetSelector.visible = false;
this.scene.add(this.planetSelector);
- }
+ };
+
StarSystem.prototype._initializeLights = function(){
var ambient = new THREE.AmbientLight( 0xffffff );
@@ -79,6 +86,7 @@
this.scene.add(pointLight);
};
+
StarSystem.prototype.loadSystem = function(data) {
@@ -109,6 +117,8 @@
}
}
};
+
+
StarSystem.prototype.loadShips = function(data){
this.fighterPool.freeAll();
this.frigatePool.freeAll();
@@ -119,7 +129,9 @@
ship.load(data.ships[i],this.scene);
this.ships.push(ship);
}
- }
+ };
+
+
StarSystem.prototype.updateCamera = function(){
var distanceVector = new THREE.Vector3(0,0,-this.cameraDistance);
App.Res.misc.rotationMatrix.setRotationX(App.Utill.degreesToRadians(this.cameraRotations.x));
@@ -134,7 +146,9 @@
this.camera.position.addSelf(distanceVector);
this.camera.lookAt(this.cameraLookTarget);
- }
+ };
+
+
StarSystem.prototype.update = function(){
//updating camera position depending on controlls
this.updateCamera();
@@ -142,6 +156,7 @@
TWEEN.update();
};
+
StarSystem.prototype.render = function(){
//not used
//postprocessing render
@@ -159,7 +174,8 @@
this.mouse.x = ( event.offsetX / $viewport.width()) * 2 - 1;
this.mouse.y = - ( event.offsetY / $viewport.height()) * 2 + 1;
this.hoverOnOneShip();
- }
+ };
+
StarSystem.prototype.selectPlanet= function(planetObject){
this.planetSelector.position = planetObject.position.clone();
@@ -171,17 +187,23 @@
new TWEEN.Tween( this.cameraLookTarget )
.to(planetObject.position, 1500 )
.start()
- }
+ };
+
+
StarSystem.prototype.deselectPlanet= function(planetObject){
this.planetSelector.visible = false;
- }
+ };
+
+
StarSystem.prototype.selectShip= function(shipObject){
this.selectedShips.push(shipObject);
shipObject.select();
new TWEEN.Tween( this.cameraLookTarget )
.to(shipObject.position, 1500 )
.start()
- }
+ };
+
+
StarSystem.prototype.deselectAll = function(){
if(this.selectedPlanet !== undefined) this.deselectPlanet(this.selectedPlanet);
for(var i = 0;i 0 ) {
- for(var i = 0;i