예제 #1
0
//
//  Load materials from file
//
static void LoadMaterial(const char* file)
{
   int k=-1;
   char* line;
   char* str;

   //  Open file or return with warning on error
   FILE* f = fopen(file,"r");
   if (!f)
   {
      fprintf(stderr,"Cannot open material file %s\n",file);
      return;
   }

   //  Read lines
   while ((line = readline(f)))
   {
      //  New material
      if ((str = readstr(line,"newmtl")))
      {
         int l = strlen(str);
         //  Allocate memory for structure
         k = Nmtl++;
         mtl = (mtl_t*)realloc(mtl,Nmtl*sizeof(mtl_t));
         //  Store name
         mtl[k].name = (char*)malloc(l+1);
         if (!mtl[k].name) Fatal("Cannot allocate %d for name\n",l+1);
         strcpy(mtl[k].name,str);
         //  Initialize materials
         mtl[k].Ka[0] = mtl[k].Ka[1] = mtl[k].Ka[2] = 0;   mtl[k].Ka[3] = 1;
         mtl[k].Kd[0] = mtl[k].Kd[1] = mtl[k].Kd[2] = 0;   mtl[k].Kd[3] = 1;
         mtl[k].Ks[0] = mtl[k].Ks[1] = mtl[k].Ks[2] = 0;   mtl[k].Ks[3] = 1;
         mtl[k].Ns  = 0;
         mtl[k].d   = 0;
         mtl[k].map = 0;
      }
      //  If no material short circuit here
      else if (k<0)
      {}
      //  Ambient color
      else if (line[0]=='K' && line[1]=='a')
         readfloat(line+2,3,mtl[k].Ka);
      //  Diffuse color
      else if (line[0]=='K' && line[1] == 'd')
         readfloat(line+2,3,mtl[k].Kd);
      //  Specular color
      else if (line[0]=='K' && line[1] == 's')
         readfloat(line+2,3,mtl[k].Ks);
      //  Material Shininess
      else if (line[0]=='N' && line[1]=='s')
         readfloat(line+2,1,&mtl[k].Ns);
      //  Textures (must be BMP - will fail if not)
      else if ((str = readstr(line,"map_Kd"))){
          mtl[k].map = LoadTexBMP(str);
      }
       
      //  Ignore line if we get here
   }
   fclose(f);
}
예제 #2
0
파일: wkm3v.cpp 프로젝트: AdrienTD/wktools
void LoadAnim3(char *fn)
{
	FILE *file; int i, ver, nparts, nverts, form;
	file = fopen(fn, "rb");
	if(!file) fErr("Cannot open file.", -4);
	form = readint(file);
	if(form == 'hseM')		// If file format is .mesh3
	{
		fclose(file);
		LoadMesh3(fn);
		noanim = 1;
		return;
	} else if(form != 'minA')	// If file format in not mesh3 nor anim3
		ferr("Input file is neither an Anim3 file nor a Mesh3 file.");

	noanim = 0;
	readint(file);
	char mshname[512]; i = 0;
	while(mshname[i++] = readchar(file));
	LoadMesh3(mshname);
	animdur = readint(file);
	fseek(file, 16, SEEK_CUR);
	nverts = readint(file);

	for(i = 0; i < 3; i++)
	{
		animcoord[i].nframes = readint(file);
		animcoord[i].ft = new uint[animcoord[i].nframes];
		animcoord[i].verts = new float*[animcoord[i].nframes];
		for(int j = 0; j < animcoord[i].nframes; j++)
			animcoord[i].ft[j] = readint(file);
		for(int j = 0; j < animcoord[i].nframes; j++)
		{
			float *v = animcoord[i].verts[j] = new float[nverts];
			float ftrans = readfloat(file);
			float fscale = readfloat(file);
			for(int k = 0; k < nverts / 3; k++)
			{
				uint w = readint(file);
				for(int l = 0; l < 3; l++)
					*(v++) = (((w>>(l*11))&1023)/1023.0f) * fscale + ftrans;
			}
			if(nverts % 3)
			{
				uint w = readint(file);
				for(int l = 0; l < (nverts%3); l++)
					*(v++) = (((w>>(l*11))&1023)/1023.0f) * fscale + ftrans;
			}
		}
	}
예제 #3
0
파일: emitc.c 프로젝트: Dergash/homm3tools
void
emitconst(void)
{
	assert(scanf("%d\n", &binary) == 1);

	printf("/*\n");
	printf(" * d=%d\n",		d = readint());
	printf(" * n=%d\n",		n = readint());
	printf(" * m=%d\n",		m = readint());
	printf(" * c=%g\n",		readfloat());
	printf(" * maxlen=%d\n",	maxlen = readint());
	printf(" * minklen=%d\n",	minklen = readint());
	printf(" * maxklen=%d\n",	maxklen = readint());
	printf(" * minchar=%d\n",	minchar = readint());
	printf(" * maxchar=%d\n",	maxchar = readint());
	printf(" * loop=%d\n",		loop = readint());
	printf(" * numiter=%d\n",	readint());

	if (readint())
		printf(" * seed=%d\n", readint());
	else
		printf(" * seed=\n", readint());

	printf(" */\n");

	alphasz = compact ? maxchar-minchar+1 : 256;
}
예제 #4
0
void readmatrix(unsigned char **file, unsigned char floatbytes,matrix &m)
{
	m_identity(m);
	for (int x=0;x<=2;x++)
		for (int y=0;y<=3;y++)
			m[x][y]=readfloat(file,floatbytes);
}
예제 #5
0
파일: 10137.c 프로젝트: bhargavakumark/src
int main()
{
	int students;
	long inttotal,share,temp,leftover,diff;
	int i;
	int amount[1000],total;

	while(1)
	{
		scanf("%d",&students);
		//printf("Students : %d",students);
		if(students == 0)
			return 0;
		
		total = 0;
		for(i=0;i<students;i++)
		{
			readfloat(&amount[i]);
			total += amount[i];
		}
		
		total = total ;
		inttotal = (int)(total);
		share = total / students;
	//	printf("Share %ld",share);
		
	//	printf("int total %ld\n",inttotal);
		leftover = inttotal % students;
	
		diff = 0;
		for(i=0;i<students;i++)
		{
			temp = (int)((amount[i])) ;
			//printf("temp %d\n",temp);
			if (temp > share)
			{
//				if(leftover > 0)
//				{
					leftover --;
//					//diff += (temp - share - 1);
//				}
				//else
//					diff += (temp - share);
			}
			else
				diff += (share - temp);
		}
		
		if(leftover > 0)
	 		diff += leftover;
		printf("$%.2f\n",diff*1.0/100);
	}	
	return 0;
}
예제 #6
0
//
//  Read coordinates
//    n is how many coordiantes to read
//    N is the coordinate index
//    M is the number of coordinates
//    x is the array
//    This function adds more memory as needed in 8192 work chunks
//
static void readcoord(char* line,int n,float* x[],int* N,int* M)
{
   //  Allocate memory if necessary
   if (*N+n > *M)
   {
      *M += 8192;
      *x = (float*)realloc(*x,(*M)*sizeof(float));
      if (!*x) Fatal("Cannot allocate memory\n");
   }
   //  Read n coordinates
   readfloat(line,n,(*x)+*N);
   (*N)+=n;
}
예제 #7
0
파일: wkm3v.cpp 프로젝트: AdrienTD/wktools
void LoadMesh3(char *fn)
{
	FILE *file; int i, ver, nparts, nverts, form;
	file = fopen(fn, "rb");
	if(!file) fErr("Cannot open file.", -4);
	form = readint(file);
	if(form != 'hseM')		// If file format in not mesh3
		fErr("Unknown format.", -5);
	ver = readint(file);

	// Attachment Points
	// Can also be attached to another Mesh3/Anim3 or even to particles (.PSystem)
	// At the moment ignored.
	fseek(file, 12, SEEK_SET);
	nparts = readshort(file);
	for(i = 0; i < nparts; i++)
	{
		ignorestr(file);
		fseek(file, 0x1D, SEEK_CUR);
		ignorestr(file);
	}

	// Positions
	nverts = readshort(file);
	lstverts = (float*)malloc(nverts*3*sizeof(float));
	int x = 0;
	fread(lstverts, nverts*3*sizeof(float), 1, file);
	dbg("1");

	// Sphere
	fseek(file, 16, SEEK_CUR);

	// Remapper
	// Only exists if version is 3 (WKO), version 4 (WKBattles) removed it.
	if(ver < 4)
	{
		nremap = (ushort)readshort(file);
		remapper = new uint[nremap];
		for(int i = 0; i < nremap; i++)
			remapper[(ushort)readshort(file)] = i;
			//remapper[i] = (ushort)readshort(file);
	}
	else
	{
		nremap = nverts;
		remapper = new uint[nremap];
		for(int i = 0; i < nremap; i++)
			remapper[i] = i;
	}

	// Normals
	// At the moment they are ignored.
	int nnorm = readshort(file);
	fseek(file, readint(file) * 2, SEEK_CUR);

	// Materials
	// A material consists of 2 things:
	//  - a single byte indicating if alpha test should be enabled (1) or not (0)
	//    on this material
	//  - a string of 8-bit characters ending with byte 0 which is the file name
	//    of the texture located in "Warrior Kings Game Set\Textures\"
	int nmat = readshort(file);
	lstmatflags = (int*)malloc(nmat*sizeof(int));
	lstmattex = (IDirect3DTexture9**)malloc(nmat*sizeof(IDirect3DTexture9*));
	for(i = 0; i < nmat; i++)
	{
		char *s = new char[256]; char *p = s;
		lstmatflags[i] = readchar(file);
		strcpy(s, texdir);
		p = s + strlen(s);
		while(*(p++) = fgetc(file));
		IDirect3DTexture9 *tex;
		if(FAILED(D3DXCreateTextureFromFile(ddev, s, &tex)))
			fErr("Cannot load texture. Be sure you have made the \"Textures\" directory in the directory of the executable and you have copied the textures from the game in that directory. Look at \"readme.txt\" for more details.", -700);
		lstmattex[i] = tex;
		delete [] s;
	}
	dbg("2");

	// Texture coordinates
	// Every UV list contains the same amount of texture coordinates.
	// Each UV list correspond to a player color. For example the UV list #0
	// contains UV vertices that map to brown parts of the texture which correspond
	// to the brown player, #1 corresponds to blue, #2 yellow, #3 red, ...
	// As such, if you want to switch the player color, you simply switch to
	// the corresponding UV list.
	int nuvlist = readint(file);
	lstuvlist = (float**)malloc(nuvlist * sizeof(float*));
	for(int l = 0; l < nuvlist; l++)
	{
		int ntexc = readshort(file);
		float *uvl = (float*)malloc(ntexc * 2 * sizeof(float));
		fread(uvl, ntexc * 2 * sizeof(float), 1, file);
		lstuvlist[l] = uvl;
		muvlist.add(new GrowList<float>);
	}
	dbg("3");

	// Groups
	// A group of a certain number corresponds to the material with the
	// same number. Logically there must be as many groups as materials.
	ngrp = readint(file);
	mgrpindex = (uint*)malloc((ngrp+1) * sizeof(uint));
	mgrpindex[0] = 0;
	for(i = 0; i < ngrp; i++)
	{
		int sg = readshort(file);
		for(int j = 0; j < sg; j++)
		{
			int v = readshort(file);
			iverts.add(v);
			for(int k = 0; k < 3; k++)
				mverts.add(lstverts[v*3+k]);
			readshort(file); // Index to normal list
			v = readshort(file);
			for(int u = 0; u < nuvlist; u++)
				for(int k = 0; k < 2; k++)
					(muvlist[u])->add((lstuvlist[u])[v*2+k]);
		}
		mgrpindex[i+1] = mgrpindex[i]+sg;
	}
	dbg("4");

	// Polygon Lists
	// One used at the moment.
	int ntrilist = readint(file);

	readshort(file); readshort(file); readshort(file); readfloat(file);
	mstartix = (uint*)malloc((nmat + 1) * sizeof(uint));
	mstartix[0] = 0;
	// For every group/material
	for(int n = 0; n < nmat; n++)
	{
		int np = readshort(file);
		readshort(file);
		readshort(file);
		mstartix[n+1] = mstartix[n] + (np * 3);
		// For every triangle (polygon with 3 points)
		for(i = 0; i < np; i++)
			for(int j = 0; j < 3; j++)
				mindices.add(readshort(file)+mgrpindex[n]);
	}

	// Output some debug file.
	//FILE *df = fopen("debug.txt", "w");
	//for(i = 0; i < mindices.len/3; i++)
	//	fprintf(df, "%u %u %u\n", mindices[i*3], mindices[i*3+1], mindices[i*3+2]);
	//for(i = 0; i < mgrpindex.len; i++)
	//	fprintf(df, "%u\n", mgrpindex[i]);
	//for(i = 0; i < mverts.len/3; i++)
	//	fprintf(df, "%f %f %f\n", mverts[i*3], mverts[i*3+1], mverts[i*3+2]);
	//for(i = 0; i < muvlist[0]->len/2; i++)
	//	fprintf(df, "%f %f\n", muvlist[0]->get(i*2), muvlist[0]->get(i*2+1));
	//fclose(df);

	fclose(file);
}
예제 #8
0
파일: hat-check.c 프로젝트: noahl/sombrero
void
nextnode (void)
{
  FileOffset offset = nextoffset;
  char b;
  int marked, err;
  err = fread(&b,sizeof(char),1,f); nextoffset+=1;
  if (err!=1) return;
  if (rmode || xmode) {
    marked = ismarked(b);
    if (marked) {
      cleartag(&b);
      newtagat(&b, offset);
    }
    if (amode) printf("%s", (marked ? "=> " : "   "));
  }
  {
    int k = lo5(b);
    if ((ExpDoStmt<k && k<AtomVariable) || k>ListCons) {
      fprintf(stderr, "strange tag %d at byte offset 0x%x\n",
                      k, offset);
      exit(1);
    } else if (smode) {
      count[k]++;
      if (rmode && marked) reachcount[k]++;
    }
    switch (k) {
    case ListCons:
	if (gmode) printf("%d [label=\"0x%x ListCons\"]\n", offset, offset);
        if (amode) printf("0x%x:  %-20s\t", offset, tag2str(k));
	if (amode) printf("elem=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "e");
	if (amode) printf(" tail=");
        dopointer(MAYBEZERO, ListCons, readpointer(), k, offset, "t");
      break;
    case Module:
      if (amode) {
        if (tracedModule(b))
             printf("0x%x:  Module (suspect) \t", offset);
        else printf("0x%x:  Module (trusted) \t", offset);
      }
      { char *s = readstring(); if (amode) printf("%s\t", s); }
      { char *s = readstring(); if (amode) printf("\"%s\"", s); }
      break;
    case SrcPos:
      if (amode) printf("0x%x:  SrcPos\t\t\t", offset);
      dopointer(NONZERO, Module, readpointer(), k, offset, "");
      { char *p = readposn(); if (amode) printf(" %s", p); }
      break;
    case AtomVariable:
      if (amode) {
        if (localDef(b))
             printf("0x%x:  AtomVariable (local)\t", offset);
        else printf("0x%x:  AtomVariable (toplevel)\t", offset);
      }
      if (gmode) printf("%d [label=\"0x%x AtomVariable", offset, offset);
      dopointer(NONZERO, Module, readpointer(), k, offset, "");
      { char *p = readposn(); if (amode) printf(" %s", p); }
      { char *fp = readfixpri(); if (*fp!='\0' && amode) printf("%s ", fp); }
      { unsigned int a = readarity();
        if (amode || gmode) printf(amode ? " arity=%u," : " %u", a); }
      { char *n = readstring(); if (amode || gmode) printf(" %s", n); }
      if (gmode) printf("\"]\n");
      break;
    case AtomConstructor:
      if (amode) printf("0x%x:  %-20s\t", offset, tag2str(k));
      if (gmode) printf("%d [label=\"0x%x AtomConstructor", offset, offset);
      dopointer(NONZERO, Module, readpointer(), k, offset, "");
      { char *p = readposn(); if (amode) printf(" %s", p); }
      { char *fp = readfixpri(); if (*fp!='\0' && amode) printf("%s", fp); }
      { unsigned int a = readarity();
        if (amode || gmode) printf(amode ? " arity=%u," : " %u", a);
        { char *n = readstring(); if (amode || gmode) printf(" %s", n); }
        if (gmode) printf("\"]\n");
        if hasFields(b) {
	  int i;
          if (amode) printf(" fields:");
          for (i=1; i<=a; i++) {
            dopointer(NONZERO, AtomVariable, readpointer(), k, offset,
	      (gmode ? (sprintf(stringbuf,"%d",i), stringbuf) : "")
	    );
          }
        }
      }
      break;
    case AtomAbstract:
      if (amode) printf("0x%x:  %-20s\t", offset, tag2str(k));
      if (gmode) printf("%d [label=\"0x%x AtomAbstract ", offset, offset);
      { char *s = readstring(); if (amode || gmode) printf("%s", s); }
      if (gmode) printf("\"]\n");
      break;
    default: {
      if (amode) printf("0x%x:  %-20s\t", offset, tag2str(k));
      if (hasSrcPos(b)) {
	  if (amode) printf("use=");
          dopointer(NONZERO, SrcPos, readpointer(), k, offset, "");
	  if (amode) printf(" ");
      }
   // if (amode && (ExpChar <= k) && (k <= ExpConstUse)) {
   //     printf("(");
   //     if (!isEntered(b)) printf("not ");
   //     printf("entered) ");
   // }
      switch (k) {
      case ExpApp:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" fun=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "f");
        if (gmode) printf("%d [label=\"0x%x ExpApp", offset, offset);
        { unsigned int a = readarity();
	  int i;
	  if (amode || gmode)
	    printf(amode ? " arity=%u, args " : " %u\"]\n",a);
	  for (i=1; i<=a; i++)
	    dopointer(NONZERO, ANYEXP, readpointer(), k, offset,
	      (gmode ? (sprintf(stringbuf,"%d",i), stringbuf) : "")
	    );
	}
	break;
      case ExpValueApp:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" fun=");
        dopointer(NONZERO, ANYATOM, readpointer(), k, offset, "f");
        if (gmode) printf("%d [label=\"0x%x ExpValueApp", offset, offset);
        { unsigned int a = readarity();
	  int i;
	  if (amode || gmode)
	    printf(amode ? " arity=%u, args " : " %u\"]\n",a);
	  for (i=1; i<=a; i++)
	    dopointer(NONZERO, ANYEXP, readpointer(), k, offset,
	      (gmode ? (sprintf(stringbuf,"%d",i), stringbuf) : "")
	    );
	}
	break;
      case ExpChar:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { char c = nextbyte();
	  if (gmode) printf("%d [label=\"ExpChar", offset);
	  if (amode || gmode) printf(" '%c'", c);
	  if (gmode) printf("\"]\n");
	}
	break;
      case ExpInt:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { int i; i = readfourbytes();
	  if (gmode) printf("%d [label=\"ExpInt", offset);
	  if (amode || gmode) printf(" %d", i);
	  if (gmode) printf("\"]\n");
	}
	break;
      case ExpInteger:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { char* i; i = readinteger();
	  if (gmode) printf("%d [label=\"ExpInteger", offset);
	  if (amode || gmode) printf(" %s", i);
	  if (gmode) printf("\"]\n");
	}
	break;
      case ExpRat:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { int n,d; n=readfourbytes(); d=readfourbytes();
	  if (gmode) printf("%d [label=\"ExpRat", offset);
          if (amode || gmode) printf(" %d%%%d", n,d);
	  if (gmode) printf("\"]\n");
        }
	break;
      case ExpRational:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { char* r = readrational();
	  if (gmode) printf("%d [label=\"ExpRational", offset);
	  if (amode || gmode) printf(" %s", r);
	  if (gmode) printf("\"]\n");
        }
	break;
      case ExpFloat:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { float f = readfloat();
	  if (gmode) printf("%d [label=\"ExpFloat", offset);
	  if (amode || gmode) printf(" %f", f);
	  if (gmode) printf("\"]\n");
        }
	break;
      case ExpDouble:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
        { double d = readdouble();
	  if (gmode) printf("%d [label=\"ExpDouble", offset);
	  if (amode || gmode) printf(" %f", d);
	  if (gmode) printf("\"]\n");
        }
	break;
      case ExpValueUse:
	if (gmode) printf("%d [label=\"0x%x ExpValueUse\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" value=");
        dopointer(MAYBELAMBDA, ANYATOM, readpointer(), ExpValueUse, offset,"v");
	break;
      case ExpConstUse:
	if (gmode) printf("%d [label=\"0x%x ExpConstUse\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" const=");
        dopointer(NONZERO, ExpConstDef, readpointer(), k, offset, "c");
	break;
      case ExpConstDef:
	if (gmode) printf("%d [label=\"0x%x ExpConstDef\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" var=");
        dopointer(NONZERO, AtomVariable, readpointer(), k, offset, "v");
	break;
      case ExpGuard:
      case ExpCase:
      case ExpIf:
	if (gmode) printf("%d [label=\"0x%x %s\"]\n", offset, offset,
                  k==ExpGuard ? "ExpGuard" : k==ExpCase ? "ExpCase" : "ExpIf");
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" cond=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "c");
	break;
      case ExpFieldUpdate:
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" arg=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "a");
        { unsigned int i, arity = readarity();
	  if (gmode) printf("%d [label=\"0x%x ExpFieldUpdate %u\"]\n", offset, offset, arity);
	  if (amode) printf(" arity=%u, binders ",arity);
          for (i=0; i<arity; i++) {
            dopointer(NONZERO, AtomVariable, readpointer(), k, offset, "");
          }
	  if (amode) printf(", bindees ",arity);
          for (i=0; i<arity; i++) {
            dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "");
          }
        }
	break;
      case ExpProjection:
	if (gmode) printf("%d [label=\"0x%x ExpProjection\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" exp=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "e");
	break;
      case ExpHidden:
	if (gmode) printf("%d [label=\"0x%x ExpHidden\"]\n", offset, offset);
	if (amode) printf("parent=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "p");
	if (amode) printf(" result=");
        dopointer(MAYBEZERO, ANYEXP, readpointer(), k, offset, "r");
	if (amode) printf(" children=");
	dopointer(MAYBEZERO, ListCons, readpointer(), k, offset, "c");
	break;
      case ExpForward:
	if (gmode) printf("%d [label=\"0x%x ExpForward\"]\n", offset, offset);
	if (amode) printf("result=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "r");
	break;
      case ExpDoStmt:
	if (gmode) printf("%d [label=\"0x%x ExpDoStmt\"]\n", offset, offset);
	if (amode) printf("stmt=");
        dopointer(NONZERO, ANYEXP, readpointer(), k, offset, "s");
	break;
      }
    }}
    if (amode) printf("\n");
    if (smode) space[k] += nextoffset - offset;
  }
}
예제 #9
0
void loadprojectfile(unsigned char *file)
{
	unsigned char *f=file;
	scenelist=NULL;
	vector3 xpse;
	float phi;
	char floatbytes=readbyte(&file);
	material *pt;
	texture  *t;

	//////////////// TEXTURE LOAD ////////////////////

	unsigned char texnum=readbyte(&file);
	
	int aa;
	for (aa=1; aa<=texnum; aa++)
	{
		texture *t=new texture;
		inittexture(*t);
		t->ID=readbyte(&file); //texture id
		t->next=texturelist;
		texturelist=t;
		char cmdcnt=readbyte(&file); //command count
		
		for (int x=0;x<cmdcnt;x++)
		{
			texturecommand cmd;
			memcpy(&cmd,file,9);
			file+=9; 
			if (cmd.commandnumber==DD_text)
			{				
				byte bb=readbyte(&file);
				memcpy(t->texts[x].text,file,bb);
				file+=bb; //text
			}
			performcommand(*t,cmd);
			//precalc((float)(aa-1)/(float)(texnum-1)+1.0f/float(texnum)*(float)x/(float)cmdcnt);
			precalc((float)(aa-1)/(float)(texnum)+1.0f/(float)(texnum)*(float)x/(float)cmdcnt);
		}		
	}

	/////////////// MATERIAL LOAD ////////////////////

    texnum=readbyte(&file);

	for (aa=1; aa<=texnum; aa++)
	{
		material *m=new material;
		m->next=materiallist;
		materiallist=m;
		m->texture=readbyte(&file);
		m->layer=readbyte(&file);
		m->alphatexture=readbyte(&file);
		m->alphalayer=readbyte(&file);
		m->alphamode=readbyte(&file);
		m->number=readbyte(&file);
		creatematerial(m);
	}

	byte scenenum=readbyte(&file);

	for (int ar=1; ar<=scenenum; ar++)
	{
		scene *Scene=newscene();
		Scene->number=readbyte(&file);

		/////////////////// ENVIRONMENT LOAD ////////////////////

		Scene->fog=readbyte(&file);
		if (Scene->fog)
		{
			Scene->fogcol[0]=(float)readbyte(&file)/255.0f;
			Scene->fogcol[1]=(float)readbyte(&file)/255.0f;
			Scene->fogcol[2]=(float)readbyte(&file)/255.0f;
			Scene->fogdensity=readfloat(&file,floatbytes);
		}

		int lightnum=readbyte(&file);
		for (int x=0; x<lightnum; x++)
		{
			int ID=readbyte(&file);
			int type=readbyte(&file);
			Scene->lights[x].turnedon=true;
			Scene->lights[x].position[3]=0;
			Scene->lights[x].ambient[0]=(float)readbyte(&file)/255.0f;
			Scene->lights[x].ambient[1]=(float)readbyte(&file)/255.0f;
			Scene->lights[x].ambient[2]=(float)readbyte(&file)/255.0f;
			Scene->lights[x].color[0]=(float)readbyte(&file)/255.0f;
			Scene->lights[x].color[1]=(float)readbyte(&file)/255.0f;
			Scene->lights[x].color[2]=(float)readbyte(&file)/255.0f;
			Scene->lights[x].position[0]=readfloat(&file,floatbytes);
			Scene->lights[x].position[1]=readfloat(&file,floatbytes);
			Scene->lights[x].position[2]=readfloat(&file,floatbytes);
			if (type>=1)
			{			
				Scene->lights[x].position[3]=1;
				Scene->lights[x].c_att=readfloat(&file,floatbytes);
				Scene->lights[x].l_att=readfloat(&file,floatbytes);
				Scene->lights[x].q_att=readfloat(&file,floatbytes);
			}
			if (type==2)
			{
				Scene->lights[x].spot_direction[0]=readfloat(&file,floatbytes);
				Scene->lights[x].spot_direction[1]=readfloat(&file,floatbytes);
				Scene->lights[x].spot_direction[2]=readfloat(&file,floatbytes);
				Scene->lights[x].spot_exponent=readfloat(&file,floatbytes);
				Scene->lights[x].spot_cutoff=readfloat(&file,floatbytes);
			}
			else
				Scene->lights[x].spot_cutoff=180.0;
		}

		/////////////////// OBJECT LOAD /////////////////////

		int objnum=readword(&file);

		for (int aa=1;aa<=objnum;aa++)
		{
			addobject(*Scene);
			tminimalobjdata objdata;
			memcpy(&objdata,file,sizeof(objdata));

			int current=Scene->objectnum-1;

			Scene->objects[current].data=objdata;
			file+=4;
			
			Scene->objects[current].number=readword(&file);
			Scene->objects[current].parent=readword(&file);

			if (objdata.textured || objdata.primitive==aDDict_map)     Scene->objects[current].texture=readbyte(&file); 
			if (objdata.red)          Scene->objects[current].color[0]=(float)readbyte(&file)/255.0f;
			if (objdata.green)        Scene->objects[current].color[1]=(float)readbyte(&file)/255.0f;
			if (objdata.blue)         Scene->objects[current].color[2]=(float)readbyte(&file)/255.0f;
			if (objdata.alpha)        Scene->objects[current].color[3]=(float)readbyte(&file)/255.0f;
			if (objdata.alphamap1set) readbyte(&file); 
			if (objdata.material2set) Scene->objects[current].envmap=readbyte(&file); 
			if (objdata.texxset || objdata.primitive==aDDict_map)      Scene->objects[current].texxscale=readbyte(&file); 
			if (objdata.texyset || objdata.primitive==aDDict_map)      Scene->objects[current].texyscale=readbyte(&file); 
			if (objdata.texoffxset || objdata.primitive==aDDict_map)   Scene->objects[current].texxoffset=readbyte(&file); 
			if (objdata.texoffyset || objdata.primitive==aDDict_map)   Scene->objects[current].texyoffset=readbyte(&file); 

			switch (objdata.primitive)
			{
			case aDDict_grid:
			case aDDict_hasab:
			case aDDict_cone:
			case aDDict_sphere:
				{
					Scene->objects[current].params[0]=readbyte(&file);
					Scene->objects[current].params[1]=readbyte(&file);
					break;
				}
			case aDDict_arc: 
				{
					Scene->objects[current].params[0]=readbyte(&file);
					Scene->objects[current].params[1]=readword(&file);
					break;
				}
			case aDDict_line: 
				{
					Scene->objects[current].params[0]=readbyte(&file);
					break;
				}
			case aDDict_loft: 
				{
					Scene->objects[current].params[0]=readword(&file);
					Scene->objects[current].params[1]=readword(&file);
					Scene->objects[current].params[2]=(int)Scene->objects;
					Scene->objects[current].params[3]=Scene->objectnum;
					break;
				}
			case aDDict_map:
				{
					texnum=readbyte(&file);
					Scene->objects[current].envmap=texnum;
					switch (texnum)
					{
					case 0:
						{
							xpse.x=readfloat(&file,floatbytes);
							xpse.y=readfloat(&file,floatbytes);
							xpse.z=readfloat(&file,floatbytes);
							break;
						}
					case 1:
						{
							xpse.x=readfloat(&file,floatbytes);
							xpse.y=readfloat(&file,floatbytes);
							xpse.z=readfloat(&file,floatbytes);
							break;
						}
					case 2:
						{
							xpse.x=readfloat(&file,floatbytes);
							xpse.y=readfloat(&file,floatbytes);
							xpse.z=readfloat(&file,floatbytes);
							phi=readfloat(&file,floatbytes);
							break;
						}
					}
					pt=findmaterial(Scene->objects[current].texture);
					t=findtexture(pt->texture);
					memcpy(maptexture,t->layers[pt->layer],256*256*4);
				}
			case aDDict_blur:
			case aDDict_linearsubdivision:
			case aDDict_butterfly: 
				{
					if (objdata.primitive!=aDDict_map)
						texnum=readbyte(&file);
					
					Scene->objects[current].params[1]=(int)readselection(&file);
					for (selection *s=(selection*)Scene->objects[current].params[1];s;s=s->next)
					{
						switch (Scene->objects[current].data.primitive)
						{
						case aDDict_map:
							{
								object *o=searchobjectbynumber(Scene->objects,Scene->objectnum,s->selected);
								obj_counttexturecoordinates( o,Scene->objects[current].texxscale,Scene->objects[current].texyscale,
									Scene->objects[current].texxoffset,
									Scene->objects[current].texyoffset,
									!Scene->objects[current].data.swaptexturexy,
									Scene->objects[current].data.inverttexx,
									Scene->objects[current].data.inverttexy);

								switch (Scene->objects[current].envmap)
								{
								case 0:
									{
										matrix s;
										for (int a=0; a<o->vertexnum; a++)
										{
											float p=getmappixel(o->vertices[a].t,Scene->objects[current].data.alphachannel,
												Scene->objects[current].data.normalsinverted);
											m_xpose(p*xpse.x,p*xpse.y,p*xpse.z,s);
											m_xformd(s,o->vertices[a].base,o->vertices[a].d);
										}
										break;
									}
								case 1:
									{
										matrix s;
										for (int a=0; a<o->vertexnum; a++)
										{
											float p=getmappixel(o->vertices[a].t,Scene->objects[current].data.alphachannel,
												Scene->objects[current].data.normalsinverted);
											m_scale(p*(xpse.x-1)+1,p*(xpse.y-1)+1,p*(xpse.z-1)+1,s);
											m_xformd(s,o->vertices[a].base,o->vertices[a].d);
										}									
										break;
									}
								case 2:
									{
										matrix s;
										for (int a=0; a<o->vertexnum; a++)
										{
											float p=getmappixel(o->vertices[a].t,Scene->objects[current].data.alphachannel,
												Scene->objects[current].data.normalsinverted);
											m_rotate(xpse.x,xpse.y,xpse.z,p*phi,s);
											m_xformd(s,o->vertices[a].base,o->vertices[a].d);
										}									
										break;
									}
								}
								for (int x=0; x<o->vertexnum; x++)
								{
									o->vertices[x].base=o->vertices[x].d;
									o->vertices[x].t=o->vertices[x].dt;
								}
								obj_counttexturecoordinates(o, o->texxscale, o->texyscale, o->texxoffset, o->texyoffset, o->data.swaptexturexy, o->data.inverttexx, o->data.inverttexy);
								obj_generatenormals(o);
								obj_transform(o,o->xformmatrix);
								break;
							}
						case aDDict_blur:
						case aDDict_linearsubdivision:
						case aDDict_butterfly: 
							{
								for (selection *s=(selection*)Scene->objects[current].params[1];s;s=s->next)
								{
									object *o=searchobjectbynumber(Scene->objects,Scene->objectnum,s->selected);
									for (int x=0; x<texnum; x++)
									{
										if (objdata.primitive==aDDict_blur) meshblur(o);
										else butterflysubdivision(o,objdata.primitive==aDDict_linearsubdivision);
									}
								}
								break;
							}
						}
					}
					
					break;
				}
			case aDDict_boolean: 
				{
					char function=readbyte(&file);
					int baseobj=readword(&file);
					int brush=readword(&file);
					//object *baseobject=searchobjectbynumber(Scene->objects,Scene->objectnum,baseobj);
					//object *brushobject=searchobjectbynumber(Scene->objects,Scene->objectnum,brush);
					matrix difference;//,m;
					readmatrix(&file, floatbytes, difference);

					//memcpy(m,brushobject->xformmatrix,sizeof(matrix));
					//matrix m2;
					//m_mult(baseobject->xformmatrix,difference,m2);
					//obj_transform(brushobject,m2);
					//obj_boolean(baseobject,brushobject,function);
					//memcpy(brushobject->xformmatrix,m,sizeof(matrix));
					//obj_transform(brushobject,brushobject->xformmatrix);
					break;
				}
			}
			
			if (objdata.primitive==aDDict_hasab) Scene->objects[current].params[2]=readbyte(&file);

			switch (objdata.primitive)
			{
			case aDDict_box:
			case aDDict_icosaeder:
			case aDDict_dodecaeder:
			case aDDict_sphere:
			case aDDict_hasab:
			case aDDict_cone:
			case aDDict_arc:
			case aDDict_loft:
			case aDDict_line:
			case aDDict_grid:
			case aDDict_clone:
				{
					readmatrix(&file, floatbytes, Scene->objects[current].xformmatrix);
					
					if (objdata.primitive==aDDict_clone)
					{
						Scene->objects[current].params[0]=(int)readselection(&file);
						Scene->objects[current].params[1]=(int)Scene->objects;
						Scene->objects[current].params[2]=Scene->objectnum;
					}
					
					obj_createprimitive(&Scene->objects[current],Scene->objects[current].data.primitive,Scene->objects[current].params[0],Scene->objects[current].params[1],Scene->objects[current].params[2],Scene->objects[current].params[3]);
					obj_transform(&Scene->objects[current],Scene->objects[current].xformmatrix);
					if (Scene->objects[current].data.primitive!=aDDict_clone)
					obj_counttexturecoordinates(&Scene->objects[current], Scene->objects[current].texxscale, Scene->objects[current].texyscale, Scene->objects[current].texxoffset, Scene->objects[current].texyoffset, Scene->objects[current].data.swaptexturexy, Scene->objects[current].data.inverttexx, Scene->objects[current].data.inverttexy);
					obj_generatenormals(&Scene->objects[current]);

					for (int x=0; x<Scene->objects[current].polygonnum; x++)
					{

						Scene->objects[current].polygons[x].color.x=Scene->objects[current].color[0];
						Scene->objects[current].polygons[x].color.y=Scene->objects[current].color[1];
						Scene->objects[current].polygons[x].color.z=Scene->objects[current].color[2];
						Scene->objects[current].polygons[x].color.w=Scene->objects[current].color[3];
						if (Scene->objects[current].data.shading!=aDDict_default) Scene->objects[current].polygons[x].shading=Scene->objects[current].data.shading;
					}

					if (Scene->objects[current].data.textured && Scene->objects[current].data.primitive!=aDDict_clone)
					{
						material *m=findmaterial(Scene->objects[current].texture);
						if (m!=NULL)
						for (int x=0; x<Scene->objects[current].polygonnum; x++)
						{
							Scene->objects[current].polygons[x].texturehandle=m->handle;
						}
					}

					if (Scene->objects[current].data.material2set && Scene->objects[current].data.primitive!=aDDict_clone)
					{
						material *m=findmaterial(Scene->objects[current].envmap);
						if (m!=NULL)
						for (int x=0; x<Scene->objects[current].polygonnum; x++)
						{
							Scene->objects[current].polygons[x].envmaphandle=m->handle;
						}
					}
					
					break;
				}
			}
		}

		//////////////////////////// CAMERA LOAD ////////////////////////////////
		//MessageBox( 0, "camload", "HelloWorld", MB_OK );
		
		byte camnum=readbyte(&file);
		for (aa=1; aa<=camnum; aa++)
		{
			camera *c=new camera;
			memset(c,0,sizeof(camera));
			c->next=Scene->cameras;
			Scene->cameras=c;
			c->number=readbyte(&file); //camera ID
			c->up.y=-1;
			byte keyframenum=readbyte(&file);
			if (keyframenum)
			{
				//c->eyex.numkey=keyframenum;
				//c->eyex.keys=new KEY[keyframenum];
				c->eyex=new CTrack(keyframenum);
				c->eyey=new CTrack(keyframenum);
				c->eyez=new CTrack(keyframenum);
				c->trgx=new CTrack(keyframenum);
				c->trgy=new CTrack(keyframenum);
				c->trgz=new CTrack(keyframenum);
				c->fovt=new CTrack(keyframenum);
				c->rollt=new CTrack(keyframenum);

				/*c->eyey.numkey=keyframenum;
				c->eyey.keys=new KEY[keyframenum];
				c->eyez.numkey=keyframenum;
				c->eyez.keys=new KEY[keyframenum];
				c->trgx.numkey=keyframenum;
				c->trgx.keys=new KEY[keyframenum];
				c->trgy.numkey=keyframenum;
				c->trgy.keys=new KEY[keyframenum];
				c->trgz.numkey=keyframenum;
				c->trgz.keys=new KEY[keyframenum];
				c->fovt.numkey=keyframenum;
				c->fovt.keys=new KEY[keyframenum];
				c->rollt.numkey=keyframenum;
				c->rollt.keys=new KEY[keyframenum];*/

				int frame=readword(&file); //frame
				int fov=readbyte(&file); //fov
				int roll=readword(&file); //roll
				float eyex=readfloat(&file,floatbytes); //eyex
				float eyey=readfloat(&file,floatbytes); //eyey
				float eyez=readfloat(&file,floatbytes); //eyez
				float trgx=readfloat(&file,floatbytes); //trgx
				float trgy=readfloat(&file,floatbytes); //trgy
				float trgz=readfloat(&file,floatbytes); //trgz
				setkeydata(c->eyex->keys,frame,eyex);
				setkeydata(c->eyey->keys,frame,eyey);
				setkeydata(c->eyez->keys,frame,eyez);
				setkeydata(c->trgx->keys,frame,trgx);
				setkeydata(c->trgy->keys,frame,trgy);
				setkeydata(c->trgz->keys,frame,trgz);
				setkeydata(c->fovt->keys,frame,(float)fov);
				setkeydata(c->rollt->keys,frame,(float)roll);
				/*c->eyex.keys[0].data=eyex;
				c->eyex.keys[0].frame=frame;
				c->eyey.keys[0].data=eyey;
				c->eyey.keys[0].frame=frame;
				c->eyez.keys[0].data=eyez;
				c->eyez.keys[0].frame=frame;
				c->trgx.keys[0].data=trgx;
				c->trgx.keys[0].frame=frame;
				c->trgy.keys[0].data=trgy;
				c->trgy.keys[0].frame=frame;
				c->trgz.keys[0].data=trgz;
				c->trgz.keys[0].frame=frame;
				c->fovt.keys[0].data=(float)fov;
				c->fovt.keys[0].frame=frame;
				c->rollt.keys[0].data=(float)roll;
				c->rollt.keys[0].frame=frame;*/

				for (int x=1; x<keyframenum; x++)
				{
					frame=readword(&file); //frame

					camfield cf;
					memset(&cf,0,sizeof(cf));
					memcpy(&cf,file,1); //mask
					file+=1;

					if (cf.fovwritten) fov=readbyte(&file);
					if (cf.rollwritten) roll=readword(&file);
					if (cf.eyexwritten) eyex=readfloat(&file,floatbytes);
					if (cf.eyeywritten) eyey=readfloat(&file,floatbytes);
					if (cf.eyezwritten) eyez=readfloat(&file,floatbytes);
					if (cf.targetxwritten) trgx=readfloat(&file,floatbytes);
					if (cf.targetywritten) trgy=readfloat(&file,floatbytes);
					if (cf.targetzwritten) trgz=readfloat(&file,floatbytes);

					/*c->eyex.keys[x].data=eyex;
					c->eyex.keys[x].frame=frame;
					c->eyey.keys[x].data=eyey;
					c->eyey.keys[x].frame=frame;
					c->eyez.keys[x].data=eyez;
					c->eyez.keys[x].frame=frame;
					c->trgx.keys[x].data=trgx;
					c->trgx.keys[x].frame=frame;
					c->trgy.keys[x].data=trgy;
					c->trgy.keys[x].frame=frame;
					c->trgz.keys[x].data=trgz;
					c->trgz.keys[x].frame=frame;
					c->fovt.keys[x].data=(float)fov;
					c->fovt.keys[x].frame=frame;
					c->rollt.keys[x].data=(float)roll;
					c->rollt.keys[x].frame=frame;*/
					
					setkeydata(&c->eyex->keys[x],frame,eyex);
					setkeydata(&c->eyey->keys[x],frame,eyey);
					setkeydata(&c->eyez->keys[x],frame,eyez);
					setkeydata(&c->trgx->keys[x],frame,trgx);
					setkeydata(&c->trgy->keys[x],frame,trgy);
					setkeydata(&c->trgz->keys[x],frame,trgz);
					setkeydata(&c->fovt->keys[x],frame,(float)fov);
					setkeydata(&c->rollt->keys[x],frame,(float)roll);

				}
				c->eyex->InitVectors();
				c->eyey->InitVectors();
				c->eyez->InitVectors();
				c->trgx->InitVectors();
				c->trgy->InitVectors();
				c->trgz->InitVectors();
				c->fovt->InitVectors();
				c->rollt->InitVectors();
			}
		}
		//MessageBox( 0, "objload", "HelloWorld", MB_OK );
		///////////////////////// OBJECT ANIM LOAD /////////////////////////////

		byte animnum=readbyte(&file);
		for (aa=1; aa<=animnum; aa++)
		{
			byte animid=readbyte(&file); //anim ID
			int on;
			for (on=0;on<Scene->objectnum;on++)
			{
				objanim *o=new objanim;
				memset(o,0,sizeof(objanim));
				o->next=Scene->objects[on].anims;
				Scene->objects[on].anims=o;
				o->number=animid;
			}
			for (on=0;on<Scene->objectnum;on++)
				if (Scene->objects[on].data.primitive!=9 && 
					Scene->objects[on].data.primitive!=11 &&
					Scene->objects[on].data.primitive<100)
				{
					byte keyframenum=readbyte(&file);
					Scene->objects[on].anims->posx=new CTrack(keyframenum);
					Scene->objects[on].anims->posy=new CTrack(keyframenum);
					Scene->objects[on].anims->posz=new CTrack(keyframenum);
					Scene->objects[on].anims->rotx=new CTrack(keyframenum);
					Scene->objects[on].anims->roty=new CTrack(keyframenum);
					Scene->objects[on].anims->rotz=new CTrack(keyframenum);
					Scene->objects[on].anims->rota=new CTrack(keyframenum);
					Scene->objects[on].anims->strx=new CTrack(keyframenum);
					Scene->objects[on].anims->stry=new CTrack(keyframenum);
					Scene->objects[on].anims->strz=new CTrack(keyframenum);
					Scene->objects[on].anims->colr=new CTrack(keyframenum);
					Scene->objects[on].anims->colg=new CTrack(keyframenum);
					Scene->objects[on].anims->colb=new CTrack(keyframenum);
					Scene->objects[on].anims->cola=new CTrack(keyframenum);
					if (keyframenum)
					{
						int frame=(unsigned short)readword(&file); //frame

						float posx=readfloat(&file,floatbytes); //posx
						float posy=readfloat(&file,floatbytes); //posy
						float posz=readfloat(&file,floatbytes); //posz

						float rotx=readfloat(&file,floatbytes); //rotx
						float roty=readfloat(&file,floatbytes); //roty
						float rotz=readfloat(&file,floatbytes); //rotz
						int rota=readword(&file); //rota

						float strx=readfloat(&file,floatbytes); //strx
						float stry=readfloat(&file,floatbytes); //stry
						float strz=readfloat(&file,floatbytes); //strz

						float colr=(float)readbyte(&file)/255.0f; //colr
						float colg=(float)readbyte(&file)/255.0f; //colg
						float colb=(float)readbyte(&file)/255.0f; //colb
						float cola=(float)readbyte(&file)/255.0f; //cola

						setkeydata(Scene->objects[on].anims->posx->keys,frame,posx);
						setkeydata(Scene->objects[on].anims->posy->keys,frame,posy);
						setkeydata(Scene->objects[on].anims->posz->keys,frame,posz);
						setkeydata(Scene->objects[on].anims->rotx->keys,frame,rotx);
						setkeydata(Scene->objects[on].anims->roty->keys,frame,roty);
						setkeydata(Scene->objects[on].anims->rotz->keys,frame,rotz);
						setkeydata(Scene->objects[on].anims->rota->keys,frame,(float)rota);
						setkeydata(Scene->objects[on].anims->strx->keys,frame,strx);
						setkeydata(Scene->objects[on].anims->stry->keys,frame,stry);
						setkeydata(Scene->objects[on].anims->strz->keys,frame,strz);
						setkeydata(Scene->objects[on].anims->colr->keys,frame,colr);
						setkeydata(Scene->objects[on].anims->colg->keys,frame,colg);
						setkeydata(Scene->objects[on].anims->colb->keys,frame,colb);
						setkeydata(Scene->objects[on].anims->cola->keys,frame,cola);

						/*Scene->objects[on].anims->posx.keys[0].frame=frame;
						Scene->objects[on].anims->posx.keys[0].data=posx;
						Scene->objects[on].anims->posy.keys[0].frame=frame;
						Scene->objects[on].anims->posy.keys[0].data=posy;
						Scene->objects[on].anims->posz.keys[0].frame=frame;
						Scene->objects[on].anims->posz.keys[0].data=posz;
						Scene->objects[on].anims->rotx.keys[0].frame=frame;
						Scene->objects[on].anims->rotx.keys[0].data=rotx;
						Scene->objects[on].anims->roty.keys[0].frame=frame;
						Scene->objects[on].anims->roty.keys[0].data=roty;
						Scene->objects[on].anims->rotz.keys[0].frame=frame;
						Scene->objects[on].anims->rotz.keys[0].data=rotz;
						Scene->objects[on].anims->rota.keys[0].frame=frame;
						Scene->objects[on].anims->rota.keys[0].data=(float)rota;
						Scene->objects[on].anims->strx.keys[0].frame=frame;
						Scene->objects[on].anims->strx.keys[0].data=strx;
						Scene->objects[on].anims->stry.keys[0].frame=frame;
						Scene->objects[on].anims->stry.keys[0].data=stry;
						Scene->objects[on].anims->strz.keys[0].frame=frame;
						Scene->objects[on].anims->strz.keys[0].data=strz;
						Scene->objects[on].anims->colr.keys[0].frame=frame;
						Scene->objects[on].anims->colr.keys[0].data=colr;
						Scene->objects[on].anims->colg.keys[0].frame=frame;
						Scene->objects[on].anims->colg.keys[0].data=colg;
						Scene->objects[on].anims->colb.keys[0].frame=frame;
						Scene->objects[on].anims->colb.keys[0].data=colb;
						Scene->objects[on].anims->cola.keys[0].frame=frame;
						Scene->objects[on].anims->cola.keys[0].data=cola;*/

						for (int x=1; x<keyframenum; x++)
						{
							frame=readword(&file); //frame

							objfield c;
							memset(&c,0,sizeof(c));
							memcpy(&c,file,2); //mask
							file+=2;

							if (c.posx) posx=readfloat(&file,floatbytes);
							if (c.posy) posy=readfloat(&file,floatbytes);
							if (c.posz) posz=readfloat(&file,floatbytes);

							if (c.rotx) rotx=readfloat(&file,floatbytes);
							if (c.roty) roty=readfloat(&file,floatbytes);
							if (c.rotz) rotz=readfloat(&file,floatbytes);
							if (c.rota) rota=readword(&file);

							if (c.strx) strx=readfloat(&file,floatbytes);
							if (c.stry) stry=readfloat(&file,floatbytes);
							if (c.strz) strz=readfloat(&file,floatbytes);

							if (c.colr) colr=(float)readbyte(&file)/255.f;
							if (c.colg) colg=(float)readbyte(&file)/255.f;
							if (c.colb) colb=(float)readbyte(&file)/255.f;
							if (c.cola) cola=(float)readbyte(&file)/255.f;

							/*Scene->objects[on].anims->posx.keys[x].frame=frame;
							Scene->objects[on].anims->posx.keys[x].data=posx;
							Scene->objects[on].anims->posy.keys[x].frame=frame;
							Scene->objects[on].anims->posy.keys[x].data=posy;
							Scene->objects[on].anims->posz.keys[x].frame=frame;
							Scene->objects[on].anims->posz.keys[x].data=posz;
							Scene->objects[on].anims->rotx.keys[x].frame=frame;
							Scene->objects[on].anims->rotx.keys[x].data=rotx;
							Scene->objects[on].anims->roty.keys[x].frame=frame;
							Scene->objects[on].anims->roty.keys[x].data=roty;
							Scene->objects[on].anims->rotz.keys[x].frame=frame;
							Scene->objects[on].anims->rotz.keys[x].data=rotz;
							Scene->objects[on].anims->rota.keys[x].frame=frame;
							Scene->objects[on].anims->rota.keys[x].data=(float)rota;
							Scene->objects[on].anims->strx.keys[x].frame=frame;
							Scene->objects[on].anims->strx.keys[x].data=strx;
							Scene->objects[on].anims->stry.keys[x].frame=frame;
							Scene->objects[on].anims->stry.keys[x].data=stry;
							Scene->objects[on].anims->strz.keys[x].frame=frame;
							Scene->objects[on].anims->strz.keys[x].data=strz;
							Scene->objects[on].anims->colr.keys[x].frame=frame;
							Scene->objects[on].anims->colr.keys[x].data=colr;
							Scene->objects[on].anims->colg.keys[x].frame=frame;
							Scene->objects[on].anims->colg.keys[x].data=colg;
							Scene->objects[on].anims->colb.keys[x].frame=frame;
							Scene->objects[on].anims->colb.keys[x].data=colb;
							Scene->objects[on].anims->cola.keys[x].frame=frame;
							Scene->objects[on].anims->cola.keys[x].data=cola;*/
						
							setkeydata(&Scene->objects[on].anims->posx->keys[x],frame,posx);
							setkeydata(&Scene->objects[on].anims->posy->keys[x],frame,posy);
							setkeydata(&Scene->objects[on].anims->posz->keys[x],frame,posz);
							setkeydata(&Scene->objects[on].anims->rotx->keys[x],frame,rotx);
							setkeydata(&Scene->objects[on].anims->roty->keys[x],frame,roty);
							setkeydata(&Scene->objects[on].anims->rotz->keys[x],frame,rotz);
							setkeydata(&Scene->objects[on].anims->rota->keys[x],frame,(float)rota);
							setkeydata(&Scene->objects[on].anims->strx->keys[x],frame,strx);
							setkeydata(&Scene->objects[on].anims->stry->keys[x],frame,stry);
							setkeydata(&Scene->objects[on].anims->strz->keys[x],frame,strz);
							setkeydata(&Scene->objects[on].anims->colr->keys[x],frame,colr);
							setkeydata(&Scene->objects[on].anims->colg->keys[x],frame,colg);
							setkeydata(&Scene->objects[on].anims->colb->keys[x],frame,colb);
							setkeydata(&Scene->objects[on].anims->cola->keys[x],frame,cola);
						}

						Scene->objects[on].anims->posx->InitVectors();
						Scene->objects[on].anims->posy->InitVectors();
						Scene->objects[on].anims->posz->InitVectors();
						Scene->objects[on].anims->rotx->InitVectors();
						Scene->objects[on].anims->roty->InitVectors();
						Scene->objects[on].anims->rotz->InitVectors();
						Scene->objects[on].anims->rota->InitVectors();
						Scene->objects[on].anims->strx->InitVectors();
						Scene->objects[on].anims->stry->InitVectors();
						Scene->objects[on].anims->strz->InitVectors();
						Scene->objects[on].anims->colr->InitVectors();
						Scene->objects[on].anims->colg->InitVectors();
						Scene->objects[on].anims->colb->InitVectors();
						Scene->objects[on].anims->cola->InitVectors();
					}
				}
		}

		Scene->next=scenelist;
		scenelist=Scene;
	}

	////////////////////////// EVENT LOAD ///////////////////////////////

	int eventnum=readword(&file);
	for (aa=1; aa<=eventnum; aa++)
	{
		event *e=new event;
		memset(e,0,sizeof(event));
		if (eventlist==NULL)
		{
			eventlist=e;
			lastevent=e;
		}
		else
		{
			lastevent->next=e;
			lastevent=e;
		}

		e->eventtype=readbyte(&file);
		e->startframe=(unsigned short)readword(&file)*10; //startframe
		e->endframe=(unsigned short)readword(&file)*10+9; //endframe
		e->pass=readbyte(&file); //pass
		if (e->eventtype==layer2d || e->eventtype==layer3d || e->eventtype==rendertotext || e->eventtype==feedback || e->eventtype==grideffect)
		{
			e->startrectx1=readword(&file);
			e->startrecty1=readword(&file);
			e->startrectx2=readword(&file);
			e->startrecty2=readword(&file);

			e->endrectx1=readword(&file);
			e->endrecty1=readword(&file);
			e->endrectx2=readword(&file);
			e->endrecty2=readword(&file);
		}
		if (e->eventtype==layer2d || e->eventtype==feedback || e->eventtype==grideffect)
		{
			e->startcol[0]=(float)readbyte(&file)/255.0f;
			e->startcol[1]=(float)readbyte(&file)/255.0f;
			e->startcol[2]=(float)readbyte(&file)/255.0f;
			e->startcol[3]=(float)readbyte(&file)/255.0f;

			e->endcol[0]=(float)readbyte(&file)/255.0f;
			e->endcol[1]=(float)readbyte(&file)/255.0f;
			e->endcol[2]=(float)readbyte(&file)/255.0f;
			e->endcol[3]=(float)readbyte(&file)/255.0f;

			switch (readbyte(&file))
			{
				case  0:e->blendfunc1=GL_ZERO; break;
				case  1:e->blendfunc1=GL_ONE; break;
				case  2:e->blendfunc1=GL_SRC_COLOR; break;
				case  3:e->blendfunc1=GL_ONE_MINUS_SRC_COLOR; break;
				case  4:e->blendfunc1=GL_SRC_ALPHA; break;
				case  5:e->blendfunc1=GL_ONE_MINUS_SRC_ALPHA; break;
				case  6:e->blendfunc1=GL_DST_ALPHA; break;
				case  7:e->blendfunc1=GL_ONE_MINUS_DST_ALPHA; break;
				case  8:e->blendfunc1=GL_DST_COLOR; break;
				case  9:e->blendfunc1=GL_ONE_MINUS_DST_COLOR; break;
				case 10:e->blendfunc1=GL_SRC_ALPHA_SATURATE; break;
			}
			switch (readbyte(&file))
			{
				case  0:e->blendfunc2=GL_ZERO; break;
				case  1:e->blendfunc2=GL_ONE; break;
				case  2:e->blendfunc2=GL_SRC_COLOR; break;
				case  3:e->blendfunc2=GL_ONE_MINUS_SRC_COLOR; break;
				case  4:e->blendfunc2=GL_SRC_ALPHA; break;
				case  5:e->blendfunc2=GL_ONE_MINUS_SRC_ALPHA; break;
				case  6:e->blendfunc2=GL_DST_ALPHA; break;
				case  7:e->blendfunc2=GL_ONE_MINUS_DST_ALPHA; break;
				case  8:e->blendfunc2=GL_DST_COLOR; break;
				case  9:e->blendfunc2=GL_ONE_MINUS_DST_COLOR; break;
				case 10:e->blendfunc2=GL_SRC_ALPHA_SATURATE; break;
			}
		}
		
		switch (e->eventtype)
		{
		case layer2d:
			{
				e->textured=readbyte(&file);
				e->texture=readbyte(&file);
				e->mattexture=findmaterial(e->texture)->handle;
				break;
			}
		case layer3d:
			{
				e->sceneid=readbyte(&file);
				e->camid=readbyte(&file);
				e->animid=readbyte(&file);
				e->camstart=readword(&file);
				e->camend=readword(&file);
				e->animstart=readword(&file);
				e->animend=readword(&file);
				e->iscene=findscene(e->sceneid);
				e->icam=findcam(e->iscene,e->camid);
				e->ianim=e->animid;
				break;
			}
		case cleargl:
			{
				e->clearscreen=readbyte(&file);
				e->clearzbuffer=readbyte(&file);
				break;
			}
		case rendertotext:
			{
				e->texture=readbyte(&file);
				break;
			}
		case feedback:
			{
				e->texture=readbyte(&file);
				e->param1=readbyte(&file);
				e->param4=readfloat(&file,floatbytes);
				break;
			}
		case grideffect:
			{
				e->texture=readbyte(&file);
				e->effect=readbyte(&file);
				e->gridstart=readfloat(&file,floatbytes);
				e->gridend=readfloat(&file,floatbytes);
				break;
			}
		}
	}
}
예제 #10
0
파일: bcm2snr.c 프로젝트: AdrienTD/wktools
int main(int argc, char *argv[])
{
	int i, j, x, z; char fnwoe[384], *e, *minimap, *hmap, **tname; int *tid;
	if(argc < 2) {printf("Usage: bcm2snr \"input.bcm\"\n"); return 0;}
	assert(file = fopen(argv[1], "rb"));

	fseek(file, 12, SEEK_CUR);
	mapw = read32(); maph = read32();

	strcpy(fnwoe, argv[1]);
	e = strrchr(fnwoe, '.');
	if(!e) {e = fnwoe + strlen(fnwoe); *e = '.';}

	strcpy(e, ".snr");
	assert(fsnr = fopen(fnwoe, "w"));
	fprintf(fsnr, "SCENARIO_VERSION 4.00\n");
	fprintf(fsnr, "SCENARIO_DIMENSIONS %u %u\n", mapw, maph);
	fprintf(fsnr, "SCENARIO_EDGE_WIDTH %u\n", read32());
	fprintf(fsnr, "SCENARIO_TEXTURE_DATABASE \""); ReadPrintWString(fsnr);
	fprintf(fsnr, "\"\n");
	strcpy(e, "");
	fprintf(fsnr, "SCENARIO_TERRAIN \"%s.trn\"\n", fnwoe);
	fprintf(fsnr, "SCENARIO_HEIGHTMAP \"%s_heightmap.pcx\"\n", fnwoe);
	fprintf(fsnr, "SCENARIO_HEIGHT_SCALE_FACTOR %f\n", readfloat());
	fprintf(fsnr, "SCENARIO_SUN_COLOUR");
	for(i = 0; i < 3; i++) fprintf(fsnr, " %u", read32());
	fprintf(fsnr, "\n");
	fprintf(fsnr, "SCENARIO_SUN_VECTOR");
	for(i = 0; i < 3; i++) fprintf(fsnr, " %f", readfloat());
	fprintf(fsnr, "\n");
	fprintf(fsnr, "SCENARIO_FOG_COLOUR");
	for(i = 0; i < 3; i++) fprintf(fsnr, " %u", read32());
	fprintf(fsnr, "\n");
	fprintf(fsnr, "SCENARIO_SKY_TEXTURES_DIRECTORY \""); ReadPrintWString(fsnr);
	fprintf(fsnr, "\"\n");
	fprintf(fsnr, "SCENARIO_MINIMAP \"%s_minimap.pcx\"\n", fnwoe);

	strcpy(e, "_minimap.pcx");
	assert(fpcx = fopen(fnwoe, "wb"));
	assert(minimap = (char*)malloc(0xC000));
	fread(minimap, 0xC000, 1, file);
	WritePCXHeader(fpcx, 128, 128, 3);
	WritePCXData(fpcx, minimap, 128, 128, 3);
	fclose(fpcx);
	free(minimap);

	nlakes = readnb(6);
	for(i = 0; i < nlakes; i++)
	{
		fprintf(fsnr, "SCENARIO_LAKE");
		for(j = 0; j < 3; j++) fprintf(fsnr, " %f", readfloat());
		fprintf(fsnr, " 0.0\n");
		readnb(2);
	}

	printf("Number of names: %u\n", nnames = read16());
	assert(tname = (char**)malloc(nnames * sizeof(char*)));
	for(i = 0; i < nnames; i++)
		{tname[i] = (char*)malloc(128); ReadName(tname[i]);}

	printf("Number of IDs: %u\n", nids = read16());
	assert(tid = (int*)malloc(nids * sizeof(int)));
	for(i = 0; i < nids; i++) tid[i] = read32();

	printf("\n------------\n\n");
	ngrpbits = GetMaxBits(nnames); //2;
	nidbits = GetMaxBits(nids); //3;

	strcpy(e, ".trn");
	assert(ftrn = fopen(fnwoe, "w"));
	for(z = maph-1; z >= 0; z--)
	for(x = 0; x < mapw; x++)
	{
		fprintf(ftrn, "X %u Z %u ", x+1, z+1);
		fprintf(ftrn, "GROUP \"%s\" ", tname[readnb(ngrpbits)]);
		fprintf(ftrn, "ID %u ", tid[readnb(nidbits)]);
		fprintf(ftrn, "ROTATION %u ", readnb(2));
		fprintf(ftrn, "XFLIP %u ", readbit());
		fprintf(ftrn, "ZFLIP %u\n", readbit());
	}
	fclose(ftrn);

	printf("End offset: 0x%08X\n", ftell(file));

	printf("\n------------\n\n");

	printf("Num of ?: %u\n", nunk = read32());
	printf("0x62: 0x%X\n", read32());
	for(i = 0; i < nunk; i++)
		{readnb(ngrpbits); readnb(nidbits);}

	assert(hmap = (char*)malloc((mapw+1)*(maph+1)));
	fread(hmap, (mapw+1)*(maph+1), 1, file);
	strcpy(e, "_heightmap.pcx");
	assert(fpcx = fopen(fnwoe, "wb"));
	WritePCXHeader(fpcx, mapw+1, maph+1, 1);
	WritePCXData(fpcx, hmap, mapw+1, maph+1, 1);
	write8(fpcx, 12);
	for(i = 0; i < 256; i++)
		for(j = 0; j < 3; j++)
			write8(fpcx, i);
	fclose(fpcx);
	free(hmap);

	printf("End offset: 0x%08X\n", ftell(file));

	fclose(file);
	fclose(fsnr);
	free(tid);
	for(i = 0; i < nnames; i++) free(tname[i]);
	free(tname);
}
예제 #11
0
파일: load.c 프로젝트: siddick/mruby
static int
read_rite_irep_record(mrb_state *mrb, unsigned char *src, mrb_irep *irep, uint32_t* len)
{
  int i, ret = MRB_DUMP_OK;
  char *buf;
  unsigned char *recordStart, *pStart;
  uint16_t crc, tt, pdl, snl, offset, bufsize=MRB_DUMP_DEFAULT_STR_LEN;
  mrb_int fix_num;
  mrb_float f;
  int ai = mrb_gc_arena_save(mrb);

  recordStart = src;
  buf = mrb_malloc(mrb, bufsize);
  if (buf == NULL) {
    ret = MRB_DUMP_INVALID_IREP;
    goto error_exit;
  }

  //Header Section
  pStart = src;
  if (*src != RITE_IREP_IDENFIFIER)
    return MRB_DUMP_INVALID_IREP;
  src += (sizeof(unsigned char) * 2);
  irep->nlocals = bin_to_uint16(src);       //number of local variable
  src += MRB_DUMP_SIZE_OF_SHORT;
  irep->nregs = bin_to_uint16(src);         //number of register variable
  src += MRB_DUMP_SIZE_OF_SHORT;
  offset = bin_to_uint16(src);              //offset of isec block
  src += MRB_DUMP_SIZE_OF_SHORT;
  crc = calc_crc_16_ccitt(pStart, src - pStart);     //Calculate CRC
  if (crc != bin_to_uint16(src))             //header CRC
    return MRB_DUMP_INVALID_IREP;
  src += offset;

  //Binary Data Section
  //ISEQ BLOCK
  pStart = src;
  irep->ilen = bin_to_uint32(src);          //iseq length
  src += MRB_DUMP_SIZE_OF_LONG;
  if (irep->ilen > 0) {
    if ((irep->iseq = mrb_malloc(mrb, sizeof(mrb_code) * irep->ilen)) == NULL) {
      ret = MRB_DUMP_GENERAL_FAILURE;
      goto error_exit;
    }
    for (i=0; i<irep->ilen; i++) {
      irep->iseq[i] = bin_to_uint32(src);     //iseq
      src += MRB_DUMP_SIZE_OF_LONG;
    }
  }
  crc = calc_crc_16_ccitt((unsigned char*)pStart, src - pStart);     //Calculate CRC
  if (crc != bin_to_uint16(src)) {          //iseq CRC
    ret = MRB_DUMP_INVALID_IREP;
    goto error_exit;
  }
  src += MRB_DUMP_SIZE_OF_SHORT;

  //POOL BLOCK
  pStart = src;
  irep->plen = bin_to_uint32(src);          //pool length
  src += MRB_DUMP_SIZE_OF_LONG;
  if (irep->plen > 0) {
    irep->pool = mrb_malloc(mrb, sizeof(mrb_value) * irep->plen);
    if (irep->pool == NULL) {
      ret = MRB_DUMP_INVALID_IREP;
      goto error_exit;
    }

    for (i=0; i<irep->plen; i++) {
      tt = *src;                              //pool TT
      src += sizeof(unsigned char);
      pdl = bin_to_uint16(src);               //pool data length
      src += MRB_DUMP_SIZE_OF_SHORT;
      if (pdl > bufsize - 1) {
        mrb_free(mrb, buf);
        bufsize = pdl + 1;
        if ((buf = mrb_malloc(mrb, bufsize)) == NULL) {
          ret = MRB_DUMP_GENERAL_FAILURE;
          goto error_exit;
        }
      }
      memcpy(buf, src, pdl);
      src += pdl;
      buf[pdl] = '\0';

      switch (tt) {                           //pool data
      case MRB_TT_FIXNUM:
        fix_num = strtol(buf, NULL, 10);
        irep->pool[i] = mrb_fixnum_value(fix_num);
        break;

      case MRB_TT_FLOAT:
        f = readfloat(buf);
        irep->pool[i] = mrb_float_value(f);
        break;

      case MRB_TT_STRING:
        irep->pool[i] = mrb_str_new(mrb, buf, pdl);
        break;

#ifdef ENABLE_REGEXP
      case MRB_TT_REGEX:
        str = mrb_str_new(mrb, buf, pdl);
        irep->pool[i] = mrb_reg_quote(mrb, str);
        break;
#endif

      default:
        irep->pool[i] = mrb_nil_value();
        break;
      }
    }
  }
  crc = calc_crc_16_ccitt((unsigned char*)pStart, src - pStart);     //Calculate CRC
  if (crc != bin_to_uint16(src)) {          //pool CRC
    ret = MRB_DUMP_INVALID_IREP;
    goto error_exit;
  }
  src += MRB_DUMP_SIZE_OF_SHORT;

  //SYMS BLOCK
  pStart = src;
  irep->slen = bin_to_uint32(src);          //syms length
  src += MRB_DUMP_SIZE_OF_LONG;
  if (irep->slen > 0) {
    if ((irep->syms = mrb_malloc(mrb, sizeof(mrb_sym) * irep->slen)) == NULL) {
      ret = MRB_DUMP_INVALID_IREP;
      goto error_exit;
    }

    memset(irep->syms, 0, sizeof(mrb_sym)*(irep->slen));
    for (i=0; i<irep->slen; i++) {
      snl = bin_to_uint16(src);               //symbol name length
      src += MRB_DUMP_SIZE_OF_SHORT;

      if (snl == MRB_DUMP_NULL_SYM_LEN) {
        irep->syms[i] = 0;
        continue;
      }

      if (snl > bufsize - 1) {
        mrb_free(mrb, buf);
        bufsize = snl + 1;
        if ((buf = mrb_malloc(mrb, bufsize)) == NULL) {
          ret = MRB_DUMP_GENERAL_FAILURE;
          goto error_exit;
        }
      }
      memcpy(buf, src, snl);                  //symbol name
      src += snl;
      buf[snl] = '\0';
      irep->syms[i] = mrb_intern2(mrb, buf, snl);
    }
  }
  crc = calc_crc_16_ccitt((unsigned char*)pStart, src - pStart);     //Calculate CRC
  if (crc != bin_to_uint16(src)) {           //syms CRC
    ret = MRB_DUMP_INVALID_IREP;
    goto error_exit;
  }
  src += MRB_DUMP_SIZE_OF_SHORT;

  *len = src - recordStart;
error_exit:
  mrb_gc_arena_restore(mrb, ai);
  if (buf)
    mrb_free(mrb, buf);

  return ret;
}