Changeset 573

Show
Ignore:
Timestamp:
05/24/08 17:45:26 (8 months ago)
Author:
LeoD
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/defend/game/Game.d

    r567 r573  
    1717import gen.util.Profiler; 
    1818import gen.util.GameState; 
     19import gen.util.Resource; 
    1920 
    2021import defend.Config; 
     
    338339        logObjectUsage(); 
    339340         
     341        // print out a list of loaded resources, for debugging 
     342        Resource.dump(); 
     343         
    340344        //dumpGCStats(); 
    341345    } 
  • trunk/src/defend/game/hud/MiniMap.d

    r567 r573  
    100100        delete sprite; 
    101101        delete texture; 
     102        delete objectLayer; 
    102103    } 
    103104 
  • trunk/src/defend/sim/Core.d

    r572 r573  
    670670 
    671671public: 
    672     // Culled by fog of war 
     672    // Culled by fog of war? 
    673673    bool fogOfWarCulled = false; 
    674674 
  • trunk/src/defend/sim/obj/Unit.d

    r572 r573  
    358358    vec3 _direction; 
    359359    vec3 direction() { return _direction; } 
    360     void direction(vec3 v) { logger.spam("new dir"); assert(v.ok); _direction = v; } 
     360    void direction(vec3 v) { assert(v.ok); _direction = v; } 
    361361     
    362362    vec3 _finalDirection; 
    363363    vec3 finalDirection() { return _finalDirection; } 
    364     void finalDirection(vec3 v) { logger.spam("final dir"); assert(v.ok); _finalDirection = v; } 
     364    void finalDirection(vec3 v) { assert(v.ok); _finalDirection = v; } 
    365365     
    366366    fixed movePercent; // from 0 to 1000 
  • trunk/src/defend/terrain/FogOfWar.d

    r570 r573  
    99import gen.util.Sprite; 
    1010import gen.util.Profiler; 
    11 import gen.util.Memory; 
     11import gen.util.Array; 
    1212import gen.math.Vector; 
    1313import gen.math.Rectangle; 
     
    3636    Texture circleTexture; 
    3737 
     38    Shader copyShader; 
     39    Shader combineShader; 
     40 
    3841    bool firstVisited; 
    3942 
    4043    // arrays of visible and visited tiles 
    41     bool[] visibleTiles, visitedTiles; 
     44    Array2D!(bool) visibleTiles, visitedTiles; 
    4245 
    4346    void updateVisibleTexture() 
     
    5760            foreach(object; gameObjects) 
    5861            { 
     62                // TODO: fog of war needs to include any object of the own team 
    5963                if(object.mayBeOrdered) 
    6064                { 
     
    8791            if(!firstVisited) { clear(); firstVisited = true; } 
    8892     
    89             auto shader = Shader.get("data/shaders/copyVisibleFog.cfg")
     93            auto shader = copyShader
    9094            setShader(shader); 
    9195             
     
    113117            clear(); 
    114118             
    115             auto shader = Shader.get("data/shaders/combineLightmaps.cfg")
     119            auto shader = combineShader
    116120            setShader(shader); 
    117121                 
     
    136140    { 
    137141        profile!("fog of war") 
    138         ({           
     142        ({ 
     143            updateTiles(); 
     144         
    139145            with(renderer) 
    140146            { 
     
    155161            } 
    156162        }); 
     163    } 
     164     
     165    void updateTiles() 
     166    { 
     167        visibleTiles.reset(); 
     168     
     169        foreach(object; gameObjects) with(object) 
     170        { 
     171            // TODO: fog of war needs to include any object of the own team 
     172            if(mayBeOrdered) 
     173            { 
     174                auto ti = typeInfo; 
     175                 
     176                visibleTiles.fill(true, mapPos.x, mapPos.y, ti.dimension.x, ti.dimension.y); 
     177                visitedTiles.fill(true, mapPos.x, mapPos.y, ti.dimension.x, ti.dimension.y); 
     178            } 
     179        } 
     180         
     181        foreach(object; gameObjects) with(object) 
     182        { 
     183            if(mayBeOrdered) 
     184                continue; 
     185             
     186            auto ti = typeInfo; 
     187            bool cull = true; 
     188             
     189            fogOfWarCulled = false; 
     190 
     191            foreach(tile; visibleTiles.iterate(mapPos.x, mapPos.y, ti.dimension.x, ti.dimension.y)) 
     192            { 
     193                if(tile) 
     194                { 
     195                    cull = false; 
     196                    break; 
     197                } 
     198            } 
     199                 
     200            fogOfWarCulled = cull; 
     201            if(cull) synchronized(Stdout) Stdout("fog of war culled: ")(object.id).newline; 
     202        } 
    157203    } 
    158204 
     
    186232            circleTexture = generateCircle(); 
    187233            sprite = new Sprite(lightmap.dimension, true); 
     234            copyShader = Shader.acquire("data/shaders/copyVisibleFog.cfg"); 
     235            combineShader = Shader.acquire("data/shaders/combineLightmaps.cfg"); 
     236             
     237            visibleTiles.create(dimension.tuple); 
     238            visitedTiles.create(dimension.tuple); 
    188239             
    189240            taskManager.addRepeatedTask(&update, 15); 
    190241        } 
    191242    } 
    192      
     243 
    193244    ~this() 
    194245    { 
     
    200251            delete circleTexture; 
    201252            delete sprite; 
     253             
     254            Shader.release(copyShader); 
     255            Shader.release(combineShader); 
     256             
     257            visibleTiles.release(); 
     258            visitedTiles.release(); 
    202259        } 
    203260    } 
  • trunk/src/defend/terrain/Terrain.d

    r566 r573  
    361361        if(heightmap) delete _heightmap; 
    362362        if(lightmapTexture) delete lightmapTexture; 
     363        if(alphaMap) delete alphaMap; 
    363364        if(detailTexture) Texture.release(detailTexture); 
    364365         
  • trunk/src/gen/rend/opengl/FBO.d

    r551 r573  
    7373    } 
    7474     
     75    ~this() { delete target; } 
     76     
    7577    override Texture texture() 
    7678    { 
  • trunk/src/gen/util/Array.d

    r464 r573  
    22 
    33import tango.io.Stdout; 
     4 
     5import gen.util.Allocator; 
     6import gen.util.Memory; 
    47 
    58bool hasElement(T)(T[] array, T what) 
     
    5760    assert([1].remove(0) == cast(int[])[]); 
    5861} 
     62 
     63struct Array2D(T, Alloc = CLibAllocator) 
     64{ 
     65private: 
     66    T[] data; 
     67 
     68    uint _width; 
     69    uint _height; 
     70 
     71    struct Iterator 
     72    { 
     73        Array2D* array; 
     74        uint x, y, w, h; 
     75         
     76        int opApply(int delegate(ref T value) dg) 
     77        { 
     78            for(uint _x = x; _x < x + w; _x++) 
     79            { 
     80                for(uint _y = y; _y < y + h; _y++) 
     81                { 
     82                    if(auto result = dg(array.data[_x + _y * array.width]) != 0) 
     83                        return result; 
     84                } 
     85            } 
     86             
     87            return 0; 
     88        } 
     89    } 
     90 
     91public: 
     92    void create(uint width, uint height) 
     93    { 
     94        this._width = width; 
     95        this._height = height; 
     96     
     97        alloc!(Alloc, T)(data, width * height); 
     98    } 
     99     
     100    void release() 
     101    { 
     102        free!(Alloc, T)(data); 
     103    } 
     104     
     105    uint width() 
     106    { 
     107        return _width; 
     108    } 
     109     
     110    uint height() 
     111    { 
     112        return _height; 
     113    } 
     114     
     115    T opIndex(uint x, uint y) 
     116    { 
     117        return data[x + y * width]; 
     118    } 
     119     
     120    T opIndexAssign(T value, uint x, uint y) 
     121    { 
     122        return data[x + y * width] = value; 
     123    } 
     124     
     125    void fill(T value, uint x, uint y, uint w, uint h) 
     126    { 
     127        data[x + y * width .. (x + w) + (y + h) * width] = value; 
     128    } 
     129     
     130    Iterator iterate(uint x, uint y, uint w, uint h) 
     131    { 
     132        Iterator result = void; 
     133        result.array = this; 
     134        result.x = x; 
     135        result.y = y; 
     136        result.w = w; 
     137        result.h = h; 
     138         
     139        return result; 
     140    } 
     141     
     142    void reset() 
     143    { 
     144        data[] = T.init; 
     145    } 
     146} 
  • trunk/src/gen/util/GameState.d

    r560 r573  
    1313{ 
    1414    /* Initialize the gamestate. That means, load resources and create tasks. 
    15        There is no update or render functions, so the gamestate can only get updated 
     15       There are no update or render functions, so the gamestate can only get updated 
    1616       via tasks. */ 
    1717    void init(); 
     
    8080        if(memoryUsageBefore != -1) 
    8181        { 
    82             if(getMemoryUsage() > memoryUsageBefore) 
     82            if(getMemoryUsage() != memoryUsageBefore) 
    8383            { 
    8484                logger.warn("gamestate `{}' is not clean, {} bytes of memory are left", 
     
    8686            } 
    8787            else 
    88                 logger.info("gamestate `{}' is clean.", state.classinfo.name); 
     88                logger.info("gamestate `{}' is clean", state.classinfo.name); 
    8989        } 
    9090    } 
  • trunk/src/gen/util/MemoryPool.d

    r501 r573  
    101101            } 
    102102             
    103             Memory.memoryUsage -= T.classinfo.init.length * freeQueue.bufferSize
     103            Memory.memoryUsage -= T.classinfo.init.length * maxObjects
    104104             
    105105            static if(!initialize) 
  • trunk/src/gen/util/Resource.d

    r565 r573  
    11module gen.util.Resource; 
     2 
     3struct Resource 
     4{ 
     5private: 
     6    static void function()[] dumps; 
     7 
     8public: 
     9    static void addType(T)() 
     10    { 
     11        dumps ~= &T.dump; 
     12    } 
     13     
     14    static void dump() 
     15    { 
     16        foreach(d; dumps) 
     17            d(); 
     18    } 
     19} 
    220 
    321template MResource() 
     
    523private: 
    624    import tango.io.FilePath; 
     25    import tango.text.Ascii : toLower; 
     26 
    727    import gen.util.Config; 
    828    import gen.util.Log; 
    9     import tango.text.Ascii : toLower; 
    1029 
    1130    alias typeof(this) T; 
     
    2241    { 
    2342        logger = Log.getLogger("resource." ~ toLower(T.stringof)); 
     43        Resource.addType!(T); 
    2444    } 
    2545 
     
    7090    static void release(T instance) 
    7191    { 
    72         if(--instance.refCount == 0) 
     92        if(instance.refCount == 0 || --instance.refCount == 0) 
    7393        { 
    7494            char[] file = instance.file; 
     
    81101        } 
    82102    } 
     103     
     104    // Print out a list of loaded resources 
     105    static void dump() 
     106    { 
     107        foreach(key, val; instances) 
     108            logger.info("loaded: `{}'", key); 
     109    } 
    83110}