Пример #1
0
//writes out an uncompressed RGB .tga file
//if we got really spiffy, we could optionally link in libpng or something, and use that.
void write_bmp(char *savename,int w,int h,unsigned char *buf)
{
	PHYSFS_file* TGAFile;
	TGA_header TGA;
	GLbyte HeightH,HeightL,WidthH,WidthL;
	unsigned int pixel;
	unsigned char *rgbaBuf;

	buf = (unsigned char*)d_calloc(w*h*4,sizeof(unsigned char));

	rgbaBuf = (unsigned char*) d_calloc(w * h * 4, sizeof(unsigned char));
	glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, rgbaBuf);
	for(pixel = 0; pixel < w * h; pixel++) {
		*(buf + pixel * 3) = *(rgbaBuf + pixel * 4 + 2);
		*(buf + pixel * 3 + 1) = *(rgbaBuf + pixel * 4 + 1);
		*(buf + pixel * 3 + 2) = *(rgbaBuf + pixel * 4);
	}
	d_free(rgbaBuf);

	if (!(TGAFile = PHYSFSX_openWriteBuffered(savename)))
	{
		con_printf(CON_URGENT,"Could not create TGA file to dump screenshot!");
		d_free(buf);
		return;
	}

	HeightH = (GLbyte)(h / 256);
	HeightL = (GLbyte)(h % 256);
	WidthH  = (GLbyte)(w / 256);
	WidthL  = (GLbyte)(w % 256);
	// Write TGA Header
	TGA.TGAheader[0] = 0;
	TGA.TGAheader[1] = 0;
	TGA.TGAheader[2] = 2;
	TGA.TGAheader[3] = 0;
	TGA.TGAheader[4] = 0;
	TGA.TGAheader[5] = 0;
	TGA.TGAheader[6] = 0;
	TGA.TGAheader[7] = 0;
	TGA.TGAheader[8] = 0;
	TGA.TGAheader[9] = 0;
	TGA.TGAheader[10] = 0;
	TGA.TGAheader[11] = 0;
	TGA.header[0] = (GLbyte) WidthL;
	TGA.header[1] = (GLbyte) WidthH;
	TGA.header[2] = (GLbyte) HeightL;
	TGA.header[3] = (GLbyte) HeightH;
	TGA.header[4] = (GLbyte) 24;
	TGA.header[5] = 0;
	PHYSFS_write(TGAFile,&TGA,sizeof(TGA_header),1);
	PHYSFS_write(TGAFile,buf,w*h*3*sizeof(unsigned char),1);
	PHYSFS_close(TGAFile);
	d_free(buf);
}
Пример #2
0
struct d_world *
d_world_generate (struct d_world_gen_params *params) {
	struct d_world *world = d_calloc (1, sizeof (struct d_world));

	/* Generate the heightmap using a fractal algorithm.
	   This heightmap is then used to build the tiles needed
	   for the surface. */
	world->hm = d_heightmap_new (params->size);
	d_fractal_heightmap_generate (world->hm, 123, 10000.f, 0.9f);

	/* Retreive highest and lowest point of the world. */
	int high, low;
	d_heightmap_get_highlow (world->hm, &high, &low);

	/* Create a world that is capable of low - 50 -> high + 50 tiles. */
	world->width = params->size;
	world->height = params->size;
	world->depth = fabs (low - 50) + fabs (high + 50);
	world->ocean = fabs (low - 50);

	/* int m = fmax (world->depth, fmax (world->width, world->height)); */
	world->tree = d_world_gen_hm_to_tiles (world->hm);

	return world;
}
Пример #3
0
struct s_chart *f_chart_new(struct s_chart *supplied) {
	struct s_chart *result = supplied;
	if (!result)
		if (!(result = (struct s_chart *) d_calloc(sizeof(struct s_chart), 1)))
			d_die(d_error_malloc);
	if (result->plane)
		gtk_widget_destroy(result->plane);
	if ((result->plane = gtk_drawing_area_new()))
		g_signal_connect(G_OBJECT(result->plane), "expose-event", G_CALLBACK(p_chart_callback), result);
	else
		d_die(d_error_malloc);
	return result;
}
Пример #4
0
/**
 * @brief SDSMemoryNode::reciveMns
 * @param mns
 */
void SDSMemoryNode::reciveMns(char * message){

    cout<<message<<endl;
    Document doc;
    doc.ParseInsitu(message);
   if(doc.IsObject()){
       if(doc.HasMember("protocolo")){
           if(doc["protocolo"].IsString()){
               string comando;
               comando=doc["protocolo"].GetString();
               if(comando=="d_calloc"){
                 if(doc.HasMember("pSize")){
                 if(doc["pSize"].IsInt()){
                 int pSize= doc["pSize"].GetInt();
                 d_calloc(pSize);
                 }
                 }
               }


               else if(comando=="d_status"){
                   d_status();

               }
               else{
                  d_pointer_size pointerSize;
                  if(doc.HasMember("dir")){
                  if(doc["dir"].IsInt()){
                   int pDir= doc["dir"].GetInt();
                   pointerSize.pointer.dirMemory=pDir;

}
                   }
                   if(doc.HasMember("pSize")){
                   if(doc["pSize"].IsInt()){
                   int pSize= doc["pSize"].GetInt();
                   pointerSize.bytes=pSize;
}
                   }


                   if(comando=="d_free"){

                        d_free(pointerSize);
                    }
                   else{

//Documento para en caso de que se quiera obtener el dato
                       StringBuffer s;
                       Writer<StringBuffer> writer(s);
                       writer.StartObject();
                       writer.String("dato");


                     int status;
                     bystream statusBystream;
                      if(doc.HasMember("tipo")){
                      if(doc["tipo"].IsString()){
                      string tipo= doc["tipo"].GetString();

                           if(tipo=="char"){

                                 if(comando=="d_set"){
                                      if(doc.HasMember("dato")){
                                          if(doc["dato"].IsString()){
                                         //Parsear a char

                                           char pData =*(const_cast<char *>(doc["dato"].GetString()));
                                           status= Manejador.setearDatoChar(pointerSize,pData);
                                          }
                                      }

                                 }
                                if(comando=="d_get"){
                                    statusBystream=Manejador.obtenerDatoChar(pointerSize);
                                    writer.String(&(statusBystream.datachar));


                                 }


                           }
                           else if(tipo=="int"){

                                if(comando=="d_set"){
                                    if(doc.HasMember("dato")){
                                    if(doc["dato"].IsInt()){
                                     //Parsear a int
                                     int pData =doc["dato"].GetInt();
                                     status= Manejador.setearDatoInt(pointerSize,pData);
                                    }
                                    }
                                }
                               if(comando=="d_get"){

                                   statusBystream=Manejador.obtenerDatoInt(pointerSize);
                                   writer.Int(statusBystream.dataint);

                                }


                           }
                           else if(tipo=="bool"){
                       //Parsear a bool
                                 //status= Manejador.setearDatoBool(pointerSize,pData);
                           }
                           else if(tipo=="float"){
                       //parsear a float
                                // status= Manejador.setearDatoFloat(pointerSize,pData);

                           }
                           else if(tipo=="arrayint"){
                       //parsear a arreglo de int
                                // status= Manejador.setearDatoArrayInt(pointerSize,pData);
                           }
                           else if(tipo=="arraychar"){
                       //Parsear a arreglos de char
                                 //status= Manejador.setearDatoArrayChar(pointerSize,pData);
                           }
                           else if(tipo=="long"){
                       //Parsear a long
                                // status= Manejador.setearDatoLong(pointerSize,pData);
                           }
                           else if(tipo=="double"){
                       //Parsear a double
                                // status= Manejador.setearDatoDouble(pointerSize,pData);
                           }
                           if(comando=="d_set"){
                              d_set(status);

                           }
                          if(comando=="d_get"){
                              writer.String("status");
                              writer.Int(statusBystream.status);
                              writer.EndObject();
                              const char* mensaje=s.GetString();
                              cout<<"Enviando... "<<mensaje<<endl;
                              puerto->sentMns(mensaje,client);

                           }


                      }}



                   }



               }
           }


       }

   }



}