Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - TheExDeus

1651
General ENIGMA / Re: Questions on EDL and ENIGMA
« on: July 10, 2011, 06:41:35 am »
Fede-lasse - Point being?

1652
It actually wasn't called in the previous example code either. Though there was an if statement at every newline character while in this code there isn't. So that's something I guess. Now about valign. That actually requires a lot less code, and it doesn't require anything in the for loop. So should I write like this:
Code: [Select]
void draw_text(int x,int y,string str)
{
  font *fnt = fontstructarray[currentfont];

  if (bound_texture != fnt->texture)
    glBindTexture(GL_TEXTURE_2D, bound_texture = fnt->texture);

  if (halign == fa_left){
      int xx = x, yy = y+fnt->yoffset;
      if (valign == fa_middle)
        yy -= string_height(str)/2;
      else if (valign == fa_bottom)
        yy -= string_height(str);
      glBegin(GL_QUADS);
      for (unsigned i = 0; i < str.length(); i++)
      {
        if (str[i] == '\r')
          xx = x, yy += fnt->height, i += str[i+1] == '\n';
        else if (str[i] == '\n')
          xx = x, yy += fnt->height;
        else if (str[i] == ' ')
          xx += fnt->height/3; // FIXME: what's GM do about this?
        else
        {
          fontglyph &g = fnt->glyphs[(unsigned char)(str[i] - fnt->glyphstart) % fnt->glyphcount];
            glTexCoord2f(g.tx,  g.ty);
              glVertex2i(xx + g.x,  yy + g.y);
            glTexCoord2f(g.tx2, g.ty);
              glVertex2i(xx + g.x2, yy + g.y);
            glTexCoord2f(g.tx2, g.ty2);
              glVertex2i(xx + g.x2, yy + g.y2);
            glTexCoord2f(g.tx,  g.ty2);
              glVertex2i(xx + g.x,  yy + g.y2);
          xx += g.xs;
        }
      }
      glEnd();
  }else{
      int xx, yy = y+fnt->yoffset, line = 0;
      if (valign == fa_middle)
        yy -= string_height(str)/2;
      else if (valign == fa_bottom)
        yy -= string_height(str);
      if (halign == fa_center){
        xx = x-string_width_line(str,0)/2;
      }else{ //fa_right
        xx = x-string_width_line(str,0);
      }
      glBegin(GL_QUADS);
      for (unsigned i = 0; i < str.length(); i++)
      {
        if (str[i] == '\r'){
          line +=1, yy += fnt->height, i += str[i+1] == '\n';
          if (halign == fa_center){
              xx = x-string_width_line(str,line)/2;
          }else{ //fa_right
              xx = x-string_width_line(str,line);
          }
        }else if (str[i] == '\n'){
          line +=1, yy += fnt->height;
          if (halign == fa_center){
              xx = x-string_width_line(str,line)/2;
          }else{ //fa_right
              xx = x-string_width_line(str,line);
          }
        }else if (str[i] == ' ')
          xx += fnt->height/3; // FIXME: what's GM do about this?
        else
        {
          fontglyph &g = fnt->glyphs[(unsigned char)(str[i] - fnt->glyphstart) % fnt->glyphcount];
            glTexCoord2f(g.tx,  g.ty);
              glVertex2i(xx + g.x,  yy + g.y);
            glTexCoord2f(g.tx2, g.ty);
              glVertex2i(xx + g.x2, yy + g.y);
            glTexCoord2f(g.tx2, g.ty2);
              glVertex2i(xx + g.x2, yy + g.y2);
            glTexCoord2f(g.tx,  g.ty2);
              glVertex2i(xx + g.x,  yy + g.y2);
          xx += g.xs;
        }
      }
      glEnd();
  }
}
Or split again? The code size will double if I split.
edit: Fixed "thou" into "though". I know I use it wrong, but no one corrects me so its hard to learn.
Anyway, sleep time. If this code is good then I will implement draw_set_halign and valign tomorrow. There will just be a question about declarations out of the functions (because I need to declare fa_ constants in both .h and .cpp file.. more on that later).

1653
Quote
No, just put the original function in a big if for align being top-left, and then put the rest of the code in the else with whatever hackery is required, that way you don't have to iterate the string for draw_text() when the aligns are default.
So like this?
Code: [Select]
void draw_text(int x,int y,string str)
{
  font *fnt = fontstructarray[currentfont];

  if (bound_texture != fnt->texture)
    glBindTexture(GL_TEXTURE_2D, bound_texture = fnt->texture);

  if (halign == fa_left){
      int xx = x, yy = y+fnt->yoffset;
      glBegin(GL_QUADS);
      for (unsigned i = 0; i < str.length(); i++)
      {
        if (str[i] == '\r')
          xx = x, yy += fnt->height, i += str[i+1] == '\n';
        else if (str[i] == '\n')
          xx = x, yy += fnt->height;
        else if (str[i] == ' ')
          xx += fnt->height/3; // FIXME: what's GM do about this?
        else
        {
          fontglyph &g = fnt->glyphs[(unsigned char)(str[i] - fnt->glyphstart) % fnt->glyphcount];
            glTexCoord2f(g.tx,  g.ty);
              glVertex2i(xx + g.x,  yy + g.y);
            glTexCoord2f(g.tx2, g.ty);
              glVertex2i(xx + g.x2, yy + g.y);
            glTexCoord2f(g.tx2, g.ty2);
              glVertex2i(xx + g.x2, yy + g.y2);
            glTexCoord2f(g.tx,  g.ty2);
              glVertex2i(xx + g.x,  yy + g.y2);
          xx += g.xs;
        }
      }
      glEnd();
  }else{
      int xx, yy = y+fnt->yoffset, line = 0;
      if (halign == fa_middle){
        xx = x-string_width_line(str,0)/2;
      }else{ //fa_right
        xx = x-string_width_line(str,0);
      }
      glBegin(GL_QUADS);
      for (unsigned i = 0; i < str.length(); i++)
      {
        if (str[i] == '\r'){
          line +=1, yy += fnt->height, i += str[i+1] == '\n';
          if (halign == fa_middle){
              xx = x-string_width_line(str,line)/2;
          }else{ //fa_right
              xx = x-string_width_line(str,line);
          }
        }else if (str[i] == '\n'){
          line +=1, yy += fnt->height;
          if (halign == fa_middle){
              xx = x-string_width_line(str,line)/2;
          }else{ //fa_right
              xx = x-string_width_line(str,line);
          }
        }else if (str[i] == ' ')
          xx += fnt->height/3; // FIXME: what's GM do about this?
        else
        {
          fontglyph &g = fnt->glyphs[(unsigned char)(str[i] - fnt->glyphstart) % fnt->glyphcount];
            glTexCoord2f(g.tx,  g.ty);
              glVertex2i(xx + g.x,  yy + g.y);
            glTexCoord2f(g.tx2, g.ty);
              glVertex2i(xx + g.x2, yy + g.y);
            glTexCoord2f(g.tx2, g.ty2);
              glVertex2i(xx + g.x2, yy + g.y2);
            glTexCoord2f(g.tx,  g.ty2);
              glVertex2i(xx + g.x,  yy + g.y2);
          xx += g.xs;
        }
      }
      glEnd();
  }
}

1654
Quote
That code doesn't consider newlines.
Yes, the full code is this (tested and works):
Code: [Select]
void draw_text(int x,int y,string str)
{
  font *fnt = fontstructarray[currentfont];

  if (bound_texture != fnt->texture)
    glBindTexture(GL_TEXTURE_2D, bound_texture = fnt->texture);

  int xx, yy = y+fnt->yoffset, line = 0;
  if (halign == fa_left){
    xx = x;
  }else if (halign == fa_middle){
    xx = x-string_width_line(str,0)/2;
  }else{ //fa_right
    xx = x-string_width_line(str,0);
  }
  glBegin(GL_QUADS);
  for (unsigned i = 0; i < str.length(); i++)
  {
    if (str[i] == '\r'){
      line +=1, yy += fnt->height, i += str[i+1] == '\n';
      if (halign == fa_left){
          xx = x;
      }else if (halign == fa_middle){
          xx = x-string_width_line(str,line)/2;
      }else{ //fa_right
          xx = x-string_width_line(str,line);
      }
    }else if (str[i] == '\n'){
      line +=1, yy += fnt->height;
      if (halign == fa_left){
          xx = x;
      }else if (halign == fa_middle){
          xx = x-string_width_line(str,line)/2;
      }else{ //fa_right
          xx = x-string_width_line(str,line);
      }
    }else if (str[i] == ' ')
      xx += fnt->height/3; // FIXME: what's GM do about this?
    else
    {
      fontglyph &g = fnt->glyphs[(unsigned char)(str[i] - fnt->glyphstart) % fnt->glyphcount];
        glTexCoord2f(g.tx,  g.ty);
          glVertex2i(xx + g.x,  yy + g.y);
        glTexCoord2f(g.tx2, g.ty);
          glVertex2i(xx + g.x2, yy + g.y);
        glTexCoord2f(g.tx2, g.ty2);
          glVertex2i(xx + g.x2, yy + g.y2);
        glTexCoord2f(g.tx,  g.ty2);
          glVertex2i(xx + g.x,  yy + g.y2);
      xx += g.xs;
    }
  }
  glEnd();
}
Quote
Not having the code as fa_left fucks everything up, efficiency wise.
Agreed.
Quote
You're best to fork up front.
Could you elaborate? You mean having separate drawing functions for all six alignments? Then how will that be backwards compatible with GM? Or how will draw_set_halign/valign actually work in that case?
Quote
There should be functions added for draw_get_halign / valign these are missing from gml.
I will. That is easy.

