On Sat, Jan 19, 2002 at 12:36:58PM +0100, Templar Viper wrote: > I was lately putting in a new piece of code that required an empty pfr flag > slot. > However, this slot was number 32, and I later found out that it wasn't > working > correctly. So I now know slots like prf etc can only contain 32 flags (zero > included).. Only, how to tackle this. Would it be more easy to create an > entire > new prf slot list (prf2) or is there a method I could increase the number of > flags? > Did anybody do this before? How did they solve it? > > If someone is willing to help me, thank you. I decided to be a complete freak and switch to C++. I created a new 'bitvect' class, and typedefed bitvector_t to it. Internally, the bitvect class is stored as an array of longs. Externally, the access methods don't change much from the way the old limited bitvectors worked, since I filled bitvect.h with inlined operator overloads to make most of the transition completely seamless, and a few inlined methods when it wasn't seamless. One problematic difference is I/O; when not using asciiflags (which had to be hacked as well), I have to use .read() and .write() methods, which need to use a FILE * or FBFILE * directly. There's also some utility methods like .anybits(), .inrange() (for the bpl20 DB sanity checking function), .print() (for things like do_stat_*). As an example, here's the bitvect.inrange() method: class bitvect { ... bool inrange(size_t count) { int start; start = count / 32; count %= 32; if (vector[start] > (~0UL >> (sizeof(unsigned long) * 8 - count))) return FALSE; for (start++; start < MAX_BITVECT; start++) if (vector[start]) return FALSE; return TRUE; } ... } And here's a couple of operators, which are marked friends of the class: inline bitvect operator |(bitvect a, bitvect b) { bitvect tmp; for (int i = 0; i < MAX_BITVECT; i++) tmp.vector[i] = a.vector[i] | b.vector[i]; return tmp; } inline bitvect &operator &=(bitvect &a, bitvect b) { for (int i = 0; i < MAX_BITVECT; i++) a.vector[i] &= b.vector[i]; return a; } One big but really easy to handle difference is that all of the old bitvector #defines are gone; all PRF_* (and AFF_ and ITEM_ and every other bit vector) flags are now actually variables (though I could probably set them const). They are all prototyped at the bottom of bitvect.h, and I created bitvect.cc to have a place to instantiate all of the vectors as actual variables and give them values. For example, in bitvect.h: extern bitvect nobits; extern int FORMAT_INDENT; extern bitvect ROOM_DARK; /* Dark */ extern bitvect ROOM_DEATH; /* Death trap */ extern bitvect ROOM_NOMOB; /* MOBs not allowed */ And bitvect.cc: bitvect nobits; bitvect ROOM_DARK(0, 0); /* Dark */ bitvect ROOM_DEATH(0, 1); /* Death trap */ bitvect ROOM_NOMOB(0, 2); /* MOBs not allowed */ My constructor takes two numbers, one an index into the array of vectors and the other a small integer for bit shift value. It would be easy enough to just take one integer instead that you would div by your long size and mod to get the bit shift. It's by no means a quick and easy transition, but it worked. I would not recommend it for the faint of heart or weak of code though. What might work for you is to redefine your bitvectors to 'unsigned long long'. You will have to change some code but depending on your compiler that might yield 64-bit vectors. Is anyone actually interested in my bitvect.h and bitvect.cc? I would be happy to distribute those, but the changes that happen elsewhere in the code are too widespread for me to make a patch, and I don't want to hand out my entire source. :) If anyone wants to attempt it, I'd be happy to help out with questions about how to handle transitioning pieces of code (I've currently got it working with OLC, ascii pfiles, and ascii rent files, so it's definitely possible). -- Elie Rosenblum That is not dead which can eternal lie, http://www.cosanostra.net And with strange aeons even death may die. Admin / Mercenary / System Programmer - _The Necronomicon_ -- +---------------------------------------------------------------+ | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html | | Newbie List: http://groups.yahoo.com/group/circle-newbies/ | +---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 06/25/03 PDT