How would I adapt the hot reloading technique used in HmH to an online game where I want to be able to have two instances of the game running at once in the same machine? As I understand it, the hot reloading worked by copying the main dll of the game into temp.dll at startup, and then when you detect that the main dll changed, unload temp.dll, overwrite it with the new main dll, and load it again. Of course, this doesn't work with two instances running at once, because the first one to try to replace temp.dll will be unable to do so because the other one is still using it.
The simplest solution I can imagine is this:
- When you try to overwrite temp.dll, allow failure. In that case, keep trying regularly, and also check if temp.dll's last edited time is after the last edited time of the original dll (that means someone else has overwritten it). Don't try to call the dll's procedures (the game code) until you've overwritten temp.dll succeessfully, or temp.dll's last edited time is higher than the original dll's, and loaded temp.dll successfully.
Is this solution reasonable or is there a simpler/better way of doing this?
If loading the dll loads it into memory, I think the API should allow deleting/overwriting the dll file after that. I understand that assuming that the file won't change simplifies loading the same dll multiple times in one process, but I don't see why they can't allow telling the API "hey, I won't be loading this in multiple threads of this process, so just forget about the file".