示例#1
0
//컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴
//Procedure		ScreenShot16
//Author		Paul.
//Date			Mon 21 Apr 1997
//
//Description
//
//Inputs
//
//Returns
//
//------------------------------------------------------------------------------
void Graphic::ScreenShot16()
{
//	#pragma message (__HERE__"VidRAM read outside of lock")

    TGA		screenShot;
    ULong	packedlength;

    screenShot.redScale 	= RedShift;							//PD 24Oct97
    screenShot.redMask 		= (1<<RedBits)-1;					//PD 24Oct97
    screenShot.redBits		= RedBits;							//DAW 24Oct97

    screenShot.greenScale 	= GreenShift;						//PD 24Oct97
    screenShot.greenMask	= (1<<GreenBits)-1;					//PD 24Oct97
    screenShot.greenBits	= GreenBits;						//DAW 24Oct97

    screenShot.blueScale	= BlueShift;						//PD 24Oct97
    screenShot.blueMask		= (1<<BlueBits)-1;					//PD 24Oct97
    screenShot.blueBits		= BlueBits;							//DAW 24Oct97

    ROWANSURFACEDESC rsd;
    Master()->DoLockScr(&rsd);

    screenShot.MakeHead(rsd.dwWidth,rsd.dwHeight);
    packedlength = screenShot.MakeBody(&rsd);		//logicalscreenptr,BytesPerScanLine);
    screenShot.Save(screenshotnum++,packedlength);
    if (screenshotnum>99)	screenshotnum=0;

    Master()->DoUnlockScr(&rsd);
}
示例#2
0
/** $(class), OnConnect:
 *  Detailed description.
 *  @return TODO
 */
void Screen::OnConnect(){
    //Hookable::Connect();
    m_conDraw = Master()->ConnectOnDraw( boost::bind( &Screen::OnDraw, boost::ref(*this) ) );
    m_conUpdate = Master()->ConnectOnUpdate( boost::bind( &Screen::OnUpdate, boost::ref(*this) ) );
    m_conEvt = Master()->ConnectOnEvent( boost::bind(&Screen::OnEvent, boost::ref(*this), _1) );
    OnFocus();
}
示例#3
0
			/// Print all registered types derived from T
			/// If multiline is true, each type name is printed on its own line, otherwise
			/// they are printed on a single line with space separation.
			static void Print(bool multiline = true)
			{
				if (!multiline)
				{
					for (auto t : Master().types) std::cout << t.first << " ";
					std::cout << std::endl;
				}
				else for (auto t : Master().types) std::cout << "    " << t.first << std::endl;
			}
示例#4
0
    /** HopperScreen, OnDraw:
     *  Detailed description.
     *  @return TODO
     */
    void HopperScreen::OnDraw(){
        static int coldelta = 0;

        CMainCanvas* m_pMainCanvas = Master()->GetMainCanvas();
        m_pMainCanvas->Lock();

        //m_pMainCanvas->Blit( m_pMainCanvas->GetDimension(), *m_pBackground, m_pBackground->GetDimension() );
        m_pBackground->RenderCopy();
        /*CRectangle frect(700, 500, 185, 185);
           SDL_Color* wavemap = ColorData::Instance()->Wavemap();
           int index = (coldelta * 2 & 63);

           //m_pMainCanvas->FillRect( frect, mcol );
           SDL_Color& fcol = wavemap[index];
           m_pMainCanvas->FillRect( frect, CColor(fcol.r, fcol.g, fcol.b) );
           m_pMainCanvas->AddUpdateRect(frect);*/

        CRectangle txtDims = m_pScrollText->GetCanvas()->GetDimension();
        CRectangle dstDims = txtDims + CPoint( 335, 200);
        m_pScrollText->Put(m_pBackground.get(), dstDims, txtDims );
        m_pMainCanvas->AddUpdateRect(dstDims);

        coldelta++;

        if (coldelta > 64) {
            coldelta = 0;
        }

        m_pSprMgr->OnDraw();

        m_pMainCanvas->Unlock();
    } // OnDraw
int main(int argc, char *argv[])
{
  shmem_init();
  input_file = argv[1];
  mype = shmem_my_pe();
  NumProcs = shmem_n_pes();
  shmemx_am_attach(hid_BESTPATH, &handler_master_bestpath);
  shmemx_am_attach(hid_SUBSCRIBE, &handler_master_subscribe);
  shmemx_am_attach(hid_PUTPATH, &handler_master_putpath);
  shmemx_am_mutex_init(&lock_shortestlen);
  shmemx_am_mutex_init(&lock_queue);
  shmemx_am_mutex_init(&lock_workers_stack);

  if (NumProcs<2) {
    printf("At least 2 processes are required\n");
    exit(-1);
  }  

  
  // Initialize distance matrix. Ususally done by one process 
  // and bcast, or initialized from a file in a shared file system.
  Fill_Dist();  // process 0 read the data and broadcast it to the others

  if (mype==0) 
    Master();
  else
    Worker();
  
  //TODO
//  shmemx_am_detach(hid_BESTPATH);
//  shmemx_am_detach(hid_SUBSCRIBE);
//  shmemx_am_detach(hid_PUTPATH);
  shmem_finalize();
  return 0;
}
示例#6
0
void PlanSelect::MPI_Write (void)
{
#ifdef MPI_EXE
    if (Master ()) {

        mpi_buffer.Data (&num_select, sizeof (num_select));

        if (num_select > 0) {
            select_map.Pack (mpi_buffer);
        }
        for (int rank=1; rank < MPI_Size (); rank++) {
            Send_MPI_Buffer (rank);
        }

    } else {	//---- slave ----

        num_select = 0;
        select_map.clear ();

        Get_MPI_Buffer (0);

        if (mpi_buffer.Size () > 0) {
            mpi_buffer.Get_Data (&num_select, sizeof (num_select));

            if (num_select > 0) {
                select_map.UnPack (mpi_buffer);
            }
        }
    }
#endif
}
示例#7
0
void Renderer::pyHandleCustomCtorArgs(py::tuple& args, py::dict& kw){
	if(py::len(kw)>0){
		string keys; py::list k(kw.keys());
		for(int i=0; i<py::len(k); i++) keys+=(i>0?", ":"")+py::extract<string>(k[i])();
		Master().instance().checkApi(10102,"Constructing Renderer with keywords ("+keys+") will have no effect unless passed to GlSetup/S.gl.",/*pyWarn*/true);
	}
}
示例#8
0
void Template::OnDraw(){
    static int coldelta = 0;

    CMainCanvas* m_pMainCanvas = Master()->GetMainCanvas();
    m_pMainCanvas->Lock();

    //m_pMainCanvas->Blit( m_pMainCanvas->GetDimension(), *m_pBackground,
    // m_pBackground->GetDimension() );
    m_pBackground->RenderCopy();
    CRectangle frect(700, 500, 185, 185);
    SDL_Color* wavemap = ColorData::Instance()->Wavemap();
    int index = (coldelta * 2 & 63);

    //m_pMainCanvas->FillRect( frect, mcol );
    SDL_Color& fcol = wavemap[index];
    CColor color = CColor(fcol.r, fcol.g, fcol.b);
    m_pMainCanvas->RenderFillRect( frect, &color );
    //m_pMainCanvas->AddUpdateRect(frect);

    CRectangle dstDims( 0, 0, 200, 200);
    //m_pScrollText->RenderPut(m_pBackground.get(), dstDims, dstDims );
    //m_pMainCanvas->AddUpdateRect(dstDims);
    m_pScroller->Render();

    coldelta++;

    if (coldelta > 64) {
        coldelta = 0;
    }

    //controls::CControl::Redraw();
    m_pOverlay->Draw();
    m_pMainCanvas->Unlock();
}   // OnDraw
示例#9
0
/*GroupId Template::GetGroupID()
   {
    static GroupId grpID = CreateNextGroupID();
    return grpID;
    //throw std::exception("The method or operation is not implemented.");
   }*/
bool Template::OnInit( int argc, char* argv[] ){
    // Master()->GetMainCanvas();
    CMainCanvas* m_pMainCanvas = Master()->GetMainCanvas();
    //m_pOverlay.reset(new DebugOverlay(m_Loader, controls::CControl::GetMainControl(), 1,
    // "Template"));
    m_pOverlay.reset( new DebugOverlay(m_Loader, NULL, 1, "Template") );

    //m_pBackground = CCanvas::CreateRGBCompatible(NULL, 1024, 768 - 320);
    //m_pBackground = CCanvas::CreateRGBCompatible(NULL, NULL, NULL);
    // Todo: c:\program files\graphviz 2.28\bin\LIBFREETYPE-6.DLL copy from DEPS
    TTF_Font* m_pArialfont;
    m_pArialfont = m_Loader.FL_LOADFONT("Fonts/ARIAL.TTF", 24);
    mcol = CColor::White();
    SDL_Surface* tmpfsurf = ( m_Loader.FL_LOADIMG("Intro/TemplateBg.png") );

    //SDL_SetColorKey(tmpfsurf, SDL_SRCCOLORKEY, 0xff00ff);
    //SDL_SetColorKey(m_pMainCanvas->GetSurface(), SDL_SRCCOLORKEY, 0xff00ff);
    //SDL_SetAlpha(tmpfsurf, SDL_SRCALPHA, 0);
    //SDL_SetAlpha(m_pMainCanvas->GetSurface(), SDL_SRCALPHA, 128);
    m_pBackground.reset( new CCanvas( tmpfsurf ) );

    //CCanvas tmpCanvas( tmpfsurf );
    m_Loader.FreeLast();

    //m_pMainCanvas->Blit(m_pMainCanvas->GetDimension(), tmpCanvas, tmpCanvas.GetDimension());
    //m_pBackground->Blit(m_pBackground->GetDimension(), tmpCanvas, tmpCanvas.GetDimension());
    //m_pMainCanvas->AddUpdateRect( m_pBackground->GetDimension() );

    //"\r\n"
    CColor m_colText = CColor::White();
    std::ostringstream outstring;
    outstring << "Bla fasel:" << gui::CApplication::ShownFrames();
    outstring << " ";

    //std::string pstr;
    outstring <<
        "Error error C2248: 'boost::noncopyable_::noncopyable::noncopyable' : cannot access private member "
              <<
        "declared in class " <<
        "'boost::noncopyable_::noncopyable'" << "\t" <<
        "d:/e/projects/c++/humbug/projects/humbug/src/gui/visual/Hookable.h" <<
        "\t" << "48" << "\t" << "Humbug" << "\r\n" <<
        "\r\n" <<
        "Error" << "\t" << "3" << "\t" <<
        "error C2248: 'boost::scoped_ptr<T>::scoped_ptr' : cannot access private member declared in "
              <<
        "class " <<
        "'boost::scoped_ptr<T>'" << "\t" <<
        "d:/e/projects/c++/humbug/projects/humbug/src/gui/visual/Hookable.h" << "\t" << "48" << "\t" <<
        "Humbug" << "\r\n" <<
        "";

    m_pScrollText.reset( new CText(m_pArialfont, outstring.str(), m_colText) );
    m_pScroller.reset(new CTextScroller(m_pBackground.get(), *m_pScrollText, CPoint(100, 600), 800));

    return Screen::OnInit(argc, argv);

    //return true;
}   // OnInit
示例#10
0
文件: Screen.cpp 项目: Jedzia/Humbug
/** $(class), OnUpdate:
 *  Detailed description.
 *  @return TODO
 */
void Screen::OnUpdate() {
    // Hookable::OnUpdate() runs SDL_UpdateTexture of the main texture with following
    // SDL_RenderCopy. Means GetSurface()->pixels to texture and then update render copy
    // later this should not need the surface any more
    if(!m_bUsesSDL2Render) {
        // render old SDL1 blit canvas stuff to the main window
        Master()->GetMainCanvas()->MainUpdateAndRenderCopy();
    }
}
示例#11
0
/*GroupId TestScreen::GetGroupID()
   {
    static GroupId grpID = CreateNextGroupID();
    return grpID;
    //throw std::exception("The method or operation is not implemented.");
   }*/
  bool TestScreen::OnInit( int argc, char* argv[] ){
      // Master()->GetMainCanvas();
      CMainCanvas* m_pMainCanvas = Master()->GetMainCanvas();

      //m_pBackground = CCanvas::CreateRGBCompatible(NULL, 1024, 768 - 320);
      //m_pBackground = CCanvas::CreateRGBCompatible(NULL, NULL, NULL);
      // Todo: c:\program files\graphviz 2.28\bin\LIBFREETYPE-6.DLL copy from DEPS
      m_pArialfont = TTF_OpenFont("D:/E/Projects/C++/Humbug/build/Humbug/src/Debug/arial.ttf", 30);
      mcol = CColor::White();
      SDL_Surface* tmpfsurf = ( m_Loader.FL_LOADIMG("Intro/TestScreenBg.png") );

      //SDL_SetColorKey(tmpfsurf, SDL_TRUE, 0xff00ff);
      //SDL_SetColorKey(m_pMainCanvas->GetSurface(), SDL_TRUE, 0xff00ff);
      //SDL_SetSurfaceAlphaMod(tmpfsurf, 0);
      //SDL_SetSurfaceAlphaMod(m_pMainCanvas->GetSurface(), 128);
      m_pBackground.reset( new CCanvas( tmpfsurf ) );

      //CCanvas tmpCanvas( tmpfsurf );
      m_Loader.FreeLast();

      //m_pMainCanvas->Blit(m_pMainCanvas->GetDimension(), tmpCanvas, tmpCanvas.GetDimension());
      //m_pBackground->Blit(m_pBackground->GetDimension(), tmpCanvas, tmpCanvas.GetDimension());
      m_pMainCanvas->AddUpdateRect( m_pBackground->GetDimension() );

      //"\r\n"
      CColor m_colText = CColor::White();
      std::ostringstream outstring;
      outstring << "Bla fasel:" << gui::CApplication::ShownFrames();
      outstring << " ";

      //std::string pstr;
      outstring <<
      "Error error C2248: 'boost::noncopyable_::noncopyable::noncopyable' : cannot access private member "
                <<
      "declared in class " <<
      "'boost::noncopyable_::noncopyable'" << "\t" <<
      "d:/e/projects/c++/humbug/projects/humbug/src/gui/visual/Hookable.h" <<
      "\t" << "48" << "\t" << "Humbug" << "\r\n" <<
      "\r\n" <<
      "Error" << "\t" << "3" << "\t" <<
      "error C2248: 'boost::scoped_ptr<T>::scoped_ptr' : cannot access private member declared in "
              <<
      "class " <<
      "'boost::scoped_ptr<T>'" << "\t" <<
      "d:/e/projects/c++/humbug/projects/humbug/src/gui/visual/Hookable.h" << "\t" << "48" << "\t" <<
      "Humbug" << "\r\n" <<
      "";

      m_pScrollText.reset( new CText(m_pArialfont, outstring.str(), m_colText) );

      return Screen::OnInit(argc, argv);

      //return true;
  } // OnInit
示例#12
0
			/// List all available types
			static std::vector<std::string> List()
			{
				std::vector<std::string> result;

				for (auto &t : Master().types)
				{
					result.push_back(t.first);
				}

				return result;
			}
示例#13
0
			/// Create instances of all registered classes
			static std::map<std::string, std::unique_ptr<T>> CreateAll()
			{
				std::map<std::string, std::unique_ptr<T>> result;

				for (auto &t : Master().types)
				{
					result.insert(std::make_pair(t.first, std::unique_ptr<T>(t.second->constructor())));
				}

				return result;
			}
示例#14
0
int sc_main(int ac, char *av[])
{
  sc_signal<bool> data_ready;
  sc_signal<bool> data_ack;
  sc_signal<int> data;

  sc_clock clock("CLOCK", 10, SC_NS, 0.5, 0.0, SC_NS);

  proc1 Master("MasterProcess", clock, data_ack, data, data_ready);
  proc2 Slave("SlaveProcess", clock, data_ready, data, data_ack);

  sc_start();
  cout << "SIMULATION COMPLETED AT TIME " << sc_time_stamp() << endl;
  return 0;
}
示例#15
0
bool Simulator_Base::Step_IO (void)
{
	if (Num_Threads () > 1) {
		return (io_barrier.Start ());
	} else {
		snapshot_output.Output_Check ();
		link_delay_output.Output_Check ();
		performance_output.Output_Check ();
		ridership_output.Output_Check ();
		turn_vol_output.Output_Check ();
		occupancy_output.Output_Check ();
#ifdef MPI_EXE
		problem_output.MPI_Processing ();
		event_output.MPI_Processing ();
		traveler_output.MPI_Processing ();
#endif
		if (Master ()) {
			return (sim_read_plans.Read_Plans ());
		} else {
			return (true);
		}
	}
}
示例#16
0
			/// Create an instance of the class from the given name
			/// Returns an empty unique_ptr if the class name cannot be found
			static std::unique_ptr<T> Create(std::string name)
			{
				return Master().types.count(name)
					? std::unique_ptr<T>(Master().types[name]->constructor())
					: std::unique_ptr<T>();
			}
示例#17
0
			/// Constructor takes the class name, referred to by the lowercase hyphenated
			/// name in the lookup table. It also takes a function which instantiates
			/// the derived type in question.
			Type(std::string name, std::function<T *()> constructor) : constructor(constructor)
			{
				Master().types[String::hyphenate(name)] = this;
			}
