Skip to content

Commit

Permalink
etc: Pretty printers for path::flow_t and path::integrated_flags_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Apr 7, 2024
1 parent 09a1e4d commit 2d58d20
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 5 deletions.
84 changes: 84 additions & 0 deletions etc/gdb_pretty/printers.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,90 @@ def children(self):
yield ('time', self.__val['time'])
yield ('value', self.__val['value'])


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

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

FLOW_DIRECTION = {
0x00: 'NORTH',
0x01: 'NORTHEAST',
0x02: 'EAST',
0x03: 'SOUTHEAST',
0x04: 'SOUTH',
0x05: 'SOUTHWEST',
0x06: 'WEST',
0x07: 'NORTHWEST',
}

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

def to_string(self):
"""
Get the flow type as a string.
"""
flow = int(self.__val)
flags = flow & 0xF0
direction = flow & 0x0F
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):
"""
Get the displayed children of the flow type.
"""
flow = int(self.__val)
flags = flow & 0xF0
direction = flow & 0x0F
yield ('direction', self.FLOW_DIRECTION[direction])
for mask, flag in self.FLOW_FLAGS.items():
yield (flag, bool(flags & mask))


@printer_typedef('openage::path::integrated_flags_t')
class PathIntegrateFlagsTypePrinter:
"""
Pretty printer for openage::path::integrated_flags_t.
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

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])}"

def children(self):
"""
Get the displayed children of the integrate type.
"""
integrate = int(self.__val)
for mask, flag in self.INTEGRATED_FLAGS.items():
yield (flag, bool(integrate & mask))


# TODO: curve types
# TODO: coord types
# TODO: pathfinding types
Expand Down
1 change: 0 additions & 1 deletion libopenage/pathfinding/flow_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "log/log.h"

#include "coord/tile.h"
#include "pathfinding/definitions.h"
#include "pathfinding/integration_field.h"
#include "pathfinding/portal.h"

Expand Down
8 changes: 4 additions & 4 deletions libopenage/pathfinding/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ struct integrate_t {
/**
* Flow field cell value.
*
* Bit 0: Line of sight flag.
* Bit 1: Pathable flag.
* Bit 2: Wavefront blocked flag.
* Bit 3: Unused.
* Bit 0: Unused.
* Bit 1: Wave front blocked flag.
* Bit 2: Line of sight flag.
* Bit 3: Pathable flag.
* Bits 4-7: flow direction.
*/
using flow_t = uint8_t;
Expand Down

0 comments on commit 2d58d20

Please sign in to comment.