Author Topic: question about map editor  (Read 12734 times)

Anonymous

  • Guest
question about map editor
« on: 2005-09-01, 01:07:21 AM »
hi, all
I'm a new guy for SGDK. I want to make a scrolling game. I find that SGDK is very useful for it. But I'm not sure that SGDK can fit all my requirement whether or not, but anyway the map editor is quite useful for the game development. So I just want to know how about the map editor for other game development? I mean, if I know the map format generated from the SGDK, can I use this map in other game?

Any help and suggestion will welcome!

frank

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
question about map editor
« Reply #1 on: 2005-09-01, 05:56:53 AM »
Yes, that's one of the purposes of the kit.  You should be able to make a map in GameDev, and use it in your own project.  You might want to make a script/program to export the map data to your own format.  This can be done by using GameDev as a COM object to load the game, use the objects inside GameDev (like ProjectObj.Maps(0).MapLayer(0).Data.MapData, which returns a byte array with one byte for each tile) to extract the pieces of the project you want in order to write them to a file in your own format.  You can also export the project to an XML file (this is a built-in feature of the IDE), which is a nicer format from which to extract data in some ways.  If you need more help on any of this, let me know.

arcus

  • Visitor
  • *
  • Posts: 8
    • View Profile
question about map editor
« Reply #2 on: 2005-09-02, 03:46:28 AM »
Thank you very much for your reply.
I still have these questions:
1. Can I paste with different size tile in SGDK?
2. When I play the game, how about the SGDK streagy of loading the map? Does it load the screens just near the sprite or the whole map?
3. It seems that SGDK can export map data into xml file. Is there any dtd file to describe the xml format? where can I find the load code of build the whole world according to the map data file?

Thanks a lot

have a nice weekend

