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

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 - cekota

Pages: [1] 2
1
(using macro makes it possible to produce C variables, or variables in the destination language.)

2
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".


3
General discussions / 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 )
 

4
General discussions / Re: SFML 2.0 RC
« on: October 08, 2012, 08:54:51 pm »
They are all accessible by a human.
By accessible I mean by the code.

While trying to reproduce the C++ API in a wrapper using CSFML, we have to hard code the default values.

Then in a future SFML 3.0, if some default values change, the wrappers will remain with the old default values.

5
General discussions / Re: SFML 2.0 RC
« on: October 08, 2012, 05:10:45 pm »
And what about providing the default parameters in an accessible way?

(as asked in my previous post)

While writing my binding, I've read sources of other SFML bindings. From comments, or svn commit messages (don't remember which) I have seen that this is not only a problem for me, but also for other binders.

6
General discussions / Re: SFML 2.0 RC
« on: October 08, 2012, 05:04:51 pm »
If CSFML does the copy, then every user in every situation will be forced to do this copy. If I directly provide the object, then it's up to the user to decide if he wants to make a copy of it or not. There are many situations where you won't need to copy it, for example when you want to pass an identity matrix to a function that has a sfTransform argument.
So there's no problem, just more flexibility.

Oh, I see.
Thank you very much for taking time to instruct me :)

Quote
The parameter "coordinateType" is missing.
https://github.com/SFML/CSFML/issues/9#issuecomment-6586469

Oh, I see.
Then I'll remove it from my bindings.

7
Feature requests / Re: Rewrite the entire library in C
« on: October 08, 2012, 01:26:49 am »
If you use the shorthand terms "pure / impure" outside of a functional programming community some people won't understand you. Then you should use the complete expression, not a shorthand, like "purly functional", and for "impure", maybe "imperative" will be more easily understood by everyone.

Also in the Free/Libre software community things don't work as you think. You should not ask anyone to do something for you. Just take what's available, and do things yourself with it.

For your problem I'm not an expert, but if I remember correctly I think that I have read on this forum that in some situations, it could be better to reuse the same circle-shape, and just change the position (and maybe other params) for all the circles to be drawn.

So maybe you could use this same technic. Create a Circle structure on the Haskell side which will be purely functional.
Then the drawCircle will just check the fields of the Haskell structure (you could use Nothing/Just to limit things) and reuse all the time the same static (I mean not allocated but not with the static keyword) SFML CircleShape and call all the functions that are needed (like setFillColor() and co) and then the draw function.

What would you think of such a solution?

Also you say in one of your post that someone told you "of a way to make the api more or less pure while minimising the number of background mallocs at the same time". Please could you share it with us? I would be interested, maybe other people too.

8
Feature requests / Re: Rewrite the entire library in C
« on: October 08, 2012, 12:18:13 am »
(ugly) C

There are very often these kind of Trolls on this forum.

Please stop it.

C++ is also a horrible thing. No-one should use it to create a user app. C/C++ are fine to make low-level things. SFML does low-level things by interfacing with the windowing system. When you create a high level application you should use a high-level language. There are several high-level languages with very good performances. There are even some that provide the same performances than C/C++. Programming with a high level language makes you write things more easily, quickly, and with less bugs. The result will be easier to maintain, contributors will contribute more easily with a higher level language.

C is ugly, yes that's true, C++ is not better, it is a very complicated programming language. A lot of people around even say often that this is one of the most complecated programming language.

If you want to troll, I can troll with you too.

Please stop trolling.

9
General discussions / Re: Pixel Engine
« on: October 07, 2012, 11:54:25 pm »
In Warmux there are destructible 2D terrains.



It's Free/Libre software, so just read the source code.

10
General discussions / Re: SFML 2.0 RC
« on: October 07, 2012, 11:30:57 pm »
In the SFML API, there are a lot of function that have default parameters.

Sometimes these default parameter are easy to find from the headers.
Sometimes there are several definitions of the same function so that tracking the default parameter has to be made by reading the source code of SFML, not the header anymore.

When wrapping CSFML this is quite a pain.

More over hard I don't like coding the default parameters in the wrapper because, maybe one day the default value would change, maybe in SFML 3.X.

It would be nice to provide some facilities to get these default parameters.

There could be several ways to do so, one simple possibility could be defining some variable, for example:


<Value_Type> <Function_Name>_<Param_Nane>_Default = <Default_Value>

sfTextureCoordinateType  sfTexture_bind_texture_default = sfTexCoordType_Normalized;

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


MAKE_DEFAULT_PARAM( sfTexture_bind, coordType, sfTextureCoordinateType, sfTexCoordType_Normalized )

 

11
General discussions / Re: SFML 2.0 RC
« on: October 07, 2012, 11:01:01 pm »
CSFML: include/SFML/Graphics/Texture.h:
CSFML_GRAPHICS_API void sfTexture_bind(const sfTexture* texture);

SFML: include/SFML/Graphics/Texture.hpp:
void bind(CoordinateType coordinateType = Normalized) const;

The parameter "coordinateType" is missing.

12
General discussions / Re: SFML 2.0 RC
« on: October 07, 2012, 10:58:35 pm »
Ok, but... the binding will also make it const. CSFML is not supposed to solve potential mistakes in bindings that use it.

If I use a function and return a new copy every time it is called, it can even be worse: a binding that would not make the corresponding object const/readonly/whatever, wouldn't see it and it would "work" although the design has a major flaw.

This is purely a design issue, technical choices won't help. The only good solution is to make sure that the objects are const/readonly/... in all the bindings. So thank you for pointing out that they were not in CSFML :)

Well, I don't want to make you change your mind, but I would like to understand, because your are an experienced programmer, and I'm a beginner, so I would really want to understand in order to improve my skills.

The problem is that I really don't see what I can do with a const sfTransform_Identity. If I want to use it I will copy it and then use some rotate and translate functions on the copy. So in this case I was thinking that sfTransform_getIdentity() would makes sens.

So please explain me what I'm supposed to do with this const sfTransform_Identity ?

13
General discussions / Re: SFML 2.0 RC
« on: September 30, 2012, 02:06:53 pm »
sorry, I thought it was so evident that CSFML is often used for building bindings to higher level languages, but it seems it is not.

indeed, if the variable is wrapped, then the const qualification is discarded

14
General discussions / Re: SFML 2.0 RC
« on: September 29, 2012, 12:53:48 pm »
and this is also why a function would be better.

15
General discussions / Re: SFML 2.0 RC
« on: September 29, 2012, 12:52:26 pm »
Hum? Why would it apply silently? It will trigger a compiler error, that's the point of using the const keyword.

Just remember what CSFML is made for :)

Is it made mainly to write pure plain C ?
Or is its main purpose for something else ?

Pages: [1] 2