calling getplane() and rplane() is a real waste of cycles (and happens enough to shortcut it)

This commit is contained in:
Enno Rehling 2007-03-01 21:51:35 +00:00
parent fc121f99a6
commit 07ecc3e517
7 changed files with 30 additions and 33 deletions

View File

@ -327,7 +327,7 @@ cr_region(variant var, char * buffer, const void * userdata)
const faction * report = (const faction*)userdata;
region * r = (region *)var.v;
if (r) {
plane * p = rplane(r);
plane * p = r->planep;
if (!p || !(p->flags & PFL_NOCOORDS)) {
sprintf(buffer, "%d %d %d", region_x(r, report), region_y(r, report), p?p->id:0);
return 0;
@ -1203,10 +1203,10 @@ report_computer(const char * filename, report_context * ctx)
{
struct bmsg * bm;
for (bm=f->battles;bm;bm=bm->next) {
if (!rplane(bm->r)) fprintf(F, "BATTLE %d %d\n", region_x(bm->r, f), region_y(bm->r, f));
if (!bm->r->planep) fprintf(F, "BATTLE %d %d\n", region_x(bm->r, f), region_y(bm->r, f));
else {
if (rplane(bm->r)->flags & PFL_NOCOORDS) fprintf(F, "BATTLESPEC %d %d\n", encode_region(f, bm->r), rplane(bm->r)->id);
else fprintf(F, "BATTLE %d %d %d\n", region_x(bm->r, f), region_y(bm->r, f), rplane(bm->r)->id);
if (bm->r->planep->flags & PFL_NOCOORDS) fprintf(F, "BATTLESPEC %d %d\n", encode_region(f, bm->r), bm->r->planep->id);
else fprintf(F, "BATTLE %d %d %d\n", region_x(bm->r, f), region_y(bm->r, f), bm->r->planep->id);
}
cr_output_messages(F, bm->msgs, f);
}
@ -1255,7 +1255,7 @@ report_computer(const char * filename, report_context * ctx)
region * r = sr->r;
const char * tname;
if (!rplane(r)) {
if (!r->planep) {
if (opt_cr_absolute_coords) {
fprintf(F, "REGION %d %d\n", r->x, r->x);
} else {
@ -1263,11 +1263,11 @@ report_computer(const char * filename, report_context * ctx)
}
} else {
#if ENCODE_SPECIAL
if (rplane(r)->flags & PFL_NOCOORDS) fprintf(F, "SPEZIALREGION %d %d\n", encode_region(f, r), rplane(r)->id);
if (r->planep->flags & PFL_NOCOORDS) fprintf(F, "SPEZIALREGION %d %d\n", encode_region(f, r), r->planep->id);
#else
if (rplane(r)->flags & PFL_NOCOORDS) continue;
if (r->planep->flags & PFL_NOCOORDS) continue;
#endif
else fprintf(F, "REGION %d %d %d\n", region_x(r, f), region_y(r, f), rplane(r)->id);
else fprintf(F, "REGION %d %d %d\n", region_x(r, f), region_y(r, f), r->planep->id);
}
if (r->land && strlen(rname(r, f->locale))) fprintf(F, "\"%s\";Name\n", rname(r, f->locale));
if (is_cursed(r->attribs,C_MAELSTROM, 0))
@ -1384,7 +1384,7 @@ report_computer(const char * filename, report_context * ctx)
}
print_curses(F, f, r, TYP_REGION);
cr_borders(ctx->seen, r, f, sr->mode, F);
if (sr->mode==see_unit && rplane(r)==get_astralplane() && !is_cursed(r->attribs, C_ASTRALBLOCK, 0))
if (sr->mode==see_unit && r->planep==get_astralplane() && !is_cursed(r->attribs, C_ASTRALBLOCK, 0))
{
/* Sonderbehandlung Teleport-Ebene */
region_list *rl = astralregions(r, inhabitable);
@ -1477,7 +1477,7 @@ crwritemap(const char * filename)
FILE * F = fopen(filename, "w+");
region * r;
for (r=regions;r;r=r->next) {
plane * p = rplane(r);
plane * p = r->planep;
fprintf(F, "REGION %d %d %d\n", r->x, r->y, p?p->id:0);
fprintf(F, "\"%s\";Name\n\"%s\";Terrain\n", rname(r, default_locale), LOC(default_locale, terrain_name(r)));
}

View File

@ -639,12 +639,11 @@ rp_battles(FILE * F, faction * f)
size_t
f_regionid(const region * r, const faction * f, char * buffer, size_t size)
{
plane * pl = NULL;
if (!r) {
strncpy(buffer, "(Chaos)", size);
} else {
pl = getplane(r);
plane * pl = r->planep;
strncpy(buffer, rname(r, f->locale), size);
buffer[size-1]=0;
if (pl==NULL || !fval(pl, PFL_NOCOORDS)) {

View File

@ -1002,7 +1002,7 @@ int
alliedunit(const unit * u, const faction * f2, int mode)
{
ally * sf;
const plane * pl = getplane(u->region);
const plane * pl = u->region->planep;
int automode;
if (u->faction == f2) return mode;

View File

@ -163,18 +163,14 @@ plane_center_y(const plane *pl)
short
region_x(const region *r, const faction *f)
{
plane *pl;
assert(r!=NULL);
pl = getplane(r);
plane *pl = r->planep;
return r->x - ursprung_x(f, pl, r) - plane_center_x(pl);
}
short
region_y(const region *r, const faction *f)
{
plane *pl;
assert(r!=NULL);
pl = getplane(r);
plane *pl = r->planep;
return r->y - plane_center_y(pl) - ursprung_y(f, pl, r);
}

View File

@ -103,10 +103,11 @@ regionname(const region * r, const faction * f)
{
static char buf[65];
const struct locale * lang = f ? f->locale : 0;
plane *pl = getplane(r);
if (r==NULL) {
strcpy(buf, "(null)");
} else if (pl && fval(pl, PFL_NOCOORDS)) {
} else {
plane *pl = r->planep;
if (pl && fval(pl, PFL_NOCOORDS)) {
strncpy(buf, rname(r, lang), 65);
} else {
#ifdef HAVE_SNPRINTF
@ -118,6 +119,7 @@ regionname(const region * r, const faction * f)
sprintf(buf+strlen(buf), " (%d,%d)", region_x(r, f), region_y(r, f));
#endif
}
}
buf[64] = 0;
return buf;
}

View File

@ -664,7 +664,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
dh=0;
if (!getarnt && f) {
if (alliedfaction(getplane(u->region), f, fv, HELP_ALL)) {
if (alliedfaction(u->region->planep, f, fv, HELP_ALL)) {
dh = 1;
}
}
@ -1185,7 +1185,7 @@ prepare_report(faction * f)
for (r = firstregion(f); r != end; r = r->next) {
attrib *ru;
unit * u;
plane * p = rplane(r);
plane * p = r->planep;
unsigned char mode = see_none;
boolean dis = false;
int light = 0;

View File

@ -500,7 +500,7 @@ autoseed(newfaction ** players, int nsize, boolean new_island)
* like the last land virgin ocean region adjacent to land.
*/
for (r=regions;r;r=r->next) {
struct plane * p = rplane(r);
struct plane * p = r->planep;
if (rterrain(r)==T_OCEAN && p==NULL && virgin_region(r)) {
direction_t d;
for (d=0;d!=MAXDIRECTIONS;++d) {
@ -546,7 +546,7 @@ autoseed(newfaction ** players, int nsize, boolean new_island)
* dmin = direction in which it's empty
*/
for (r=regions;r;r=r->next) {
struct plane * p = rplane(r);
struct plane * p = r->planep;
if (rterrain(r)==T_OCEAN && p==0 && (rmin==NULL || r->age<=MAXAGEDIFF)) {
direction_t d;
for (d=0;d!=MAXDIRECTIONS;++d) {