Changeset 581
- Timestamp:
- 05/27/08 11:34:59 (8 months ago)
- Files:
-
- trunk/src/defend/demo/Player.d (modified) (5 diffs)
- trunk/src/defend/game/hud/Mouse.d (modified) (3 diffs)
- trunk/src/defend/sim/Core.d (modified) (14 diffs)
- trunk/src/defend/sim/Effector.d (modified) (2 diffs)
- trunk/src/defend/sim/civ/Test.d (modified) (1 diff)
- trunk/src/defend/sim/obj/Building.d (modified) (8 diffs)
- trunk/src/defend/sim/obj/Citizen.d (modified) (2 diffs)
- trunk/src/defend/sim/obj/House.d (modified) (1 diff)
- trunk/src/defend/sim/obj/Sheep.d (modified) (1 diff)
- trunk/src/defend/sim/obj/Unit.d (modified) (9 diffs)
- trunk/src/defend/terrain/FogOfWar.d (modified) (3 diffs)
- trunk/src/defend/terrain/Generator.d (modified) (1 diff)
- trunk/src/defend/terrain/Heightmap.d (modified) (1 diff)
- trunk/src/defend/terrain/Map.d (modified) (1 diff)
- trunk/src/gen/image/Devil.d (modified) (1 diff)
- trunk/src/gen/model/ModelMD2.d (modified) (3 diffs)
- trunk/src/gen/scene/MeshNode.d (modified) (2 diffs)
- trunk/src/xf/omg/core/Fixed.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/defend/demo/Player.d
r574 r581 6 6 7 7 import gen.math.Vector; 8 import gen.util.Log; 8 9 import gen.util.Wrapper; 9 10 import gen.util.Serialize; … … 19 20 { 20 21 private: 22 Logger logger; 23 21 24 FileConduit file; 22 25 float _speed = 20; … … 24 27 ubyte[] dataBuffer; 25 28 Phase phase; 29 30 bool finished = false; 26 31 27 32 ChunkHeader readChunkHeader() … … 97 102 this(char[] filename) 98 103 { 104 logger = Log.getLogger("demo"); 105 99 106 file = new FileConduit(filename, FileConduit.ReadExisting); 100 107 dataBuffer.length = 1024; … … 204 211 override void startPhase() 205 212 { 213 if(finished) 214 return; 215 206 216 while(true) 207 217 { 208 218 if(file.position == file.length) 209 219 { 210 Stdout("demo finished playing").newline; 220 logger.info("demo finished playing"); 221 finished = true; 211 222 212 223 return; trunk/src/defend/game/hud/Mouse.d
r576 r581 222 222 { 223 223 // Look if the mouse ray hits this object 224 if(obj.visible && obj.intersectRay(ray))224 if(obj.visible && !obj.fogOfWarCulled && obj.intersectRay(ray)) 225 225 { 226 226 // Deselect the object, if left shift is pressed … … 383 383 if(target is null) 384 384 { 385 // tmp :D386 //for(uint i = 0; i < 100; i++)387 385 gameObjects.order(gameObjects.gateway, selection, 388 386 OrderMapRightClick(mapPos.x, mapPos.y)); … … 606 604 607 605 mouseCube.scaling = vec3(0.05, 0.05, 0.05); 608 mouseCube.hide = true;606 mouseCube.hide = false; 609 607 mouseCube.renderShadow = true; 610 608 trunk/src/defend/sim/Core.d
r577 r581 262 262 263 263 // Properties 264 prop erty_value_t[MAX_OBJECT_PROPERTIES] propertyFactors;264 prop_t[MAX_OBJECT_PROPERTIES] propertyFactors; 265 265 266 266 // Effectors … … 310 310 311 311 // Basic properties 312 prop erty_value_t[MAX_OBJECT_PROPERTIES] properties;312 prop_t[MAX_OBJECT_PROPERTIES] properties; 313 313 314 314 // Number of tiles occupied … … 350 350 return false; 351 351 352 // TODO: fixed point 352 353 float height = -1; 353 354 const float tolerance = 0.2; … … 417 418 418 419 foreach(ref pf; propertyFactors) 419 pf = prop erty_value_t.ctFromReal!(1.0);420 pf = prop_t.ctFromReal!(1.0); 420 421 421 422 foreach(ref pf; properties) 422 pf = prop erty_value_t.ctFromReal!(1.0);423 pf = prop_t.ctFromReal!(1.0); 423 424 424 425 foreach(ref order; tempOrders) … … 429 430 430 431 // Set a property 431 override void mulPropertyFactor(prop erty_t property, property_value_t value)432 override void mulPropertyFactor(prop_type_t property, prop_t value) 432 433 { 433 434 propertyFactors[property] *= value; … … 435 436 436 437 // Returns a property factor 437 prop erty_value_t getPropertyFactor(property_t property)438 prop_t getPropertyFactor(prop_type_t property) 438 439 { 439 440 return (parent !is null ? 440 parent.getPropertyFactor(property) : prop erty_value_t.ctFromReal!(1.0)) *441 parent.getPropertyFactor(property) : prop_t.ctFromReal!(1.0)) * 441 442 propertyFactors[property]; 442 443 } 443 444 444 445 // Returns the value of a property 445 prop erty_value_t getProperty(property_t property)446 prop_t getProperty(prop_type_t property) 446 447 { 447 448 return properties[property] * getPropertyFactor(property); … … 609 610 610 611 EffectorInfo[MAX_OBJECT_EFFECTORS] effectors; 611 prop erty_value_t[MAX_OBJECT_PROPERTIES] propertyFactors;612 prop_t[MAX_OBJECT_PROPERTIES] propertyFactors; 612 613 613 614 void realPos(vec3 v) { _realPos = v; } … … 685 686 686 687 // TODO: PLX CAN HAS STRINGS FOR PROPERTIES KTHX. 687 enum Property : prop erty_t688 enum Property : prop_type_t 688 689 { 689 690 MaxLife, … … 754 755 } 755 756 756 override void mulPropertyFactor(prop erty_t property, property_value_t value)757 override void mulPropertyFactor(prop_type_t property, prop_t value) 757 758 { 758 759 propertyFactors[property] *= value; 759 760 } 760 761 761 prop erty_value_t property(property_t property)762 prop_t property(prop_type_t property) 762 763 { 763 764 assert(property < MAX_OBJECT_PROPERTIES); … … 799 800 final MapPos searchFreeTileAround(MapPos from) 800 801 { 802 // TODO: fixed point 801 803 bool hasResult = false; 802 804 float minDistance; … … 926 928 927 929 foreach(ref pf; propertyFactors) 928 pf = prop erty_value_t.ctFromReal!(1.0);930 pf = prop_t.ctFromReal!(1.0); 929 931 930 932 // dis no good … … 1575 1577 abstract class ObjectTechnology : Technology, Effector 1576 1578 { 1577 prop erty_value_t[MAX_OBJECT_PROPERTIES] factors;1579 prop_t[MAX_OBJECT_PROPERTIES] factors; 1578 1580 1579 1581 this() 1580 1582 { 1581 foreach(ref pf; factors) pf = prop erty_value_t.ctFromReal!(1.0);1583 foreach(ref pf; factors) pf = prop_t.ctFromReal!(1.0); 1582 1584 } 1583 1585 … … 1586 1588 foreach(i, pf; factors) 1587 1589 { 1588 if(pf != prop erty_value_t.ctFromReal!(1.0))1590 if(pf != prop_t.ctFromReal!(1.0)) 1589 1591 effected.mulPropertyFactor(i, pf); 1590 1592 } … … 1595 1597 foreach(i, pf; factors) 1596 1598 { 1597 if(pf != prop erty_value_t.ctFromReal!(1.0))1598 effected.mulPropertyFactor(i, prop erty_value_t.ctFromReal!(1.0) / pf);1599 if(pf != prop_t.ctFromReal!(1.0)) 1600 effected.mulPropertyFactor(i, prop_t.ctFromReal!(1.0) / pf); 1599 1601 } 1600 1602 } trunk/src/defend/sim/Effector.d
r572 r581 9 9 const uint MAX_OBJECT_PROPERTIES = 64; 10 10 11 alias uint property_t; 12 alias fixed property_value_t; 13 14 property_value_t objProp(real r) { return property_value_t.fromReal(r); } 11 alias uint prop_type_t; 12 alias fixed prop_t; 15 13 16 14 struct EffectorInfo … … 22 20 interface Effected 23 21 { 24 void mulPropertyFactor(prop erty_t, property_value_t);22 void mulPropertyFactor(prop_type_t, prop_t); 25 23 } 26 24 trunk/src/defend/sim/civ/Test.d
r572 r581 59 59 with(civ.objectTypes["unit"]) 60 60 { 61 mulPropertyFactor(Unit.Property.MovementSpeed, objProp(2));61 mulPropertyFactor(Unit.Property.MovementSpeed, prop_t(2)); 62 62 } 63 63 } trunk/src/defend/sim/obj/Building.d
r571 r581 66 66 { 67 67 BuildingQueueEntryType type; 68 ushort simulationSteps;68 fixed progress; 69 69 70 70 union … … 78 78 BuildingQueueEntry result; 79 79 result.type = BuildingQueueEntryType.Unit; 80 result. simulationSteps = unitType.developmentSteps;80 result.progress = fixed.fromInt(unitType.developmentSteps); 81 81 result.unitType = unitType; 82 82 … … 88 88 BuildingQueueEntry result; 89 89 result.type = BuildingQueueEntryType.Tech; 90 result. simulationSteps = tech.developmentSteps;90 result.progress = fixed.fromInt(tech.developmentSteps); 91 91 result.tech = tech; 92 92 … … 382 382 } 383 383 384 enum Property : prop erty_t384 enum Property : prop_type_t 385 385 { 386 386 BuildSpeed = GameObject.Property.max + 1 … … 409 409 typeInfo.scale.z); 410 410 411 propertyFactors[GameObject.Property.Sight] = prop erty_value_t.ctFromReal!(0.1);411 propertyFactors[GameObject.Property.Sight] = prop_t.ctFromReal!(0.1); 412 412 } 413 413 } … … 429 429 _sceneNode.scaling = typeInfo.scale; 430 430 status = Status.Finished; 431 propertyFactors[GameObject.Property.Sight] = prop erty_value_t.ctFromReal!(1.0);431 propertyFactors[GameObject.Property.Sight] = prop_t.ctFromReal!(1.0); 432 432 } 433 433 } … … 508 508 auto entry = &queue[0]; 509 509 510 assert(entry.simulationSteps != 0); 511 512 // well, this sucks :( 513 entry.simulationSteps -= min(cast(ushort)cast(real)property(Property.BuildSpeed), 514 entry.simulationSteps); 515 516 if(entry.simulationSteps == 0) 510 assert(entry.progress > fixed(0)); 511 512 entry.progress -= property(Property.BuildSpeed); 513 514 if(entry.progress <= fixed(0)) 517 515 { 518 516 switch(entry.type) … … 527 525 if(unitPos == mapPos) 528 526 { 529 entry.simulationSteps = 30; 527 Stdout("no place").newline; 528 // no space to spawn unit, retry later 529 entry.progress = fixed(50); 530 530 return; 531 531 } trunk/src/defend/sim/obj/Citizen.d
r579 r581 33 33 developmentSteps = 18; 34 34 canBuild = [ "house" ]; 35 properties[GameObject.Property.MaxLife] = objProp(500);36 properties[Unit.Property.Attack] = objProp(10);37 properties[Unit.Property.MovementSpeed] = objProp(5);38 properties[Unit.Property.AttackSpeed] = objProp(250);39 properties[GameObject.Property.Sight] = objProp(15);35 properties[GameObject.Property.MaxLife] = prop_t(500); 36 properties[Unit.Property.Attack] = prop_t(10); 37 properties[Unit.Property.MovementSpeed] = prop_t(5); 38 properties[Unit.Property.AttackSpeed] = prop_t(250); 39 properties[GameObject.Property.Sight] = prop_t(15); 40 40 } 41 41 … … 231 231 } 232 232 233 enum Property : prop erty_t233 enum Property : prop_type_t 234 234 { 235 235 // Speed for building buildings trunk/src/defend/sim/obj/House.d
r579 r581 26 26 canBuild = [ "sheep", "citizen" ]; 27 27 canDevelop = [ "sheep on drugs" ]; 28 properties[GameObject.Property.MaxLife] = objProp(2000);29 properties[GameObject.Property.Sight] = objProp(70);28 properties[GameObject.Property.MaxLife] = prop_t(2000); 29 properties[GameObject.Property.Sight] = prop_t(70); 30 30 } 31 31 trunk/src/defend/sim/obj/Sheep.d
r580 r581 32 32 normRotation = vec3(1.6, -1.6, 0); 33 33 developmentSteps = 18; 34 properties[GameObject.Property.MaxLife] = objProp(500);35 properties[Unit.Property.Attack] = objProp(5);36 properties[Unit.Property.MovementSpeed] = objProp(10);37 properties[Unit.Property.AttackSpeed] = objProp(50);38 properties[GameObject.Property.Sight] = objProp(20);34 properties[GameObject.Property.MaxLife] = prop_t(500); 35 properties[Unit.Property.Attack] = prop_t(5); 36 properties[Unit.Property.MovementSpeed] = prop_t(10); 37 properties[Unit.Property.AttackSpeed] = prop_t(50); 38 properties[GameObject.Property.Sight] = prop_t(20); 39 39 } 40 40 trunk/src/defend/sim/obj/Unit.d
r580 r581 22 22 import defend.Config; 23 23 import defend.mp.Types; 24 import defend.mp.PlayerManager; 24 25 import defend.terrain.Map; 25 26 import defend.terrain.Terrain; … … 53 54 targets = [ "sheep" ]; 54 55 miniPic = "data/minipics/speed.png"; 55 factors[Unit.Property.MovementSpeed] = objProp(20);56 factors[Unit.Property.MovementSpeed] = prop_t(20); 56 57 developmentSteps = 20; 57 58 } … … 94 95 auto target = gameObjects.getObject(order.target); 95 96 96 return OrderError.Okay; // tmp for testing 97 return target.owner != objects[0].owner ? 98 OrderError.Okay : OrderError.Error; 97 //return OrderError.Okay; // tmp for testing 98 return target.owner != objects[0].owner && 99 target.owner != NEUTRAL_PLAYER ? 100 OrderError.Okay : OrderError.Ignored; 99 101 } 100 102 … … 370 372 void finalDirection(vec3 v) { assert(v.ok); _finalDirection = v; } 371 373 372 fixed movePercent; // from 0 to 1000373 const MAX_MOVE_PERCENT = fixed.ctFrom Real!(100);374 fixed movePercent; 375 const MAX_MOVE_PERCENT = fixed.ctFromInt!(100); 374 376 375 377 // Attacking … … 513 515 lastWayPoint = terrain.getWorldPos(mapPos); 514 516 mapPos = p; 515 movePercent = fixed .fromInt(0);517 movePercent = fixed(0); 516 518 nextWayPoint = terrain.getWorldPos(mapPos); 517 519 … … 547 549 } 548 550 549 enum Property : prop erty_t551 enum Property : prop_type_t 550 552 { 551 553 Attack = GameObject.Property.max + 1, … … 699 701 if(movePercent < MAX_MOVE_PERCENT) 700 702 movePercent += property(Unit.Property.MovementSpeed); 701 703 702 704 if(movePercent > MAX_MOVE_PERCENT) 703 705 movePercent = MAX_MOVE_PERCENT; 704 706 705 707 // Reached the next tile 706 708 if(movePercent == MAX_MOVE_PERCENT) … … 733 735 else if(!checkCollision(path[1])) 734 736 { 735 //logger.spam("tile before: [{}|{}]", path[1].x, path[1].y);736 737 path = path[1 .. $]; 737 //logger.spam("tile afterwards: [{}|{}]", path[1].x, path[1].y);738 738 moveToPoint(path[0]); 739 739 } … … 746 746 realPos = lastWayPoint * (1.0 - percent) + nextWayPoint * percent; 747 747 748 // Path finished749 /*if(!path.length)750 {751 direction = finalDirection;752 //moving = false;753 status = Status.Idle;754 moveFinished();755 }*/756 757 748 break; 758 749 trunk/src/defend/terrain/FogOfWar.d
r579 r581 104 104 sprite.render(vec2.zero, visibleBuffer.texture); 105 105 106 setTexture(1, null); 106 107 setShader(null); 108 setTexture(0, null); 107 109 108 110 unsetFramebuffer(visitedBuffer); … … 131 133 sprite.render(vec2.zero, lightmap); 132 134 135 setTexture(1, null); 136 setTexture(2, null); 133 137 setShader(null); 138 setTexture(0, null); 134 139 135 140 unsetFramebuffer(framebuffer); … … 281 286 Texture texture() 282 287 { 288 //enable = false; 283 289 return enable ? framebuffer.texture : lightmap; 284 290 } trunk/src/defend/terrain/Generator.d
r580 r581 77 77 // localCreate(cast(player_id_t)0, "house", 40, 30); 78 78 79 version( none) for(int i = 0; i < 50; i++)79 version(all) for(int i = 0; i < 50; i++) 80 80 { 81 81 auto ti = getTypeInfo(NEUTRAL_PLAYER, "wood"); trunk/src/defend/terrain/Heightmap.d
r564 r581 16 16 MapPos _size; 17 17 18 // TODO: fixed point 18 19 float maxHeight = 0; 19 20 float[] heightMap; trunk/src/defend/terrain/Map.d
r565 r581 16 16 Map map; 17 17 18 // TODO: fixed point 18 19 struct MapTile 19 20 { trunk/src/gen/image/Devil.d
r446 r581 42 42 43 43 case 8: 44 ilConvertImage(IL_ LUMINANCE, IL_UNSIGNED_BYTE);45 _format = ImageFormat. A;44 ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE); 45 _format = ImageFormat.RGB; 46 46 break; 47 47 trunk/src/gen/model/ModelMD2.d
r580 r581 1 1 module gen.model.ModelMD2; 2 3 // this won't be needed anymore, once Lich is usable 2 4 3 5 import tango.io.Stdout; … … 82 84 83 85 d["stand"] = a(0, 39, 9); 84 d["run"] = a(40, 45, 10);86 d["run"] = a(40, 45, 6); 85 87 d["attack"] = a(46, 53, 10); 86 88 d["pain_a"] = a(54, 57, 7); … … 194 196 vertex.position.y = currPos.y + state.interp * (nextPos.y - currPos.y); 195 197 vertex.position.z = currPos.z + state.interp * (nextPos.z - currPos.z); 196 198 197 199 bbox.max.x = .max(bbox.max.x, vertex.position.x); 198 200 bbox.max.y = .max(bbox.max.y, vertex.position.y); trunk/src/gen/scene/MeshNode.d
r580 r581 63 63 renderer.pushMatrix(); 64 64 renderer.mulMatrix(absoluteModelview); 65 renderer.setColor(parent.color); // use color of parent model 65 66 66 67 mesh.render(); … … 72 73 } 73 74 75 renderer.setColor(vec3.one); 74 76 renderer.popMatrix(); 75 77 } trunk/src/xf/omg/core/Fixed.d
r541 r581 40 40 } 41 41 42 template ctFromInt(int val) { 43 static assert (val >= minInt && val <= maxInt); 44 const fixed32T ctFromInt = { store : val << fracBits }; 45 } 42 46 43 47 static fixed32T fromInt(int val) {
