Beispiel #1
0
/**
 * The game loop, this function is called periodically to update the game.
 */
void game_loop()
{
    static int last_time = -1;
    int delta, now;
    
    /* Update the game */
    now = GET_CURRENT_TIME();
    
    if( last_time == -1 )
    {
        last_time = now;
        return;
    }
    
    // Get the time since the last update (minimum of one millisecond)
    delta = 1 + now - last_time; // TODO: remove the 1
    update_world(delta);
    
    /* Update the render module */
    render_update(delta);
    
    /* Render the game */
    render();
    
    last_time = now;
}
Beispiel #2
0
static void game_draw(context *ctx)
{
  struct game_context *game = (struct game_context *)ctx;
  struct config_info *conf = get_config();
  struct world *mzx_world = ctx->world;

  // No game state change has happened (yet)
  mzx_world->change_game_state = CHANGE_STATE_NONE;

  if(game->is_title && game->fade_in)
  {
    // Focus on center
    int x, y;
    set_screen_coords(640/2, 350/2, &x, &y);
    focus_pixel(x, y);
  }

  if(!mzx_world->active)
  {
    // There is no MZX_SPEED to derive a framerate from, so use the UI rate.
    set_context_framerate_mode(ctx, FRAMERATE_UI);
    if(!conf->standalone_mode)
      draw_intro_mesg(mzx_world);
    m_show();
    return;
  }

  set_context_framerate_mode(ctx, FRAMERATE_MZX_SPEED);
  update_world(ctx, game->is_title);
  draw_world(ctx, game->is_title);
}
Beispiel #3
0
int main(int argc, char** argv) {
    uint32_t last_frame_time = 0;
    uint32_t width = 640;
    uint32_t height = 480;
    bool quit = false;
    SDL_Window* window = NULL;
    SDL_Renderer* ren = NULL;
    SDL_Texture* texture = NULL;
    static uint32_t* pxbuf = NULL;
    static uint8_t* bug_data = NULL;
    //Initialize game
    pxbuf = new uint32_t[width*height];
    bug_data = new uint8_t[width*height];
    memset(pxbuf, 0x00, width*height); 
    memset(bug_data, 0x00, width*height); 

    if(init_sdl(width, height, &window, &ren, &texture)) {
        return 1;
    }   printf("SDL successfully initialized.\n");

    while (!quit) {
        last_frame_time = SDL_GetTicks();
        if (process_events() == -1) {
            quit = true;
        }
        update_bugs(width, height, bug_data);
        update_world(width, height, pxbuf, bug_data, texture);
        draw_world(width, height, texture, ren);
        printf("FPS: %f  \r", 1000./(SDL_GetTicks()-last_frame_time));
    }
    SDL_Quit();
    return 0;
}
Beispiel #4
0
void
move_pt(int id, int x, int y, xgobidata *xg) {
  int i, k;

  if (mpdir_type == horiz || mpdir_type == both)
    xg->screen[id].x = x;
  if (mpdir_type == vert || mpdir_type == both)
    xg->screen[id].y = y;

  /* Move the selected point */
  screen_to_plane(xg, id, &eps,
		  (mpdir_type == horiz || mpdir_type == both),
		  (mpdir_type == vert || mpdir_type == both));
  move_pt_pipeline(id, &eps, xg);  /*-- eps won't be changed here --*/

  /* Move all points with same glyph as the selected point */
  if (move_type == 1) {
    for (i=0; i<xg->nrows_in_plot; i++) {
      k = xg->rows_in_plot[i];
      if (k!=id && !xg->erased[k] && SAMEGLYPH(k,id)) {
	if (mpdir_type == horiz || mpdir_type == both) { xg->planar[k].x += eps.x; }
	if (mpdir_type == vert  || mpdir_type == both) { xg->planar[k].y += eps.y; }
	move_pt_pipeline(k, &eps, xg);
  }}}  /* sorry AB */

  /* Move ALL points */
  if (move_type == 2) {
    for (i=0; i<xg->nrows_in_plot; i++) {
      k = xg->rows_in_plot[i];
      if (k!=id && !xg->erased[k]) {
	if (mpdir_type == horiz || mpdir_type == both) { xg->planar[k].x += eps.x; }
	if (mpdir_type == vert  || mpdir_type == both) { xg->planar[k].y += eps.y; }
	move_pt_pipeline(k, &eps, xg);
  }}}  /* sorry AB */

  /* and now forward again, all the way ... */
  update_world(xg);
  world_to_plane(xg);
  plane_to_screen(xg);
  if (xg->is_brushing) {
    assign_points_to_bins(xg);
    if (xg->brush_mode == transient)
      reinit_transient_brushing(xg);
  }
  plot_once(xg);
  if (xg->is_cprof_plotting && xg->link_cprof_plotting)
    update_cprof_plot(xg);
}
Beispiel #5
0
static void test_json_report(CuTest * tc) {
    region * r;
    faction * f;
    unit * u;
    cJSON * json;

    cleargame(true);
    turn = 0;
    r = create_region(0, 1, 1, create_terrain("plain"));
    f = addplayer(r, 0, 0);
    u = r->units;
    update_world(0, 0, 1, 1);

    json = json_report(f);
    CuAssertIntEquals(tc, turn, cJSON_GetObjectItem(json, "turn")->valueint);
    free(json);
}
void loop_iter()
{
    clock_t time = clock();
    double delta = (double)(time - last_time)/(CLOCKS_PER_SEC/1000.0);
    last_time = time;

    reset_input_state();
    update_input();

    update_world(delta);

#ifdef __EMSCRIPTEN__
    if (done) {
 	        emscripten_cancel_main_loop();
 	    }
#endif
}
Beispiel #7
0
void
update_server(server_t *server)
{
    struct timeval t1;
    gettimeofday(&t1, NULL);

    double t0f = (double)server->t.tv_sec +
        (double)server->t.tv_usec / 1000 / 1000;
    double t1f = (double)t1.tv_sec +
        (double)t1.tv_usec / 1000 / 1000;
    double dt = t1f - t0f;

    if (t0f > 0)
        update_world(server->world, dt);

    gettimeofday(&server->t, NULL);
}
Beispiel #8
0
void update_all(int gno)
{
    update_set_lists(gno);
    update_world(gno);
    update_view(gno);
    update_status(gno, cur_statusitem, -1);
    update_ticks(gno);
    update_autos(gno);
    updatelegends(gno);
    updatesymbols(gno, -1);
    update_label_proc();
    update_locator_items(gno);
    update_draw();
    update_frame_items(gno);
    update_graph_items();
    update_hotlinks();
}
Beispiel #9
0
int main(int argc, char* argv[])
{
	char	buffer[2048];		/* string buffer for self-control list */

	signal(SIGINT, SIG_IGN);

	vrConfigure(&argc, argv, NULL);
	vrStart();

	signal(SIGINT, exit_application);

	/* TODO: it would be nice to put these above vrStart(), since */
	/*   it will block until all input devices are open, and this */
	/*   way we could be rendering something while waiting.       */
	/* TODO: actually, we almost *need* to have the init_gfx stuff*/
	/*   set before vrStart, so the window opening function will  */
	/*   have something to call (other than vrDoNothing()).       */
	/*   In fact, I have no idea how init_gfx() gets called at    */
	/*   all given the current setup.                             */
	vrFunctionSetCallback(VRFUNC_ALL_DISPLAY_INIT, vrCallbackCreate(init_gfx, 0));
	vrFunctionSetCallback(VRFUNC_ALL_DISPLAY, vrCallbackCreate(draw_server_world, 0));
	vrFunctionSetCallback(VRFUNC_HANDLE_USR2, vrCallbackCreate(vrDbgInfo, 0));

	if (vrContext->input->num_input_devices > 0) {
		vrDbgPrintfN(SELDOM_DBGLVL+1, "input viewer: input device[0] version = '%s'\n",
			vrContext->input->input_devices[0]->version);
	} else {
		vrDbgPrintfN(SELDOM_DBGLVL+1, "input viewer: No input devices defined.\n");
	}

	vrSystemSetName("inputs -- FreeVR inputs display application");
	vrSystemSetAuthors("Bill Sherman");
	list_self_controls(buffer, vrContext->input, sizeof(buffer), verbose);
	vrPrintf(buffer);
	vrSystemSetExtraInfo(buffer);

	vrDbgPrintf("input viewer: looping\n");
	while(vrFrame()) {
		update_world();
	}

	exit_application();

	exit(0);
}
void EXP_Class::adv ( void ){
 //cout << "enter advance" << endl;
  if( viewing ) stop_iterations_loop( );
  
  update_sensors( );//here you compute the input vector
  
  update_controllers ( ); //here you update the controllers and you generate a new output vector
  
  if( viewing ) param->eye->view_eye_movement();
  
  update_world(); //Here you call the set eye fucntion to upadte the eye position given the output vector

  //manage_collisions ( );

  compute_fitness();
  
  iter++;
  //cout << "leave advance" << endl;
}
Beispiel #11
0
void
reset_plot1d_type(xgobidata *xg)
{
  XtVaSetValues(plot1d_type_cmd[DOTPLOT],
    XtNstate, plot1d_type == DOTPLOT,
    NULL);
  setToggleBitmap(plot1d_type_cmd[DOTPLOT], plot1d_type == DOTPLOT);

  XtVaSetValues(plot1d_type_cmd[ASH],
    XtNstate, plot1d_type == ASH,
    NULL);
  setToggleBitmap(plot1d_type_cmd[ASH], plot1d_type == ASH);

  XtSetSensitive(nASHes_sbar, plot1d_type == ASH);

  plot1d_texture_var(xg);

  update_world(xg);
  world_to_plane(xg);
  plane_to_screen(xg);
  init_ticks(&xg->plot1d_vars, xg);
  plot_once(xg);
}
void update() {
  update_world();
  for (int i = 0; i < 10; i++) {
    update_enemy(i);
  }
}
Beispiel #13
0
/**
 * Starting point for the program.
 *
 * @param argc The number of command line arguments.
 * @param argv The array of command line arguments.
 * @return Program exit status.
 */
