Re: Raylib and Classes

new topic     » goto parent     » topic index » view thread      » older message » newer message
Icy_Viking said...

Maybe I'll just wait for Eu 4.2 with memstruct. Hopefully it can get out the door this year!

Maybe, but memstruct wouldn't fix this. Memstruct is for accessing structures in memory. This involves passing structures members as a list of parameters, which are scattered around the CPU registers depending on their type (int, float, etc.). See Parameter passing and Return values. Hypothetically the interface for that would look something like what I have below. Although I'm unsure of what to call that member_ctypes() function and that's the best I've got for now. What I'd really prefer to do is integrate the declared memstruct names into the type system so we can avoid this change of concept for "dot" halfway through a statement, but I'm still trying to figure out all the necessary parts to make that happen.

typedef struct Vector2 { 
    float x;                // Vector x component 
    float y;                // Vector y component 
} Vector2; 
 
typedef struct Color { 
    unsigned char r;        // Color red value 
    unsigned char g;        // Color green value 
    unsigned char b;        // Color blue value 
    unsigned char a;        // Color alpha value 
} Color; 
 
RLAPI void DrawPixelV(Vector2 position, Color color);    // Draw a pixel (Vector version) 
RLAPI Vector2 GetMonitorPosition(int monitor);           // Get specified monitor position 

memstruct rlVector2 
    float x             -- Vector x component 
    float y             -- Vector y component 
end memstruct 
 
memstruct rlColor 
    unsigned char r     -- Color red value 
    unsigned char g     -- Color green value 
    unsigned char b     -- Color blue value 
    unsigned char a     -- Color alpha value 
end memstruct 
 
constant RL_VECTOR2 = member_ctypes(rlVector2) -- {C_FLOAT,C_FLOAT} 
constant RL_COLOR = member_ctypes(rlColor) -- {C_UCHAR,C_UCHAR,C_UCHAR,C_UCHAR} 
 
constant xDrawPixelV = define_c_proc(raylib,"DrawPixelV",{RL_VECTOR2,RL_COLOR}) 
constant xGetMonitorPosition = define_c_func(raylib,"GetMonitorPosition",{C_INT},RL_VECTOR2) 
 
public procedure DrawPixelV(atom position, atom color) 
    c_proc(xDrawPixelV, { 
        position.rlVector2, -- passes {x,y} 
        color.rlColor       -- passes {r,g,b,a} 
    } ) 
end procedure 
 
public function GetMonitorPosition(integer monitor) 
    return c_func(xGetMonitorPosition, {monitor}) -- returns {x,y} 
end function 

-Greg

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu