When I .load() a new ANS or BIN file into a frame, does Frame.js just replaceã>all data and redraw every character in the entire frame? Or does it check theã>new data against the old data to see if there are characters it can skipã>repainting?ããOkay, after some testing, I am pretty sure that frame.load() will require every character in the frame to be redrawn.ããI cooked up my own routine to work around this. I set up a frame that serves as a temporary holder. When I'm updating all the tile frames, I no longer .load() the data straight into each tile frame. Instead, I load the tile graphic into the holder frame. Then I iterate over the holder frame and compare each character with the corresponding character in the target tile frame. If they are different, then I .setData() on that character in the tile frame. Once all this is finished, .cycle() the entire screen.ããI wrote some debug code to measure how long each screen redraw was taking. Before my optimizations, the average screen refresh was about 0.67 seconds. After the optimizations, they are down to 0.23 seconds. So it has made a pretty big difference.ããHere's the code if anyone cares:ãã// Get the name of this tile type's BIN fileãvar tileFile = this._map[mY][mX].getFile();ã// empty the tileHolderãthis._tileHolder.invalidate();ã// Load new tile graphic into tile holderãthis._tileHolder.load(js.exec_dir '/tiles/' tileFile, this._mapTileW, this._mapTileH);ã// Iterate over all characters in this frameãfor (var a=0; a<this._mapTileW; a ) {ã for (var b=0; b<this._mapTileH; b ) {ã var newChar = this._tileHolder.getData(a,b);ã var oldChar = this._tiles[x][y].getData(a,b);ã if ( newChar.attr !== oldChar.attr || newChar.ch !== oldChar.ch) {ã this._tiles[x][y].clearData(a,b);ã this._tiles[x][y].setData(a,b,newChar.ch,newChar.attr);ã }ã}ã}ã// mark this tile for updatingãthis._tiles[x][y].cycle();ãã---ã þ Synchronetã
Re: Another Frame.js questionã> By: Kirkman to All on Tue Jun 09 2015 15:29:46ã>ã>How many different kinds of tiles are there? If each is saved as an individualã>.bin or .ans, you might try combining them all into a single spritesheet. Loadã>the entire spritesheet into each 16x16 frame, then scroll the frame toã>different x/y offsets as needed to reveal the desired portion of the largerã>graphic. This would cut out the .load() and .draw() calls, as .cycle() (whichã>I assume is being called regularly on the overall parent frame) should takeã>care of redrawing all child frames as needed.ããI finally got around to trying your suggested tileset approach, and I ran into a a couple roadblocks. Let me explain.ããI'm taking a 132 char x 60 char canvas and dividing it into an 8x3 grid of frames. Each frame holds a 16 char x 16 char tile.ããIn my test code, I'm iterating over each frame and .load()ing my tileset. The tileset is 128x112. I have tried various versions of this tileset, as an ANSI file, a BIN file, with SAUCE or without. No matter what, I always run out of memory.ããAdditionally, when I try to debug the errors, Frame.js is giving the wrong data dimensions for my tileset files. As I said, the tileset is 128x112, but if I call .data_width and .data_height after .load()ing, I get 17x832 for the .ANS version or 129x112 for the BIN.ããI don't *think* I'm asking too much of the system memory-wise, but maybe I'm wrong. If you have a minute could you take a look and tell me if you have any thoughts on the out-of-memory issue, or the wrong data dimensions?ããMy test code is here: https://gist.github.com/Kirkman/0853cad3deaad373f000#file-1tileset-test-jsããThe out-of-memory errors can be seen here (They are slightly different depending on whether you load the ANS or BIN version of the tileset):ãhttps://gist.github.com/Kirkman/0853cad3deaad373f000#file-2errors-txtããThe debugging info is here:ãhttps://gist.github.com/Kirkman/0853cad3deaad373f000#file-3debugging-txtããYou can download the ANS and BIN version of the tileset here:ãhttp://breakintochat.com/files/misc/debug/16x16_tileset.ansãhttp://breakintochat.com/files/misc/debug/16x16_tileset.binãã--Joshãã---ã þ Synchronetã
If you find that you actually need to allow JS modules to use more memory, youã>can bump these values up. On a test BBS, I got around the 'Out of memory'ã>error when running your script by bumping the ContextStack value up to 512Kã>from the default 16K. (That's quite a jump, but then again on my main BBS Iã>have these values set higher, I don't recall by how much.) Some rough mathã>suggests that if every character cell in your 128x112 graphic was occupied, andã>repeated over 24 frames, you might need more than that. The overhead of theã>Frame objects would need to be allowed for as well.ããThanks, I didn't realize these settings were configurable in SBBS. I think I will try to stick to Synch's default settings for memory. ããIt occurs to me that I can combine my frame "re-painting" method with the tilesheet method: Make one invisible "holder" frame that loads the entire tileset at the beginning. Then on each redraw, copy data out of the holder to paint those characters that have changed in the visible frames. By loading only one copy of the tileset, I should have no memory issues, and I'll also get the benefit of no longer constantly loading individual tile BIN files.ãã>I generally use .BIN files for loading into frames. The data_width of 129 inã>this case suggests that something is slightly off (by one) in the way thatã>Frame is reporting this. At a glance, it looks like Frame is adding 1 to thisã>value ... for reasons I do not know. ã>ã>The data_width of 17 for the .ANS file would be a two-part issue. Again,ã>data_width would actually be 16 in this case, which is the width of the frameã>in question. Apparently when loading a .ANS file, Frame wraps the loadedã>content to the width of the frame.ããI thought data_width and _height properties were supposed to be the true dimensions of the loaded image, since you can use offset to scroll that image around in the frame. But, yeah, until that's sorted, I'll stick to BINs.ãã--Joshãã---ã þ Synchronetã
I thought data_width and _height properties were supposed to be the true dimensions of the loaded image, since you can use offset to scroll that image around in the frame. But, yeah, until that's sorted, I'll stick to BINs.
Sysop: | Karloch |
---|---|
Location: | Madrid, Spain |
Users: | 78 |
Nodes: | 8 (0 / 8) |
Uptime: | 61:10:49 |
Calls: | 1,390 |
Calls today: | 1 |
Files: | 17,895 |
D/L today: |
8 files (174K bytes) |
Messages: | 66,273 |