Esempio n. 1
0
std::string GetConfsInt(std::string Name, std::string Namespace, LuaManager &L)
{
    std::string Retval;
    if (Namespace.length())
    {
        if (L.UseArray(Namespace))
        {
			if (L.CallFunction(Name.c_str(), 0, 1)) {
				if (L.RunFunction())
					Retval = L.GetFunctionResultS();
			}
			else {
				Retval = L.GetFieldS(Name);
			}
			L.Pop();
		}
    }
    else {
		if (L.CallFunction(Name.c_str(), 0, 1)) {
			if (L.RunFunction())
				Retval = L.GetFunctionResultS();
		} else
	        Retval = L.GetGlobalS(Name);
	}
    return Retval;
}
Esempio n. 2
0
double GetConffInt(std::string Name, std::string Namespace, LuaManager &L)
{
    double Retval = 0;
    if (Namespace.length())
    {
        if (L.UseArray(Namespace))
        {
			if (L.CallFunction(Name.c_str(), 0, 1)) {
				if (L.RunFunction())
					Retval = L.GetFunctionResultD();
			}
			else {
				Retval = L.GetFieldD(Name, 0);
			}

			L.Pop();
        }
    }
    else {
		if (L.CallFunction(Name.c_str(), 0, 1)) {
			if (L.RunFunction())
				Retval = L.GetFunctionResultD();
		} else
	        Retval = L.GetGlobalD(Name, 0);
	}
    return Retval;
}
	int SetTarget(lua_State *L)
	{
		GraphObject2D *Target = *GetUserObject<GraphObject2D*> (L, 1, GraphObject2DMetatable);
		LuaManager *Lua = GetObjectFromState<LuaManager>(L, "Luaman");
		Lua->RegisterStruct("Target", Target);
		return 0;
	}
Esempio n. 4
0
void Purity::PhysicsSystem::runUpdateScripts()
{
    LuaManager* luaManager = LuaManager::getManager();
	std::string physicsUpdateScript = mCurrentScene->getLuaPhysicsUpdatePath();

	luaManager->doFile(physicsUpdateScript);
}
	int Require(lua_State *L)
	{
		LuaManager *Lua = GetObjectFromState<LuaManager>(L, "Luaman");
		GString Request = luaL_checkstring(L, 1);
		GString File = GameState::GetInstance().GetSkinScriptFile(Request.c_str());
		lua_pushboolean(L, Lua->Require(File));
		return 1;
	}
