void ObjectEditor::ClikedButton(QPushButton *b){ if(b==OpenObjectButton){ openObject((*Projectpatch)+"/"+OBJECT_DIR); } if(b==PlayAnimation&&ObjectRender!=NULL&&AnimationsIndex->count()){ ObjectRender->Play(AnimationsIndex->currentIndex()); } if(b==create){ createObject((*Projectpatch)+"/"+SPRITE_DIR); } if(b==ClearAnimation&&ObjectRender!=NULL){ ObjectRender->Replay(); } if(b==Save&&ObjectRender){ saveObject(); } if(b==Bcolor&&ObjectRender!=NULL&&AnimationsIndex->count()){ QColor temp=QColorDialog::getColor(Qt::black,getMain()); camera->setBackgroundColor(temp); } if(b==Delete&&ObjectRender){ int temp = QMessageBox::question(getMain(), "Warning","delete \'"+ObjectRender->getObjectPatch()+"\' Object?", QMessageBox::No|QMessageBox::Yes); if(temp== QMessageBox::Yes){ if(ObjectRender->getEObjectNameClass()==E_GAME_RESURS){ pack->remove(((EGameResurs*)ObjectRender)->getRes()->getSource()->id()); pack->save(); } QString temp=ObjectRender->getObjectPatch(); this->removeObject(ObjectRender); QFile(temp).remove(); ObjectRender=NULL; } } }
void createScene() override { Scene *scene = getMain().getResourceManager()->queryResource<Scene>("SimpleScene", "samples:scenes/scene.json"); setMainCamera(getMain().getCamera("MyCamera")); mMinigun = scene->getObject("Minigun"); mPlasmagun = scene->getObject("Plasmagun"); }
void PhysicSampleBase::createScene() { // load empty scene with floor plane only mScene = getMain().getResourceManager()->queryResource<lite3dpp::Scene>("SampleScene", "samples:scenes/empty.json"); setMainCamera(getMain().getCamera("MyCamera")); mScene->instancingMode(true); mGroundPlane = createGroundPlane("Ground"); }
bool Unit::compileTimeFatal(const StringData*& msg, int& line) const { // A compile-time fatal is encoded as a pseudomain that contains precisely: // // String <id>; Fatal; // // Decode enough of pseudomain to determine whether it contains a // compile-time fatal, and if so, extract the error message and line number. const Opcode* entry = getMain()->getEntry(); const Opcode* pc = entry; // String <id>; Fatal; // ^^^^^^ if (*pc != OpString) { return false; } pc++; // String <id>; Fatal; // ^^^^ Id id = *(Id*)pc; pc += sizeof(Id); // String <id>; Fatal; // ^^^^^ if (*pc != OpFatal) { return false; } msg = lookupLitstrId(id); line = getLineNumber(Offset(pc - entry)); return true; }
void timerTick(lite3d_timer *timerid) override { Sample::timerTick(timerid); if(timerid == getMain().getFixedUpdateTimer()) { mMinigun->getRoot()->rotateAngle(KM_VEC3_POS_Z, 0.01f); mPlasmagun->getRoot()->rotateAngle(KM_VEC3_NEG_Z, 0.01f); } }
Context& Context::getCurrent() { // thread-local, therefore threadsafe // Do not restructure code without making sure you don't end up with // multiple pthread_getspecific calls (git blame this comment) Context* context = _currentContext.get(); if( context ) return *context; context = &getMain(); _currentContext = context; return *context; }
void UnitEmitter::addTrivialPseudoMain() { initMain(0, 0); auto const mfe = getMain(); emitOp(OpInt); emitInt64(1); emitOp(OpRetC); mfe->maxStackCells = 1; mfe->finish(bcPos(), false); recordFunction(mfe); TypedValue mainReturn; mainReturn.m_data.num = 1; mainReturn.m_type = KindOfInt64; m_mainReturn = mainReturn; m_mergeOnly = true; }
std::unique_ptr<UnitEmitter> createFatalUnit(StringData* filename, const MD5& md5, FatalOp /*op*/, StringData* err) { auto ue = std::make_unique<UnitEmitter>(md5); ue->m_filepath = filename; ue->initMain(1, 1); ue->emitOp(OpString); ue->emitInt32(ue->mergeLitstr(err)); ue->emitOp(OpFatal); ue->emitByte(static_cast<uint8_t>(FatalOp::Runtime)); FuncEmitter* fe = ue->getMain(); fe->maxStackCells = 1; // XXX line numbers are bogus fe->finish(ue->bcPos(), false); ue->recordFunction(fe); return ue; }
void ObjectEditor::saveObject(){ this->OffAll(); QUrl patch=QFileDialog::getSaveFileUrl(SpaceEngineEvents,"Save object",QUrl::fromLocalFile(*Projectpatch+"/"+OBJECT_DIR+"/"+ObjectRender->getName()),OBJECTS_FILTERS); this->OnAll(); QString tempPatch=patch.path(); #ifdef Q_OS_WIN tempPatch=tempPatch.right(tempPatch.size()-1); #endif if(!ObjectRender->getContur()){ QMessageBox::information(getMain(),"Save fail!","Object is not saved, HitBox not detected!"); }else{ //ObjectRender->saveObject(tempPatch); static_cast<Module*>(module->currentWidget())->saveObject(tempPatch); } /*if(ObjectRender->getEObjectNameClass()==E_GAME_RESURS){ pack->save(); }*/ }
/// <summary> /// Get most executed thread /// </summary> /// <returns>Pointer to thread object, nullptr if failed</returns> Thread* ProcessThreads::getMostExecuted() { uint64_t maxtime = 0; Thread* pThread = getMain(); if (pThread->Suspended()) pThread = nullptr; for (auto& thread : getAll( true )) { uint64_t time = thread.execTime(); if (!thread.Suspended() && time > maxtime) { maxtime = time; pThread = &thread; } } return pThread; }
void createScene() override { Scene *scene = getMain().getResourceManager()->queryResource<Scene>("Warship", "warship:scenes/warship_prepass.json"); scene->instancingMode(true); setMainCamera(getMain().getCamera("MainCamera")); addFlashlight(scene); scene = getMain().getResourceManager()->queryResource<Scene>("WarshipCombine", "warship:scenes/warship_combine.json"); scene = getMain().getResourceManager()->queryResource<Scene>("WarshipPostProcess", "warship:scenes/warship_postprocess.json"); lite3dpp::Material::setIntGlobalParameter("FXAA", 0); kmVec3 resolution = { (float)getMain().window()->width(), (float)getMain().window()->height(), 0 }; lite3dpp::Material::setFloatv3GlobalParameter("screenResolution", resolution); }
static Variant eval_for_assert(ActRec* const curFP, const String& codeStr) { String prefixedCode = concat3("<?php return ", codeStr, ";"); auto const oldErrorLevel = s_option_data->assertQuietEval ? HHVM_FN(error_reporting)(Variant(0)) : 0; SCOPE_EXIT { if (s_option_data->assertQuietEval) HHVM_FN(error_reporting)(oldErrorLevel); }; auto const unit = g_context->compileEvalString(prefixedCode.get()); if (unit == nullptr) { raise_recoverable_error("Syntax error in assert()"); // Failure to compile the eval string doesn't count as an // assertion failure. return Variant(true); } if (!(curFP->func()->attrs() & AttrMayUseVV)) { throw_not_supported("assert()", "assert called from non-varenv function"); } if (!curFP->hasVarEnv()) { curFP->setVarEnv(VarEnv::createLocal(curFP)); } auto varEnv = curFP->getVarEnv(); if (curFP != vmfp()) { // If we aren't using FCallBuiltin, the stack frame of the call to assert // will be in middle of the code we are about to eval and our caller, whose // varEnv we want to use. The invokeFunc below will get very confused if // this is the case, since it will be using a varEnv that belongs to the // wrong function on the stack. So, we rebind it here, to match what // invokeFunc will expect. assert(!vmfp()->hasVarEnv()); vmfp()->setVarEnv(varEnv); varEnv->enterFP(curFP, vmfp()); } ObjectData* thiz = nullptr; Class* cls = nullptr; Class* ctx = curFP->func()->cls(); if (ctx) { if (curFP->hasThis()) { thiz = curFP->getThis(); cls = thiz->getVMClass(); } else { cls = curFP->getClass(); } } auto const func = unit->getMain(ctx); return Variant::attach( g_context->invokeFunc( func, init_null_variant, thiz, cls, varEnv, nullptr, ExecutionContext::InvokePseudoMain ) ); }
std::unique_ptr<Unit> UnitEmitter::create() { auto u = folly::make_unique<Unit>(); u->m_repoId = m_repoId; u->m_sn = m_sn; u->m_bc = allocateBCRegion(m_bc, m_bclen); u->m_bclen = m_bclen; u->m_filepath = m_filepath; u->m_mainReturn = m_mainReturn; u->m_mergeOnly = m_mergeOnly; u->m_isHHFile = m_isHHFile; u->m_useStrictTypes = m_useStrictTypes; { const std::string& dirname = FileUtil::safe_dirname(m_filepath->data(), m_filepath->size()); u->m_dirpath = makeStaticString(dirname); } u->m_md5 = m_md5; for (unsigned i = 0; i < m_litstrs.size(); ++i) { NamedEntityPair np; np.first = m_litstrs[i]; np.second = nullptr; u->m_namedInfo.push_back(np); } u->m_arrays = [&]() -> std::vector<const ArrayData*> { auto ret = std::vector<const ArrayData*>{}; for (unsigned i = 0; i < m_arrays.size(); ++i) { ret.push_back(m_arrays[i]); } return ret; }(); for (auto const& pce : m_pceVec) { u->m_preClasses.push_back(PreClassPtr(pce->create(*u))); } u->m_typeAliases = m_typeAliases; size_t ix = m_fes.size() + m_hoistablePceIdList.size(); if (m_mergeOnly && !m_allClassesHoistable) { size_t extra = 0; for (auto& mergeable : m_mergeableStmts) { extra++; if (!RuntimeOption::RepoAuthoritative && SystemLib::s_inited) { if (mergeable.first != MergeKind::Class) { extra = 0; u->m_mergeOnly = false; break; } } else { switch (mergeable.first) { case MergeKind::PersistentDefine: case MergeKind::Define: case MergeKind::Global: extra += sizeof(TypedValueAux) / sizeof(void*); break; default: break; } } } ix += extra; } Unit::MergeInfo *mi = Unit::MergeInfo::alloc(ix); u->m_mergeInfo = mi; ix = 0; for (auto& fe : m_fes) { Func* func = fe->create(*u); if (func->top()) { if (!mi->m_firstHoistableFunc) { mi->m_firstHoistableFunc = ix; } } else { assert(!mi->m_firstHoistableFunc); } mi->mergeableObj(ix++) = func; } assert(u->getMain()->isPseudoMain()); if (!mi->m_firstHoistableFunc) { mi->m_firstHoistableFunc = ix; } mi->m_firstHoistablePreClass = ix; assert(m_fes.size()); for (auto& id : m_hoistablePceIdList) { mi->mergeableObj(ix++) = u->m_preClasses[id].get(); } mi->m_firstMergeablePreClass = ix; if (u->m_mergeOnly && !m_allClassesHoistable) { for (auto& mergeable : m_mergeableStmts) { switch (mergeable.first) { case MergeKind::Class: mi->mergeableObj(ix++) = u->m_preClasses[mergeable.second].get(); break; case MergeKind::TypeAlias: mi->mergeableObj(ix++) = (void*)((intptr_t(mergeable.second) << 3) + (int)mergeable.first); break; case MergeKind::ReqDoc: { assert(RuntimeOption::RepoAuthoritative); void* name = u->lookupLitstrId(mergeable.second); mi->mergeableObj(ix++) = (char*)name + (int)mergeable.first; break; } case MergeKind::Define: case MergeKind::Global: assert(RuntimeOption::RepoAuthoritative); case MergeKind::PersistentDefine: { void* name = u->lookupLitstrId (m_mergeableValues[mergeable.second].first); mi->mergeableObj(ix++) = (char*)name + (int)mergeable.first; auto& tv = m_mergeableValues[mergeable.second].second; auto* tva = (TypedValueAux*)mi->mergeableData(ix); tva->m_data = tv.m_data; tva->m_type = tv.m_type; // leave tva->m_aux uninitialized ix += sizeof(*tva) / sizeof(void*); assert(sizeof(*tva) % sizeof(void*) == 0); break; } case MergeKind::Done: case MergeKind::UniqueDefinedClass: not_reached(); } } } assert(ix == mi->m_mergeablesSize); mi->mergeableObj(ix) = (void*)MergeKind::Done; /* * What's going on is we're going to have a m_lineTable if this UnitEmitter * was loaded from the repo, and no m_sourceLocTab (it's demand-loaded by * unit.cpp because it's only used for the debugger). Don't bother creating * the line table here, because we can retrieve it from the repo later. * * On the other hand, if this unit was just created by parsing a php file (or * whatnot) which was not committed to the repo, we'll have a m_sourceLocTab. * In this case we should populate m_lineTable (otherwise we might lose line * info altogether, since it may not be backed by a repo). */ if (m_sourceLocTab.size() != 0) { stashLineTable(u.get(), createLineTable(m_sourceLocTab, m_bclen)); } for (size_t i = 0; i < m_feTab.size(); ++i) { assert(m_feTab[i].second->past == m_feTab[i].first); assert(m_fMap.find(m_feTab[i].second) != m_fMap.end()); u->m_funcTable.push_back( FuncEntry(m_feTab[i].first, m_fMap.find(m_feTab[i].second)->second)); } // Funcs can be recorded out of order when loading them from the // repo currently. So sort 'em here. std::sort(u->m_funcTable.begin(), u->m_funcTable.end()); m_fMap.clear(); if (RuntimeOption::EvalDumpBytecode) { // Dump human-readable bytecode. Trace::traceRelease("%s", u->toString().c_str()); } if (RuntimeOption::EvalDumpHhas && SystemLib::s_inited) { std::printf("%s", disassemble(u.get()).c_str()); std::fflush(stdout); _Exit(0); } static const bool kVerify = debug || getenv("HHVM_VERIFY"); static const bool kVerifyVerboseSystem = getenv("HHVM_VERIFY_VERBOSE_SYSTEM"); static const bool kVerifyVerbose = kVerifyVerboseSystem || getenv("HHVM_VERIFY_VERBOSE"); const bool isSystemLib = u->filepath()->empty() || boost::contains(u->filepath()->data(), "systemlib"); const bool doVerify = kVerify || boost::ends_with(u->filepath()->data(), "hhas"); if (doVerify) { auto const verbose = isSystemLib ? kVerifyVerboseSystem : kVerifyVerbose; auto const ok = Verifier::checkUnit(u.get(), verbose); if (!ok && !verbose) { std::cerr << folly::format( "Verification failed for unit {}. Re-run with HHVM_VERIFY_VERBOSE{}=1 " "to see more details.\n", u->filepath()->data(), isSystemLib ? "_SYSTEM" : "" ); } } return u; }
void addFlashlight(Scene *scene) { kmVec3 spotFactor = { 0.35f, 0.52f, 0.0f }; kmVec4 attenuation = { 0.0f, 1.0f, 0.0f, 1000.0f }; String flashLightParams = ConfigurationWriter().set(L"Name", "FlashLight.node").set(L"Light", ConfigurationWriter().set(L"Ambient", KM_VEC3_ZERO) .set(L"Diffuse", KM_VEC3_ONE) .set(L"Position", KM_VEC3_ZERO) .set(L"Name", "FlashLight") .set(L"Specular", KM_VEC3_ONE) .set(L"SpotDirection", KM_VEC3_NEG_Z) .set(L"Type", "Spot") .set(L"SpotFactor", spotFactor) .set(L"Attenuation", attenuation)).write(true); mFlashLight.reset(new LightSceneNode(ConfigurationReader(flashLightParams.data(), flashLightParams.size()), NULL, &getMain())); mFlashLight->addToScene(scene); mFlashLight->getLight()->enabled(false); }