Moments of Inertia by Rachel Crawford

About     Archive     Categories     Tags     Feed     Projects     Magewinds     Warcry Card Creator    

London Trip (16th-19th June)

Introduction

In June me and Natalie took a trip down to London. I started writing this blog post about it on the way back to Dundee, but completely forgot to finish it because of how much work I had to do. So here it is, a month and a bit late…

Read more...

Handling JSON with json.hpp

json.hpp is a single-header C++ library for handling JSON. It provides easy, clean ways to read from and write to JSON files. It’s written in C++ 11, which has pros (great functionality, trivial to integrate) and cons (won’t work with older compilers or those that don’t fully support C++ 11), but, like, it’s 2016, man. It’s about time to make use of modern C++, rather than just stare wistfully at it from afar.

Reading in JSON from a file is easy. Let’s say you’ve got a file called ‘data.json’ which looks like this:

{
  "info": {
    "name": "Rachel",
    "age": 22,
    "likesBacon": true
  }
}

To read it into a C++ application, you use a std::ifstream to feed the data to an instance of nlohmann::json:

using json = nlohmann::json;
json j;
std::ifstream ifs("data.json");
if (!ifs.is_open()) {
  return false;
}
ifs >> j;
ifs.close();

Next, you operate on j using a variety of syntax options to extract the data you want. json::find is a safe way to search the JSON for a particular attribute (field). Standard square-brackets syntax can be used to extract the value of an attribute, which can itself be another group of attributes. To make accessing the sub-attributes of an attribute easier you can just create another json object, like so:

Person person;

// verify that "info" attribute exists in j
if (j.find("info") != j.end()) {
  json info = j["info"];

  // verify that "name" attribute exists in info
  if (info.find("name") != info.end()) {
    person.name = info["name"]; // person.name == "Rachel"
  }

}

And that’s how simple it is to extract data from a .json file and use it in an application.

Outputting to a file is easy, too. You just fill up a json object and then stream it out to an std::ofstream or something of the sort.

I really like this little library, although I’ve only scratched the surface of what you can do with it here. I wanted to make others aware of it for the next time they need to handle JSON in C++. There’s no standard library support for JSON in C++ like there is in other languages like Python and there’s not really a go-to non-standard option out there, so recommendations are useful. I’m using it to create an import system for Aseprite, which can export .json files to accompany sprite-sheets. More on that later.

I'm Back!

Hello. Things have been quiet around here for the last month or so, as I swore off writing blog posts and working on side projects in order to commit all my energy to finishing my dissertation. I submitted that yesterday, having reached the point where I could abandon it, so now I can return to the blog pilot seat, strap in, and write some bad metaphors.

Where I’m At

So I ‘finished’ my dissertation a couple months later than originally scheduled because I deferred it into the summer. I don’t know how well it’ll do and I am very pessimistic but my supervisor seemed to like it, which means one of us is insane. I’m fairly confident, at least, that it’s the best dissertation/honours project I could have done in the unusual circumstances I had to do it. I’ll write about it all soon.

The lease for the flat I lived in in Dundee for the last 3 years expired on Thursday, so I’ve moved back to Edinburgh and set up camp in my old bedroom at my mum’s house. It’s quiet here. There’s no constant noise of people in the street, chatting outside the pub, cars, trucks and buses rushing up and down the road. Just the occasional swoosh of a car, or the buzz of a lawnmower. My room is stuffed with my belongings like a bursting sack. I’m trying to create some kind of order from the chaos but there’s just so much.

What Next

Doors are open to many things. I might even have a job soon. Until then I’m going to crack on with a lot of projects, blog posts and improvements to this site. Check in with family members and friends, go for a lot of walks. Oh, and definitely squeeze in some gaming quality time. Stay tuned!

Cool Links

The World Wide Web is big and scary, and sometimes you need the recommendations of others to guide your way to webpages worth watching. Here, therefore, are some cool links to cool things that you might want to, cool-ly, inspect.

Sandi Metz - Nothing is Something (keynote speech at RailsConf 2015) Should be interesting and educational for all the programmers out there. Sandi talks about how to tackle object oriented programming problems, and the Null Object pattern, the idea of the Active Nothing. It’s Ruby-focused, but practical Object-Oriented Design lessons are applicable across most languages. Her speech from the previous year is more about ‘life’ than programming, but it is very, very worth a watch.

Woodland Secrets Ep. 54: Katherine Cross – This was a great episode, with Merritt Kopas and her guest, Katherine Cross, holding a long, in-depth conversation on the subjects of sociology, work, gamification, and online discourse. Katherine’s writing on society, culture and games is well worth exploring. Go and check it out.

Here’s a talk about universal basic income. Worth a listen.

You may have heard of 99% Invisible, the excellent design podcast. Episode 212: Turf Wars of East New York, contains some excellent historical insight into the widespread issue facing American cities (and other cities around the world) of gentrification, 20th-century shifts in inner city residential demographics, and how inextricably knotted up it all is with US racist and ethnic tension.

Landlords and real estate investors saw opportunity in the desperation of immigrant populations. They would come to hone two profit-driven tactics that would subsequently shape neighborhoods around the country: fear-induced white flight and predatory lending.

The Next Civilization Game Sounds Okay

I tend to complain about the Civilization games whenever they come up. I really want to love them (and other 4X games), but every installment has some elements that just feel wrong, making the overall experience long, boring, frustrating and unfulfilling.

Civilization VI was just revealed by Firaxis and pegged for an October release, and the way the designers say they’re shaking up the formula has really piqued my interest: every change mentioned in Rock, Paper, Shotgun’s details splurge and PC Gamer’s addresses a problem I have with Civilization V (and, by extension, the others).

I’m not getting hyped, or anything sticky like that, but I think about strategy games a lot - particularly the elusive and mysterious creature that is the 4X-I-Find-Enjoyable - so I am getting intrigued.

Read more...