Month: January 2021

lldb-mi no longer exists

lldb-mi no longer exists

lldb vs code extensionsThis is debugging vs code with lldb. It seems as of clang-10, it’s no longer supported which is a pita. I’d been working on the Onslaught code and something wasn’t working so I thought I’d try to debug it.  However the debugger wouldn’t start. Investigating a bit further and I found this discussion thread on the GitHub cpp tools.

I have to say this. I find Linux development quite frustrating at times because of things like this. Something that worked in an earlier version of clang has been removed. Why? There’s a similar issue with Ubuntu 18.04 compared to 20.04 running in Hyper-V VM. With 18.04 I can use the clipboard to copy and paste between Windows and Ubuntu, but so far I have been unable to do it in 20.04.

You spend ages wasting time trying to find answers. I find Windows development with C# much less problematic. Open source developers sometimes don’t appear to take the needs of their users as seriously as say commercial developers do.

So now I’m looking a for a better way to debug C/C++ programs from vs code. There is a lldb – vs code adapter as well as native debug and Code LLDB (see screenshots) so I’ll investigate and see if any of these work. Or I can just study my code and work out in my head why it isn’t working!

Interesting article on the state of Linux gaming

Interesting article on the state of Linux gaming

Linux playYes it’s on Medium, but its worth a read. The gist of the article and this one is saying that there’s a problem with Linux for gaming. Also that anyone new to Linux gaming is looking online and finding old articles that suggests that SteamOS is a good distro to use while in reality it hasn’t been updated in a while.  The problem is that Valve (creators of Steam) have let SteamOS languish.

Though its not as if Valve have ignored Linux gaming. They released an open source tool Steam Proton (Link goes to it on GitHub) that lets you run many Windows games (6000 or so)  on Linux. The Linux Steam client includes a copy of Proton.

The problem though is that this hasn’t really helped attract more people to Linux gaming. People I know either play games on Windows or on consoles like PlayStations.  Linux is perceived, wrongly I’m sure as being an inferior game platform.

Doing 3D Math(s) in C

Doing 3D Math(s) in C

Donuts.cIf you’re interested in seeing how 3D math(s) are done, this article by ex Googler Andy Sloane is about a program he wrote called donut.c. The name is doubly appropriate as not only is the source code shaped like a Donut (doughnut for us Brits), when run on Linux, it outputs an animated 3D donut. This was an attempt at obfuscated C back in 2006.

Now 15 years later he’s updated it to work without using the math library. Interesting is the explanation of how he did all the mathematics without using sin and cos directly. Also it includes a version that uses 10 bit integer arithmetic; no floats at all. If you’re interested in understanding how Donuts.c works, read this post from 2011.

I like articles like this- they’re a bit different and add to programming knowledge. and you can never get enough of that

 

 

 

Interesting Visualisation – like tixy.land

Interesting Visualisation – like tixy.land

Tileflip visualisationIf you remember tixy.land that I mentioned back in November last year, here is another website that lets you control a visualisation. In this case, tileflip.xyz lets you create a single function and applies it to every square on a board. You can control how many squares the board has and how often they are updated through a pair of sliders. You can pause the animation and toggle squares by clicking on them in the mouse. One of the early examples runs Conway’s Life and has a really short function.

The functions can be quite complicated (it’s JavaScript) as this example shows which moves a ball around the screen while changing colours.

The ctx (short for context) object has various properties and functions that you can call on it. For example ctx.resolution is how many squares there are on the board and this page lists all the properties and functions.

function rule(ctx){
  
  ctx.color = ctx.floatToColor(10/ctx.t)
  
  let r = Math.min(ctx.t**2/10, ctx.resolution/4);
  let cx = ctx.t*2%(2*ctx.resolution+1);
  let cy = ctx.t*3%(2*ctx.resolution+1);

  
  if(cx >= ctx.resolution+1){
    cx = 2*ctx.resolution - cx;
  }
  
  if(cy >= ctx.resolution){
    cy = 2*ctx.resolution - cy;
  }
  
  cx = cx/(ctx.resolution)*(ctx.resolution-2*r+1)
  cx += r - 1;
  
  cy = cy/(ctx.resolution)*(ctx.resolution-2*r+1)
  cy += r - 1;
  
  let toReturn = inCircle(cx, cy, ctx.x, ctx.y, r);
  
  if(!toReturn){
    ctx.color = 'black'
    ctx.invert = true;
  }
  
  return toReturn;
}

function inCircle(cx, cy, x, y, r){
  return (cx-x)**2 + (cy-y)**2 < r**2 ? 1 : 0
}

JavaScript is like C in many ways and while not the main purpose of LearnCGames.com, websites like this are an inspiration to games creators. My other interest is C# and I’m currently learning about Blazor a technology that lets you create webpages in C# using WebAssembly so it’s quite possible that things like this could be done in Blazor.

But it’s fun to look at the different example functions and you can also download the images as gifs via a link at the bottom of the page,

