Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[A] Create interface & implementation for each cost matrix (PARENT TICKET) #102

Open
jakesboy2 opened this issue May 7, 2020 · 0 comments
Labels
enhancement New feature or request movement Issue deals with our pathfinding / movement code
Projects

Comments

@jakesboy2
Copy link
Collaborator

jakesboy2 commented May 7, 2020

  • Create an interface that requests a .Get() method for all implementations. This method accepts arguments for flags, uses those flags to route to the correct method
  • Each class contains methods that implement the flags passed in above, required per above interface
  • each method above is cached individually in a per class, per room cache --- Should be able to expire different flags at different times

Caching of Cost Matrices should be done by introducing a variable at the top of each class file:

export class CostMatrixExample{
    public static cache: CostMatrixCache = {};
}
interface CostMatrixCache {
    [roomName: string]: {
              matrixName: { cm: CostMatrix, expireTime: number }
     }
}

The expire time on a CostMatrixCache will signify the maximum Game.time that a matrix can be used. Once the Game.time is greater than the expireTime, the matrix is invalid and should be regenerated.

export class CostMatrixExample{
    Get(params): CostMatrix {
        if(params.ignoreCreep) { // for the sake of example, the only options are ignoreCreep and ignoreStructure
             return this.ExampleMatrix_ignoreCreep(params.roomName);
        }
    }

    ExampleMatrix_ignoreCreep(roomName: string): CostMatrix {
        if(cache[roomName] !== undefined &&
           cache[roomName].ignoreCreep !== undefined &&
           cache[roomname].ignoreCreep.expireTime >= Game.time()) {
             return cache[roomName].ignoreCreep.cm;
          }
         // else generate the matrix and store it into the cache structure,
         // setting the expireTime = Game.time() + #ticks to cache the matrix
        return matrix;
    }
}

PARENT TICKET, Closed once all child tickets are closed

@jakesboy2 jakesboy2 added the enhancement New feature or request label May 7, 2020
@jakesboy2 jakesboy2 added this to To do in Voyager May 7, 2020
@jakesboy2 jakesboy2 moved this from To do to Parent Tickets In Progress in Voyager May 7, 2020
@UhmBrock UhmBrock added the movement Issue deals with our pathfinding / movement code label May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request movement Issue deals with our pathfinding / movement code
Projects
Voyager
  
Parent Tickets In Progress
Development

No branches or pull requests

2 participants