December 03, 2020, 08:59:26 PM

Author Topic: [bb] Non-Type Based Vector Lib by Jonathan Nguyen [ 1+ years ago ]  (Read 729 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Non-Type Based Vector Lib
Author : Jonathan Nguyen
Posted : 1+ years ago

Description : Basically instead of having to deal with type declarations (ie. the myVector.Vector) you can use handles to banks instead (ie. just myVector). I've written it with some basis on "temporary" vectors which are deleted automatically when used in a non-value-returning vector function. This is primarily for when you want to add a vector with another arbitrary vector but you don't want to actually create another vector (or subtract, dot product, cross, whatever). So instead of:

myVector1=CreateVector(1,2,3)
myVector2=CreateVector(2,3,4)
myVector3=CreateVector(3,4,5)
AddVectors(myVector1,myVector2)
myVector4=CrossProduct(myVector1,myVector3)
UnitVector(myVector4)
myVector5=CreateVector()
CopyVector(myVector5,myVector4)

It would simplify to something like this:

myVector5=CreateVector()
CopyVector(myVector5,TUnitVector(TCrossProduct(TAddVectors(TVector(1,2,3),TVector(2,3,4)),TVector(3,4,5))))

So that's that. I've also added functions to find the pitch and yaw of a vector, two methods of finding the angle between two vectors, and all three projections.


Code :
Code: BlitzBasic
  1. ; /////////////////////////////////// VECTORS
  2.  
  3.  
  4.  
  5. ; // Create Vector
  6. ;    Action: Creates a vector.
  7. ;    Return: Vector handle of the new vector.
  8. Function CreateVector(x#=0,y#=0,z#=0)
  9.         Local vectorBank=CreateBank(13)
  10.                 PokeFloat vectorBank,0,x#
  11.                 PokeFloat vectorBank,4,y#
  12.                 PokeFloat vectorBank,8,z#
  13.                 PokeByte vectorBank,12,0
  14.         Return vectorBank
  15. End Function
  16.  
  17. ; // Temporary Vector
  18. ;    Action: Creates a temporary vector.
  19. ;    Return: Vector handle of the new vector.
  20. ;    Notes: Deleted automatically when used in a non-data-returning vector function.
  21. Function TVector(x#=0,y#=0,z#=0)
  22.         Local vectorBank=CreateBank(13)
  23.                 PokeFloat vectorBank,0,x#
  24.                 PokeFloat vectorBank,4,y#
  25.                 PokeFloat vectorBank,8,z#
  26.                 PokeByte vectorBank,12,1
  27.         Return vectorBank
  28. End Function
  29.  
  30. ; // Free Vector
  31. ;    Action: Deletes a vector.
  32. ;    Return: True if successful, False if failed.
  33. Function FreeVector(vectorBank)
  34.         If vectorBank=0
  35.                 Return False
  36.                 Else
  37.                 FreeBank vectorBank
  38.                 Return True
  39.         EndIf
  40. End Function
  41.  
  42. ; // Copy Vector
  43. ;    Action: Copies the components of Vector 2 onto Vector 1.
  44. ;    Return: True if successful, False if failed.
  45. Function CopyVector(vector1Bank,vector2Bank)
  46.         If vector1Bank=0 Or vector2Bank=0
  47.                 Return False
  48.                 Else
  49.                 PokeFloat vector1Bank,0,PeekFloat#(vector2Bank,0)
  50.                 PokeFloat vector1Bank,4,PeekFloat#(vector2Bank,4)
  51.                 PokeFloat vector1Bank,8,PeekFloat#(vector2Bank,8)
  52.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  53.                 Return True
  54.         EndIf
  55. End Function
  56.  
  57. ; // Set Vector
  58. ;    Action: Set's a vector's components.
  59. ;    Return: True if successful, False if failed.
  60. Function SetVector(vectorBank,x#=0,y#=0,z#=0)
  61.         If vectorBank=0
  62.                 Return False
  63.                 Else
  64.                 PokeFloat vectorBank,0,x#
  65.                 PokeFloat vectorBank,4,y#
  66.                 PokeFloat vectorBank,8,z#
  67.                 Return True
  68.         EndIf
  69. End Function
  70.  
  71. ; // Set Vector X
  72. ;    Action: Sets the X component of a vector.
  73. ;    Return: Nothing.
  74. Function SetVectorX#(vectorBank,tX#)
  75.         PokeFloat vectorBank,0,tX#
  76. End Function
  77.  
  78. ; // Set Vector Y
  79. ;    Action: Sets the Y component of a vector.
  80. ;    Return: Nothing.
  81. Function SetVectorY#(vectorBank,tY#)
  82.         PokeFloat vectorBank,4,tY#
  83. End Function
  84.  
  85. ; // Set Vector Z
  86. ;    Action: Sets the Z component of a vector.
  87. ;    Return: Nothing.
  88. Function SetVectorZ#(vectorBank,tZ#)
  89.         PokeFloat vectorBank,8,tZ#
  90. End Function
  91.  
  92. ; // Vector X
  93. ;    Action: Returns the X component of a vector.
  94. ;    Return: The X component of a vector.
  95. Function VectorX#(vectorBank)
  96.         Return PeekFloat#(vectorBank,0)
  97. End Function
  98.  
  99. ; // Vector Y
  100. ;    Action: Returns the Y component of a vector.
  101. ;    Return: The Y component of a vector.
  102. Function VectorY#(vectorBank)
  103.         Return PeekFloat#(vectorBank,4)
  104. End Function
  105.  
  106. ; // Vector Z
  107. ;    Action: Returns the Z component of a vector.
  108. ;    Return: The Z component of a vector.
  109. Function VectorZ#(vectorBank)
  110.         Return PeekFloat#(vectorBank,8)
  111. End Function
  112.  
  113. ; // Vector AX
  114. ;    Action: Returns the "pitch" of a vector in Blitz3D space.
  115. ;    Return: The "pitch" of a vector in Blitz3D space.
  116. Function VectorAX#(vectorBank)
  117.         Return ATan2(Sqr#(PeekFloat#(vectorBank,0)^2+PeekFloat#(vectorBank,8)^2),PeekFloat#(vectorBank,4))-90
  118. End Function
  119.  
  120. ; // Vector AY
  121. ;    Action: Returns the "yaw" of a vector in Blitz3D space.
  122. ;    Return: The "yaw" of a vector in Blitz3D space.
  123. Function VectorAY#(vectorBank)
  124.         Return ATan2(-PeekFloat#(vectorBank,0),PeekFloat#(vectorBank,8))
  125. End Function
  126.  
  127. ; // Vector Magnitude
  128. ;    Action: Returns the magnitude of a vector.
  129. ;    Return: The magnitude of a vector, 0 if failed.
  130. Function VectorMagnitude#(vectorBank)
  131.         If vectorBank=0
  132.                 Return 0
  133.                 Else
  134.                 Return Sqr#(PeekFloat#(vectorBank,0)^2+PeekFloat#(vectorBank,4)^2+PeekFloat#(vectorBank,8)^2)
  135.         EndIf
  136. End Function
  137.  
  138. ; // Add Vectors
  139. ;    Action: Vector 1 = Vector 1 + Vector 2
  140. ;    Return: True if successful, False if failed.
  141. ;    Notes: Directly writes the result onto Vector 1.
  142. Function AddVectors(vector1Bank,vector2Bank)
  143.         If vector1Bank=0 Or vector2Bank=0
  144.                 Return False
  145.                 Else
  146.                 PokeFloat vector1Bank,0,PeekFloat#(vector1Bank,0)+PeekFloat#(vector2Bank,0)
  147.                 PokeFloat vector1Bank,4,PeekFloat#(vector1Bank,4)+PeekFloat#(vector2Bank,4)
  148.                 PokeFloat vector1Bank,8,PeekFloat#(vector1Bank,8)+PeekFloat#(vector2Bank,8)
  149.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  150.                 Return True
  151.         EndIf
  152. End Function
  153.  
  154. ; // Subtract Vectors
  155. ;    Action: Vector 1 = Vector 1 - Vector 2
  156. ;    Return: True if successful, False if failed.
  157. ;    Note: Directly writes the result onto Vector 1.
  158. Function SubtractVectors(vector1Bank,vector2Bank)
  159.         If vector1Bank=0 Or vector2Bank=0
  160.                 Return False
  161.                 Else
  162.                 PokeFloat vector1Bank,0,PeekFloat#(vector1Bank,0)-PeekFloat#(vector2Bank,0)
  163.                 PokeFloat vector1Bank,4,PeekFloat#(vector1Bank,4)-PeekFloat#(vector2Bank,4)
  164.                 PokeFloat vector1Bank,8,PeekFloat#(vector1Bank,8)-PeekFloat#(vector2Bank,8)
  165.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  166.                 Return True
  167.         EndIf
  168. End Function
  169.  
  170. ; // Temporary Add Vectors
  171. ;    Action: Adds Vector 1 and Vector 2 and returns the handle of the new resultant vector.
  172. ;    Return: Vector handle of the resultant vector.
  173. ;    Notes: Deleted automatically when used in a non-data-returning vector function.
  174. Function TAddVectors(vector1Bank,vector2Bank)
  175.         If vector1Bank=0 Or vector2Bank=0
  176.                 Return 0
  177.                 Else
  178.                 tBank=TVector(PeekFloat#(vector1Bank,0)+PeekFloat#(vector2Bank,0),PeekFloat#(vector1Bank,4)+PeekFloat#(vector2Bank,4),PeekFloat#(vector1Bank,8)+PeekFloat#(vector2Bank,8))
  179.                 If PeekByte(vector1Bank,12)=1 Then FreeBank vector1Bank
  180.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  181.                 Return tBank
  182.         EndIf
  183. End Function
  184.  
  185. ; // Temporary Subtract Vectors
  186. ;    Action: Subtracts Vector 2 from Vector 1 and returns the handle of the new resultant vector.
  187. ;    Return: Vector handle of the resultant vector.
  188. ;    Notes: Deleted automatically when used in a non-data-returning vector function.
  189. Function TSubtractVectors(vector1Bank,vector2Bank)
  190.         If vector1Bank=0 Or vector2Bank=0
  191.                 Return 0
  192.                 Else
  193.                 tBank=TVector(PeekFloat#(vector1Bank,0)-PeekFloat#(vector2Bank,0),PeekFloat#(vector1Bank,4)-PeekFloat#(vector2Bank,4),PeekFloat#(vector1Bank,8)-PeekFloat#(vector2Bank,8))
  194.                 If PeekByte(vector1Bank,12)=1 Then FreeBank vector1Bank
  195.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  196.                 Return tBank
  197.         EndIf
  198. End Function
  199.  
  200. ; // Scale Vector
  201. ;    Action: Scales a vector by the second parameter.
  202. ;    Return: True if successful, False if failed.
  203. Function ScaleVector(vectorBank,c#)
  204.         If vectorBank=0
  205.                 Return False
  206.                 Else
  207.                 PokeFloat vectorBank,0,PeekFloat#(vectorBank,0)*c#
  208.                 PokeFloat vectorBank,4,PeekFloat#(vectorBank,4)*c#
  209.                 PokeFloat vectorBank,8,PeekFloat#(vectorBank,8)*c#
  210.                 Return True
  211.         EndIf
  212. End Function
  213.  
  214. ; // Unit Vector
  215. ;    Action: Scales a vector to a unit vector (vector of length 1).
  216. ;    Return: True if successful, False if failed.
  217. Function UnitVector(vectorBank)
  218.         If vectorBank=0
  219.                 Return False
  220.                 Else
  221.                 ScaleVector vectorBank,1.0/VectorMagnitude#(vectorBank)
  222.                 Return True
  223.         EndIf
  224. End Function
  225.  
  226. ; // Temporary Scale Vector
  227. ;    Action: Scales a vector by the second parameter.
  228. ;    Return: Vector handle of resulting scaled vector.
  229. ;    Notes: Deleted automatically when used in a non-data-returning vector function.
  230. Function TScaleVector(vectorBank,c#,freeTemporary=True)
  231.         If vectorBank=0
  232.                 Return 0
  233.                 Else
  234.                 tBank=TVector(PeekFloat#(vectorBank,0)*c#,PeekFloat#(vectorBank,4)*c#,PeekFloat#(vectorBank,8)*c#)
  235.                 If PeekByte(vectorBank,12)=1 And freeTemporary=True Then FreeBank vectorBank
  236.                 Return tBank
  237.         EndIf
  238. End Function
  239.  
  240. ; // Temporary Unit Vector
  241. ;    Action: Scales a vector to a unit vector (vector of length 1).
  242. ;    Return: Vector handle of resulting unit vector.
  243. ;    Notes: Deleted automatically when used in a non-data-returning vector function.
  244. Function TUnitVector(vectorBank,freeTemporary=True)
  245.         If vectorBank=0
  246.                 Return 0
  247.                 Else
  248.                 c#=VectorMagnitude#(vectorBank)
  249.                 tBank=TVector(PeekFloat#(vectorBank,0)/c#,PeekFloat#(vectorBank,4)/c#,PeekFloat#(vectorBank,8)/c#)
  250.                 If PeekByte(vectorBank,12)=1 And freeTemporary=True Then FreeBank vectorBank
  251.                 Return tBank
  252.         EndIf
  253. End Function
  254.  
  255. ; // Dot Product Explanation
  256. ;    v1 = <x,y,z>
  257. ;    v2 = <a,b,c>
  258. ;    v1 * v2 = x*a+y*b+z*c
  259. ;    v1 * v2 is a scalar, NOT a vector.
  260. ;    If v1 * v2 = 0 Then v1 is orthogonal (perpendicular) to v2.
  261. ;    If v1 * v2 > 0 Then angle between v1 and v2 is less than 90 degrees.
  262. ;    If v1 * v2 < 0 Then angle between v1 and v2 is greater than 90 degrees.
  263.  
  264. ; // Dot Product
  265. ;    Action: Returns the dot product of two vectors.
  266. ;    Return: The dot product of the two vectors, 0 if failed.
  267. ;    Notes: Last parameter is only for internal library usage (projections).
  268. Function DotProduct#(vector1Bank,vector2Bank,freeTemporary=True)
  269.         If vector1Bank=0 Or vector2Bank=0
  270.                 Return 0
  271.                 Else
  272.                 tDot#=PeekFloat#(vector1Bank,0)*PeekFloat#(vector2Bank,0)+PeekFloat#(vector1Bank,4)*PeekFloat#(vector2Bank,4)+PeekFloat#(vector1Bank,8)*PeekFloat#(vector2Bank,8)
  273.                 If PeekByte(vector1Bank,12)=1 And freeTemporary=True Then FreeBank vector1Bank
  274.                 If PeekByte(vector2Bank,12)=1 And freeTemporary=True Then FreeBank vector2Bank
  275.                 Return tDot#
  276.         EndIf
  277. End Function
  278.  
  279. ; // Cross Product Explanation
  280. ;    v1 = <x,y,z>
  281. ;    v2 = <a,b,c>
  282. ;    v1 X v2 = <y*c-z*b,z*a-x*c,x*b-y*a>
  283. ;    v1 X v2 is a new vector.
  284. ;    v1 X v2 is orthogonal (perpendicular) to v1 AND v2.
  285. ;    If v1 X v2 = <0,0,0> Then v1 is parallel to v2.
  286.  
  287. ; // Cross Product
  288. ;    Action: Crosses Vector 1 to Vector 2 and returns the handle of the new resultant vector.
  289. ;    Return: Vector handle of the resultant vector.
  290. Function CrossProduct(vector1Bank,vector2Bank)
  291.         If vector1Bank=0 Or vector2Bank=0
  292.                 Return 0
  293.                 Else
  294.                 tBank=CreateVector(PeekFloat#(vector1Bank,4)*PeekFloat#(vector2Bank,8)-PeekFloat#(vector1Bank,8)*PeekFloat#(vector2Bank,4),PeekFloat#(vector1Bank,8)*PeekFloat#(vector2Bank,0)-PeekFloat#(vector1Bank,0)*PeekFloat#(vector2Bank,8),PeekFloat#(vector1Bank,0)*PeekFloat#(vector2Bank,4)-PeekFloat#(vector1Bank,4)*PeekFloat#(vector2Bank,0))
  295.                 If PeekByte(vector1Bank,12)=1 Then FreeBank vector1Bank
  296.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  297.                 Return tBank
  298.         EndIf
  299. End Function
  300.  
  301. ; // Temporary Cross Product
  302. ;    Action: Crosses Vector 1 to Vector 2 and returns the handle of the new resultant vector.
  303. ;    Return: Vector handle of the resultant vector.
  304. ;    Notes: Deleted automatically when used in a non-data-returning vector function.
  305. Function TCrossProduct(vector1Bank,vector2Bank,freeTemporary=True)
  306.         If vector1Bank=0 Or vector2Bank=0
  307.                 Return 0
  308.                 Else
  309.                 tBank=TVector(PeekFloat#(vector1Bank,4)*PeekFloat#(vector2Bank,8)-PeekFloat#(vector1Bank,8)*PeekFloat#(vector2Bank,4),PeekFloat#(vector1Bank,8)*PeekFloat#(vector2Bank,0)-PeekFloat#(vector1Bank,0)*PeekFloat#(vector2Bank,8),PeekFloat#(vector1Bank,0)*PeekFloat#(vector2Bank,4)-PeekFloat#(vector1Bank,4)*PeekFloat#(vector2Bank,0))
  310.                 If PeekByte(vector1Bank,12)=1 And freeTemporary=True Then FreeBank vector1Bank
  311.                 If PeekByte(vector2Bank,12)=1 And freeTemporary=True Then FreeBank vector2Bank
  312.                 Return tBank
  313.         EndIf
  314. End Function
  315.  
  316. ; // Dot Angle Between
  317. ;    Action: Returns the absolute angle between Vector 1 and Vector 2 [0,180].
  318. ;    Return: Absolute angle between Vector 1 and Vector 2.
  319. ;    Notes: The angle returned is between 0 and 180 degrees meaning that it gives no indication of direction.
  320. Function DotAngleBetween#(vector1Bank,vector2Bank)
  321.         If vector1Bank=0 Or vector2Bank=0
  322.                 Return 0
  323.                 Else
  324.                 tAngle#=ACos(DotProduct#(vector1Bank,vector2Bank,False)/(VectorMagnitude#(vector1Bank)*VectorMagnitude#(vector2Bank)))
  325.                 If PeekByte(vector1Bank,12)=1 Then FreeBank vector1Bank
  326.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  327.                 Return tAngle#
  328.         EndIf
  329. End Function
  330.  
  331. ; // Cross Angle Between
  332. ;    Action: Returns the absolute angle between the lines drawn by Vector 1 and Vector 2 [0,90].
  333. ;    Return: Absolute angle between lines drawn by Vector 1 and Vector 2.
  334. ;    Notes: The angle returned is between 0 and 90 degrees meaning that it gives no indication of direction.
  335. Function CrossAngleBetween#(vector1Bank,vector2Bank)
  336.         If vector1Bank=0 Or vector2Bank=0
  337.                 Return 0
  338.                 Else
  339.                 tAngle#=ASin(VectorMagnitude#(TCrossProduct(vector1Bank,vector2Bank,False))/(VectorMagnitude#(vector1Bank)*VectorMagnitude#(vector2Bank)))
  340.                 If PeekByte(vector1Bank,12)=1 Then FreeBank vector1Bank
  341.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  342.                 Return tAngle#
  343.         EndIf
  344. End Function
  345.  
  346. ; // Scalar Projection
  347. ;    Action: Returns the length of Vector 2 projected onto Vector 1.
  348. ;    Return: Length of projection of Vector 2 onto Vector 1.
  349. ;    Notes: The return is a scalar, not a vector. Use vector projection for that.
  350. Function ScalarProjection#(vector1Bank,vector2Bank)
  351.         If vector1Bank=0 Or vector2Bank=0
  352.                 Return 0
  353.                 Else
  354.                 tScalar#=DotProduct#(vector1Bank,vector2Bank,False)/VectorMagnitude#(vector1Bank)
  355.                 If PeekByte(vector1Bank,12)=1 Then FreeBank vector1Bank
  356.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  357.                 Return tScalar#
  358.         EndIf
  359. End Function
  360.  
  361. ; // Vector Projection
  362. ;    Action: Returns the handle for the vector result of Vector 2 projected onto Vector 1.
  363. ;    Return: Vector handle of the resultant vector.
  364. ;    Notes: The return is a vector in the direction of Vector 1.
  365. Function VectorProjection(vector1Bank,vector2Bank)
  366.         If vector1Bank=0 Or vector2Bank=0
  367.                 Return 0
  368.                 Else
  369.                 c#=DotProduct#(vector1Bank,vector2Bank,False)/DotProduct#(vector1Bank,vector1Bank,False)
  370.                 tBank=CreateVector(PeekFloat#(vector1Bank,0)*c#,PeekFloat#(vector1Bank,4)*c#,PeekFloat#(vector1Bank,8)*c#)
  371.                 If PeekByte(vector1Bank,12)=1 Then FreeBank vector1Bank
  372.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  373.                 Return tBank
  374.         EndIf
  375. End Function
  376.  
  377. ; // Temporary Vector Projection
  378. ;    Action: Returns the handle for the vector result of Vector 2 projected onto Vector 1.
  379. ;    Return: Vector handle of the resultant vector.
  380. ;    Notes: Deleted automatically when used in a non-data-returning vector function.
  381. Function TVectorProjection(vector1Bank,vector2Bank)
  382.         If vector1Bank=0 Or vector2Bank=0
  383.                 Return 0
  384.                 Else
  385.                 c#=DotProduct#(vector1Bank,vector2Bank,False)/DotProduct#(vector1Bank,vector1Bank,False)
  386.                 tBank=TVector(PeekFloat#(vector1Bank,0)*c#,PeekFloat#(vector1Bank,4)*c#,PeekFloat#(vector1Bank,8)*c#)
  387.                 If PeekByte(vector1Bank,12)=1 Then FreeBank vector1Bank
  388.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  389.                 Return tBank
  390.         EndIf
  391. End Function
  392.  
  393. ; // Orthogonal Projection
  394. ;    Action: Returns the handle for the orthogonal vector result of Vector 2 projected onto Vector 1.
  395. ;    Return: Vector handle of the resultant orthogonal vector.
  396. ;    Notes: The return is a vector orthogonal (perpendicular) to Vector 1.
  397. Function OrthogonalProjection(vector1Bank,vector2Bank)
  398.         If vector1Bank=0 Or vector2Bank=0
  399.                 Return 0
  400.                 Else
  401.                 c#=DotProduct#(vector1Bank,vector2Bank,False)/DotProduct#(vector1Bank,vector1Bank,False)
  402.                 tBank=CreateVector()
  403.                 CopyVector(tBank,TSubtractVectors(vector2Bank,TVector(PeekFloat#(vector1Bank,0)*c#,PeekFloat#(vector1Bank,4)*c#,PeekFloat#(vector1Bank,8)*c#)))
  404.                 If PeekByte(vector1Bank,12)=1 Then FreeBank vector1Bank
  405.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  406.                 Return tBank
  407.         EndIf
  408. End Function
  409.  
  410. ; // Temporary Orthogonal Projection
  411. ;    Action: Returns the handle for the vector result of Vector 2 projected onto Vector 1.
  412. ;    Return: Vector handle of the resultant vector.
  413. ;    Notes: Deleted automatically when used in a non-data-returning vector function.
  414. Function TOrthogonalProjection(vector1Bank,vector2Bank)
  415.         If vector1Bank=0 Or vector2Bank=0
  416.                 Return 0
  417.                 Else
  418.                 c#=DotProduct#(vector1Bank,vector2Bank,False)/DotProduct#(vector1Bank,vector1Bank,False)
  419.                 tBank=TSubtractVectors(vector2Bank,TVector(PeekFloat#(vector1Bank,0)*c#,PeekFloat#(vector1Bank,4)*c#,PeekFloat#(vector1Bank,8)*c#))
  420.                 If PeekByte(vector1Bank,12)=1 Then FreeBank vector1Bank
  421.                 If PeekByte(vector2Bank,12)=1 Then FreeBank vector2Bank
  422.                 Return tBank
  423.         EndIf
  424. End Function


Comments :


Chroma(Posted 1+ years ago)

 OMG that looks like it costs alot in computing power.  I'm pretty sure that types are much faster than banks.  Pretty wicked looking stuff tho. =)


Jonathan Nguyen(Posted 1+ years ago)

 isnt accessing a bank just like accessing a type's variable? otherwise itd be the same computing power in regards to math.nice to see ya again btw chroma.


Chroma(Posted 1+ years ago)

 Nice to see you too man.  Nah, I thot someone did a speed test and came up banks being slower than types.


Danny(Posted 1+ years ago)

 Banks could be faster than types if you got good chunck of static-sized data, but types are way faster when you need to insert or delete them (e.g. when needing to sort a list).While working on my Pathfinding routine -that can create 10.000's of types (inserting and deleting) I rewrote the whole thing from types to Banks - thinking banks would be quicker and optimise it, but they weren't. Banks were actually only a like a fraction of 1ms slower or something like that, defenitly not worth the headache - in my case..I don't think (but haven't tested it) that creating tiny memory banks like that, which are created & free'd at high frequency will outperform Blitz's types..my 2 cents...d.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal