AaronCameron.net
Grotesque: fun to say, fun to be.
Not a Member? - Login or Create an Account...MC Offline
Saturday the 24th of June 2017 @ 08:01am
Front Page Projects Your Profile About
[]
[]

Filed Under: Journal - Development

mkEnumFlagsLookup

2010.10.18 08:35pm
Aaron

As mentioned here's the script to generate a ToString method for a C\C++ bitwise mask enumeration. Again this is simple stuff, but can be pretty useful for debugging.

This, again, 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 SDL_RendererFlags enum in:

/**
 *  \brief Flags used when creating a rendering context
 */
typedef enum
{
    SDL_RENDERER_SINGLEBUFFER = 0x00000001,     /**< Render directly to the 
                                                     window, if possible */
 
    SDL_RENDERER_PRESENTCOPY = 0x00000002,      /**< Present uses a copy from 
                                                     back buffer to the front 
                                                     buffer */
 
    SDL_RENDERER_PRESENTFLIP2 = 0x00000004,     /**< Present uses a flip, 
                                                     swapping back buffer and 
                                                     front buffer */
 
    SDL_RENDERER_PRESENTFLIP3 = 0x00000008,     /**< Present uses a flip, 
                                                     rotating between two back 
                                                     buffers and a front buffer
                                                 */
 
    SDL_RENDERER_PRESENTDISCARD = 0x00000010,   /**< Present leaves the contents
                                                     of the backbuffer undefined
                                                 */
 
    SDL_RENDERER_PRESENTVSYNC = 0x00000020,     /**< Present is synchronized 
                                                     with the refresh rate */
 
    SDL_RENDERER_ACCELERATED = 0x00000040       /**< The renderer uses hardware 
                                                     acceleration */
 
    } SDL_RendererFlags;

Yields:

const std::string GetSDL_RendererFlagsAsString( const int iVal ) {
	string r, sep;
 
	if (iVal & SDL_RENDERER_SINGLEBUFFER) {
		r += sep+"SDL_RENDERER_SINGLEBUFFER";
		sep = ", ";
	}
 
	if (iVal & SDL_RENDERER_PRESENTCOPY) {
		r += sep+"SDL_RENDERER_PRESENTCOPY";
		sep = ", ";
	}
 
	if (iVal & SDL_RENDERER_PRESENTFLIP2) {
		r += sep+"SDL_RENDERER_PRESENTFLIP2";
		sep = ", ";
	}
 
	if (iVal & SDL_RENDERER_PRESENTFLIP3) {
		r += sep+"SDL_RENDERER_PRESENTFLIP3";
		sep = ", ";
	}
 
	if (iVal & SDL_RENDERER_PRESENTDISCARD) {
		r += sep+"SDL_RENDERER_PRESENTDISCARD";
		sep = ", ";
	}
 
	if (iVal & SDL_RENDERER_PRESENTVSYNC) {
		r += sep+"SDL_RENDERER_PRESENTVSYNC";
		sep = ", ";
	}
 
	if (iVal & SDL_RENDERER_ACCELERATED) {
		r += sep+"SDL_RENDERER_ACCELERATED";
		sep = ", ";
	}
 
	return r;
}

Braindead, but a great debugging tool. 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",
	"\tstring r, sep;\n\n";
 
foreach (@defs) {
	$_ =~ /^\s*(.+?)(\s+|\s*=.+|)$/;
	print "\tif (iVal & $1) {\n\t\tr += sep+\"$1\";\n",
		"\t\tsep = \", \";\n\t}\n\n";
}
print "\treturn r;\n}\n";

More useful than you'd think.

See or add to 0 Comments

Share:

Filed Under: Journal - Development

I'm waiting for WoW to patch, and Minecraft files to scp to my box, so I thought I'd throw up another small code snippet from my toolbox of extensions. This command is a tiny Perl script that drops a bunch of asterisk filled lines in your terminal. Ultra-simple, but useful for separating the output of one command from another without clearing your buffer.

I don't use this nearly as much as I used to, but I found it useful when running compiling C++ which threw out gigantic std:: template errors that tend to run into each other. Usage would look something like this:

s; g++ myfile.cpp -o main;

It provides a natural break in the flow of output. The only vaguely interesting thing here is that it will fill the output line regardless of the terminal dimensions. I'm aware this is brain dead simple.

s

#!/usr/bin/perl -t
 
use strict;
use warnings;
 
require 'sys/ioctl.ph';
 
my $winsize;
 
die 'no TIOCGWINSZ' unless defined &TIOCGWINSZ;
 
open(TTY, "+</dev/tty") or die "No tty: $!";
unless (ioctl(TTY, &TIOCGWINSZ, $winsize='')) {
        die sprintf "$0: ioctl TIOCGWINSZ (%08x: $!)\n", &TIOCGWINSZ;
}
 
my ($row, $col, $xpixel, $ypixel) = unpack('S4', $winsize);
 
 
print "\n";
for (my $i=0; $i<16; ++$i) {
        print '*'x$col, "\n";
}
print "\n";
 
exit 0;

See or add to 0 Comments

Share:

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.

See or add to 0 Comments

Share:

Filed Under: Journal - Development

I dug back into some game development tonight and was pleasantly surprised to find I had forgotten slightly less than I'd expected.

Change can be a good thing, I'm learning. I've been a rather unmovable object in some of the development decisions I've made in the past, and I think I've been worse off for it. Just like every other developer out there I went through a phase of Not Invented Here, but I think many vestiges of that anti-pattern have stayed with me longer than they should have.

