bool OptionsInputEventHandler::OnPressA() { if (!InputHandler::OnPressA()) { SmartPointer<OptionsScreen> sc = SmartPointerFunctions::Cast<Scene, OptionsScreen>(SceneManager::GetScene()); if (sc->GetMenuPosition() == 6) { sc->Save(); ReturnToPreviousScreen(); } else { sc->IncrementValueAt(); } } return false; }
void Disk3D_BB::setMetric(SmartPointer<Metric::Generic> gg) { //Metric must be KerrBL (see emission function) string kind = gg->getKind(); if (kind != "KerrBL") throwError ("Disk3D_BB::setMetric(): metric must be KerrBL"); Disk3D::setMetric(gg); }
/*** * Loads textures, attributes, uniforms, shaders, etc. * * @param filename is the name for the file where we get the data */ void Scene::loadData(const string &filename) { int currentLine = 0; recentProgramHandle = -1; const Resource *data = FAH::Viewer::resource0.find(filename); if (!data) THROWS("Could not find resource: " << filename); string s(data->getData(), data->getLength()); istringstream in(s); freeResources(); while (!in.eof()) { SmartPointer<Uniform> uniform; string lineString; string item; string key; getline(in, lineString); stringstream line(lineString); ++currentLine; line >> item; if (8 < item.length() && item.substr(0, 8) == "uniform_") { float val[16]; line >> key; item = item.substr(8); int count; uniform_t type; if (item == "float") {type = SAMPLE_FLOAT; count = 1;} else if (item == "vec2") {type = SAMPLE_FLOAT_VEC2; count = 2;} else if (item == "vec3") {type = SAMPLE_FLOAT_VEC3; count = 3;} else if (item == "vec4") {type = SAMPLE_FLOAT_VEC4; count = 4;} else if (item == "mat4") {type = SAMPLE_FLOAT_MAT4; count = 16;} else THROWS("Invalid uniform type " << item); for (int i = 0; i < count; i++) line >> val[i]; uniform = new Uniform(key, type); uniform->setLocation(recentProgramHandle); uniform->update(val); } else if (item == "attribute") {
void STLModule::bounds(const js::Value &args, js::Sink &sink) { SmartPointer<js::Value> facets = args.get("stl")->get("facets"); Rectangle3F bounds; unsigned length = facets->length(); for (unsigned i = 0; i < length; i++) { SmartPointer<js::Value> facet = facets->get(i); for (unsigned j = 0; j < 3; j++) bounds.add(toVector3F(*facet->get(j))); } sink.beginList(); append(sink, bounds.getMin()); append(sink, bounds.getMax()); sink.endList(); }
static bool is_xml(const std::string &filename) { try { if (!SystemUtilities::exists(filename)) return false; SmartPointer<iostream> stream = SystemUtilities::open(filename, ios::in); while (true) { int c = stream->peek(); if (c == '<') return true; else if (isspace(c)) stream->get(); // Next else return false; // Not XML } } CATCH_WARNING; return false; }
void DynamicalDisk3D::metric(SmartPointer<Metric::Generic> gg) { //Metric must be KerrBL (see emission function) string kin = gg->kind(); if (kin != "KerrBL" && kin != "Minkowski") throwError ("DynamicalDisk3D::metric(): metric must be KerrBL"); Disk3D::metric(gg); }
ALLEGRO_BITMAP *create_bitmap_ex(int color_depth, int width, int height) { SmartPointer<SDL_Surface> surf; if(color_depth == 8) surf = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8, 0,0,0,0); else surf = create_32bpp_sdlsurface__allegroformat(width, height); if(!surf.get()) { errors << "create_bitmap_ex: cannot create surface with " << width << "x" << height << "x" << color_depth << endl; return NULL; } FillSurface(surf.get(), Color()); if(surf->format->BitsPerPixel != color_depth) warnings << "create_bitmap_ex: couldn't create surface with " << color_depth << " bpp" << endl; return create_bitmap_from_sdl(surf); }
void PatternDiskBB::metric(SmartPointer<Metric::Generic> gg) { //Metric must be KerrBL or alike string kin = gg->kind(); if ((kin != "KerrBL") && (kin != "ChernSimons")) throwError ("PatternDiskBB::metric(): metric must be KerrBL or CS"); ThinDisk::metric(gg); }
void LifeForm::resolve_encounter(SmartPointer<LifeForm> alien) { Action my_act = this->encounter(this->info_about_them(alien)); // my action (EAT or IGNORE) SmartPointer<LifeForm> self = SmartPointer<LifeForm>(this); // alien's action Action alien_act = alien->encounter(alien->info_about_them(self)); // if both sides are willing to eat each other if (my_act == Action::LIFEFORM_EAT && alien_act == Action::LIFEFORM_EAT) { bool me_succeed = LifeForm::eat_trial(self, alien); bool alien_succeed = LifeForm::eat_trial(alien, self); // break the tie based on the strategy if (me_succeed && alien_succeed) { if (::encounter_strategy == EncounterResolver::EVEN_MONEY) { drand48() > 0.5 ? this->eat(alien) : alien->eat(self); } else if (::encounter_strategy == EncounterResolver::BIG_GUY_WINS) { this->energy > alien->energy ? this->eat(alien) : alien->eat(self); } else if (::encounter_strategy == EncounterResolver::UNDERDOG_IS_HERE) { this->energy < alien->energy ? this->eat(alien) : alien->eat(self); } else if (::encounter_strategy == EncounterResolver::FASTER_GUY_WINS) { this->speed > alien->speed ? this->eat(alien) : alien->eat(self); } else if (::encounter_strategy == EncounterResolver::SLOWER_GUY_WINS) { this->speed < alien->speed ? this->eat(alien) : alien->eat(self); } } else if (me_succeed) { this->eat(alien); } else if (alien_succeed) { alien->eat(self); } } else if (my_act == Action::LIFEFORM_EAT && alien_act == Action::LIFEFORM_IGNORE) { if (LifeForm::eat_trial(self, alien)) { this->eat(alien); } } else if (my_act == Action::LIFEFORM_IGNORE && alien_act == Action::LIFEFORM_EAT) { if (LifeForm::eat_trial(alien, self)) { alien->eat(self); } } }
QString ContributionRoot::CreateIdentifierId(const SmartPointer<IContributionItem>& item) { QString namespaze = factory->GetNamespace(); // create the activity identifier ID. If this factory doesn't have a namespace // it will be null. QString identifierID = (!namespaze.isEmpty()) ? namespaze + '/' + item->GetId() : QString(); return identifierID; }
void WorldSimulation::SetController(int index,SmartPointer<RobotController> c) { if(robotControllers.empty()) { robotControllers.resize(world->robots.size()); } robotControllers[index] = c; controlSimulators[index].controller = c; if(c) c->Reset(); }
Action byf69::encounter(const ObjInfo& info) { if (this->is_byf69(info) && info.species != this->m_name_eat_me) { return LIFEFORM_IGNORE; } else { if (info.species == this->m_name_eat_me) { if ((this->m_eat_health_factor - 1.0) * this->health() > info.health) { return LIFEFORM_IGNORE; // false encounter with eat_me lifeform } } this->sniff_event->cancel(); this->reverse_direction_event->cancel(); SmartPointer<byf69> self = SmartPointer<byf69>(this); this->sniff_event = new Event(0.0, [self](void) { self->sniff(); }); this->reverse_direction_event = new Event(0.0, [self]() { self->reverse_direction(); }); return LIFEFORM_EAT; } }
void EditorHistory::Add(const SmartPointer<EditorHistoryItem>& newItem, int index) { // Remove the item if it already exists so that it will be put // at the top of the list. if (newItem->IsRestored()) { this->Remove(newItem->GetInput()); } // Remove the oldest one if (fifoList.size() == MAX_SIZE) { fifoList.pop_back(); } // Add the new item. fifoList.insert(index < MAX_SIZE ? index : MAX_SIZE - 1, newItem); }
ParameterValueConverterProxy::ParameterValueConverterProxy( const SmartPointer<IConfigurationElement>& converterConfigurationElement) : converterConfigurationElement(converterConfigurationElement) { if (converterConfigurationElement.IsNull()) { throw ctkInvalidArgumentException( "converterConfigurationElement must not be null"); } }
SmartPointer<VMEntryType> VirtualMachine::findType(std::string const& name) { NamespaceEntry entry; //If the namespace entry is not found in the namespace if (!VM::NamespaceEntry::searchNamespace(namespace_, name, entry)) { VM_PRINTF_LOG("Type %s not found, inspecting to check if array\n", name.c_str()); //If it starts with 'array(' try to generate it from existing types char const* prefix = "array("; if (strncmp(prefix, name.c_str(), strlen(prefix)) == 0) { std::string subtypeName = name.substr(strlen(prefix), name.size() - strlen(prefix) - 1); VM_PRINTF_LOG("Generating subtype %s\n", subtypeName.c_str()); SmartPointer<VMEntryType> subtype = findType(subtypeName); if (subtype.get() == nullptr) { VM_PRINTF_FATAL("Cannot create array of invalid subtype %s\n", subtypeName.c_str()); return nullptr; } SmartPointer<VMEntryType> entryType = SmartPointer<VMEntryType>(new VMEntryType(name, subtype)); registerEntry(name, entryType); VM_PRINTF_LOG("Generating new type %s\n", name.c_str()); return entryType; } else { VM_PRINTF_LOG("Prefix of %s does not match with array(\n", name.c_str()); return nullptr; } } //If the entry in the namespace specified is not a type then return null if (entry.getType() != Type) { VM_PRINTF_LOG("Error searched type %s (%i)\n", name.c_str(), entry.getType()); return nullptr; } return entry.getTypeReference(); }
void SessionManager::load(LevelDB db) { sessions_t sessions; // Load sessions LevelDB nsDB = db.ns("session:"); for (LevelDB::Iterator it = nsDB.begin(); it.valid(); it++) { SmartPointer<Session> session = factory->createSession(it.key()); session->parse(it.value()); sessions.insert(sessions_t::value_type(session->getID(), session)); } // Replace current SmartLock lock(this); this->sessions = sessions; // Update update(); }
void SessionManager::load(DB::Database &db) { SmartPointer<DB::Statement> readStmt = table.makeReadStmt(db); sessions_t sessions; // Load sessions while (readStmt->next()) { SmartPointer<Session> session = factory->createSession(""); table.readRow(readStmt, *session); sessions.insert(sessions_t::value_type(session->getID(), session)); } // Replace current SmartLock lock(this); this->sessions = sessions; // Update update(); }
void SessionManager::save(DB::Database &db) const { if (!dirty) return; dirty = false; SmartPointer<DB::Statement> writeStmt = table.makeWriteStmt(db); SmartPointer<DB::Transaction> transaction = db.begin(); // Delete old sessions table.deleteAll(db); // Write sessions SmartLock lock(this); for (iterator it = begin(); it != end(); it++) { table.bindWriteStmt(writeStmt, *it->second); writeStmt->execute(); } db.commit(); }
void Complex::append(SmartPointer<Generic> e) { if (debug()) cerr << "DEBUG: in Complex::append(SmartPointer<Generic> e)" << endl; if (cardinal_+1 == 0) throwError("Complex::append(): OVERFLOW"); SmartPointer<Generic> * orig = elements_; elements_ = new SmartPointer<Generic> [cardinal_+1]; for (size_t i=0; i< cardinal_; ++i) { elements_[i] = orig[i]; orig[i] = NULL; } delete [] orig; orig = NULL; elements_[cardinal_] = e; ++cardinal_; if (gg_) e->metric(gg_); else gg_ = e->metric(); if (debug()) cerr << "DEBUG: out Complex::append(SmartPointer<Generic> e)" << endl; }
CommandLine::CommandLine() : keywords(0), allowConfigAsFirstArg(false), allowSingleDashLongOpts(false), allowExtraOpts(false), allowPositionalArgs(true), warnOnInvalidArgs(false) { SmartPointer<Option> opt; opt = add("help", 0, new OptionAction<CommandLine>(this, &CommandLine::usageAction), "Print help screen or help on a particular option and exit."); opt->setType(Option::STRING_TYPE); opt->setOptional(); add(string(), 'v', new OptionAction<CommandLine>(this, &CommandLine::incVerbosityAction), "Increase verbosity level."); alias("-v", "--verbose"); add("license", 0, new OptionAction<CommandLine> (this, &CommandLine::licenseAction), "License information and exit."); }
// The "main" function void Checkers::run() { // Build the Debug Table's Headers QStringList header; header << "one" << "two" << "three"; gui->setDebugHeader( header ); timeManager->setNumTurns( 0 ); animationEngine->registerGame(0, 0); // Look through each turn in the gamelog for(int state = 0; state < (int)m_game->states.size() && !m_suicide; state++) { Frame turn; // The frame that will be drawn SmartPointer<Something> something = new Something(); something->addKeyFrame( new DrawSomething( something ) ); turn.addAnimatable( something ); animationEngine->buildAnimations(turn); addFrame(turn); // Register the game and begin playing delayed due to multithreading if(state > 5) { timeManager->setNumTurns(state - 5); animationEngine->registerGame( this, this ); if(state == 6) { animationEngine->registerGame(this, this); timeManager->setTurn(0); timeManager->play(); } } } if(!m_suicide) { timeManager->setNumTurns( m_game->states.size() ); timeManager->play(); } } // Checkers::run()
void LifeForm::eat(SmartPointer<LifeForm> that){ // cout<<this->species_name(); // cout<<" eat"<<endl; if (!is_alive) { return; } SmartPointer<LifeForm> self = SmartPointer<LifeForm>(this); double that_energy = that->health()*start_energy; that->die(); energy-=eat_cost_function(0.0,0.0); if (energy<min_energy) { self->die(); } //new Event(digestion_time,[self,that_energy](){self->gain_energy(that_energy);}); new Event(digestion_time,[self,that_energy](){self->energy +=that_energy*eat_efficiency;}); }
void Window::CreateTrimWidgets(SmartPointer<Shell> shell) { if (menuBarManager.IsNotNull()) { QMainWindow* mw = qobject_cast<QMainWindow*>(shell->GetControl()); if (mw) { mw->setMenuBar(menuBarManager->CreateMenuBar(shell->GetControl())); menuBarManager->UpdateAll(true); } } // if (showTopSeperator()) // { // seperator1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); // } //CreateToolBarControl(shell); //CreateStatusLine(shell); }
void CommandContributionItem::UpdateCommandPropertiesInUI(const SmartPointer< const CommandEvent>& commandEvent) { if (commandEvent->GetCommand()->IsDefined()) { this->Update(); } if (commandEvent->IsEnabledChanged() || commandEvent->IsHandledChanged()) { if (visibleEnabled) { IContributionManager* parent = this->GetParent(); if (parent) { parent->Update(true); } } } }
QString RegistryPersistence::ReadOptional(const SmartPointer<IConfigurationElement>& configurationElement, const QString& attribute) { QString value = configurationElement->GetAttribute(attribute); if (value.isEmpty()) { value = QString(); } return value; }
void RegistryPersistence::AddWarning(QList<SmartPointer<IStatus> >& warningsToLog, const QString& message, const SmartPointer<IConfigurationElement>& element, const QString& id, const QString& extraAttributeName, const QString& extraAttributeValue) { QString statusMessage = message; if (element.IsNotNull()) { statusMessage += ": plug-in='" + element->GetContributor()->GetName() + '\''; } if (!id.isNull()) { if (element.IsNotNull()) { statusMessage += ','; } else { statusMessage += ':'; } statusMessage += " id='" + id + '\''; } if (!extraAttributeName.isNull()) { if ((element.IsNotNull()) || (!id.isNull())) { statusMessage += ','; } else { statusMessage += ':'; } statusMessage += ' ' + extraAttributeName + "='" + extraAttributeValue + '\''; } IStatus::Pointer status(new Status(IStatus::WARNING_TYPE, PlatformUI::PLUGIN_ID(), 0, statusMessage, BERRY_STATUS_LOC)); warningsToLog.push_back(status); }
bool CSprite::loadHQSprite( const std::string& filename ) { if(!IsFileAvailable(filename)) return false; if(!mpSurface.empty()) { const std::string fullpath = GetFullFileName(filename); SmartPointer<SDL_Surface> temp_surface = SDL_LoadBMP( fullpath.c_str() ); if(!temp_surface.empty()) { SmartPointer<SDL_Surface> displaysurface = SDL_ConvertSurface(temp_surface.get(), mpSurface->format, mpSurface->flags); readMask(displaysurface.get()); readBBox(displaysurface.get()); SDL_BlitSurface(displaysurface.get(), NULL, mpSurface.get(), NULL); return true; } } return false; }
AgentPointer WorldFacadeImpl::findAgentByName(string name) { for (LocationMap::const_iterator it = locations.begin(); it != locations.end(); it++) { LocationPtr location = it->second; //cout << "FOUND LOCATION: " << *location << endl; AgentList agentsInside = location->agentsInside(); for (AgentList::const_iterator it2 = agentsInside.begin(); it2 != agentsInside.end(); it++) { SmartPointer<Agent> agent = *it2; //cout << "FOUND AGENT: " << *agent << endl; if (name == agent->getName()) { //cout << "AGENT MATCH NAME: " << name << endl; return agent; } } } return NULL; }
SmartPointer<const IStatus> EditorHistory::SaveState(const SmartPointer<IMemento>& memento) const { for (auto iter = fifoList.begin(); iter != fifoList.end(); ++iter) { if ((*iter)->CanSave()) { IMemento::Pointer itemMemento = memento->CreateChild(WorkbenchConstants::TAG_FILE); (*iter)->SaveState(itemMemento); } } return Status::OK_STATUS(BERRY_STATUS_LOC); }
BufferEvent::BufferEvent(cb::Event::Base &base, const SmartPointer<SSLContext> &sslCtx, const string &host) : bev(0), deallocate(true) { if (sslCtx.isNull()) bev = bufferevent_socket_new(base.getBase(), -1, BEV_OPT_CLOSE_ON_FREE); #ifdef HAVE_OPENSSL else { ::SSL *ssl = SSL_new(sslCtx->getCTX()); #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME if (!host.empty() && host.find_first_not_of("1234567890.") != string::npos) SSL_set_tlsext_host_name(ssl, host.c_str()); #endif bev = bufferevent_openssl_socket_new (base.getBase(), -1, ssl, BUFFEREVENT_SSL_CONNECTING, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_DEFER_CALLBACKS); } #else else THROW("C! was not built with OpenSSL support");