16 reputation
5
bio website
location
age
visits member for 2 years
seen Jun 25 at 20:47

Apr
13
awarded  Popular Question
Sep
26
comment Compressing 2D level data
First of all, thanks for your answer. Unfortunately, due to time constraints, I can't spend more time on this - luckily, as I said in my reply to John, I managed to make it less memory consuming by simply using a 3D array and not creating hundreds of identical objects. That being said, the idea of only keeping one map loaded in memory - as simple as it may be - is actually quite good, though it would require some loading screens when going to another map, but that isn't that bad. I'll see about using that, and in a future project I'll be sure to remember all the tips you gave me here.
Sep
26
awarded  Commentator
Sep
26
comment Compressing 2D level data
As I said in my reply to John's comment, I changed that Map to a 3D array which pretty much solved my problem. It can still be improved quite a lot, but due to time constraints, I must move forward and try to finish this. In a future project, though, I'll pay more attention to this kind of stuff. Thanks for the answer anyway.
Sep
1
comment Efficient way to render tile-based map in Java
@Byte56 I did some research but wasn't able to find this specific topic you posted amid all the results I got, but there was no clear answer to my specific problem there. Even so, if this is a duplicate, I'm sorry.
Aug
31
awarded  Scholar
Aug
31
accepted Efficient way to render tile-based map in Java
Aug
31
comment Efficient way to render tile-based map in Java
I can't say this project is near it's end, but it MUST be complete in about 3 months because it's a school project and can't be delayed at all. But I installed YourKit and I can't say how thankfull I am to you. I said that the problem probably was at g2d.drawImage but I wasn't sure exactly why. Turns out that each call of tile.getImage() would go through a huge tileset and cut the part corresponding to the tile. By simply adding a HashMap containing the tiles that were previously draw, the CPU usage now is about 17%. I just hope this wont use too much memory - probably not. Thanks!
Aug
31
comment Efficient way to render tile-based map in Java
It's not really slow - I have a solid 60fps which is all I need - it's just using too much CPU compared to other games I have here. I do know that if I remove the g2d.drawImage the CPU usage here falls from 35% to 15% which is what I would like to have all the time. I haven't had a chance to test this on slower computers - my friend and partner in this project have a computer with the same processor as mine - but I do believe that the frames may drop. I'll look into this YourKit you talk about and see if I can use it - never had too much luck with profiling tools.
Aug
30
comment Efficient way to render tile-based map in Java
By "only render the top tile" do you mean the top layer? If so, then that's not really an option because some tiles are not fully opaque and show the tiles below. About this "sprite batching" I'm not doing it and it's actually the first time I've ever heard of it. I'm going to look into it and see if I can use it, but I'm not really sure it will work since if I were to draw all the tiles of the same type at once I would have to loop through the same layer a couple of times and not just once.
Aug
30
comment Efficient way to render tile-based map in Java
@Byte56 I'm worried I might in computers slower than mine
Aug
30
awarded  Student
Aug
30
asked Efficient way to render tile-based map in Java
Jul
26
comment Compressing 2D level data
I'm doing something like that now, but instead of having the ids in the array, I just make the position point back to a specific tile (which is pretty much the same, I believe).
Jul
26
comment Compressing 2D level data
@John After reviewing my code, I found a place where I was creating hundreds of identical objects, which was using a lot of memory. After fixing that and switching to a 3D array, the memory usage was halved. I was thinking of trying out using 1D arrays, but for some reason that seems to end up using more memory, so for now I'll just use the 3D array. Thanks for the tips.
Jul
25
comment Compressing 2D level data
@John The 2D array stores HashMaps that stores integers that are the ids of tiles. But I've run some tests in the last hour and it seems that even though a 2D array of HashMaps uses less memory than a 3D array of integers at first, once I populate it, the 3D array seems much better. So most likely I was just being dumb, using tons of HashMaps. I'll try to adapt the code to use a 3D array of integers (something like int[columns][rows][layers]) and see if it's any better.
Jul
25
revised Compressing 2D level data
added 2 characters in body
Jul
25
comment Compressing 2D level data
@John what I'm currently using is a 2D array - edited the original post with more info on that. Maybe you (or anyone else) can suggest something better? I would really appreciate.
Jul
25
awarded  Editor
Jul
25
revised Compressing 2D level data
added 259 characters in body