Skip to content

Commit

Permalink
etc: Pretty printer for path::integrated_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Apr 7, 2024
1 parent 954fb24 commit 230ae59
Showing 1 changed file with 55 additions and 9 deletions.
64 changes: 55 additions & 9 deletions etc/gdb_pretty/printers.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@ class PathFlowTypePrinter:
TODO: Inherit from gdb.ValuePrinter when gdb 14.1 is available in all distros.
"""

FLOW_FLAGS = {
FLOW_FLAGS: dict = {
0x10: 'PATHABLE',
0x20: 'LOS',
0x40: 'WAVEFRONT_BLOCKED',
0x80: 'UNUSED',
}

FLOW_DIRECTION = {
FLOW_DIRECTION: dict = {
0x00: 'NORTH',
0x01: 'NORTHEAST',
0x02: 'EAST',
Expand All @@ -271,7 +271,7 @@ def to_string(self):
flow = int(self.__val)
flags = flow & 0xF0
direction = flow & 0x0F
return (f"{self.FLOW_DIRECTION.get(direction, 'INVALID')} | ("
return (f"{self.FLOW_DIRECTION.get(direction, 'INVALID')} ("
f"{', '.join([self.FLOW_FLAGS[f] for f in self.FLOW_FLAGS if f & flags])})")

def children(self):
Expand All @@ -286,6 +286,28 @@ def children(self):
yield (flag, bool(flags & mask))


# Integrated flags
INTEGRATED_FLAGS: dict = {
0x01: 'LOS',
0x02: 'WAVEFRONT_BLOCKED',
}


def get_integrated_flags_list(value: int) -> str:
"""
Get the list of flags as a string.
:param value: The value to get the flags for.
:type value: int
"""
flags = []
for mask, flag in INTEGRATED_FLAGS.items():
if value & mask:
flags.append(flag)

return ' | '.join(flags)


@printer_typedef('openage::path::integrated_flags_t')
class PathIntegratedFlagsTypePrinter:
"""
Expand All @@ -294,11 +316,6 @@ class PathIntegratedFlagsTypePrinter:
TODO: Inherit from gdb.ValuePrinter when gdb 14.1 is available in all distros.
"""

INTEGRATED_FLAGS = {
0x01: 'LOS',
0x02: 'WAVEFRONT_BLOCKED',
}

def __init__(self, val: gdb.Value):
self.__val = val

Expand All @@ -307,7 +324,7 @@ def to_string(self):
Get the integrate type as a string.
"""
integrate = int(self.__val)
return f"{', '.join([self.INTEGRATED_FLAGS[f] for f in self.INTEGRATED_FLAGS if f & integrate])}"
return get_integrated_flags_list(integrate)

def children(self):
"""
Expand All @@ -318,6 +335,35 @@ def children(self):
yield (flag, bool(integrate & mask))


@printer_typedef('openage::path::integrated_t')
class PathIntegratedTypePrinter:
"""
Pretty printer for openage::path::integrated_t.
TODO: Inherit from gdb.ValuePrinter when gdb 14.1 is available in all distros.
"""

def __init__(self, val: gdb.Value):
self.__val = val

def to_string(self):
"""
Get the integrate type as a string.
"""
output_str = f'cost = {self.__val["cost"]}'
flags = get_integrated_flags_list(int(self.__val['flags']))
if len(flags) > 0:
output_str += f' ({flags})'
return output_str

def children(self):
"""
Get the displayed children of the integrate type.
"""
yield ('cost', self.__val['cost'])
yield ('flags', self.__val['flags'])


# TODO: curve types
# TODO: coord types
# TODO: pathfinding types
Expand Down

0 comments on commit 230ae59

Please sign in to comment.