Exemple #1
0
 chips_state get_chips_state(level const & l)
 {
     entity const & chip = l.chip;
     auto const & el = l.entity_list;
     
     if (not chip) {
         chips_state const *opt_st = chip.get_raw<chips_state>();
         if (opt_st) return *opt_st;
         return chips_state::normal;
     }
     
     ELIB_ASSERT(!chip.has<chips_state>());
     
     if (OnWater(chip).contains(el)) {
         return chips_state::swimming;
     }
   
     return chips_state::normal;
 }
Exemple #2
0
 AtEntity(entity const & e)
 {
     ELIB_ASSERT(e.has<position>());
     m_pos = e.get<position>();
 }
Exemple #3
0
  Message receive(
      web::socket const & s
    , std::chrono::seconds timeout_in
  )
  {
      static_assert(
          elib::aux::is_same<Message, request>::value
          || elib::aux::is_same<Message, response>::value
        , "The only two choices"
      );
      
      Message msg;
      data_type buff(10024);
      data_type remaining;
      
      
      
      const auto timeout_at = std::chrono::system_clock::now() + timeout_in;
                       
      auto timeout_receive = 
          [&]()
          {
              std::error_code ec;
              while (std::chrono::system_clock::now() < timeout_at)
              {
                  ec.clear();
                  ::ssize_t ret = web::receive(s, buff, ec);
                  if (ec.value() == EAGAIN || ec.value() == EWOULDBLOCK)
                      continue;
                  if (ec)
                  {
                      ELIB_THROW_EXCEPTION(socket_error(
                          elib::fmt(
                              "http::receive failed with error %s"
                            , ec.message()
                          )
                        , ec
                      ));
                  }
                  ELIB_ASSERT(ret >= 0);
                  std::copy_n(
                      buff.begin()
                    , static_cast<std::size_t>(ret)
                    , std::back_inserter(remaining)
                  );
             
                  return ret;
              }
              
              ELIB_THROW_EXCEPTION(web_error(
                  "http::receive timed out"
              ));
          };
         
      // get header
 
      while (true)
      {
          timeout_receive();
  
          auto pos = parse(remaining.begin(), remaining.end(), msg.header);
          
          if (pos == remaining.begin()) continue;
          
          remaining.erase(remaining.begin(), pos);
          break;
      }
      // get fields and newline
      while (true)
      {
          auto field_end = parse(remaining.begin(), remaining.end(), msg.fields);
          remaining.erase(remaining.begin(), field_end);
          
          auto newl_end = parse_newl(remaining.begin(), remaining.end());
          
          bool have_newl = newl_end != remaining.begin();
          
          remaining.erase(remaining.begin(), newl_end);
          
          if (have_newl) break;
              
          // receive must only happen if we fail to parse till the 
          // newline break. othewise we could be waiting on a message
          // we already have
          timeout_receive();
      }
      
     
      std::size_t const con_size = content_size(msg);
      ELIB_ASSERT(con_size >= remaining.size());
      
      // get remaining data if needed 
      while (remaining.size() != con_size)
      {
          timeout_receive();                
      }
      
      msg.data.insert(msg.data.end(), remaining.begin(), remaining.end());
      
      return msg;
  }
Exemple #4
0
 resource_manager::resource_manager(const char *tileset_name)
 {
     ELIB_ASSERT(tileset_name);
     init_tileset(tileset_name);
     init_scoreboard(tileset_name);
 }