▲ 2 r/dotnet

Devirtualize generic method calls

I have this interface:

interface IDrawable
{
    void Draw();
}

and then I have this class:

sealed class Circle : IDrawable {...}

and this:

class Canvas<T> where T : IDrawable
{
    public Canvas(T[] items)
    {
        foreach (T item in items)
        {
            item.Draw();
        }
    }
}

Now, the Circle class is sealed, so if I do:

new Canvas<Circle>(circles)

will the Draw calls be devirtualized?

If they won't, is there a way to make it, WITHOUT switching Circle from class to struct?

Thanks in advance.

reddit.com
u/Alert-Neck7679 — 8 hours ago
▲ 51 r/dotnet

Testing the performances of my game engine built with .NET

Just wanted to share this little game I made to test the performance of my C# game engine. Honestly, I'm impressed with the performance it's achieving. It's nothing compared to professional game engines, but this is a solo project, and the language it uses is interpreted, so I was a bit worried about performance.

What you see here is powered by only about 15 lines of code in total! I'm really proud of this personal project.

A bit about the engine: it's built on MonoGame and has its own programming language that I wrote entirely from scratch, along with its own IDE. It's heavily inspired by the good old GameMaker 8, and it's open source [<- GitHub] (I'm looking for contributors!). There is also a YouTube video showing me creating another little game with it. I also talked about it here in a previous post in r/csharp.

And no, it's NOT AI slop - I built this myself over the course of several years.

What do you think?🙂

Note: The lag you see in the GIF is caused by the screen recorder. The actual gameplay is smooth.

u/Alert-Neck7679 — 5 days ago

Testing the performances of my engine

Just wanted to share this little game I made to test the performance of my C# game engine. Honestly, I'm impressed with the performance it's achieving. It's nothing compared to professional game engines, but this is a solo project, and the language it uses is interpreted, so I was a bit worried about performance.

What you see here is powered by only about 15 lines of code in total! I'm really proud of this personal project.

A bit about the engine: it's built on MonoGame and has its own programming language that I wrote entirely from scratch, along with its own IDE. It's heavily inspired by the good old GameMaker 8, and it's open source [<- GitHub] (I'm looking for contributors!). There is also a YouTube video showing me creating another little game with it. I also talked about it here in a previous post.

And no, it's NOT AI slop - I built this myself over the course of several years.

What do you think?🙂

Note: The lag you see in the GIF is caused by the screen recorder. The actual gameplay is smooth.

u/Alert-Neck7679 — 5 days ago

Testing the performances of my engine

Just wanted to share this little game I made to test the performance of my C# game engine. Honestly, I'm impressed with the performance it's achieving. It's nothing compared to professional game engines, but this is a solo project, and the language it uses is interpreted, so I was a bit worried about performance.

What you see here is powered by only about 15 lines of code in total! I'm really proud of this personal project.

A bit about the engine: it's built on MonoGame and has its own programming language that I wrote entirely from scratch, along with its own IDE. It's heavily inspired by the good old GameMaker 8, and it's open source [<- GitHub] (I'm looking for contributors!). There is also a YouTube video showing me creating another little game with it. I also talked about it here in a previous post in r/csharp .

And no, it's NOT AI slop - I built this myself over the course of several years.

What do you think?🙂

Note: The lag you see in the GIF is caused by the screen recorder. The actual gameplay is smooth.

u/Alert-Neck7679 — 5 days ago
▲ 74 r/csharp

Testing the performances of my game engine

Just wanted to share this little game I made to test the performance of my C# game engine. Honestly, I'm impressed with the performance it's achieving. It's nothing compared to professional game engines, but this is a solo project, and the language it uses is interpreted, so I was a bit worried about performance.

What you see here is powered by only about 15 lines of code in total! I'm really proud of this personal project.

A bit about the engine: it's built on MonoGame and has its own programming language that I wrote entirely from scratch, along with its own IDE. It's heavily inspired by the good old GameMaker 8, and it's open source [<- GitHub] (I'm looking for contributors!). There is also a YouTube video showing me creating another little game with it. I also talked about it here in a previous post.

And no, it's NOT AI slop - I built this myself over the course of several years.

What do you think?🙂

Note: The lag you see in the GIF is caused by the screen recorder. The actual gameplay is smooth.

u/Alert-Neck7679 — 5 days ago
▲ 1 r/csharp

Devirtualize calls on generic type

I have this interface:

interface IDrawable
{
    void Draw();
}

and then I have this class:

sealed class Circle : IDrawable {...}

and this:

class Canvas&lt;T&gt; where T : IDrawable
{
    public Canvas(T[] items)
    {
        foreach (T item in items)
        {
            item.Draw();
        }
    }
}

Now, the Circle class is sealed, so if I do:

new Canvas&lt;Circle&gt;(circles)

will the Draw calls be devirtualized?

If they won't, is there a way to make it, WITHOUT switching Circle from class to struct?

Thanks in advance.

reddit.com
u/Alert-Neck7679 — 18 days ago

2D Game Engine with its own programming language!

GitHub repo

(first of all, i want to say that I made this project for fun and challenge. I always wanted to create my own language. This has no business goal or something.)

So the project is a 2D game engine (MonoGame backend) inspired by GameMaker 8. It includes its own IDE (built with WinForms) and an interpreted programming language that I wrote myself.

The language—definitely the biggest challenge in the project—is a simple dynamically typed language. When I started, I had zero knowledge of how to build something like this. I didn’t even know I was making an interpreter; at first I called it a compiler. It was a personal challenge, and I wanted to figure everything out without using any resources or tutorials. My mindset was basically: “I need to write software that takes a text file containing code and just does what it says.”

Somehow, I made it work. In the beginning, running an empty loop counting to 1M took 7 seconds. After a lot of performance work and rebuilding parts of the system, the same machine can now run a 30M loop in 2–3 seconds. Pretty nice improvement.

The language itself is a bit unusual, and I want to share one small feature I really like: loop counters.

foreach item in ['a', 'b', 'c'] : counter c
{
   println(c + ": " + item)
} 
// Output: 
// 0: a 
// 1: b 
// 2: c

Not a complicated feature, but pretty useful.

Here's a YouTube video showing me using the engine to build a little game

Anyway, these days I barely have time to work on the project, so I decided to open-source it. I’m hoping people here will find it interesting and help turn it into something real.

Any feedback is welcome.🙂

u/Alert-Neck7679 — 27 days ago
▲ 9 r/csharp

Different method implementations without vtable

I’m building a game engine, and I’m trying to figure out the best architecture for separating the core engine from the rendering backend.

Right now, the core engine is responsible for the game logic, and it holds a reference to a backend rendering engine, which is responsible for drawing sprites. The core engine and the backend engine live in different assemblies. The structure looks something like this:

Core engine project:

interface IRenderEngine
{
    void DrawGameInstance(GameObject instance);
}

class Game
{
    private readonly IRenderEngine renderEngine;
    ...
    void DrawFrame()
    {
        foreach (var obj in objs)
            renderEngine.DrawGameInstance(obj);
    }
}

Currently, I’ve only implemented a MonoGame-based rendering backend, but in the future I want to add another backend that will allow me to target the browser.

The architecture is clean and convenient, but it comes with a cost: using interfaces and virtual/abstract methods introduces overhead, and I’d really like to avoid that for performance reasons.

If the core engine and the rendering engine were in the same assembly, I could do something like this:

partial class Game
{
    ...
}

#if MONOGAME
partial class Game
{
    void DrawGameInstance(GameObject instance) =&gt; ...
}
#endif

#if ANOTHER_RENDER_ENGINE
partial class Game
{
    void DrawGameInstance(GameObject instance) =&gt; ...
}
#endif

But I really want to keep the core engine and the backend engines separated into different assemblies.

So what’s the best solution here?

Thanks in advance!

reddit.com
u/Alert-Neck7679 — 28 days ago
▲ 150 r/csharp

A little life hack🙂

I just realized that you can do:

public static class Extensions
{
    public static bool IsNullOrWhiteSpace(this string? str) =&gt; string.IsNullOrWhiteSpace(str);
}

And then you can just do:

if (name.IsNullOrWhiteSpace()) ...

Instad of:

if (string.IsNullOrWhiteSpace(name)) ...

Actually, while writing this i'm realising that now with the extensions keyword you can even implement it as a read-only property.

What are some other life hacks that can make us happier people?

reddit.com
u/Alert-Neck7679 — 1 month ago

My biggest solo project: Game Engine with its own programming language

So the project is a 2D game engine (MonoGame backend) inspired by GameMaker 8. It includes its own IDE (built with WinForms) and an interpreted programming language that I wrote myself.

The language—definitely the biggest challenge in the project—is a simple dynamically typed language. When I started, I had zero knowledge of how to build something like this. I didn’t even know I was making an interpreter; at first I called it a compiler. It was a personal challenge, and I wanted to figure everything out without using any resources or tutorials. My mindset was basically: “I need to write software that takes a text file containing code and just does what it says.”

