Originally I was considering embedding python in my C++ game engine.
Though my game engine is multi-threaded cpython well isn't.
So I was thinking why not make a modified version of the game engine that is contained in a DLL.
Then use python an initializer and setup system.
Most of you probably are thinking what benefit would that give you over SDL or pygame.
Well pygame and SDL are libraries that the primary execution runs in python.
In this case I am talking about building the primary loop inside the DLL. (Yes, that is possible.)
As I stated above pythons job would be to initialize it and setup.
Those of you that are moderately good at programming are probably thinking that you have no control over the loop and how to handle any of that.
Not really a flow model can be used sort of like a script system just it doesn't need interpretation.
So what's the benefit?
SDL2 and opengl access. I can add other like vulkan and maybe one day I'll give two hoots about mac and see what they need.
Plus the performance of C/C++ so 10+ times faster.
You don't need to learn C/C++.
The other benefit is it isn't just python it can be used with given it is a shared library.
If you are wondering how realistic it is well I spent the better part of today making sure it was by coding and testing.
Before it is fully usable there is a lot to do. All I made at present was a very basic system to prove it was possible. That way I would have an idea how much work it will be.
For those of you with an advanced understanding of C++ who are curious how flow control is handled for a variety of games:
A manager class: I have 2 options here.
1. I can have it register classes with it that have a single function for designating the game operational path.
2. I can build the operational path using multiple functions that are registered in the order desired.
I figured I would update this to give a better understanding of what actually can be done this way.
If you read below a few response it might answer some question but this might give you a bit more of an idea.
There are technically more options in which I could choose to solve the problem. I chose one that gives good performance but isn't the most amount of work. There is still a lot of work just not as much as there could be.
1. I could write an inline compiler. By that I mean it would be an actual compiler to generate machine code when the game is initialized then run that code as functions. The way GNU's licensing is it can't be used and nor can any proprietary compiler. That said LLVM could be used for this method.
Though my game engine is multi-threaded cpython well isn't.
So I was thinking why not make a modified version of the game engine that is contained in a DLL.
Then use python an initializer and setup system.
Most of you probably are thinking what benefit would that give you over SDL or pygame.
Well pygame and SDL are libraries that the primary execution runs in python.
In this case I am talking about building the primary loop inside the DLL. (Yes, that is possible.)
As I stated above pythons job would be to initialize it and setup.
Those of you that are moderately good at programming are probably thinking that you have no control over the loop and how to handle any of that.
Not really a flow model can be used sort of like a script system just it doesn't need interpretation.
So what's the benefit?
SDL2 and opengl access. I can add other like vulkan and maybe one day I'll give two hoots about mac and see what they need.
Plus the performance of C/C++ so 10+ times faster.
You don't need to learn C/C++.
The other benefit is it isn't just python it can be used with given it is a shared library.
If you are wondering how realistic it is well I spent the better part of today making sure it was by coding and testing.
Before it is fully usable there is a lot to do. All I made at present was a very basic system to prove it was possible. That way I would have an idea how much work it will be.
For those of you with an advanced understanding of C++ who are curious how flow control is handled for a variety of games:
A manager class: I have 2 options here.
1. I can have it register classes with it that have a single function for designating the game operational path.
2. I can build the operational path using multiple functions that are registered in the order desired.
If functions A,B,C are registered with the manager the manager then runs the functions in order A,B,C.
This functionality can be used from low order systems to higher order systems so the general flow of the game to what happens if player A does X to another player.
The problem with using this method is while it is fairly fast the more you add to it the slower it becomes. You are still having to iterate through a loop of some type as overhead and so on. So using pre-designed methods for each type of game would result improved performance. Either method though allows for multi-threading.
Update:I figured I would update this to give a better understanding of what actually can be done this way.
If you read below a few response it might answer some question but this might give you a bit more of an idea.
There are technically more options in which I could choose to solve the problem. I chose one that gives good performance but isn't the most amount of work. There is still a lot of work just not as much as there could be.
1. I could write an inline compiler. By that I mean it would be an actual compiler to generate machine code when the game is initialized then run that code as functions. The way GNU's licensing is it can't be used and nor can any proprietary compiler. That said LLVM could be used for this method.
That would give the greatest performance and highest flexibility.
a. This does have one interesting benefit. You could write a python parser with it so that you could compile it. Thus the person writing code would be able to modify the internal game code using python and suffer no performance hit doing so.
2. I could write an interpreter. So that they could pass in scripts. Moderately flexible poor performance.
Last edited: