Singpolyma

's Profile

Author Archive

BitBrawl, Opening Screen

Posted on

It’s not got a very shiny look yet, but I’ve got an opening screen for BitBrawl working now that lets the players join and configure their controls simultaneously. Only one player is actually rendered once the game is started by pushing one of the configured START buttons, but it is progress!

BitBrawl Opening Screen

After the game is started, the player can, as before, walk about the screen using the controls as they were configured for player 1.

The code is a bit hacky, but I’m quite excited by my progress so far!

Liberated Pixel Cup

Posted on

This is my first post about the Liberated Pixel Cup. I only became aware of the contest near the end of last month (indirectly, though a discussion on identi.ca) and was immidiately intrigued. The first phase of the contest (which is completed) involved pixel artists submitting compatible-yet-thematically-diverse isometric art. One of the big blockers to me getting seriously involved in a video game project has always been access to a body of art. Looking over the art that has been submitted, I think there is enough to do something I would be interested in, so I decided to start.

Using my latest favourite hammer, Haskell, as well as previous favourites of mine, SDL (which has good Haskell bindings) and Chipmunk Physics (which has acceptable Haskell bindings, though a bit out of date), I played around with ideas until I hit some inspiration. I am going to attempt to create a PvP brawler (dubbed “BitBrawl”) since this is a sort of game that I have always enjoyed (and of which there are too few!) I’m going to experiment with a twist involving “energy pellets” that players pick up which both decrease their odds of being eliminated (damage increases said odds) and gets used up by special abilities. I’m currently enjoying my new LoL gutter that I bought at unrankedsmurfs.com.

I want the combat mechanics to be of medium complexity (more complex than “hit A repeatedly”, but simpler than something like God of War), and auto-generated maps. Though honestly that’s a bit grandiose at this point. My primary target with the project is really experience, though I hope to also get a playable game out of it that can maybe be improved upon after the competition ends.

The last two days are the first chance I’ve really gotten to do some serious coding, and I’ve made quite a bit of progress, given my lack of experience with the tools and with game development in general. I have a single player who can walk around the screen (using any of the walkcycle art submitted to the competition) using configurable (hard-coded, but in a datastructure) keyboard commands and configurable (I parse a text file) animations.

Character control uses the top-down “Tank demo” physics from Chipmunk, which means that collisions and such will be nicely handled for me (once I get around to adding a second thing to the space).

My next step will be allowing two characters to be walking around. Then maybe a better background than just all-black. Then trivial combat. We’ll see how far I get.

One thing I’ve had to do is make a small patch to the Chipmunk bindings for Haskell to give me access to the maxForce and maxBias properties of constraints (necessary for the “Tank demo” physics). I will submit the patch upstream, but may have to package the library myself for my submission if it does not get mainlined in time.

I have released the code on GitHub under my normal ISC license, as well as the GPLv3.0 license required by the competition. There is no art or data in the repository yet, so it won’t run unless you put some in, but you can take a look. It’s a bit messy and IO-heavy right now, but it is getting cleaner as I go.

Hope to write more later.

Business Cards

Posted on

This morning, I went through my backpack and threw out all the business cards I have collected. If I have met you in the last 5 years and you’ve never actally corrosponded with me, it may be that I no longer have your contact information.

Why?

Because they were just taking up space in my backpack. Some of them have been in there so long that they could no longer be read. One of them was just a paper with an email address scribbled on it.

Why did I have so many? Because at every conference and networking event I go to, people try to shove me their business cards. Sometimes I take them to be polite, and sometimes I take them because I’m genuinely interested in the person or what they do. In the end, though, if they never contact me and I don’t have an immidiate reason to contact them, the card just sits in a pile. I suppose I could transcribe them into my digital address book, but that takes work.

This is why I’ve never really had business cards and I don’t give them out. I have a simple string of characters, “singpolyma”, that I give out to anyone who asks. This string of characters will find my on almost any service, or on a web search. Then, if you actually want to connect with me about something, you can do so using the mechanism that makes the most sense.

Similarly, if I actually want to connect with you, I will probably write down why I want to connect and who you are on my phone. I may even initiate contact digitally (by adding you on IM or following on a microblogging service) while I’m still physically standing with you.

I’ve found that the really interesting people often keep popping up. I may stop taking business cards, or I may just clean out my backpack again in four more years, but I definitely won’t be giving out little waste scraps of cardboard any time soon.

Let’s Talk About Strings

Posted on