Frank

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
question about map editor
« Reply #3 on: 2005-09-03, 09:24:03 AM »
[list=1]
[*] Each layer has its own tileset, and each tileset has only one tile size.  You must use the same tileset and tile size throughout the layer.  Of course you can have different sized graphics by combining multiple tiles in a single graphic (you could make a house out of many tiles that look like a piece of a house).  Also, each map can have multiple layers, and since each layer can have its own tileset and tile size, you can put different sized tiles on the same map by using multiple layers.  Another way to use a different tileset on a map is to create a sprite.  Even if the layer is using tileset #1 for all it's tiles, you can put a sprite using tileset #2 anywhere on any layer.
[*] SGDK loads the whole map because it is very efficient, and loading the whole map has not diminished performance.  A map containing 1 million tiles only requires 1 MB of RAM.  And 1 million tiles is quite a large map to explore (I don't think anyone has created a map this large yet).  However, it is up to the game designer to determine when sprites are activated.  It is not recommended to have all the sprites on the map active at once.  This is why there are special functions for defining when to create and delete sprites.  The goal is to only have sprites active near the player.  But it is up to the game designer to determine this in the design of their game.
[*] There is no DTD file that defines the schema of the XML document.  I have not been able to determine how a DTD file could be used with GameDev's XML file so I didn't bother creating one.  If you have the GameDev source code, there are two pieces of code you might want to look at:
    [*] in Map.cls there is a function called "Load" that reads the entire contents of a .MAP file into memory.  This code in the Load function reads the tiles from the map file and stores them in the layer's data in memory:
    Code: [Select]
    ReDim BA(0 To Layers(I).Columns * Layers(I).Rows - 1) As Byte
    Get #FF, , BA
    Layers(I).Data.MapData = BA

    [*] In GameDev.bas there is a function called XML2Prj that loads an entire project (all GDP and MAP data) from an XML file into memory.  The following line in this function is the line that loads all the tiles from an XML element into a layer in a map:
    Code: [Select]
    NewMap.MapLayer(J).Data.MapData = oLevel4Node.selectSingleNode("Tiles").nodeTypedValue
    [/list]
    [/list:o]

    guest

    • Guest
    question about map editor
    « Reply #4 on: 2005-09-06, 12:01:17 AM »
    Hi!
    Maybe my question is similitude as the previous question.

    I want to make a 2d game by myself. I use visual c++.net. I found it's best use the scrolling gamedev to editor the map, for it is powerful. But I didn't know how load the files in my c++ project, when I create a map use GameDev. Is there anyway?

    Frank,

    arcus

    • Visitor
    • *
    • Posts: 8
      • View Profile
    question about map editor
    « Reply #5 on: 2005-09-06, 02:52:39 AM »
    It is so happy meet the same name guy in this topic.
    I have a question, how about the format of map, xml or other format. I don't like xml because of the efficiency. I see some other map data file in the gamedev, and how can I read this map information into memory.

    Thanks a lot

    Frank

    bluemonkmn

    • SGDK Author
    • Administrator
    • Fanatic
    • *****
    • Posts: 2761
      • ICQ Messenger - 2678251
      • MSN Messenger - BlueMonkMN@gmail.com
      • View Profile
      • http://sgdk2.sf.net/
      • Email
    question about map editor
    « Reply #6 on: 2005-09-06, 06:24:50 PM »
    As I wrote above, the Map.cls file has a Load function that will demonstrate how to read the map file directly from the .MAP file that GameDev created.  Do you need help converting this code to C++ code that will read the file?

    arcus

    • Visitor
    • *
    • Posts: 8
      • View Profile
    question about map editor
    « Reply #7 on: 2005-09-06, 07:26:06 PM »
    Quote from: "bluemonkmn"
    As I wrote above, the Map.cls file has a Load function that will demonstrate how to read the map file directly from the .MAP file that GameDev created.  Do you need help converting this code to C++ code that will read the file?

    yes, it is exactly what I want.  Would you please to give me some help for this?

    Thanks a lot
    Frank

    bluemonkmn

    • SGDK Author
    • Administrator
    • Fanatic
    • *****
    • Posts: 2761
      • ICQ Messenger - 2678251
      • MSN Messenger - BlueMonkMN@gmail.com
      • View Profile
      • http://sgdk2.sf.net/
      • Email
    question about map editor
    « Reply #8 on: 2005-09-07, 06:16:21 AM »
    I don't have time to write the whole C++ procedure for you, but I can get you started at understanding the VB code so you can write the C++ code.

    The first thing to understand about the file format of the .MAP file is that it consists of many sections.  Each section contains a 4-character header followed by a 32-bit integer representing the length in bytes of that section.  The one exception is the BMGC section which has a version number between the header and the section length.  For example, the file I am looking at has BMGC0005 as the first 8 bytes.  The next byte is 0x12 (hex 12 = decimal 18) followed by 3 zero-bytes.  That represents a long integer whose value is 18.  So the next 18 bytes represent the BMGC section, and immediately after that is the "LYRS" section header.

    You will see that the first line that reads the file is "Get #FF, , S".  Since S is a string containing 4 characters, this will read 4 characters (8-bit characters) from the file.  You will see that the code is verifying that the first 4 characters are "BMGC" which is the signature for the beginning of the .MAP file.

    Next it does "Get #FF, , S" again which reads the next 4 characters.  These 4 characters represent the version of the MAP file as a string.  For example, "0005" represents a map file from GameDev version 1.4.x.

    Next it does "Get #FF, , SLen".  Since SLen is declared as a "Long", it will read a 32-bit integer from the file.  This integer represents the length of the map header section of the file before you get to the LYRS section.  It is the number of bytes after the end of this integer and before the "LYRS" signature.

    Next it does Get #FF, , PixWidth, which you will see is a property of the Map object at the top of the file.  It is declared as a Long, so it too will read a 4-byte (32-bit) integer from the file.  This integer represents the map width entered by the user (the width of the map in pixels).

    Get #FF, , PixHeight is treated similarly.

    Next you see BackgroundMusic = LoadString(FF).  The LoadString function will perform two main steps.  It reads a long integer from the file.  Then it creates a string whose length matches that integer and reads that many characters into the string.  This particular string represents the name of the background music clip for this map.

    Next you will see that it reads a long integer called BackgroundColor from the file, but only if the version of the file is greater than 4 (because background color did not exist before version 1.3).  

    If you continue to follow the function through like this you can identify every byte in the MAP file format.  I don't have time to finish the entire description here, but this is a basic picture of what has been covered so far:

    "BMGC" - map header signature
    "000n" - 4-character string representing map version (0005 is 1.4.x)
    32-bit int - length of remainder of BMGC section
    32-bit int - Pixel width of this map
    32-bit int - Pixel height of this map
    32-bit int - length of background music string
    <string> - name of background music for this map (length determined above)
    VERSION 4 OR LATER: 32-bit int - background color of this map

    Is this helpful at all?  Can you proceed to understand more of the function based on this and let me know where you get stuck or are you completely lost still?

    arcus

    • Visitor
    • *
    • Posts: 8
      • View Profile
    question about map editor
    « Reply #9 on: 2005-09-09, 03:25:24 AM »
    Thanks greatly for the reply.
    I follow the guideline as you say, and meet some problem.
    e.g.,

    "code
    AddLayer LName, LTDName, LXR, Lyr, LTrans > 0
    .............
    ReDim BA(0 To Layers(I).Columns * Layers(I).Rows - 1) As Byte
    Get #FF, , BA
    Layers(I).Data.MapData = BA "

    1,"Layers(I).Data.MapData" This code is related to BMDXCtls.dll, would you please give more detail information about the BMDXCtls.dll? And can you describe the relationship among the layer, map, tileset and so on from the code side?  For example, which class is related to these object and there relationship.
     
    2,What is the information include in "BA"?

    thanks a lot
    have a nice weekend

    Frank

    bluemonkmn

    • SGDK Author
    • Administrator
    • Fanatic
    • *****
    • Posts: 2761
      • ICQ Messenger - 2678251
      • MSN Messenger - BlueMonkMN@gmail.com
      • View Profile
      • http://sgdk2.sf.net/
      • Email
    Map file format
    « Reply #10 on: 2005-09-09, 06:23:40 AM »
    BMDXCtls.dll is written in C++ so it should be easier to read if you are a C++ programmer.  The source code is available on SourceForge in the project where you can find the GameDev source code.  Included in the source code is a help file for BMDXCtls to understand the interface.  However, I don't think you need to get any of BMDXCtls because BA is quite simple, and you don't need to look at BMDXCtls to understand it.  BA is simply an array of bytes.  Each layer on a map has tiles on it.  Each tile is one byte.  When the Load function reads BA from the file, the size of BA is Columns * Rows where Columns is width of the layer in tiles and Rows is the height of the layer in tiles.  So the total number of tiles is Columns * Rows -- 1 byte for each tile.  The first byte represente the tile at the top left corner of the layer.  The next byte is the tile to the right of that.  The last byte is the tile at the lower right corner of the map.

    Each byte in a layer represents an index into the tileset where the graphic for that tiel can be found.  Each layer refers to only 1 tileset.  And if the first byte on the layer is 3, then the tile that should be drawn on the layer in that position is number 3 from teh tileset.  The tileset indexes start from 0, so tile number 3 is the fourth tile in the tileset.  A map is just a collection of layers, and each layer can have its own tileset.  Each layer has its own size too (because the tile sizes on the layers might be different and the scroll rates might be different too).

    Does this help?

    arcus

    • Visitor
    • *
    • Posts: 8
      • View Profile
    question about map editor
    « Reply #11 on: 2005-09-13, 02:06:06 AM »
    hi,
    I have another question.
    In the .map file, I can only read the tileset name, such as
                Get #FF, , SLen
                LTDName = Space$(SLen)
                Get #FF, , LTDName
    but I cannot get the image location information or the which image assciated with this tileset name, how can I get these information? Because without this, I cannot paste image according to a layer in my application.

    Thanks a lot
    Frank

    bluemonkmn

    • SGDK Author
    • Administrator
    • Fanatic
    • *****
    • Posts: 2761
      • ICQ Messenger - 2678251
      • MSN Messenger - BlueMonkMN@gmail.com
      • View Profile
      • http://sgdk2.sf.net/
      • Email
    GDP
    « Reply #12 on: 2005-09-13, 05:19:54 AM »
    The locations of the files (maps and tilesets etc) are all located in the GDP file, not the MAP file.  I hope that's not a problem.  The GDP file is plain text (you can read it in notepad).  So I don't think you need me to describe the format of the GDP file.  But I am very interested to hear how this turns out.  Please come back and let me know of your success!  Of course I'll be happy to answer any more questions you may have too.

    When you are done, if you are willing to share your C++ code that loads the MAP file and the GDP file, there may be others who would be interested.  I could post the code that does this (and give you credit of course) if you're interested.  I have always wanted a GameDev runtime engine written in C++, but I've never had the motivation to do it myself -- how many of GameDev's features will be implemented/supported in your engine?  This sounds very interesting!

    arcus

    • Visitor
    • *
    • Posts: 8
      • View Profile
    question about map editor
    « Reply #13 on: 2005-09-13, 11:39:37 PM »
    Thank you very much for help.
    I want to make a scrolling game, and I hope to use GameDev as the map editor. While for the basic game logic, I will create it in c++ with DirectX. And I'm still not sure whether I can use GameDev's physics and script system?
    Anyway I will share the c++ code when the work is done?

    thanks a lot
    frank

    bluemonkmn

    • SGDK Author
    • Administrator
    • Fanatic
    • *****
    • Posts: 2761
      • ICQ Messenger - 2678251
      • MSN Messenger - BlueMonkMN@gmail.com
      • View Profile
      • http://sgdk2.sf.net/
      • Email
    Reusing GameDev
    « Reply #14 on: 2005-09-14, 05:29:59 AM »
    If you want to use GameDev's physics system, you'd either need to use the engine itself (GDPlay.exe) to play the game, or re-create the logic within the engine in your own code.  GameDev's scripting system is just VBScript, but if you want all the same objects exposed, once again, you'd have to use GameDev's engine to play the game.  The ScrHost.dll is the wrapper for GameDev's VBScript support, but it doesn't contain any of the GameDev objects used in scripting -- those are all inside GDPlay.exe.

    You could use GameDev's physics system without actually using GameDev to run the game by interacting with GDPlay.exe as a COM object.  You can call the methods in GDPlay.exe to load the project and manage the sprites etc, and you could do all the drawing on your own.  But if you do that, I think you should not write an EXE because communicating from one EXE to another EXE is slow if you make many calls (and I think checking on the status of all the sprites would involve many calls to GDPlay.exe).  If you write it as a DLL, though, then you could have some external launcher -- the achitecture would go something like this:
    1. Launcher.exe: Load GDPlay.exe
    2. Launcher.exe: Load MyGame.dll
    3. Launcher.exe: Connect MyGame.dll to GDPlay.exe
    4. Launcher.exe: Pass control to MyGame.dll (MyGame.Play() )
    5: MyGame.dll: Tell GDPlay.exe to load project
    6. GDPlay.exe: Loads all project data
    7. MyGame.dll: Load your own copy of the project?
    8. MyGame.dll: Tell GDPlay to Initialize Map1
    9. GDPlay.exe: Initializes its copy of Map1 and creates all the sprite objects
    10. MyGame.dll: Begin game -- initialize your own copy of the project and begin playing.
    11. MyGame.dll: Draw the tiles for Map1 in your own engine
    12. MyGame.dll: Tell GDPlay to move the sprites for Map1
    13. GDPlay.exe: Moves all the sprites in its copy of the project data
    14. MyGame.dll: Draw the sprites in the positions determined by GDPlay's copy of the project.
    15: Go to step 11.

    Of course it would be easier to only load one copy of the project in GDPlay.exe, and let GameDev do the drawing, but it sounds like you want to write your own code to draw the map, which complicates things a bit.