Mega

Last Login:
September 03, 2015
Warn:

Rank:
Member



User Profile
Follow

Hits: 131,095
Joined August 08, 2010
Games (11)

Game Music Player
October 10, 2011
Exile
August 01, 2012
In a word
August 10, 2010
Trace
October 07, 2010
Flood the mines Demo
November 12, 2010
Tetris
January 25, 2011
Velocite R
April 12, 2011
Shinsetsu Ninja
February 18, 2013
Walk of Darkness Demo
November 15, 2013
Project Phoenix
April 30, 2014
Frosty RPG WIP
December 23, 2014
Examples (1)
Favorite Users


Stealth Inc 2 free this weekend
Posted on August 29, 2015 at 07:31

Humble is having an "End of Summer" Sale, and just like last time I remember them doing something like this, they're giving away a game for free.

This time, it's Stealth Inc 2. No idea if its any good, I've only played Stealth Bastard. But hey, free game!

https://www.humblebundle.com/store

Available until the 31st.

On an unrelated note
I've seen (And played a little of) the Megaman Legacy Collection. It's really solid. I'd say get it if the price comes down a few notches over the next Steam sale, especially if you've never played a Megaman game before :D

There is a little contention over the release though. The creators are saying they created an "Entirely new engine" and are fond of calling this release a "port".
Reddit users have discovered though that there exist the full ROM dumps of the original US/EU cartridges that, when iNES headers are added, can be played in an emulator.

Quite frankly, if the guys used emulation, they should just say they used it. But I do think that it's possible that they're just pulling sprite and palette data from the ROMs (Not that hard to do); there are several things (Like hooks for the challenge mode and such) that would be a pain to do if this was just emulation as opposed to a port or custom engine.

Personally, I'm probably not going to buy this unless the price comes down; I already have a couple of Famicom Megaman carts at home, and have played the heck out of the entire series to the point where I don't actually play the games that much any more.

I'll update this blog if there are any more freebies, or particularly good sales.




New Drawing Program
Posted on August 25, 2015 at 11:37

Yesterday I started messing around with art again, so as to keep in practice.
Only problem is that GIMP keeps on crashing with my tablet; 2.8 doesn't like non-WACOM branded tablets, and 2.6 doesn't pick up the tablet at all.

Then I discovered Krita. And holy crap, I'm not using GIMP again.
Not only does it work perfectly with my tablet, but it supports the CMYK colorspace, can work with PSD images, has full vector support and is basically Photoshop, without the price tag.

It also, for me, beats SAI hands-down. Again, it's free, and its updated more frequently (SAI crashes often on my machine while in the middle of drawing).

I spent the morning sketching things, getting used to the interface and such. Made myself a new avatar that I'm pretty happy with.

So yeah, if any of the other artists on the site want to try it out:
https://krita.org/




Finishing Exile
Posted on August 19, 2015 at 18:53

I started a somewhat annoying project yesterday on a whim.
A friend and I were going through some of my old games and he wanted to see me play Exile. It's been just over 3 years now since I made it, and I actually managed to dig up the original release, and found its source code.

After playing through the game (and actually sucking at it, since the developer immunity wore off in the 3 years since I've played it), I came to two conclusions:
- I need to finish this, just because.
- I need to clean up the damned code.

I technically already have a "cleaned" version of the code in the form of whatever-version-number I'm up to of the Exile Engine. But here's the problem: It works a lot better but isn't compatible with the original game's data.

I've tried several times before now to 'upgrade' the original game to the new engine, as well as write backwards-compatibility for the old data into the new engine, but I tend to burn out far too quickly (There are a ton of tools I have to make, converters, redesign maps and AI, etc).

So I decided yesterday to instead use the horrible code I already have, and just "complete" the game.

Part of that completion includes making it Linux compatible. Because there isn't any excuse for developers to not make their games Linux compatible.

Yesterday, while playing the game I started to come up with a list of small ideas that'll drastically improve the flow and feel of the game. If any of you remember Exile and have an idea, please add it :P

Here's what I have so far:

Mechanics
- Reduce all attack cooldowns drastically
- Increase movement speed to Doomier levels
- Fix the maps that have holes in them
- Make spells use charges or regents instead of mana pool.
- Replenish player health between levels (Past me was a douche.)
- Replace XP system with permanent upgrades for ATK, STR and SPD
- Make inventory easier to use (Items mapped to hotkeys, like old Build games)

Features
- Re-enable Minimap feature. Yeah, there was one in the original game. It wasn't bound to anything.
- New map geometry (Basically, I want diagonals)
- New lighting (Based on Exile Engine 1.5.whatever, shader based)
- More items (Key types, healing, buffs, treasure, etc)
- More enemies
- Fix facepalming grunt enemies
- Crossbow (Will pull it from Exile "2"'s build)
- Better hands (Again, Exile 2)
- Conversion unit for TilEd (So I can replace crappy GridMap and its lag)
- Static items and wall decals (Already kinda in-code, just not used)
- More spells of varying levels.
- New Bosses
- New levels, better level design (And themed levels).

Sounds like a lot, but I already have a lot of the resources (Art, sound, music) I need for these.

Frankly, that's all the easy stuff. The big challenge is...

Porting and Cleaning the code
Here's where the annoyance factors into things.

To be blunt, Exile's code is a mess. All of the player code, including stuff that shouldn't be in the player code, is all in one file named "player.h".

There's problem two: Almost everything is header based, except for what isn't. What isn't? Hell if I know, my directory structure is crap.

Oh, and I have no dedicated logger or config handler. One third of my logging is done with printf, another with std::cout, and the last third with Win32's MessageBox.

To be fair to 2012 Mega, I was under a lot of pressure at the time of the competition (RPG4D 2012). I had just started a new job in retail (Water shop), was building my first 3D-ish game, not to mention my first full game in C++... and yeah.
Deadlines and work. I did a lot of weekend/midnight rushes, and as one friend of mine put it when I showed him a Gist of some of the files, it looks like it was written by somebody with Schizophrenia.

Anyway, on the cleanup side, I have to deal with a few big things:

- I don't use SFML 1.2, so I need to port it to SFML 2.x. Big problem here is that between 1.x and 2.x, they changed the casing from Something.LikeThis to Something.likeThis. Not to mention that a lot of static methods were removed and replaced with new methods (Notably, sf::Input was replaced with sf::Keyboard, sf::Mouse and sf::Joystick). Mostly naming changes, and changes to texture handling.

- OpenGL needs to be bumped up from fixed-pipeline to at least GL 2.1. I used to be pretty much an asshat about this (With apologies to sirxemic, to whom most of the asshattery was directed). Now I can't do without my shaders. Billboards become a million times easier.
Of course, this is a slightly lower priority modification; if it's gonna take too long, I'm going to cut it until later. I want to keep momentum up.

- Headers need to be re-arranged, split into implementation files, and renamed. I tend to follow Quake/Doom naming conventions with prefixes now (g_, ent_, u_, etc).

- Repetitive code needs to be put into utility functions, and small optimizations need to be made regarding things like index calculations (Basically, I should get a pointer to something once on creation if possible and leave it during the lifespan of the object, which I'm not doing at the moment. Calls to AssetManager::getImage() are killing things performance-wise).

- Remove all the crappy reliance on Win32's Message Boxes, as well as use of io.h, which isn't available on Linux. I use it once in the level loader to find the size of the map files.
Technically, map files should be read in streams instead of blocks; they identify for themselves exactly how many bytes of data there will be just by virtue of being a grid-based system.

The Linux side of things is relatively easy once I manage to get around all the other issues I've created for myself. The music engine, currently relying on GME, needs to be recompiled for Linux, as well as my "math" library. More like a psuedo-math library. No wonder my collisions were so bad.

I started a bit of work on it this morning while at the shop. GCC started to spit out a near endless stream of errors. And as if to laugh, there was a //TODO in the main file labeled "Clean everything up later". Thanks past-me.
Now I know they never invent a time machine, or I'd have already experienced a smack upside the head with a Clue-by-Four a few years ago for being snarky.

Oh, and if you've never played Exile =3
About Exile (Show)




Windows 10 Review
Posted on July 30, 2015 at 15:45

I'll be writing a cumulative 'review' here, along with any problems and workarounds I encounter.

Day Zero
The download of the upgrade finished at about 11PM. I was tired already, and had work the next morning.
Nevertheless, I thought I'd start the installer and leave it running.

I remembered after the fact that I have a non-standard boot setup.
My PC has two physical drives. The first is my "Windows" drive, and contains the EFI boot partition for Windows.
The Second is my Debian drive, and contains a boot partition for GRUB.

This didn't cause any problems, just a minor annoyance. The way I have Grub set up is to boot into Linux if I don't enter a response (About 4 seconds to respond).
And the setup process restarted about 5 times in total. So I sat wrapped in a thick blanket with the cat on my lap, half asleep, watching the numbers crawl.
Took about two hours from start to finish.

Crashed in bed as soon as I could and decided to leave it for the next day.

Day One
Woke up late, so it was a mad dash to get ready for work. I quickly peeked at my 'new' installation and noticed that my primary display wasn't usable. Needed to install the drivers for my Nvidia 750.
I set that to download and ran to work (Ended up forgetting my lunch).

Got back and booted up.
And all told, everything is looking pretty good. The system is basically exactly how I had it before I started the upgrade. Icons in the same place across both screens, network mappings intact, applications intact, etc.

Even my slightly weird startup batches are working fine (One of them is a call to SUBST to map my C:\Dev\ folder to a drive letter on startup).

And the only thing I was a bit leery of, the "forced" updates, was easily solved by a trip to the Group Policy Editor. Details at bottom of blog.

So far, so good. Everything works that I've used so far. I have yet to play any games, but my normal "work" stuff is perfect.

Will update tomorrow.

EDIT: Oh, and Microsoft has finally changed the default CMD font:

And in the process of poking around CMD, I found that my entire MSYS style setup was still in place, as well as my SSH stuff.
Heck, even my context-menu entries are intact and working as intended.

EDIT2: All my games seem to be working so far. Also tried out Minecraft: Windows 10 Edition, which led me to poking around the XBox app, which further led me to discover that it supports XBox Live Avatars and even has an app for creating them.

Then there's the built in game recording tools. They're pretty decent, showing a measure of elapsed time on the top of the screen.
But I've already got both OBS and ShadowPlay to use.

Speaking of ShadowPlay, I had to turn it off and on again before it would work (Probably had to reinstall the service layer). Working flawlessly now.

Day One Point Five / Two
Woke up earlier than normal this morning and tested a few things out.
I could post a long checklist of what works and what doesn't, but I literally haven't encountered anything that doesn't work as normal.

The Command Line spontaneously returned to its old self again, and I have encountered one or two runtime errors while using the Windows Store and the new "Settings" app.

Hasn't happened since.

Performance wise, I did a comparison with The Witcher 3. I intentionally set it up on my Windows 8 installation so that it was running at a sub-par framerate (40FPS), and tried it with the same settings in Windows 10. Again, 40FPS. So no major improvements (DirectX12 doesn't affect everything just by existing, as many of my misguided customers seem to think).

Anyway, so far my experience is "normal". I've set up the Email app for a bit of use testing, and it's far better than that piece of crap in Windows 8.
The Notification/Action Center is a welcome addition, and I haven't properly used Task View yet (Though I did discover that additional desktops retain settings between reboots).

This weekend I plan on testing out my build environment and compiling the most complex project I have on-hand: Exile.

Workarounds and fixes
Change Windows Update Options (Show)




Current Projects
Posted on July 18, 2015 at 19:14

It feels like forever since I've even had any tangible progress to report on any of my projects.

In fact, it's been a while since I've had time to work on a project. Retail is soul-crushing.

A few weeks ago I basically handed in my notice, and will no longer be working at the front-desk from September 1st.
I'll instead be repairing computer problems on contract, with an up-front fee per machine (Nominal, I'm not going to fleece my boss; she's helped me out a lot - I'll be earning more than I am currently on a good week, since it'll be per-job and not a fixed weekly rate).
I've got my learner license for motorcycles, so I'll have easy transport between home and the workshop (Only a 2.5km trip, but I'm not walking when I have wheels available).

This means one thing to me: Time. I'll finally have time to get back to doing what I want to do.

Which is get all my skills back up to scratch again.

Skills rust. I can still draw and sprite relatively well, but can't animate for shit.

Music? I don't even know where to start.

So yeah, I'm going to have time to get back into practice; maybe release a few mini-games, do a Ludum Dare if I remember to join.

Oh right, the blog title is "Current Projects". I still tinker at work when I can; I have a crappy Linux box (Crappy because of crappy hardware, not because it's Linux).
I actually got around to not being a lazy ass and figured out how to implement both 2D and 3D renderers using modern GL (2.1, 3.0 mostly).

I've spent a lot of time streamlining my development process too. On my home machine, I've made use of a semi-forgotten command line program in Windows, SUBST, to map my dev folder to a drive letter.
Makes for much easier access via command line, and do 50% of my work in the command line (MSYS. Once you BASH, you can never CMD again).

For moving code between work and home, I set up a git repo for my projects on my USB drive. Simple git push, and a pull on the other machine and I'm done.

My build system at the moment is either very simple or very complicated, depending on the project.
For small things, I just set up a pair of shell scripts (One for Linux, one for Windows).

If things start to get mildly complicated, I usually slap together a makefile. Then I inevitably get tired of doing that and switch to using CMake, which is wonderful when it works, and a piece of shit when it doesn't.

Anyway... projects. I've got one game project I'm working on at the moment, not counting the other cold-starts I have in my dev folder.
It's mostly art at this point.


I just want to make a solid platformer. No gimmicks; just core concepts from the Megaman series: Jump 'n shoot.
I've gotten over the "Indie Disease" where you start every project trying to figure out a unique mechanic or theme. It doesn't work, you just end up with a bunch of false starts and end up feeling like crap.

I've played games like Axiom Verge and Freedom Planet recently. They both are just really solid games. Axiom Verge is pretty much a 1:1 Metroid Clone; everything you know about Metroid applies here. And I loved it.
Ditto for Freedom Planet.

I'd rather make something that fulfills the expected platformer mechanics first, and as solidly as possible, before I create any new mechanics; that way, I can create a gameplay element that fits the game, rather than create a game to fit it.

Entertainment


You know what I feel like doing at the end of a long day of dealing with the pests commonly known as the Computer Illiterate Masses?

Nothing. Absolutely nothing.

Nothing requiring input anyway. That's one of the major reasons I haven't been doing anything creative recently.

So basically I end up trawling Youtube and watching a ton of Anime. I tend to play games on the weekend when I have a bit of time.

Anime I'm watching
> Shokugeki no Soma (Genius, if you don't mind the Ecchi)
> Overlord (Mixed opinion on this so far)
> Dragon Ball Super
> Ranma 1/2
> One Piece (I'll never catch up)

Anime I recently finished
> Fate/Stay Night: Ultimate Blade Works (Excellent fight-scenes, slow story)
> Sword Art Online 2 (Stronger overall than the first season).
> JoJo's Bizarre Adventure. (Contents as on label. Loved it though, and am now reading the Manga).

Those of you who remember my viewing preferences from a few years ago will notice a huge shift. That is, I'm watching stuff that isn't Mecha.

Games I'm playing
> The Witcher 3 - I get the feeling this is going to take me months to get through.
> Dark Souls - I love doing speedruns and challenge runs.
> DoomRL
> NetHack, Crawl, ZAngband.
> A bit of TF2 on occasions.
> ARK: Survival Evolved
> Megaman X3: Been working out 100% Speedrun routes for this during quiet periods at work.

Games I recently finished
> Kerbal Space Program (Demo)
> Axiom Verge (Recommend highly to Metroid fans)
> Freedom Planet (Recommend it highly to Sonic 2/3 fans)

Impulse-bought Fallout New Vegas Ultimate Edition at the shop yesterday. I swear, they placed it right where I would see it ;_;
I already had the main game, but for all the DLC, it was nice and cheap (Approximately $7).

Well, that's enough out of me. Go watch these guys make a sword:




Meh
Posted on June 25, 2015 at 09:20

*grumble grumble* Mind altering code *grumble*

Blogging anywhere else sucks. I don't want to use a buggy Javascript implementation of an RTF text editor every time I want to write a small blog.

So hi. I'm back, unless bullshit starts up again.

Stuff I'm doing/have done
End of the month, I'm doing an aptitude test for the South African branch of this: http://42.fr
Not necessarily going in for it, I want to see what costs there will be first; and whether they'll be teaching anything I need to learn.

I'm still working at the PC shop. I plan on leaving towards September in order to pursue programming a bit more fervently. I kinda need the cash :P

During the Steam Summer Sales, I managed to buy a total of 10 games using nothing but trading cards. 11 if you count the gift copy of One Way Heroics I sent to my brother.

Speaking of that, it's a cool game. Take Pokemon Mystery Dungeon, add a liberal dose of JRPG tropes and throw in some Roguelike features and that's pretty much this game. Also has some online functionality.
It was going for $0.29 during the sales.

I pretty much freaked out during the Fallout 4 announcement at E3 and have promptly started dumping cash in a jar to save up for it (They're releasing it two days before my birthday, assuming there aren't any delays).

Jeremy and I made a Curses/Terminal based chat client in Node from scratch in about 7 hours.

I've started to want a HoloLens more than an Oculus Rift, but still want both.

I've hit a wall with that Point of Sales app I was making, mostly because of thermal receipt printer drivers, Node and cash drawers.

I've started to make a new engine based purely on OpenGL 4.x. It's more fun than fixed pipeline, that's for sure. Have also got a BSP editor in progress, and the skeleton of a voxel based "pixel art" editor I'm experimenting with.
More on that when I have pics/video.

Well that's enough out of me. I've got money to take from people who broke their computers.




March Blog
Posted on March 23, 2015 at 20:38

I've got a distinct lack of blogs for this month, besides that UE4 announcement thingy.
So here's a hodgepodge of a blog; I'll try to section things off neatly and remember to use paragraphs for once.

Work
Work has been... interesting. I still get basket cases bringing their PCs into the shop, along with other electronic devices.

I've been asked, over the last two weeks, whether I can repair:
> Fax Machines
> Toasters
> Televisions (CRT & LED with a busted screen)
> Amplifiers
> Microwaves
> DSTV Decoder (Set-top Satellite Box)

The looks on people's faces when I remind them that this is a computer repair shop straddle the line between bewildered and horrified.
They seriously don't see why I don't fix these objects. I mean, heck... I could try, but I'd more likely break it/turn it into an analogue computer than actually do what they want me to do.

Also had one of the usual dicks in the shop last week. I was pleased to learn that most of the other shopkeepers I know refer to him as "That Bloody Wanker".
He's a musician, plays Afrikaans gigs (Guitar + Singing, solo) and obviously thinks he's a Big Deal.

So, he walks into my shop with his laptop. He uses it to play his backing tracks and record music on, and for some reason his audio ports have stopped working, and he has a gig the next day. So it's a big emergency, and I help him out.
About 10 minutes and one driver repair later, they're working again. He's overjoyed, until I tell him the repair cost.

Our shop has a basic "service" fee, per hour. So the first hour costs a fixed amount, at our discretion. This applies to any 'basic' job such as the above, or helping people "Fix their Facebook", and so on.
It's about $15, R150 locally (And about 15 loaves of cheap white bread around here).

This is a middling bit of cash; it's not huge though. We pride ourselves on having lower basic rates than the other computer shops in the nearby area. The next lowest price for this sort of thing is R450, three times what we charge.

This guy proceeds to throw the biggest tantrum I've ever heard an adult throw. He goes on and on about how he's a "Starving musician", that I'm a "greedy son of a bitch trying to take his hard earned money" and the usual allotment of swears that the locals learned in school.
If this was my first month on the job, I'd probably have been scared off. Fortunately, I've figured out the best way to deal with them:
"Shut the hell up, pay up, and get out. I don't want to see you in my shop again."

A lot of the customers I have in the shop tend to have a bit of an attitude, like they're doing us a 'favor' in bringing their problems to us.
I often have to remind people that if they knew what they were doing, a lot of the problems they pay for me to fix wouldn't happen in the first place.

I get three primary customer groups (Four if you count the Toaster brigade).
> People needing a problem solved (Repair, Viruses, etc)
> People wanting advice
> People wanting to buy a retail product

The latter two are usually amiable, and never cause any trouble.

People who fall into the first category tend to either be very polite, or extremely vitriolic.
Often, when they see how 'simple' a problem was for me to solve, they get angry and seem to think it's somehow my fault that they didn't know how to solve the problem.

But yeah, my policy with these customers is that I don't want them or need them. Let them go; they'll probably come back later with mumbled apologies (Which has happened a few times when they go to the competition and pay through their nose for the same job).

On a more cheerful note, our landlord told us to move at the beginning of the month. And no, I'm not being sarcastic; she's letting us have another shop in the building that's 6 times the floor space, with a storage room at the back, and all for the same rent!
We're actually in the position where this feels like too much space, and we're puzzling out ways to effectively use it.

One of the improvements we're making is the placement of a coffee table and armchairs, along with a coffee machine and a stack of computer magazines (Those being provided by me; have nearly 300 assorted mags).

To make our shelves seem a little less empty, I'm putting a bunch of old empty part boxes on display; things like GPU boxes, motherboard boxes, etc. Looks nice, and also happens to be stuff we can order.
I'm going to make sure to put an "Order on request" sticker on the empties though, because otherwise I'm going to be explaining myself every day.

Programming
I haven't been doing as much programming recently as I'd like to be doing, but I'm slowly getting back into it. I have a multitude of mini-projects I'm working on at work.
These include:
> QRL - Quick Roguelike; something like Binding of Isaac, with rudimentary graphics. Looks like an Atari 2600 game at the moment.
> QRL3D - Working on a span-renderer akin to Doom and making a simple shooter/roguelike hybrid.
> CSH - C-like scripting language library, trying to make it as tight as possible.
> RAY - Simple raytracer I'm kinda piecing together using the materials below.

I've been getting into the recent habit of naming all my projects in upper-case, as you can see.

At home, I'm working on a Super Secret Project with Jeremy; if you know what it is, let it be known that major progress has been made on it.

I've also been working on a simple port of Exile to UE4, just to learn the ropes. I haven't got much further than importing my assets though. :P

Interesting programming materials
I've been reading from these two sites recently:

Fabien Sanglard's Site
Full of wonderfully constructed breakdowns of classic game engines. Wonderful to read, especially how the Doom & Quake engines work.

ScratchAPixel
Want to learn CG? This site is an absolute gem. Written by anonymous programmers who may or may not work for Pixar and other big companies, it even includes a primer on the basic math you need to know to start writing raytracers. All in C++ too.

Also FlipCode, which I'm using to write the semi-software renderer for QRL3D above.
I say "semi" software, because I'm technically using a GL context to provide an easy way of writing pixels to the screen in a simulated limited-color environment.
Screenshots when I remember to bring them home from work.

Games
Recently, I've been playing quite a lot of Guild Wars 2 (somebody bought it for me, and insisted I try it).
I've never really "gotten into" an MMO before, but this one is definitely interesting. Lots of platforming, adventure, dynamic events, and smooth combat. Musical score is decent too. :P

And for those times when I don't feel like playing anything online, I've been playing a ton of heavily modded Minecraft. I've got about 230 mods installed on my main pack, and I'm having fun building virtual server farms. I'm obviously channeling my rage at a work-related thing from a few weeks ago involving a server, a horrible network and other nameless horrors.

At work, when I'm bored and remember that Klondike/Solitaire isn't healthy, I've been playing through Megaman Zero again, as well as Super Mario Bros 3.

Footnote
The year is just about a third gone. It's scary, because it feels like my birthday in November was just a few days ago. Time flies when you have a job.

I'm thinking of joining both 7DFPS and LD again this year, when they next come around. Assuming I remember, and assuming I have the time. Events tend to conspire to steal time from me just as I'm about to do something I enjoy...

Well, that's enough out of me. Go blog some more you lazy cactus-people.




Unreal Engine 4 Free to all users
Posted on March 03, 2015 at 07:43

Apparently, on Monday, Epic decided to spontaneously drop all subscription fees for everyone, making Unreal Engine 4 free for download and use for anybody.

The only fees still in place are those related to income (After a certain amount of income, you pay Epic 5% of the game's revenue).

Here's the official blog:
https://www.unrealengine.com/blog/ue4-is-free

I'm gonna get to downloading this when I get home.

EDIT:
In other news, Khronos has just officially announced the successor to OpenGL, to be called Vulkan




64DCG 2015?
Posted on February 28, 2015 at 00:37

Yeah, I'm tired, jumped up on energy drinks and coffee...

Here's a thing:



I have no regrets.
Actually, my only regret is recording that in such a crappy resolution.




Engineering Logs - Singletons Revisited
Posted on February 26, 2015 at 09:28

Now that I have free time again for my own programming projects, I decided to start working on games again, and thus on my game engine.
My current goal is to transfer the gameplay from that puzzle/RPG game that I was working on in collaboration (Which is on halt due to the guy I'm working with being bogged down by the German education system).

So yeah, I'm quietly porting it to C++; we don't want to use GM for it, because it's damned messy.

Anyway, the last blog I wrote about Singletons showed me doing it in the naive way: Manually creating classes 'as' a Singleton type by giving it specific properties.
That works, but is a slog. Wouldn't it be far easier to just inherit some sort of global "Singleton" type and not have to do anything further?
Well, we can. And it's easy too.

There are two methods I'm going to address: One for those who like templates, and one for those who don't.

The Template method
Templates are a very powerful part of the C++ language... but in my personal opinion, they can also be messy, unwieldy abominations that make your code look like it fell part-way into a mincer.
It all depends on how you use them, of course.

Originally, I was just going to write the quick and dirty 'macro' technique, as below, but then on the spur of the moment I added this as an elegant alternative.

Code

template<class ATYPE>
class Singleton {
    public:
        static ATYPE & getInstance() {
            static ATYPE singleton_instance;
            return singleton_instance;
        }
};


And that is pretty much it. Define your classes as such:
Code

class Tester : public Singleton<Tester> {
    private:
        Tester(){} // Prevent construction
    public:
        void doSomething() { 
            printf("Something is being done\n");
        }
};


And use it like this:
Code

int main(int argc, char** argv) {
    Tester::getInstance().doSomething();
}


Or, as I like to do it:
Code

#define INST(singleton) (singleton::getInstance())

int main(int argc, char** argv) {
    INST(Tester).doSomething();
}


Works like a charm, easy to use, and easy enough to understand.

The Black Magic method (Macros)
First things first, Macros aren't by any means "bad". But there are "bad" ways to use them.
The C Pre-processor is a very powerful tool in the right hands; I use it to process my game scripts (Whether LUA or Squirrel), allowing me to use the ever-useful #include directive, as well as macros.

Macros, when used incorrectly, can cause all kinds of headaches for the developer; so use them at your own risk.

This, however, is an interesting little use for the things.

Code

#define DECL_SINGLETON(stype) static stype & getInstance() { static stype singleton; return singleton; }
#define INST(singleton) ((singleton&) singleton::getInstance())

class Test2 {
    private:
        Test2(){}
    public:
        void doSomething() {
            printf("Something else is being done!\n");
        }

        DECL_SINGLETON(Singleton)
};

int main(int argc, char** argv) { 
    INST(Test2).doSomething();
}


Arguments for and against either method
Both of these methods work; they are almost equal in performance, identical in use... it's just a case of how you want to create your singletons.
Personally, I'm a fan of simply inheriting from the Singleton type. It's clean, elegant and easy.

On the other hand, you may be working in an embedded environment where templates may not be supported (Unlikely as that may be. Embedded systems are pretty sophisticated these days). Or, you know, you're using wxWidgets and already have a million macros sprinkled throughout your source.

So basically, flip a coin.

Footnote
I'll probably be posting a few updates on that game, specifically on the 'porting' process, within a week or two.
Though porting is a bit of a grand word to use; it's like creating a whole new game; I'm just reusing the art and game rules. :P



Prev Page | Next Page

Recent Activity
 
Active Users (0)