int main(int argc, char **argv) {
  SDL_Window *win = NULL;
  SDL_Renderer *rend = NULL;
  SDL_Texture *tex_player = NULL;

  if(init(&win, &rend, &tex_player)) {
    return 1;
  }

  Game_Data game_data;

  game_data.battle_data.state = GAME_BATTLE_MOVE;
  game_data.battle_data.num_units = 2;
  game_data.battle_data.board.tiles
    = malloc(GRID_COLS * GRID_ROWS * sizeof *game_data.battle_data.board.tiles);
  game_data.battle_data.turn_order =
    malloc(game_data.battle_data.num_units
           * sizeof *game_data.battle_data.turn_order);
  game_data.battle_data.camera_pos = (Coord_f){0.0, 0.0};
  game_data.battle_data.camera_vel = (Coord_f){0.0, 0.0};
  game_data.battle_data.board.cols = GRID_COLS;
  game_data.battle_data.board.rows = GRID_ROWS;
  game_data.battle_data.turn = 0;

  for(int i = 0; i < GRID_COLS; i++)
    for(int j = 0; j < GRID_ROWS; j++) {
      game_data.battle_data.board.tiles[j * GRID_COLS + i].ent = NULL;
    }

  SDL_Event event;
  Battle_Entity *temp;

  temp = game_data.battle_data.board.tiles[10 * GRID_ROWS + 5].ent
    = malloc(sizeof(Battle_Entity));

  temp->img.tex = tex_player;
  temp->img.dest_x = 5.0 * WIN_WIDTH / GRID_ROWS;
  temp->img.dest_y = 10.0 * WIN_HEIGHT / GRID_COLS;
  temp->img.dest_w = WIN_WIDTH / GRID_ROWS;
  temp->img.dest_h = WIN_HEIGHT / GRID_COLS;
  temp->img.src_x = 0.0;
  temp->img.src_y = 0.0;
  temp->img.src_w = 0.0;
  temp->img.src_h = 0.0;
  temp->team = TEAM_SELECTED;
  temp->pos = (Coord_f){10.0, 5.0};
  temp->vel = (Coord_f){0.0, 0.0};
  temp->move_queue.key_size = 0;
  temp->move_queue.head = NULL;

  game_data.battle_data.turn_order[0] = temp;

  temp = game_data.battle_data.board.tiles[19 * GRID_ROWS + 19].ent
    = malloc(sizeof(Battle_Entity));

  temp->img.tex = tex_player;
  temp->img.dest_x = 19.0 * WIN_WIDTH / GRID_ROWS;
  temp->img.dest_y = 19.0 * WIN_HEIGHT / GRID_COLS;
  temp->img.dest_w = WIN_WIDTH / GRID_ROWS;
  temp->img.dest_h = WIN_HEIGHT / GRID_COLS;
  temp->img.src_x = 0.0;
  temp->img.src_y = 0.0;
  temp->img.src_w = 0.0;
  temp->img.src_h = 0.0;
  temp->team = TEAM_SELECTED;
  temp->pos = (Coord_f){19.0, 19.0};
  temp->vel = (Coord_f){0.0, 0.0};
  temp->move_queue.key_size = 0;
  temp->move_queue.head = NULL;
  
  game_data.battle_data.turn_order[1] = temp;
  game_data.battle_data.keys = 0;
  
  double time = SDL_GetTicks();

  while(game_data.battle_data.state != GAME_STOPPED) {
    SDL_RenderClear(rend);
    
    while(SDL_PollEvent(&event)) {
      handle_event(&event, &game_data);
    }

    update_world(&game_data, SDL_GetTicks() - time);
    time = SDL_GetTicks();
    render(rend, &game_data);
    SDL_RenderPresent(rend);
  }

  free(game_data.battle_data.board.tiles[10 * GRID_ROWS + 5].ent);
  free(game_data.battle_data.board.tiles[19 * GRID_ROWS + 19].ent);

  SDL_DestroyTexture(tex_player);
  SDL_DestroyRenderer(rend);
  SDL_DestroyWindow(win);
  SDL_Quit();

  return 0;
}
Beispiel #14
0
static void
tform_response(xgobidata *xg, int *cols, int ncols)
{
  int j, n;
/*
  Boolean reset_vgroups = false;
*/

  /*
   * Reset vgroups?
  */
/*  gid = xg->vgroup_ids[cols[0]];
  for (n=1; n<ncols; n++) {
    if (xg->vgroup_ids[cols[n]] != gid) {
      reset_vgroups = true;
      break;
    }
  }
  if (reset_vgroups) {
    gid = numvargroups(xg)+1;
    for (n=0; n<ncols; n++) {
      xg->vgroup_ids[cols[n]] = gid;
    }

    resort_vgroup_ids(xg, xg->vgroup_ids);
  }*/


  if (xg->ncols_used > 2)
    update_sphered(xg, cols, ncols);
  update_lims(xg);
  update_world(xg);

/*  if (xg->is_xyplotting) - bug fix di 4/19/2000*/
  if (xg->is_plotting1d)
    plot1d_texture_var(xg);

  world_to_plane(xg);
  plane_to_screen(xg);

  /*
    This bit of init_axes() is needed.
  */
  for (n=0; n<ncols; n++) {
    j = cols[n];
    xg->nicelim[j].min = xg->lim0[j].min;
    xg->nicelim[j].max = xg->lim0[j].max;
    SetNiceRange(j, xg);
    xg->deci[j] = set_deci(xg->tickdelta[j]);
  }

  if (xg->is_xyplotting) {
    init_ticks(&xg->xy_vars, xg);
  }
  else if (xg->is_plotting1d)
    init_ticks(&xg->plot1d_vars, xg);

  if (xg->is_brushing) {
    assign_points_to_bins(xg);
    if (xg->brush_mode == transient)
      reinit_transient_brushing(xg);
  }

  plot_once(xg);

  if (xg->is_cprof_plotting)
    update_cprof_plot(xg);
}
Beispiel #15
0
void
plot1d_on(xgobidata *xg)
/*
 * Turn on and off the plot1d mode.
*/
{
  int j;
  Boolean cycle_on;
  extern xgobidata xgobi;
  int jvar = (plot1d_vertically) ? xg->plot1d_vars.y : xg->plot1d_vars.x;

/*
 *  If this mode is currently selected, turn it off.
*/
  if (xg->prev_plot_mode == PLOT1D_MODE && xg->plot_mode != PLOT1D_MODE) {
    map_plot1d(False);

    xg->is_plot1d_cycle = False;
    if (cycle_timeout_id)
    {
      XtRemoveTimeOut(cycle_timeout_id);
      cycle_timeout_id = 0L;
    }
  }
  /* Else turn it on */
  else if (xg->plot_mode == PLOT1D_MODE &&
           xg->prev_plot_mode != PLOT1D_MODE)
  {
    map_plot1d(True);

    if (!xg->is_plotting1d) {
      if (xg->is_touring && xg->is_princ_comp) {
	set_sph_labs(xg, xg->nsph_vars);
        xg->is_touring = False;
/*        reset_var_labels(xg, PRINCCOMP_OFF);i think not needed anymore
                                             sphering transformation*/
      }

      if (xg->carry_vars)
        carry_plot1d_vars(xg);

      xg->is_xyplotting = xg->is_spinning = xg->is_touring = False;
      xg->is_plotting1d = True;
      xg->is_corr_touring = False;

      plot1d_data = (float *) XtMalloc( (Cardinal)
        xg->nrows_in_plot * sizeof(float));

      plot1d_texture_var(xg);

      update_lims(xg);
      update_world(xg);
      world_to_plane(xg);
      plane_to_screen(xg);

      init_ticks(&xg->plot1d_vars, xg);

      plot_once(xg);
      /*
       * Reinitialize the sin and cos variables.  Why???
      */
      init_trig(xg);

      for (j=0; j<xg->ncols; j++) {
        if (j == jvar)
          xg->varchosen[j] = True;
        else
          xg->varchosen[j] = False;
      }

      set_varsel_label(xg);
      refresh_vboxes(xg);
    }
    /*
     * If the cycle button is activated, start cycling.
    */
    XtVaGetValues(plot1d_cycle_cmd, XtNstate, &cycle_on, NULL);

    if (cycle_on) {
      xg->is_plot1d_cycle = True;
      (void) XtAppAddWorkProc(app_con, RunWorkProcs, (XtPointer) NULL);
    }
  }

  setToggleBitmap(plot1d_cycle_cmd, xg->is_plot1d_cycle);
}
Beispiel #16
0
int goSomewhere(struct state *s, char **a, int penalty){
    int i,j, is, js, k, wx=0, wy=0, stage=-1;
	unsigned int change = 0, end = 0;
    struct state *ns;
	char * answer;
	char move='U';
	unsigned int *c = malloc( ((s-> world_w+1) * s->world_h+1) * sizeof( unsigned int ));
	
	if (c == NULL ){}
	for(i=0; i<((s-> world_w+1) * s->world_h+1); i++){
		c[i]=UINT_MAX;  
	}
	
	c[point_to_index(s, s->robot_x, s->robot_y)]=0;	
	
	put(s, 1, 1, O_EMPTY);
	move_robot(s, 1, 1);
	ns = copy(s);
	
	do{
	    free(s);
	    s = copy(ns);
		update_world(ns, s);
		change++;
		stage++;
		end = 0;
		for(i=1; i <= s->world_w; i++){
			for(j=1; j <= s->world_h; j++){
				if(c[point_to_index(s,i,j)]==stage){
					if(get(s, i, j) == O_LIFT_OPEN || get(s, i, j) == O_LAMBDA){
						wx=i;
						wy=j;
						end=stage;
						break;
					}
					//consider four cells - (-1, 0), (1, 0), (0, -1), (0, 1)
					for(k = 1; k<=4; k++){
						if(k==1) {is= 0 ; js=-1;}
						if(k==2) {is= 0 ; js= 1;}
						if(k==3) {is=-1 ; js= 0;}
						if(k==4) {is= 1 ; js= 0;}						
						if(bounded(s,i+is,j+js)	&& c[point_to_index(s, i+is, j+js)]==UINT_MAX){
							//can we go there?
							if(	!bounded(s, i+is, j+js+1) || (get(s, i+is, j+js+1) != O_EMPTY || get(ns, i+is, j+js+1) != O_ROCK)){	
								if(get(s, i+is, j+js)==O_LIFT_OPEN 
								|| get(s, i+is, j+js)==O_LAMBDA 
								|| get(s, i+is, j+js)==O_EARTH 
								|| get(s, i+is, j+js)==O_EMPTY){
									if((bounded(s, i+is, j+js+1) && get(s, i+is, j+js+1)==O_ROCK)
										|| (bounded(s, i+is+1, j+js+1) && get(s, i+is+1, j+js)==O_ROCK && get(s, i+is+1, j+js+1)==O_ROCK)
										|| (bounded(s, i+is-1, j+js+1) && get(s, i+is-1, j+js)==O_ROCK && get(s, i+is-1, j+js+1)==O_ROCK)){
										c[point_to_index(s, i+is, j+js)]=stage+penalty;
									}else{
										c[point_to_index(s, i+is, j+js)]=stage+1;
									}
									change = 0;
							    }
							}
						}
					}
				}
			}
		}
	}while(change <= penalty && end == 0);
	
	//debug
	//dump(s);
	
	if(0){
		for(j=s->world_h; j>0; j--){
			for(i=1; i<=s->world_w; i++){
				if(c[point_to_index(s, i, j)]==UINT_MAX){
					printf("X");
				}else{
					printf("%u", c[point_to_index(s, i, j)]);
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	
	i=0;
	if(end>0){
		answer = malloc( (end+2)*sizeof( char ));
		if (answer == NULL ){}
		
		while(end>0){
			for(k=1; k<=4;k++){
				if(k==1) {is=-1; js= 0;move='R';}
				if(k==2) {is= 1; js= 0;move='L';}						
				if(k==3) {is= 0; js=-1;move='U';}
				if(k==4) {is= 0; js= 1;move='D';}
				if( bounded(s, wx+is, wy+js) && c[point_to_index(s, wx+is, wy+js)] < end) {
					end = c[point_to_index(s, wx+is, wy+js)];
					answer[i++]=move;
					wx = wx+is;
					wy = wy+js;
					break;
				}
			}
		}
		answer[i]='\0';
		reverse(answer,0,strlen(answer)-1);
	}else{
		answer = malloc(1*sizeof( char ));
		if (answer == NULL ){}
		answer[0]='\0';
     	*a=answer;
		free(c);
		return 1;
	}
	*a=answer;
	free(c);
	return 0;
}
Beispiel #17
0
int main(int argc, char* argv[])
{

	/* TODO: do I want to ignore interrupts for all of this?  or */
	/*   just during vrStart()?                                  */
	//signal(SIGINT, SIG_IGN);

	vrShmemInit(30 * 1024 * 1024);
	vrConfigure(&argc, argv, NULL);

	/* TODO: it would be nice to put these above vrStart(), since */
	/*   it will block until all input devices are open, and this */
	/*   way we could be rendering something while waiting.       */
	/* TODO: actually, we almost *need* to have the init_gfx stuff*/
	/*   set before vrStart, so the window opening function will  */
	/*   have something to call (other than vrDoNothing()).       */
	/*   In fact, I have no idea how init_gfx() gets called at    */
	/*   all given the current setup.                             */
	/* [5/30/00: I have now moved the function setting routines to*/
	/*   come before vrStart().  The library needs to be changed  */
	/*   such that the incoming callbacks are stored in a holding */
	/*   bin, until the render/input/whatever loop is ready to    */
	/*   update them.                                             */
#if 1
	/* TODO: unfortunately this shorthand doesn't work when there are extra */
	/*   arguments but these work okay.                                     */
	vrCallbackSet(VRFUNC_DISPLAY_INIT, "init_gfx", init_gfx, 0);
	vrCallbackSet(VRFUNC_DISPLAY_FRAME, "gfx_frame", gfx_frame, 0);
	vrCallbackSet(VRFUNC_DISPLAY, "draw_world", draw_world, 0);
	vrCallbackSet(VRFUNC_DISPLAY_SIM, "my_sim", my_sim, 0);
	vrCallbackSet(VRFUNC_HANDLE_USR2, "travel:vrDbgInfo", vrDbgInfo, 0);
#else
#  if 1 /* 1/4/2003: test of possible startup race condition */
	vrSetFunc(VRFUNC_DISPLAY_INIT, vrCreateNamedCallback("init_gfx", init_gfx, 0));
#  endif
	vrSetFunc(VRFUNC_DISPLAY, vrCreateNamedCallback("draw_world", draw_world, 0));
#  ifdef PERSONAL_SIMULATOR
	vrSetFunc(VRFUNC_DISPLAY_SIM, vrCreateNamedCallback("my_sim", my_sim, 0));
#  endif
	vrSetFunc(VRFUNC_HANDLE_USR2, vrCreateNamedCallback("travel:vrDbgInfo", vrDbgInfo, 0));
#endif

	vrStart();

	signal(SIGINT, exit_application);

	if (vrContext->input->num_input_devices > 0) {
		vrDbgPrintfN(SELDOM_DBGLVL+1, "TRAVEL: input device[0] version = '%s'\n",
			vrContext->input->input_devices[0]->version);
	} else {
		vrDbgPrintfN(SELDOM_DBGLVL+1, "TRAVEL: No input devices defined.\n");
	}

#if 0
	if (vrDbgDo(AALWAYS_DBGLVL+1)) {
		vrFprintContext(stdout, vrContext, verbose);
		vrFprintConfig(stdout, vrContext->config, verbose);
		vrFprintInput(stdout, vrContext->input, verbose);
	}
#endif

        if(vrContext->input->num_input_devices > 0)
	    vrDbgPrintf("TRAVEL: input device[0] version = '%s'\n",
		vrContext->input->input_devices[0]->version);

#if 0 /* NOTE: this isn't really necessary, so don't use for non-test applications */
	update_world();
	vrInputWaitForAllInputDevicesToBeOpen();
#endif
	vrSystemSetName("travel -- FreeVR test program");
	vrSystemSetAuthors("Bill Sherman");
	vrSystemSetExtraInfo("A really good program for testing the FreeVR library");
	vrSystemSetStatusDescription("Application running fine");
	vrInputSet2switchDescription(0, "Terminate the application");
	vrInputSet2switchDescription(1, "Reset User Travel");
	vrInputSet2switchDescription(2, "Move User 0.1 to the right");
	vrInputSet2switchDescription(3, "Move User 0.1 to the left");
	vrInputSetValuatorDescription(0, "Rotate User");
	vrInputSetValuatorDescription(1, "Move User in direction of Wand");
#if 0 /* for testing */
	vrInputSetNswitchDescription(0, "Do something with a switch");
	vrInputSetNsensorDescription(0, "Do something with an N-sensor");
	vrInputSet6sensorDescription(0, "Move the Head");
	vrInputSet6sensorDescription(1, "Move the Wand");
#endif

	vrDbgPrintf("TRAVEL: looping\n");
#if 1
	while(vrFrame()) {
		update_world();
	}
#else /* run for two frames and then quit */
	vrFrame();
	update_world();
	vrFrame();
	update_world();
#endif

	vrPrintf(BOLD_TEXT "TRAVEL: I guess we're all done now.\n" NORM_TEXT);
	exit_application();

	exit(0);
}
Beispiel #18
0
Datei: main.c Projekt: needs/anko
int main(int argc, char **argv)
{
	world_t world;
	game_t game;
	double last_time = 0;
	double current_time = 0;
	float deltatime = 0;
	float sleep_time;

	if (config_from_file("anko.cfg", 1) == 2)
		return EXIT_FAILURE;
	if (config_from_args(argc, argv))
		return EXIT_FAILURE;

	if (!init())
		goto err_init;
	if (!new_game(&game, config.board_width, config.board_height, &config.gen_params, config.sim_speed * 1000))
		goto err_game;
	if (!create_world(&world, &game))
		goto err_world;
	if ((current_ui = init_ui_game(&world)) == NULL)
		goto err_ui;

	world_set_active_player(&world, add_player(&game, TEAM_BURNER));
	events_link_frame(&current_ui); // link window event to game ui frame
	glClearColor(0, 0, 0, 1);

	last_time = 0;
	while(!glfwWindowShouldClose(window)) {
	    current_time = glfwGetTime();
		deltatime = current_time - last_time;
		update_speed(deltatime);
		glfwPollEvents();

		// Update
		update_ui(current_ui, deltatime);
		update_world(&world);
		if (update_game(&game, deltatime * 1000))
			refresh_world(&world);
		if(should_quit)
			glfwSetWindowShouldClose(window, GL_TRUE);

		// Rendering
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		draw_ui(current_ui);
		font_swap_buffers();
		glfwSwapBuffers(window);

		// Update speed and sleep if necessary
		last_time = current_time;
		sleep_time = (current_time + MAX_MSPF - glfwGetTime()) * 1000 * 1000;
		if(sleep_time > 0)
			usleep(sleep_time);
	}

	destroy_ui(current_ui);
	game_over(&game);
	end_of_the_world(&world); // Tin tin tin
	terminate();

	return EXIT_SUCCESS;
err_ui:
	end_of_the_world(&world);
err_world:
	game_over(&game);
err_game:
	terminate();
err_init:
	return EXIT_FAILURE;
}