3 ms·
In my first attempt at a PlayStation emulator I did something similar to what you describe, with the shared state in a separate struct that's passed around and
by simias 7y ago
In my first attempt at a PlayStation emulator I did something similar to what you describe, with the shared state in a separate struct that's passed around and the rest of the code embedded in member function for the various GPU, CPU, SPU and other classes.
In the end I found that it was more trouble that was worth. I didn't feel like it made the code significantly clearer and if you realized later on that something actually ought to be shared between two modules it required a ton of refactoring.
Also having everything in a single struct that's passed everywhere can make debugging slightly easier. For instance if I encounter a situation where some bogus command is sent to the GPU I catch it in the GPU code and dump the CPU state right there instead of having to notify the condition upstream and add some hook in the higher layers to handle the CPU dumping for instance.
It's probably not the most elegant solution but I find it simple and rather effective.
- rightbyte 7y agoYe I agree. Copying a state to not make the memory shared when the actual data is rw shared (all modules should have the same conception of what the state is) seems quite pointless. I guess a pointer to const get function and a pointer to non-const get function would suffice for making it clear which modules could manipulate it.