A string is a sequence of letters and numbers. It is text. Or, is it just any array? The term ‘string’ has been used and abused over time to mean many different things. This has lead to confusion, bugs, and a plethora of conflicting opinions.

The Two Main String Types

There are two things people mainly mean when they say ‘string’. On the one hand, they may mean a data structure representing human-language text. On the other hand, they may mean whatever data structure or type their programming environment often uses for representing human-language text. In many cases, this data structure is also used for other sorts of data, such as raw binary data.

This has lead to much confusion.

In some programming environments, like C, everything is low-level enough that there cannot be expected to be One True Way to handle a high-level concept such as “human-language text”. Other environments, however, should know better.

Encodings

An encoding, in the context of text, is the scheme whereby text is represented in actual bytes. I will talk about three different kinds of encodings: internal, input, and output encodings.

Internal Encoding

In low-level languages (and, sadly, many high-level languages) there is no native support for the high-level concept of ‘text’. The programmer is given a way to represent an array of bytes (also called a byte string) and must decide how to encode text in RAM for his/her own application. This is true of C’s char*, Ruby 1.8’s strings, and many others. Historically, ASCII was the de-facto internal encoding, but this is not generally acceptable if your application will be used for anything except a subset of English. Different internal encodings have different trade-offs, which I’m not really interested in covering here. As with so many other things you probably should not be making this decision. Find a library or a programming environment that handles text and let it deal with how to actually store the data in RAM.

Input Encoding

Input encoding is the only encoding an application programmer should ever have to deal with. Unfortunately, for historical reasons, there are a plethora of encodings out there. You will have to decide a way to know how the file, network socket, or other input you are reading is encoded. Many protocols and file formats have simple markers that will let you know. You have to feed this information to whatever calls you use to get your high-level text representation from the input.

Output Encoding

This is the encoding you use in files you write, prints to stdout, bytes you send over network sockets, etc. If you are writing some existing file format or protocol, you need to see how that format handles specifying what encoding you are using and correctly mark it. This, however, should be the extent of what you need to do to handle output encodings. I’m going to say something some people consider controversial, but I’ve given it a lot of thought, and after working with this stuff in many contexts I’ve come to a conclusion.

There is only one acceptable output encoding, and it is UTF-8.

Always.

There are some people around who will bad-mouth Unicode for some of the problems it had historically (for awhile they used 16-bit-max-width encodings and could not properly handle some Asian languages), but these have been fixed for some time now. The standard is not set in stone, so if bugs are found they can be fixed.

The other thing people complain about is that UTF-8 is unfairly smaller for English text than it is for other text. It is true that language-specific encodings will take less space than UTF-8, however the complexity and potential for bugs that comes from using a plethora of encoding mechanisms as a hobo compression mechanism is not worth it. If you’re concerned about space, then compress your content.

UTF-8 is backwards-compatible with ASCII implementations, such that they will continue to work in a UTF-8 environment (at least as much as they ever worked). This also means that your application can easily handle old ASCII data even if all you implement is UTF-8.

Haskell and Ruby

As a way to illustrate this topic, I will take as examples Haskell and Ruby 1.9.

In Ruby 1.9, strings have an associated encoding. They are objects with a byte string and an encoding property. When you write them out, they are written in whatever encoding you specify. This is a huge improvement over 1.8 (where all encoding decisions were manual), but still exposes more complexity than is necessary to the programmer.

Furthermore, all I/O operations in Ruby 1.9 are done using String. How is binary data read, then? String has an associated encoding called ‘binary’. This is just shameful. The programmer still has to keep track of which String are text and which are byte strings.

In Haskell, the default String type is actual an alias for [Char] (a list of Char) and Char is defined to be a 32-bit Unicode code point. It is unequivocally for text. Binary data can be represented as [Word8] (a list of Word8, that is, a list of bytes).

Because linked lists are not always the most efficient, there are also convenient array-packed-representation libraries for both of these types, intuitively named Text and ByteString.

Unfortunately, because of the confusion that often comes from the shameful state of so much tooling, many Haskellers use ByteString.Char8 to store what should be Text, and handle the internal encoding themselves (often poorly).

I/O in Haskell can easily be done directly with any of these types.

Summary

  1. Use a text library for text, use a raw byte string type for binary data. Do not confuse the two.
  2. If you’re reading an existing format, you’ll have to correctly detect the input encoding and transform to the datastructure used by your text library.
  3. If you’re writing an existing format, you’ll have to correctly identify what output encoding you’re using.
  4. You should only use UTF-8 as your output encoding.

Dystoparx — Part 17

Posted on

Child Abuse Right at the Top?

Yesterday, RCMP Comissioner Robert Sandall was suspended on suspicions raised by an internal investigation. No details have been released, but a source close to the matter has told the CBC that Sandall may be implicated in several cases of direct child abuse and possibly the creation and distribution of child pornography. No charges have yet been filed.

Watch this space for updates as the situation develops.

Acklas pulls out his laptop and logs on. He has taken a bus to a neighbouring city and is in a coffee shop there, hoping no one will bother him to buy something before his task is complete. Everything that needs doing has been scripted in advance. He runs the script and watches the output, hoping that everything works on the first try. To his suprise, it does. He smiles. Good, everything is in place. He double-checks a couple of things to make sure the script has indeed done its job. It has.

He closes his laptop and waits a few minutes before heading out. No one bothers him.

Acklas boards a bus heading back towards home. He waits several more minutes before putting the battery back in his cell-phone and connecting to a chat with Jack and Nicnus.

* Your connection has been secured

17:19 <acklas> on to phase 2 😀

17:21 <jjdavis> phase 2 of what?

17:22 <nicnus> jjdavis: of his plan to take down All the Bad Guys

17:23 <acklas> nicnus: 😛 yes, sure

17:23 <jjdavis> what does phase 2 entail?

“What do you mean, it’s gone?” Bill gives the tech a smouldering stare.

“Well, uh… obviously we still have any data we saved out of the stream as it came in, but—”

A second tech breaks in, trying to save the first from some embarassment, “But nothing is coming in anymore. That source is sending literally no data.”

Bill considers this, then calms down, “That’s expected. The Comissioner has been suspended. He knows we know. He would stop anything that was happening.”

A moment, then, “Sure, but—”

The first tech breaks back in, “We called the MusicBox people. They have no record of any of the data. At all.”

Bill considers this. No record at all? But… it’s their data. All the data comes from the MusicBox people… “How is that possible?”

“We don’t know.”

Someone is calling his name. He looks around. A head pops up from another area of the office and calls him over.

They’re showing him a YouTube video. What? A YouTube video? Something is happening, he—

“Shh.”

Clouds are rolling on the screen. A storm. Some kind of nature video? Then the voice begins.

Chilling.

It’s clearly just a cheap computer voice, and yet… paired with the visuals this computer voice sounds like… well…

“Good morning,” it begins, flubbing the intotation already just this far into the speech, “When the RCMP and other law enforcement agencies first got excited by the idea of circumventing privacy law by taking the data being collected by the MusicBox software and using it for their own purposes, many experts pointed out that flaws in the system could allow false data to be injected into the stream. Some of these weaknesses were exploited to produce an anti-spyware pseudo-virus, which now lives on many of your computers, protecting you from the prying eyes of those who would read your private data.

“Yesterday, I proved a practical exploitation of a much more sinister weakness. I sent false evidence of child pornography creation and distribution to the RCMP, and only to the RCMP. No one else has this data. On the basis of this data and this data alone (for there could not be any other source, especially given the timing), the RCMP suspended their own Comissioner and began an internal investigation.

“The code which I used to do this has been published at the location linked to in the description of this video. It is so simple, and yet the most important law enforcement agency in Canada started a witch hunt after just one day of its use. Imagine what would happen if they were given the power to exploit other, even less reliable, data streams? It would be just like the French Revolution: accusations flying wherever they will, and law enforcement blindly following along with everything they are told.

“I have stopped the transmission of the false data. I hope the law enforcement officers, the politicians, and the media, will see this as a sign that they cannot trust the data they have been trumpeting as their salvation. No real arrests have come of these projects, and now it is obvious that many false arrests may be their eventual result.

“If, however, this warning goes unheeded, I have no doubt that many others like me will rise up to make chaos. Too long have we sat aside while our governments slide into a pit. They have declared war on us the people, and if it is war they want, then we will bring the chaos. We are Anonymous. We are Legion. We do not forgive. We do not forget. Expect us.”

17:50 <jjdavis> Really, acklas? An *Anonymous* video?

* acklas shrugs

17:51 <acklas> seemed like a reasonable way to communicate

* nicnus shakes his head

17:54 <acklas> either way, the ball is now firmly in their court. I may not even have to do anything more

17:55 <nicnus> acklas: you have way too much faith in the Internet Hate Machine. They get bored easily

17:55 <acklas> maybe

Later that day, Nicnus’ brother also sees the video. He shows it to his girlfriend. They have no idea. His girlfriend, however, is disgusted. She supports the legitimate actions of law enforcement to bring an end to all that is unwholesome. Or something like that.

She’s watching her favourite talkshow. Or whatever this sort of show is being called by her social group. The video has become a topic. Acklas has done a very good job of blanketing the media in awareness. Lots of messages went out. Once the mainstream is reporting it at all, then they all have to report it, or look like they’re behind. The show’s host is asking for submissions on her website, to get feedback from “you out there” on what people think of the situation. There will be a summary on tomorrow’s show.

She flips open her laptop, navigates to the website, and begins a submission.

Well, I think it’s disgusting! here’s the police, trying to do something good, get rid of the weirdos that ppl the entire internet, and what does this guy do? he just makes their job harder! stupid. i dont care if what their doing can be faked…everything can be faked…he needs to get over himself and they need to arrest him so they can get on with their jobs, maybe if we give the police the ability to collect all the stuff from the internet, they can track this guy down and make ppl like him stop and then we can finally be safe!!

She slaps her laptop closed and walks off. Nicnus’ brother sits by his computer, thinking about hiding. She’s in that mood again. Ah, well, it’ll pass. He mouses around his system a bit, trying to find the program his brother prefers he use for chatting. Normally he would just text him, but his brother wouldn’t get back to him for hours in that case. He wonders breifly if Nicnus has got Facebook, but no, still no Facebook for Nicnus. Oh, there’s the program. Pidgin. What a stupid name. They should call it “geeky messaging application”. Actually, maybe he can rename it that, would make it easier to find…

He opens a chat with Nicnus and pastes a link to the video. Suddenly another window pops up. A chat with more than one person. Looks like his brothers’ friends.

* This chat is not secure

21:50 <brann> Woah, what is this?

21:52 <acklas> we were already discussing the video, so nicnus just brought you in here 🙂

21:53 <nicnus> brann: What did you think of the video?

21:53 <brann> g/f hates it.

21:54 <nicnus> suresure, would expect that

21:56 <jjdavis> nicnus: you rag on his SO too much

21:57 <nicnus> maybe

21:57 <brann> It’s a bit creepy.

21:58 <nicnus> brann: which is?

21:58 <brann> Well, all of it

21:58 <brann> the video is… but I think that’s more just a ploy or whatever

21:58 <brann> but, I don’t like the cops faking data for themselves either

22:00 <acklas> Who said the cops would fake data for themselves?

22:01 <brann> no one, but… seems the next logical step, no?

22:01 <brann> Not enough evidence on this guy? No problem, just make some and shove it in here. done

22:02 <jjdavis> holy crap…

22:03 <acklas> yeah. brann: I hope no one *else* thinks of that 😐

Jack is relaxing. His girlfriend is over, and she’s bubbling happily. He only sort of hears what she says. He’s just happy. Nothing has happened to him yet. If they were going to come after him, wouldn’t something have happened? Maybe not. Still, he’s happy for now.

More and more datacentres are finding the same sort of activity he found. One by one, they’re turning it off. If the FBI is snooping on their population, they won’t be for much longer. At least, not in the same way.

On a whim, he browses some of the groups where discussion is happening around the efforts to stop what most people are calling an ‘exploit’. One message in particular interests him. It seems that, hidden in the guts of some Omnibus bill about kittens, there is a section dedicated to increasing the online ‘wiretapping’ abilities of the FBI and other federal agencies. The mechanisms outlined are very suspiciously similar to what is already happening. If it becomes law, though, it won’t be hidden. The datacentres will be ordered to install this software on purpose.

His girlfriend has stopped talking. She’s looking over his shoulder. Wondering what’s up.

“Uh…” Will she even get it? If she does, will she care?

It doesn’t matter. He’s trying really hard. He’s not making assumptions about that anymore. He’ll tell her what’s going on.

He starts at the beginning, in the datacentre. He hasn’t told her before because it didn’t seem important, in light of their relationship trouble. Well, sure, maybe he should have mentioned it before now. No, nothing bad has happened yet. Maybe nothing will. Maybe it will become legal, he’ll be forced to re-install the software, and he can just pretend that’s it.

Yes, he does have a problem with what it seems the FBI is doing, even if it becomes legal. No, there’s nothing much he’s going to do about it. Why not? Because he’s a guest in this country and he wants to stay here. Because she’s here. Right, she’s not that interested in leaving. But can’t something be done? Spying seems icky. Yes, that’s her word, ‘icky’. Fine. Maybe. He’d really rather not stick his neck out and find out.

Well, wait and see for right now, that’s the plan. Maybe nothing will happen.