diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-11-06 08:19:46 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-11-06 08:19:46 -0500 |
commit | cb55d6e72ae1f48622ffc2a36d7bdb3719355afe (patch) | |
tree | e38b215d2fc45368a76bf9350138046c38afa946 /src/world.cpp | |
parent | f2886601e15f41938c6735feb552e831ffeeefc1 (diff) |
world save/load
Diffstat (limited to 'src/world.cpp')
-rw-r--r-- | src/world.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
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<<sp->lineCount<<std::endl; + x_start=sp->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. |