示例#18
0
void TripPrep::MPI_Setup (void)
{
#ifdef MPI_EXE
	if (MPI_Size () == 1) return;

	int range [2];

	if (Master ()) {
		int num_parts, rank;
		Db_File temp_file;
		String key, dir;
		Integers count;
		Int_Itr itr;
		Int_RItr ritr;

		dir = Get_Control_String (PROJECT_DIRECTORY);
		if (!dir.empty ()) {
			Fix_Directory (dir);
		}
		key = Get_Control_String (System_File_ID (TRIP));
	
		temp_file.Filename (dir + key);
		num_parts = temp_file.Num_Parts ();
		if (num_parts < 2) return;

		Write (1, "Number of MPI Processors = ") << MPI_Size ();
		Write (1, "Number of Trip Partitions = ") << num_parts;
		Write (1);

		count.assign (MPI_Size (), 0);

		for (itr = count.begin (); itr != count.end (); itr++) {
			(*itr)++;
			if (--num_parts == 0) break;
		}
		while (num_parts > 0) {
			for (ritr = count.rbegin (); ritr != count.rend (); ritr++) {
				(*ritr)++;
				if (--num_parts == 0) break;
			}
		}
		num_parts = 0;

		for (rank=0, itr = count.begin (); itr != count.end (); itr++, rank++) {
			range [0] = num_parts;
			num_parts += *itr;
			range [1] = num_parts - 1;

			if (rank == 0) {
				First_Partition (range [0]);
				Last_Partition (range [1]);
			} else {
				Send_MPI_Array (range, 2, rank);
			}
		}

	} else {	//---- slave ----

		Get_MPI_Array (range, 2, 0);

		First_Partition (range [0]);
		Last_Partition (range [1]);
	}
#endif
}
示例#19
0
void PlanCompare::MPI_Processing (void)
{
#ifdef MPI_EXE
	int i, lvalue [7], rank;

	if (Master ()) {
		Write (1);

		for (i=1; i < MPI_Size (); i++) {

			rank = Show_MPI_Message ();

			//---- retrieve the data buffer ----

			Get_MPI_Buffer (rank);
			
			if (mpi_buffer.Size () == 0) continue;

			//---- retrieve the plan statistics

			mpi_buffer.Get_Data (lvalue, sizeof (lvalue));

			plan_file->Add_Files (lvalue [0]);
			plan_file->Add_Records (lvalue [1]);
			plan_file->Add_Households (lvalue [2]);
			plan_file->Add_Persons (lvalue [3]);
			plan_file->Add_Tours (lvalue [4]);
			plan_file->Add_Trips (lvalue [5]);
			num_trips += lvalue [6];

			//---- retrieve the compare statistics

			mpi_buffer.Get_Data (lvalue, sizeof (lvalue));

			compare_file.Add_Files (lvalue [0]);
			compare_file.Add_Records (lvalue [1]);
			compare_file.Add_Households (lvalue [2]);
			compare_file.Add_Persons (lvalue [3]);
			compare_file.Add_Tours (lvalue [4]);
			compare_file.Add_Trips (lvalue [5]);
			num_compare += lvalue [6];

			//---- selection map data ----

			selected.UnPack (mpi_buffer);

			//---- time difference data ----

			if (time_diff.Active_Flag ()) {
				Difference_Data temp;
				temp.Replicate (time_diff);

				temp.UnPack (mpi_buffer);
				time_diff.Merge_Data (temp);
			}

			//---- cost difference data ----

			if (cost_diff.Active_Flag ()) {
				Difference_Data temp;
				temp.Replicate (cost_diff);

				temp.UnPack (mpi_buffer);
				cost_diff.Merge_Data (temp);
			}

			//---- time gap data ----

			if (time_gap.Active_Flag ()) {
				Trip_Gap_Data temp;
				temp.Replicate (time_gap);

				temp.UnPack (mpi_buffer);
				time_gap.Merge_Data (temp);
			}

			//---- cost gap data ----

			if (cost_gap.Active_Flag ()) {
				Trip_Gap_Data temp;
				temp.Replicate (cost_gap);

				temp.UnPack (mpi_buffer);
				cost_gap.Merge_Data (temp);
			}

		}
		Show_Message (1);

		plan_file->Close ();
		compare_file.Close ();

	} else {	//---- slave ----

		if (Partition_Range ()) {
			Send_MPI_Message (String ("Slave %d Read %ss %d..%d") % MPI_Rank () % plan_file->File_Type () % First_Partition () % Last_Partition ());
		} else {
			Send_MPI_Message (String ("Slave %d Read %s %d") % MPI_Rank () % plan_file->File_Type () % First_Partition ());
		}

		//---- send plan statistics ----

		lvalue [0] = plan_file->Num_Files ();
		lvalue [1] = plan_file->Num_Records ();
		lvalue [2] = plan_file->Num_Households ();
		lvalue [3] = plan_file->Num_Persons ();
		lvalue [4] = plan_file->Num_Tours ();
		lvalue [5] = plan_file->Num_Trips ();
		lvalue [6] = num_trips;
		plan_file->Close ();

		mpi_buffer.Data (lvalue, sizeof (lvalue));

		//---- send compare statistics ----

		lvalue [0] = compare_file.Num_Files ();
		lvalue [1] = compare_file.Num_Records ();
		lvalue [2] = compare_file.Num_Households ();
		lvalue [3] = compare_file.Num_Persons ();
		lvalue [4] = compare_file.Num_Tours ();
		lvalue [5] = compare_file.Num_Trips ();
		lvalue [6] = num_compare;
		compare_file.Close ();

		mpi_buffer.Add_Data (lvalue, sizeof (lvalue));

		//---- selection map data ----

		selected.Pack (mpi_buffer);

		//---- time difference data ----

		if (time_diff.Active_Flag ()) {
			time_diff.Pack (mpi_buffer);
		}

		//---- cost difference data ----

		if (cost_diff.Active_Flag ()) {
			cost_diff.Pack (mpi_buffer);
		}

		//---- time gap data ----

		if (time_gap.Active_Flag ()) {
			time_gap.Pack (mpi_buffer);
		}

		//---- cost gap data ----

		if (cost_gap.Active_Flag ()) {
			cost_gap.Pack (mpi_buffer);
		}

		//---- send the data buffer ----

		Send_MPI_Buffer ();

		if (!new_plan_flag && !select_parts) Exit_Stat (DONE);
	}
#endif
}
示例#20
0
    /** HopperScreen, OnInit:
     *  Detailed description.
     *  @param argc TODO
     * @param argv TODO
     * @return TODO
     */
    bool HopperScreen::OnInit( int argc, char* argv[] ){
        // Master()->GetMainCanvas();
        CMainCanvas* m_pMainCanvas = Master()->GetMainCanvas();

        //m_pBackground = CCanvas::CreateRGBCompatible(NULL, 1024, 768 - 320);
        //m_pBackground = CCanvas::CreateRGBCompatible(NULL, NULL, NULL);
        // Todo: c:\program files\graphviz 2.28\bin\LIBFREETYPE-6.DLL copy from DEPS
        m_pArialfont = m_Loader.FL_LOADFONT("Fonts/ARIAL.TTF", 24);
        //m_pArialfont =
        // TTF_OpenFont("E:/Projects/C++/Humbug/projects/Humbug/Resources/Fonts/ARIAL.TTF", 24);
        mcol = CColor::White();
        SDL_Surface* tmpfsurf = ( m_Loader.FL_LOADIMG("Intro/HopperScreenBg.png") );

        //SDL_SetColorKey(tmpfsurf, SDL_TRUE, 0xff00ff);
        //SDL_SetColorKey(m_pMainCanvas->GetSurface(), SDL_TRUE, 0xff00ff);
        //SDL_SetSurfaceAlphaMod(tmpfsurf, 0);
        //SDL_SetSurfaceAlphaMod(m_pMainCanvas->GetSurface(), 128);
        m_pBackground.reset( new CCanvas( tmpfsurf ) );

        //CCanvas tmpCanvas( tmpfsurf );
        m_Loader.FreeLast();

        //m_pMainCanvas->Blit(m_pMainCanvas->GetDimension(), tmpCanvas, tmpCanvas.GetDimension());
        //m_pBackground->Blit(m_pBackground->GetDimension(), tmpCanvas, tmpCanvas.GetDimension());
        m_pMainCanvas->AddUpdateRect( m_pBackground->GetDimension() );

        //"\r\n"
        CColor m_colText = CColor::White();
        std::ostringstream outstring;
        outstring << "Jedzia";
        outstring << " .................... ";
        outstring << "328.123.847";

        CText* text = new CText(m_pArialfont, outstring.str(), m_colText);

        //const boost::function<void(CCanvas*, int)> textMo = mtextfloat;
        //text->AddAnimator(boost::ref( mtextfloat ));
        text->AddAnimator( WavyTextFloat(64) );
        m_pScrollText.reset(text);

        // ### Sprites ###
        m_pSprEye = new CSprite(m_Loader, "Sprites/male_sprites.png", m_pMainCanvas, CPoint(64, 0),
                CRectangle(0, 0, 64, 64) );
        m_pSprMgr->AddSprite(m_pSprEye, "mytag", hspriv::EyeMover(160, 8));
        //m_pSprMgr->AddSprite(m_pSprEye, boost::ref( pimpl_->eyemover ) );
        //m_pSprMgr->AddSprite(m_pSprEye);
        CSprite* m_pSprWormler = new CSprite(m_Loader, "Sprites/wormtiles.png", m_pMainCanvas, CPoint(0, 64),
                CRectangle(0, 0, 256, 64) );
        m_pSprWormler->SetColorAndAlpha(0xff00ff, 128);
        m_pSprMgr->AddSprite(m_pSprWormler, "mytag", hspriv::EyeMover(260, 40));

        //_CrtSetBreakAlloc(pimpl_->allocReqNum+4);
        //_crtBreakAlloc = pimpl_->allocReqNum+4;

        shost::ScriptHost shost;
        //shost.RunScript2(m_Loader.FL_LOADASSTRING("Lua/hello.lua"));
        // shost.RunScript(m_Loader.FL_LOADASSTRING("Lua/funcret.lua"));
        //shost.RunScript4(m_Loader.FL_LOADASSTRING("Lua/iowrite.lua"));
        //shost.RunScript(m_Loader.FL_LOADASSTRING("Lua/globalclass.lua"));
        //shost.RunScript6( m_Loader.FL_LOADASSTRING("Lua/globalclass.lua") );
		//shost.RunScript7( m_Loader.FL_LOADASSTRING("Lua/--FREE--.lua") );

		typedef shost::LuaScript<int, double, double> ScriptType;
		ScriptType::Script s = shost.generate<int, double, double>( m_Loader.FL_LOADASSTRING(
			"Lua/sprite1.lua"), "Ticks", "X", "Y" );
		pimpl_->script = s;

        world.FPS = CApplication::FramesCap();
        CRectangle screenRect = m_pMainCanvas->GetDimension();
        world.ScreenX = screenRect.GetW();
        world.ScreenY = screenRect.GetH();

		// Todo maybe an functor to initialize more global stuff
		(*s->AddStatic(world))("World")
			.def("greet", &greetHopper)
			.def_readonly("FPS", &World::FPS)
			.def_readonly("ScreenX", &World::ScreenX)
			.def_readonly("ScreenY", &World::ScreenY);



		ScriptType::Script sprInit = shost.generate<int, double, double>( m_Loader.FL_LOADASSTRING(
			"Sprites/male_sprites.spr"), "Ticks", "X", "Y" );
		//ScriptType::Script sprInit = shost.generate<int, double, double>( m_Loader.FL_LOADASSTRING(
		//	"Sprites/male_sprites.spr"), "Ticks", "X", "Y" );

		TestClass st(12,99);

		(*sprInit->AddStatic(st))("TestClass", "tc")
			.def(luabind::constructor<std::vector<int> >())
			.def(luabind::constructor<int, int>())
			.def("get", &TestClass::get);

		//boost::shared_ptr<shost::LuaScript::register_binder<SpriteFrame >>& bla=
		int xyz = 55;

		typedef shost::LuaVarCapsule<luabind::class_<SpriteFrame>> SprCapsule;
		SprCapsule maleSpriteCap = shost::makeFarm(sprInit,
		(*sprInit->Register<SpriteFrame>())("SpriteFrame")
			.def(luabind::constructor<int, int>())
			.def("X", &SpriteFrame::X)
			.def("Y", &SpriteFrame::Y));

		(*sprInit->Register<SpriteMovieOld>())("SpriteMovieOld")
			.def(luabind::constructor<std::string, SpriteFrame>())
			.def("X", &SpriteMovieOld::X)
			.def("Y", &SpriteMovieOld::Y);

		(*sprInit->Register<SpriteMovie>())("SpriteMovie")
			.def(luabind::constructor<std::string, std::vector<SpriteFrame>>())
			.def("X", &SpriteMovie::X)
			.def("Y", &SpriteMovie::Y);

		//luabind::class_<SpriteFrame>& xasd = maleSpriteCap.Value();
		//SprCapsule::ObjType mmy(1,2);
		//mmy.X();

		/*luabind::module(sprInit->L())
			[
				luabind::class_<TestClass>("TestClass_")
				.def(luabind::constructor<std::vector<int> >())
				.def(luabind::constructor<int, int>())
				.def("get", &TestClass::get)
			];*/


		int success = sprInit->run_script(99);

		luabind::object o3(luabind::globals(sprInit->L())["tcx"]);
		if (o3)
		{
			// is_valid
			// ...

			int luatype = luabind::type(o3);
			if (luabind::type(o3) == LUA_TUSERDATA)
			{
				TestClass otherValue = luabind::object_cast<TestClass>(o3);
				int abc = 4;
				abc++;
			}
		}

		SpriteFrame otherValue2(0,0);
		bool success3 = maleSpriteCap.GetLuaValue("spf", otherValue2);
		SpriteFrame otherValuex = maleSpriteCap.GetLuaValue("spf");

		SpriteFrame otherValue3(0,0);
		bool fsuccess = sprInit->GetLuaValue<SpriteFrame>("spf", otherValue3);

		luabind::object o4(luabind::globals(sprInit->L())["spf"]);
		if (o4)
		{
			// is_valid
			// ...

			int luatype = luabind::type(o4);
			if (luabind::type(o4) == LUA_TUSERDATA)
			{
				SpriteFrame otherValue = luabind::object_cast<SpriteFrame>(o4);
				int abc = 4;
				abc++;
			}
		}




		//SpriteMovie otherValue3(0,0);
		//fsuccess = sprInit->GetLuaValue<SpriteMovie>("spMovie", otherValue3);
		SpriteMovieOld smovieOld = sprInit->GetLuaValue<SpriteMovieOld>("spMovieOld");
		SpriteMovie smovie = sprInit->GetLuaValue<SpriteMovie>("spMovie");

		//int *x = new int(666);

        return Screen::OnInit(argc, argv);
    } // OnInit
