#include "cSpace.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

cSpace::cSpace(){

}

cSpace::~cSpace(){
	Close();
}

bool cSpace::Open(){
	Close();
	return true;
}

void cSpace::Close(){
	cRealObject *pObject;
	cObjectList::iterator it;

	// 활성인 객체들을 없엔다.
	it = ObjectList.begin();
	while(it != ObjectList.end()){
		pObject = *it;
		it = ObjectList.erase(it);
		delete pObject;
	}
}

int cSpace::Act(){
	// 동적 객체들을 동작시킨다.
	// 객체의 위치가 바뀌었을 경우 순서를 새로정리한다.
	cObjectList::iterator it;

	for(it = ObjectList.begin(); it != ObjectList.end(); it ++){
		(*it)->Act();
	}

	return 0;
}

BOOL cSpace::AddObject(cRealObject *pObject){
	pObject->SetSpace(this);
	ObjectList.push_back(pObject);
	return TRUE;
}

void cSpace::Show(cPicture *pDestPic, int Left, int Top, LPRECT pSrcRect){
	ShowObjects(pDestPic, Left, Top, pSrcRect);
}

void cSpace::ShowObjects(cPicture *pDestPic, int Left, int Top, LPRECT pSrcRect){
	cObjectList::iterator it;

	for(it = ObjectList.begin(); it != ObjectList.end(); it ++){
		(*it)->Show(pDestPic, Left - pSrcRect->left, Top - pSrcRect->top);
	}
}
