forked from github/server
delete the old seen.* files
remove includes for seen.h remove unused functions
This commit is contained in:
parent
f520d8396d
commit
20578da0e9
|
@ -18,7 +18,6 @@ without prior permission by the authors of Eressea.
|
|||
#include "bindings.h"
|
||||
#include "move.h"
|
||||
#include "reports.h"
|
||||
#include "seen.h"
|
||||
#include "guard.h"
|
||||
|
||||
/* attributes includes */
|
||||
|
|
|
@ -26,7 +26,6 @@ without prior permission by the authors of Eressea.
|
|||
#include "helpers.h"
|
||||
#include "console.h"
|
||||
#include "reports.h"
|
||||
#include "seen.h"
|
||||
#include "study.h"
|
||||
#include "calendar.h"
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "reports.h"
|
||||
#include "jsreport.h"
|
||||
#include "seen.h"
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/terrain.h>
|
||||
|
|
|
@ -22,7 +22,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/config.h>
|
||||
|
||||
#include "reports.h"
|
||||
#include "seen.h"
|
||||
#include "laws.h"
|
||||
#include "travelthru.h"
|
||||
#include "monster.h"
|
||||
|
|
|
@ -1142,25 +1142,6 @@ static void faction_add_seen(faction *f, region *r, seen_mode mode) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static void view_default(region * r, faction * f)
|
||||
{
|
||||
int dir;
|
||||
for (dir = 0; dir != MAXDIRECTIONS; ++dir) {
|
||||
region *r2 = rconnect(r, dir);
|
||||
if (r2) {
|
||||
connection *b = get_borders(r, r2);
|
||||
while (b) {
|
||||
if (!b->type->transparent(b, f))
|
||||
break;
|
||||
b = b->next;
|
||||
}
|
||||
if (!b) {
|
||||
add_seen(r2, seen_neighbour);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void view_neighbours(struct seen_region **seen, region * r, faction * f)
|
||||
{
|
||||
int d;
|
||||
|
@ -1470,13 +1451,6 @@ void prepare_seen(report_context *ctx)
|
|||
ctx->last = lastregion(f);
|
||||
}
|
||||
|
||||
static void cb_set_last(region *r, unit *u, void *cbdata) {
|
||||
faction *f = (faction *)cbdata;
|
||||
if (u->faction == f) {
|
||||
f->last = r;
|
||||
}
|
||||
}
|
||||
|
||||
static void prepare_report(report_context *ctx, faction *f)
|
||||
{
|
||||
ctx->f = f;
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "report.h"
|
||||
#include "creport.h"
|
||||
#include "move.h"
|
||||
#include "seen.h"
|
||||
#include "travelthru.h"
|
||||
#include "keyword.h"
|
||||
|
||||
|
|
139
src/seen.c
139
src/seen.c
|
@ -1,139 +0,0 @@
|
|||
/*
|
||||
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "seen.h"
|
||||
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/faction.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define MAXSEEHASH 0x1000
|
||||
seen_region *reuse;
|
||||
|
||||
seen_region **seen_init(void)
|
||||
{
|
||||
return (seen_region **)calloc(MAXSEEHASH, sizeof(seen_region *));
|
||||
}
|
||||
|
||||
void seen_done(seen_region * seehash[])
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i != MAXSEEHASH; ++i) {
|
||||
seen_region *sd = seehash[i];
|
||||
if (sd == NULL)
|
||||
continue;
|
||||
while (sd->nextHash != NULL)
|
||||
sd = sd->nextHash;
|
||||
sd->nextHash = reuse;
|
||||
reuse = seehash[i];
|
||||
seehash[i] = NULL;
|
||||
}
|
||||
free(seehash);
|
||||
}
|
||||
|
||||
void free_seen(void)
|
||||
{
|
||||
while (reuse) {
|
||||
seen_region *r = reuse;
|
||||
reuse = reuse->nextHash;
|
||||
free(r);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
link_seen(seen_region * seehash[], const region * first, const region * last)
|
||||
{
|
||||
const region *r = first;
|
||||
seen_region *sr = NULL;
|
||||
|
||||
if (first == last)
|
||||
return;
|
||||
|
||||
do {
|
||||
sr = find_seen(seehash, r);
|
||||
r = r->next;
|
||||
} while (sr == NULL && r != last);
|
||||
|
||||
while (r != last) {
|
||||
seen_region *sn = find_seen(seehash, r);
|
||||
if (sn != NULL) {
|
||||
sr->next = sn;
|
||||
sr = sn;
|
||||
}
|
||||
r = r->next;
|
||||
}
|
||||
if (sr) sr->next = 0;
|
||||
}
|
||||
|
||||
seen_region *find_seen(struct seen_region *seehash[], const region * r)
|
||||
{
|
||||
unsigned int index = reg_hashkey(r) & (MAXSEEHASH - 1);
|
||||
seen_region *find = seehash[index];
|
||||
while (find) {
|
||||
if (find->r == r) {
|
||||
return find;
|
||||
}
|
||||
find = find->nextHash;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void seenhash_map(struct seen_region *seen[], void(*cb)(seen_region *, void *), void *cbdata) {
|
||||
int i;
|
||||
for (i = 0; i != MAXSEEHASH; ++i) {
|
||||
seen_region *sr = seen[i];
|
||||
while (sr != NULL) {
|
||||
cb(sr, cbdata);
|
||||
sr = sr->nextHash;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct cb_interval {
|
||||
region *first;
|
||||
region *last;
|
||||
} cb_interval;
|
||||
|
||||
static void cb_get_interval(seen_region *sr, void *cbdata) {
|
||||
cb_interval *iv = (cb_interval *)cbdata;
|
||||
region *r = sr->r;
|
||||
if (iv->first == NULL || r->index < iv->first->index) {
|
||||
iv->first = r;
|
||||
}
|
||||
if (iv->last != NULL && r->index >= iv->last->index) {
|
||||
iv->last = r->next;
|
||||
}
|
||||
}
|
||||
|
||||
/* this function adds the neighbour regions of the ones we have seen
|
||||
* to the interval, which may be outside of [faction.first, faction.last)
|
||||
*/
|
||||
void get_seen_interval(struct seen_region *seen[], struct region **firstp, struct region **lastp)
|
||||
{
|
||||
cb_interval interval;
|
||||
|
||||
interval.first = *firstp;
|
||||
interval.last = *lastp;
|
||||
seenhash_map(seen, cb_get_interval, &interval);
|
||||
*firstp = interval.first;
|
||||
*lastp = interval.last;
|
||||
}
|
52
src/seen.h
52
src/seen.h
|
@ -1,52 +0,0 @@
|
|||
#pragma once
|
||||
/*
|
||||
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
**/
|
||||
|
||||
#ifndef H_SEEN_REGION
|
||||
#define H_SEEN_REGION
|
||||
|
||||
struct region;
|
||||
struct faction;
|
||||
struct seen_region;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct seen_region {
|
||||
struct seen_region *nextHash;
|
||||
struct seen_region *next;
|
||||
struct region *r;
|
||||
seen_t mode;
|
||||
bool disbelieves; /* potion of truth */
|
||||
} seen_region;
|
||||
|
||||
struct seen_region **seen_init(void);
|
||||
void seen_done(struct seen_region *seehash[]);
|
||||
void free_seen(void);
|
||||
void link_seen(struct seen_region *seehash[], const struct region * first, const struct region * last);
|
||||
struct seen_region *find_seen(struct seen_region *seehash[], const struct region * r);
|
||||
void get_seen_interval(struct seen_region *seen[], struct region **firstp, struct region **lastp);
|
||||
seen_region *add_seen(struct seen_region *seehash[], struct region *r, seen_t mode, bool dis);
|
||||
void link_seen(struct seen_region *seehash[], const struct region *first, const struct region *last);
|
||||
void seenhash_map(struct seen_region *seen[], void(*cb)(struct seen_region *, void *), void *cbdata);
|
||||
struct seen_region *faction_add_seen(struct faction *f, struct region *r, seen_t mode);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
202
src/seen.test.c
202
src/seen.test.c
|
@ -1,202 +0,0 @@
|
|||
#include <platform.h>
|
||||
#include <config.h>
|
||||
#include "seen.h"
|
||||
#include "reports.h"
|
||||
#include "travelthru.h"
|
||||
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/faction.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
static void setup_seen(int x, int y) {
|
||||
int dir;
|
||||
|
||||
for (dir = 0; dir != MAXDIRECTIONS; ++dir) {
|
||||
test_create_region(x+delta_x[dir], y+delta_y[dir], 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_add_seen(CuTest *tc) {
|
||||
region *r;
|
||||
seen_region **seen, *sr;
|
||||
|
||||
test_setup();
|
||||
seen = seen_init();
|
||||
r = test_create_region(0, 0, 0);
|
||||
sr = add_seen(seen, r, see_travel, false);
|
||||
CuAssertPtrEquals(tc, r, sr->r);
|
||||
CuAssertIntEquals(tc, see_travel, sr->mode);
|
||||
CuAssertIntEquals(tc, false, sr->disbelieves);
|
||||
CuAssertPtrEquals(tc, 0, sr->next);
|
||||
CuAssertPtrEquals(tc, 0, sr->nextHash);
|
||||
CuAssertPtrEquals(tc, sr, find_seen(seen, r));
|
||||
sr = add_seen(seen, r, see_neighbour, true);
|
||||
CuAssertIntEquals(tc, true, sr->disbelieves);
|
||||
CuAssertIntEquals(tc, see_travel, sr->mode);
|
||||
sr = add_seen(seen, r, see_unit, false);
|
||||
CuAssertIntEquals(tc, true, sr->disbelieves);
|
||||
CuAssertIntEquals(tc, see_unit, sr->mode);
|
||||
seen_done(seen);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_faction_add_seen(CuTest *tc) {
|
||||
faction *f;
|
||||
seen_region *sr;
|
||||
|
||||
test_setup();
|
||||
f = test_create_faction(0);
|
||||
f->seen = seen_init();
|
||||
test_create_region(0, 0, 0);
|
||||
test_create_region(0, 1, 0);
|
||||
sr = faction_add_seen(f, regions, see_unit);
|
||||
CuAssertIntEquals(tc, false, sr->disbelieves);
|
||||
CuAssertPtrEquals(tc, regions, f->first);
|
||||
CuAssertPtrEquals(tc, regions, f->last);
|
||||
seen_done(f->seen);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_prepare_seen(CuTest *tc) {
|
||||
region *r;
|
||||
faction *f;
|
||||
unit *u;
|
||||
|
||||
test_setup();
|
||||
f = test_create_faction(0);
|
||||
r = test_create_region(0, 0, 0);
|
||||
u = test_create_unit(f, r);
|
||||
f->seen = seen_init();
|
||||
faction_add_seen(f, r, see_unit);
|
||||
setup_seen(0, 0);
|
||||
r = test_create_region(2, 2, 0);
|
||||
setup_seen(2, 2);
|
||||
travelthru_add(r, u);
|
||||
|
||||
init_reports();
|
||||
prepare_seen(f);
|
||||
CuAssertPtrEquals(tc, regions, f->first);
|
||||
CuAssertPtrEquals(tc, 0, f->last);
|
||||
seen_done(f->seen);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_seen_travelthru(CuTest *tc) {
|
||||
seen_region *sr;
|
||||
region *r;
|
||||
faction *f;
|
||||
unit *u;
|
||||
|
||||
test_setup();
|
||||
setup_seen(0, 0);
|
||||
f = test_create_faction(0);
|
||||
u = test_create_unit(f, test_create_region(0, 0, 0));
|
||||
r = test_create_region(0, 1, 0);
|
||||
travelthru_add(r, u);
|
||||
init_reports();
|
||||
view_default(f->seen, r, f);
|
||||
get_seen_interval(f->seen, &f->first, &f->last);
|
||||
link_seen(f->seen, f->first, f->last);
|
||||
CuAssertPtrEquals(tc, regions, f->first);
|
||||
CuAssertPtrEquals(tc, 0, f->last);
|
||||
sr = find_seen(f->seen, regions);
|
||||
CuAssertPtrEquals(tc, regions, sr->r);
|
||||
CuAssertIntEquals(tc, see_neighbour, sr->mode);
|
||||
sr = find_seen(f->seen, r);
|
||||
CuAssertPtrEquals(tc, r, sr->r);
|
||||
CuAssertIntEquals(tc, see_travel, sr->mode);
|
||||
seen_done(f->seen);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_seen_region(CuTest *tc) {
|
||||
seen_region **seen, *sr;
|
||||
region *r;
|
||||
|
||||
test_setup();
|
||||
setup_seen(0, 0);
|
||||
r = test_create_region(0, 0, 0);
|
||||
seen = seen_init();
|
||||
add_seen(seen, r, see_unit, false);
|
||||
sr = find_seen(seen, r);
|
||||
CuAssertPtrEquals(tc, r, sr->r);
|
||||
seen_done(seen);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_seen_interval_backward(CuTest *tc) {
|
||||
region *r, *first, *last;
|
||||
seen_region **seen;
|
||||
|
||||
test_setup();
|
||||
r = test_create_region(0, 0, 0);
|
||||
setup_seen(0, 0);
|
||||
seen = seen_init();
|
||||
add_seen(seen, r, see_unit, false);
|
||||
view_default(seen, r, 0);
|
||||
first = r;
|
||||
last = 0;
|
||||
get_seen_interval(seen, &first, &last);
|
||||
CuAssertPtrEquals(tc, regions, first);
|
||||
CuAssertPtrEquals(tc, 0, last);
|
||||
seen_done(seen);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_seen_interval_forward(CuTest *tc) {
|
||||
region *r, *first, *last;
|
||||
seen_region **seen;
|
||||
|
||||
test_setup();
|
||||
setup_seen(0, 0);
|
||||
r = test_create_region(0, 0, 0);
|
||||
seen = seen_init();
|
||||
add_seen(seen, r, see_unit, true);
|
||||
view_default(seen, r, 0);
|
||||
first = r;
|
||||
last = 0;
|
||||
get_seen_interval(seen, &first, &last);
|
||||
CuAssertPtrEquals(tc, regions, first);
|
||||
CuAssertPtrEquals(tc, 0, last);
|
||||
seen_done(seen);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void cb_testmap(seen_region *sr, void *cbdata) {
|
||||
int *ip = (int *)cbdata;
|
||||
*ip += sr->r->y;
|
||||
}
|
||||
|
||||
static void test_seenhash_map(CuTest *tc) {
|
||||
region *r;
|
||||
seen_region **seen;
|
||||
int i = 0;
|
||||
|
||||
test_setup();
|
||||
seen = seen_init();
|
||||
r = test_create_region(1, 1, 0);
|
||||
add_seen(seen, r, see_unit, false);
|
||||
r = test_create_region(2, 2, 0);
|
||||
add_seen(seen, r, see_unit, false);
|
||||
seenhash_map(seen, cb_testmap, &i);
|
||||
CuAssertIntEquals(tc, 3, i);
|
||||
seen_done(seen);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_seen_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
DISABLE_TEST(suite, test_prepare_seen);
|
||||
DISABLE_TEST(suite, test_seen_travelthru);
|
||||
DISABLE_TEST(suite, test_add_seen);
|
||||
DISABLE_TEST(suite, test_faction_add_seen);
|
||||
DISABLE_TEST(suite, test_seen_region);
|
||||
DISABLE_TEST(suite, test_seen_interval_backward);
|
||||
DISABLE_TEST(suite, test_seen_interval_forward);
|
||||
DISABLE_TEST(suite, test_seenhash_map);
|
||||
return suite;
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
#include <platform.h>
|
||||
#include "tests.h"
|
||||
#include "keyword.h"
|
||||
#include "seen.h"
|
||||
#include "prefix.h"
|
||||
#include "reports.h"
|
||||
|
||||
|
|
Loading…
Reference in New Issue