/bitfield/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/bitfield/trunk

« back to all changes in this revision

Viewing changes to README

  • Committer: Gustav Hartvigsson
  • Date: 2020-06-05 21:05:07 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20200605210507-cf47ohzmnet3ohc4
* encountered a bug in Valac:
https://gitlab.gnome.org/GNOME/vala/-/issues/1003

This makes it so I can't continue with this in any sane way.

Show diffs side-by-side

added added

removed removed

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