示例#21
0
void PlanCompare::MPI_Close (void)
{
#ifdef MPI_EXE
	int i, lvalue [6], rank;

	if (Master ()) {
		if (new_plan_flag) {
			Show_Message (1);

			for (i=1; i < MPI_Size (); i++) {

				rank = Show_MPI_Message ();

				//---- retrieve the new plan statistics

				Get_MPI_Array (lvalue, 6, rank);

				new_plan_file->Add_Files (lvalue [0]);
				new_plan_file->Add_Records (lvalue [1]);
				new_plan_file->Add_Households (lvalue [2]);
				new_plan_file->Add_Persons (lvalue [3]);
				new_plan_file->Add_Tours (lvalue [4]);
				new_plan_file->Add_Trips (lvalue [5]);
			}
			new_plan_file->Close ();
		}

		//---- write the new selection file ----

		if (select_parts) {
			Show_Message (1);

			select_map.swap (selected);
			Write_Selections ();

			for (i=1; i < MPI_Size (); i++) {
				Show_MPI_Message ();
			}
		}
		Show_Message (1);

	} else {	//---- slave ----

		if (new_plan_flag) {
			if (Partition_Range ()) {
				Send_MPI_Message (String ("Slave %d Wrote %ss %d..%d") % MPI_Rank () % new_plan_file->File_Type () % First_Partition () % Last_Partition ());
			} else {
				Send_MPI_Message (String ("Slave %d Wrote %s %d") % MPI_Rank () % new_plan_file->File_Type () % First_Partition ());
			}

			//---- send new plan statistics ----

			lvalue [0] = new_plan_file->Num_Files ();
			lvalue [1] = new_plan_file->Num_Records ();
			lvalue [2] = new_plan_file->Num_Households ();
			lvalue [3] = new_plan_file->Num_Persons ();
			lvalue [4] = new_plan_file->Num_Tours ();
			lvalue [5] = new_plan_file->Num_Trips ();
			new_plan_file->Close ();

			Send_MPI_Array (lvalue, 6);
		}

		//---- write the new selection file ----

		if (select_parts) {
			select_map.swap (selected);
			Write_Selections ();

			Selection_File *file = System_Selection_File (true);

			if (Partition_Range ()) {
				Send_MPI_Message (String ("Slave %d Wrote %ss %d..%d") % MPI_Rank () % file->File_Type () % First_Partition () % Last_Partition ());
			} else {
				Send_MPI_Message (String ("Slave %d Wrote %s %d") % MPI_Rank () % file->File_Type () % First_Partition ());
			}
		}
		Exit_Stat (DONE);
	}
#endif
}
示例#22
0
int main ( int argc, char *argv[] )
{
  
  omp_set_num_threads(omp_get_max_threads());
  
  //Control number of input parameter
  if(argc<3)
  {
    printf("ERROR MISSING DIR PATH IN/OUT \n");
    return 1;
  }
  
  //MPI vars
  int error = 0; // mi restituisce gli errori mpi
  int nproc = 0; // numero processori totali 
  int myid  = 0; // id singolo processore
  
  //init MPI
  error = MPI_Init(&argc, &argv);
  
  //init MPI Comm
  error = MPI_Comm_size(MPI_COMM_WORLD, &nproc);
  error = MPI_Comm_rank(MPI_COMM_WORLD, &myid);
  
  //check directory
  char * dirIn;
  char * dirOut;
  char * istant;
  dirIn = (char *) malloc(500*sizeof(char ));
  dirOut = (char *) malloc(500*sizeof(char ));
  istant = (char *) malloc(100*sizeof(char ));
  strcpy(dirIn,argv[1]);
  strcpy(dirOut,argv[2]);
  strcat(dirIn,"/");
  strcat(dirOut,"/");
  
  
  //printf("I'm %d of %d\n",myid,nproc);
  
  // read number of json file in input dir
  int numFile = 0;
  numFile = readDirectoryNum(dirIn);
  
  //create file list structure
  char ** list;
  list = (char **) malloc(numFile*sizeof(char*));
  for(int i=0;i<numFile;i++)
    list[i] = (char *) malloc(200*sizeof(char));
  
  // read list file in input directory
  readDirectory(dirIn,list,numFile);
  
  if(myid == 0)
  {
    printf("\n");
    printf("GILLESPIE HT v 1.0 \n");
    printf("Gillespie algo high throughput software\n");
    printf("https://github.com/EricPascolo/GillespieHT\n");
    printf("Created by Eric Pascolo (set 2014)\n");
    printf("\n");
    
    if(nproc>1)
      printf("\tParallel Run with %d slave\n",nproc-1);
    else
      printf("\tSerial Run\n");
    
    printf("\tThreads/Task : %d \n",omp_get_max_threads());
    printf("\tInput directory : %s \n",dirIn);
    printf("\tOutput directory : %s \n",dirOut);
    printf("\tNumber of file: %d \n",numFile);
    printf("\nBEGIN Simulation at %s\n",getTime(istant));
    printf("\n");
    printf("\n");
    printf("\tLIST FILE\n");
    printf("\t---------\n");
    for(int i=0;i<numFile;i++)
      printf("\t%5d %20s\n",i,list[i]);
    printf("\t---------\n\n");
  }
  
  MPI_Barrier(MPI_COMM_WORLD);
  
  if(myid == 0)
  {
    Master(nproc,dirIn,dirOut,list,numFile);
  }
  else
  {
    Slave(myid,nproc,dirIn,dirOut,list,numFile);
  }
  
  MPI_Barrier(MPI_COMM_WORLD);
  
  if(myid == 0)
  {
    printf("\nEND Simulation at %s\n",getTime(istant));
  }
  
  error = MPI_Finalize();
  return 0;
  
  
}
示例#23
0
void PlanSum::Program_Control (void)
{
	String key;
	bool link_flag, report_flag;

	link_flag = report_flag = false;

	if (!Set_Control_Flag (UPDATE_FLOW_RATES) && !Set_Control_Flag (UPDATE_TRAVEL_TIMES)) {
		System_File_False (NEW_LINK_DELAY);
	}

	//---- initialize the MPI thread range ----

	MPI_Setup ();

	//---- set equivalence flags ---
	
	if (Report_Flag (LINK_GROUP) || Report_Flag (RIDER_GROUP)) {
		Link_Equiv_Flag (true);
		link_flag = true;
	}
	if (skim_flag || trip_flag) {
		Zone_Equiv_Flag (true);
		zone_flag = true;
	}
	Stop_Equiv_Flag (Report_Flag (STOP_GROUP));

	//---- create the network files ----

	Data_Service::Program_Control ();
	
	Read_Select_Keys ();
	Read_Flow_Time_Keys ();

	plan_file = (Plan_File *) System_File_Handle (PLAN);
	if (!plan_file->Part_Flag ()) Num_Threads (1);

	select_flag = System_File_Flag (SELECTION);
	new_delay_flag = System_File_Flag (NEW_LINK_DELAY);

	if (System_File_Flag (LINK_DELAY)) {
		link_flag = true;
		Link_Delay_File *file = (Link_Delay_File *) System_File_Handle (LINK_DELAY);
		turn_flag = file->Turn_Flag ();
	}
	if (new_delay_flag) {
		link_flag = true;
		Link_Delay_File *file = (Link_Delay_File *) System_File_Handle (NEW_LINK_DELAY);
		turn_flag = file->Turn_Flag ();
	} else {
		turn_flag = System_File_Flag (CONNECTION);
	}
	Print (2, String ("%s Control Keys:") % Program ());

	//---- new trip time file ----

	key = Get_Control_String (NEW_TRIP_TIME_FILE);

	if (!key.empty ()) {
		time_file.File_Type ("New Trip Time File");
		time_file.File_ID ("Time");

		if (Master ()) {
			time_file.Create (Project_Filename (key));
		}
		time_flag = true;
	}

	//---- new link volume file ----

	key = Get_Control_String (NEW_LINK_VOLUME_FILE);

	if (!key.empty ()) {
		volume_file.File_Type ("New Link Volume File");
		volume_file.File_ID ("Volume");

		if (Master ()) {
			volume_file.Create (Project_Filename (key));

			volume_file.Num_Decimals (1);
			volume_file.Data_Units (Performance_Units_Map (FLOW_DATA));
			volume_file.Copy_Periods (sum_periods);

			volume_file.Create_Fields ();
			volume_file.Write_Header ();
		}
		volume_flag = new_delay_flag = link_flag = true;
	}

	//---- read report types ----

	List_Reports ();

	if (Report_Flag (TOP_100) || Report_Flag (VC_RATIO) || Report_Flag (LINK_GROUP)) {
		new_delay_flag = link_flag = report_flag = true;
		cap_factor = (double) sum_periods.Range_Length () / (Dtime (1, HOURS) * sum_periods.Num_Periods ());
	}
	if (link_flag && (!System_File_Flag (LINK) || !System_File_Flag (NODE))) {
		Error ("Link and Node Files are Required for Link-Based Output");
	}
	if (System_File_Flag (LANE_USE) && !System_File_Flag (LINK)) {
		Error ("A Link File is Required for Lane-Use Processing");
	}
	travel_flag = Report_Flag (SUM_TRAVEL);

	//---- ridership summary ----

	passenger_flag = Report_Flag (SUM_PASSENGERS);
	transfer_flag = (Report_Flag (SUM_STOPS) || Report_Flag (STOP_GROUP));
	rider_flag = (System_File_Flag (NEW_RIDERSHIP) || Report_Flag (SUM_RIDERS) || Report_Flag (RIDER_GROUP));
	xfer_flag = Report_Flag (SUM_TRANSFERS);
	xfer_detail = Report_Flag (XFER_DETAILS);

	if (passenger_flag || transfer_flag || rider_flag || xfer_flag || xfer_detail) {
		if (!System_File_Flag (TRANSIT_STOP) || !System_File_Flag (TRANSIT_ROUTE) ||
			!System_File_Flag (TRANSIT_SCHEDULE)) {

			Error ("Transit Network Files are Required for Ridership Output");
		}
		if ((passenger_flag || rider_flag) && !System_File_Flag (TRANSIT_DRIVER)) {
			Error ("A Transit Driver File is needed for Passengers Summaries");
		}
	} else {
		System_File_False (TRANSIT_STOP);
		System_File_False (TRANSIT_ROUTE);
		System_File_False (TRANSIT_SCHEDULE);
		System_File_False (TRANSIT_DRIVER);
	}

	//---- process support data ----

	if (Link_Equiv_Flag ()) {
		link_equiv.Read (Report_Flag (LINK_EQUIV));
	}
	if (Zone_Equiv_Flag ()) {
		zone_equiv.Read (Report_Flag (ZONE_EQUIV));
	}
	if (Stop_Equiv_Flag ()) {
		stop_equiv.Read (Report_Flag (STOP_EQUIV));
	}

	//---- allocate work space ----

	if (time_flag || Report_Flag (TRIP_TIME)) {
		time_flag = true;

		int periods = sum_periods.Num_Periods ();
		
		start_time.assign (periods, 0);
		mid_time.assign (periods, 0);
		end_time.assign (periods, 0);
	}

	//---- transfer arrays ----

	if (xfer_flag || xfer_detail) {
		Integers rail;

		rail.assign (10, 0);
		total_on_array.assign (10, rail);

		if (xfer_detail) {
			int num = sum_periods.Num_Periods ();
			if (num < 1) num = 1;

			walk_on_array.assign (num, total_on_array);
			drive_on_array.assign (num, total_on_array);
		}
	}

	//---- initialize the trip summary data ----

	if (travel_flag) {
		trip_sum_data.Copy_Periods (sum_periods);
	}

	//---- initialize the passenger summary data ----

	if (passenger_flag) {
		pass_sum_data.Copy_Periods (sum_periods);
	}
}
示例#24
0
bool Simulator_Base::Start_Simulator (void)
{
	int num;
	Int2_Map_Itr part_itr;
	Int2_Map_Data part_rec;
	Int2_Array int2_array;

	//---- read the first travel plan ----

	if (Master ()) {
		if (!sim_read_plans.First_Plan ()) return (false);
	}

	//---- create simulators ----

	num = Last_Part () - First_Part () + 1;
	Num_Simulators (num);

	simulator = new Sim_Method * [num];

	if (Num_Parts () > 1) {
		for (part_itr = part_map.begin (); part_itr != part_map.end (); part_itr++) {
			if (part_itr->second >= First_Part () && part_itr->second <= Last_Part ()) {
				part_rec = *part_itr;
				num = part_itr->second - First_Part ();
				simulator [num] = new Sim_Method (*this, &part_rec);
			}
		}
	} else {
		*simulator = new Sim_Method (*this);
	}

	//---- create the partition lists ----

	work_step.Num_Workers (Num_Simulators ());
	transfers.assign (Num_Simulators (), int2_array);

	if (Num_Threads () == 1) {
		work_step.Num_Barriers (0);
		xfer_barrier.Num_Barriers (0);
		veh_barrier.Num_Barriers (0);
	} else {
		xfer_barrier.Num_Barriers (Num_Simulators ());
		veh_barrier.Num_Barriers (Num_Simulators ());
	}

	//---- create output threads ----

 #ifdef BOOST_THREADS
	if (Num_Threads () > 1) {
		int num_barrier = (int) snapshot_output.Output_Flag () + (int) link_delay_output.Output_Flag () + 
			(int) performance_output.Output_Flag () + (int) ridership_output.Output_Flag () + 
			(int) turn_vol_output.Output_Flag () + (int) occupancy_output.Output_Flag ();

		if (Master ()) {
			num_barrier++;
		}
#ifdef MPI_EXE
		if (problem_output.Output_Flag ()) num_barrier++;
		if (event_output.Output_Flag ()) num_barrier++;
		if (traveler_output.Output_Flag ()) num_barrier++;
#endif
		io_barrier.Num_Barriers (num_barrier);

		if (Master ()) {
			io_threads.create_thread (boost::ref (sim_read_plans));
		}
		if (snapshot_output.Output_Flag ()) {
			io_threads.create_thread (boost::ref (snapshot_output));
		}
		if (link_delay_output.Output_Flag ()) {
			io_threads.create_thread (boost::ref (link_delay_output));
		}
		if (performance_output.Output_Flag ()) {
			io_threads.create_thread (boost::ref (performance_output));
		}
		if (ridership_output.Output_Flag ()) {
			io_threads.create_thread (boost::ref (ridership_output));
		}
		if (turn_vol_output.Output_Flag ()) {
			io_threads.create_thread (boost::ref (turn_vol_output));
		}
		if (occupancy_output.Output_Flag ()) {
			io_threads.create_thread (boost::ref (occupancy_output));
		}

		//---- not barrier controlled unless MPI ----

		if (problem_output.Output_Flag ()) {
			io_threads.create_thread (boost::ref (problem_output));
		}
		if (event_output.Output_Flag ()) {
			io_threads.create_thread (boost::ref (event_output));
		}
		if (traveler_output.Output_Flag ()) {
			io_threads.create_thread (boost::ref (traveler_output));
		}
	}
#endif

	//---- processing threads ---

	num = (Num_Threads () > Num_Simulators ()) ? Num_Simulators () : Num_Threads ();

	step_preps = new Step_Preps * [num];
	boundaries = new Boundaries * [num];
	processors = new Processors * [num];

	for (int i=0; i < num; i++) {
		step_preps [i] = new Step_Preps (this);
		boundaries [i] = new Boundaries (this);
		processors [i] = new Processors (this);

#ifdef BOOST_THREADS
		if (Num_Threads () > 1) {
			sim_threads.create_thread (boost::ref (*step_preps [i]));
			sim_threads.create_thread (boost::ref (*boundaries [i]));
			sim_threads.create_thread (boost::ref (*processors [i]));
		}
#endif
	}
	return (true);
}
示例#25
0
// Do the initialization tasks. This is where all the buttons are created
void Board::init()
{
    layout = new QVBoxLayout;          // Create a vertical layout for a column of buttons
    QLabel *status =new QLabel("        Score");
    QLabel *status2 = new QLabel("    Chances Left");
    QLabel *Name =new QLabel("         Player Name");

    layout->addWidget(Name);
    QPushButton *b = new QPushButton(tr("Restart")); // create a button for restarting the game
    connect(b, SIGNAL(clicked()), this, SLOT(restartGame()));           // connect restart button to restartGame function
    layout->addWidget(b);        // add the restart button to the button row

    b = new QPushButton(tr("Top 10"));   // Create a button for showing top 10 high scores
    connect(b, SIGNAL(clicked()), this, SLOT(topTen()));   // connect this button to high score function
    layout->addWidget(b);                           // Add it to the row of buttons

    b = new QPushButton(tr("Help"));    //Creat a button for showing helpful instructions
    connect(b, SIGNAL(clicked()), this, SLOT(help()));  //connect this button to help function
    layout->addWidget(b);                               //add it to the row of buttons

    QVBoxLayout *vbox = new QVBoxLayout;
    rbn = new QRadioButton(tr("Novice"));
    connect(rbn, SIGNAL(clicked()), this, SLOT(Novice()));
    rbn->setCheckable(true);
    rbn->setChecked(true);
    rbn->setDown(true);
    vbox->addWidget(rbn);                           // Add it to the row of buttons

    rbe = new QRadioButton(tr("Expert"));
    connect(rbe, SIGNAL(clicked()), this, SLOT(Expert()));
    rbe->setCheckable(true);
    vbox->addWidget(rbe);                           // Add it to the row of buttons

    rbm = new QRadioButton(tr("Master"));
    connect(rbm, SIGNAL(clicked()), this, SLOT(Master()));
    rbm->setCheckable(true);
    vbox->addWidget(rbm);                           // Add it to the row of buttons

    QGroupBox *bg = new QGroupBox(tr("Game Mode"));
    bg->setLayout(vbox);
    layout->addWidget(bg);

    QWidget *window = new QWidget;      // create a window to whold the row of buttons
    window->setLayout(layout);          // add the row of buttons to this window
    window->move(W+2*T,0);                // position it at the right edge
    this->scene()->addWidget(window);   // add the button window to the scene

    layout->addWidget(status2);
    turn=new QLCDNumber(1);     //creates QLCDNumber to hold remaining shots
    turn->setSegmentStyle(QLCDNumber::Filled);
    layout->addWidget(turn);
    turn->display(5);

    layout->addWidget(status);                  //adds text label to say score
    showscore=new QLCDNumber(10);               //creates QLCDNumber to show score
    showscore->setSegmentStyle(QLCDNumber::Filled);
    layout->addWidget(showscore);                //adds a box to display the score
    showscore->display(0);                      //sets the score

    showtimer=new QLabel("     Time Left (ms)");    //label to say time left
    layout->addWidget(showtimer);


    int y=Bubble::R*17+2;

    for(int i=0; i<9; i++)              //draws 9 rows of random coloured bubbles
    {
        int x=Bubble::R+3;
        if(i%2==0)
            x+=Bubble::R;
        for(int p=0; p<17; p++)         // draws 17 column of random coloured bubbles
        {
            start.append(new Bubble(random(rand1),shootAngle));
            start.last()->setParentItem(this);
            start.last()->setPos(x,y);
            x+=Bubble::R*2;
        }
        y-=Bubble::R*2;
    }
    first=random(first);            //gives first a new random colour
    next=random(next);              //gives next a new random colour
    FirstandSecond.append(new Bubble(first,shootAngle));    //adds new bubble to be shot next
    FirstandSecond.back()->setParentItem(this);
    FirstandSecond.back()->setPos(W/2,H);
    FirstandSecond.append(new Bubble(next,shootAngle));     //adds new bubble to be shot after that
    FirstandSecond.back()->setParentItem(this);
    FirstandSecond.back()->setPos(W+Bubble::R*4,H-Bubble::R*8);

    gameStart();                                    // calls function to diplay ten highest scores

}
示例#26
0
文件: mpidag.cpp 项目: juve/mpidag
int mpidag(int argc, char *argv[]) {
    int numprocs;
    program = argv[0];
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
    
    std::list<char *> flags;
    for (int i=1; i<argc; i++) {
        flags.push_back(argv[i]);
    }
    
    std::string outfile;
    std::string errfile;
    std::string logfile;
    std::list<std::string> args;
    int loglevel = LOG_INFO;
    bool skiprescue = false;
    int max_failures = 0;
    int tries = 1;
    
    while (flags.size() > 0) {
        std::string flag = flags.front();
        if (flag == "-h" || flag == "--help") {
            usage();
            return 0;
        } else if (flag == "-o" || flag == "--stdout") {
            flags.pop_front();
            if (flags.size() == 0) {
                if (rank == 0) {
                    fprintf(stderr, "-o/--stdout requires PATH\n");
                }
                return 1;
            }
            outfile = flags.front();
        } else if (flag == "-e" || flag == "--stderr") {
            flags.pop_front();
            if (flags.size() == 0) {
                if (rank == 0) {
                    fprintf(stderr, "-e/--stderr requires PATH\n");
                }
                return 1;
            }
            errfile = flags.front();
        } else if (flag == "-q" || flag == "--quiet") {
            loglevel -= 1;
        } else if (flag == "-v" || flag == "--verbose") {
            loglevel += 1;
        } else if (flag == "-L" || flag == "--logfile") {
            flags.pop_front();
            if (flags.size() == 0) {
                if (rank == 0) {
                    fprintf(stderr, "-L/--logfile requires PATH\n");
                }
                return 1;
            }
            logfile = flags.front();
        } else if (flag == "-s" || flag == "--skip-rescue") {
            skiprescue = true;
        } else if (flag == "-m" || flag == "--max-failures") {
            flags.pop_front();
            if (flags.size() == 0) {
                if (rank == 0) {
                    fprintf(stderr, "-m/--max-failures requires N\n");
                }
                return 1;
            }
            std::string N = flags.front();
            if (!sscanf(N.c_str(), "%d", &max_failures)) {
                fprintf(stderr, "N for -m/--max-failures is invalid\n");
                return 1;
            }
            if (max_failures < 0) {
                fprintf(stderr, "N for -m/--max-failures must be >= 0\n");
                return 1;
            }
        } else if (flag == "-t" || flag == "--tries") {
            flags.pop_front();
            if (flags.size() == 0) {
                if (rank == 0) {
                    fprintf(stderr, "-t/--tries requires N\n");
                }
                return 1;
            }
            std::string N = flags.front();
            if (!sscanf(N.c_str(), "%d", &tries)) {
                fprintf(stderr, "N for -t/--tries is invalid\n");
                return 1;
            }
            if (tries < 1) {
                fprintf(stderr, "N for -t/--tries must be >= 1\n");
                return 1;
            }
        } else if (flag[0] == '-') {
            if (rank == 0) {
                fprintf(stderr, "Unrecognized argument: %s\n", flag.c_str());
            }
            return 1;
        } else {
            args.push_back(flag);
        }
        flags.pop_front();
    }
    
    if (args.size() == 0) {
        usage();
        return 1;
    }
    
    if (args.size() > 1) {
        fprintf(stderr, "Invalid argument\n");
        return 1;
    }
    
    std::string dagfile = args.front();
    
    if (numprocs < 2) {
        fprintf(stderr, "At least one worker process is required\n");
        return 1;
    }
    
    // Everything is pretty deterministic up until the processes reach
    // this point. Once we get here the different processes can diverge 
    // in their behavior for many reasons (file systems issues, bad nodes,
    // etc.), so be careful how failures are handled after this point
    // and make sure MPI_Abort is called when something bad happens.
    
    char dotrank[25];
    sprintf(dotrank, ".%d", rank);
    
    FILE *log = NULL;
    log_set_level(loglevel);
    if (logfile.size() > 0) {
        logfile += dotrank;
        log = fopen(logfile.c_str(), "w");
        if (log == NULL) {
            failure("Unable to open log file: %s: %s\n", 
                logfile.c_str(), strerror(errno));
        }
        log_set_file(log);
    }
    
    try {
        if (rank == 0) {
            
            // IMPORTANT: The rank 0 process figures out the names
            // of these files so that we don't have 1000 workers all
            // slamming the file system with stat() calls to check if
            // the out/err/rescue files exist. The master will figure
            // it out here, and then broadcast it to the workers when
            // it starts up.
            
            // Determine task stdout file
            if (outfile.size() == 0) {
                outfile = dagfile;
                outfile += ".out";
            }
            next_retry_file(outfile);
            log_debug("Using stdout file: %s", outfile.c_str());
            
            
            // Determine task stderr file
            if (errfile.size() == 0) {
                errfile = dagfile;
                errfile += ".err";
            }
            next_retry_file(errfile);
            log_debug("Using stderr file: %s", errfile.c_str());
            
            
            // Determine old and new rescue files
            std::string rescuebase = dagfile;
            rescuebase += ".rescue";
            std::string oldrescue;
            std::string newrescue = rescuebase;
            int next = next_retry_file(newrescue);
            if (next == 0 || skiprescue) {
                // Either there is no old rescue file, or the
                // user doesnt want to read it.
                oldrescue = "";
            } else {
                char rbuf[5];
                snprintf(rbuf, 5, ".%03d", next-1);
                oldrescue = rescuebase;
                oldrescue += rbuf;
            }
            log_debug("Using old rescue file: %s", oldrescue.c_str());
            log_debug("Using new rescue file: %s", newrescue.c_str());
            
            DAG dag(dagfile, oldrescue);
            Engine engine(dag, newrescue, max_failures, tries);
            
            return Master(engine, dag, outfile, errfile).run();
        } else {
            return Worker().run();
        }
    } catch (...) {
        // Make sure we close the log
        if (log != NULL) {
            fclose(log);
        }
        throw;
    }
    
    if (log != NULL) {
        fclose(log);
    }

    return 0;
}