summaryrefslogtreecommitdiff
path: root/src/map/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/map.c')
-rw-r--r--src/map/map.c149
1 files changed, 102 insertions, 47 deletions
diff --git a/src/map/map.c b/src/map/map.c
index 83ef75762..f36ef0ccf 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -150,20 +150,9 @@ struct charid2nick {
int req_id;
};
-//�e�}�b�v���Ƃ̍ŏ�������������́AREAD_FROM_BITMAP�p
-/*typedef struct{
- char fn[32];//�t�@�C����
- int xs,ys; //���ƍ���
- int sizeinint;//int�ł̑傫���A1int��32�Z���̏�񂪓��Ă�
- int celltype[MAX_CELL_TYPE];//�}�b�v���Ƃɂ��̃^�C�v�̃Z��������ΑΉ����鐔��������A�Ȃ����1
- //(�^�C�v1���̂��̂�0�Ɠ����z��gat_fileused[0]��
- long pos[MAX_CELL_TYPE];//�r�b�g�}�b�v�t�@�C���ł̏ꏊ�A�ǂݏo�����Ɏg��
-} CELL_INFO;*/
-
-//#define READ_FROM_GAT 0 //gat�t�@�C������
-//#define READ_FROM_BITMAP 1 //�r�b�g�}�b�v�t�@�C������
-int map_read_flag = READ_FROM_GAT;//��̔���t���O,�ǂ������g������map_athana.conf����read_map_from_bitmap�Ŏw��
- //0�Ȃ��READ_FROM_GAT,1�Ȃ��READ_FROM_BITMAP
+int map_read_flag = READ_FROM_GAT;
+// �}�b�v�L���b�V�����p�t���O,�ǂ������g������map_athana.conf����read_map_from_bitmap�Ŏw��
+// 0�Ȃ�Η��p���Ȃ��A1���Ɣ񈳏k�ۑ��A2���ƈ��k���ĕۑ�
int map_getcell(int,int x,int y,CELL_CHK cellchk);
int map_getcellp(struct map_data* m,int x,int y,CELL_CHK cellchk);
@@ -1569,9 +1558,9 @@ static int map_cache_open(char *fn) {
return 1;
}
fclose(map_cache.fp);
- } else {
- map_read_flag = CREATE_BITMAP;
- }
+ } else if (map_read_flag == READ_FROM_BITMAP || map_read_flag == READ_FROM_BITMAP_COMPRESSED)
+ ++map_read_flag; // set to CREATE flag
+
// �ǂݍ��݂Ɏ��s�����̂ŐV�K�ɍ쐬����
map_cache.fp = fopen(fn,"wb");
if(map_cache.fp) {
@@ -1611,10 +1600,8 @@ int map_cache_read(struct map_data *m) {
if(map_cache.map[i].water_height != map_waterheight(m->name)) {
// ����̍������Ⴄ�̂œǂݒ���
return 0;
- } else if(map_cache.map[i].compressed) {
- // ���k�t�@�C���͖��Ή�
- return 0;
- } else {
+ } else if(map_cache.map[i].compressed == 0) {
+ // �񈳏k�t�@�C��
int size = map_cache.map[i].xs * map_cache.map[i].ys;
m->xs = map_cache.map[i].xs;
m->ys = map_cache.map[i].ys;
@@ -1625,12 +1612,36 @@ int map_cache_read(struct map_data *m) {
return 1;
} else {
// �Ȃ����t�@�C���㔼�������Ă�̂œǂݒ���
- m->xs = 0;
- m->ys = 0;
- free(m->gat);
- m->gat = NULL;
+ m->xs = 0; m->ys = 0; m->gat = NULL; free(m->gat);
+ return 0;
+ }
+ } else if(map_cache.map[i].compressed == 1) {
+ // ���k�t���O=1 : zlib
+ unsigned char *buf;
+ unsigned long dest_len;
+ int size_compress = map_cache.map[i].compressed_len;
+ m->xs = map_cache.map[i].xs;
+ m->ys = map_cache.map[i].ys;
+ m->gat = (unsigned char *)aMalloc(m->xs * m->ys * sizeof(unsigned char));
+ buf = (unsigned char*)aMalloc(size_compress);
+ fseek(map_cache.fp,map_cache.map[i].pos,SEEK_SET);
+ if(fread(buf,1,size_compress,map_cache.fp) != size_compress) {
+ // �Ȃ����t�@�C���㔼�������Ă�̂œǂݒ���
+ printf("fread error\n");
+ m->xs = 0; m->ys = 0; m->gat = NULL;
+ free(m->gat); free(buf);
return 0;
}
+ dest_len = m->xs * m->ys;
+ decode_zip(m->gat,&dest_len,buf,size_compress);
+ if(dest_len != map_cache.map[i].xs * map_cache.map[i].ys) {
+ // ����ɉ𓀂��o���ĂȂ�
+ m->xs = 0; m->ys = 0; m->gat = NULL;
+ free(m->gat); free(buf);
+ return 0;
+ }
+ free(buf);
+ return 1;
}
}
}
@@ -1639,29 +1650,52 @@ int map_cache_read(struct map_data *m) {
static int map_cache_write(struct map_data *m) {
int i;
+ unsigned long len_new , len_old;
+ char *write_buf;
if(!map_cache.fp) { return 0; }
for(i = 0;i < map_cache.head.nmaps ; i++) {
if(!strcmp(m->name,map_cache.map[i].fn)) {
// �����G���g���[������Ώ㏑��
- if(
- map_cache.map[i].xs == m->xs && map_cache.map[i].ys == m->ys &&
- !map_cache.map[i].compressed
- ) {
- // ���ƍ��������ň��k���ĂȂ��Ȃ�ꏊ�͕ς��Ȃ�
+ if(map_cache.map[i].compressed == 0) {
+ len_old = map_cache.map[i].xs * map_cache.map[i].ys;
+ } else if(map_cache.map[i].compressed == 1) {
+ len_old = map_cache.map[i].compressed_len;
+ } else {
+ // �T�|�[�g����ĂȂ��`���Ȃ̂Œ����O
+ len_old = 0;
+ }
+ if(map_read_flag >= READ_FROM_BITMAP_COMPRESSED) {
+ // ���k�ۑ�
+ // �������ɂQ�{�ɖc��鎖�͂Ȃ��Ƃ�������
+ write_buf = aMalloc(m->xs * m->ys * 2);
+ len_new = m->xs * m->ys * 2;
+ encode_zip(write_buf,&len_new,m->gat,m->xs * m->ys);
+ map_cache.map[i].compressed = 1;
+ map_cache.map[i].compressed_len = len_new;
+ } else {
+ len_new = m->xs * m->ys;
+ write_buf = m->gat;
+ map_cache.map[i].compressed = 0;
+ map_cache.map[i].compressed_len = 0;
+ }
+ if(len_new <= len_old) {
+ // �T�C�Y���������������Ȃ����̂ŏꏊ�͕ς��Ȃ�
fseek(map_cache.fp,map_cache.map[i].pos,SEEK_SET);
- fwrite(m->gat,m->xs,m->ys,map_cache.fp);
+ fwrite(write_buf,1,len_new,map_cache.fp);
} else {
- // ���ƍ������Ⴄ�Ȃ�V�����ꏊ�ɓo�^
- int size = m->xs * m->ys;
+ // �V�����ꏊ�ɓo�^
fseek(map_cache.fp,map_cache.head.filesize,SEEK_SET);
- fwrite(m->gat,1,size,map_cache.fp);
+ fwrite(write_buf,1,len_new,map_cache.fp);
map_cache.map[i].pos = map_cache.head.filesize;
- map_cache.map[i].xs = m->xs;
- map_cache.map[i].ys = m->ys;
- map_cache.head.filesize += size;
+ map_cache.head.filesize += len_new;
}
+ map_cache.map[i].xs = m->xs;
+ map_cache.map[i].ys = m->ys;
map_cache.map[i].water_height = map_waterheight(m->name);
map_cache.dirty = 1;
+ if(map_read_flag >= READ_FROM_BITMAP_COMPRESSED) {
+ free(write_buf);
+ }
return 0;
}
}
@@ -1669,16 +1703,30 @@ static int map_cache_write(struct map_data *m) {
for(i = 0;i < map_cache.head.nmaps ; i++) {
if(map_cache.map[i].fn[0] == 0) {
// �V�����ꏊ�ɓo�^
- int size = m->xs * m->ys;
+ if(map_read_flag >= READ_FROM_BITMAP_COMPRESSED) {
+ write_buf = aMalloc(m->xs * m->ys * 2);
+ len_new = m->xs * m->ys * 2;
+ encode_zip(write_buf,&len_new,m->gat,m->xs * m->ys);
+ map_cache.map[i].compressed = 1;
+ map_cache.map[i].compressed_len = len_new;
+ } else {
+ len_new = m->xs * m->ys;
+ write_buf = m->gat;
+ map_cache.map[i].compressed = 0;
+ map_cache.map[i].compressed_len = 0;
+ }
strncpy(map_cache.map[i].fn,m->name,sizeof(map_cache.map[0].fn));
fseek(map_cache.fp,map_cache.head.filesize,SEEK_SET);
- fwrite(m->gat,1,size,map_cache.fp);
+ fwrite(write_buf,1,len_new,map_cache.fp);
map_cache.map[i].pos = map_cache.head.filesize;
map_cache.map[i].xs = m->xs;
map_cache.map[i].ys = m->ys;
map_cache.map[i].water_height = map_waterheight(m->name);
- map_cache.head.filesize += size;
+ map_cache.head.filesize += len_new;
map_cache.dirty = 1;
+ if(map_read_flag >= READ_FROM_BITMAP_COMPRESSED) {
+ free(write_buf);
+ }
return 0;
}
}
@@ -1931,13 +1979,14 @@ int map_readallmap(void) {
int map_cache = 0;
// �}�b�v�L���b�V�����J��
- if(map_read_flag == READ_FROM_BITMAP) {
+ if(map_read_flag >= READ_FROM_BITMAP) {
map_cache_open(map_bitmap_filename);
}
sprintf(tmp_output, "Loading Maps%s...\n",
- (map_read_flag == CREATE_BITMAP ? " (Generating Map Cache)" :
- map_read_flag == READ_FROM_BITMAP ? " (w/ Map Cache)" :
+ (map_read_flag == CREATE_BITMAP_COMPRESSED ? " (Generating Map Cache w/ Compression)" :
+ map_read_flag == CREATE_BITMAP ? " (Generating Map Cache)" :
+ map_read_flag >= READ_FROM_BITMAP ? " (w/ Map Cache)" :
map_read_flag == READ_FROM_AFM ? " (w/ AFM)" : ""));
ShowStatus(tmp_output);
@@ -2001,8 +2050,8 @@ int map_readallmap(void) {
ShowInfo(tmp_output);
map_cache_close();
- if(map_read_flag == CREATE_BITMAP) {
- map_read_flag = READ_FROM_BITMAP;
+ if(map_read_flag == CREATE_BITMAP || map_read_flag == CREATE_BITMAP_COMPRESSED) {
+ --map_read_flag;
}
if (maps_removed) {
@@ -2214,10 +2263,14 @@ int map_config_read(char *cfgName) {
} else if (strcmpi(w1, "mapreg_txt") == 0) {
strcpy(mapreg_txt, w2);
}else if(strcmpi(w1,"read_map_from_bitmap")==0){
- if (atoi(w2) == 1)
+ if (atoi(w2) == 2)
+ map_read_flag = READ_FROM_BITMAP_COMPRESSED;
+ else if (atoi(w2) == 1)
map_read_flag = READ_FROM_BITMAP;
else
map_read_flag = READ_FROM_GAT;
+ }else if(strcmpi(w1,"map_bitmap_path")==0){
+ strncpy(map_bitmap_filename,w2,255);
} else if (strcmpi(w1, "import") == 0) {
map_config_read(w2);
} else if (strcmpi(w1, "console") == 0) {
@@ -2408,7 +2461,9 @@ int sql_config_read(char *cfgName)
} else if(strcmpi(w1,"log_db_port")==0) {
log_db_port = atoi(w2);
}else if(strcmpi(w1,"read_map_from_bitmap")==0){
- if (atoi(w2) == 1)
+ if (atoi(w2) == 2)
+ map_read_flag = READ_FROM_BITMAP_COMPRESSED;
+ else if (atoi(w2) == 1)
map_read_flag = READ_FROM_BITMAP;
else
map_read_flag = READ_FROM_GAT;