示例#1
0
//----------------------------------------------------------------------------
bool ServerLoop::Initlize()
{
	InitializeNetwork();

	time_t ti; time(&ti); srand((unsigned int)ti);

#ifdef PX2_USE_MEMORY
	Memory::Initialize();
#endif

	StringHelp::Initlize();
	FString::Initlize();

	Logger *logger = new0 Logger();

#if defined(_WIN32) || defined(WIN32)
	logger->AddFileHandler("log_server.txt", LT_INFO | LT_ERROR | LT_USER);
#endif
	logger->AddOutputWindowHandler(LT_INFO | LT_ERROR | LT_USER);
	logger->AddConsoleHandler(LT_INFO | LT_ERROR | LT_USER);
	logger->SetLogFileInfo(false);
	logger->StartLogger();

	LocalDateTime time;
	int year1 = time.Year();
	int month1 = time.Month();
	int week1 = time.Week();
	int dayOfMonth1 = time.Day();
	int dayOfWeek1 = time.DayOfWeek();
	int dayOfYear1 = time.DayOfYear();
	int hour1 = time.Hour();
	int minute1 = time.Minute();
	int second1 = time.Second();
	int millisecond1 = time.Millisecond();
	int microsecond1 = time.Microsecond();
	PX2_LOG_INFO("Y:%d; M:%d; W:%d; DayfMonth:%d; DayOfWeek:%d; H:%d; M:%d; S:%d; Milli:%d; MicroS:%d",
		year1, month1, week1, dayOfMonth1, dayOfWeek1, hour1, minute1, second1, millisecond1, microsecond1);

	return true;
}
//----------------------------------------------------------------------------
bool EngineLoop::Initlize()
{
	time_t ti; time(&ti); srand((unsigned int)ti);

#ifdef PX2_USE_MEMORY
	Memory::Initialize();
#endif

	StringHelp::Initlize();
	FString::Initlize();

	Logger *logger = new0 Logger();

#if defined(_WIN32) || defined(WIN32)
	logger->AddFileHandler("PX2Application_Log.txt", LT_INFO | LT_ERROR | LT_USER);
#endif
	logger->AddOutputWindowHandler(LT_INFO | LT_ERROR | LT_USER);
	logger->StartLogger();

	LocalDateTime time;
	int year1 = time.Year();
	int month1 = time.Month();
	int week1 = time.Week();
	int day1 = time.Day();
	int dayOfWeek1 = time.DayOfWeek();
	int dayOfYear1 = time.DayOfYear();
	int hour1 = time.Hour();
	int minute1 = time.Minute();
	int second1 = time.Second();
	int millisecond1 = time.Millisecond();
	int microsecond1 = time.Microsecond();
	PX2_LOG_INFO("Year:%d; Month:%d; Week:%d; Day:%d; DayOfWeek:%d; DayOfYear:%d; Hour:%d; Minute:%d; Second:%d; Millisecond:%d; Microsecond:%d",
		year1, month1, week1, day1, dayOfWeek1, dayOfYear1, hour1, minute1, second1, millisecond1, microsecond1);

	mTimerMan = new0 TimerManager();

	mIMEDisp = new0 IMEDispatcher();

	mInputMan = new0 InputManager();

	mLanguageMan = new0 LanguageManager();
	mResMan = new0 ResourceManager();

	//PX2_LM.Add("Data/engine/engineLanguage.csv");

	mEventWorld = new0 EventWorld();

	mScriptMan = new0 LuaManager();

	mRoot = new0 GraphicsRoot();
	mRoot->Initlize();

	mFontMan = new0 FontManager();
	PX2_UNUSED(mFontMan);

	mADMan = new0 AddDeleteManager();
	PX2_UNUSED(mADMan);

	mSelection = new0 Selection();
	PX2_UNUSED(mSelection);

	mCreater = new0 Creater();
	PX2_UNUSED(mCreater);

	mURDoMan = new0 URDoManager();
	PX2_UNUSED(mURDoMan);

	mAccoutManager = new0 AccoutManager();

	LuaManager *luaMan = (LuaManager*)mScriptMan;
	tolua_PX2_open(luaMan->GetLuaState());

	mScriptMan->SetUserTypePointer("PX2_ENGINELOOP", "EngineLoop", this);
	mScriptMan->SetUserTypePointer("PX2_LOG", "Logger", Logger::GetSingletonPtr());
	mScriptMan->SetUserTypePointer("PX2_LM", "LanguageManager", &(PX2_LM));
	mScriptMan->SetUserTypePointer("PX2_RM", "ResourceManager", ResourceManager::GetSingletonPtr());
	mScriptMan->SetUserTypePointer("PX2_SM", "ScriptManager", ScriptManager::GetSingletonPtr());
	mScriptMan->SetUserTypePointer("PX2_SELECTION", "Selection", Selection::GetSingletonPtr());
	mScriptMan->SetUserTypePointer("PX2_CREATER", "Creater", Creater::GetSingletonPtr());
	mScriptMan->SetUserTypePointer("PX2_URM", "URDoManager", URDoManager::GetSingletonPtr());

	LoadBoost("Data/boost.xml");

	return true;
}
//----------------------------------------------------------------------------
bool ApplicationBase::Initlize ()
{
	if (msIsInitlized)
		return true;

	// srand
	time_t ti;
	time(&ti);
	srand((unsigned int)ti);

#ifdef PX2_USE_MEMORY
	Memory::Initialize();
#endif

	StringHelp::Initlize();
	FString::Initlize();

	Logger *logger = new0 Logger();

#if defined(_WIN32) || defined(WIN32)
	logger->AddFileHandler("PX2Application_Log.txt", LT_INFO|LT_ERROR|LT_USER);
#endif
	logger->AddOutputWindowHandler(LT_INFO|LT_ERROR|LT_USER);
	logger->StartLogger();

	InitializeNetwork();

	DateTime time;
	int year1 = time.Year();
	int month1 = time.Month();
	int week1 = time.Week();
	int day1 = time.Day();
	int dayOfWeek1 = time.DayOfWeek();
	int dayOfYear1 = time.DayOfYear();
	int hour1 = time.Hour();
	int minute1 = time.Minute();
	int second1 = time.Second();
	int millisecond1 = time.Millisecond();
	int microsecond1 = time.Microsecond();
	PX2_LOG_INFO("Year:%d; Month:%d; Week:%d; Day:%d; DayOfWeek:%d; DayOfYear:%d; Hour:%d; Minute:%d; Second:%d; Millisecond:%d; Microsecond:%d",
		year1, month1, week1, day1, dayOfWeek1, dayOfYear1, hour1, minute1, second1, millisecond1, microsecond1);

	PX2_LOG_INFO("Begin ApplicationBase::Initlize.");

	mTimerMan = new0 TimerManager();

	mIMEDisp = new0 IMEDispatcher();
	PX2_UNUSED(mIMEDisp);

	mLanguageMan = new0 LanguageManager();

	mResMan = new0 ResourceManager();
	PX2_LM.Add("Data/engine/engineLanguage.csv");

	mEventWorld = new0 EventWorld();
	mEventWorld->ComeIn(this);

#if defined (PX2_LUA)
	mScriptMan = ScriptManager::Create(ScriptManager::ST_LUA);
	LuaManager *luaMan = (LuaManager*)mScriptMan;
	tolua_PX2_open(luaMan->GetLuaState());
#endif
	mScriptEventHandler = new0 ScriptEventHandler();
	mEventWorld->ComeIn(mScriptEventHandler);

	mRoot = new0 GraphicsRoot();
	mRoot->Initlize();

	//mDBM = new0 DynamicBufferManager();
	//mDBM->Initlize();

	mGameMan = new0 GameManager();
	mGameMan->LoadBoost("Data/boost.xml");
	int width = mGameMan->GetBoostWidth();
	int height = mGameMan->GetBoostHeight();
#ifdef __MARMALADE__
	width = s3eSurfaceGetInt(S3E_SURFACE_DEVICE_WIDTH);
	height = s3eSurfaceGetInt(S3E_SURFACE_DEVICE_HEIGHT);
#endif
	std::string projPath = mGameMan->GetProjectPath();
	if (0!=width && 0!=height)
	{
		mWidth = width;
		mHeight = height;
	}

	mInputEventAdapter = new0 InputEventAdapter(); // input manager created in it
	mInputEventAdapter->Convert2Touch(true);

	mFontMan = new0 FontManager();
	PX2_UNUSED(mFontMan);

	mUIManager = new0 UIManager();
	mEventWorld->ComeIn(mUIManager);
	mInputEventAdapter->GetInputEventListener()->AddHandler(mUIManager->GetDefaultView());

	SoundSystemInitInfo info;
	info.MaxChannels = 24;
	info.DopplerScale = 1.0f;
	info.DistanceFactor = 100.0f;
	info.RolloffScale = 1.2f;
#if defined(_WIN32) || defined(WIN32)
	mSoundSystem = SoundSystem::Create(SoundSystem::ST_FMOD, info);
#elif defined (__ANDROID__) || defined(__MARMALADE__)
	mSoundSystem = SoundSystem::Create(SoundSystem::ST_ANDROID, info);
#endif

	mProject = new0 Project();
	mProject->SetInGamePlay(true);
	mProject->Load(projPath);
#if defined (__ANDROID__) || defined(__MARMALADE__)
	if (AST_960X640==mScreenSuitType)
	{
		mProject->SetWidth(960.0f);
		mProject->SetHeight(640.0f);
	}
	else if (AST_1136X640==mScreenSuitType)
	{
		mProject->SetWidth(1136.0f);
		mProject->SetHeight(640.0f);
	}
	else if (AST_640X960 == mScreenSuitType)
	{
		mProject->SetWidth(640.0f);
		mProject->SetHeight(960.0f);
	}
	else if (AST_640X1136 == mScreenSuitType)
	{
		mProject->SetWidth(640.0f);
		mProject->SetHeight(1136.0f);
	}
#endif
	mUIManager->GetDefaultView()->SetProjSize((float)mProject->GetWidth(), (float)mProject->GetHeight());
	Float4 color = mProject->GetColor();

	bool loadDataVersion = PX2_RM.LoadDataVersionXML("Data/version.xml");
	if (!loadDataVersion)
	{
		assertion(false, "Load Data/version.xml failed.\n");
		PX2_LOG_ERROR("Load Data/version.xml failed.");
	}

	PX2_LOG_INFO("Begin ApplicationBase::OnInitlizeApp.");
	OnInitlizeApp();
	
	mInputEventAdapter->Initlize();

	PX2_LOG_INFO("Begin ApplicationBase::OnSize.");
	OnSize(width, height);

	mScriptMan->SetUserTypePointer("PX2_LOG", "Logger", Logger::GetSingletonPtr());
	mScriptMan->SetUserTypePointer("PX2_GM", "GameManager", mGameMan);
	mScriptMan->SetUserTypePointer("PX2_PROJ", "Project", mProject);
	mScriptMan->SetUserTypePointer("PX2_LM", "LanguageManager", &(PX2_LM));
	mScriptMan->SetUserTypePointer("PX2_RM", "ResourceManager", mResMan);
	mScriptMan->SetUserTypePointer("PX2_SM", "ScriptManager", mScriptMan);
	mScriptMan->SetUserTypePointer("PX2_UIM", "UIManager", mUIManager);
	mScriptMan->SetUserTypePointer("PX2_SS", "SoundSystem", mSoundSystem);
	mScriptMan->SetUserTypePointer("PX2_SOUNDM", "SoundManager", SoundManager::GetSingletonPtr());
	
	PX2_LOG_INFO("OnInitlize()");
	OnInitlize();

	msIsInitlized = true;

	return true;
}