Still in the first week of GSoC, this blog is a record for a problem which confused me over day, and finally solved with help of sev
wish to write more blogs which can help me with the communication skills
let me describe more detailed here.
few day’s earlier, i was on a task about adding custom target to director
because for those games, seems like they have those info in those executables. e.g. game name, director version.
but for those movies which don’t have executables. such as Dictionary, we can only lanunch them by
--start-movie. they don’t save info which is needed.
previously, we put some special file like
D3-win into Dictionary to indicate their platform, director version.
But we won’t be able to save much info directly though that file name, which is not user friendly.
So here’s the goal of this task. Add more info into those special files which is created by us, and we use fallback detect to detect those files. We create a list called
custom target list and read info from those files. thus we can gain more than just platform and version.
Currently, we are putting 4 stuff into that file, platform, version, targetID and game name. Previously, in fallback detect, we need to return a struct which used to save info of the game. And that struct already has the slot for version and platform, but we don’t have slots for the targetID and game name. Thus, sev told me to extend that struct to save more info.
At first, i want to just extend the previous struct by using a method which is very similar to inheriting. We keep the head as the same and put extra info at the end. Thus we can easily cast the pointer from base struct to the extended one.
Then here comes another problem, director has already using this trick to save gameGID and version, which means, if we directly append extra info to the tail of base struct, then we will facing a problem that the tail will be different. One is for directorGameDescription, and the other is ExtendedGameDescription.
This problem really confused me a lot. I take nearly a day trying to figure out some approach to solve this. But finally failed.
I think there are two reason that i didn’t managed to solve this problem. one is the lack of experience. With more experience with those problems, i think i can tackle those thing easily.
And the second is that i don’t want to give up on that idea. I though that extending the existing struct by using that trick is good. I’m trapped into that framework. I want to solve that problem by using that idea, and didn’t even think about other approach. And that leads to my failure.
Later sev gave me another solution, which i think is more readable and extendable.
we can just extend that function with one more parameter which is a pointer point to that extra info.
If there are extra info, then fallback detect can allocate the resource and add extra info into it.
then we just need to check whether it’s nullptr or not, and handle the task of freeing that pointer.
with this approach, devs can read this code easily and extend the extra info structure with no non-sense efforts.
During this task, i learned not only the technical solutions, but also the disposition of mind as a dev.
Think about the question from the begining and the top level, don’t stick to one plan, and don’t let those tricks trap my mind.
We gather together here for creating something amazing.