mirror of https://github.com/Askill/r_place.git
saving every 10 sec
This commit is contained in:
parent
14584c41a0
commit
e3cf4ab1e7
|
|
@ -114,8 +114,8 @@ func loadState(img *image, path string) {
|
||||||
json.Unmarshal(byteValue, &img)
|
json.Unmarshal(byteValue, &img)
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveState(img *image, path string) {
|
func saveState(img *image, path string, period time.Duration) {
|
||||||
ticker := time.NewTicker(1 * time.Second)
|
ticker := time.NewTicker(period * time.Second)
|
||||||
|
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
imgJSON, _ := json.Marshal(img)
|
imgJSON, _ := json.Marshal(img)
|
||||||
|
|
@ -143,7 +143,7 @@ func main() {
|
||||||
cachePath := "./state.json"
|
cachePath := "./state.json"
|
||||||
|
|
||||||
loadState(&img, cachePath)
|
loadState(&img, cachePath)
|
||||||
go saveState(&img, cachePath)
|
go saveState(&img, cachePath, 10)
|
||||||
|
|
||||||
http.HandleFunc("/get", get)
|
http.HandleFunc("/get", get)
|
||||||
http.HandleFunc("/set", set)
|
http.HandleFunc("/set", set)
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ async def client():
|
||||||
x = pixel(**json.loads(await websocket.recv()))
|
x = pixel(**json.loads(await websocket.recv()))
|
||||||
#image[x.x][x.y] = ([y*255 for y in colors[x.color]])
|
#image[x.x][x.y] = ([y*255 for y in colors[x.color]])
|
||||||
image[x.x][x.y] = ((x.color, x.color, x.color))
|
image[x.x][x.y] = ((x.color, x.color, x.color))
|
||||||
if i% 1000 == 0:
|
if i% 500000 == 0:
|
||||||
cv2.imshow("changes x", image)
|
cv2.imshow("changes x", image)
|
||||||
cv2.waitKey(10) & 0XFF
|
cv2.waitKey(10) & 0XFF
|
||||||
await websocket.send("1")
|
await websocket.send("1")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue