Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split chunkMesh to ChunkMeshImpl #4893

Merged
merged 14 commits into from
Nov 8, 2021

Conversation

pollend
Copy link
Member

@pollend pollend commented Sep 6, 2021

This introduces an interface for ChunkMesh. should let us mock in the interface when we want to test some rendering code and other graphics API's down the line. still not sure about some of these methods that I'm keeping in the interface. I want to move some of this metric information somewhere else but that is something to consider later.

PR: #4786

@github-actions github-actions bot added the Type: Chore Request for or implementation of maintenance changes label Sep 6, 2021
@pollend pollend requested a review from keturn September 6, 2021 15:08
@pollend pollend changed the title chore: split chunkMesh to ChunkMeshImpl refactor: split chunkMesh to ChunkMeshImpl Sep 7, 2021
Copy link
Member

@keturn keturn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few quick notes so far. I hope to give it another look later.

Coming from Python, the practice of making an Interface/Class separation purely for the purpose of internal tests always feels weird. We'd just 🦆-type it in Python, right? So I end up second-guessing this sort of thing, even though I often do prefer it to Mockito.

I notice you did add a HeadlessChunkMesh implementation of the interface. Is that something a headless server will use? Or does the HeadlessGraphics subsystem already skip over all the engine.rendering.* stuff?

@pollend
Copy link
Member Author

pollend commented Sep 9, 2021

A few quick notes so far. I hope to give it another look later.

Coming from Python, the practice of making an Interface/Class separation purely for the purpose of internal tests always feels weird. We'd just duck-type it in Python, right? So I end up second-guessing this sort of thing, even though I often do prefer it to Mockito.

I notice you did add a HeadlessChunkMesh implementation of the interface. Is that something a headless server will use? Or does the HeadlessGraphics subsystem already skip over all the engine.rendering.* stuff?

I don't think we need the headlesssChunkMesh will just creating a mock object from the interface.

@DarkWeird
Copy link
Contributor

I prefer to implement test object over interface than use mockito:

  1. Mockito add duration around 200-500ms to every test with using mockito.
  2. I think that if you should use mockito - you have architecture problem.
  3. Copy pasted mockito code from test to test(also feels noisy)

@github-actions github-actions bot added the Type: Refactoring Request for or implementation of pure and automatic refactorings, e.g. renaming, to improve clarity label Sep 9, 2021
@pollend pollend requested a review from keturn September 11, 2021 02:58
@pollend pollend requested a review from keturn September 19, 2021 18:30
@keturn keturn dismissed their stale review September 25, 2021 19:14

javadoc did get fixed

@pollend
Copy link
Member Author

pollend commented Oct 3, 2021

@keturn we probably want to keep the chunk mesh hook. it will be used for this: Terasology/FallingBlocks#9

@keturn
Copy link
Member

keturn commented Oct 5, 2021

we probably want to keep the chunk mesh hook. it will be used for this: Terasology/FallingBlocks#9

How is that related to ChunkMesh.disposalHook? The FallingBlocks PR was a bit too big to look at in github web, but I checked it out and searched for "disposal" (or "dispose") in that branch and came up empty.

If we do have a use case for disposalHook, that's fine, but my question from earlier still stands: Can we get rid of the code duplication between ChunkMeshImpl.dispose and ChunkMeshImpl.disposalHook().dispose(), or are my sleepy eyes reading it wrong and it's not actually a duplication?

@pollend
Copy link
Member Author

pollend commented Oct 5, 2021

we probably want to keep the chunk mesh hook. it will be used for this: Terasology/FallingBlocks#9

How is that related to ChunkMesh.disposalHook? The FallingBlocks PR was a bit too big to look at in github web, but I checked it out and searched for "disposal" (or "dispose") in that branch and came up empty.

If we do have a use case for disposalHook, that's fine, but my question from earlier still stands: Can we get rid of the code duplication between ChunkMeshImpl.dispose and ChunkMeshImpl.disposalHook().dispose(), or are my sleepy eyes reading it wrong and it's not actually a duplication?

its for the chunkMeshComponent where that hook is used.. the disposal hook is just for this edge case introduced by this chunkMeshComponent stuff

@keturn
Copy link
Member

keturn commented Oct 5, 2021

Used where?

@Replicate
public ChunkMesh mesh;
@Replicate
public AABBf aabb;
@Replicate
public boolean animated = true;
public ChunkMeshComponent() { }
public ChunkMeshComponent(ChunkMesh mesh, AABBf aabb) {
this.mesh = mesh;
this.aabb = aabb;
}

@keturn
Copy link
Member

keturn commented Oct 5, 2021

ah, the pointer to ChunkMeshRenderer system helped, thank you.

This system is already defining an onDestroyMesh lifecycle handler for the component. Why do we need to do this reference-tracking stuff instead of doing disposal there?

If we can't use normal component lifecycle events, could we at least make this a WeakReference instead of a PhantomReference, so we can call the normal dispose method on the reference?

(Please include the answers to both of the above in ChunkMeshRenderer's javadoc.)

If we do have a use case for disposalHook, that's fine, but my question from earlier still stands: Can we get rid of the code duplication between ChunkMeshImpl.dispose and ChunkMeshImpl.disposalHook().dispose(), or are my sleepy eyes reading it wrong and it's not actually a duplication?

@pollend
Copy link
Member Author

pollend commented Oct 6, 2021

ah, the pointer to ChunkMeshRenderer system helped, thank you.

This system is already defining an onDestroyMesh lifecycle handler for the component. Why do we need to do this reference-tracking stuff instead of doing disposal there?

If we can't use normal component lifecycle events, could we at least make this a WeakReference instead of a PhantomReference, so we can call the normal dispose method on the reference?

(Please include the answers to both of the above in ChunkMeshRenderer's javadoc.)

If we do have a use case for disposalHook, that's fine, but my question from earlier still stands: Can we get rid of the code duplication between ChunkMeshImpl.dispose and ChunkMeshImpl.disposalHook().dispose(), or are my sleepy eyes reading it wrong and it's not actually a duplication?

better to just keep it simple. I just moved it to use the normal events to drive disposing chunks.

keturn
keturn previously approved these changes Oct 16, 2021
Copy link
Member

@keturn keturn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just moved it to use the normal events to drive disposing chunks.

That does look a lot simpler for the Renderer as well as the dispose method!

CheckStyle has a few notes for you that you may want to address before merging this. I recommend turning on IntelliJ's “optimize imports on the fly“ setting—or, if you don't like it doing stuff on the fly, at least the “optimize imports“ option in the “before commit“ section.

pollend and others added 3 commits November 7, 2021 08:21
…esh-into-implementation

# Conflicts:
#	engine/src/main/java/org/terasology/engine/rendering/logic/ChunkMeshRenderer.java
Copy link
Member

@keturn keturn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I think that's everything! And checks pass and I can still see chunks in game. Although I did run out of RAM pretty quickly this run.

How would I know if things weren't getting disposed of as they should?

@keturn keturn merged commit 85d0f0f into develop Nov 8, 2021
@keturn keturn deleted the chore/split-ChunkMesh-into-implementation branch November 8, 2021 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Chore Request for or implementation of maintenance changes Type: Refactoring Request for or implementation of pure and automatic refactorings, e.g. renaming, to improve clarity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants