www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Question regarding D v.0110

reply Remi <remigillig gmail.com> writes:
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
next sibling parent reply aberba <karabutaworld gmail.com> writes:
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
parent aberba <karabutaworld gmail.com> writes:
On Saturday, 11 July 2020 at 09:47:36 UTC, aberba wrote:
 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?
Just a guess by the way
Jul 11 2020
prev sibling next sibling parent Basile B. <b2.temp gmx.com> writes:
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.

  [...]
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.
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 ?
Jul 11 2020
prev sibling next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
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
prev sibling next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
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
next sibling parent aberba <karabutaworld gmail.com> writes:
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
prev sibling parent reply Remi <remigillig gmail.com> writes:
On Saturday, 11 July 2020 at 10:14:05 UTC, Walter Bright wrote:
 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)
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.
Jul 11 2020
parent reply Kagamin <spam here.lot> writes:
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
parent reply Remi <remigillig gmail.com> writes:
On Saturday, 11 July 2020 at 14:58:31 UTC, Kagamin wrote:
 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.
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.
Jul 11 2020
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
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
parent reply Remi <remigillig gmail.com> writes:
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:
 I'm now trying to find docs on the "bit" type.
it is really the same as bool
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.
Jul 11 2020
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 7/11/2020 10:52 AM, Remi wrote:
 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:
 I'm now trying to find docs on the "bit" type.
it is really the same as bool
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.
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.
Jul 11 2020
next sibling parent reply Remi <remigillig gmail.com> writes:
On Saturday, 11 July 2020 at 20:17:40 UTC, Walter Bright wrote:
 On 7/11/2020 10:52 AM, Remi wrote:
 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:
 I'm now trying to find docs on the "bit" type.
it is really the same as bool
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.
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.
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.
Jul 11 2020
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
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
next sibling parent reply Remi <remigillig gmail.com> writes:
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:
 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.
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!
Jul 12 2020
next sibling parent Mike Parker <aldacron gmail.com> writes:
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
prev sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
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
parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 7/12/20 10:19 AM, Adam D. Ruppe wrote:
 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!
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! -Steve
Jul 12 2020
prev sibling parent Patrick Schluter <Patrick.Schluter bbox.fr> writes:
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:
 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,
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 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
prev sibling parent reply Remi <remigillig gmail.com> writes:
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 with
class 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:
 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:
 I'm now trying to find docs on the "bit" type.
it is really the same as bool
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.
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.
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?
Jul 13 2020
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
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:
 
 class Foo
 {
     static Rand rand;
     public static this()
     {
         rand = new Rand;
     }
     public static void setRandSeed(long n)
     {
         rand.setSeed(n);
     }
 }
which I replaced with
 class Foo
 {
     static Rand rand;
     public static void setRandSeed(long n)
     {
         if (!rand)
         {
             rand = new Rand;
         }
         rand.setSeed(n);
     }
 }
Simple and it works!
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. -Steve
Jul 13 2020
parent reply Remi <remigillig gmail.com> writes:
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.

 -Steve
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
next sibling parent Remi <remigillig gmail.com> writes:
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:
 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.

 -Steve
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?
I tried and got the same runtime error regarding cycling dependencies between static constructors/destructors.
Jul 13 2020
prev sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 7/13/20 9:33 AM, Remi wrote:
 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.
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?
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. -Steve
Jul 13 2020
prev sibling parent reply Remi <remigillig gmail.com> writes:
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
parent Clarice <cl ar.ice> writes:
On Sunday, 19 July 2020 at 13:37:30 UTC, Remi wrote:
 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!
I look forward to your writings!
Jul 19 2020