don't click here

Utility Captain PlaneEd

Discussion in 'Engineering & Reverse Engineering' started by Clownacy, Apr 1, 2016.

  1. Clownacy

    Clownacy

    Tech Member
    1,053
    581
    93
    Old April Fools' post:
    Greetings. I am here today to address a matter of utmost importance.

    For decades, the Ed family has enjoyed a glorious reign, ushered into being by our founder, SonED, whose brilliance radiated down onto the groveling masses, bringing us into our golden age. SonED's magnificence remained unsullied, as its great legacy was honoured by its successor, SonED2. When the time came for SonED2 to entrust the crown to SonMapEd, the legatee pursued its dreams of travelling to exotic lands, extending the Ed family's reach. In time, no name would be more known, and more feared, than SonMapEd's. Indeed, it was as if SonED's majesty was lost to the world.

    Alas, SonMapEd met an unfortunate end before its time, and corners of the world remained unenlightened by the Ed family's righteous glow. It was then that PlaneEd headed the Ed name, at a pitifully young age. PlaneEd looked up to its successor, and its heart was set on fully-realising the late master's dream.

    Fate, however, would not be so kind: the tragic death of the heir's sibling, SpecialEd, who was closer to the young heir than anyone else, devastated it, and sent its life in a downwards spiral.

    Deaf to the divine will of SonED, and driven by sorrow, PlaneEd forever tarnished the Ed family name, allowing the unclean to crawl from the filthy corners of the world, and clamber to positions of power. Vermin like SonLVL, Flex, SoniPlane, these lowest of the low took what was rightfully ours, and PlaneEd turned a blind eye to it all.

    But no longer.

    Today, the glorious Ed family makes its grand ret-
    *cough* ...okay, I'll stop.

    [​IMG]

    What is this?
    This is a fancy-pantsy improved version of the original PlaneEd, featuring a port to SDL2, a bugfix here and there, and a disgusting amount of Windows-ification. Hey, the original PlaneEd only seemed to work on Windows, anyway, so nothing of value was really lost.

    Well, what does any of that mean?
    First up, the port from SDL1 to SDL2, along with opening the project up to SDL2's feature pool, also allows the resizing of the window, without me having to implement some kind of software upscaler. This means you can actually see what you're doing. This also lets me use SDL_ShowSimpleMessageBox, which I use to display error messages, instead of immediately quitting and hoping people read the stdout/stderr files.

    The bugfixes I've made are rather minor. First up, using the original PlaneEd, open the Sonic and Miles animated background.txt file in the PlaneEd Projects folder of the S2 Git disasm. You'll notice the gaps in between the repeating 'SONIC's are an odd shade of blue/purple, while, in Captain PlaneEd, it's the same colour as what you'd see in the actual game. This is because PlaneEd stores the palette data in memory as BGR, but one section of code reads it as RGB. I accidentally fixed this when I converted the palette data to RGB while it's being loaded to memory, rather than during tile generation (which, might I add, SDL2 is very picky about). An odd bugfix in the original PlaneEd caused a crash if you tried to copy and paste anything while editing the S1 Git disasm's Title Screen.txt project. Removing this hackish bugfix eliminated that problem, but because the bug it was meant to prevent wasn't documented, I have no idea what side-effects that might have.

    Finally, there's the mess that is the Windows-ification. No longer do you have to drag-and-drop files onto the EXE, or start it with the command prompt, to get it to work. Now, you can simply double click on the program, and be presented with a blank window with a Windows-style menu bar, from which you can select File, Open, and navigate to your projects in a much more natural way. Be aware, not everything has a Windows button for it yet. Heck, the only things the menu bar does at the moment is Open, Save, Close, and Exit. You still have to get used to the Function Keys to do anything practical. There's also a View option, which allows you to select a background colour for the window, so you can see your tiles better, in the event that they happen to blend in with the default background.

    I also replaced the stripped down KENS library with the full-fledged KENSC library, allowing access to Comper(?), Moduled Kosinski(??), and Saxman(???), for all your oddball needs. The mappings can also be in whatever compression you want (except Kid Chameleon), and not just uncompressed and Enigma. Because, you know, people do that.

    This thing should be completely backwards-compatible with regular PlaneEd projects, as much as I would love to introduce a required header, so any old file cannot be accidentally loaded...

    PlaneEd sucks, why would you do this?
    I wanted to learn C++. I've also had a pretty rough time with the SoniPlane editor in the past, so I figured, why not make my own ('own' being in huge quotation marks). I needed something to do for April Fools' anyway.

    Links
    Download
    GitHub source repo
    (This thing should be LGPLv2.1, but PlaneEd's original source never made it too clear)

    Credits
    From the original PlaneEd:
    • qiuu: for writing the original program
    • The KENS library authors: for making KENS available
    • Damian Grove: for the documentation and code of the Kid Chameleon compression format
    • Puto: for consulting on license issues and trying to run it under Mac OS (which sadly failed)
    • the #boom crew: for beta-testing - any bug you encounter is their fault :p
    Captain PlaneEd:
    • flamewing: KENSC library
    • Clownacy: working on the code, when people would rather just complain about it =P

    [​IMG]

    Captain PlaneEd is a modified version of PlaneEd, sporting a basic menu bar as well as bugfixes and under-the-hood changes such as a rebase from SDL1 to SDL2.

    Download
     
    Last edited: Feb 28, 2024
  2. qiuu

    qiuu

    Tech Member
    144
    9
    18
    Blue Ball & Blocks
    I'm surprised someone's actually willing to go through my horribly structured old code. :)/> Especially considering that SoniPlane and RetroGraphics Toolkit are also open source (then again, I've never looked at their source so maybe they are just as bad? :P) Considering you went through the trouble of porting it to SDL2 and adding a toolbar, I wonder if a complete re-write wouldn't have been less work. Either way, I appreciate your effort! And as for the licence, LGPL should be fine (I don't want to impose any unnecessary restrictions).

    I'm not a big fan of the Windowsification as I support platform compatibility (and I'm using Linux nowadays which I've switched to two years ago). The reason I initially only released a Windows build of PlaneEd was that that was all I had at the time, but I don't see any reason why it shouldn't build on Linux. I certainly agree that adding these menus adds to user friendliness though. My workflow at the time was that I just had a batch file for each mapping file that I ran to edit the mappings, which is much faster, and I didn't know how to add a tool bar without entirely programming it myself. Nowadays I'd probably use Qt for that.

    I tested Captain PlaneEd in Wine, here are some notes:
    • It runs quite sluggishly while the original PlaneEd runs smoothly for me (in Wine). That might be due to SDL2 using hardware acceleration for its bitmaps unlike SDL, which might not be supported all that well in Wine.
    • When I open a project file via commandline parameter, its paths (pointing to mapping files etc) are taken relative to where Captain PlaneEd is run from (working directory), while I open it with File -> Open (why's there no hotkey anyway :P) it's relative to the location of the project file it seems.
    • Being able to zoom in by resizing the window is nice. Though does SDL2 have no other scaling filter than pixel repetition? It looks awfully ugly for non-integer zoom levels.

    So while I'll probably stick to the old PlaneEd for the few occasions I have to use it, for Windows users that don't use the commandline this should make the program a lot easier to get into.
     
  3. Clownacy

    Clownacy

    Tech Member
    1,053
    581
    93
    It's been a long time since I looked at the SDL2 code, but I'm sure it can be improved. The SDL2 port was the first thing I did to the tool, but I gave up on it halfway through because the SDL_CreateSurfaceFrom was failing when it was used on tilesData. I'll never understand why SDL2 limited the ARGB mask combinations. One thing to improve would be making sure the screen's Texture is set to Updated Frequently, which could be why things are sluggish. It was all one big hack to begin with, and I haven't touched it since.

    I am hoping to bring back platform-independance at some point: I already have a branch with all the Windows stuff stripped out, and I've been looking into Qt. I've kept the source code arranged in a way that detangling the Windows stuff is easy. My reason for assuming PlaneEd was Windows-only to begin with was because the credits say that Puto couldn't get it to run on Mac OS.

    I'll look into the other issues you noted. Truth be told, I have no idea why the relative path issue is a thing, since the code for reading those hasn't changed, but there might be some weird background thing I haven't noticed. A hotkey for opening and saving should be possible, I just never looked it up. Upscaling/downscaling might be controllable with an 'SDL hint'. Again, it's not something I looked into.

    About licensing, I'm still new to it all, but, with your permission, could I attach the LGPL 'boiler plate' notice to the top of each source file? And would you be willing to license it to LGPLv2.1+, for better compatibility? I know I'm probably getting ahead of myself, but it's my first time working with licenses this much, and I want to be thorough. I've already gone through the headache of trying to figure out if the LGPLv3 KENSC could go with the LGPLv2.1 PlaneEd.
     
  4. qiuu

    qiuu

    Tech Member
    144
    9
    18
    Blue Ball & Blocks
    So it's a hack on top of a hackjob? :P

    Sure, it's fine if you prepend the LGPL note to the source files. You can also relicence it to whichever LGPL version suits you best, at least as far as I'm concerned.

    As for the path issue, I didn't test it that thoroughly, and it might also be an artefact of using Wine.
     
  5. Clownacy

    Clownacy

    Tech Member
    1,053
    581
    93
    I've addressed the working directory issue in v1.0.1. I've also tried improving the SDL2 performance, though there may still be more work to be done, since the current way doesn't perfectly imitate how the SDL1 code worked. For every SDL event, the image has to be reconstructed (SDL_Surface -> SDL_Texture generation), so some form of dirty drawing might need looking into.
     
  6. Clownacy

    Clownacy

    Tech Member
    1,053
    581
    93
    I set up a Linux Mint installation, and the lag seems to be a Wine thing. A native WinAPI-less build isn't laggy at all.
     
  7. Clownacy

    Clownacy

    Tech Member
    1,053
    581
    93
    v1.1 is out: it mainly fixes bugs, but it also features some rather extensive modifications under the hood.
    • Fixed garbage data that would appear at the sides of the screen after resizing the window
    • Fixed compiling on Linux
    • Ditched the old dirty-rendering system, fixing the bug where 'ghost' tiles would appear after moving the mouse around
    • Converted to hardware-accelerated rendering, replacing the previous software renderer
    • The smoothing filter that is applied to the window when it is resized has been redone entirely, which should make it look better while also using fewer system resources
    • Fixed crash that would occur when doing CTRL+A after previously selecting a region
    In particular, Captain PlaneEd is fully hardware-accelerated now: previously it was software-rendered, and only used the GPU to upscale the final image to fit the resizeable window.

    The reason for the switch to hardware acceleration was so I could ditch the old dirty-rendering system: instead of redrawing the whole screen multiple times a second like a video game, the original PlaneEd would only redraw bits of the screen when you did things like select or draw a tile. Unfortunately, this system had a few holes in it that don't seem possible to fix (namely, moving your mouse out of the window causes a 'ghost' tile to be left on the screen), so I decided to just get rid of it entirely, and hope that an optimised hardware-accelerated renderer would be fast enough that no one would notice any difference. Technically, earlier versions of Captain PlaneEd already drew multiple times a second, which is why it performed so sluggishly compared to vanilla PlaneEd, but now that problem should be gone.
     
    Last edited: May 13, 2021
  8. Clownacy

    Clownacy

    Tech Member
    1,053
    581
    93
    [​IMG]

    Captain PlaneEd v1.2
    I found myself itching for a fun project to work on, and my mind settled on updating Captain PlaneEd to use Dear ImGui instead of WinAPI. This allows the previously-Windows-only menu bar to work on Linux, macOS, and the BSDs too. Additionally, Linux and BSD users get to enjoy file dialogs.

    This update can be downloaded here.