88-----
99
1010Snow-Data is a simple gem for dealing with memory and defining structs in a
11- C-like way. Incidentally, it's also hideously unsafe, so everything is tainted
12- by default. You'll thank me for this later, even if almost every operation does
13- bounds-checking where possible to ensure you're not being a horrible person.
11+ C-like way. It's also hideously unsafe, so everything is tainted by default.
1412
1513For more information on usage, see the rdoc documentation for Snow::Memory
16- and Snow::CStruct, as it explains the important things. Like CStructs. And how
17- to talk to people. Ok, it can't help you with that.
18-
19- _ ALLONS-Y!_
20-
14+ and Snow::CStruct, as it should explain most of the important things.
2115
2216Example
2317-------
2418
25- For those wanting a quick-ish example of using snow-data, I'll include one here
26- showing you how you might define a few structs, including a Vec3, Vec2, Color,
27- and Vertex and working with those .
19+ For those wanting a quick-ish example of using snow-data, the following example
20+ shows how to define a few structs. These are a Vec3, Vec2, Color, and Vertex ,
21+ which may be common in game code .
2822
29- Bear in mind that, down the road, it will also be possible to assign snow-math
30- types to these as well (provided they use the same underlying types), though I
31- wouldn't use this for defining data types for anything other than transit to
32- another API that expects its data in a format like this.
33-
34- How you use it, ultimately, is really up to you.
23+ In practice, this tends not to be highly useful except for interacting with
24+ some APIs over FFI, such as OpenGL. That said, if it happens to be useful,
25+ all the better.
3526
3627 #!/usr/bin/env ruby -w
3728
@@ -42,11 +33,12 @@ How you use it, ultimately, is really up to you.
4233 # it helps to illustrate that you can specify alignment).
4334 Vec3 = Snow::CStruct[:Vec3, 'x: float :4; y: float :4; z: float :4']
4435 Vec2 = Snow::CStruct[:Vec2, 'x: float :4; y: float :4']
36+
4537 # ui8 is shorthand for uint8_t -- you can write either, and the documentation
4638 # for CStruct::new explains the short- and long-form names for each primitive
4739 # type provided by Snow-Data. Further, CStructs defined with a name, as with
4840 # Vec3, Vec2, and Color, have getters and setters defined in the Memory class
49- # and are usable as member types, as I'll show below.
41+ # and are usable as member types (see below) .
5042 Color = Snow::CStruct[:Color, 'r: ui8; g: ui8; b: ui8; a: ui8']
5143
5244 # Define a vertex type whose members are all also 4-byte aligned. The vertex
@@ -69,7 +61,7 @@ How you use it, ultimately, is really up to you.
6961 VERTEX_DESCRIPTION
7062 end
7163
72- # So let's create a vertex.
64+ # Now create a vertex:
7365 a_vertex = Vertex.new { |v|
7466 v.position = Vec3.new { |p| p.x = 1; p.y = 2; p.z = 3 }
7567 v.normal = Vec3.new { |n| n.x = 0.707107; n.y = 0; n.z = 0.707107 }
@@ -83,7 +75,7 @@ How you use it, ultimately, is really up to you.
8375
8476 puts "Our vertex:\n#{stringify_vertex a_vertex}"
8577
86- # For kicks, let's create an array.
78+ # Create an array of 64 vertices:
8779 some_vertices = Vertex[64]
8880
8981 # And set all vertices to the above vertex.
0 commit comments