delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/06/26/17:06:53

From: "nicolas.gasnier" <nicolas DOT gasnier AT wanadoo DOT fr>
Newsgroups: comp.os.msdos.djgpp
Subject: file reading problem
Date: Sat, 26 Jun 1999 14:45:09 +0200
Organization: Wanadoo, l'internet avec France Telecom
Lines: 90
Message-ID: <7l2hlq$g3k$1@wanadoo.fr>
NNTP-Posting-Host: tntorl12-163.abo.wanadoo.fr
X-Trace: wanadoo.fr 930400762 16500 164.138.14.163 (26 Jun 1999 12:39:22 GMT)
X-Complaints-To: abuse AT wanadoo DOT fr
NNTP-Posting-Date: 26 Jun 1999 12:39:22 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi.

I'm actually working on a doom-style 3d engine, but I'm having a problem
loading the maps I do with my editor.
My structures are correctly allocated with the 'new' operator, but when
I try to load a map, it don't load the size I've given to the 'read'
function,  and the loaded data are almost always  garbages instead of the
expected datas. Thinking it is a problem with 'new', I tried with malloc,
but there is always the same problem. I don't understand what happens, since
I'm sure all is ok in my program. Note that I uses allegro with my program.
Please help me before I become silly !!

Here is my initialisation code and load/save procedures :

#define MaxWalls 8192
#define MaxSectors 1024
#define MaxSprites 4096

Sector_T  *Sectors=NULL ;
Wall_T    *Walls=NULL ;
Sprite_T  *Sprites=NULL ;

int NumWall=0,NumSect=0,NumSprite=0 ;

Player_T  Player ;

void InitWalls()
  {
    Walls=new Wall_T[MaxWalls+1] ;
  }

void InitSectors()
  {
    Sectors=new Sector_T[MaxSectors+1] ;
  }


void InitSprites()
  {
    Sprites=new Sprite_T[MaxSprites+1] ;
  }

// for a hack I don't use the first element of the arrays.

void LoadMap(char *FileName)
  {
    int fic ;

    fic=open(FileName,O_RDONLY,0666) ;

    read(fic,&NumWall,sizeof(int)) ;
    read(fic,&NumSect,sizeof(int)) ;
    read(fic,&NumSprite,sizeof(int)) ;
    read(fic,&Player,sizeof(Player_T)) ;
    if (NumWall)
      read(fic,&Walls[1],sizeof(Wall_T)*NumWall) ;
    if (NumSect)
      read(fic,&Sectors[1],sizeof(Sector_T)*NumSect) ;
    if (NumSprite)
      read(fic,&Sprites[1],sizeof(Sprite_T)*NumSprite) ;

    close(fic) ;
  }


void SaveMap(char *FileName)
  {
    int fic ;

    fic=open(FileName,O_WRONLY | O_CREAT,0666) ;

    write(fic,&NumWall,sizeof(int)) ;
    write(fic,&NumSect,sizeof(int)) ;
    write(fic,&NumSprite,sizeof(int)) ;
    write(fic,&Player,sizeof(Player_T)) ;
    if (NumWall)
      write(fic,&Walls[1],sizeof(Wall_T)*NumWall) ;
    if (NumSect)
      write(fic,&Sectors[1],sizeof(Sector_T)*NumSect) ;
    if (NumSprite)
      write(fic,&Sprites[1],sizeof(Sprite_T)*NumSprite) ;

    close(fic) ;

  }





- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019