Ticket #4441: patch.diff

File patch.diff, 4.5 KB (added by OMGtechy, 7 years ago)
  • binaries/data/mods/public/gui/credits/texts/programming.json

     
    144144            {"nick": "Offensive ePeen", "name": "Jared Ryan Bills"},
    145145            {"nick": "Ols", "name": "Oliver Whiteman"},
    146146            {"nick": "olsner", "name": "Simon Brenner"},
     147            {"nick": "OMGtechy", "name": "Joshua Gerrard"},
    147148            {"nick": "otero"},
    148149            {"name": "Nick Owens"},
    149150            {"nick": "Palaxin", "name": "David A. Freitag"},
  • source/lib/sysdep/gfx.cpp

     
    1 /* Copyright (c) 2015 Wildfire Games
     1/* Copyright (c) 2017 Wildfire Games
    22 *
    33 * Permission is hereby granted, free of charge, to any person obtaining
    44 * a copy of this software and associated documentation files (the
     
    3434# include "lib/sysdep/os/win/wgfx.h"
    3535#endif
    3636
     37namespace {
     38    // takes no ownership
     39    struct ReplacementPhrase {
     40        const wchar_t* longPhrase;
     41        const wchar_t* shortPhrase;
     42    };
    3743
     44    void ShortenWideStringPrefix(std::wstring& toShorten,
     45                                 ReplacementPhrase phrase) {
     46
     47        const size_t phraseLength = wcslen(phrase.longPhrase);
     48
     49        // we only care if it matches the start of the string,
     50        // hence the 0 == ... rather than npos != ...
     51        const bool startsWithPhrase = (0 == toShorten.find(phrase.longPhrase,
     52                                                           0, // start at character 0
     53                                                           phraseLength));
     54
     55        if(startsWithPhrase) {
     56                toShorten.replace(0,
     57                                  phraseLength,
     58                                  phrase.shortPhrase);
     59        }
     60    }
     61
     62    template <size_t ArraySize>
     63    void ShortenWideStringPrefixes(std::wstring& toShorten,
     64                                   std::array<ReplacementPhrase, ArraySize> phrases) {
     65        for(auto phrase : phrases) {
     66            ShortenWideStringPrefix(toShorten, phrase);
     67        }
     68    }
     69}
     70
    3871namespace gfx {
    3972
    4073std::wstring CardName()
    4174{
    42     // GL_VENDOR+GL_RENDERER are good enough here, so we don't use wgfx_CardName,
    43     // plus that can cause crashes with Nvidia Optimus and some netbooks
    44     // see http://trac.wildfiregames.com/ticket/1952
    45     //     http://trac.wildfiregames.com/ticket/1575
    46     wchar_t cardName[128];
    47     const char* vendor   = (const char*)glGetString(GL_VENDOR);
    48     const char* renderer = (const char*)glGetString(GL_RENDERER);
    49     // (happens if called before ogl_Init or between glBegin and glEnd.)
    50     if(!vendor || !renderer)
    51         return L"";
    52     swprintf_s(cardName, ARRAY_SIZE(cardName), L"%hs %hs", vendor, renderer);
     75    std::wstring cardName;
    5376
     77    {
     78        // GL_VENDOR+GL_RENDERER are good enough here, so we don't use wgfx_CardName,
     79        // plus that can cause crashes with Nvidia Optimus and some netbooks
     80        // see http://trac.wildfiregames.com/ticket/1952
     81        //     http://trac.wildfiregames.com/ticket/1575
     82        const char* const vendor   = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
     83        const char* const renderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER));
     84
     85        // (happens if called before ogl_Init or between glBegin and glEnd.)
     86        if(!vendor || !renderer) {
     87            return L"";
     88        }
     89
     90        wchar_t cardNameBuffer[128];
     91        swprintf_s(cardNameBuffer, ARRAY_SIZE(cardNameBuffer), L"%hs %hs", vendor, renderer);
     92
     93        cardName.assign(cardNameBuffer);
     94    }
     95
    5496    // remove crap from vendor names. (don't dare touch the model name -
    5597    // it's too risky, there are too many different strings)
    56 #define SHORTEN(what, charsToKeep)\
    57     if(!wcsncmp(cardName, what, ARRAY_SIZE(what)-1))\
    58         memmove(cardName+charsToKeep, cardName+ARRAY_SIZE(what)-1, (wcslen(cardName)-(ARRAY_SIZE(what)-1)+1)*sizeof(wchar_t));
    59     SHORTEN(L"ATI Technologies Inc.", 3);
    60     SHORTEN(L"NVIDIA Corporation", 6);
    61     SHORTEN(L"S3 Graphics", 2);                 // returned by EnumDisplayDevices
    62     SHORTEN(L"S3 Graphics, Incorporated", 2);   // returned by GL_VENDOR
    63 #undef SHORTEN
    6498
     99    ShortenWideStringPrefixes(
     100        cardName,
     101        std::array<ReplacementPhrase, 4> {
     102            ReplacementPhrase { L"ATI Technologies Inc.", L"ATI" },
     103                              { L"NVIDIA Corporation", L"NVIDIA" },
     104                              { L"S3 Graphics", L"S3" },          // returned by EnumDisplayDevices
     105                              { L"S3 Graphics, Incorporated", L"S3" } // returned by GL_VENDOR
     106        }
     107    );
     108
    65109    return cardName;
    66110}
    67111