Somehow, I made it work. In the beginning, running an empty loop counting to 1M took 7 seconds. After a lot of performance work and rebuilding parts of the system, the same machine can now run a 30M loop in 2–3 seconds. Pretty nice improvement.

The language itself is a bit unusual, and I want to share one small feature I really like: loop counters.

foreach item in ['a', 'b', 'c'] : counter c
{
   println(c + ": " + item)
} 
// Output: 
// 0: a 
// 1: b 
// 2: c

Not a complicated feature, but pretty useful.

Here's a YouTube video showing me using the engine to build a little game

Any feedback is welcome.🙂

u/Alert-Neck7679 — 1 month ago

Working on a game engine with its own programming language!

GitHub repo

(first of all, i want to say that I made this project for fun and challenge. I always wanted to create my own language. This has no business goal or something.)

So the project is a 2D game engine (MonoGame backend) inspired by GameMaker 8. It includes its own IDE (built with WinForms) and an interpreted programming language that I wrote myself.

The language—definitely the biggest challenge in the project—is a simple dynamically typed language. When I started, I had zero knowledge of how to build something like this. I didn’t even know I was making an interpreter; at first I called it a compiler. It was a personal challenge, and I wanted to figure everything out without using any resources or tutorials. My mindset was basically: “I need to write software that takes a text file containing code and just does what it says.”

Somehow, I made it work. In the beginning, running an empty loop counting to 1M took 7 seconds. After a lot of performance work and rebuilding parts of the system, the same machine can now run a 30M loop in 2–3 seconds. Pretty nice improvement.

The language itself is a bit unusual, and I want to share one small feature I really like: loop counters.

foreach item in ['a', 'b', 'c'] : counter c
{
   println(c + ": " + item)
} 
// Output: 
// 0: a 
// 1: b 
// 2: c

Not a complicated feature, but pretty useful.

Here's a YouTube video showing me using the engine to build a little game

Anyway, these days I barely have time to work on the project, so I decided to open-source it. I’m hoping people here will find it interesting and help turn it into something real.

Any feedback is welcome.🙂

u/Alert-Neck7679 — 1 month ago
▲ 209 r/csharp

My biggest C# project: A game engine with its own programming language

GitHub repo

(first of all, i want to say that I made this project for fun and challenge. I always wanted to create my own language. This has no business goal or something.)

So the project is a 2D game engine (MonoGame backend) inspired by GameMaker 8. It includes its own IDE (built with WinForms) and an interpreted programming language that I wrote myself.

The language—definitely the biggest challenge in the project—is a simple dynamically typed language. When I started, I had zero knowledge of how to build something like this. I didn’t even know I was making an interpreter; at first I called it a compiler. It was a personal challenge, and I wanted to figure everything out without using any resources or tutorials. My mindset was basically: “I need to write software that takes a text file containing code and just does what it says.”

Somehow, I made it work. In the beginning, running an empty loop counting to 1M took 7 seconds. After a lot of performance work and rebuilding parts of the system, the same machine can now run a 30M loop in 2–3 seconds. Pretty nice improvement.

The language itself is a bit unusual, and I want to share one small feature I really like: loop counters.

foreach item in ['a', 'b', 'c'] : counter c
{
   println(c + ": " + item)
} 
// Output: 
// 0: a 
// 1: b 
// 2: c

Not a complicated feature, but pretty useful.

Here's a YouTube video showing me using the engine to build a little game

Anyway, these days I barely have time to work on the project, so I decided to open-source it. I’m hoping people here will find it interesting and help turn it into something real.

Any feedback is welcome.🙂

u/Alert-Neck7679 — 1 month ago

Anyone who knows C# and wants to help with this engine?

[GitHub repo]

It’s a 2D game engine (MonoGame backend) inspired by GameMaker 8. It includes its own IDE (built with WinForms) and an interpreted programming language that I wrote myself.

The whole project is written in C#.

I'm doing it mostly for fun and challenge, but I have almost no time to work on it and I would really love to get some help and contribution, for the core engine functionality mostly. If someone finds this project interesting, he is more that welcome to check the GitHub repo and see if he can contribute. It's a very cool project!

The language—definitely the biggest challenge in the project—is a simple dynamically typed language. When I started, I had zero knowledge of how to build something like this. I didn’t even know I was making an interpreter; at first I called it a compiler. It was a personal challenge, and I wanted to figure everything out without using any resources or tutorials. My mindset was basically: “I need to write software that takes a text file containing code and just does what it says.”

Somehow, I made it work. In the beginning, running an empty loop counting to 1M took 7 seconds. After a lot of performance work and rebuilding parts of the system, the same machine can now run a 30M loop in 2–3 seconds. Pretty nice improvement.

Here's a YouTube video showing me using the engine to build a little game

Anyway, add i said, these days I barely have time to work on the project, so I decided to open-source it. I’m hoping people here will find it interesting and help turn it into something real.

u/Alert-Neck7679 — 2 months ago
▲ 161 r/dotnet

My biggest ever dotnet project: Game Engine with its own programming language

GitHub repo

[Edit: I made this project for fun and challenge. I always wanted to create my own language. This has no business goal or something]

It’s a 2D game engine (MonoGame backend) inspired by GameMaker 8. It includes its own IDE (built with WinForms) and an interpreted programming language that I wrote myself.

The language—definitely the biggest challenge in the project—is a simple dynamically typed language. When I started, I had zero knowledge of how to build something like this. I didn’t even know I was making an interpreter; at first I called it a compiler. It was a personal challenge, and I wanted to figure everything out without using any resources or tutorials. My mindset was basically: “I need to write software that takes a text file containing code and just does what it says.”

Somehow, I made it work. In the beginning, running an empty loop counting to 1M took 7 seconds. After a lot of performance work and rebuilding parts of the system, the same machine can now run a 30M loop in 2–3 seconds. Pretty nice improvement.

The language itself is a bit unusual, and I want to share one small feature I really like: loop counters.

foreach item in ['a', 'b', 'c'] : counter c { 
    println(c + ": " + item) 
}
// Output:
// 0: a
// 1: b
// 2: c

Not a complicated feature, but pretty useful.

Here's a YouTube video showing me using the engine to build a little game

Anyway, these days I barely have time to work on the project, so I decided to open-source it. I’m hoping people here will find it interesting and help turn it into something real.

Any feedback is welcome.

u/Alert-Neck7679 — 2 months ago
▲ 20 r/csharp

Are there any programming language interpreters written in C#?

Hi, the reason I'm asking this is because I'm making my own and i would like to know if there are other interpreted written in C#, how they used to solve the problems i faced.

reddit.com
u/Alert-Neck7679 — 2 months ago

I've built a MonoGame based engine that uses my own scripting language

So this is the story: ~2.5 years ago, I decided that i want to make my own GameMaker8 based engine. The only problem was that i didn't know anything about HOW. I made a winforms IDE for this but the backend "engine" was... Winforms window that uses System.Drawing APIs to draw the textures. The language u used inside the engine was C# as well.

It wasn't a big success and i abandoned it for a few years. Half year ago, i decided i want to make my own programming language. I know absolute nothing about HOW, and i thought I'm building a compiler while what i actually built was an interpreter, but somehow i figured my way and had it get to the point that it's kind of ready for a prototype.

In that point i returned to the game engine, implemented a MonoGame backend and integrated my language in it, instead of C#.

Unfortunately, i have not enough time for this project now so ive open sourced it, hoping people would find that interesting and help with it: https://github.com/ArcadeMakerSources/ArcadeMaker .

Here's a YouTube video showing how i use the engine to create a small game.

i would love to get some feedback here🙂

u/Alert-Neck7679 — 2 months ago

I'm making my own mini GameMaker

I'm making a GameMaker based engine with my own scripting language.

https://preview.redd.it/hi6x8ab47x1h1.png?width=1599&format=png&auto=webp&s=b28e3839fc1d2a6dfb7ef06eaf10e05e48e90f56

https://preview.redd.it/ebyy5ob47x1h1.png?width=1599&format=png&auto=webp&s=ce902b095766eb40e631f2da00cf7cf138834f7e

https://i.redd.it/33lr8nb47x1h1.gif

Here's a video of me using the engine to build this little game

It's a C# project containing an IDE that equals to the old GameMaker 8 IDE, an interpreter programming language that i made myself, and a backend MonoGame-based engine that will allow me, in the future, to export the games for desktop and mobile.

I'm doing it because it's super fun and challenging, it will probably never get to the level of modern GameMaker but this isn't the goal. If it sounds interesting to you, then you'll be happy to hear that it's open source and you can find the full code of all project parts + some basic documentation here: https://github.com/ArcadeMakerSources/ArcadeMaker . And here you can read more about how i started this project.

Would love to hear what you think about this!

reddit.com
u/Alert-Neck7679 — 2 months ago

I'm making an engine with my own programming language!

https://preview.redd.it/bxuxvlxvdw1h1.png?width=1599&format=png&auto=webp&s=06f72d35ef43ca0864b293ad602e04f7039df5c9

https://preview.redd.it/2fk8aywvdw1h1.png?width=1599&format=png&auto=webp&s=221392a03ba2fb60ee2ae267d592188e1d1ff611

