Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
"sortablejs": "^1.10.2",
"styled-components": "^5.3.3",
"ts-dedent": "^2.0.0",
"uuid": "^8.3.2"
"uuid": "^8.3.2",
"yjs": "^13.5.41",
"y-indexeddb": "^9.0.9"
},
"scripts": {
"declarations": "tsc -p tsconfig.decs.json",
Expand Down
46 changes: 30 additions & 16 deletions client/src/Backend/GameLogic/GameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ import {
verifyTwitterHandle,
} from '../Network/UtilityServerAPI';
import { SerializedPlugin } from '../Plugins/SerializedPlugin';
import OtherStore from '../Storage/OtherStore';
import PersistentChunkStore from '../Storage/PersistentChunkStore';
import { easeInAnimation, emojiEaseOutAnimation } from '../Utils/Animation';
import SnarkArgsHelper from '../Utils/SnarkArgsHelper';
Expand Down Expand Up @@ -207,6 +208,8 @@ class GameManager extends EventEmitter {
* or something like that.
*/
private readonly persistentChunkStore: PersistentChunkStore;
// Literally other storage stuff that people dumped into the chunk store
private readonly otherStore: OtherStore;

/**
* Responsible for generating snark proofs.
Expand Down Expand Up @@ -368,6 +371,7 @@ class GameManager extends EventEmitter {
contractsAPI: ContractsAPI,
contractConstants: ContractConstants,
persistentChunkStore: PersistentChunkStore,
otherStore: OtherStore,
snarkHelper: SnarkArgsHelper,
homeLocation: WorldLocation | undefined,
useMockHash: boolean,
Expand Down Expand Up @@ -474,6 +478,7 @@ class GameManager extends EventEmitter {

this.contractsAPI = contractsAPI;
this.persistentChunkStore = persistentChunkStore;
this.otherStore = otherStore;
this.snarkHelper = snarkHelper;
this.useMockHash = useMockHash;
this.paused = paused;
Expand Down Expand Up @@ -588,20 +593,25 @@ class GameManager extends EventEmitter {

terminal.current?.println('Loading game data from disk...');

const persistentChunkStore = await PersistentChunkStore.create({ account, contractAddress });
const persistentChunkStore = new PersistentChunkStore({ account, contractAddress });
const otherStore = await OtherStore.create({ account, contractAddress });

terminal.current?.println('Downloading data from Ethereum blockchain...');
terminal.current?.println('(the contract is very big. this may take a while)');
terminal.current?.newline();

const initialState = await gameStateDownloader.download(contractsAPI, persistentChunkStore);
const possibleHomes = await persistentChunkStore.getHomeLocations();
const initialState = await gameStateDownloader.download(
contractsAPI,
persistentChunkStore,
otherStore
);
const possibleHomes = await otherStore.getHomeLocations();

terminal.current?.println('');
terminal.current?.println('Building Index...');

await persistentChunkStore.saveTouchedPlanetIds(initialState.allTouchedPlanetIds);
await persistentChunkStore.saveRevealedCoords(initialState.allRevealedCoords);
await otherStore.saveTouchedPlanetIds(initialState.allTouchedPlanetIds);
await otherStore.saveRevealedCoords(initialState.allRevealedCoords);

const knownArtifacts: Map<ArtifactId, Artifact> = new Map();

Expand Down Expand Up @@ -632,7 +642,7 @@ class GameManager extends EventEmitter {
for (const loc of possibleHomes) {
if (initialState.allTouchedPlanetIds.includes(loc.hash)) {
homeLocation = loc;
await persistentChunkStore.confirmHomeLocation(loc);
await otherStore.confirmHomeLocation(loc);
break;
}
}
Expand Down Expand Up @@ -666,6 +676,7 @@ class GameManager extends EventEmitter {
contractsAPI,
initialState.contractConstants,
persistentChunkStore,
otherStore,
snarkHelper,
homeLocation,
useMockHash,
Expand Down Expand Up @@ -751,12 +762,12 @@ class GameManager extends EventEmitter {
gameManager.entityStore.onTxIntent(tx);
})
.on(ContractsAPIEvent.TxSubmitted, (tx: Transaction) => {
gameManager.persistentChunkStore.onEthTxSubmit(tx);
gameManager.otherStore.onEthTxSubmit(tx);
gameManager.onTxSubmit(tx);
})
.on(ContractsAPIEvent.TxConfirmed, async (tx: Transaction) => {
if (!tx.hash) return; // this should never happen
gameManager.persistentChunkStore.onEthTxComplete(tx.hash);
gameManager.otherStore.onEthTxComplete(tx.hash);

if (isUnconfirmedRevealTx(tx)) {
await gameManager.hardRefreshPlanet(tx.intent.locationId);
Expand Down Expand Up @@ -832,7 +843,7 @@ class GameManager extends EventEmitter {
.on(ContractsAPIEvent.TxErrored, async (tx: Transaction) => {
gameManager.entityStore.clearUnconfirmedTxIntent(tx);
if (tx.hash) {
gameManager.persistentChunkStore.onEthTxComplete(tx.hash);
gameManager.otherStore.onEthTxComplete(tx.hash);
}
gameManager.onTxReverted(tx);
})
Expand All @@ -844,7 +855,7 @@ class GameManager extends EventEmitter {
gameManager.setRadius(newRadius);
});

const unconfirmedTxs = await persistentChunkStore.getUnconfirmedSubmittedEthTxs();
const unconfirmedTxs = await otherStore.getUnconfirmedSubmittedEthTxs();
const confirmationQueue = new ThrottledConcurrentQueue({
invocationIntervalMs: 1000,
maxInvocationsPerIntervalMs: 10,
Expand Down Expand Up @@ -1590,6 +1601,9 @@ class GameManager extends EventEmitter {
getChunkStore(): PersistentChunkStore {
return this.persistentChunkStore;
}
getOtherStore(): OtherStore {
return this.otherStore;
}

/**
* The perlin value at each coordinate determines the space type. There are four space
Expand Down Expand Up @@ -1912,7 +1926,7 @@ class GameManager extends EventEmitter {
);
this.terminal.current?.println('');

await this.persistentChunkStore.addHomeLocation(planet.location);
await this.otherStore.addHomeLocation(planet.location);

const getArgs = async () => {
const args = await this.snarkHelper.getInitArgs(
Expand Down Expand Up @@ -2012,7 +2026,7 @@ class GameManager extends EventEmitter {
*/
async addAccount(coords: WorldCoords): Promise<boolean> {
const loc: WorldLocation = this.locationFromCoords(coords);
await this.persistentChunkStore.addHomeLocation(loc);
await this.otherStore.addHomeLocation(loc);
this.initMiningManager(coords);
this.homeLocation = loc;
return true;
Expand Down Expand Up @@ -2983,7 +2997,7 @@ class GameManager extends EventEmitter {
* all of the information about those planets from the blockchain.
*/
addNewChunk(chunk: Chunk): GameManager {
this.persistentChunkStore.addChunk(chunk, true);
this.persistentChunkStore.addChunk(chunk);
for (const planetLocation of chunk.planetLocations) {
this.entityStore.addPlanetLocation(planetLocation);

Expand Down Expand Up @@ -3012,7 +3026,7 @@ class GameManager extends EventEmitter {
);
const planetIdsToUpdate: LocationId[] = [];
for (const chunk of chunks) {
this.persistentChunkStore.addChunk(chunk, true);
this.persistentChunkStore.addChunk(chunk);
for (const planetLocation of chunk.planetLocations) {
this.entityStore.addPlanetLocation(planetLocation);

Expand Down Expand Up @@ -3236,14 +3250,14 @@ class GameManager extends EventEmitter {
* Load the serialized versions of all the plugins that this player has.
*/
public async loadPlugins(): Promise<SerializedPlugin[]> {
return this.persistentChunkStore.loadPlugins();
return this.otherStore.loadPlugins();
}

/**
* Overwrites all the saved plugins to equal the given array of plugins.
*/
public async savePlugins(savedPlugins: SerializedPlugin[]): Promise<void> {
await this.persistentChunkStore.savePlugins(savedPlugins);
await this.otherStore.savePlugins(savedPlugins);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion client/src/Backend/GameLogic/GameUIManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class GameUIManager extends EventEmitter {
const uiEmitter = UIEmitter.getInstance();

const uiManager = new GameUIManager(gameManager, terminalHandle);
const modalManager = await ModalManager.create(gameManager.getChunkStore());
const modalManager = await ModalManager.create(gameManager.getOtherStore());

uiManager.setModalManager(modalManager);

Expand Down
12 changes: 8 additions & 4 deletions client/src/Backend/GameLogic/InitialGameStateDownloader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TerminalHandle } from '../../Frontend/Views/Terminal';
import { ContractConstants } from '../../_types/darkforest/api/ContractsAPITypes';
import { AddressTwitterMap } from '../../_types/darkforest/api/UtilityServerAPITypes';
import { tryGetAllTwitters } from '../Network/UtilityServerAPI';
import OtherStore from '../Storage/OtherStore';
import PersistentChunkStore from '../Storage/PersistentChunkStore';
import { ContractsAPI } from './ContractsAPI';

Expand Down Expand Up @@ -61,18 +62,19 @@ export class InitialGameStateDownloader {

async download(
contractsAPI: ContractsAPI,
persistentChunkStore: PersistentChunkStore
persistentChunkStore: PersistentChunkStore,
otherStore: OtherStore
): Promise<InitialGameState> {
/**
* In development we use the same contract address every time we deploy,
* so storage is polluted with the IDs of old universes.
*/
const storedTouchedPlanetIds = import.meta.env.DEV
? []
: await persistentChunkStore.getSavedTouchedPlanetIds();
: await otherStore.getSavedTouchedPlanetIds();
const storedRevealedCoords = import.meta.env.DEV
? []
: await persistentChunkStore.getSavedRevealedCoords();
: await otherStore.getSavedRevealedCoords();

this.terminal.printElement(<DarkForestTips tips={tips} />);
this.terminal.newline();
Expand All @@ -98,7 +100,9 @@ export class InitialGameStateDownloader {
const arrivals: Map<VoyageId, QueuedArrival> = new Map();
const planetVoyageIdMap: Map<LocationId, VoyageId[]> = new Map();

const minedChunks = Array.from(await persistentChunkStore.allChunks());
// Ensure that all chunks have been loaded from indexeddb
await persistentChunkStore.chunksLoaded();
const minedChunks = Array.from(persistentChunkStore.allChunks());
const minedPlanetIds = new Set(
_.flatMap(minedChunks, (c) => c.planetLocations).map((l) => l.hash)
);
Expand Down
Loading