当前位置: 首页>>代码示例>>C++>>正文


C++ Net::addUnit方法代码示例

本文整理汇总了C++中Net::addUnit方法的典型用法代码示例。如果您正苦于以下问题:C++ Net::addUnit方法的具体用法?C++ Net::addUnit怎么用?C++ Net::addUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Net的用法示例。


在下文中一共展示了Net::addUnit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sendFilename

void Picturecontrol::sendFilename(int cid, int myId, int pid, Net &net, Client &client)
{
  // boundary checks for from and to already done in net.cpp
  // pid is checked against piclen but not against files

  if (pid > -1 && pid < (int) files.size()) {
    *out << VERBOSE_QUIET << "sending filename...\n";

    Unit unit;

    unit.picfetch.flag = UNIT_PICFETCH;
    unit.picfetch.from = myId;
    unit.picfetch.to = cid;
    unit.picfetch.pid = pid;

    // don't get rid of path cos when client requests file I need to know where it is!
    /*std::string name;
    size_t found = files[pid].find_last_of('/');
    if (found != std::string::npos) name = files[pid].substr(found+1);
    else name = files[pid];*/

    if (files[pid].size() > MAX_FILENAME_SIZE - 1) {
      *out << VERBOSE_LOUD << "Filename too long: " << files[pid] << '\n';
    }else{

      std::strncpy(unit.picfetch.filename, files[pid].c_str(), MAX_FILENAME_SIZE);
      net.addUnit(unit, client);
    }
  }else{
    *out << VERBOSE_LOUD << "Error, pid out of range for files.size: " << (int) files.size() << '\n';
  }
}
开发者ID:drtrev,项目名称:geo,代码行数:32,代码来源:picturecontrol.cpp

示例2: fetch

void Picturecontrol::fetch(int myId, Net &net, Client &client)
{
  // deal with fetching
  Unit unit;

  for (int c = 0; c < MAX_CLIENTS; c++) {
    for (int i = 0; i < piclen[c]; i++) {
      // if not active then fetch them
      if (!pic[c][i].getActive() && !pic[c][i].getRequested()) {
        pic[c][i].setRequested(true);
        unit.picfetch.flag = UNIT_PICFETCH;
        unit.picfetch.from = myId;
        unit.picfetch.to = c;
        unit.picfetch.pid = i;
        unit.picfetch.filename[0] = '\0';
        net.addUnit(unit, client);
        *out << VERBOSE_QUIET << "Requesting picture: " << unit.picfetch.pid << '\n';
      }
    }
  }
}
开发者ID:drtrev,项目名称:geo,代码行数:21,代码来源:picturecontrol.cpp

示例3: load

void Picturecontrol::load(int myId, Net &net, Client &client)
// if we are given a path, then load and transmit which pics are active
// if path is an empty string then we expect either pictures aren't being used or we're receving them
{
  if (readPath != "") {
    *out << VERBOSE_LOUD << "Loading pics...\n";
    files = dir.getPics(readPath);

    // error checks done in allocate, but left to segfault below!
    // (error messages from allocate() should help track down problem!)
    allocate(myId, files.size()); // this also calls incrementLoaded

    for (int i = 0; i < piclen[myId]; i++) {
      pic[myId][i].load(readPath+files[i]);
      pic[myId][i].setActive(true);
    }

    *out << VERBOSE_LOUD << "Loaded\n";

    // tell server number of pics
    Unit unit;

    unit.picalloc.flag = UNIT_PICALLOC;
    unit.picalloc.id = myId;
    unit.picalloc.total = piclen[myId];
    net.addUnit(unit, client);

    // set to plausible picnum and transmit picselect,
    // note that client who has pictures may not be client 0
    if (picnum > piclen[clientnum] - 1) {

      bool found = false;

      for (int c = clientnum + 1; c < MAX_CLIENTS; c++) {
        if (piclen[c] > 0) {
          clientnum = c;
          found = true;
          break;
        }
      }

      if (!found) {
        for (int c = 0; c < clientnum; c++) {
          if (piclen[c] > 0) {
            clientnum = c;
            found = true;
            break;
          }
        }
      }

      if (!found) *out << VERBOSE_LOUD << "Error: not found any plausible clientnum in Picturecontrol::load()\n";

      picnum = 0;
    }

    // transmit picnum
    unit.picselect.flag = UNIT_PICSELECT;
    unit.picselect.clientnum = clientnum;
    unit.picselect.picnum = picnum;
    unit.picselect.direction = 1;

    net.addUnit(unit, client);
    // this transmission will bounce back and setPicnum will be called to set up positions
    //setPicnum(clientnum, picnum); // sets up positions

    *out << VERBOSE_LOUD << "Picselect clientnum: " << unit.picselect.clientnum << ", picnum: " << unit.picselect.picnum
    << ", direction: " << unit.picselect.direction << '\n';
  }
}
开发者ID:drtrev,项目名称:geo,代码行数:70,代码来源:picturecontrol.cpp


注:本文中的Net::addUnit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。