Re: How do you print all Unicode characters in a range - I want the subscripts, can't google a range of Unicode.
The output will be bad because of Windows specific behavior related to not outputting as UTF-16. This will print all the characters in the block "Superscripts and Subscripts". The Unicode database is very out of date (just waiting for merge for update), but should be ok for this example. ``` import std.uni : unicode; import std.stdio : writefln; void main() { foreach(c; unicode.InSuperscriptsandSubscripts.byCodepoint) writefln!"U+%X = "(c, c); } ``` Unfortunately I'm not seeing an obvious way of determining subscript/superscript from what we have. You can do it with the help of[0] via Super/Sub field values, which originate from UnicodeData.txt's Decomposition_Type field, but you shouldn't parse that if you only want just this one set of values. [0] https://www.unicode.org/Public/15.0.0/ucd/extracted/DerivedDecompositionType.txt
How do you print all Unicode characters in a range - I want the subscripts, can't google a range of Unicode.
``` dstring s = ""; for (dchar i='ₐ'; i < 'ₜ'; i++) s ~= i; writeln(s); ``` Doesn't work. The result I get is shit: ΓéÉΓéæΓéÆΓéôΓéöΓéòΓéûΓéùΓéÿΓéÖΓéÜΓé¢
Re: Getting the default value of a class member field
You could potentially skip running the `@constructValue` lambdas in the ctor via `if (__ctfe)`, if skipping this extra init is acceptable for CTFE instances.
Re: Getting the default value of a class member field
On Friday, 2 December 2022 at 04:14:37 UTC, kinke wrote: [...] Such an instance should be CTFE-constructible, and the valid instance would feature the expected value for the `validUntil` field. [...] Oh well, that time-sensitive example clearly isn't CTFE-able. :D - If that's the primary use case for these `@constructValue` UDAs, then yeah, this makes things more complicated.
Re: Getting the default value of a class member field
On Friday, 2 December 2022 at 00:24:44 UTC, WebFreak001 wrote: I want to use the static initializers (when used with an UDA) as default values inside my SQL database. See https://github.com/rorm-orm/dorm/blob/a86c7856e71bbc18cd50a7a6f701c325a4746518/source/dorm/declarative/conversion.d#L959 With my current design it's not really possible to move it out of compile time to runtime because the type description I create there gets serialized and output for use in another program (the migrator). Right now it's simply taking the compile time struct I generate and just dumping it without modification into a JSON serializer. [...] Okay, so what's blocking CTFE construction of these models? AFAICT, you have a templated base constructor in `Model`, which runs an optional `@constructValue!(() => Clock.currTime + 4.hours)` lambda UDA for all fields of the derived type. Can't you replace all of that with a default ctor in the derived type? ``` class MyModel : Model { int x = 123;// statically initialized SysTime validUntil; // dynamically initialized in ctor this() { validUntil = Clock.currTime + 4.hours; } } ``` Such an instance should be CTFE-constructible, and the valid instance would feature the expected value for the `validUntil` field. If you need to know about such dynamically generated fields (as e.g. here in this time-critical example), an option would be a `@dynamicallyInitialized` UDA. Then if you additionally need to be able to re-run these current `@constructValue` lambdas for an already constructed instance, you could probably go with creating a fresh new instance and copying over the fresh new field values.
Re: raylib-d Gamepad Detection Fails
On 12/1/22 5:50 PM, jwatson-CO-edu wrote: On Thursday, 1 December 2022 at 22:16:30 UTC, jwatson-CO-edu wrote: That was the trick, [inside the loop it detects the gamepad](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d#L35). No other changes needed. I have a new problem: Raylib-d [can see all 6 gamepad axes](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d#L44). However, they [all return 0](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d#L48) for all stick motion. Do I need to initialize the gamepad somehow? Looking at the example posted by ryuukk, you shouldn't have to. Does it detect the buttons? Does your gamepad actually have analog sticks? Do all 6 axes show no movement? I don't see anything inherently wrong with your code. I also don't have a gamepad to try with, plus even if I did, it's possible my setup would work while yours doesn't. It's important to remember that raylib-d doesn't do any special things with the raylib functions -- they are just straight calls into the library. -Steve
Re: Getting the default value of a class member field
On Thursday, 1 December 2022 at 23:02:31 UTC, kinke wrote: On Thursday, 1 December 2022 at 08:09:05 UTC, WebFreak001 wrote: [...] AFAIK, there is no way. Unlike a struct's init symbol, a class' one doesn't necessarily represent a valid instance state - it's just the raw payload before invoking a ctor (which constructs a valid instance), and the state 'dead' memory is reset to after finalizing an object instance (to prevent dead pointers keeping other GC refs alive). If the ctor worked at CTFE, one could use: ```d int get() { scope x = new X; return x.x; } enum bla = get(); ``` to get the `x` value of a *valid* instance, which might be different than the static initializer (if modified in the ctor). I guess the main question is why do you require the static initializers of these fields at compile-time. `__traits(initSymbol)` was added to aid in manual blitting at runtime. I want to use the static initializers (when used with an UDA) as default values inside my SQL database. See https://github.com/rorm-orm/dorm/blob/a86c7856e71bbc18cd50a7a6f701c325a4746518/source/dorm/declarative/conversion.d#L959 With my current design it's not really possible to move it out of compile time to runtime because the type description I create there gets serialized and output for use in another program (the migrator). Right now it's simply taking the compile time struct I generate and just dumping it without modification into a JSON serializer. I might be abusing classes a little bit here, but they provide the easiest way to do a variety of things: - `is(T : Model)` and especially type specialization like `void foo(T : Model)(T x)` is much easier to write and use - it basically allows me to inject methods into my type (using template parameter `this This` I can even get my real type) - it's the most easy and pretty to type for the user. A struct with `mixin Model` would be quite verbose imo and doesn't allow Model to define custom fields easily, because they would break the implicitly generated constructor
Re: raylib-d Create Light Sources
On Thursday, 1 December 2022 at 01:17:16 UTC, Steven Schveighoffer wrote: On 11/30/22 7:56 PM, jwatson-CO-edu wrote: uint MAX_LIGHTS = 4; The rlights header file is not part of the raylib library, but is in the examples directory, you will need to port it. It's not very big, you probably can do it in a half hour. https://github.com/raysan5/raylib/blob/387c06000618ef0aa3b15c5e46d1c525ba194c50/examples/shaders/rlights.h -Steve [This seems to work](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/06_gliderShaded/source/rlights.d), in case anyone else wanted to do lighting in this way.
Re: Getting the default value of a class member field
On Thursday, 1 December 2022 at 08:09:05 UTC, WebFreak001 wrote: I've got this class definition: ```d class X { this() { assert(false); } int x = 3; } ``` due to internal reasons the constructor would fail at compile time, so I put in an assert(false) here, and I can't add or change any methods in X. How do I get `3` if I have `X` and field name `"x"` at compile time? For structs `X.init.x` / `__traits(getMember, X.init, "x")` would work, however for classes it complains about null dereference. I saw there is __traits(initSymbol), however that one doesn't work at compile time. AFAIK, there is no way. Unlike a struct's init symbol, a class' one doesn't necessarily represent a valid instance state - it's just the raw payload before invoking a ctor (which constructs a valid instance), and the state 'dead' memory is reset to after finalizing an object instance (to prevent dead pointers keeping other GC refs alive). If the ctor worked at CTFE, one could use: ```d int get() { scope x = new X; return x.x; } enum bla = get(); ``` to get the `x` value of a *valid* instance, which might be different than the static initializer (if modified in the ctor). I guess the main question is why do you require the static initializers of these fields at compile-time. `__traits(initSymbol)` was added to aid in manual blitting at runtime.
Re: raylib-d Gamepad Detection Fails
On Thursday, 1 December 2022 at 22:16:30 UTC, jwatson-CO-edu wrote: That was the trick, [inside the loop it detects the gamepad](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d#L35). No other changes needed. I have a new problem: Raylib-d [can see all 6 gamepad axes](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d#L44). However, they [all return 0](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d#L48) for all stick motion. Do I need to initialize the gamepad somehow?
Re: raylib-d Gamepad Detection Fails
On Thursday, 1 December 2022 at 15:35:37 UTC, Steven Schveighoffer wrote: On 12/1/22 3:24 AM, bauss wrote: But probably not on every frame, have a delay between checks. It's not anything controllable by the user. The library does the check every frame regardless of whether you use it or not. When you call the raylib function, you are not actually querying the device, you are checking a boolean in a struct. https://github.com/raysan5/raylib/blob/387c06000618ef0aa3b15c5e46d1c525ba194c50/src/rcore.c#L3567 -Steve Oh yeah then it's fine :)
Re: raylib-d Gamepad Detection Fails
On Thursday, 1 December 2022 at 21:34:41 UTC, Steven Schveighoffer wrote: On 12/1/22 11:10 AM, ryuukk_ wrote: Can you try with this page: https://www.raylib.com/examples/core/loader.html?name=core_input_gamepad Does it detect your gamepad? It should work because the `IsGamepadAvailable` function call is inside the loop. That's most certainly the problem with the OP code. -Steve That was the trick, [inside the loop it detects the gamepad](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d#L35). No other changes needed.
Re: raylib-d Gamepad Detection Fails
On 12/1/22 11:10 AM, ryuukk_ wrote: Can you try with this page: https://www.raylib.com/examples/core/loader.html?name=core_input_gamepad Does it detect your gamepad? It should work because the `IsGamepadAvailable` function call is inside the loop. That's most certainly the problem with the OP code. -Steve
Re: raylib-d Gamepad Detection Fails
On Thursday, 1 December 2022 at 01:49:09 UTC, jwatson-CO-edu wrote: On Thursday, 1 December 2022 at 01:12:17 UTC, Steven Schveighoffer wrote: On 11/30/22 7:28 PM, jwatson-CO-edu wrote: On Wednesday, 30 November 2022 at 23:18:33 UTC, ryuukk_ wrote: On Wednesday, 30 November 2022 at 22:46:52 UTC, jwatson-CO-edu wrote: Hello, I have this small [gamepad input test program](https://github.com/jwatson-CO-edu/nanoverse/blob/main/d/raylib/04_jsInput/source/app.d). Which OS and wich controllers are you using? You might want to open an issue on the raylib-d repo: https://github.com/schveiguy/raylib-d/issues I tested on Ubuntu 22.04 and Linux Mint 20 with an older GameSir brand wired XBox controller. Built with Raylib 2.4.0 and raylib-d 2.4.1. I know that the author monitors the forum. So, I will open an issue if he does not point out something obvious that I missed. Do you have that version correct? I'm assuming you mean raylib 4.2.0 and raylib-d 4.2.1? Highly recommend to update to raylib-d 4.2.4, and use the the Linux raylib-d:install as that now works (and will properly grab the correct raylib library from the repository for you). -Steve Yes, following your instructions I have raylib 4.2.0 and raylib-d 4.2.4 in the project directory. I am now using the latest version of raylib-d, but this did not resolve the gamepad issue. I can ask around on the raylib channels. Can you try with this page: https://www.raylib.com/examples/core/loader.html?name=core_input_gamepad Does it detect your gamepad?
Re: raylib-d Gamepad Detection Fails
On 12/1/22 3:24 AM, bauss wrote: But probably not on every frame, have a delay between checks. It's not anything controllable by the user. The library does the check every frame regardless of whether you use it or not. When you call the raylib function, you are not actually querying the device, you are checking a boolean in a struct. https://github.com/raysan5/raylib/blob/387c06000618ef0aa3b15c5e46d1c525ba194c50/src/rcore.c#L3567 -Steve
Re: raylib-d Gamepad Detection Fails
On Thursday, 1 December 2022 at 02:06:43 UTC, Steven Schveighoffer wrote: On 11/30/22 8:49 PM, jwatson-CO-edu wrote: Yes, following your instructions I have raylib 4.2.0 and raylib-d 4.2.4 in the project directory. I am now using the latest version of raylib-d, but this did not resolve the gamepad issue. I can ask around on the raylib channels. Oh, I think I know the issue -- you need to check inside the loop. The way raylib works is that it polls events from the glfw library. So unless you are actually calling `BeginDrawing` and `EndDrawing`, those flags won't change. -Steve But probably not on every frame, have a delay between checks.
Getting the default value of a class member field
I've got this class definition: ```d class X { this() { assert(false); } int x = 3; } ``` due to internal reasons the constructor would fail at compile time, so I put in an assert(false) here, and I can't add or change any methods in X. How do I get `3` if I have `X` and field name `"x"` at compile time? For structs `X.init.x` / `__traits(getMember, X.init, "x")` would work, however for classes it complains about null dereference. I saw there is __traits(initSymbol), however that one doesn't work at compile time.