Changeset 576
- Timestamp:
- 05/25/08 09:55:14 (8 months ago)
- Files:
-
- trunk/run/data/shaders/combineLightmaps-pixel.glsl (modified) (1 diff)
- trunk/src/defend/Camera.d (modified) (3 diffs)
- trunk/src/defend/game/Game.d (modified) (1 diff)
- trunk/src/defend/game/hud/MiniMap.d (modified) (1 diff)
- trunk/src/defend/game/hud/Mouse.d (modified) (2 diffs)
- trunk/src/defend/sim/Core.d (modified) (4 diffs)
- trunk/src/defend/sim/SceneNode.d (modified) (2 diffs)
- trunk/src/defend/sim/obj/Resource.d (modified) (1 diff)
- trunk/src/defend/terrain/FogOfWar.d (modified) (5 diffs)
- trunk/src/defend/terrain/Generator.d (modified) (1 diff)
- trunk/src/defend/terrain/Terrain.d (modified) (2 diffs)
- trunk/src/gen/util/Array.d (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/run/data/shaders/combineLightmaps-pixel.glsl
r574 r576 9 9 vec4 c = texture2D(lightmap, vec2(gl_TexCoord[0])); 10 10 11 gl_FragColor = max(a, b * 0.67f) * c; 11 gl_FragColor = max(a, b * 0.55f) * c; 12 //gl_FragColor = a * c; 12 13 } trunk/src/defend/Camera.d
r572 r576 100 100 if(minDistance < 2) 101 101 minDistance = 2; 102 103 //collision(); 102 104 } 103 105 … … 153 155 }); 154 156 155 / +foreach(object; gameObjects)157 /*foreach(object; gameObjects) 156 158 { 157 159 auto bbox = object.sceneNode.boundingBox.expanded(2); … … 159 161 if(bbox.checkCollision(pos) && bbox.max.y > minDistance) 160 162 { 161 minDistance= bbox.max.y;163 pos.y = bbox.max.y; 162 164 return; 163 165 } 164 } +/166 }*/ 165 167 } 166 168 trunk/src/defend/game/Game.d
r575 r576 274 274 275 275 // Fog of war 276 fogOfWar = new FogOfWar(gameObjects, terrain.lightmapTexture, vec2i.from(terrain.dimension) );276 fogOfWar = new FogOfWar(gameObjects, terrain.lightmapTexture, vec2i.from(terrain.dimension), true); 277 277 278 278 // Create the HUD trunk/src/defend/game/hud/MiniMap.d
r573 r576 40 40 void renderTerrain() 41 41 { 42 with(renderer) 43 { 44 assert(terrain !is null); 45 assert(texture !is null); 42 renderer.setViewport(Rect(0, 0, width, height)); 46 43 47 setViewport(Rect(0, 0, width, height)); 44 renderer.identity(MatrixType.Projection); 45 glOrtho(terrain.dimension.x - 1, 0, terrain.dimension.y - 1, 0, 0, 1337); 46 47 renderer.identity(); 48 49 auto center = vec2( (terrain.dimension.x - 1), 50 -(terrain.dimension.y - 1)); 51 52 gluLookAt(center.x, 500.0f, center.y, center.x, 0.0f, 53 center.y, 0.0f, 0.0f, 1.0f); 48 54 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 } 55 renderer.clear(); 56 terrain.renderOrthogonal(); 61 57 62 clear();63 terrain.renderOrthogonal();58 texture.copyFromScreen(); 59 renderer.clear(); 64 60 65 texture.copyFromScreen(); 66 clear(); 67 } 61 renderer.setViewport(Rect(0, 0, renderer.width, renderer.height)); 68 62 } 69 63 trunk/src/defend/game/hud/Mouse.d
r575 r576 72 72 BufferedArray!(GameObject) selectionBuffer; 73 73 BufferedArray!(object_id_t) objectIDBuffer; 74 74 75 invariant() 76 { 77 if(selectionBuffer.length) 78 { 79 auto owner = selectionBuffer[0].owner; 80 81 foreach(object; selectionBuffer.toArray[1 .. $]) 82 assert(object.owner == owner); 83 } 84 } 85 75 86 // Object placement 76 87 object_type_t placeObject; … … 239 250 { 240 251 // Don't put it twice into the list 241 if(!obj.selected && selectionBuffer.length < MAX_ORDERED_OBJECTS) 252 if(!obj.selected && selectionBuffer.length < MAX_ORDERED_OBJECTS && 253 (!selectionBuffer.length || selectionBuffer[0].owner == obj.owner)) 242 254 { 243 selectionBuffer.append( cast(GameObject)obj);255 selectionBuffer.append(obj); 244 256 245 257 obj.selected = true; trunk/src/defend/sim/Core.d
r575 r576 358 358 { 359 359 final tile = map.getTile(x, y); 360 final tile_height = tile.height;361 360 362 361 if(height == -1) 363 height = tile _height;362 height = tile.height; 364 363 else 365 364 { 366 if(abs(tile _height - height) > tolerance)365 if(abs(tile.height - height) > tolerance) 367 366 return false; 368 367 } … … 933 932 934 933 debug(gameobjects) 935 logger = Log.getLogger(" objects.object." ~ Integer.toString(id));934 logger = Log.getLogger("sim.object." ~ Integer.toString(id)); 936 935 } 937 936 … … 950 949 { 951 950 assert(objects.length > 0); 951 952 auto owner = objects[0].owner; 953 foreach(object; objects[1 .. $]) assert(object.owner == owner); 952 954 } 953 955 body … … 964 966 { 965 967 ObjectTypeInfo ti = object.typeInfo; 966 968 967 969 if(!ti.isTypeInHierarchy(currentLevel.localTypeID)) 968 970 { trunk/src/defend/sim/SceneNode.d
r574 r576 44 44 public: 45 45 mixin MAllocator; 46 47 bool fogOfWarCulled; 46 48 47 49 this(SceneNode parent, char[] file, vec3 color, bool isNeutral = false) … … 72 74 override void process(Camera camera) 73 75 { 74 visible = camera.frustum.boundingBoxVisible(bbox) ;76 visible = camera.frustum.boundingBoxVisible(bbox) && !fogOfWarCulled; 75 77 } 76 78 trunk/src/defend/sim/obj/Resource.d
r574 r576 138 138 } 139 139 140 bool intersectRay(Ray!(float) ray)140 override bool intersectRay(Ray!(float) ray) 141 141 { 142 142 return ray.intersectBoundingBox(_sceneNode.boundingBox); 143 } 144 145 override void update() 146 { 147 _sceneNode.fogOfWarCulled = fogOfWarCulled; 143 148 } 144 149 trunk/src/defend/terrain/FogOfWar.d
r574 r576 12 12 import gen.math.Vector; 13 13 import gen.math.Rectangle; 14 import gen.math.Misc : clamp ;14 import gen.math.Misc : clamp, min, max; 15 15 16 16 import defend.sim.Core; … … 169 169 foreach(object; gameObjects) with(object) 170 170 { 171 // TODO: fog of war needs to include any object of the own team171 // TODO: fog of war needs to include any objects of the own team 172 172 if(mayBeOrdered) 173 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 174 auto sight = cast(int)(cast(real)property(GameObject.Property.Sight)); 175 176 auto x = max(0, cast(int)mapPos.x - sight / 2); 177 auto y = max(0, cast(int)mapPos.y - sight / 2); 178 auto w = min(dimension.x - 1 - mapPos.x, sight); 179 auto h = min(dimension.y - 1 - mapPos.y, sight); 180 181 visibleTiles.fill(true, x, y, w, h); 182 visitedTiles.fill(true, x, y, w, h); 183 } 184 } 185 181 186 foreach(object; gameObjects) with(object) 182 187 { … … 197 202 } 198 203 } 199 204 205 if(cull) 206 { 207 foreach(tile; visitedTiles.iterate(mapPos.x, mapPos.y, ti.dimension.x, ti.dimension.y)) 208 { 209 if(tile) 210 { 211 cull = false; 212 break; 213 } 214 } 215 } 216 200 217 fogOfWarCulled = cull; 201 218 //if(cull) synchronized(Stdout) Stdout("fog of war culled: ")(object.id).newline; … … 204 221 205 222 // Generate a circle, which can be rendered on the fog of war texture 206 static Texture generateCircle(vec2i size = vec2i(64, 64), float intensity = 1.2)223 static Texture generateCircle(vec2i size = vec2i(64, 64), float intensity = 5) 207 224 { 208 225 scope image = new Image(size.tuple, ImageFormat.A); … … 216 233 217 234 public: 235 //bool isVisible(uint x, uint y) { return visibleTiles[x, y]; } 236 218 237 this(GameObjectManager gameObjects, Texture lightmap, vec2i dimension, bool enable = true) 219 238 { trunk/src/defend/terrain/Generator.d
r574 r576 76 76 // localCreate(cast(player_id_t)0, "house", 40, 30); 77 77 78 for(int i = 0; i < 20; i++)78 for(int i = 0; i < 50; i++) 79 79 { 80 80 auto ti = getTypeInfo(NEUTRAL_PLAYER, "wood"); trunk/src/defend/terrain/Terrain.d
r573 r576 424 424 425 425 // debugging if the unit sight ranges are scaled correctly 426 / *renderer.setRenderState(RenderState.Wireframe, true);426 /+renderer.setRenderState(RenderState.Wireframe, true); 427 427 renderer.setRenderState(RenderState.Blending, true); 428 428 renderer.setColor(vec4(1, 1, 1, 0.5)); … … 434 434 435 435 renderer.setRenderState(RenderState.Blending, false); 436 renderer.setRenderState(RenderState.Wireframe, false); */436 renderer.setRenderState(RenderState.Wireframe, false);+/ 437 437 438 438 debug if(sceneGraph.debugNodeVisible(this)) 439 439 foreach(patch; patches) if(patch.visible) 440 440 renderer.drawBoundingBox(patch.boundingBox, vec3(0, 0.7, 1)); 441 442 /+for(uint x = 0; x < dimension.x; x++) 443 { 444 for(uint y = 0; y < dimension.y; y++) 445 { 446 auto visible = fogOfWar.isVisible(x, y); 447 448 if(visible) 449 { 450 auto pos = getWorldPos(x, y); 451 renderer.drawLine(pos, pos + vec3(0, 1, 0), vec3(1, 0, 0)); 452 } 453 } 454 }+/ 441 455 442 456 renderer.popMatrix(); trunk/src/gen/util/Array.d
r573 r576 74 74 uint x, y, w, h; 75 75 76 int opApply(int delegate(ref T value) dg)76 int opApply(int delegate(ref T) dg) 77 77 { 78 78 for(uint _x = x; _x < x + w; _x++) … … 81 81 { 82 82 if(auto result = dg(array.data[_x + _y * array.width]) != 0) 83 return result; 84 } 85 } 86 87 return 0; 88 } 89 90 int opApply(int delegate(ref uint, ref uint, ref T) dg) 91 { 92 for(uint _x = x; _x < x + w; _x++) 93 { 94 for(uint _y = y; _y < y + h; _y++) 95 { 96 if(auto result = dg(_x, _y, array.data[_x + _y * array.width]) != 0) 83 97 return result; 84 98 } … … 125 139 void fill(T value, uint x, uint y, uint w, uint h) 126 140 { 127 data[x + y * width .. (x + w) + (y + h) * width] = value; 141 //data[x + y * width .. (x + w) + (y + h) * width] = value; 142 143 foreach(ref x; iterate(x, y, w, h)) 144 x = value; 128 145 } 129 146 … … 140 157 } 141 158 159 Iterator iterate() 160 { 161 return iterate(0, 0, width, height); 162 } 163 142 164 void reset() 143 165 {
