int SpdyStream::sendData(IOVec *pIov, int total) { char achHeader[8]; int ret; buildDataFrameHeader(achHeader, total); m_pSpdyConn->getBuf()->append(achHeader, 8); ret = m_pSpdyConn->cacheWritev(*pIov, total); LS_DBG_L(this, "SpdyStream::sendData(), total: %d, ret: %d", total, ret); if (ret == -1) { setFlag(HIO_FLAG_ABORT, 1); return LS_FAIL; } setActiveTime(DateTime::s_curTime); bytesSent(total); m_pSpdyConn->dataFrameSent(total); if (isFlowCtrl()) { m_iWindowOut -= total; if (m_iWindowOut <= 0) setFlag(HIO_FLAG_BUFF_FULL, 1); } return total; }
void WindowMission::onUpdate( float t ) { NodeWindow::onUpdate( t ); if ( visible() ) { if ( activeTime() > UPDATE_MISSION_WINDOW ) { setActiveTime( 0 ); } } }
//***int SpdyStream::read( char * buf, int len )***// // return > 0: number of bytes of that has been read // return = 0: 0 byte of data has been read, but there will be more data coming, // need to read again // return = -1: EOF (End of File) There is no more data need to be read, the // stream can be removed int SpdyStream::read(char *buf, int len) { int ReadCount; if (getState() == HIOS_DISCONNECTED) return LS_FAIL; ReadCount = m_bufIn.moveTo(buf, len); if (ReadCount == 0) { if (getFlag(HIO_FLAG_PEER_SHUTDOWN)) { return LS_FAIL; //EOF (End of File) There is no more data need to be read } } if (ReadCount > 0) setActiveTime(DateTime::s_curTime); return ReadCount; }
void TextMission::onUpdate( float t ) { WindowText::onUpdate( t ); if ( visible() ) { if ( activeTime() > UPDATE_MISSION_TEXT ) { GameDocument * pDoc = WidgetCast<GameDocument>( document() ); ASSERT( pDoc ); NounShip * pShip = pDoc->ship(); if (! pShip ) return; static char * ORDER_DESC[] = { "NO ORDER %s", // NOORDER "Engage %s and destroy.", // ATTACK "Defend %s from attack by enemy ships.", // DEFEND "Capture %s.", // CAPTURE "Proceed to %s.", // MOVE "Reload and repair %s.", // RELOAD "Attach beacon to %s.", // BEACON "Hold current position %s.", // HOLD "Trade %s", // TRADE "Recon enemy positions at %s.", // RECON "Build structures on %s.", // BUILD "Fallback and repair at %s." // FALLBACK }; CharString sText; sText.format( ORDER_DESC[ pShip->order() ], pShip->orderTarget() ? pShip->orderTarget()->name() : "" ); setText( sText ); setActiveTime( 0 ); } } }
void TextNavigation::onUpdate( float t ) { WindowText::onUpdate( t ); if ( visible() && activeTime() > UPDATE_NAV_TEXT ) { setActiveTime( 0 ); GameDocument * pDoc = (GameDocument *)document(); ASSERT( pDoc ); CharString sText; if ( pDoc->isTeamValid() ) { GameContext * pContext = pDoc->context(); ASSERT( pContext ); Hash< dword, Array<NounPlanet *> > factionPlanets; Hash< dword, Array<NounShip *> > factionShips; int nStars = 0; int nAsteroids = 0; int nGates = 0; // get the players teamId int nFactionId = pDoc->factionId(); // push all detected objects for(int z=0;z<pContext->zoneCount();z++) { NodeZone * pZone = pContext->zone( z ); for(int i=0;i<pZone->childCount();i++) { NounGame * pNoun = WidgetCast<NounGame>( pZone->child(i) ); if (! pNoun ) continue; if ( pNoun->isDetected( nFactionId ) ) { if ( WidgetCast<NounShip>( pNoun ) ) factionShips[ pNoun->factionId() ].push( (NounShip *)pNoun ); else if ( WidgetCast<NounPlanet>( pNoun ) ) factionPlanets[ pNoun->factionId() ].push( (NounPlanet *)pNoun ); else if ( WidgetCast<NounStar>( pNoun ) ) nStars++; else if ( WidgetCast<NounAsteroid>( pNoun ) ) nAsteroids++; else if ( WidgetCast<NounJumpGate>( pNoun ) ) nGates++; } } } // update navigation text information const GameContext::Team & fleet = pContext->team( pDoc->teamId() ); sText += CharString().format( "<b;l>%s</b;/l>:\n", fleet.name ); Array< NounShip * > & ships = factionShips[ fleet.factionId ]; sText += CharString().format("<x;10>Ships:<x;150>%d\n", ships.size() ); for(int k=0;k<NounShip::TYPE_COUNT;k++) { // how many ships of this type int count = 0; for(int j=0;j<ships.size();j++) if ( ships[j]->type() == (NounShip::Type)k ) count++; if ( count > 0 ) sText += CharString().format( "<X;20>%s:<X;150>%d\n", NounShip::typeText( (NounShip::Type)k ), count ); } if ( factionPlanets.find( fleet.factionId ).valid() ) { Array< NounPlanet *> & planets = factionPlanets[ fleet.factionId ]; sText += CharString().format("<X;10>Planets:<X;150>%d\n", planets.size() ); int population = 0; int ports = 0; int depots = 0; int yards = 0; int units = 0; for(int j=0;j<planets.size();j++) { NounPlanet * pPlanet = planets[ j ]; population += pPlanet->population(); units += pPlanet->friendlyUnitCount(); if ( pPlanet->flags() & NounPlanet::FLAG_HAS_DEPOT ) depots++; if ( pPlanet->flags() & NounPlanet::FLAG_HAS_PORT ) ports++; if ( pPlanet->flags() & NounPlanet::FLAG_HAS_SHIPYARD ) yards++; } if ( population > 0 ) sText += CharString().format( "<X;20>Population:<X;150>%d\n", population ); if ( units > 0 ) sText += CharString().format( "<X;20>Units:<X;150>%d\n", units ); if ( ports > 0 ) sText += CharString().format( "<X;20>Ports:<X;150>%d\n", ports ); if ( depots > 0 ) sText += CharString().format( "<X;20>Depots:<X;150>%d\n", depots ); if ( yards > 0 ) sText += CharString().format( "<X;20>Ship Yards:<X;150>%d\n", yards ); } } setText( sText ); } }