error de compilacion sobre la sentencia pointer

Started by l1nk3rn3l, March 26, 2009, 06:15:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

l1nk3rn3l

//////////////////////////////////////////////////////////////////////
//                                                                  //
//  Routines to realize the use of sprite fonts                     //
//                                    by Quiest                     //
//                                                                  //
//                                                                  //
//  Usage:                                                          //
//  ------                                                          //
//  Make your own fonts and store them in a seperate FPG.           //
//  Look below for a list of what number every symbol,letter,       //
//  etc., should have in the font FPG.                              //
//                                                                  //
//  Then just copy&paste the processes to your code and use         //
//  like this:                                                      //
//                                                                  //
//////////////////////////////////////////////////////////////////////
/**
* QLOAD_FONT(string fileName, int fixed)
*
* string fileName             .fpg file containing the font
* int fixed                   0 -> variable width font 1 -> fixed width font
*
*
* QDELETE_TEXT(int id_value)
*
* int id_value              ID value of the text to delete
*
*
* QMOVE_TEXT(int id_value,int x,int y,int center)
*
* int id_value                ID of the text to move
* int x                       horizontal coordinate to move the text to
* int y                       vertical coordinate to move the text to
*
*
* QWRITE(int qfont,int x,int y,int center,string qvar)
*
* int qfont                   font number as returned by [qload_font]
* int x                       horizontal coordinate to write the text to
* int y                       vertical coordinate to write the text to
* int center                  centering value, analog to the one in [write]
* string qvar                 text to write
*
*
* QWRITE_INT(int qfont,int x,int y,int center,int pointer qvar)
*
* int qfont                   Font to write
* int x                       horizontal coordinate to write the text to
* int y                       vertical coordinate to write the text to
* int center                  centering value, analog to the one in [write]
* int pointer qvar            integer to write
*
* Returns the ID of the text, equaling the ID of the process. This is used for [qdelete_text] and [qmove_text]
*
* NOT WORKING DUE TO FENIX ERROR => Mmnemonico no implementado 0x445(opcode taking care of negative floats not implemented in CVS before 12-12-04)
* QWRITE_FLOAT(int qfont,int x,int y,int center,float pointer qvar)
*
* int qfont                   Font to write
* int x                       horizontal coordinate to write the text to
* int y                       vertical coordinate to write the text to
* int center                  centering value, analog to the one in [write]
* float pointer qvar          float to write
*
* Returns the ID of the text, equaling the ID of the process. This is used for [qdelete_text] and [qmove_text]

//////////////////////////////////////////////////////////////////////
//  Notes:                                                          //
//  ------                                                          //
//  *The routines need NOT to be called in a loop to stay on screen.//
//   Usage is exactly the same as with the regular write/write_int/ //
//   write_float functionality.                                     //
//  *I used racemaniacs standart fpg, which is included in the      //
//   zip file, for the included fonts.                              //
//   Note that the font fpgs need to have the same palette as       //
//   the fpgs used for your game.                                   //
//  *Do whatever you want with this prg.                            //
//   If you can optimize it or add more functions to it, do so!     //
//   But please let me know! :-)                                    //
//                                                                  //
//  Additional Notes:                                               //
//  -----------------                                               //
//  Well, I changed pretty much, so usage is now same as you would  //
//  normally use write and it's fella's when it comes to parameters.//
//  Another note, when loading there is new a parameter 'fixed'     //
//  indicating whether or not you want the font to be treated as    //
//  fixed width. When using variable width mind that you include an //
//  empty graphic for space, not doing this results in all words    //
//  glued together. Also, in regards to qwrite_float, this still    //
//  doesn't work because of a Fenix error. An opcode handling       //
//  negative float values was not implemented until 12 december of  //
//  last year, which means that only the latest Fenix release can   //
//  be used for floats. For that reason I have not included an      //
//  example float, it's pretty obvious how it works and this should //
//  keep the prg usable for everyone who still works with old       //
//  versions like myself :). That's about it I think. And of course://
//  Good work Quiest!                                               //
//                                                                  //
//  Moogle                                                          //
//                                                                  //
////////////////////////////////////////////////////////////////////*/
program qwrite_test;

global
   //Font structure
   struct font[10]
     taken;       // whether or not this font index is taken
     fpg;         // fpg in which the font is stored
     width;       // in case of fixed width
     height;      // maximum height of the font
     depth;       // colourdepth
     fixed;       // force fixed width
   end

   //IDs used for the fonts
   font1; font2;

   //IDs used for example texts
   sinText1,sinText2;
   delTexts[10];
   delCursor;

   //texts to use:
   text[10] = "BANG","BOOM","YEAH","WOO","DEL","NO?","QUIEST!","GOODNESS","FOOD","</BR>","GP2X";

   //examples to demonstrate integer and float
   int seconds,minutes,hours;
   float var5=0.99;

private
   i;

begin
   set_mode(320,240,8); //screen init
   set_fps(30,0);       //fps init

   //Load fonts
   font1=qload_font("font1.fpg",1); //loading FPG font
   font2=qload_font("font2.fpg",0); //loading FPG font

   //examples start=============
   sinText1 = qwrite(font2,160,60,4, "Quiests 'qwrite' routines");
   sinText2 = qwrite(font2,160,80,4, "to realize sprite fonts.");

   //write the time:
   qwrite(font2,0,0,0, "Time:");
   qwrite_int(font1,100,0,0,&hours);
   qwrite_int(font1,160,0,0,&minutes);
   qwrite_int(font1,220,0,0,&seconds);
   
   //qwrite_float(font1,200,120,0,&var5);

   //write delText's
   for(i=0;i<10;i++)
     delTexts = qwrite(font2,rand(50,280),rand(100,230),4,text[rand(0,10)]);
   end
   //examples end===============

    loop
      //alternate the integer and float values
      var5 += 0.01;  if(var5 > 1.50) var5 -= 2*var5 ;end

      //Adjust the time
      seconds = time() % 60;
      minutes = time() /60 % 60;
      hours = time() / 60 / 60 % 24;

      //Move a few texts
      angle += 5000;
      qmove_text(sinText1,160+get_distx(angle+180000,30),60);
      qmove_text(sinText2,160+get_distx(angle,30),80);

      //Delete and write one of the 10 texts in delTexts
      delCursor = ++delCursor % 10;
      qdelete_text(delTexts[delCursor]);
      delTexts[delCursor] = qwrite(font2,rand(50,280),rand(100,230),4,text[rand(0,10)]);

      //Quit if necessary
      if(key(_esc))
        exit("",0);
      end

      frame;
    end

  end

/**
* qload_font(string fileName, int fixed)
*
* string fileName             .fpg file containing the font
* int fixed                   0 -> variable width font 1 -> fixed width font
*/
process qload_font(string fileName,int fixed)

private
   i,j,currentFont;

begin

   //find available font index
   while(currentFont < 10 and font[currentFont].taken == 1)
     ++currentFont;
   end
   if(currentFont == 10)return 0;end

   //set taken so the same index won't be used twice
   font[currentFont].taken = 1;

   //if fixed width set that
   if(fixed == 1)
     font[currentFont].fixed = 1;
   end

   //load font file
   font[currentFont].fpg = load_fpg(fileName);


   //keep track of width/height/depth
   for(i=1;i<127;i++)
     if(map_exists(font[currentFont].fpg,i))

       //eventually fix the colourdepth
       if(graphic_info(font[currentFont].fpg,i,G_DEPTH) > font[currentFont].depth)
         font[currentFont].depth = graphic_info(font[currentFont].fpg,i,G_DEPTH);
       end
       //the width(for fixed width fonts)
       if(graphic_info(font[currentFont].fpg,i,G_WIDTH) > font[currentFont].width)
         font[currentFont].width = graphic_info(font[currentFont].fpg,i,G_WIDTH);
       end
       //or the maximum height
       if(graphic_info(font[currentFont].fpg,i,G_HEIGHT) > font[currentFont].height)
         font[currentFont].height = graphic_info(font[currentFont].fpg,i,G_HEIGHT);
       end

     end
   end

   //return the number(index) of the font
   return currentFont;
end

/**
* qdelete_text(int id_value)
*
* int id_value              ID value of the text to delete
*/
process qdelete_text(int id_value)

begin
   //if exists, unload map and delete
   if(exists(id_value))
     unload_map(id_value.file,id_value.graph);
     signal(id_value,S_KILL);
     return 1;
   end

   //if zero, do that for every map
   if(id_value == 0)
     while(id_value = get_id(type qwrite))
       unload_map(id_value.file,id_value.graph);
       signal(id_value,S_KILL);
     end
     while(id_value = get_id(type qwrite_float))
       unload_map(id_value.file,id_value.graph);
       signal(id_value,S_KILL);
     end
     while(id_value = get_id(type qwrite_int))
       unload_map(id_value.file,id_value.graph);
       signal(id_value,S_KILL);
     end
     return 1;
   end//if

   return 0;
end


/**
* qmove_text(int id_value,int x,int y,int center)
*
* int id_value                ID of the text to move
* int x                       horizontal coordinate to move the text to
* int y                       vertical coordinate to move the text to
*/
process qmove_text(int id_value,x,y)

begin

   if(exists(id_value))
     id_value.x = x;
     id_value.y = y;
   end

end


/**
* qwrite(int qfont,int x,int y,int center,string qvar)
*
* int qfont                   font number as returned by [qload_font]
* int x                       horizontal coordinate to write the text to
* int y                       vertical coordinate to write the text to
* int center                  centering value, analog to the one in [write]
* string qvar                 text to write
*/
process qwrite(qfont,x,y,center,string qvar);
private
   int i,j,tempMap,high,wide;
   int xPixels;
begin

   graph = qgenerate_graph(qfont,center,qvar);

   loop
     frame;
   end
end


/**
* qwrite_int(int qfont,int x,int y,int center,int pointer qvar)
*
* int qfont                   Font to write
* int x                       horizontal coordinate to write the text to
* int y                       vertical coordinate to write the text to
* int center                  centering value, analog to the one in [write]
* int pointer qvar            integer to write
*
* Returns the ID of the text, equaling the ID of the process. This is used for [qdelete_text] and [qmove_text]
*/
process qwrite_int(qfont,x,y,center,int pointer qvar)

private
   int qvarValue=0;

begin
   qvarValue = pointer qvar;
   graph = qgenerate_graph(qfont,center,itoa(pointer qvar));
   loop
     if(pointer qvar != qvarValue)
       qvarValue = pointer qvar;
       unload_map(file,graph);
       graph = qgenerate_graph(qfont,center,itoa(pointer qvar));
     end
     frame;
   end

end;


/** NOT WORKING DUE TO FENIX ERROR => Mmnemonico no implementado 0x445(opcode taking care of negative floats not implemented in CVS before 12-12-04)
* qwrite_float(int qfont,int x,int y,int center,float pointer qvar)
*
* int qfont                   Font to write
* int x                       horizontal coordinate to write the text to
* int y                       vertical coordinate to write the text to
* int center                  centering value, analog to the one in [write]
* float pointer qvar          float to write
*
* Returns the ID of the text, equaling the ID of the process. This is used for [qdelete_text] and [qmove_text]
*/
process qwrite_float(qfont,x,y,center,float pointer qvar)

private
   float qvarValue;

begin
   qvarValue = pointer qvar;
   graph = qgenerate_graph(qfont,center,itoa(pointer qvar));
   loop
     if(pointer qvar != qvarValue)
       qvarValue = pointer qvar;
       unload_map(file,graph);
       graph = qgenerate_graph(qfont,center,itoa(pointer qvar));
     end
     frame;
   end

end

/** INTERNAL FUNCTION -> NOT foolproof.
* qgenerate_graph(int qfont,int center,string qvar)
*
* int qfont                   font to use
* int center                  centering value, analog to the one in [write]
* string qvar                 text to write
*
* Returns the position of the generated graphic in FPG 0.
*/
process qgenerate_graph(qfont,center,string qvar)

private
   i,xPixels,tempMap;
   wide,high;

begin
   //determine the length in pixels of the text
   if(font[qfont].fixed)
     //fixed width, simple multiplication
     xPixels = len(qvar) * (font[qfont].width + 1);
   else
     //not fixed width, add the lengths of all characters
     for(i=0;i<len(qvar);i++)
       if(map_exists(font[qfont].fpg,asc(substr(qvar,i,1))))
         xPixels++;//space between characters
         xPixels += graphic_info(font[qfont].fpg,asc(substr(qvar,i,1)),G_WIDTH);
       end
     end
   end

   //create the map
   file = 0;
   graph = new_map(xPixels,font[qfont].height,font[qfont].depth);

   xPixels = 0;

   //blit the characters on it
   for(i=0;i<len(qvar);i++)

     if(font[qfont].fixed)

       if(map_exists(font[qfont].fpg,asc(substr(qvar,i,1))))

         //clone the charactermap we need
         tempMap = map_clone(font[qfont].fpg,asc(substr(qvar,i,1)));
         set_center(0,tempMap,0,0);
         map_put(file,graph,tempMap,xPixels,0);
         unload_map(0,tempMap);

       end//map_exists
       xPixels += font[qfont].width + 1;

     else

       if(map_exists(font[qfont].fpg,asc(substr(qvar,i,1))))
         //space between characters
         xPixels++;

         //clone the charactermap we need
         tempMap = map_clone(font[qfont].fpg,asc(substr(qvar,i,1)));
         set_center(0,tempMap,0,0);
         map_put(file,graph,tempMap,xPixels,0);
         unload_map(0,tempMap);
         xPixels += graphic_info(font[qfont].fpg,asc(substr(qvar,i,1)),G_WIDTH);
       end//map_exists
     end

   end

   //set the center:
   wide = graphic_info(file,graph,G_WIDTH);
   high = graphic_info(file,graph,G_HEIGHT);

   switch(center)
     case 0:
       set_center(file,graph,0,0);
     end
     case 1:
       set_center(file,graph,wide/2,0);
     end
     case 2:
       set_center(file,graph,wide,0);
     end
     case 3:
       set_center(file,graph,0,high/2);
     end
     case 4:
       set_center(file,graph,wide/2,high/2);
     end
     case 5:
       set_center(file,graph,wide,high/2);
     end
     case 6:
       set_center(file,graph,0,high);
     end
     case 7:
       set_center(file,graph,wide/2,high);
     end
     case 8:
       set_center(file,graph,wide,high);
     end
   end


   return graph;
end

///////////////////////////////////////////////
//                                           //
//  The sprites for your font gets stored    //
//  at the fpg index number that equals the  //
//  symbols ascii number, you can also look  //
//  at every other ascii table.              //
//                                           //
//  symbol - fpg index                       //
//                                           //
//    - 32          @ - 64          ´ - 96   //
//  ! - 33          A - 65          a - 97   //
//  " - 34          B - 66          b - 98   //
//  # - 35          C - 67          c - 99   //
//  $ - 36          D - 68          d - 100  //
//  % - 37          E - 69          e - 101  //
//  & - 38          F - 70          f - 102  //
//  ` - 39          G - 71          g - 103  //
//  ( - 40          H - 72          h - 104  //
//  ) - 41          I - 73          i - 105  //
//  * - 42          J - 74          j - 106  //
//  + - 43          K - 75          k - 107  //
//  , - 44          L - 76          l - 108  //
//  - - 45          M - 77          m - 109  //
//  . - 46          N - 78          n - 110  //
//  / - 47          O - 79          o - 111  //
//  0 - 48          P - 80          p - 112  //
//  1 - 49          Q - 81          q - 113  //
//  2 - 50          R - 82          r - 114  //
//  3 - 51          S - 83          s - 115  //
//  4 - 52          T - 84          t - 116  //
//  5 - 53          U - 85          u - 117  //
//  6 - 54          V - 86          v - 118  //
//  7 - 55          W - 87          w - 119  //
//  8 - 56          X - 88          x - 120  //
//  9 - 57          Y - 89          y - 121  //
//  : - 58          Z - 90          z - 122  //
//  ; - 59          [ - 91          { - 123  //
//  < - 60          \ - 92          | - 124  //
//  = - 61          ] - 93          } - 125  //
//  > - 62          ^ - 94          ~ - 126  //
//  ? - 63          _ - 95                   //
//                                           //
///////////////////////////////////////////////

SplinterGU

Download Lastest BennuGD Release: http://www.bennugd.org/node/2

SplinterGU

esto esta mal:


process qwrite_int(qfont,x,y,center,int pointer qvar)

private
   int qvarValue=0;

begin
   qvarValue = pointer qvar;
   graph = qgenerate_graph(qfont,center,itoa(pointer qvar));
   loop
     if(pointer qvar != qvarValue)
       qvarValue = pointer qvar;
       unload_map(file,graph);
       graph = qgenerate_graph(qfont,center,itoa(pointer qvar));
     end
     frame;
   end

end;


pointer es solo para declarar o castear... cuando vas a usarlas tenes que usar "*"
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

SplinterGU

tu codigo corregido, me da "excepcion de coma flotante", no se si es un error de bennu o que pisaste memoria en algun lado, ahora mismo no puedo revisar, si alguien revisa este codigo, fantastico
Download Lastest BennuGD Release: http://www.bennugd.org/node/2

SplinterGU

aca tambien esta mal... itoa de un float....


process qwrite_float(qfont,x,y,center,float pointer qvar)

private
   float qvarValue;

begin
   qvarValue = * qvar;
   graph = qgenerate_graph(qfont,center,itoa(* qvar));
   loop
     if(* qvar != qvarValue)
       qvarValue = * qvar;
       unload_map(file,graph);
       graph = qgenerate_graph(qfont,center,itoa(* qvar));
     end
     frame;
   end

end

Download Lastest BennuGD Release: http://www.bennugd.org/node/2

SplinterGU

claro, falla porque no tengo los fpg, y en la funcion qgenerate_graph manda a crear un map_new(0,0,0);
Download Lastest BennuGD Release: http://www.bennugd.org/node/2