schveiguy / raylib-d

Resurrected copy of onroundit's raylib-d
zlib License
57 stars 14 forks source link

unneserry imports hurt wasm compatibility #44

Closed crazymonkyyy closed 6 days ago

crazymonkyyy commented 12 months ago

for whatever reason wasm doesn't have c_long, so ive been hunting down those imports

reasing line 87; narrow to import core.stdc.math:sinf,cosf,sqrtf,powf;

raymathext line 4 import core.stdc.math:cos,sin,atan2,sqrt;

raygui line 17

alias c_long=long
alias c_ulong=ulong

theres probably others and my other modification may have moved the lines around

schveiguy commented 12 months ago

Is there a version I can use to only do this for WASM?

crazymonkyyy commented 12 months ago

I'm using this command in a lazily reargended folder ldc2 -I./raylib -c -betterC -mtriple=wasm32-unknown-unknown-wasm app.d to get the errors Im not going to be using dub since I have no reason to think it will be remotely easy to convince it to run enscription; but like some of my edits of "official style guide" approved; ill probably publish my raylib "fork" when I get a hello world running both locally and on wasm

crazymonkyyy commented 12 months ago

version

my hello world that works on both passed to a c compiler and dmd ... its hell honestly, wasmstd is going to be an ugly hack on ugly hack

version(D_BetterC){
    import wasmstd; 
    enum betterc=true;
    extern(C) void main()=>main_;
} else {
    import std;
    enum betterc=false;
    void main()=>main_;
}
void main_(){
    betterc.writeln;
    "hello".writeln;
}
schveiguy commented 12 months ago

Note that all the files are generated by dstep, so probably these "changes" would have to go in as manual steps (see the generating.md document)

crazymonkyyy commented 6 months ago

https://github.com/schveiguy/raylib-d/blob/07f79053b471efa674b20f1bee9e81edfb92eb58/source/raylib/raymathext.d#L5

template FieldNameTuple(T)
{
    static if (is(T == struct) || is(T == union))
        alias FieldNameTuple = staticMap!(NameOf, T.tupleof[0 .. $ - isNested!T]);
    else static if (is(T == class) || is(T == interface))
        alias FieldNameTuple = staticMap!(NameOf, T.tupleof);
    else
        alias FieldNameTuple = AliasSeq!"";
}
template staticMap(alias fun, args...)
{
    alias staticMap = AliasSeq!();
    static foreach (arg; args)
        staticMap = AliasSeq!(staticMap, fun!arg);
}

I think this is the only place phoboes is used, and this is very easy to replace code

schveiguy commented 1 week ago

Just looking at old issues. We removed the linear mixin, which took care of most of the need for FieldNameTuple

The only place it's now used is length and dot. I think I can probably just use a __traits call there, instead of relying on FieldNameTuple. But an easy fix is to just move the import inside the function. This does mean you will be left without length and dot, but you do have raylib equivalents...

Does this seem reasonable?

schveiguy commented 1 week ago

And also, these 2 places are only to build a mixin, so maybe it still will work?

schveiguy commented 6 days ago

@crazymonkyyy if you are still interested, try again. I moved all the imports inside the CTFE-only lambdas.

crazymonkyyy commented 6 days ago

Im giving up on focusing on wasm, maybe ill try a test when I make my next iteration of a raylib project, but its just to painful to have nothing, for a platform designed by idiots who broke file io while pretending they support unix.