Legacy GM c++

L

lord_berto

Guest
what if I code some function in c++ and have game maker read its output,
will it be faster than just coding it in gamemaker? (example, a while loop checking for a value in a 100x100 array) after all, isn't game maker slow, and c++ really fast?
 

GMWolf

aka fel666
what if I code some function in c++ and have game maker read its output,
will it be faster than just coding it in gamemaker? (example, a while loop checking for a value in a 100x100 array) after all, isn't game maker slow, and c++ really fast?
You can create DLLs that GM can call.
But there is overhead involved, and it is a lot more work. Considering that GML really isnt all that slow with YYC, its rarely worth it.

For something as simple as looping through 10,000 values, just use GML.

However, if you are dealing with more complex data and want to use more complex algorithms, the writing a DLL may be a good option.

I would recommend attempting a GML implementation first, and only write a DLL if the performance or language features isnt enough.
Though remember that better algorithms are more important than the language choice.
 

zbox

Member
GMC Elder
Echoing what Fel666 said, I was really surprised the other day. I rewrote a big part of the GMLVideo encoder in C++, it took me two days, and I got a measly 20% speed increase. 25% If I was lucky by eliminating some overhead.

Annoying for me but also I'm very impressed by GM!
 
L

lord_berto

Guest
Well, one big improvement c++ has to offer is multithreading.
Other than that, I would only consider using it for it's OO or wrapping an existing library.
what is multi-threading?
 
L

lord_berto

Guest
You can create DLLs that GM can call.
But there is overhead involved, and it is a lot more work. Considering that GML really isnt all that slow with YYC, its rarely worth it.

For something as simple as looping through 10,000 values, just use GML.

However, if you are dealing with more complex data and want to use more complex algorithms, the writing a DLL may be a good option.

I would recommend attempting a GML implementation first, and only write a DLL if the performance or language features isnt enough.
Though remember that better algorithms are more important than the language choice.
i always thought that since you are instructing the computer something.. at a higher level, closer to binary, that it should be faster though right? for example using the function point_distance in game maker is better than creating your own distance formula inside of gmaker. so shouldn't coding a function in c++ be even faster than coding it in gml?
 
i always thought that since you are instructing the computer something.. at a higher level, closer to binary, that it should be faster though right? for example using the function point_distance in game maker is better than creating your own distance formula inside of gmaker. so shouldn't coding a function in c++ be even faster than coding it in gml?
At a very abstract level, you are correct. But, not all code is created equal. It is possible for you to write (or try to write) a more efficient function to handle point_distance(), but probably not - it is all fairly well optimized in GML. I think everyone is saying that YYC is pretty well tuned and unless you are doing absolutely massive amounts of computations, just stick with it. The benefits will likely be nominal at best, and possibly worse.

Also - my understanding (and I could be wrong) is that DLLs will be incompatible across many platforms - so if you have any intention of making your game for many places (Windows, Linux, Android, iOS, etc...) you probably don't want to monkey around with this at all.

Final Note: You are always welcome to do it your own way, of course... If you are more comfortable with C++ and can write more efficient code more quickly, sure, do it. Just be ready to deal with other issues. My guess is that if you can write really efficient C++ more quickly than GML, you may want to just skip GML altogether and go with a different game engine. (maybe other more seasoned game devs can comment on my thought... if I am right on this.)
 

sylvain_l

Member
i always thought that since you are instructing the computer something.. at a higher level, closer to binary, that it should be faster though right? for example using the function point_distance in game maker is better than creating your own distance formula inside of gmaker. so shouldn't coding a function in c++ be even faster than coding it in gml?
if this was holy true, we were all coding in assembly :p

I'm not sure, but i you use YYC, it first translate code into native code for the target platform before compiling it. Not sure it means C++ for windows. And at the end what matters is the binary ! (I mean coding in Fortran doesn't mean having a slower binary then in C++ in fact I believe its the opposite So why do you believe gml would automatically be slower ?!?)

Also, at some level, compiler can optimize your code for faster or less memory , etc... But honestly it can do nothing to handle the fact that you make crappy algorithms and design decisions (for example using 4k sprite to display them as 32x32 block on screen will just kill memory and swap page, etc...)

also using dynamic linking (.dll for windows) is a bit slower than static linking (plain exe) just cause of having to resolve the dynamic adress, and some other thing but its not much. So shouldn't concern you to much (except if all you do in your dll function is adding to integer)
 

GMWolf

aka fel666
what is multi-threading?
I'm not sure you are ready for c++...

i always thought that since you are instructing the computer something.. at a higher level, closer to binary, that it should be faster though right?
Sure, but is it worth it?
Also DLLs introduce calling overhead.

If you are just looping through 10000 values, it is not worth it at all!

Forget about optimization, just write good code that works.
 
L

lord_berto

Guest
I'm not sure you are ready for c++...


Sure, but is it worth it?
Also DLLs introduce calling overhead.

If you are just looping through 10000 values, it is not worth it at all!

Forget about optimization, just write good code that works.
Thanks for the comment, i just feel I've reached game makers limits, and to do certain things, just takes way too much focus on optimization specially if developing for ios or andriod. i've spent weeks optimizing everywhere, as much as i can. along the journey, you come to figure out game makers weak points, what to avoid, etc. I'm currently still learning c++ but have sufficient knowledge to make a game with a simple graphics library. As of now im deciding to either use xcode or a learn c# and use a game engine like unity, I just wanted to know if it was possible to simply code certain tasks in c++ like a light/shadow effect, and have game maker run it. thanks.
 

GMWolf

aka fel666
like a light/shadow effect
You can do that in GM. Use shaders.

Seriously, if you are hitting GMs limit, its 99% probably that you are simply writing bad code, with bad algorithms.

Heck, I wrote code that ran faster in GML than some older code I wrote in C simply because I got better at programming!

What limits are you hitting?
 

nivlat

Member
I have done a chesslike game that had to check literally millions of combinations on computer's turn (which took minutes). Considered doing a dll but in the end what Fel666 said is true. I looked for a better algorithm to cut down "thinking" time.
 

FrostyCat

Redemption Seeker
Thanks for the comment, i just feel I've reached game makers limits, and to do certain things, just takes way too much focus on optimization specially if developing for ios or andriod. i've spent weeks optimizing everywhere, as much as i can. along the journey, you come to figure out game makers weak points, what to avoid, etc. I'm currently still learning c++ but have sufficient knowledge to make a game with a simple graphics library. As of now im deciding to either use xcode or a learn c# and use a game engine like unity, I just wanted to know if it was possible to simply code certain tasks in c++ like a light/shadow effect, and have game maker run it. thanks.
Have you exhausted other ways of optimizing it on an algorithmic basis? This is the biggest problem that rookie CPU/RAM misers often don't pay attention to. Badly written algorithms look just as stupid in C++ as they do in GML and have the same bottlenecks.

For example, if the prevailing operation on that 100x100 array is setting and getting isolated entries, why is it not implemented as a sparse array? That would have shaved thousands of entries off your data. With a good data model, the speed difference between C++ and GML might even become negligible.

Same with your attempt to make shadows in code. No amount of software-level hacks in GML, C++, or whatever can beat the hardware-level acceleration that shaders can afford. It shows you have no idea where your real bottlenecks are.

You haven't reached GM's limits, chances are you've only reached the limits of your understanding of computer science.
 
L

lord_berto

Guest
Have you exhausted other ways of optimizing it on an algorithmic basis? This is the biggest problem that rookie CPU/RAM misers often don't pay attention to. Badly written algorithms look just as stupid in C++ as they do in GML and have the same bottlenecks.

For example, if the prevailing operation on that 100x100 array is setting and getting isolated entries, why is it not implemented as a sparse array? That would have shaved thousands of entries off your data. With a good data model, the speed difference between C++ and GML might even become negligible.

Same with your attempt to make shadows in code. No amount of software-level hacks in GML, C++, or whatever can beat the hardware-level acceleration that shaders can afford. It shows you have no idea where your real bottlenecks are.

You haven't reached GM's limits, chances are you've only reached the limits of your understanding of computer science.
So you are telling me shader's aren't programmed for? LoL. this is exactly what i mean. in c++ you can go off and create your own shader's and graphic libraries, operating systems, etc. because you have speed and closer communication between software and the hardware. You can get creative with Game maker all you want, but at the end of the day, you are going to be dealing with issues regarding speed. It has nothing to do with understanding computer science. It is simply the limitation of the software. Hope you now understand.
 
L

lord_berto

Guest
Time for you to download VS.net and get cracking then. :p
been there done that mate. after all this post is about whether its possible to simply code in c++ and somehow let game-maker include my c++ files.
 
L

lord_berto

Guest
Well the answer is 'yes' in a limited fashion.

Been there, done that too. ;)

I've made GMS earn me thousands by making it do things it cant do. I've never had to release a game with GM in order to make money from it. So, I know a little on the subject also. :)
Thank you I appreciate the positive attitude.
 
...in c++ you can go off and create your own shader's...
Forgive me if I'm mistaken, but what you said here makes it sound like you think you can't create your own shaders in GameMaker, which of course, you can.

...because you have speed and closer communication between software and the hardware....
I think its a balancing act. I've coded prototypes in GameMaker in under an hour, heck sometimes in 20 minutes, that would have taken me 10 times as long if I had used another engine or library.

If I wanted to get close to the hardware, I could use assembly or binary, or even design my own custom chip, but then I'd probably be out of a few weeks of my life before getting something playable on screen. :)

As somewhat mentioned above, these days compilers do handle a lot of optimizations for code so that developers can focus on developing, not wrestling with the hardware and low level assembly language.

If you are having an issue with processing speed in GameMaker, you could always post the specific problem and example code you are working on, I'm sure there's a good chance someone in the forum could help.
 
L

lord_berto

Guest
Forgive me if I'm mistaken, but what you said here makes it sound like you think you can't create your own shaders in GameMaker, which of course, you can.



I think its a balancing act. I've coded prototypes in GameMaker in under an hour, heck sometimes in 20 minutes, that would have taken me 10 times as long if I had used another engine or library.

If I wanted to get close to the hardware, I could use assembly or binary, or even design my own custom chip, but then I'd probably be out of a few weeks of my life before getting something playable on screen. :)

As somewhat mentioned above, these days compilers do handle a lot of optimizations for code so that developers can focus on developing, not wrestling with the hardware and low level assembly language.

If you are having an issue with processing speed in GameMaker, you could always post the specific problem and example code you are working on, I'm sure there's a good chance someone in the forum could help.
if you wanted to get close to the hardware you would use assembly or binary? Lol why would you ever do that when you can use C or c++ which has tons more features that will help you create something faster.
- I was just stating this because the guy above made it sound like language of choice has nothing to do with whether your apps or fast or slow. He called my lack of being able to "optimize my app" lack of computer science knowledge. obviously he cant see that game maker was made to be a lower level language, and therefor its limits, like draw calls can be reached alot faster and easier if you are not careful.
 
A few weeks? You must be a dead set master with electronics!
It would be a very small chip :) . The last time I did anything like that was back at University.

It's making a die-cast version of it, formally testing it and getting it to market that takes more than a few weeks.
Yes! And don't forget the time spent extracting the various precious metals from the earth and smelting them down with high enough purity for fabrication.
 

FrostyCat

Redemption Seeker
if you wanted to get close to the hardware you would use assembly or binary? Lol why would you ever do that when you can use C or c++ which has tons more features that will help you create something faster.
- I was just stating this because the guy above made it sound like language of choice has nothing to do with whether your apps or fast or slow. He called my lack of being able to "optimize my app" lack of computer science knowledge. obviously he cant see that game maker was made to be a lower level language, and therefor its limits, like draw calls can be reached alot faster and easier if you are not careful.
More evidence that not knowing enough computer science is a sure-fire way to sound silly on the GMC.

I never said the language of choice has nothing to do with a final product's speed at runtime, you're putting words into my mouth. I said if you simply change the language without also improving the underlying algorithm you wrote, you aren't removing the true bottleneck.

And by the way, C++ is the lower level language because it operates closer to machine code than GML. When a programming language is said to be high-level or low-level, it refers to its closeness to machine code (high-level=far, low-level=close), not the skill level of its intended audience.
 

Mick

Member
Anyone can "design a custom chip" with an FPGA.
I love your optimistic view of mankind! :)

When it comes to Gamemaker and GML, there a so many ways to optimise things. If something is running too slow, the reason is much more likely the algorithm used, not the language. I'm learning new things every day even if I have been programming for more than 20 years.
 
if you wanted to get close to the hardware you would use assembly or binary?
yeah, that comment of mine is a little tongue-in-cheek there.

I think i get your point though. If I wrote the exact same code/algorithm for both GameMaker and C++, I would in general expect the C++ code to run faster because it wouldn't have the overhead of the rest of the game engine that GameMaker provides. However, I believe the other people replying to this thread are very aware of that (you are getting replies from some GameMaker gurus indeed!).

The thing is, I would then be missing out on all the great ease of use and time saving tools that GameMaker provides. If the C++ code runs at 800fps and GameMaker runs it at 700fps, it's not really a concern, because that is still going to let me render my game at 60fps with room to spare, plus I'll have all the features of the GameMaker engine available to me.

C++ might let me make something that executes code slightly faster, but GameMaker let's me create the game itself in less time.

At this point, it is a matter of choosing the right tool for the job, instead of saying that someone should always choose C++ because it runs faster.

And @FrostyCat and @Mick have the right idea. Whereas changing the language Might gain you arguably 10 or 20% speed, choosing the right algorithm / technique is what will make a significant difference.
 

GMWolf

aka fel666
in c++ you can go off and create your own shader's and graphic libraries, operating systems, etc. because you have speed and closer communication between software and the hardware.
C++ doesnt allow you to write shaders. You are thinking of open GL or direct X.
Shaders really have nothing to do with what language you choose to code you game logic.
Game maker allows you to write shaders in GLSL or HLSL.

You can get creative with Game maker all you want, but at the end of the day, you are going to be dealing with issues regarding speed. It has nothing to do with understanding computer science. It is simply the limitation of the software. Hope you now understand.
Hahaha, it has everything to do with computer science knowledge!
Lets assume GML compiled with YYC is around 20% slower (quite accurate according to some tests), however you look a at it, if your game doesn't quite reach 60 fps in GML, it will only barely be at 60 fps in C++. Hardly a good solution.

That is unless you multi thread your logic but we already established you don't know what that is.

Now let's assume you have a custom collision system that checks all your objects. That's O(N^2) relationship.
Say you study a bit of comp science and choose to implemented t BVH or sort and sweep: you can get down to O(n log(n)) relationship.
That means that if you have 10 items, your game will run about 3 times faster.
Have 10,000 items? Game will run about 10,000 times faster.

As you can see, algorithms are everything.

if you wanted to get close to the hardware you would use assembly or binary?
Assembly, yes.
Have a look at any major engines source code. Quite a few ASM files.
The truth is that you can do a lot of funky stuff in ASM, if you know what you are doing, you can outsmart even C optimizers.
But, most of us here are probably better off sticking to C or C++

Incidentally, did you know that managed/interpreted languages like C# or Java can outperform c++ in some situations?Whilst performing rather similarly to C++ in common workloads? I'll let you think that one over. (That is not true for games due to their kinds of workloads)

- I was just stating this because the guy above made it sound like language of choice has nothing to do with whether your apps or fast or slow. He called my lack of being able to "optimize my app" lack of computer science knowledge
Yes, yes that's probably it!
There is a reason why DLLs are mostly used to wrap libraries or methods GM doesn't make available. But I have not seen it being used to provide logic since GM8, where DLLs for data structures where quite popular. (We got YYC and better arrays since).


obviously he cant see that game maker was made to be a lower level language, and therefor its limits, like draw calls can be reached alot faster and easier if you are not careful.
You can reach the draw call limit faster in GM not because it uses GML, but because it is not a custom engine. You will get the same issues when using other engines too.
Draw calls are ultimately bottlenecked by the rendering engine, not the language that made the call.
And is why GML has a multitude of lower level graphical stuff like vertex buffers.

Another did you know:
YYC will compile your GML to C++ (though, early in UYG talked a lot obput llvm?) Meaning if you know how to take advantage of GML you can get very good performance.
It is my understanding that instance variables end up slower to manipulate than local variables. Though we would need confirmation from one of the devs.

I don't mean to be mean, but it does sound like you are trying to go a little too fast. From what we have heard, c++ is clearly not for you at the moment. But go ahead and figure it out for yourself :)
 
Last edited:
Top