forked from ppfun/pixelplanet
copy 3d canvas
This commit is contained in:
parent
ccbd091d61
commit
2869b5fa0c
|
@ -1,30 +1,37 @@
|
||||||
/* @flow */
|
/* @flow */
|
||||||
//this script just copies chunks from one redis to another with a different key as needed
|
//this script just copies chunks from one redis to another with a different
|
||||||
|
//key as needed
|
||||||
|
|
||||||
import redis from 'redis';
|
import redis from 'redis';
|
||||||
import bluebird from 'bluebird';
|
import bluebird from 'bluebird';
|
||||||
bluebird.promisifyAll(redis.RedisClient.prototype);
|
bluebird.promisifyAll(redis.RedisClient.prototype);
|
||||||
bluebird.promisifyAll(redis.Multi.prototype);
|
bluebird.promisifyAll(redis.Multi.prototype);
|
||||||
|
|
||||||
|
import {
|
||||||
|
TILE_SIZE,
|
||||||
|
THREE_TILE_SIZE,
|
||||||
|
} from '../src/core/constants';
|
||||||
|
|
||||||
//ATTENTION Make suer to set the rdis URLs right!!!
|
//ATTENTION Make suer to set the rdis URLs right!!!
|
||||||
const oldurl = "redis://localhost:6379";
|
const oldurl = "redis://localhost:6380";
|
||||||
const oldredis = redis.createClient(oldurl, { return_buffers: true });
|
const oldredis = redis.createClient(oldurl, { return_buffers: true });
|
||||||
const newurl = "redis://localhost:6380";
|
const newurl = "redis://localhost:6379";
|
||||||
const newredis = redis.createClient(newurl, { return_buffers: true });
|
const newredis = redis.createClient(newurl, { return_buffers: true });
|
||||||
|
|
||||||
const CANVAS_SIZE = 256 * 256;
|
const CANVAS_SIZE = 1024;
|
||||||
const TILE_SIZE = 256;
|
const OUR_TILE_SIZE = THREE_TILE_SIZE;
|
||||||
const CHUNKS_XY = CANVAS_SIZE / TILE_SIZE;
|
const CHUNKS_XY = CANVAS_SIZE / OUR_TILE_SIZE;
|
||||||
|
|
||||||
async function copyChunks() {
|
async function copyChunks() {
|
||||||
for (let x = 0; x < CHUNKS_XY; x++) {
|
for (let x = 0; x < CHUNKS_XY; x++) {
|
||||||
for (let y = 0; y < CHUNKS_XY; y++) {
|
for (let y = 0; y < CHUNKS_XY; y++) {
|
||||||
const oldkey = `chunk:${x}:${y}`;
|
const oldkey = `ch:2:${x}:${y}`;
|
||||||
const newkey = `ch:0:${x}:${y}`;
|
const newkey = `ch:2:${x}:${y}`;
|
||||||
const chunk = await oldredis.getAsync(oldkey);
|
const chunk = await oldredis.getAsync(oldkey);
|
||||||
if (chunk) {
|
if (chunk) {
|
||||||
const setNXArgs = [newkey, chunk];
|
const setNXArgs = [newkey, chunk];
|
||||||
await newredis.sendCommandAsync('SETNX', setNXArgs);
|
await newredis.sendCommandAsync('SET', setNXArgs);
|
||||||
console.log("Created Chunk ", key);
|
console.log("Created Chunk ", newkey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user