Re: Dangling pointers and saving references to file in C.
- From: Perdurabo <perdurabo93@xxxxxxxxxxxxxx>
- Date: Thu, 22 May 2008 06:00:40 -0700 (PDT)
On May 22, 1:47 pm, Pfhoenix <pfhoe...@xxxxxxxxx> wrote:
Could be, but I don't think its that big a deal. Its next to no extra
memory usage, and not reusing IDs prevents any possible corruption.
But I wouldn't consider keeping absolute indices into an array a good
design decision at all.
Heh. I didn't say it was perfect, but it does the job, does the job
quickly, and it meshes well with my chosen collection object: Delphi's
TObjectList (which isn't an array, although it can be accessed as
such).
Adeo manages reference serialization (which is what we're talking
about here) as such : every class that needs serialization at all
(which includes all gameplay relevant classes) subclasses Object,
which has a string UniqueObjectName. The UON gets built by
concatenating the class name with a randomly generated unsigned int.
When it comes time to serialize, references are saved by UON, and when
a map is loaded, after the entire map is loaded, the engine does a
reference clean up that provides all objects a chance to lazily
restore references by matching up against UONs.
I actually do/am intending to do something similar with items. Each
item has its own unique identifier that allows me to recreate the
object (and all its properties) from a simple string - since my item
classes inherit from the same base class as my monster classes (and
share the same interfaces), it would be possible to extend this to
monsters, but I've held off from doing so due to the amount of
variable data that monsters store (much more than items).
I've gone through 3 major revisions of Adeo's serialization subsystem.
It's quite robust at this point, fast, and works rather well. It's a
bit more complex than you may need, since it's possible for maps to be
referenced and loaded like any other object (and some gameplay objects
reference objects on other maps entirely, like telepads), but if you
go with "every map is an island", it gets simpler and is about perfect
for what you need.
*nods*.
I expect to rewrite this sort of functionality in Kharne many times.
Its the nature of the beast, isn't it? At the moment, dungeons are
stored as simple multi-layered arrays of ints/booleans.
Best,
P.
.
- Follow-Ups:
- Re: Dangling pointers and saving references to file in C.
- From: Pfhoenix
- Re: Dangling pointers and saving references to file in C.
- References:
- Dangling pointers and saving references to file in C.
- From: MBrenaman
- Re: Dangling pointers and saving references to file in C.
- From: Perdurabo
- Re: Dangling pointers and saving references to file in C.
- From: Brog
- Re: Dangling pointers and saving references to file in C.
- From: Perdurabo
- Re: Dangling pointers and saving references to file in C.
- From: Pfhoenix
- Dangling pointers and saving references to file in C.
- Prev by Date: Re: Dangling pointers and saving references to file in C.
- Next by Date: libfov in PHP
- Previous by thread: Re: Dangling pointers and saving references to file in C.
- Next by thread: Re: Dangling pointers and saving references to file in C.
- Index(es):
Relevant Pages
|