bzr branch
http://gegoxaren.bato24.eu/bzr/bitfield/trunk
3
by Gustav Hartvigsson
* It works. :-) |
1 |
BitField,
|
2 |
manage bit fields in vala without going insane. |
|
3 |
(c) Gustav Hartvigsson 2020 |
|
4 |
||
5
by Gustav Hartvigsson
* added main repo to README |
5 |
Main Reposetory: |
14
by Gustav Hartvigsson
* Added new project location. |
6 |
https://launchpad.net/bitfield |
5
by Gustav Hartvigsson
* added main repo to README |
7 |
|
3
by Gustav Hartvigsson
* It works. :-) |
8 |
|
9 |
CONCEPT:
|
|
10 |
||
11 |
The basic concept of a bitfield is to provide some kind of siple storrage of |
|
12 |
information, that should not take too much space. |
|
13 |
||
14 |
The basic way of doing this is using something like uint8 or uint16, |
|
15 |
which provides us with up to 8 and 16 fields respectivly, with the simplest |
|
16 |
field being 1 bit, up to the one-field type having the full 8bit (256 value) |
|
17 |
or 16bit (65535 values) to work with in one field. |
|
18 |
||
19 |
When defining a bitfiled type you need to consider what fields you need, how |
|
20 |
many values each feald sholud have and how they corrolate to your data. |
|
21 |
||
22 |
lets take the examlpe of a simple game map, where you have information like |
|
23 |
if a tile is travelsable or if only cetain types of units can move over them. |
|
24 |
||
25 |
If we have land units and water units, we could represet that with as little as |
|
26 |
2 bits: |
|
27 |
* 00 - Not traverable, |
|
28 |
* 01 - travelable by land units, |
|
29 |
* 10 - travelable by sea units. |
|
30 |
* 11 - traverable by both types of units. |
|
31 |
||
32 |
That means that we have 14 bits left if we use a 16 bit value, or 6 bits left |
|
33 |
if we use an 8 bit value. |
|
34 |
||
35 |
For the sake of argument, we are going to be using an 8 bit value in the |
|
36 |
example below. |
|
37 |
||
38 |
Tile [0][0][0][0][0][0][0][0] |
|
39 |
^--^ ^--^ ^--------^ |
|
40 |
trav Tile Tile |
|
41 |
Set Texture |
|
42 |
||
43 |
Legend:
|
|
44 |
* Trav - What sort of traversal is posible on the tile. |
|
45 |
* Tile Set - You four tile sets, you cound switch between them here. |
|
46 |
* Tile Texture - The specific tile texture in the tile set you want to have |
|
47 |
on this tile. |
|
48 |
||
49 |
Since each tile on the map is only one 8 bit value, instead of multi byte |
|
50 |
data structures, you will save on memory. |
|
51 |
||
52 |
The nivé solution would be to use a struct or each tile and have the information |
|
53 |
stored in seral bytes and store that in an array, but that would take up 3 times |
|
54 |
as much space, or more if you use other types. |
|
55 |
||
56 |
struct foo { |
|
57 |
uint8 traversable; |
|
58 |
uint8 tile_set; |
|
59 |
uint8 texture; |
|
60 |
} |
|
61 |
||
62 |
USAGE:
|
|
63 |
||
64 |
For basic usage see the example in main.vala. |
|
65 |
||
66 |
C HowTo: |
|
67 |
int main (int argc, char * argv[]) { |
|
68 |
// TODO |
|
69 |
} |
|
70 |