I did something similar in my FPS game. Every 5 loops, I check to see the distance of my objects from the camera. All objects that are far enough away and visible I hide, and any that are hidden, but now close enough to see, I show. Example:
LoopCount=LoopCount+1
if LoopCount=5
for x=200 to 299
if object exist(x)=1
if Distance(1,0,x)>20000 and object visible(x)=1
hide object x
endif
if Distance(1,0,x)<20000 and object visible(x)=0
show object x
endif
endif
next x
for x=500 to 750
if object exist(x)=1
if Distance(1,0,x)>20000 and object visible(x)=1
hide object x
endif
if Distance(1,0,x)<20000 and object visible(x)=0
show object x
endif
endif
next x
LoopCount=0
endif
You will need a distance function for that code to work. Here is the one I made.
Function Distance(colType,object1, object2)
if colType=1
Distance# = sqrt((camera position x()-object position x(object2))^2 + (camera position y()-object position y(object2))^2 + (camera position z()-object position z(object2))^2)
endif
if colType=2
Distance#=sqrt((object position x(object1)-object position x(object2))^2+(object position y(object1)-object position y(object2))^2+(object position z(object1)-object position z(object2))^2)
endif
EndFunction Distance#
The distance function above has two options. One for calculating distance from the camera to an object, and from object to object. Hopefully, this makes some sense.