Changeset 50

Show
Ignore:
Timestamp:
02/12/08 14:22:08 (4 years ago)
Author:
barrett9h
Message:

updated to new dmd version, plus other misc changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/GNUmakefile

    r11 r50  
    1010 
    1111backup: 
    12     @base=qonkd-src.$(shell date +%Y%m%d); n=1; \ 
     12    dir=$(shell basename `pwd`); base=qonkd-src.$(shell date +%Y%m%d); n=1; \ 
    1313    while true; do true; tgzname=$$base-$$n.tgz; test -s $$tgzname || break; let n=n+1; done; \ 
    14     tar -C .. -czf $$tgzname `basename $(PWD)`
     14    tar -C .. -czf $$tgzname $$dir
    1515        --exclude .svn \ 
    1616        --exclude $(BUILD_DIR) \ 
    1717        --exclude 'qonkd-src.*' \ 
    18         --exclude $(TARGET) \ 
     18        --exclude ./$(TARGET) \ 
    1919        --exclude core --exclude 'core.*' \ 
    2020        --exclude '*.ttf'; \ 
  • trunk/derelict/sdl/audio.d

    r44 r50  
    3232module derelict.sdl.audio; 
    3333 
     34private import std.string; 
    3435private import derelict.sdl.types; 
    3536private import derelict.sdl.rwops; 
     
    110111SDL_AudioSpec* SDL_LoadWAV(char *file, SDL_AudioSpec *spec, Uint8 **buf, Uint32 *len) 
    111112{ 
    112     return SDL_LoadWAV_RW(SDL_RWFromFile(file, "rb"), 1, spec, buf, len); 
     113    return SDL_LoadWAV_RW(SDL_RWFromFile(file, std.string.toStringz("rb")), 1, spec, buf, len); 
    113114} 
    114115 
  • trunk/derelict/sdl/video.d

    r44 r50  
    3232module derelict.sdl.video; 
    3333 
     34private import std.string; 
    3435private import derelict.sdl.types; 
    3536private import derelict.sdl.mutex; 
     
    203204SDL_Surface* SDL_LoadBMP(char *file) 
    204205{ 
    205     return SDL_LoadBMP_RW(SDL_RWFromFile(file, "rb"), 1); 
     206    return SDL_LoadBMP_RW(SDL_RWFromFile(file, std.string.toStringz("rb")), 1); 
    206207} 
    207208 
    208209int SDL_SaveBMP(SDL_Surface *surfave, char *file) 
    209210{ 
    210     return SDL_SaveBMP_RW(surfave, SDL_RWFromFile(file,"wb"), 1); 
     211    return SDL_SaveBMP_RW(surfave, SDL_RWFromFile(file,std.string.toStringz("wb")), 1); 
    211212} 
    212213 
  • trunk/derelict/util/exception.d

    r5 r50  
    3838{ 
    3939public: 
    40     this(char[] msg) 
     40    this(string msg) 
    4141    { 
    4242        super(msg); 
     
    5252public: 
    5353 
    54     this(char[] sharedLibName) 
     54    this(string sharedLibName) 
    5555    { 
    5656        super("Failed to load shared library " ~ sharedLibName); 
    57         _sharedLibName = sharedLibName.dup
     57        _sharedLibName = sharedLibName
    5858    } 
    5959 
    60     char[] sharedLibName() 
     60    string sharedLibName() 
    6161    { 
    6262        return _sharedLibName; 
     
    6464 
    6565private: 
    66     char[] _sharedLibName; 
     66    string _sharedLibName; 
    6767} 
    6868 
     
    7575{ 
    7676public: 
    77     this(char[] msg) 
     77    this(string msg) 
    7878    { 
    7979        super(msg); 
     
    8181    } 
    8282 
    83     this(char[] sharedLibName, char[] procName) 
     83    this(string sharedLibName, string procName) 
    8484    { 
    8585        super("Failed to load proc " ~ procName ~ " from shared library " ~ sharedLibName); 
    86         _procName = procName.dup
     86        _procName = procName
    8787    } 
    8888 
    89     char[] procName() 
     89    string procName() 
    9090    { 
    9191        return _procName; 
     
    9393 
    9494private: 
    95     char[] _procName; 
     95    string _procName; 
    9696} 
    9797 
     
    104104public: 
    105105 
    106     this(char[] sharedLibName) 
     106    this(string sharedLibName) 
    107107    { 
    108108        super("Attempted to use handle to unloaded shared library " ~ sharedLibName); 
    109         _sharedLibName = sharedLibName.dup
     109        _sharedLibName = sharedLibName
    110110    } 
    111111 
    112     char[] sharedLibName() 
     112    string sharedLibName() 
    113113    { 
    114114        return _sharedLibName; 
     
    116116 
    117117private: 
    118     char[] _sharedLibName; 
     118    string _sharedLibName; 
    119119} 
    120120 
     
    128128* to be thrown. 
    129129*/ 
    130 typedef bool function(char[] libName, char[] procName) MissingProcCallback; 
     130typedef bool function(string libName, string procName) MissingProcCallback; 
    131131 
    132132private MissingProcCallback missingProcCallback; 
    133133 
    134 public void Derelict_HandleMissingProc(char[] libName, char[] procName) 
     134public void Derelict_HandleMissingProc(string libName, string procName) 
    135135{ 
    136136    bool result = false; 
  • trunk/derelict/util/loader.d

    r44 r50  
    11/* 
    2  * Copyright (c) 2005-2006 Derelict Developers 
     2 * Copyright (c) 2004-2007 Derelict Developers 
    33 * All rights reserved. 
    44 * 
     
    5151} 
    5252 
    53 version (DerelictUseStdLoader) { 
     53 
     54private alias void* SharedLibHandle; 
     55 
     56//============================================================================== 
     57class SharedLib 
     58
     59public: 
     60    string name() 
     61    { 
     62        return _name; 
     63    } 
     64 
     65private: 
     66    SharedLibHandle _handle; 
     67    string _name; 
     68 
     69    this(SharedLibHandle handle, string name) 
     70    { 
     71        _handle = handle; 
     72        _name = name; 
     73    } 
     74
     75//============================================================================== 
     76SharedLib Derelict_LoadSharedLib(string libName) 
     77in 
     78
     79    assert(libName !is null); 
     80
     81body 
     82
     83    return Platform_LoadSharedLib(libName); 
     84
     85 
     86//============================================================================== 
     87SharedLib Derelict_LoadSharedLib(string[] libNames) 
     88in 
     89
     90    assert(libNames !is null); 
     91
     92body 
     93
     94    SharedLibLoadException exception = null; 
     95    SharedLib lib = null; 
     96 
     97    foreach(string libName; libNames) 
     98    { 
     99        try 
     100        { 
     101            lib = Derelict_LoadSharedLib(libName); 
     102            if(lib !is null) break; 
     103        } 
     104        catch(SharedLibLoadException slle) 
     105        { 
     106            exception = slle; 
     107        } 
     108    } 
     109    if(lib is null) 
     110        throw exception; 
     111 
     112    return lib; 
     113
     114 
     115//============================================================================== 
     116void Derelict_UnloadSharedLib(SharedLib lib) 
     117
     118    if(lib !is null && lib._handle !is null) 
     119        Platform_UnloadSharedLib(lib); 
     120
     121//============================================================================== 
     122void* Derelict_GetProc(SharedLib lib, string procName) 
     123in 
     124
     125    assert(lib !is null); 
     126    assert(procName !is null); 
     127
     128body 
     129
     130    if(lib._handle is null) 
     131        throw new InvalidSharedLibHandleException(lib._name); 
     132    return Platform_GetProc(lib, procName); 
     133
     134//============================================================================== 
     135version(Windows) 
     136
     137    private import derelict.util.wintypes; 
     138 
     139    SharedLib Platform_LoadSharedLib(string libName) 
     140    { 
     141        HMODULE hlib = LoadLibraryA(toCString(libName)); 
     142        if(null is hlib) 
     143            throw new SharedLibLoadException(libName); 
     144 
     145        return new SharedLib(hlib, libName); 
     146    } 
     147 
     148    void Platform_UnloadSharedLib(SharedLib lib) 
     149    { 
     150        FreeLibrary(cast(HMODULE)lib._handle); 
     151        lib._handle = null; 
     152    } 
     153 
     154    void* Platform_GetProc(SharedLib lib, string procName) 
     155    { 
     156        void* proc = GetProcAddress(cast(HMODULE)lib._handle, toCString(procName)); 
     157        if(null is proc) 
     158            Derelict_HandleMissingProc(lib._name, procName); 
     159 
     160        return proc; 
     161    } 
     162 
     163
     164else version(Nix) 
     165
    54166    version(Tango) 
    55167    { 
    56         static assert(0, "Cannot use std.loader with Tango"); 
    57     } 
    58  
    59     import std.loader; 
    60  
    61     //============================================================================== 
    62     class SharedLib 
    63     { 
    64     public: 
    65         char[] name() 
     168        private import tango.sys.Common; 
     169    } 
     170    else version(linux) 
     171    { 
     172        private import std.c.linux.linux; 
     173    } 
     174    else 
     175    { 
     176        extern(C) 
    66177        { 
    67             return _name; 
    68         } 
    69  
    70     private: 
    71         char[]      _name; 
    72  
    73         void* delegate(in char[] symbolName)    getSymbolDg; 
    74         Object theLib; 
    75  
    76         private void unload() { 
    77             if (theLib) { 
    78                 delete theLib; 
    79                 theLib = null; 
    80                 getSymbolDg = null; 
    81             } 
    82         } 
    83  
    84  
    85         void* getSymbol(char[] symName) { 
    86             if (theLib !is null) return getSymbolDg(symName); 
    87             else return null; 
    88         } 
    89  
    90  
    91         this(Object theLib, void* delegate(in char[])   getSymbolDg, char[] name) 
    92         in { 
    93             assert (theLib !is null); 
    94             assert (getSymbolDg !is null); 
    95         } 
    96         body { 
    97             this.theLib = theLib; 
    98             this.getSymbolDg = getSymbolDg; 
    99             this._name = name; 
    100         } 
    101     } 
    102     //============================================================================== 
    103     SharedLib Derelict_LoadSharedLib(char[] libName) 
    104     in 
    105     { 
    106         assert(libName !is null); 
    107     } 
    108     body 
    109     { 
    110         try { 
    111             auto ExeModule exeMod = new ExeModule(libName); 
    112             auto res = new SharedLib(exeMod, &exeMod.getSymbol, libName); 
    113             exeMod = null;      // fool the auto 
    114             return res; 
    115         } 
    116         catch (ExeModuleException exc) { 
    117             throw new SharedLibLoadException(libName); 
    118         } 
    119     } 
    120  
    121     //============================================================================== 
    122     SharedLib Derelict_LoadSharedLib(char[][] libNames) 
    123     in 
    124     { 
    125         assert(libNames !is null); 
    126     } 
    127     body 
    128     { 
    129         SharedLibLoadException exception = null; 
    130         SharedLib lib = null; 
    131  
    132         foreach(char[] libName; libNames) 
    133         { 
    134             try 
    135             { 
    136                 lib = Derelict_LoadSharedLib(libName); 
    137             } 
    138             catch(SharedLibLoadException slle) 
    139             { 
    140                 exception = slle; 
    141             } 
    142         } 
    143         if(lib is null) 
    144             throw exception; 
    145  
    146         return lib; 
    147     } 
    148  
    149     //============================================================================== 
    150     void Derelict_UnloadSharedLib(SharedLib lib) 
    151     { 
    152         if(lib !is null) lib.unload(); 
    153     } 
    154     //============================================================================== 
    155     void* Derelict_GetProc(SharedLib lib, char[] procName) 
    156     in 
    157     { 
    158         assert(lib !is null); 
    159         assert(procName !is null); 
    160     } 
    161     body 
    162     { 
    163         void* proc = lib.getSymbol(procName); 
    164         if (proc is null) { 
     178            /* From <dlfcn.h> 
     179            *  See http://www.opengroup.org/onlinepubs/007908799/xsh/dlsym.html 
     180            */ 
     181 
     182            const int RTLD_NOW = 2; 
     183 
     184            void *dlopen(char* file, int mode); 
     185            int dlclose(void* handle); 
     186            void *dlsym(void* handle, char* name); 
     187            char* dlerror(); 
     188        } 
     189    } 
     190 
     191    SharedLib Platform_LoadSharedLib(string libName) 
     192    { 
     193        void* hlib = dlopen(toCString(libName), RTLD_NOW); 
     194        if(null is hlib) 
     195            throw new SharedLibLoadException("Failed to load shared library " ~ libName); 
     196 
     197        return new SharedLib(hlib, libName); 
     198    } 
     199 
     200    void Platform_UnloadSharedLib(SharedLib lib) 
     201    { 
     202        dlclose(lib._handle); 
     203        lib._handle = null; 
     204    } 
     205 
     206    void* Platform_GetProc(SharedLib lib, string procName) 
     207    { 
     208        void* proc = dlsym(lib._handle, toCString(procName)); 
     209        if(null is proc) 
    165210            Derelict_HandleMissingProc(lib._name, procName); 
    166         } 
     211 
    167212        return proc; 
    168213    } 
    169     //============================================================================== 
    170 
    171 //============================================================================== 
    172 else { 
    173     private alias void* SharedLibHandle; 
    174  
    175     //============================================================================== 
    176     class SharedLib 
    177     { 
    178     public: 
    179         char[] name() 
    180         { 
    181             return _name; 
    182         } 
    183  
    184     private: 
    185         SharedLibHandle _handle; 
    186         char[] _name; 
    187  
    188         this(SharedLibHandle handle, char[] name) 
    189         { 
    190             _handle = handle; 
    191             _name = name; 
    192         } 
    193     } 
    194     //============================================================================== 
    195     SharedLib Derelict_LoadSharedLib(char[] libName) 
    196     in 
    197     { 
    198         assert(libName !is null); 
    199     } 
    200     body 
    201     { 
    202         return Platform_LoadSharedLib(libName); 
    203     } 
    204  
    205     //============================================================================== 
    206     SharedLib Derelict_LoadSharedLib(char[][] libNames) 
    207     in 
    208     { 
    209         assert(libNames !is null); 
    210     } 
    211     body 
    212     { 
    213         SharedLibLoadException exception = null; 
    214         SharedLib lib = null; 
    215  
    216         foreach(char[] libName; libNames) 
    217         { 
    218             try 
    219             { 
    220                 lib = Derelict_LoadSharedLib(libName); 
    221             } 
    222             catch(SharedLibLoadException slle) 
    223             { 
    224                 exception = slle; 
    225             } 
    226         } 
    227         if(lib is null) 
    228             throw exception; 
    229  
    230         return lib; 
    231     } 
    232  
    233     //============================================================================== 
    234     void Derelict_UnloadSharedLib(SharedLib lib) 
    235     { 
    236         if(lib !is null && lib._handle !is null) 
    237             Platform_UnloadSharedLib(lib); 
    238     } 
    239     //============================================================================== 
    240     void* Derelict_GetProc(SharedLib lib, char[] procName) 
    241     in 
    242     { 
    243         assert(lib !is null); 
    244         assert(procName !is null); 
    245     } 
    246     body 
    247     { 
    248         if(lib._handle is null) 
    249             throw new InvalidSharedLibHandleException(lib._name); 
    250         return Platform_GetProc(lib, procName); 
    251     } 
    252     //============================================================================== 
    253     version(Windows) 
    254     { 
    255         private import derelict.util.wintypes; 
    256  
    257         SharedLib Platform_LoadSharedLib(char[] libName) 
    258         { 
    259             HMODULE hlib = LoadLibraryA(toCString(libName)); 
    260             if(null is hlib) 
    261                 throw new SharedLibLoadException(libName); 
    262  
    263             return new SharedLib(hlib, libName); 
    264         } 
    265  
    266         void Platform_UnloadSharedLib(SharedLib lib) 
    267         { 
    268             FreeLibrary(cast(HMODULE)lib._handle); 
    269             lib._handle = null; 
    270         } 
    271  
    272         void* Platform_GetProc(SharedLib lib, char[] procName) 
    273         { 
    274             void* proc = GetProcAddress(cast(HMODULE)lib._handle, toCString(procName)); 
    275             if(null is proc) 
    276                 Derelict_HandleMissingProc(lib._name, procName); 
    277  
    278             return proc; 
    279         } 
    280  
    281     } 
    282     else version(Nix) 
    283     { 
    284         version(Tango) 
    285         { 
    286             private import tango.sys.Common; 
    287         } 
    288         else version(linux) 
    289         { 
    290             private import std.c.linux.linux; 
    291         } 
    292         else 
    293         { 
    294             extern(C) 
    295             { 
    296                 /* From <dlfcn.h> 
    297                 *  See http://www.opengroup.org/onlinepubs/007908799/xsh/dlsym.html 
    298                 */ 
    299  
    300                 const int RTLD_NOW = 2; 
    301  
    302                 void *dlopen(char* file, int mode); 
    303                 int dlclose(void* handle); 
    304                 void *dlsym(void* handle, char* name); 
    305                 char* dlerror(); 
    306             } 
    307         } 
    308  
    309         SharedLib Platform_LoadSharedLib(char[] libName) 
    310         { 
    311             void* hlib = dlopen(toCString(libName), RTLD_NOW); 
    312             if(null is hlib) 
    313                 throw new SharedLibLoadException("Failed to load shared library " ~ libName); 
    314  
    315             return new SharedLib(hlib, libName); 
    316         } 
    317  
    318         void Platform_UnloadSharedLib(SharedLib lib) 
    319         { 
    320             dlclose(lib._handle); 
    321             lib._handle = null; 
    322         } 
    323  
    324         void* Platform_GetProc(SharedLib lib, char[] procName) 
    325         { 
    326             void* proc = dlsym(lib._handle, toCString(procName)); 
    327             if(null is proc) 
    328                 Derelict_HandleMissingProc(lib._name, procName); 
    329  
    330             return proc; 
    331         } 
    332     } 
    333     else 
    334     { 
    335         static assert(0); 
    336     } 
     214
     215else 
     216
     217    static assert(0); 
    337218} 
    338219 
     
    340221 
    341222struct GenericLoader { 
    342     void setup(char[] winLibs, char[] linLibs, char[] macLibs, void function(SharedLib) userLoad, char[] versionStr = "") { 
     223    void setup(string winLibs, string linLibs, string macLibs, void function(SharedLib) userLoad, string versionStr = "") { 
    343224        assert (userLoad !is null); 
    344225        this.winLibs = winLibs; 
     
    349230    } 
    350231 
    351     void load(char[] libNameString = null) 
     232    void load(string libNameString = null) 
    352233    { 
    353234        if (myLib !is null) { 
     
    367248            } 
    368249            else version(darwin) { 
    369                libNameString = macLibs; 
     250                libNameString = macLibs; 
    370251            } 
    371              
     252 
    372253            if(libNameString is null || libNameString == "") 
    373254            { 
    374                throw new DerelictException("Invalid library name"); 
     255                throw new DerelictException("Invalid library name"); 
    375256            } 
    376257        } 
    377258 
    378         char[][] libNames = libNameString.splitStr(","); 
    379         foreach (inout char[] l; libNames) { 
     259        string[] libNames = libNameString.splitStr(","); 
     260        foreach (inout string l; libNames) { 
    380261            l = l.stripWhiteSpace(); 
    381262        } 
    382263 
     264        load(libNames); 
     265    } 
     266 
     267    void load(string[] libNames) 
     268    { 
    383269        myLib = Derelict_LoadSharedLib(libNames); 
     270 
     271        if(userLoad is null) 
     272        { 
     273            // this should never, ever, happen 
     274            throw new DerelictException("Something is horribly wrong -- internal load function not configured"); 
     275        } 
    384276        userLoad(myLib); 
    385277    } 
    386278 
    387     char[] versionString() 
     279    string versionString() 
    388280    { 
    389281        return versionStr; 
     
    398290    } 
    399291 
     292    bool loaded() 
     293    { 
     294        return (myLib !is null); 
     295    } 
     296 
     297    string libName() 
     298    { 
     299        return loaded ? myLib.name : null; 
     300    } 
     301 
    400302    static ~this() 
    401303    { 
     
    409311 
    410312        SharedLib myLib; 
    411         char[] winLibs; 
    412         char[] linLibs; 
    413         char[] macLibs; 
    414         char[] versionStr = ""; 
     313        string winLibs; 
     314        string linLibs; 
     315        string macLibs; 
     316        string versionStr = ""; 
    415317 
    416318        void function(SharedLib) userLoad; 
     
    429331    } 
    430332 
    431     private SharedLib myLib() { 
    432         return dependence.myLib; 
    433     } 
    434  
    435333    void load() 
    436334    { 
    437         assert (myLib !is null); 
    438         userLoad(myLib); 
    439     } 
    440  
    441     char[] versionString() 
     335        assert (dependence.loaded); 
     336        userLoad(dependence.myLib); 
     337    } 
     338 
     339    string versionString() 
    442340    { 
    443341        return dependence.versionString; 
     
    446344    void unload() 
    447345    { 
     346    } 
     347 
     348    bool loaded() 
     349    { 
     350        return dependence.loaded; 
     351    } 
     352 
     353    string libName() 
     354    { 
     355        return dependence.libName; 
    448356    } 
    449357 
     
    456364//============================================================================== 
    457365 
    458 struct GenericStaticLoader { 
    459     void setup(void function() userLoad = null, char[] versionStr = "") { 
    460         this.userLoad = userLoad; 
    461         this.versionStr = versionStr; 
    462     } 
    463  
    464     void load() 
    465     { 
    466         if (userLoad !is null) { 
    467             userLoad(); 
    468         } 
    469     } 
    470  
    471     char[] versionString() 
    472     { 
    473         return versionString; 
    474     } 
    475  
    476     void unload() 
    477     { 
    478     } 
    479  
    480     private { 
    481         char[]          versionStr; 
    482         void function() userLoad; 
    483     } 
    484 } 
    485  
    486  
    487 //============================================================================== 
    488  
    489366package struct Binder(T) { 
    490     void opCall(char[] n, SharedLib lib) { 
     367    void opCall(string n, SharedLib lib) { 
    491368        *fptr = Derelict_GetProc(lib, n); 
    492369    } 
  • trunk/derelict/util/wrapper.d

    r45 r50  
    5151} 
    5252 
    53 char* toCString(char[] str) 
     53char* toCString(string str) 
    5454{ 
    5555    version(Tango) 
     
    6363} 
    6464 
    65 char[] toDString(char* cstr) 
     65string toDString(char* cstr) 
    6666{ 
    6767    version(Tango) 
     
    7575} 
    7676 
    77 int findStr(char[] str, char[] match) 
     77int findStr(string str, string match) 
    7878{ 
    7979    version(Tango) 
     
    8888} 
    8989 
    90 char[][] splitStr(char[] str, char[] delim) 
     90string[] splitStr(string str, string delim) 
    9191{ 
    9292    return split(str, delim); 
    9393} 
    9494 
    95 char[] stripWhiteSpace(char[] str) 
     95string stripWhiteSpace(string str) 
    9696{ 
    9797    version(Tango) 
  • trunk/src/GNUmakefile

    r39 r50  
    1 link GNUmakefile.gdc 
     1link GNUmakefile.dmd 
  • trunk/src/GNUmakefile.dmd

    r48 r50  
    8787 
    8888$(THE_TARGET): $(OBJS) 
    89     gcc -m32 -o $(THE_TARGET) $(OBJS) $(DMD_DIR)/lib/libphobos.a -lm -lpthread -ldl 
     89    gcc -m32 -o $(THE_TARGET) $(OBJS) $(DMD_DIR)/lib/libphobos2.a -lm -lpthread -ldl 
    9090 
    9191$(BUILD_DIR)/%.o : %.d 
  • trunk/src/color.d

    r28 r50  
    1 /*{{{ 
     1/*{// 
    22 
    33    QonkD - A simple space conquest strategy game 
     
    1919    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    2020 
    21 }}}*/ 
     21}//*/ 
    2222 
    2323module color; 
    2424 
    2525import std.string; 
    26  
    27 class Color //{{{ 
    28 
    29     real R, G, B, A; 
     26import std.stdio; 
     27import std.c.stdlib; 
     28 
     29class Color 
     30{// 
     31    float R, G, B, A; 
     32    float H, S, V; 
    3033    ubyte r, g, b, a; 
    3134    uint c; 
    3235 
    33     static Color opCall( uint _c ) //{{{ 
    34     { 
     36    //{// static constructors 
     37 
     38    static Color opCall( uint _c ) 
     39    {// 
    3540        Color color = new Color; 
    3641        with( color ) { 
     
    3843            c = _c; 
    3944 
    40             r = c>>24; 
    41             g = (c>>16)&0xff; 
    42             b = (c>>8)&0xff; 
    43             a = c&0xff; 
    44  
    45             R = r/255.; 
    46             G = g/255.; 
    47             B = b/255.; 
    48             A = a/255.; 
     45            r = cast(ubyte)(c>>24); 
     46            g = cast(ubyte)((c>>16)&0xff); 
     47            b = cast(ubyte)((c>>8)&0xff); 
     48            a = cast(ubyte)(c&0xff); 
     49 
     50            set_reals(); 
    4951        } 
    5052        return color; 
    5153 
    52     } //}}} 
    53  
    54     static Color opCall( ubyte _r, ubyte _g, ubyte _b, ubyte _a = 0xff ) //{{{ 
    55     { 
     54    }// 
     55 
     56    static Color opCall( ubyte _r, ubyte _g, ubyte _b, ubyte _a = 0xff ) 
     57    {// 
    5658        Color color = new Color; 
    5759        with( color ) { 
     
    6466            c = r<<24 | g<<16 | b<<8 | a; 
    6567 
    66             R = r/255.; 
    67             G = g/255.; 
    68             B = b/255.; 
    69             A = a/255.; 
     68            set_reals(); 
    7069        } 
    7170        return color; 
    72     } //}}} 
    73  
    74     static Color opCall( real rr, real rg, real rb, real ra = 1. ) //{{{ 
    75     { 
     71    }// 
     72 
     73    static Color opCall( float rr, float rg, float rb, float ra = 1. ) 
     74    {// 
    7675        Color color = new Color; 
    7776        with( color ) { 
     
    8180            B = rb > 1. ? 1. : rb; 
    8281            A = ra > 1. ? 1. : ra; 
     82            rgb2hsv( R, G, B, H, S, V ); 
    8383 
    8484            r = cast(ubyte)(R*255); 
     
    9090        } 
    9191        return color; 
    92     } //}}} 
    93  
    94     static Color opCall( char[] str ) //{{{ 
    95     { 
    96         uint h[char[]]; 
     92    }// 
     93 
     94    static Color opCall( string str ) 
     95    {// 
     96        uint h[string]; 
    9797        h["black"]   = 0x000000ff; 
    9898        h["white"]   = 0xffffffff; 
     
    105105        h["gray"]    = 0x7f7f7fff; 
    106106 
    107         if(!( str in h )) 
    108             str = "magenta"; 
    109  
    110         return Color( h[str] ); 
    111  
    112     } //}}} 
    113  
    114     static Color hsv( real h, real s = 1., real v = 1., real a = 1. ) //{{{ 
    115     { 
    116         real r, g, b; 
     107        long hex2long( string str ) { 
     108            version(stdlib) { 
     109                char* end; 
     110                char* ptr = toStringz(str); 
     111                long i = std.c.stdlib.strtol( ptr, &end, 16 ); 
     112                if( end == ptr  ||  *end != '\0' ) 
     113                    throw new Exception( format("invalid hex format \"%s\"", str) ); 
     114                debug writefln("h2l: %s=>%s=>%x, ptr=%d, end=%d",str,std.string.toString(ptr),i,cast(long)ptr,cast(long)end); 
     115                return i; 
     116            } 
     117            else { 
     118                long i = 0; 
     119                str = tolower(str); 
     120                foreach( c; str ) { 
     121                    i = i << 4; 
     122                    if( c >= '0' && c <= '9' ) 
     123                        i |= c - '0'; 
     124                    else if( c >= 'a' && c <= 'f' ) 
     125                        i |= c - 'a' + 10; 
     126                    else 
     127                        throw new Exception( format("invalid hex format \"%s\"", str) ); 
     128                } 
     129                return i; 
     130            } 
     131        } 
     132 
     133        if( str in h ) { 
     134            return Color( h[str] ); 
     135        } 
     136        else { 
     137            long c = 0x1deadbeef; 
     138            if( str[0] == '#' ) { 
     139                str = str[1 .. str.length]; 
     140 
     141                if( str.length == 3 ) 
     142                    str = "" ~ str[0] ~ str[0] ~ str[1] ~ str[1] ~ str[2] ~ str[2]; 
     143 
     144                if( str.length == 6 ) 
     145                    str ~= "FF"; 
     146 
     147                if( str.length == 8 ) 
     148                    c = hex2long(str); 
     149            } 
     150 
     151            if( c == 0x1deadbeef ) 
     152                throw new Exception( format("error parsing color string \"%s\"", str) ); 
     153 
     154            return Color(cast(uint)c); 
     155        } 
     156 
     157    }// 
     158 
     159    static Color hsv( float h, float s = 1., float v = 1., float a = 1. ) 
     160    {// 
     161        float r, g, b; 
    117162 
    118163        if( s == 0 ) { 
     
    124169            h /= 60;  // sector 0 to 5 
    125170            int i = cast(int)h; 
    126             real f = h - i;  // factorial part of h 
    127             real p = v * ( 1 - s ); 
    128             real q = v * ( 1 - s * f ); 
    129             real t = v * ( 1 - s * ( 1 - f ) ); 
     171            float f = h - i;  // factorial part of h 
     172            float p = v * ( 1 - s ); 
     173            float q = v * ( 1 - s * f ); 
     174            float t = v * ( 1 - s * ( 1 - f ) ); 
    130175 
    131176            switch( i ) { 
     
    165210        return Color( r, g, b, a ); 
    166211 
    167     } //}}} 
    168  
    169     char[] toString() //{{{ 
    170     { 
    171         return format( "#%08x", c ); 
    172     } //}}} 
     212    }// 
     213 
     214    //}// 
     215 
     216    static void rgb2hsv( float r, float g, float b, out float h, out float s, out float v ) 
     217    in {// 
     218        assert( r>=0. && r<=1.  &&  g>=0. && g<=1.  &&  b>=0. && b<=1. ); 
     219    } 
     220    out { 
     221        //assert( s>=0. && s<=1.  &&  v>=0. && v<=1.  &&  h>=0. && h<360. ); 
     222        if(!( s>=0. && s<=1.  &&  v>=0. && v<=1.  &&  h>=0. && h<360. )) { 
     223            writefln("rgb(%f,%f,%f) -> hsv(%f,%f,%f)", r,g,b, h,s,v ); 
     224            assert(false); 
     225        } 
     226    } 
     227    body { 
     228        // r,g,b values are from 0 to 1 
     229        // h = [0,360], s = [0,1], v = [0,1] 
     230        //      if s == 0, then h = -1 (undefined) 
     231 
     232        v = r<g?(g<b?b:g):(r<b?b:r); // max(r,g,b) 
     233 
     234        if( v == 0 ) { 
     235            s = 0; 
     236            h = 0; 
     237            return; 
     238        } 
     239 
     240        float delta = v - (r>g?(g>b?b:g):(r>b?b:r)); // max - min 
     241        s = delta / v; 
     242 
     243        if( delta == 0 ) // gray 
     244            h = 0; 
     245        else if( r == v ) 
     246            h = ( g - b ) / delta;      // between yellow & magenta 
     247        else if( g == v ) 
     248            h = 2 + ( b - r ) / delta;  // between cyan & yellow 
     249        else 
     250            h = 4 + ( r - g ) / delta;  // between magenta & cyan 
     251 
     252        h *= 60;  // degrees 
     253        if( h < 0 ) 
     254            h += 360; 
     255    }// 
     256 
     257    static void rgb2hsv( ubyte r, ubyte g, ubyte b, out float h, out float s, out float v ) 
     258    {// 
     259        rgb2hsv( r/255., g/255., b/255., h, s, v ); 
     260    }// 
     261 
     262    string toString() 
     263    {// 
     264        return format ("#%08x", c); 
     265    }// 
    173266 
    174267    // operators: 
    175268 
    176     Color opMul( real x ) //{{{ 
    177     { 
     269    Color opMul( float x ) 
     270    {// 
    178271        //return Color( R*x, G*x, B*x, A ); 
    179272        return Color( R, G, B, A*x ); 
    180     } //}}} 
    181  
    182 } //}}} 
    183  
    184 class HueFactory //{{{ provides sequencialy hue-distributed colors 
    185 
     273    }// 
     274 
     275    private: 
     276 
     277    void set_reals() 
     278    {// 
     279        R = cast(float) r / ubyte.max; 
     280        G = cast(float) g / ubyte.max; 
     281        B = cast(float) b / ubyte.max; 
     282        A = cast(float) a / ubyte.max; 
     283        rgb2hsv( R, G, B, H, S, V ); 
     284    }// 
     285 
     286}// 
     287 
     288class HueFactory 
     289{// provides sequencialy hue-distributed colors 
     290 
    186291    uint idx = 0; 
    187292 
     
    189294 
    190295    Color next() { 
    191         real hue, value; 
     296        float hue, value; 
    192297        uint i = idx++; 
    193298        if( i < 8 ) { 
     
    211316    } 
    212317 
    213 } //}}} 
    214  
    215 // vim600:fdm=marker
     318}// 
     319 
     320// vim600:foldmethod=marker:foldmarker={//,}//
  • trunk/src/config.d

    r48 r50  
    2929class Config 
    3030{ 
    31         void load_from_args( char[][] args ) 
     31        void load_from_args( string[] args ) 
    3232        {// 
    3333            // BUG: how will this work on a external repository? 
    34             char[] ver = "$Revision$ $Date$"; 
    35             char[] help_arg; 
    36             char[] version_arg; 
     34            string ver = "$Revision$ $Date$"; 
     35            string help_arg; 
     36            string version_arg; 
    3737            version(Windows) { 
    3838                help_arg = "/?"; 
     
    6060        }// 
    6161 
    62         void load_from_arg( char[] arg ) 
     62        void load_from_arg( string arg ) 
    6363        {// 
    6464            int p = find( arg, '=' ); 
    65             char[] key; 
    66             char[] val; 
     65            string key; 
     66            string val; 
    6767            if( p > 0 ) { 
    6868                key = arg[0 .. p]; 
     
    8888        }// 
    8989 
    90         void load_from_file( char[] filename ) 
     90        void load_from_file( string filename ) 
    9191        {// 
    92             throw Error( "not implemented" ); 
     92            throw new Error( "not implemented" ); 
    9393        }// 
    9494 
    95         void save_to_file( char[] filename ) 
     95        void save_to_file( string filename ) 
    9696        {// 
    97             throw Error( "not implemented" ); 
     97            throw new Error( "not implemented" ); 
    9898        }// 
    9999 
    100         char[] opIndex( char[] key ) 
     100        string opIndex( string key ) 
    101101        {// 
    102102            try { 
     
    109109        }// 
    110110 
    111         char[] opIndexAssign( char[] value, char[] key ) 
     111        string opIndexAssign( string value, string key ) 
    112112        {// 
    113113            debug(config) writefln( "values[%s] := \"%s\"", key, value ); 
     
    115115        }// 
    116116 
    117     protected
    118         char[] [char[]] values; 
     117    private
     118        string[string] values; 
    119119} 
    120120 
     
    123123    protected: 
    124124 
    125     char[] default_value; 
    126     char[] help; 
     125    string default_value; 
     126    string help; 
    127127    /* TODO 
    128128       - know the type of the item; 
    129129       - constraints (min/max for numbers, list of possible values for strings (along with help for each one)); 
    130130    */ 
    131     char[] value; 
     131    string value; 
    132132}// 
    133133 
  • trunk/src/display.d

    r49 r50  
    4040class Display 
    4141{ 
    42     this( char[] title, Config cfg = null ) {// init video device, load font 
     42    this( string title, Config cfg = null ) {// init video device, load font 
    4343 
    4444        Derelict_SetMissingProcCallback( &missing_proc_handler ); // support older SDL library versions 
     
    8787 
    8888            // font loading 
    89             char[] filename = (cfg is null) ? "" : cfg["font_filename"]; 
    90             if( filename != "" ) 
    91             { 
    92                 DerelictSDLttf.load(); 
    93                 if( TTF_Init() < 0 ) 
    94                     throw new Exception( format( 
    95                             "TTF_Init: %s", 
    96                             std.string.toString(TTF_GetError()) ) ); 
    97  
    98                 uint ptsize = cast(uint)atoi(cfg["font_size"]); 
    99                 if( ptsize <= 0 ) 
    100                     ptsize = 12; 
    101                 font = TTF_OpenFont( std.string.toStringz(filename), ptsize ); 
    102                 if( font is null ) { 
    103                     TTF_Quit(); 
    104                     throw new Exception( format( 
    105                             "Unable to open font %s at size %d", 
    106                             filename, ptsize ) ); 
    107                 } 
     89            string filename = (cfg is null) ? "" : cfg["font_filename"]; 
     90            if( filename == "" ) { 
     91                //TODO: find system font 
     92                filename = "font.ttf"; 
    10893            } 
    10994 
     95            DerelictSDLttf.load(); 
     96            if( TTF_Init() < 0 ) 
     97                throw new Exception( format( 
     98                        "TTF_Init: %s", 
     99                        std.string.toString(TTF_GetError()) ) ); 
     100 
     101            uint ptsize = cast(uint)atoi(cfg["font_size"]); 
     102            if( ptsize <= 0 ) 
     103                ptsize = 12; 
     104            font = TTF_OpenFont( std.string.toStringz(filename), ptsize ); 
     105            if( font is null ) { 
     106                TTF_Quit(); 
     107                throw new Exception( format( 
     108                        "Unable to open font %s at size %d", 
     109                        filename, ptsize ) ); 
     110            } 
     111 
    110112            int h_width; 
    111             TTF_SizeText( font, "H", &h_width, &text_height ) ; 
     113            TTF_SizeText( font, std.string.toStringz("H"), &h_width, &text_height ) ; 
     114 
    112115        }// 
    113116 
     
    322325    //}// 
    323326 
    324     TextImage text_to_image( char[] text, Color color ) {// 
     327    TextImage text_to_image( string text, Color color ) {// 
    325328 
    326329        if( font is null ) 
     
    328331 
    329332        // cache of text images 
    330         char[] key = color.toString ~ ":" ~ text; 
     333        string key = color.toString ~ ":" ~ text; 
    331334        if( key in text_cache ) 
    332335            return text_cache[key]; 
     
    345348    //}// 
    346349 
    347     void draw_text( char[] text, int align_, short i, short j, Color color, out int w, out int h ) {// 
     350    void draw_text( string text, int align_, short i, short j, Color color, out int w, out int h ) {// 
    348351 
    349352        TextImage img = text_to_image( text, color ); 
     
    367370    } 
    368371 
    369     void draw_text( char[] text, int align_, short i, short j, Color color ) 
     372    void draw_text( string text, int align_, short i, short j, Color color ) 
    370373    { 
    371374        int w, h; 
     
    373376    } 
    374377 
    375     void draw_text( char[] text, short i, short j, Color color, out int w, out int h ) 
     378    void draw_text( string text, short i, short j, Color color, out int w, out int h ) 
    376379    { 
    377380        draw_text( text, 0, i, j, color, w, h ); 
     
    416419 
    417420    TTF_Font* font; 
    418     TextImage[char[]] text_cache; 
     421    TextImage[string] text_cache; 
    419422 
    420423    float cx, cy, sz; // viewport 
     
    422425    //}// 
    423426 
    424     static bool missing_proc_handler( char[] libName, char[] procName ) {// 
     427    static bool missing_proc_handler( string libName, string procName ) {// 
    425428        switch( procName ) { 
    426429            case "SDL_GetKeyRepeat": 
     
    446449    uint last_used; 
    447450 
    448     this( char[] text, TTF_Font* font, Color color ) 
     451    this( string text, TTF_Font* font, Color color ) 
    449452    { 
    450453        debug(text_cache) 
  • trunk/src/dl_gfx.d

    r5 r50  
    257257private SharedLib libSDLGfxPrimitives; 
    258258 
    259 private void* getProc( char[] procName ) 
     259private void* getProc( string procName ) 
    260260{ 
    261261    return Derelict_GetProc( libSDLGfxPrimitives, procName ); 
     
    316316} 
    317317 
    318 public void DerelictSDLGfx_Load( char[] libName ) 
     318public void DerelictSDLGfx_Load( string libName ) 
    319319{ 
    320320    if( libSDLGfxPrimitives !is null ) 
  • trunk/src/events.d

    r48 r50  
    2727import player; 
    2828import objects; 
     29private import std.string; 
    2930 
    3031//}// 
     
    3637abstract class GameEvent 
    3738{// 
    38     char[] serialize(); 
    39     static GameEvent deserialize( char[] ); 
     39    string serialize(); 
     40 
     41    static GameEvent deserialize (string str) 
     42    {// 
     43        if (std.string.find (str, "attack:") == 0) 
     44            return GameEvent_Attack.deserialize (str); 
     45        else if (std.string.find (str, "sendship:") == 0) 
     46            return GameEvent_SendShip.deserialize (str); 
     47        else if (std.string.find (str, "spawnship:") == 0) 
     48            return GameEvent_SpawnShip.deserialize (str); 
     49        else 
     50            throw new Error ("unknown game event \"" ~ str ~ "\""); 
     51    }// 
     52 
    4053}// 
    4154 
     
    5063    } 
    5164 
    52     /* 
    53     char[] serialize() 
     65    string serialize() 
    5466    { 
    55         char[] str = "attack:"; 
     67        version(none) { 
     68        string str = "attack:"; 
    5669        str ~= planet.id; 
    5770        if( previous_owner !is null ) 
    5871            str ~= ":" ~ previous_owner.id; 
    5972        return str; 
     73        } else return null; 
    6074    } 
    6175 
    62     GameEvent_Attack deserialize( char[] str ) 
     76    static GameEvent_Attack deserialize( string str ) 
    6377    { 
    6478        return null; //TODO 
    6579    } 
    66     */ 
    6780}// 
    6881 
     
    7790    } 
    7891 
    79     /* 
    80     char[] serialize() 
     92    string serialize() 
    8193    { 
    82         return format( "sendship:%d:%d", from.id, to.id ); 
     94        version(none) { 
     95        return std.string.format( "sendship:%d:%d", from.id, to.id ); 
     96        } else { return null; } 
    8397    } 
    8498 
    85     void deserialize( char[] str ) 
     99    static GameEvent deserialize( string str ) 
    86100    { 
     101        return null; 
    87102    } 
    88     */ 
    89103}// 
    90104 
     
    92106{// 
    93107    Planet planet; 
     108 
     109    string serialize() 
     110    { 
     111        return null; 
     112    } 
     113 
     114    static GameEvent deserialize (string str) 
     115    { 
     116        return null; 
     117    } 
    94118}// 
    95119 
  • trunk/src/list.d

    r48 r50  
    172172    //}}} 
    173173 
    174     invariant { // {{{ consistency checking 
     174    invariant() { // {{{ consistency checking 
    175175        assert( item_count == 0 || ( head_ !is null && tail_ !is null ) ); 
    176176    } //}}} 
  • trunk/src/main.d

    r48 r50  
    2929 
    3030import derelict.sdl.sdl; 
     31import std.stdio; 
    3132 
    3233//}// 
     
    3738        this() { 
    3839            // game 
    39             values[ "game_planets" ] = "10"; 
    40             values[ "game_bots" ] = "2"; 
    41             values[ "game_players" ] = "1"; 
     40            this[ "game_planets" ] = "10"; 
     41            this[ "game_bots" ] = "2"; 
     42            this[ "game_players" ] = "1"; 
    4243            // networking 
    43             values[ "net_start" ] = "0"; 
    44             values[ "net_local_port" ] = "9666"; 
    45             values[ "net_remote_port" ] = "9666"; 
    46             values[ "net_remote_addr" ] = ""; 
     44            this[ "net_start" ] = "0"; 
     45            this[ "net_local_port" ] = "9666"; 
     46            this[ "net_remote_port" ] = "9666"; 
     47            this[ "net_remote_addr" ] = ""; 
    4748            // video 
    48             values[ "display_width" ] = "1024"; 
    49             values[ "display_height" ] = "768"; 
    50             values[ "display_bpp" ] = "0"; 
    51             values[ "display_fullscreen" ] = "0"; 
     49            this[ "display_width" ] = "1024"; 
     50            this[ "display_height" ] = "768"; 
     51            this[ "display_bpp" ] = "0"; 
     52            this[ "display_fullscreen" ] = "0"; 
    5253            // misc 
    53             values[ "coredump" ] = "0"; 
     54            this[ "coredump" ] = "0"; 
    5455        } 
    5556}// 
    5657 
    57 int main( char[][] args
     58int main (string[] args
    5859{ 
    59     QonkD_Config cfg = new QonkD_Config; 
    60     cfg.load_from_args( args[1 .. args.length] ); 
     60    try { 
     61        QonkD_Config cfg = new QonkD_Config; 
     62        cfg.load_from_args (args[1 .. args.length]); 
    6163 
    62     Display display = new Display( args[0], cfg ); 
    63     UI ui = new UI( cfg ); 
    64     Visual visual = new Visual( display, ui ); 
     64        Display display = new Display (args[0], cfg); 
    6565 
    66     //{// key-to-function mapping 
     66        UI ui = new UI (cfg); 
     67        Visual visual = new Visual (display, ui); 
    6768 
    68     char[][SDLKey] sdlkey_to_function; 
    69     sdlkey_to_function[SDLK_ESCAPE] = "quit"; 
    70     sdlkey_to_function[SDLK_b]      = "addbot"; 
    71     sdlkey_to_function[SDLK_F1]     = "addship"; 
    72     sdlkey_to_function[SDLK_SPACE]  = "send_mode"; //TODO: split-screen 
     69        //{// key-to-function mapping 
    7370 
    74     sdlkey_to_function[SDLK_w]      = "up"
    75     sdlkey_to_function[SDLK_a]      = "left"; 
    76     sdlkey_to_function[SDLK_s]      = "down"; 
    77     sdlkey_to_function[SDLK_d]      = "right"; 
    78     sdlkey_to_function[SDLK_LCTRL]  = "activate"; 
     71       string[SDLKey] sdlkey_to_function
     72       sdlkey_to_function[SDLK_ESCAPE] = "quit"; 
     73       sdlkey_to_function[SDLK_b]      = "addbot"; 
     74       sdlkey_to_function[SDLK_F1]     = "addship"; 
     75       sdlkey_to_function[SDLK_SPACE]  = "send_mode"; //TODO: split-screen 
    7976 
    80     sdlkey_to_function[SDLK_UP]     = "up"; 
    81     sdlkey_to_function[SDLK_DOWN]   = "down"; 
    82     sdlkey_to_function[SDLK_LEFT]   = "left"; 
    83     sdlkey_to_function[SDLK_RIGHT]  = "right"; 
    84     sdlkey_to_function[SDLK_RCTRL]  = "activate"; 
     77       sdlkey_to_function[SDLK_w]      = "up"; 
     78       sdlkey_to_function[SDLK_a]      = "left"; 
     79       sdlkey_to_function[SDLK_s]      = "down"; 
     80       sdlkey_to_function[SDLK_d]      = "right"; 
     81       sdlkey_to_function[SDLK_LCTRL]  = "activate"; 
    8582 
    86     sdlkey_to_function[SDLK_KP8]    = "up"; 
    87     sdlkey_to_function[SDLK_KP4]    = "left"; 
    88     sdlkey_to_function[SDLK_KP2]    = "down"; 
    89     sdlkey_to_function[SDLK_KP6]    = "right"; 
    90     sdlkey_to_function[SDLK_KP5]    = "activate"; 
     83       sdlkey_to_function[SDLK_UP]     = "up"; 
     84       sdlkey_to_function[SDLK_DOWN]   = "down"; 
     85       sdlkey_to_function[SDLK_LEFT]   = "left"; 
     86       sdlkey_to_function[SDLK_RIGHT]  = "right"; 
     87       sdlkey_to_function[SDLK_RCTRL]  = "activate"; 
    9188 
    92     sdlkey_to_function[SDLK_u] = "min_defense++"; 
    93     sdlkey_to_function[SDLK_j] = "min_defense--"; 
    94     sdlkey_to_function[SDLK_i] = "min_attack++"; 
    95     sdlkey_to_function[SDLK_k] = "min_attack--"; 
    96     sdlkey_to_function[SDLK_o] = "max_attack++"; 
    97     sdlkey_to_function[SDLK_l] = "max_attack--"; 
     89        sdlkey_to_function[SDLK_KP8]    = "up"; 
     90        sdlkey_to_function[SDLK_KP4]    = "left"; 
     91        sdlkey_to_function[SDLK_KP2]    = "down"; 
     92        sdlkey_to_function[SDLK_KP6]    = "right"; 
     93        sdlkey_to_function[SDLK_KP5]    = "activate"; 
    9894 
    99     int[SDLKey] sdlkey_to_player
    100     sdlkey_to_player[SDLK_w]        = 0
    101     sdlkey_to_player[SDLK_a]        = 0
    102     sdlkey_to_player[SDLK_s]        = 0
    103     sdlkey_to_player[SDLK_d]        = 0
    104     sdlkey_to_player[SDLK_LCTRL]    = 0
     95       sdlkey_to_function[SDLK_u] = "min_defense++"
     96       sdlkey_to_function[SDLK_j] = "min_defense--"
     97       sdlkey_to_function[SDLK_i] = "min_attack++"
     98       sdlkey_to_function[SDLK_k] = "min_attack--"
     99       sdlkey_to_function[SDLK_o] = "max_attack++"
     100       sdlkey_to_function[SDLK_l] = "max_attack--"
    105101 
    106     sdlkey_to_player[SDLK_UP]       = 1; 
    107     sdlkey_to_player[SDLK_DOWN]     = 1; 
    108     sdlkey_to_player[SDLK_LEFT]     = 1; 
    109     sdlkey_to_player[SDLK_RIGHT]    = 1; 
    110     sdlkey_to_player[SDLK_RCTRL]    = 1; 
     102        int[SDLKey] sdlkey_to_player; 
     103        sdlkey_to_player[SDLK_w]        = 0; 
     104        sdlkey_to_player[SDLK_a]        = 0; 
     105        sdlkey_to_player[SDLK_s]        = 0; 
     106        sdlkey_to_player[SDLK_d]        = 0; 
     107        sdlkey_to_player[SDLK_LCTRL]    = 0; 
    111108 
    112     sdlkey_to_player[SDLK_KP8]      = 2
    113     sdlkey_to_player[SDLK_KP4]      = 2
    114     sdlkey_to_player[SDLK_KP2]      = 2
    115     sdlkey_to_player[SDLK_KP6]      = 2
    116     sdlkey_to_player[SDLK_KP5]      = 2
     109       sdlkey_to_player[SDLK_UP]       = 1
     110       sdlkey_to_player[SDLK_DOWN]     = 1
     111       sdlkey_to_player[SDLK_LEFT]     = 1
     112       sdlkey_to_player[SDLK_RIGHT]    = 1
     113       sdlkey_to_player[SDLK_RCTRL]    = 1
    117114 
    118     //}// 
    119  
    120     while( ui.is_running ) 
    121     {// main event loop 
    122  
    123         SDL_Event sdl_event; 
    124         while( SDL_PollEvent(&sdl_event) ) 
    125         {// process ui events 
    126             Event ui_event; 
    127             ui_event.now = SDL_GetTicks()/1000.0; 
    128  
    129             switch(sdl_event.type) 
    130             { 
    131                 case SDL_KEYDOWN: 
    132                 case SDL_KEYUP: 
    133                     SDLKey key = sdl_event.key.keysym.sym; 
    134                     if( key in sdlkey_to_function ) { 
    135                         ui_event.func = sdlkey_to_function[key]; 
    136                         ui_event.name = ( sdl_event.type == SDL_KEYUP ? "up" : "down" ); 
    137                     } 
    138                     if( key in sdlkey_to_player ) 
    139                         ui_event.player = sdlkey_to_player[key]; 
    140                 break; 
    141  
    142                 case SDL_QUIT: 
    143                     ui_event.name = "down"; 
    144                     ui_event.func = "quit"; 
    145                 break; 
    146  
    147                 case SDL_MOUSEMOTION: 
    148                     ui_event.name = "move"; 
    149                     ui_event.func = ""; 
    150                     ui_event.x = display.i2x( sdl_event.motion.x ); 
    151                     ui_event.y = display.j2y( sdl_event.motion.y ); 
    152                 break; 
    153  
    154                 case SDL_MOUSEBUTTONDOWN: 
    155                 case SDL_MOUSEBUTTONUP: 
    156                     ui_event.name = ( sdl_event.type == SDL_MOUSEBUTTONUP ? "up" : "down" ); 
    157                     if( sdl_event.button.button == SDL_BUTTON_LEFT ) 
    158                         ui_event.func = "select"; 
    159                     else if( sdl_event.button.button == SDL_BUTTON_RIGHT ) 
    160                         ui_event.func = "activate"; 
    161                     ui_event.x = display.i2x( sdl_event.motion.x ); 
    162                     ui_event.y = display.j2y( sdl_event.motion.y ); 
    163                 break; 
    164  
    165                 default: 
    166                 break; 
    167             } 
    168  
    169             ui.process_ui_event( ui_event ); 
    170         }// 
    171  
    172         //{// process game tick and network events 
    173  
    174         ui.process_tick( SDL_GetTicks()/1000.0 ); 
    175  
    176         visual.render(); 
    177  
    178         if( ui.world !is null ) 
    179             ui.world.events = []; 
     115        sdlkey_to_player[SDLK_KP8]      = 2; 
     116        sdlkey_to_player[SDLK_KP4]      = 2; 
     117        sdlkey_to_player[SDLK_KP2]      = 2; 
     118        sdlkey_to_player[SDLK_KP6]      = 2; 
     119        sdlkey_to_player[SDLK_KP5]      = 2; 
    180120 
    181121        //}// 
    182122 
    183         SDL_Delay(10); //TODO: proper fps handling 
     123        while (ui.is_running) 
     124        {// main event loop 
    184125 
    185     }// 
     126            SDL_Event sdl_event; 
     127            while (SDL_PollEvent (&sdl_event)) 
     128            {// process ui events 
     129                Event ui_event; 
     130                ui_event.now = SDL_GetTicks()/1000.0; 
     131 
     132                switch (sdl_event.type) 
     133                { 
     134                    case SDL_KEYDOWN: 
     135                    case SDL_KEYUP: 
     136                        SDLKey key = sdl_event.key.keysym.sym; 
     137                        if (key in sdlkey_to_function) { 
     138                            ui_event.func = sdlkey_to_function[key]; 
     139                            ui_event.name = (sdl_event.type == SDL_KEYUP ? "up" : "down"); 
     140                        } 
     141                        if (key in sdlkey_to_player) 
     142                            ui_event.player = sdlkey_to_player[key]; 
     143                    break; 
     144 
     145                    case SDL_QUIT: 
     146                        ui_event.name = "down"; 
     147                        ui_event.func = "quit"; 
     148                    break; 
     149 
     150                    case SDL_MOUSEMOTION: 
     151                        ui_event.name = "move"; 
     152                        ui_event.func = ""; 
     153                        ui_event.x = display.i2x (sdl_event.motion.x); 
     154                        ui_event.y = display.j2y (sdl_event.motion.y); 
     155                    break; 
     156 
     157                    case SDL_MOUSEBUTTONDOWN: 
     158                    case SDL_MOUSEBUTTONUP: 
     159                        ui_event.name = (sdl_event.type == SDL_MOUSEBUTTONUP ? "up" : "down"); 
     160                        if (sdl_event.button.button == SDL_BUTTON_LEFT) 
     161                            ui_event.func = "select"; 
     162                        else if (sdl_event.button.button == SDL_BUTTON_RIGHT) 
     163                            ui_event.func = "activate"; 
     164                        ui_event.x = display.i2x (sdl_event.motion.x); 
     165                        ui_event.y = display.j2y (sdl_event.motion.y); 
     166                    break; 
     167 
     168                    default: 
     169                    break; 
     170                } 
     171 
     172                ui.process_ui_event (ui_event); 
     173            }// 
     174 
     175            //{// process game tick and network events 
     176 
     177            ui.process_tick (SDL_GetTicks()/1000.0); 
     178 
     179            visual.render(); 
     180 
     181            if (ui.world !is null) 
     182                ui.world.events = []; 
     183 
     184            //}// 
     185 
     186            SDL_Delay(10); //TODO: proper fps handling 
     187 
     188        }// 
     189    } 
     190    catch (Exception e) { 
     191        writefln ("exception(%s)", e); 
     192    } 
    186193 
    187194    return 0; 
  • trunk/src/math.d

    r16 r50  
    3636//{{{ random number generation functions 
    3737 
    38 real rand( real min, real max ) 
     38float rand( float min, float max ) 
    3939in { 
    4040    assert( min < max ); 
     
    8888} 
    8989 
     90/+ 
     91 
     92T max(T) ( T[] a ) 
     93{ 
     94    T m = a[0]; 
     95    for( uint i = 1; i < a.length; ++i ) { 
     96        if( a[i] > m ) 
     97            m = a[i]; 
     98    } 
     99    return m; 
     100} 
     101 
     102T min(T) ( T[] a ) 
     103{ 
     104    T m = a[0]; 
     105    for( uint i = 1; i < a.length; ++i ) { 
     106        if( a[i] < m ) 
     107            m = a[i]; 
     108    } 
     109    return m; 
     110} 
     111 
     112+/ 
     113 
    90114//}}} 
    91115 
  • trunk/src/menu.d

    r48 r50  
    2929abstract class MenuItem //{{{ 
    3030{ 
    31     char[] text; 
     31    string text; 
    3232    void activate( bool ); 
    33     invariant
     33    invariant()
    3434        assert( text !is null ); 
    3535    } 
     
    4040    public: 
    4141 
    42     this( char[] t, void delegate() f ) 
     42    this( string t, void delegate() f ) 
    4343    { 
    4444        text = t; 
     
    6363    void delegate() func; 
    6464 
    65     invariant
     65    invariant()
    6666        assert( func !is null ); 
    6767    } 
     
    7373    public: 
    7474 
    75     this( char[] t, int _min, int _max, int _val, int delegate(int) f ) //{{{ 
     75    this( string t, int _min, int _max, int _val, int delegate(int) f ) //{{{ 
    7676    in { 
    7777        assert( _min <= _max ); 
     
    128128 
    129129    int min, max, value; 
    130     char[] text_format; 
     130    string text_format; 
    131131    int delegate(int) func; 
    132132 
    133     invariant
     133    invariant()
    134134        assert( value >= min ); 
    135135        assert( value <= max ); 
     
    169169    } 
    170170 
    171     char[] opIndex( uint i ) { 
     171    string opIndex( uint i ) { 
    172172        return items[i].text; 
    173173    } 
    174174 
    175     char[] opIndexAssign( char[] t, uint i ) { 
     175    string opIndexAssign( string t, uint i ) { 
    176176        return ( items[i].text = t ); 
    177177    } 
     
    181181    } 
    182182 
    183     /*char[][] opCall() { 
     183    /*string[] opCall() { 
    184184        return items; 
    185185    }*/ 
     
    187187    //}}} 
    188188 
    189     void command( char[] cmd ) //{{{ 
     189    void command( string cmd ) //{{{ 
    190190    { 
    191191        debug(menu) 
     
    251251        menu ~= new MI_Action( "exit", { running = false; } ); 
    252252 
    253         char[][char] k2f; 
     253        string[char] k2f; 
    254254        k2f['h'] = "left"; 
    255255        k2f['l'] = "right"; 
  • trunk/src/messages.d

    r48 r50  
    4040    } //}}} 
    4141 
    42     void add( char[] text, Color c, uint display_time = 10000 ) //{{{ 
     42    void add( string text, Color c, uint display_time = 10000 ) //{{{ 
    4343    { 
    4444        lines.insert( new MessageLine( text, c, display_time ) ); 
     
    7373private class MessageLine //{{{ 
    7474{ 
    75     char[] text; 
     75    string text; 
    7676    uint display_time; 
    7777    uint display_start; 
    7878    Color color; 
    7979 
    80     this( char[] _text, Color _color, uint time ) 
     80    this( string _text, Color _color, uint time ) 
    8181    { 
    8282        text = _text; 
  • trunk/src/net.d

    r33 r50  
    1 /*{{{ 
     1/*{// 
    22 
    33    QonkD - A simple space conquest strategy game 
     
    1919    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    2020 
    21 }}}*/ 
    22  
    23 // {{{ imports 
     21}//*/ 
     22 
     23//{// imports 
    2424 
    2525import world; 
     26import events; 
    2627import list; 
    2728import std.string; 
     
    3132import derelict.sdl.sdl; 
    3233 
    33 //}}} 
    34  
    35 class Net 
    36 
    37     TCPsocket incoming_socket; 
    38     TCPsocket server_socket; 
    39     TCPsocket[] peer_sockets; 
    40     SDLNet_SocketSet peer_set; 
     34//}// 
     35 
     36static bool init = false; 
     37 
     38abstract class Net 
     39{// 
     40public: 
     41 
    4142    uint max_peers = 16; 
    4243 
    43     this( uint port ) 
    44     { 
     44    this() 
     45    {// 
     46        assert( !net.init ); 
     47        net.init = true; 
    4548        DerelictSDLNet.load(); 
    4649        if( SDLNet_Init() < 0 ) 
    4750            throw new Exception( format( "SDLNet_Init: %s", SDLNet_GetError() ) ); 
    48  
    49         IPaddress ip; 
    50         resolve_host( &ip, null, port ); 
    51         incoming_socket = tcp_open( &ip ); 
    52         peer_set = new_socket_set( max_peers ); 
    53     } 
     51    }// 
    5452 
    5553    ~this() 
    56     { 
     54    {// 
    5755        //TODO: send quit message 
    5856        SDLNet_Quit(); 
    59     } 
    60  
    61     bool connect( char[] addr, uint port ) 
    62     { 
    63         IPaddress remote_ip; 
    64         resolve_host( &remote_ip, addr, port ); 
    65         TCPsocket remote_socket = tcp_open( &remote_ip ); 
    66         peer_sockets ~= remote_socket; 
    67         server_socket = remote_socket; 
    68         return true; 
    69     } 
    70  
    71     void get_peers() 
    72     { 
    73         write_line( server_socket, "get_peers" ); 
    74     } 
    75  
    76     World get_world() 
    77     { 
    78         write_line( server_socket, "get_world" ); 
    79  
    80         while(true) { 
    81             while( !SDLNet_SocketReady( server_socket ) ) { 
    82                 SDL_Delay( 10 ); //XXX: ugly 
    83             } 
    84  
    85             char[] line = read_line( server_socket ); 
    86             if( line is null || line == "" ) 
    87                 return null; 
    88             char[][] tokens = split( line ); 
    89             if( tokens[0] != "world" ) 
    90                 continue; 
    91         } 
    92         return null; 
    93     } 
    94  
    95     void send_events( List!(GameEvent) events ) 
    96     { 
    97     } 
    98  
    99     char[] socket_to_string( TCPsocket socket ) 
    100     { 
    101         IPaddress* p_ip = SDLNet_TCP_GetPeerAddress( socket ); 
    102         assert( p_ip !is null ); 
    103         return format( "%s %s", p_ip.host, p_ip.port ); 
    104     } 
    105  
    106     /* 
    107     TCPsocket string_to_socket( char[] str ) 
    108     { 
    109         char[][] a = std.string.split( str, ":" ); 
    110     } 
    111     */ 
    112  
    113     void write_line( TCPsocket socket, ... ) //{{{ 
    114     { 
    115         char[] buf; 
     57    }// 
     58 
     59    void send_events( GameEvent[] events ); 
     60 
     61    GameEvent[] receive_events(); 
     62 
     63    GameEvent[] receive_events_from_socket( TCPsocket socket ) 
     64    {// 
     65        GameEvent[] events; 
     66        while( SDLNet_SocketReady(socket) ) { 
     67            string line = read_line(socket); 
     68            events ~= GameEvent.deserialize( line ); 
     69        } 
     70        return events; 
     71    }// 
     72 
     73private: 
     74    void write_line( TCPsocket socket, ... ) 
     75    {// 
     76        string buf; 
    11677        std.format.doFormat( delegate( dchar c ) { buf ~= c; }, _arguments, _argptr ); 
    11778        debug writefln("write_line(%s)", buf); 
    11879        buf ~= "\n"; 
    11980        SDLNet_TCP_Send( socket, toStringz(buf), buf.length ); 
    120     } //}}} 
    121  
    122     char[] read_line( TCPsocket socket ) //{{{ 
    123     { 
    124         char[] line = ""; 
     81    }// 
     82 
     83    string read_line( TCPsocket socket ) 
     84    {// 
     85        string line = ""; 
    12586        while(true) { 
    12687            char c; 
     
    13394            line ~= c; 
    13495        } 
    135     } //}}} 
     96    }// 
     97 
     98    //{// Safe wraper for SDLNet functions (throws exception on error). 
     99 
     100    void resolve_host( IPaddress* ip, string addr, ushort port ) 
     101    { 
     102        if( SDLNet_ResolveHost( ip, std.string.toStringz(addr), port ) != 0 ) 
     103            throw new Exception( format( "SDLNet_ResolveHost(%s, %s): %s", addr ? addr : "<null>", port, std.string.toString(SDLNet_GetError()) ) ); 
     104    } 
     105 
     106    TCPsocket tcp_open( IPaddress* ip ) 
     107    { 
     108        TCPsocket socket = SDLNet_TCP_Open( ip ); 
     109        if( !socket ) 
     110            throw new Exception( format( "SDLNet_TCP_Open: %s", std.string.toString(SDLNet_GetError()) ) ); 
     111        return socket; 
     112    } 
     113 
     114    SDLNet_SocketSet new_socket_set( uint max_sockets ) 
     115    { 
     116        SDLNet_SocketSet set = SDLNet_AllocSocketSet( max_sockets ); 
     117        if( !set ) 
     118            throw new Exception( format( "SDLNet_AllocSocketSet: %s", std.string.toString(SDLNet_GetError()) ) ); 
     119        return set; 
     120    } 
     121 
     122    //}// 
     123}// 
     124 
     125class Net_Server : Net 
     126{// 
     127public: 
     128    this( int port ) 
     129    {// 
     130        IPaddress ip; 
     131        resolve_host( &ip, null, port ); 
     132        incoming_socket = tcp_open( &ip ); 
     133        peer_set = new_socket_set( max_peers ); 
     134    }// 
     135 
     136    void send_events( GameEvent[] events ) 
     137    {// 
     138        foreach( peer_socket; peer_sockets ) { 
     139            foreach( event; events ) { 
     140                auto ev = cast(GameEvent_SendShip) event; 
     141                if( ev is null ) 
     142                    write_line( peer_socket, event.serialize() ); 
     143            } 
     144        } 
     145    }// 
     146 
     147    GameEvent[] receive_events() 
     148    {// 
     149        GameEvent[] events; 
     150        foreach( socket; peer_sockets ) 
     151            events ~= receive_events_from_socket( socket ); 
     152        return events; 
     153    }// 
     154 
     155private: 
     156    TCPsocket incoming_socket; 
     157    TCPsocket[] peer_sockets; 
     158    SDLNet_SocketSet peer_set; 
     159}// 
     160 
     161class Net_Client : Net 
     162{// 
     163public: 
     164    this( string server_addr, int port ) 
     165    {// 
     166        IPaddress server_ip; 
     167        resolve_host( &server_ip, server_addr, port ); 
     168        server_socket = tcp_open( &server_ip ); 
     169    }// 
     170 
     171    void send_events( GameEvent[] events ) 
     172    {// 
     173        foreach( event; events ) { 
     174            auto ev = cast(GameEvent_SendShip) event; 
     175            if( ev !is null ) 
     176                write_line( server_socket, event.serialize() ); 
     177        } 
     178    }// 
     179 
     180    GameEvent[] receive_events() 
     181    {// 
     182        return receive_events_from_socket( server_socket ); 
     183    }// 
     184 
     185private: 
     186    TCPsocket server_socket; 
     187}// 
     188 
     189/+ 
     190class Net_Peer 
     191{// deprecated 
     192 
     193    void get_peers() 
     194    { 
     195        write_line( server_socket, "get_peers" ); 
     196    } 
     197 
     198    World get_world() 
     199    { 
     200        write_line( server_socket, "get_world" ); 
     201 
     202        while(true) { 
     203            while( !SDLNet_SocketReady( server_socket ) ) { 
     204                SDL_Delay( 10 ); //XXX: ugly 
     205            } 
     206 
     207            string line = read_line( server_socket ); 
     208            if( line is null || line == "" ) 
     209                return null; 
     210            string[] tokens = split( line ); 
     211            if( tokens[0] != "world" ) 
     212                continue; 
     213        } 
     214        return null; 
     215    } 
     216 
     217    string socket_to_string( TCPsocket socket ) 
     218    { 
     219        IPaddress* p_ip = SDLNet_TCP_GetPeerAddress( socket ); 
     220        assert( p_ip !is null ); 
     221        return format( "%s %s", p_ip.host, p_ip.port ); 
     222    } 
     223 
     224    /* 
     225    TCPsocket string_to_socket( string str ) 
     226    { 
     227        string[] a = std.string.split( str, ":" ); 
     228    } 
     229    */ 
    136230 
    137231    void send_peer_list( TCPsocket remote ) 
    138232    { 
    139         foreach( TCPsocket socket; peer_sockets ) 
     233        foreach( socket; peer_sockets ) 
    140234            write_line( remote, "peer_in %s", socket_to_string(socket) ); 
    141235    } 
     
    146240    } 
    147241 
    148     void process_line( char[] line ) //{{{ 
    149     { 
    150         char[][] tokens = split( line ); 
     242    void process_line( string line ) 
     243    {// 
     244        string[] tokens = split( line ); 
    151245        switch( tokens[0] ) { 
    152246            /* 
     
    166260            */ 
    167261        } 
    168     } //}}} 
    169  
    170     void listen() //{{{ 
    171     { 
     262    }// 
     263 
     264    void listen() 
     265    {// 
    172266        TCPsocket new_socket = SDLNet_TCP_Accept( incoming_socket ); 
    173267        if( new_socket ) { 
     
    185279 
    186280        if( SDLNet_CheckSockets( peer_set, 0 ) > 0 ) { 
    187             foreach( uint i, TCPsocket socket; peer_sockets ) { 
     281            foreach( i, socket; peer_sockets ) { 
    188282                if( SDLNet_SocketReady( socket ) ) { 
    189                     char[] line = read_line(socket); 
     283                    string line = read_line(socket); 
    190284                    if( line !is null && line != "" ) 
    191285                        process_line( line ); 
     
    195289            } 
    196290        } 
    197     } //}}} 
    198  
    199     void remove_peer( uint i ) //{{{ 
    200     { 
     291    }// 
     292 
     293    void remove_peer( uint i ) 
     294    {// 
    201295        debug writefln( "peer disconencted" ); 
    202296 
     
    214308                peer_sockets ~= peer_sockets[i+1..last]; 
    215309        } 
    216     } //}}} 
    217  
    218     // {{{ Safe wraper for SDLNet functions (throws exception on error). 
    219  
    220     void resolve_host( IPaddress* ip, char[] addr, ushort port ) 
    221     { 
    222         if( SDLNet_ResolveHost( ip, std.string.toStringz(addr), port ) != 0 ) 
    223             throw new Exception( format( "SDLNet_ResolveHost(%s, %s): %s", addr ? addr : "<null>", port, std.string.toString(SDLNet_GetError()) ) ); 
    224     } 
    225  
    226     TCPsocket tcp_open( IPaddress* ip ) 
    227     { 
    228         TCPsocket socket = SDLNet_TCP_Open( ip ); 
    229         if( !socket ) 
    230             throw new Exception( format( "SDLNet_TCP_Open: %s", std.string.toString(SDLNet_GetError()) ) ); 
    231         return socket; 
    232     } 
    233  
    234     SDLNet_SocketSet new_socket_set( uint max_sockets ) 
    235     { 
    236         SDLNet_SocketSet set = SDLNet_AllocSocketSet( max_sockets ); 
    237         if( !set ) 
    238             throw new Exception( format( "SDLNet_AllocSocketSet: %s", std.string.toString(SDLNet_GetError()) ) ); 
    239         return set; 
    240     } 
    241  
    242     //}}} 
    243 
    244  
    245 // vim600:fdm=marker: 
     310    }// 
     311}// 
     312+/ 
     313 
     314// vim600:foldmethod=marker:foldmarker={//,}//: 
  • trunk/src/objects.d

    r48 r50  
    1 /*{{{ 
     1/*{// 
    22 
    33    QonkD - A simple space conquest strategy game 
     
    1919    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    2020 
    21 }}}*/ 
     21}//*/ 
    2222 
    2323module objects; 
    2424 
    25 // {{{ imports 
     25//{// imports 
     26 
    2627import world; 
    2728import player; 
     
    3031import std.math; 
    3132import std.stdio; 
    32 //}}} 
    33  
    34 class FlyingShip : GameObject //{{{ 
    35 
    36     const Planet home; // planet that generated this ship 
    37     const Planet target; // planet the ship is headed to 
     33 
     34//}// 
     35 
     36class FlyingShip : GameObject 
     37{// 
     38    Planet home; // planet that generated this ship 
     39    Planet target; // planet the ship is headed to 
    3840    float speed; 
    3941 
    40     invariant { //{{{ 
     42    invariant() 
     43    {// 
    4144        assert( home !is null ); 
    4245        assert( target !is null ); 
    4346        assert( speed == speed ); 
    44     } //}}} 
    45  
    46     this( Planet _home, Planet _target ) { //{{{ 
     47    }// 
     48 
     49    this( Planet _home, Planet _target ) 
     50    {// 
    4751        home = _home; 
    4852        target = _target; 
     
    5054        super( home.x, home.y, World.ship_size, home.owner ); 
    5155        owner.flying_ships.append( this ); 
    52     } //}}} 
    53  
    54     void update( float now ) //{{{ 
    55     { 
     56    }// 
     57 
     58    void update( float now ) 
     59    {// 
    5660        float dx = target.x - x; 
    5761        float dy = target.y - y; 
     
    7175        } 
    7276 
    73     } //}}} 
    74  
    75 } //}}} 
    76  
    77 class Planet : GameObject //{{{ 
    78 { 
    79     // {{{ data members 
     77    }// 
     78 
     79}// 
     80 
     81class Planet : GameObject 
     82{// 
     83    //{// data members 
    8084 
    8185    float orbit_distance; 
     
    8892    float new_ship_interval; 
    8993 
    90     //}}} 
    91  
    92     // {{{ constructor 
    93  
    94     this( Player owner_, float size_, float distance_, float speed_ ) { 
     94    //}// 
     95 
     96    this( Player owner_, float size_, float distance_, float speed_ ) 
     97    {// 
    9598        super( 0, 0, size_, owner_ ); 
    9699        orbit_distance = distance_; 
     
    114117            } 
    115118        } 
    116     } 
    117  
    118     this( Player owner ) { 
     119    }// 
     120 
     121    this( Player owner ) 
     122    {// 
    119123        this( owner, 
    120124                rand( World.min_planet_size, World.max_planet_size ), 
     
    122126                rand( -16., 16. ) 
    123127        ); 
    124     } 
    125  
    126     //}}} 
    127  
    128     void send_ship( Planet to, uint count = 1 ) //{{{ 
    129     in { 
     128    }// 
     129 
     130    void send_ship( Planet to, uint count = 1 ) 
     131    in {// 
    130132        //assert( nships >= count ); 
    131133        assert( to !is null ); 
     
    136138            new FlyingShip( this, to ); 
    137139        } 
    138     } //}}} 
    139  
    140     void update( float now ) { //{{{ 
     140    }// 
     141 
     142    void update( float now ) 
     143    {// 
    141144 
    142145        //TODO: speed should be linear, not circular 
     
    156159        } 
    157160 
    158     } //}}} 
    159  
    160     void receive_ship( Player ship_owner ) //{{{ 
    161     { 
     161    }// 
     162 
     163    void receive_ship( Player ship_owner ) 
     164    {// 
    162165        if( owner is ship_owner.world.god ) { 
    163166            // burn at the sun 
     
    191194            } 
    192195        } 
    193     } //}}} 
    194  
    195     int opCmp( Planet b ) { //{{{ 
     196    }// 
     197 
     198    int opCmp( Planet b ) 
     199    {// 
    196200        if( size > b.size) 
    197201            return -1; 
     
    200204        else 
    201205            return 0; 
    202     } //}}} 
    203  
    204 } //}}} 
    205  
    206 class Moon : Planet //{{{ 
    207 
    208     this( Planet planet_ ) { //{{{ 
     206    }// 
     207 
     208}// 
     209 
     210class Moon : Planet 
     211{// 
     212    this( Planet planet_ ) 
     213    {// 
    209214        parent = planet_; 
    210215        super( parent.owner, 
     
    214219        ); 
    215220        update( 0 ); // to compute initial position 
    216     } //}}} 
    217  
    218     void update( float now ) { //{{{ 
     221    }// 
     222 
     223    void update( float now ) 
     224    {// 
    219225        super.update( now ); 
    220226        x += parent.x; 
    221227        y += parent.y; 
    222     } //}}} 
    223  
    224 } //}}} 
    225  
    226 abstract class GameObject // {{{ base class for physical entities in the game 
    227 { 
     228    }// 
     229 
     230}// 
     231 
     232abstract class GameObject // base class for physical entities in the game 
     233{// 
    228234    float x; 
    229235    float y; 
     
    231237    Player owner; 
    232238 
    233     invariant { 
     239    invariant() 
     240    {// 
    234241        assert( x == x ); 
    235242        assert( y == y ); 
    236243        assert( size > 0 ); 
    237244        assert( owner !is null ); 
    238     } 
    239  
    240     this( float _x, float _y, float _size, Player _owner ) { 
     245    }// 
     246 
     247    this( float _x, float _y, float _size, Player _owner ) 
     248    {// 
    241249        x = _x; 
    242250        y = _y; 
    243251        size = _size; 
    244252        owner = _owner; 
    245     } 
    246  
    247     float dist2( float px, float py ) { 
     253    }// 
     254 
     255    float dist2( float px, float py ) 
     256    {// 
    248257        float dx = x - px; 
    249258        float dy = y - py; 
    250259        return dx*dx + dy*dy; 
    251     } 
    252  
    253     float dist2( GameObject a ) { 
     260    }// 
     261 
     262    float dist2( GameObject a ) 
     263    {// 
    254264        return dist2( a.x, a.y ); 
    255     } 
    256  
    257 } //}}} 
    258  
    259 // vim600:fdm=marker: 
     265    }// 
     266 
     267}// 
     268 
     269// vim600:fdm=marker:fmr={//,}//: 
  • trunk/src/player.d

    r48 r50  
    3838 
    3939    World world; 
    40     char[] name; 
     40    string name; 
    4141    Color color; 
    4242    List!(Planet) planets; 
     
    5151    //}// 
    5252 
    53     invariant 
     53    invariant() 
    5454    {// 
    5555        assert( world !is null ); 
     
    6161    //{// constructors 
    6262 
    63     this( World _world, char[] _name, Color _color ) { 
     63    this( World _world, string _name, Color _color ) 
     64    { 
    6465        world = _world; 
    6566        name = _name; 
     
    7071    } 
    7172 
    72     this( World _world, char[] _name ) { 
     73    this( World _world, string _name ) 
     74    { 
    7375        this( _world, _name, _world.hue_factory.next() ); 
    7476    } 
     
    137139class Human_Player : Player 
    138140{// 
    139     this( World _world, char[] _name, Color _color ) { 
     141    this( World _world, string _name, Color _color ) { 
    140142        super( _world, _name, _color ); 
    141143    } 
     
    160162class Neutral_Player : Player 
    161163{// 
    162     this( World _world, char[] _name, Color _color ) { 
     164    this( World _world, string _name, Color _color ) { 
    163165        super( _world, _name, _color ); 
    164166        update_score(); 
  • trunk/src/ui.d

    r47 r50  
    1 /*{{{ 
     1/*{// 
    22 
    33    QonkD - A simple space conquest strategy game 
     
    1919    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    2020 
    21 }}}*/ 
     21}//*/ 
    2222 
    2323module ui; 
    2424 
    25 // {{{ imports 
     25//{// imports 
     26import world; 
     27import events; 
    2628import color; 
    2729import config; 
     
    3133import messages; 
    3234import net; 
    33 import world; 
    3435import std.math; 
    3536import std.string; 
    3637debug import std.stdio; 
    37 //}}} 
     38//}// 
    3839 
    3940static bool running = true; 
    4041 
    4142class UI 
    42 { 
     43{// 
    4344    public: 
    4445 
    45     //{{{ class data 
     46    //{// class data 
    4647 
    4748    // game data 
     
    6364    } 
    6465 
    65     //}}} 
    66  
    67     this( Config cfg ) //{{{ 
    68     { 
     66    //}// 
     67 
     68    this( Config cfg ) 
     69    {// 
    6970        messages = new Messages; 
    7071        drag = new Drag; 
     
    7374        version(menu) { 
    7475            main_menu = new Menu; 
    75             main_menu ~= new MI_Action( "start game", &menu_start ); 
     76            main_menu ~= new MI_Action( "start singleplayer game", &menu_singleplayer ); 
    7677            main_menu ~= new MI_Int( "planets = %d", 6, 600, atoi(config["game_planets"]), &menu_planets ); 
    7778            main_menu ~= new MI_Int( "bots = %d", 1, 600-1, atoi(config["game_bots"]), &menu_bots ); 
     79            main_menu ~= new MI_Separator(); 
     80            version(network) { 
     81                main_menu ~= new MI_Action( "host network game", &menu_server ); 
     82                main_menu ~= new MI_Action( "join network game", &menu_client ); 
     83                main_menu ~= new MI_Separator(); 
     84            } 
     85            main_menu ~= new MI_Action( "start splitscreen multiplayer game", &menu_splitscreen ); 
     86            main_menu ~= new MI_Int( "players = %d", 1, 3, atoi(config["game_players"]), &menu_players ); 
     87            main_menu ~= new MI_Separator(); 
    7888            main_menu ~= new MI_Action( "exit", &menu_exit ); 
    7989 
     
    8898        is_running = true; 
    8999 
    90     } //}}} 
    91  
    92     void start_singleplayer() //{{{ 
    93     { 
     100    }// 
     101 
     102    void start_singleplayer() 
     103    {// 
    94104        uint planet_count = atoi(config["game_planets"]); 
    95105        assert( world is null ); 
     
    118128            } 
    119129        } 
    120     } //}}} 
    121  
    122     void start_multiplayer() //{{{ 
    123     { 
    124         uint local_port = atoi( config["net_local_port"] ); 
    125         uint remote_port = atoi( config["net_remote_port"] ); 
    126         net = new Net( local_port ); 
     130    }// 
     131 
     132    /* 
     133    void start_multiplayer() 
     134    {// 
    127135        if( config["net_remote_addr"] != "" ) { 
    128             assert( net.connect( config["net_remote_addr"], remote_port ) ); 
    129             world = net.get_world(); 
     136            // join 
     137            net = new Net_Client( config["net_remote_addr"], atoi(config["net_remote_port"]) ); 
     138            //world = new World(); 
    130139        } 
    131140        else { 
    132             uint planet_count = atoi( config["game_planets"] ); 
    133             world = new World( planet_count ); 
     141            // host 
     142            net = new Net_Server( atoi(config["net_local_port"]) ); 
     143            //world = new World( atoi(config["game_planets"]) ); 
    134144        } 
    135145 
     
    137147        control_count = 1; 
    138148        controls[0] = new Control( 0, world, "me", Color("white") ); 
    139         world.player_join( controls[0] ); 
    140     } //}}} 
    141  
    142     //{{{ menu callbacks 
     149        //world.player_join( controls[0] ); 
     150    }// 
     151    */ 
     152 
     153    //{// menu callbacks 
    143154 
    144155    version(menu) { 
    145         void menu_start() { 
     156 
     157        void menu_singleplayer() { 
     158            active_menu = null; 
     159            config["game_players"] = "1"; 
     160            start_singleplayer(); 
     161        } 
     162 
     163        void menu_splitscreen() { 
    146164            active_menu = null; 
    147165            start_singleplayer(); 
    148166        } 
    149167 
    150         void menu_exit() { 
    151             is_running = false; 
     168        void menu_server() { 
     169        } 
     170 
     171        void menu_client() { 
    152172        } 
    153173 
     
    163183            return n; 
    164184        } 
    165     } 
    166  
    167     //}}} 
    168  
    169     void select( Control player, bool all = false ) //{{{ 
    170     { 
     185 
     186        int menu_players( int n ) { 
     187            config["game_players"] = std.string.toString(n); 
     188            return n; 
     189        } 
     190 
     191        void menu_exit() { 
     192            is_running = false; 
     193        } 
     194    } 
     195 
     196    //}// 
     197 
     198    void select( Control player, bool all = false ) 
     199    {// 
    171200        if( player !is null ) { 
    172201            player.selected_planets.remove_all(); 
    173             foreach( Planet p; player.planets ) { 
     202            foreach( p; player.planets ) { 
    174203                if( all || drag.is_inside( p.x, p.y ) ) 
    175204                    player.selected_planets.append( p ); 
    176205            } 
    177206        } 
    178     } //}}} 
    179  
    180     void process_event( Event e ) //{{{ 
    181     { 
     207    }// 
     208 
     209    void process_ui_event( Event e ) 
     210    {// 
    182211        version(menu) { 
    183212            if( active_menu is null ) 
    184                 process_game_event( e ); 
     213                process_game_ui_event( e ); 
    185214            else { 
    186215                if( e.name == "down" ) { 
     
    192221            } 
    193222        } else { 
    194             process_game_event( e ); 
    195         } 
    196     } //}}} 
    197  
    198     void process_game_event( Event e ) //{{{ 
    199     { 
     223            process_game_ui_event( e ); 
     224        } 
     225    }// 
     226 
     227    void process_game_ui_event( Event e ) 
     228    {// 
    200229        assert( world !is null ); 
    201230        const bool select_while_dragging = true; // move to preferences? 
    202         const real drag_threshold = 2*world.ship_size; 
     231        const float drag_threshold = 2*world.ship_size; 
    203232        uint player_idx = ( control_count > 1 ) ? e.player : 0; 
    204233        Control player = controls[player_idx]; 
     
    319348        } 
    320349 
    321     } //}}} 
    322  
    323     void process_tick( real now ) //{{{ 
    324     { 
    325         void do_process_tick( real now ) { 
     350    }// 
     351 
     352    void process_tick( float now ) 
     353    {// 
     354        void do_process_tick( float now ) { 
     355 
     356            if( net ) { 
     357                net.send_events( world.events ); 
     358                world.events ~= net.receive_events(); 
     359            } 
     360 
    326361            for( uint i = 0; i < control_count; i++ ) { 
    327362                if( controls[i].activate_repeat.update( now ) ) 
    328363                    controls[i].game_activate(); 
    329364            } 
     365 
    330366            world.update( now ); 
    331  
    332             if( net ) { 
    333                 net.send_events( world.events); 
    334                 net.listen(); 
    335             } 
    336367 
    337368            process_game_events(); 
     
    345376        } 
    346377 
    347     } //}}} 
    348  
    349     void process_game_events() //{{{ 
    350     { 
    351         foreach( GameEvent e; world.events ) { 
    352             GameEvent_SendShip ev = cast(GameEvent_SendShip)e; 
     378    }// 
     379 
     380    void process_game_events() 
     381    {// 
     382        foreach( e; world.events ) { 
     383            auto ev = cast(GameEvent_SendShip)e; 
    353384            if( ev !is null ) 
    354385                ev.from.send_ship( ev.to ); 
    355386        } 
    356     } //}}} 
    357  
    358     void update_player_count( uint n_players_alive ) { //{{{ 
    359  
     387    }// 
     388 
     389    void update_player_count( uint n_players_alive ) 
     390    {// 
    360391        Player new_leader = world.players.head(); 
    361392        Control me = (control_count == 1) ? controls[0] : null; 
     
    383414            current_leader = new_leader; 
    384415        } 
    385     } //}}} 
    386  
    387 } 
    388  
    389 class Control : Human_Player //{{{ 
    390 { 
     416    }// 
     417 
     418}// 
     419 
     420class Control : Human_Player 
     421{// 
    391422    AutoRepeat activate_repeat; 
    392423    Planet cursor_planet = null; 
    393424    List!(Planet) selected_planets; 
    394     char[] send_mode; 
     425    string send_mode; 
    395426    uint idx; 
    396427 
    397     this( uint idx_, World world_, char[] name_, Color color_ ) //{{{ 
    398     { 
     428    this( uint idx_, World world_, string name_, Color color_ ) 
     429    {// 
    399430        super( world_, name_, color_ ); 
    400431        idx = idx_; 
     
    402433        activate_repeat = new AutoRepeat; 
    403434        send_mode = "nearest"; 
    404     } //}}} 
    405  
    406     void game_activate() //{{{ 
    407     { 
     435    }// 
     436 
     437    void game_activate() 
     438    {// 
    408439        if( cursor_planet ) { 
    409440 
    410441            Planet find_richest( List!(Planet) list ) { 
    411442                Planet richest; 
    412                 real richest_dist2; 
    413                 foreach( Planet p; list ) { 
     443                float richest_dist2; 
     444                foreach( p; list ) { 
    414445                    if( p !is cursor_planet && p.owner is this && p.nships > 0 ) { 
    415                         real dist2 = cursor_planet.dist2( p ); 
     446                        float dist2 = cursor_planet.dist2( p ); 
    416447                        if( richest is null || 
    417448                                p.nships > richest.nships || 
     
    444475 
    445476            if( from ) { 
    446                 world.events.append( new GameEvent_SendShip( from, cursor_planet ) ); 
    447             } 
    448         } 
    449     } //}}} 
    450  
    451     void move_cursor( char[] dir ) //{{{ 
    452     { 
     477                world.events ~= new GameEvent_SendShip( from, cursor_planet ); 
     478            } 
     479        } 
     480    }// 
     481 
     482    void move_cursor( string dir ) 
     483    {// 
    453484        if( cursor_planet is null ) { 
    454485            cursor_planet = planets.head(); 
     
    480511        } 
    481512 
    482     } //}}} 
    483  
    484 } //}}} 
    485  
    486 class Drag //{{{ 
    487 { 
     513    }// 
     514 
     515}// 
     516 
     517class Drag 
     518{// 
    488519    public: 
    489520 
    490521    bool pressed; 
    491     real x0, y0, x1, y1; 
    492  
    493     void down( real x, real y ) { 
     522    float x0, y0, x1, y1; 
     523 
     524    void down( float x, float y ) { 
    494525        pressed = true; 
    495526        x0 = x1 = x; 
     
    497528    } 
    498529 
    499     bool move( real x, real y, real threshold = 4 ) { 
     530    bool move( float x, float y, float threshold = 4 ) { 
    500531        if( pressed ) { 
    501532            if( x0 != x1 || ( abs(x-x0) > threshold ) ) { 
     
    517548    } 
    518549 
    519     bool is_inside( real x, real y ) { 
    520         real a0 = x0, b0 = y0, a1 = x1, b1 = y1; 
     550    bool is_inside( float x, float y ) { 
     551        float a0 = x0, b0 = y0, a1 = x1, b1 = y1; 
    521552        sort2( a0, a1 ); 
    522553        sort2( b0, b1 ); 
    523554        return( x >= a0 && x <= a1 && y >= b0 && y <= b1 ); 
    524555    } 
    525 } //}}} 
    526  
    527 class AutoRepeat //{{{ 
    528 { 
     556}// 
     557 
     558class AutoRepeat 
     559{// 
    529560    private: 
    530561 
     
    560591    } 
    561592 
    562 } //}}} 
    563  
    564 struct Event //{{{ 
    565 { 
     593}// 
     594 
     595struct Event 
     596{// 
    566597    float now; 
    567598    float x, y; 
    568     char[] name; 
    569     char[] func; 
     599    string name; 
     600    string func; 
    570601    int player; 
    571 } //}}} 
    572  
    573 // vim600:fdm=marker
     602}// 
     603 
     604// vim600:foldmethod=marker:foldmarker={//,}//
  • trunk/src/visual.d

    r48 r50  
    5252    } 
    5353 
    54     invariant 
     54    invariant() 
    5555    { 
    5656        assert( dpy !is null ); 
  • trunk/src/world.d

    r37 r50  
    1 /*{{{ 
     1/*{// 
    22 
    33    QonkD - A simple space conquest strategy game 
     
    1919    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
    2020 
    21 }}}*/ 
     21}//*/ 
    2222 
    2323module world; 
    2424 
    25 // {{{ imports 
     25//{// imports 
    2626 
    2727public import objects; 
    2828public import player; 
     29import events; 
    2930 
    3031import color; 
    3132import list; 
    3233 
    33 //}}} 
     34//}// 
    3435 
    3536class World 
     
    3738    public: 
    3839 
    39     this( uint planet_count ) { //{{{ 
    40  
     40    this (uint planet_count) 
     41    {// 
    4142        players = new List!(Player); 
    42         events = new List!(GameEvent); 
    4343        hue_factory = new HueFactory; 
    4444 
     
    6060        players.sort_me(); 
    6161 
    62     } //}}} 
     62    }// 
    6363 
    6464    // this( Net_World ) { TODO; } 
    6565 
    66     bool player_join( Player player ) { //{{{ 
     66    bool player_join( Player player ) 
     67    {// 
    6768 
    6869        // takes one planet from neutral player 
     
    8283 
    8384        return true; 
    84     } //}}} 
     85    }// 
    8586 
    86     Planet find_closest_planet( real x, real y, //{{{ 
     87    Planet find_closest_planet( float x, float y, 
    8788            bool delegate(Player a) player_cond = null, 
    88             bool delegate(Planet b) planet_cond = null 
    89     ) { 
     89            bool delegate(Planet b) planet_cond = null ) 
     90    {// 
    9091        Planet closest_planet; 
    91         real closest_distance; 
     92        float closest_distance; 
    9293 
    93         foreach( Player player; players ) { 
     94        foreach( player; players ) { 
    9495 
    9596            if( player is god ) 
     
    99100                continue; 
    100101 
    101             foreach( Planet planet; player.planets ) { 
     102            foreach( planet; player.planets ) { 
    102103 
    103104                if( planet_cond && !planet_cond( planet ) ) 
     
    105106 
    106107                if( closest_planet ) { 
    107                     real d = planet.dist2( x, y ); 
     108                    float d = planet.dist2( x, y ); 
    108109                    if( d < closest_distance ) { 
    109110                        closest_planet = planet; 
     
    119120 
    120121        return closest_planet; 
    121     } 
     122    }// 
    122123 
    123     //}}} 
    124  
    125     void update( real now ) { //{{{ 
     124    void update( float now ) 
     125    {// 
    126126 
    127127        if( last_update ) 
     
    131131        last_update = now; 
    132132 
    133         foreach( Player player; players ) { 
     133        foreach( player; players ) { 
    134134 
    135             foreach( Planet planet; player.planets ) 
     135            foreach( planet; player.planets ) 
    136136                planet.update( now ); 
    137137 
    138             foreach( FlyingShip ship; player.flying_ships ) 
     138            foreach( ship; player.flying_ships ) 
    139139                ship.update( now ); 
    140140 
    141141            player.update(); 
    142142        } 
    143     } //}}} 
     143    }// 
    144144 
    145     //{{{ class data 
     145    Player get_player( string name ) 
     146    {// 
     147        foreach( player; players ) { 
     148            if( player.name == name ) 
     149                return player; 
     150        } 
     151 
     152        return null; 
     153    }// 
     154 
     155    //{// class data 
    146156 
    147157    List!(Player) players; 
    148     const real ship_production_rate = 60; //120; 
    149     const real ship_size = 0.8; 
    150     const real min_moon_size = 2.; 
    151     const real max_moon_size = 2.5; 
    152     const real min_planet_size = 3.; 
    153     const real max_planet_size = 4.; 
    154     const real min_ship_speed = 60; 
    155     const real max_ship_speed = 90; 
    156     const real radius = 300; 
     158    const float ship_production_rate = 60; //120; 
     159    const float ship_size = 0.8; 
     160    const float min_moon_size = 2.; 
     161    const float max_moon_size = 2.5; 
     162    const float min_planet_size = 3.; 
     163    const float max_planet_size = 4.; 
     164    const float min_ship_speed = 60; 
     165    const float max_ship_speed = 90; 
     166    const float radius = 300; 
    157167 
    158168    bool started; 
     
    160170    int initial_ship_count = 3; 
    161171 
    162     real last_update = 0; 
    163     real dt; 
     172    float last_update = 0; 
     173    float dt; 
    164174 
    165     List!(GameEvent) events; 
     175    GameEvent[] events; 
    166176    HueFactory hue_factory; 
    167177 
     
    170180    Player god; 
    171181 
    172     //}}} 
     182    //}// 
    173183 
    174     invariant { //{{{ 
     184    invariant() 
     185    {// 
    175186        assert( players !is null ); 
    176187        assert( hue_factory !is null ); 
     
    178189        assert( god !is null ); 
    179190        assert( radius > 0 ); 
    180     } //}}} 
     191    }// 
    181192} 
    182193 
    183 // {{{ game events 
    184  
    185 // send_ship ( planet, planet ) 
    186 // attack ( planet, prev_owner ) 
    187 // spawn ship ( planet ) 
    188  
    189 abstract class GameEvent 
    190 
    191     //char[] serialize(); 
    192     //void deserialize( char[] ); 
    193 
    194  
    195 class GameEvent_Attack : GameEvent 
    196 
    197     Planet planet; 
    198     Player previous_owner; 
    199  
    200     this( Planet p, Player o = null ) { 
    201         planet = p; 
    202         previous_owner = o; 
    203     } 
    204 
    205  
    206 class GameEvent_SendShip : GameEvent 
    207 
    208     Planet from, to; 
    209  
    210     this( Planet from_, Planet to_ ) 
    211     { 
    212         from = from_; 
    213         to = to_; 
    214     } 
    215  
    216     /* 
    217     char[] serialize() 
    218     { 
    219         return format( "sendship:%d:%d", from.id, to.id ); 
    220     } 
    221  
    222     void deserialize( char[] str ) 
    223     { 
    224     } 
    225     */ 
    226 
    227  
    228 class GameEvent_SpawnShip : GameEvent 
    229 
    230     Planet planet; 
    231 
    232  
    233 //}}} 
    234  
    235 // vim600:fdm=marker: 
     194// vim600:fdm=marker:fmr={//,}//