Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: default function arguments, available for bindings  (Read 2129 times)

0 Members and 1 Guest are viewing this topic.

cekota

  • Newbie
  • *
  • Posts: 16
    • View Profile
default function arguments, available for bindings
« on: October 09, 2012, 09:57:05 pm »
And how would your macros automatically keep the wrappers up to date? ???

const unsigned int sfVideoMode_bitsPerPixel_default = 32;

const unsigned int ContextSettings_depth_default = 0;
const unsigned int ContextSettings_stencil_default = 0;
const unsigned int ContextSettings_antialiasing_default = 0;
const unsigned int ContextSettings_major_default = 2;
const unsigned int ContextSettings_minor_default = 0;

const unsigned int sfSoundRecorder_start_sampleRate_default = 44100;

const unsigned short sfFtp_connect_port_default = 21;
const sfTime sfFtp_connect_timeout_default = sfTime_Zero;

const char* sfFtp_login_userName_default = "";
const char* sfFtp_login_password_default = "";

const char* sfFtp_getDirectoryListing_directory_default = "";

const sfFtpTransferMode sfFtp_download_mode_default = sfFtpBinary;
const sfFtpTransferMode sfFtp_upload_mode_default = sfFtpBinary;

const sfUint8 sfColor_a_default = 255;

const sfIntRect sfIntRect_Zero = { 0, 0, 0, 0 };

const sfIntRect sfImage_copyImage_sourceRect_default = sfIntRect_Zero;
const sfBool sfImage_copyImage_applyAlpha_default = sfFalse;

const sfBlendMode sfRenderStates_blendMode_default = sfBlendAlpha;
const sfTransform sfRenderStates_transform_default = sfTransform_Identity;
const sfTexture* sfRenderStates_texture_default = NULL;
const sfShader* sfRenderStates_shader_default = NULL;

const sfRenderStates* sfRenderWindow_drawSprite_states_default = NULL;
const sfRenderStates* sfRenderWindow_drawText_states_default = NULL;
const sfRenderStates* sfRenderWindow_drawShape_states_default = NULL;
const sfRenderStates* sfRenderWindow_drawCircleShape_states_default = NULL;
const sfRenderStates* sfRenderWindow_drawConvexShape_states_default = NULL;
const sfRenderStates* sfRenderWindow_drawRectangleShape_states_default = NULL;
const sfRenderStates* sfRenderWindow_drawVertexArray_states_default = NULL;
const sfRenderStates* sfRenderWindow_drawPrimitives_states_default = NULL;

const sfBool sfRenderTexture_create_depthBuffer_default = sfFalse;

const sfBool sfRenderTexture_setActive_active_default = sfTrue;

const sfUint32 sfWindow_create_style_default = sfDefaultStyle;
const sfContextSettings* sfWindow_create_settings_default = NULL;

const sfUint32 sfRenderWindow_create_style_default = sfDefaultStyle;
const sfContextSettings* sfRenderWindow_create_settings_default = NULL;

const sfContextSettings* sfWindow_createFromHandle_settings_default = NULL;
const sfContextSettings* sfRenderWindow_createFromHandle_settings_default = NULL;

const sfBool sfRectangleShape_setTexture_resetRect_default = sfFalse;
const sfBool sfSprite_setTexture_resetRect_default = sfFalse;

const unsigned int sfText_setCharacterSize_characterSize_default = 30;

const sfIntRect* sfTexture_createFromFile_area_default = NULL;
const sfIntRect* sfTexture_createFromMemory_area_default = NULL;
const sfIntRect* sfTexture_createFromStream_area_default = NULL;
const sfIntRect* sfTexture_createFromImage_area_default = NULL;

static inline unsigned int sfVector2u_get_x(sfVector2u v) { return v.x }
static inline unsigned int sfVector2u_get_y(sfVector2u v) { return v.y }

#define sfTexture_updateFromImage_width_default  sfVector2u_get_x(sfImage_getSize(image))
#define sfTexture_updateFromImage_height_default  sfVector2u_get_y(sfImage_getSize(image))
const unsigned int sfTexture_updateFromImage_x_default = 0;
const unsigned int sfTexture_updateFromImage_y_default = 0;

