Variadic and template specializations for serialize and deserialize#498
Variadic and template specializations for serialize and deserialize#498Sebanisu wants to merge 4 commits into
Conversation
|
One other way we could of done this is the move the serialize code into member functions of each component. Then we just call that. Though This seemed more in line with how you were already doing stuff. |
43577e5 to
42f41d6
Compare
|
I just merged the upstream/master into my branch as it was several months old. I wanted to make sure stuff was still working. 6e309d4 I noticed
|
|
This pull request was originally on dev and now on it's master. Some of the changes in my pull request are from dev. There was one commit I accidentally reverted. So I had a revert revert. 7b19ce5 |
I split the serialize and deserialize functions into template specializations. Then I used the `AllComponents{}` variadic templates to call each of the templated specializations. The catch all / default function is deleted so you get a compile time error if you forgot to handle one of the Components.
add tag to Serialize All.
add comments
add static
Correct spelling mistake
Added CircleCollider2DComponent to SerializeEntityComponent and DeserializeEntryComponent Added `GetPath()` to `Texture` and `OpenGLTexture` Added TextureExample.hazel
7b19ce5 to
73d478e
Compare
|
I cherry picked my commits and reset this branch so I no longer have anything from the dev branch in my pull request. |
|
Cherno added TexturePath and Tiling Factor. |
ff8f5ff to
d6336c6
Compare
delete duplicate GetPath() The example isn't really needed to pull request. Cherno has his own.
d6336c6 to
44ea684
Compare
Describe the issue (if no issue has been made)
Serialize and Deserialize were 2 large functions. I thought it might become hard to manage.
Proposed fix
This gives you a separate function for each component, for both serializing and deserializing. I grouped them by
Componentand placed them at the bottom ofSceneSerializer.cpp. The default catch all case is deleted so if you add a newComponenttoAllComponentsthen you will get a compile time error. So you know what you forgot and can fix it.Hazel/Hazel/src/Hazel/Scene/SceneSerializer.cpp
Lines 234 to 238 in 73d478e
PR impact (Make sure to add closing keywords)
List of related issues/PRs this will solve:
I took a different approach than the previous ideas I had in #496. Instead of changing
AllComponents, I altered my function to accept more template arguments. So this way we are serializingTagComponent.Hazel/Hazel/src/Hazel/Scene/SceneSerializer.cpp
Lines 515 to 547 in 73d478e
TagComponentis deserialized on creation of an entity. So we only need it for serialization.Hazel/Hazel/src/Hazel/Scene/SceneSerializer.cpp
Lines 208 to 213 in 73d478e
Additional context
Add any other context about the solution here. Did you test the solution on all (relevant) platforms?
I tested on Windows 10, with a Nvidia 980 TI.
We don't serialize with
NativeScriptComponent. I just put a TODO there maybe we can serialize it in the future.Hazel/Hazel/src/Hazel/Scene/SceneSerializer.cpp
Lines 503 to 513 in 73d478e
CircleCollider2DComponent was missing from my original commit:
Hazel/Hazel/src/Hazel/Scene/SceneSerializer.cpp
Lines 466 to 501 in 73d478e
Cherno fixed this on his stream as well. So I just had to fix the merge conflicts.
Texture wasn't being serialized #561:
Added
GetPath()Hazel/Hazel/src/Hazel/Renderer/Texture.h
Line 17 in 73d478e
Hazel/Hazel/src/Platform/OpenGL/OpenGLTexture.h
Line 19 in 73d478e
Serialize TexturePath:
Hazel/Hazel/src/Hazel/Scene/SceneSerializer.cpp
Lines 340 to 373 in 73d478e