GLBasic forum

Main forum => GLBasic - en => Topic started by: bigsofty on 2007-Dec-02

Title: Request: More types...
Post by: bigsofty on 2007-Dec-02
Support for...

BYTE , WORD, LONG types, signed and unsigned.

Its very hard to convert code from other languages which have various types that GLBasic does not support. Sometimes its necessary to define the exact size and length of a datastructure in bytes but in GLBasic everything is a float so even if I am storing a byte a float is allocated. There is no SizeOf function for example because of the lack of defined variable types.
Title: Request: More types...
Post by: Schranz0r on 2007-Dec-02
Inline?
Title: Request: More types...
Post by: bigsofty on 2007-Dec-02
I can get it to work that's not the problem, various types would simply be cleaner, more logical and slightly faster. SizeOf can easily be calculated, structs can be read in bytes, words, longwords etc... then inserted into a GLBasic struct... I CAN get it to work, its just kinda 'clumsy' without suitable types to suit the data being manipulated...

I am however aware that this is no small request, as to modify something as base as basic types in a language has ripples for syntax right through the language as a whole.
Title: Request: More types...
Post by: Quentin on 2007-Dec-02
Hmm,
sometimes I miss different data types too.
But I think GLBasic was designed to be easy to learn, so that you won't have to spend to much thougts in your data structure. Perhaps it will be harder to learn especially for beginners if there are a lot of different data types ;)
Title: Request: More types...
Post by: Kitty Hello on 2007-Dec-03
I've checked some speed tests. There's about zero speed up when using ints instead of double on an x86 platform. The only reason would be large arrays of char, e.g., but if you really need these, go for a quick INLINE wrapper, please.

You can do this easily by making this:

Code (glbasic) Select
INLINE
DGArray gCharArray;
#define GLBArray gCharArray
ENDINLINE
GLOBAL GLBArray[]

// use GLBArray as if it were a GLBasic array, but the preprocessor will replace it with the char array from above.
Title: Request: More types...
Post by: bigsofty on 2007-Dec-03
Wow, that's a much simpler way than I was trying, thanks Gernot... and I can use WORDS, LONGWORDS, Signd WORDS etc... in the same way?

Speed is not really my priority here its mainly just that I am trying to convert code, in this case from delphi, that uses packed arrays of bytes and words and uses byte offsets into the datastructures... I think the way you just suggested will work! :)

Sorry Schranz0r, looks like you were quite right bud ;)
Title: Request: More types...
Post by: Kitty Hello on 2007-Dec-03
Make a regular type, then use the READxxx function to read the specific types into GLBasic doubles.
Title: Request: More types...
Post by: bigsofty on 2007-Dec-03
Quote from: GernotFrischMake a regular type, then use the READxxx function to read the specific types into GLBasic doubles.
This is what I was doing but as I could only define GLB floats. Im writing an MD2 loader...

This is part of the structure types deinitions in Pascal....

Code (glbasic) Select
 // One range-compressed vertex.
  TMD2Vertex = packed record
    Vertex: array [0..2] of Byte;
    LightNormalIndex: Byte;
  end;
  // One animation frame.
  TMD2Frame = record
    Scale: array [0..2] of Single;
    Translate: array [0..2] of Single;
    Name: array [0..15] of Char;
    Vertices: array of TMD2Vertex;
  end;
  // One triangle.
  TMD2Triangle = packed record
    VertexIndices: array [0..2] of SmallInt;
    TextureIndices: array [0..2] of SmallInt;
  end;
  // A skin name.
  TMD2Skin = array [0..63] of Char;
  // One pair of texcoords.
  TMD2TextureCoordinate = packed record
    s, t: SmallInt;
  end;
  // One vertex as sent to the GL.
  TMD2GLCommand = packed record
    s, t: Single;
    VertexIndex: Integer;
  end;
  // MD2s contain either strips or fans.
  TMD2GLCommandMode = ( MD2_GLCOMMAND_STRIP, MD2_GLCOMMAND_FAN );
  // List of GLCommands.
  TMD2GLCommands = record
    Mode: TMD2GLCommandMode;
    Commands: array of TMD2GLCommand;
  end;
These are the read in a record at a time. If I use GLBasic variables, then everything is a record types with floats and I cant read them in as correct length records. I  have to read each field in and adjust the READxxx to match the individual field type... although possible, its a slow laborious process and I am also storing bytes in 8 bytes floats... not good, when dealing with thousands of bytes...

Some of the calculations are a bit messed up too as the original program was expecting integers not floats, so I have to be careful to enforce INTEGER() on variables that are floats, which I have to use in GLBasic to store integers... :P hehe See what I mean about additional compilcation?

All workable but long-winded...
Title: Request: More types...
Post by: Kitty Hello on 2007-Dec-03
MD2 can be converted easily with the convert3D tool, since it's basically the same format.
Usually loading the mesh in one buffer with READxxx and then store only what you need should work.
Title: Request: More types...
Post by: bigsofty on 2007-Dec-03
Yeah but Its not strictly MD2, I have my own 'tweaks' to the model format, bump map and specular maps for the skin for example... I'm kinda creating my own 3D Engine for extra flexibility...

I can load in the data, its just a bit of pain... or maybe I'm too much of a perfectionist... I like things to  be stored in the smallest possible space (a variable that is a byte should be stored in a byte type for example), efficiently as possible... :P