Esempio n. 1
0
	void gui::update(engine& eng, double t, const entity_list& elist)
	{
		using namespace component;
		static component_id gui_mask
			= genmask(Component::GUI)
			| genmask(Component::STATS)
			| genmask(Component::POSITION)
			| genmask(Component::SPRITE);
		
		for(auto& e : elist) {
			if((e->mask & gui_mask) == gui_mask) {
				auto& stats = e->stat;
				auto& pos = e->pos;
				auto& spr = e->spr;
				auto fnt = font::get_font("SourceCodePro-Regular.ttf", 20);
				// XXX we should color code some of these
				// i.e. as health gets lower it goes from green to red, to grey dead/unconscious
				std::stringstream ss;
				ss  << "Turn: " << std::setw(4) << eng.get_turns()
					<< " | "
					<< "Health: " << stats->health
					<< " | "
					<< datetime(eng.get_turns()).printable()
					;
				auto surf = font::render_shaded(ss.str(), fnt, graphics::color(255,255,255), graphics::color(0,0,0));
				// surface gets free'd by update_texture, so we need to get height (and width if needed) before we call it.
				// gui tagged entities get absolute pixel positioning for *free*.
				pos->pos.x = 0;
				pos->pos.y = eng.get_window().height() - surf->h;
				spr->update_texture(std::make_shared<graphics::surface>(surf));
			}
		}
	}
Esempio n. 2
0
	void lua::register_mark_library(const engine & engine) {
		// Register the Lua API.
		engine.register_library("object", mark_library);
		
		// Register the mark userdata type.
		if (engine.push_metatable(mark_class)) {
			// Garbage collection finalizer.
			lua_pushcfunction(engine, mark_gc);
			lua_setfield(engine, -2, "__gc");
		}
		lua_pop(engine, 1);
		
		// Register the actor userdata type.
		if (engine.push_metatable(actor_class)) {
			// Getter metamethod.
			lua_pushcfunction(engine, actor_index);
			lua_setfield(engine, -2, "__index");
			
			// Setter metamethod.
			lua_pushcfunction(engine, actor_newindex);
			lua_setfield(engine, -2, "__newindex");
			
			// Garbage collection finalizer.
			lua_pushcfunction(engine, actor_gc);
			lua_setfield(engine, -2, "__gc");
		}
		lua_pop(engine, 1);
	}
