Exemple #1
0
void kernel_start()
{
   init_pic();
   init_gdt();
   init_idt();
   init_graphic();

   io_sti();

   while(1);
//   halt();

}
Exemple #2
0
void init_game(void) {
  srand(time(NULL));

  game.game_name = "Auto AI";
  game.author_name = "Ya Shou";
  game.author_email = "*****@*****.**";
  game.impl = &impl;

  game_ctrl.repeat_on = 0;
  game_ctrl.automove_interval = 10;
  game_ctrl.auto_move = &do_auto_move;
  game_ctrl.before_auto_move = &do_step_ai;
  game_ctrl.kill_bm_lines = &kill_lines_hook;
  game_ctrl.quit = 0;

  game_render.render = &do_render;
  game_render.clrscr = 0;
  game_render.draw_block = 0;
  game_render.update = 0;

  game_event.kbd_handler = &dealkbd;
  game_event.quit_handler = 0;

  g_cfg.scrw = WNDW;
  g_cfg.scrh = WNDH;
  g_cfg.ctrl = &game_ctrl;
  g_cfg.render = &game_render;
  g_cfg.event = &game_event;

  init_ui();
  init_graphic();
  
  default_init_shapes();

  impl.bm = create_blockmap(XRES, YRES);
  impl.queue = create_queue(7, 7);
  impl.sb = create_shapebuf(-1);
  impl.cvs = create_canvas(BOX_SZ*XRES, BOX_SZ*YRES);
  impl.pnl = create_canvas(WNDW-BOX_SZ*XRES, WNDH);

  newgame();
}
Exemple #3
0
int main(int argc, char** argv) {
	init_core();
	debug_message("[hunter] initialized core");

	init_graphic();
	debug_message("[hunter] initialized graphics, mode W%d H%d", window_get_width(global_get(global_get_singleton(), GLOBAL_WINDOW)), window_get_height(global_get(global_get_singleton(), GLOBAL_WINDOW)));

	init_sound();
	debug_message("[hunter] initialized sound");

	init_systems();
	debug_message("[hunter] initialized systems");

	window* window_handle = global_get(global_get_singleton(), GLOBAL_WINDOW);
	input* input_handle = global_get(global_get_singleton(), GLOBAL_INPUT);
	syscontainer* syscontainer_handle = global_get(global_get_singleton(), GLOBAL_SYSCONTAINER);
	text* text_handle = global_get(global_get_singleton(), GLOBAL_TEXT);
	hl_render* hl_render_handle = global_get(global_get_singleton(), GLOBAL_HL_RENDER);
	shader* shader_texture_handle = global_get(global_get_singleton(), GLOBAL_SHADER_TEXTURE);
	camera* camera_handle = global_get(global_get_singleton(), GLOBAL_CAMERA);
	debug_draw* debug_draw_handle = global_get(global_get_singleton(), GLOBAL_DEBUG_DRAW);

	float delta_ref_point = time_get_elapsed(window_handle);
	float delta_accumulator = 0.0f;
	float delta_frame_time = 0.0f;

	float fps_accumulator = 0.0f;
	float fps_value = 0.0f;
	float fps_value_last = fps_value;
	unsigned int fps_counter = 0;

	unsigned int game_kill_flag = 0;

	debug_message("[hunter] posting init event to systems");
	syscontainer_post_event(syscontainer_handle, EVENT_INIT);

	while (!game_kill_flag) {
		delta_frame_time = time_get_elapsed(window_handle) - delta_ref_point;
		delta_ref_point = time_get_elapsed(window_handle);

		window_update(window_handle);

		input_state current_input_state;
		input_get_input_state(input_handle, &current_input_state);

		game_kill_flag |= window_get_should_close(window_handle);
		game_kill_flag |= current_input_state.key_dev;

		window_set_clear_color(window_handle, 1.0f, 0.0f, 1.0f, 0.0f);
		debug_draw_clear(debug_draw_handle);
		window_clear(window_handle);

		delta_accumulator += delta_frame_time;

		if (delta_accumulator < 0.0f) {
			delta_accumulator = 0.0f;
		}

		while (delta_accumulator >= 1.0f / DELTA_REFERENCE_FPS) {
			syscontainer_post_event(syscontainer_handle, EVENT_PRE_LOGIC);
			syscontainer_post_event(syscontainer_handle, EVENT_LOGIC);
			syscontainer_post_event(syscontainer_handle, EVENT_POST_LOGIC);

			delta_accumulator -= 1.0f / DELTA_REFERENCE_FPS;
		}

		syscontainer_post_event(syscontainer_handle, EVENT_DRAW);

		window_set_blend_mode(window_handle, WINDOW_BLEND_ALPHA);

		debug_draw_render_all(debug_draw_handle);

		hl_render_draw(hl_render_handle, shader_texture_handle, camera_handle);
		hl_render_clear(hl_render_handle);

		fps_counter++;
		fps_accumulator += delta_frame_time;

		if (fps_accumulator >= 1.0f) {
			fps_value_last = fps_value;
			fps_value = (float) fps_counter / fps_accumulator;
			fps_counter = 0;
			fps_accumulator = 0.0f;
		}

		text_batch fps_batch = {20, 20, 0.2f, 0.8f, 1.0f, 1.0f, "", "monospace", 12};
		sprintf(fps_batch.text_data, "FPS : %3.2f (%3.2f)", fps_value, fps_value - fps_value_last);

		text_submit_batch(text_handle, &fps_batch);

		text_render_all(text_handle);
		text_flush_batch(text_handle);

		window_swap_buffers(window_handle);
	}

	debug_message("[hunter] posting destroy event to systems");
	syscontainer_post_event(syscontainer_handle, EVENT_DESTROY);

	free_systems();
	free_sound();
	free_graphic();
	free_core();

	h_free_all();

	debug_message("[hunter] terminated cleanly");
	return 0;
}
Exemple #4
0
 /*
  read gjf Cartesian file.
 */
