caustik's blog

programming and music

Archive for the ‘Programming’ Category

Where’s caustik?

with 9 comments

Geesh haven’t updated this blog in a while. I’ll do this mini update at least..

Took a new job at opencandy (some really cool stuff in the pipeline there!), still pushing out DJ mixes here and there over at my soundcloud page (caustik’s sound cloud). Create a soundcloud account if you haven’t got one already and make sure to add me =)

Every once in a while I’ve been working a bit on this app that lets you create sprites that can walk around your desktop and interact with your windows and each other. Here’s a little screenshot. It’d be cool to talk with some of the guys who run sprite repository web sites and get a bunch of characters created =)

Here’s the latest build. Just drag and drop an .spr file or any image file on the executable and it should drop on your desktop. You can drag and throw them around, and you can click the sprite/image and press left/right/up/down/space to move it around. It’s fairly basic right now, but the plan is to make them able to walk around by themselves and interact more, etc.

sprites

oh, and double click to exit. if you drag and drop a bunch of them, they all open in one instance and double clicking on one will close them all. have fun =)

Written by caustik

January 7th, 2011 at 10:34 pm

Fix for multiple monitors with fullscreen games

with 3 comments

There’s a pretty annoying issue that happens in windows when you are playing a game in fullscreen on one monitor, and have a second (or third, fourth) monitor with other stuff open on it. If your game is playing at a resolution that is different than your normal desktop resolution on that monitor, everything gets all moved around on the other monitors.

To fix this, I wrote a tiny utility program which you can run before you start the game, and it fixes this behavior by calculating what the correct location should be for all your windows and moving them there. It’s useful if you like having IM windows open, notes or a web browser, etc. You can’t interact with those programs while you’re in the game, but at least you can *see* them (for example, if you have a strategy guide or map, etc open)

Of course, I’m not responsible for any damage this program does to your computer. I’ve tested it a fair amount, but it’s entirely possible somebody with an unusual setup could find a situation where you may lose a program’s window due to it being positioned in the wrong place.

Let me know if this is useful, I’ll try to improve it and turn it into a proper project.

fsfix

caustik

Written by caustik

September 6th, 2010 at 4:28 am

Posted in Games,Programming

Tagged with , ,

Prettier C/C++ code using explicit scope

with 3 comments

Probably the single most impactful epiphony I’ve had in my years of programming in C/C++ is discovering the ability to provide explicit scope inside a function. For snippets of code that are conceptually self-contained, but only used once in the program, they improve readability, provide optimization hints to the compiler, and are just kind of cool =)

Here’s some “before” code, like you’d expect to see throughout C source code:

int func1(int param1, int param2)
{
    int ret = GREAT_SUCCESS;
    int tmp1, tmp2;
    structType struct1;
    otherStructType struct2;

    struct1.val1 = param1;
    struct1.val2 = 20;

    /*! do something */
    ret = func2(&struct1);

    if(FAILED(ret)) { return ret; }

    struct2.whatever = param2;
    struct2.somethingElse = 4;

    /*! do something else */
    ret = func2(&struct2);

    if(FAILED(ret)) { return ret; }

    return ret;
}

The variables are declared at the top of the function, the parameters for each function call
are determined, the struct parameter is filled out, return code checked.

Compare to using explicit scope:

int func1(int param1, int param2)
{
    int ret = GREAT_SUCCESS;

    /*! do something */
    {
        structType struct1;

        struct1.val1 = param1;
        struct1.val2 = 20;

        ret = func2(&struct1);

        if(FAILED(ret)) { return ret; }
    }

    /*! do something else */
    {
        otherStructType struct2;

        struct2.whatever = param2;
        struct2.somethingElse = 4;

        ret = func2(&struct2);

        if(FAILED(ret)) { return ret; }
    }

    return ret;
}

What this has accomplished is your eyes immediately see that “do something” and “do something” else
are functional blocks, which you can quickly read as independent units. In addition, you can very
easily tell that the function simply “does something”, then “does something else”, then returns the result.

Each functional block has it’s variables declared only inside it’s explicit scope. So you don’t have this huge block of declarations at the top of your function, making things much easier to read. Also, the compiler now knows without ambiguity which variables are used where, which can help optimize it’s memory usage (e.g. it can re-use stack space instead of reserving it all at the top).

To me, the difference is night and day – and this is only a really simple example. Try it out on some
more complex code, and watch your code quality/readability improve. This works in both C and C++, it’s
particularly great for C since you normally are forced to declare your variables at the top of the function.
When you explicitly declare your scope, this is no longer the case! Really, C just makes you declare at the
start of {} blocks.

Written by caustik

April 12th, 2010 at 12:37 am

Posted in Programming

Tagged with

[Electronica] Caustik – Add9

with one comment

