Jump to content

  • Log In with Google      Sign In   
  • Create Account


sliders_alpha

Member Since 14 Apr 2012
Offline Last Active Jul 22 2012 03:07 PM
-----

Posts I've Made

In Topic: Static is evil, supposedly

18 July 2012 - 12:25 AM

why not have that as part of your current sector's information?

because their is 5626 sector in RAM at all time, this would only add 5.626MB but I'm trying to reduce memory usage, every pieces count.


from what I read using statics the way I do it is "ok" since they are all defined as final, and thus never changing
.
public class Global {
//Sector size
public static final int CHUNK_Z = 16;  
public static final int CHUNK_HEIGHT = 256;
public static final int CHUNK_X = 16;  
//nb de display list par chunk
public static final int DL_Y = 16;
//windows parameter
public static final int WINDOW_HEIGHT = 480;
public static final int WINDOW_WIDTH = 640;
public static final int WINDOW_BITPERPIX = 32;
//paths
public static final String ROOT_DIRECTORIE = "C:\\MEngCl\\";
public static final String TEXTURES_PATH = ROOT_DIRECTORIE+"Textures\\";
public static final String WORLD_PATH = ROOT_DIRECTORIE+"World\\";
//display area
public static final short DISPLAY_AREA = 30;
}

thanks for your awnsers ;)

In Topic: java serializable class, really usefull?

06 May 2012 - 09:58 AM

damn, looks like I'll need to do as mojang did and implement a "region" system.

anyway serializable is not bringing anything usefull to the table, good to know.

In Topic: java serializable class, really usefull?

06 May 2012 - 09:25 AM

mmh, I'm not getting result as good as you Antheus with you code (slightly modified for 3D arrays) :


public void storeToDisk(String path) throws IOException{
long time = System.currentTimeMillis();
final RandomAccessFile fs = new RandomAccessFile(path +x+","+z+".txt", "rw");
final ByteBuffer bb = fs.getChannel().map(MapMode.READ_WRITE, 0, (Global.CHUNK_HEIGHT*Global.CHUNK_X*Global.CHUNK_Z)* 2);


for(short yy=0; yy<Global.CHUNK_HEIGHT; yy++){
	 for(short zz=0; zz<Global.CHUNK_Z; zz++){
		  for(short xx=0; xx<Global.CHUNK_X; xx++){
		  bb.putShort(sect[xx][yy][zz]);
		  }
	 }
}
fs.getChannel().force(true);
fs.getFD().sync();
fs.close();
System.out.println("write time : " + (System.currentTimeMillis() - time)+"ms");
Global.totalTime += (System.currentTimeMillis() - time);
}

//with synch

19ms, 16ms, 14ms, 57ms, 77ms, 21ms, 56ms, 15ms, 9ms, 74ms, 10ms, 9ms, 74ms, 18ms, 22ms, 66ms, 31ms, 50ms, 18ms, 49ms, 72ms, 18ms, 16ms, 68ms, 17ms, 23ms, 66ms, 17ms, 23ms, 72ms, 17ms, 17ms, 75ms, 17ms, 17ms, 66ms, total write time : 1308ms

//without synch
24ms, 32ms, 15ms, 57ms, 16ms, 22ms, 56ms, 28ms, 14ms, 75ms, 17ms, 17ms, 48ms, 26ms, 15ms, 66ms, 14ms, 60ms, 15ms, 17ms, 62ms, 28ms, 17ms, 58ms, 16ms, 14ms, 52ms, 29ms, 17ms, 78ms, 14ms, 17ms, 61ms, 15ms, 25ms, 68ms, total write time : 1208ms




Also, yesterday I changed my chunk2text methods, adding some bufferedWriter, it basically takes the same time

public void storeToDisk(String path) throws IOException{
long time = System.currentTimeMillis();

File file = new File(path+x+","+z+".txt");
FileWriter fw = new FileWriter(file);
BufferedWriter out = new BufferedWriter(fw);
for(short yy=0; yy<Global.CHUNK_HEIGHT; yy++){
	 for(short zz=0; zz<Global.CHUNK_Z; zz++){
	 String s = "";
		  for(short xx=0; xx<Global.CHUNK_X; xx++){
		  s += String.valueOf(sect[xx][yy][zz]);
		  s += ",";
		  }
	 out.write(s);
	 }
}
out.close();
System.out.println("write time : " + (System.currentTimeMillis() - time));
Global.totalTime += (System.currentTimeMillis() - time);
}

38ms, 33ms, 29ms, 30ms, 27ms, 28ms, 33ms, 31ms, 28ms, 28ms, 29ms, 33ms, 28ms, 28ms, 31ms, 28ms, 29ms, 32ms, 28ms, 30ms, 31ms, 30ms, 33ms, 30ms, 30ms, 33ms, 29ms, 29ms, 30ms, 28ms, 34ms, 30ms, 32ms, 58ms, 33ms, 31ms, total write time : 1124ms


In Topic: java serializable class, really usefull?

05 May 2012 - 01:44 PM

aaah, I'm not using byte, but short, wich double the size.
futhermore, i'm inserting a "," betwen each value, getting even a bigger file.

It is possible that the OS does the file open asynchronosly, so the actual open call returns immediatly and the cost of it gets tacked onto your writing/reading if it is done immediatly afterwards.



Try doubling the amount of data you write and see how much the time increases.



Amazing, I would never have though about that, your theory is indeed correct,


when doubling the amount of data to write the write time is only increased by 1-2ms.


Therefore the file access time must be about 62ms.



The reading time is far longer because in addition to opening the file I'm also decoding it, getting each value betwen ",".




...

trying your code Antheus =D


In Topic: java serializable class, really usefull?

05 May 2012 - 12:10 PM

the thing is, the world is generated as the player explore (minecraft clone).
if the player only goes toward the east this one file containing everything will be filled with 75% of 0.

Someone else told me that actually using a database such as MySQL could be usefull.
1 column for the coordinates (primary key), 1 column for the data.
Since I only open a session at the beginning of the game I won't lose time like when I need to acces 900 separated text files.

In addition to that I can even uses indexes for equality seach (on the coordinates) to speed those database access.

....
calculating the coordinate is not time consuming since the player position on the sector grid is always being tracked.
a sector contains more information but I'm only storing the data, since the coordinate are stored inside, storing the file with it's coordinate name is also quick.
public class Sector{
	 byte[][][] data;
	 int x,y;
	 int DL;

	 //some methods
}

I also noticed something weird today, using System.currentTimeMillis()
opening a file = 0ms
writing = 65ms
closing = 0 ms
same thing for reading, shouldn't opening the file be time consuming?

PARTNERS