Changeset 573
- Timestamp:
- 05/24/08 17:45:26 (8 months ago)
- Files:
-
- trunk/src/defend/game/Game.d (modified) (2 diffs)
- trunk/src/defend/game/hud/MiniMap.d (modified) (1 diff)
- trunk/src/defend/sim/Core.d (modified) (1 diff)
- trunk/src/defend/sim/obj/Unit.d (modified) (1 diff)
- trunk/src/defend/terrain/FogOfWar.d (modified) (9 diffs)
- trunk/src/defend/terrain/Terrain.d (modified) (1 diff)
- trunk/src/gen/rend/opengl/FBO.d (modified) (1 diff)
- trunk/src/gen/util/Array.d (modified) (2 diffs)
- trunk/src/gen/util/GameState.d (modified) (3 diffs)
- trunk/src/gen/util/MemoryPool.d (modified) (1 diff)
- trunk/src/gen/util/Resource.d (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/defend/game/Game.d
r567 r573 17 17 import gen.util.Profiler; 18 18 import gen.util.GameState; 19 import gen.util.Resource; 19 20 20 21 import defend.Config; … … 338 339 logObjectUsage(); 339 340 341 // print out a list of loaded resources, for debugging 342 Resource.dump(); 343 340 344 //dumpGCStats(); 341 345 } trunk/src/defend/game/hud/MiniMap.d
r567 r573 100 100 delete sprite; 101 101 delete texture; 102 delete objectLayer; 102 103 } 103 104 trunk/src/defend/sim/Core.d
r572 r573 670 670 671 671 public: 672 // Culled by fog of war 672 // Culled by fog of war? 673 673 bool fogOfWarCulled = false; 674 674 trunk/src/defend/sim/obj/Unit.d
r572 r573 358 358 vec3 _direction; 359 359 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; } 361 361 362 362 vec3 _finalDirection; 363 363 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; } 365 365 366 366 fixed movePercent; // from 0 to 1000 trunk/src/defend/terrain/FogOfWar.d
r570 r573 9 9 import gen.util.Sprite; 10 10 import gen.util.Profiler; 11 import gen.util. Memory;11 import gen.util.Array; 12 12 import gen.math.Vector; 13 13 import gen.math.Rectangle; … … 36 36 Texture circleTexture; 37 37 38 Shader copyShader; 39 Shader combineShader; 40 38 41 bool firstVisited; 39 42 40 43 // arrays of visible and visited tiles 41 bool[]visibleTiles, visitedTiles;44 Array2D!(bool) visibleTiles, visitedTiles; 42 45 43 46 void updateVisibleTexture() … … 57 60 foreach(object; gameObjects) 58 61 { 62 // TODO: fog of war needs to include any object of the own team 59 63 if(object.mayBeOrdered) 60 64 { … … 87 91 if(!firstVisited) { clear(); firstVisited = true; } 88 92 89 auto shader = Shader.get("data/shaders/copyVisibleFog.cfg");93 auto shader = copyShader; 90 94 setShader(shader); 91 95 … … 113 117 clear(); 114 118 115 auto shader = Shader.get("data/shaders/combineLightmaps.cfg");119 auto shader = combineShader; 116 120 setShader(shader); 117 121 … … 136 140 { 137 141 profile!("fog of war") 138 ({ 142 ({ 143 updateTiles(); 144 139 145 with(renderer) 140 146 { … … 155 161 } 156 162 }); 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 } 157 203 } 158 204 … … 186 232 circleTexture = generateCircle(); 187 233 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); 188 239 189 240 taskManager.addRepeatedTask(&update, 15); 190 241 } 191 242 } 192 243 193 244 ~this() 194 245 { … … 200 251 delete circleTexture; 201 252 delete sprite; 253 254 Shader.release(copyShader); 255 Shader.release(combineShader); 256 257 visibleTiles.release(); 258 visitedTiles.release(); 202 259 } 203 260 } trunk/src/defend/terrain/Terrain.d
r566 r573 361 361 if(heightmap) delete _heightmap; 362 362 if(lightmapTexture) delete lightmapTexture; 363 if(alphaMap) delete alphaMap; 363 364 if(detailTexture) Texture.release(detailTexture); 364 365 trunk/src/gen/rend/opengl/FBO.d
r551 r573 73 73 } 74 74 75 ~this() { delete target; } 76 75 77 override Texture texture() 76 78 { trunk/src/gen/util/Array.d
r464 r573 2 2 3 3 import tango.io.Stdout; 4 5 import gen.util.Allocator; 6 import gen.util.Memory; 4 7 5 8 bool hasElement(T)(T[] array, T what) … … 57 60 assert([1].remove(0) == cast(int[])[]); 58 61 } 62 63 struct Array2D(T, Alloc = CLibAllocator) 64 { 65 private: 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 91 public: 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 13 13 { 14 14 /* Initialize the gamestate. That means, load resources and create tasks. 15 There isno update or render functions, so the gamestate can only get updated15 There are no update or render functions, so the gamestate can only get updated 16 16 via tasks. */ 17 17 void init(); … … 80 80 if(memoryUsageBefore != -1) 81 81 { 82 if(getMemoryUsage() >memoryUsageBefore)82 if(getMemoryUsage() != memoryUsageBefore) 83 83 { 84 84 logger.warn("gamestate `{}' is not clean, {} bytes of memory are left", … … 86 86 } 87 87 else 88 logger.info("gamestate `{}' is clean .", state.classinfo.name);88 logger.info("gamestate `{}' is clean", state.classinfo.name); 89 89 } 90 90 } trunk/src/gen/util/MemoryPool.d
r501 r573 101 101 } 102 102 103 Memory.memoryUsage -= T.classinfo.init.length * freeQueue.bufferSize;103 Memory.memoryUsage -= T.classinfo.init.length * maxObjects; 104 104 105 105 static if(!initialize) trunk/src/gen/util/Resource.d
r565 r573 1 1 module gen.util.Resource; 2 3 struct Resource 4 { 5 private: 6 static void function()[] dumps; 7 8 public: 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 } 2 20 3 21 template MResource() … … 5 23 private: 6 24 import tango.io.FilePath; 25 import tango.text.Ascii : toLower; 26 7 27 import gen.util.Config; 8 28 import gen.util.Log; 9 import tango.text.Ascii : toLower;10 29 11 30 alias typeof(this) T; … … 22 41 { 23 42 logger = Log.getLogger("resource." ~ toLower(T.stringof)); 43 Resource.addType!(T); 24 44 } 25 45 … … 70 90 static void release(T instance) 71 91 { 72 if( --instance.refCount == 0)92 if(instance.refCount == 0 || --instance.refCount == 0) 73 93 { 74 94 char[] file = instance.file; … … 81 101 } 82 102 } 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 } 83 110 }