Just added a new electronica track to soundcloud. add9 is the chord returned to at each phrase. Yea, so maybe I’m not great at coming up with names… :)

Written by caustik

November 6th, 2009 at 7:21 am

autoblitz + source code

with 163 comments

Since some folks have expressed interest in trying this bot for themselves, I decided to share the source code and binary :)

It’s not perfect, but you can tweak the source code (for example, changing how long rp_thread::sleep() is called, and where), and probably get some better performance. If you’re up for a challenge, you can also try to improve the code that decides on the next move! (if you do, it’d be great if you shared the changes!).

Anyway, here is the zip file. [ autoblitz-export.zip ]

The binaries are in the export directory. You will be asked for a “hWnd” (window handle), which can be found using the program “Spyxx” which comes with visual studio.

Written by caustik

April 12th, 2009 at 3:10 pm

Posted in Games,Hacking,Programming

Tagged with ,

Cxbx Update (Smashing Drive in-game)

with 2 comments

Updated the official Cxbx site, with an update from shogun: http://caustik.com/cxbx/

Written by caustik

December 2nd, 2008 at 8:51 pm

Posted in Cxbx,Hacking,Programming

Tagged with , , , ,

cygstart

with 4 comments

Just stumbled upon a simple but really useful cygwin command –

“cygstart .”

Typing this command will do something simple, but really nice. It will open an explorer window at the your current directory. Seems so simple and dumb, but when you tend to juggle a lot of explorer windows, and tend to use cygwin frequently, this is a nice way to help speed things up!

Written by caustik

May 13th, 2008 at 2:22 am

Posted in Programming

Wtf, MS?

with 5 comments

When you see this line of code in your source window, how does your brain read it?

My brain says “There’s a hex number, with a couple of 1′s in it.”

Guess what? WRONG. It has one ’1′. The end character is a secret hidden lowercase “L”. Thanks, Microsoft. Lucida console has literally a one pixel difference between it’s ’1′ and ‘l’, which is fairly typical. These things are speckled all over mmsystem.h. Personally I never use ‘L’ at the end of a hex digit, and if I was feeling clinically insane enough to do it, I’d at least use a capital ‘L’.

Written by caustik

May 5th, 2008 at 5:25 pm

Posted in Funny,Programming

Cxbx Progress

with 77 comments

There was some amount of activity in a private branch in the Cxbx project recently..

I have been talking to a developer, Martin, who has spent some of his extra time fiddling with Cxbx. He was able to get some teaser screenshots from Battlestar Galactica. The game displays the menu, and even some in-game. I won’t get into too many details, but here are a couple screenshots.

Battlestar Galactica - menu 2 Battlestar Galactica - menu 3

Battlestar Galactica - in-game (fullscreen) Battlestar Galactica - in-game (windowed)

I have not started to work on Cxbx on a regular basis — but I think this progress is very motivating, and it is tempting me to boot back up my development setup and take another look after a very long absence.

Many thanks to Martin for the contributions and for allowing me to post about his progress. Cheers.

Written by caustik

September 25th, 2007 at 5:05 pm

Posted in Cxbx,Hacking,Programming

Tagged with , , , ,

Painless Debug Console

with 18 comments

I have had the pleasure of writing a pretty large number of apps for Windows. There are a few things that I have learned, over time, that have really helped to improve my productivity. One of those things is a basic debug console.

Typically, a debug console is handy – go figure – while you’re debugging. Once you have a release quality build, you won’t want the debug console hanging around anymore.

This is one of those snippets of code that, while brutally simple, is rather non-obvious and most people don’t know of.

#ifdef MYAPP_DEBUG_TRACE
if(AllocConsole())
{
    freopen("CONOUT$", "wt", stdout);

    SetConsoleTitle(L"MyApp : Debug Console");

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);

    printf("\n");
    printf(" MyApp Debug Console\n");
    printf("\n");
}
#endif

Basically this code, if debug trace preprocessor is set (add MYAPP_DEBUG_TRACE to your preprocessor settings), will allocate a nice little debug console window, change the title, set the font colors, and redirect standard output to the console.

This snippet of code can be added to any Win32 application, and gives you the instant capability to spit out oodles of delicious debugging data. Typically, I combine this method with something along these lines:

#ifdef __cplusplus
inline void null_func(char *format, ...) { }
#define DbgEmpty null_func
#else
#define DbgEmpty { }
#endif
/* Debug Trace Enabled */
#ifdef  MYAPP_DEBUG_TRACE
#include
#define DbgPrintf printf
#else
/* Debug Trace Disabled */
#define DbgPrintf DbgEmpty
#endif

Now, you can use the function “DbgPrintf” just as if it was “printf” – and it will compile away to nothing in a release mode build!

Written by caustik

October 24th, 2006 at 5:51 am

Posted in Programming

Tagged with