Show me the code: cpuid and popcount

 

So, modern CPUs have built-in functions for a lot of things, these days, which can offer you blisteringly fast access to some otherwise rather awkward and slow algorithms.

In my case, I wanted to access the CPU’s popcount function (count how many set bits there are in a value). The trick is that either the CPU supports it or it doesn’t, and different systems have different ways of testing if it does, and accessing it if it does. Of course if the CPU doesn’t support it, you still have to do it in software anyway.

So, I thought I’d write something extensible, and I thought I’d share.

Continue reading Show me the code: cpuid and popcount

Romance without routes. Breaking the CYOA/VN formula

Choice-based interactive-fiction comes in a whole bunch of narrative models. If you haven’t read the These Heterogenous Tasks article, Standard Patterns in Choice-Based Games, you should run right out and do that. It’s excellent, and I’ll be making some references to it. I’ll wait. Promise.

Done that? Good, let’s move along.

Continue reading Romance without routes. Breaking the CYOA/VN formula

How can your own characters surprise you?

You are responsible for their every thought, their every word, their every gesture. Not a one of them bears so much as a single punctuation mark that you didn’t put there.

But you hear writers say, “My characters surprised me.” It happens. It’s happened to me.


First, a little context.

I’m writing a multi-perspective branching novel, where the all of the main characters are simultaneously experiencing the narrative and making their own choices about it. You, the player, pick a character at the beginning, and ride along with them, making their choices, and following the narrative where it goes.

As seems to be usual for a writer, I selected my stable of characters, and invented as much information as I needed for them to fulfil their roles in my story. Gender, age, profession, prior knowledge of other characters, and so on. With a variable narrative you have key points where you know things need to be – or maybe points where you know they might get to. You fashion your characters to take your narrative to those milestones.

Fit-for-purpose characters, with the traits you designed, ready to line up on stage and perform whatever lines you hand to them.

But the tale grows, as they say, in the telling.

Each character’s narrative in this story is a complete thing. They speak and do, but they also think, consider and feel, all of which rolls out in a first-person narrative. Normally all that extra guff is reserved for the protagonist of a story, but I have a dozen protagonists right now. The narrative is complete, no matter who’s eyes you’re looking through.

That means you hold the characters apart, in your head. Apart from yourself and apart from each-other. You visualise each one as a living being and you think, what is going through his head right now? What is she feeling? And why?

And as the words scurry out into the keyboard from the fingertips, they surprise you.

This character has suffered at the hands of a sexist institution. That character is hiding his past. He prefers beers. She likes a certain kind of pastries. He is shy. She suffers from post-traumatic-stress disorder. He was (unexpectedly) married.

Temporarily, each of these characters gets to use your brain and your knowledge of the setting as you put yourself in their shoes. They suddenly know things about people or places or events that you did not know until they did. Having found it, it becomes a fact. And it snowballs. They make your world and themselves more solid, and the more solid it all is, the more interesting they become.

And things you planned ahead for? Well, maybe some of those have to be discarded, but what you get in exchange is just so much better.

Have you played D&D? Been the Game-Master, switching between a dozen NPCs, while you interact with your players from behind all those faces and personalities? Ever had your prepared material go out the window because of those interactions? It’s like that.

Solid characters in solid situations will surprise you. Thin characters will make themselves more solid (because underneath all your meticulous, or not-so-meticulous, planning that’s where your head is taking them).

But it’s your own head, isn’t it?

Well, yes and no. What did I see the other day? Oh, yes, this:

The king does the writing. You just whisper in his ear.

 

 

Branching story planning

I have a chart of the way scenes branch in the SNAFU story. You might have looked at that and thought “Well, that looks a tad complex” – or maybe you didn’t. Maybe you thought it looked quite straightforward compared to branching fiction that you’re familiar with.

For a refresher, this is a chunk of the diagram:

snafu1

It has grown a little since then. The thing is, that traditionally, the scene is the “atomic” node of choice-based interactive-fiction, and that is not the case here.

Continue reading Branching story planning

Regression and ignorance

One of the more involved aspects of the Argus story engine is how characters learn and express information about each-other. Some of that knowledge is just used for conditional narrative, but the most important part (currently) is how characters address each-other.

Names, titles, nationality, differing levels of formality, age, gender, and more, all get churned through sets of constructs provided by the story, which ultimately result in some form of address. That’s what I call the reference model. It’s updated as characters learn new information about each-other, and gaps in the knowledge-structure are filled in with assumptions, where no direct knowledge exists.

And annoyingly, way down in scene 360, one of the characters seemed suddenly unable to create a valid form of address for the character she was speaking to.

Continue reading Regression and ignorance

That’s what you get

What do you get when you rework, redesign, extend and simplify your conditional expression evaluators? You get bugs, that’s what you get.

Thankfully, nothing was terribly difficult to figure out, once I’d actually discovered that the bug was there at all. The problem was that I didn’t notice for about a day.

Continue reading That’s what you get

Rewriting text output

Rendering text in a graphical environment is … let’s call it ‘involved’. Assuming you want to output a single line of text in a single typeface and colour, that’s pretty easy. The interface libraries will even probably be willing to word-wrap it for you.

If you want to do other things, like mix plain text with italics or bold or text in other colours, well suddenly you’ve got dozens of hoops to jump through.

Well, I did want that, so I had to work for it.

Continue reading Rewriting text output

Story length, surprising characters, and planning

Talking about story-length can be like asking “How long is a piece of string?”

Work flows back and forth between optimising the Argus engine and working on the showcase story, SNAFU. SNAFU’s up to 135,000+ words now, and that’s more than 13,000 lines of script.

I have a testing mode that allows the story to run without the requirement for a human user. The actors perform their scenes, and make their choices, until the system runs out of story for everyone. Everything that happens gets written out to a log, where I can check each actor’s personal narratives.

That takes about a second and a half. It takes longer to load the story from the disk than it takes to process it all to completion.

I guess the optimising efforts have not been wasted, though I have somewhat mixed feelings about all the effort in content-creation resulting in such a short unattended runtime.

Continue reading Story length, surprising characters, and planning

Stupidly Ambitious

Argus, regrettably, doesn’t have a specialised authoring tool – not yet, anyway. Authoring is done with just a text editor. Within the last few days, I’ve added file-inclusion, so that I’m no longer chasing my tail across 13,000 lines of source-text trying to find a particular scene. More on the files later.

If I had to characterise the project, I’d call it “stupidly ambitious.”

Continue reading Stupidly Ambitious