Esempio n. 6
0
/*
	注册C++调用Lua函数的界面
*/
static int lua_SetScript( lua_State* L )
{
	LuaManager* pl = LuaManager::getSingletonPtr();
	if( pl )
	{
		return pl->SetScript( L );
	}
	return 0;
}
Esempio n. 7
0
float ScreenSelectMusic::GetListVerticalTransformation(const float Y)
{
    LuaManager *Lua = Animations->GetEnv();
    if (Lua->CallFunction("TransformListVertical", 1, 1))
    {
        Lua->PushArgument(Y);
        Lua->RunFunction();
        return Lua->GetFunctionResultF();
    }
    else return 0;
}
Esempio n. 8
0
double GetConffInt(String Name, String Namespace, LuaManager &L)
{
	double Retval;
	if (Namespace.length())
	{
		L.UseArray(Namespace);
		Retval = L.GetFieldD(Name, 0);
		L.Pop();
	}else
		Retval = L.GetGlobalD(Name, 0);

	return Retval;
}
Esempio n. 9
0
String GetConfsInt(String Name, String Namespace, LuaManager &L)
{
	String Retval;
	if (Namespace.length())
	{
		L.UseArray(Namespace);
		Retval = L.GetFieldS(Name);
		L.Pop();
	}else
		Retval = L.GetGlobalS(Name);

	return Retval;
}
Esempio n. 10
0
//-----------------------------------------------------------------------------
bool L_App::OnInit()
{
	PX2_ENGINELOOP.Initlize();


	PX2_ENGINELOOP.Play(EngineLoop::PT_NONE);

	LuaManager *luaMan = (LuaManager*)ScriptManager::GetSingletonPtr();
	luaMan->CallFile("DataLauncher/scripts/language.lua");

	luaMan->CallFile("DataLauncher/scripts/start.lua");

	wxLog::SetLogLevel(0);

	wxImage::AddHandler(new wxBMPHandler());
	wxImage::AddHandler(new wxPNGHandler());
	wxImage::AddHandler(new wxGIFHandler());
	wxFileSystem::AddHandler(new wxArchiveFSHandler());
	wxXmlResource::Get()->InitAllHandlers();
	//wxXmlResource::Get()->Load(wxT("DataLauncher/wxfbp/*.xrc"));

	int displayWidth, displayHeight;
	wxDisplaySize(&displayWidth, &displayHeight);

	std::string title = "Launcher";
	title += Renderer::GetRenderTag();

#if defined(_WIN64) || defined(WIN64)
	title += "64";
#endif

#ifdef _DEBUG
	title += "D";
#endif

	mMainFrame = new L_MainFrame(title, 0, 0, wxMin(1024, displayWidth), wxMin(768, displayHeight));
	mMainFrame->SetMinClientSize(wxSize(800, 600));
	//luaMan->SetUserTypePointer("L_MainFrame", "L_MainFrame", mMainFrame);

	mMainFrame->Initlize();
	SetTopWindow(mMainFrame);
	mMainFrame->Center();

	//PX2_ENGINELOOP.SetPt_Data(mMainFrame->GetRenderViewScene()->GetHandle());
	//PX2_ENGINELOOP.SetPt_Size(Sizef(1024.0f, 768.0f));
	//PX2_ENGINELOOP.InitlizeRenderer();

	mMainFrame->Show(true);

	return true;
}
Esempio n. 11
0
void Purity::PhysicsSystem::handleInput()
{
    std::string luaEventHandlerFileName = mCurrentScene->getLuaEventHandlerPath();
    std::string luaEventHandlerFunction = mCurrentScene->getLuaEventHandlerFunctionName();
    LuaManager* luaManager = LuaManager::getManager();
    lua_State* luaState = luaManager->getState();
    
    while (!mInputQueue->empty())
    {
	    sf::Event event = mInputQueue->front();
	    mInputQueue->pop();
	
	    luaManager->doFile(luaEventHandlerFileName);

	    luabind::call_function<void>(luaState, luaEventHandlerFunction.c_str(), event);
    }
}
void ScreenGameplay7K::UpdateScriptScoreVariables()
{
	LuaManager *L = Animations->GetEnv();
	L->SetGlobal("Combo", score_keeper->getScore(ST_COMBO));
	L->SetGlobal("MaxCombo", score_keeper->getScore(ST_MAX_COMBO));
	L->SetGlobal("Accuracy", score_keeper->getPercentScore(PST_ACC));
	L->SetGlobal("EXScore", score_keeper->getScore(ST_EX));
	L->SetGlobal("SCScore", score_keeper->getScore(ST_SCORE));
	L->SetGlobal("LifebarValue", score_keeper->getLifebarAmount(LT_GROOVE));
}
Esempio n. 13
0
//-----------------------------------------------------------------------------
bool E_App::OnInit()
{
	PX2_ENGINELOOP.Initlize();
	PX2_EDIT.LoadEditorTheme();
	NirMan *nirMan = new0 NirMan();
	nirMan->Initlize();

	PX2_ENGINELOOP.Play(EngineLoop::PT_NONE);

	LuaManager *luaMan = (LuaManager*)ScriptManager::GetSingletonPtr();
	luaMan->CallFile("DataEditor/scripts/language.lua");
	tolua_PX2Editor_open(luaMan->GetLuaState());

	luaMan->CallFile("DataEditor/scripts/start.lua");

	luaMan->SetUserTypePointer("NirMan", "NirMan", nirMan);

	wxLog::SetLogLevel(0);

	wxImage::AddHandler(new wxBMPHandler());
	wxImage::AddHandler(new wxPNGHandler());
	wxImage::AddHandler(new wxGIFHandler());
	wxFileSystem::AddHandler(new wxArchiveFSHandler());
	wxXmlResource::Get()->InitAllHandlers();
	wxXmlResource::Get()->Load(wxT("DataEditor/wxfbp/*.xrc"));

	int displayWidth, displayHeight;
	wxDisplaySize(&displayWidth, &displayHeight);

	std::string title = "Nirvana";
	title += Renderer::GetRenderTag();

#if defined(_WIN64) || defined(WIN64)
	title += "64";
#endif

#ifdef _DEBUG
	title += "D";
#endif

	mMainFrame = new E_MainFrame(title, 0, 0, wxMin(1024, displayWidth), wxMin(768, displayHeight));

	luaMan->SetUserTypePointer("E_MainFrame", "E_MainFrame", mMainFrame);

	mMainFrame->Initlize();
	SetTopWindow(mMainFrame);
	mMainFrame->Center();
	mMainFrame->Maximize();

	PX2_ENGINELOOP.SetPt_Data(mMainFrame->GetRenderViewScene()->GetHandle());
	PX2_ENGINELOOP.SetPt_Size(Sizef(1024.0f, 768.0f));
	PX2_ENGINELOOP.InitlizeRenderer();

	mMainFrame->Show(true);

	return true;
}
Esempio n. 14
0
void doLua()
{
	LuaManager L;
	int s;
	char* err;
	cout << "Starting lua!" << endl;
	L.reg_func("afunc", my_function);
	s = L.load("scripts/test2.lua");
	err = const_cast<char*>(L.errors(s));
	if (err)
		cout << err << endl;
	else
		s = L.exec(0, 0);
		err = const_cast<char*>(L.errors(s));
		if (err)
			cout << err << endl;
	cout << "Completed doing lua!" << endl;
}
Esempio n. 15
0
static int rum_post_config(apr_pool_t *p, apr_pool_t *pLog, apr_pool_t *pTmp,
                           server_rec *s)
{
    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                 "BEG post_config hook");


    // since creating the RUM Config instance can be time consuming,
    // do it only once
    void *data;
    const char *userdata_key = "rum_post_config_only_once_key";
    apr_pool_userdata_get(&data, userdata_key, s->process->pool);
    if (!data) {
        apr_pool_userdata_set((const void *)1, userdata_key,
                              apr_pool_cleanup_null, s->process->pool);
        return OK;
    }


    rum_server_config *sc_main = NULL;
    server_rec *s2;
    for (s2 = s; s2; s2 = s2->next)
    {
        rum_server_config *sc2 =
            static_cast<rum_server_config *>
            (ap_get_module_config(s2->module_config, &rum_module));

        // is this the main server
        bool isMain = (s == s2);

        if (isMain)
        {
            sc_main = sc2;
        }

        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s2,
                     "RUM: processing "
                     "server: %s, defined at %s:%d",
                     s2->server_hostname, s2->defn_name,
                     s2->defn_line_number);

        if (sc2->useMain)
        {
            if (isMain)
            {
                ap_log_error(APLOG_MARK, APLOG_ERR, 0, s2,
                             "RumUseMain not allowed for main server");
                return HTTP_INTERNAL_SERVER_ERROR;
            }
            else
            {
                if (sc2->configFiles->size() > 0)
                {
                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s2,
                                 "RumConfigFile directive not allowed here "
                                 "because RumUseMain specified for virtual "
                                 "server: %s, defined at %s:%d",
                                 s2->server_hostname, s2->defn_name,
                                 s2->defn_line_number);
                    return HTTP_INTERNAL_SERVER_ERROR;
                }
                if (sc2->baseDir)
                {
                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s2,
                                 "RumBaseDir directive not allowed here "
                                 "because RumUseMain specified for virtual "
                                 "server: %s, defined at %s:%d",
                                 s2->server_hostname, s2->defn_name,
                                 s2->defn_line_number);
                    return HTTP_INTERNAL_SERVER_ERROR;
                }
                if (sc2->maxLookups)
                {
                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s2,
                                 "RumMaxLookups directive not allowed here "
                                 "because RumUseMain specified for virtual "
                                 "server: %s, defined at %s:%d",
                                 s2->server_hostname, s2->defn_name,
                                 s2->defn_line_number);
                    return HTTP_INTERNAL_SERVER_ERROR;
                }
                if (sc2->fullLuaGC)
                {
                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s2,
                                 "RumFullLuaGC directive not allowed here "
                                 "because RumUseMain specified for virtual "
                                 "server: %s, defined at %s:%d",
                                 s2->server_hostname, s2->defn_name,
                                 s2->defn_line_number);
                    return HTTP_INTERNAL_SERVER_ERROR;
                }
                if (sc2->initLuaStatePoolSize)
                {
                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s2,
                                 "RumInitialLuaStatePoolSize "
                                 "directive not allowed here "
                                 "because RumUseMain specified for virtual "
                                 "server: %s, defined at %s:%d",
                                 s2->server_hostname, s2->defn_name,
                                 s2->defn_line_number);
                    return HTTP_INTERNAL_SERVER_ERROR;
                }

                // refer to the main server's RUM Config
                if (!sc_main->conf)
                {
                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s2,
                                 "RumConfigFile directive not specified "
                                 "for main server but "
                                 "RumUseMain specified for virtual "
                                 "server: %s, defined at %s:%d",
                                 s2->server_hostname, s2->defn_name,
                                 s2->defn_line_number);
                    return HTTP_INTERNAL_SERVER_ERROR;
                }
                ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s2,
                             "using main RUM config for "
                             "server: %s, defined at %s:%d",
                             s2->server_hostname, s2->defn_name,
                             s2->defn_line_number);
                sc2->conf = sc_main->conf;
            }
        }
        else
        {
            // RumUseMain not specified

            if ((sc2->server == s2) && (sc2->configFiles->size() > 0))
            {
                ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s2,
                             "configuring RUM for "
                             "server: %s, defined at %s:%d",
                             s2->server_hostname, s2->defn_name,
                             s2->defn_line_number);

                rum::ServerLogger *logger =
                    new (p) rum::ServerLogger(0,
#if RUM_AP22
                                              s2->loglevel,
#else
                                              s2->log.level,
                                              APLOG_MODULE_INDEX,
#endif
                                              s2);
                logger->destroyWithPool();

                const char *baseDir;
                if (sc2->baseDir)
                {
                    const char *rootpath;
                    const char *filepath = sc2->baseDir;
                    if (apr_filepath_root(&rootpath, &filepath,
                                          APR_FILEPATH_TRUENAME, pTmp) ==
                        APR_SUCCESS)
                    {
                        baseDir = sc2->baseDir;
                    }
                    else
                    {
                        // relative RumBaseDir is relative to server root
                        baseDir = rum_base_dir_relative(pTmp,
                                                        ap_server_root,
                                                        sc2->baseDir);
                    }

                }
                else
                {
                    baseDir = ap_server_root;
                }

                apr_ssize_t maxLookups =
                    sc2->maxLookups ? sc2->maxLookups : 10;

                LuaManager *luaManager =
                    new (p, PoolAllocated::UseSubPools)
                    LuaManager(0, logger, baseDir);
                luaManager->destroyWithPool();

                sc2->conf = new (p) Config(0, logger, pTmp, baseDir,
                                           *sc2->configFiles, maxLookups,
                                           luaManager);
                sc2->conf->destroyWithPool();

                if (sc2->conf->ctorError())
                {
                    return HTTP_INTERNAL_SERVER_ERROR;
                }

                // pre-initialize some Lua states
                if (sc2->initLuaStatePoolSize >= 0)
                {
                    apr_size_t ilsps = sc2->initLuaStatePoolSize;

                    // initialize at least one state so that run-time errors
                    // in the definitions section are caught
                    apr_size_t minInitStates = ilsps ? ilsps : 1;

                    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s2,
                                 "initializing %d Lua states for "
                                 "server: %s, defined at %s:%d",
                                 static_cast<int>(minInitStates),
                                 s2->server_hostname, s2->defn_name,
                                 s2->defn_line_number);

                    PtrVec<LuaManager::LuaRef *> *luaRefVec =
                        new (p, PoolAllocated::UseSubPools)
                        PtrVec<LuaManager::LuaRef *>(0, minInitStates);
                    apr_size_t i;
                    for (i = 0; i < minInitStates; i++)
                    {
                        LuaManager::LuaRef *luaRef =
                            new (p) LuaManager::LuaRef(p, luaManager);
                        if (! luaRef->isValid())
                        {
                            ap_log_error(APLOG_MARK, APLOG_ERR,
                                         0, s2,
                                         "failed to initialize Lua state for "
                                         "server: %s, defined at %s:%d",
                                         s2->server_hostname, s2->defn_name,
                                         s2->defn_line_number);
                            return HTTP_INTERNAL_SERVER_ERROR;
                        }
                        luaRefVec->push_back(luaRef);
                    }
                    delete luaRefVec;
                }
            }
            else
            {
                if ((sc2->server == s2) && sc2->baseDir)
                {
                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s2,
                                 "RumBaseDir "
                                 "directive not allowed here "
                                 "because RumConfigFile not specified "
                                 "for server: %s, defined at %s:%d",
                                 s2->server_hostname, s2->defn_name,
                                 s2->defn_line_number);
                    return HTTP_INTERNAL_SERVER_ERROR;
                }
                if ((sc2->server == s2) && sc2->maxLookups)
                {
                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s2,
                                 "RumMaxLookups "
                                 "directive not allowed here "
                                 "because RumConfigFile not specified "
                                 "for server: %s, defined at %s:%d",
                                 s2->server_hostname, s2->defn_name,
                                 s2->defn_line_number);
                    return HTTP_INTERNAL_SERVER_ERROR;
                }
                if ((sc2->server == s2) && sc2->fullLuaGC)
                {
                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s2,
                                 "RumFullLuaGC "
                                 "directive not allowed here "
                                 "because RumConfigFile not specified "
                                 "for server: %s, defined at %s:%d",
                                 s2->server_hostname, s2->defn_name,
                                 s2->defn_line_number);
                    return HTTP_INTERNAL_SERVER_ERROR;
                }
                if ((sc2->server == s2) && sc2->initLuaStatePoolSize)
                {
                    ap_log_error(APLOG_MARK, APLOG_ERR, 0, s2,
                                 "RumInitialLuaStatePoolSize "
                                 "directive not allowed here "
                                 "because RumConfigFile not specified "
                                 "for server: %s, defined at %s:%d",
                                 s2->server_hostname, s2->defn_name,
                                 s2->defn_line_number);
                    return HTTP_INTERNAL_SERVER_ERROR;
                }

                ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s2,
                             "RUM not configured for "
                             "server: %s, defined at %s:%d",
                             s2->server_hostname, s2->defn_name,
                             s2->defn_line_number);
            }
        }
    }

    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
                 "END post_config");

    return OK;
}
// Called every time a note is hit or missed, before the lua events
void ScreenGameplay7K::UpdateScriptScoreVariables()
{
	LuaManager *L = Animations->GetEnv();
	L->SetGlobal("Combo", ScoreKeeper->getScore(ST_COMBO));
	L->SetGlobal("MaxCombo", ScoreKeeper->getScore(ST_MAX_COMBO));
	L->SetGlobal("Accuracy", ScoreKeeper->getPercentScore(PST_ACC));
	L->SetGlobal("SCScore", ScoreKeeper->getScore(scoring_type));
	L->SetGlobal("EXScore", ScoreKeeper->getScore(ST_EX));

	std::pair<GString, int> autopacemaker = ScoreKeeper->getAutoRankPacemaker();
	L->SetGlobal("PacemakerText", autopacemaker.first);
	L->SetGlobal("PacemakerValue", autopacemaker.second);

	L->SetGlobal("AccText", "ACC:");
	L->SetGlobal("AccValue", ScoreKeeper->getPercentScore(PST_EX));

	double lifebar_amount = ScoreKeeper->getLifebarAmount(lifebar_type);
	L->SetGlobal("LifebarValue", lifebar_amount);
	if (lifebar_type == LT_GROOVE || lifebar_type == LT_EASY)
		L->SetGlobal("LifebarDisplay", max(2, int(floor(lifebar_amount * 50) * 2)));
	else
		L->SetGlobal("LifebarDisplay", int(ceil(lifebar_amount * 50) * 2));

}
// Called every frame, before the lua update event
void ScreenGameplay7K::UpdateScriptVariables()
{
	LuaManager *L = Animations->GetEnv();
	L->SetGlobal("SpeedMultiplier", SpeedMultiplier);
	L->SetGlobal("SpeedMultiplierUser", SpeedMultiplierUser);
	L->SetGlobal("waveEffectEnabled", waveEffectEnabled);
	L->SetGlobal("Active", Active);
	L->SetGlobal("SongTime", SongTime);

	L->SetGlobal("Beat", CurrentBeat);

	L->NewArray();

	for (uint32 i = 0; i < CurrentDiff->Channels; i++)
	{
		L->SetFieldI(i + 1, HeldKey[i]);
	}

	L->FinalizeArray("HeldKeys");

	float CurBPS = SectionValue(BPS, WarpedSongTime);
	L->SetGlobal("CurrentSPB", 1 / CurBPS);
	L->SetGlobal("CurrentBPM", 60 * CurBPS);
}
// Called right after the scorekeeper and the engine's objects are initialized.
void ScreenGameplay7K::SetupScriptConstants()
{
	LuaManager *L = Animations->GetEnv();
	L->SetGlobal("Upscroll", Upscroll);
	L->SetGlobal("Channels", CurrentDiff->Channels);
	L->SetGlobal("JudgmentLineY", JudgmentLinePos);
	L->SetGlobal("Auto", Auto);
	L->SetGlobal("AccuracyHitMS", ScoreKeeper->getMissCutoff());
	L->SetGlobal("SongDuration", CurrentDiff->Duration);
	L->SetGlobal("SongDurationBeats", IntegrateToTime(BPS, CurrentDiff->Duration));
	L->SetGlobal("WaitingTime", WaitingTime);
	L->SetGlobal("Beat", CurrentBeat);
	L->SetGlobal("Lifebar", ScoreKeeper->getLifebarAmount(lifebar_type));
	L->SetGlobal("SpecialStyle", CurrentDiff->Data->Turntable);

	luabridge::push(L->GetState(), &BGA->GetTransformation());
	lua_setglobal(L->GetState(), "Background");
}
	int FallbackRequire(lua_State *L)
	{
		LuaManager *Lua = GetObjectFromState<LuaManager>(L, "Luaman");
		lua_pushboolean(L, Lua->Require(GameState::GetInstance().GetFallbackSkinFile(luaL_checkstring(L, 1))));
		return 1;
	}
	int Require(lua_State *L)
	{
		LuaManager *Lua = GetObjectFromState<LuaManager>(L, "Luaman");
		lua_pushboolean(L, Lua->RunScript(FileManager::GetSkinPrefix() + luaL_checkstring(L, 1)));
		return 1;
	}
