Перенос библиотек

This commit is contained in:
Kernell 2015-11-28 04:42:36 +03:00
parent 31a0c20137
commit 5a38df8feb
2 changed files with 203 additions and 204 deletions

View File

@ -1,139 +1,139 @@
#include "Common.h" #include "Common.h"
CVehicleColor::CVehicleColor ( void ) CVehicleColor::CVehicleColor( void )
{ {
// Init // Init
m_ucPaletteColors[0] = 0; // Palette color 0 is black m_ucPaletteColors[ 0 ] = 0; // Palette color 0 is black
m_ucPaletteColors[1] = 0; m_ucPaletteColors[ 1 ] = 0;
m_ucPaletteColors[2] = 0; m_ucPaletteColors[ 2 ] = 0;
m_ucPaletteColors[3] = 0; m_ucPaletteColors[ 3 ] = 0;
m_RGBColors[0] = 0; m_RGBColors[ 0 ] = 0;
m_RGBColors[1] = 0; m_RGBColors[ 1 ] = 0;
m_RGBColors[2] = 0; m_RGBColors[ 2 ] = 0;
m_RGBColors[3] = 0; m_RGBColors[ 3 ] = 0;
m_bPaletteColorsWrong = false; m_bPaletteColorsWrong = false;
m_bRGBColorsWrong = false; m_bRGBColorsWrong = false;
} }
// Use black for colours that are not used (bandwidth saving) // Use black for colours that are not used (bandwidth saving)
void CVehicleColor::SetRGBColors ( SColor color1, SColor color2, SColor color3, SColor color4 ) void CVehicleColor::SetRGBColors( SColor color1, SColor color2, SColor color3, SColor color4 )
{ {
if ( if(
m_RGBColors[0] != color1 || m_RGBColors[ 0 ] != color1 ||
m_RGBColors[1] != color2 || m_RGBColors[ 1 ] != color2 ||
m_RGBColors[2] != color3 || m_RGBColors[ 2 ] != color3 ||
m_RGBColors[3] != color4 m_RGBColors[ 3 ] != color4
) )
{ {
m_RGBColors[0] = color1; m_RGBColors[ 0 ] = color1;
m_RGBColors[1] = color2; m_RGBColors[ 1 ] = color2;
m_RGBColors[2] = color3; m_RGBColors[ 2 ] = color3;
m_RGBColors[3] = color4; m_RGBColors[ 3 ] = color4;
InvalidatePaletteColors (); InvalidatePaletteColors();
} }
} }
void CVehicleColor::SetPaletteColors ( unsigned char ucColor1, unsigned char ucColor2, unsigned char ucColor3, unsigned char ucColor4 ) void CVehicleColor::SetPaletteColors( unsigned char ucColor1, unsigned char ucColor2, unsigned char ucColor3, unsigned char ucColor4 )
{ {
if ( m_ucPaletteColors[0] != ucColor1 || if( m_ucPaletteColors[ 0 ] != ucColor1 ||
m_ucPaletteColors[1] != ucColor2 || m_ucPaletteColors[ 1 ] != ucColor2 ||
m_ucPaletteColors[2] != ucColor3 || m_ucPaletteColors[ 2 ] != ucColor3 ||
m_ucPaletteColors[3] != ucColor4 ) m_ucPaletteColors[ 3 ] != ucColor4 )
{ {
m_ucPaletteColors[0] = ucColor1; m_ucPaletteColors[ 0 ] = ucColor1;
m_ucPaletteColors[1] = ucColor2; m_ucPaletteColors[ 1 ] = ucColor2;
m_ucPaletteColors[2] = ucColor3; m_ucPaletteColors[ 2 ] = ucColor3;
m_ucPaletteColors[3] = ucColor4; m_ucPaletteColors[ 3 ] = ucColor4;
InvalidateRGBColors (); InvalidateRGBColors();
} }
} }
void CVehicleColor::SetRGBColor ( uint uiSlot, SColor color ) void CVehicleColor::SetRGBColor( uint uiSlot, SColor color )
{ {
ValidateRGBColors (); ValidateRGBColors();
uiSlot = Min ( uiSlot, static_cast < uint > ( NUMELMS( m_RGBColors ) ) ); uiSlot = Min( uiSlot, static_cast <uint> ( NUMELMS( m_RGBColors ) ) );
if ( m_RGBColors [ uiSlot ] != color ) if( m_RGBColors[ uiSlot ] != color )
{ {
m_RGBColors [ uiSlot ] = color; m_RGBColors[ uiSlot ] = color;
InvalidatePaletteColors (); InvalidatePaletteColors();
} }
} }
void CVehicleColor::SetPaletteColor ( uint uiSlot, uchar ucColor ) void CVehicleColor::SetPaletteColor( uint uiSlot, uchar ucColor )
{ {
ValidatePaletteColors (); ValidatePaletteColors();
uiSlot = Min ( uiSlot, static_cast < uint > ( NUMELMS( m_ucPaletteColors ) ) ); uiSlot = Min( uiSlot, static_cast <uint> ( NUMELMS( m_ucPaletteColors ) ) );
if ( m_ucPaletteColors [ uiSlot ] != ucColor ) if( m_ucPaletteColors[ uiSlot ] != ucColor )
{ {
m_ucPaletteColors [ uiSlot ] = ucColor; m_ucPaletteColors[ uiSlot ] = ucColor;
InvalidateRGBColors (); InvalidateRGBColors();
} }
} }
// Get a slot colour as a palette index // Get a slot colour as a palette index
uchar CVehicleColor::GetPaletteColor ( uint uiSlot ) uchar CVehicleColor::GetPaletteColor( uint uiSlot )
{ {
ValidatePaletteColors (); ValidatePaletteColors();
uiSlot = Min ( uiSlot, static_cast < uint > ( NUMELMS( m_ucPaletteColors ) ) ); uiSlot = Min( uiSlot, static_cast <uint> ( NUMELMS( m_ucPaletteColors ) ) );
return m_ucPaletteColors [ uiSlot ]; return m_ucPaletteColors[ uiSlot ];
} }
// Get a slot colour as an RGB colour // Get a slot colour as an RGB colour
SColor CVehicleColor::GetRGBColor ( uint uiSlot ) SColor CVehicleColor::GetRGBColor( uint uiSlot )
{ {
ValidateRGBColors (); ValidateRGBColors();
uiSlot = Min ( uiSlot, static_cast < uint > ( NUMELMS( m_RGBColors ) ) ); uiSlot = Min( uiSlot, static_cast <uint> ( NUMELMS( m_RGBColors ) ) );
return m_RGBColors [ uiSlot ]; return m_RGBColors[ uiSlot ];
} }
// Can return: 1,2,3, or 4 // Can return: 1,2,3, or 4
int CVehicleColor::GetNumColorsUsed ( void ) int CVehicleColor::GetNumColorsUsed( void )
{ {
// Find last unblack // Find last unblack
int i; int i;
for ( i = NUMELMS( m_RGBColors ) ; i > 1 ; i-- ) for( i = NUMELMS( m_RGBColors ); i > 1; i-- )
{ {
if ( GetRGBColor ( i - 1 ) ) if( GetRGBColor( i - 1 ) )
break; break;
} }
assert ( i >= 1 && i <= 4 ); assert( i >= 1 && i <= 4 );
return i; return i;
} }
// Switching to RGB mode // Switching to RGB mode
void CVehicleColor::InvalidatePaletteColors ( void ) void CVehicleColor::InvalidatePaletteColors( void )
{ {
m_bRGBColorsWrong = false; m_bRGBColorsWrong = false;
m_bPaletteColorsWrong = true; m_bPaletteColorsWrong = true;
} }
// Switching to palette mode // Switching to palette mode
void CVehicleColor::InvalidateRGBColors ( void ) void CVehicleColor::InvalidateRGBColors( void )
{ {
m_bPaletteColorsWrong = false; m_bPaletteColorsWrong = false;
m_bRGBColorsWrong = true; m_bRGBColorsWrong = true;
} }
// Ensure switched // Ensure switched
void CVehicleColor::ValidateRGBColors ( void ) void CVehicleColor::ValidateRGBColors( void )
{ {
if ( m_bRGBColorsWrong ) if( m_bRGBColorsWrong )
{ {
m_bRGBColorsWrong = false; m_bRGBColorsWrong = false;
for ( uint i = 0 ; i < NUMELMS( m_RGBColors ) ; i++ ) for( uint i = 0; i < NUMELMS( m_RGBColors ); i++ )
m_RGBColors[i] = GetRGBFromPaletteIndex ( m_ucPaletteColors[i] ); m_RGBColors[ i ] = GetRGBFromPaletteIndex( m_ucPaletteColors[ i ] );
} }
} }
// Ensure switched // Ensure switched
void CVehicleColor::ValidatePaletteColors ( void ) void CVehicleColor::ValidatePaletteColors( void )
{ {
if ( m_bPaletteColorsWrong ) if( m_bPaletteColorsWrong )
{ {
m_bPaletteColorsWrong = false; m_bPaletteColorsWrong = false;
for ( uint i = 0 ; i < NUMELMS( m_ucPaletteColors ) ; i++ ) for( uint i = 0; i < NUMELMS( m_ucPaletteColors ); i++ )
m_ucPaletteColors[i] = GetPaletteIndexFromRGB ( m_RGBColors[i] ); m_ucPaletteColors[ i ] = GetPaletteIndexFromRGB( m_RGBColors[ i ] );
} }
} }
@ -170,20 +170,20 @@ static const uchar paletteColorTable8[] = {
0x22, 0x34, 0x57, 0xff, 0x64, 0x0d, 0x1b, 0xff, 0xa3, 0xad, 0xc6, 0xff, 0x69, 0x58, 0x53, 0xff, 0x22, 0x34, 0x57, 0xff, 0x64, 0x0d, 0x1b, 0xff, 0xa3, 0xad, 0xc6, 0xff, 0x69, 0x58, 0x53, 0xff,
0x9b, 0x8b, 0x80, 0xff, 0x62, 0x0b, 0x1c, 0xff, 0x5b, 0x5d, 0x5e, 0xff, 0x62, 0x44, 0x28, 0xff, 0x9b, 0x8b, 0x80, 0xff, 0x62, 0x0b, 0x1c, 0xff, 0x5b, 0x5d, 0x5e, 0xff, 0x62, 0x44, 0x28, 0xff,
0x73, 0x18, 0x27, 0xff, 0x1b, 0x37, 0x6d, 0xff, 0xec, 0x6a, 0xae, 0xff, 0x73, 0x18, 0x27, 0xff, 0x1b, 0x37, 0x6d, 0xff, 0xec, 0x6a, 0xae, 0xff,
}; };
uchar CVehicleColor::GetPaletteIndexFromRGB ( SColor color ) uchar CVehicleColor::GetPaletteIndexFromRGB( SColor color )
{ {
ulong ulBestDist = 0xFFFFFFFF; ulong ulBestDist = 0xFFFFFFFF;
uchar ucBestMatch = 0; uchar ucBestMatch = 0;
for ( uint i = 0 ; i < NUMELMS( paletteColorTable8 ) / 4 ; i++ ) for( uint i = 0; i < NUMELMS( paletteColorTable8 ) / 4; i++ )
{ {
int r = paletteColorTable8[ i * 4 + 0 ] - color.R; int r = paletteColorTable8[ i * 4 + 0 ] - color.R;
int g = paletteColorTable8[ i * 4 + 1 ] - color.G; int g = paletteColorTable8[ i * 4 + 1 ] - color.G;
int b = paletteColorTable8[ i * 4 + 2 ] - color.B; int b = paletteColorTable8[ i * 4 + 2 ] - color.B;
ulong ulDist = r * r + g * g + b * b; ulong ulDist = r * r + g * g + b * b;
if ( ulDist < ulBestDist ) if( ulDist < ulBestDist )
{ {
ulBestDist = ulDist; ulBestDist = ulDist;
ucBestMatch = i; ucBestMatch = i;
@ -192,11 +192,11 @@ uchar CVehicleColor::GetPaletteIndexFromRGB ( SColor color )
return ucBestMatch; return ucBestMatch;
} }
SColor CVehicleColor::GetRGBFromPaletteIndex ( uchar ucColor ) SColor CVehicleColor::GetRGBFromPaletteIndex( uchar ucColor )
{ {
ucColor = Min < uchar > ( ucColor, static_cast < uint > ( NUMELMS( paletteColorTable8 ) / 4 ) ); ucColor = Min < uchar >( ucColor, static_cast <uint> ( NUMELMS( paletteColorTable8 ) / 4 ) );
uchar r = paletteColorTable8[ ucColor * 4 ]; uchar r = paletteColorTable8[ ucColor * 4 ];
uchar g = paletteColorTable8[ ucColor * 4 + 1 ]; uchar g = paletteColorTable8[ ucColor * 4 + 1 ];
uchar b = paletteColorTable8[ ucColor * 4 + 2 ]; uchar b = paletteColorTable8[ ucColor * 4 + 2 ];
return SColorRGBA ( r, g, b, 0 ); return SColorRGBA( r, g, b, 0 );
} }

View File

@ -41,7 +41,7 @@ extern "C"
#include <glib.h> #include <glib.h>
#pragma warning( pop ) #pragma warning( pop )
#include <mono/mini/jit.h> #include <mono/jit/jit.h>
#include <mono/metadata/assembly.h> #include <mono/metadata/assembly.h>
#include <mono/metadata/mono-debug.h> #include <mono/metadata/mono-debug.h>
#include <mono/metadata/debug-helpers.h> #include <mono/metadata/debug-helpers.h>
@ -53,7 +53,6 @@ extern "C"
#include "extra/Vector2.h" #include "extra/Vector2.h"
#include "extra/Vector3.h" #include "extra/Vector3.h"
// Obviously i can't get us this so other includes will most likely be needed later on
using namespace std; using namespace std;