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

Further abstraction of the dependency system for non-cube dependents and bugfixing of the dependency system #18

Merged
merged 24 commits into from
Jun 17, 2016

Conversation

Cyclonit
Copy link
Collaborator

@Cyclonit Cyclonit commented Jun 6, 2016

The 2d visualization code you posted does not show any unloading of cubes. However, I did make the ServerCubeCache log whenever it unloaded a cube (and loaded) and it did appear to act properly. I couldn't find any cubes not being unloaded after moving 1000 blocks to the north. One issue remaining is the world not showing up on the first generation. Saving the game and reloading solves the problem.

@@ -24,6 +24,8 @@
package cubicchunks.server;

import com.google.common.collect.Maps;

import cubicchunks.CubeProviderDebug;
Copy link
Member

Choose a reason for hiding this comment

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

Make sure to remove this before commit, it breaks the build

@Barteks2x
Copy link
Member

Which world type did you test it with? I think I've seen some columns being left loaded as I'm moving, see #11.

Also, this issue needs fixing: #14

@Cyclonit
Copy link
Collaborator Author

Cyclonit commented Jun 6, 2016

I tested using Custom Cubic.

@Barteks2x
Copy link
Member

Barteks2x commented Jun 6, 2016

Just squash all of these small commits... this is getting a bit too messy. And undo formatting changes in CubeIO, at some point my IDE will undo your changes, and it will cause just a lot of pointless changes. (this may be useful to read if you don't know what it means)

@Cyclonit
Copy link
Collaborator Author

Cyclonit commented Jun 6, 2016

I'll clean it up asap. I managed to confuse origin/upstream and master/dependency, leading to a jambled mess... Sorry

@@ -95,7 +95,7 @@ private static DB initializeDBConnection(final File saveFile, final WorldProvide

file.getParentFile().mkdirs();

DB db = DBMaker.fileDB(file).transactionEnable().make();
DB db = DBMaker.fileDB(file).make();
Copy link
Member

Choose a reason for hiding this comment

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

transactions should be enabled

@Cyclonit Cyclonit force-pushed the dependency branch 2 times, most recently from 5fb2a97 to f03fcf1 Compare June 6, 2016 21:21
- Trying to fix git synchronization issues... sorry

- Trying to fix git synchronization issues... sorry

- Fixed cubes not appearing on first world load (by reverting change to ServerCubeCache)

- Removed unnecessary imports.
- Trying to fix git synchronization issues... sorry

- Trying to fix git synchronization issues... sorry

- Fixed cubes not appearing on first world load (by reverting change to ServerCubeCache)

- Removed unnecessary imports.
@Barteks2x
Copy link
Member

I would also really suggest switching to IntelliJ IDEA, at least for this project. This way you will avois almost all formatting changes.

- Extracted interface Dependent and renamed former class to DependentCube in preparation for allowing non-cube dependents.
… DependentCube in preparation for permitting generic dependent entities.

- Reverted changes to RegionDependency to use a singleton instead.
- Removed explicit type declarations.
… DependentCube in preparation for permitting generic dependent entities.

- Reverted changes to RegionDependency to use a singleton instead.
- Removed explicit type declarations.
@Cyclonit
Copy link
Collaborator Author

Cyclonit commented Jun 7, 2016

I have changed to IDEA, but I cannot guarantee an immediate improvement with regards to formatting as it is driving me nuts D:

@Barteks2x
Copy link
Member

Barteks2x commented Jun 7, 2016

Just import my formatter settings. This way you will have exactly the same settings = no difference.

}

public RegionDependency(Cube cube, GeneratorStage stage, int xLow, int xHigh, int yLow, int yHigh, int zLow, int zHigh) {
public RegionDependency(GeneratorStage targetStage, int xLow, int xHigh, int yLow, int yHigh, int zLow, int zHigh) {
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest using Vec3is instead of ints here, argument order isn't obvious from code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you have any naming in mind? "lowerFrontLeft" and "upperBackRight" sound kinda wrong...

Copy link
Member

Choose a reason for hiding this comment

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

startPosition and endPosition? You can sort them in constructor.

…stead of individual integers.

- Added todos to several classes.
CubeCoords coords = new CubeCoords(cube.getX() + x, cube.getY() + y, cube.getZ() + z);
if (!cache.cubeExists(coords) || cache.getCube(coords).getCurrentStage().precedes(generatorStage)) {
CubicChunks.LOGGER.error("Missing cube ({})! {}/{}", coords, cache.getCube(coords).getCurrentStage().getName(), generatorStage.getName());
System.exit(1);
Copy link
Member

@Barteks2x Barteks2x Jun 14, 2016

Choose a reason for hiding this comment

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

  1. Never use System.exit(), or Forge will show a big warning when loading it that it has direct reference to it, and that it will redirect it. Use FMLCommonHandler.exitJava(). Or throw new Error().
  2. You can simply create new FastCubeBlockAccess(cubeCache, centerCube, radius) and modify it to also check stage (and it should check the stage, I simply forgot about that) - it will throw exception if required cube isn't loaded and it will dump information about which cubes are loaded (you can also modify that to include stage if it doesn't do that now). And maybe you could pass that FastCubeBlockAccess to some of these methods and use it there.

Or leave it as it's now and let me fix that later.

I want to do as few things as possible in FirstLightProcessor because it needs to be fast. Currently it's close to vanilla initial lighting preformance. And most of the time is spent creating FastCubeBlockAccess objects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just quickly commited my current code so you can have a go at it if you want to. The check in FirstLightProcessor can go as it never encounters a missing block. If the DependencySystem were failing at delivering the required cubes properly, that loop would exit the program and it does not.

Copy link
Member

@Barteks2x Barteks2x Jun 14, 2016

Choose a reason for hiding this comment

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

Ok, just keep in mind that before merging it, System.exit() must be removed. Or possibly remove this check entirely. There is a check if world.checkLightFor() returns true (if it returns false it means that world.isAreaLoaded(thePosition, 17, false) returned false).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Of course, I'll clean it up once I found this f*** bug...

@Barteks2x
Copy link
Member

Barteks2x commented Jun 14, 2016

I'm not sure what the issue is now. I'm flying around for several minutes and din't experience any bug (I didn't test cube unloading yet). Lighting works as I expect it to work and it shows no rogue cubes.

Update: well, I did find some bug, but nothing is wrong in the log.

image

@Cyclonit
Copy link
Collaborator Author

Try logging the DependentCubeManager.getDependentCubeCount and DependencyManager.getRequiredCubeCount. Those should approach zero, but sometimes they don't.

@Barteks2x
Copy link
Member

As for these cubes that are not sent to player: they seem to have wrong target stage set. After trying to see why PlayerCubeMap doesn't send it to me it turned out that target stage is set to lighting. And I was in that cube.

@Barteks2x
Copy link
Member

Barteks2x commented Jun 14, 2016

Also, as of some recent changes FeatureProcessor has no dependencies as I merged surface and terrain stages. I could technically even merge terrain and features (as in vanilla). And (at least in my case) debugging showed that it's this stage that has some issues (still, it would be better to fix it properly if it works with Features as independent stage)

@Cyclonit
Copy link
Collaborator Author

Cyclonit commented Jun 14, 2016

I'm somewhat confident now that everything works as it was supposed to do last week...

Thanks for pointing out the wrong targetStage. Apparently some reorganization of loadCube caused it not being set in all cases when loadCube was invoked with a targetStage as parameter.

@@ -122,7 +122,7 @@ public void generate(Cube cube) {
public void generate(Cube cube, GeneratorStage targetStage) {

// Make sure the proper target stage is set.
if (cube.getTargetStage().precedes(targetStage)) {
if (cube.getTargetStage() == null || cube.getTargetStage().precedes(targetStage)) {
Copy link
Member

Choose a reason for hiding this comment

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

Can target stage be null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently yes, because it is no longer set in all paths of ServerCubeCache.loadCube, but I'll change that to get rid of that additional check. Cleaner without it.

- Fixed Cube.targetStage not being set properly in ServerCubeCache.loadCube.
- Fixed casing in comments.
- Added missing comments.
- Removed debug code from DependencyManager.
- Removed debug code from DependentCubeManager.
- Added missing annotations in RegionDependency.
- Changed ServerCubeCache.loadCube such that Cube.targetStage is defined in all paths and removed a null check from GeneratorPipeline.
@Barteks2x
Copy link
Member

Chunk unloading still needs to be fixed, this PR breaks it:
unloading

@Cyclonit
Copy link
Collaborator Author

The dependency system makes it difficult for cubes to be unloaded during generation. Usually they end up being finished and unloaded afterwards, meaning it may take some time for them to disappear.

@Barteks2x
Copy link
Member

The way it works is a bit weird. It works fine when moving vertically, but when moving in x/z - cubes are not getting unloaded as in screenshot above. Except that they eventually do end up unloaded because vanilla unloads all cubes that are not loaded by any players every time it saves all chunks. But this is definitely not something that you should rely on. Maybe unload a cube when there is nothing left that depends on it?

@Barteks2x
Copy link
Member

Barteks2x commented Jun 15, 2016

Another approach would be to keep them in unload queue and just skip them from unloading if there is something that depends on them. This way they will be automatically unloaded as soon as possible (potentially slow for high view distance/a lot of players)

@Cyclonit
Copy link
Collaborator Author

Cyclonit commented Jun 15, 2016

That's what is happening right now. In unloadCube and unloadQueuedCubes the ServerCubeCache skips cubes that are currently being required for other cubes. Cubes which are not required can be unloaded (and all cubes blocked by them will be unloaded thereafter), but since the lighting stage requires the other cubes to be in the exact same stage, this doesn't change much.

So to break it down: Dependents must be unloaded first, but since lots of dependents are required themselves, cubes end up not being unloaded early on.

@Barteks2x
Copy link
Member

It's not skipping them. It's removing them from unload queue and skipping.

@Cyclonit
Copy link
Collaborator Author

Does PlayerCubeMap not put them in the queeue again regardless?

@Barteks2x
Copy link
Member

Nope. It unloads once. And then it assumes that it's unloaded.

@Barteks2x
Copy link
Member

Also, why don't you just read the code?

@Cyclonit
Copy link
Collaborator Author

I apologize, I'm on the phone right now and commented faster than I was thinking.

…oUnload.

- Changed ServerCubeCache to not remove skipped cubes in unloadQueuedChunks.
@Cyclonit
Copy link
Collaborator Author

The ServerCubeCache no longer removes required cubes from the queue. But to be honest, I don't see a significant change.

long cubeAddress = this.cubesToUnload.poll();
Iterator<CubeCoords> iter = this.cubesToUnload.iterator();
while (iter.hasNext()) {
CubeCoords coords = iter.next();
Copy link
Member

Choose a reason for hiding this comment

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

you never limit the amount of unloaded cubes per tick. unloadQueuedChunks should be really called tick.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right. But I assume limiting it would be a good idea. If you agree I'll add a simple counter and exit once the maximum number is reached. But I'll have to postpone doing so to tomorrow.

Copy link
Member

Choose a reason for hiding this comment

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

This is how it was done before, and this is how vanilla does it.

- Fixed CustomCubicChunksWorldType to use IndependentGeneratorStage for feature stage.
- Fixed ServerCubeCache.unloadQueuedChunks to not process all queued cubes at once.
@Barteks2x Barteks2x merged commit dd14d25 into OpenCubicChunks:master Jun 17, 2016
@Barteks2x
Copy link
Member

I know that unloadding still dowan't work correctly, but fixing that rewuored rewriting some parts of ServerCubeCache (changes from the branch I told you not to merge).

@Cyclonit Cyclonit deleted the dependency branch June 17, 2016 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants