|
-
Pumpkin Carving 2008
[F8] Coding Techniques - Nest Frame loader?
n. Frame Loader - To spread the work of a Flash application across several frames, instead of forcing the application to complete all the work in a single frame. Prerequisites - No For, For...in, or While loops!
Hey all. I've noticed in the map editor I've made: mapEdit, that if you have to load a couple of maps, the system bogs right down to about 3fps. I've pinpointed this on what's returned from the website; Several 10000-character strings, which are parsed with a while loop and transformed into a usable map array. Unfortunately, I'm already doing a frame loader and waiting for the end of the php script to finish returning all the map data. However, the only way I see to sidestep the insane amount of overhead, is to parse the data via frame loader, instead of a while loop. I am not at home right now, so I am unable to test this, but I think this is a possible solution. Extra help is greatly appreciated.
Code:
// dynamic function
onEnterFrame = function() {
Primary();
}
// first test
function frameLoad() {
if (curX1 < maxX1) {
if(curY1 < maxY1) {
// Our nested frame loader?
if (curX2 < maxX2 and !done) {
if (curY2 < maxY2) {
curY2++;
} else {
curY2 = 0;
curX2++;
}
} else {
done = true;
}
if (done) {
curY1++;
}
} else {
curY1 = 0;
curX1++;
}
} else {
curX1 = curY1 = curX2 = curY2 = 0;
done = false;
Primary = finishUp;
}
}
// Run once everything is completed
function finishUp() {
trace("Finally, we're all done.");
}
// Run at startup to prime frameLoad
function init() {
maxX1 = maxY1 = maxX2 = maxY2 = 50;
curX1 = curY1 = curX2 = curY2 = 0;
done = false;
Primary = frameLoad;
}
// Start
init();
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Pumpkin Carving 2008
Actually I should add... the application for something like this would be loading a map or something along those lines, I find frame loading great for reading 2d arrays smoothly and easily, however, as I wrote above is not my general practice. If you array is 100x20, that is, an array of 100, 20 element arrays, I generally only use an if statement to count through the longer of the two, and a for loop the other way, becuase flash can easily handle a 20 increment for loop each frame. Something like:
Code:
;
arrayW = 20;
arrayH = 100;
currH=0;
//function stub
function someFunc() {
.
.
.
if (currH < arrayH) {
for(i=0; i<arrayW; i++) {
// do w/e here
}
currH++;
}
}
The reason, obviously, is that if you use a nested if (and I'm not saying this is ALWAYS the case; it depends on what your code inside does), you are actually wasiting cpu resources each frame by not using them. Anyhow... yeah if that works in my first post, great. If not, anyone got any pointers?
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
some quick suggestion:
Code:
// dynamic function
onEnterFrame = function() {
Primary();
}
to
Code:
onEnterFrame = Primary;//without the ()
oh so much love flash editors (propably more than games themselves),- looking nice.
I am not sure if I understand propper what you want to cover in your thread,- but it looks like you divide the operations that need to be executed in order to execute only a limited amount each frame interval. I did something similar in the past allowing me to display a progress bar of the complex calculation.
But in the end time wont change and it rather seems that it willl take longer with the advantage knowing how much you progressed so far. Or did you noticed any speed improvements- it´s propably just better balanced with some slightly more time.
-
Pumpkin Carving 2008
Thanks for the kind words. Yeah on my website I mentioned that I have all but stopped development of the actual game, and focused solely on the editor. The good part about this though is that it isn't game specific. As long as I have a tile sheet, I can create a map for the game with a few exceptions (map size, tile size, etc); though I'm considering making it changable (details to be posted on my website). Anyhow, I ran a test, running a single for loop for 10000 elements, and running a nested if/for like above to 10000. While it took significantly longer (some 2-3 seconds longer in fact), the overhead was unwavering, staying between 29-31, where as with the former, there's a major hang, which snaps the frame rate down down to 3 fps for a few frames before going back up. In case I'm in the middle of saving a very important map or something, I don't want the slight hang to result in any flash/browser errors. For sake of ease on the CPU, I think I'll wait a few extra seconds. Also it's not a very common operation that I run, only when the map list on the right is refreshed. Anyhow, I guess it's resolved.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|