cleanup & debug-output
This commit is contained in:
parent
fc72fd8095
commit
eaeae7d4e2
@ -75,7 +75,7 @@ readHeader = do
|
|||||||
_ <- lift $ string (pack "INTERQUAKEMODEL\0")
|
_ <- lift $ string (pack "INTERQUAKEMODEL\0")
|
||||||
modify (+16)
|
modify (+16)
|
||||||
v <- w32leCParser
|
v <- w32leCParser
|
||||||
lift $ when (v /= 2) $ fail "Version /= 2.\nThis Parser only supports Version 2 of the InterQuake-Model IQM"
|
lift $ when (v /= 2) $ fail "Version /= 2.\nThis Parser only supports Version 2 of the InterQuake-Model IQM"
|
||||||
-- when v /= 2 then fail parsing.
|
-- when v /= 2 then fail parsing.
|
||||||
size' <- w32leCParser
|
size' <- w32leCParser
|
||||||
flags' <- w32leCParser
|
flags' <- w32leCParser
|
||||||
@ -207,24 +207,25 @@ skipToCounter a = do
|
|||||||
-- fills the Structure in a 2nd Pass from Offsets (O(memcpy'd bytes)).
|
-- fills the Structure in a 2nd Pass from Offsets (O(memcpy'd bytes)).
|
||||||
parseIQM :: String -> IO IQM
|
parseIQM :: String -> IO IQM
|
||||||
parseIQM a =
|
parseIQM a =
|
||||||
do
|
do
|
||||||
f <- B.readFile a
|
f <- B.readFile a
|
||||||
vao <- makeVAO (return ())
|
vao <- makeVAO (return ())
|
||||||
-- Parse Headers/Offsets
|
-- Parse Headers/Offsets
|
||||||
let result = parse (doIQMparse vao) f
|
let result = parse (doIQMparse vao) f
|
||||||
raw <- case result of
|
raw <- case result of
|
||||||
Done _ x -> return x
|
Done _ x -> return x
|
||||||
y -> error $ show y
|
y -> error $ show y
|
||||||
-- Fill Vertex-Arrays with data of Offsets
|
-- Fill Vertex-Arrays with data of Offsets
|
||||||
let va = vertexArrays raw
|
let va = vertexArrays raw
|
||||||
va' <- mapM (readInVAO f) va
|
va' <- mapM (readInVAO f) va
|
||||||
vbo <- sequence $ map toVBOfromVAO va
|
vbo <- mapM toVBOfromVAO va
|
||||||
withVAO vao $ createVAO (zip va' vbo)
|
withVAO vao $ createVAO (zip va' vbo)
|
||||||
return $ raw
|
print raw
|
||||||
{ vertexArrays = va'
|
return $ raw
|
||||||
|
{ vertexArrays = va'
|
||||||
, vertexBufferObjects = vbo
|
, vertexBufferObjects = vbo
|
||||||
, vertexArrayObject = vao
|
, vertexArrayObject = vao
|
||||||
}
|
}
|
||||||
|
|
||||||
createVAO :: [(IQMVertexArray, BufferObject)] -> IO ()
|
createVAO :: [(IQMVertexArray, BufferObject)] -> IO ()
|
||||||
createVAO bo = do
|
createVAO bo = do
|
||||||
@ -267,9 +268,9 @@ toBufferTargetfromVAType _ = ArrayBuffer
|
|||||||
-- Note: The String-Operations are O(1), so only O(numberOfCopiedBytes)
|
-- Note: The String-Operations are O(1), so only O(numberOfCopiedBytes)
|
||||||
-- is needed in term of computation.
|
-- is needed in term of computation.
|
||||||
readInVAO :: ByteString -> IQMVertexArray -> IO IQMVertexArray
|
readInVAO :: ByteString -> IQMVertexArray -> IO IQMVertexArray
|
||||||
readInVAO d (IQMVertexArray type' a format num offset ptr) =
|
readInVAO d (IQMVertexArray type' a format num offset ptr) =
|
||||||
do
|
do
|
||||||
let
|
let
|
||||||
byteLen = fromIntegral num * vaSize format
|
byteLen = fromIntegral num * vaSize format
|
||||||
data' = skipDrop (fromIntegral offset) byteLen d
|
data' = skipDrop (fromIntegral offset) byteLen d
|
||||||
|
|
||||||
@ -279,31 +280,31 @@ readInVAO d (IQMVertexArray type' a format num offset ptr) =
|
|||||||
putStrLn $ concat ["Filling with: ", show data', " starting at ", show offset]
|
putStrLn $ concat ["Filling with: ", show data', " starting at ", show offset]
|
||||||
unsafeUseAsCString data' (\s -> copyBytes p s byteLen)
|
unsafeUseAsCString data' (\s -> copyBytes p s byteLen)
|
||||||
return $ IQMVertexArray type' a format num offset $ castPtr p
|
return $ IQMVertexArray type' a format num offset $ castPtr p
|
||||||
|
|
||||||
-- | Real internal Parser.
|
-- | Real internal Parser.
|
||||||
--
|
--
|
||||||
-- Consumes the String only once, thus in O(n). But all Data-Structures are
|
-- 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.
|
-- not allocated and copied. readInVAO has to be called on each one.
|
||||||
doIQMparse :: VertexArrayObject -> Parser IQM
|
doIQMparse :: VertexArrayObject -> Parser IQM
|
||||||
doIQMparse vao =
|
doIQMparse vao =
|
||||||
flip evalStateT 0 $ --evaluate parser with state starting at 0
|
flip evalStateT 0 $ --evaluate parser with state starting at 0
|
||||||
do
|
do
|
||||||
h <- readHeader --read header
|
h <- readHeader --read header
|
||||||
skipToCounter $ ofs_text h --skip 0-n bytes to get to text
|
skipToCounter $ ofs_text h --skip 0-n bytes to get to text
|
||||||
text <- lift . take . fromIntegral $ num_text h --read texts
|
text <- lift . take . fromIntegral $ num_text h --read texts
|
||||||
modify . (+) . fromIntegral $ num_text h --put offset forward
|
modify . (+) . fromIntegral $ num_text h --put offset forward
|
||||||
skipToCounter $ ofs_meshes h --skip 0-n bytes to get to meshes
|
skipToCounter $ ofs_meshes h --skip 0-n bytes to get to meshes
|
||||||
meshes' <- readMeshes $ fromIntegral $ num_meshes h --read meshes
|
meshes' <- readMeshes $ fromIntegral $ num_meshes h --read meshes
|
||||||
skipToCounter $ ofs_vertexarrays h --skip 0-n bytes to get to Vertex-Arrays
|
skipToCounter $ ofs_vertexarrays h --skip 0-n bytes to get to Vertex-Arrays
|
||||||
vaf <- readVAFs $ fromIntegral $ num_vertexarrays h --read Vertex-Arrays
|
vaf <- readVAFs $ fromIntegral $ num_vertexarrays h --read Vertex-Arrays
|
||||||
return IQM
|
return IQM
|
||||||
{ header = h
|
{ header = h
|
||||||
, texts = filter (not.null) (split (unsafeCoerce '\0') text)
|
, texts = filter (not.null) (split (unsafeCoerce '\0') text)
|
||||||
, meshes = meshes'
|
, meshes = meshes'
|
||||||
, vertexArrays = vaf
|
, vertexArrays = vaf
|
||||||
, vertexBufferObjects = [] --initialized later, after vaf get allocated.
|
, vertexBufferObjects = [] --initialized later, after vaf get allocated.
|
||||||
, vertexArrayObject = vao
|
, vertexArrayObject = vao
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Helper-Function for Extracting a random substring out of a Bytestring
|
-- | Helper-Function for Extracting a random substring out of a Bytestring
|
||||||
-- by the Offsets provided.
|
-- by the Offsets provided.
|
||||||
@ -311,6 +312,6 @@ doIQMparse vao =
|
|||||||
-- O(1).
|
-- O(1).
|
||||||
skipDrop :: Int -- ^ Bytes to drop
|
skipDrop :: Int -- ^ Bytes to drop
|
||||||
-> Int -- ^ Bytes to take
|
-> Int -- ^ Bytes to take
|
||||||
-> ByteString
|
-> ByteString
|
||||||
-> ByteString
|
-> ByteString
|
||||||
skipDrop a b= B.take b . B.drop a
|
skipDrop a b= B.take b . B.drop a
|
||||||
|
Loading…
Reference in New Issue
Block a user