I'm giving eclipse a try and finding it far less objectionable than I'd expected. I certainly wouldn't have been willing to do anything with it a couple years ago. I'm still not willing to hand the full build configuration over to it, but maybe I'm growing up just a little.

For that matter, I think I'm finally going to be willing to use a 3rd party engine to take care of rendering. That's something I've been completely unwilling to release control of whilst simultaneously being absolutely dreadful at implementing solutions myself.

It's exciting that by lowering some of my ideological shields I may have gained (proper) access to Windows and the iPhone, not to mention other possibilities like consoles.

There is nothing really to be said about the projects themselves at this point, so I shall stop rambling and go to bed.

I'm never going to accept spaces instead of tabs, though. Till the grave.

See or add to 0 Comments

Share:

Filed Under: Journal - Development

Is that all? This post is amazingly overdue so I'm going to try to cover everything as quickly as I possibly can. One thing at a time, so here we go:

Jimmy's World


Jimmy's World isn't actually dead. It looks dead, and it acts dead... and if one was to measure usefulness, or recentness, or value it would seem dead. It isn't. Trust me. Jimmy's World suffers from misfire problems. I've started at least 30 articles and written several pages only to realize I have neither the time nor the inclination to do the research necessary to cover the ground I wish to cover with the credibility that I feel I need to have. That is, I run the site like kindergartner but demand the accuracy of a university thesis. This results, somewhat predictably, in nothing ever being finished and published.

I have no solution for this. I state it only for the limited value of acknowledging it. Solutions are in the works, but, well, don't hold your breath.

Religion dot jimmysworld.org

I have no idea where to find the time to work on this project, but it has the potential to piss off too many people for me to just let it go. See Jimmy's World above for where this site sits. Not dead, just in carbon freeze.

The Unfortunately Esoteric Tale of libN2L-4, n2l5

LibN2L-4 is the backbone of Onyx and is a beautiful mess of poorly thought out dependencies, inappropriately categorized functionality, needlessly verbose code and really, really cool stuff. LibN2L-4 gave birth to DynVars, the ResourceManager and countless other really awesome chunks of code that I am going to labour very hard to finally give legs to. Enter n2l5.

The revised name, n2l5, is a symbol of where libN2L is going in the near future. It will be an improved, but smaller and more streamlined version of everything LibN2L-4 meant to do. The prefix 'Lib' is extraneous, the final 'L' of the acronym stands for library. A standing sentinel of duplication which had no business being there to begin with. The dash was syntactical complexity for no perceivable reason, a sign of ideology over reason. The four represents a fourth generation, when we all know that a fifth generation is bound to be better. You see how n2l5 fixes all these horrible mistakes.

In seriousness n2l5 will seek to cut the fat of LibN2L-4 and simplify the syntax while focusing on the functionality that should be in an underlying library. Where does that culled functionality go, you ask?

orange, and Orange

Orange was a codename assigned to a new game meant to occupy the Life2130 universe circa 2060-2100 shortly after the First Solar War as a sort of SimCity in space. The game lives on in a semi-mature design phase, renamed to ... something and Orange moves forward as the engine that will drive the games to come. Orange is the glue that LibN2L-4 inappropriately sought to be.

Designed and developed to simultaneously support Onyx, Onyx: Free Trader, Life2130 and orange (the first iteration): Orange will be the environment which will connect the power of n2l with the assets of already designed games. It will combine function with design.

Life2130

Life2130 is evolving yet again. Yeah, I'm not talking about Life2130 yet.

Onyx

The current codebase was declared dead as of 1:17am March 29 2007. the new codebase was born 1:17am March 29 2007. Onyx is dead, long live Onyx.

While long have I whined about the technical inadequacies of Onyx, particularly the physical and graphical inadequacies, on paper and in implementation Onyx had always been intended to pad my resume with game development goodness. It has totally and completely failed to do so. Now I realize I don't even want a game development job, and irregardless Onyx never fit the bill since as much as I may be proud of everything it was and everything it could do it simply doesn't look formidable enough to be worth anything.

Onyx was a failure and a success. I'm proud of what I accomplished on some levels, but what I accomplished has no externally visible value to speak of. Finally recognizing and fully digesting that fact leaves me with the inescapable conclusion that I need to close the book on Onyx the implementation and decide how I want to tell Onyx the story, if I want to tell its story.

Onyx the story is a story of the years 2108 to 2148 in the Life2130 universe and not 115,762 lines of C++, 71,541 lines of definition files and 850 meg of data. Realizing and accepting that lets me tell the story and divorce myself from the learning experience.

From this moment on Onyx will be restarted in concert with other projects and it will be back better, stronger and more descriptive of the universe it occupies.

And so...

And so JwGames moves forward. To define this turning point one needs to really define Onyx as an experience. How does one define Onyx? Onyx was a painful, bloody and crushing experience. Onyx was a vessel into which was poured the ill-conceived and outdated objectives of an extinct set of childish goals. Onyx became bitterness and cynicism crystallized. Onyx was a horrific, life-adjusting mistake. Onyx was and is a war that occupied 1370+ days, nearly 15% of my life and resulted in failure.

Onyx is an opportunity, and it sure as fuck isn't over yet.

See or add to 1 Comments

Share:

Journal - Development

©2017 Aaron Cameron