home *** CD-ROM | disk | FTP | other *** search
- class GDK.World extends GDK.Generic
- {
- var children;
- var objects;
- var updateList;
- var displayQueue;
- var activeObjects;
- var name;
- var viewport;
- var world;
- var target;
- var engine;
- var onUpdate;
- static var worldsCreated = -1;
- var useDefaultCamera = true;
- var className = "World";
- var isDisplayNode = true;
- var renderable = true;
- var affectChildren = false;
- var objectsAdded = 0;
- function World(name, viewPort)
- {
- super();
- this.uniqueID = ++GDK.World.worldsCreated;
- this.children = null;
- this.objects = [];
- this.updateList = new GDK.Collection();
- this.displayQueue = [];
- this.activeObjects = new GDK.Collection();
- this.name = name == null ? "World " + this.uniqueID : name;
- if(this.viewport)
- {
- this.addObject(this.viewport);
- }
- else if(this.useDefaultCamera)
- {
- this.addObject(this.viewport = new GDK.Camera());
- }
- this.world = this;
- }
- function addActiveObject(obj)
- {
- return this.activeObjects.addMember(obj);
- }
- function removeActiveObject(obj)
- {
- if(!obj.__a)
- {
- return undefined;
- }
- delete obj.__a;
- var _loc2_ = this.activeObjects.length;
- while((_loc2_ = _loc2_ - 1) > -1)
- {
- if(this.activeObjects[_loc2_] == obj)
- {
- this.activeObjects.splice(_loc2_,1);
- return undefined;
- }
- }
- }
- function addToUpdateList(obj)
- {
- return this.updateList.addMember(obj);
- }
- function removeFromUpdateList(obj)
- {
- return this.updateList.removeMember(obj);
- }
- function sendUpdates(elapsed)
- {
- this.updateList.update(elapsed);
- }
- function render(elapsed)
- {
- var _loc2_ = undefined;
- if(!(_loc2_ = this.displayQueue.length))
- {
- return undefined;
- }
- while((_loc2_ = _loc2_ - 1) > -1)
- {
- this.displayQueue[_loc2_].setDisplay(elapsed);
- delete this.displayQueue[_loc2_].queueForDisplay;
- }
- this.displayQueue = [];
- updateAfterEvent();
- }
- function centerViewport(vertical, horizontal)
- {
- this.viewport.halfWidth = this.target._x = (this.viewport.screenWidth = this.engine.width) * 0.5;
- this.viewport.halfHeight = this.target._y = (this.viewport.screenHeight = this.engine.height) * 0.5;
- }
- function queueForDisplay(obj)
- {
- if(!obj.queueForDisplay)
- {
- return undefined;
- }
- obj.queueForDisplay = null;
- this.displayQueue.push(obj);
- }
- function update(elapsed)
- {
- this.sendUpdates(elapsed);
- this.onUpdate(elapsed);
- this.render(elapsed);
- }
- function addObject(obj, isolated)
- {
- if(obj.world == this)
- {
- return false;
- }
- if(obj.world)
- {
- obj.world.removeObject(obj);
- }
- this.objects.push(obj);
- obj.world = this;
- obj.uniqueID = this.objectsAdded++;
- if(obj.children.length)
- {
- var _loc3_ = obj.children.length;
- while((_loc3_ = _loc3_ - 1) > -1)
- {
- this.addObject(obj.children[_loc3_],true);
- }
- }
- if(!isolated)
- {
- this.addChild(obj,true);
- }
- obj.positionChanged(0,0,0);
- obj.onAddToWorld();
- return true;
- }
- function removeObject(obj)
- {
- obj.removeFromScene();
- this.removeChild(obj);
- var _loc2_ = this.objects.length;
- while((_loc2_ = _loc2_ - 1) > -1)
- {
- if(this.objects[_loc2_] == obj)
- {
- this.objects.splice(_loc2_,1);
- break;
- }
- }
- GDK.Collection.removeFromAll(obj);
- this.removeFromUpdateList(obj);
- obj.onRemoveFromWorld();
- }
- function addChild(obj, isolated)
- {
- super.addChild(obj,true);
- }
- function timelineUpdate(elapsed)
- {
- this.render(elapsed);
- }
- }
-