Moved

23 11 2010

I’ve got my own web-space now.
http://blog.morleydev.co.uk

Gives me much more control and power. So yeah, moved all posts there and gonna update there from now on.





Cocktails: Jamaican Gluttony

19 11 2010

And now for something completely different…booze!

Ingredients:

  • 1 part Vodka
  • 1 part White Rum and Coconut
  • 2 parts Cranberry Juice
  • 3 parts Orange Juice

Just put these into a cocktail mixer, punch bowel, milk jug or container of your choice, mix, and voila and nice and sneakily strong drink punch. I worked it out, and it comes to about 10% alcohol. Enjoy.

Quote of the Day
“It only takes one drink to get me drunk– I can just never remember if its the eighth or ninth.”
George Burns





Generic Bresenham’s Line Algorithm in Visual Basic .NET

18 11 2010

Module Module1

    Sub Swap(ByRef X As Long, ByRef Y As Long)
        Dim t As Long = X
        X = Y
        Y = t
    End Sub

    ' If the plot function returns true, the bresenham's line algorithm continues.
    ' if the plot function returns false, the algorithm stops
    Delegate Function PlotFunction(ByVal x As Long, ByVal y As Long) As Boolean

    Sub Bresenham(ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, ByVal plot As PlotFunction)
        Dim steep As Boolean = (Math.Abs(y2 - y1) > Math.Abs(x2 - x1))
        If (steep) Then
            Swap(x1, y1)
            Swap(x2, y2)
        End If

        If (x1 > x2) Then
            Swap(x1, x2)
            Swap(y1, y2)
        End If

        Dim deltaX As Long = x2 - x1
        Dim deltaY As Long = y2 - y1
        Dim err As Long = deltaX / 2
        Dim ystep As Long
        Dim y As Long = y1

        If (y1 < y2) Then
            ystep = 1
        Else
            ystep = -1
        End If

        For x As Long = x1 To x2
            Dim result As Boolean
            If (steep) Then result = plot(y, x) Else result = plot(x, y)
            If (Not result) Then Exit Sub
            err = err - deltaY
            If (err < 0) Then
                y = y + ystep
                err = err + deltaX
            End If
        Next

    End Sub

    Function plot(ByVal x As Long, ByVal y As Long) As Boolean
        Console.WriteLine(x.ToString() + " " + y.ToString())
        Return True 'This just prints each co-ord
    End Function

    Sub Main()
        ' example
        Bresenham(1, 1, 10, 15, New PlotFunction(AddressOf plot))
        Console.ReadLine()
    End Sub

End Module

I wrote this quickly for someone over on a roguelike forum whose Bresenham’s Line Algorithm code wasn’t working. I don’t pretend to like Visual Basic .NET, I don’t pretend to use it with any regularity. In fact, I’m with Dijkstra regarding BASIC languages.

