! Most of the comments are included from the original header
! for your convenience.
USING: accessors alien alien.c-types alien.destructors alien.libraries
-alien.syntax classes.struct combinators kernel math sequences
+alien.syntax classes.struct combinators kernel raylib.ffi.util sequences
sequences.private system vocabs ;
IN: raylib.ffi
FROM: alien.c-types => float ;
STRUCT: Mesh
{ vertexCount int } ! Number of vertices stored in arrays
{ triangleCount int } ! Number of triangles stored (indexed or not )
- { texcoords float* } ! Vertex texture coordinates (UV - 2 components per vertex )
- { vertices float* } ! Vertex position (XYZ - 3 components per vertex)
+ { _vertices float* } ! Vertex position (XYZ - 3 components per vertex)
+ { _texcoords float* } ! Vertex texture coordinates (UV - 2 components per vertex )
{ texcoords2 float* } ! Vertex second texture coordinates (useful for lightmaps)
- { normals float* } ! Vertex normals (XYZ - 3 components per vertex)
+ { _normals float* } ! Vertex normals (XYZ - 3 components per vertex)
{ tangents float* } ! Vertex tangents (XYZW - 4 components per vertex )
{ colors uchar* } ! Vertex colors (RGBA - 4 components per vertex)
{ indices ushort* } ! Vertex indices (in case vertex data comes indexed)
{ vaoId uint } ! OpenGL Vertex Array Object id
{ vboId uint* } ; ! OpenGL Vertex Buffer Objects id (7 types of vertex data)
+ARRAY-SLOT: Mesh Vector3 _vertices [ vertexCount>> ] vertices
+ARRAY-SLOT: Mesh Vector2 _texcoords [ vertexCount>> ] texcoords
+ARRAY-SLOT: Mesh Vector3 _normals [ vertexCount>> ] normals
STRUCT: Shader
{ id uint } ! Shader program id
{ color Color } ! Material map color
{ value float } ; ! Material map value
+CONSTANT: MAX_MATERIAL_MAPS 12 ! NOTE: This seems to be a compile-time constant!
STRUCT: Material
{ shader Shader } ! Material shader
- { maps MaterialMap* } ! Material maps. Uses MAX_MATERIAL_MAPS.
+ { _maps MaterialMap* } ! Material maps. Uses MAX_MATERIAL_MAPS.
{ params float* } ; ! Material generic parameters (if required)
+ARRAY-SLOT: Material MaterialMap _maps [ drop 12 ] maps
STRUCT: Transform
{ translation Vector3 }
{ transform Matrix }
{ meshCount int }
{ materialCount int }
- { meshes Mesh* }
- { materials Material* }
+ { _meshes Mesh* }
+ { _materials Material* }
{ meshMaterial int* }
{ boneCount int }
- { bones BoneInfo* }
+ { _bones BoneInfo* }
{ bindPose Transform* } ;
+ARRAY-SLOT: Model Material _materials [ materialCount>> ] materials
+ARRAY-SLOT: Model Mesh _meshes [ meshCount>> ] meshes
+ARRAY-SLOT: Model BoneInfo _bones [ boneCount>> ] bones
+
STRUCT: ModelAnimation
{ boneCount int }
- { bones BoneInfo* }
+ { _bones BoneInfo* }
{ frameCount int }
{ framePoses Transform** } ;
+ARRAY-SLOT: ModelAnimation BoneInfo _bones [ boneCount>> ] bones
STRUCT: Ray
{ position Vector3 } ! Ray position (origin)
--- /dev/null
+USING: accessors alien alien.parser classes generic kernel lexer parser
+quotations sequences slots specialized-arrays specialized-arrays.private
+vocabs.parser words ;
+
+IN: raylib.ffi.util
+
+: array-word ( c-type -- str )
+ name>> "-array" append parse-word ;
+
+: array-direct-like ( c-type -- quot: ( alien len -- array ) )
+ array-word "prototype" word-prop '[ _ direct-like ] ;
+
+: ?use-vocab ( vocab -- )
+ dup using-vocab? [ drop ] [ use-vocab ] if ;
+
+: use-specialized-array ( c-type -- direct-constructor )
+ [ define-array-vocab ?use-vocab ]
+ [ array-direct-like ] bi ;
+
+! TODO: setter?
+
+:: define-array-slot ( struct-class element-type pointer-slot length-quot accessor -- )
+ element-type use-specialized-array :> cons-quot
+ accessor [ define-protocol-slot ] [ reader-word ] bi :> reader
+ struct-class reader create-method :> reader-method
+ pointer-slot reader-word 1quotation length-quot cons-quot
+ '[ [ @ >c-ptr ] _ bi @ ] reader-method swap define ;
+
+! ARRAY-SLOT: struct-class element-type-class pointer-slot length-quotation new-accessor
+SYNTAX: ARRAY-SLOT: scan-class scan-c-type scan-token scan-object quotation check-instance scan-token define-array-slot ;