Esempio n. 1
0
int init() {
    mt_seed();

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);

    TTF_Init();

    fIntro = TTF_OpenFont("Media/Fonts/PressStart2P.ttf", 15);
    fButton = TTF_OpenFont("Media/Fonts/vSHandprinted.otf", 30);
    fSmall = TTF_OpenFont("Media/Fonts/vSHandprinted.otf", 10);
    fBig = TTF_OpenFont("Media/Fonts/vSHandprinted.otf", 30);

    screen = SDL_SetVideoMode(SCR_W, SCR_H, SCR_BPP, SDL_SWSURFACE);

    SDL_WM_SetCaption("Operation Get Out | Knights of the Compiler", NULL);

    commonBG = loadImage("Media/Graphics/commonbg.png");

    gm = new cGameMan(STATE_INTRO);

    // console hack
    // freopen( "CON", "wt", stdout );
    // freopen( "CON", "wt", stderr );

    return 0;
}
Esempio n. 2
0
void mersenne_crypt(char *decrypted, char *encrypted, size_t num_bytes, uint16_t seed) {
    twister mt;
    mt_seed(&mt, seed);
    for (size_t offset = 0; offset < num_bytes; ++offset) {
        encrypted[offset] = decrypted[offset] ^ mt_extract(&mt);
    }
}
Esempio n. 3
0
int init() {
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);

    TTF_Init();

    Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);

    screen = SDL_SetVideoMode(SCR_W, SCR_H, SCR_BPP, SDL_SWSURFACE);
    SDL_WM_SetCaption("Relentless Escape", NULL);

    mt_seed();

    gm = new cGameMan(STATE_INTRO);

    fHeadline = TTF_OpenFont("Media/Fonts/courier_noir.ttf", 50);
    fBigHeadline = TTF_OpenFont("Media/Fonts/courier_noir.ttf", 80);
    fButton = TTF_OpenFont("Media/Fonts/courier_noir.ttf", 40);
    fSmall = TTF_OpenFont("Media/Fonts/courier_noir.ttf", 20);
    fMedium = TTF_OpenFont("Media/Fonts/courier_noir.ttf", 30);

    white = SDL_MapRGB(screen->format, 255, 255, 255);
    grey = SDL_MapRGB(screen->format, 128, 128, 128);

    // console hack
    // freopen( "CON", "wt", stdout );
    // freopen( "CON", "wt", stderr );

    return 0;
}
Esempio n. 4
0
bool init(int w, int h, bool fullscreen = false) {
//	HWND hWndDisplay = NULL;
	const char* err;
	#define INIT(x, y) if(!(x)) { err = y; goto err; }

	mt_seed();
	
	// Allegro initialization

	INIT( al_init() &&
	      al_install_mouse() &&
	      al_install_keyboard() &&
	      al_init_image_addon() &&
		  al_init_primitives_addon(),
		"initialize allegro" );
	
	
	if(fullscreen) al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);
	INIT(display = al_create_display(w, h), "create display")
	al_set_window_title(display, "ŒwiteŸ");
//	{	auto icon = al_load_bitmap("img\\icon.gif");
//		if(icon) al_set_display_icon(display, icon);	}
//	if(fullscreen) {
//		hWndDisplay = al_get_win_window_handle(display);
//		SetWindowLong(hWndDisplay, GWL_STYLE, 0);
//		ShowWindow(hWndDisplay, SW_MAXIMIZE);
//	}


	INIT(timer = al_create_timer(1.0 / 60), "create timer")

    INIT(event_queue = al_create_event_queue(), "create event queue")

	al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_mouse_event_source());
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_start_timer(timer);

	// End of Allegro initialization

	INIT(setup(display), "initialize renderer");

	#undef INIT
	return true;

err:
	if(display) al_destroy_display(display);
	{
		char* buf = new char[strlen(err) + 13];
		sprintf(buf, "Failed to %s!\n", err);
//		MessageBoxA(NULL, buf, "Error", MB_ICONERROR);
		delete buf;
	}
	return false;
}
Esempio n. 5
0
int main(){
    //srand(42424242);
    mt_seed();
    int n = 10000;
    struct Particle particles[n];
    struct Force acc = {0.,0.,0.};

    for (int i = 0; i < n; ++i)
    {
        // particles[i].position.x = (double)rand() / (double)RAND_MAX ;
        // particles[i].position.y = (double)rand() / (double)RAND_MAX ;
        // particles[i].position.z = (double)rand() / (double)RAND_MAX ;
        // particles[i].velocity.x = (double)rand() / (double)RAND_MAX ;
        // particles[i].velocity.y = (double)rand() / (double)RAND_MAX ;
        // particles[i].velocity.z = (double)rand() / (double)RAND_MAX ;
        // particles[i].acceleration.x = 0.;
        // particles[i].acceleration.y = 0.;
        // particles[i].acceleration.z = 0.;
        particles[i].position.x = mt_ldrand()-.5;
        particles[i].position.y = mt_ldrand()-.5;
        particles[i].position.z = mt_ldrand()-.5;
        particles[i].velocity.x = mt_ldrand()-.5;
        particles[i].velocity.y = mt_ldrand()-.5;
        particles[i].velocity.z = mt_ldrand()-.5;
        particles[i].acceleration.x = 0.;
        particles[i].acceleration.y = 0.;
        particles[i].acceleration.z = 0.;
        particles[i].mass = mt_ldrand() ;
    }

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if(i!=j){
                calcforce(&particles[i], particles[j]);
            }
        }
    }

    for (int i = 0; i < n; ++i)
    {
        acc.x += particles[i].acceleration.x;
        acc.y += particles[i].acceleration.y;
        acc.z += particles[i].acceleration.z;
    }

    printf("%1.16e %1.16e %1.16e\n", acc.x, acc.y, acc.z);
}
Esempio n. 6
0
map* init_map(int sideX, int sideY, int scale){

    int x, y;
    unsigned int i, count = 0;
    int aux = 0;
    unsigned int n;
    void **word_adresses;
    word *pt_aux = malloc(sizeof(word));;
    map *_map = malloc(sizeof(map));
    _map->latice_size = sideX * sideY;
    _map->sideX       = sideX;
    _map->sideY       = sideY; 
    _map->scale       = scale;
    _map->lattice     = malloc(_map->latice_size * sizeof( neuron));
    mt_seed ();

    if ((n = get_list(pt_aux)))
    {
        printf("n: %d\n", n);
        word_adresses = malloc(n * sizeof(void *));
        while (pt_aux != NULL)
        {
            x = mt_rand() %sideX;
            y = mt_rand() %sideY;
            init_neuron(_map->lattice, x, y, pt_aux->frames, pt_aux->n, pt_aux->name);
            word_adresses[count++] = pt_aux;
            pt_aux = pt_aux->next;
        }
        printf("count: %d\n", count);
        for (i = 0; i < count; i++)
            free(word_adresses[i]);
        free(word_adresses);
    }

    return _map;
}
Esempio n. 7
0
int main(int argc, const char *argv[])
{
    mt_seed();
    unsigned int i,j;
    unsigned int total_games=100;
    double b;

    unsigned int **count;
    unsigned int **count_aux;
    count=malloc(total_games*sizeof(unsigned int *));
    count_aux=malloc(total_games*sizeof(unsigned int *));

    unsigned int **coop_cluster;
    coop_cluster=malloc(total_games*sizeof(unsigned int *));
    for (i = 0; i < total_games; i++)
        coop_cluster[i]=NULL;
    double coop_mean;
    double coop_fixed_mean;
    double coop_isolated_mean;
    double coop_cluster_mean;
    double coop_effective_surface_mean;

    unsigned int **def_cluster;
    def_cluster=malloc(total_games*sizeof(unsigned int *));
    for (i = 0; i < total_games; i++)
        def_cluster[i]=NULL;
    double def_mean;
    double def_fixed_mean;
    double def_isolated_mean;
    double def_cluster_mean;
    double def_effective_surface_mean;
    
    unsigned int *iter;
    unsigned int iter0=5000;
    unsigned int iter1;
    unsigned int iter_mean;
    iter=malloc(total_games*sizeof(unsigned int));

    FILE *f;
    f=fopen("data_iter2.csv","w");
    fprintf(f,"b\t");
    fprintf(f,"coop_mean\tcoop_fixed_mean\tcoop_isolated_mean\tcoop_cluster_mean\tcoop_effective_surface_mean\t");
    fprintf(f,"def_mean\tdef_fixed_mean\tdef_isolated_mean\tdef_cluster_mean\tdef_effective_surface_mean\t");
    fprintf(f,"iter_mean\n");
    fclose(f);

    struct game gam;
    struct game *g_aux;
    g_aux=&gam;

    for (b = 1.5; b < 2.0; b+=0.05)
    {
        for (j = 0; j < total_games;) 
        {
            gam=create_prisioner_dilemma_game(b,4000,8000,1);

            for (i = 0; i < iter0; i++)
                evolve_game(g_aux,0);
            iter[j]=iter0;

            iter1=1000;
            do
            {
                count[j]=count_type(gam);
                for (i = 0; i < iter1; i++)
                    evolve_game(g_aux,0);
                iter[j]+=iter1;
                count_aux[j]=count_type(gam);
            }
            while (abs(count[j][0]-count_aux[j][0])>10);

            iter1=10000;
            for (i = 0; i < iter1; i++)
                evolve_game(g_aux,0);
                
            iter1=1000;
            for (i = 0; i < iter1; i++)
                evolve_game(g_aux,1);

            free(count[j]);
            free(coop_cluster[j]);
            free(def_cluster[j]);

            count[j]=count_type(gam);
            coop_cluster[j]=cluster_analize(gam,0);
            def_cluster[j]=cluster_analize(gam,1);
/*
            if(coop_cluster[j][2]==0)
                printf("b: %.3lf game: %u FAILED, COOPERATORS DESTROYED\n",b,j);
            else if(def_cluster[j][2]==0)
                printf("b: %.3lf game: %u FAILED, DEFECTORS DESTROYED\n",b,j);
            else
            {*/
                printf("b: %.3lf game: %u DONE\n",b,j);
                j++;
            //}

            //graph_to_file("grafo.gdf",gam.g,1);

            free_game(g_aux);
        }

        coop_mean=0;
        coop_fixed_mean=0;
        coop_isolated_mean=0;
        coop_cluster_mean=0;
        coop_effective_surface_mean=0;

        def_mean=0;
        def_fixed_mean=0;
        def_isolated_mean=0;
        def_cluster_mean=0;
        def_effective_surface_mean=0;

        iter_mean=0;
        for (i = 0; i < total_games; i++)
        {
            coop_mean+=(double)count[i][0]/total_games;
            coop_fixed_mean+=(double)coop_cluster[i][2]/total_games;
            coop_isolated_mean+=(double)coop_cluster[i][4]/total_games;
            coop_cluster_mean+=(double)(coop_cluster[i][0]-coop_cluster[i][1])/total_games;
            coop_effective_surface_mean+=(double)coop_cluster[i][3]/(coop_cluster[i][2]-coop_cluster[i][4])/total_games;

            def_mean+=(double)count[i][1]/total_games;
            def_fixed_mean+=(double)def_cluster[i][2]/total_games;
            def_isolated_mean+=(double)def_cluster[i][4]/total_games;
            def_cluster_mean+=(double)(def_cluster[i][0]-def_cluster[i][1])/total_games;
            def_effective_surface_mean+=(double)def_cluster[i][3]/(def_cluster[i][2]-def_cluster[i][4])/total_games;

            iter_mean+=iter[i]/total_games;
        }

        coop_mean/=4000.;
        coop_fixed_mean/=4000.;
        coop_isolated_mean/=4000.;

        def_mean/=4000.;
        def_fixed_mean/=4000.;
        def_isolated_mean/=4000.;

        f=fopen("data_iter2.csv","a");
        fprintf(f,"%lf\t",b);
        fprintf(f,"%lf\t%lf\t%lf\t%lf\t%lf\t",coop_mean,coop_fixed_mean,coop_isolated_mean,coop_cluster_mean,coop_effective_surface_mean);
        fprintf(f,"%lf\t%lf\t%lf\t%lf\t%lf\t",def_mean,def_fixed_mean,def_isolated_mean,def_cluster_mean,def_effective_surface_mean);
        fprintf(f,"%u\n",iter_mean);
        fclose(f);
        printf("\n");
    }
    return 0;
}
Esempio n. 8
0
// 从汇编阶段,进入C语言的阶段,传承了Unix的典型思想
// 汇编只负责引导和必要的硬件打交道的阶段
void start_ling(start_info_t *si)
{
	//-------- init phase 1 --------
	//
	//start_info包含的是xen的初始化信息
	//是xen在启动GuestOS的时候,放在特定的地方
	memcpy(&start_info, si, sizeof(*si));
    
	phys_to_machine_mapping = (unsigned long *)start_info.mfn_list;

	HYPERVISOR_update_va_mapping((unsigned long)&shared_info,
		__pte(start_info.shared_info | 7), UVMF_INVLPG);
	HYPERVISOR_shared_info = &shared_info;
//进行时钟初始化
	time_init();	// sets start_of_day_wall_clock

	// use the time value to seed PRNG
	mt_seed(start_of_day_wall_clock);
	
#if defined(__x86_64__)
	HYPERVISOR_set_callbacks(0, 0, 0);
#else /* __x86_64__ */
	HYPERVISOR_set_callbacks(0, 0, 0, 0);
#endif

	mm_init(start_info.nr_pages, start_info.pt_base, start_info.nr_pt_frames);
	nalloc_init();

	events_init();
	grants_init();

	console_init(mfn_to_virt(start_info.console.domU.mfn),
			start_info.console.domU.evtchn);
	xenstore_init(mfn_to_virt(start_info.store_mfn),
		start_info.store_evtchn);

	xenstore_read("name", my_domain_name, sizeof(my_domain_name));
	//print_xenstore_values();

	if (disk_vbd_is_present())
		disk_init();

	lwip_init();
	netfe_init();

	//-------- init phase 2 --------
	//
	if (nalloc_no_memory())
		fatal_error("init phase 2: no memory"); 	

	sys_stats_init();

	atoms_init();
	embed_init();
	code_base_init();
	scheduler_init();
	ets_init();
	pcre_init();
	counters_init();

	//print_start_info();
	//print_xenmem_info();
	//run_alloc_tests();
	//run_mm_tests();
	//print_xenstore_values();
	//run_bignum_tests();
	
	//printk("\r\nLing %s is here\r\n", quote_and_expand(LING_VER));

	proc_main(0); // preliminary run

	spawn_init_start(start_info.cmd_line);

	//while (1)
	//	HYPERVISOR_sched_op(SCHEDOP_block, 0);

	/* UNREACHABLE */
}
Esempio n. 9
0
bool Application::OnInit()
{
#if defined __DEBUG_MODE__ && defined __WINDOWS__
	_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

	std::cout << "This is free software: you are free to change and redistribute it." << std::endl;
	std::cout << "There is NO WARRANTY, to the extent permitted by law." << std::endl;
	std::cout << "Review COPYING in RME distribution for details." << std::endl;
	mt_seed(time(nullptr));
	srand(time(nullptr));

	// Discover data directory
	gui.discoverDataDirectory("clients.xml");

	// Tell that we are the real thing
	wxAppConsole::SetInstance(this);
	
	// Load some internal stuff
	settings.load();
	FixVersionDiscrapencies();
	gui.LoadHotkeys();
	ClientVersion::loadVersions();

#ifdef _USE_PROCESS_COM
	proc_server = nullptr;
	// Setup inter-process communice!
	if(settings.getInteger(Config::ONLY_ONE_INSTANCE)) 
	{
		{	
			// Prevents WX from complaining 'bout there being no server.
			wxLogNull nolog;

			RMEProcessClient client;
			wxConnectionBase* n_connection = client.MakeConnection(wxT("localhost"), wxT("rme_host"), wxT("rme_talk"));
			if(n_connection) 
			{
				RMEProcessConnection* connection = dynamic_cast<RMEProcessConnection*>(n_connection);
				ASSERT(connection);
				std::pair<bool, FileName> ff = ParseCommandLineMap();
				if(ff.first) 
				{
					connection->AskToLoad(ff.second);
					connection->Disconnect();
#if defined __DEBUG_MODE__ && defined __WINDOWS__
					gui.SaveHotkeys();
					settings.save(true);
#endif
					return false;
				}
				connection->Disconnect();
			}
		}
		// We act as server then
		proc_server = newd RMEProcessServer();
		if(!proc_server->Create(wxT("rme_host"))) 
		{
			// Another instance running!
			delete proc_server;
			proc_server = nullptr;
		}
	}
#endif

	// Image handlers
	//wxImage::AddHandler(newd wxBMPHandler);
	wxImage::AddHandler(newd wxPNGHandler);
	wxImage::AddHandler(newd wxJPEGHandler);
	wxImage::AddHandler(newd wxTGAHandler);

	gui.gfx.loadEditorSprites();

#ifndef __DEBUG_MODE__
	//wxHandleFatalExceptions(true);
#endif
	// Load all the dependency files
	std::string error;
	StringVector warnings;


	gui.root = newd MainFrame(wxT("Remere's Map Editor"), wxDefaultPosition, wxSize(700,500) );
	SetTopWindow(gui.root);
	gui.SetTitle(wxT(""));

	gui.root->LoadRecentFiles();

	// Load palette
	gui.LoadPerspective();

	// Show all windows
	gui.root->Show(true);

	// Set idle event handling mode
	wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);

	// Goto RME website?
	if(settings.getInteger(Config::GOTO_WEBSITE_ON_BOOT) == 1) 
	{
		::wxLaunchDefaultBrowser(wxT("http://www.remeresmapeditor.com/"), wxBROWSER_NEW_WINDOW);
		settings.setInteger(Config::GOTO_WEBSITE_ON_BOOT, 0);
	}

	// Check for updates
#ifdef _USE_UPDATER_
	if(settings.getInteger(Config::USE_UPDATER) == -1) 
	{
		int ret = gui.PopupDialog(
			wxT("Notice"),
			wxT("Do you want the editor to automatically check for updates?\n")
			wxT("It will connect to the internet if you choose yes.\n")
			wxT("You can change this setting in the preferences later."), wxYES | wxNO);
		if(ret == wxID_YES) 
		{
			settings.setInteger(Config::USE_UPDATER, 1);
		} 
		else 
		{
			settings.setInteger(Config::USE_UPDATER, 0);
		}
	}
	if(settings.getInteger(Config::USE_UPDATER) == 1) 
	{
		UpdateChecker updater;
		updater.connect(gui.root);	
	}
#endif

	FileName save_failed_file = gui.GetLocalDataDirectory();
	save_failed_file.SetName(wxT(".saving.txt"));
	if(save_failed_file.FileExists())
	{
		std::ifstream f(nstr(save_failed_file.GetFullPath()).c_str(), std::ios::in);

		std::string backup_otbm, backup_house, backup_spawn;

		getline(f, backup_otbm);
		getline(f, backup_house);
		getline(f, backup_spawn);

		// Remove the file
		f.close();
		std::remove(nstr(save_failed_file.GetFullPath()).c_str());

		// Query file retrieval if possible
		if(!backup_otbm.empty())
		{
			int ret = gui.PopupDialog(
				wxT("Editor Crashed"),
				wxString(
					wxT("IMPORTANT! THE EDITOR CRASHED WHILE SAVING!\n\n")
					wxT("Do you want to recover the lost map? (it will be opened immedietely):\n")) <<
					wxstr(backup_otbm) << wxT("\n") <<
					wxstr(backup_house) << wxT("\n") <<
					wxstr(backup_spawn) << wxT("\n"),
				wxYES | wxNO);

			if(ret == wxID_YES)
			{
				// Recover if the user so wishes
				std::remove(backup_otbm.substr(0, backup_otbm.size() - 1).c_str());
				std::rename(backup_otbm.c_str(), backup_otbm.substr(0, backup_otbm.size() - 1).c_str());

				if(backup_house.size())
				{
					std::remove(backup_house.substr(0, backup_house.size() - 1).c_str());
					std::rename(backup_house.c_str(), backup_house.substr(0, backup_house.size() - 1).c_str());
				}
				if(backup_spawn.size())
				{
					std::remove(backup_spawn.substr(0, backup_spawn.size() - 1).c_str());
					std::rename(backup_spawn.c_str(), backup_spawn.substr(0, backup_spawn.size() - 1).c_str());
				}
				
				// Load the map
				gui.LoadMap(wxstr(backup_otbm.substr(0, backup_otbm.size() - 1)));
				return true;
			}
		}
	}

	// Keep track of first event loop entry
	startup = true;
	return true;
}
Esempio n. 10
0
int main(int args, char *argv[]) {
    // Init
    mt_seed();

    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);

    TTF_Init();
    TTF_Font* f = TTF_OpenFont("courier_noir.ttf", 40);

    SDL_Surface* screen;
    screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);
    SDL_WM_SetCaption("Buttonset by Bob Rubbens", NULL);

    bool quit = false;
    int draw = 0;
    SDL_Event event;

    // cButton b(f, "TEST", 300, 300, B_MOUT, DIR_LEFT, 1000, SDL_MapRGB(screen->format, 0, 0, 0), SDL_MapRGB(screen->format, 128, 128, 128), screen->format);
    cButtonSet b(f, true, B_MIN, 100, 100, 50, 50, 1000, 500, DIR_LEFT, SDL_MapRGB(screen->format, 0, 0, 0), SDL_MapRGB(screen->format, 128, 128, 128), screen->format);

    b.addB("Add Button");
    b.addB("Quit");

    SDL_Rect t;
    t.x = 0;
    t.y = t.x;
    t.w = 10;
    t.h = t.w;

    std::string caption = "Deactivate";

    // Game loop
    while (!quit) {
        // Input handling
        while (SDL_PollEvent(&event)) {
            b.handleEvents(&event);

            switch (event.type) {
                case SDL_QUIT: // User x's out
                    quit = true;
                    break;
                case SDL_KEYDOWN: // ESCAPE terminates program
                    if (event.key.keysym.sym == SDLK_ESCAPE) {
                        quit = true;
                    }
                    break;
            }
        }

        if (b.gPressed() == 1) {
            b.addB(caption);
            caption = "Activate";
        }

        if (b.gPressed() == 2) {
            quit = true;
        }

        if (b.gPressed() == 3) {
            b.off(3, true);
        }

        if (b.gReleased() == 4) {
            b.on(3, false);
        }

        // Logic
        b.logic();

        // Rendering
        SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));

        b.render(screen);

        SDL_Flip(screen);
    }

    // Exit
    TTF_CloseFont(f);

    TTF_Quit();

    SDL_Quit();

    return 0;
}