Esempio n. 3
0
void add_testing_generators(engine& e,
                            generator_registry& gr)
{
   auto run_product = make_shared<product_argument_writer>("run_product", e.get_type_registry().get(types::TESTING_RUN_PASSED));
   auto run_output_product = make_shared<product_argument_writer>("run_output_product", e.get_type_registry().get(types::TESTING_OUTPUT));
   auto test_executable = make_shared<source_argument_writer>("test_executable", e.get_type_registry().get(types::EXE));
   auto additional_dirs = make_shared<shared_lib_dirs_writer>("additional_dirs", e.get_type_registry().get(types::SHARED_LIB));
   auto args = make_shared<testing_run_args_writer>(e.get_type_registry());
#if defined(_WIN32)
   cmdline_builder cmdline("@SET PATH=%PATH%;$(additional_dirs)\n"
                           "@$(test_executable) $(args)\n");
#else
   cmdline_builder cmdline("export LD_LIBRARY_PATH=$(additional_dirs):$LD_LIBRARY_PATH\n"
                           "$(test_executable) $(args)");
#endif
   cmdline += run_product;
   cmdline += run_output_product;
   cmdline += test_executable;
   cmdline += additional_dirs;
   cmdline += args;

   auto action = std::make_shared<testing_run_action>("testing.run", run_product, run_output_product);
   *action += cmdline;

   auto sources = make_consume_types(e, {types::EXE});
   auto products = make_product_types(e, {types::TESTING_OUTPUT, types::TESTING_RUN_PASSED});

   unique_ptr<generator> g(new generator(e, "testing.run", sources, products, true, action));
   g->include_composite_generators(true);
   gr.insert(std::move(g));

   add_testing_suite_generator(e, gr);
}
Esempio n. 4
0
void menu_system::do_menu(engine& window)
{
    if(!window.render_me)
        return;

    if(window.width != lw || window.height != lh)
    {
        lw = window.width;
        lh = window.height;

        tex.create(lw, lh);

        tex.clear(sf::Color(60, 60, 60, 255));

        tex.display();
    }

    ///Note to self, I have totally broken the OpenGL rendering internals
    ///which makes SFML really very sad
    //glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, 0);

    //text::immediate(&window.window, "Start", {window.width/2.f, window.height/1.5f}, 60, true);

    bool lclick = once<sf::Mouse::Left>();

    vec2f wind = (vec2f){window.width, window.height};

    for(auto& i : ui_elements)
    {
        vec2f mouse_coords = {window.get_mouse_x(), window.get_mouse_y()};

        bool is_within = mouse_coords > i.pos * wind - i.dim/2.f && mouse_coords < i.pos * wind + i.dim/2.f;

        vec3f col = {0.7,0.7,0.7};

        if(is_within)
        {
            col = {1,1,1};

            if(lclick)
            {
                i.callback(*this);
            }
        }

        text::immediate(&window.window, i.label, i.pos * (vec2f){window.width, window.height}, i.font_size, true, col);
    }

    sf::Sprite spr;
    spr.setTexture(tex.getTexture());

    spr.setColor(sf::Color(255, 255, 255, 60));

    window.window.draw(spr);

    //window.window.clear(sf::Color(0,0,0,255));
}
Esempio n. 5
0
void add_link_generators(engine& e,
                         const build_action_ptr& link_action,
                         std::function<std::unique_ptr<generator>(const build_action_ptr& action)> link_generator_creator)
{
   e.generators().insert(link_generator_creator(link_action));

   auto a1 = std::make_shared<testing_link_action>(link_action);
   e.generators().insert(make_unique<testing_link_generator>(e, move(link_generator_creator(a1))));

   auto a2 = std::make_shared<testing_link_fail_action>(e, link_action);
   e.generators().insert(make_unique<testing_link_fail_generator>(e, move(link_generator_creator(a2))));
}
Esempio n. 6
0
 engine::want operator()(engine& eng,
     asio::error_code& ec,
     std::size_t& bytes_transferred) const
 {
   bytes_transferred = 0;
   return eng.shutdown(ec);
 }
Esempio n. 7
0
 engine::want operator()(engine& eng,
     asio::error_code& ec,
     std::size_t& bytes_transferred) const
 {
   bytes_transferred = 0;
   return eng.handshake(type_, ec);
 }
Esempio n. 8
0
	void action::update(engine& eng, float t, const entity_list& elist)
	{
		using namespace component;
		static component_id mask = genmask(Component::INPUT) | genmask(Component::POSITION);
		for(auto& e : elist) {
			if((e->mask & mask) == mask) {
				auto& inp = e->inp;
				auto& pos = e->pos;

				switch(inp->action)
				{
				case input::Action::none:	break;
				case input::Action::moved:	
					// Test to see if we moved but the collision detection failed it.
					// XX there must be a better way.
					if(pos->mov.x == 0 && pos->mov.y == 0) {
						inp->action = input::Action::none;
					} else {
						e->pos->pos += e->pos->mov;
						e->pos->mov.clear();
						if(e->is_player()) {
							eng.set_camera(e->pos->pos);

							eng.getMap()->clearVisible();
							eng.getMap()->updatePlayerVisibility(e->pos->pos, e->stat->visible_radius);
						}
					}
					break;
				case input::Action::pass:	break;
				case input::Action::attack:	break;
				case input::Action::spell:	break;
				case input::Action::use:	break;
				default: 
					ASSERT_LOG(false, "No action defined for " << static_cast<int>(inp->action));
					break;
				}
				// increment turns on successful update.
				if(inp->action != input::Action::none) {
					eng.inc_turns();
				}
			} else if((e->mask & genmask(Component::AI)) == genmask(Component::AI)) {
				//auto& aip = e->aip;
			}
		}
	}
Esempio n. 9
0
	void render::update(engine& eng, double t, const entity_list& elist)
	{
		using namespace component;
		static component_id sprite_mask = genmask(Component::POSITION)  | genmask(Component::SPRITE);
		static component_id gui_mask = sprite_mask | genmask(Component::GUI);
		static component_id map_mask = genmask(Component::MAP);
		
		const point& cam = eng.get_camera();
		const point screen_centre(eng.get_window().width() / 2, eng.get_window().height() / 2);
		const point& ts = eng.get_tile_size();

		for(auto& e : elist) {
			if((e->mask & gui_mask) == gui_mask) {
				auto& spr = e->spr;
				auto& pos = e->pos;
				auto& g = e->gui;
				if(spr->tex.is_valid()) {
					spr->tex.blit(rect(pos->pos.x, pos->pos.y));
				}
				for(auto& w : g->widgets) {
					w->draw(rect(0, 0, eng.get_window().width(), eng.get_window().height()), 0.0f, 1.0f);
				}
			}  else if((e->mask & sprite_mask) == sprite_mask) {
				auto& spr = e->spr;
				auto& pos = e->pos;
				if(spr->tex.is_valid()) {
					spr->tex.blit(rect(screen_centre.x - (cam.x - pos->pos.x) * ts.x - ts.x/2, screen_centre.y - (cam.y - pos->pos.y) * ts.y - ts.y/2, ts.x, ts.y));
				}
			} else if((e->mask & map_mask) == map_mask) {
				auto& map = e->map;

				const int screen_width_in_tiles = (eng.get_window().width() + eng.get_tile_size().x - 1) / eng.get_tile_size().x;
				const int screen_height_in_tiles = (eng.get_window().height() + eng.get_tile_size().y - 1) / eng.get_tile_size().y;
				rect area = rect::from_coordinates(-screen_width_in_tiles / 2 + cam.x, 
					-screen_height_in_tiles / 2 + cam.y,
					screen_width_in_tiles / 2 + cam.x,
					screen_height_in_tiles / 2 + cam.y);

				for(auto& chk : map->t.get_chunks_in_area(area)) {
					chk->draw(eng, cam);
				}
			}
		}
	}
  engine::want operator()(engine& eng,
      asio::error_code& ec,
      std::size_t& bytes_transferred) const
  {
    typename ConstBufferSequence::const_iterator iter = buffers_.begin();
    typename ConstBufferSequence::const_iterator end = buffers_.end();
    std::size_t accumulated_size = 0;

    for (;;)
    {
      engine::want want = eng.handshake(type_, ec);
      if (want != engine::want_input_and_retry
          || bytes_transferred == total_buffer_size_)
        return want;

      // Find the next buffer piece to be fed to the engine.
      while (iter != end)
      {
        const_buffer buffer(*iter);

        // Skip over any buffers which have already been consumed by the engine.
        if (bytes_transferred >= accumulated_size + buffer_size(buffer))
        {
          accumulated_size += buffer_size(buffer);
          ++iter;
          continue;
        }

        // The current buffer may have been partially consumed by the engine on
        // a previous iteration. If so, adjust the buffer to point to the
        // unused portion.
        if (bytes_transferred > accumulated_size)
          buffer = buffer + (bytes_transferred - accumulated_size);

        // Pass the buffer to the engine, and update the bytes transferred to
        // reflect the total number of bytes consumed so far.
        bytes_transferred += buffer_size(buffer);
        buffer = eng.put_input(buffer);
        bytes_transferred -= buffer_size(buffer);
        break;
      }
    }
  }