void read_gjf_cartesian(char *file, structGraphic *g)
{
   FILE *fp;
   int flag;
   int i, k,  nedge;
   int ncount, key[20];
   decimal value[20];
   char line[300], name[15];
   
   flag = 0;   i = k = 0;   nedge = 0;
   
   init_graphic(g);

   fp = fopen(file, "r");
     
   JmpOrNot(fp, '%');
   JmpOrNot(fp, '#');
   JmpSpace(fp);
   toss(fp, 3);
   
   while(fgets(line, sizeof(line), fp) != NULL)
   {
      if(is_blank_line(line))
          break;
      else
      {
          sscanf(line, "%s", name);
          g->vex[i].id = i+1;
         
          strcpy(g->vex[i].element_name, name);
          //printf("%s\n", name);
          i++;
      }                     
    }
    
    g->n = i;
    
    while(fgets(line, sizeof(line), fp) != NULL)
    {
         if(is_blank_line(line))
             break;
                      
         ncount = count_tokens(ltrim(line), " ");  
		 //printf("%d\n\n", ncount);
         nedge += ncount/2; 
		 k = 0;
         for(i = 0; i < ncount; i++)
         {
             if(i == 0 || i%2 == 1)             
                 key[k++] = atoi(gettoken(line," ",i+1)); 
             else
                 value[0] = (decimal)atof(gettoken(line," ",i+1));              
         }                
          
         //g->edge[key[0]-1][key[0]-1] = INFINITY;
		 //printf("%d\n", k);
         for(i = 1; i < k; i++)
         {
            g->edge[key[0]-1][key[i]-1] = 1;
            g->edge[key[i]-1][key[0]-1] = 1;
			
         }  
                
     }
     
     g->e = nedge;
	 //printf("%d\n", nedge);

    if(read_gjf_match_ff(file, "match", g) != g->n)
	{
	  printf("ERROR OCCURED... FILE:%s LINE:%s\n", __FILE__, __LINE__);
	  exit(1);
	}

  return;

 }
Exemple #5
0
/***********************************************************************
* plugin main ppu thread
***********************************************************************/
static void vsh_menu_thread(uint64_t arg)
{
    #ifdef DEBUG
    dbg_init();
    dbg_printf("programstart:\n");
    #endif

    uint16_t oldpad = 0, curpad = 0;
    CellPadData pdata;

    // wait for XMB, feedback
    sys_timer_sleep(13);

    //vshtask_notify("sprx running...");

    play_rco_sound("system_plugin", "snd_trophy");

    #ifdef HAVE_STARFIELD
    init_once(/* stars */);
    #endif

    // custom bg_color init
    a = GET_A(bg_color_menu[1]);
    r = GET_R(bg_color_menu[1]);
    g = GET_G(bg_color_menu[1]);
    b = GET_B(bg_color_menu[1]);

    while(1)
    {
        // if VSH Menu is running, we get pad data over our MyPadGetData()
        // else, we use the vsh pad_data struct
        if(menu_running)
            MyPadGetData(0, &pdata);
        else
            VSHPadGetData(&pdata);

        // if pad_data and we are in XMB(vshmain_EB757101() == 0)
        if((pdata.len > 0)
        && (vshmain_EB757101() == 0)
        )
        {
            curpad = (pdata.button[2] | (pdata.button[3] << 8));

            if((curpad & PAD_SELECT) && (curpad != oldpad))
            {
                switch(menu_running)
                {
                    // VSH Menu not running, start VSH Menu
                    case 0:
                      // main view and start on first entry 
                      view = line = 0;

                      //
                      pause_RSX_rendering();

                      // create VSH Menu heap memory from memory container 1("app")
                      create_heap(64);       // 64 MB

                      // initialize VSH Menu graphic (init drawing context, alloc buffers, blah, blah, blah...)
                      init_graphic();

                      // stop vsh pad
                      start_stop_vsh_pad(0);

                      // set menu_running
                      menu_running = 1;

                      break;

                    // VSH Menu is running, stop VSH Menu
                    case 1:
                      stop_VSH_Menu();

                      // restart vsh pad
                      start_stop_vsh_pad(1);

                      break;
                }

                oldpad = 0;
                sys_timer_usleep(300000);
            }


          // VSH Menu is running, draw menu / check pad
          if(menu_running)
          {
                #ifdef DEBUG
                dbg_printf("%p\n", pdata);
                #endif

                draw_frame(&pdata);

                flip_frame();

                if(curpad != oldpad)
                {

                    if(curpad & PAD_UP)
                    {
                        if(line <= 0){
                            line = 0;
                        }else{
                            line--;
                            play_rco_sound("system_plugin", "snd_cursor");
                        }
                    }

                    if(curpad & PAD_DOWN)
                    {
                        if(line >= max_menu[view]-1){
                            line = max_menu[view]-1;
                        }else{
                            line++;
                            play_rco_sound("system_plugin", "snd_cursor");
                        }
                    }

                    if(curpad & PAD_LEFT
                    || curpad & PAD_RIGHT) do_leftright_action(curpad);

                    if(curpad & PAD_CROSS) do_menu_action();

                }

                // ...

                sys_timer_usleep(30);

            } // end VSH Menu is running

            oldpad = curpad;
        }else{
            oldpad = 0;
        }
    }

    #ifdef DEBUG
    dbg_fini();
    #endif
    sys_ppu_thread_exit(0);
}
Exemple #6
0
int main(int argc, char **argv)
{
	SDL_Event event;
	Uint8 mstat;
	int xw, yh, optc;
	int bombs = -1, width = -1, height = -1;
	struct option const longopts[] = {
		{"width", 1, NULL, 'w'},
		{"height", 1, NULL, 'h'},
		{"bombs", 1, NULL, 'b'},
		{"help", 0, NULL, 'H'},
		{NULL, 0, NULL, 0}
	};

	progname = argv[0];

	while ((optc = getopt_long(argc, argv, "w:h:b:H", longopts, NULL)) != -1) {
		switch (optc) {
			case 'w':
				width = atoi(optarg);
				break;
			case 'h':
				height = atoi(optarg);
				break;
			case 'b':
				bombs = atoi(optarg);
				break;
			case 'H':
				usage(0);
				exit(EXIT_SUCCESS);
			default:
				usage(1);
				exit(EXIT_FAILURE);
		}
	}
	usage(0);

	/* Use default value if invalid argument is given. */
	if (width < 1 || width > 99)
		width = W_DEF;
	if (height < 1 || height > 99)
		height = H_DEF;
	if (bombs < 1 || bombs > width*height)
		bombs = width*height / 6;

	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		fprintf(stderr, "Error: %s\n", SDL_GetError());
		exit(EXIT_FAILURE);
	}
	atexit(SDL_Quit);

	init_graphic(width, height);
	atexit(deinit_graphic);

	init_game(width, height, bombs);
	atexit(deinit_game);

	start_game();

	while (SDL_WaitEvent(&event) >= 0) {
		switch (event.type) {
			case SDL_MOUSEBUTTONDOWN:
				if (is_gameover()) {
					start_game();
					break;
				}

				xw = event.motion.x;
				yh = event.motion.y;
				pixel2pos(&xw, &yh);

				mstat = SDL_GetMouseState(NULL, NULL);
				if(mstat & SDL_BUTTON(1) || mstat & SDL_BUTTON(2)) 
					open_box(get_box(xw, yh));
				else if (mstat & SDL_BUTTON(3))
					set_flag(get_box(xw, yh));
				break;
			case SDL_QUIT:
				putchar('\n');
				exit(EXIT_SUCCESS);
				break;
			default:
				break; /* Nothing. */
		}
	}

	return 0;
}