edit: Also, why do I need this:
Code: [Select]
    if (str[i] == '\r')
      xx = x, yy += fnt->height, i += str[i+1] == '\n';
    else if (str[i] == '\n')
      xx = x, yy += fnt->height;
and can't have simply:
Code: [Select]
    if (str[i] == '\r' or str[i] == '\n')
      xx = x, yy += fnt->height;
I left that in legacy sake and I know that there are several end line characters, but why I have to  i += str[i+1] == '\n' which actually doesn't make sense (I insert \n as far as I know, but that's funny way to write that). This part was written by Josh or TGMG a long time ago.

1655
That's good, because my changes don't really change the position or height of a separate glyph. It looks for the biggest y2 and then subtracts that from the whole y position when drawing. When this is done it draws properly.

Also, I just tested and I can't even load wingdings in LGM, it just renders boxes. And that leads to my next question - How UTF support will be added? I am actually quite incompetent in that matter, because UTF standard has more than hundred thousand characters, and then I guess fonts just have the basic chars in them and not all of them, right? I doubt games that has UTF support renders all of thous chars on a texture, but they do use them somehow. For example, in Source Engine games (like CS:S) I have seen chinese symbols in chat while I don't actually have that charset installed. LGM's scripting editor does seem to handle utf chars so no problem there (though I don't know if gm6 format supports them, but the newest gmk does).

Next thing is about draw_set_halign(). I have an idea on how to do this, but that will involve cluttering the draw_text functions. I wouldn't want to make them slower than they need to be. This is the original line:
Code: [Select]
int xx = x, yy = y+fnt->yoffset; and it will have to be changed to this:
Code: [Select]
  if (halign == fa_left){
    xx = x;
  }else if (halign == fa_middle){
    xx = x-string_width(str)/2;
  }else{ //fa_right
    xx = x-string_width(str);
  }
I did fa_left the first because its the default and usual alignment. So in default case this will slow the code down by a one if statement. On the other hand things like fa_middle require me to know the width of the string, and string_width() is O(n). And this only for the halign.

1656
No problem. I try to work fast (unlike whatever).

1657
Yeah, that is still something to do with the sprite aspect of it. I will look into it. If I load a font, make it use it, and then compare ENIGMA and GM then the difference is a lot smaller (especially the y aspect). The difference there is from the different methods fonts are drawn on textures (and AA differences and so on). I will look into all of that, but I don't know if I will be able to minimize the difference even more. I will try to fix sprite fonts though.

edit: This is how it looks when I just load a font in LGM:
[img size=100x100]http://img812.imageshack.us/img812/7004/diffl.png[/img]

edit2: Looking at the font_add_sprite() code it seems that Josh doesn't revolve thous coordinates around the baseline (like in the regular loaded fonts and that is why positions in previous revisions were also off). So the fix was actually even simpler:
Code: [Select]
font->yoffset = 0;Now I want to know what kind of problems that create. Like what if I load a normal Arial font from sprite instead of this all caps monospaced one.

1658
Just like I suspected. He uses sprite fonts, and that is what I didn't yet update. I committed a change that fixes this.
Quote
I fixed font_add_sprite() for him a while back.
No, I mean that I changed the struct but didn't declare the yoffset variable inside the font_add_sprite function.

1659
Function Peer Review / Re: "Choose" statement
« on: July 08, 2011, 03:10:15 pm »
Quote
is incorrect; the string should come out as
It still works though.

Quote
Again, double max(double numbers, ...){} won't work.
That was actually the whole working code. :D I have this in mathnc.h:
Code: [Select]
double max(double n, ...);And this in mathnc.cpp:
Code: [Select]
#include "stdarg.h"
double max(double n, ...){}
So nothing inside the function. And when I do this in EDL:
Code: [Select]
draw_text(100,100,string(max(12,329,21,343,1000,2981)));It correctly draws 2981. And IDE_EDIT_objectfunctionality.h has it parsed like this:
Code: [Select]
draw_text(100, 100, toString(max(varargs(), (varargs(), 12, 329, 21, 343, 1000, 2981))));That is why its weird. I don't have any code inside that would actually do the comparing, but it still works. On the other hand if I deleted the code from mathnc.cpp it would trow an error saying that the function max is undefined.

1660
I sent you a PM before finding this topic. Can you maybe change the background color and see if its a color problem? I will change some font sizes and see what happens. I tested only on one font unfortunately. Also, is this font sprite based (so added with font_sprite_add)?

edit: maybe post the gmk? I know for certain that I didn't update font_sprite_add function, so that might as well be the problem if you use it. It tries to access unpopulated struct variable which in runtime can cause these kinds of problems (and not show error).

1661
Function Peer Review / Re: "Choose" statement
« on: July 08, 2011, 02:14:12 pm »
Quote
stdargs.h will kill the program if you pass it a var or a variant.
Yeah, that is what I meant. :D
Quote
Also, good luck getting the argument count.
Indeed, though if you made compiler parse this:
Quote
max(10,25,34.2);
into this:
Quote
max(4,10,25,34.2);
where the first argument is the argument number, then stdargs.h could be used. You already parse that string into this:
Code: [Select]
max(varargs(), (varargs(), 10, 25, 34.2));, so it seems that you can do it (and arguments are counted anyway for error reporting purposes, but I guess GCC is the one that does it).
Also, it seems that you have implemented the max function, but its chaotic in that definitions in mathc.h and .cpp are not used, but required. So if I delete max(double x,double y){ return fmax(x,y);   }, I will get an error, while the function itself isn't called. Also, it will take only 3 arguments if its written like that. I still need to change it into:
Code: [Select]
double max(double numbers, ...){} to take any number of arguments and still work.

edit: Also, if max(10,25,34.2) is called then it will return 34, not 34.2.
edit2: And I would want to study your method on how you implemented max, so I can add median and others.
edit3: Also, if it seems I'm just mumbling then ignore me. I'm in a habit of not explaining myself clearly.

1662
Function Peer Review / Re: "Choose" statement
« on: July 08, 2011, 10:25:03 am »
Why can't we use stdarg.h? Is this nested max() is really better than this:
Code: [Select]
double max(int n, ...){
        double max, tmp;
        va_list ap;
        va_start(ap, n);
        max = va_arg(ap, double);
        for(int i = 2; i <= n_args; i++) {
                if((tmp = va_arg(ap, double)) > max)
                        max = tmp;
        }
        va_end(ap);
        return max;
}

edit: Didn't see this:
Quote
ENIGMA will have one shortly. I need to make modifications to the syntax checker to allow functions to accept enigma::varargs.
And whats the difference exactly between this and stdarg.h provided functionality? I guess its that Josh's thing uses variants, so I don't need to cast to double or something. So max like this:
max(int 5, double 3.14) would return integer, while this:
max(int 5, double 6) would return a double. Using the simple stdarg would only return doubles or integers.

edit: Also, if doesn't really do what I think it does, then can we finally implement them with stdarg? Its like 10min of work to implement max, min, average, median and so on. Thous are some basic functions I really need.

1663
General ENIGMA / Re: Enigma status
« on: July 08, 2011, 10:15:48 am »
Why does it say "enigma_max", "enigma_floor" and so on? I suspect these are just the regular max and floor functions, but ENIGMAS current max implementation can only have two arguments (while here it could require more).

1664
Quote
but I forget where I left off
Near the first line probably.
Quote
Case-closed then, yes? :P
Yes, I also committed 801, but SF doesn't show that for some reason. Thou I didn't change font_add_sprite function, forgot about that.

1665
Issues Help Desk / Re: enigma can't find 'make'
« on: July 07, 2011, 04:10:05 pm »
Thank your for the explanation.