|
From: Greg <evo...@us...> - 2005-12-19 17:54:34
|
Update of /cvsroot/evolutionlejeu/evolutionlejeu/Evolution/Ulysses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv460/Evolution/Ulysses Modified Files: ELandscape.cpp ELandscape.h EWorldview.cpp Log Message: CHG : code refactoring (rename zoom with more explicit value) ADD : Province fit the governor minimap (in dev) Index: ELandscape.cpp =================================================================== RCS file: /cvsroot/evolutionlejeu/evolutionlejeu/Evolution/Ulysses/ELandscape.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ELandscape.cpp 18 Dec 2005 21:37:03 -0000 1.5 --- ELandscape.cpp 19 Dec 2005 17:53:52 -0000 1.6 *************** *** 10,16 **** #define PTZ( x, y ) ( m_pCoordinates[ 3 * ( (x) + (y) * m_iAltWidth) + 2 ] ) ! #define SQX( x, y ) ( PTX( (x)*( (int)m_fZoom ), (y)*( (int)m_fZoom ) ) ) ! #define SQY( x, y ) ( PTY( (x)*( (int)m_fZoom ), (y)*( (int)m_fZoom ) ) ) ! #define SQZ( x, y ) ( PTZ( (x)*( (int)m_fZoom ), (y)*( (int)m_fZoom ) ) ) #define SQZP( x, y ) ( min( 0, SQZ( (x),(y) ) ) ) --- 10,16 ---- #define PTZ( x, y ) ( m_pCoordinates[ 3 * ( (x) + (y) * m_iAltWidth) + 2 ] ) ! #define SQX( x, y ) ( PTX( (x)*( m_iSquareSizeInTile ), (y)*( m_iSquareSizeInTile ) ) ) ! #define SQY( x, y ) ( PTY( (x)*( m_iSquareSizeInTile ), (y)*( m_iSquareSizeInTile ) ) ) ! #define SQZ( x, y ) ( PTZ( (x)*( m_iSquareSizeInTile ), (y)*( m_iSquareSizeInTile ) ) ) #define SQZP( x, y ) ( min( 0, SQZ( (x),(y) ) ) ) *************** *** 25,29 **** m_fMapPlaneRadius = 30.0f; m_fTileSize = m_fMaxTileSize = 30.0f; ! m_fZoom = 1.0f; m_fVerticalInflation = 2.0f; --- 25,29 ---- m_fMapPlaneRadius = 30.0f; m_fTileSize = m_fMaxTileSize = 30.0f; ! m_fTileSizeRatio = 1.0f; m_fVerticalInflation = 2.0f; *************** *** 130,134 **** OSpotConfig& oSpotConfig = (OSpotConfig&) aiInterface.SendOrder( e_orderGetSpotConfig, oGetSpotConfig, m_spotId ); ! m_fZoom = ( 1 << oSpotConfig.m_iNbrAltIteration ); --- 130,134 ---- OSpotConfig& oSpotConfig = (OSpotConfig&) aiInterface.SendOrder( e_orderGetSpotConfig, oGetSpotConfig, m_spotId ); ! m_iSquareSizeInTile = ( 1 << oSpotConfig.m_iNbrAltIteration ); *************** *** 176,180 **** // Screen items MainMapScreenItem *pMapScreenItem = new MainMapScreenItem; ! pMapScreenItem->m_squareSize = m_fZoom * m_config.m_fTileSize; pMapScreenItem->m_xMapUpLeft = SQX(0,0); pMapScreenItem->m_yMapUpLeft = SQY(0,0); --- 176,180 ---- // Screen items MainMapScreenItem *pMapScreenItem = new MainMapScreenItem; ! pMapScreenItem->m_squareSize = m_iSquareSizeInTile * m_config.m_fTileSize; pMapScreenItem->m_xMapUpLeft = SQX(0,0); pMapScreenItem->m_yMapUpLeft = SQY(0,0); *************** *** 210,214 **** int iAltWidth = oSpotResult.GetAltMapWidth(); int iAltHeight = oSpotResult.GetAltMapHeight(); ! double fZoom = m_fZoom; if( ! m_bTerrainListUpToDate ) --- 210,215 ---- int iAltWidth = oSpotResult.GetAltMapWidth(); int iAltHeight = oSpotResult.GetAltMapHeight(); ! ! double fZoom = (double) m_iSquareSizeInTile; if( ! m_bTerrainListUpToDate ) *************** *** 343,347 **** if( dx != 0 ) { ! double fRealScroll = ( (double) dx ) / m_config.m_fZoom; m_config.m_fXScroll += fRealScroll; --- 344,348 ---- if( dx != 0 ) { ! double fRealScroll = ( (double) dx ) / m_config.m_fTileSizeRatio; m_config.m_fXScroll += fRealScroll; *************** *** 353,357 **** if( dy != 0 ) { ! double fRealScroll = ( (double) dy ) / m_config.m_fZoom; m_config.m_fYScroll += fRealScroll; --- 354,358 ---- if( dy != 0 ) { ! double fRealScroll = ( (double) dy ) / m_config.m_fTileSizeRatio; m_config.m_fYScroll += fRealScroll; *************** *** 411,419 **** if( !bUnzoom ) { ! SetZoom( m_config.m_fZoom * 1.1f ); } else { ! SetZoom( m_config.m_fZoom * 0.9f ); } } --- 412,420 ---- if( !bUnzoom ) { ! SetZoom( m_config.m_fTileSizeRatio * 1.1f ); } else { ! SetZoom( m_config.m_fTileSizeRatio * 0.9f ); } } *************** *** 421,425 **** void ELandscape::SetZoom( double fZoom ) { ! m_config.m_fZoom = fZoom; // Process the tile size & the iteration number --- 422,426 ---- void ELandscape::SetZoom( double fZoom ) { ! m_config.m_fTileSizeRatio = fZoom; // Process the tile size & the iteration number *************** *** 482,485 **** --- 483,516 ---- + void ELandscape::SetZoomToViewRect( GeoDimension dimLength, GeoDimension dimHeight ) + { + // The goal is to find the good m_fTileSizeRatio associated with the good + // number of iterations to show a dimLength x dimHeight rect. + + double dHorizontalSquareSizeToReach = ( (double) GetWidth() ) / (double) dimLength; + double dVerticalSquareSizeToReach = ( (double) GetHeight() ) / (double) dimHeight / cos( m_config.m_fMapPlaneRadius * PI / 180.0f ); + + // Take the minimum of the two => we are sure to display the rect even if Landscape + // doesn't match exactly the same ratio width/height than dimLength/dimHeight + double dSquareSizeToReach = min( dHorizontalSquareSizeToReach, dVerticalSquareSizeToReach ); + + // Now, we adjust the number of iteration in order TileSize is between 1/2 max and max + + double dSquareSizeInTileToReach = dSquareSizeToReach / m_config.m_fMaxTileSize; + + int iSquareSizeInTile, iNbrIteration; + for( iNbrIteration = 1, iSquareSizeInTile = 1;; iNbrIteration ++, iSquareSizeInTile *= 2 ) + { + if( (double)iSquareSizeInTile >= dSquareSizeInTileToReach ) + { + break ; + } + } + + // last, we compute the exact value of tile size to match what we want + + double dFinalTileSizeInTile = dSquareSizeInTileToReach / (double)iSquareSizeInTile ; + SetZoom( dFinalTileSizeInTile ); + } double ELandscape::sqx( int x, int y ) *************** *** 514,519 **** int iAltHeight = m_poCurrentSpot->GetAltMapHeight(); ! int iSquareHeight = (int)( iAltHeight / m_fZoom ); ! int iSquareWidth = (int)( iAltWidth / m_fZoom ); int lon = gc.LonLow(); --- 545,550 ---- int iAltHeight = m_poCurrentSpot->GetAltMapHeight(); ! int iSquareHeight = (int)( iAltHeight / m_iSquareSizeInTile ); ! int iSquareWidth = (int)( iAltWidth / m_iSquareSizeInTile ); int lon = gc.LonLow(); *************** *** 566,570 **** m_pCoordinates = new int[ 3 * iAltHeight * iAltWidth ]; // x,y,z ! double fAltMult = m_config.m_fVerticalInflation * m_config.m_fZoom; double fTile = m_config.m_fTileSize; --- 597,601 ---- m_pCoordinates = new int[ 3 * iAltHeight * iAltWidth ]; // x,y,z ! double fAltMult = m_config.m_fVerticalInflation * m_config.m_fTileSizeRatio; double fTile = m_config.m_fTileSize; *************** *** 627,632 **** for( x = 0; x < iAltWidth; x++ ) { ! int xSquare = (int)( x / m_fZoom ); ! int ySquare = (int)( y / m_fZoom ); if( ! oSpotResult.GetSquareInfo( xSquare, ySquare ).bDiscovered ) --- 658,663 ---- for( x = 0; x < iAltWidth; x++ ) { ! int xSquare = (int)( x / m_iSquareSizeInTile ); ! int ySquare = (int)( y / m_iSquareSizeInTile ); if( ! oSpotResult.GetSquareInfo( xSquare, ySquare ).bDiscovered ) *************** *** 722,726 **** int iSquareSize = min( ( 512 / height ), ( 512 / width ) ); ! double fTextureRatio = 6.0f / m_config.m_fZoom; m_iTileSizeOnSurface = iSquareSize; --- 753,757 ---- int iSquareSize = min( ( 512 / height ), ( 512 / width ) ); ! double fTextureRatio = 6.0f / m_config.m_fTileSizeRatio; m_iTileSizeOnSurface = iSquareSize; *************** *** 807,812 **** int iAltHeight = oSpotResult.GetAltMapHeight(); ! int iSquareHeight = (int)( iAltHeight / m_fZoom ); ! int iSquareWidth = (int)( iAltWidth / m_fZoom ); --- 838,843 ---- int iAltHeight = oSpotResult.GetAltMapHeight(); ! int iSquareHeight = (int)( iAltHeight / m_iSquareSizeInTile ); ! int iSquareWidth = (int)( iAltWidth / m_iSquareSizeInTile ); *************** *** 818,822 **** for( int y = 0; y < (iSquareHeight-1); y++ ) { ! int iAltY = (int)( y * m_fZoom ); double fTexCoordY1 = ( (double) (y) ) * (double)m_iTileSizeOnSurface / 20.0f; --- 849,853 ---- for( int y = 0; y < (iSquareHeight-1); y++ ) { ! int iAltY = (int)( y * m_iSquareSizeInTile ); double fTexCoordY1 = ( (double) (y) ) * (double)m_iTileSizeOnSurface / 20.0f; *************** *** 825,829 **** for( int x = 0; x < (iSquareWidth-1); x++ ) { ! int iZoom = (int) m_fZoom; int iAltX = x * iZoom; --- 856,860 ---- for( int x = 0; x < (iSquareWidth-1); x++ ) { ! int iZoom = (int) m_iSquareSizeInTile; int iAltX = x * iZoom; *************** *** 914,919 **** int iScreenCenterY = GetHeight() /2; ! *fOffsetX = ( (double)iScreenCenterX - m_fZoom * ( (double)iMapCenterX ) * m_config.m_fTileSize ); ! *fOffsetY = ( (double)iScreenCenterY - m_fZoom * ( (double)iMapCenterY ) * m_config.m_fTileSize ); SDL_Rect rctControl = GetAbsRect(); --- 945,950 ---- int iScreenCenterY = GetHeight() /2; ! *fOffsetX = ( (double)iScreenCenterX - m_iSquareSizeInTile * ( (double)iMapCenterX ) * m_config.m_fTileSize ); ! *fOffsetY = ( (double)iScreenCenterY - m_iSquareSizeInTile * ( (double)iMapCenterY ) * m_config.m_fTileSize ); SDL_Rect rctControl = GetAbsRect(); *************** *** 922,927 **** // Screen scroll ! *fOffsetX -= m_config.m_fXScroll * m_config.m_fTileSize * m_fZoom; ! *fOffsetY -= m_config.m_fYScroll * m_config.m_fTileSize * m_fZoom; } --- 953,958 ---- // Screen scroll ! *fOffsetX -= m_config.m_fXScroll * m_config.m_fTileSize * m_iSquareSizeInTile; ! *fOffsetY -= m_config.m_fYScroll * m_config.m_fTileSize * m_iSquareSizeInTile; } *************** *** 950,985 **** } - void ELandscape::SetZoomToViewRect( GeoDimension dimLength, GeoDimension dimHeight ) - { - // 1. Process nbIteration and TileSize for the requested dimensions - // 2. Set up m_config - - int iNbrIteration; - GeoDimension dimCurrentWidth, dimCurrentHeight; - m_config.m_fTileSize = m_config.m_fMaxTileSize / 2; - - // We have set the TileSize to minimum ( max/2 ) - // Now, we try to find the NbrIteration need to have an area with the requested size - - for( iNbrIteration = 1; iNbrIteration < 999; iNbrIteration ++ ) // 999 is a protection ... - { - GetMapDimFromNbIteration( iNbrIteration, & dimCurrentWidth, & dimCurrentHeight ); - - if( (dimCurrentWidth >= dimLength) && (dimCurrentHeight >= dimHeight ) ) - { - // With iNbrIteration, we have a bigger area than requested - // Now, we increase m_fTileSize to fit exactly what we want - // rmq : m_fTileSize = zoom * m_fMaxTileSize - - double fHorZoom = ( (double) dimCurrentWidth ) / ( (double)dimLength ); // >= 1 - double fVerZoom = ( (double) dimCurrentHeight ) / ( (double)dimHeight ); // >= 1 - - SetZoom( min( fHorZoom, fVerZoom ) ); - return ; - } - } - - assert( false ); - } - - --- 981,982 ---- Index: ELandscape.h =================================================================== RCS file: /cvsroot/evolutionlejeu/evolutionlejeu/Evolution/Ulysses/ELandscape.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ELandscape.h 18 Dec 2005 21:37:03 -0000 1.6 --- ELandscape.h 19 Dec 2005 17:53:52 -0000 1.7 *************** *** 29,33 **** // Zoom stuff double m_fMaxTileSize; ! double m_fZoom; // Configuration --- 29,34 ---- // Zoom stuff double m_fMaxTileSize; ! double m_fTileSizeRatio; // tile size = m_fTileSizeRatio * m_fMaxTileSize ! // (this ratio is between 1/2 and 1) // Configuration *************** *** 73,77 **** void Zoom( bool bUnzoom ); ! double GetZoom() { return m_fZoom; } double GetMapRadius() { return m_config.m_fMapPlaneRadius; } --- 74,78 ---- void Zoom( bool bUnzoom ); ! int GetSquareSizeInTile() { return m_iSquareSizeInTile; } double GetMapRadius() { return m_config.m_fMapPlaneRadius; } *************** *** 138,142 **** int * m_pCoordinates; int m_iAltWidth; ! double m_fZoom; // Last terrain processed --- 139,143 ---- int * m_pCoordinates; int m_iAltWidth; ! int m_iSquareSizeInTile; // Last terrain processed Index: EWorldview.cpp =================================================================== RCS file: /cvsroot/evolutionlejeu/evolutionlejeu/Evolution/Ulysses/EWorldview.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** EWorldview.cpp 18 Dec 2005 21:37:03 -0000 1.9 --- EWorldview.cpp 19 Dec 2005 17:53:52 -0000 1.10 *************** *** 126,130 **** OSpotResult::ProvInfos infos = it->second; ! if( m_Landscape.GetZoom() >= m_fZoomMinForProvinceNames ) { int xScreen; --- 126,130 ---- OSpotResult::ProvInfos infos = it->second; ! if( (double)m_Landscape.GetSquareSizeInTile() >= m_fZoomMinForProvinceNames ) { int xScreen; *************** *** 359,364 **** int iAltHeight = oSpotResult.GetAltMapHeight(); ! int iSquareHeight = (int)( iAltHeight / m_Landscape.GetZoom() ); ! int iSquareWidth = (int)( iAltWidth / m_Landscape.GetZoom() ); glDisable(GL_DEPTH_TEST); --- 359,364 ---- int iAltHeight = oSpotResult.GetAltMapHeight(); ! int iSquareHeight = (int)( iAltHeight / m_Landscape.GetSquareSizeInTile() ); ! int iSquareWidth = (int)( iAltWidth / m_Landscape.GetSquareSizeInTile() ); glDisable(GL_DEPTH_TEST); *************** *** 482,487 **** int iAltHeight = m_poCurrentSpot->GetAltMapHeight(); ! int iSquareHeight = (int)( iAltHeight / m_Landscape.GetZoom() ); ! int iSquareWidth = (int)( iAltWidth / m_Landscape.GetZoom() ); --- 482,487 ---- int iAltHeight = m_poCurrentSpot->GetAltMapHeight(); ! int iSquareHeight = (int)( iAltHeight / m_Landscape.GetSquareSizeInTile() ); ! int iSquareWidth = (int)( iAltWidth / m_Landscape.GetSquareSizeInTile() ); |