Changeset 563

Show
Ignore:
Timestamp:
05/24/08 10:07:38 (8 months ago)
Author:
LeoD
Message:

removed cyclic import

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/run/data/shaders/combineLightmaps-pixel.glsl

    r560 r563  
    99    vec4 c = texture2D(lightmap, vec2(gl_TexCoord[0])); 
    1010 
    11     gl_FragColor = max(a, b * 0.5f) * c; 
     11    gl_FragColor = max(a, b * 0.65f) * c; 
    1212} 
  • trunk/src/defend/FogOfWar.d

    r561 r563  
    99import gen.util.Sprite; 
    1010import gen.util.Profiler; 
     11import gen.util.Memory; 
    1112import gen.math.Vector; 
    1213import gen.math.Rectangle; 
     
    3637 
    3738    bool firstVisited; 
     39 
     40    // arrays of visible and visited tiles 
     41    bool[] visibleTiles, visitedTiles; 
    3842 
    3943    void updateVisibleTexture() 
     
    154158 
    155159    // Generate a circle, which can be rendered on the fog of war texture 
    156     static Texture generateCircle(vec2i size = vec2i(64, 64), float intensity = 1.3
     160    static Texture generateCircle(vec2i size = vec2i(64, 64), float intensity = 5
    157161    { 
    158162        scope image = new Image(size.tuple, ImageFormat.A); 
  • trunk/src/defend/Map.d

    r550 r563  
    1212 
    1313import defend.com.Types; 
    14 import defend.terrain.Terrain
     14import defend.terrain.Heightmap
    1515 
    1616Map map; 
     
    7171    } 
    7272 
    73     void copyTiles(
     73    void copyTiles(TerrainHeightmap heightmap
    7474    { 
    7575        for(uint x = 0; x < size.x; x++) 
     
    7878            { 
    7979                auto tile = getTile(x, y); 
    80                 tile.height = terrain.getHeight(x, y); 
     80                tile.height = heightmap.getHeight(x, y); 
    8181                tile.pos = MapPos(x, y); 
    8282 
     
    112112                foreach(neighbor; possibleNeighbors(x, y)) 
    113113                { 
    114                     if(terrain.within(neighbor)) 
     114                    if(within(neighbor)) 
    115115                        calcTileCost(neighbor); 
    116116 
     
    133133    } 
    134134 
    135     void initPathfinding(
    136     { 
    137         copyTiles(); 
     135    void initPathfinding(TerrainHeightmap heightmap
     136    { 
     137        copyTiles(heightmap); 
    138138        calculateTileCosts(); 
    139139        connectTiles(Rect(0, 0, size.x, size.y)); 
     
    192192        { 
    193193            foreach(i, neighbor; possibleNeighbors(x, y)) 
    194                 if(terrain.within(neighbor)) 
     194                if(within(neighbor)) 
    195195                { 
    196196                    auto neighborTile = getTile(neighbor); 
     
    216216    } 
    217217 
     218    bool within(vec2us p) 
     219    { 
     220        return within(p.x, p.y); 
     221    } 
     222 
     223    bool within(ushort x, ushort y) 
     224    { 
     225        return x >= 0 && y >= 0 && x < size.x && y < size.y; 
     226    } 
     227 
    218228public: 
    219229    mixin MAllocator; 
    220230 
    221     this() 
    222     { 
    223         assert(terrain !is null, "terrain has to be initialized before the map"); 
     231    this(TerrainHeightmap heightmap) 
     232    { 
    224233        assert(map is null, "there may only be one map"); 
    225234 
    226         size = MapPos(terrain.dimension.x, terrain.dimension.y)
     235        size = heightmap.size
    227236        tiles.alloc(size.x * size.y); 
    228237         
    229238        posPool.create(MAX_PATH_LENGTH, MAX_THREADS * BUFFERS_PER_THREAD); 
    230239 
    231         initPathfinding();  
     240        initPathfinding(heightmap);  
    232241    } 
    233242 
     
    258267    MapTile* getTile(uint x, uint y) 
    259268    { 
    260         assert(terrain.within(x, y)); 
     269        assert(within(x, y)); 
    261270        return &tiles[x + y * size.x]; 
    262271    } 
     
    419428    in 
    420429    { 
    421         assert(terrain.within(to)); 
    422         assert(terrain.within(from));  
     430        assert(within(to)); 
     431        assert(within(from));  
    423432    } 
    424433    body 
     
    437446            for(int y = cast(int)to.y - i; y <= cast(int)to.y + i; y++) 
    438447            { 
    439                 if(terrain.within(cast(int)to.x - i, y)) 
     448                if(within(cast(int)to.x - i, y)) 
    440449                { 
    441450                    tileList[listIndex] = MapPos(cast(int)to.x - i, y); 
     
    443452                } 
    444453 
    445                 if(terrain.within(cast(int)to.x + i, y)) 
     454                if(within(cast(int)to.x + i, y)) 
    446455                { 
    447456                    tileList[listIndex] = MapPos(cast(int)to.x + i, y); 
     
    452461            for(int x = cast(int)to.x - i + 1; x <= cast(int)to.x + i - 1; x++) 
    453462            { 
    454                 if(terrain.within(x, cast(int)to.y - i)) 
     463                if(within(x, cast(int)to.y - i)) 
    455464                { 
    456465                    tileList[listIndex] = MapPos(x, cast(int)to.y - i); 
     
    458467                } 
    459468 
    460                 if(terrain.within(x, cast(int)to.y + i)) 
     469                if(within(x, cast(int)to.y + i)) 
    461470                { 
    462471                    tileList[listIndex] = MapPos(x, cast(int)to.y + i); 
     
    529538                x <= cast(int)end.x + searchBorder; x++) 
    530539            { 
    531                 if(terrain.within(x, y)) 
     540                if(within(x, y)) 
    532541                    getTile(x, y).open = false; 
    533542            } 
     
    549558                    x <= cast(int)end.x + searchBorder; x++) 
    550559                { 
    551                     if(terrain.within(x, y) && !getTile(x, y).open) 
     560                    if(within(x, y) && !getTile(x, y).open) 
    552561                    { 
    553562                        for(uint i = 0; i < 8; i++) 
  • trunk/src/defend/demo/Demo.d

    r561 r563  
    1818import defend.MapGenerator; 
    1919import defend.Camera; 
     20import defend.FogOfWar; 
    2021import defend.Simulation; 
    2122import defend.com.Gateway; 
     
    4849        { 
    4950            terrain = new Terrain(sceneGraph.root, heightmap); 
    50             map = new Map
     51            map = new Map(heightmap)
    5152        }, gameObjects, players); 
    5253    } 
     
    7778        demoPlayer.init(); 
    7879        assert(terrain !is null); 
     80         
     81        fogOfWar = new FogOfWar(gameObjects, terrain.lightmapTexture, vec2i.from(terrain.dimension)); 
    7982 
    8083        taskManager.addRepeatedTask(&InputChannel.global.update, 100); 
     
    8891    { 
    8992        delete demoPlayer; 
     93        delete fogOfWar; 
    9094        delete gameObjects; 
    9195        delete players; 
  • trunk/src/defend/game/Game.d

    r562 r563  
    132132        { 
    133133            terrain = new Terrain(sceneGraph.root, heightmap); 
    134             map = new Map
     134            map = new Map(heightmap)
    135135        }, gameObjects, players); 
    136136         
  • trunk/src/defend/game/hud/Hud.d

    r541 r563  
    270270            guiRenderer = new GuiRenderer(); 
    271271         
    272         miniMap = new MiniMap
     272        miniMap = new MiniMap(gameObjects)
    273273        mouse = new Mouse(gameObjects, guiController, miniMap); 
    274274 
  • trunk/src/defend/game/hud/MiniMap.d

    r562 r563  
    33import tango.io.Stdout; 
    44 
     5import gen.core.TaskManager; 
    56import gen.image.Image; 
    67import gen.math.Rectangle; 
     
    1920import defend.Config; 
    2021import defend.FogOfWar; 
     22import defend.objects.Core; 
    2123import defend.terrain.Terrain; 
    2224 
     
    2729    const height = 128; 
    2830 
    29     Image image; 
     31    GameObjectManager gameObjects; 
     32     
    3033    Texture texture; 
    3134    Sprite sprite; 
     35 
     36    Framebuffer objectLayer; 
    3237 
    3338    vec2i position; 
     
    3540    void renderTerrain() 
    3641    { 
    37         assert(terrain !is null); 
    38         assert(texture !is null); 
     42        with(renderer) 
     43        { 
     44            assert(terrain !is null); 
     45            assert(texture !is null); 
    3946 
    40         renderer.pushMatrix(MatrixType.Projection); 
    41         renderer.setViewport(Rect(0, 0, width, height)); 
     47            setViewport(Rect(0, 0, width, height)); 
    4248 
    43         GLint[4] viewport; 
    44         glGetIntegerv(GL_VIEWPORT, viewport.ptr); 
     49            identity(MatrixType.Projection); 
     50            orthogonal(vec2i.from(terrain.dimension) - vec2i.one); 
     51             
     52            identity(MatrixType.Modelview); 
     53             
     54            { 
     55                auto center = vec2( (terrain.dimension.x - 1), 
     56                                   -(terrain.dimension.y - 1)); 
     57                 
     58                gluLookAt(center.x, 500.0f, center.y, center.x, 0.0f, 
     59                          center.y, 0.0f, 0.0f, 1.0f); 
     60            } 
     61 
     62            clear(); 
     63            terrain.renderOrthogonal(); 
     64 
     65            texture.copyFromScreen(); 
     66            clear(); 
     67        } 
     68    } 
     69 
     70    void updateObjects() 
     71    { 
    4572         
    46         glMatrixMode(GL_PROJECTION); 
    47         glLoadIdentity(); 
    48          
    49         glOrtho(terrain.dimension.x - 1, 0, terrain.dimension.y - 1, 0, 0, 1337); 
    50          
    51         renderer.identity(MatrixType.Modelview); 
    52          
    53         auto center = vec2( (terrain.dimension.x - 1), 
    54                            -(terrain.dimension.y - 1)); 
    55          
    56         gluLookAt(center.x, 500.0f, center.y, center.x, 0.0f, 
    57                   center.y, 0.0f, 0.0f, 1.0f); 
    58  
    59         renderer.clear(); 
    60         terrain.renderOrthogonal(); 
    61  
    62         texture.copyFromScreen(); 
    63         renderer.clear(); 
    64  
    65         renderer.popMatrix(MatrixType.Projection); 
    66         renderer.setViewport(Rect(0, 0, renderer.width, renderer.height)); 
    6773    } 
    6874 
     
    7076    mixin MAllocator; 
    7177 
    72     this(
     78    this(GameObjectManager gameObjects
    7379    { 
     80        this.gameObjects = gameObjects; 
     81     
    7482        if(!texture) 
    7583        { 
    76             texture = renderer.createTexture(vec2i(width, height), ImageFormat.RGB); 
     84            texture = renderer.createTexture(vec2i(width, height)); 
    7785            renderTerrain(); 
    7886        } 
     
    8189        sprite.scaling = vec2(128.0f / width, 128.0f / width); 
    8290         
     91        objectLayer = renderer.createFramebuffer(vec2i(width, height)); 
     92         
    8393        position = vec2i(renderer.width - 150, renderer.height - HUD_HEIGHT + 10); 
     94         
     95        taskManager.addRepeatedTask(&updateObjects, 10); 
    8496    } 
    8597 
  • trunk/src/defend/objects/Core.d

    r551 r563  
    2929import defend.Map; 
    3030import defend.Config; 
    31 import defend.terrain.Terrain; 
     31//import defend.terrain.Terrain; 
    3232import defend.player.Manager; 
    3333import defend.com.Types; 
     
    676676 
    677677public: 
     678    // Culled by fog of war 
     679    bool fogOfWarCulled = false; 
     680 
    678681    ~this() 
    679682    { 
     
    835838        assert(result.left >= 0); 
    836839        assert(result.top >= 0); 
    837         assert(result.right < terrain.dimension.x); 
    838         assert(result.bottom < terrain.dimension.y); 
     840        assert(result.right < map.size.x); 
     841        assert(result.bottom < map.size.y); 
    839842    } 
    840843    body 
     
    843846                                        mapPos.y >= radius ? mapPos.y - radius : 0, 
    844847                     
    845                                         mapPos.x + typeInfo.dimension.x + radius < terrain.dimension.x ? 
     848                                        mapPos.x + typeInfo.dimension.x + radius < map.size.x ? 
    846849                                        mapPos.x + typeInfo.dimension.x + radius : 
    847850                                        mapPos.x + typeInfo.dimension.x, 
    848851                     
    849                                         mapPos.y + typeInfo.dimension.y + radius < terrain.dimension.y ? 
     852                                        mapPos.y + typeInfo.dimension.y + radius < map.size.y ? 
    850853                                        mapPos.y + typeInfo.dimension.y + radius : 
    851854                                        mapPos.y + typeInfo.dimension.y); 
  • trunk/src/defend/terrain/Terrain.d

    r562 r563  
    422422            renderer.setTexture(0, null); 
    423423 
     424            // debugging if the unit sight ranges are scaled correctly 
     425            /*renderer.setRenderState(RenderState.Wireframe, true); 
     426            renderer.setRenderState(RenderState.Blending, true); 
     427            renderer.setColor(vec4(1, 1, 1, 0.5)); 
     428             
     429            renderer.translate(0, 0.1, 0); 
     430             
     431            foreach(patch; patches) 
     432                if(patch.visible) patch.render(); 
     433             
     434            renderer.setRenderState(RenderState.Blending, false); 
     435            renderer.setRenderState(RenderState.Wireframe, false);*/ 
     436 
    424437            debug if(sceneGraph.debugNodeVisible(this)) 
    425438                foreach(patch; patches) if(patch.visible) 
  • trunk/src/defend/terrain/Vertex.d

    r465 r563  
    1515                add(VertexUsage.Texture3). 
    1616                add(VertexUsage.Texture4). 
    17                 add(VertexUsage.Normal). 
    1817                add(VertexUsage.Position); 
    1918    } 
     
    2827        result.texture3 = texture3; 
    2928        result.texture4 = texture4; 
    30         result.normal = vec3(0.0, 1.0, 0.0); 
    3129        result.position = position; 
    3230 
     
    3836    vec2 texture3; 
    3937    vec2 texture4; 
    40     vec3 normal; 
    4138    vec3 position; 
    4239} 
  • trunk/src/gen/core/TaskManager.d

    r506 r563  
    3838} 
    3939 
    40 // Stolen from deadlock, slightly modified 
     40// Stolen from Deadlock, slightly modified 
    4141 
    4242final class TaskManager 
  • trunk/src/gen/rend/Renderer.d

    r555 r563  
    189189 
    190190/** 
     191 * Capabilities 
     192 */ 
     193struct RendererCaps 
     194{ 
     195    bool multiTexturing; 
     196    bool shaders; 
     197    bool framebuffers; 
     198    bool vertexBuffers; 
     199} 
     200 
     201/** 
    191202 * 3D-renderer interface 
    192203 */ 
    193204abstract class Renderer 
    194205{ 
     206    /** 
     207     * Returns the renderer's capabilities 
     208     */ 
     209    RendererCaps caps(); 
     210 
    195211    /** 
    196212     * Clears the screen. 
  • trunk/src/gen/rend/opengl/Renderer.d

    r562 r563  
    2929import derelict.opengl.extension.arb.multitexture; 
    3030import derelict.opengl.extension.arb.vertex_buffer_object; 
     31import derelict.opengl.extension.arb.vertex_shader; 
     32import derelict.opengl.extension.arb.fragment_shader; 
     33import derelict.opengl.extension.ext.framebuffer_object; 
    3134 
    3235import gen.util.Log; 
     
    8689    Logger logger; 
    8790 
     91    RendererCaps _caps; 
     92 
    8893    RendererConfig _config; 
    8994    Window _window; 
     
    260265    } 
    261266 
     267    void initCaps() 
     268    { 
     269        with(_caps) 
     270        { 
     271            multiTexturing = ARBMultitexture.isEnabled; 
     272            shaders = ARBVertexShader.isEnabled && ARBFragmentShader.isEnabled; 
     273            framebuffers = EXTFramebufferObject.isEnabled; 
     274            vertexBuffers = ARBVertexBufferObject.isEnabled; 
     275        } 
     276    } 
     277 
    262278public: 
    263279    this(RendererConfig c) 
     
    274290        DerelictGL.loadExtensions(); 
    275291         
     292        initCaps(); 
     293         
    276294        DerelictGLU.load(); 
    277          
    278         if(!ARBVertexBufferObject.isEnabled) 
    279             logger.warn("vertex buffer objects extension not available, rendering might be slow"); 
    280              
    281         if(!ARBMultitexture.isEnabled) 
    282             logger.info("multitexturing extension not available; disabling"); 
    283295    } 
    284296 
     
    304316    } 
    305317 
     318    override RendererCaps caps() 
     319    { 
     320        return _caps; 
     321    } 
     322 
    306323    override void clear(vec3 color2 = vec3.zero, bool color = true, bool depth = true) 
    307324    { 
  • trunk/src/gen/rend/opengl/Texture.d

    r541 r563  
    116116        bind(); 
    117117         
    118         //glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height); 
    119         glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, width, height, 0); 
     118        glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, width, height); 
     119        //glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, width, height, 0); 
    120120    } 
    121121