View mode: basic / threaded / horizontal-split · Log in · Help
August 09, 2011
PSP emulator written in D
Just found this. Seems pretty interesting. Anyone know more about the 
developer?

http://www.appleumbrella.com/2011/08/d-psp-emulator-svn-r306/

One thing I like is the use of CustomFloat for defining half-floating 
point numbers - one application I had in mind when defining CustomFloat. 
Glad to see it works (after the community fixed it :o)).


Andrei
August 09, 2011
Re: PSP emulator written in D
On 09.08.2011 17:13, Andrei Alexandrescu wrote:
> Just found this. Seems pretty interesting. Anyone know more about the
> developer?
>
> http://www.appleumbrella.com/2011/08/d-psp-emulator-svn-r306/
>
> One thing I like is the use of CustomFloat for defining half-floating
> point numbers - one application I had in mind when defining CustomFloat.
> Glad to see it works (after the community fixed it :o)).
>
>
> Andrei

Nice - is the code to find somewhere ??
August 09, 2011
Re: PSP emulator written in D
On Tue, 09 Aug 2011 17:31:05 +0200, Stephan wrote:

> On 09.08.2011 17:13, Andrei Alexandrescu wrote:
>> Just found this. Seems pretty interesting. Anyone know more about the
>> developer?
>>
>> http://www.appleumbrella.com/2011/08/d-psp-emulator-svn-r306/
>>
>> One thing I like is the use of CustomFloat for defining half-floating
>> point numbers - one application I had in mind when defining
>> CustomFloat. Glad to see it works (after the community fixed it :o)).
>>
>>
>> Andrei
> 
> Nice - is the code to find somewhere ??

http://code.google.com/p/pspemu/
August 09, 2011
Re: PSP emulator written in D
Lars T. Kyllingstad:

> http://code.google.com/p/pspemu/

Thank you for the link.

I think there is enough evidence that it is possible to use D (V.1) to write some video games. It's one of the very few niches where D has shown some more appreciation. So to blow on this tiny fire, do you know ways to improve the D2 language and D2 Phobos to help game development?

-----------------

Some comments on the source code:

The author seems to believe that the right way to name D modules is with a starting uppercase, like "Event.d".


In the modules I see a large amount of array appends (~=), the author maybe thinks those are efficient operations, as in C++ vectors.


To simulate a CPU computed gotos help performance. Interpreters are common, computed gotos are useful to run finite state machines too (and in computational biology I have had to build such machines. I have used computed gotos of GNU-C to speed up code).


This again shows that some common basic exceptions are needed in Phobos:
http://code.google.com/p/pspemu/source/browse/trunk/src/pspemu/Exceptions.d

-----------------

With the idea recently discussed this code:
http://code.google.com/p/pspemu/source/browse/trunk/src/pspemu/core/EmulatorState.d

this(Interrupts interrupts, Memory memory, IBattery battery,
    IDisplay display, Controller controller, Gpu gpu, Cpu cpu) {
   this.interrupts    = interrupts; 
   this.memory        = memory;
   this.battery       = battery;
   this.display       = display;
   this.controller    = controller;
   this.runningState  = runningState;
   this.gpu           = gpu;
   this.cpu           = cpu;

   resetVariables();
}


Becomes:

this(this.interrupts, this.memory, this.battery,
    this.display, this.controller, this.gpu, this.cpu) {
   this.runningState  = runningState;
   resetVariables();
}


This is not just shorter, it's more DRY and less bug-prone.

-----------------

This page:
http://code.google.com/p/pspemu/source/browse/trunk/src/pspemu/core/Memory.d

Contains code like:

class InvalidAddressException : public MemoryException {


I think that "public" needs to become a syntax error.

-----------------

This is bad code, I didn't even know D supports empty catch:


http://pspemu.googlecode.com/svn/trunk/src/pspemu/utils/Expression.d

static long parseString(string s, long default_value = 0) {
   if (s.length > 0) {
       try {
           ...
       } catch {
       }
   }
   return default_value;
}

-----------------

That asm code for the float[4] vectors are cute, unfortunately they kill inlining with DMD, so they often produce slower code:
http://pspemu.googlecode.com/svn/trunk/src/pspemu/utils/MathUtils.d

-----------------

This seems at home in Phobos too:
http://code.google.com/p/pspemu/source/browse/trunk/src/pspemu/utils/Types.d

Bye,
bearophile
August 09, 2011
Re: PSP emulator written in D
bearophile wrote:
> This is bad code, I didn't even know D supports empty catch:
>
>
> http://pspemu.googlecode.com/svn/trunk/src/pspemu/utils/Expression.d
>
> static long parseString(string s, long default_value = 0) {
>     if (s.length > 0) {
>         try {
>             ...
>         } catch {
>         }
>     }
>     return default_value;
> }

That he is using an empty catch is actually not too bad compared to the fact that
what he intends to catch is an AssertError from the preceding function, which is
an actual bug, not just bad practice.
August 10, 2011
Re: PSP emulator written in D
On Aug 10, 11 05:15, bearophile wrote:
> This again shows that some common basic exceptions are needed in Phobos:
> http://code.google.com/p/pspemu/source/browse/trunk/src/pspemu/Exceptions.d

These exceptions are not common or basic. I think it's better to make 
constructors inheritable when there are no new members, or add something 
like this to std.exception:

---------------
mixin template ExceptionConstructors() {
    this(string msg, string file = __FILE__, size_t line = __LINE__, 
Throwable next = null) {
        super(msg, file, line, next);
    }
    this(string msg, Throwable next, string file = __FILE__, size_t 
line = __LINE__) {
        super(msg, next, file, line);
    }
}
---------------

So those custom exceptions can be created as

class TimeoutException : Exception {
   mixin ExceptionConstructors;
}
August 10, 2011
Re: PSP emulator written in D
On 9/08/11 10:15 PM, bearophile wrote:
> So to blow on this tiny fire, do you know ways to improve the D2 language and D2 Phobos to help game development?

There's different levels of game developer. Indies will mostly want 
convenience, but AAA developers need control.

For example, a good vector + matrix + quaternion math library would be 
great for indies, but AAA developers would likely write their own, even 
if the library was highly optimised with SIMD, floatInVec etc.

SIMD intrinsics are obviously essential for AAA development.

The garbage collector is something that still needs work. My current 
project has several second stalls every once in a while due to the GC 
(indies might be happy to miss a frame or two (30-60ms) but AAA 
developers won't, so you either don't use the GC, or it has to collect 
in under a couple of ms).

I managed to remove all my per-frame allocations, but this was not easy. 
I had to modify my druntime to print out when allocations where 
happening to find them (most were those static array initialisations 
that I often talk about).

Of course, having libraries available for audio/image 
loading/manipulation is helpful, and bindings for OpenGL etc. but those 
are already available through Derelict. I don't think they need to be in 
Phobos.

The most important thing at the moment is just to get the language into 
a usable state and to get all the advertised features working. We also 
need more tutorials and resources to explain the subtler parts of D2 
(e.g. when, why and how template alias parameters work).
August 10, 2011
Re: PSP emulator written in D
Peter Alexander:

>There's different levels of game developer. Indies will mostly want convenience, but AAA developers need control.<

Right. Both groups are important.


>For example, a good vector + matrix + quaternion math library would be great for indies, but AAA developers would likely write their own, even if the library was highly optimised with SIMD, floatInVec etc.<

A 2D/3D/4D vector is good to have in Phobos. (Quaternion are optional).


>SIMD intrinsics are obviously essential for AAA development.<

The problem is they change as time goes. So instead of adding a ton of those (ugly) intrinsics, I suggest to add a meta-feature to D: a syntax to write inlin-able asm expressions (as present in LDC). With this syntax, SIMD intrinsics become library (even Phobos) code to standardize.


>I had to modify my druntime to print out when allocations where happening to find them (most were those static array initialisations that I often talk about).<

This is useful. Why don't you create a patch that (when a specific compiler switch is on) lists at compile-time all heap allocations and closure allocations of a compilation unit?


>The most important thing at the moment is just to get the language into a usable state<

This will take time, and you can't rush it.

Thank you for the answers,
bye,
bearophile
August 10, 2011
Re: PSP emulator written in D
> The garbage collector is something that still needs work. My current  
> project has several second stalls every once in a while due to the GC  
> (indies might be happy to miss a frame or two (30-60ms) but AAA  
> developers won't, so you either don't use the GC, or it has to collect  
> in under a couple of ms).

There already is a concurrent GC which might be of interest for you.
August 10, 2011
Re: PSP emulator written in D
KennyTM~:

> These exceptions are not common or basic.

You are right, sorry. I meant common ones like this:
http://d.puremagic.com/issues/show_bug.cgi?id=6410

Bye,
bearophile
« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home