Changeset 550

Show
Ignore:
Timestamp:
05/20/08 15:29:14 (8 months ago)
Author:
LeoD
Message:

added lots of spam-logging for units, fixed some pathfinding and collision resolution bugs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/defend/Graphics.d

    r548 r550  
    5454    {    
    5555        // Preallocate objects 
    56         MeshNode.memoryPool.create(2000); 
     56        MeshNode.memoryPool.create(8); 
    5757     
    5858        // Create particle systems 
  • trunk/src/defend/Main.d

    r547 r550  
    2121import gen.sound.openal.SoundSystem : OALSoundSystem; 
    2222import gen.util.FPS : FPSCounter; 
    23 import gen.util.Log : Log, Logger
     23import gen.util.Log : Log, Logger, LogLevel
    2424import gen.util.HardwareTimer : HardwareTimer; 
    2525import gen.util.Config : Config; 
     
    4949    // Print a header to the console 
    5050    Stdout.formatln("{} {} (built {})", DEFEND_NAME, DEFEND_VERSION, __DATE__); 
     51 
     52    // Spam :P 
     53    Log.defaultLevel = LogLevel.Spam; 
    5154 
    5255    // Load the config 
  • trunk/src/defend/Map.d

    r542 r550  
    361361                } 
    362362 
    363                 buffer[bufferIndex] = goal; 
    364                 bufferIndex++; 
     363                //buffer[bufferIndex] = goal; 
     364                //bufferIndex++; 
    365365 
    366366                return buffer[0 .. bufferIndex]; 
     
    372372                    if(neighbor !is null && 
    373373                       neighbor.walkable && 
    374                        (!considerObjects || 
    375                         neighbor.mapObject is null)) 
     374                       (!considerObjects || neighbor.mapObject is null)) 
    376375                    { 
    377376                        bool inList = false; 
  • trunk/src/defend/demo/Player.d

    r547 r550  
    2020private: 
    2121    FileConduit file; 
    22     float _speed = 1
     22    float _speed = 20
    2323 
    2424    ubyte[] dataBuffer; 
  • trunk/src/defend/objects/Core.d

    r549 r550  
    620620    void realPos(vec3 v) { _realPos = v; } 
    621621 
    622     debug(objects) 
    623     { 
    624         Logger logger; 
    625     } 
     622    debug(gameobjects) Logger logger; 
    626623     
    627624    void markMap(bool status) 
     
    648645    void selfRemove() 
    649646    { 
    650         debug(objects) 
     647        debug(gameobjects) 
    651648        { 
    652649            logger.trace("removing myself"); 
     
    872869        assert(!removed); 
    873870        removed = true; 
    874          
    875         //Stdout("base remove ")(cast(void*)this)(" -- ")(mapPos).newline; 
    876          
     871 
    877872        Remove(); 
    878873    } 
     
    935930        _life = cast(int)property(Property.MaxLife); 
    936931 
    937         debug(objects) 
    938         { 
     932        debug(gameobjects) 
    939933            logger = Log.getLogger("objects.object." ~ Integer.toString(id)); 
    940             logger.trace("object has been created"); 
    941         } 
    942934    } 
    943935 
     
    13841376            gateway.checkSync(__FILE__, __LINE__, object.id); 
    13851377             
    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); 
    13871381 
    13881382            objects.removeByIndex(object.id); 
     
    15041498        object.onCreate(); 
    15051499         
    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: {})", 
    15081502                         type, id, owner); 
    15091503             
  • trunk/src/defend/objects/types/Building.d

    r549 r550  
    280280         
    281281            (cast(Building)objects[0]).enqueue(techPointer); 
    282          
    283             /*iterateObjects(objects, (Building object) 
    284             { 
    285                 object.enqueue(techPointer); 
    286             });*/ 
    287282        } 
    288283         
     
    497492        _sceneNode = new GameObjectModel(sceneGraph.root, buildingInfo.model, 
    498493                                         playerColors[gameObjects.players.get(owner).info.color]); 
    499         //_sceneNode.color = playerColors[gameObjects.players.get(owner).info.color]; 
    500          
     494 
    501495        realPos = terrain.getWorldPos(mapPos); 
    502496        sceneNode.translation = realPos + buildingInfo.posOffset; 
  • trunk/src/defend/objects/types/Unit.d

    r549 r550  
    218218{ 
    219219protected:   
    220     // Unit collision resolution 
     220    // Unit collision resolution, returns true when a collision happened 
    221221    bool checkCollision(MapPos pos) 
    222222    { 
    223         //Stdout(id)(" check coll ")(pos).newline
    224         
     223        //logger.spam("checking [{}|{}] for collisions", pos.x, pos.y)
     224     
    225225        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."); 
    227227         
    228228        // Test, if the tile we're going to is already in use 
     
    245245                    pause = 20; 
    246246                    path = null; 
     247                 
     248                    debug(gameobjects) logger.spam("tile occupied; taking a break of {} steps", movePause); 
    247249                     
    248                     moveFinished(); 
     250                    //auto dir = direction; 
     251                    //moveFinished(); // do I need to call it? 
     252                    //direction = dir; 
    249253                } 
    250254                else 
     
    271275                        if(newGoal == mapPos || mapPos.distance(finalGoal) < 2) 
    272276                        { 
    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 
    277279                            moveFinished(); 
    278280                        } 
    279281                        else 
    280282                        { 
     283                            debug(gameobjects) logger.spam("tile occupied; going to a tile around the goal"); 
     284                         
    281285                            // Otherwise, go there 
    282286                            move(newGoal, false, false, true); 
     
    285289                    else 
    286290                    { 
     291                        debug(gameobjects) 
     292                            logger.spam("tile occupied; going to [{}|{}] and then to the final goal", 
     293                                        tempGoal.x, tempGoal.y); 
     294                     
    287295                        /* Go to this free tile while avoiding other units, 
    288296                           and then continue to go to the final goal */ 
     
    295303            else 
    296304            { 
     305                assert(false, "there is no need for this!"); 
     306             
    297307                // Test if this our last tile 
    298308                if(pos == finalGoal) 
    299309                { 
    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 
    307313                    moveFinished(); 
    308314                    
     
    332338        assert(followObject !is null); 
    333339     
    334         debug(unit
    335             trace("stopping to follow " ~ Integer.toString(followObject.id)); 
     340        debug(gameobjects
     341            logger.spam("stopping to follow {}", followObject.id); 
    336342     
    337343        isFollowing = false; 
     
    342348    void moveFinished() 
    343349    { 
     350        direction = finalDirection; 
     351        status = Status.Idle; 
     352        path = null; 
     353     
    344354        if(followObject) 
    345355        { 
    346356            if(isStandingNearby(followObject)) 
    347357            { 
    348                 debug(unit
    349                     trace("reached the followed object"); 
     358                debug(gameobjects
     359                    logger.spam("reached the followed object ({})", followObject.id); 
    350360             
    351361                followCallback(); 
     
    354364            else 
    355365            { 
    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"); 
    358368             
    359369                follow(followObject, followCallback); 
     
    369379    body 
    370380    { 
    371         debug(unit
    372             trace("following " ~ Integer.toString(object.id)); 
     381        debug(gameobjects
     382            logger.trace("following {}", object.id); 
    373383     
    374384        isFollowing = true; 
     
    382392 
    383393        // Move there, even if there's no tile around it free 
    384         move(walkPos, true, false, true); 
     394        localMove(walkPos); 
    385395 
    386396        followObject = object; 
     
    404414    //bool moving = false; 
    405415    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     
    407421    vec3 finalDirection; 
    408422     
     
    426440                    bool considerObjects = false, bool isFinalGoal = true) 
    427441    { 
     442        debug(gameobjects) 
     443            logger.trace("moving to [{}|{}] (order: {})", 
     444                         p.x, p.y, orderOfUser, considerObjects, isFinalGoal); 
     445     
    428446        if(isFinalGoal) 
    429447            finalGoal = p; 
     
    454472                } 
    455473            } 
     474            else 
     475                debug(gameobjects) logger.spam("no path found"); 
    456476        } 
    457477         
     
    465485    void attack(GameObject object) 
    466486    { 
     487        debug(gameobjects) 
     488            logger.trace("attacking {}", object.id); 
     489     
    467490        // TODO: !melee 
    468491         
     
    475498    void targetReached() 
    476499    { 
    477         debug(unit
    478             trace("reached target"); 
     500        debug(gameobjects
     501            logger.spam("reached attack target ({})", target.id); 
    479502     
    480503        status = Status.Attacking; 
     
    525548    void moveToPoint(MapPos p) 
    526549    { 
     550        assert(p != mapPos); 
     551     
     552        //debug(gameobjects) 
     553        //  logger.spam("walking to [{}|{}]", p.x, p.y); 
     554     
    527555        assert(map.getTile(mapPos).mapObject is this); 
    528556        map.getTile(mapPos).mapObject = null; 
     
    674702     
    675703        sceneNode.translation = realPos + unitInfo.posOffset; 
     704         
     705        debug(gameobjects) 
     706        { 
     707            if(!direction.ok) 
     708                logger.warn("direction is a nan"); 
     709        } 
     710         
    676711        sceneNode.rotation(direction); 
    677712    } 
     
    687722            { 
    688723                if(!moving && mapPos != finalGoal) 
     724                { 
     725                    logger.spam("continuing to final goal after pause"); 
    689726                    move(finalGoal, false, false, true); 
     727                } 
    690728            } 
    691729             
     
    718756            { 
    719757                // Path finished 
    720                 if(path.length <= 1
     758                if(path.length <= 2
    721759                { 
    722                     debug(unit
    723                         trace("path finished"); 
     760                    debug(gameobjects
     761                        logger.spam("path finished"); 
    724762                     
    725763                    status = Status.Idle; 
     
    729767                     
    730768                    if(mapPos != finalGoal) 
     769                    { 
     770                        logger.spam("moving to the final goal now"); 
    731771                        move(finalGoal, false, false, true); 
     772                    } 
    732773                    else 
    733774                        moveFinished(); 
     
    737778                 
    738779                // Start walking to the next tile 
    739                 else if(path.length
     780                else if(!checkCollision(path[1])
    740781                { 
    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]); 
    746786                } 
    747787            } 
     
    749789            // Calculate progress of the current tile, in percent 
    750790            auto percent = movePercent / cast(float)MAX_MOVE_PERCENT; 
     791            assert(percent >= 0.0f && percent <= 1.0f); 
     792             
    751793            realPos = lastWayPoint * (1.0 - percent) + nextWayPoint * percent; 
    752794             
    753795            // Path finished 
    754             if(!path.length) 
     796            /*if(!path.length) 
    755797            { 
    756798                direction = finalDirection; 
     
    758800                status = Status.Idle; 
    759801                moveFinished(); 
    760             } 
     802            }*/ 
    761803             
    762804            break; 
  • trunk/src/gen/util/Log.d

    r489 r550  
    88import tango.text.convert.Layout; 
    99 
     10enum LogLevel 
     11{ 
     12    Spam, 
     13    Trace, 
     14    Info, 
     15    Warn, 
     16    Fatal 
     17} 
     18 
    1019final class Log 
    1120{ 
     
    1524     
    1625public: 
     26    static LogLevel defaultLevel = LogLevel.Trace; 
     27 
    1728    static Logger getLogger(char[] name) 
    1829    { 
     
    3445} 
    3546 
    36 enum LogLevel 
    37 { 
    38     Trace, 
    39     Info, 
    40     Warn, 
    41     Fatal 
    42 } 
    43  
    4447private char[] levelToString(LogLevel level) 
    4548{ 
    4649    switch(level) 
    4750    { 
     51    case LogLevel.Spam: 
     52        return "Spam"; 
     53     
    4854    case LogLevel.Trace: 
    4955        return "Trace"; 
     
    129135    { 
    130136        _name = string; 
    131         _level = LogLevel.Trace
     137        _level = Log.defaultLevel
    132138    } 
    133139     
     
    156162        synchronized foreach(appender; Log.appenders) 
    157163            appender.write(name, type, text); 
     164    } 
     165     
     166    void spam(char[] format, ...) 
     167    { 
     168        log(LogLevel.Spam, format, _arguments, _argptr); 
    158169    } 
    159170     
  • trunk/src/windefend.cbp

    r545 r550  
    3434                    <Add option="-g" /> 
    3535                    <Add option="-debug" /> 
    36                     <Add option="-debug=objects" /> 
     36                    <Add option="-debug=gameobjects" /> 
    3737                </Compiler> 
    3838                <Linker>