Jump to content

Nikiee

Resident
  • Posts

    7
  • Joined

  • Last visited

Reputation

0 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Why aren't you blacklisting the objects if you're always derendering them? To re-render objects that have been temporarily derendered, simply leaving the sim and returning should recover them.
  2. Hokay. After a lot of trial and error, and heavy use of decimal2binary(), I think I finally have an alright grasp of how the operators work! For anybody else who might stumble accross this thread, I'll leave the practice script I ended up with by this point. Personally I learn the fastest when I have a consistent base that I use as an example, so with slight modifications, this is how I ended up using the examples by all of you. Some extra formatting for readability, too. (But the comments don't look quite as good without color-coding.) // CREATE INITIAL STRUCTUREinteger db_record(integer class, integer faction, integer outfit, integer gender){ class = (class & 0x7) <<6; // 0x7 = binary 111xxxxxx (6 = width of GENDER and OUTFIT and FACTION) faction = (faction & 0x7) <<3; // 0x7 = binary 111xxx (3 = width of GENDER and OUTFIT) outfit = (outfit & 0x3) <<1; // 0x3 = binary 11x (1 = width of GENDER) gender = (gender & 0x1); // 0x1 = binary 1 (No shifting because it's the right-most) // // x's replaced by 0 when shifted, then replaced by next value return class | faction | outfit | gender;}// GET VALUEinteger get_flag(integer w, integer x){ // x = Amount of bits to shift in the x "axis." check db_record for x. return ( (db >>x) & ((1<<w)-1) );}// SET VALUEinteger set_flag(integer i, integer w, integer x){ // i = integer to set db = db & ~( (1<<w)-1 <<x); // Mask return db = db | (i & (1<<w)-1) <<x;}integer db;default{ state_entry() { //class 5, faction 7, fully clothed, male db = db_record(5, 7, 3, 1); set_flag(1, 3, 6); // 0x7 = 111 set_flag(1, 3, 3); // 0x7 = 111 set_flag(1, 2, 1); // 0x3 = 11 set_flag(0, 1, 0); // 0x1 = 1 llOwnerSay("current flags: " +(string)get_flag(3, 6)+" " +(string)get_flag(3, 3)+" " +(string)get_flag(2, 1)+" " +(string)get_flag(1, 0)); }} I also wrote this down because it was by far the most helpful set of sentences in the whole thread for me: //It would be handy to have a way to create that mask of 0x7.//If we shift a solitary one bit left by 3 places, we get 8.//The expression (1<<w)-1 produces a field of ones w bits wide.// 1 = 0001// 0001 <<3 = 1000 (8)// 8-1 = 7 = 0111 (0x7)
  3. That is incredibly helpful and I'm so thankful that you took the time to go over all of that twice. <3 And I ended up surprising myself by having guessed w, p, and d right, and half-guessed the purpose of s. Once I get home, I'm going to play around with the function and apply it into some made-up code of my own to see what breaks.
  4. Bah, the first time I delete a comment anywhere because I felt dumb and then this happens. :< Sorry! Anyway, if this was all done in a single small script, it wouldn't really be that much more optimal for just a couple integers, but the point of the exercise (for me) is to get an understanding of bitfields and learning to operate them. That said, having stared at the functions for a while, I'm having trouble making sense of them because I don't understand what the variables are for. (I get that it's on purpose, but!)
  5. integer dbRecord(integer gender, integer class, integer outfit){ // longhand method so can see more easy what is happening // & mask to make sure data value is in range. then shift right into position gender = (gender & 0x1) << 5; // 0x1 = binary 1. 5 = bit width of class and outfit class = (class & 0x7) << 2; // 0x7 = binary 111. 2 = bitwidth of outfit outfit = (outfit & 0x3); // 0x3 = binary 11.} The way you explained how many values each bit can store, and the way you ordered dbRecord() had my head stuck for quite a while. But I think I understand what you're doing with the values now. Neat! Just as a note for myself (and clarification for others?), the function would be "better" (in this situation) formatted like this: integer dbRecord(integer class, integer outfit, integer gender){ class = (class & 0x7) << 3; // 0x7 = binary 111xxx (3 = width of GENDER and OUTFIT) outfit = (outfit & 0x3) << 1; // 0x3 = binary 11x (1 = width of GENDER) gender = (gender & 0x1); // 0x1 = binary 1 (No shifting because it's the first) return gender | class | outfit; // OR them together and return as integer dbRecord} There would never be a need for more than 2 values for gender, clothing could be 3 layers (as an example), and classes we could have 7 or more. That aside, this is a very nice way of dealing with any amount of properties, especially since you could store more than 8 values using this method.
  6. Recently I've decided that I want to optimize my code further by collapsing several integers to a single bitfield (signed-32). I keep wanting to store properties or "states" as integers and check those when needed, for example: integer gender = 1; integer class = 5; integer outfit = 2; default { state_entry() { ... } }The globals and values are arbitrary, but this is what I do. This ends up using 48 bytes of memory for simple checks that are done sparingly. What I've tried doing to compress the memory usage is this: integer specs; default { state_entry() { integer gender = 1; integer class = 5 <<4; integer outfit = 2 <<8; specs = gender|class|outfit; // result: 519, binary: 0010 0000 0111 ... } }Since a 1-digit integer can be stored in 4 bits, I could compress up to 8 (128 bytes) separate integers into one (16 bytes). But now when I'm trying to figure out a way to check for those individual values, I feel like I'm doing an unnecessary amount of math and/or checks to get there. This is where I'm stumped, and hoping that someone more familiar with bitfields could explain a good way to do this.
×
×
  • Create New...