saiyadjin's Recent Forum Activity

  • next up, improvement in collision detection:

    http://i.imgur.com/OguZ26n.png

    since i've got a project that achieves around 60 000 collision checks per second, these values seem pretty good for improvement. it changes the section intersect code. i've noticed that it can be further improved by moving the code to gpu, but that's another pair of glasses. in preview i noticed around 3-4% less cpu usage when high collision checks hits in. found in common_prelude.js

    old code:

    // Segment intersection
    	cr.segments_intersect = function(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y)
    	{
    		var max_ax, min_ax, max_ay, min_ay, max_bx, min_bx, max_by, min_by;
    		
    		// Long-hand code since this is a performance hotspot and this type of
    		// code minimises the number of conditional tests necessary.
    		if (a1x < a2x)
    		{
    			min_ax = a1x;
    			max_ax = a2x;
    		}
    		else
    		{
    			min_ax = a2x;
    			max_ax = a1x;
    		}
    		
    		if (b1x < b2x)
    		{
    			min_bx = b1x;
    			max_bx = b2x;
    		}
    		else
    		{
    			min_bx = b2x;
    			max_bx = b1x;
    		}
    		
    		if (max_ax < min_bx || min_ax > max_bx)
    			return false;
    		
    		if (a1y < a2y)
    		{
    			min_ay = a1y;
    			max_ay = a2y;
    		}
    		else
    		{
    			min_ay = a2y;
    			max_ay = a1y;
    		}
    		
    		if (b1y < b2y)
    		{
    			min_by = b1y;
    			max_by = b2y;
    		}
    		else
    		{
    			min_by = b2y;
    			max_by = b1y;
    		}
    		
    		if (max_ay < min_by || min_ay > max_by)
    			return false;
    			
    		var dpx = b1x - a1x + b2x - a2x;
    		var dpy = b1y - a1y + b2y - a2y;
    		var qax = a2x - a1x;
    		var qay = a2y - a1y;
    		var qbx = b2x - b1x;
    		var qby = b2y - b1y;
    
    		var d = cr.abs(qay * qbx - qby * qax);
    		var la = qbx * dpy - qby * dpx;
    		
    		if (cr.abs(la) > d)
    			return false;
    		
    		var lb = qax * dpy - qay * dpx;
    		
    		return cr.abs(lb) <= d;
    	};[/code:2tumiohd]
    
    new code:
    [code:2tumiohd]// Segment intersection	
    	cr.segments_intersect = function (a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
    		
    	var s02_x, s02_y, s10_x, s10_y, s32_x, s32_y, s_numer, t_numer, denom, t;
    	s10_x = a2x - a1x;
    	s10_y = a2y - a1y;
    	s32_x = b2x - b1x;
    	s32_y = b2y - b1y;
        denom = s10_x * s32_y - s32_x * s10_y;
    	
        if (denom == 0)
        {
    		return false;
    	}
    		
        var denomPositive = denom > 0;
        s02_x = a1x - b1x;
        s02_y = a1y - b1y;
        s_numer = s10_x * s02_y - s10_y * s02_x;
    	
        if ((s_numer < 0) == denomPositive)
    	{
            return false; 	
    	}
    	
        t_numer = s32_x * s02_y - s32_y * s02_x;
    	
        if ((t_numer < 0) == denomPositive)
    	{
            return false; 
    	}
    	
        if (((s_numer > denom) == denomPositive) || ((t_numer > denom) == denomPositive))
    	{
            return false; 
        }
    	
        return true;
    	};[/code:2tumiohd]
  • here's a first test i've done.. function "next power of two" - found in common_prelude.js

    results here:

    http://i.imgur.com/HCpm6ne.png

    old code:

    cr.nextHighestPowerOfTwo = function (x) {
    	    --x;
    	    for (var i = 1; i < 32; i <<= 1) {
    	        x = x | x >> i;
    	    }
    	    return x + 1;
    	};[/code:d6luuvun]
    
    new code:
    [code:d6luuvun]	cr.nextHighestPowerOfTwo = function (x) {
    
    		x--;
    		x |= x >> 1;
    		x |= x >> 2;
    		x |= x >> 4;
    		x |= x >> 8;
    		x |= x >> 16;
    		return x+1;
    	};[/code:d6luuvun]
  • i'd go with 720p still. resolution really doesn't matter much, and 720p is a solid resolution for upscaling to 1920x1080 and lowering to less reses. like 640x360 and more. here's a chart for it: https://en.wikipedia.org/wiki/720p#/med ... dards2.svg

    but beware . if you make your game 720p, when different resolution is used your sprites might deform. therefore you should test your game on 720p and 1080p and 320p devices to see the differences.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • i'd stay with 720p.

  • this won't work.

    since you set sub events - they will fire the same tick / next, and attacks animation won't end for let's say - 2.3 sec, and you don't know if it will hit, how long it flies and stuff. depends what kind of attack it is - melee or range?

    the solution is next:

    add local variable to attack named "didHit" with value 0.

    when you activate the hit with some key (for example space) - set the animation on and wait till it ends. if it collided somewhere set didHit = 1.

    once the animation ends - check if didHit is = 1, if it's 0 - kill player, otherwise don't do anything.

    now this applies good for melee attacks, but what if you want a range projectile to check if it collided? add the same variable to the fired projectile.

    on destroyed check if didHit is 0, if it is kill player, if not then nothing. ofcourse you will have to check if projectile collided and have a way to "terminate" projectile on miss... for example - starts with speed 400 and deceleration 100, after ~6seconds it will stop - therefore you destroy it when it reaches speed 0, which will trigger checking didHit. and ofcourse if collision happend you destroy it in that moment it hits (and set didHit to 1ofc)

  • ok, since i've cleaned most of the stuff i'll start in a few days with optimizations and microopts, hopefully these are taken care of if nothing at least i've done it for my pleasure, regardless if ashley finds them usefull / useless.

  • i've noticed another "bug", while c2runtime.js is being created, i'll have to display that in images. but first things first - here's all JS's cleaned in exporters/html folder.

    tested on my big project, works ok.

    here's the DL:

    https://dl.dropboxusercontent.com/u/136 ... rFiles.rar

    still though i've tried exporting empty project and i noticed there is still some problems and i've found out which ones:

    if you open c2runtime.js and find this line (1485):

    RenderCell_.prototype.isEmpty = function ()
    	{
    		if (!this.objects.length)
    		{
    ;
    ;
    			return true;
    		}
    		if (this.objects.length > this.pending_removal.count())
    			return false;
    ;
    		this.flush_pending();		// takes fast path and just resets state
    		return true;
    	};[/code:38s3eehs]
    
    as you can notice there are some ";" appearing randomly inside that code which is very very wierd. it happens because the following code which is found in common_prelude.js has some "assert2" statements that are on export translated to ";" instead to empty space:
    
    [code:38s3eehs]RenderCell_.prototype.isEmpty = function ()
    	{
    		// 'Empty' state is a little non-trivial since there is the set of objects pending_removal
    		// to take in to consideration. First of all if objects is empty then we know the cell is empty.
    		if (!this.objects.length)
    		{
    			assert2(this.pending_removal.isEmpty(), "expected empty pending removal list");
    			assert2(!this.any_pending_removal, "expected no pending removal state");
    			return true;
    		}
    		
    		// 'objects' is not empty. However if there are fewer instances in the removal queue, then
    		// even if we called flush_pending we know there would still be instances left.
    		// So we can safely indicate that the cell is not empty.
    		if (this.objects.length > this.pending_removal.count())
    			return false;
    		
    		// Otherwise every item in objects must be in the pending removal set.
    		// The set will be empty if we update it. Use this opportunity to clear the state
    		// and indicate empty.
    		assert2(this.objects.length === this.pending_removal.count(), "expected pending queue to be same size as object list");
    		this.flush_pending();		// takes fast path and just resets state
    		return true;
    	};[/code:38s3eehs]
    
    as you all know, to minimize size, comments are removed, and assert2  statements are removed, which leave a semicolon in their place for no obvious reason. since this happens in runtime while exporting i can't fix that one, this one is on Ashley <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">
  • i agree with blackhornet. seems like the easiest way to control what each instance does.

  • glerikud - i will keep this post updated with everything i do, so stay tuned.

    R0J0hound - true. but some users report that some stuff doesn't work when minimized from c2. therefore those might get fixed.

  • i don't see why following conventions that were written by JSLint and other JS developers shouldn't be followed. even a small semicolon missing can cause errors in execution of code, same as badly written code. i've just used the tool to fix the few missing errors in each JS file you provide.

    if you really don't trust me, just check how much "fight" did they have about one single semicolon on bootstrap, and in the end both jQuery and bootstrap fix'd the error - https://github.com/twbs/bootstrap/issues/3057

    also like i said, i'll post (today or tommorow) cleaned the rest of files, and then i will go do some microoptimizations (maybe i find even some larger ones, we'll see), just don't come then saying "but this small optimization doesn't mean much, so we won't implement it", because in tight performing systems like game engines, each optimization is a bless.

  • maybe, not sure that there is a performance improvement, but following these fixes that JSLint provides makes code more "stable" and less prone to errors. also minification works better when it's clean.

    i was checking code for performance improvements and i'll do that next once i finish this "cleanup". i've spotted some functions and stuff that can be improved, possibly only in microbenchmarks, but lots of micro ~ 1 macro

    i noticed that some statements don't end with ";" for example, which makes compiler compile 2 times the same statement because JS compilers "try" to parse the same thing with / without ";", so if it's missing it's doing a double job. (at least according to guys on stack overflow). still some functions that are long one liners (saw these a lot) and end up with })})})}) are better written }); }); }); just because it provides more stability when compiling and reducing errors.

  • here, i've cleaned the plugins with JSLint (runtime and editme). tested on 3-4 projects and my huge one, everything seems to work normally, didn't have errors before, don't have them now, still might help with minimizing / compiling errors.

    Ashley

    https://dl.dropboxusercontent.com/u/136 ... lugins.rar

    i'll go and finish with JS files in c2/exporters/html

saiyadjin's avatar

saiyadjin

Member since 19 Jul, 2014

Twitter
saiyadjin has 2 followers

Trophy Case

  • 10-Year Club
  • Jupiter Mission Supports Gordon's mission to Jupiter
  • Forum Contributor Made 100 posts in the forums
  • Forum Patron Made 500 posts in the forums
  • Coach One of your tutorials has over 1,000 readers
  • RTFM Read the fabulous manual
  • Email Verified

Progress

16/44
How to earn trophies