Esempio n. 11
0
    node_pointer get_document() throw(std::string)
    {
      if (document.get() == nullptr) {
	expat_engine.parse();
      }
      if (document.get() == nullptr) {
	throw std::string(nullptr);
      }
      return document;
    }
Esempio n. 12
0
  engine::want operator()(engine& eng,
      boost::system::error_code& ec,
      std::size_t& bytes_transferred) const
  {
    boost::asio::mutable_buffer buffer =
      boost::asio::detail::buffer_sequence_adapter<boost::asio::mutable_buffer,
        MutableBufferSequence>::first(buffers_);

    return eng.read(buffer, ec, bytes_transferred);
  }
Esempio n. 13
0
  engine::want operator()(engine& eng,
      pdalboost::system::error_code& ec,
      std::size_t& bytes_transferred) const
  {
    pdalboost::asio::const_buffer buffer =
      pdalboost::asio::detail::buffer_sequence_adapter<pdalboost::asio::const_buffer,
        ConstBufferSequence>::first(buffers_);

    return eng.write(buffer, ec, bytes_transferred);
  }
Esempio n. 14
0
void car::getinfo(engine& m)
{
	cout << endl;
	cout << "lenth " << length << endl;
	cout << "width " << width << endl;
	cout << "hight " << hight << endl;
	cout << "weight " << weight << endl;
	cout << "places " << numplaces << endl;
	cout << "max speed " << maxspeed << endl;
	m.getinfo1();
	cout << endl << "===========================" << endl << endl;
}
Esempio n. 15
0
///none of these affect the camera, so engine does not care about them
///assume main is blocking
void debug_controls(fighter* my_fight, engine& window)
{
    sf::Keyboard key;

    if(once<sf::Keyboard::T>())
    {
        my_fight->queue_attack(attacks::OVERHEAD);
    }

    if(once<sf::Keyboard::Y>())
    {
        my_fight->queue_attack(attacks::SLASH);
    }

    if(once<sf::Keyboard::F>())
    {
        my_fight->queue_attack(attacks::STAB);
    }

    if(once<sf::Keyboard::G>())
    {
        my_fight->queue_attack(attacks::REST);
    }

    if(once<sf::Keyboard::R>())
    {
        my_fight->queue_attack(attacks::BLOCK);
    }

    if(once<sf::Keyboard::V>())
    {
        my_fight->queue_attack(attacks::RECOIL);
    }

    if(once<sf::Keyboard::Z>())
    {
        my_fight->queue_attack(attacks::TROMBONE);
    }

    if(once<sf::Mouse::XButton1>())
        my_fight->queue_attack(attacks::SLASH_ALT);

    if(once<sf::Mouse::XButton2>())
        my_fight->queue_attack(attacks::OVERHEAD_ALT);


    if(once<sf::Keyboard::H>())
    {
        my_fight->try_feint();
    }

    if(once<sf::Keyboard::SemiColon>())
    {
        my_fight->die();
    }

    float y_diff = 0;

    if(key.isKeyPressed(sf::Keyboard::U))
    {
        y_diff = 0.01f * window.get_frametime()/2000.f;
    }

    if(key.isKeyPressed(sf::Keyboard::O))
    {
        y_diff = -0.01f * window.get_frametime()/2000.f;
    }

    my_fight->set_rot_diff({0, y_diff, 0});

    static float look_height = 0.f;

    if(key.isKeyPressed(sf::Keyboard::Comma))
    {
        look_height += 0.01f * window.get_frametime() / 8000.f;
    }

    if(key.isKeyPressed(sf::Keyboard::Period))
    {
        look_height += -0.01f * window.get_frametime() / 8000.f;
    }

    my_fight->set_look({look_height, 0.f, 0.f});

    vec2f walk_dir = {0,0};

    if(key.isKeyPressed(sf::Keyboard::I))
        walk_dir.v[0] = -1;

    if(key.isKeyPressed(sf::Keyboard::K))
        walk_dir.v[0] = 1;

    if(key.isKeyPressed(sf::Keyboard::J))
        walk_dir.v[1] = -1;

    if(key.isKeyPressed(sf::Keyboard::L))
        walk_dir.v[1] = 1;

    if(key.isKeyPressed(sf::Keyboard::P))
        my_fight->try_jump();

    bool sprint = key.isKeyPressed(sf::Keyboard::LShift);

    bool crouching = key.isKeyPressed(sf::Keyboard::LControl);

    my_fight->crouch_tick(crouching);

    if(crouching)
        sprint = false;

    if(sprint && walk_dir.v[0] < 0)
    {
        my_fight->queue_attack(attacks::SPRINT);
    }

    if(my_fight->cube_info)
        walk_dir = my_fight->cube_info->transform_move_dir_no_rot(walk_dir);

    my_fight->walk_dir(walk_dir, sprint);
}
Esempio n. 16
0
void fps_trombone_controls(fighter* my_fight, engine& window)
{
    trombone_manager& trombone = my_fight->trombone_manage;

    sf::Keyboard key;

    if(key.isKeyPressed(sf::Keyboard::F10))
        window.request_close();

    vec2f walk_dir = {0,0};

    if(key.isKeyPressed(sf::Keyboard::W))
        walk_dir.v[0] = -1;

    if(key.isKeyPressed(sf::Keyboard::S))
        walk_dir.v[0] = 1;

    if(key.isKeyPressed(sf::Keyboard::A))
        walk_dir.v[1] = -1;

    if(key.isKeyPressed(sf::Keyboard::D))
        walk_dir.v[1] = 1;

    bool crouching = key.isKeyPressed(sf::Keyboard::LControl);

    my_fight->crouch_tick(crouching);

    bool sprint = key.isKeyPressed(sf::Keyboard::LShift);

    if(crouching)
        sprint = false;

    if(my_fight->cube_info)
        walk_dir = my_fight->cube_info->transform_move_dir_no_rot(walk_dir);

    my_fight->walk_dir(walk_dir, sprint);

    my_fight->update_headbob_if_sprinting(sprint);

    if(once<sf::Mouse::Left>())
        trombone.play(my_fight);

    //if(once<sf::Keyboard::Z>())
    my_fight->queue_attack(attacks::TROMBONE);

    if(once<sf::Keyboard::Space>())
        my_fight->try_jump();

    ///this will probably break
    my_fight->set_look({-window.c_rot_keyboard_only.s[0], window.get_mouse_sens_adjusted_x() / 1.f, 0});


    vec2f m;
    m.v[0] = window.get_mouse_sens_adjusted_x();
    m.v[1] = window.get_mouse_sens_adjusted_y();

    float source_m_yaw = 0.0003839723;

    float yout = m.v[0] * source_m_yaw;

    ///ok, so this is essentially c_rot_keyboard_only
    ///ie local
    ///ie we give no f***s anymore because the mouse look scheme is fully consistent from local -> global
    ///ie we can ignore this, just apply the overall matrix rotation and offset to te position
    ///and etc
    my_fight->set_rot_diff({0, -yout, 0.f});

    trombone.set_active(true);
}
Esempio n. 17
0
void fps_controls(fighter* my_fight, engine& window)
{
    sf::Keyboard key;

    if(key.isKeyPressed(sf::Keyboard::F10))
        window.request_close();

    vec2f walk_dir = {0,0};

    if(key.isKeyPressed(sf::Keyboard::W))
        walk_dir.v[0] = -1;

    if(key.isKeyPressed(sf::Keyboard::S))
        walk_dir.v[0] = 1;

    if(key.isKeyPressed(sf::Keyboard::A))
        walk_dir.v[1] = -1;

    if(key.isKeyPressed(sf::Keyboard::D))
        walk_dir.v[1] = 1;

    bool crouching = key.isKeyPressed(sf::Keyboard::LControl);

    my_fight->crouch_tick(crouching);

    bool sprint = key.isKeyPressed(sf::Keyboard::LShift);

    if(crouching)
        sprint = false;

    if(my_fight->cube_info)
        walk_dir = my_fight->cube_info->transform_move_dir_no_rot(walk_dir);

    my_fight->walk_dir(walk_dir, sprint);

    my_fight->update_headbob_if_sprinting(sprint);

    if(sprint && walk_dir.v[0] < 0)
        my_fight->queue_attack(attacks::SPRINT);

    if(once<sf::Mouse::Left>())
        my_fight->queue_attack(attacks::SLASH);

    if(once<sf::Mouse::Middle>())
        my_fight->queue_attack(attacks::OVERHEAD);

    if(window.get_scrollwheel_delta() > 0.01)
        my_fight->queue_attack(attacks::STAB);

    if(once<sf::Mouse::Right>())
        my_fight->queue_attack(attacks::BLOCK);

    if(once<sf::Mouse::XButton1>())
        my_fight->queue_attack(attacks::SLASH_ALT);

    if(once<sf::Mouse::XButton2>())
        my_fight->queue_attack(attacks::OVERHEAD_ALT);

    if(once<sf::Keyboard::Z>())
        my_fight->queue_attack(attacks::TROMBONE);

    if(once<sf::Keyboard::Q>())
        my_fight->try_feint();

    if(once<sf::Keyboard::Space>())
        my_fight->try_jump();

    //window.c_rot.x = clamp(window.c_rot.x, -M_PI/2.f, M_PI/2.f);

    ///this will probably break
    my_fight->set_look({-window.c_rot_keyboard_only.s[0], window.get_mouse_sens_adjusted_x() / 1.f, 0});


    vec2f m;
    m.v[0] = window.get_mouse_sens_adjusted_x();
    m.v[1] = window.get_mouse_sens_adjusted_y();

    float source_m_yaw = 0.0003839723;

    float yout = m.v[0] * source_m_yaw;

    ///ok, so this is essentially c_rot_keyboard_only
    ///ie local
    ///ie we give no f***s anymore because the mouse look scheme is fully consistent from local -> global
    ///ie we can ignore this, just apply the overall matrix rotation and offset to te position
    ///and etc
    my_fight->set_rot_diff({0, -yout, 0.f});
}
Esempio n. 18
0
	game::actor_ref lua::to_actor(const engine & engine, index_t index) {
		return boost::dynamic_pointer_cast<game::actor>(
			engine.to_proxy(actor_class, index, actor_empty)
		);
	}
Esempio n. 19
0
	game::mark_ref lua::to_mark(const engine & engine, index_t index) {
		return engine.to_proxy(mark_class, index, mark_empty);
	}
Esempio n. 20
0
 T operator() (engine& eng) const
 {
     return (T)eng.uniform(min, max);
 }
Esempio n. 21
0
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	char const * class_name = "Pong";
	char const * window_title = "Adolf Hitler Pong";

	WNDCLASSEX window_class;
	window_class.cbSize = sizeof(window_class);
	window_class.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
	window_class.lpfnWndProc = &window_procedure;
	window_class.cbClsExtra = 0;
	window_class.cbWndExtra = 0;
	window_class.hInstance = hInstance;
	window_class.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_HITLER));
	window_class.hCursor = LoadCursor(0, IDC_ARROW);
	window_class.hbrBackground = reinterpret_cast<HBRUSH>(GetStockObject(WHITE_BRUSH));
	window_class.lpszMenuName = 0;
	window_class.lpszClassName = class_name;
	window_class.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_HITLER));
	RegisterClassEx(&window_class);

	HWND window_handle = CreateWindowEx(0, class_name, window_title, WS_POPUP | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, window_width, window_height, 0, 0, hInstance, 0);
	//SetTimer(window_handle, 0, 1000 / fps, 0);

	std::string arguments(lpCmdLine);
	if(!arguments.empty())
	{
		if(arguments[0] == '"' && arguments.length() >= 2)
		{
			arguments.erase(arguments.begin());
			arguments.erase(arguments.end() - 1);
		}
		bool success = game.load_demo(arguments);
		if(!success)
		{
			MessageBox(window_handle, "Unable to load demo file", "Demo playback error", MB_OK | MB_ICONERROR);
			SendMessage(window_handle, WM_DESTROY, 0, 0);
			return 0;
		}
	}
	else
		game.start_game();

	nil::ini ini;
	if(ini.load("pong.ini"))
	{
		game.set_demo_level_limit(ini.number<unsigned>("demo_level_limit", 3));
		SetThreadPriority(GetCurrentThread(), ini.number<int>("thread_priority", 0));
	}

	LARGE_INTEGER frequency_struct;
	QueryPerformanceFrequency(&frequency_struct);
	unsigned long long divisor = frequency_struct.QuadPart / fps;
	unsigned long long last_state = 0ull;
	while(run)
	{
		MSG message;
		while(PeekMessage(&message, window_handle, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&message);
			DispatchMessage(&message);
		}

		LARGE_INTEGER counter;
		QueryPerformanceCounter(&counter);
		unsigned long long current_state = counter.QuadPart / divisor;
		if(last_state < current_state)
		{
			game.invalidate(window_handle);
			game.process_frame(window_handle);
			last_state = current_state;
		}
		//Sleep(20);
	}

	return 0;
}
Esempio n. 22
0
    integrator_type integrator(const system& sys, const engine& eng) {
      return [&](const dof::velocity& v, math::real dt) { 
	eng.integrate(v, sys.mass * v, dt); 
      };
    }
Esempio n. 23
0
LRESULT CALLBACK window_procedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_CREATE:
		{
			game.create_dc(GetDC(hWnd));

			int
				resolution_x = GetSystemMetrics(SM_CXSCREEN),
				resolution_y = GetSystemMetrics(SM_CYSCREEN);
			RECT window_rectangle;
			GetWindowRect(hWnd, &window_rectangle);
			int
				width = window_rectangle.right - window_rectangle.left,
				height = window_rectangle.bottom - window_rectangle.top;

			SetWindowPos(hWnd, HWND_TOP, (resolution_x - width) / 2, (resolution_y - height) / 2, 0, 0, SWP_NOSIZE);
			break;
		}

		case WM_ERASEBKGND:
			return 1;

		case WM_PAINT:
			game.process_frame(hWnd);
			break;

		/*
		case WM_TIMER:
			game.invalidate(hWnd);
			break;

		case WM_ERASEBKGND:
			return 1;

		case WM_PAINT:
			try
			{
				game_mutex.lock();
				game.process_frame(hWnd);
				game_mutex.unlock();
			}
			catch(std::exception const & exception)
			{
				MessageBox(hWnd, (std::string("The following exception has occured:\n\n\t") + exception.what() + "\n\nTerminating program.").c_str(), "Exception", MB_OK | MB_ICONERROR);
				run_timer = false;
				PostQuitMessage(WM_QUIT);
			}
			break;
			*/

		case WM_CLOSE:
		case WM_DESTROY:
			run = false;
			PostQuitMessage(WM_QUIT);
			break;

		case WM_LBUTTONDOWN:
			return DefWindowProc(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);

		case WM_KEYDOWN:
			game.process_key_down(wParam);
			break;

		case WM_KEYUP:
			game.process_key_up(wParam);
			break;
	}

	return DefWindowProc(hWnd, msg, wParam, lParam);
}
Esempio n. 24
0
 T operator() (engine& eng, const int bound) const
 {
     return (T)eng.uniform(min, bound);
 }