
#include "GameWorld.h"
#include "GameObject.h"
#include "GameNetInterface.h"
#include "GameConnection.h"

using namespace TNL;
using namespace DinastyOnline::Network;

namespace DinastyOnline {
	namespace Network {

		GameWorld::~GameWorld() {
		}
		
		void GameWorld::addToGameObjectList(GameObject *theObject) {
			mGameObjects.push_back(theObject);
		}
	
		void GameWorld::removeFromGameObjectList(GameObject *theObject) {
			for(S32 i = 0; i < mGameObjects.size(); i++) {
				if(mGameObjects[i] == theObject) {
					mGameObjects.erase_fast(i);
					return;
				}
			}
			TNLAssert(0, "Object not in game's list!");
		}
		
		void GameWorld::setScopeAlwaysObject(GameObject *theObject) {
			mScopeAlwaysList.push_back(theObject);
		}
	
		void GameWorld::idle() {
			TNL::U32 currentTime = TNL::Platform::getRealMilliseconds();
			if(currentTime == lastTime) {
				return;
			}
	
			TNL::F32 timeDelta = (currentTime - lastTime) / 1000.0f;
			for(TNL::S32 i = 0; i < mGameObjects.size(); i++) {
				mGameObjects[i]->idle(timeDelta);
			}
			theNetInterface->idle();
			lastTime = currentTime;
		}
	}

}
