void process_tasks() { #define MAX_THREADS 64 int i, ret, nthreads, max_queue_len; pthread_t threads[MAX_THREADS]; pthread_attr_t attr; void worker(), boss(); /* initialization code */ /* ... */ /* determine the number of threads to create and max queue length */ nthreads = optimal_number_of_threads(); max_queue_len = optimal_queue_length(); /* initialize the queue */ if ( queue_init(&thr_queue, max_queue_len) != 0 ) { fprintf(stderr, "queue_init() error\n"); exit(-1); } /* initialize any special thread attributes (if needed) */ (void) pthread_attr_init(&attr); /* ... */ /* create worker threads */ for (i = 1; (i < nthreads) && (i < MAX_THREADS); i++) { ret = pthread_create(&threads[i], &attr, (void *(*)())worker, NULL); check_error(ret, "pthread_create()"); } (void) pthread_attr_destroy(&attr); /* we are in the boss thread */ boss(); /* request the workers terminate when all work is processed */ if ( queue_terminate_workers(&thr_queue) != 0 ) { fprintf(stderr, "dequeue() error\n"); exit(-1); } /* wait for the workers to terminate */ for (i = 1; (i < nthreads) && (i < MAX_THREADS); i++) { ret = pthread_join(threads[i], NULL); check_error(ret, "pthread_join()"); } /* perform any final processing and return */ }
int main(int argc, char* argv[]) { std::list<TEmployee*> mlist; TManager boss("Ezha", "Fukin", 'V', 1, 100); mlist.push_back(&boss); TEmployee analyst("Yosya", "Gupkin", 'M', 2); mlist.push_back(&analyst); for (std::list<TEmployee*>::const_iterator it = mlist.begin(); it != mlist.end(); ++it) { (*it)->Print(); std::cout << std::endl; } return (0); }
void Cconfig::save() //saves to ~/.gnurpgm/config { QDir targetFolder( QDir::homePath() + "/.gnurpgm" ); if (!targetFolder.exists()) targetFolder.mkdir( QDir::homePath() + "/.gnurpgm" ); //writing the lines QFile target( QDir::homePath() + "/.gnurpgm/config" ); // if (target.exists()) // target.remove(); if ( !target.exists() ) { // target. } if (!target.open(QIODevice::WriteOnly)) { // QMessageBox::information(this,tr("File Error"),tr("Could not write config File:\n") + this->targetConfigFile); } //now write those bastards! QTextStream boss(&target); // QString bla; boss << tr("#Notice, that changing things in here may eat your toaster *dump*") << "\r\n"; boss << "mainwindow_x=" << this->config_file_system->mainWindowX << "\r\n"; boss << "mainwindow_y=" << this->config_file_system->mainWindowY << "\r\n"; boss << "mainwindow_width=" << this->config_file_system->mainWindowWidth << "\r\n"; boss << "mainwindow_height=" << this->config_file_system->mainWindowHeight << "\r\n"; boss << "guistyle=" << QString::number(this->config_file_system->guiStyle) << "\r\n"; //see *.h for 0=.. boss << "guitype=" << QString::number(this->config_file_system->guiType) << "\r\n"; //see *.h for 0=.. boss << "lastprojectpath=" << this->config_file_system->lastProjectFilePath << "\r\n"; //boss << "updatetype=" << QString::number( this->config_file_system->updateCycle ) << "\r\n"; boss << "lastupdate=" << this->config_file_system->updateLastUpdateDate.toString( "dd.MM.yyyy" ) << "\r\n"; boss << "language=" <<this->config_file_system->language << "\r\n"; boss << "autosave_delay=" << QString::number(this->config_file_system->autosave_delay) << "\r\n"; if ( this->config_file_system->checkForUpdateOnStartup ) boss << "updateautocheck=true" << "\r\n"; else boss << "updateautocheck=false" << "\r\n"; if ( this->config_file_system->showTutorials ) boss << "showtutorials=true" << "\r\n"; else boss << "showtutorials=false" << "\r\n"; if ( this->config_file_system->acceptedLicense ) boss << "accepted_license=true" << "\r\n"; else boss << "accepted_license=false" << "\r\n"; if ( this->config_file_system->useKicon ) boss << "kicon=true" << "\r\n"; else boss << "kicon=false" << "\r\n"; if ( this->config_file_system->depug ) boss << "debug=true" << "\r\n"; else boss << "debug=false" << "\r\n"; boss << "main_menu_buttons_style=" <<this->config_file_system->main_menu_buttons_style << "\r\n"; if ( this->config_file_system->main_menu_buttons_show_text ) boss << "main_menu_buttons_show_text=true" << "\r\n"; else boss << "main_menu_buttons_show_text=false" << "\r\n"; if ( this->config_file_system->main_menu_buttons_show_icons ) boss << "main_menu_buttons_show_icons=true" << "\r\n"; else boss << "main_menu_buttons_show_icons=false" << "\r\n"; // boss << "current_version=" <<this->config_file_system->current_version << "\r\n"; target.close(); }
UINT MainLoop(WindowManager *winmgr) { //window setting Window window; winmgr->RegisterWindow(&window); ARSG g(window.hWnd, WINDOW_WIDTH, WINDOW_HEIGHT, true); ARSI *keyIn = window.GetInputHandler(); ARSS s; Sound bgm, badend, atk; s.CreateSoundBuffer(&atk, L"../sound/atk.wav"); s.CreateSoundBuffer(&bgm, L"../sound/bgm.wav"); s.CreateSoundBuffer(&badend, L"../sound/fadein.wav"); //Texture Texture board; Texture bg; Texture mask; Texture gameover; Texture clear; //BitPlane BitPlane source; BitPlane stored; BitPlane hitArea; BitPlane bitmask; //Light Light light; g.CreateLight(&light); light.SetLightIntensity(10); //Camera ARSD d; d.Init(); d.AttachCam(0); d.BindBitPlane(&source); d.StartGraph(); while (!source.GetPointer()); source.GetSize(&sizex, &sizey, &depth); source.CopyTo(&stored); //background g.CreateTexture(&bg, L"../img/bgbg.jpg"); bg.SetDrawMode(true); g.CreateTexture(&mask, L"../img/mask.jpg"); mask.SetDrawMode(true); mask.GetBitData(&bitmask); g.CreateTexture(&board, sizex, sizey); board.SetDrawMode(true); Mesh f; g.CreateMesh(&f, L"../model/f4.x"); float scale=25.0f; f.SetScale(scale, scale, scale, GL_ABSOLUTE); f.SetPosition(45.0f, -4.0f, 65.0f, GL_ABSOLUTE); f.SetRotationY(1.57f); g.CreateTexture(&gameover, L"../img/gameover.jpg"); gameover.SetDrawMode(true); g.CreateTexture(&clear, L"../img/clear.PNG"); gameover.SetDrawMode(true); //gun Gun gun(&g, &s, L"gun2.x", L"../sound/gun2.wav"); gun.DefaultPosition(0.0f, -1.2f, -17.0f); gun.SetRotation(-0.1f, 3.14f, 0.0f, GL_ROTXYZ, GL_ABSOLUTE); //enemy int i, j; Batman bats[BAT]; for(i=0,j=-1; i<BAT; ++i,j*=-1){ new(bats+i)Batman(j*3.0f, 5.0f, 25.0f, j*-1*0.02f, -0.03f, -0.25f, j*-1*0.04f); bats[i].setting(&g, L"../model/bat.x"); } Bone bons[BONE]; for(i=0; i<BONE; ++i){ new(bons+i)Bone(i*2, -4.8f, 20.0f, 0.0f, 0.01f, -0.25f); bons[i].setting(&g, L"../model/bone.x"); } Boss boss(0.0f, -8.0f, 5.0f); boss.setSize(3.0f); boss.setting(&g, L"../model/teki.x"); //add g.RegisterLight(&light); g.RegisterShape(&bg); g.RegisterShape(&f); for(i=0; i<BAT; ++i) g.RegisterShape(&bats[i]); g.RegisterShape(&board); g.RegisterShape(&gun); Effect e(&g); Player p(&g); enum {START, BAD, SCARLE, ARMER, BOSS, GAMEOVER, END}; int state = START; unsigned int cnt=0; j=0; bgm.Play(true); while (!winmgr->WaitingForTermination()){ if (keyIn->GetKeyTrig('A')) source.CopyTo(&stored); if (keyIn->GetKeyTrig('Q')) break; subtract_maskf(&bitmask, &hitArea,&stored,&source,0x50505050); gun.move(&hitArea); switch(state){ case START: if(cnt==20){ cnt=0; state=BAD; } break; case BAD: if(cnt<400) f.SetPosition(-0.004f, 0.0f, -0.05f, GL_RELATIVE); else if(cnt<410) f.SetPosition(-0.01f, 0.0f, -0.15f, GL_RELATIVE); else if(cnt<420){ f.SetRotationY(-0.157f); f.SetPosition(-9.0f, 0.0f, -1.7f, GL_RELATIVE); }else if(cnt<565){ f.SetRotationY(-0.001f); f.SetPosition(-0.04f, 0.0f, -0.14f, GL_RELATIVE); }else if(cnt<745){ f.SetRotationY(0.001f); f.SetPosition(0.0f, 0.0f, -0.15f, GL_RELATIVE); }else if(cnt<770){ f.SetRotationY(0.052f); f.SetPosition(1.5f, 0.0f, 0.72f, GL_RELATIVE); }else if(cnt==771){ cnt=0; j=0; state=SCARLE; for(i=0; i<BONE; ++i) g.RegisterShape(&bons[i]); e.reSet(); } break; case SCARLE: if(cnt<45){ f.SetPosition(0.0f, 0.0f, 0.31f, GL_RELATIVE); }else if(cnt == 201){ cnt=0; j=0; state=ARMER; for(i=0; i<BONE; ++i) g.UnregisterShape(&bons[i]); } break; case ARMER: if(cnt<20){ f.SetRotationY(0.055f); f.SetPosition(1.5f, 0.0f, 0.72f, GL_RELATIVE); }else if(cnt<100){ f.SetRotationY(0.005f); f.SetPosition(0.12f, 0.0f, -0.16f, GL_RELATIVE); }else if(cnt<210){ f.SetPosition(0.0f, 0.0f, -0.175f, GL_RELATIVE); }else if(cnt<220){ f.SetRotationY(-0.055f); f.SetPosition(-0.1f, 0.0f, -0.2f, GL_RELATIVE); }else if(cnt<370){ f.SetRotationY(0.003f); f.SetPosition(0.0f, 0.0f, -0.12f, GL_RELATIVE); } if(p.getWin()){ state=BOSS; } if(cnt==360){ g.RegisterShape(&boss); e.reSet(); } if(cnt>370){ boss.move(&p, &e, &atk); boss.hitCheck(&gun, &e, &p); } break; case BOSS: bgm.Stop(); g.RegisterShape(&clear); state=END; break; case GAMEOVER: bgm.Stop(); badend.Play(); g.RegisterShape(&gameover); state=END; break; default: break; } if(state==START || state==BAD){ if(j<BAT && cnt%61==0) ++j; for(i=0; i<j; ++i){ bats[i].move(&p, &e, &atk); bats[i].hitCheck(&gun, &e); } } if(state==SCARLE){ if(j<BONE && cnt%61==0) ++j; for(i=0; i<j; ++i){ bons[i].move(&p, &e, &atk); bons[i].hitCheck(&gun, &e); } } e.addEffect(); if(p.checkHP()) state=GAMEOVER; board.SetBitData(&hitArea); g.Draw(); ++cnt; } d.StopGraph(); return 0; }
void VRAY_clusterThis::preProcess(GU_Detail * gdp) { GEO_Point * ppt; long int num_points = (long int) gdp->points().entries(); long int stat_interval = (long int)(num_points * 0.10) + 1; for(uint32 i = gdp->points().entries(); i-- > 0;) { ppt = gdp->points()(i); myPointList.append(i); } // If the user wants to build grids for pre processing // TODO: Should this be an option? There may be functions/features that will depend on this ... discuss! if(!myPreProcess) return; if(myVerbose > CLUSTER_MSG_INFO) cout << "VRAY_clusterThis::preProcess() Pre Processing Voxels" << std::endl; // openvdb::ScalarGrid::Accessor accessor; // openvdb::FloatTree myTree; openvdb::FloatTree::ConstPtr myGeoTreePtr; openvdb::VectorTree::ConstPtr myGeoGradTreePtr; ParticleList paGeoList(gdp, myPreVDBRadiusMult, myPreVDBVelocityMult); openvdb::tools::PointSampler myGeoSampler, geoGradSampler; // openvdb::tools::GridSampling<openvdb::FloatTree> myGridSampler; if(myVerbose == CLUSTER_MSG_DEBUG) std::cout << "VRAY_clusterThis::preProcess() paGeoList.size() ... " << paGeoList.size() << std::endl; if(paGeoList.size() != 0) { hvdb::Interrupter boss("VRAY_clusterThis::preProcess() Converting particles to level set"); Settings settings; settings.mRadiusMin = myPreRadiusMin; settings.mRasterizeTrails = myPreRasterType; settings.mDx = myPreDx; // only used for rasterizeTrails() settings.mFogVolume = myPreFogVolume; settings.mGradientWidth = myPreGradientWidth; // only used for fog volume float background; // background in WS units if(myPreWSUnits) background = myPreBandWidth; // background NOT in WS units else background = myPreVoxelSize * myPreBandWidth; // Construct a new scalar grid with the specified background value. openvdb::math::Transform::Ptr transform = openvdb::math::Transform::createLinearTransform(myPreVoxelSize); // openvdb::ScalarGrid::Ptr myGeoGrid = openvdb::ScalarGrid::create(background); myGeoGrid = openvdb::ScalarGrid::create(background); myGeoGrid->setTransform(transform); myGeoGrid->setGridClass(openvdb::GRID_LEVEL_SET); // Perform the particle conversion. this->convert(myGeoGrid, paGeoList, settings, boss); if(myVerbose == CLUSTER_MSG_DEBUG) { std::cout << "VRAY_clusterThis::preProcess() - activeVoxelCount(): " << myGeoGrid->activeVoxelCount() << std::endl; std::cout << "VRAY_clusterThis::preProcess() - background: " << myGeoGrid->background() << std::endl; } // Insert the new grid into the ouput detail. UT_String gridNameStr = "ClusterGrid"; myGeoGrid->insertMeta("float type", openvdb::StringMetadata("averaged_velocity")); myGeoGrid->insertMeta("name", openvdb::StringMetadata((const char *)gridNameStr)); myGeoGrid->insertMeta("VoxelSize", openvdb::FloatMetadata(myPreVoxelSize)); myGeoGrid->insertMeta("background", openvdb::FloatMetadata(background)); UT_Vector3 pos, seed_pos, currVel; // const GA_PointGroup * sourceGroup = NULL; long int pt_counter = 0; float radius = 5.0f; if(myVerbose > CLUSTER_MSG_INFO) std::cout << "VRAY_clusterThis::preProcess() - Massaging data ... " << std::endl; long int pointsFound = 0; GEO_AttributeHandle inst_vel_gah = gdp->getPointAttribute("v"); GEO_AttributeHandle source_vel_gah = gdp->getPointAttribute("v"); GEO_AttributeHandle inst_N_gah = gdp->getPointAttribute("N"); GEO_AttributeHandle source_N_gah = gdp->getPointAttribute("N"); GEO_AttributeHandle inst_Cd_gah = gdp->getPointAttribute("Cd"); GEO_AttributeHandle source_Cd_gah = gdp->getPointAttribute("Cd"); GEO_AttributeHandle inst_Alpha_gah = gdp->getPointAttribute("Alpha"); GEO_AttributeHandle source_Alpha_gah = gdp->getPointAttribute("Alpha"); if(!inst_vel_gah.isAttributeValid()) throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Instance velocity handle invalid, exiting ...", 1); if(!source_vel_gah.isAttributeValid()) throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Source velocity handle invalid, exiting ...", 1); if(!inst_N_gah.isAttributeValid()) throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Instance normal handle invalid, exiting ...", 1); if(!source_N_gah.isAttributeValid()) throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Source normal handle invalid, exiting ...", 1); if(!inst_Cd_gah.isAttributeValid()) throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Instance color handle invalid, exiting ...", 1); if(!source_Cd_gah.isAttributeValid()) throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Source color handle invalid, exiting ...", 1); if(!inst_Alpha_gah.isAttributeValid()) throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Instance alpha handle invalid, exiting ...", 1); if(!source_Alpha_gah.isAttributeValid()) throw VRAY_clusterThis_Exception("VRAY_clusterThis::preProcess() Source alpha handle invalid, exiting ...", 1); openvdb::FloatTree::ValueType sampleResult; openvdb::VectorGrid::ValueType gradResult; const openvdb::FloatTree aTree; openvdb::FloatTree& myGeoTree = myGeoGrid->treeRW(); openvdb::tools::Filter<openvdb::FloatGrid> preProcessFilter(*myGeoGrid); // openvdb::tools::Filter<openvdb::FloatGrid> barFilter(myGeoGrid); if(myPreVDBMedianFilter) preProcessFilter.median(); if(myPreVDBMeanFilter) preProcessFilter.mean(); if(myPreVDBMeanCurvatureFilter) preProcessFilter.meanCurvature(); if(myPreVDBLaplacianFilter) preProcessFilter.laplacian(); // if(myVDBReNormalizeFilter) // float r = barFilter.renormalize(3, 0.1); if(myPreVDBOffsetFilter) preProcessFilter.offset(myPreVDBOffsetFilterAmount); myGradientGrid = openvdb::VectorGrid::create(); // openvdb::VectorGrid::Ptr myGradientGrid = openvdb::VectorGrid::create(); myGradientGrid->setTransform(transform); // myGradientGrid->setGridClass(openvdb::GRID_FOG_VOLUME ); myGradientGrid->setGridClass(openvdb::GRID_LEVEL_SET); openvdb::tools::Gradient<openvdb::ScalarGrid> myGradient(*myGeoGrid); myGradientGrid = myGradient.process(); openvdb::VectorTree& myGeoGradTree = myGradientGrid->treeRW(); gridNameStr = "ClusterGradientGrid"; myGradientGrid->insertMeta("vector type", openvdb::StringMetadata("covariant (gradient)")); myGradientGrid->insertMeta("name", openvdb::StringMetadata((const char *)gridNameStr)); myGradientGrid->insertMeta("VoxelSize", openvdb::FloatMetadata(myPreVoxelSize)); myGradientGrid->insertMeta("background", openvdb::FloatMetadata(background)); GA_FOR_ALL_GPOINTS(gdp, ppt) { // myCurrPtOff = ppt->getMapOffset(); // std::cout << "myCurrPtOff: " << myCurrPtOff << std::endl; pos = ppt->getPos(); // Vec3d worldToIndex ( const Vec3d & xyz ) const // openvdb::Vec3R theIndex = // (openvdb::Vec3R(pos[0], pos[1], pos[2])); openvdb::Vec3R theIndex = myGeoGrid->worldToIndex(openvdb::Vec3R(pos[0], pos[1], pos[2])); radius = static_cast<fpreal>(ppt->getValue<fpreal>(myInstAttrRefs.pointVDBRadius, 0)); // std::cout << "radius: " << radius << std::endl; // static bool sample (const TreeT &inTree, const Vec3R &inCoord, typename TreeT::ValueType &sampleResult) const openvdb::Vec3R inst_sample_pos(theIndex[0], theIndex[1], theIndex[2]); bool success = myGeoSampler.sample(myGeoTree, inst_sample_pos, sampleResult); geoGradSampler.sample(myGeoGradTree, inst_sample_pos, gradResult); // // std::cout << "success: " << success << "\tpos: " << pos // << "\tinst_sample_pos: " << inst_sample_pos // << "\tsampleResult: " << sampleResult << std::endl; //ValueType sampleWorld (const Vec3R &pt) const //ValueType sampleWorld (Real x, Real y, Real z) const // if the instanced point is within the vdb volume if(success) { // std::cout << "pos: " << pos << " inst_sample_pos: " // << inst_sample_pos << " sampleResult: " << sampleResult // << " gradResult: " << gradResult << std::endl; // float weight; pointsFound++; inst_vel_gah.setElement(ppt); currVel = inst_vel_gah.getV3(); UT_Vector3 gradVect = UT_Vector3(gradResult[0], gradResult[1], gradResult[2]); ppt->setPos(pos + (myPrePosInfluence *(sampleResult * gradVect))); // ppt->setPos(pos + (sampleResult * myPosInfluence *(currVel / myFPS))); // inst_vel_gah.setV3(currVel * ((1 / sampleResult) * radius)); inst_vel_gah.setV3(currVel + (myPreVelInfluence *(sampleResult * gradVect))); // std::cout << "currVel: " << currVel << " sampleResult " << sampleResult // << " new vel: " << currVel * sampleResult << std::endl; inst_N_gah.setV3(inst_N_gah.getV3() + (myPreNormalInfluence *(sampleResult * gradVect))); // inst_Cd_gah.setElement(ppt); // inst_Cd_gah.setV3(inst_Cd_gah.getV3() * abs(sampleResult)); // // // inst_Alpha_gah.setElement(ppt); // inst_Alpha_gah.setF(inst_Alpha_gah.getF() * abs(sampleResult)); } // if the instanced point is within the vdb volume if(myVerbose == CLUSTER_MSG_DEBUG) { pt_counter++; if((long int)(pt_counter % (stat_interval * myNumCopies * myRecursion)) == 0) { cout << "VRAY_clusterThis::preProcess() Number of points pre processed: " << pt_counter << "\t - Number of points found in vdb grid: " << pointsFound << std::endl; } } }