lots of bugs / warnings c2runtime

Discussion and feedback on Construct 2

Post » Thu May 19, 2016 12:38 pm

Honestly, I have doubts this is at all helpful. I'm sorry, it's a very complex engine and it has years of subtleties coded in for long-ago bug fixes, backwards-compatibility purposes, and optimising for general-purpose performance rather than specific cases.

For the leftover semicolons: this basically doesn't matter, but the reason it's there is because the exporter deletes all assert checks on export. It has to leave a semicolon so they still count as statements though. For example:

Code: Select all
if (x)
    assert(y);

doSomething()


If the runtime deletes the assert and the semicolon, this effectively becomes:

Code: Select all
if (x)
    doSomething();


What was previously an unconditional call is now conditional based on the if. So in this case your suggestion of removing the semicolons could create bugs where there were none before.

"nextHighestPowerOfTwo" has never come up in any profiling measurements I've made so I believe any attempts to optimise it are just a waste of time.

The collision checks are optimised for general-purpose performance. It's often possible to take some specific case and optimise that to be something like twice as fast, but it could make other cases half as fast. That's not a good tradeoff for an engine like Construct 2, since making some games slower and others faster is worse than having them all run at reasonable performance. (What if your game is one of the slowed-down ones? "It made other people's games faster" isn't much consolation.) For example the existing C2 segment intersection check can early-reject based on a bounding box check before it does any math. Your alternate version does some math calculations before it can reject, which isn't necessarily faster or slower over all, probably just different (a different set of cases will be faster/slower). The same is probably true of your contains_pt code.

Then on top of that, there is a significant backwards-compatibility concern. One of the reasons I don't want to make any changes to these functions is they are absolutely core functions that almost every game heavily depends on. In the early days we made some tweak - smaller than your changes - and it broke a bunch of platform games because floating-point numbers started rounding in a different direction and ultimately it meant you couldn't fit in tunnels you could previously fit in to! At the time I reverted the change and it's been left like that ever since. So it seems very unlikely we could ship any such changes without breaking a wide range of games. I mean, you say yourself, your changes already broke your own game :P It doesn't matter if it's 100x faster, if it doesn't work correctly we can't use it, it will break existing games, and if that is our overall philosophy, we end up building a buggy nightmare of a product which is fast but never works properly (quite a good description of how Construct Classic ended up).

Finally, I'm afraid if you so much as change a single line of code in the C2 engine, we can't support you any more. For example we cannot accept any of your bug reports any more. If you have even a tiny change to the engine, and you report a bug, we will reject it in order to rule out the chance the bug is caused by your own engine changes (which is especially likely if it's an unfamiliar codebase). A warning to other users: this is also true if you are looking at these posts and decide to paste in any changes to the engine. If the code is not 100% exactly identical to what comes with the installer, we can no longer offer support.

I don't see that you will be able to overcome any of these limitations in your approach, so I must discourage you from trying this. By all means hack away and experiment for your own learning purposes, but we will probably not use any of the changes, and we cannot offer any support if you have made a single change to the engine.
Scirra Founder
B
387
S
229
G
87
Posts: 24,245
Reputation: 192,050

Post » Thu May 19, 2016 1:59 pm

@Ashley - thanks for the long answer :)

i'll reply shortly (backwards) - i don't agree with you about overcoming limitations. limits can always be overcome, one way or another, that's why not a single software is "ever finished". always something to improve, upgrade, develop and so on.. when i'm using your engine to export my games i use it in it's native form as it came with installer, but i've got a separate installation for testing stuff out where i replace code and see if things improve/change etc.., however all the things i do i keep in my folder, each test i've done in its own file.
on top of the support thing and including changes and tests that users comment / commit to forums, at least i would love if you'd take at least 5-10 mins to check them out and see if there is a possibility of improving something that someone has tested / tried and so on. whether you include that in the engine in some newer versions is ofcourse up to you, and your team alone. as a developer i have a need to tweak stuff, so if i can help that ends up great, and even if you do use any (even 1 out of 100 tweaks i do) it feels like a great job for me, to contribute to the devs of engine i use / follow /etc.

and now to the tech part:
- i've posted now 4 posts about tweaks / changes, and some of them do seem useless like the semicolons problem that is left after assert statements, but i've just mentioned it because i've noticed some random semicolons appearing out of nowhere. now i know that compiler probably ignores them, still uses a bit of time to process them, but ok. not much of a problem.
- nextPowerofTwo - i didn't find it's use, but still a faster way is faster, at least by a bit, but also i think you're right when you say it doesn't appear anywhere in performance profiling.

but the last 2 are pretty performance based...
cr.segments_intersect - i've optimized that and it returns correct results, and have been testing with random values for both algorithms, both receiving random input data, but same data for both functions. it appeared that everytime results were the same and my function was faster. also your comment there is:
"// Long-hand code since this is a performance hotspot and this type of
// code minimises the number of conditional tests necessary." :)

i would like if you could take a look at that one at least. I've noticed also that you mentioned that code is optimized for one type of game but not optimized for another type of game. i understand your approach to the problem when you say "general-purpose" and i didn't even try to go in some specific direction for it. Still a function that returns a value, should return always the same value, no matter how it's written, but that could impact it's performance. i highly doubt that one function can determine if a game is of one type or other.

i agree that checks with math calculation can reject before/after, but after testing that function against the regular one, with over 10 000 000 input data, every time mine got the best of it.

and what happens with the last (contains_pt) is a mystery to me, i might have missed something, but it's performance is double of the performance of default function. as much as i've understood you split the quad into 2 triangles and check if the point is in each. if it is in first you return true, and if not then you check for 2nd one, and return true if there, if not return false. that's exactly the same what mine code should do, and i my tests it did, but when used in engine it produces halfway good working. i'll try to fix that today and see if it gets better.

i would be also gratefull if you could check the code and the 2 links i've posted and see if there is a possibility to improve that function.
i also know how deep the rabbit hole goes when you have to be careful with floats and overflow and 4-5-6 decimal places and stuff..

and also, i can give you my test html files (which include the JS with functions and how i've tested) if it will make it easier for you to see what happens.
i'm pretty sure there's a lot more in the engine that can be fastened in microbenchmarks and improve overall performance of the engine, without depending on what type of game it is.

p.s. sorry if my post is long, i'm not here to argue, insult or anything, i love C2, love your work, but i would appreciate if you'd "let" me at least post those improvements and take periodically a look, and even if you find 1 useful it will be my joy!
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
41
S
14
G
12
Posts: 623
Reputation: 9,359

Post » Thu May 19, 2016 5:06 pm

The only way we can actually verify we don't break or slow down people's games is to ship the change in a beta release, and my previous experience of this is much smaller changes had game-breaking results. Even just reordering the operations or putting brackets in a different place (e.g. (a * b) / c vs. a * (b / c)) can change the floating-point precision, increasing or decreasing rounding errors, and break some games which relied on the previous behavior. I already did a bunch of work optimising all this in the early days so it has pretty good all-round performance, and I just don't see the point of risking such enormous collateral damage for some pretty small changes.
Scirra Founder
B
387
S
229
G
87
Posts: 24,245
Reputation: 192,050

Post » Thu May 19, 2016 5:29 pm

@Ashley
so what you're telling me i should just give up and go make some games?
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
41
S
14
G
12
Posts: 623
Reputation: 9,359

Post » Fri May 20, 2016 4:12 am

saiyadjin wrote:@Ashley
so what you're telling me i should just give up and go make some games?


Not what I am seeing. Ashley said you can hack away all you want. But perhaps keep everything well documented to yourself for now, and come back if you have something more solid? Some of your numbers are intriguing, but with working in large projects myself sometimes that does not translate well once deployed. Depending on the server deployed too, the code can run worse then testing. Which in terms of C2, would be a nightmare if a bunch of apps started performing badly.

Anyways, point I am trying to make is, if you enjoy what you are doing, continue on. I don't think you will get any immediate action, and you would need to do a lot of work on your end to prove this more. Something well documented and well tested. We are talking hundreds upon hundreds of hours of testing if you really want to try it. I think it would be hard to get Ashley to do that . . . you would be asking him to do those hours upon hours of testing and as the saying goes...if it ain't broke, don't fix it!
B
41
S
17
G
8
Posts: 484
Reputation: 8,261

Post » Fri May 20, 2016 7:20 am

Ashley also said that he won't be checking this things out, that he used a lot of time to optimize things for general purpose usage. And i believe him. So why would i waste more time for this then he already did. Also if he believes that he can't optimize further (i think he can, but it's time consuming) then i'm fine with it. In the end it all comes to how your game performs on different platforms and in the end it's not about the engine, it's about the product that is made with that engine. For some tower defense games and such stuff that i am preparing to do, the engine itself is more then enough good. A lot of people complain about performance and such issues but they mostly come from compilers and wrappers (xdk / crosswalk / etc..) or users creating huge games that are overblown in size, etc, not following image usage and so on and so forth..
i've built one game for PC as my own testing of engine and i've noticed that even with loads of objects and over 100 000 collision checks per second everything works fluidly.
but particles are badly optimized, also for some reason, collisions appear to be higher then they should be, i mean collision system is pretty bad and every optimization is godlike for that - why? because when you have a screen like this:

http://imgur.com/J2lEi4e

you don't expect 1095 collisions per tick, let alone 60 000 per second, and CPU usage of 30%.
@Ashley - can you elaborate this?

for more info - ignore the object count - it's particles mostly and most of those objects have collision disabled.
these objects have collision enabled:
boats, player boat, islands and cannonballs, and that mine up there.
so if you count all the "collidable" objects the count of them on this image is - 26.

how do i get 1095 / 60 000 collision checks from 26 objects?

forgot to mention this is on a gtx980M 8GB ddr and 4860HQ processor (3.6GHz) - and 30% usage ? wtf?
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
41
S
14
G
12
Posts: 623
Reputation: 9,359

Post » Fri May 20, 2016 10:08 am

This is my main point:

Ashley wrote:By all means hack away and experiment for your own learning purposes, but we will probably not use any of the changes, and we cannot offer any support if you have made a single change to the engine.


So you can hack away if you like, but we can't exactly copy-paste snippets of code from the forum to our engine. (There's also copyright concerns and code licensing - I just thought of that :P)

Off-screen collisions always count, and if you have a lot of different collision checking events, they all count too. So if you have 25 objects and you test collisions between all of them, that's already 600, suppose you have four repeated sets of events which makes it 2400, then at 60 FPS it's 144,000 checks per second. So you can easily fill large collision check numbers even with a small number of objects. The key is to reduce collision checks to only objects which need it, and eliminate redundant collision check events. (i.e. use sub-events to a single collision check event, rather than making the same check in different places)

Again, nothing specific to Construct 2 there, it's just maths. But C2 does make it easy to accidentally make loads of checks, because things like checking every combination are implicit.
Scirra Founder
B
387
S
229
G
87
Posts: 24,245
Reputation: 192,050

Post » Fri May 20, 2016 10:48 am

@Ashley - i agree, but when i wrote code on forum i've pasted function as it appears in (for example) common_prelude.js, both original and changed, retaining variable names, return values and so on (but okay). p.s. didn't think about the copyright, since i'm doing it out of my own will so it's more of a helping hand (and not sure if i need copyright when taking something from stackoverflow or such pages).

collisions thing - i'm destroying objects when they leave screen so they shouldn't count. the thing i didn't know is that it counts events? so when i have cannonball checking for each other object that can hit it multiplies? 1 cannonball = checks if hits boat/island/mine = 3 collision checks? and then 10 cannonballs = 30 collision checks? is this right?
could family help with that? (example - 1 event for checking if cannonball hits family (of boat/island/mine) ) so it's 1 check and 10 cannonballs does 10 checks?
this sounds pretty false to me, but is it working like this / could it?

anyway here's an image, and i'd love if you could explain a bit in detail what is causing the increased collisions there:
http://imgur.com/Y0CAccx

this is a part of code (ignore the comments) which does collisions with objects for cannonball. i've used 2 families (enemies (boats and other) and objects (islands mines and bouyes except crates) ) to check if canonball hits any of these objects, if it does.. it does it's thing (we're not discussing actions here so no need to look at them either)..

so the problematic area then appears to be this "canonball is overlapping" and that is a collision check against 2 more objects? and instead of this it should be that bullet = 0 should be the first condition to check instead of collision because we want "watery explosion" when bomb stops and doesn't overlap anything (meaning it's on water). or should it be subevented when bullet = 0 ?

thanks :)
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
41
S
14
G
12
Posts: 623
Reputation: 9,359

Post » Fri May 20, 2016 9:17 pm

@Ashley - also, what else is performance unfriendly in engine?
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
41
S
14
G
12
Posts: 623
Reputation: 9,359

Post » Mon May 23, 2016 10:37 am

@Ashley anything? can you at least look 2 posts behind and answer to that? thnx
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
41
S
14
G
12
Posts: 623
Reputation: 9,359

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 3 guests