So everything started about 2.5 years ago. I built a game engine using C# as the programming language, along with a basic IDE (which I designed to look exactly like the old GameMaker 8 IDE). It used System.Drawing on a WinForms window (!!) to render the game, along with the standard WinForms input methods.

Well, it wasn’t a big success, but it was really fun to build.

Now, 2 years later, one day I was bored, and I decided to make what I had always wanted to make: my own programming language. So I opened an online C# IDE (which is what I usually do when I want to start something I’ll probably abandon after 5 minutes) and started writing an interpreter.

At that time, I had absolutely zero knowledge about how programming languages are built. I didn’t even know the difference between a compiler and an interpreter, and I called the main class “Compiler.” I didn’t know what a lexer was, what a parser was, or what a syntax tree was. I just thought: I need to write software that takes a text file and runs what it says.

This was something I had already tried a few times before, and I always stopped after about 10 minutes when I realized I had no idea how to do it. But somehow, this time it started to work. So I opened Visual Studio, and for the next few months I built the interpreter.

At the beginning, it took 7 seconds to run an empty loop counting to 1 million. But gradually, I improved how things worked, and now it takes about 2 seconds to run a loop of 30 million iterations on the same computer.

It’s not fully ready yet—I’ve reached that stage where only the last “10%” remains, which usually takes 90% of the total time—but it’s already good enough to integrate into prototype projects.

So I went back to the game engine, removed the old engine from the solution (keeping the IDE), and started building a new one based on MonoGame that uses my interpreter. I started this about a week ago, and now I already have some basic functionality: input handling, collision detection, and core game logic. I’ve also attached a screenshot of a small demo game I made:

https://i.redd.it/h4q1yzt1ew1h1.gif

Because this engine is based on MonoGame, it should eventually support all major desktop and mobile platforms—and even consoles. I’m also about to try setting up a KNI-based project to support in-browser games as well.

I don’t think this will ever compete with professional engines like GameMaker, but as a solo project made for fun, I’m really proud of what I’ve built so far—and what I’m planning for it to become.

Full project source is available on GitHub: https://github.com/ArcadeMakerSources/ArcadeMaker

And there's also a screen record showing me creating the above game:

https://youtu.be/h_AnUg4yJWs?si=Kn2cGUXIZcCdQz62

so what do you think about this? 🙂

reddit.com
u/Alert-Neck7679 — 2 months ago
▲ 18 r/csharp

Using C# to make my own Game Engine and Programming Language!

[Full project source on GitHub: https://github.com/ArcadeMakerSources/ArcadeMaker ]

I’m building a cross‑platform 2D game engine that includes its own IDE and programming language.

It all started about two years ago. I built an engine that let you create games in C#, but I abandoned it after a few months. A little over a year later, I decided—without any knowledge of how to do it—to create my own programming language. Somehow I figured things out, and once the language reached a more advanced stage, I decided to return to the engine project and replace the original C# scripting with my own language.

Now the project has reached a really fun and interesting point where you can actually make small games with it. It’s still far from finished, and since I have very limited time to work on it, I decided to open‑source it in the hope that others will find it interesting and help turn it into something real.

I wanted to share it here because some of you might want to check out the video or the GitHub repository, which includes the full source code and some basic documentation.

Here's a video of me creating a small game with it: https://youtu.be/h_AnUg4yJWs?si=MR3nQCVvOMDP3iqg

and here's some screenshots:

https://preview.redd.it/faukjbqyaw1h1.png?width=1599&format=png&auto=webp&s=a10f561c7baea1c34076537dbfb4e78d3c05f492

https://preview.redd.it/3gsgwcqyaw1h1.png?width=1599&format=png&auto=webp&s=92e42ea23c2a8f000707fcabf2d755396246e57c

https://i.redd.it/ga9v7dqyaw1h1.gif

Would love to get some feedback🙂

reddit.com
u/Alert-Neck7679 — 2 months ago
▲ 0 r/csharp

It feels like the language would be so much more flexible if they were, wouldn’t it? I started thinking about this while looking for a list implementation that automatically reacts to collection changes (by the way, do you know one?). If C# worked that way, I could simply write something like:

public class ModAlertList&lt;T&gt; : List&lt;T&gt;
{
    public event EventHandler CollectionChanged;

    public override void Add(T item)
    {
        base.Add(item);
        CollectionChanged?.Invoke(this, EventArgs.Empty);
    }

    // ... same for Remove()
}

And there are tons of other examples like this.
So what’s the reason?

reddit.com
u/Alert-Neck7679 — 2 months ago