From cb55d6e72ae1f48622ffc2a36d7bdb3719355afe Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 6 Nov 2015 08:19:46 -0500 Subject: world save/load --- src/world.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/world.cpp') diff --git a/src/world.cpp b/src/world.cpp index 77872c1..01c06c4 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -34,6 +34,35 @@ float worldGetYBase(World *w){ return base; } +struct wSavePack { + int x_start; + unsigned int lineCount; +} __attribute__ ((packed)); + +char *World::save(unsigned int *ssize){ + struct wSavePack *sp; + unsigned int size; + char *buf; + size=sizeof(struct wSavePack) + lineCount * sizeof(struct line_t); + buf=(char *)malloc(size); + sp=(struct wSavePack *)buf; + sp->x_start=x_start; + sp->lineCount=lineCount; + memcpy(buf+sizeof(struct wSavePack),line,lineCount * sizeof(struct line_t)); + *ssize=size; + return buf; +} + +void World::load(char *buf){ + struct wSavePack *sp; + sp=(struct wSavePack *)buf; + std::cout<lineCount<x_start; + lineCount=sp->lineCount; + line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)); + memcpy(line,buf+sizeof(struct wSavePack),lineCount * sizeof(struct line_t)); +} + World::World(void){ /* * Nullify pointers to other worlds. -- cgit v1.2.3