Archived

This topic is now archived and is closed to further replies.

rpg world management in vb

This topic is 5859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

lately ive been having trouble figuring out why my world management is so slow in vb basically what im trying to accomplish is loading tiles (which is a class) into an array. Ive tried single dimension array, 2 dimensional array, and 3 dimensional array (first 2 for x and y, the 3rd is for multiple maps, or effectively the "Z" layer) the problem anyway is that its WAY too slow, its so slow its horrible, times like 10 minutes to 20 minutes, and my code isnt that bad, its just setting variables!!! look at this the world class
private atoms() as ffatom
public sub AddAtom(name as string,bmpname as string)
redim preserve atoms(ubound(atoms)+1)
set atoms(ubound(atoms))= new ffatom
atoms(ubound(atoms)).create name,ubound(atoms),bmpname
end sub
public function getatom(name as string) as ffatom
dim i as long
for i = 1 to ubound(atoms)
if atoms(i).name = name then
set getatom = atoms(i)
exit for
end if
next
end function
public sub removeatom(name as string)
dim i as long
dim del as long
for i = 1 to ubound(atoms)
if atoms(i).name = name then
del = i
exit for
end if
next
set atoms(del) = nothing
for i = del to ubound(atoms)-1
set atoms(i) = atoms(i+1)
next
set atoms(ubound(Atoms)) = nothing
redim preserve atoms(ubound(Atoms)-1)
end sub

the create function for the atom is something simple like this the atom class create function
public sub Create(xname as string,xid as long,xbmpname as long)
name = xname
id = xid
bmpname = xbmpname
end sub

everything works, there is nothing wrong with my code thats basically how you handle the resizing of arrays. the only thing i cant figure out is the fact that is just way too slow. i dont know why it is too slow, its just setting a few variables. ive tried loading a 500x500 map in a multidimension array, it was way too slow, i tried loading 500 x 500 as 500*500 = 250000 single dimension array, and GOD it was slower than you will EVER know. and we arent even to the point where we draw! any help will be greatly appreciated, i hope i can get this world management down. --Fireking Owner/Leader Genetics 3rd Dimension Development

Share on other sites
Two suggestions.

1) You may want to consider moving to an uninterpreted language

2) Try creating your array all at once. If you''ve got an array of size 2500, you seem to be resizing it 2500 times. It is best to simply make the array the size that you will need it to be once and for all. That way you will only allocate it once.

-D

Share on other sites
hmm, very valid point, i dont want to move to anything other than vb mainly because vb gives me the flexibility to build complicated tools for creating the game, i build the engine as generic as possible, and give it the ability to read files. and basically create the entire game out of the files, as the engine just displays it.

i never thought of resizing it once. goooooood idea man. thanks.

--Fireking

Genetics 3rd Dimension Development

Share on other sites
Firstly VB5 onward supported a native compiler, so the output EXE is not interpreted.

Share on other sites
wow, that worked wonders, loads in 2 seconds. thanks for bringing that to my attention, these must be long days!

--Fireking

Genetics 3rd Dimension Development

Share on other sites
quote:
Original post by Anonymous Poster
Firstly VB5 onward supported a native compiler, so the output EXE is not interpreted.

well actually its bad programming to use collections anyways, collections are slower and generally crappy as hell. arrays are much faster and more robust.

if resizing arrays are bad then why is it fully supported in VB and STL for C++?

i dont see how its possible for any of the latest games to work without resizing arrays.

--Fireking

Genetics 3rd Dimension Development

Share on other sites
It's also how you (and STL and VB, etc.) resize the array that counts. Redim Preserve, by its very nature, is a slow command as you've already seen. The less times this is called, the better. The latest games would only resize the array when it gets full, which would be after every 100 items or so (maybe more, depending).

Arrays are good for accessing items very quickly, but resizing an array to add more items is not one of their strong points.

[edited by - Tri on November 5, 2002 10:54:55 AM]

Share on other sites
try looking into linked lists that would be faster.

I have found with VB if your code is slow try using objects works a treat normally but remember to kill those objects after use.

Cheers

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• Forum Statistics

• Total Topics
633410
• Total Posts
3011723
• Who's Online (See full list)

There are no registered users currently online

×