ID:154305
 
I have a choice right now in my game, but I don't know which way would be considered "more efficient", or more importantly, least laggy.

The options:

I can have descriptions for objects that players can manipulate, sticks, fountains, rocks, clothes, whatever, stored in variables. To my knowledge, this means that whenever someone looks at the item and shows the description, it will load it faster. Keeping the information loaded in the game constantly though, might to my knowledge slow things down a wee bit anyway.

The other option, I can store the descriptions in save files, like I've done with room descriptions. This makes them load a bit more slowly, but it means that the game won't have to put up with the description until it's needed.

But, I'm not sure which way I should go with. Recommendations?
Foomer wrote:
The other option, I can store the descriptions in save files, like I've done with room descriptions. This makes them load a bit more slowly, but it means that the game won't have to put up with the description until it's needed.

But, I'm not sure which way I should go with. Recommendations?

If a vast set of descriptions is needed, then I recommend an associative cache. Try this out for size (code untested):
textcache
var/filename
var/list/cache
var/list/cleanup

New(_filename)
filename=_filename
cache=list()
cleanup=list()
spawn(6000) Clean() // in 10 minutes, clear out the junk

proc/Clean()
var/maxtime=world.realtime-300 // kill anything 5+ minutes old
for(var/key in cleanup)
if(cleanup[key]<maxtime) cleanup-=key // this loop is legal in DM
spawn(1200) Clean() // check again in 2 minutes

proc/Get(type,thevar)
var/key="[type]:[thevar]"
var/val=cache[key]
if(!val)
var/file/F=file(filename)
F[key] >> val
cache[key]=val
cleanup[key]=world.realtime
return val

The idea behind this is to load from a file, but keep the item in memory as needed. You could then do things like this:
var/textcache/thecache

world/New()
thecache=new

obj
proc/Describe()
usr << thecache.Get(type,"desc")

In the long run it's probably easier to store your descriptions in some kind of file anyway for easy access, so you don't have to recompile your game every time.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
In the long run it's probably easier to store your descriptions in some kind of file anyway for easy access, so you don't have to recompile your game every time.

Very nice idea :) Going to incorporate that into my text engine right away! Was thinking of something like that anyways when I stumbled upon this post

Alathon
In response to Alathon
Sigh... anything I ever do behind-the-scenes is always exposed from independent development by Lummox. =)