New Tutorial – Implementing the Windows game Slay

New Tutorial – Implementing the Windows game Slay

Slay gameOne of my favourite casual games is Slay by Sean O’Connor. I bought the full game which sells for $10 and it’s still selling well via his site or Steam. His game is only for Windows so my reimagining (great word!) will be for Linux only including Raspberry Pi.

His game comes with several hundred islands, in four sizes from very small, small, Large and very large. You play against 6 computer players with intelligence ranging from very stupid, stupid, clever to very clever. In addition there are a bunch of predefined maps like Britain or even the world.

Troops exist in four sizes with each size three times bigger than the one below. Your territory must be big enough to support the troops there and if it isn’t they all starve.  Splitting an enemies’ territory to starve his troops is a valid tactic.

Add in with trees which can spread and waste land which spreads even faster and its a cute addictive game.

My game will be called Onslaught and use its own graphics. Islands will be computer generated and hopefully the AI will play a decent game. The first tutorial which just explains the game and the scope of what I intend to do is now available.

 

 

Atoms tutorial three- finishing the game off

Atoms tutorial three- finishing the game off

Atoms 3 screenshotI fixed the bug in the Atoms game and the third tutorial finishes it off. The source code (in this case atoms3.c) has been placed on GitHub and the final version is about 300 lines long.

As well as the bug fix, I added a line to show the number of cells owned by the player and the computer. You can see it after the player move (Player : 41 Computer 16) and after the Computer move.

This whole atoms game was an experiment to see if I can introduce C programming without having to go overboard explaining every statement etc as I’ve done in the past. I think I’ll get back to programming games!

 

Tronus Project 1945 – Coursework

Tronus Project 1945 – Coursework

Project 1945A university student by the pen name of Tronus has put a project from his 3rd year in his degree course on GitHub. The screenshot shows the game running on my PC. The build folder includes a release folder with game exe plus all dlls and game assets in a resources folder below that so you can run it immediately on Windows. ,

I vaguely remember playing a similar game (a vertical scroller) in arcades back in the 1980s. That game was 1942.

The 1945 game has been programmed in C and uses SDL2. As always I took a walk through the source just to compare how it was done say compared to my own efforts. One thing I noticed is that he uses a fixed delay of 11 milliseconds each frame in the game loop by calling SDL_delay(11) rather than setting up the video to sync to the fly back. Is this better or worse? I’m not sure.

I think I prefer my method in case something takes a bit longer. Having a fixed delay means that you could risk overrunning the 16.666 milliseconds allowed per frame. That could never happen with my asteroids game as syncing to the fly back means my game can take as long as 16.66 milliseconds per frame and still not overrun.

 

 

Answer to simple C Question

Answer to simple C Question

Answer sign
Image by Gerd Altmann from Pixabay

Hopefully you got choice 2. 62. Here’s the question again.

#include <stdio.h>
int main() {
	float* p = (float*)50;
	p = p + 3;
	printf("%u\n", p);
}

The first line in main() creates a “pointer to a float” p with the initial value 50. This 50 is the value of p i.e. the address that p is pointing to, NOT the value at that address P is pointed to.

Adding 3 to p moves the pointer by 3 x the size of a float. As it’s unspecified, this size of a float is typically 32-bits or 4 bytes. So this line adds 12 to p. It now has the value 62.

You can try this out and step through it on the Python Tutor. Despite its name, it will let you run run programs in Python, C, C++, Java, JavaScript, TypeScript and Ruby. It compiles C with GCC 4.8 and uses a Valgrind Memcheck plugin. There are a few restrictions its quite a nice way to show off execution of simple programs.

Simple C question

Simple C question

question marks
Image by Gerd Altmann from Pixabay

I saw this this morning and got the correct answer. I also tried it just to be sure in Visual Studio and apart from a warning, it compiled ok and ran and gave the correct answer.

#include <stdio.h>
int main() {
	float* p = (float*)50;
	p = p + 3;
	printf("%u\n", p);
}

If you want to avoid the warning, change the last line to

	printf("%u\n", (unsigned int)p);

So the question is what does this output?

  1. 53
  2. 62
  3. 66
  4. 68

Answer and explanation tomorrow.

Next atoms tutorial added

Next atoms tutorial added

Atom2sThe first version of the program was 90 lines long but now it has grown to 275. This includes code to let the computer play and checking code plus I’ve refactored it a bit, simplifying the code.  I haven’t extensively tested it and at least one bug has crept in. Occasionally the computer seems to claim ownership of a player cell. This stops you adding one to that cell so its not good.

You are welcome to have a look at the code and fix it. I will in a few days. The code is on GitHub and is a single file atoms2.c. As before its been compiled with Visual Studio 2019 Community edition though it should compile more or less unchanged with gcc, clang etc. It runs in a terminal/command line. You can see the computer playing in the screenshot.

I’ve also added the tutorial for this.