Archived

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

fireking

rpg world management in vb

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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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

Owner/Leader
Genetics 3rd Dimension Development

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Firstly VB5 onward supported a native compiler, so the output EXE is not interpreted.

Secondly to address your problem, you might want to use a collection object instead of resizing the array... which is really bad programming practice in your situation.

Share this post


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

Secondly to address your problem, you might want to use a collection object instead of resizing the array... which is really bad programming practice in your situation.


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

Owner/Leader
Genetics 3rd Dimension Development

Share this post


Link to post
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 this post


Link to post
Share on other sites