예제 #1
0
  //Appends a subimage
  void sprite_add_subimage(int sprid, unsigned int w, unsigned int h, unsigned char* chunk, unsigned char* collision_data, collision_type ct)
  {
	unsigned int fullwidth = nlpo2dc(w)+1, fullheight = nlpo2dc(h)+1;
    char *imgpxdata = new char[4*fullwidth*fullheight+1], *imgpxptr = imgpxdata;
    unsigned int rowindex,colindex;
    for (rowindex = 0; rowindex < h; rowindex++)
    {
      for(colindex = 0; colindex < w; colindex++)
      {
        *imgpxptr++ = *chunk++;
        *imgpxptr++ = *chunk++;
        *imgpxptr++ = *chunk++;
        *imgpxptr++ = *chunk++;
      }
      memset(imgpxptr, 0, (fullwidth-colindex) << 2);
      imgpxptr += (fullwidth-colindex) << 2;
    }
    memset(imgpxptr,0,(fullheight-h) * fullwidth);

    unsigned texture = graphics_create_texture(fullwidth,fullheight,imgpxdata,false);

    sprite* sprstr = spritestructarray[sprid];

    sprstr->texturearray.push_back(texture);
    sprstr->texbordxarray.push_back((double) w/fullwidth);
    sprstr->texbordyarray.push_back((double) h/fullheight);
    sprstr->colldata.push_back(get_collision_mask(sprstr,collision_data,ct));
	
	sprstr->subcount += 1;

    delete[] imgpxdata;
  }
예제 #2
0
 //Adds a subimage to an existing sprite from the exe
 void sprite_set_subimage(int sprid, int imgindex, int x,int y, unsigned int w,unsigned int h,unsigned char*chunk)
 {
   unsigned int fullwidth = nlpo2dc(w)+1, fullheight = nlpo2dc(h)+1;
   char *imgpxdata = new char[4*fullwidth*fullheight+1], *imgpxptr = imgpxdata;
   unsigned int rowindex,colindex;
   for (rowindex = 0; rowindex < h; rowindex++)
   {
     for(colindex = 0; colindex < w; colindex++)
     {
       *imgpxptr++ = *chunk++;
       *imgpxptr++ = *chunk++;
       *imgpxptr++ = *chunk++;
       *imgpxptr++ = *chunk++;
     }
     memset(imgpxptr, 0, (fullwidth-colindex) << 2);
     imgpxptr += (fullwidth-colindex) << 2;
   }
   memset(imgpxptr,0,(fullheight-h) * fullwidth);
   
   unsigned texture = graphics_create_texture(fullwidth,fullheight,imgpxdata);
   delete[] imgpxdata;
   
   enigma::sprite* sprstr = enigma::spritestructarray[sprid];
   
   sprstr->texturearray[imgindex] = texture;
   sprstr->colldata[imgindex] = collisionsystem_sprite_data_create(imgpxdata,x,y,w,h);
 }
예제 #3
0
    void sprite_add_to_index(sprite *ns, string filename, int imgnumb, bool transparent, bool smooth, int x_offset, int y_offset)
    {
        int width,height,fullwidth,fullheight;

        char *pxdata = load_bitmap(filename,&width,&height,&fullwidth,&fullheight);
        unsigned texture = graphics_create_texture(fullwidth, fullheight, pxdata);
        delete[] pxdata;

        //ns.pixeldata=(void**) malloc(sizeof(void*));
        //ns.pixeldata[0]=bitmapbuffer;
        ns->id = sprite_idmax;
        ns->subcount  = 1;
        ns->width     = width;
        ns->height    = height;
        ns->xoffset   = (int)x_offset;
        ns->yoffset   = (int)y_offset;
        ns->texturearray = new unsigned int[1];
        ns->texturearray[0] = texture;
        ns->texbordxarray = new double[1];
        ns->texbordxarray[0] = (double) width/fullwidth;
        ns->texbordyarray = new double[1];
        ns->texbordyarray[0] = (double) height/fullheight;
    }
예제 #4
0
  void exe_loadfonts(FILE *exe)
  {
    int nullhere;
	  unsigned fontcount, fntid, twid, thgt, gwid, ghgt;
	  float advance, baseline, origin, gtx, gty, gtx2, gty2;

    if (!fread(&nullhere,4,1,exe)) return;
    if (nullhere != *(int*)"FNT ")
      return;

    if (!fread(&fontcount,4,1,exe)) return;
    if ((int)fontcount != rawfontcount) {
      show_error("Resource data does not match up with game metrics. Unable to improvise.",0);
      return;
    }

	  fontstructarray = (new font*[rawfontmaxid + 2]) + 1;

	  for (int rf = 0; rf < rawfontcount; rf++)
	  {
		  // int unpacked;
		  if (!fread(&fntid, 4,1,exe)) return;
		  if (!fread(&twid, 4,1,exe)) return;
		  if (!fread(&thgt,4,1,exe)) return;
		  const int i = fntid;

		  fontstructarray[i] = new font;

		  fontstructarray[i]->name = rawfontdata[rf].name;
		  fontstructarray[i]->fontname = rawfontdata[rf].fontname;
		  fontstructarray[i]->fontsize = rawfontdata[rf].fontsize;
		  fontstructarray[i]->bold = rawfontdata[rf].bold;
		  fontstructarray[i]->italic = rawfontdata[rf].italic;

		  fontstructarray[i]->glyphstart = rawfontdata[rf].glyphstart;
		  fontstructarray[i]->glyphcount = rawfontdata[rf].glyphcount;

		  fontstructarray[i]->height = 0;

		  fontstructarray[i]->glyphs = new fontglyph[fontstructarray[i]->glyphcount];

		  const unsigned int size = twid*thgt;

		  int* pixels=new int[size+1]; //FYI: This variable was once called "cpixels." When you do compress them, change it back.

		  unsigned int sz2;
		  for (sz2 = 0; !feof(exe) and sz2 < size; sz2++)
		    pixels[sz2] = 0x00FFFFFF | ((unsigned char)fgetc(exe) << 24);

		  if (size!=sz2) {
			  show_error("Failed to load font: Data is truncated before exe end. Read "+toString(sz2)+" out of expected "+toString(size),0);
			  return;
		  }
      if (!fread(&nullhere,4,1,exe)) return;
      if (nullhere != *(int*)"done")
      {
        printf("Unexpected end; eof:%s\n",feof(exe)?"true":"false");
        return;
      }
		  //unpacked = width*height*4;
		  /*unsigned char* pixels=new unsigned char[unpacked+1];
		  if (zlib_decompress(cpixels,size,unpacked,pixels) != unpacked)
		  {
			  show_error("Background load error: Background does not match expected size",0);
			  continue;
		  }
		  delete[] cpixels;*/

		  int ymin=100, ymax=-100;
		  for (int gi = 0; gi < enigma::fontstructarray[i]->glyphcount; gi++)
		  {
		    if (!fread(&advance,4,1,exe)) return;
        if (!fread(&baseline,4,1,exe)) return;
        if (!fread(&origin,4,1,exe)) return;
        if (!fread(&gwid,4,1,exe)) return;
        if (!fread(&ghgt,4,1,exe)) return;
        if (!fread(&gtx,4,1,exe)) return;
        if (!fread(&gty,4,1,exe)) return;
        if (!fread(&gtx2,4,1,exe)) return;
        if (!fread(&gty2,4,1,exe)) return;

        fontstructarray[i]->glyphs[gi].x = int(origin + .5);
        fontstructarray[i]->glyphs[gi].y = int(baseline + .5);
        fontstructarray[i]->glyphs[gi].x2 = int(origin + .5) + gwid;
        fontstructarray[i]->glyphs[gi].y2 = int(baseline + .5) + ghgt;
        fontstructarray[i]->glyphs[gi].tx = gtx;
        fontstructarray[i]->glyphs[gi].ty = gty;
        fontstructarray[i]->glyphs[gi].tx2 = gtx2;
        fontstructarray[i]->glyphs[gi].ty2 = gty2;
        fontstructarray[i]->glyphs[gi].xs = advance + .5;

        if (fontstructarray[i]->glyphs[gi].y < ymin)
          ymin = fontstructarray[i]->glyphs[gi].y;
        if (fontstructarray[i]->glyphs[gi].y2 > ymax)
          ymax = fontstructarray[i]->glyphs[gi].y2;
        //printf("fntid%d, twid%d, thgt%d, advance%f, baseline%f, origin%f, gwid%d, ghgt%d, gtx%f, gty%f, gtx2%f, gty2%f\n", fntid, twid, thgt, advance, baseline, origin, gwid, ghgt, gtx, gty, gtx2, gty2);
		  }
		  fontstructarray[i]->height = ymax - ymin + 2;
		  fontstructarray[i]->yoffset = - ymin + 1;

		  fontstructarray[i]->texture = graphics_create_texture(twid,thgt,pixels);
		  fontstructarray[i]->twid = twid;
		  fontstructarray[i]->thgt = thgt;

      /*int sss = 'A' - fontstructarray[i]->glyphstart;
      fontstructarray[i]->glyphs[sss].x = 0;
      fontstructarray[i]->glyphs[sss].y = 0;
      fontstructarray[i]->glyphs[sss].x2 = twid;
      fontstructarray[i]->glyphs[sss].y2 = thgt;
      fontstructarray[i]->glyphs[sss].tx = 0;
      fontstructarray[i]->glyphs[sss].ty = 0;
      fontstructarray[i]->glyphs[sss].tx2 = 1;
      fontstructarray[i]->glyphs[sss].ty2 = 1;*/

		  delete[] pixels;

      if (!fread(&nullhere,4,1,exe)) return;
      if (nullhere != *(int*)"endf")
        return;
	  }
  }
예제 #5
0
    void sprite_add_to_index(sprite *ns, string filename, int imgnumb, bool precise, bool transparent, bool smooth, int x_offset, int y_offset)
    {
        unsigned int width, height,fullwidth, fullheight;

        unsigned char *pxdata = image_load(filename, &width, &height, &fullwidth, &fullheight);
        
        // If sprite transparent, set the alpha to zero for pixels that should be transparent from lower left pixel color
        if (pxdata && transparent)
        {
          int t_pixel_r = pxdata[(height-1)*width*4]; 
          int t_pixel_g = pxdata[(height-1)*width*4+1]; 
          int t_pixel_b = pxdata[(height-1)*width*4+2];
          unsigned int ih, iw;
          for (ih = 0; ih <= height - 1; ih++)
          {
            int tmp = ih*width*4;
            for (iw=0; iw < width; iw++)
            {
              if (pxdata[tmp] == t_pixel_r && pxdata[tmp+1] == t_pixel_g && pxdata[tmp+2] == t_pixel_b)
                pxdata[tmp+3] = 0;
              
              tmp+=4;
            }
          }
        }
        
        int cellwidth =width/imgnumb;

        ns->id = sprite_idmax;
        ns->subcount  = imgnumb;
        ns->width     = cellwidth;
        ns->height    = height;
        // FIXME: Calculate and assign correct bbox values.
        int bbb = height;
        int bbl = 0;
        int bbt = 0;
        int bbr = cellwidth;
        ns->bbox.bottom  = bbb;
          ns->bbox.left  = bbl;
          ns->bbox.top   = bbt;
          ns->bbox.right = bbr;
        ns->bbox_relative.bottom  = bbb - y_offset;
          ns->bbox_relative.left  = bbl - x_offset;
          ns->bbox_relative.top   = bbt - y_offset;
          ns->bbox_relative.right = bbr - x_offset;
        ns->xoffset   = (int)x_offset;
        ns->yoffset   = (int)y_offset;

        unsigned char* pixels=new unsigned char[cellwidth*height*4]();
        for (int ii=0;ii<imgnumb;ii++) 
        {
                int ih,iw;
                int xcelloffset=ii*cellwidth*4;
                for(ih = height - 1; ih >= 0; ih--)
                {
                        int tmp = ih*fullwidth*4+xcelloffset;
                        int tmpcell = ih*cellwidth*4;
                        for (iw=0; iw < cellwidth; iw++)
                        {
                                pixels[tmpcell+3] = pxdata[tmp+3];
                                pixels[tmpcell+2] = pxdata[tmp+2];
                                pixels[tmpcell+1] = pxdata[tmp+1];
                                pixels[tmpcell] = pxdata[tmp];
                                tmp+=4;
                                tmpcell+=4;
                        }
                }
                unsigned texture = graphics_create_texture(cellwidth, fullheight, pixels, false);
                ns->texturearray.push_back(texture);
                ns->texbordxarray.push_back((double) 1.0);//width/fullwidth;
                ns->texbordyarray.push_back((double) height/fullheight);
				
                collision_type coll_type = precise ? ct_precise : ct_bbox;
                ns->colldata.push_back(get_collision_mask(ns,(unsigned char*)pixels,coll_type));
        }
        delete[] pixels;
        delete[] pxdata;
    }