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

Author Topic: Call and return by reference in CSFML  (Read 18412 times)

0 Members and 2 Guests are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Call and return by reference in CSFML
« Reply #15 on: December 23, 2010, 09:28:56 pm »
Quote
On the second point ... yeahhh ... seem to remember making similar mistakes. Is there a better alternative?

I don't think so.
Laurent Gomila - SFML developer

Flash

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Call and return by reference in CSFML
« Reply #16 on: May 31, 2014, 07:31:37 pm »
I know this is an old topic, but may I add my support to this request?
Forth is not the only language that is designed this way, it is true for Common Lisp (and other languages) as well.
The functions that get or return structs on stack would not need to be replaced, it would be OK to merely implement an alternative and make it clear in the documentation that they are only to be used for bindings.

I can do the additions myself, all I'd ask is that *if* I ever finish the Common Lisp binding, I'd be allowed to commit the changes back to CSFML, so that the binding would compatible with the main branch, without needing an additional wrapper dll.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Call and return by reference in CSFML
« Reply #17 on: June 01, 2014, 02:23:53 pm »
And this would break almost every single existing binding for SFML, not to mention introduce more issues for binding maintainers.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Flash

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Call and return by reference in CSFML
« Reply #18 on: June 01, 2014, 07:57:45 pm »
How would alternative implementations that do not change any of the functions that already exist break anything?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Call and return by reference in CSFML
« Reply #19 on: June 01, 2014, 10:33:52 pm »
If it's an alternative implementation, why does it have to be in CSFML? Can't you fork it and do the modifications in your own modified CSFML?
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Call and return by reference in CSFML
« Reply #20 on: June 01, 2014, 10:52:50 pm »
I guess it might be helpful to provide a bit more information on your idea, especially since the bumped thread is like four years old. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Flash

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Call and return by reference in CSFML
« Reply #21 on: June 01, 2014, 11:18:27 pm »
If it's an alternative implementation, why does it have to be in CSFML? Can't you fork it and do the modifications in your own modified CSFML?
Well, of course I can do that. But what would it be good for? It would only add confusion and unnecessary work of re-merging if SFML or CSFML is updated. CSFML is being provided precompiled for many systems, and people would just need to download the binding + CSFML.
It would also enable other people with similar problems to write a binding directly to CSFML. There's a reason SDL only passes pointers.

Again, as I don't want to cause any work, I'd fork it anyway, and only ask to submit if the binding gets finished. It possibly was a bit premature to ask, as that is still a way off.  ;)

I guess it might be helpful to provide a bit more information on your idea, especially since the bumped thread is like four years old. ;)
The basic idea is to just provide alternative functions that pass pointers, e.g.

CSFML_GRAPHICS_API sfRenderWindow *     sfRenderWindow_create (sfVideoMode mode, const char *title, sfUint32 style, const sfContextSettings *settings)
=>
CSFML_GRAPHICS_API sfRenderWindow *     sfRenderWindow_create (sfVideoMode *mode, const char *title, sfUint32 style, const sfContextSettings *settings)
and
CSFML_GRAPHICS_API sfContextSettings    sfRenderWindow_getSettings (const sfRenderWindow *renderWindow)
=>
CSFML_GRAPHICS_API void sfRenderWindow_getSettings (const sfRenderWindow *renderWindow, sfContextSettings *settings)
I'm not so sure about the second example, or if it's better to create a new sfContextSettings struct and return it, but I'd rather have a "who creates it, is responsible" approach.

If anyone is interested, I asked a question on the Common Lisp side of this on StackOverflow a while back, to make sure I'm not missing anything.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Call and return by reference in CSFML
« Reply #22 on: June 02, 2014, 12:53:33 am »
I don't know if this helps you out at all, but you could look at DSFML-C, which is a modified version of CSFML that removed all POD structs (sfVector2f, sfTime, etc) in lieu of using a set of scalars instead.

For example:
CSFML_GRAPHICS_API sfImage* sfImage_createFromColor(unsigned int width, unsigned int height, sfColor color);
Looks like
DSFML_GRAPHICS_API sfImage* sfImage_createFromColor(DUint width, DUint height, DUbyte r, DUbyte b, DUbyte g, DUbyte a);

(though now I realize this function passes the color in rbga order instead of rgba order :P)

Feel free to use it if you want, but some of it (the audio stuff) is a little experimental. Just a heads up.
DSFML - SFML for the D Programming Language.

Flash

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Call and return by reference in CSFML
« Reply #23 on: June 02, 2014, 07:25:11 am »
I don't know if this helps you out at all, but you could look at DSFML-C, which is a modified version of CSFML that removed all POD structs (sfVector2f, sfTime, etc) in lieu of using a set of scalars instead.

For example:
CSFML_GRAPHICS_API sfImage* sfImage_createFromColor(unsigned int width, unsigned int height, sfColor color);
Looks like
DSFML_GRAPHICS_API sfImage* sfImage_createFromColor(DUint width, DUint height, DUbyte r, DUbyte b, DUbyte g, DUbyte a);

(though now I realize this function passes the color in rbga order instead of rgba order :P)

Feel free to use it if you want, but some of it (the audio stuff) is a little experimental. Just a heads up.
Thanks, this one would actually work.  :D
Deconstructing all structs seems a little overkill for my purposes, though, as I only have problems with very few functions, and you lose some readability. Still, it'd be a better alternative than having to maintain yet another fork, IMO.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Call and return by reference in CSFML
« Reply #24 on: June 02, 2014, 07:43:22 am »
Quote
It would only add confusion
Having two versions of each function in CSFML would be confusing. Having a fork which is dedicated to this modification would be a lot clearer in my opinion.

Quote
unnecessary work of re-merging if SFML or CSFML is updated
Updating these functions every time CSFML is updated is not unnecessary work, it has to be done anyway. Of course it's easier for you if it's me who does it... ;)

Quote
CSFML is being provided precompiled for many systems, and people would just need to download the binding + CSFML
You can provide your own releases. And since people interested in this fork would be bindings creators, I don't think they would be afraid to compile it if they can't find a precompiled version for their platform.

Quote
There's a reason SDL only passes pointers.
Did they say it is for this particular reason?
Laurent Gomila - SFML developer

Flash

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Call and return by reference in CSFML
« Reply #25 on: June 02, 2014, 07:56:02 pm »
Quote
It would only add confusion
Having two versions of each function in CSFML would be confusing. Having a fork which is dedicated to this modification would be a lot clearer in my opinion.

Quote
unnecessary work of re-merging if SFML or CSFML is updated
Updating these functions every time CSFML is updated is not unnecessary work, it has to be done anyway. Of course it's easier for you if it's me who does it... ;)
I'm sorry, I just realized that I made this request under false preconceptions.
For whatever reasons I thought that rogerlevy's list posted in this thread was accurate, and I still think that it would have been a good idea for ~10 functions (and little extra work to maintain).
However, knowing the CSFML source I should have known better, as this list contains none of the functions that return vectors, rects and similar stuff (I think I realized this a few weeks ago, but had forgotten, as I did not work on the binding in the meantime).
Thus I realize that having alternatives for that many functions might be confusing, and is additional work to maintain.


Quote
Quote
CSFML is being provided precompiled for many systems, and people would just need to download the binding + CSFML
You can provide your own releases. And since people interested in this fork would be bindings creators, I don't think they would be afraid to compile it if they can't find a precompiled version for their platform.
Well, I hope that the people interested in this fork would be Common Lisp Users. ;) And it would have been nice to just download the appropriate dll, load the bindings via quicklisp and everything would work, regardless of system. Alas, that's not gonna be. :P

Quote
Quote
There's a reason SDL only passes pointers.
Did they say it is for this particular reason?
No, it was an assumption on my part, because I couldn't think of a better reason other than speed (but they do it even for all structs). It might be one of several reasons, or not play a role.

So I'll see what I'll do. Possibly DSFML-C is the best alternative, as I really want to avoid having yet another fork unless I really have to. As I plan to have high-level lispy abstractions modeled on SFML anyway, the deconstructed parameters would be hidden anyway.
« Last Edit: June 03, 2014, 08:27:11 am by Flash »

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Call and return by reference in CSFML
« Reply #26 on: June 02, 2014, 08:32:24 pm »
Please be aware that DSFML-C is written specifically to interface with the D binding so it might not fit right for lisp in all cases.
DSFML - SFML for the D Programming Language.

Flash

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Call and return by reference in CSFML
« Reply #27 on: June 02, 2014, 09:13:26 pm »
Please be aware that DSFML-C is written specifically to interface with the D binding so it might not fit right for lisp in all cases.
How does this specificity manifest itself?
I thought it was just a normal C binding without structs.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Call and return by reference in CSFML
« Reply #28 on: June 03, 2014, 12:35:51 am »
In some cases, D is able to interface directly with C++, so I do that when I can and it makes sense. That means that some functions in DSFML-C expect C++ objects to be passed to them by address since those can be created in the D code.
DSFML - SFML for the D Programming Language.

Flash

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Call and return by reference in CSFML
« Reply #29 on: June 03, 2014, 07:26:37 am »
In some cases, D is able to interface directly with C++, so I do that when I can and it makes sense. That means that some functions in DSFML-C expect C++ objects to be passed to them by address since those can be created in the D code.
OK, so I can't use it either.   :-\