What makes it generic? It uses delegates (which as so much neater in C#. If I wasn’t writing to help (though the really helpful advice should be: Get away from Visual Basic and never return to it) I’d have written it in C# obviously) so you can plug any plotting function you like in there. This means it could be used for graphics, calculating line of sight, and much more without actually needing to touch the function or do needless position calculations.

Update: I had to do it. I needed to wash away the sin by writing a C# version:

using System;

namespace Bresenhams
{
    /// <summary>
    /// The Bresenham algorithm collection
    /// </summary>
    public static class Algorithms
    {
        private static void Swap<T>(ref T lhs, ref T rhs) { T temp; temp = lhs; lhs = rhs; rhs = temp; }

        /// <summary>
        /// The plot function delegate
        /// </summary>
        /// <param name="x">The x co-ord being plotted</param>
        /// <param name="y">The y co-ord being plotted</param>
        /// <returns>True to continue, false to stop the algorithm</returns>
        public delegate bool PlotFunction(int x, int y);

        /// <summary>
        /// Plot the line from (x0, y0) to (x1, y10
        /// </summary>
        /// <param name="x0">The start x</param>
        /// <param name="y0">The start y</param>
        /// <param name="x1">The end x</param>
        /// <param name="y1">The end y</param>
        /// <param name="plot">The plotting function (if this returns false, the algorithm stops early)</param>
        public static void Line(int x0, int y0, int x1, int y1, PlotFunction plot)
        {
            bool steep = Math.Abs(y1 - y0) > Math.Abs(x1 - x0);
            if (steep) { Swap<int>(ref x0, ref y0); Swap<int>(ref x1, ref y1); }
            if (x0 > x1) { Swap<int>(ref x0, ref x1); Swap<int>(ref y0, ref y1); }
            int dX = (x1 - x0), dY = (y1 - y0), err = (dX / 2), ystep = (y0 < y1 ? 1 : -1), y = y0;

            for (int x = x0; x <= x1; ++x)
            {
                if (!(steep ? plot(y, x) : plot(x, y))) return;
                err = err - dY;
                if (err < 0) { y += ystep;  err += dX; }
            }
        }
    }
}

Quote of the Day
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
How do we tell truths that might hurt? – Edsger W. Dijkstra





Choice, Philosophy and Morality in video games.

30 10 2010

I’m not going to deny it, I find moral choices in video games fascinating. On the one hand, having options and therefore the illusion of control is very nice. On the other, for f*cks sake video games, why is the choice always to be either Jesus, Satan or apathetic?

At it’s core, our sense of “Morality” is just avoidance of the negative consequences of actions that aren’t worth the potential benefits of those actions. Conscience is the voice in our head that says “Well, if we get caught doing x sh*t will hit the fan and life will suck for awhile”. Whether this is something inherently involved into people, or a conscious process, does not change that this is where morality stems and a moral system in games needs to be designed to reflect that. Games have no real consequences anyway, which is why games have to dangle some form of engineered carrot in front of players.

Star Wars: KoToR had simple carrots, dark side powers which hurt enemies and light side which healed and buffed allies. Being light side or dark side was basically a playing style choice. Dark side sometimes had an extra money carrot, but not always. Sometimes you got more from light side. Or you could take less light-side points by asking for a reward but get more money or…you get the idea.

Mass Effect has two carrots: Being a bastard gives you renegade and lets you do more intimidation, being a paragon let’s you be more charismatic. But the carrots are the same both ways, being renegade is just funnier to watch most of the time. I can’t be the only player he basically did all the big paragon choices but at every other step of the way was a complete bastard, just so he could laugh at the bastardry.

Both these carrots give players “the weaknesses of amorality”, being a grey made you inherently weaker which sucked.

Personally I’d like to see a game implement a morality system akin to that of the World of Darkness: One-way. Being cruel cost you morality, but when only your current morality was above the level of cruelty of that action. A common thief would not lose any more morality from stealing, but if they ever kill someone they’d take a plunge. Also it means the game can easily keep track of how to treat the player, you can’t “puppy-poke” your way to becoming the Lord of the Sith.

Of course some kinds of carrots would be required. WoD implements “derangements”, as your character goes more (a/im)moral they go insane(r). This means players have to balance the rewards of their “evil” actions with the risked penalties of such actions. Also this situation can lead to interesting problems, like the “batman dilema”. If Batman (the player) kills Joker (some bad guy), killing becomes easier for Batman (Morality score lowers) and he may therefore do it again (no longer risk of gaining a derangement from murder). You effectively put the player at the top of the slippery slope and watch them roll down.

Understandibly, choices and a morality system can only be implemented into a relatively freeform game, otherwise they feel incredibly painful. They are best suited to games which, like novels, explicitly make one of their purposes simply to be making you think. Take for example, Planescape: Torment. A cult classic with very little emphasis on combat and much ultimately on a simple question:

“What can change the nature of a man?”

A question with so many answers that reveal so much about the person creating the answer. Take me for example, ask me this question and my answer would be profit. What can change the nature of a man? What he stands to gain from making that change. Others would come up which so many different answers, age, time, death, belief, hope, fear, regret, so many possibilities. These kinds of games are fascinating. They offer insights into the human condition, and our own depravities.

Knights of the Old Republic 2, Fallout 2, Planescape: Torment, all of these were story based in my opinion. It was the story that interested me, the story that kept me playing, and the choices that story provided that made me play again.

These are the games that we replay because we want to see real differences in our choices, they are highly character based, highly plot heavy, and I think we need more of them. I am interested in what you all think of almost entirely story-driven games, to the point of being almost if not entirely interactive fiction. From a game development point of view, the pros and cons of such games would be a fascinating discussion.

So, what is your opinion on low-action, high-narrative games? What do you think can change the nature of a man?

Quotes of the Day
“The belief in a supernatural source of evil is not necessary; men alone are quite capable of every wickedness.”
“What makes mankind tragic is not that they are the victims of nature, it is that they are conscious of it.”
Joseph Conrad





Java Event Maps

18 10 2010

I openly admit to not being fond of coding in Java. It’s just not got the elegance C# has. However, I will use Java if only to remind myself why I don’t like using it.

I recently did just this. Largely so I could see whether the event queue system I made in C++ could easily port to Java and C#. Guess what? It does. This pleases me.

Here’s a code example of how to use the event queue:

package eventtesting;

import JpmEvents.CEventMap;
import JpmEvents.IEvent;
import JpmEvents.IEventHandler;
import JpmEvents.BEvent;

/**
 *
 * @author Jason
 */
public class Main
{
    private class TestEvent1 extends BEvent { public TestEvent1() { super("TestEvent1"); } }
    private class TestEvent2 implements IEvent
    {
        public Integer Hash() { return Name().hashCode(); }
        public String Name() { return "TestEvent2"; }
        public TestEvent2() {  }
    }

    private boolean OnEvent(TestEvent1 e)
    {
        System.out.println("Event One Called!!!");
        return false;
    }
    private boolean OnEvent(TestEvent2 e)
    {
        System.out.println("Event Two Called!!!");
        return false;
    }

    protected void Run()
    {
        CEventMap emMap = new CEventMap();

        emMap.Bind(new IEventHandler<TestEvent1>(){public boolean HandleEvent(TestEvent1 event){return OnEvent(event);}}, "TestEvent1");
        emMap.Bind(new IEventHandler<TestEvent2>(){public boolean HandleEvent(TestEvent2 event){return OnEvent(event);}}, "TestEvent2");

        System.out.println("Triggering events...");
        emMap.Trigger(new TestEvent2());

        System.out.println("Queueing events...");
        emMap.Queue(new TestEvent1());
        emMap.Queue(new TestEvent2());
        emMap.Queue(new TestEvent1());

        System.out.println("Flushing events...");
        emMap.Flush();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        Main m = new Main();
        m.Run();
    }
}

And here is the link to the Project Kenai page I’m making the library and it’s source available on, under the MIT Licence

.

Quote of the Day
“I account for morality as an accidental capability produced,
in its boundless stupidity, by a biological process that is normally
opposed to the expression of such a capability”
George C. Williams (May 12, 1926 – September 8, 2010)





Refactoring

16 10 2010

“I don’t like how I did this at all! TO THE REDESIGN ENTIRE SYSTEM FROM GROUND UP MOBILE!!!”

So I basically had the realisation that my for Project Pauper design was modular so would be better fit into multiple Dynamically Linked Libraries than one Statically Linked Library. Unfortunately, my event system relied on RTTI, which in C++ under Windows can’t be relied upon across DLLs. At all. Ever.

So I decided to pull the event system and replace it with a new one. And one thing led to another and suddenly I had decided I wanted to refactor half the code. Joy.

Zip and date old Pauper, move it to backup directory and begin working on new pauper. Most of the start up is just getting what worked in the old to work in the new, copy and paste or rewrite as I go.

Whilst I was at it I decided Window and Graphics Device should not be one item, but separate. This design is one I dropped awhile ago, but fsuck old me, new me says it comes back. I have finally figured a good way to keep window logic in it’s own thread though, via a thread-safe event queue sitting between the window’s events and the events Pauper has to respond to. It just feels cleaner for some reason.





OMG UPDATE!

19 09 2010

Hello from a place that is not Nottingham! Yep, I moved house. Well, temporarily…ish. I’m in Brighton and Hove now. Yes, Brighton and Hove. That’s what the area of England is called. Honestly.

I am going to be studying Computer Science at the University of Brighton. You see, awhile ago I was going to Bath. They rejected me because I failed my A-Levels. Well, I didn’t fail. I got BBC, which people tell me isn’t bad. But I failed enough to not get into my choice universities. Fortunately (or un, we shall see) Brighton had places in clearing (BBC is dead on in terms of their requirements) and I didn’t fancy repeating the year, especially since the college I was going to stopped it’s Computing course so I would have to go to a different one…yeah, too awkward.

Instead, I begged until they offered me a place in clearing ^^ So, here I am. Hello Brighton and Hove. I frantically found a place to live with some other students whom I have never met, and I moved in yesterday, and so far am the only one living here has been jolly devilishly handsome me.

I met the neighbours (another student house) and they seem nice, but that’s about the extend of my socialisation so far. I’m still getting used to the place. In another day or too, my “joint tenants” will arrive and we’ll all meet face-to-face and the fun can begin.

In the rush I’ve not done much programming lately, though I did make Tic-Tac-Toe with the Project Pauper Framework. That’s…something, right? It’s only like an hour of programming at most. Not a lot, but something. Now I’ve a bit of time I may start work on something else, Space Invaders maybe?

Or maybe I’ll start work on the AudioCore component of Project Pauper…because audio is such a delight to work with

Quote of the Day
“The true interest of an absolute monarch generally coincides with that of his people. Their numbers, their wealth, their order, and their security, are the best and only foundations of his real greatness; and were he totally devoid of virtue, prudence might supply its place, and would dictate the same rule of conduct.”
Edward Gibbon, The Decline and Fall of the Roman Empire, Chapter V








Follow

Get every new post delivered to your Inbox.