Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BlitzMax 15.05 KB | None | 0 0
  1. SuperStrict
  2. Framework sidesign.minib3d 'https://github.com/si-design/minib3d
  3.  
  4. Graphics3D(DesktopWidth() * 0.7, DesktopHeight() * 0.7, 2)
  5.  
  6. Local camera:TCamera = CreateCamera()
  7. MoveEntity(camera, 0, 0, -10)
  8.  
  9. AmbientLight(255, 255, 255)
  10.  
  11. Local testCube:TMesh = CreateCube()
  12.  
  13. Local myBSP:TQBSP = TQBSP.LoadFile("DM1.BSP")
  14.  
  15. 'Debug make a mesh
  16. Local mesh:TMesh = CreateMesh()
  17. Local surf:TSurface = CreateSurface(mesh, Null)
  18.  
  19. For Local m:TQModel = EachIn myBSP.Models
  20.     Local face:TQFace
  21.     For Local fNr:Int = m.Face_ID Until m.Face_ID + m.Face_Num
  22.         face = TQFace(myBSP.Faces.ValueAtIndex(fNr))
  23.         Print face.Ledge_ID
  24.     Next
  25. Next
  26.  
  27. While Not AppTerminate() And Not KeyDown(KEY_ESCAPE)
  28.     Cls()
  29.    
  30.     If KeyDown(KEY_LEFT) Then TurnEntity(camera, 0, 2, 0)
  31.     If KeyDown(KEY_RIGHT) Then TurnEntity(camera, 0, -2, 0)
  32.     If KeyDown(KEY_UP) Then TurnEntity(camera, -2, 0, 0)
  33.     If KeyDown(KEY_DOWN) Then TurnEntity(camera, 2, 0, 0)
  34.    
  35.     If KeyDown(KEY_W) Then MoveEntity(camera, 0, 0, 1.5)
  36.     If KeyDown(KEY_S) Then MoveEntity(camera, 0, 0, -1.5)
  37.     If KeyDown(KEY_A) Then MoveEntity(camera, -1.5, 0, 0)
  38.     If KeyDown(KEY_D) Then MoveEntity(camera, 1.5, 0, 0)
  39.    
  40.     If KeyDown(KEY_SPACE) Then MoveEntity(camera, 0, 1, 0)
  41.     If KeyDown(KEY_LCONTROL) Then MoveEntity(camera, 0, -1, 0)
  42.    
  43.     RenderWorld()
  44.     Flip(1)
  45. Wend
  46. End
  47.  
  48. Type TQBSP
  49.     Field File:String
  50.     Field Stream:TStream
  51.    
  52.     Field Header:TQHeader
  53.    
  54.     Field PLANES:TList = CreateList()
  55.     Field Vertices:TList = CreateList()
  56.     Field Nodes:TList = CreateList()
  57.     Field TexInfo:TList = CreateList()
  58.     Field Faces:TList = CreateList()
  59.     Field ClipNodes:TList = CreateList()
  60.     Field Leaves:TList = CreateList()
  61.     Field Edges:TList = CreateList()
  62.     Field Models:TList = CreateList()
  63.    
  64.     Function LoadFile:TQBSP(url:String)
  65.         Local nB:TQBSP = New TQBSP
  66.         nB.File = url
  67.        
  68.         If nB.Process() Then
  69.             Return nB
  70.         Else
  71.             nB.StreamError("Map ~q" + nB.file + "~q NOT loaded")
  72.             Return Null
  73.         EndIf
  74.     EndFunction
  75.    
  76.     Method StreamError(MSG:String)
  77.         If Stream Then CloseStream(Stream)
  78.         Print "Read error: " + MSG
  79.     EndMethod
  80.    
  81.     Method Process:Int()
  82.         Stream = OpenStream(File)
  83.         If Not Stream Then
  84.             StreamError("Unable to read file ~q" + file + "~q")
  85.             Return False
  86.         EndIf
  87.        
  88.         Local num:Int 'For counting stuff
  89.         Local i:Int 'For loops
  90.        
  91.         'Read header
  92.         Self.Header = TQHeader.Read(Stream)
  93.        
  94.         'Read planes
  95.         'num = Self.Header.PLANES.Count(TQPlane.Size())
  96.         'DebugLog "Planes: " + num
  97.         'Self.Header.PLANES.JumpTo(Stream)
  98.         'For i = 0 Until num
  99.         '   ListAddLast(Self.PLANES, TQPlane.Read(Stream))
  100.         'Next
  101.        
  102.         'Read vertices
  103.         num = Self.Header.Vertices.Count(TQVertex.Size())
  104.         DebugLog "Vertices: " + num
  105.         Self.Header.Vertices.JumpTo(Stream)
  106.         For i = 0 Until num
  107.             ListAddLast(Self.Vertices, TQVertex.Read(Stream))
  108.         Next
  109.        
  110.         'Read nodes
  111.         'num = Self.Header.Nodes.Count(TQNode.Size())
  112.         'DebugLog "Nodes: " + num
  113.         'Self.Header.Nodes.JumpTo(Stream)
  114.         'For i = 0 Until num
  115.         '   ListAddLast(Self.Nodes, TQNode.Read(Stream))
  116.         'Next
  117.        
  118.         'Read texture info
  119.         num = Self.Header.TexInfo.Count(TQSurface.Size())
  120.         DebugLog "TexInfos: " + num
  121.         Self.Header.TexInfo.JumpTo(Stream)
  122.         For i = 0 Until num
  123.             ListAddLast(Self.TexInfo, TQSurface.Read(Stream))
  124.         Next
  125.        
  126.         'Read faces
  127.         num = Self.Header.Faces.Count(TQFace.Size())
  128.         DebugLog "Faces: " + num
  129.         Self.Header.Faces.JumpTo(Stream)
  130.         For i = 0 Until num
  131.             ListAddLast(Self.Faces, TQFace.Read(Stream))
  132.         Next
  133.        
  134.         'Read clipnodes
  135.         'num = Self.Header.ClipNodes.Count(TQClipNode.Size())
  136.         'DebugLog "ClipNodes: " + num
  137.         'Self.Header.ClipNodes.JumpTo(Stream)
  138.         'For i = 0 Until num
  139.         '   ListAddLast(Self.ClipNodes, TQClipNode.Read(Stream))
  140.         'Next
  141.        
  142.         'Read leaves
  143.         'num = Self.Header.Leaves.Count(TQDLeaf.Size())
  144.         'DebugLog "Leaves: " + num
  145.         'Self.Header.Leaves.JumpTo(Stream)
  146.         'For i = 0 Until num
  147.         '   ListAddLast(Self.Leaves, TQDLeaf.Read(Stream))
  148.         'Next
  149.        
  150.         'Read edges
  151.         num = Self.Header.Edges.Count(TQEdge.Size())
  152.         DebugLog "Edges: " + num
  153.         Self.Header.Edges.JumpTo(Stream)
  154.         For i = 0 Until num
  155.             ListAddLast(Self.Edges, TQEdge.Read(Stream))
  156.         Next
  157.        
  158.         'Read models
  159.         num = Self.Header.Models.Count(TQModel.Size())
  160.         DebugLog "Models: " + num
  161.         Self.Header.Models.JumpTo(Stream)
  162.         For i = 0 Until num
  163.             ListAddLast(Self.Models, TQModel.Read(Stream))
  164.         Next
  165.        
  166.         CloseStream(Stream)
  167.         Return True
  168.     EndMethod
  169. EndType
  170.  
  171. 'http://www.gamers.org/dEngine/quake/spec/quake-spec34/qkspec_4.htm
  172. 'char 8bit = negative byte
  173. 'u_char 8bit = byte
  174. 'short 16bit = negative short
  175. 'u_short 16bit = short
  176. 'long 32bit = int
  177. 'u_long 32bit = longer int
  178. 'float 32bit = float
  179. 'scalar_t 32bit = float
  180.  
  181. Type TQHeader
  182.     Field Version:Int
  183.     Field Entities:TQEntry
  184.     Field PLANES:TQEntry
  185.     Field MipTex:TQEntry
  186.     Field Vertices:TQEntry
  187.     Field VisiList:TQEntry
  188.     Field Nodes:TQEntry
  189.     Field TexInfo:TQEntry
  190.     Field Faces:TQEntry
  191.     Field LightMaps:TQEntry
  192.     Field ClipNodes:TQEntry
  193.     Field Leaves:TQEntry
  194.     Field LFace:TQEntry
  195.     Field Edges:TQEntry
  196.     Field Ledges:TQEntry
  197.     Field Models:TQEntry
  198.    
  199.     Function Read:TQHeader(Stream:TStream)
  200.         Local nH:TQHeader = New TQHeader
  201.        
  202.         nH.Version = ReadCInt(Stream)
  203.         If nH.Version = "29" Then
  204.             Print "Correct BSP version (" + nH.Version + ")"
  205.         Else
  206.             Print "Warning: Wrong BSP version (" + nH.Version + ")"
  207.         EndIf
  208.        
  209.         nH.Entities = TQEntry.Read(Stream)
  210.         nH.PLANES = TQEntry.Read(Stream)
  211.        
  212.         nH.MipTex = TQEntry.Read(Stream)
  213.         nH.Vertices = TQEntry.Read(Stream)
  214.        
  215.         nH.VisiList = TQEntry.Read(Stream)
  216.         nH.Nodes = TQEntry.Read(Stream)
  217.        
  218.         nH.TexInfo = TQEntry.Read(Stream)
  219.        
  220.         nH.Faces = TQEntry.Read(Stream)
  221.        
  222.         nH.LightMaps = TQEntry.Read(Stream)
  223.         nH.ClipNodes = TQEntry.Read(Stream)
  224.        
  225.         nH.Leaves = TQEntry.Read(Stream)
  226.        
  227.         nH.LFace = TQEntry.Read(Stream)
  228.         nH.Edges = TQEntry.Read(Stream)
  229.        
  230.         nH.Ledges = TQEntry.Read(Stream)
  231.         nH.Models = TQEntry.Read(Stream)
  232.        
  233.         Return nH
  234.     EndFunction
  235. EndType
  236.  
  237. Type TQModel
  238.     Field Bound:TQBoundBox
  239.     Field Origin:TQVec3
  240.     Field Node_ID0:Int
  241.     Field Node_ID1:Int
  242.     Field Node_ID2:Int
  243.     Field Node_ID3:Int
  244.     Field NumLeafs:Int
  245.     Field Face_ID:Int
  246.     Field Face_Num:Int
  247.    
  248.     Function Read:TQModel(Stream:TStream)
  249.         Local nM:TQModel = New TQModel
  250.         nM.Bound = TQBoundBox.Read(Stream)
  251.         nM.Origin = TQVec3.Read(Stream)
  252.         nM.Node_ID0 = ReadCInt(Stream)
  253.         nM.Node_ID1 = ReadCInt(Stream)
  254.         nM.Node_ID2 = ReadCInt(Stream)
  255.         nM.Node_ID3 = ReadCInt(Stream)
  256.         nM.NumLeafs = ReadCInt(Stream)
  257.         nM.Face_ID = ReadCInt(Stream)
  258.         nM.Face_Num = ReadCInt(Stream)
  259.         Return nM
  260.     EndFunction
  261.    
  262.     Function Size:Int(C:Int = True)
  263.         If C Then
  264.             Return CSize([B_INT ,B_INT,B_INT,B_INT,B_INT,B_INT,B_INT, TQBoundBox.Size(), TQVec3.Size()])
  265.         Else
  266.             Return (B_INT * 7) + TQBoundBox.Size() + TQVec3.Size()
  267.         EndIf
  268.     EndFunction
  269. EndType
  270.  
  271. Type TQVertex
  272.     Field X:Float
  273.     Field Y:Float
  274.     Field Z:Float
  275.    
  276.     Function Read:TQVertex(Stream:TStream)
  277.         Local nV:TQVertex = New TQVertex
  278.         nV.Z = ReadCFloat(Stream)
  279.         nV.X = ReadCFloat(Stream)
  280.         nV.Y = ReadCFloat(Stream)
  281.        
  282.         Return nV
  283.     EndFunction
  284.    
  285.     Function Size:Int(C:Int = True)
  286.         If C Then
  287.             Return CSize([B_FLOAT, B_FLOAT, B_FLOAT])
  288.         Else
  289.             Return B_FLOAT * 3
  290.         EndIf
  291.     EndFunction
  292. EndType
  293.  
  294. Type TQSurface
  295.     Field VectorS:TQVec3
  296.     Field DistS:Float
  297.     Field VectorT:TQVec3
  298.     Field DistT:Float
  299.     Field Texture_ID:Int
  300.    
  301.     Field Animated:Int
  302.    
  303.     Function Read:TQSurface(Stream:TStream)
  304.         Local nS:TQSurface = New TQSurface
  305.         nS.VectorS = TQVec3.Read(Stream)
  306.         nS.DistS = ReadCFloat(Stream)
  307.         nS.VectorT = TQVec3.Read(Stream)
  308.         nS.DistT = ReadCFloat(Stream)
  309.         nS.Texture_ID = ReadCInt(Stream)
  310.         nS.Animated = ReadCInt(Stream)
  311.         Return nS
  312.     EndFunction
  313.    
  314.     Function Size:Int(C:Int = True)
  315.         If C Then
  316.             Return CSize([B_FLOAT, B_FLOAT, B_INT, B_INT, TQVec3.Size(), TQVec3.Size()])
  317.         Else
  318.             Return (B_FLOAT * 2) + (B_INT * 2) + (TQVec3.Size() * 2)
  319.         EndIf
  320.     EndFunction
  321. EndType
  322.  
  323. Type TQEdge
  324.     Field Vertex0:Short
  325.     Field Vertex1:Short
  326.    
  327.     Function Read:TQEdge(Stream:TStream)
  328.         Local nE:TQEdge = New TQEdge
  329.         nE.Vertex0 = ReadCShort(Stream)
  330.         nE.Vertex1 = ReadCShort(Stream)
  331.         Return nE
  332.     EndFunction
  333.    
  334.     Function Size:Int(C:Int = True)
  335.         If C Then
  336.             Return CSize([B_SHORT, B_SHORT])
  337.         Else
  338.             Return B_SHORT*2
  339.         EndIf
  340.     EndFunction
  341. EndType
  342.  
  343. Type TQFace
  344.     Field Plane_ID:Short
  345.    
  346.     Field Side:Short
  347.     Field Ledge_ID:Int
  348.    
  349.     Field Ledge_Num:Short
  350.     Field TexInfo_ID:Short
  351.    
  352.     Field TypeLight:Byte
  353.     Field BaseLight:Byte
  354.     Field Light:Byte[2]
  355.     Field LightMap:Int
  356.    
  357.     Function Read:TQFace(Stream:TStream)
  358.         Local nF:TQFace = New TQFace
  359.         nF.Plane_ID = ReadCShort(Stream)
  360.         nF.Side = ReadCShort(Stream)
  361.         nF.Ledge_ID = ReadCInt(Stream)
  362.         nF.Ledge_Num = ReadCShort(Stream)
  363.         nF.TexInfo_ID = ReadCShort(Stream)
  364.         nF.TypeLight = ReadCByte(Stream)
  365.         nF.BaseLight = ReadCByte(Stream)
  366.         nF.Light = ReadCByteArray(Stream, 2)
  367.         nF.LightMap = ReadCInt(Stream)
  368.         Return nF
  369.     EndFunction
  370.    
  371.     Function Size:Int(C:Int = True)
  372.         If C Then
  373.             Return CSize([B_SHORT, B_SHORT, B_SHORT, B_SHORT, B_INT, B_INT, B_BYTE, B_BYTE, B_BYTE, B_BYTE])
  374.         Else
  375.             Return (B_SHORT * 4) + (B_INT * 2) + (B_BYTE * 4)
  376.         EndIf
  377.     EndFunction
  378. EndType
  379.  
  380. Type TQMipHeader
  381.     Field NumTex:Int
  382.     Field Offset:Int[]
  383.    
  384.     Function Read:TQMipHeader(Stream:TStream)
  385.         Local nM:TQMipHeader = New TQMipHeader
  386.         nM.NumTex = ReadCInt(Stream)
  387.         nM.Offset = ReadCIntArray(Stream, nM.NumTex) 'Should I even read this?
  388.         Return nM
  389.     EndFunction
  390. EndType
  391.  
  392. Type TQMipTex
  393.     'Field Name:Byte[16]
  394.     Field Name:String
  395.     Field width:Int
  396.     Field Height:Int
  397.     Field Offset1:Int
  398.     Field Offset2:Int
  399.     Field Offset4:Int
  400.     Field Offset8:Int
  401.    
  402.     Function Read:TQMipTex(Stream:TStream)
  403.         Local nM:TQMipTex = New TQMipTex
  404.         nM.Name = ReadCString(Stream, 16)
  405.         nM.width = ReadCInt(Stream)
  406.         nM.Height = ReadCInt(Stream)
  407.         nM.Offset1 = ReadCInt(Stream)
  408.         nM.Offset2 = ReadCInt(Stream)
  409.         nM.Offset4 = ReadCInt(Stream)
  410.         nM.Offset8 = ReadCInt(Stream)
  411.         Return nM
  412.     EndFunction
  413.    
  414.     Function Size:Int()
  415.         Print "Not correct!"
  416.         Return (4 * 6) + (16)
  417.     EndFunction
  418. EndType
  419.  
  420. Type TQEntry
  421.     Field Offset:Int
  422.     Field Size:Int
  423.    
  424.     Function Read:TQEntry(Stream:TStream)
  425.         Local nE:TQEntry = New TQEntry
  426.         nE.Offset = ReadCInt(Stream)
  427.         nE.Size = ReadCInt(Stream)
  428.         Return nE
  429.     EndFunction
  430.    
  431.     Method Count:Int(typeSize:Int)
  432.         Return Size / typeSize
  433.     EndMethod
  434.    
  435.     Method JumpTo(Stream:TStream)
  436.         Stream.Seek(Self.Offset)
  437.     EndMethod
  438. EndType
  439.  
  440. Type TQNode
  441.     Field Plane_ID:Int
  442.    
  443.     Field Front:Short
  444.    
  445.     Field Back:Short
  446.    
  447.     Field Box:TQBBoxShort
  448.     Field Face_ID:Short
  449.     Field Face_Num:Short
  450.    
  451.     Function Read:TQNode(Stream:TStream)
  452.         Local nN:TQNode = New TQNode
  453.         nN.Plane_ID = ReadCInt(Stream)
  454.         nN.Front = ReadCShort(Stream)
  455.         nN.Back = ReadCShort(Stream)
  456.         nN.Box = TQBBoxShort.Read(Stream)
  457.         nN.Face_ID = ReadCShort(Stream)
  458.         nN.Face_Num = ReadCShort(Stream)
  459.         Return nN
  460.     EndFunction
  461.    
  462.     Function Size:Int()
  463.         Print "Not correct!"
  464.         Return (4) + (2 * 4) + TQBBoxShort.Size()
  465.     EndFunction
  466. EndType
  467.  
  468. Type TQDLeaf
  469.     Field Typ:Int
  470.     Field VisList:Int
  471.    
  472.     Field Bound:TQBBoxShort
  473.     Field LFace_ID:Short
  474.    
  475.     Field LFace_Num:Short
  476.     Field SndWater:Byte
  477.     Field SndSky:Byte
  478.     Field SndSlime:Byte
  479.     Field SndLava:Byte
  480.    
  481.     Function Read:TQDLeaf(Stream:TStream)
  482.         Local nD:TQDLeaf = New TQDLeaf
  483.         nD.Typ = ReadCInt(Stream)
  484.         nD.VisList = ReadCInt(Stream)
  485.        
  486.         nD.Bound = TQBBoxShort.Read(Stream)
  487.         nD.LFace_ID = ReadCShort(Stream)
  488.        
  489.         nD.LFace_Num = ReadCShort(Stream)
  490.         nD.SndWater = ReadCByte(Stream)
  491.         nD.SndSky = ReadCByte(Stream)
  492.         nD.SndSlime = ReadCByte(Stream)
  493.         nD.SndLava = ReadCByte(Stream)
  494.         Return nD
  495.     EndFunction
  496.    
  497.     Function Size:Int()
  498.         Print "Not correct!"
  499.         Return (4 * 2) + (2 * 2) + (4) + TQBBoxShort.Size()
  500.     EndFunction
  501. EndType
  502.  
  503. Type TQPlane
  504.     Field Normal:TQVec3
  505.    
  506.     Field Dist:Float
  507.    
  508.     Field Typ:Int
  509.    
  510.     Function Read:TQPlane(Stream:TStream)
  511.         Local nP:TQPlane = New TQPlane
  512.         nP.Normal = TQVec3.Read(Stream)
  513.         nP.Dist = ReadCFloat(Stream)
  514.         nP.Typ = ReadCInt(Stream)
  515.         Return nP
  516.     EndFunction
  517.    
  518.     Function Size:Int()
  519.         Print "Not correct!"
  520.         Return SizeOf(4 * 2) + TQVec3.Size()
  521.     EndFunction
  522. EndType
  523.  
  524. Type TQClipNode
  525.     Field PlaneNum:Int
  526.     Field Front:Short
  527.    
  528.     Field Back:Short
  529.    
  530.     Function Read:TQClipNode(Stream:TStream)
  531.         Local nC:TQClipNode = New TQClipNode
  532.         nC.PlaneNum = ReadCInt(Stream)
  533.         nC.Front = ReadCShort(Stream)
  534.         nC.Back = ReadCShort(Stream)
  535.         Return nC
  536.     EndFunction
  537.    
  538.     Function Size:Int()
  539.         Print "Not correct!"
  540.         Return SizeOf(TQClipNode)
  541.     EndFunction
  542. EndType
  543.  
  544. 'Basic types
  545. Type TQVec3
  546.     Field X:Float
  547.     Field Y:Float
  548.     Field Z:Float
  549.    
  550.     Function Read:TQVec3(Stream:TStream)
  551.         Local nV:TQVec3 = New TQVec3
  552.         nV.X = ReadCFloat(Stream)
  553.         nV.Y = ReadCFloat(Stream)
  554.         nV.Z = ReadCFloat(Stream)
  555.         Return nV
  556.     EndFunction
  557.    
  558.     Function Size:Int(C:Int = True)
  559.         If C Then
  560.             Return CSize([B_FLOAT, B_FLOAT, B_FLOAT])
  561.         Else
  562.             Return B_FLOAT * 3
  563.         EndIf
  564.     EndFunction
  565. EndType
  566.  
  567. Type TQBoundBox
  568.     Field Minimum:TQVec3
  569.     Field Maximum:TQVec3
  570.    
  571.     Function Read:TQBoundBox(Stream:TStream)
  572.         Local nB:TQBoundBox = New TQBoundBox
  573.         nB.Minimum = TQVec3.Read(Stream)
  574.         nB.Maximum = TQVec3.Read(Stream)
  575.         Return nB
  576.     EndFunction
  577.    
  578.     Function Size:Int(C:Int = True)
  579.         If C Then
  580.             Return CSize([TQVec3.Size(), TQVec3.Size()])
  581.         Else
  582.             Return TQVec3.Size() * 2
  583.         EndIf
  584.     EndFunction
  585. EndType
  586.  
  587. Type TQBBoxShort
  588.     Field Minimum:Short
  589.     Field Maximum:Short
  590.    
  591.     Function Read:TQBBoxShort(Stream:TStream)
  592.         Local nB:TQBBoxShort = New TQBBoxShort
  593.         nB.Minimum = ReadCShort(Stream)
  594.         nB.Maximum = ReadCShort(Stream)
  595.         Return nB
  596.     EndFunction
  597.    
  598.     Function Size:Int(C:Int = True)
  599.         If C Then
  600.             Return CSize([B_SHORT, B_SHORT])
  601.         Else
  602.             Return B_SHORT * 2
  603.         EndIf
  604.     EndFunction
  605. EndType
  606.  
  607. 'Reading padded C values
  608. Const B_BYTE:Int = 1
  609. Const B_SHORT:Int = 2
  610. Const B_INT:Int = 4
  611. Const B_FLOAT:Int = 4
  612.  
  613. Function ReadCByte:Byte(Stream:TStream)
  614.     Local result:Byte = ReadByte(Stream)
  615.     Stream.Seek(((StreamPos(Stream) + 3) / 4) * 4)
  616.     Return result
  617. EndFunction
  618.  
  619. Function ReadCShort:Short(Stream:TStream)
  620.     Local result:Short = ReadShort(Stream)
  621.     Stream.Seek(((StreamPos(Stream) + 3) / 4) * 4)
  622.     Return result
  623. EndFunction
  624.  
  625. Function ReadCInt:Int(Stream:TStream)
  626.     Return ReadInt(Stream)
  627. EndFunction
  628.  
  629. Function ReadCFloat:Int(Stream:TStream)
  630.     Return ReadFloat(Stream)
  631. EndFunction
  632.  
  633. Function ReadCByteArray:Byte[] (Stream:TStream, Length:Int)
  634.     Local result:Byte[Length]
  635.     For Local i:Int = 0 Until result.Length
  636.          result[i] = ReadByte(Stream)
  637.     Next
  638.     Stream.Seek(((StreamPos(Stream) + 3) / 4) * 4)
  639.     Return result
  640. EndFunction
  641.  
  642. Function ReadCIntArray:Int[] (Stream:TStream, Length:Int)
  643.     Local result:Int[Length]
  644.     For Local i:Int = 0 Until result.Length
  645.          result[i] = ReadInt(Stream)
  646.     Next
  647.     Stream.Seek(((StreamPos(Stream) + 3) / 4) * 4)
  648.     Return result
  649. EndFunction
  650.  
  651. Function ReadCString:String(Stream:TStream, Length:Int)
  652.     Local result:String
  653.     For Local i:Int = 0 Until Length
  654.          result:+ReadByte(Stream)
  655.     Next
  656.     Stream.Seek(((StreamPos(Stream) + 3) / 4) * 4)
  657.     Return result
  658. EndFunction
  659.  
  660. Function CSize:Int(val:Int[])
  661.     Local result:Int
  662.     For Local i:Int = 0 Until val.Length
  663.         result:+((val[i] + 3) / 4) * 4
  664.     Next
  665.     Return result
  666. EndFunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement