This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

Changeset 329 for ps


Ignore:
Timestamp:
05/31/04 14:21:14 (21 years ago)
Author:
janwas
Message:

removed endian.* and rolled it into (w)sdl

Location:
ps/trunk/source/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/lib/sdl.h

    r216 r329  
    44# include <SDL/SDL.h>
    55# include <SDL/SDL_thread.h>
     6# include <SDL/SDL_endian.h>
     7    // if the compiler doesn't support inlining, this header will pull
     8    // in static bswap routines. doesn't matter - modern compilers
     9    // will strip them if unused, and this is more convenient than
     10    // another header that toggles between wsdl and SDL_endian.h.
    611#endif
  • ps/trunk/source/lib/sysdep/win/wsdl.cpp

    r293 r329  
    5858static u16 mouse_x, mouse_y;
    5959
     60
     61static void gamma_swap(bool restore_org);
     62
     63
    6064/*
    6165 * shared msg handler
     
    7781    case WM_ACTIVATE:
    7882        app_active = (wParam & 0xffff) != 0;
     83
     84        gamma_swap(!app_active);
    7985
    8086        if(fullscreen)
     
    374380static int wsdl_init()
    375381{
     382    // ignore BoundsChecker warnings here. subsystem is set to "Windows"
     383    // to avoid the OS opening a console on startup (ugly). that means
     384    // stdout isn't associated with a lowio handle; _close ends up
     385    // getting called with fd = -1. oh well, nothing we can do.
    376386    FILE* const ret = freopen("stdout.txt", "w", stdout);
    377387    if(!ret)
     
    489499
    490500
     501//////////////////////////////////////////////////////////////////////////////
     502
     503
     504static bool gamma_changed;
     505static u16 org_ramp[3][256];
     506static u16 cur_ramp[3][256];
     507
     508
    491509static int calc_gamma_ramp(float gamma, u16* ramp)
    492510{
     
    495513
    496514    // identity
    497     // (special-case it to make sure we get the exact value)
     515    // (special-case it to make sure we get exact values)
    498516    if(gamma == 1.0f)
    499517    {
     
    516534
    517535
     536static void gamma_swap(bool restore_org)
     537{
     538    if(gamma_changed)
     539    {
     540        void* ramp = (restore_org)? org_ramp : cur_ramp;
     541        SetDeviceGammaRamp(hDC, ramp);
     542    }
     543}
     544
     545
    518546int SDL_SetGamma(float r, float g, float b)
    519547{
    520     u16 ramp[3][256];
    521     CHECK_ERR(calc_gamma_ramp(r, ramp[0]));
    522     CHECK_ERR(calc_gamma_ramp(g, ramp[1]));
    523     CHECK_ERR(calc_gamma_ramp(b, ramp[2]));
    524     return SetDeviceGammaRamp(hDC, ramp)? 0 : -1;
    525 }
    526 
     548    if(!gamma_changed)
     549        if(!GetDeviceGammaRamp(hDC, org_ramp))
     550            return -1;
     551
     552    CHECK_ERR(calc_gamma_ramp(r, cur_ramp[0]));
     553    CHECK_ERR(calc_gamma_ramp(g, cur_ramp[1]));
     554    CHECK_ERR(calc_gamma_ramp(b, cur_ramp[2]));
     555
     556    if(!SetDeviceGammaRamp(hDC, cur_ramp))
     557        return -1;
     558
     559    gamma_changed = true;
     560    return 0;
     561}
     562
     563
     564//////////////////////////////////////////////////////////////////////////////
     565
     566
     567// implement only if the header hasn't mapped SDL_Swap* to intrinsics
     568
     569#ifndef SDL_Swap16
     570u16 SDL_Swap16(const u16 x)
     571{
     572    return (u16)(((x & 0xff) << 8) | (x >> 8));
     573}
     574#endif
     575
     576#ifndef SDL_Swap32
     577u32 SDL_Swap32(const u32 x)
     578{
     579    return (x << 24) |
     580           (x >> 24) |
     581           ((x << 8) & 0x00ff0000) |
     582           ((x >> 8) & 0x0000ff00);
     583}
     584#endif
     585
     586#ifndef SDL_Swap64
     587u64 SDL_Swap64(const u64 x)
     588{
     589    const u32 lo = (u32)(x & 0xffffffff);
     590    const u32 hi = (u32)(x >> 32);
     591    u64 ret = SDL_Swap32(lo);
     592    ret <<= 32;
     593        // careful: must shift var of type u64, not u32
     594    ret |= SDL_Swap32(hi);
     595    return ret;
     596}
     597#endif
     598
     599//////////////////////////////////////////////////////////////////////////////
    527600
    528601
    529602void SDL_Quit()
    530603{
     604    gamma_swap(true);
     605
    531606    if(hDC != INVALID_HANDLE_VALUE)
    532607    {
  • ps/trunk/source/lib/sysdep/win/wsdl.h

    r258 r329  
    9797
    9898
     99//////////////////////////////////////////////////////////////////////////////
     100
     101
     102#ifdef linux
     103# include <asm/byteorder.h>
     104# ifdef __arch__swab16
     105#  define SDL_Swap16  __arch__swab16
     106# endif
     107# ifdef __arch__swab32
     108#  define SDL_Swap32  __arch__swab32
     109# endif
     110#endif
     111
     112#ifdef _MSC_VER
     113# define SDL_Swap16 _byteswap_ushort
     114# define SDL_Swap32 _byteswap_ulong
     115# define SDL_Swap64 _byteswap_uint64
     116#endif
     117
     118#ifndef SDL_Swap16
     119extern u16 SDL_Swap16(u16);
     120#endif
     121
     122#ifndef SDL_Swap32
     123extern u32 SDL_Swap32(u32);
     124#endif
     125
     126#ifndef SDL_Swap64
     127extern u64 SDL_Swap64(u64);
     128#endif
     129
     130
     131//////////////////////////////////////////////////////////////////////////////
    99132
    100133
Note: See TracChangeset for help on using the changeset viewer.