#define sfTexture_updateFromPixels_width_default  sfVector2u_get_x(sfTexture_getSize(texture))
#define sfTexture_updateFromPixels_height_default  sfVector2u_get_y(sfTexture_getSize(texture))
const unsigned int sfTexture_updateFromPixels_x_default = 0;
const unsigned int sfTexture_updateFromPixels_y_default = 0;

const unsigned int sfTexture_updateFromWindow_x_default = 0;
const unsigned int sfTexture_updateFromWindow_y_default = 0;
 

The previous code is produced by cpp from the file below.
(I put it for readablility to see what we get)

////////////////////////////////////////////////////////////
//
// SFML Default Args - Default arguments for the SFML library
// Copyright (C) 2012 <My Name> (ask me my name if you want to use it)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the
// use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
//    you must not claim that you wrote the original software.
//    If you use this software in a product, an acknowledgment
//    in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
//    and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////

#define MAKE_DEFAULT_PARAM(elem_name, param_type, param_name, default_value) \
    const param_type elem_name##_##param_name##_default = default_value;


#define DEFAULT_PARAM_FROM_FUNC(elem_name, param_type, param_name, func) \
    SHARP define elem_name##_##param_name##_default  func


MAKE_DEFAULT_PARAM( sfVideoMode, unsigned int, bitsPerPixel, 32 )

MAKE_DEFAULT_PARAM( ContextSettings, unsigned int, depth, 0 )
MAKE_DEFAULT_PARAM( ContextSettings, unsigned int, stencil, 0 )
MAKE_DEFAULT_PARAM( ContextSettings, unsigned int, antialiasing, 0 )
MAKE_DEFAULT_PARAM( ContextSettings, unsigned int, major, 2 )
MAKE_DEFAULT_PARAM( ContextSettings, unsigned int, minor, 0 )

MAKE_DEFAULT_PARAM( sfSoundRecorder_start, unsigned int, sampleRate, 44100 )

MAKE_DEFAULT_PARAM( sfFtp_connect, unsigned short, port, 21 )
MAKE_DEFAULT_PARAM( sfFtp_connect, sfTime, timeout, sfTime_Zero )

MAKE_DEFAULT_PARAM( sfFtp_login, char*, userName, "" )
MAKE_DEFAULT_PARAM( sfFtp_login, char*, password, "" )

MAKE_DEFAULT_PARAM( sfFtp_getDirectoryListing, char*, directory, "" )

MAKE_DEFAULT_PARAM( sfFtp_download, sfFtpTransferMode, mode, sfFtpBinary )
MAKE_DEFAULT_PARAM( sfFtp_upload, sfFtpTransferMode, mode, sfFtpBinary )

MAKE_DEFAULT_PARAM( sfColor, sfUint8, a, 255 )

const sfIntRect sfIntRect_Zero = { 0, 0, 0, 0 };

MAKE_DEFAULT_PARAM( sfImage_copyImage, sfIntRect, sourceRect, sfIntRect_Zero )
MAKE_DEFAULT_PARAM( sfImage_copyImage, sfBool, applyAlpha, sfFalse )

MAKE_DEFAULT_PARAM( sfRenderStates, sfBlendMode, blendMode, sfBlendAlpha )
MAKE_DEFAULT_PARAM( sfRenderStates, sfTransform, transform, sfTransform_Identity )
MAKE_DEFAULT_PARAM( sfRenderStates, sfTexture*, texture, NULL )
MAKE_DEFAULT_PARAM( sfRenderStates, sfShader*, shader, NULL )

MAKE_DEFAULT_PARAM( sfRenderWindow_drawSprite, sfRenderStates*, states, NULL )
MAKE_DEFAULT_PARAM( sfRenderWindow_drawText, sfRenderStates*, states, NULL )
MAKE_DEFAULT_PARAM( sfRenderWindow_drawShape, sfRenderStates*, states, NULL )
MAKE_DEFAULT_PARAM( sfRenderWindow_drawCircleShape, sfRenderStates*, states, NULL )
MAKE_DEFAULT_PARAM( sfRenderWindow_drawConvexShape, sfRenderStates*, states, NULL )
MAKE_DEFAULT_PARAM( sfRenderWindow_drawRectangleShape, sfRenderStates*, states, NULL )
MAKE_DEFAULT_PARAM( sfRenderWindow_drawVertexArray, sfRenderStates*, states, NULL )
MAKE_DEFAULT_PARAM( sfRenderWindow_drawPrimitives, sfRenderStates*, states, NULL )

