Author Topic: Map Editor Backend  (Read 1857 times)

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Map Editor Backend
« on: May 05, 2005, 04:12:29 PM »
For those that don't know, or haven't noticed. The DLL included with the map editor is a COM DLL with the TypeLibrary embedded in it. In other words, it's really easy to use the backend from any language that supports COM, like VB. To use the library, just add a reference to the TypeLibrary (or DLL with an embedded TypeLibrary). You can do this from the menu Project->References. Either find it in the list if the DLL is already registered, or browse for the DLL (VB will register it for you). You can use the object browser in VB (hit F2) to view what classes are included and what methods/parameters those classes have. It also contains some basic help strings for the things in there.

Here is an attached VB project I used just to quickly test the interface and make sure the idea would work. It demonstrates really basic useage of the backend. It's basically just a map viewer. Sorry, the map it views was hardcoded into the project since this was just an interface test, not an attempt to make a useful project. Anyways, it'll handle loading/saving of maps and tile sets. It also has some basic VOL and CLM file processing (which is why V2 of the editor can load stuff right from the VOL files). Yes, the viewer does have some really basic/sick/cheap hack scrolling implemented in it. Again, just an interface test, so I didn't care if it wasn't very good. I just needed to test the drawing code. (You have to hold left mouse button down AND move the mouse continuously. I stuck the code in the MouseMove event, so it only fires when the mouse is moving.  :blush:  Move the mouse to the corners of the view area to control the direction of the scroll.)

Please note that the backend was never finished (and hasn't been worked on in a few months either :(). Some things are incomplete, or are going to change. When I do change the interfaces, I'll change all the GUIDs so their shouldn't be any problems. Don't expect me to support a library that is compatible with this one. It is incomplete, so it's kinda silly to stay compatibile with it. The changes should be fairly minor though so it should be easy to fix up any code you write to work with a new library. So yeah, if you find something that doesn't work right or crashes, it probably wasn't finished. (I know the CLM stuff was never finished, and something else important that I'm forgetting about now).


So, if anyone wants to play around with VB, you could try making a decent map viewer that doesn't have a hardcoded map name. (Easy, with basic programming knowledge). And maybe even have some better scrolling.


Oh, and in case you were wondering, this is that secret project I've been working on for months but was all hush hush about. I've spent countless hours reading assembly to make sure I got the file formats just right, and figured out what most of the fields mean. It shouldn't have any problems in that area I hope. It was written in C++ and has grown to over 7000 lines of code. (Over 10000 lines if you count the autogenerated lines for the COM stuff). It took a few months to write, and probably a few more to complete once I get back to it. (If it can ever really be finished, or will just keep experienceing scope creep  :blink: ).

Well, enjoy.  :)  

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Map Editor Backend
« Reply #1 on: June 03, 2005, 12:03:25 AM »
I got around to fixing and testing the backend under win98. It seems to work now. I'm not sure how happy I am with the fix, but it seems to do the job and goes along the lines with how other people handled the problem.


Technical details:
The issue being that CreateFileW (the unicode version of CreateFile) doesn't seem to work on Win98 (or 95 or ME?). (Or maybe that was, it doesn't work without something extra installed). Anyways, I still use CreateFileW when possible, so unicode names should still work, but if I get a return value of 0 then I try again with the ANSI version CreateFileA. According to Microsoft's documentation, CreateFile should return INVALID_HANDLE_VALUE on error, which has the value -1. They make no mention of what a return value of 0 means, and according to their documentation, it would implicitly suggest that anything other than -1 is a valid file handle. Which is why I'm not so sure about treating 0 as an error, but other people seem to as well, and it's definately returning 0 and failing on Win98. Anyways, even if 0 is a valid value, it's would seem very unlikely that it should ever return 0 for success.

So, that's the fix and it seems to work on all versions of Windows now. I'll maybe see if I can get an official answer from Microsoft about what to do with 0.



Edit: Updated backend DLL with another bug fix. There was a problem saving tile group names which caused them to get corrupted. The map data was not currupted at all, just these text strings. The problem was I saved the wrong area of memory to the file due to an extra "&" where it shouldn't have been.

Still waiting on some info from Microsoft for the first issue. I've had a few email exchanges, and it sounds like I'm gonna get the answer I need. I guess it kinda helps to have the right question.  :P


Edit: Removed the attachment as it seems to be causing some problems for people. I'll repost it as soon as I get it fixed.
 
« Last Edit: June 15, 2005, 04:21:01 PM by Hooman »

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4954
Map Editor Backend
« Reply #2 on: June 22, 2005, 03:48:57 PM »
Ok, I got an official answer from Microsoft that was quite helpful. I've fixed the code for the backend so it should work without problems on any version of Windows now. If CreateFileW is supported, it will be used, otherwise, it will fall back on using CreateFileA.

The TileGroup naming issue was fixed. (An extra "&" where it didn't belong).

The new version of the DLL causing crashes has been determined. I'd forgotten that I'd changed some interfaces since the first version of V2 of the editor was released. Anyways, that basically broke binary compatibility, which is why the crashes occured. I didn't realize it since I ran things from the source, and it recompiled to use the new interface definitions. I would like to point out that the backend isn't finished, and neither are the interfaces, so I will likely be changing them again. I'll probably change the GUIDs though so it won't cause the same version compatibility issues. Hopefully I can finish them soon so none of this will be an issue any longer. (Yeah, I'm a COM newbie  :( ) If you downloaded an intermediate version I released here, you should probably just delete it.

As for releasing the fixed code, I'll have to speak to Hacker first. If the next editor version is almost ready, I might just get the fixed version bundled with it. If not, I'll see about digging out an older copy of the project and applying the changes to the version with the older interfaces.