Changeset 550
- Timestamp:
- 05/20/08 15:29:14 (8 months ago)
- Files:
-
- trunk/src/defend/Graphics.d (modified) (1 diff)
- trunk/src/defend/Main.d (modified) (2 diffs)
- trunk/src/defend/Map.d (modified) (2 diffs)
- trunk/src/defend/demo/Player.d (modified) (1 diff)
- trunk/src/defend/objects/Core.d (modified) (6 diffs)
- trunk/src/defend/objects/types/Building.d (modified) (2 diffs)
- trunk/src/defend/objects/types/Unit.d (modified) (23 diffs)
- trunk/src/gen/util/Log.d (modified) (5 diffs)
- trunk/src/windefend.cbp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/defend/Graphics.d
r548 r550 54 54 { 55 55 // Preallocate objects 56 MeshNode.memoryPool.create( 2000);56 MeshNode.memoryPool.create(8); 57 57 58 58 // Create particle systems trunk/src/defend/Main.d
r547 r550 21 21 import gen.sound.openal.SoundSystem : OALSoundSystem; 22 22 import gen.util.FPS : FPSCounter; 23 import gen.util.Log : Log, Logger ;23 import gen.util.Log : Log, Logger, LogLevel; 24 24 import gen.util.HardwareTimer : HardwareTimer; 25 25 import gen.util.Config : Config; … … 49 49 // Print a header to the console 50 50 Stdout.formatln("{} {} (built {})", DEFEND_NAME, DEFEND_VERSION, __DATE__); 51 52 // Spam :P 53 Log.defaultLevel = LogLevel.Spam; 51 54 52 55 // Load the config trunk/src/defend/Map.d
r542 r550 361 361 } 362 362 363 buffer[bufferIndex] = goal;364 bufferIndex++;363 //buffer[bufferIndex] = goal; 364 //bufferIndex++; 365 365 366 366 return buffer[0 .. bufferIndex]; … … 372 372 if(neighbor !is null && 373 373 neighbor.walkable && 374 (!considerObjects || 375 neighbor.mapObject is null)) 374 (!considerObjects || neighbor.mapObject is null)) 376 375 { 377 376 bool inList = false; trunk/src/defend/demo/Player.d
r547 r550 20 20 private: 21 21 FileConduit file; 22 float _speed = 1;22 float _speed = 20; 23 23 24 24 ubyte[] dataBuffer; trunk/src/defend/objects/Core.d
r549 r550 620 620 void realPos(vec3 v) { _realPos = v; } 621 621 622 debug(objects) 623 { 624 Logger logger; 625 } 622 debug(gameobjects) Logger logger; 626 623 627 624 void markMap(bool status) … … 648 645 void selfRemove() 649 646 { 650 debug( objects)647 debug(gameobjects) 651 648 { 652 649 logger.trace("removing myself"); … … 872 869 assert(!removed); 873 870 removed = true; 874 875 //Stdout("base remove ")(cast(void*)this)(" -- ")(mapPos).newline; 876 871 877 872 Remove(); 878 873 } … … 935 930 _life = cast(int)property(Property.MaxLife); 936 931 937 debug(objects) 938 { 932 debug(gameobjects) 939 933 logger = Log.getLogger("objects.object." ~ Integer.toString(id)); 940 logger.trace("object has been created");941 }942 934 } 943 935 … … 1384 1376 gateway.checkSync(__FILE__, __LINE__, object.id); 1385 1377 1386 //Stdout("removing object ")(object.id).newline; 1378 debug(gameobjects) 1379 logger.info("removing object (type: '{}'; id: {}, owner: {})", 1380 object.typeInfo.objectType, object.id, object.owner); 1387 1381 1388 1382 objects.removeByIndex(object.id); … … 1504 1498 object.onCreate(); 1505 1499 1506 debug( objects)1507 logger.trace("new object of type {} with id {} for player {} created",1500 debug(gameobjects) 1501 logger.trace("new game object (type: '{}'; id: {}; owner: {})", 1508 1502 type, id, owner); 1509 1503 trunk/src/defend/objects/types/Building.d
r549 r550 280 280 281 281 (cast(Building)objects[0]).enqueue(techPointer); 282 283 /*iterateObjects(objects, (Building object)284 {285 object.enqueue(techPointer);286 });*/287 282 } 288 283 … … 497 492 _sceneNode = new GameObjectModel(sceneGraph.root, buildingInfo.model, 498 493 playerColors[gameObjects.players.get(owner).info.color]); 499 //_sceneNode.color = playerColors[gameObjects.players.get(owner).info.color]; 500 494 501 495 realPos = terrain.getWorldPos(mapPos); 502 496 sceneNode.translation = realPos + buildingInfo.posOffset; trunk/src/defend/objects/types/Unit.d
r549 r550 218 218 { 219 219 protected: 220 // Unit collision resolution 220 // Unit collision resolution, returns true when a collision happened 221 221 bool checkCollision(MapPos pos) 222 222 { 223 // Stdout(id)(" check coll ")(pos).newline;224 223 //logger.spam("checking [{}|{}] for collisions", pos.x, pos.y); 224 225 225 auto tile = map.getTile(pos); 226 assert(tile.mapObject !is this || pos == mapPos);226 assert(tile.mapObject !is this, "um, I'm already standing here."); 227 227 228 228 // Test, if the tile we're going to is already in use … … 245 245 pause = 20; 246 246 path = null; 247 248 debug(gameobjects) logger.spam("tile occupied; taking a break of {} steps", movePause); 247 249 248 moveFinished(); 250 //auto dir = direction; 251 //moveFinished(); // do I need to call it? 252 //direction = dir; 249 253 } 250 254 else … … 271 275 if(newGoal == mapPos || mapPos.distance(finalGoal) < 2) 272 276 { 273 status = Status.Idle; 274 //moving = false; 275 direction = finalDirection; 276 277 debug(gameobjects) logger.spam("tile occupied and no new path found; stopping"); 278 277 279 moveFinished(); 278 280 } 279 281 else 280 282 { 283 debug(gameobjects) logger.spam("tile occupied; going to a tile around the goal"); 284 281 285 // Otherwise, go there 282 286 move(newGoal, false, false, true); … … 285 289 else 286 290 { 291 debug(gameobjects) 292 logger.spam("tile occupied; going to [{}|{}] and then to the final goal", 293 tempGoal.x, tempGoal.y); 294 287 295 /* Go to this free tile while avoiding other units, 288 296 and then continue to go to the final goal */ … … 295 303 else 296 304 { 305 assert(false, "there is no need for this!"); 306 297 307 // Test if this our last tile 298 308 if(pos == finalGoal) 299 309 { 300 debug(unit) 301 trace("final goal reached"); 302 303 //moving = false; 304 status = Status.Idle; 305 direction = finalDirection; 306 310 debug(gameobjects) 311 logger.spam("tile occupied; but final goal already reached"); 312 307 313 moveFinished(); 308 314 … … 332 338 assert(followObject !is null); 333 339 334 debug( unit)335 trace("stopping to follow " ~ Integer.toString(followObject.id));340 debug(gameobjects) 341 logger.spam("stopping to follow {}", followObject.id); 336 342 337 343 isFollowing = false; … … 342 348 void moveFinished() 343 349 { 350 direction = finalDirection; 351 status = Status.Idle; 352 path = null; 353 344 354 if(followObject) 345 355 { 346 356 if(isStandingNearby(followObject)) 347 357 { 348 debug( unit)349 trace("reached the followed object");358 debug(gameobjects) 359 logger.spam("reached the followed object ({})", followObject.id); 350 360 351 361 followCallback(); … … 354 364 else 355 365 { 356 debug( unit)357 trace("didn't come near enough, try again");366 debug(gameobjects) 367 logger.spam("didn't come near enough to the followed object, try again"); 358 368 359 369 follow(followObject, followCallback); … … 369 379 body 370 380 { 371 debug( unit)372 trace("following " ~ Integer.toString(object.id));381 debug(gameobjects) 382 logger.trace("following {}", object.id); 373 383 374 384 isFollowing = true; … … 382 392 383 393 // Move there, even if there's no tile around it free 384 move(walkPos, true, false, true);394 localMove(walkPos); 385 395 386 396 followObject = object; … … 404 414 //bool moving = false; 405 415 bool moving() { return status == Status.Moving; } 406 vec3 direction; 416 417 vec3 _direction; 418 vec3 direction() { return _direction; } 419 void direction(vec3 v) { assert(v.ok); _direction = v; } 420 407 421 vec3 finalDirection; 408 422 … … 426 440 bool considerObjects = false, bool isFinalGoal = true) 427 441 { 442 debug(gameobjects) 443 logger.trace("moving to [{}|{}] (order: {})", 444 p.x, p.y, orderOfUser, considerObjects, isFinalGoal); 445 428 446 if(isFinalGoal) 429 447 finalGoal = p; … … 454 472 } 455 473 } 474 else 475 debug(gameobjects) logger.spam("no path found"); 456 476 } 457 477 … … 465 485 void attack(GameObject object) 466 486 { 487 debug(gameobjects) 488 logger.trace("attacking {}", object.id); 489 467 490 // TODO: !melee 468 491 … … 475 498 void targetReached() 476 499 { 477 debug( unit)478 trace("reached target");500 debug(gameobjects) 501 logger.spam("reached attack target ({})", target.id); 479 502 480 503 status = Status.Attacking; … … 525 548 void moveToPoint(MapPos p) 526 549 { 550 assert(p != mapPos); 551 552 //debug(gameobjects) 553 // logger.spam("walking to [{}|{}]", p.x, p.y); 554 527 555 assert(map.getTile(mapPos).mapObject is this); 528 556 map.getTile(mapPos).mapObject = null; … … 674 702 675 703 sceneNode.translation = realPos + unitInfo.posOffset; 704 705 debug(gameobjects) 706 { 707 if(!direction.ok) 708 logger.warn("direction is a nan"); 709 } 710 676 711 sceneNode.rotation(direction); 677 712 } … … 687 722 { 688 723 if(!moving && mapPos != finalGoal) 724 { 725 logger.spam("continuing to final goal after pause"); 689 726 move(finalGoal, false, false, true); 727 } 690 728 } 691 729 … … 718 756 { 719 757 // Path finished 720 if(path.length <= 1)758 if(path.length <= 2) 721 759 { 722 debug( unit)723 trace("path finished");760 debug(gameobjects) 761 logger.spam("path finished"); 724 762 725 763 status = Status.Idle; … … 729 767 730 768 if(mapPos != finalGoal) 769 { 770 logger.spam("moving to the final goal now"); 731 771 move(finalGoal, false, false, true); 772 } 732 773 else 733 774 moveFinished(); … … 737 778 738 779 // Start walking to the next tile 739 else if( path.length)780 else if(!checkCollision(path[1])) 740 781 { 741 if(!checkCollision(path[1])) 742 { 743 path = path[1 .. $]; 744 moveToPoint(path[0]); 745 } 782 //logger.spam("tile before: [{}|{}]", path[1].x, path[1].y); 783 path = path[1 .. $]; 784 //logger.spam("tile afterwards: [{}|{}]", path[1].x, path[1].y); 785 moveToPoint(path[0]); 746 786 } 747 787 } … … 749 789 // Calculate progress of the current tile, in percent 750 790 auto percent = movePercent / cast(float)MAX_MOVE_PERCENT; 791 assert(percent >= 0.0f && percent <= 1.0f); 792 751 793 realPos = lastWayPoint * (1.0 - percent) + nextWayPoint * percent; 752 794 753 795 // Path finished 754 if(!path.length)796 /*if(!path.length) 755 797 { 756 798 direction = finalDirection; … … 758 800 status = Status.Idle; 759 801 moveFinished(); 760 } 802 }*/ 761 803 762 804 break; trunk/src/gen/util/Log.d
r489 r550 8 8 import tango.text.convert.Layout; 9 9 10 enum LogLevel 11 { 12 Spam, 13 Trace, 14 Info, 15 Warn, 16 Fatal 17 } 18 10 19 final class Log 11 20 { … … 15 24 16 25 public: 26 static LogLevel defaultLevel = LogLevel.Trace; 27 17 28 static Logger getLogger(char[] name) 18 29 { … … 34 45 } 35 46 36 enum LogLevel37 {38 Trace,39 Info,40 Warn,41 Fatal42 }43 44 47 private char[] levelToString(LogLevel level) 45 48 { 46 49 switch(level) 47 50 { 51 case LogLevel.Spam: 52 return "Spam"; 53 48 54 case LogLevel.Trace: 49 55 return "Trace"; … … 129 135 { 130 136 _name = string; 131 _level = Log Level.Trace;137 _level = Log.defaultLevel; 132 138 } 133 139 … … 156 162 synchronized foreach(appender; Log.appenders) 157 163 appender.write(name, type, text); 164 } 165 166 void spam(char[] format, ...) 167 { 168 log(LogLevel.Spam, format, _arguments, _argptr); 158 169 } 159 170 trunk/src/windefend.cbp
r545 r550 34 34 <Add option="-g" /> 35 35 <Add option="-debug" /> 36 <Add option="-debug= objects" />36 <Add option="-debug=gameobjects" /> 37 37 </Compiler> 38 38 <Linker>
