Comments (2)
Proposal:
give members a Bitfield
class from a dict
bitfield repr can show each member, bitfield members can be accessed by name as top level class members
MappedArray
:
class FirstExample(base.MappedArray):
_mapping = ["member", "bitfield"]
_format = "hi"
_bitfields = {"bitfield": [("a", 8), ("b", 16), ("c", 8)]}
struct FirstExample {
uint16_t member;
uint32_t a: 8, b: 16, c: 8;
}
Struct
:
class SecondExample(base.Struct):
__slots__ = ["member", "child"]
_format = "2hi"
_arrays = {"child": ["member", "bitfield"]}
_bitfields = {"child.bitfield": [("a", 8), ("b", 16), ("c", 8)]}
# if "." in _bitfields_key, add _bitfields to child
# else _bitfields_key = Bitfield(...)
struct SecondExample {
uint16_t member;
struct {
uint16_t member;
uint32_t a: 8, b: 16, c: 8;
} child;
};
Use:
>>> fe = FirstExample.frombytes(b"\x11\x11\xCC\xBB\xBB\xAA")
>>> fe.bitfield
<Bitfield (a: 0xAA, b: 0xBBBB, c: 0xCC)>
>>> fe.a
0xAA
All of this will require some checks (or at least tests w/ warnings):
- Fields to cover the whole bitfield type (need to match struct type char to bitfield)
- Bitfield must know it's type to create a inverted mask
- in
@b.setter
:bitfield = b << 8 | bitfield & (2 ** 32 - 1 ^ (2 ** 8 - 1) << 8)
could probably build a mask dict in__init__
...
number of calculations per lookup should be minimal, so calculate constants in__init__
- in
We'll also be overlapping with other planned MappedArray
& Struct
features:
- subclasses (e.g.
DisplacementNeighbour(base.Struct)
or_subclasses = {"origin": vec3}
) - C struct conversion / repr (be sure to use stdint)
- unpacking
_format
& matching each member to a type (part of C conversion)
If the BitField
class handles all the getting & setting, the LumpClass can just access the bitfield members
from bsp_tool.
commit 810cb7e introduces this feature
from bsp_tool.
Related Issues (20)
- `RespawnBsp.save_as` dumps `.bsp_lump` copies in working directory HOT 1
- `RespawnBsp.save_as()` test cases HOT 1
- Quake II Rerelease increased lightmap resolution HOT 2
- Usage of ContentsMask in source.py HOT 3
- Need integer vectors to preserve accuracy
- (extensions.convert.respawn) r1 -> r2 for `.ain` generation HOT 2
- (MegaTest) download & catalogue dukeworld maps
- Standardising geometry extraction & processing HOT 9
- extensions should add new methods to branches HOT 2
- how use x360.py? HOT 9
- Consider `sprp` version part of "branch id"
- Split related files handler out of `BspClass._preload`
- cannot load CS:O2 `aim_dust.bsp` with `nexon.cso2_2018` HOT 1
- Catalogue Genesis3D Engine HOT 1
- Need a common Image LumpClass base type
- [Test Maps] `genesis3d`
- Configure `pytest` to remove naming convention HOT 2
- Create a `utils` submodule to pull tools out of `branches` HOT 1
- (extensions.editor) `.save_as(filename: str)` method for all `MapFile` classes
- (extensions.editor) MetaPattern string conversion is an ugly mess
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bsp_tool.