SSGNet Forums: LVZ module - SSGNet Forums

Jump to content

  • 5 Pages
  • 1
  • 2
  • 3
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

LVZ module a.k.a. The newbie's guide to make a module

#1 User is offline   Samapico 

    • Group: Administrators
    • Posts: 7,664
    • Joined: Jun 11, 2004
    • Zone:SSCU 17th Parallel
    • Squad:-=SMG=-

    Posted 18 December 2009 - 02:38 PM

    Ok, I want to make a module to handle LVZ files. I'm making this topic for any kind of questions I'll have along the way, especially to keep the design of the module consistent with the rest.

    For the moment I just skimmed real quick through the other available modules.

    I'm guessing the modules I'll need to reference are: UniqueImage, Animations, Level, ...
    Though I'm not exactly sure which would be for what purpose. Do you draw the entire map virtually, and some module will handle the actual rendering? Or do you have somewhere where you refresh the whole screen to draw stuff?


    Edit: On a side note, I hate eclipse... What's the difference between .so files and .dll's? I'm guessing VS will build dll's, can they coexist with the other .so modules already built?

    Edit2: lol wtf... f***** thing raped my folders. Import screwed up badly. Can't even delete that shit, filenames too long http://www.ssforum.n...tyle_emoticons/default/help.gif
    Yeah... switching to VS

    Edit3: Managed to get rid of these folders... it involved renaming folders to 'a' to make the path shorter, and cut/pasting a part of it to the root of the drive

    Attached thumbnail(s)



    #2 User is offline   Bak 

      • Group: Project Moderators
      • Posts: 1,027
      • Joined: Jul 21, 2004

      Posted 18 December 2009 - 03:45 PM

      Uh that path is definitely wrong (svn did that?) If you copy the selfship module, make SURE that you delete the .svn folder, as it will be invalid. You can then readd the correct folder to the repository using "svn add " and it will create the proper .svn folder. Give eclipse another chance it's wonderful.

      .so and .dll are the same exact thing. Having two different extensions was pointless and only caused more trouble.

      For LVZ, I would use the SettingsHandler->updateSetting function to add settings in the [Animation] and [UniqueImage] section as it expects (look in the default config file for animations settings), and then use the Animations module exclusively which will load from the settings you create (treating static images as 1 frame animations, much like I suspect continuum does). One thing I noticed that Animations doesn't support yet is screen coordinates (ScreenObjects). Mapobjects seem doable now though. I don't think you need to mess with Level*. You'll probably want to use Utilities to decompress the .lvz file.

      #3 User is offline   Samapico 

        • Group: Administrators
        • Posts: 7,664
        • Joined: Jun 11, 2004
        • Zone:SSCU 17th Parallel
        • Squad:-=SMG=-

        Posted 18 December 2009 - 03:51 PM

        The path crap was when I did something with eclipse, tried to import a project, or something like that... it decided to import it recursively or something.

        Thanks for the heads up

        #4 User is offline   Samapico 

          • Group: Administrators
          • Posts: 7,664
          • Joined: Jun 11, 2004
          • Zone:SSCU 17th Parallel
          • Squad:-=SMG=-

          Posted 19 December 2009 - 01:59 PM

          hmmm, I think I'm starting to get the hang of eclipse a bit;
          but I'm wondering, with Visual Studio you could make a huge "Solution" that contains every project, and you could mass-build them, or work them individually. Is there a way to do the same with eclipse? Or do I need to get another junk to use the makefile thing?

          ----------------------

          And is there any reason why you're not using classes entirely? Correct me if I'm wrong: Each module has a class with the public functions (declared as function pointers), and the functions are defined in the .cpp as a public function, and these functions are assigned to the function pointers when the module is initialized...
          Why not simply use classes, with public functions for interface, and private for the rest? Is it easier to do some part (maybe memory protection?) if all the data is simply public?

          ----------------------

          Callbacks... basically they're events that a module can trigger, and another module could "listen" for a specific callback and do something about it, right? For example, I could have a callback that says a specific LVZ file is done loading (or all lvz's requested are loaded, or they didn't load right), and whatever module loads the map/graphics when entering an arena will have to wait for this before loading stuff, cause the lvz might override graphics. (Or not, since it would just be a function call, no delay involved)

          I'll also need to somehow listen for the objon/off/set/move packets, and mess with the animations. I think I seen some code that told the Net module to pass on every packet about "something", or something like that... Anyway, I'll start by unpacking some lvz's http://www.ssforum.n...tyle_emoticons/default/blum.gif

          ----------------------

          If I understand it right, I'd use SettingsHandler to add [Animations] (these settings are regenerated entirely for each arena, correct?)
          Then I'd use UniqueImage because some images can belong to thousands of animations.
          Then I'd start/stop the animations through the Animation interface.

          That makes sense? This will be able to handle 65000 map objects?

          ----------------------

          I see you use BOOL's and bool's, any reason for this, or it just depends on your mood?

          #5 User is offline   Bak 

            • Group: Project Moderators
            • Posts: 1,027
            • Joined: Jul 21, 2004

            Posted 20 December 2009 - 04:31 PM

            Quote

            hmmm, I think I'm starting to get the hang of eclipse a bit;
            but I'm wondering, with Visual Studio you could make a huge "Solution" that contains every project, and you could mass-build them, or work them individually. Is there a way to do the same with eclipse? Or do I need to get another junk to use the makefile thing?

            Eclipse has a notion of a workspace, which contains projects. Try to change your current workspace (use file menu) to the Modules folder; there should be an eclipse workspace file there with all the modules included (if I added it to the svn). If not, tell me and I'll add it. You can then build all projects (which, for me, is faster than build solution in VC++, by the way), or build individual projects.

            Quote

            And is there any reason why you're not using classes entirely? Correct me if I'm wrong: Each module has a class with the public functions (declared as function pointers), and the functions are defined in the .cpp as a public function, and these functions are assigned to the function pointers when the module is initialized...
            Why not simply use classes, with public functions for interface, and private for the rest? Is it easier to do some part (maybe memory protection?) if all the data is simply public?

            The way dll export works is in plain C (see the expansion of the DLLEXPORT macro), so using anything public functions and such is out of the question. Maybe that's not a perfect answer because I don't understand dynamic loading completely. This was the way MervBot and ASSS did it, so it's the way I do it. If you want to use classes within a specific module to better organize your code, feel free.

            Quote

            Callbacks... basically they're events that a module can trigger, and another module could "listen" for a specific callback and do something about it, right? For example, I could have a callback that says a specific LVZ file is done loading (or all lvz's requested are loaded, or they didn't load right), and whatever module loads the map/graphics when entering an arena will have to wait for this before loading stuff, cause the lvz might override graphics. (Or not, since it would just be a function call, no delay involved)

            I'll also need to somehow listen for the objon/off/set/move packets, and mess with the animations. I think I seen some code that told the Net module to pass on every packet about "something", or something like that... Anyway, I'll start by unpacking some lvz's http://www.ssforum.n...tyle_emoticons/default/blum.gif

            Yes callbacks are events you listen to, which are sort of like interrupts. Rather than periodically polling if a player has died, it's much cleaner to simply say "call this function when a player dies". This is the idea with callbacks. For the packets, however, you'll want to do the following:

            register and wait for the CB_REGPACKETS callback to occur, then call Net::regPacketFunc for any packets they wish to handle. regPacketFunc takes in a string for the type of packet you want to listen for and a callback-like function. The packet types and relevant fields are defined in conf/modules/net.conf in the [Packet Templates] section. grep for regPacketFunc to see some examples.


            Quote

            If I understand it right, I'd use SettingsHandler to add [Animations] (these settings are regenerated entirely for each arena, correct?)
            Then I'd use UniqueImage because some images can belong to thousands of animations.
            Then I'd start/stop the animations through the Animation interface.

            That makes sense? This will be able to handle 65000 map objects?

            You are correct, yes there is no limit to the number of map objects save the computer's memory (also, don't reuse animation names and/or unique image names, obviously).


            Quote

            I see you use BOOL's and bool's, any reason for this, or it just depends on your mood?

            Ideally I should use bools everywhere except in interface functions (since they get exported as C, although honestly I don't think it matters). I didn't pay too much attention to this, admittedly.

            #6 User is offline   Samapico 

              • Group: Administrators
              • Posts: 7,664
              • Joined: Jun 11, 2004
              • Zone:SSCU 17th Parallel
              • Squad:-=SMG=-

              Posted 20 December 2009 - 07:38 PM

              Awesome, all makes sense

              #7 User is offline   Samapico 

                • Group: Administrators
                • Posts: 7,664
                • Joined: Jun 11, 2004
                • Zone:SSCU 17th Parallel
                • Squad:-=SMG=-

                Posted 20 December 2009 - 10:51 PM

                Holy crap, I just used a union for the first time in my life (to make something useful, that is)

                typedef struct LvzObjectDefinition
                {
                        unsigned isMapObject    :1;
                        unsigned objectID               :15;
                
                        union /* Unnamed union */
                        {
                                struct
                                {
                                        signed   xCoord                 :16;
                                        signed   yCoord                 :16;
                                }mapObjectCoord;
                                struct
                                {
                                        unsigned xReference             :4;             //Coordinate reference in x
                                        signed   xCoord                 :12;    //X coordinate
                                        unsigned yReference             :4;             //Coordinate reference in y
                                        signed   yCoord                 :12;    //Y coordinate
                                }screenObjectCoord; //Only used for CLV2 screenobjects
                        };
                
                
                        unsigned imageNumber    :8;
                        unsigned objectLayer    :8;
                        unsigned displayTime    :12;
                        unsigned displayMode    :4;
                } LvzObjectDefinition;
                


                #8 User is offline   Samapico 

                  • Group: Administrators
                  • Posts: 7,664
                  • Joined: Jun 11, 2004
                  • Zone:SSCU 17th Parallel
                  • Squad:-=SMG=-

                  Posted 20 December 2009 - 11:27 PM

                  I hate the STL lists and crap... I feel like copy-pasting Mervbot's implementation of linked list... so much easier to use http://www.ssforum.n...tyle_emoticons/default/blum.gif

                  #9 User is offline   Samapico 

                    • Group: Administrators
                    • Posts: 7,664
                    • Joined: Jun 11, 2004
                    • Zone:SSCU 17th Parallel
                    • Squad:-=SMG=-

                    Posted 20 December 2009 - 11:44 PM

                    Ok, it's kinda late, it's probably nothing but...

                    Trying to load my LVZ module; placed it in bin\modules\lvz, added it in modules.conf,
                    and when I run discretion.bat, I get:

                    Using debug terminal trick... (cskinviewer ..\main.cpp, line 1788)
                    Zone description does not contain update site!
                    SUCCESS: CHECK FOR UPDATES SUCCEEDED!
                    SEGFAULT - debug information printed to bin/errorlog.txt

                    Do I need to hack out some security check or something? (and wtf is the debug terminal trick?)

                    #10 User is offline   Bak 

                      • Group: Project Moderators
                      • Posts: 1,027
                      • Joined: Jul 21, 2004

                      Posted 21 December 2009 - 09:44 AM

                      debug terminal trick is having SDL print to the terminal, which normally I would need to recompile SDL since the normal output goes into .txt files (look at the FrontEnd/cskinviewer project near the start of main if you're interested).

                      There is no security check for what you are doing, your module is simply crashing (segment fault = crash). You might check the bin/errorlog.txt file which may or may not contain useful information. If you can't find it attach your code and I'll take a look.

                      #11 User is offline   Samapico 

                        • Group: Administrators
                        • Posts: 7,664
                        • Joined: Jun 11, 2004
                        • Zone:SSCU 17th Parallel
                        • Squad:-=SMG=-

                        Posted 21 December 2009 - 10:14 AM

                        ok thanks... I didn't assign the interface function pointers properly in the init... works now. I think I'm almost done with step 1: Open a lvz file and scan all the data in it (easy)

                        step 2: Save the files somewhere (easy)

                        step 3: Open the lvz files after they were downloaded, while loading the level (medium) (Does ASSS already sends the lvz files to it? Or does the client have to request them?)

                        step 4: Create UniqueImages and Animations for the mapobjects (hard)

                        step 5: Make Animations support screenobjects (easy I guess)

                        step 6: Make it override default graphics with the files in the lvz's (no idea)

                        #12 User is offline   Samapico 

                          • Group: Administrators
                          • Posts: 7,664
                          • Joined: Jun 11, 2004
                          • Zone:SSCU 17th Parallel
                          • Squad:-=SMG=-

                          Posted 21 December 2009 - 11:48 AM

                          Gotta love that debugging phase where you keep getting one step working at a time... adding printf's everywhere, then the console is clogged with crap http://www.ssforum.n...tyle_emoticons/default/blum.gif


                          Getting somewhere...
                          Spoiler


                          Only problem is, there isn't 196608 objects in that LVZ, and there isn't 0 image definitions either http://www.ssforum.n...tyle_emoticons/default/blum.gif
                          I was fread'ing from the file that part, but it was already read and decompressed in a byte buffer... bleh.

                          #13 User is offline   Samapico 

                            • Group: Administrators
                            • Posts: 7,664
                            • Joined: Jun 11, 2004
                            • Zone:SSCU 17th Parallel
                            • Squad:-=SMG=-

                            Posted 21 December 2009 - 12:35 PM

                            Almost there...
                            Spoiler


                            It skipped about 4 image definitions at the beginning, so it messed up at the end too... hmm... I hope fread()'ing a struct with unions in it works fine...
                            It seems this LVZ doesn't even have screenobjects, so there's definitely something wrong in there



                            Oh well... c++ is dumb... sizeof(a struct with unions) = combined size of the unions
                            wadafak?
                            typedef struct
                            {
                                    unsigned isMapObject    :1;
                                    unsigned objectID               :15;
                            
                                    union /* Unnamed union */
                                    {
                                            struct
                                            {
                                                    signed   xCoord                 :16;
                                                    signed   yCoord                 :16;
                                            }mapObjectCoord;
                                            struct
                                            {
                                                    unsigned xReference             :4;             //Coordinate reference in x, see LvzScreenObjectReference
                                                    signed   xCoord                 :12;    //X coordinate
                                                    unsigned yReference             :4;             //Coordinate reference in y, see LvzScreenObjectReference
                                                    signed   yCoord                 :12;    //Y coordinate
                                            }screenObjectCoord; //Only used for CLV2 screenobjects
                                    };
                            
                            
                                    unsigned imageNumber    :8;
                                    unsigned objectLayer    :8;
                                    unsigned displayTime    :12;
                                    unsigned displayMode    :4;
                            } LvzObjectDefinition;

                            Aren't the 2 32bits structs in the union supposed to share the same memory space?
                            I also tried to typedef the union on its own, then use a field of that type in the big struct, but got the same result.
                            sizeof(LvzObjectDefinition) gives me 12 bytes instead of 10

                            #14 User is offline   Bak 

                              • Group: Project Moderators
                              • Posts: 1,027
                              • Joined: Jul 21, 2004

                              Posted 21 December 2009 - 02:44 PM

                              two notes: the way you're doing it you probably need to #pragma pack(1) to make sure there's no bytes buffering structures, which I suspect is what is happening.

                              However, that method not compatible across platforms (And pragma pack is the devil), so is there anyway you could manually read a u32 and pick out the bits by hand and store them in the appropriate structure? It's not much more work but it's full proof in terms of compatibility across platforms.

                              So for example something like

                              u8 rawData[10];
                              
                              while (fread(rawData, sizeof(rawData),1, f))
                              {
                                LvzObjectDefinition l;
                              
                                l.isMapObject = (rawData[9] & 0x80) ? 1 : 0;
                                l.objectId = ((rawData[9] & 0x7F) 
                              

                              Quote

                              Open the lvz files after they were downloaded, while loading the level (medium) (Does ASSS already sends the lvz files to it? Or does the client have to request them?)
                              Yes all files will be downloaded correctly, including lvz files. It will be put in the zone's path. I believe UniqueImage will check the zone's path when looking for images, which override the default graphics path.

                              #15 User is offline   Samapico 

                                • Group: Administrators
                                • Posts: 7,664
                                • Joined: Jun 11, 2004
                                • Zone:SSCU 17th Parallel
                                • Squad:-=SMG=-

                                Posted 21 December 2009 - 03:22 PM

                                hmmm, is the padding only at the end of the whole struct?

                                Could I just do:

                                for (ii = 0; ii 
                                
                                ??

                                I got the data already in a larger byte buffer, I don't even need to fread() them individually.
                                I hate using a magic number (10) in there, but it would be so much easier http://www.ssforum.n...tyle_emoticons/default/blum.gif

                                #16 User is offline   Samapico 

                                  • Group: Administrators
                                  • Posts: 7,664
                                  • Joined: Jun 11, 2004
                                  • Zone:SSCU 17th Parallel
                                  • Squad:-=SMG=-

                                  Posted 21 December 2009 - 04:05 PM

                                  And now that I think about it... another struct I use has 3 i16 fields, and its sizeof() comes out as 6... so why can't this one be 10? The bitfields messing it up?

                                  #17 User is offline   Bak 

                                    • Group: Project Moderators
                                    • Posts: 1,027
                                    • Joined: Jul 21, 2004

                                    Posted 21 December 2009 - 09:29 PM

                                    gcc supports pragma pack, use this one if you want:

                                    #pragma pack(push, 1)
                                    struct LvzObjectDefinition 
                                    {
                                    unsigned isMapObject    :1;
                                    unsigned objectID               :15;
                                    
                                    union /* Unnamed union */
                                    {
                                                    struct
                                                    {
                                                                    signed   xCoord                 :16;
                                                                    signed   yCoord                 :16;
                                                    }mapObjectCoord;
                                                    struct
                                                    {
                                                                    unsigned xReference             :4;             //Coordinate reference in x, see LvzScreenObjectReference
                                                                    signed   xCoord                 :12;    //X coordinate
                                                                    unsigned yReference             :4;             //Coordinate reference in y, see LvzScreenObjectReference
                                                                    signed   yCoord                 :12;    //Y coordinate
                                                    }screenObjectCoord; //Only used for CLV2 screenobjects
                                    };
                                    
                                    
                                    unsigned imageNumber    :8;
                                    unsigned objectLayer    :8;
                                    unsigned displayTime    :12;
                                    unsigned displayMode    :4;
                                    };
                                    #pragma pack(pop)
                                    


                                    My concern is that fread on a structure (or casting from a byte array) will vary depending on the endianness of the architecture. http://www.gamedev.n...article2091.asp . Then again, I'm pretty sure I fread a structure when reading in the tileset, so it may not be a huge deal; up to you.

                                    #18 User is offline   Samapico 

                                      • Group: Administrators
                                      • Posts: 7,664
                                      • Joined: Jun 11, 2004
                                      • Zone:SSCU 17th Parallel
                                      • Squad:-=SMG=-

                                      Posted 22 December 2009 - 10:57 AM

                                      (I thought I posted this, but apparently I didn't hit the big button)
                                      I don't need to fread the struct, cause the block is read as one byte block of a definite size, uncompressed, and only then I know it's a bunch of object definitions. So I just scroll through the byte buffer.
                                      But thanks, that pack push, pop thing seems to work fine

                                      #19 User is offline   Samapico 

                                        • Group: Administrators
                                        • Posts: 7,664
                                        • Joined: Jun 11, 2004
                                        • Zone:SSCU 17th Parallel
                                        • Squad:-=SMG=-

                                        Posted 22 December 2009 - 11:19 AM

                                        Some projects use SDL/... includes. It gives me unresolved inclusion errors. I can see where the required files are at, but what's the trick to get eclipse to look for them?

                                        #20 User is offline   jabjabjab 

                                          • Group: Members
                                          • Posts: 794
                                          • Joined: Aug 17, 2003
                                          • Zone:SSCU Trench Wars`
                                          • Squad:MainFrame

                                          Posted 22 December 2009 - 11:24 AM

                                          So Im guessing Samapico is officially a programmer for Discretion?

                                          Share this topic:


                                          • 5 Pages
                                          • 1
                                          • 2
                                          • 3
                                          • Last »
                                          • You cannot start a new topic
                                          • You cannot reply to this topic

                                          1 User(s) are reading this topic
                                          0 members, 1 guests, 0 anonymous users