Would this be faster than using a TList

BlitzMax Forums/BlitzMax Programming/Would this be faster than using a TList

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi,

I've heard alot about how TLists are slow and such, so I devised an alternative way for me to store Vertex's for a Surface. Basically Vertex information is stored in a TBank and the individual values (such as xyz, rgb, normal info etc) are accessed using PeekFloat with the correct offset. I have managed to put together a working example of the code. One thing I need to know, Is my method of storing Vertex's in a TBank faster than using a TList?

Thanks,

Test.bmx:
Const OFS_VERTEXX 	= 0
Const OFS_VERTEXY 	= 4
Const OFS_VERTEXZ 	= 8
Const OFS_VERTEXU 	= 12
Const OFS_VERTEXV 	= 16
Const OFS_VERTEXW 	= 20
Const OFS_VERTEXR 	= 24
Const OFS_VERTEXG 	= 28
Const OFS_VERTEXB 	= 32
Const OFS_VERTEXA 	= 36
Const OFS_VERTEXNX 	= 40
Const OFS_VERTEXNY 	= 44
Const OFS_VERTEXNZ 	= 48

Type TSurface
	Field Vertices			: TBank = CreateBank(0)
	Field VerticesOffset	: Int
	Field Count				: Int
	Field Triangles			: Int
	
	Method AddTriangle(V1:TVertex, V2:TVertex, V3:TVertex)
		AddVertex(V1)
		AddVertex(V2)
		AddVertex(V3)
	End Method
	
	Method AddVertex(V:TVertex)
		ResizeBank(Vertices, VerticesOffset + 48)
		PokeFloat(Vertices, VerticesOffset, V.X)
		VerticesOffset :+ 4
		PokeFloat(Vertices, VerticesOffset, V.Y)
		VerticesOffset :+ 4
		PokeFloat(Vertices, VerticesOffset, V.Z)
		VerticesOffset :+ 4
		PokeFloat(Vertices, VerticesOffset, V.U)
		VerticesOffset :+ 4
		PokeFloat(Vertices, VerticesOffset, V.V)
		VerticesOffset :+ 4
		PokeFloat(Vertices, VerticesOffset, V.W)
		VerticesOffset :+ 4
		PokeFloat(Vertices, VerticesOffset, V.R)
		VerticesOffset :+ 4
		PokeFloat(Vertices, VerticesOffset, V.G)
		VerticesOffset :+ 4
		PokeFloat(Vertices, VerticesOffset, V.B)
		VerticesOffset :+ 4
		PokeFloat(Vertices, VerticesOffset, V.A)
		VerticesOffset :+ 4
		PokeFloat(Vertices, VerticesOffset, V.NX)
		VerticesOffset :+ 4
		PokeFloat(Vertices, VerticesOffset, V.NY)
		VerticesOffset :+ 4
		PokeFloat(Vertices, VerticesOffset, V.NZ)
		
		Count :+ 1
		Triangles = Count / 3
	End Method
	
	Method Render()
		For Local I:Int = 0 To Count - 1
			glTexCoord2f(PeekFloat(Vertices, 48 * I + OFS_VERTEXU), PeekFloat(Vertices, 48 * I + OFS_VERTEXV))
			glColor4f(PeekFloat(Vertices, 48 * I + OFS_VERTEXR), PeekFloat(Vertices, 48 * I + OFS_VERTEXG), PeekFloat(Vertices, 48 * I + OFS_VERTEXB), PeekFloat(Vertices, 48 * I + OFS_VERTEXA))
			glNormal3f(PeekFloat(Vertices, 48 * I + OFS_VERTEXNX), PeekFloat(Vertices, 48 * I + OFS_VERTEXNY), PeekFloat(Vertices, 48 * I + OFS_VERTEXNZ))
			glVertex3f(PeekFloat(Vertices, 48 * I + OFS_VERTEXX), PeekFloat(Vertices, 48 * I + OFS_VERTEXY), PeekFloat(Vertices, 48 * I + OFS_VERTEXZ))
		Next
	End Method
End Type

Type TVertex
	Field X:Float, Y:Float, Z:Float
	Field U:Float, V:Float, W:Float
	Field R:Float, G:Float, B:Float
	Field A:Float
	Field NX:Float, NY:Float, NZ:Float
End Type


Example.bmx:
SuperStrict

Import "Test.bmx"

Global Event:Int
GLGraphics 800, 600, 0

glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45.0, 1.33333, 1, 1000)

Global S:TSurface = New TSurface
Global V:TVertex = New TVertex

V.X = 0
V.Y = 1
V.Z = -10
V.R = 1
V.G = 1
V.B = 0.1
S.AddVertex(V)

V.X = -1
V.Y = -1
V.Z = -10
S.AddVertex(V)

V.X = 1
V.Y = -1
V.Z = -10
S.AddVertex(V)

V.X = -1
V.Y = 1
V.Z = -10
S.AddVertex(V)

While(Event <> EVENT_APPTERMINATE)
	PollSystem()
	PollEvent()
	Event = EventID()
	
	glClear(GL_COLOR_BUFFER_BIT)
	
	glMatrixMode(GL_MODELVIEW)
	glLoadIdentity()
	
	glBegin(GL_POLYGON)
	S.Render()
	glEnd()
	
	GLDrawText "Triangles: " + S.Triangles, 10, 10
	
	Flip
	glFlush()
Wend
End


Thanks in advance,