saiyadjin's Forum Posts

  • ok, i did some checks, here's what i found out:

    http://imgur.com/a/PALKg

    images show measurements and what events trigger how:

    here's a short explanation - if you have a object that collides with something - if you check vs family - it checks for all objects in that family each instance on screen - for example red and green squares are 7 = so checking 1 blue vs 7 objects (2 are in family, but red has 5 instances, and green 2)

    if you add "on collision" - it checks for collision whole time, but if you want additionally to check if it's collided with something and nothign else, adding not overlapping under it won't be checked until collision happens. when using overlapping - it checks the same thing - if there is collision / overlapping, but triggers every time there is, not just once like event trigger on collision.

    and finally the sexy part - if your object moves (for example with bullet and some speed) - and you want to check if he overlapps when it stops, put bullet speed = 0 first, because then collision checks do not happen until your object stops - after that speed = 0 and checks activate.

    there's probably much more combination but these are some common and happen the most, so designing your game for reduced colly checks should be taken with much care, hopefully someone will find use of these graphs and images..

    if anyone has questions, pm / write here

  • blah, i guess i'll just have to do everything myself.

  • Ashley - i wasn't asking for debugging, just for concept. you said that having multiple checking for collision in events multiplies checks. the screenshot provided just a few checks of cannonball colliding with some objects - 2 triggers and 4-5 overlapping conditions. i was wondering does trigger collision check cause multiplying of collision checking and does overlapping cause it too? which is worse and why? how to fix that? i don't need you to copy paste the exact code, just some tips like you provided before (subevents), how would you change the existing checks into a better one to reduce collision checks? that's all i need to know. the concept. thnx again, and sorry if i'm boring you..

  • because i did it on last stable version (before 228 came), and i've done them in such typing so that they can be just replaced (For example - i've fully replaced function segment intersection with mine), so it's technically save backup of file, copy paste mine over existing, test, if good gg if not revert to old file.

    that's not the point, i won't be doing anymore of this, i just want Ashley to explain me if this is correct what he said on the example before, and i'm all fine.

  • what? what messages?

  • Ashley anything? can you at least look 2 posts behind and answer to that? thnx

  • it would be great if we had objects per layouts view.

    then we would just drag 'n' drop repeating objects to the layout 2 folders, and those which do not repeat would stay in the first layout only. of course on export they would be all the same object (grass in layout 1 and layout 5) still exports as 1 grass texture.

    currently you can only create lots of folders and stuff, but that doesn't make it cleaner :/

  • yes you can.

    most of the games today work on this principle:

    • you have a server that accepts connections
    • players search match and when they are found by some rules they are put on 1 instance on that server
    • they are all connected to the same IP with instance ID
    • when someone moves (let's say it's a real time fps) - server
    • processes data and predicts future movement and sends that data back to all players (except the one who's input it did)
    • players see change with some delay (ping, depends on how far you really actually are from server and connection speed and so on (but this is not the point)

    and that's about it. ofcourse server has to process data from every user, and it's a lot of job so server are usually hardcore PCs, dual xeon and so on, with good connection speed, etc.. also, they can handle more then 1 instance, for example - let's say a game takes 10 players, and server handles 100 instances - 1000 players on that server. also you have to know how much data you send to server so that if it's full it can handle, and how much it sends. for example - max data sent to server from each player could be ~100kB * 1000 players = 100 000kB = 100mB /s connection speed for download on that server so that's another thing to watch, but usually data packets are smaller and speeds today are big.

    that's how it's done in real - time games. but in turn based games you have a bit of an advantage, and that is that you don't have to calculate prediction on server,

    you just have to send new positions / game data to server, and he dispatches it to other players so they update their view. and you do it only on the end of the turn. the only thing to handle here is some combat between players / interactions and so on.

    and yes, you can have a pc which creates an instance of the game, and people can join / leave while game stays in the same state as it is, but you've got to design the game carefully, and it's a tough job really.

  • Ashley - also, what else is performance unfriendly in engine?

  • 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 <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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?

  • Ashley

    so what you're telling me i should just give up and go make some games?

  • 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!

  • here comes a big one, which i didn't use in ingame engine (i did but reverted change) but Ashley might describe where the problem is and why:

    so there's this function that tests if a point is in quad (Quad.prototype.contains_pt = function (x, y)), so here's it's code:

    Quad.prototype.contains_pt = function (x, y)
    	{
    		var tlx = this.tlx;
    		var tly = this.tly;
    		var v0x = trx - tlx;
    		
    		var v0y = try_ - tly;
    		var v1x = brx - tlx;
    		var v1y = bry - tly;
    		var v2x = x - tlx;
    		var v2y = y - tly;
    
    		var dot00 = v0x * v0x + v0y * v0y;
    		var dot01 = v0x * v1x + v0y * v1y;
    		var dot02 = v0x * v2x + v0y * v2y;
    		var dot11 = v1x * v1x + v1y * v1y;
    		var dot12 = v1x * v2x + v1y * v2y;
    
    		var invDenom = 1.0 / (dot00 * dot11 - dot01 * dot01);
    		var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
    		var v = (dot00 * dot12 - dot01 * dot02) * invDenom;
    				
    		if ((u >= 0.0) && (v > 0.0) && (u + v < 1))
    		{
    			return true;
    		}
    						
    		v0x = blx - tlx;
    		v0y = bly - tly;
    
    		dot00 = v0x * v0x + v0y * v0y;
    		dot01 = v0x * v1x + v0y * v1y;
    		dot02 = v0x * v2x + v0y * v2y;
    
    		invDenom = 1.0 / (dot00 * dot11 - dot01 * dot01);
    		u = (dot11 * dot02 - dot01 * dot12) * invDenom;
    		v = (dot00 * dot12 - dot01 * dot02) * invDenom;
    
    						// Point is in second triangle
    		return (u >= 0.0) && (v > 0.0) && (u + v < 1);
    	};[/code:ysujrfy2]
    
    so i've wanted to upgrade this, and after checking manual and doing some work of my own, i've noticed that every quad is split into 2 triangles and then the point is checked in each, if found in first return true, else check other and return true if there or it's false.  it's being done with some mad math. 
    so i went to see what is the most performant way to do it, and here's what i got:
    
    [code:ysujrfy2]		if((((this.try_ - this.tly) * (x - this.tlx) - (this.trx - this.tlx) * (y - this.tly)) | ((this.bry - this.try_) * (x - this.trx) - (this.brx - this.trx) * (y - this.try_)) | ((this.tly - this.bry) * (x - this.brx) - (this.tlx - this.brx) * (y - this.bry))) >= 0)
    					{
    						return true;
    					}
    				    if(!compareResult)
    					{
    						if((((this.bry - this.tly) * (x-this.tlx) - (this.brx - this.tlx) * (y - this.tly)) | ((this.bly - this.bry) * (x - this.brx) - (this.blx - this.brx) * (y- this.bry)) | ((this.tly - this.bly) * (x - this.blx) - (this.tlx - this.blx) * (y - this.bly))) >= 0)
    						{
    							return true;
    						}
    						else
    						{
    							return false;
    						}
    					}[/code:ysujrfy2]
    this code does the same. takes the first 3 points (tl, tr, br) and 2nd  3 points (tl,br,bl) and checks if in those triangles the point is in. and really this works way faster and in my testing examples gives the same results. here's a link to "performance difference" which is almost double. 
    [url=http://imgur.com/GPFfzbe]http://imgur.com/GPFfzbe[/url]
    
    so where's the problem, i've put this function instead of the original and what happened is that in my game that i was testing it with happend this - the bombs sometimes fly through the objects and sometimes explode on the objects (they should explode every time they hit the object). now there is probably something different which i can't get through what and i was wondering if @Ashley you could take a look into it. you could gain some performance in collisions if this is optimized and people would be gratefull. it's not much but it will help. funny thing is that when i go from right side to left side bombs hit well, but form the left side to right side they "miss". like something is wrongly / badly calculated. do variables change in realtime in quads? that might be possibly a problem. 
    
    p.s. - here are articles i've been using to "improve" solution
    [url=http://jsfiddle.net/z7x0udf7/3/]http://jsfiddle.net/z7x0udf7/3/[/url]
    [url=http://stackoverflow.com/questions/2049582/how-to-determine-a-point-in-a-2d-triangle]http://stackoverflow.com/questions/2049 ... d-triangle[/url]  (last answer is JS) 
    
    i'm off to optimize some more and some other things.. i'll be back <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">
    
    p.p.s.  pls check 4 posts behind @Ashley about those assert statements that leave junk in code.
  • it can't. if it's a server side turn based game, server works only as much as players (1 per current turn) pushes data up on server.

    unless you have a huuuuuge amount of players at the same time, then you're pretty much ok. if you do have ~1000 or more players pushing data onto server at the same time (ending their turn) this could slow things down. still you would have to do this - make asycn calls to database so they are queued up for processing, and since servers can easily process ~1000 connections at once, they will be processed in a matter of minute / two /etc.. other players wait until they have the turn. it can take that minute two or more since they don't know when really the other player is done, and through pings on database you should check turns.

    also if someone DC-s, make it a permanent DC and make sure when it's that players turn, to automatically skip it.