Changeset 589
- Timestamp:
- 05/30/08 18:09:18 (7 months ago)
- Files:
-
- trunk/src/defend/demo/Player.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/Mouse.d (modified) (1 diff)
- trunk/src/defend/game/net/Client.d (modified) (2 diffs)
- trunk/src/defend/game/net/Server.d (modified) (5 diffs)
- trunk/src/defend/mp/Gateway.d (modified) (1 diff)
- trunk/src/defend/sim/Core.d (modified) (6 diffs)
- trunk/src/defend/sim/Simulation.d (modified) (9 diffs)
- trunk/src/defend/sim/obj/Citizen.d (modified) (1 diff)
- 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) (11 diffs)
- trunk/src/defend/terrain/Terrain.d (modified) (1 diff)
- trunk/src/engine/font/FreeType.d (modified) (1 diff)
- trunk/src/engine/model/Mesh.d (modified) (1 diff)
- trunk/src/engine/model/Model.d (modified) (1 diff)
- trunk/src/engine/rend/PrimitiveType.d (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/defend/demo/Player.d
r583 r589 23 23 24 24 FileConduit file; 25 float _speed = 20;25 float _speed = 0.3; 26 26 27 27 ubyte[] dataBuffer; … … 209 209 } 210 210 211 override voidstartPhase()211 override bool startPhase() 212 212 { 213 213 if(finished) 214 return ;214 return false; 215 215 216 216 while(true) … … 221 221 finished = true; 222 222 223 return ;223 return false; 224 224 } 225 225 … … 245 245 break; 246 246 } 247 248 return true; 247 249 } 248 250 trunk/src/defend/game/Game.d
r585 r589 298 298 299 299 taskManager.addRepeatedTask(&InputChannel.global.update, 100); 300 taskManager.addRepeatedTask(&gameObjects.update, 30);300 taskManager.addRepeatedTask(&gameObjects.update, 100); 301 301 taskManager.addRepeatedTask(&sceneGraph.update, 60); 302 302 taskManager.addRepeatedTask(&gateway.update, 10); trunk/src/defend/game/hud/Hud.d
r583 r589 118 118 }); 119 119 120 version(none) foreach(obj; mouse.selection) 121 { 122 auto p = mouse.getScreenPos(obj.realPos); 123 p.y = renderer.height - p.y; 124 125 smallFont.write(guiRenderer, vec2i(p.x, p.y), vec3.one, "[{}]", obj.id); 126 } 120 foreach(obj; mouse.selection) 121 smallFont.write(guiRenderer, mouse.getScreenPos(obj.realPos), 122 vec3.one, "[{}]", obj.id); 127 123 } 128 124 } trunk/src/defend/game/hud/Mouse.d
r588 r589 527 527 overTerrain = true; 528 528 529 mouseCube.hide = true;529 mouseCube.hide = !overTerrain; 530 530 531 531 auto pos = terrain.getWorldPos(mapPos); trunk/src/defend/game/net/Client.d
r583 r589 344 344 } 345 345 346 override voidstartPhase()346 override bool startPhase() 347 347 { 348 348 if(!phaseQueue.first.mayBeStarted) 349 return ;349 return false; 350 350 351 351 phase++; … … 367 367 phaseQueue.last.whichPhase = phaseQueue[phaseQueue.length - 2].whichPhase + 368 368 cast(phase_counter_t)1; 369 370 return true; 369 371 } 370 372 trunk/src/defend/game/net/Server.d
r584 r589 247 247 logger.info("need to adjust order's phase from {} to {}", 248 248 message.phase, 249 server.currentPhase + cast(phase_counter_t) 2);250 251 message.phase = server.currentPhase + cast(phase_counter_t) 2;249 server.currentPhase + cast(phase_counter_t)1); 250 251 message.phase = server.currentPhase + cast(phase_counter_t)1; 252 252 } 253 253 … … 495 495 496 496 currentPhase++; 497 498 //debug(networking) 499 // logger.info("current phase now {}", currentPhase); 497 500 } 498 501 … … 577 580 // Start first phase 578 581 synchronized(phaseMutex) 579 startPhase(0, 100, numberSimulationSteps(100));582 startPhase(0, MIN_PHASE_LENGTH, numberSimulationSteps(MIN_PHASE_LENGTH)); 580 583 } 581 584 … … 636 639 // Calculates the number of simulation steps for a phase's length 637 640 ushort numberSimulationSteps(ushort length) 638 { 639 return cast(ushort)((SIMULATION_STEPS_PER_SECOND) / (1000.0f / length)); 640 } 641 641 out(result) 642 { 643 //logger.info("steps: {}; length: {}", result, length); 644 assert(result > 0); 645 } 646 body 647 { 648 //return 1; 649 return cast(ushort)(SIMULATION_STEPS_PER_SECOND / (1000.0f / length)); 650 } 651 652 //const uint MIN_PHASE_LENGTH = 5000; 653 //const uint MAX_PHASE_LENGTH = 20500; 654 642 655 const uint MIN_PHASE_LENGTH = 100; 643 656 const uint MAX_PHASE_LENGTH = 1000; 644 const uint SIMULATION_STEPS_PER_SECOND = 50;657 const uint SIMULATION_STEPS_PER_SECOND = 10; 645 658 646 659 void run() … … 660 673 int length; 661 674 662 length = min( 1000, max(MIN_PHASE_LENGTH, maxPing));675 length = min(MAX_PHASE_LENGTH, max(MIN_PHASE_LENGTH, maxPing)); 663 676 664 677 //Trace.formatln("phase length: {}", length); 665 666 length = min(length, MAX_PHASE_LENGTH);667 678 668 679 startPhase(currentPhase, length, trunk/src/defend/mp/Gateway.d
r584 r589 61 61 abstract void phaseDone(); 62 62 63 // Try to start the next phase 64 abstract voidstartPhase();63 // Try to start the next phase, returns true if it could be started 64 abstract bool startPhase(); 65 65 66 66 /* Check, that the simulation is not out of sync with other clients. trunk/src/defend/sim/Core.d
r588 r589 1016 1016 private: 1017 1017 Logger logger; 1018 1019 // Current simulation step 1018 1020 uint _currentSimulationStep; 1019 1021 1022 // Player list 1020 1023 PlayerManager _players; 1021 1024 1022 1025 // The communication gateway 1023 1026 Gateway _gateway; 1027 1028 // Simulation runner 1029 Simulation _simulation; 1024 1030 1025 1031 // The object list … … 1032 1038 // Civs 1033 1039 Civ neutralCiv; 1034 Civ[player_id_t] civs; // fuuuuuck1040 Civ[player_id_t] civs; 1035 1041 1036 1042 // Queueing orders … … 1216 1222 Signal!(GameObject) ObjectDead; 1217 1223 1218 this(Gateway g, PlayerManager _players, Simulationsimulation)1224 this(Gateway _gateway, PlayerManager _players, Simulation _simulation) 1219 1225 { 1220 1226 logger = Log.getLogger("sim.manager"); 1221 1227 1228 this._gateway = _gateway; 1222 1229 this._players = _players; 1230 this._simulation = _simulation; 1223 1231 1224 1232 objects.create(1024, true); … … 1230 1238 1231 1239 // Connect signals 1232 with(_gateway = g)1240 with(_gateway) 1233 1241 { 1234 1242 CreateObject.connect(&onCreateObject); … … 1237 1245 } 1238 1246 1239 simulation.SimulationStep.connect(&onSimulationStep);1247 _simulation.SimulationStep.connect(&onSimulationStep); 1240 1248 1241 1249 neutralCiv = typeRegister.loadCiv(this, NEUTRAL_PLAYER, "neutral"); … … 1382 1390 } 1383 1391 1392 Simulation simulation() 1393 { 1394 return _simulation; 1395 } 1396 1384 1397 GameObject getObject(object_id_t id) 1385 1398 out(result) trunk/src/defend/sim/Simulation.d
r583 r589 1 1 module defend.sim.Simulation; 2 3 import tango.io.Stdout; 2 4 3 5 import engine.core.TaskManager; 4 6 import engine.util.Profiler; 5 7 import engine.util.Signal; 8 import engine.util.HardwareTimer; 9 import engine.util.Log; 6 10 7 11 import defend.mp.Phase; … … 11 15 { 12 16 private: 17 Logger logger; 18 13 19 Gateway gateway; 14 20 … … 19 25 bool runningPhase; 20 26 27 const interpolationFrequency = 100.0f; 28 float frequency = 10.0f; 29 float _interpolation = 0.0f; 30 21 31 void update() 22 32 { … … 26 36 { 27 37 assert(doneSimulationSteps == simulationSteps); 28 29 // Try to start the next phase 30 gateway.startPhase(); 31 32 return; 38 39 if(!gateway.startPhase()) 40 return; 33 41 } 34 42 43 //logger.spam("simulation step"); 44 35 45 assert(doneSimulationSteps < simulationSteps); 36 46 37 47 SimulationStep(); 38 48 doneSimulationSteps++; 49 _interpolation = 0; 39 50 40 51 if(doneSimulationSteps == simulationSteps) … … 46 57 } 47 58 }); 59 } 60 61 void updateInterpolation() 62 { 63 if(!runningPhase) 64 { 65 gateway.startPhase(); 66 return; 67 } 68 69 _interpolation += frequency / interpolationFrequency; 70 if(_interpolation > 1.0f) _interpolation = 1.0f; 48 71 } 49 72 … … 59 82 60 83 simulationSteps = phase.simulationSteps; 84 61 85 doneSimulationSteps = 0; 62 86 runningPhase = true; … … 65 89 if(oldSimulationSteps != simulationSteps) 66 90 { 67 final frequency = (1000 / cast(float)phase.length) * simulationSteps; 68 91 frequency = (1000 / cast(float)phase.length) * simulationSteps; 69 92 taskManager.setTaskFrequency(&update, frequency); 70 93 } … … 78 101 this(Gateway g) 79 102 { 103 logger = Log.getLogger("sim.runner"); 104 80 105 with(gateway = g) 81 106 { … … 83 108 } 84 109 85 taskManager.addRepeatedTask(&update, 50); 110 taskManager.addRepeatedTask(&update, frequency); 111 taskManager.addRepeatedTask(&updateInterpolation, interpolationFrequency); 112 } 113 114 float interpolation() 115 { 116 return _interpolation; 86 117 } 87 118 } trunk/src/defend/sim/obj/Citizen.d
r588 r589 33 33 posOffset = vec3(0, 1, 0); 34 34 scale = vec3.one; 35 developmentSteps = 18;35 developmentSteps = 2; 36 36 canBuild = [ "house" ]; 37 37 properties[GameObject.Property.MaxLife] = prop_t(500); 38 38 properties[Unit.Property.Attack] = prop_t(10); 39 properties[Unit.Property.MovementSpeed] = prop_t(5 );39 properties[Unit.Property.MovementSpeed] = prop_t(50); 40 40 properties[Unit.Property.AttackSpeed] = prop_t(250); 41 41 properties[GameObject.Property.Sight] = prop_t(15); trunk/src/defend/sim/obj/House.d
r583 r589 23 23 posOffset = vec3(2, 0.2, -2.5); 24 24 scale = vec3(0.4, 0.4, 0.4); 25 buildSteps = 10000;25 buildSteps = 2000; 26 26 canBuild = [ "sheep", "citizen" ]; 27 27 canDevelop = [ "sheep on drugs" ]; trunk/src/defend/sim/obj/Sheep.d
r583 r589 31 31 scale = vec3(0.035, 0.035, 0.035); 32 32 normRotation = vec3(1.6, -1.6, 0); 33 developmentSteps = 1 8;33 developmentSteps = 10; 34 34 properties[GameObject.Property.MaxLife] = prop_t(500); 35 35 properties[Unit.Property.Attack] = prop_t(5); 36 properties[Unit.Property.MovementSpeed] = prop_t( 10);36 properties[Unit.Property.MovementSpeed] = prop_t(35); 37 37 properties[Unit.Property.AttackSpeed] = prop_t(50); 38 38 properties[GameObject.Property.Sight] = prop_t(20); trunk/src/defend/sim/obj/Unit.d
r588 r589 110 110 override void onOrder(GameObject[] objects, OrderMapRightClick* order) 111 111 { 112 113 112 // TODO: Group pathfinding 114 113 iterateObjects(objects, (Unit object) … … 196 195 unit.property(Unit.Property.MovementSpeed)) 197 196 { 198 pause = 20;197 pause = 5; 199 198 path = null; 200 199 status = Status.Idle; 200 201 currentRealPos = nextRealPos = realPos; 202 201 203 sceneNode.setAnimation("stand"); 202 204 … … 384 386 const MAX_MOVE_PERCENT = fixed.ctFromInt!(100); 385 387 388 // Interpolation 389 vec3 currentRealPos = vec3.one; 390 vec3 nextRealPos = vec3.one; 391 386 392 // Attacking 387 393 GameObject target; // Attack target … … 400 406 bool considerObjects = false, bool isFinalGoal = true) 401 407 { 408 pause = 0; 409 402 410 debug(gameobjects) 403 411 logger.trace("moving to [{}|{}] (order: {})", … … 529 537 assert(map.getTile(mapPos).mapObject is null); 530 538 map.getTile(mapPos).mapObject = this; 539 540 currentRealPos = realPos; 541 calcNextRealPos(); 531 542 } 532 543 … … 541 552 { 542 553 pathPool.create(MAX_PATH_LENGTH, MAX_OBJECT_NUMBER); 554 } 555 556 // For interpolation 557 void calcNextRealPos() 558 { 559 auto percent = cast(real)((movePercent + property(Unit.Property.MovementSpeed)) / 560 MAX_MOVE_PERCENT); 561 562 if(percent > 1) percent = 1; 563 564 nextRealPos = lastWayPoint * (1.0 - percent) + nextWayPoint * percent; 543 565 } 544 566 … … 621 643 _sceneNode = new GameObjectModel(sceneGraph.root, unitInfo.model, 622 644 playerColors[gameObjects.players.get(owner).info.color]); 623 645 624 646 _realPos = terrain.getWorldPos(mapPos); 625 647 sceneNode.translation = realPos + unitInfo.posOffset; … … 657 679 foreach(b; path) 658 680 { 659 renderer.drawLine(terrain.getWorldPos(a) + vec3(0, 1, 0),660 terrain.getWorldPos(b) + vec3(0, 1, 0),681 renderer.drawLine(terrain.getWorldPos(a) + vec3(0, 0.11, 0), 682 terrain.getWorldPos(b) + vec3(0, 0.11, 0), 661 683 vec3(1, 0, 0)); 662 684 … … 674 696 override void update() 675 697 { 676 // TODO: interpolate unit positions 677 698 // interpolation 699 if(moving && path) 700 { 701 auto interp = gameObjects.simulation.interpolation; 702 assert(interp <= 1.0f); 703 704 realPos = currentRealPos * (1.0 - interp) + nextRealPos * interp; 705 } 706 678 707 sceneNode.translation = realPos + unitInfo.posOffset; 679 708 sceneNode.rotation = direction + unitInfo.normRotation; … … 708 737 else if(!--attackCounter) 709 738 { 739 // ouch :( 710 740 target.hurt(cast(int)cast(real)property(Property.Attack)); 711 741 … … 758 788 759 789 // Calculate progress of the current tile, in percent 760 auto percent = cast(real)(movePercent / MAX_MOVE_PERCENT); 761 assert(percent >= 0.0f && percent <= 1.0f); 762 763 realPos = lastWayPoint * (1.0 - percent) + nextWayPoint * percent; 790 { 791 auto percent = cast(real)(movePercent / MAX_MOVE_PERCENT); 792 assert(percent >= 0.0f && percent <= 1.0f); 793 794 currentRealPos = lastWayPoint * (1.0 - percent) + nextWayPoint * percent; 795 //realPos = currentRealPos; 796 } 797 798 // interpolation 799 calcNextRealPos(); 764 800 765 801 break; trunk/src/defend/terrain/Terrain.d
r588 r589 456 456 { 457 457 auto pos = getWorldPos(x, y); 458 renderer.drawLine(pos, pos + vec3(0, 0. 5, 0), vec3(1, 0, 0));458 renderer.drawLine(pos, pos + vec3(0, 0.1, 0), vec3(1, 0, 0)); 459 459 } 460 460 } trunk/src/engine/font/FreeType.d
r583 r589 21 21 import engine.rend.Texture; 22 22 import engine.rend.VertexArray; 23 import engine.rend.PrimitiveType;24 23 import engine.rend.opengl.Wrapper; 25 24 import engine.font.Font; trunk/src/engine/model/Mesh.d
r583 r589 12 12 import engine.rend.IndexBuffer; 13 13 import engine.rend.Texture; 14 import engine.rend.PrimitiveType;15 14 16 15 class ModelInstance trunk/src/engine/model/Model.d
r583 r589 13 13 import engine.rend.Texture; 14 14 import engine.rend.VertexArray; 15 import engine.rend.PrimitiveType;16 15 import engine.rend.Renderer; 17 16