MAKE_DEFAULT_PARAM( sfRenderTexture_create, sfBool, depthBuffer, sfFalse )

MAKE_DEFAULT_PARAM( sfRenderTexture_setActive, sfBool, active, sfTrue )

MAKE_DEFAULT_PARAM( sfWindow_create, sfUint32, style, sfDefaultStyle )
MAKE_DEFAULT_PARAM( sfWindow_create, sfContextSettings*, settings, NULL )

MAKE_DEFAULT_PARAM( sfRenderWindow_create, sfUint32, style, sfDefaultStyle )
MAKE_DEFAULT_PARAM( sfRenderWindow_create, sfContextSettings*, settings, NULL )

MAKE_DEFAULT_PARAM( sfWindow_createFromHandle, sfContextSettings*, settings, NULL )
MAKE_DEFAULT_PARAM( sfRenderWindow_createFromHandle, sfContextSettings*, settings, NULL )

MAKE_DEFAULT_PARAM( sfRectangleShape_setTexture, sfBool, resetRect, sfFalse )
MAKE_DEFAULT_PARAM( sfSprite_setTexture, sfBool, resetRect, sfFalse )

MAKE_DEFAULT_PARAM( sfText_setCharacterSize, unsigned int, characterSize, 30 )

MAKE_DEFAULT_PARAM( sfTexture_createFromFile, sfIntRect*, area, NULL )
MAKE_DEFAULT_PARAM( sfTexture_createFromMemory, sfIntRect*, area, NULL )
MAKE_DEFAULT_PARAM( sfTexture_createFromStream, sfIntRect*, area, NULL )
MAKE_DEFAULT_PARAM( sfTexture_createFromImage, sfIntRect*, area, NULL )

static inline unsigned int sfVector2u_get_x(sfVector2u v)  { return v.x }
static inline unsigned int sfVector2u_get_y(sfVector2u v)  { return v.y }

DEFAULT_PARAM_FROM_FUNC( sfTexture_updateFromImage, unsigned int, width, sfVector2u_get_x(sfImage_getSize(image)) )
DEFAULT_PARAM_FROM_FUNC( sfTexture_updateFromImage, unsigned int, height, sfVector2u_get_y(sfImage_getSize(image)) )
MAKE_DEFAULT_PARAM( sfTexture_updateFromImage, unsigned int, x, 0 )
MAKE_DEFAULT_PARAM( sfTexture_updateFromImage, unsigned int, y, 0 )

DEFAULT_PARAM_FROM_FUNC( sfTexture_updateFromPixels, unsigned int, width, sfVector2u_get_x(sfTexture_getSize(texture)) )
DEFAULT_PARAM_FROM_FUNC( sfTexture_updateFromPixels, unsigned int, height, sfVector2u_get_y(sfTexture_getSize(texture)) )
MAKE_DEFAULT_PARAM( sfTexture_updateFromPixels, unsigned int, x, 0 )
MAKE_DEFAULT_PARAM( sfTexture_updateFromPixels, unsigned int, y, 0 )

MAKE_DEFAULT_PARAM( sfTexture_updateFromWindow, unsigned int, x, 0 )
MAKE_DEFAULT_PARAM( sfTexture_updateFromWindow, unsigned int, y, 0 )
 
« Last Edit: October 09, 2012, 10:06:12 pm by cekota »

cekota

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: default function arguments, available for bindings
« Reply #1 on: October 09, 2012, 09:59:16 pm »
Then while wrapping the function sfSoundRecorder_start() using CSFML instead of hard coding 44100 as the default value, we could use "sfSoundRecorder_start_sampleRate_default".


cekota

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: default function arguments, available for bindings
« Reply #2 on: October 09, 2012, 10:04:32 pm »
(using macro makes it possible to produce C variables, or variables in the destination language.)

 

anything