Changeset 638 for trollforge/lastmeasure


Ignore:
Timestamp:
01/20/12 00:45:53 (17 months ago)
Author:
sam
Message:

Remove the need for redundant preprocessor stuff. Add comments here and there.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trollforge/lastmeasure/server/lmresource.h

    r637 r638  
    1313//#include "lmutil.h" 
    1414 
    15 #ifndef SOFT 
    16 static size_t imagecount = 33; 
     15#ifdef SOFT 
     16#   define IMAGES_PREFIX "/soft/" 
    1717#else 
    18 static size_t imagecount = 13; 
     18#   define IMAGES_PREFIX "/images/" 
    1919#endif 
    20  
    21 static size_t audiocount = 16; 
    2220 
    2321static char const *staticnames[] = 
    2422{ 
    25 #ifndef SOFT 
    26     /* Static images - 33 */ 
     23    /* Shock pictures */ 
    2724    "/images/awesome.jpg",    "/images/Pain4.jpg", 
    2825    "/images/balloonboy.jpg", "/images/Pain5.jpg", 
     
    4239    "/images/Pain3.jpg",      "/images/jar.jpg", 
    4340    "/images/lunch.jpg", 
    44 #else 
    45     /* Static soft images - 13 */ 
     41 
     42    /* Soft images */ 
    4643    "/soft/christmas.jpg",    "/soft/pillowfight.jpg", 
    4744    "/soft/eww.jpg",          "/soft/pooped.jpg", 
     
    5148    "/soft/loopback.jpg",     "/soft/weightlifter.jpg", 
    5249    "/soft/ouch.jpg", 
    53 #endif 
    54  
    55     /* Static sound samples - 16 */ 
     50 
     51    /* Static sound samples */ 
    5652    "/audio/abez2.wav",    "/audio/abez.wav", 
    5753    "/audio/blackman.wav", "/audio/eska.wav", 
     
    154150 
    155151    "  <body style=\"background-image: url(http://" << host 
    156 #ifndef SOFT 
    157           << RandomAsset("/images/") << "); background-color: #FFFFFF;\"" 
    158 #else 
    159           << RandomAsset("/soft/") << "); background-color: #FFFFFF;\"" 
    160 #endif 
     152          << RandomAsset(IMAGES_PREFIX) << "); background-color: #FFFFFF;\"" 
    161153    "\r\n        onload=\"bookmark(); noframes(); load_goatse(); document.getElementById('goatse').innerHTML = ''; movew0w(); "; 
    162154        if (is_ie6) 
     
    217209        { 
    218210            data << 
    219  
    220             "<div>\r\n" 
    221211// This object plays the "hey everybody, I'm looking at gay porno!" sound 
    222212            "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" " 
     
    227217            "<script type=\"text/javascript\">\r\n" 
    228218            "<!--\r\n" 
    229             "var audio = new Array();\r\n" 
    230             "var audiocount = " << audiocount << ";\r\n"; 
    231  
    232             for(size_t i = 0; i < audiocount; i++) { 
    233                 data << "    audio[" << i << "] = 'http://" << host << "" << staticnames[i+imagecount] << "';\r\n"; 
     219            "var audio = new Array();\r\n"; 
     220 
     221            for (int i = FindAssetIndex("/audio/", -1), n = 0; 
     222                 i < (int)NSTATICS; 
     223                 i = FindAssetIndex("/audio/", i)) 
     224            { 
     225                data << "    audio[" << n << "] = 'http://" 
     226                     << host << "" << staticnames[i] << "';\r\n"; 
    234227            } 
    235228 
    236229            data << 
    237  
    238             "for (i = 0; i < audiocount; i++) {\r\n" 
     230            "for (i = 0; i < audio.length; i++) {\r\n" 
    239231            "    setTimeout('document.getElementById(\"audio\").innerHTML += \\'<embed src=\"' + audio[i] + '\" loop=\"true\" />\\';', 6000 * (i/2));\r\n" 
    240232            "}\r\n" 
     
    260252             << host << "/" << rand() 
    261253             << "\">something else</a>.</p>" 
    262 #ifndef SOFT 
    263              << "<img src=\"http://" << host << "" << RandomAsset("/images/") << "\" />" 
    264 #else 
    265              << "<img src=\"http://" << host << "" << RandomAsset("/soft/") << "\" />" 
    266 #endif 
     254             << "<img src=\"http://" << host << "" << RandomAsset(IMAGES_PREFIX) << "\" />" 
    267255             << "</body></html>"; 
    268256        return Response(data.str(), "text/html"); 
     
    449437    } 
    450438 
     439    /* Pick a random asset starting with @prefix. For instance if @prefix 
     440     * is "/images/" we pick one at random and if it starts with "/images/" 
     441     * we return it. Otherwise, pick another one. Repeat 32 times. */ 
    451442    static std::string RandomAsset(char const *prefix) 
    452443    { 
    453444        size_t prefixlen = strlen(prefix); 
    454445 
    455         for (size_t i = 0; i < 32; i++) // XXX Why 32? 
     446        for (int i = 0; i < 32; i++) 
    456447        { 
    457448            char const *name = staticnames[rand() % NSTATICS]; 
     
    463454    } 
    464455 
     456    /* Find the asset index after @previous that matches @prefix. This can 
     457     * be used as an iterator. To get the first matching asset, use -1 as 
     458     * an argument. */ 
     459    static int FindAssetIndex(char const *prefix, int previous) 
     460    { 
     461        if (previous < -1 || previous > (int)NSTATICS) 
     462            return NSTATICS; 
     463 
     464        size_t prefixlen = strlen(prefix); 
     465 
     466        while (++previous < (int)NSTATICS) 
     467        { 
     468            char const *name = staticnames[previous]; 
     469            if (!strncmp(name, prefix, prefixlen)) 
     470                break; 
     471        } 
     472 
     473        return previous; 
     474    } 
     475 
    465476    static std::string MoveAround(size_t width, size_t height, char const *host) 
    466477    { 
     
    468479 
    469480        ret << 
    470  
    471481        "<script type=\"text/javascript\">\r\n" 
    472482        "<!--\r\n" 
    473         "    var images = new Array();\r\n" 
    474         "    var imagecount = " << imagecount << ";\r\n"; 
    475  
    476         for(size_t i = 0; i < imagecount; i++) 
    477         { 
    478             ret << "    images[" << i << "] = 'http://" << host << "" << staticnames[i] << "';\r\n"; 
     483        "    var images = new Array();\r\n"; 
     484 
     485        for (int i = FindAssetIndex(IMAGES_PREFIX, -1), n = 0; 
     486             i < (int)NSTATICS; 
     487             i = FindAssetIndex(IMAGES_PREFIX, i)) 
     488        { 
     489            ret << "    images[" << n << "] = 'http://" << host << "" << staticnames[i] << "';\r\n"; 
    479490        } 
    480491 
     
    505516        "    }\r\n" 
    506517 
    507         "    document.body.background = images[(Math.floor(curstep) % imagecount) + 1];\r\n" 
     518        "    document.body.background = images[(Math.floor(curstep) % images.length) + 1];\r\n" 
    508519        "    setTimeout(\"movew0w()\", delay);\r\n" 
    509520        "}\r\n" 
Note: See TracChangeset for help on using the changeset viewer.