snake-biscuits / bsp_tool

Python library for analysing .bsp files
GNU General Public License v3.0
102 stars 8 forks source link

BitField order is backwards, should be the same as C/C++ #171

Closed snake-biscuits closed 3 months ago

snake-biscuits commented 7 months ago
class Float32(base.BitField):
    _fields = {"fraction": 23, "exponent": 8, "sign": 1}
    _format = "I"

sign should come first

Need to document this better too, & make a C/C++ program to confirm the order

Will need to update tests & all subclasses of BitField

BitFields in correct order

BasicLumpClasses

snake-biscuits commented 7 months ago
>>> {lc
...  for b in bsp_tool.branches.quake_based
...  for lc in b.BASIC_LUMP_CLASSES.values()
...  if issubclass(lc, bsp_tool.branches.base.BitField)}
set()
>>> {lc
...  for b in bsp_tool.branches.source_based
...  for vd in b.BASIC_LUMP_CLASSES.values()
...  for lc in vd.values()
...  if issubclass(lc, bsp_tool.branches.base.BitField)}
{bsp_tool.branches.respawn.titanfall.BrushSideProperty,
 bsp_tool.branches.respawn.titanfall.Primitive,
 bsp_tool.branches.respawn.titanfall.TricollTriangle}
>>> {lc
...  for b in bsp_tool.branches.quake_based
...  for lc in b.LUMP_CLASSES.values()
...  if len(getattr(lc, "_bitfields", [])) != 0}
set()
>>> {lc
...  for b in bsp_tool.branches.source_based
...  for vd in b.LUMP_CLASSES.values()
...  for lc in vd.values()
...  if len(getattr(lc, "_bitfields", [])) != 0}
{bsp_tool.branches.nexon.vindictus69.Face,
  bsp_tool.branches.nexon.vindictus69.Facev2,
  bsp_tool.branches.nexon.vindictus69.Overlay,
  bsp_tool.branches.respawn.apex_legends.BVHNode,
  bsp_tool.branches.respawn.apex_legends.CellAABBNode,
  bsp_tool.branches.respawn.titanfall.GeoSet,
  bsp_tool.branches.respawn.titanfall2.GeoSet,
  bsp_tool.branches.strata.strata.Face,
  bsp_tool.branches.strata.strata.Leaf,
  bsp_tool.branches.valve.orange_box.Leaf,
  bsp_tool.branches.valve.source.Face,
  bsp_tool.branches.valve.source.Leaf,
  bsp_tool.branches.x360.Face_x360,
  bsp_tool.branches.x360.Face_x360,
  bsp_tool.branches.x360.GeoSet_x360,
  bsp_tool.branches.x360.Leaf_x360,
  bsp_tool.branches.x360.Leaf_x360}
snake-biscuits commented 7 months ago
>>> {lc: [*lc._bitfields.keys()] for lc in slcs}  # slcs is source LUMP_CLASSES w/ bitfields - x360
{bsp_tool.branches.nexon.vindictus69.Overlay: ['bitfield'],
 bsp_tool.branches.respawn.titanfall.GeoSet: ['primitive'],
 bsp_tool.branches.strata.strata.Face: ['primitives'],
 bsp_tool.branches.respawn.apex_legends.CellAABBNode: ['children'],
 bsp_tool.branches.nexon.vindictus69.Face: ['primitives'],
 bsp_tool.branches.nexon.vindictus69.Facev2: ['primitives'],
 bsp_tool.branches.valve.orange_box.Leaf: ['area_flags'],
 bsp_tool.branches.strata.strata.Leaf: ['bitfield'],
 bsp_tool.branches.valve.source.Face: ['primitives'],
 bsp_tool.branches.valve.source.Leaf: ['bitfield'],
 bsp_tool.branches.respawn.titanfall2.GeoSet: ['child'],
 bsp_tool.branches.respawn.apex_legends.BVHNode: [
  'index.child0', 'index.child1', 'index.child2', 'index.child3']}
snake-biscuits commented 3 months ago

for Leaf.bitfield I'm keeping the area, flags order from the C/C++ implementation also renamed valve.orange_box.Leaf.area_flags to bitfield for consistency