private void readObject(ObjectInputStream in) throws IOException
	{
		int keys=in.readInt();
		entitiesByDepth=new HashMap<Integer,ArrayList<Entity>>();
		for(int i=0;i<keys;i++)
		{
			int key=in.readInt();
			ArrayList<Entity> entities=new ArrayList<Entity>();
			try
			{
				int size=in.readInt();
				for(int a=0;a<size;a++)
				{
					Entity e=(Entity)in.readObject();
					Entity actual=Entity.entity(e.id());
					actual.move(e.lastX(),e.lastY());
					actual.move(e.x(),e.y());
					actual.imageIndex(e.imageIndex());
					actual.depth(e.lastDepth());
					actual.depth(e.depth());
					actual.offset(e.offset().x,e.offset().y);
					System.out.println("e.mask(): "+e.mask());
					actual.mask(new Area(e.mask()));
					entities.add(actual);
				}
				entitiesByDepth.put(key,entities);
				
			}
			catch(ClassNotFoundException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		keys=in.readInt();
		backgroundLayers=new HashMap<Integer,BufferedImage>();
		for(int i=0;i<keys;i++)
		{
			int key=in.readInt();
			int size=in.readInt();
			byte[] bytebuf=new byte[size];
			int index=0;
			while(index<size)
			{
				try
				{
					bytebuf[index++]=in.readByte();
				}
				catch(EOFException ex)
				{
					throw ex;
				}
			}
			ByteArrayInputStream buffer=new ByteArrayInputStream(bytebuf);
			BufferedImage img=ImageIO.read(buffer);
			backgroundLayers.put(key,img);
		}
		addEntitiesDepthQueue=new ArrayList<Pair<Entity,Pair<Integer,Integer>>>();
	}