void Universe::InitializeSystemClass(VMClass* systemClass, VMClass* superClass, const char* name) { StdString s_name(name); if (superClass != nullptr) { systemClass->SetSuperClass(superClass); VMClass* sysClassClass = systemClass->GetClass(); VMClass* superClassClass = superClass->GetClass(); sysClassClass->SetSuperClass(superClassClass); } else { VMClass* sysClassClass = systemClass->GetClass(); sysClassClass->SetSuperClass(load_ptr(classClass)); } VMClass* sysClassClass = systemClass->GetClass(); systemClass->SetInstanceFields(NewArray(0)); sysClassClass->SetInstanceFields(NewArray(0)); systemClass->SetInstanceInvokables(NewArray(0)); sysClassClass->SetInstanceInvokables(NewArray(0)); systemClass->SetName(SymbolFor(s_name)); ostringstream Str; Str << s_name << " class"; StdString classClassName(Str.str()); sysClassClass->SetName(SymbolFor(classClassName)); SetGlobal(systemClass->GetName(), systemClass); }
ASErr Plugin::ReloadPlugin(SPInterfaceMessage * /*message*/) { ASErr error = kNoErr; if (!error) error = SetGlobal(this); // fSuites should always be nil here, but check just to be sure if (!fSuites) fSuites = new(std::nothrow) Suites; if(!fSuites) error = kOutOfMemoryErr; else { error = fSuites->Error(); fSuites->InitializeRefCount(); } if (error) { if (fSuites) delete fSuites; fSuites = nil; } if (!error) FillSuiteTables(); return error; }
Value Interpreter::MakeGlobal(const char * name) { int index = DefineGlobal(String(name)); Value global = NewObject(mObject, name); SetGlobal(index, global); return global; }
void Scene_House_Out::Logic() { EScene::Logic(); // Le joueur a répondu à la boite Yes/No demandant si il voulait un tuto if (_nYesForTutorial != -1) { // Activation du tutorial if (_nYesForTutorial == 1) { _bTutorial = true; // Démarre le tutorial _lpSceneDirector->getSequencer()->Tutobox(NULL, KStr("HOUSE_OUT_TUTO_CAR"), 776, 367, -45, 200); SetGlobal("__tutorial__","1"); } else { SetGlobal("__tutorial__","0"); } _nYesForTutorial = -1; } }
ASErr Plugin::ShutdownPlugin(SPInterfaceMessage * /*message*/) { ASErr error = kNoErr; if(fSuites) { delete fSuites; fSuites = nil; } SetGlobal(nil); return error; }
ASErr Plugin::UnloadPlugin(SPInterfaceMessage *message) { EmptySuiteTables(); SetGlobal(nil); if (fSuites) { delete fSuites; fSuites = nil; } return kNoErr; }
ASErr Plugin::ShutdownPlugin(SPInterfaceMessage *message) { if(fSuites) { delete fSuites; fSuites = nil; } SetGlobal(nil); return kNoErr; }
ASErr Plugin::StartupPlugin(SPInterfaceMessage *message) { ASErr error = kNoErr; if (!error) error = SetGlobal(this); fSuites = new(std::nothrow) Suites; if (!fSuites) error = kOutOfMemoryErr; else { error = fSuites->Error(); fSuites->InitializeRefCount(); } if (error) { if (fSuites) delete fSuites; fSuites = nil; } if (!error) { if(!error) error = sSPPlugins->SetPluginName( message->d.self, fPluginName ); if (!error) { char notifierName[kMaxStringLength]; sprintf(notifierName, "%s App Started Notifier", fPluginName); error = sAINotifier->AddNotifier(message->d.self, notifierName, kAIApplicationStartedNotifier, NULL); } } if (!error) error = AllocateSuiteTables(); if (!error) FillSuiteTables(); if(!error) error = Plugin::LockPlugin(true); return error; }
VMClass* Universe::LoadClass(VMSymbol* name) { VMClass* result = static_cast<VMClass*>(GetGlobal(name)); if (result != nullptr) return result; result = LoadClassBasic(name, nullptr); if (!result) { // we fail silently, it is not fatal that loading a class failed return (VMClass*) nilObject; } if (result->HasPrimitives() || result->GetClass()->HasPrimitives()) result->LoadPrimitives(classPath); SetGlobal(name, result); return result; }
VMClass* Universe::GetBlockClassWithArgs(long numberOfArguments) { map<long, GCClass*>::iterator it = blockClassesByNoOfArgs.find(numberOfArguments); if (it != blockClassesByNoOfArgs.end()) return load_ptr(it->second); Assert(numberOfArguments < 10); ostringstream Str; Str << "Block" << numberOfArguments; VMSymbol* name = SymbolFor(Str.str()); VMClass* result = LoadClassBasic(name, nullptr); result->AddInstancePrimitive(new (GetHeap<HEAP_CLS>()) VMEvaluationPrimitive(numberOfArguments) ); SetGlobal(name, result); # warning is _store_ptr sufficient here? blockClassesByNoOfArgs[numberOfArguments] = _store_ptr(result); return result; }
XPCWrappedNativeScope::XPCWrappedNativeScope(XPCCallContext& ccx, JSObject* aGlobal) : mRuntime(ccx.GetRuntime()), mWrappedNativeMap(Native2WrappedNativeMap::newMap(XPC_NATIVE_MAP_SIZE)), mWrappedNativeProtoMap(ClassInfo2WrappedNativeProtoMap::newMap(XPC_NATIVE_PROTO_MAP_SIZE)), mWrapperMap(WrappedNative2WrapperMap::newMap(XPC_WRAPPER_MAP_SIZE)), mComponents(nsnull), mNext(nsnull), mGlobalJSObject(nsnull), mPrototypeJSObject(nsnull), mPrototypeJSFunction(nsnull), mPrototypeNoHelper(nsnull) { // add ourselves to the scopes list { // scoped lock XPCAutoLock lock(mRuntime->GetMapLock()); #ifdef DEBUG for(XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) NS_ASSERTION(aGlobal != cur->GetGlobalJSObject(), "dup object"); #endif mNext = gScopes; gScopes = this; // Grab the XPCContext associated with our context. mContext = mRuntime->GetContextMap()->Find(ccx.GetJSContext()); NS_ASSERTION(mContext, "Context map is not synchronized"); mContext->AddScope(this); } if(aGlobal) SetGlobal(ccx, aGlobal); DEBUG_TrackNewScope(this); MOZ_COUNT_CTOR(XPCWrappedNativeScope); }
XPCWrappedNativeScope::XPCWrappedNativeScope(XPCCallContext& ccx, JSObject* aGlobal, nsISupports* aNative) : mRuntime(ccx.GetRuntime()), mWrappedNativeMap(Native2WrappedNativeMap::newMap(XPC_NATIVE_MAP_SIZE)), mWrappedNativeProtoMap(ClassInfo2WrappedNativeProtoMap::newMap(XPC_NATIVE_PROTO_MAP_SIZE)), mMainThreadWrappedNativeProtoMap(ClassInfo2WrappedNativeProtoMap::newMap(XPC_NATIVE_PROTO_MAP_SIZE)), mComponents(nsnull), mNext(nsnull), mGlobalJSObject(nsnull), mPrototypeJSObject(nsnull), mPrototypeNoHelper(nsnull), mScriptObjectPrincipal(nsnull), mNewDOMBindingsEnabled(ccx.GetRuntime()->NewDOMBindingsEnabled()) { // add ourselves to the scopes list { // scoped lock XPCAutoLock lock(mRuntime->GetMapLock()); #ifdef DEBUG for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) NS_ASSERTION(aGlobal != cur->GetGlobalJSObject(), "dup object"); #endif mNext = gScopes; gScopes = this; // Grab the XPCContext associated with our context. mContext = XPCContext::GetXPCContext(ccx.GetJSContext()); mContext->AddScope(this); } if (aGlobal) SetGlobal(ccx, aGlobal, aNative); DEBUG_TrackNewScope(this); MOZ_COUNT_CTOR(XPCWrappedNativeScope); }
void Scene_House_IncaBook::PageSet(int page) { KAssert(page < _nPages && page >= 0); _nCurrentPage = page; // Activation des zone pour tourner les pages SetVisible("livingroom_book_left",true); SetVisible("livingroom_book_right",true); if (_nCurrentPage == 0) SetVisible("livingroom_book_left",false); if (_nCurrentPage == _nPages -1) SetVisible("livingroom_book_right",false); // Efface tout SetVisible("livingroom_book_page1", false); SetVisible("txt_title_left_page1", false); SetVisible("txt_subtitle_left_page1", false); SetVisible("livingroom_book_page2", false); SetVisible("txt_title_left_page2", false); SetVisible("txt_subtitle_left_page2", false); SetVisible("txt_text_page2", false); SetVisible("livingroom_book_page3", false); SetVisible("txt_title_left_page3", false); SetVisible("txt_subtitle_left_page3", false); SetVisible("txt_text_page3", false); SetVisible("livingroom_book_page4", false); SetVisible("txt_title_left_page4", false); SetVisible("txt_subtitle_left_page4", false); SetVisible("txt_text_page4", false); SetVisible("livingroom_book_page5", false); SetVisible("txt_title_left_page5", false); SetVisible("txt_subtitle_left_page5", false); SetVisible("txt_text_page5", false); SetVisible("livingroom_book_page6", false); SetVisible("txt_title_left_page6", false); SetVisible("txt_subtitle_left_page6", false); SetVisible("txt_text_page6", false); switch (_nCurrentPage) { case 0: SetVisible("livingroom_book_page1", true); SetVisible("txt_subtitle_left_page1", true); SetVisible("txt_title_left_page1", true); break; case 1: SetVisible("livingroom_book_page2", true); SetVisible("txt_subtitle_left_page2", true); SetVisible("txt_title_left_page2", true); SetVisible("txt_text_page2", true); break; case 2: SetVisible("livingroom_book_page3", true); SetVisible("txt_subtitle_left_page3", true); SetVisible("txt_title_left_page3", true); SetVisible("txt_text_page3", true); break; case 3: SetVisible("livingroom_book_page4", true); SetVisible("txt_subtitle_left_page4", true); SetVisible("txt_title_left_page4", true); SetVisible("txt_text_page4", true); break; case 4: SetVisible("livingroom_book_page5", true); SetVisible("txt_subtitle_left_page5", true); SetVisible("txt_title_left_page5", true); SetVisible("txt_text_page5", true); break; case 5: SetVisible("livingroom_book_page6", true); SetVisible("txt_subtitle_left_page6", true); SetVisible("txt_title_left_page6", true); SetVisible("txt_text_page6", true); break; default: break; } // Mémorisation de la page courante SetGlobal(HOUSE_BOOK_CURRENT_PAGE,itos(_nCurrentPage).c_str()); }
void EInventory::Order(bool bLock) { if (!bLock) { // Déplace les éléments si l'inventaire n'est plus plein if (getCount(_szUniverseName) - _nFirstCell < INVENTORY_CELLMAX) { _nFirstCell = getCount(_szUniverseName) - INVENTORY_CELLMAX; if (_nFirstCell < 0) { _nFirstCell = 0; } SCENEDIRECTOR->UpdateInventoryButtons(); } } // Reset for (int n = 0; n < INVENTORY_CELLMAX; n++) { _InventoryCells[n]->setItem(NULL); _InventoryCells[n]->setOrder(_nFirstCell+n); } // Chaine pour dumper l'inventaire dans le profil char szDump[INVENTORY_BUFFERLEN]; memset(szDump, 0, INVENTORY_BUFFERLEN); // Positionne les items dans les cellules if (_nFirstCell != -1) { // Se positionne sur le 1er item demandé puis positionne les items dans les cellules int n = 0; int nCell = 0; EInventoryItem *o; bool bGotNext = EInventoryItem::g_ListInventoryItem.getHead (o); if (bGotNext) { while (bGotNext) { // Ajout au dump KStringCat(szDump, o->_szItemName,INVENTORY_BUFFERLEN); KStringCat(szDump, ",",INVENTORY_BUFFERLEN); KStringCat(szDump, o->_szUniverseName,INVENTORY_BUFFERLEN); KStringCat(szDump, ",",INVENTORY_BUFFERLEN); KStringCat(szDump, itos(o->_nNbPartNeeded).c_str(),INVENTORY_BUFFERLEN); KStringCat(szDump, ",",INVENTORY_BUFFERLEN); KStringCat(szDump, itos(o->_nNbPartCurrent).c_str(),INVENTORY_BUFFERLEN); KStringCat(szDump, ";",INVENTORY_BUFFERLEN); // Visible dans l'inventaire if (strcmp(o->_szUniverseName,_szUniverseName) == 0) { if (n >= _nFirstCell) { _InventoryCells[nCell]->setItem(o); // L'item est nouvellement instancié, on le fait clignoter si c un objet à combiner if (o->_bNew) { o->_bNew = false; _InventoryCells[nCell]->_bFirstDisplay = true; _InventoryCells[nCell]->_nNbFirstDiplayBlink = 0; } // Positionne l'image dans la cellule int x,y; x = _InventoryCells[nCell]->getPosX(); x += INVENTORY_CELLWIDTH/2; x -= (int) o->_lpGraphic->getWidth()/2; y = _InventoryCells[nCell]->getPosY(); y += INVENTORY_CELLHEIGHT/2; y -= (int) o->_lpGraphic->getHeight()/2; o->setPos((float) x, (float) y); nCell++; if (nCell >= INVENTORY_CELLMAX) break; } n++; } bGotNext = EInventoryItem::g_ListInventoryItem.getNext (o); } } } // Sauvegarde du dump dans le profil SetGlobal("__inventory__", szDump); K_LOG("Inventory order:%s len=%d",szDump,strlen(szDump)); }
void LuaEngine::Init(const char* main_script_file) { Fini(); int ret = 0; // TODO: 定时器个数采用宏配置 heap_timer_ = new HeapTimer(1024); CHECK(heap_timer_ != NULL) << "timer heap init error!"; master_state_ = luaL_newstate(); CHECK(master_state_ != NULL) << "luaL_newstate error!"; luaL_openlibs(master_state_); lua_tinker::init(master_state_); lua_tinker::init_s64(master_state_); lua_tinker::init_u64(master_state_); // 将script_main.lua所在文件夹路径加入require路径搜索 char script_path[256] = {0}; realpath(main_script_file, script_path); strncpy(script_path, dirname(script_path), 256); AddRequirePath(script_path); AddRequireCPath(script_path); // package.path 处理 std::ostringstream oss_require; oss_require << "package.path = \"" << oss_require_path_.str() << "\""; ret = luaL_dostring(master_state_, oss_require.str().c_str()); LOG(INFO) << "luaL_dostring [" << oss_require.str().c_str() << "]"; CHECK(ret == 0) << "luaL_dostring [" << oss_require.str().c_str() << "] error!"; oss_require.str(""); oss_require_path_.str(""); // package.cpath 处理 oss_require << "package.cpath = \"" << oss_require_cpath_.str() << "\""; ret = luaL_dostring(master_state_, oss_require.str().c_str()); LOG(INFO) << "luaL_dostring [" << oss_require.str().c_str() << "]"; CHECK(ret == 0) << "luaL_dostring [" << oss_require.str().c_str() << "] error!"; oss_require.str(""); oss_require_cpath_.str(""); // 设置LUA_SCRIPT_PATH SetGlobal("LUA_SCRIPT_PATH", script_path); // 注册log函数 RegFunc("C_LOG_INFO", &LuaEngine::LogInfo); RegFunc("C_LOG_ERROR", &LuaEngine::LogError); // lua_tinker中日志函数 RegFunc("_ALERT", &LuaEngine::LogInfo); ret = luaL_dofile(master_state_, main_script_file); if (ret != 0) { LOG(ERROR) << lua_tostring(master_state_, -1); } CHECK(ret == 0) << "luaL_dofile error!"; // 第一次加载模块 Reload(); // 设置检查信号宏 SetGlobal<int>("CHECK_SIG_OK", CHECK_SIG_OK); SetGlobal<int>("CHECK_SIG_TIMEOUT", CHECK_SIG_TIMEOUT); // 设置定时器 SetHandler(this, &LuaEngine::OnTimer); }
// Called every time a note is hit or missed, before the lua events void ScreenGameplay7K::UpdateScriptScoreVariables() { auto 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)); auto autopacemaker = ScoreKeeper->getAutoRankPacemaker(); L->SetGlobal("PacemakerText", autopacemaker.first); L->SetGlobal("PacemakerValue", autopacemaker.second); auto bmpacemaker = ScoreKeeper->getAutoPacemaker(); L->SetGlobal("BMPacemakerText", bmpacemaker.first); L->SetGlobal("BMPacemakerValue", bmpacemaker.second); L->SetGlobal("AccText", "ACC:"); L->SetGlobal("AccValue", ScoreKeeper->getPercentScore(PST_EX)); auto lifebar_amount = ScoreKeeper->getLifebarAmount(lifebar_type); L->SetGlobal("LifebarValue", lifebar_amount); if (lifebar_type == LT_GROOVE || lifebar_type == LT_EASY) L->SetGlobal("LifebarDisplay", std::max(2, int(floor(lifebar_amount * 50) * 2))); else L->SetGlobal("LifebarDisplay", int(ceil(lifebar_amount * 50) * 2)); }
void Universe::initialize(long _argc, char** _argv) { #ifdef GENERATE_ALLOCATION_STATISTICS allocationStats["VMArray"] = {0,0}; #endif heapSize = 1 * 1024 * 1024; vector<StdString> argv = handleArguments(_argc, _argv); // remember file that was executed (for writing statistics) if (argv.size() > 0) bm_name = argv[0]; Heap<HEAP_CLS>::InitializeHeap(heapSize); interpreter = new Interpreter(); #if CACHE_INTEGER # warning is _store_ptr sufficient/correct here? // create prebuilt integers for (long it = INT_CACHE_MIN_VALUE; it <= INT_CACHE_MAX_VALUE; ++it) { prebuildInts[(unsigned long)(it - INT_CACHE_MIN_VALUE)] = _store_ptr(new (GetHeap<HEAP_CLS>()) VMInteger(it)); } #endif InitializeGlobals(); VMObject* systemObject = NewInstance(load_ptr(systemClass)); SetGlobal(SymbolForChars("nil"), load_ptr(nilObject)); SetGlobal(SymbolForChars("true"), load_ptr(trueObject)); SetGlobal(SymbolForChars("false"), load_ptr(falseObject)); SetGlobal(SymbolForChars("system"), systemObject); SetGlobal(SymbolForChars("System"), load_ptr(systemClass)); SetGlobal(SymbolForChars("Block"), load_ptr(blockClass)); symbolIfTrue = _store_ptr(SymbolForChars("ifTrue:")); symbolIfFalse = _store_ptr(SymbolForChars("ifFalse:")); VMMethod* bootstrapMethod = NewMethod(SymbolForChars("bootstrap"), 1, 0); bootstrapMethod->SetBytecode(0, BC_HALT); bootstrapMethod->SetNumberOfLocals(0); bootstrapMethod->SetMaximumNumberOfStackElements(2); bootstrapMethod->SetHolder(load_ptr(systemClass)); if (argv.size() == 0) { Shell* shell = new Shell(bootstrapMethod); shell->Start(); return; } /* only trace bootstrap if the number of cmd-line "-d"s is > 2 */ short trace = 2 - dumpBytecodes; if (!(trace > 0)) dumpBytecodes = 1; VMArray* argumentsArray = NewArrayFromStrings(argv); VMFrame* bootstrapFrame = interpreter->PushNewFrame(bootstrapMethod); bootstrapFrame->Push(systemObject); bootstrapFrame->Push(argumentsArray); VMInvokable* initialize = load_ptr(systemClass)->LookupInvokable( SymbolForChars("initialize:")); (*initialize)(bootstrapFrame); // reset "-d" indicator if (!(trace > 0)) dumpBytecodes = 2 - trace; interpreter->Start(); }