Пример #1
0
// Entry point
int main(int argc, char *argv[])
{
	// Initialize SDL's subsystems - in this case, only video.
	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) 
	{
		fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
		exit(1);
	}

	// Register SDL_Quit to be called at exit; makes sure things are
	// cleaned up when we quit.
	atexit(SDL_Quit);

	Uint32 maybe_fullscreen;
	maybe_fullscreen = USE_FULLSCREEN ? SDL_FULLSCREEN : 0;

	// Attempt to create a window.
	screen = SDL_SetVideoMode(DISPLAY_WIDTH, DISPLAY_HEIGHT, 32, SDL_SWSURFACE | maybe_fullscreen);

	// If we fail, return error.
	if ( screen == NULL ) {
		fprintf(stderr, "Unable to set DISPLAY_WIDTHxDISPLAY_HEIGHT video: %s\n", SDL_GetError());
		exit(1);
	}

	setup();

	// Main loop: loop forever.
	while (1)
	{

		// Fill background black
		SDL_FillRect(screen, 0, 0);

		// advance game
		do_game();

		// Render stuff
		render();

		// Poll for events, and handle the ones we care about.
		SDL_Event event;
		while (SDL_PollEvent(&event)) 
		{
			switch (event.type) 
			{
				case SDL_KEYDOWN:
					switch (event.key.keysym.sym)
					{
						case 119: // W
							plr.y_input += 1;
							break;

						case 115: // S
							plr.y_input -= 1;
							break;

						case 97: // A
							plr.x_input -= 1;
							break;

						case 100: // D
							plr.x_input += 1;
							break;

						case SDLK_RETURN:
							spawn_wall(wal, i_vector(DISPLAY_WIDTH/2, DISPLAY_WIDTH/2), i_vector(plr.face.x, plr.face.y));
							break;

						default:
							break;
					}
					break;

				case SDL_MOUSEMOTION:			/* Mouse moved */
					plr.face.x = event.motion.x;
					plr.face.y = event.motion.y;

					// keep mouse in window
					if (event.motion.x < PLAYER_BOUND_WIDTH) 
						SDL_WarpMouse(PLAYER_BOUND_WIDTH,event.motion.y);

					if (event.motion.x > DISPLAY_WIDTH - PLAYER_BOUND_WIDTH) 
						SDL_WarpMouse(DISPLAY_WIDTH - PLAYER_BOUND_WIDTH,event.motion.y);

					if (event.motion.y < PLAYER_BOUND_WIDTH) 
						SDL_WarpMouse(event.motion.x,PLAYER_BOUND_WIDTH);

					if (event.motion.y > DISPLAY_HEIGHT - PLAYER_BOUND_WIDTH) 
						SDL_WarpMouse(event.motion.x,DISPLAY_HEIGHT - PLAYER_BOUND_WIDTH);

					break;

				case SDL_MOUSEBUTTONDOWN:		/* Mouse button pressed */
					plr.fire = 1;
					break;

				case SDL_MOUSEBUTTONUP:		/* Mouse button released */
					plr.fire = 0;
					break;

				case SDL_KEYUP:
					switch (event.key.keysym.sym)
					{
						case 119: // W
							plr.y_input -= 1;
							break;

						case 115: // S
							plr.y_input += 1;
							break;

						case 97: // A
							plr.x_input += 1;
							break;

						case 100: // D
							plr.x_input -= 1;
							break;

						default:
							break;
					}

					// If escape is pressed, return (and thus, quit)
					if (event.key.keysym.sym == SDLK_ESCAPE)
						return 0;
					break;

				case SDL_QUIT:
					return(0);
			}
		}
	}
	return 0;
}
Пример #2
0
// Last parameter exists to keep everything hidden in options
template <class IArchive, class OArchive> inline
void test_endian_serialization( typename IArchive::Options const & iOptions, typename OArchive::Options const & oOptions, const std::uint8_t inputLittleEndian )
{
  std::random_device rd;
  std::mt19937 gen(rd());

  for(size_t i=0; i<100; ++i)
  {
    bool     o_bool   = random_value<uint8_t>(gen) % 2 ? true : false;
    uint8_t  o_uint8  = random_value<uint8_t>(gen);
    int8_t   o_int8   = random_value<int8_t>(gen);
    uint16_t o_uint16 = random_value<uint16_t>(gen);
    int16_t  o_int16  = random_value<int16_t>(gen);
    uint32_t o_uint32 = random_value<uint32_t>(gen);
    int32_t  o_int32  = random_value<int32_t>(gen);
    uint64_t o_uint64 = random_value<uint64_t>(gen);
    int64_t  o_int64  = random_value<int64_t>(gen);
    float    o_float  = random_value<float>(gen);
    double   o_double = random_value<double>(gen);

    std::vector<int32_t> o_vector(100);
    for(auto & elem : o_vector)
      elem = random_value<uint32_t>(gen);

    std::ostringstream os;
    {
      OArchive oar(os, oOptions);
      oar(o_bool);
      oar(o_uint8);
      oar(o_int8);
      oar(o_uint16);
      oar(o_int16);
      oar(o_uint32);
      oar(o_int32);
      oar(o_uint64);
      oar(o_int64);
      oar(o_float);
      oar(o_double);
      // We can't test vector directly here since we are artificially interfering with the endianness,
      // which can result in the size being incorrect
      oar(cereal::binary_data( o_vector.data(), static_cast<std::size_t>( o_vector.size() * sizeof(int32_t) ) ));
    }

    bool     i_bool   = false;
    uint8_t  i_uint8  = 0;
    int8_t   i_int8   = 0;
    uint16_t i_uint16 = 0;
    int16_t  i_int16  = 0;
    uint32_t i_uint32 = 0;
    int32_t  i_int32  = 0;
    uint64_t i_uint64 = 0;
    int64_t  i_int64  = 0;
    float    i_float  = 0;
    double   i_double = 0;
    std::vector<int32_t> i_vector(100);

    std::istringstream is(os.str());
    {
      IArchive iar(is, iOptions);
      iar(i_bool);
      iar(i_uint8);
      iar(i_int8);
      iar(i_uint16);
      iar(i_int16);
      iar(i_uint32);
      iar(i_int32);
      iar(i_uint64);
      iar(i_int64);
      iar(i_float);
      iar(i_double);
      iar(cereal::binary_data( i_vector.data(), static_cast<std::size_t>( i_vector.size() * sizeof(int32_t) ) ));
    }

    // Convert to big endian if we expect to read big and didn't start big
    if( cereal::portable_binary_detail::is_little_endian() ^ inputLittleEndian ) // Convert to little endian if
    {
      CEREAL_TEST_SWAP_OUTPUT
      for( auto & val : o_vector )
        swapBytes(val);
    }

    CEREAL_TEST_CHECK_EQUAL

    check_collection(i_vector, o_vector);
  }
Пример #3
0
// Initial game setup
void setup()
{
	setup_player(&plr);
	time = SDL_GetTicks();
	old_time = 0;
	time_since_fps = 0;


	// TEMP (make some walls)
	// <<
	int ws = 100;

	spawn_wall(wal, i_vector(500, 140-ws), i_vector(501, 140+ws));
	spawn_wall(wal, i_vector(500-ws, 140), i_vector(500+ws, 141));

	spawn_wall(wal, i_vector(500, 340-ws), i_vector(500, 340+ws));
	spawn_wall(wal, i_vector(500-ws, 340), i_vector(500+ws, 341));

	spawn_wall(wal, i_vector(140, 340-ws), i_vector(141, 340+ws));
	spawn_wall(wal, i_vector(140-ws, 340), i_vector(140+ws, 341));
	// >>
}