Skip to content

Add a new pygamelib.engine.ExtendableBoard object to support chunks #213

@arnauddupuis

Description

@arnauddupuis

Problem summary/missing feature:
The Board object, while handy, is not very optimized. It is one single 2.5D array and the bigger it becomes the slower it is. partial display alleviate the performance issue but it is not the best way of doing things.

It also makes it very difficult to dynamically expand a board.

Expected behavior:
It would be nice for a Board to have a chunk system where the 2.5D arrays are contained. It would also make adding and discarding chunks very easy.

Work to do:
Here are my initial thoughts on what to do for this to work (all of this is up for discussion):

  • Create a new class in pygamelib.engine: ExtendableBoard (or StechableBoard or MalleableBoard, pick the best name you can think about). This object should be able to have the following constructor parameters:
    • max_width: int: to limit the maximum width expansion.
    • max_height: int: to limit the maximum height expansion.
    • screen_width: int: The width when drawn on the screen (not all chunks are going to be drawn at all time, that's the point). Name is up for debate.
    • screen_height: int: The height when drawn on the screen (not all chunks are going to be drawn at all time, that's the point). Name is up for debate.
    • extend_strategy: that can be pygamelib.constants.HORIZONTAL_EXTEND or pygamelib.constants.VERTICAL_EXTEND (add the constants to the constants module. Horizontal means that it will be filled row by row and vertical column by column (unless a specific chunk is specified).
    • discard_strategy: that can be DOF_STRATEGY (Discard Older First which means that we need to know who is the older), DNF_STRATEGY (Discard Newer First), DFF_STRATEGY (Discard Furthest First, the furthest according to the euclidian distance is discarded first), DCF_STRATEGY (Discard Closest First).
    • chunks: a 2D array of Board objects, it will initialize the ExtendableBoard with chunks. Positions are taken straight from the
  • create a dict ExtendableBoard._chunks that will hold the chunks (a single chunk being a pygamelib.engine.Board object). This should be indexed using the chunk position in the chunk map using a tuple: (row, column). Indexing should start by default at (0, 0).
  • Add API: ExtendableBoard.add_chunks(board: pygamelib.engine.Board, chunk_row: Optional(int), chunk_column: Optional(int)) -> bool: Add a chunk to the ExtendableBoard. If no chunk row and column are specified extend the chunk according to extend_strategy.
  • Add API: ExtendableBoard.discard_chunks(chunk_row: Optional(int), chunk_column: Optional(int)) -> bool: discard the chunk at this coordinate (put the dict to None).
  • Add API: ExtendableBoard.discard_chunks(board: pygamelib.engine.Board) -> bool : find object in chunk map and discard it.
  • Add API: render_to_buffer(self, buffer, row, column, buffer_height, buffer_width) -> None: render the ExtendableBoard on screen according to screen and ExtendableBoard constraints.
  • Wrap the pygamelib.engine.Board features that are used by pygamelib.engine.Game to allow for a drop in replacement of a Board by an ExtandableBoard.

We probably also need some property that hold the current position in the ExtendableBoard (what are the chunks that are currently displayed). This may (or may not) raise a discussion about the object that goes into the extendable board. Could it be a new wrapping class around Board, that holds some of the needed attributes (like the visibility, time of insertion, etc.).

Metadata

Metadata

Assignees

Labels

HacktoberfestGood issue for HacktoberfestNew featureThe issue is leading to the implementation of a new feature.documentationImprovements or additions to documentationenhancementNew feature or requestgood first issueGood for newcomers

Type

No type

Projects

Status

In Progress

Relationships

None yet

Development

No branches or pull requests

Issue actions