Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
A good way to reading bits? (reading the lvz format)

 
Post new topic   Reply to topic Printable version
 View previous topic  JPG/PNG Compression Post :: Post need help!  View next topic  
Author Message
grazzhoppa
Novice


Joined: Jan 03 2007
Posts: 29
Offline

PostPosted: Sat Jan 06, 2007 11:47 pm    Post subject: A good way to reading bits? (reading the lvz format) Reply to topic Reply with quote

I made something that reads a .lvz file and it works for all the .lvz's I tested it on, but I have feeling there is an easier way to read "# bits" than the way I tried.

Here is a snip of what it does for each item that "lvzformat.txt" describes:

It puts an uncompressed section into a char array called "uncompressedDATA". And it uses an int called "dataPointer" to keep track of where it is in the uncompressed data array.

Code: Show/Hide

        // next 2 bytes:
        // i12 Display Time - How long will display for, in 1/10th of a second.
    unsigned short displayTime = 0;  // 16 bit int, will hold a 12 bit number
    memcpy(&displayTime, &uncompressedDATA[dataPointer], 2); // read 16 bits/2 bytes. Only interested in the first 12 bits though.
    dataPointer += 1; // move the dataPointer only one byte because the next item shares some of the 2nd byte

    displayTime <<= 4;   // push the last 4 bits off of the number
    displayTime >>= 4;   // move the significant 12 bits back to the beginning of the number

    printf(" object loop: displayTime is %i 1/100ths of a second\n", displayTime);

        // i4 Display Mode - Which display mode this object uses. Values later.
    unsigned char displayMode = 0;  // 8 bit int, unsigned so bit shift is predictable
    memcpy(&displayMode, &uncompressedDATA[dataPointer], 1);    // read 8 bits/1 byte, only interested last 4 bits.
    dataPointer += 1;

    displayMode >>= 4;  // push the rightmost 4 bits of the 8bit number off, so only the last 4 bits represent the number.


Is there a better way other than bit shifting like that for each "item" in the lvz format that is not a multiple of 1byte/8bits?

Also, I don't know bitshift will work when the item in the .lvz is supposed to represent a negative number (like the x coord/y coord of a screen object). I don't have a Windows computer, so I can't make a new .lvz to test a .lvz that uses negative numbers for those items.
Can someone please supply a .lvz that uses negative numbers for the x and y coord of a screen object?

Here is how it reads the x/y coord of a screen object:
Code: Show/Hide

        // next 2 bytes after mapOrScreenObject and objectID bytes:
        // u4 X Type - Which part of the screen the X coord is offset from (see OffsetTypes lower down).
    unsigned char xScreenOffsetType = 0;   // will hold 4 significant bits only.
    memcpy(&xScreenOffsetType, &uncompressedDATA[dataPointer], 1);    // read 1 byte
    // ++dataPointer;   // do not move the pointer, still need to read part of the 1st byte.

    xScreenOffsetType <<= 4;  // push 4 leftmost bits off the 8 bit number
    xScreenOffsetType >>= 4;  // move the significant 4 bits back to the significant side of the number.

    printf(" object loop: xScreenOffsetType is %i\n", xScreenOffsetType);

        // i12 X Coord - The X coord value, in pixels, this object will be displayed on. More info later.
    /*unsigned */ short xCoord = 0;  // 16 bit int, only 12 significant bits will be put into it. This value can be negative.
    memcpy(&xCoord, &uncompressedDATA[dataPointer], 2); // read 16 bits/2 bytes from the uncompressedDATA.
    dataPointer += 2;

    xCoord >>= 4;   // push the 4bits from the previous variable off of this 16bit number, to get the significant 12 bits of this variable. Bitshifting a signed int!

    printf(" object loop: xCoord at %i pixel\n", xCoord);


If you're going to run the program - warning: it'll dump all the files from the .lvz into the same directory as the program. It doesn't create a nice .ini like deBuildLevel from the lvzToolKit, but it prints out all the .lvz information to the console. It compiles with g++, and not tested on other compilers.
Give the path to the .lvz file as the argument to the program:
Code: Show/Hide
./lvzreader "./test lvz information/akoth5.lvz"


it is in c/c++ code




LVZReader.cpp - 31.77 KB
File downloaded or viewed 24 time(s)

LVZstructures.h - 2.79 KB
File downloaded or viewed 27 time(s)
Back to top
View users profile Send private message Add User to Ignore List
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:40
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3614
Location: Las Vegas
Offline

PostPosted: Sun Jan 07, 2007 12:49 am    Post subject: Reply to topic Reply with quote

Try looking into using struct. But this depends on your processor's byte order, but assuming you are using a normal x86 processor (ie: windows, the Intel macs), this isn't a problem.
Code: Show/Hide
#pragma pack(1)

struct PacketObjectInfo2Map {
   unsigned short mapobject : 1;
   unsigned short id : 15;
   short x;
   short y;
   unsigned char imagenumber;
   unsigned char layer;
   unsigned short displaytime : 12;
   unsigned short timermode : 4;
};

#pragma pack()
The above is a sample cut from my DeBuildLVZ program. At least in Visual Studios, the #pragma pack(1) is a signal to the compiler that the following structures need to be packed to one byte boundaries. This is required, since most compilers will add in spaces so variables align on 4 byte intervals (read up on 32bit processors and how they read/write memory to understand why). The #pragma pack() at the end tells the compiler that it can go back to whatever the default is for your compiler. (For others, it is better to use push and pull so your headers can be reused in other projects that may adjust the bit packing boundaries.)

How a struct works, look at the Wikipedia article I linked to above. What do those :# things mean? They are bit fields. They allow you to pack data into space much easier than using normal bit shifting operations.

How to use them? Say you have a char* array that you know contains object data. The array should be 10 bytes long.
Code: Show/Hide
struct PacketObjectInfo2Map *objinfo;

objinfo = (struct PacketObjectInfo2Map*)myCharArray;

printf("Object ID: %d   Location: (%d,%d)\n", objinfo->id, objinfo->x, objinfo->y);
These are horrible examples, but searching about bit fields and struct will lead you to better examples of how they work.
Back to top
View users profile Send private message Add User to Ignore List Send email
grazzhoppa
Novice


Joined: Jan 03 2007
Posts: 29
Offline

PostPosted: Sun Jan 07, 2007 1:39 am    Post subject: Reply to topic Reply with quote

Thank you
Back to top
View users profile Send private message Add User to Ignore List
Bak
?ls -s
0 in


Age:24
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Sun Jan 07, 2007 2:29 pm    Post subject: Re: A good way to reading bits? (reading the lvz format) Reply to topic Reply with quote

grazzhoppa wrote:
I don't have a Windows computer, so I can't make a new .lvz to test a .lvz that uses negative numbers for those items.


You don't need windows if you use X-LvzToolkit.
_________________
SubSpace Discretion: A Third Generation SubSpace Client
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> LVZ/LVL Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 679 page(s) served in previous 5 minutes.

phpBB Created this page in 0.491811 seconds : 31 queries executed (93.7%): GZIP compression disabled