User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14

Thread: Storing two values in one

  1. #1
    Clicker Fusion 2.5Android Export ModuleSWF Export Module
    EE's Avatar
    Join Date
    Sep 2009
    Posts
    200
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Storing two values in one

    Hey hey!
    I was just wondering how you go about storing two values in one with individual retrieval functionality.
    Case in point - I'm saving a value between 0-127 in an unsigned byte and would really like to make use
    of the 128-255 range too. Since my bitmasking skills are... lacking, I was wondering if someone who
    already knows how could school me?
    //EE

  2. #2
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleInstall Creator ProUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jul 2006
    Posts
    574
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    You can store 2 Short values in 1 32bit in INT but if you wanted to store bytes you could store upto 4 bytes. Or 2 bytes and 1 Short in the INT (or even 8 values 0-15, or 32 bit flags). Seems as you want to use 0-255 the remaining 16bits could be left over reserved for other use:
    Mask for the first value in the INT: 11111111 (255 / 0xFF)
    Mask for the second value in the INT: 1111111100000000 (65280 / 0xFF00)
    Transferring values from store value to the working value (for addition within you app/game):
    Value 1 = Store value AND 255
    Value 2 = Store value AND 65280 / (2 POW 8) or 256 (Unfortunately fusion doesn't support shifting without another extension but its simple to work around by applying 2 the power of the amount of bits you need to shift in this case 8).
    Now you can work with Values 1 and 2 until you need to store them again.

    To store them:
    Store value = (Value 1 AND 255) OR ((Value 2 AND 255) * (2 POW 8))

    For example:
    Store value = 44693
    Value 1 = 44693 AND 255 = 149
    Value 2 = 44693 AND 65280 = 44544 / (2 POW 8) = 174

    add 10 to both values and then store them
    Store Value = (159 AND 255) OR (184 * (2 POW 8)) = 47263

    If you wanted to store a 3rd and 4th value in the INT you just need to shift the value another 8 bits for each value (2 POW 16, 2 POW 24) and then apply the bit mask (16711680 / 0xFF0000, 4278190080 / 0xFF000000)

  3. #3
    Clicker Fusion 2.5Android Export ModuleSWF Export Module
    EE's Avatar
    Join Date
    Sep 2009
    Posts
    200
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot for the that!
    I'm trying to minimize filesize for external levels while at the same time keeping data processing at it's lowest for good speed.
    Currently I'm storing each cell (50x28 per screen) in a 1d byte array, thats why I'm interested in using the 0-255 range.
    0-127 corresponds to the tile used, so it makes sense including the collision data too since I have the space.
    I'm gonna try and experiment some with the info!

  4. #4
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleInstall Creator ProUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jul 2006
    Posts
    574
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Bear in mind 127 is 7 bits. 255 is 8. So if you're wanting to store the tile number and something else in the byte you'll only have a bit to work with. I also opt for the binary object for storing level data in my own format too instead of the array object.

  5. #5
    Clicker Fusion 2.5Android Export ModuleSWF Export Module
    EE's Avatar
    Join Date
    Sep 2009
    Posts
    200
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by danworth View Post
    Bear in mind 127 is 7 bits. 255 is 8.
    After reading up a tiny bit more I quickly realized my error...
    I had the byte value range mixed up in dreams of nibbles and bit fields!
    Anyway, my options are nice; either extend the tileset to 256 tiles and keep the
    collision data in the next Z-layer in turn doubling the memory usage. Or I keep
    to 127 tiles and use the 8:th bit as collision test.

  6. #6
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleInstall Creator ProUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jul 2006
    Posts
    574
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    I think you'll benefit from documenting your format and requirements. Its best to try to included everything you'll think you'll need otherwise if you wanted to add to the format you'll have to included some sort of upgrade/conversion code to make older levels compatible. I can post an example of a file format if needed. I've been thinking of making an example of a level format with level editor.

  7. #7
    Clicker Fusion 2.5Android Export ModuleSWF Export Module
    EE's Avatar
    Join Date
    Sep 2009
    Posts
    200
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I tend to make it up as I go along way too often. An example on file formats would be really cool since I'd love to make my own!

  8. #8
    Clicker Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleInstall Creator ProUnicode Add-on
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Jul 2006
    Posts
    574
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Something like this is how I'd go about things. I'd also add some sort of identification to the header like a 4 byte string so that the game could confirm that its a compatible file and the compression/encryption to the file:

    (Offset: Datatype - Description)
    Header (0x00000000):
    0x00000000: Int - File version (eg 0x00010203 / v1.02.03)
    0x00000004: Short - Grid Width
    0x00000006: Short - Grid Height
    0x00000008: 32 bytes (string) - Level Name
    0x00000028: Byte - Sprite Set
    0x00000029: Byte - Tile Set
    0x0000002A: Byte - Music Track
    0x0000002B: Short - Time limit
    0x0000002D: Byte - Difficulty
    0x0000002E: Short - Level Number
    0x00000030: Short - Layer 1 Pointer (Multiply by 4)
    0x00000032: Short - Layer 2 Pointer (Multiply by 4)
    0x00000034: Short - Layer 3 Pointer (Multiply by 4)

    Each Layer then will have its own structure and header:
    Layer Header:
    0x00000000: Int - Tile count
    0x00000004: 12 Bytes - Reserved for future use
    0x00000010: [First tile in layer]
    0x00000016: [Secord tile in layer]
    0x0000001C: [and so on...]

    Tile Structure:
    Short - X Position (grid position could be a byte if grid is 256x256 or smaller)
    Short - Y Position (grid position could be a byte if grid is 256x256 or smaller)
    byte - Sprite ID
    byte - Sprite Flag (Special characteristics)
    Byte - Sprite Attribute value 1
    Byte - Sprite Attribute value 2

  9. #9
    Clickteam Clickteam
    Danny's Avatar
    Join Date
    Aug 2007
    Location
    United Kingdom
    Posts
    3,010
    Mentioned
    21 Post(s)
    Tagged
    2 Thread(s)
    This is a great topic. Some useful info here danworth.
    Want to learn Clickteam Fusion 2.5?




  10. #10
    Clicker Fusion 2.5Android Export ModuleSWF Export Module
    EE's Avatar
    Join Date
    Sep 2009
    Posts
    200
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    That was a really smart way of using the binary object.
    I'm gonna go ahead and dive into this more. I'm still in the process of designing my level editor so to remake the code to work with the binary object instead of the byte array shouldn't be impossible.
    Thanks alot!

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Replies: 12
    Last Post: 9th August 2018, 01:56 PM
  2. Storing infomation in ini++...
    By Earl in forum iOS Export Module Version 2.0
    Replies: 2
    Last Post: 6th August 2012, 02:53 AM
  3. Storing Data
    By Kracker in forum Android Export Module Version 2.0
    Replies: 14
    Last Post: 12th June 2012, 07:24 PM
  4. Storing variables on which way?
    By Ran_TH in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 27th August 2008, 02:17 PM
  5. Storing Decimal Numbers as Alterable Values
    By Raphael in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 21st September 2006, 02:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •