diff --git a/src/Importer/IQM/Parser.hs b/src/Importer/IQM/Parser.hs index 0295516..1d5b9fe 100644 --- a/src/Importer/IQM/Parser.hs +++ b/src/Importer/IQM/Parser.hs @@ -196,6 +196,9 @@ skipToCounter a = do put d -- | Parses an IQM-File and handles back the Haskell-Structure +-- +-- Does a 2-Pass-Parsing. Reads in Structure on first pass (O(n))and +-- fills the Structure in a 2nd Pass from Offsets (O(memcpy'd bytes)). parseIQM :: String -> IO IQM parseIQM a = do @@ -212,6 +215,11 @@ parseIQM a = vertexArrays = va' } +-- | Allocates memory for the Vertex-data and copies it over there +-- from the given input-String +-- +-- Note: The String-Operations are O(1), so only O(numberOfCopiedBytes) +-- is needed in term of computation. readInVAO :: ByteString -> IQMVertexArray -> IO IQMVertexArray readInVAO d (IQMVertexArray type' a format num offset ptr) = do @@ -225,6 +233,10 @@ readInVAO d (IQMVertexArray type' a format num offset ptr) = unsafeUseAsCString data' (\s -> copyBytes p s byteLen) return $ IQMVertexArray type' a format num offset $ castPtr p +-- | Real internal Parser. +-- +-- Consumes the String only once, thus in O(n). But all Data-Structures are +-- not allocated and copied. readInVAO has to be called on each one. doIQMparse :: Parser IQM doIQMparse = flip evalStateT 0 $ --evaluate parser with state starting at 0 @@ -244,5 +256,9 @@ doIQMparse = , vertexArrays = vaf } +-- | Helper-Function for Extracting a random substring out of a Bytestring +-- by the Offsets provided. +-- +-- O(1). skipDrop :: Int -> Int -> ByteString -> ByteString skipDrop a b= B.drop b . B.take a diff --git a/src/Importer/IQM/Types.hs b/src/Importer/IQM/Types.hs index 01ec020..847320f 100644 --- a/src/Importer/IQM/Types.hs +++ b/src/Importer/IQM/Types.hs @@ -20,10 +20,19 @@ newtype Mesh = Mesh Word32 deriving (Show, Eq) -- Bytes read for offset-gap reasons type CParser a = StateT Int64 Parser a +-- | Alias type Flags = GLbitfield -- ^ Alias for UInt32 + +-- | Alias type Offset = Word32 -- ^ Alias for UInt32 + +-- | Alias type Index = GLuint -- ^ Alias for UInt32 + +-- | Alias type NumComponents = GLsizei -- ^ Alias for UInt32 + +-- | Data-BLOB inside IQM type IQMData = Ptr IQMVertexArrayFormat -- ^ Pointer for Data -- | Header of IQM-Format. @@ -104,7 +113,6 @@ data IQM = IQM -- | Different Vertex-Array-Types in IQM -- -- Custom Types have to be > 0x10 as of specification - data IQMVertexArrayType = IQMPosition | IQMTexCoord | IQMNormal @@ -116,7 +124,6 @@ data IQMVertexArrayType = IQMPosition deriving (Show, Eq) -- | Lookup-Function for internal enum to VertexArrayFormat - rawEnumToVAT :: Word32 -> CParser IQMVertexArrayType rawEnumToVAT 0 = return IQMPosition rawEnumToVAT 1 = return IQMTexCoord @@ -140,6 +147,7 @@ data IQMVertexArrayFormat = IQMbyte -- | Unknown Word32 deriving (Show, Eq) +-- | Get the Size (in Bytes) of the given IQMVertexArrayFormat-Struct vaSize :: IQMVertexArrayFormat -> Int vaSize IQMbyte = sizeOf (undefined :: CSChar) vaSize IQMubyte = sizeOf (undefined :: CUChar) @@ -156,7 +164,6 @@ vaSize IQMdouble = sizeOf (undefined :: CDouble) --mallocVArray IQMubyte n = mallocArray n :: IO (Ptr CUChar) -- | Lookup-Function for internal enum to VertexArrayFormat - rawEnumToVAF :: Word32 -> CParser IQMVertexArrayFormat rawEnumToVAF 0 = return IQMbyte rawEnumToVAF 1 = return IQMubyte