//----------------------------------------------------------------------------
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;
}
Esempio n. 22
0
void ArenaLocker::_handleScript()
{
	LuaManager* lua = LuaManager::getSingletonPtr();
	lua->clearLuaStack();
	lua->prepFunction("Arena_CameraMovement");
	//lua->pushFunctionArgVector(_camera->getPosition());

	if(_deltaTime == 0)
	{
		lua->pushFunctionArg(16.0f);
	}
	else
	{
		lua->pushFunctionArg(_deltaTime);
	}
	lua->callFunction(1,3);

	//check for returned values
	lua_State* luaS = lua->getLuaState();
	//assume it's a vector that's being returned. Otherwise some seriously f****d up shit is going on.
	Ogre::Vector3 targetVector = Ogre::Vector3::UNIT_X;
	Ogre::Vector3 lookVector = Ogre::Vector3::UNIT_X;
	if(lua_istable(luaS,1))
	{
		targetVector = LuaManager::getVectorFromLua(luaS,1);
	}

	if(lua_istable(luaS,2))
	{
		lookVector = LuaManager::getVectorFromLua(luaS,2);
	}

	//Movement time
	if(lua_isnumber(luaS,3))
	{
		_cameraMovementTime = lua_tonumber(luaS,3);
	}
	else
	{
		_cameraMovementTime = 0.0f;
	}

	//Target Vector
	if(targetVector == Ogre::Vector3::ZERO)
	{
		_stateShutdown = true;
	}
	else
	{
		_cameraPositionTarget = targetVector;
	}

	//Look vector
	if(lookVector != Ogre::Vector3::ZERO)
	{
		//lookVector = _camera->getPosition() + lookVector;
		if(lookVector != _oldCameraLookTarget)
		{
			std::cout << "CameraLookTarget changed!" << std::endl;
			std::cout << "New LookTarget:" << lookVector << std::endl;
			_oldCameraLookTarget = _cameraLookTarget;
			_cameraLookTarget = lookVector;
			_oldCameraOrientation = _camera->getOrientation();
		}
	}

	

	/*
	_cameraMovementTime += .001f;
	if(_cameraMovementTime > 1.0f)
	{
		_cameraMovementTime = 0.0f;
	}

	LuaManager::getSingletonPtr()->clearLuaStack();
	LuaManager::getSingletonPtr()->prepFunction("Bezier_Test");
	LuaManager::getSingletonPtr()->pushFunctionArg(_cameraMovementTime);
	//LuaManager::getSingletonPtr()->_printStack();
	LuaManager::getSingletonPtr()->callFunction(1,1);

	//get the vector from it.
	Ogre::Vector2 tmp = Ogre::Vector2::ZERO;
	lua_State* l = LuaManager::getSingleton().getLuaState();
	if(lua_istable(l,1))
	{
		for(int i = 1; i < 3; ++i)
		{
			lua_pushnumber(l,i);
			lua_gettable(l,1);
			if(lua_isnumber(l,-1))
			{
				tmp[i-1] = static_cast<float>(lua_tonumber(l,-1));
			}
			else
			{
				tmp[i-1] = 0;
			}
			lua_pop(l,1);
		}
	}

	if(tmp != Ogre::Vector2::ZERO)
	{
		_sphere->setPosition(tmp.x,1.0f,tmp.y);
	}
	LuaManager::getSingletonPtr()->clearLuaStack();
	*/

	//handle updating the camera in another function.
	//keeps this one cleaner.

	return;
}
//----------------------------------------------------------------------------
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;
}