Game Design, Programming and running a one-man games business…

Solar farm mini-update: Waiting for rego

I haven’t mentioned my solar farm for a bit, because frankly nothing has happened. This is extremely frustrating, to put it mildly. Anyway, we have been beset by the evils of bureaucracy and delays again. The REGO stuff is taking ages, and we have been waiting on agreement on earthing…

Solar farms need earthing, in case of lightning strikes etc, and earthing 3,024 solar panels, inverters and a lot of metal framework is a big task. Because the soil at each site is different, the amount of earthing you need differs, and also the topography of each site differs, its not a standard thing that applies everywhere. We have CCTV masts, a surrounding fence (which will be mostly wooden posts IIRC, but definitely has metal components), a metal gate, a substation, and switchgear. The earthing for all of this has to be designed so its safe.

What causes mayhem is that the earthing has to be approved by the DNO (who will have their own substation), but they only design ‘their bit’ and then we have to use external consultants to design our bit, and then both sides have to agree that the other sides design doesn’t interfere with them, and then you can proceed. This involves at least 5 companies (mine, the HV consultant, the farm developer, the DNO and the earthing specialist), and everyone seems to take it in turns to have summer holidays, which has stretched things out enormously :(

The trouble is you cant do digging for foundations for the substation until you know what earthing grid you need. Without the earthworks you cant have the substation, without the substation you cant move the HV line. Without moving the HV line, we cant finish the panels…

So anyway, we finally have agreement (I think) on what the earthing design is, which means we can now start implementing it, which means we can do the substation foundations, and then the actual substation and switchgear install, and also then the meter install, the final panels & frames, and the moving of the HV line. We also need to do CCTV and perimeter fencing…and then its done!

At the same time (because I like to keep SOME progress happening) I have been trying to get certified for REGOs, to prove I am a renewable generator, and thus earn a higher rate for selling my power. This involves a hugely confusing process to fill out a form on a website from 1970, whereupon your application just sits in a pile and is totally ignored. Welcome to the UK government, and its 0.001% level of efficiency. Quite why there is a delay of more than 24 hours for a REGO application is beyond me, but I strongly suspect its something that I can do nothing about, that no politician will ever fix, and that just acts as yet another irritating drag on productivity because this is seemingly a country in terminal decline :(.

I have already chased my application by email twice, but obviously they get ignored too. I’m away for a week, and planning on starting with daily phone calls to chase it once I get back. I make no excuse for being annoying with stuff like this. If the system was well managed nobody would ever have to chase anything, but here we are…

Anyway, thats the update. No pictures to show, nothing to report except waiting, and waiting and waiting :(. The latest guess I have for energisation is early November, which frankly I would be content with.

Its gloriously sunny here today.

Code Breakdown for Gratuitous Space Shooty Game

I code my games in C++ using visual studio 2015, and some help from visual assist from whole tomato (basically improved intellisense). I coded my own engine, but as GSSG is a simple 2D space shooter, thats easily good enough. I thought just in case anyone who reads my blog is learning C++, it might be interesting to describe some of the code.

The core part of the game is a function called GameProc, which is what gets called from the WinMain function in a loop, assuming the game is running, and its super simple:

void Game::GameProc()
{
GetInput()->Process();
GUI_GetSounds()->Process();
GGame::GameProc();
}

Thats the whole game loop! But obviously most of the relevant stuff happens in other classes. The basic principle is important though. My games reads all asynch user input (basically its checking the keystates for the keyboard), then it processes the sound engine, then the core game does its thing in a separate class. User input from mouseclicks and key hits is handled differently. I go through the windows messages for my app, and handle them as they happen outside this loop.

The fun stuff happens in that second GameProc function, which looks like this:

void GGame::GameProc()
{
	HRESULT result = GetD3DEngine()->GetDevice()->TestCooperativeLevel();
	if (FAILED(result))
	{
		if (result == D3DERR_DEVICELOST)
		{
			Sleep(50);
			return;
		}
		else
		{
			RecoverGraphicsEngine();
		}
	}
	if(PCurrentGameMode)
	{
		PCurrentGameMode->ProcessInput();
	}
	if (BActive)
	{
		GetD3DEngine()->BeginRender();

		if(PCurrentGameMode)
		{
			PCurrentGameMode->Draw();
		}

 		GetD3DEngine()->EndRender();
		GetD3DEngine()->Flip();
	}
	else
	{
		ReleaseResources();
	}
}

This is more interesting! Lets go through it. This code first checks to see if we somehow have lost the focus of the graphics driver, and if we have, it just pauses for 50ms and checks back later. Ideally everything then recovers from losing directx, and gets rebuilt. This sort of stuff isn’t really a problem now, as everyone is using non-exclusive borderless windowed mode, so its kinda legacy. The main game stuff comes next. The current game mode reacts to input, then assuming the game is still running, we begin the scene, draw everything and then end the scene, copying the backbuffer to the screen with flip.

So where is all the actual game code I hear you ask?

The trick is that PCurrentGameMode pointer. This is a pointer to an object thast represents the current game mode, and which one is selected and current is based on what we are doing. Right now my game has one object for the main menu, one for the (debug only) level editor, and one for the main game class. To make it interesting, lets check out the code for the main game objects call to Draw():

void GUI_Game::Draw()
{
	SIM_GetGameplay()->Process(); 
	GetD3DEngine()->ClearScreen(RGBA_MAKE(0, 0, 0, 255));
	GetD3DEngine()->ClipViewport(GetGame()->ScreenArea);
	if (GetGame()->GetGameModeName() == "game")
	{
		SetRT("rt_offscreen");

		GUI_GetBackground()->Draw();

		if (SIM_GetGameplay()->GetGameMode() != SIM_Gameplay::PREGAME)
		{
			SIM_GetShipManager()->Draw();
			GUI_GetAsteroids()->Draw();
			SIM_GetBulletManager()->Draw();
			SIM_GetPowerupManager()->Draw();

			GUI_GetParticleManager()->Update();
			GUI_GetParticleManager()->Draw();
			GUI_GetFloaterManager()->Draw();
			GUI_GetShieldStrengths()->Draw();
			GUI_GetDropLabels()->DrawAll();
		}

		PostProcess();

		GUI_GetInterface()->Draw();
		switch (SIM_GetGameplay()->GetGameMode())
		{
		case SIM_Gameplay::GAMEOVER:
			PGameOver->Draw();
			break;
		case SIM_Gameplay::POST_LEVEL:
			break;
		case SIM_Gameplay::PREGAME:
			DrawPreGame();
			break;
		}


		GUI_GetWindowManager()->Draw();

		if (BPaused)
		{
			DrawPaused();
		}
	}

	GetD3DEngine()->RestoreViewport();
	DrawBorders();
}

There is a lot of hacky nonsense happening here, but this is just a little hobby game, so I’m not too ashamed :D. So what does this do? Well the very first line of code does all of the actual gameplay stuff. I have an object of class type SIM_Gameplay, and I call that here and do all of the game simulation stuff. This moves the alien ships, handles scores, collision detection, and anything like that. All of the game mechanics are processed here, neatly separate from the graphics code.

Then I clear the screen to black, and clip the viewport (where we render) to an area I defined to be the gameplay screen. This is not the full screen, because I’m fixing the aspect ratio for this game to be some multiple of 1920×1080. This is the ‘ScreenArea’ which is just a RECT structure.

Then I get a bit clever. I set the render target to be an offscreen copy of the backbuffer I called rt-Offscreen. This is where I do 90% of the drawing in the game. I then go through a bunch of various singletons which access different visuals objects that get drawn, from back to front in painter-algorithm style, no Z buffer needed.

Finally I call PostProcess(). This is where I handle some fancy shockwave effects. I fill up yet another offscreen buffer with special images to donate any visual distortions I want to have, for when ships have shockwave explosions. I then copy the whole of that rt_offscreen to the backbuffer, using a shader which combines it with the contents of the distortion buffer to give me a nice distorted shimmer effect. Then finally I set the new render target to be the backbuffer, and draw the UI overlay stuff normally, so its NOT distorted by my shimmer effect.

Then I have some hacky places where I draw certain UI elements if the game is over, or not started yet, and then any windowed stuff, and finally some hacky code to draw GAME PAUSED if relevant.

Finally I restore the viewport so that I can fill in any surrounding borders for unusual aspect ratios and not have anything ‘leak’ out onto the edges.

This code is all a bit messy, because I haven’t nicely settled on a naming convention for a lot of those functions. Am I calling Draw() or Update() or DrawAll() its kinda random! Plus that UI stuff thats on the end of that function is a mess. I’m handling things THREE different ways here! An enum (GameMode) to call different functions, a complete window manager UI PLUS a special case there for if the game is paused. What a mess!

It all works and feels bug free, but its not clearly software engineered at all. I will definitely go back and re-arrange stuff and re-factor it so everything is laid out nicely. The reason I do NOT code like that at the start of the project is because I often throw things in quickly to see if they are a good idea, and I don’t want to type out a whole bunch of complex engineering layout baggage just to discover that this is a bad game mechanic or that this thing looks awful :D.

This is just the way I code, it doesn’t make it officially good, or fast, or better, its just what works for me!

Making a hobby game!

I’ve been getting very motivated about a little hobby game I’ve been working on in-between dealing with solar farm stuff, and playing the guitar. I have a lot of really cool space-game assets from my old game (some might say classic!) ‘Gratuitous Space Battles‘ and it just feels wrong to have all the art to make a space-invaders style game and not just do it! I decided to call the game ‘Gratuitous Space Shooty Game’.

I am so disorganised that its simpler for me to code a new game engine from scratch than find the hard drive with GSB code on it (or at least all of it), but luckily I have time plus experience, and I can type stupidly fast, so I’ve basically written a new game engine for this little hobby project. Its nothing amazing, the game currently only uses 2 shaders, no clever effects, no amazing visuals, just a simple ‘shoot at static sprites and enjoy some primitive particle effects’ style game:

Obviously its 2023, so just making simple ‘space invaders’ wont cut it even for a hobby game, so there is a lot of influence from stuff like galaxian, and pheonix, and all the other space shooters out there. Right now, the alien movement is very generic and simple, and nothing to shout about. No fancy splines, just left right and down!

The thing thats motivating me about this game is the small scope, and ease of adding new stuff. When I work on a giant commercial game of mine like Production Line or Democracy, every single line of code or change to a single data item needs to be checked and balanced for 11 different languages and every conceivable screen resolution and hardware, then uploaded as a patch to itch, gog, epic, humble and steam. The amount of admin, and busywork required to make marginal changes to a large project can be pretty overwhelming.

With this game, its 1920×1080 res or nothing (stretched to actual resolution, and bordered if necessary), only in English. And right now its not even on any store. This means I can have a cool idea, start typing code, and be testing it within minutes, which makes the development process pretty fun.

I don’t want to put up a public build for it quite yet, because so much of it is just totally broken, or half assed. The current font sucks, and doesn’t even display percentage symbols :D. The gameplay is unbalanced, and there is no high score system that actually stores anything anywhere yet. I reckon I need to code a primitive online high score system, and include music and sfx volume controls before I make it public. Oh and a pause button might be nice too!

I have to say though… its already very very fun. There is something very adrenaline-rushy about playing it on the harder levels, where everything gets a bit hectic. In these days of F2P, monetization, competitive e-sports, multi gigabyte patches, and achievements and so on… there is something very pleasurable about a simple game where you move left and right and hit the fire button!

When I stick it on itch or the humble widget I’ll post about it here :D.

Fourth site visit to the solar farm

2 days ago we took our fourth trip up to the farm to take a look at the site. Its over 400 miles a day of driving to do the round trip, so not something done lightly. Luckily this time we had arranged to be there when it was super-sunny, which is always a nicer way to visit a solar farm. Sun might mean no mud, but it doesn’t change the fact that this is a farm full of grazing sheep. 2 days later and I still have not got all of the sheep crap off my boots. After a while you stop looking where you are treading…

Because we are in the phase of the site build where MOST of the panels are up, and they are being wired, there is not much change to see on a day-to-day process. Most people would struggle to notice if the panels in a farm were wired-in. The wiring is always looped around the metal frame, then bundled into metal channels and cable tied together, so its not like you should expect to see cable trailing on the ground. There is a kind of minimum height to aim for with most of the cabling, which is above the height a sheep can gnaw at.

Here is an image near the end of a row showing the bundled cabling that runs along connecting the panels, and how it goes into the big chunky inverter:

Normal inverters just have one ‘string’ of panels connected to them, but industrial ones have multiple strings. This allows the inverter to do clever voltage balancing so that each cluster of panels is operating as efficiently as possible given that some may be a bit more shaded than others at certain points in the day. When you have just 10 panels on your roof, it tends to be ‘cloudy’ or ‘sunny’ at any point in time, and the inverter will adjust accordingly, but when you have 4 acres of panels, the conditions are going to always vary across even just 300 panels (one inverter) so you need the inverter to be more adaptable.

Not all the panels are connected yet. I insisted on being ‘that guy’ who wanted to plug one in personally!

This was our first visit where we saw panels installed on the right hand side of the overhead line. This makes the farm feel much bigger, and it will feel bigger still once that overhead line is moved and the two sections of panels can be joined. Waiting for confirmation on the grid connection works date and the substation and earthing design has been the biggest headache for me in recent weeks. It does feel impossible to get progress to move at any faster rate. Basically electricity generation connection in the UK has been handed over to private monopolies with no demand that they proceed in a reasonable timeframe. You have no choice but to just accept their quotes and their timescales. Its a huge scandal that nothing is done about it, but then we have a government who actively despises renewable energy, so I doubt anything will change until a new government. Very depressing…

On a happier note, it always makes me feel good to get a sense of perspective in photos like this showing how much renewable energy my little company is building:

I also had some genuinely great news, by co-incidence while I was at the farm. I had got ‘indicative quotes’ from the company building the farm for how much I could get for the power, in what is called a ‘power purchase agreement’ (PPA). You sign these for 1, 2 or 3 years with a fixed price to take all the power you generate. Of course in real physical terms, your power will flow to the nearest demand, which will be local villages and a nearby town in Shropshire, but in market terms, someone will contract to pay me for my power, and that could be anyone.

The interesting thing is that there is a dual market here. There is a simple PPA, where someone wants electricity, and they will buy it anywhere. It could come from nuclear, coal, gas, oil, wind or even from France or Norway. There is a thriving free market for this stuff. Then there is the REGO market. REGO is “Renewable Energy Guarantee of Origin”.

A REGO is a virtual certificate you get if you generate a megawatt-hour of renewable energy. It proves that the power came from a real renewable source. The REGO is basically traded on the free market, and keeps people honest. You cant sell the same REGO to 2 people, so it means if 10 companies each want 1,000 MWH, then they need to do deals with renewable generators who can provide that much power. If demand exceeds supply, the price of REGOs will go up, and vice versa.

For anybody super cynical, be aware, this system is real and works. If a company is bragging that they are 100% powered by renewable energy, they need to buy the REGOs to prove it, and only us renewable energy companies have them to sell. If you are getting your power 100% from a company that only supplies renewable generation, this is how that is enforced, and it really works.

In practice, at my scale, its not two separate things. You find a company who both needs power, and wants it to be renewable, and they give you a price for the bundle of the power + REGOs for everything you generate. In effect, this is a premium on top of the PPA I would get offered if I was a gas or coal-fired power station. Anyway… this is all a long technical explanation to say that I got 2 quotes from big (household name) energy companies and they were both WAY HIGHER than the other quotes I got. I am VERY nervous about the finances of this project, but if those prices stay in the same sort of level until I energize the plant (maybe October?) then, I will make a reasonable profit and it wont be a disaster :D.

My life will be far more chill when I finally get a date for the grid connection, or even just for the overhead line move… Fun fun fun.

Solar Farm: 3rd site visit during construction

In case you didn’t know. I run a small energy company and am building a small solar farm with the money I made from selling video games. Here is the company website: http://www.positechenergy.com

We made another trip to the site yesterday. Its a 350 mile round trip, and part of it was in the rain. This was the first time we visited in bad weather, but to be honest it wasn’t TOO bad. The site is basically the crest of a hill, so drainage is excellent, and it wasn’t too muddy. Despite, this they were still transporting solar panels on pallets using tracked vehicles, because…mud is still a thing.

I bought these solar panels about 8 months ago, in a fit of enthusiasm to push the project forwards. This turned out to be madness, as I then had to store 3,000 of them in a warehouse at huge expense. The panel prices did then rise…but then fell. I think overall, it was a bad decision, but not catastrophic. Despite owning solar panels all this time, I had never seen them until today. Also, 60 tons of solar panels sounds a lot, but does it look a lot in person…?

The answer is YES. It does. Its a lot of boxes, and thats not all of them, a lot of them were already fitted to the frames. Its multiple big articulated lorries full of them. On the plus side, I am no longer getting monthly storage bills. On the negative side, I had to pay £700 to the warehouse to load them on to the truck. This sounded a lot, but it is a lot of panels so… I guess its understandable.

The real excitement for this trip was to see panels actually on frames, to get an idea of what the finished project will look like. Our first impressions were that they were being fitted pretty quickly, and that the frames are really high. No danger of long grass obscuring the bottom of a panel! (A disaster when that happens, as it effectively shadows the whole panel, and indeed the whole string).

I posted that picture to give some idea of scale. Thats not a complete row of panels, we currently have a ‘gap’ awaiting the moving of the HV cable. once that is moved we can fill it in and have longer rows. You can just about see that a few rows are now double paneled, and some they have just done the bottom row. The bottom row is first, then they go back with a sort of frame to stand on so they can access the top row and fit those. There was a team of 4 people working together to mark out the location, attach the fixtures, and then place the panels on the rails. While they do this, fresh panels are delivered to points along each row on pallets ready to be fitted.

At this point, the panels are attached, but there is no wiring. A separate team of people (electricians this time) are connecting the panels together to form strings which eventually get wired to the inverters at the end of some rows.

Thats one of the inverters already mounted. Its a 100kw inverter, so about 25x the power of the kind you have if you get panels on your house. The box to the right is the emergency cut out switch. All that metal stuff underneath is just a bracket to attach a LOT of DC cabling to the inverter, which will run at head height along the length of the panels. In cases where the inverter is connected to panels on another row, there is underground armored cable & ducting to bring all the DC cabling together. Further underground ducts will connect each inverter to the substation using AC cable, but that work has not started yet. The substation design is holding everything up!

A picture to show the scale of each solar table next to a mere human. As someone with a small ground-mount array of 10 panels in his garden, its surprising how high up these are, and how tall they are at the top of the final panel. They are fitted in 2 rows height, in portrait mode (some farms are landscape), and each panel is ‘split’ into two, hence the white line in the middle. They are effectively 2 panels each, and have 2 connectors on the back of each one. Each panel outputs 410 watts

and lastly…

When people repeat stupid oil-company propaganda nonsense about losing farming land to solar panels, I’ll be tempted to reply with this. The grass is still very appealing to the sheep, and plenty of room between and under the panels for them to graze. Frankly on a day like yesterday the sheep probably thought the shelter was awesome. Technically the sheep are supposed to be out of the way during construction, mostly for their safety, but they got in somehow, and it turns out getting them out again isn’t easy. They seem to co-exist with the construction site pretty happily :D.

There will likely be a delay of a few weeks before I go back, unless something exciting happens. There are a lot of panels to attach, and then a LOT of wiring to be done, which is still a manual procedure. There is no clever automation or robotics that can do this yet. Actual humans have to walk to each panel, grab a cable, plug it in, then probably cable tie the cabling nicely out of the way, so it stays there in thunderstorms for 25 years. Maybe one day Teslabots will do this, but not this year.

The real hold up on this project has been the grid connection. First it was planning, then grid connection. I could write a whole epic space opera about how much grief it has been. I HOPE that we are now zeroing in on final agreement as to how everything will work, and thus we can a) start building the earthing mesh and connections for the substation and b) get a date for the DNO to move that overhead cable so we can fill-in the final mounting frames and tables and have everything connected.

The project is still a cause of daily worry and stress, because it involves literally dozens of people talking to each other in email threads that are contradictory, out of synch and confusing. Hopefully things get much better soon.

Meanwhile, a reminder of how important it is that we do projects like this.