AaronCameron.net
Wrecking things for people is important - it makes you a better person. -- Sabrina Constans
Not a Member? - Login or Create an Account...MC Offline
Saturday the 24th of June 2017 @ 08:00am
Front Page Projects Your Profile About
[]

Filed Under: Journal - Development

Recently I've been doing a little bit of work getting up to speed with Ogre, starting to re-learn AC3d, a bit of ACNet hacking, a whole lot of time wasting in Minecraft and starting to dig myself even a bigger hole.

Also I think I'll start posting the scraps of code I write as I write scraps of code to make my life easier. More on that later.

SDL and Ogre

I picked up hacking on Ogre and SDL where I left off a few weeks ago. As usual it took half the time just getting back up to steam, but I did make a little headway. I'm hobbling along using a mishmash of Eclipse, vim and other tools rather than sticking to the IDE exclusively still trying to find where my sweet spot is going to be. Eclipse really drives me crazy sometimes, but it's hard to argue with the advantages it provides.

I got the Ogre Test Framework up and running, with obligatory and redundant screenshot provided to the right. I'm impressed with how simple it seems to be to get basic results. Unfortunately, in my experience however, whenever it is easy to do simple and straightforward things with a toolkit it's often very difficult to do complicated, specific things. I'm not making that claim yet. It's way too early to make that kind of determination.

The next steps will be looking into an import/export scheme that'll let me use AC3D, or to start investigating new simple tools for making meshes. Also I need to start considering how I'll integrate the n2lGUI libraries into the whole thing. They have OpenGL calls all over the place inside them which'll all have to be torn out and replaced. With those changes on top of all of the restructuring I was planning on doing it makes me wonder if I'm not better off starting from scratch, or with using something pre-built.

Making quick C/C++ Enum Lookups for Debugging

Most of this is going to be things better done with some existing app, but it shows how I do my thing. Maybe the act of putting this stuff out here will get me feedback describing even better tools of the trade.

This post is a little tool which parses a C/C++ enumeration and fabricates a C++ method which provides ToString for that enumeration. It isn't optimal, or pretty, but I find it very useful for hacking at new libraries when you just want a quickie way to see what is hiding variables.

This reads from stdin. The idea is to copy the enum from the library source and paste it into the terminal, then copy the output and paste it in your code.

For example, copying the following subset of the SDL_EventType enum in:

typedef enum
{
    SDL_FIRSTEVENT     = 0,     /**< Unused (do not remove) */
 
    /* Application events */
    SDL_QUIT           = 0x100, /**< User-requested quit */
 
    /* Window events */
    SDL_WINDOWEVENT    = 0x200, /**< Window state change */
    SDL_SYSWMEVENT,             /**< System specific event */
 
    /**
     *  This last event is only for bounding internal arrays
     */
    SDL_LASTEVENT    = 0xFFFF
} SDL_EventType;

Yields:

const std::string getSDL_EventTypeAsString( const int iVal ) {
	if (iVal == SDL_FIRSTEVENT) return "SDL_FIRSTEVENT";
	if (iVal == SDL_QUIT) return "SDL_QUIT";
	if (iVal == SDL_WINDOWEVENT) return "SDL_WINDOWEVENT";
	if (iVal == SDL_SYSWMEVENT) return "SDL_SYSWMEVENT";
	if (iVal == SDL_LASTEVENT) return "SDL_LASTEVENT";
	return "(INTERNAL) Unknown";
}

Simple, but I find quite useful. Here's the perl code:

mkEnumLookup.pl

#!/usr/bin/perl
 
use strict;
use warnings;
 
my $buf = join '', <>;
 
# Strip out useless stuff.
$buf =~ s/\/\.*$//g;
$buf =~ s/\n/ /g;
$buf =~ s/\/\*.*?\*\///g;
 
# Start processing.
my $name = '';
if ($buf =~ /\{(.*)$/) {
	$buf = $1;
}
 
if ($buf =~ /(.*)\}\s*(.*);+.*$/) {
	$buf = $1;
	$name = $2;
} elsif ($buf =~ /(.*)\}.*$/) {
	$buf = $1;
}
 
my @defs = split /\s*,\s*/, $buf;
my @names = ();
 
 
$name ||= 'MyEnum';
 
print "const std::string get$name","AsString( const int iVal ) {\n";
foreach (@defs) {
	$_ =~ /^\s*(.+?)(\s+|\s*=.+|)$/;
	if (length($1)*2+length("    if (iVal == ) return \"\";")<=80) {
		print "\tif (iVal == $1) return \"$1\";\n";
	} else {
		print "\tif (iVal == $1)\n\t\treturn \"$1\";\n\n";
	}
}
print "\treturn \"(INTERNAL) Unknown\";\n}\n";

I have a variant for dumping all the enabled flags in a bitmask as well, which I'll post next time.

ACNet Hacking

I've spent a few hours here and there modernizing the publishing and visual style of pages through out the site. Some of that payed off tonight, and some has turned into a huge mess. I'm always right on the edge of throwing the whole thing out and installing WordPress. Coding a publishing system just seems so unnecessary these days. Then I realize that there's so much more going on under the hood that I'd lose that it isn't realistic. Then I get disheartened.

Project/ Site and Documentation sections for Orange and Tang are coming. There's still not much to put up there, and I'd like to tighten up the integration with the project manager a bit before releasing it, so not much to say on that front.

In other news...

Minecraft has happened to me. I'll get into that a lot more in the near future.

As if that wasn't bad enough. I've gone and done this to myself:

I'm not a smart man.

Share:

Reader Comments

©2017 Aaron Cameron