Changeset 563
- Timestamp:
- 05/24/08 10:07:38 (8 months ago)
- Files:
-
- trunk/run/data/shaders/combineLightmaps-pixel.glsl (modified) (1 diff)
- trunk/src/defend/FogOfWar.d (modified) (3 diffs)
- trunk/src/defend/Map.d (modified) (15 diffs)
- trunk/src/defend/demo/Demo.d (modified) (4 diffs)
- trunk/src/defend/game/Game.d (modified) (1 diff)
- trunk/src/defend/game/hud/Hud.d (modified) (1 diff)
- trunk/src/defend/game/hud/MiniMap.d (modified) (6 diffs)
- trunk/src/defend/objects/Core.d (modified) (4 diffs)
- trunk/src/defend/terrain/Terrain.d (modified) (1 diff)
- trunk/src/defend/terrain/Vertex.d (modified) (3 diffs)
- trunk/src/gen/core/TaskManager.d (modified) (1 diff)
- trunk/src/gen/rend/Renderer.d (modified) (1 diff)
- trunk/src/gen/rend/opengl/Renderer.d (modified) (5 diffs)
- trunk/src/gen/rend/opengl/Texture.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/run/data/shaders/combineLightmaps-pixel.glsl
r560 r563 9 9 vec4 c = texture2D(lightmap, vec2(gl_TexCoord[0])); 10 10 11 gl_FragColor = max(a, b * 0. 5f) * c;11 gl_FragColor = max(a, b * 0.65f) * c; 12 12 } trunk/src/defend/FogOfWar.d
r561 r563 9 9 import gen.util.Sprite; 10 10 import gen.util.Profiler; 11 import gen.util.Memory; 11 12 import gen.math.Vector; 12 13 import gen.math.Rectangle; … … 36 37 37 38 bool firstVisited; 39 40 // arrays of visible and visited tiles 41 bool[] visibleTiles, visitedTiles; 38 42 39 43 void updateVisibleTexture() … … 154 158 155 159 // 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) 157 161 { 158 162 scope image = new Image(size.tuple, ImageFormat.A); trunk/src/defend/Map.d
r550 r563 12 12 13 13 import defend.com.Types; 14 import defend.terrain. Terrain;14 import defend.terrain.Heightmap; 15 15 16 16 Map map; … … 71 71 } 72 72 73 void copyTiles( )73 void copyTiles(TerrainHeightmap heightmap) 74 74 { 75 75 for(uint x = 0; x < size.x; x++) … … 78 78 { 79 79 auto tile = getTile(x, y); 80 tile.height = terrain.getHeight(x, y);80 tile.height = heightmap.getHeight(x, y); 81 81 tile.pos = MapPos(x, y); 82 82 … … 112 112 foreach(neighbor; possibleNeighbors(x, y)) 113 113 { 114 if( terrain.within(neighbor))114 if(within(neighbor)) 115 115 calcTileCost(neighbor); 116 116 … … 133 133 } 134 134 135 void initPathfinding( )136 { 137 copyTiles( );135 void initPathfinding(TerrainHeightmap heightmap) 136 { 137 copyTiles(heightmap); 138 138 calculateTileCosts(); 139 139 connectTiles(Rect(0, 0, size.x, size.y)); … … 192 192 { 193 193 foreach(i, neighbor; possibleNeighbors(x, y)) 194 if( terrain.within(neighbor))194 if(within(neighbor)) 195 195 { 196 196 auto neighborTile = getTile(neighbor); … … 216 216 } 217 217 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 218 228 public: 219 229 mixin MAllocator; 220 230 221 this() 222 { 223 assert(terrain !is null, "terrain has to be initialized before the map"); 231 this(TerrainHeightmap heightmap) 232 { 224 233 assert(map is null, "there may only be one map"); 225 234 226 size = MapPos(terrain.dimension.x, terrain.dimension.y);235 size = heightmap.size; 227 236 tiles.alloc(size.x * size.y); 228 237 229 238 posPool.create(MAX_PATH_LENGTH, MAX_THREADS * BUFFERS_PER_THREAD); 230 239 231 initPathfinding( );240 initPathfinding(heightmap); 232 241 } 233 242 … … 258 267 MapTile* getTile(uint x, uint y) 259 268 { 260 assert( terrain.within(x, y));269 assert(within(x, y)); 261 270 return &tiles[x + y * size.x]; 262 271 } … … 419 428 in 420 429 { 421 assert( terrain.within(to));422 assert( terrain.within(from));430 assert(within(to)); 431 assert(within(from)); 423 432 } 424 433 body … … 437 446 for(int y = cast(int)to.y - i; y <= cast(int)to.y + i; y++) 438 447 { 439 if( terrain.within(cast(int)to.x - i, y))448 if(within(cast(int)to.x - i, y)) 440 449 { 441 450 tileList[listIndex] = MapPos(cast(int)to.x - i, y); … … 443 452 } 444 453 445 if( terrain.within(cast(int)to.x + i, y))454 if(within(cast(int)to.x + i, y)) 446 455 { 447 456 tileList[listIndex] = MapPos(cast(int)to.x + i, y); … … 452 461 for(int x = cast(int)to.x - i + 1; x <= cast(int)to.x + i - 1; x++) 453 462 { 454 if( terrain.within(x, cast(int)to.y - i))463 if(within(x, cast(int)to.y - i)) 455 464 { 456 465 tileList[listIndex] = MapPos(x, cast(int)to.y - i); … … 458 467 } 459 468 460 if( terrain.within(x, cast(int)to.y + i))469 if(within(x, cast(int)to.y + i)) 461 470 { 462 471 tileList[listIndex] = MapPos(x, cast(int)to.y + i); … … 529 538 x <= cast(int)end.x + searchBorder; x++) 530 539 { 531 if( terrain.within(x, y))540 if(within(x, y)) 532 541 getTile(x, y).open = false; 533 542 } … … 549 558 x <= cast(int)end.x + searchBorder; x++) 550 559 { 551 if( terrain.within(x, y) && !getTile(x, y).open)560 if(within(x, y) && !getTile(x, y).open) 552 561 { 553 562 for(uint i = 0; i < 8; i++) trunk/src/defend/demo/Demo.d
r561 r563 18 18 import defend.MapGenerator; 19 19 import defend.Camera; 20 import defend.FogOfWar; 20 21 import defend.Simulation; 21 22 import defend.com.Gateway; … … 48 49 { 49 50 terrain = new Terrain(sceneGraph.root, heightmap); 50 map = new Map ;51 map = new Map(heightmap); 51 52 }, gameObjects, players); 52 53 } … … 77 78 demoPlayer.init(); 78 79 assert(terrain !is null); 80 81 fogOfWar = new FogOfWar(gameObjects, terrain.lightmapTexture, vec2i.from(terrain.dimension)); 79 82 80 83 taskManager.addRepeatedTask(&InputChannel.global.update, 100); … … 88 91 { 89 92 delete demoPlayer; 93 delete fogOfWar; 90 94 delete gameObjects; 91 95 delete players; trunk/src/defend/game/Game.d
r562 r563 132 132 { 133 133 terrain = new Terrain(sceneGraph.root, heightmap); 134 map = new Map ;134 map = new Map(heightmap); 135 135 }, gameObjects, players); 136 136 trunk/src/defend/game/hud/Hud.d
r541 r563 270 270 guiRenderer = new GuiRenderer(); 271 271 272 miniMap = new MiniMap ;272 miniMap = new MiniMap(gameObjects); 273 273 mouse = new Mouse(gameObjects, guiController, miniMap); 274 274 trunk/src/defend/game/hud/MiniMap.d
r562 r563 3 3 import tango.io.Stdout; 4 4 5 import gen.core.TaskManager; 5 6 import gen.image.Image; 6 7 import gen.math.Rectangle; … … 19 20 import defend.Config; 20 21 import defend.FogOfWar; 22 import defend.objects.Core; 21 23 import defend.terrain.Terrain; 22 24 … … 27 29 const height = 128; 28 30 29 Image image; 31 GameObjectManager gameObjects; 32 30 33 Texture texture; 31 34 Sprite sprite; 35 36 Framebuffer objectLayer; 32 37 33 38 vec2i position; … … 35 40 void renderTerrain() 36 41 { 37 assert(terrain !is null); 38 assert(texture !is null); 42 with(renderer) 43 { 44 assert(terrain !is null); 45 assert(texture !is null); 39 46 40 renderer.pushMatrix(MatrixType.Projection); 41 renderer.setViewport(Rect(0, 0, width, height)); 47 setViewport(Rect(0, 0, width, height)); 42 48 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 { 45 72 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));67 73 } 68 74 … … 70 76 mixin MAllocator; 71 77 72 this( )78 this(GameObjectManager gameObjects) 73 79 { 80 this.gameObjects = gameObjects; 81 74 82 if(!texture) 75 83 { 76 texture = renderer.createTexture(vec2i(width, height) , ImageFormat.RGB);84 texture = renderer.createTexture(vec2i(width, height)); 77 85 renderTerrain(); 78 86 } … … 81 89 sprite.scaling = vec2(128.0f / width, 128.0f / width); 82 90 91 objectLayer = renderer.createFramebuffer(vec2i(width, height)); 92 83 93 position = vec2i(renderer.width - 150, renderer.height - HUD_HEIGHT + 10); 94 95 taskManager.addRepeatedTask(&updateObjects, 10); 84 96 } 85 97 trunk/src/defend/objects/Core.d
r551 r563 29 29 import defend.Map; 30 30 import defend.Config; 31 import defend.terrain.Terrain;31 //import defend.terrain.Terrain; 32 32 import defend.player.Manager; 33 33 import defend.com.Types; … … 676 676 677 677 public: 678 // Culled by fog of war 679 bool fogOfWarCulled = false; 680 678 681 ~this() 679 682 { … … 835 838 assert(result.left >= 0); 836 839 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); 839 842 } 840 843 body … … 843 846 mapPos.y >= radius ? mapPos.y - radius : 0, 844 847 845 mapPos.x + typeInfo.dimension.x + radius < terrain.dimension.x ?848 mapPos.x + typeInfo.dimension.x + radius < map.size.x ? 846 849 mapPos.x + typeInfo.dimension.x + radius : 847 850 mapPos.x + typeInfo.dimension.x, 848 851 849 mapPos.y + typeInfo.dimension.y + radius < terrain.dimension.y ?852 mapPos.y + typeInfo.dimension.y + radius < map.size.y ? 850 853 mapPos.y + typeInfo.dimension.y + radius : 851 854 mapPos.y + typeInfo.dimension.y); trunk/src/defend/terrain/Terrain.d
r562 r563 422 422 renderer.setTexture(0, null); 423 423 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 424 437 debug if(sceneGraph.debugNodeVisible(this)) 425 438 foreach(patch; patches) if(patch.visible) trunk/src/defend/terrain/Vertex.d
r465 r563 15 15 add(VertexUsage.Texture3). 16 16 add(VertexUsage.Texture4). 17 add(VertexUsage.Normal).18 17 add(VertexUsage.Position); 19 18 } … … 28 27 result.texture3 = texture3; 29 28 result.texture4 = texture4; 30 result.normal = vec3(0.0, 1.0, 0.0);31 29 result.position = position; 32 30 … … 38 36 vec2 texture3; 39 37 vec2 texture4; 40 vec3 normal;41 38 vec3 position; 42 39 } trunk/src/gen/core/TaskManager.d
r506 r563 38 38 } 39 39 40 // Stolen from deadlock, slightly modified40 // Stolen from Deadlock, slightly modified 41 41 42 42 final class TaskManager trunk/src/gen/rend/Renderer.d
r555 r563 189 189 190 190 /** 191 * Capabilities 192 */ 193 struct RendererCaps 194 { 195 bool multiTexturing; 196 bool shaders; 197 bool framebuffers; 198 bool vertexBuffers; 199 } 200 201 /** 191 202 * 3D-renderer interface 192 203 */ 193 204 abstract class Renderer 194 205 { 206 /** 207 * Returns the renderer's capabilities 208 */ 209 RendererCaps caps(); 210 195 211 /** 196 212 * Clears the screen. trunk/src/gen/rend/opengl/Renderer.d
r562 r563 29 29 import derelict.opengl.extension.arb.multitexture; 30 30 import derelict.opengl.extension.arb.vertex_buffer_object; 31 import derelict.opengl.extension.arb.vertex_shader; 32 import derelict.opengl.extension.arb.fragment_shader; 33 import derelict.opengl.extension.ext.framebuffer_object; 31 34 32 35 import gen.util.Log; … … 86 89 Logger logger; 87 90 91 RendererCaps _caps; 92 88 93 RendererConfig _config; 89 94 Window _window; … … 260 265 } 261 266 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 262 278 public: 263 279 this(RendererConfig c) … … 274 290 DerelictGL.loadExtensions(); 275 291 292 initCaps(); 293 276 294 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");283 295 } 284 296 … … 304 316 } 305 317 318 override RendererCaps caps() 319 { 320 return _caps; 321 } 322 306 323 override void clear(vec3 color2 = vec3.zero, bool color = true, bool depth = true) 307 324 { trunk/src/gen/rend/opengl/Texture.d
r541 r563 116 116 bind(); 117 117 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); 120 120 } 121 121
