<commit_before>//**************************************************************
//*            OpenGLide - Glide to OpenGL Wrapper
//*             http://openglide.sourceforge.net
//*
//*                      Fog Functions
//*
//*         OpenGLide is OpenSource under LGPL license
//*              Originaly made by <NAME>
//*      Modified by <NAME> (http://www.glidos.net)
//**************************************************************

#include <math.h>

#include "GlOgl.h"
#include "GLRender.h"


// extern functions
void ConvertColorB( GrColor_t GlideColor, BYTE &R, BYTE &G, BYTE &B, BYTE &A );
void ConvertColorF( GrColor_t GlideColor, float &R, float &G, float &B, float &A );
void MMXCopyMemory( void *Dst, void *Src, DWORD NumberOfBytes );

//*************************************************
//* download a fog table
//* Fog is applied after color combining and before alpha blending.
//*************************************************
DLLEXPORT void __stdcall
grFogTable( const GrFog_t *ft )
{
#ifdef DONE
    GlideMsg( "grFogTable( --- )\n" );
#endif

    DWORD   i, 
            j,
            s_i, 
            e_i,
            s, 
            e,
            forth_root[ 4 ] = { 0x10000, 0x1306f, 0x16a09, 0x1ae89 };

    if ( InternalConfig.FogEnable )
    {
        if ( InternalConfig.MMXEnable )
        {
            MMXCopyMemory( Glide.FogTable, (GrFog_t *)ft, GR_FOG_TABLE_SIZE * sizeof( FxU8 ) );
        }
        else
        {
            CopyMemory( Glide.FogTable, ft, GR_FOG_TABLE_SIZE * sizeof( FxU8 ) );
        }

        for ( i = 0; i < GR_FOG_TABLE_SIZE; i++ )
        {
            s_i = ( forth_root[ i & 3 ] >> ( 16 - ( i >> 2 ) ) );
            e_i = ( forth_root[ ( i + 1 ) & 3 ] >> ( 16 - ( ( i + 1 ) >> 2 ) ) );
            s = ft[ i ];
            e = ( ( i + 1 ) < GR_FOG_TABLE_SIZE ) ? ft[ i + 1 ] : 255;

            for ( j = s_i; j < e_i; j++ )
            {
                OpenGL.FogTable[ j ] = (BYTE)( s + ( e - s ) * ( j - s_i ) / ( e_i - s_i ) );
            }
        }
    }
}

//----------------------------------------------------------------
DLLEXPORT void __stdcall
grFogColorValue( GrColor_t fogcolor )
{
#ifdef PARTDONE
    GlideMsg( "grFogColorValue( %x )\n", fogcolor );
#endif

    RenderDrawTriangles( );

    Glide.State.FogColorValue = fogcolor;
    ConvertColorF( fogcolor, 
                   OpenGL.FogColor[ 0 ], 
                   OpenGL.FogColor[ 1 ], 
                   OpenGL.FogColor[ 2 ], 
                   OpenGL.FogColor[ 3 ] );
    glFogfv( GL_FOG_COLOR, &OpenGL.FogColor[0] );
}

//----------------------------------------------------------------
DLLEXPORT void __stdcall
grFogMode( GrFogMode_t mode )
{
#ifdef PARTDONE
    GlideMsg( "grFogMode( %d )\n", mode );
#endif

    static GrFogMode_t  modeSource, 
                        modeAdd;
    static GLfloat      ZeroColor[ 4 ] = { 0.0f, 0.0f, 0.0f, 0.0f };

    RenderDrawTriangles( );

    modeSource = mode & ( GR_FOG_WITH_TABLE | GR_FOG_WITH_ITERATED_ALPHA );
    modeAdd = mode & ( GR_FOG_MULT2 | GR_FOG_ADD2 );

    if ( modeSource )
    {
        OpenGL.Fog = true;
        if ( InternalConfig.FogCoordEXTEnable )
        {
            glEnable( GL_FOG );
        }
    }
    else
    {
        OpenGL.Fog = false;
        glDisable( GL_FOG );
    }

    switch ( modeAdd )
    {
    case GR_FOG_MULT2:
    case GR_FOG_ADD2:
        glFogfv( GL_FOG_COLOR, &ZeroColor[ 0 ] );
        break;

    default:
        glFogfv( GL_FOG_COLOR, &OpenGL.FogColor[ 0 ] );
        break;
    }
    
    Glide.State.FogMode = modeSource;
}

//----------------------------------------------------------------
DLLEXPORT void __stdcall
guFogGenerateExp( GrFog_t *fogtable, float density )
{
#ifdef PARTDONE
    GlideMsg( "guFogGenerateExp( ---, %-4.2f )\n", density );
#endif

    float Temp;

    for ( int i = 0; i < GR_FOG_TABLE_SIZE; i++ )
    {
        Temp = ( 1.0f - (float) exp( (- density) * guFogTableIndexToW( i ) ) ) * 255.0f;
        fogtable[ i ] = (BYTE) Temp;
    }
}

//----------------------------------------------------------------
DLLEXPORT void __stdcall
guFogGenerateExp2( GrFog_t *fogtable, float density )
{
#ifdef PARTDONE
    GlideMsg( "guFogGenerateExp2( ---, %-4.2f )\n", density );
#endif<commit_msg>Normalise fog table in GuFogGenerateExp<commit_after>//**************************************************************
//*            OpenGLide - Glide to OpenGL Wrapper
//*             http://openglide.sourceforge.net
//*
//*                      Fog Functions
//*
//*         OpenGLide is OpenSource under LGPL license
//*              Originaly made by <NAME>
//*      Modified by <NAME>idos (http://www.glidos.net)
//**************************************************************

#include <math.h>

#include "GlOgl.h"
#include "GLRender.h"


// extern functions
void ConvertColorB( GrColor_t GlideColor, BYTE &R, BYTE &G, BYTE &B, BYTE &A );
void ConvertColorF( GrColor_t GlideColor, float &R, float &G, float &B, float &A );
void MMXCopyMemory( void *Dst, void *Src, DWORD NumberOfBytes );

//*************************************************
//* download a fog table
//* Fog is applied after color combining and before alpha blending.
//*************************************************
DLLEXPORT void __stdcall
grFogTable( const GrFog_t *ft )
{
#ifdef DONE
    GlideMsg( "grFogTable( --- )\n" );
#endif

    DWORD   i, 
            j,
            s_i, 
            e_i,
            s, 
            e,
            forth_root[ 4 ] = { 0x10000, 0x1306f, 0x16a09, 0x1ae89 };

    if ( InternalConfig.FogEnable )
    {
        if ( InternalConfig.MMXEnable )
        {
            MMXCopyMemory( Glide.FogTable, (GrFog_t *)ft, GR_FOG_TABLE_SIZE * sizeof( FxU8 ) );
        }
        else
        {
            CopyMemory( Glide.FogTable, ft, GR_FOG_TABLE_SIZE * sizeof( FxU8 ) );
        }

        for ( i = 0; i < GR_FOG_TABLE_SIZE; i++ )
        {
            s_i = ( forth_root[ i & 3 ] >> ( 16 - ( i >> 2 ) ) );
            e_i = ( forth_root[ ( i + 1 ) & 3 ] >> ( 16 - ( ( i + 1 ) >> 2 ) ) );
            s = ft[ i ];
            e = ( ( i + 1 ) < GR_FOG_TABLE_SIZE ) ? ft[ i + 1 ] : 255;

            for ( j = s_i; j < e_i; j++ )
            {
                OpenGL.FogTable[ j ] = (BYTE)( s + ( e - s ) * ( j - s_i ) / ( e_i - s_i ) );
            }
        }
    }
}

//----------------------------------------------------------------
DLLEXPORT void __stdcall
grFogColorValue( GrColor_t fogcolor )
{
#ifdef PARTDONE
    GlideMsg( "grFogColorValue( %x )\n", fogcolor );
#endif

    RenderDrawTriangles( );

    Glide.State.FogColorValue = fogcolor;
    ConvertColorF( fogcolor, 
                   OpenGL.FogColor[ 0 ], 
                   OpenGL.FogColor[ 1 ], 
                   OpenGL.FogColor[ 2 ], 
                   OpenGL.FogColor[ 3 ] );
    glFogfv( GL_FOG_COLOR, &OpenGL.FogColor[0] );
}

//----------------------------------------------------------------
DLLEXPORT void __stdcall
grFogMode( GrFogMode_t mode )
{
#ifdef PARTDONE
    GlideMsg( "grFogMode( %d )\n", mode );
#endif

    static GrFogMode_t  modeSource, 
                        modeAdd;
    static GLfloat      ZeroColor[ 4 ] = { 0.0f, 0.0f, 0.0f, 0.0f };

    RenderDrawTriangles( );

    modeSource = mode & ( GR_FOG_WITH_TABLE | GR_FOG_WITH_ITERATED_ALPHA );
    modeAdd = mode & ( GR_FOG_MULT2 | GR_FOG_ADD2 );

    if ( modeSource )
    {
        OpenGL.Fog = true;
        if ( InternalConfig.FogCoordEXTEnable )
        {
            glEnable( GL_FOG );
        }
    }
    else
    {
        OpenGL.Fog = false;
        glDisable( GL_FOG );
    }

    switch ( modeAdd )
    {
    case GR_FOG_MULT2:
    case GR_FOG_ADD2:
        glFogfv( GL_FOG_COLOR, &ZeroColor[ 0 ] );
        break;

    default:
        glFogfv( GL_FOG_COLOR, &OpenGL.FogColor[ 0 ] );
        break;
    }
    
    Glide.State.FogMode = modeSource;
}

//----------------------------------------------------------------
DLLEXPORT void __stdcall
guFogGenerateExp( GrFog_t *fogtable, float density )
{
#ifdef PARTDONE
    GlideMsg( "guFogGenerateExp( ---, %-4.2f )\n", density );
#endif
    
    float f;
    float scale;
    float dp;
    
    dp = density * guFogTableIndexToW( GR_FOG_TABLE_SIZE - 1 );
    scale = 255.0F / ( 1.0F - (float) exp( -dp ) );
    
    for ( int i = 0; i < GR_FOG_TABLE_SIZE; i++ )
    {
        dp = density * guFogTableIndexToW( i );
        f = ( 1.0F - (float) exp( -dp ) ) * scale;
        
        if ( f > 255.0F )
        {
            f = 255.0F;
        }
        else if ( f < 0.0F )
        {
            f = 0.0F;
        }
        
        fogtable[i] = (GrFog_t) f;
    }
}

//----------------------------------------------------------------
DLLEXPORT void __stdcall
guFogGenerateExp2( GrFog_t *fogtable, float density )
{
#ifdef PARTDONE
    GlideMsg( "guFogGenerateExp2( ---, %-4.2f )\n", density );
#endif
{'fraction_non_alphanumeric': 0.22477477477477478, 'fraction_numerical': 0.017905405405405406, 'mean_word_length': 1.6159057437407953, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4278488', 'n_tokens_mistral': 3200, 'n_tokens_neox': 2991, 'n_words': 670}