digitalmars.D - Question regarding D v.0110
- Remi (12/36) Jul 11 2020 Hello all,
- aberba (2/3) Jul 11 2020 Not greater than or equal to?
- aberba (2/7) Jul 11 2020 Just a guess by the way
- Basile B. (4/18) Jul 11 2020 It's lesser, i.e "<". The code in itself looks like a
- rikki cattermole (5/10) Jul 11 2020 https://digitalmars.com/d/1.0/operatoroverloading.html#Binary
- Walter Bright (6/10) Jul 11 2020 Here's a truth table for it:
- aberba (5/8) Jul 11 2020 I checked some of the articles there and it seems some were not
- Remi (5/16) Jul 11 2020 That's great thanks! I didn't think of checking in that original
- Kagamin (2/6) Jul 11 2020 Undead package contains code from old phobos for such cases.
- Remi (3/9) Jul 11 2020 I did indeed get most of the code to compile with undead! Thanks
- Adam D. Ruppe (2/3) Jul 11 2020 it is really the same as bool
- Remi (4/7) Jul 11 2020 Thanks! It seems it was in an old SDL binding (1.x) and I
- Walter Bright (4/13) Jul 11 2020 BTW, your work updating it would make for a nice D Blog article. If acce...
- Remi (8/23) Jul 11 2020 I'll keep that in mind, it's not my game unfortunately and it's
- Adam D. Ruppe (6/10) Jul 11 2020 That would be the OMF format that D on Windows supports. It is
- Remi (8/19) Jul 12 2020 I got it work thanks! The problem was the way the extern(Windows)
- Mike Parker (3/8) Jul 12 2020 version(Win32) is version(Windows) these days.
- Adam D. Ruppe (11/17) Jul 12 2020 Use `extern(System)` in that case - it will be extern(Windows)
- Steven Schveighoffer (16/36) Jul 12 2020 It's probably not going to be bad, but it can be. If it finds a cycle,
- Patrick Schluter (5/16) Jul 12 2020 OMF is a bit older than windows or even Microsoft DOS. It goes
- Remi (11/50) Jul 13 2020 Thanks for the suggestions regarding the cyclic dependency, I
- Steven Schveighoffer (16/48) Jul 13 2020 This is slightly different. In the first case, rand is initialized even
- Remi (6/13) Jul 13 2020 Interesting, is that a language feature? I found the "shared
- Remi (3/19) Jul 13 2020 I tried and got the same runtime error regarding cycling
- Steven Schveighoffer (9/24) Jul 13 2020 The difference between shared and not-shared is that shared constructors...
- Remi (5/12) Jul 19 2020 I have now made it so it compiles, runs, doesn't depend on old
- Clarice (2/17) Jul 19 2020 I look forward to your writings!
Hello all, I found source code for an old game written in D, I'm talking circa 2004 here. It seems like it was written against D v0.110 according to the documentation I found. My project is to modernise it, maybe make it multiplatform, or even compile to wasm and browser based. But first, I'm trying to compile it as is and I found something odd.private void calcIndex(in float z, out int idx, out float ofs) { idx = slice.length + 99999; for (int i = 1; i < slice.length; i++) { if (z < slice[i].depth) { idx = i - 1; ofs = (z - slice[idx].depth) / (slice[idx + 1].depth - slice[idx].depth); break; } } if (idx < 0) { idx = 0; ofs = 0; } else if (idx >= slice.length - 1) { idx = slice.length - 2; ofs = 0.99; } if (ofs !>= 0) ofs = 0; else if (ofs >= 1) ofs = 0.99; }Trying to compile this, it complains about:Error: template argument expected following !This is from the line with "if (ofs !>= 0)". Would anyone know what this operator was for back in v0.110? I'm assuming it's been removed some time ago... Thanks, Remi.
Jul 11 2020
On Saturday, 11 July 2020 at 09:37:42 UTC, Remi wrote:This is from the line with "if (ofs !>= 0)".Not greater than or equal to?
Jul 11 2020
On Saturday, 11 July 2020 at 09:47:36 UTC, aberba wrote:On Saturday, 11 July 2020 at 09:37:42 UTC, Remi wrote:Just a guess by the wayThis is from the line with "if (ofs !>= 0)".Not greater than or equal to?
Jul 11 2020
On Saturday, 11 July 2020 at 09:37:42 UTC, Remi wrote:Hello all, I found source code for an old game written in D, I'm talking circa 2004 here. It seems like it was written against D v0.110 according to the documentation I found. My project is to modernise it, maybe make it multiplatform, or even compile to wasm and browser based. But first, I'm trying to compile it as is and I found something odd.It's lesser, i.e "<". The code in itself looks like a wrap(0.0,0.99). Maybe 0.99 and not 1 is because of FP comparison ?[...]Trying to compile this, it complains about:[...]This is from the line with "if (ofs !>= 0)". Would anyone know what this operator was for back in v0.110? I'm assuming it's been removed some time ago... Thanks, Remi.
Jul 11 2020
On 11/07/2020 9:37 PM, Remi wrote:This is from the line with "if (ofs !>= 0)". Would anyone know what this operator was for back in v0.110? I'm assuming it's been removed some time ago...https://digitalmars.com/d/1.0/operatoroverloading.html#Binary After hunting for dmd 0.110, it looks like it just means a < b for integrals. For floats it checks for NaN instead. http://ftp.digitalmars.com/dmd.110.zip
Jul 11 2020
On 7/11/2020 2:37 AM, Remi wrote:This is from the line with "if (ofs !>= 0)". Would anyone know what this operator was for back in v0.110? I'm assuming it's been removed some time ago...Here's a truth table for it: https://www.digitalmars.com/ctg/ctgNumerics.html#comparisons and !>= means "unordered or less than". Unordered means if one of the operands is a NaN. So, you can rewrite it as: if (std.math.isNaN(ofs) || ofs < 0)
Jul 11 2020
On Saturday, 11 July 2020 at 10:14:05 UTC, Walter Bright wrote:Here's a truth table for it: https://www.digitalmars.com/ctg/ctgNumerics.html#comparisons [...]I checked some of the articles there and it seems some were not ported to the new website. This one especially on memory management is very well articulated. https://digitalmars.com/d/2.0/memory.html#realtime
Jul 11 2020
On Saturday, 11 July 2020 at 10:14:05 UTC, Walter Bright wrote:On 7/11/2020 2:37 AM, Remi wrote:That's great thanks! I didn't think of checking in that original docs, duh! It now compiles the game code but not some dependencies, I'll need to resolve issues regarding the std it seems as I think that changed since then.This is from the line with "if (ofs !>= 0)". Would anyone know what this operator was for back in v0.110? I'm assuming it's been removed some time ago...Here's a truth table for it: https://www.digitalmars.com/ctg/ctgNumerics.html#comparisons and !>= means "unordered or less than". Unordered means if one of the operands is a NaN. So, you can rewrite it as: if (std.math.isNaN(ofs) || ofs < 0)
Jul 11 2020
On Saturday, 11 July 2020 at 10:42:20 UTC, Remi wrote:That's great thanks! I didn't think of checking in that original docs, duh! It now compiles the game code but not some dependencies, I'll need to resolve issues regarding the std it seems as I think that changed since then.Undead package contains code from old phobos for such cases.
Jul 11 2020
On Saturday, 11 July 2020 at 14:58:31 UTC, Kagamin wrote:On Saturday, 11 July 2020 at 10:42:20 UTC, Remi wrote:I did indeed get most of the code to compile with undead! Thanks for the pointer! I'm now trying to find docs on the "bit" type.That's great thanks! I didn't think of checking in that original docs, duh! It now compiles the game code but not some dependencies, I'll need to resolve issues regarding the std it seems as I think that changed since then.Undead package contains code from old phobos for such cases.
Jul 11 2020
On Saturday, 11 July 2020 at 16:18:52 UTC, Remi wrote:I'm now trying to find docs on the "bit" type.it is really the same as bool
Jul 11 2020
On Saturday, 11 July 2020 at 16:23:21 UTC, Adam D. Ruppe wrote:On Saturday, 11 July 2020 at 16:18:52 UTC, Remi wrote:Thanks! It seems it was in an old SDL binding (1.x) and I replaced it with SDL_bool, seems to have done the trick. It seems to have been useful in the past to make bitfields for example.I'm now trying to find docs on the "bit" type.it is really the same as bool
Jul 11 2020
On 7/11/2020 10:52 AM, Remi wrote:On Saturday, 11 July 2020 at 16:23:21 UTC, Adam D. Ruppe wrote:BTW, your work updating it would make for a nice D Blog article. If accepted, you'll even get paid! Also, if the license of the game permits it, please make it available on github.On Saturday, 11 July 2020 at 16:18:52 UTC, Remi wrote:Thanks! It seems it was in an old SDL binding (1.x) and I replaced it with SDL_bool, seems to have done the trick. It seems to have been useful in the past to make bitfields for example.I'm now trying to find docs on the "bit" type.it is really the same as bool
Jul 11 2020
On Saturday, 11 July 2020 at 20:17:40 UTC, Walter Bright wrote:On 7/11/2020 10:52 AM, Remi wrote:I'll keep that in mind, it's not my game unfortunately and it's pretty obscure but I'll try to get approval from the original author once I got it to work. Finally got everything to compile but having linking issues. The game came with .lib files but I have no idea what format they are, I assumed a Windows MSVC format but the VC tools don't seem to be able to read them.On Saturday, 11 July 2020 at 16:23:21 UTC, Adam D. Ruppe wrote:BTW, your work updating it would make for a nice D Blog article. If accepted, you'll even get paid! Also, if the license of the game permits it, please make it available on github.On Saturday, 11 July 2020 at 16:18:52 UTC, Remi wrote:Thanks! It seems it was in an old SDL binding (1.x) and I replaced it with SDL_bool, seems to have done the trick. It seems to have been useful in the past to make bitfields for example.I'm now trying to find docs on the "bit" type.it is really the same as bool
Jul 11 2020
On Saturday, 11 July 2020 at 22:44:08 UTC, Remi wrote:Finally got everything to compile but having linking issues. The game came with .lib files but I have no idea what format they are, I assumed a Windows MSVC format but the VC tools don't seem to be able to read them.That would be the OMF format that D on Windows supports. It is old, think Windows 95, but dmd and the optlink program that comes with it on 32 bit windows still has the support code in there. idk if dub allows it, but if you just compile+link with dmd itself using `-m32` it should use it.
Jul 11 2020
On Saturday, 11 July 2020 at 23:00:29 UTC, Adam D. Ruppe wrote:On Saturday, 11 July 2020 at 22:44:08 UTC, Remi wrote:I got it work thanks! The problem was the way the extern(Windows) was selected as it was inside a version(Win32) which didn't seem to work. I just forced it to always use extern(Windows) for now until I need to make it work across platforms. Good news! Finally got a .exe and it seems to start running, but it has now detected a cyclic dependency between constructors/destructors. Time to dive more into the code itself!Finally got everything to compile but having linking issues. The game came with .lib files but I have no idea what format they are, I assumed a Windows MSVC format but the VC tools don't seem to be able to read them.That would be the OMF format that D on Windows supports. It is old, think Windows 95, but dmd and the optlink program that comes with it on 32 bit windows still has the support code in there. idk if dub allows it, but if you just compile+link with dmd itself using `-m32` it should use it.
Jul 12 2020
On Sunday, 12 July 2020 at 08:18:00 UTC, Remi wrote:I got it work thanks! The problem was the way the extern(Windows) was selected as it was inside a version(Win32) which didn't seem to work. I just forced it to always use extern(Windows) for now until I need to make it work across platforms.version(Win32) is version(Windows) these days. https://dlang.org/spec/version.html#predefined-versions
Jul 12 2020
On Sunday, 12 July 2020 at 08:18:00 UTC, Remi wrote:I just forced it to always use extern(Windows) for now until I need to make it work across platforms.Use `extern(System)` in that case - it will be extern(Windows) and windows and extern(C) elsewhere. Common enough case to be built into D.Good news! Finally got a .exe and it seems to start running, but it has now detected a cyclic dependency between constructors/destructors. Time to dive more into the code itself!You can disable that cycle check by just adding this global declaration somewhere to the file with the main function: ``` // enable cycles in static ctors extern(C) __gshared string[] rt_options = ["oncycle=ignore"]; ``` Then you can probably get it actually going!
Jul 12 2020
On 7/12/20 10:19 AM, Adam D. Ruppe wrote:On Sunday, 12 July 2020 at 08:18:00 UTC, Remi wrote:It's probably not going to be bad, but it can be. If it finds a cycle, it can't actually sort the ctors. This means that things could be run out of order, and if one static value depends on another, then you could have bad things happen. However, most static ctors don't really depend on other static data, so in that case, it would be fine. Another option to try is "oncycle=deprecate", which uses the old algorithm that was flawed. I should say though that the old algorithm, even though "old" may not be as old as the game, which means it still might not work right. Also, the old flawed algorithm changes the order of construction sometimes based on the order modules are passed to the compiler (hence the "flawed" part of it). Good luck! -SteveI just forced it to always use extern(Windows) for now until I need to make it work across platforms.Use `extern(System)` in that case - it will be extern(Windows) and windows and extern(C) elsewhere. Common enough case to be built into D.Good news! Finally got a .exe and it seems to start running, but it has now detected a cyclic dependency between constructors/destructors. Time to dive more into the code itself!You can disable that cycle check by just adding this global declaration somewhere to the file with the main function: ``` // enable cycles in static ctors extern(C) __gshared string[] rt_options = ["oncycle=ignore"]; ``` Then you can probably get it actually going!
Jul 12 2020
On Saturday, 11 July 2020 at 23:00:29 UTC, Adam D. Ruppe wrote:On Saturday, 11 July 2020 at 22:44:08 UTC, Remi wrote:OMF is a bit older than windows or even Microsoft DOS. It goes back to 8080 times in the 70s https://www.os2museum.com/wp/how-old-is-omf/ but dmd and the optlink program thatFinally got everything to compile but having linking issues. The game came with .lib files but I have no idea what format they are, I assumed a Windows MSVC format but the VC tools don't seem to be able to read them.That would be the OMF format that D on Windows supports. It is old, think Windows 95,comes with it on 32 bit windows still has the support code in there. idk if dub allows it, but if you just compile+link with dmd itself using `-m32` it should use it.
Jul 12 2020
Thanks for the suggestions regarding the cyclic dependency, I figured out a way to remove the cycles. It was mostly doing this in each class:class Foo { static Rand rand; public static this() { rand = new Rand; } public static void setRandSeed(long n) { rand.setSeed(n); } }which I replaced withclass Foo { static Rand rand; public static void setRandSeed(long n) { if (!rand) { rand = new Rand; } rand.setSeed(n); } }Simple and it works! On Saturday, 11 July 2020 at 20:17:40 UTC, Walter Bright wrote:On 7/11/2020 10:52 AM, Remi wrote:I finally got the game to run and I was able to play, up until it crashed. I think just that part of getting up to this point would make a good article. I've started writing a quick draft to see if that's what you'd expect. Where should I contact you regarding the blog post?On Saturday, 11 July 2020 at 16:23:21 UTC, Adam D. Ruppe wrote:BTW, your work updating it would make for a nice D Blog article. If accepted, you'll even get paid! Also, if the license of the game permits it, please make it available on github.On Saturday, 11 July 2020 at 16:18:52 UTC, Remi wrote:Thanks! It seems it was in an old SDL binding (1.x) and I replaced it with SDL_bool, seems to have done the trick. It seems to have been useful in the past to make bitfields for example.I'm now trying to find docs on the "bit" type.it is really the same as bool
Jul 13 2020
On 7/13/20 3:45 AM, Remi wrote:Thanks for the suggestions regarding the cyclic dependency, I figured out a way to remove the cycles. It was mostly doing this in each class:This is slightly different. In the first case, rand is initialized even if you don't call setRandSeed. A more correct approach: public static Rand rand() { static Rand result; if(result is null) result = new Rand; return result; } Though it depends on usage -- perhaps a Rand is useless without a seed set? As I suspected, the static ctor could easily be marked standalone (as in, it can't be part of a cycle, because it doesn't depend on any other module to run). This is quite frequently one of the biggest problems with D's static ctors. -Steveclass Foo { static Rand rand; public static this() { rand = new Rand; } public static void setRandSeed(long n) { rand.setSeed(n); } }which I replaced withclass Foo { static Rand rand; public static void setRandSeed(long n) { if (!rand) { rand = new Rand; } rand.setSeed(n); } }Simple and it works!
Jul 13 2020
On Monday, 13 July 2020 at 12:25:33 UTC, Steven Schveighoffer wrote:Though it depends on usage -- perhaps a Rand is useless without a seed set? As I suspected, the static ctor could easily be marked standalone (as in, it can't be part of a cycle, because it doesn't depend on any other module to run). This is quite frequently one of the biggest problems with D's static ctors. -SteveInteresting, is that a language feature? I found the "shared static constructors" in the documentation which I think could be used here and would achieve the same thing but might also be covered by cyclicity checks, do you know?
Jul 13 2020
On Monday, 13 July 2020 at 13:33:45 UTC, Remi wrote:On Monday, 13 July 2020 at 12:25:33 UTC, Steven Schveighoffer wrote:I tried and got the same runtime error regarding cycling dependencies between static constructors/destructors.Though it depends on usage -- perhaps a Rand is useless without a seed set? As I suspected, the static ctor could easily be marked standalone (as in, it can't be part of a cycle, because it doesn't depend on any other module to run). This is quite frequently one of the biggest problems with D's static ctors. -SteveInteresting, is that a language feature? I found the "shared static constructors" in the documentation which I think could be used here and would achieve the same thing but might also be covered by cyclicity checks, do you know?
Jul 13 2020
On 7/13/20 9:33 AM, Remi wrote:On Monday, 13 July 2020 at 12:25:33 UTC, Steven Schveighoffer wrote:The difference between shared and not-shared is that shared constructors run once per program, whereas non-shared constructors run once per thread. This is D1, so likely it's equivalent to running shared constructors. But it depends on whether there are multiple threads. There is no feature right now that allows you to mark a ctor as standalone. But the compiler will mark some of them as standalone if it can determine that it's that way. -SteveThough it depends on usage -- perhaps a Rand is useless without a seed set? As I suspected, the static ctor could easily be marked standalone (as in, it can't be part of a cycle, because it doesn't depend on any other module to run). This is quite frequently one of the biggest problems with D's static ctors.Interesting, is that a language feature? I found the "shared static constructors" in the documentation which I think could be used here and would achieve the same thing but might also be covered by cyclicity checks, do you know?
Jul 13 2020
On Saturday, 11 July 2020 at 09:37:42 UTC, Remi wrote:Hello all, I found source code for an old game written in D, I'm talking circa 2004 here. It seems like it was written against D v0.110 according to the documentation I found. My project is to modernise it, maybe make it multiplatform, or even compile to wasm and browser based. But first, I'm trying to compile it as is and I found something odd.I have now made it so it compiles, runs, doesn't depend on old OMF .lib files (except one I can't replace yet). I have also started writing an article about it, it's already 2 parts, and a 3rd in the works hopefully soon. Thanks for all the help!
Jul 19 2020
On Sunday, 19 July 2020 at 13:37:30 UTC, Remi wrote:On Saturday, 11 July 2020 at 09:37:42 UTC, Remi wrote:I look forward to your writings!Hello all, I found source code for an old game written in D, I'm talking circa 2004 here. It seems like it was written against D v0.110 according to the documentation I found. My project is to modernise it, maybe make it multiplatform, or even compile to wasm and browser based. But first, I'm trying to compile it as is and I found something odd.I have now made it so it compiles, runs, doesn't depend on old OMF .lib files (except one I can't replace yet). I have also started writing an article about it, it's already 2 parts, and a 3rd in the works hopefully soon. Thanks for all the help!
Jul 19 2020