Ejemplo n.º 1
0
void mud_update(void)
{
	static long creature_time = 0;
	static long object_time = 0;
	static long reset_time = 0;
	static long mysql_time = 0;
	static long mudtime_time = 0;
	static long backup_time = 0;
	static long heal_time = 0;
	static long socket_time = 0;

	if( ++socket_time % (LOOPS_PER_SECOND) == 0 )
		socket_update();
	
	if( ++heal_time % (LOOPS_PER_SECOND*5) == 0 )
		heal_update();	

	if( ++creature_time % (LOOPS_PER_SECOND*60) == 0 )
		creature_update();

	if( ++object_time % (LOOPS_PER_SECOND) == 0 )
		object_update();

	if( ++reset_time % (LOOPS_PER_SECOND) == 0 )
		reset_update();

	if( ++mysql_time % (LOOPS_PER_SECOND*60*60) == 0 )
		mudlog("Pinging mysql server == %s", mysql_ping(mysql) == 0 ? "Connected" : "Disconnected");

	if( ++mudtime_time % (LOOPS_PER_SECOND) == 0 )
	{
		if(mudtime_time % (LOOPS_PER_SECOND*60*15) == 0) // 15 minutes
			fwrite_time();
		mudtime.age++;
	}

	if( ++backup_time % (LOOPS_PER_SECOND*60*60) == 0) // check at startup and every hour
		backup_update();
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
     World *w;
     View *view;
     Intent *intent;
     Graphics_info *ginfo;
     Tcl_Interp *interp;
     Object *me;
     Boolean quit = False;
#if PROFILE
     int fps_count = 0;
     double total_time = 0.0;
     double start_time;
#endif


     interp = Tcl_CreateInterp();
     updater = updater_create(interp);

     if (argc != 2) {
	  fprintf(stderr, "Usage:  %s <world file>\n", argv[0]);
	  exit(EXIT_FAILURE);
     }

     ginfo = init_graphics();
#define TRUECOLOR
#ifdef TRUECOLOR
     set_texture_trans(32, ginfo->palette.color_lookup);
#else
     set_texture_trans(ginfo->palette.rgb_cube_size,
		       ginfo->palette.color_lookup);
#endif
     init_renderer(ginfo->width, ginfo->height);
     init_input_devices();

     /* Initialize the view */
     view = new_view(FLOAT_TO_FIXED(3.14159265 / 2.0));

     w = new_world();

     parser_init(interp, w);
     if (Tcl_EvalFile(interp, WT_INIT_FILENAME) != TCL_OK) {
	  fprintf(stderr, "%s\n", Tcl_GetVar(interp, "errorCode", 0));
	  fprintf(stderr, "%s\n", Tcl_GetVar(interp, "errorInfo", 0));
	  exit(1);
     }

     if (Tcl_EvalFile(interp, argv[1]) != TCL_OK) {
	  fprintf(stderr, "%s\n", Tcl_GetVar(interp, "errorCode", 0));
	  fprintf(stderr, "%s\n", Tcl_GetVar(interp, "errorInfo", 0));
	  exit(1);
     }


     while (!quit) {
	  double sin_facing, cos_facing;
	  double fx, fy, fz, torque;
	  Framebuffer *fb;
	  int i;


	  start_time = current_time();

	  intent = read_input_devices();
	  
	  me = get_controlled_object();
	  if (me == NULL)
	       fatal_error("No controlled object");

	  for (i = 0; i < intent->n_special; i++) {

	       switch (intent->special[i]) {
		  case INTENT_END_GAME:
		    quit = True;
		    (void) Tcl_Eval(interp, "action_quit");
		    break;

		  case INTENT_JUMP:
		    (void) Tcl_Eval(interp, "action_jump");
		    break;

		  case INTENT_ACTION1:
		    (void) Tcl_Eval(interp, "action_1");
		    break;

		  case INTENT_ACTION2:
		    (void) Tcl_Eval(interp, "action_2");
		    break;

		  case INTENT_ACTION3:
		    (void) Tcl_Eval(interp, "action_3");
		    break;

		  case INTENT_ACTION4:
		    (void) (Tcl_Eval(interp, "action_4") != TCL_OK);
		    break;

		  case INTENT_ACTION5:
		    (void) Tcl_Eval(interp, "action_5");
		    break;

		  default:
		    break;
	       }
	  }

	  /* Determine forces on viewer. */
	  sin_facing = sin(me->angle);
	  cos_facing = cos(me->angle);
	  fx = cos_facing * intent->force_x - sin_facing * intent->force_y;
	  fy = sin_facing * intent->force_x + cos_facing * intent->force_y;
 	  fz = -0.05 * me->mass;  /* gravity */
	  torque = intent->force_rotate;

	  /* Apply the forces. */
	  object_apply_force(me, fx, fy, fz);
	  object_apply_torque(me, torque);
	  object_update(me);
	  if (me->z <= 0.0 && me->dz <= 0.0) {
	       me->z = 0.0;
	       me->dz = 0.0;
	  }

	  /* Determine the view. */
	  me = get_viewpoint_object();
	  if (me == NULL)
	       fatal_error("No viewpoint object");
	  object_view(me, view);

	  updater_run(updater);

	  /* Display the world. */
	  fb = render(w, view);
	  update_screen(fb);
#if PROFILE
	  fps_count++;
	  total_time += current_time() - start_time;
	  if (fps_count == 100) {
	       printf("fps = %3.2f\n", (double) fps_count / total_time);
	       fps_count = 0;
	       total_time = 0.0;
	  }
#endif
     }

     end_input_devices();
     end_graphics();

     return EXIT_SUCCESS;
}