Possible problem with loading maplist?

Discuss programming in the QuakeC language.
Post Reply
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Possible problem with loading maplist?

Post by Wazat »

I'm about to make the maplist saving/loading feature for Conquest's town. However, I've just realized it probably won't work the way I'm planning it.

The original idea for loading was to run through the file and generate a linked list of entities. Each entity would store the map name, how many times it was beaten, etc. Then I could cycle through the linked list to print out the map list to screen, or to find the map I wanted. This system sounds really good to me because it helps keep the map file organized (when the map list is saved again I can just traverse the linked list, which was sorted already).

However, the snag is Quake's string system. It doesn't actually copy strings around, it just makes a const for all the strings mentioned in the code, and temporarily stores the rest of the strings in buffers that will be soon overwritten. So, if I say:
ent.netname = temp; // copy name into entity
all the ents will end up with the same name, because temp is pointing to the fgets buffer instead of a separate string, and the next call to fgets will change that buffer.

In other words, unless DP supports a whole lot of temp strings, I won't be able to do it this way. :(
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

http://wiki.quakesrc.org/index.php/FRIK_FILE

string(string s) strzone = #118;
void(string s) strunzone = #119;

ent.str = strzone(fgets(f));


ent.str will then be valid at any point for the rest of the map.
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

>>unless DP supports a whole lot of temp strings, I won't be able to do it this way

>ent.str = strzone(fgets(f));

Yes, I knew about string zones, but how many of those can I make? 5? 1024? 2^350? As many as I can create before I run out of memory?

If DP & other engines can give me as many temp strings as I need, then the problem is solved.

Thanks, Spike.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

Wazat wrote:>>unless DP supports a whole lot of temp strings, I won't be able to do it this way

>ent.str = strzone(fgets(f));

Yes, I knew about string zones, but how many of those can I make? 5? 1024? 2^350? As many as I can create before I run out of memory?

If DP & other engines can give me as many temp strings as I need, then the problem is solved.

Thanks, Spike.
DP imposes no limit.
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

Great! Thanks again!
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

...btw, when I'm done with the linked list, I'll probably want to dealloc/unzone the strings when I'm done with the linked list and want to destroy it, right? (unless I'm changing maps right then, in which case I need not bother) What if there are duplicate entries in the list, for whatever reason? Will calling unzone on the same string twice cause crashes?
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

Wazat wrote:...btw, when I'm done with the linked list, I'll probably want to dealloc/unzone the strings when I'm done with the linked list and want to destroy it, right? (unless I'm changing maps right then, in which case I need not bother) What if there are duplicate entries in the list, for whatever reason? Will calling unzone on the same string twice cause crashes?
QC coders are expected to be lazy. The engine frees all unfreed strings at the end of the level.

Each call to strzone returns a unique string (indistinguishable from QC though). Thus two strzones with the same origional string require two unzones to fully free.
If you remember to clear strings to "" when unzoning, how are you going to be able to try unzoning the same one twice?
Tei
Posts: 193
Joined: Mon Oct 25, 2004 12:22 pm

Re: Possible problem with loading maplist?

Post by Tei »

imho:

Avoid strings. Use floats instead (1,2,3,4...)
Wazat
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Post by Wazat »

Spike: Thanks!

Tei: Why? I'm using strings for map names because I'm going to be using more than just the original Quake maps. When all is said and done, Mappers should be able to just paste their campaign into Conquest's directory, make a .cfg file listing their campain name and the maps in it, and then include their .cfg in campaign.cfg. Then that campaign will be available in-game without having to change the code at all.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Post Reply