Archive

Author Archive

Game engine + FTP == awesome stuff

February 2nd, 2011

For a couple of days I was tossing an idea of integrating FTP into my game engine.  Yeah, it totally sounds crazy, and this was my first thought too. But I have a very good reason why. The iOS game, I’m currently working on, has a level editor only on Windows. To test and tweak the level for a game I have to edit it with the editor on Windows, then commit to SVN, check out it on Mac, build the game, and run on iPhone. That’s quite a path and wastes a lot of time. All this makes quick iterations impossible, and the worst part is that all this repetition is very annoying and demotivating.

At first, an idea flashed in a head about doing it all myself , but I was smart enough to quickly reject it. So, I’ve went to see if there were any solutions ready, and googled for FTP server or client code. I guess my googling skills are dusting, as it took some time, but I finally came across ftplib. It’s a small and portable library implementing FTP client’s protocol. On Windows it worked without any modifications. On iOS I wasn’t so lucky, but the only problem was that Xcode’s compiler doesn’t define “__unix__”. So after modifying couple #ifdef’s it was ready to go. Overall it took me a couple of hours to get it working, mainly because the first FTP server I’ve tried was crashing. But then I came across ftpdmin, which worked flawlessly, and the best thing about it is that its distribution is only 1 exe file. Here’s a screenshot showing ftpdmin serving a level to the game engine:

Whole code for this takes just like 20 lines or so. Here’s the first hackish implementation (with a bonus buffer overflow!) that got the snowball running:

    netbuf* control;
    FtpInit();
    if (FtpConnect("192.168.2.100", &control) == 1) {
        LogInfo("Connected to ftp");

        FtpLogin("game", "game", control);

        netbuf* data;
        if (FtpAccess(gLevels[mLevel].mFile, FTPLIB_FILE_READ, FTPLIB_IMAGE, control, &data) == 1) {
            LogInfo("Ftp file open");

            const int size = 102400;
            char buf[size];
            int read;
            read = FtpRead(buf, size, data);
            if (read == -1) {
                LogWarning("Error reading ftp file");
            } else {
                buf[read] = 0;
                LogInfo("Ftp file read");
            }

            FtpClose(data);
        } else {
            LogWarning("Couldn't open ftp file");
        }

        FtpQuit(control);
    } else {
        LogWarning("Couldn't connect to ftp");
    }

So now when I’m working on levels I simply launch ftpdmin on my Windows machine, and the game on my iPod automatically downloads the levels. I play it, edit on Windows, save it, restart the level and it’s ready to be played again. Fast and effective. Yay for iterative development! The only thing I hate is that it has to use Wi-Fi… I wish iPods could access network through it’s USB cable.

The best thing about this is that you don’t need to stop with level editing. Just imagine editing and instantly downloading scripts. :-)

Smilediver Coding , , , , ,

Mac and Windows not resolving *.local hostnames

January 4th, 2011

Yesterday, after all these holidays, I was trying to get back to working on my game. For developing iOS games I’m using: my laptop with Windows 7, that hosts all code in SVN; and a Mac Mini with Mac Os X, that I basically use to port and test games on iOS. For several months, I had them in separate rooms, because our house has one router in a garage, and each room gets only one Ethernet cable. So yesterday I’ve got another router, setup a mini network in my room and connected laptop and Mac Mini to it. I’ve committed all the code from laptop to SVN, proceeded to check it out on a Mac Mini, and was surprised with a nice “Host sandbox.local not found” (sandbox is a hostname for my laptop).

I’m using Bonjour (which is an implementation of Zeroconf) on Windows to resolve it’s hostname to IP for Mac. It’s a single nice side effect of having iTunes installed. :-) Our router has a DHCP service, and since I’m using laptop in a lot of different places I’d hate to mess with “/etc/hosts” and switch to a static IP, or relocate SVN in a Mac Mini to a different IP of my laptop each time I needed to get sources from SVN. It’s so nice just to be able to enter “svn://sandbox.local” for a repository url and see everything magically work. So if you’re struggling with a similar situation, then I advice to look into solving this with Bonjour.

And finally the solution to the problem… since Bonjour uses multicast for it’s service, router also must support it, and it must be enabled. I’m using Linksys BEFSR41, so for me the option was in “Security->Filter->Filter Multicast”, and it simply had to be enabled. The option is also misleading, as it seems that enabling it would actually filter out multicast packets, but it’s backwards. Another name that this might hide behind is IGMP, so if it’s not working, then check related settings too.

Smilediver General , , , , , ,

Resolve Ambiguity

August 12th, 2010

Solving ambiguities in Visual Studio… yeah… :-D

Smilediver Blabing , ,