Updates to Game21 since Random Mazes
Going hard down the 'stuff required to simulate data networks' tech path:
- Replaced the build system with a homegrown Make-like tool because GNU Make doesn't work well on Windows and Gulp/Grunt/etc don't do what I want.
- Entities can be defined with subsystems that can send signals through attached wires, and those signals can be received by other entities on the same wire.
- Integrated rendering systems to allow more complex entity visuals:
- Visuals can now change their look based on entity state (this allows things like switches to turn on and off without changing the entity's class).
- Visuals can be defined as a composite of other visuals (switch box and switch can be different colors, even when defined as 1-bit images!)
- Supports cyclic animations for decorative things like fans on the wall or flashing lights.
- Supports resettable one-time animations for e.g. blinking indicator lights.
- ProceduralShapes can now be used, and their
t
parameter varied through an animation.
Here's a video (in animated GIF format) of me switching some switches while some decorative box fans run above me:
In this example, toggling a green switch also sends a 1-byte zero or one signal along the wire connected on its top side. When receiving a signal, switches change their own state to match the signal's content (on or off). Much more complex behaviors are possible, and I even have some ethernet switch simulation classes defined, but I haven't figured a good way to integrate them into the demo game yet. Because what good are ethernet frames if you can't put IP data in them? And then you start getting into complexity of ARP tables and how do you configure who a device's peers are, etc. And I'm not sure I really want to deal with all that stuff. So the mind still churns on this as I commute to and from work.
To prevent broadcast storms I cheated a bit in my ethernet switch implementation. My switches don't do spanning tree protocol, but they will drop duplicate frames...using a hash-set of CRC32s of recent frames. It's pretty ghetto.
Home Automation Stuff
I've discovered ESP8266. After some trouble programming the first one with the Arduino IDE (due to a combination of a bad ESP8266 board and a bad USB cable) I got going and started building temperature/humidity sensors and battery charge controllers all over. They both use MQTT for logging, specifically the following format for messages:
[<ISO 8601 timestamp>] {<key>:<value>}* [# <comment>]
e.g.
2017-04-29T15:22:43-05:00 batteryVoltage:13.03 regPowered:1 regConnected:1 time:187746 nodeId:5M-MP-7P-34-44-7L 2017-04-29T15:22:44-05:00 batteryVoltage:13.17 regPowered:1 regConnected:1 time:188754 nodeId:5M-MP-7P-34-44-7L 2017-04-29T15:22:45-05:00 batteryVoltage:13.10 regPowered:1 regConnected:1 time:189761 nodeId:5M-MP-7P-34-44-7L 2017-04-29T15:22:46-05:00 temperature:16.70 humidity:36.00 nodeId:K0-20-K6-04-7N-21/dht0 2017-04-29T15:22:46-05:00 batteryVoltage:12.96 regPowered:1 regConnected:1 time:190769 nodeId:5M-MP-7P-34-44-7L 2017-04-29T15:22:46-05:00 # Increased bogon flux detected... 2017-04-29T15:22:47-05:00 batteryVoltage:12.75 regPowered:1 regConnected:1 time:191777 nodeId:5M-MP-7P-34-44-7L 2017-04-29T15:22:49-05:00 batteryVoltage:12.82 regPowered:1 regConnected:1 time:192785 nodeId:5M-MP-7P-34-44-7L 2017-04-29T15:22:49-05:00 temperature:16.70 humidity:35.90 nodeId:K0-20-K6-04-7N-21/dht0
Node IDs are MAC addresses, if you hadn't already guessed.
I built a couple of 20+3/4"-wide shelves to mount stuff on. 20+3/4" was chosen as the width because with 1+1/2"-thick legs (2x2s or 2x3s) that makes it a 19" rack (gap between rails ('aperture') in a 19" rack is about 17.75"). I don't have any 19" racks or equipment, but I like the idea of them, so decided to make my stuff 'compatible', even though it's all made out of scrap wood.
Here's my battery charge control panel, all hooked up:
It keeps a car battery charged for days when the sun isn't shining. Or on days when the sun is shining, but I haven't yet assembled enough solar panels. Such as today.
Parts (from top-left to bottom-right):
- ESP8266 sub-panel:
- WeMoS D1 mini (a small ESP8266 board) on a cheap breadboard
- 4-channel relay board. Not sure of exact brand, but these things seem to be pretty interchangeable. Top relay controls wall power supply's input power (120V AC), next controls its output. Other 2 are currently unused but I may hook them up in the future to indicator lights that only come on under certain conditions, or something like that.
- Bunch of connectors (see next section)
- A 30A standard blade fuse
- A bundle of 6 3A Shottky diodes to nowhere (above and to the left of the power supply). This was my previous solution to making sure current didn't flow backwards through the power supply, but the diodes just wasted power and got all hot. Hence the entire left end of the panel (the right end, on which the power supply and diodes are mounted, used to be mounted on its own between some studs, which is why it's only 14").
- 120V AC to 12V 30A power supply
I like to standardize my connectors somewhat:
- #6-32 screws as my standard 'need to bind N wires together' connector. Chosen for compatibility with the #6 spade lugs that I use for connecting to the power supply. I later switched to using ring terminals because they don't fall off as easily and don't get all bent up when you're changing things around, and, upon being informed that nut drivers are a thing, from wing nuts to regular old nuts. Ring lugs > spade lugs when you're smashing them down under a nut.
- 4mm binding posts (i.e. banana jacks) for plugging whatever into.
- IEC 60320 C14 power inlet with manual switch. Because I like my devices to be separable from their cables, and I have a drawer full of desktop computer power cables.
- 2.1mm barrel connectors for passing around 12V (nominal), which seems to be a bit of a de-facto standard. Unfortunately I had to order some 2.1mm to 2.5mm adapters for a certain USB hub. I'm guessing the USB hub factory got a discount on 2.5mm connectors because why else would you do that.
- JST RCY connectors for stringing together LED strips because that's what Mark uses for his living room lighting. But it turns out the barrel connectors are almost if not just as cheap, so I'm phasing these out.
The pile of parts I've acquired lately is going to require some organizing if I'm going to be able to find things later, or even remember what I have.
The Factory
Since I was spending a lot of my free time trying to re-invent Factorio (that's a simplification; while my ultimate vision for Game21 includes simulated power networks, railroads, automated crafting, and pre-rendered sprites, it is otherwise completely different from Factorio), I e-mailed them and asked if I could work on their thing. If I'm going to be dedicating brainpower to something, may as well have someone pay me for it, right? A few C++ quizzes, several weeks, and a trip to Prague later and it seems we have an arrangement. So that's exciting. Hopefully some of my weird ideas will work their way in. >:-)
Working on Factorio has sparked some thoughts about the different approaches to implementing a simulator (immutable, independent objects vs stateful interlinked ones, scaling out by parallelization vs optimizing by skipping unneeded calculations, and how the different approaches are sometimes at odds with each other), but I think I'll save that essay for later. John Carmack has already gone there.