Pass old element to empfile callback prewrite()
Change sct_prewrite(), shp_prewrite(), pln_prewrite(), lnd_prewrite(), nuk_prewrite() accordingly. New argument isn't used for anything, yet.
This commit is contained in:
parent
0bcd0a8422
commit
c5482e4bfb
9 changed files with 33 additions and 33 deletions
|
@ -67,12 +67,12 @@ struct empfile {
|
||||||
*/
|
*/
|
||||||
void (*postread)(int id, void *elt);
|
void (*postread)(int id, void *elt);
|
||||||
/*
|
/*
|
||||||
* Called before write. ID is the element id, and ELT is the
|
* Called before write. ID is the element id, OLD is the element
|
||||||
* element being written. May modify the element. Modifications
|
* being updated (null unless it is cached) and ELT is the element
|
||||||
* will be visible to caller of ef_write() and are written to the
|
* being written. May modify the element. Modifications will be
|
||||||
* file.
|
* visible to caller of ef_write() and are written to the file.
|
||||||
*/
|
*/
|
||||||
void (*prewrite)(int id, void *elt);
|
void (*prewrite)(int id, void *old, void *elt);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct emptypedstr {
|
struct emptypedstr {
|
||||||
|
|
|
@ -451,7 +451,7 @@ extern int getele(char *, char *);
|
||||||
/* land.c */
|
/* land.c */
|
||||||
extern char *prland(struct lndstr *);
|
extern char *prland(struct lndstr *);
|
||||||
extern void lnd_postread(int, void *);
|
extern void lnd_postread(int, void *);
|
||||||
extern void lnd_prewrite(int, void *);
|
extern void lnd_prewrite(int, void *, void *);
|
||||||
/* landgun.c */
|
/* landgun.c */
|
||||||
extern double seagun(int, int);
|
extern double seagun(int, int);
|
||||||
extern double fortgun(int, int);
|
extern double fortgun(int, int);
|
||||||
|
@ -518,7 +518,7 @@ extern void nreport(natid, int, natid, int);
|
||||||
/* nuke.c */
|
/* nuke.c */
|
||||||
extern char *prnuke(struct nukstr *);
|
extern char *prnuke(struct nukstr *);
|
||||||
extern void nuk_postread(int, void *);
|
extern void nuk_postread(int, void *);
|
||||||
extern void nuk_prewrite(int, void *);
|
extern void nuk_prewrite(int, void *, void *);
|
||||||
extern int nuk_on_plane(struct nukstr *, int);
|
extern int nuk_on_plane(struct nukstr *, int);
|
||||||
/* nxtitem.c */
|
/* nxtitem.c */
|
||||||
extern int nxtitem(struct nstr_item *, void *);
|
extern int nxtitem(struct nstr_item *, void *);
|
||||||
|
@ -529,7 +529,7 @@ extern int onearg(char *, char *);
|
||||||
/* plane.c */
|
/* plane.c */
|
||||||
extern char *prplane(struct plnstr *);
|
extern char *prplane(struct plnstr *);
|
||||||
extern void pln_postread(int, void *);
|
extern void pln_postread(int, void *);
|
||||||
extern void pln_prewrite(int, void *);
|
extern void pln_prewrite(int, void *, void *);
|
||||||
/* plnsub.c */
|
/* plnsub.c */
|
||||||
extern void count_planes(struct shpstr *);
|
extern void count_planes(struct shpstr *);
|
||||||
extern int get_planes(struct nstr_item *, struct nstr_item *,
|
extern int get_planes(struct nstr_item *, struct nstr_item *,
|
||||||
|
@ -619,7 +619,7 @@ extern void satmap(int, int, int, int, int, int);
|
||||||
extern void sathead(void);
|
extern void sathead(void);
|
||||||
/* sect.c */
|
/* sect.c */
|
||||||
extern void sct_postread(int, void *);
|
extern void sct_postread(int, void *);
|
||||||
extern void sct_prewrite(int, void *);
|
extern void sct_prewrite(int, void *, void *);
|
||||||
extern void item_prewrite(short *);
|
extern void item_prewrite(short *);
|
||||||
extern int issector(char *);
|
extern int issector(char *);
|
||||||
/* sectdamage.c */
|
/* sectdamage.c */
|
||||||
|
@ -628,7 +628,7 @@ extern int sectdamage(struct sctstr *, int);
|
||||||
/* ship.c */
|
/* ship.c */
|
||||||
extern char *prship(struct shpstr *);
|
extern char *prship(struct shpstr *);
|
||||||
extern void shp_postread(int, void *);
|
extern void shp_postread(int, void *);
|
||||||
extern void shp_prewrite(int, void *);
|
extern void shp_prewrite(int, void *, void *);
|
||||||
/* show.c */
|
/* show.c */
|
||||||
extern void show_bridge(int);
|
extern void show_bridge(int);
|
||||||
extern void show_tower(int);
|
extern void show_tower(int);
|
||||||
|
|
|
@ -314,7 +314,7 @@ int
|
||||||
ef_read(int type, int id, void *into)
|
ef_read(int type, int id, void *into)
|
||||||
{
|
{
|
||||||
struct empfile *ep;
|
struct empfile *ep;
|
||||||
void *from;
|
void *cachep;
|
||||||
|
|
||||||
if (ef_check(type) < 0)
|
if (ef_check(type) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -325,15 +325,15 @@ ef_read(int type, int id, void *into)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (ep->flags & EFF_MEM) {
|
if (ep->flags & EFF_MEM) {
|
||||||
from = ep->cache + id * ep->size;
|
cachep = ep->cache + id * ep->size;
|
||||||
} else {
|
} else {
|
||||||
if (ep->baseid + ep->cids <= id || ep->baseid > id) {
|
if (ep->baseid + ep->cids <= id || ep->baseid > id) {
|
||||||
if (fillcache(ep, id) < 1)
|
if (fillcache(ep, id) < 1)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
from = ep->cache + (id - ep->baseid) * ep->size;
|
cachep = ep->cache + (id - ep->baseid) * ep->size;
|
||||||
}
|
}
|
||||||
memcpy(into, from, ep->size);
|
memcpy(into, cachep, ep->size);
|
||||||
|
|
||||||
if (ep->postread)
|
if (ep->postread)
|
||||||
ep->postread(id, into);
|
ep->postread(id, into);
|
||||||
|
@ -480,15 +480,19 @@ int
|
||||||
ef_write(int type, int id, void *from)
|
ef_write(int type, int id, void *from)
|
||||||
{
|
{
|
||||||
struct empfile *ep;
|
struct empfile *ep;
|
||||||
char *to;
|
char *cachep;
|
||||||
|
|
||||||
if (ef_check(type) < 0)
|
if (ef_check(type) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
ep = &empfile[type];
|
ep = &empfile[type];
|
||||||
if (CANT_HAPPEN((ep->flags & (EFF_MEM | EFF_PRIVATE)) == EFF_PRIVATE))
|
if (CANT_HAPPEN((ep->flags & (EFF_MEM | EFF_PRIVATE)) == EFF_PRIVATE))
|
||||||
return 0;
|
return 0;
|
||||||
|
if (id >= ep->baseid && id < ep->baseid + ep->cids)
|
||||||
|
cachep = ep->cache + (id - ep->baseid) * ep->size;
|
||||||
|
else
|
||||||
|
cachep = NULL;
|
||||||
if (ep->prewrite)
|
if (ep->prewrite)
|
||||||
ep->prewrite(id, from);
|
ep->prewrite(id, cachep, from);
|
||||||
if (CANT_HAPPEN((ep->flags & EFF_MEM) ? id >= ep->fids : id > ep->fids))
|
if (CANT_HAPPEN((ep->flags & EFF_MEM) ? id >= ep->fids : id > ep->fids))
|
||||||
return 0; /* not implemented */
|
return 0; /* not implemented */
|
||||||
new_seqno(ep, from);
|
new_seqno(ep, from);
|
||||||
|
@ -496,12 +500,8 @@ ef_write(int type, int id, void *from)
|
||||||
if (do_write(ep, from, id, 1) < 0)
|
if (do_write(ep, from, id, 1) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (id >= ep->baseid && id < ep->baseid + ep->cids) {
|
if (cachep && cachep != from) /* update the cache if necessary */
|
||||||
/* update the cache if necessary */
|
memcpy(cachep, from, ep->size);
|
||||||
to = ep->cache + (id - ep->baseid) * ep->size;
|
|
||||||
if (to != from)
|
|
||||||
memcpy(to, from, ep->size);
|
|
||||||
}
|
|
||||||
if (id >= ep->fids) {
|
if (id >= ep->fids) {
|
||||||
/* write beyond end of file extends it, take note */
|
/* write beyond end of file extends it, take note */
|
||||||
ep->fids = id + 1;
|
ep->fids = id + 1;
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
struct fileinit {
|
struct fileinit {
|
||||||
int ef_type;
|
int ef_type;
|
||||||
void (*postread) (int, void *);
|
void (*postread) (int, void *);
|
||||||
void (*prewrite) (int, void *);
|
void (*prewrite) (int, void *, void *);
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct fileinit fileinit[] = {
|
static struct fileinit fileinit[] = {
|
||||||
|
|
|
@ -109,9 +109,9 @@ lnd_postread(int n, void *ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
lnd_prewrite(int n, void *ptr)
|
lnd_prewrite(int n, void *old, void *new)
|
||||||
{
|
{
|
||||||
struct lndstr *llp = ptr;
|
struct lndstr *llp = new;
|
||||||
struct lndstr *lp;
|
struct lndstr *lp;
|
||||||
struct plnstr *pp;
|
struct plnstr *pp;
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -74,9 +74,9 @@ nuk_postread(int n, void *ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nuk_prewrite(int n, void *ptr)
|
nuk_prewrite(int n, void *old, void *new)
|
||||||
{
|
{
|
||||||
struct nukstr *np = ptr;
|
struct nukstr *np = new;
|
||||||
|
|
||||||
if (np->nuk_effic == 0) {
|
if (np->nuk_effic == 0) {
|
||||||
if (np->nuk_own)
|
if (np->nuk_own)
|
||||||
|
|
|
@ -108,9 +108,9 @@ pln_postread(int n, void *ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pln_prewrite(int n, void *ptr)
|
pln_prewrite(int n, void *old, void *new)
|
||||||
{
|
{
|
||||||
struct plnstr *pp = ptr;
|
struct plnstr *pp = new;
|
||||||
struct nukstr *np;
|
struct nukstr *np;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
|
@ -59,9 +59,9 @@ sct_postread(int id, void *ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sct_prewrite(int id, void *ptr)
|
sct_prewrite(int id, void *old, void *new)
|
||||||
{
|
{
|
||||||
struct sctstr *sp = ptr;
|
struct sctstr *sp = new;
|
||||||
int mil, civs;
|
int mil, civs;
|
||||||
natid own;
|
natid own;
|
||||||
|
|
||||||
|
|
|
@ -62,9 +62,9 @@ shp_postread(int n, void *ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
shp_prewrite(int n, void *ptr)
|
shp_prewrite(int n, void *old, void *new)
|
||||||
{
|
{
|
||||||
struct shpstr *sp = ptr;
|
struct shpstr *sp = new;
|
||||||
struct lndstr *lp;
|
struct lndstr *lp;
|
||||||
struct plnstr *pp;
|
struct plnstr *pp;
|
||||||
int i;
|
int i;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue