void Model::DrawAt(Coord3D origin, GLfloat scale, Colour colour) { //Draw all vertices for each polygon, setting texture coords and vertex normals int a, b; Vertex v; colour.Set(); for (a = 0; a < numFaces; a++) { glBegin(GL_POLYGON); for (b = 0; b < faceData[a].numIndicies; b++) { // Lookup vertex index in polygonData, // then use to get actual vertex from vertexData v = vertexData[faceData[a].vIdxs[b]]; // Define texture coordinates of vertex // glTexCoord2f(v.tex_coord[0], v.tex_coord[1]); // Define normal of vertex glNormal3f(v.normal[0], v.normal[1], v.normal[2]); // Define coordinates of vertex glVertex3f(origin.x + v.coord[0]*scale, origin.y + v.coord[1]*scale, origin.z + v.coord[2]*scale); } glEnd(); } }
void Silo::Render() { WorldObject::Render(); // // Render nuke count under the silo if( m_teamId == g_app->GetWorld()->m_myTeamId || g_app->GetWorld()->m_myTeamId == -1 || g_app->GetGame()->m_winner != -1 ) { int numNukesInStore = m_states[0]->m_numTimesPermitted; int numNukesInQueue = m_actionQueue.Size(); Team *team = g_app->GetWorld()->GetTeam(m_teamId); Colour colour = team->GetTeamColour(); colour.m_a = 150; Image *bmpImage = g_resource->GetImage("graphics/smallnuke.bmp"); if( bmpImage ) { float x = m_longitude.DoubleValue(); float y = m_latitude.DoubleValue() - GetSize().DoubleValue() * 0.9f; float nukeSize = GetSize().DoubleValue() * 0.35f; x -= GetSize().DoubleValue()*0.95f; for( int i = 0; i < numNukesInStore; ++i ) { if( i >= (numNukesInStore-numNukesInQueue) ) { colour.Set( 128,128,128,100 ); } g_renderer->Blit( bmpImage, x+i*nukeSize*0.5f, y, nukeSize, -nukeSize, colour ); } } } }
void ConnectingWindow::Render( bool _hasFocus ) { InterfaceWindow::Render( _hasFocus ); float yPos = m_y + 40; // // Render our connection state g_renderer->SetFont( "kremlin" ); float fraction = 0.0f; char *caption = NULL; Colour col; switch( g_app->GetClientToServer()->m_connectionState ) { case ClientToServer::StateDisconnected: col.Set(255,0,0,255); caption = LANGUAGEPHRASE("dialog_state_disconnected"); fraction = 0.0f; break; case ClientToServer::StateConnecting: col.Set(255,255,0,255); caption = LANGUAGEPHRASE("dialog_state_connecting"); fraction = 0.5f; break; case ClientToServer::StateHandshaking: case ClientToServer::StateConnected: col.Set(0,255,0,255); caption = LANGUAGEPHRASE("dialog_state_connected"); fraction = 1.0f; break; } g_renderer->TextCentreSimple( m_x+m_w/2, yPos, col, 20, caption ); yPos += 20; if( fraction > 0.0f ) { g_renderer->RectFill( m_x + 30, yPos, (m_w-60)*fraction, 20, col ); g_renderer->Rect( m_x+30, yPos, (m_w-60), 20, White ); int numConnectionAttempts = g_app->GetClientToServer()->m_connectionAttempts; if( fraction < 1.0f && numConnectionAttempts > 0 ) { char caption[512]; sprintf( caption, LANGUAGEPHRASE("dialog_state_attempts") ); LPREPLACEINTEGERFLAG( 'A', numConnectionAttempts, caption ); g_renderer->TextCentreSimple( m_x + m_w/2, m_y + m_h - 60, White, 14, caption ); } } // // Render our sync status (ie receiving all data from the server) yPos += 40; if( g_app->GetClientToServer()->IsConnected() ) { if( m_stage == 0 ) { m_stage = 1; m_stageStartTime = GetHighResTime(); } int serverSeqId = g_app->GetClientToServer()->m_serverSequenceId; int latestSeqId = g_app->GetClientToServer()->m_lastValidSequenceIdFromServer; int numRemaining = serverSeqId-latestSeqId; numRemaining--; if( numRemaining > m_maxUpdatesRemaining ) { m_maxUpdatesRemaining = numRemaining; } if( m_maxUpdatesRemaining > 0 ) { fraction = numRemaining / (float) m_maxUpdatesRemaining; } else { fraction = 0.0f; } Clamp( fraction, 0.0f, 1.0f ); fraction = 1.0f - fraction; col.Set( (1-fraction)*255, fraction*255, 0, 255 ); const char *caption = numRemaining > 5 ? LANGUAGEPHRASE("dialog_state_receiving") : LANGUAGEPHRASE("dialog_state_received"); g_renderer->TextCentreSimple( m_x+m_w/2, yPos, col, 20, caption ); yPos += 20; g_renderer->RectFill( m_x+30, yPos, (m_w-60)*fraction, 20, col ); g_renderer->Rect( m_x+30, yPos, (m_w-60), 20, White ); if( m_stage == 1 ) { RenderTimeRemaining(fraction); } // // Render how much of the received data we have successfully parsed int lagRemaining = 0; if( g_lastProcessedSequenceId > 0 && numRemaining < 10 ) { if( m_stage != 2 ) { m_stage = 2; m_stageStartTime = GetHighResTime(); } yPos += 40; int serverSeqId = g_app->GetClientToServer()->m_serverSequenceId; lagRemaining = serverSeqId - g_lastProcessedSequenceId; lagRemaining --; if( lagRemaining > m_maxLagRemaining ) { m_maxLagRemaining = lagRemaining; } fraction = lagRemaining / (float) m_maxLagRemaining; Clamp( fraction, 0.0f, 1.0f ); fraction = 1.0f - fraction; col.Set( (1-fraction)*255, fraction*255, 0, 255 ); const char *caption = lagRemaining > 5 ? LANGUAGEPHRASE("dialog_state_synchronising") : LANGUAGEPHRASE("dialog_state_synchronised"); g_renderer->TextCentreSimple( m_x+m_w/2, yPos, col, 20, caption ); yPos += 20; g_renderer->RectFill( m_x+30, yPos, (m_w-60)*fraction, 20, col ); g_renderer->Rect( m_x+30, yPos, (m_w-60), 20, White ); if( m_stage == 2 ) { RenderTimeRemaining( fraction ); } } // // Connection is done, we can shut down now // Pop up lobby if we were asked to do so if( g_app->GetClientToServer()->m_connectionState == ClientToServer::StateConnected ) { if( m_popupLobbyAtEnd ) { if( !EclGetWindow( "LOBBY" ) ) { LobbyWindow *lobby = new LobbyWindow(); ChatWindow *chat = new ChatWindow(); chat->SetPosition( g_windowManager->WindowW()/2 - chat->m_w/2, g_windowManager->WindowH() - chat->m_h - 30 ); EclRegisterWindow( chat ); float lobbyX = g_windowManager->WindowW()/2 - lobby->m_w/2; float lobbyY = chat->m_y - lobby->m_h - 30; lobbyY = std::max( lobbyY, 0.0f ); lobby->SetPosition(lobbyX, lobbyY); EclRegisterWindow( lobby ); } } if( numRemaining < 5 && lagRemaining < 5 ) { EclRemoveWindow(m_name); } } } else { if( g_app->GetClientToServer()->m_connectionState == ClientToServer::StateDisconnected ) { EclRemoveWindow(m_name); } } g_renderer->SetFont(); }
void NetworkWindow::Render( bool hasFocus ) { InterfaceWindow::Render( hasFocus ); int y = m_y+15; int h = 15; if( g_app->GetServer() ) { char caption[128]; char number[32]; sprintf( caption, LANGUAGEPHRASE("dialog_network_server_seqid") ); LPREPLACEINTEGERFLAG( 'S', g_app->GetServer()->m_sequenceId, caption ); g_renderer->TextSimple( m_x + 10, y+=h, White, 12, caption ); sprintf( caption, LANGUAGEPHRASE("dialog_network_server_send") ); sprintf( number, "%2.1f", g_app->GetServer()->m_sendRate/1024.0f ); LPREPLACESTRINGFLAG( 'R', number, caption ); g_renderer->TextSimple( m_x + 10, y+=h, White, 12, caption ); sprintf( caption, LANGUAGEPHRASE("dialog_network_server_receive") ); sprintf( number, "%2.1f", g_app->GetServer()->m_receiveRate/1024.0f ); LPREPLACESTRINGFLAG( 'R', number, caption ); g_renderer->TextSimple( m_x + 10, y+=h, White, 12, caption ); g_renderer->Line( m_x + 10, y + 20, m_x + m_w - 10, y + 20, White, 1 ); int clientX = m_x + 20; int ipX = clientX + 60; int seqX = ipX + 140; int playerX = seqX + 60; int lagX = playerX + 150; int syncX = lagX + 90; y+=h*2; g_renderer->TextSimple( clientX, y, White, 14, LANGUAGEPHRASE("dialog_network_id") ); g_renderer->TextSimple( ipX, y, White, 14, LANGUAGEPHRASE("dialog_network_ip_port") ); g_renderer->TextSimple( seqX, y, White, 14, LANGUAGEPHRASE("dialog_network_seqid") ); g_renderer->TextSimple( playerX, y, White, 14, LANGUAGEPHRASE("dialog_network_name") ); g_renderer->TextSimple( lagX, y, White, 14, LANGUAGEPHRASE("dialog_network_status") ); y+=h*2; int maxClients = g_app->GetGame()->GetOptionValue("MaxTeams") + g_app->GetGame()->GetOptionValue("MaxSpectators"); for( int i = 0; i < maxClients; ++i ) { if( g_app->GetServer()->m_clients.ValidIndex(i) ) { ServerToClient *sToc = g_app->GetServer()->m_clients[i]; char netLocation[256]; sprintf( netLocation, "%s:%d", sToc->m_ip, sToc->m_port); char caption[256]; Colour col; float timeBehind = GetHighResTime() - sToc->m_lastMessageReceived; if( timeBehind > 2.0f ) { col.Set( 255, 0, 0, 255 ); sprintf( caption, LANGUAGEPHRASE("dialog_network_lost_con") ); LPREPLACEINTEGERFLAG( 'S', (int)timeBehind, caption ); } else if( !sToc->m_caughtUp ) { col.Set( 200, 200, 30, 255 ); int percent = 100 * (sToc->m_lastKnownSequenceId / (float)g_app->GetServer()->m_sequenceId); sprintf( caption, LANGUAGEPHRASE("dialog_network_synching") ); LPREPLACEINTEGERFLAG( 'P', percent, caption ); } else { float latency = (g_app->GetServer()->m_sequenceId - sToc->m_lastKnownSequenceId); float latencyMs = latency * 100.0f; sprintf( caption, LANGUAGEPHRASE("dialog_network_ping") ); LPREPLACEINTEGERFLAG( 'P', (int)latencyMs, caption ); int red = std::min(255,(int) latency*20); int green = 255 - red; col.Set(red,green,0,255); } Colour normalCol(200,200,255,200); char *playerName = NULL; if( sToc->m_spectator ) { for( int j = 0; j < g_app->GetWorld()->m_spectators.Size(); ++j ) { Spectator *thisTeam = g_app->GetWorld()->m_spectators[j]; if( thisTeam->m_clientId == sToc->m_clientId ) { playerName = thisTeam->m_name; break; } } } else { for( int j = 0; j < g_app->GetWorld()->m_teams.Size(); ++j ) { Team *thisTeam = g_app->GetWorld()->m_teams[j]; if( thisTeam->m_clientId == sToc->m_clientId ) { playerName = thisTeam->m_name; break; } } } g_renderer->Text( clientX, y, normalCol, 12, "%d", sToc->m_clientId ); if( playerName ) { g_renderer->TextSimple( playerX, y, normalCol, 12, playerName ); } g_renderer->TextSimple( ipX, y, normalCol, 12, netLocation ); g_renderer->Text( seqX, y, normalCol, 12, "%d", sToc->m_lastKnownSequenceId ); g_renderer->TextSimple( lagX, y, col, 12, caption ); if( sToc->m_spectator ) { g_renderer->TextSimple( clientX+10, y, normalCol, 12, LANGUAGEPHRASE("dialog_network_spec") ); } if( sToc->m_syncErrorSeqId != -1 ) { g_renderer->Text( syncX, y, Colour(255,0,0,255), 12, LANGUAGEPHRASE("dialog_worldstatus_out_of_sync_2") ); } } else { g_renderer->Text( clientX, y, Colour(255,255,255,50), 12, LANGUAGEPHRASE("dialog_network_empty") ); } y += 20; } } // // Show which packets are queued up if we're a client if( g_app->GetClientToServer() && g_lastProcessedSequenceId >= 0 ) { float yPos = m_y + m_h - 25; g_renderer->TextSimple( m_x + 10, yPos-25, White, 13, LANGUAGEPHRASE("dialog_network_sequence_msg_queue") ); float xPos = m_x + 10; float width = (m_w - 120) / 10; float gap = width * 0.2f; for( int i = 0; i <= 10; ++i ) { if( i != 0 ) { g_renderer->RectFill( xPos, yPos-5, width-gap, 20, Colour(20,20,50,255) ); if( g_app->GetClientToServer()->IsSequenceIdInQueue( g_lastProcessedSequenceId+i ) ) { g_renderer->RectFill( xPos, yPos-5, width-gap, 20, Colour(0,255,0,255) ); } g_renderer->Rect( xPos, yPos-5, width-gap, 20, Colour(255,255,255,100) ); } if( i == 0 ) { char caption[128]; sprintf( caption, LANGUAGEPHRASE("dialog_network_seqid_number") ); LPREPLACEINTEGERFLAG( 'S', g_lastProcessedSequenceId, caption ); g_renderer->TextSimple( xPos, yPos, White, 13, caption ); xPos += width * 1; } xPos += width; } } if( g_app->GetClientToServer() ) { char caption[128]; char number[32]; if( !g_app->GetServer() ) { sprintf( caption, LANGUAGEPHRASE("dialog_network_svr_known_seqid") ); LPREPLACEINTEGERFLAG( 'S', g_app->GetClientToServer()->m_serverSequenceId, caption ); g_renderer->TextSimple( m_x + 10, y+=h, White, 12, caption ); sprintf( caption, LANGUAGEPHRASE("dialog_network_svr_estimated_seqid") ); LPREPLACEINTEGERFLAG( 'S', g_app->GetClientToServer()->GetEstimatedServerSeqId(), caption ); g_renderer->TextSimple( m_x + 10, y+=h, White, 12, caption ); sprintf( caption, LANGUAGEPHRASE("dialog_network_estimated_latency") ); sprintf( number, "%2.1f", g_app->GetClientToServer()->GetEstimatedLatency() ); LPREPLACESTRINGFLAG( 'L', number, caption ); g_renderer->TextCentreSimple( m_x + m_w/2, y+40, White, 15, caption ); } y = m_y + 15; sprintf( caption, LANGUAGEPHRASE("dialog_network_client_seqid") ); LPREPLACEINTEGERFLAG( 'S', g_app->GetClientToServer()->m_lastValidSequenceIdFromServer, caption ); g_renderer->TextSimple( m_x + 250, y+=h, White, 12, caption ); sprintf( caption, LANGUAGEPHRASE("dialog_network_client_send") ); sprintf( number, "%2.1f", g_app->GetClientToServer()->m_sendRate/1024.0f ); LPREPLACESTRINGFLAG( 'R', number, caption ); g_renderer->TextSimple( m_x + 250, y+=h, White, 12, caption ); sprintf( caption, LANGUAGEPHRASE("dialog_network_client_receive") ); sprintf( number, "%2.1f", g_app->GetClientToServer()->m_receiveRate/1024.0f ); LPREPLACESTRINGFLAG( 'R', number, caption ); g_renderer->TextSimple( m_x + 250, y+=h, White, 12, caption ); } }