PascalGameDevelopment / SDL2-for-Pascal

Unit files for building Free Pascal and Delphi applications using the SDL2 library
https://pascalgamedevelopment.github.io/SDL2-for-Pascal/
Mozilla Public License 2.0
103 stars 20 forks source link

ADD: Support for dynamic linking first version that can be compiled u… #149

Open PascalCorpsman opened 1 week ago

PascalCorpsman commented 1 week ago

Hello all,

based on the discussion https://github.com/ev1313/Pascal-SDL-2-Headers/issues/78#issuecomment-2480539141 i wrote a little FPC Transpiler and switched now my complete work over to this repository.

In Order to create the least impact possible, i choosed to do "inplace" modifications for the code switchings for dynamic / static linked version.

The static linked version is 99% unchanged (only needed to rename the two overloaded functions from sdl2.pas).

The dynamic linked version does compile under Windows64 and Linux64, under Linux64 i was also able to test the joystick part (and that worked ;) )

So if you choose to migrate this PR then all users who are using the SDL2.pas at least need to do this step:

(*

And yes there is still plenty work to do, to have a fully supported dynamic linked SDL2.pas, but beside the already mentioned differences you could stay at the static linked version with nearly no change and at least the "basic" dynamic linked version does now exist ;).

I think if you merge this code base, maybe other interested users could finish the work i started here (y).

PascalCorpsman commented 1 week ago

One Question it seems that i upladed the files with the wrong line endings, which one is the one of the project, than i will try to correct this ?

Free-Pascal-meets-SDL-Website commented 1 week ago

Thanks for this overwhelming PR; wow but a hell of a commit :D

I guess we will need some time to review this.

suve commented 1 week ago

We're using \n line endings in the project; your PR seems to rewrite most of the files to use \r\n instead, hence the humongous diff.

PascalCorpsman commented 1 week ago

ok i reworked the code to change the lineendings, now there are a lot less changed lines :)

suve commented 1 week ago

Why create a separate commit? Please amend the original one, instead.

Looking through the PR, this creates an SDL_DYNAMIC_LINKING define which changes all function definitions to a pair of typedef + function pointer. The idea's simple, but it creates a lot of extra churn in the code, to the point where I'm wondering if it'd make sense to store the definitions in some templated form and have a program generate the final .pas/.inc files.

Another thing is that the nomenclature is wrong - dynamic linking is what we're doing right now. This switches the library to runtime loading.

PascalCorpsman commented 1 week ago

sry i do not know how to amend a commit.

if i rename

{.$DEFINE SDL_DYNAMIC_LINKING}

to

{.$DEFINE SDL_RUNTIME_LOADING}

then we solved the nomenclature thing.

Your point according the "Churn" thing is surely right, but maybe this should be part of work after you merged the PR ?

Free-Pascal-meets-SDL-Website commented 1 week ago

@PascalCorpsman May I ask, did you add all the ifdef's by hand? Or did you use some kind of a script?

Could you please change the function pointer suffixes to "func" instead of "fun". I mean, this library is fun indeed, but this suffix choice if just funny :D.

One thing I see as kind of a problem: To stay consistent in the future, merging this (without the proposed template solution) would force the project to add the ifdefs for all new definitions. On the other hand this is a "hot" feature and it may be worth it.

I'm also a little bit concerned about the pasdoc generator, it will not recognize the comments anymore, especially since pasdoc also has no groupBegin/groupEnd feature to my knowledge.

PascalCorpsman commented 6 days ago

May I ask, did you add all the ifdef's by hand? Or did you use some kind of a script? Lucky me, the code in the .inc files is really good structured, so i could do this with some easy string manipulation functions, and yes initially this was a program written in Lazarus, i only needed to adjust less than 10 functions by hand to get it compiled.

I attached the program, but be aware that this code is a complete mess, as it was created to run exactly once and then thrown away .. inc_converter.zip

Could you please change the function pointer suffixes to "func" instead of "fun". I mean, this library is fun indeed, but this suffix choice if just funny :D. did ;)

as i already suggested, if you come up with a good template solution this should be done, all i wanted to do, is showing how it could be done and that it is doable. And at least for my fpc_atomic project it already does the trick ;)