Free Hero Mesh

Check-in [17b9aedf92]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Add implementation of loading level index
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 17b9aedf9267afe50532ac0d79817586a9aee780
User & Date: user on 2018-10-23 03:31:01
Other Links: manifest | tags
Context
2018-10-26
06:47
A few minor corrections, including displaying width/height of level in editor and allowing loading levels by index. check-in: 01830be55a user: user tags: trunk
2018-10-23
03:31
Add implementation of loading level index check-in: 17b9aedf92 user: user tags: trunk
03:16
Some more display in the margin in the editor check-in: 31ac1ffcb3 user: user tags: trunk
Changes

Modified main.c from [7611edaf9e] to [d47c90633f].

177
178
179
180
181
182
183












184
185
186
187
188
189
190
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202







+
+
+
+
+
+
+
+
+
+
+
+







  sqlite3_bind_int(st,2,lvl);
  sqlite3_bind_text(st,3,lvl==LUMP_CLASS_DEF?"CLASS.DEF":lvl==LUMP_LEVEL_IDX?"LEVEL.IDX":sol?".SOL":".LVL",-1,SQLITE_STATIC);
  sqlite3_bind_blob64(st,4,data,sz,0);
  while((e=sqlite3_step(st))==SQLITE_ROW);
  if(e!=SQLITE_DONE) fatal("SQL error (%d): %s\n",e,sqlite3_errmsg(userdb));
  sqlite3_finalize(st);
}

static void load_level_index(void) {
  long sz;
  int i;
  unsigned char*data=read_lump(0,LUMP_LEVEL_IDX,&sz,0);
  if(!data) return;
  if(sz>65536) fatal("Too many levels\n");
  level_index=malloc((level_nindex=sz>>1)*sizeof(Uint16));
  if(!level_index) fatal("Allocation failed\n");
  for(i=0;i<level_nindex;i++) level_index[i]=data[i+i]|(data[i+i+1]<<8);
  free(data);
}

const char*load_level(int lvl) {
  // Load level by ID. Returns null pointer if successful, or an error message if it failed.
  long sz=0;
  unsigned char*buf=lvl>=0?read_lump(FIL_LEVEL,lvl,&sz,0):0;
  unsigned char*p=buf;
  unsigned char*end=buf+sz;
294
295
296
297
298
299
300







301
302
303
304
305
306
307
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326







+
+
+
+
+
+
+







      }
    }
  }
  // skip level strings for now
  if(p>end) goto bad1;
  free(buf);
  level_id=lvl;
  level_ord=0;
  if(level_index) {
    for(i=0;i<level_nindex;i++) if(level_index[i]==lvl) {
      level_ord=i+1;
      break;
    }
  }
  return 0;
bad1:
  free(buf);
  return "Corrupted level data";
bad2:
  free(buf);
  return "Object out of bounds";
770
771
772
773
774
775
776

777
778
779
780
781
782
783
784
785
786
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806







+










  load_pictures();
  if(main_options['T']) {
    test_mode();
    return 0;
  }
  init_usercache();
  load_classes();
  load_level_index();
  optionquery[1]=Q_maxObjects;
  max_objects=strtoll(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"",0,0)?:0xFFFF0000L;
  annihilate();
  if(main_options['x']) {
    fprintf(stderr,"Ready for executing SQL statements.\n");
    do_sql_mode();
    return 0;
  }
  for(;;) { if(main_options['e']) run_editor(); else run_game(); }
}