Пример #1
0
void ParallelComposer::createCtx( ViewportPtr port)
{
#ifdef OSG_WITH_PARALLEL
    // get needed attributes from viewport
    PCint attribs[40];
    UInt32 i = 0;
    PCerr err;
    
    attribs[i++] = PC_FRAME_WIDTH;              attribs[i++] = _wWidth;
    attribs[i++] = PC_FRAME_HEIGHT;             attribs[i++] = _wHeight;
    attribs[i++] = PC_COMPOSITE_TYPE;           attribs[i++] = PC_COMP_DEPTH;
    attribs[i++] = PC_PIXEL_FORMAT;             attribs[i++] = PC_PF_BGRA8|PC_PF_Z32I;
    // maybe this will change?
    attribs[i++] = PC_OUTPUT_DEPTH;             attribs[i++] = 1;
    // maybe more, force depth? compression?
    attribs[i++] = PC_ATTRIB_END;
     
    if(isClient())
    {
        // we need a global context
        err = pcContextCreateGlobal(attribs, _serverList, _serviceAddr, &_context);
        if(err)
        {
            SLOG  << "Error creating global context" << std::endl;
        }
    }
    else
    {
        // create a local context
        err = pcContextCreateLocal(PC_ID_DEFAULT, _serviceAddr, &_context);
        if(err)
        {
            SLOG << "Error creating local context" << std::endl;
        }
    }
    
    if(isClient())
    {
        pcContextSetInteger(_context,PC_OUTPUT_LEFT,PC_LOCALHOST_INDEX,0);
        pcContextSetInteger(_context,PC_OUTPUT_TOP,PC_LOCALHOST_INDEX,0);
        pcContextSetInteger(_context,PC_OUTPUT_WIDTH,PC_LOCALHOST_INDEX,_wWidth);
        pcContextSetInteger(_context,PC_OUTPUT_HEIGHT,PC_LOCALHOST_INDEX,_wHeight);
    }
    
    if(_bufColor)
        delete [] _bufColor;
    _bufColor = new UInt8 [_wWidth * _wHeight * 4 * sizeof(GLubyte)];
     
    if(_bufDepth)
        delete [] _bufDepth;
    _bufDepth = new UInt8 [_wWidth * _wHeight  * sizeof(GLuint)];
#endif
}
Пример #2
0
/* Updates the viewNode approximating the current focusNode */
void zoom(int level) {
  while (level < 0) {
    if (viewNode -> parent) { 
      unmapNode(viewNode);
      viewNode = viewNode -> parent;
    } else { return; }
    placeNode(viewNode, rootX, rootY, rootWidth, rootHeight);
    focusNode(focusedNode, NULL, True, True);
    level++;
  }
  while (level > 0) {
    if (focusedNode == viewNode) return;
    Node *n = focusedNode;
    while (n && n -> parent != viewNode) n = n -> parent;
    if (!n) return;

    unmapNode(viewNode);
    viewNode = n;
    //TODO:: Need placeNode to be aware of focusnnode (in)active colors....
    
    fprintf(stderr, "placeing yo");
    placeNode(viewNode, rootX, rootY, rootWidth, rootHeight);
    if (focusedNode == viewNode && !isClient(focusedNode)) {
      focusNode(focusOrChildOf(focusedNode), NULL, True, True);
    }
    level--;
  }
}
Пример #3
0
void ParallelComposer::endFrame(UInt32 id)
{
#ifdef OSG_WITH_PARALLEL
    
    PCerr err;

    /* send the pixels */
    err = pcFrameAddFramelet(_context,id,_bufColor,_bufDepth);
    if(err)
    {
        SLOG << "Error adding framelet in endFrame" << std::endl;
    }
    //}
    
    /* done with the frame */
    err = pcFrameEnd(_context,id);
    if(err)
    {
        SLOG << "Error while calling pcFrameEnd" << std::endl;
    }
    if (isClient()) 
    {
        /* grab the results */
        err = pcFrameResult(_context,id,0,0,_wWidth,_wHeight,reinterpret_cast<void**>(&_bufRet),NULL,
                          &_rowPixels);
        if(err)
        {
            SLOG << "Error while getting frame results" << std::endl;
        }
    }

#endif
}
Пример #4
0
bool QtLocalPeer::sendMessage(const QString &message, int timeout)
{
    if (!isClient())
        return false;

    QLocalSocket socket;
    bool connOk = false;
    for (int i = 0; i < 2; i++) {
        // Try twice, in case the other instance is just starting up
        socket.connectToServer(socketName);
        connOk = socket.waitForConnected(timeout/2);
        if (connOk || i)
            break;
        int ms = 250;
#if defined(Q_OS_WIN)
        Sleep(DWORD(ms));
#else
        struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
        nanosleep(&ts, NULL);
#endif
    }
    if (!connOk)
        return false;

    QByteArray uMsg(message.toUtf8());
    QDataStream ds(&socket);
    ds.writeBytes(uMsg.constData(), uMsg.size());
    bool res = socket.waitForBytesWritten(timeout);
    res &= socket.waitForReadyRead(timeout);   // wait for ack
    res &= (socket.read(qstrlen(ack)) == ack);
    return res;
}
Пример #5
0
qint64 QtLocalPeer::getRunningPid() {
  if (!isClient())
      return 0;

  QLocalSocket socket;
  bool connOk = false;
  for (int i = 0; i < 2; i++) {
      // Try twice, in case the other instance is just starting up
      socket.connectToServer(socketName);
      connOk = socket.waitForConnected(5000/2);
      if (connOk || i)
          break;
      Sleep(250);
  }
  if (!connOk) return -1;

  const char* msg = "qbt://pid";
  QDataStream ds(&socket);
  ds.writeBytes(msg, qstrlen(msg));
  bool res = socket.waitForBytesWritten(5000) && socket.waitForReadyRead(5000);
  if (!res) return -1;

  DWORD pid;
  qint64 pid_size = sizeof pid;
  while (socket.bytesAvailable() < pid_size)
      socket.waitForReadyRead();
  if (socket.read((char *)&pid, pid_size) < pid_size)
      return -1;

  return pid;
}
void PipelineComposer::close(void)
{
    if(!isClient() && _writer)
    {
        _lock->acquire();
        _queue.push_back(NULL);
        if(_waiting)
        {
            _lock   ->release( );
            _barrier->enter  (2);
        }
        else
        {
            _lock->release();
        }
        BaseThread::join(_writer);

        _writer          = NULL;
        _composer        = NULL;
        _barrier         = NULL;
        _composeBarrier  = NULL;
        _frameEndBarrier = NULL;
        _lock            = NULL;        
    }
}
Пример #7
0
/*!
 * Disconnects from the server. The QIODevice is deleted. Use takeDevice() to disconnect from the server without
 * deleting the device.
 *
 * If not connected to a server, for instance if acting as a server, this function is ignored with a warning.
 * \sa device()
 * \sa takeDevice()
 */
void QxtRPCService::disconnectServer()
{
    if(!isClient()) {
        qWarning() << "QxtRPCService::disconnectServer: not connected to a server";
        return;
    }
    takeDevice()->deleteLater();
}
Пример #8
0
void absorb(char * argA, char * argB) {
  /* Absorbs the given node into the container of the focused node 
   * If the focused node is a client, containerize will be called then absorb
   * */
  if (!focusedNode) return;

  if (isClient(focusedNode)) containerize();

}
Пример #9
0
void BinarySwapComposer::close(void)
{
    if(!isClient() && _writer)
    {
        _stopWriter = true;
        _barrier->enter(2);
        BaseThread::join(_writer);
        _writer = NULL;
    }
}
Пример #10
0
/*!
 * Disconnects all clients, or disconnects from the server.
 */
void QxtRPCService::disconnectAll()
{
    if(isClient()) 
        disconnectServer();

    if(isServer()) {
        QList<quint64> clientIDs = clients();
        foreach(quint64 id, clientIDs) {
            // Disconnect from each client in turn.
            disconnectClient(id);
        }
    }
Пример #11
0
ACSIClient *findClient(ACSIClient *client_list, char ip[48], int port) {
	ACSIClient *client = client_list;

	while (client != NULL) {
		if (isClient(client, ip, port)) {
			return client;
		}

		client = client->next;
	}

	return NULL;
}
Пример #12
0
void NetworkManager::update()
{
	if (!isActive()) return;
	
	if (GameState::instance()->isRunning()) {
		broadcastHeartbeat();
	}

	if (isServer()) {
		server->update();
	} else if (isClient()) {
		client->update();
	}
}
Пример #13
0
void NetwalkWindow::checkFlow()
{
  for( int y = 0; y < pSizeY; y++ ){
    for( int x = 0; x < pSizeX; x++ ){
      int t = mapView.tiles(x,y).objectImage(0);
      if ( isClient(x,y) )
        mapView.tiles(x,y).objectImage(1) = 29;
      if ( t > 13 ) {
        mapView.tiles(x,y).objectImage(0) = t - 14;
      }
    }
  }
  traceFlow( pServX, pServY, -1, true );
}
Пример #14
0
void ParallelComposer::drawFrame(void)
{
#ifdef OSG_WITH_PARALLEL
   if (isClient()) 
   {
       if (!_bufRet) return;
       glDisable(GL_DEPTH_TEST);
       glPixelStorei(GL_UNPACK_ROW_LENGTH,_rowPixels);
       glDrawPixels(_wWidth,_wHeight,GL_BGRA,GL_UNSIGNED_BYTE,_bufRet);
       glEnable(GL_DEPTH_TEST);
       // swap buffers?
       _bufRet = NULL;
   }
#endif
}
Пример #15
0
void PipelineComposer::close(void)
{
    if(!isClient() && _writer)
    {
        _lock->aquire();
        _queue.push_back(NULL);
        if(_waiting)
        {
            _waiting = false;
            _barrier->enter(2);
        }
        _lock->release();
        BaseThread::join(_writer);
    }
}
Пример #16
0
void jump(char * markName) {
  fprintf(stderr, "Finding a node");

  Mark *n = NULL;
  for(n = markTail; n; n = n -> previous) {
    if (!strcmp(n -> name, markName)) {
      fprintf(stderr, "Going to focus mark %p", n -> node);
      unmapNode(viewNode);
      viewNode = n -> node;
      placeNode(n -> node, rootX, rootY, rootWidth, rootHeight);
      focusNode(n -> node, NULL, True, True);
      while (!isClient(focusedNode)) focus("pc", "1");
    }
  }
}
void PipelineComposer::startViewport(Viewport *)
{
    if(getPipelined())
    {
        if(!isClient()) 
        {
            _composeBarrier->enter(2);
        }
        else
        {
            // transfer tile size
            _composeTilesX  = _readTilesX;
            _composeTilesY  = _readTilesY;
        }
    }
}
Пример #18
0
void layout(char * l) {
  fprintf(stderr, "Setting layout to: %s", l);

  Node *setNode = isClient(focusedNode) ?  focusedNode -> parent : focusedNode;
  int newLayout = 0;

  if      (!strcmp(l, "vertical"))   newLayout = VERTICAL;
  else if (!strcmp(l, "horizontal")) newLayout = HORIZONTAL;
  else if (!strcmp(l, "grid"))       newLayout = GRID;
  else if (!strcmp(l, "max"))        newLayout = MAX;
  else if (!strcmp(l, "float"))      newLayout = FLOAT;


  setNode -> layout = newLayout;
  rePlaceNode(setNode);
}
Пример #19
0
// In Nexus, we'll add 20 seconds, and permanently open the Nexus
void NexusGameType::onOvertimeStarted()
{
    mEndingGamePlay += TWENTY_SECONDS;
    openNexus(0);

    // And release a text effect to notify players
    if(isClient())
    {
        // The 750 ms delay of the second TextEffect makes a nice two-tiered effect
        string msg = isOvertime() ? "MORE OVERTIME!" : "OVERTIME!";
        getGame()->emitTextEffect(msg, Colors::red, Point(0,0), false);
        getGame()->emitDelayedTextEffect(750,  "+20 SECONDS", Colors::red, Point(0,0), false);
        getGame()->emitDelayedTextEffect(1500, "NEXUS IS OPEN!", Colors::red, Point(0,0), false);

        // TODO: Need a SFX here
    }
}
Пример #20
0
bool Host::dispatchEvent(TargetID sourceID, PacketData& data)
{
  const ObjectID recipientID = data.read16();
  const EventID eventID = data.read8();

  Object* object = findObject(recipientID);
  if (!object)
  {
    if (isClient() || m_objectIDs.bucketOf(recipientID) == ID_BUCKET_UNUSED)
      logError("Failed to find recipient object %u", recipientID);

    return false;
  }

  object->receiveEvent(sourceID, data, eventID);
  return true;
}
Пример #21
0
void containerize(void) {
  if (!focusedNode) return;
  if (focusedNode -> parent && focusedNode -> parent -> child && !isClient(focusedNode -> parent))
    if (isOnlyChild(focusedNode)) return;

  Node *insertNode, *newContainer = allocateNode(); int insertPosition;
  if (focusedNode -> parent && focusedNode -> parent -> focus == focusedNode)
    focusedNode -> parent -> focus = newContainer;

  if (focusedNode -> previous) {
    insertNode = focusedNode -> previous; insertPosition = NEXT;
  } else {
    insertNode = focusedNode -> next; insertPosition = PREVIOUS;
  }

  parentNode(focusedNode, newContainer);
  brotherNode(newContainer, insertNode, insertPosition);
  placeNode(viewNode, rootX, rootY, rootWidth, rootHeight);
}
Пример #22
0
void
ReliSock::exit_reverse_connecting_state(ReliSock *sock)
{
	ASSERT( _state == sock_reverse_connect_pending );
	_state = sock_virgin;

	if( sock ) {
		int assign_rc = assign(sock->get_file_desc());
		ASSERT( assign_rc );
		isClient(true);
		if( sock->_state == sock_connect ) {
			enter_connected_state("REVERSE CONNECT");
		}
		else {
			_state = sock->_state;
		}
		sock->_sock = INVALID_SOCKET;
		sock->close();
	}
	m_ccb_client = NULL;
}
Пример #23
0
void kill(void) {
  fprintf(stderr, "Destroying Client %p\n", focusedNode);

  if (isClient(focusedNode)) {

    /* Save closest client and destroy node */
    Node *newFocus = getClosestClient(focusedNode);

    if (focusedNode == viewNode) viewNode = viewNode -> parent;

    if ( isOnlyChild(focusedNode) && focusedNode -> parent) {
      viewNode = focusedNode -> parent -> parent ?
        focusedNode -> parent -> parent : focusedNode -> parent;
    }

    Node *oldFocus = focusedNode;
    focusNode(newFocus, NULL, True, True);
    destroyNode(oldFocus);

    rePlaceNode(viewNode);
  }
}
Пример #24
0
void NetwalkWindow::traceFlow( const int x, const int y, const int dir, const bool enable )
{
  if ( (x < 0) || ( x >= pSizeX) ) return;
  if ( (y < 0) || ( y >= pSizeY) ) return;

  if ( dir != -1 )
    if ( !hasDir( x, y, (dir + 2) % 4) ) return;

  int t = mapView.tiles(x,y).objectImage(0);
  if ( (enable) && ( t != -1 ) && ( t < 14) ) {
    mapView.tiles(x,y).objectImage(0) = t + 14;
    if ( isClient(x,y) ) {
      mapView.tiles(x,y).objectImage(1) = 30;
      pCliConn++;
    }
  } else if ( (enable) && ( t > 14 ) ) {
    return;
  } else if ( (!enable) && ( t > 14 ) ) {
    mapView.tiles(x,y).objectImage(0) = t - 14;
  } else if ( (!enable) && ( t != -1 ) && ( t < 14) ) {
    return;
  }


  if ( (dir != 2 ) && (hasDir(x,y,0)) ) { // Try Up
    traceFlow( x, y-1, 0, enable );
  }
  if ( (dir != 3) && (hasDir(x,y,1)) ) { // Try Right
    traceFlow( x+1, y, 1, enable );
  }
  if ( (dir != 0) && (hasDir(x,y,2)) ) { // Try Down
    traceFlow( x, y+1, 2, enable );
  }
  if ( (dir != 1) && (hasDir(x,y,3)) ) { // Try Left
    traceFlow( x-1, y, 3, enable );
  }

}
Пример #25
0
int* authentification (int desClient, int* nb_client, client_t listeClientsEntreprise[])
{
	int reception(-1);
	int* infos_client(NULL);	
	Client temp_client;
  
  cout << "Attente login client... "<< endl;
	reception = recv(desClient,temp_client.message,sizeof(temp_client.message),0);
	if(reception == -1)
		perror("Erreur réception recv authentification()");
	else 
	{
		cout << "login : "******"Status client : "<< infos_client[0] << endl;
	  send(desClient,&infos_client[0],sizeof(int),0);
	} // End if(reception > 0)
	
return infos_client;
}
Пример #26
0
	void Turret::fireProjectile(const FBox &target_box, const Weapon &weapon, float randomness) {
		if(isClient())
			return;

		Segment best_ray = computeBestShootingRay(target_box, weapon);

		if(randomness > 0.0f) {
			float3 dir = perturbVector(best_ray.dir(), random(), random(), randomness);
			best_ray = Ray(best_ray.origin(), dir);
		}

#ifdef DEBUG_SHOOTING
		{
			m_aiming_lines.clear();
			m_aiming_lines.push_back(best_ray.origin());
			Intersection isect = trace(best_ray, {Flags::all | Flags::colliding, ref()});
			m_aiming_lines.push_back(best_ray.origin() + best_ray.dir() * isect.distance());
		}
#endif

		//TODO: spawned projectiles should be centered
		if( const ProjectileProto *proj_proto = weapon.projectileProto() )
			addNewEntity<Projectile>(best_ray.origin(), *proj_proto, actualDirAngle(), best_ray.dir(), ref(), weapon.proto().damage_mod);
	}
Пример #27
0
void ParallelComposer::composeViewport(ViewportPtr port)
{
#ifdef OSG_WITH_PARALLEL
    // setup viewport
    GLint 
        pl=port->getPixelLeft(), 
        pr=port->getPixelRight(),
        pb=port->getPixelBottom(), 
        pt=port->getPixelTop();
    if(_wWidth != pr-pl+1 || _wHeight != pt-pb+1)
    {
        _wWidth = pr-pl+1;
        _wHeight= pt-pb+1;
        _createContext = true;
    }
    bool full = port->isFullWindow();
    glViewport(pl, pb, _wWidth, _wHeight);
    glScissor(pl, pb, _wWidth, _wHeight);
    if(! full)
        glEnable(GL_SCISSOR_TEST);

    GLboolean depth = glIsEnabled(GL_DEPTH_TEST);
    GLboolean blend = glIsEnabled(GL_BLEND);

    glDisable(GL_DEPTH_TEST);
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, port->getPixelWidth(),
            0, port->getPixelHeight(),-1,1);

    if(_createContext)
    {
        createCtx(port);
        _createContext = false;
    }

    if(getAlpha())
    {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }

    if(isClient())
    {
        UInt32 id = beginFrame();
        renderRead();
        endFrame(id);
        drawFrame();
    }
    else
    {
        if(clusterId() < _usableServers)
        {
            UInt32 id = beginFrame();
            renderRead();
            endFrame(id);
            //drawFrame();
        }
    }
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glEnable(GL_DEPTH_TEST);

    // reset state
    if(depth && !glIsEnabled(GL_DEPTH_TEST))
        glEnable(GL_DEPTH_TEST);
    if(!blend && glIsEnabled(GL_BLEND))
        glDisable(GL_BLEND);
#endif
}
Пример #28
0
void BinarySwapComposer::composeViewport(ViewportPtr port)
{
    // setup viewport
    GLint 
        pl=port->getPixelLeft(), 
        pr=port->getPixelRight(),
        pb=port->getPixelBottom(), 
        pt=port->getPixelTop();
    GLint pw=pr-pl+1,ph=pt-pb+1;
    bool full = port->isFullWindow();
    glViewport(pl, pb, pw, ph);
    glScissor(pl, pb, pw, ph);
    if(! full)
        glEnable(GL_SCISSOR_TEST);

    GLboolean depth = glIsEnabled(GL_DEPTH_TEST);
    GLboolean blend = glIsEnabled(GL_BLEND);

    glDisable(GL_DEPTH_TEST);
    glPushMatrix();
    glLoadIdentity();
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0, port->getPixelWidth(),
            0, port->getPixelHeight(),-1,1);

//    printf("max %x,%x\n",_intDepthMax,_shortDepthMax);

    if(getAlpha())
    {
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    }
    _tilesX = port->getPixelWidth()  / getTileSize() + 1;
    _tilesY = port->getPixelHeight() / getTileSize() + 1;

    _tileBufferSize = getTileSize()*getTileSize()*8+sizeof(TileBuffer);
    _readTile.resize(_tileBufferSize);

    _statistics.bytesIn  = 0;
    _statistics.bytesOut = 0;

    if(isClient())
    {
        if(getShort())
        {
            UInt16 colorDummy;
            UInt32 depthDummy;
            recvFromServers(depthDummy,colorDummy,
                            GL_RGB,
                            GL_UNSIGNED_SHORT_5_6_5,
                            port);
        }
        else
        {
            if(getAlpha())
            {
                UInt32 colorDummy;
                UInt32 depthDummy;
                recvFromServers(depthDummy,colorDummy,
                                GL_RGBA,
                                GL_UNSIGNED_BYTE,
                                port);
            }
            else
            {
                RGBValue colorDummy;
                UInt32   depthDummy;
                recvFromServers(depthDummy,colorDummy,
                                GL_RGB,
                                GL_UNSIGNED_BYTE,
                                port);
            }
        }
        if(getStatistics())
        {
            UInt32      maxIn   = _statistics.bytesIn;
            UInt32      maxOut  = _statistics.bytesOut;
            UInt32      maxIO   = maxIn + maxOut;
            UInt32      sumOut  = _statistics.bytesOut;
            UInt32      missing = _usableServers;
            double      composeTime = 1e32;
            
            Connection *server;
            Statistics  statistics;
            for(UInt32 i=0 ; i<_usableServers ;++i)
            {
                server = clusterWindow()->getNetwork()->getConnection(i);
                server->selectChannel();
                server->get(&statistics,sizeof(Statistics));
                sumOut += statistics.bytesOut;
                if(statistics.composeTime < composeTime)
                    composeTime = statistics.composeTime;
                if(statistics.bytesOut > maxOut)
                    maxOut = statistics.bytesOut;
                if(statistics.bytesIn > maxIn)
                    maxIn = statistics.bytesIn;
                if(statistics.bytesIn + statistics.bytesOut > maxIO)
                    maxIO = statistics.bytesIn + statistics.bytesOut;
                missing--;
            }
            printf("compose Time     : %1.5lf\n",composeTime);
            printf("Transfered bytes : %10d\n",sumOut);
            printf("Max out          : %10d\n",maxOut);
            printf("Max in           : %10d\n",maxIn);
            printf("Max io           : %10d\n",maxIO);
        }
    }
    else
    {
        if(clusterId() < _usableServers)
        {
            _statistics.composeTime = -getSystemTime();
            _tile.resize(_tileBufferSize * _tilesX * _tilesY);
            if(getShort())
            {
                UInt16 colorDummy;
                UInt32 depthDummy=_shortDepthMax;
//                UInt32 depthDummy=_intDepthMax;
                startReader(depthDummy,colorDummy,
//                            GL_UNSIGNED_SHORT,
                            GL_UNSIGNED_INT,
                            GL_RGB,
                            GL_UNSIGNED_SHORT_5_6_5,
                            port);
            }
            else
            {
                if(getAlpha())
                {
                    UInt32 colorDummy;
                    UInt32 depthDummy=_intDepthMax;
                    startReader(depthDummy,colorDummy,
                                GL_UNSIGNED_INT,
                                GL_RGBA,
                                GL_UNSIGNED_BYTE,
                                port);
                }
                else
                {
                    RGBValue colorDummy;
                    UInt32   depthDummy=_intDepthMax;
                    startReader(depthDummy,colorDummy,
                                GL_UNSIGNED_INT,
                                GL_RGB,
                                GL_UNSIGNED_BYTE,
                                port);
                }
            }
            _statistics.composeTime += getSystemTime();
            if(getStatistics())
            {
                Connection *client = clusterWindow()->getNetwork()->getConnection(serverCount());
                client->put(&_statistics,sizeof(Statistics));
                client->flush();
            }
        }
/*
        // max depth value !! find a better way
        glClear(GL_DEPTH_BUFFER_BIT);
        glReadPixels(0, 0, 1, 1, 
                     GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,
                     &_intDepthMax);
        glReadPixels(0, 0, 1, 1, 
                     GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT,
                     &_shortDepthMax);
*/
    }

    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    glEnable(GL_DEPTH_TEST);

    // reset state
    if(depth && !glIsEnabled(GL_DEPTH_TEST))
        glEnable(GL_DEPTH_TEST);
    if(!blend && glIsEnabled(GL_BLEND))
        glDisable(GL_BLEND);
}
Пример #29
0
bool ProtocolTCP::initbase()
{
	int optval = 1;
        char buf[SOCKADDR_SIZE];
        struct sockaddr *local_addr = (struct sockaddr *)buf;
        socklen_t addrlen = 0;
        int af = AF_INET;
        unsigned short port = isClient() ? 0 : localport;
	char ip_str[50];
	
        if (!localIface) {
		HAGGLE_ERR("Local interface is NULL\n");
                return false;
        }

	// Check if we are already connected, i.e., we are a client
	// that was created from acceptClient()
	if (isConnected()) {
		// Nothing to initialize
		return true;
	}
        // Figure out the address type based on the local interface
#if defined(ENABLE_IPv6)
	if (localIface->getAddress<IPv6Address>() && peerIface && peerIface->getAddress<IPv6Address>())
                af = AF_INET6;
#endif

        /* Configure a sockaddr for binding to the given port. Do not
         * bind to a specific interface. */
        if (af == AF_INET) {
                struct sockaddr_in *sa = (struct sockaddr_in *)local_addr;
                sa->sin_family = AF_INET;
                sa->sin_addr.s_addr = htonl(INADDR_ANY);
                sa->sin_port = htons(port);
                addrlen = sizeof(struct sockaddr_in);
        }
#if defined(ENABLE_IPv6)
        else if (af == AF_INET6) {
                struct sockaddr_in6 *sa = (struct sockaddr_in6 *)local_addr;
                sa->sin6_family = AF_INET6;
                sa->sin6_len = SOCKADDR_SIZE;
                sa->sin6_addr = in6addr_any;
                sa->sin6_port = htons(port);
                addrlen = sizeof(struct sockaddr_in6);
        }
#endif

	if (!openSocket(local_addr->sa_family, SOCK_STREAM, IPPROTO_TCP, isServer())) {
		HAGGLE_ERR("Could not create TCP socket\n");
                return false;
	}

	if (!setSocketOption(SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval))) {
		closeSocket();
		HAGGLE_ERR("setsockopt SO_REUSEADDR failed\n");
                return false;
	}

	if (!setSocketOption(SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval))) {
		closeSocket();
		HAGGLE_ERR("setsockopt SO_KEEPALIVE failed\n");
                return false;
	}

	if (!bind(local_addr, addrlen)) {
		closeSocket();
		HAGGLE_ERR("Could not bind TCP socket\n");
                return false;
        }
	if (inet_ntop(af, &((struct sockaddr_in *)local_addr)->sin_addr, ip_str, sizeof(ip_str))) {
		HAGGLE_DBG("%s Created %s TCP socket - %s:%d\n", 
			   getName(), af == AF_INET ? "AF_INET" : "AF_INET6", ip_str, port);
	}
	return true;
}
Пример #30
0
/*
	TPlayer: Prop-Manipulation
*/
CString TPlayer::getProp(int pPropId)
{
	// TODO: is there a reason for this?  Check serveroptions.
	CSettings* settings = server->getSettings();
	switch (pPropId)
	{
		case PLPROP_NICKNAME:
		return CString() >> (char)nickName.length() << nickName;

		case PLPROP_MAXPOWER:
		return CString() >> (char)maxPower;

		case PLPROP_CURPOWER:
		return CString() >> (char)(power * 2);

		case PLPROP_RUPEESCOUNT:
		return CString() >> (int)gralatc;

		case PLPROP_ARROWSCOUNT:
		return CString() >> (char)arrowc;

		case PLPROP_BOMBSCOUNT:
		return CString() >> (char)bombc;

		case PLPROP_GLOVEPOWER:
		return CString() >> (char)glovePower;

		case PLPROP_BOMBPOWER:
		return CString() >> (char)bombPower;

		case PLPROP_SWORDPOWER:
		return CString() >> (char)(swordPower+30) >> (char)swordImg.length() << swordImg;

		case PLPROP_SHIELDPOWER:
		return CString() >> (char)(shieldPower+10) >> (char)shieldImg.length() << shieldImg;

		case PLPROP_GANI:
		if (versionID < CLVER_2)
			return bowImage;
		return CString() >> (char)gani.length() << gani;

		case PLPROP_HEADGIF:
		return CString() >> (char)(headImg.length()+100) << headImg;

		case PLPROP_CURCHAT:
		return CString() >> (char)chatMsg.length() << chatMsg;

		case PLPROP_COLORS:
		return CString() >> (char)colors[0] >> (char)colors[1] >> (char)colors[2] >> (char)colors[3] >> (char)colors[4];

		case PLPROP_ID:
		return CString() >> (short)id;

		case PLPROP_X:
		return CString() >> (char)(x * 2);

		case PLPROP_Y:
		return CString() >> (char)(y * 2);

		case PLPROP_Z:
		return CString() >> (char)(((z + 25) * 2)/* + 50*/);

		case PLPROP_SPRITE:
		return CString() >> (char)sprite;

		case PLPROP_STATUS:
		return CString() >> (char)status;

		case PLPROP_CARRYSPRITE:
		return CString() >> (char)carrySprite;

		case PLPROP_CURLEVEL:
		if (isClient() || type == PLTYPE_AWAIT)
		{
			if (pmap && pmap->getType() == MAPTYPE_GMAP)
				return CString() >> (char)pmap->getMapName().length() << pmap->getMapName();
			else
				return CString() >> (char)levelName.length() << levelName;
		}
		else
			return CString() >> (char)1 << " ";