Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Jan 8, 2025
1 parent d57a751 commit d9701ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancel
import kotlinx.coroutines.future.asCompletableFuture
import kotlinx.coroutines.launch
import org.piepmeyer.gauguin.creation.GridCalculatorFactory
import org.piepmeyer.gauguin.grid.Grid
Expand Down Expand Up @@ -34,6 +35,8 @@ class GridCalculationService(
nextGrid = null
this.variant = variant
calculateCurrentGrid(scope, invokeAfterNewGridWasCreated)

calculateNextGrid(scope)
}

private fun calculateCurrentGrid(
Expand All @@ -55,9 +58,11 @@ class GridCalculationService(
}
}

fun calculateNextGrid(scope: CoroutineScope) {
private fun calculateNextGrid(scope: CoroutineScope) {
nextGridJob =
scope.launch(dispatcher) {
currentGridJob?.asCompletableFuture()?.join()

logger.info { "Calculating next grid of $variant" }
listeners.forEach { it.startingNextGridCalculation() }

Expand All @@ -70,9 +75,7 @@ class GridCalculationService(
}
}

fun hasCalculatedNextGrid(variantParam: GameVariant): Boolean {
return nextGrid != null && variantParam == variant
}
fun hasCalculatedNextGrid(variantParam: GameVariant): Boolean = nextGrid != null && variantParam == variant

fun consumeNextGrid(): Grid {
val grid = nextGrid!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ class GameLifecycle(
startNewGrid()
}
}

calculationService.calculateNextGrid(scope)
}

fun loadGame(saveGameFile: File) {
Expand Down

0 comments on commit d9701ae

Please sign in to comment.