Changeset 521
- Timestamp:
- 04/26/08 06:50:21 (9 months ago)
- Files:
-
- trunk/run/data/shaders/terrain.pixel.glsl (modified) (3 diffs)
- trunk/src/defend/Main.d (modified) (1 diff)
- trunk/src/defend/objects/Core.d (modified) (9 diffs)
- trunk/src/defend/objects/types/Building.d (modified) (4 diffs)
- trunk/src/defend/objects/types/Citizen.d (modified) (1 diff)
- trunk/src/defend/objects/types/House.d (modified) (1 diff)
- trunk/src/defend/objects/types/Sheep.d (modified) (1 diff)
- trunk/src/defend/objects/types/Unit.d (modified) (20 diffs)
- trunk/src/gen/rend/opengl/Renderer.d (modified) (3 diffs)
- trunk/src/gen/rend/opengl/Shader.d (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/run/data/shaders/terrain.pixel.glsl
r520 r521 1 #include shadowmap.glsl 2 1 3 uniform sampler2D alpha; 2 4 uniform sampler2D texture1; … … 5 7 uniform sampler2D lightmap; 6 8 uniform sampler2D shadow; 7 8 uniform vec3 lightPos;9 9 10 10 varying vec4 lightSpacePos; … … 23 23 c3 *= a.b * inverse; 24 24 25 gl_FragColor = (c1 + c2 + c3) * (l * 2); 26 27 /*vec2 shadowMapCoord = 0.5f * lightSpacePos.xy / lightSpacePos.w + vec2(0.5f, 0.5f); 28 float shadowMapDistance = texture2D(shadow, shadowMapCoord).r; 29 30 #define FAR 300.0f 31 #define NEAR 50.0f 32 33 float lightDistance = (1.0f / NEAR - 1.0f / (lightSpacePos.z)) / (1.0f / NEAR - 1.0f / FAR); 34 lightDistance = lightSpacePos.z / lightSpacePos.w; 35 36 if(lightDistance < 0 || lightDistance > 1) // debugging 37 { 38 gl_FragColor = vec4(1, 0, 0, 0); 39 return; 40 } 41 42 float shadowValue = 1; 43 44 if(lightDistance + 0.2f >= shadowMapDistance && shadowMapDistance != 1.0f) // point is in shadow 45 { 46 shadowValue = 0.3; 47 } 48 49 if(shadowMapCoord.x >= 0 && shadowMapCoord.x <= 1 && shadowMapCoord.y >= 0 && shadowMapCoord.y <= 1) 50 { 51 //float x = shadowMapDistance - lightDistance; 52 53 gl_FragColor *= vec4(shadowValue, shadowValue, shadowValue, 0); 54 //gl_FragColor = vec4(lightDistance, lightDistance, lightDistance, 0); 55 //gl_FragColor = vec4(x, x, x, 0); 56 //gl_FragColor = vec4(shadowMapDistance, shadowMapDistance, shadowMapDistance, 0); 57 }*/ 25 gl_FragColor = (c1 + c2 + c3) * (l * 2); //* shadowMap(shadow, lightSpacePos); 58 26 } trunk/src/defend/Main.d
r513 r521 191 191 parser.parse(args[1 .. $]); 192 192 193 gameConfig.recordDemo = !gameConfig.multiplayer.isServer;193 gameConfig.recordDemo = gameConfig.multiplayer.isServer; 194 194 195 195 // Show help? trunk/src/defend/objects/Core.d
r505 r521 651 651 652 652 Gateway gateway; 653 GameObjectManager manager;653 GameObjectManager gameObjects; 654 654 655 655 vec3 _realPos; // The real position … … 696 696 } 697 697 698 manager.localRemove(id);698 gameObjects.localRemove(id); 699 699 } 700 700 … … 702 702 void status(object_status_t s) 703 703 { 704 assert(_status != Status.Dead);704 //assert(_status != Status.Dead); 705 705 706 706 _status = s; … … 779 779 { 780 780 status = Status.Dead; 781 manager.objectDead(this); 782 } 781 //gameObjects.objectDead(this); 782 gameObjects.localRemove(id); 783 } 784 } 785 786 void hurt(int i) 787 { 788 life = life - min(life, i); 783 789 } 784 790 … … 813 819 if(element.effector is null) 814 820 { 815 element.whenApplied = manager.currentSimulationStep();821 element.whenApplied = gameObjects.currentSimulationStep(); 816 822 element.effector = effector; 817 823 … … 955 961 void simulate() 956 962 { 957 assert(!removed);963 //assert(!removed); 958 964 959 965 foreach(element; effectors) 960 966 { 961 967 if(element.effector !is null && element.effector.lifetime != 0 && 962 manager.currentSimulationStep() - element.whenApplied == 0)968 gameObjects.currentSimulationStep() - element.whenApplied == 0) 963 969 { 964 970 element.effector.detach(this); … … 971 977 void afterSimulate() 972 978 { 973 assert(!removed);979 //assert(!removed); 974 980 } 975 981 … … 1571 1577 object.mapPos = MapPos(x, y); 1572 1578 object.gateway = gateway; 1573 object. manager= this;1579 object.gameObjects = this; 1574 1580 object.onCreate(); 1575 1581 … … 1583 1589 } 1584 1590 1585 void objectDead(GameObject object) 1586 { 1591 deprecated void objectDead(GameObject object) 1592 { 1593 // wtf is that for lol 1587 1594 ObjectDead(object); 1588 1595 } trunk/src/defend/objects/types/Building.d
r511 r521 12 12 import gen.scene.Graph; 13 13 import gen.scene.ModelNode; 14 import gen.scene.ParticleSystem; 14 15 import gen.math.Rectangle; 15 16 import gen.math.Vector; … … 559 560 560 561 _sceneNode = new GameObjectModel(sceneGraph.root, buildingInfo.model, 561 playerColors[ manager.players.get(owner).info.color]);562 //_sceneNode.color = playerColors[ manager.players.get(owner).info.color];562 playerColors[gameObjects.players.get(owner).info.color]); 563 //_sceneNode.color = playerColors[gameObjects.players.get(owner).info.color]; 563 564 564 565 realPos = terrain.getWorldPos(mapPos); … … 575 576 { 576 577 super.onRemove(); 578 579 //void spawn(vec3 point, uint number) 580 581 foreach(x, y; mapRectangle) 582 particles("smoke").spawn(terrain.getWorldPos(x, y) + vec3(0, 0.5, 1), 1); 577 583 578 584 markMap(true); … … 627 633 } 628 634 629 auto obj = cast(Unit) manager.localCreate(owner,635 auto obj = cast(Unit)gameObjects.localCreate(owner, 630 636 entry.unitType.objectType, 631 637 unitPos.x, trunk/src/defend/objects/types/Citizen.d
r469 r521 34 34 canBuild = [ "house" ]; 35 35 properties[GameObject.Property.MaxLife] = 500; 36 properties[Unit.Property.Attack] = 10; 36 37 properties[Unit.Property.MovementSpeed] = 50; 38 properties[Unit.Property.AttackSpeed] = 250; 37 39 } 38 40 trunk/src/defend/objects/types/House.d
r483 r521 26 26 canDevelop = [ "sheep on drugs" ]; 27 27 miniPic = "data/minipics/house.png"; 28 properties[GameObject.Property.MaxLife] = 2000; 28 29 } 29 30 trunk/src/defend/objects/types/Sheep.d
r515 r521 33 33 developmentSteps = 18; 34 34 properties[GameObject.Property.MaxLife] = 500; 35 properties[Unit.Property.Attack] = 5; 35 36 properties[Unit.Property.MovementSpeed] = 100; 37 properties[Unit.Property.AttackSpeed] = 50; 36 38 } 37 39 trunk/src/defend/objects/types/Unit.d
r511 r521 167 167 } 168 168 169 override OrderError checkOrder(GameObject[] objects, OrderObjectRightClick* order) 170 { 171 auto target = gameObjects.getObject(order.target); 172 173 return OrderError.Okay; // tmp for testing 174 return target.owner != objects[0].owner ? 175 OrderError.Okay : OrderError.Error; 176 } 177 169 178 override void onOrder(GameObject[] objects, OrderMapRightClick* order) 170 179 { 180 // TODO: Group pathfinding 171 181 iterateObjects(objects, (Unit object) 172 182 { … … 182 192 { 183 193 object.finalDirection = direction; 194 }); 195 } 196 197 override void onOrder(GameObject[] objects, OrderObjectRightClick* order) 198 { 199 auto target = gameObjects.getObject(order.target); 200 201 iterateObjects(objects, (Unit object) 202 { 203 object.attack(target); 184 204 }); 185 205 } … … 239 259 240 260 /* If the unit on this tile is moving too, 241 we simply wait some ticks and go to the final goal then*/261 we simply wait some ticks and go to the final goal afterwards */ 242 262 if(unit.moving && unit.movePause == 0 && 243 263 property(Unit.Property.MovementSpeed) <= 244 264 unit.property(Unit.Property.MovementSpeed)) 245 265 { 246 pause (3);266 pause = 3; 247 267 path = []; 248 268 … … 273 293 { 274 294 status = Status.Idle; 275 moving = false;295 //moving = false; 276 296 direction = finalDirection; 277 297 … … 302 322 trace("final goal reached"); 303 323 304 moving = false;324 //moving = false; 305 325 status = Status.Idle; 306 326 direction = finalDirection; … … 403 423 vec3 nextWayPoint; 404 424 MapPos finalGoal; 405 bool moving = false; 425 //bool moving = false; 426 bool moving() { return status == Status.Moving; } 406 427 vec3 direction; 407 428 vec3 finalDirection; … … 409 430 uint movePercent; // from 0 to 1000 410 431 const MAX_MOVE_PERCENT = 1000; 432 433 // Attacking 434 GameObject target; // Attack target 435 uint attackCounter; // Countdown to the next attack 411 436 412 437 MapPos[] pathBuffer; … … 422 447 bool considerObjects = false, bool isFinalGoal = true) 423 448 { 424 status = Status.Moving;425 426 449 if(isFinalGoal) 427 450 finalGoal = p; … … 435 458 path = map.getPath(mapPos, p, pathBuffer[1 .. $], considerObjects, this); 436 459 path = pathBuffer[0 .. path.length == 0 ? 1 : path.length]; 460 461 assert(moving); 437 462 } 438 463 else … … 442 467 if(path.length) 443 468 { 444 moving = true;445 446 if(!checkCollision(path[0]) && moving)469 status = Status.Moving; 470 471 if(!checkCollision(path[0])) 447 472 moveToPoint(path[0]); 448 473 } … … 451 476 gateway.checkSync(__FILE__, __LINE__, id); 452 477 gateway.checkSync(__FILE__, __LINE__, path.length); 478 } 479 480 // Attack another unit 481 void attack(GameObject object) 482 { 483 // TODO: !melee 484 485 target = object; 486 follow(target, &targetReached); 487 488 resetAttackCounter(); 489 } 490 491 void targetReached() 492 { 493 debug(unit) 494 trace("reached target"); 495 496 status = Status.Attacking; 497 } 498 499 void resetAttackCounter() 500 { 501 Stdout("setting counter to ")(cast(int)property(Property.AttackSpeed)).newline; 502 503 attackCounter = cast(int)property(Property.AttackSpeed); 504 assert(attackCounter > 0); 453 505 } 454 506 … … 534 586 Armour, 535 587 Range, 536 MovementSpeed 588 MovementSpeed, 589 AttackSpeed 537 590 } 538 591 … … 545 598 dg("range", property(Property.Range)); 546 599 dg("movement speed", property(Property.MovementSpeed)); 600 dg("attack speed", property(Property.AttackSpeed)); 547 601 } 548 602 … … 553 607 if(which is followObject) 554 608 stopFollow(); 609 610 if(which is target) 611 { 612 target = null; 613 status = Status.Idle; 614 } 555 615 } 556 616 … … 575 635 realPos = terrain.getWorldPos(mapPos); 576 636 finalGoal = mapPos; 577 moving = false;578 637 579 638 pathPoolSlice = pathBuffer = pathPool.allocate(); 580 639 581 640 _sceneNode = new GameObjectModel(sceneGraph.root, unitInfo.model, 582 playerColors[ manager.players.get(owner).info.color]);583 //_sceneNode.color = playerColors[ manager.players.get(owner).info.color];641 playerColors[gameObjects.players.get(owner).info.color]); 642 //_sceneNode.color = playerColors[gameObjects.players.get(owner).info.color]; 584 643 585 644 _realPos = terrain.getWorldPos(mapPos); … … 636 695 super.simulate(); 637 696 638 if(movePause > 0) 639 { 640 movePause--; 641 642 if(movePause == 0) 643 { 644 if(!moving && mapPos != finalGoal) 645 move(finalGoal, false, false, true); 646 } 647 } 648 649 if(moving) 650 { 697 switch(status) 698 { 699 case Status.Attacking: 700 if(!target) 701 status = Status.Idle; 702 else if(!--attackCounter) 703 { 704 target.hurt(cast(int)property(Property.Attack)); 705 706 resetAttackCounter(); 707 } 708 709 break; 710 711 case Status.Moving: 712 // Continue moving after taking a break 713 if(movePause > 0) 714 { 715 movePause--; 716 717 if(movePause == 0) 718 { 719 if(!moving && mapPos != finalGoal) 720 move(finalGoal, false, false, true); 721 } 722 } 723 651 724 if(movePercent < MAX_MOVE_PERCENT) 652 725 movePercent += property(Unit.Property.MovementSpeed); … … 655 728 movePercent = MAX_MOVE_PERCENT; 656 729 730 // Reached the next tile 657 731 if(movePercent == MAX_MOVE_PERCENT) 658 732 { 733 // Path finished 659 734 if(path.length <= 1) 660 735 { … … 662 737 trace("path finished"); 663 738 664 moving = false;665 739 status = Status.Idle; 666 740 path = []; … … 675 749 gateway.checkSync(__FILE__, __LINE__, id); 676 750 } 751 752 // Start walking to the next tile 677 753 else if(!checkCollision(path[1]) && moving && path.length) 678 754 { … … 682 758 } 683 759 760 // Calculate progress in percent of the current tile 684 761 auto percent = movePercent / cast(float)MAX_MOVE_PERCENT; 685 762 realPos = lastWayPoint * (1.0 - percent) + nextWayPoint * percent; 686 763 764 // Path finished 687 765 if(!path.length) 688 766 { 689 767 direction = finalDirection; 690 moving = false; 768 //moving = false; 769 status = Status.Idle; 691 770 moveFinished(); 692 771 } 772 773 break; 774 775 default: 776 break; 693 777 } 694 778 } trunk/src/gen/rend/opengl/Renderer.d
r520 r521 464 464 override Texture createTexture(Image image) 465 465 { 466 logger.info("creating {}*{} texture (from \"{}\")", image.width, image.height, image.file); 467 466 468 return new OGLTexture(image); 467 469 } … … 469 471 override Texture createTexture(vec2i dimension, ImageFormat format) 470 472 { 473 logger.info("creating {}*{} texture render target", dimension.x, dimension.y); 474 471 475 return new OGLTexture(dimension, format); 472 476 } … … 573 577 override Shader createShader(char[] file) 574 578 { 579 logger.info("creating shader from \"{}\"", file); 580 575 581 return new OGLShader(file); 576 582 } trunk/src/gen/rend/opengl/Shader.d
r520 r521 2 2 3 3 import tango.io.Stdout; 4 import tango.io.File; 4 5 import tango.io.FilePath; 5 6 import tango.stdc.stringz; 7 import tango.text.Util; 6 8 7 9 import derelict.opengl.gl; … … 25 27 26 28 int[char[]] uniformHandles; 29 30 char[] preprocess(char[] basedir, char[] code) 31 { 32 char[] result; 33 34 foreach(line; lines(code)) 35 { 36 //Stdout(line).newline; 37 38 line = trim(line); 39 40 if(line.length && line[0] == '#') 41 { 42 if(auto pos = locate(line, ' ')) 43 { 44 switch(line[1 .. pos]) 45 { 46 case "include": 47 result ~= preprocess(basedir, cast(char[])(new File(basedir ~ line[pos + 1 .. $])).read); 48 break; 49 50 default: 51 result ~= line ~ "\n"; 52 } 53 } 54 } 55 else 56 result ~= line ~ "\n"; 57 } 58 59 return result; 60 } 27 61 28 62 void checkError(int object, int type) … … 55 89 auto codep = toStringz(code); 56 90 int lengthp = code.length; 91 92 //Stdout("compiling....................").newline; 57 93 58 94 glShaderSourceARB(result, 1, &codep, &lengthp); … … 101 137 context = glCreateProgramObjectARB(); 102 138 139 char[] basedir; 140 foreach(part; split(file, "/")[0 .. $ - 1]) 141 basedir ~= part ~ "/"; 142 143 //Stdout(basedir).newline; 144 103 145 char[] path = file ~ ".vertex.glsl"; 104 146 if(FilePath(path).exists) withReadFile(path, (char[] code) 105 147 { 106 vertexShaderObject = compile( code, GL_VERTEX_SHADER_ARB);148 vertexShaderObject = compile(preprocess(basedir, code), GL_VERTEX_SHADER_ARB); 107 149 }); 108 150 … … 110 152 if(FilePath(path).exists) withReadFile(path, (char[] code) 111 153 { 112 pixelShaderObject = compile( code, GL_FRAGMENT_SHADER_ARB);154 pixelShaderObject = compile(preprocess(basedir, code), GL_FRAGMENT_SHADER_ARB); 113 155 }); 114 156
