Esempio n. 1
0
int main (int argc, char **argv)
{
	srand(time(0));

	MAP map;
	setDefaults(&map);

	PLAYER hero;
	startPlayer(&hero);

	getargs(&map, &hero, argc, argv);

	startMap(&map);
	hero.face = map.elements.hero.face;
	hero.pos = putElement(&map, hero.face);

	GHOSTS ghosts;
	ghosts.face = GHOST;
	ghosts.count = 0;

	startGhosts(&map, &ghosts);

	fflush(stdout);
	initscr();
	nodelay(stdscr, TRUE);
	noecho();
	keypad(stdscr, TRUE);

	if (map.props.hascolor)
		startColors();

	struct timespec tim, tim2;
	tim.tv_sec = 0;
	tim.tv_nsec = map.props.speed;

	do {
		nanosleep(&tim, &tim2);
		getCommand(&hero);
		walk(&map, &hero, &ghosts);
		showMap(&map, &hero, &ghosts);
		repopMap(&map);
		upGhosts(&map, &ghosts);
		walkGhosts(&map, &ghosts);

	} while (!isDead(&hero));

	if (!noRecords)
		writeRecords(&hero, &ghosts);
	finalize(&map, &ghosts);
	finalText(&map, &hero, &ghosts);

	exit(0);

}
Esempio n. 2
0
void Map::autoStart () {
	// already spawned
	if (!_players.empty())
		return;
	// no players available yet
	if (_playersWaitingForSpawn.empty())
		return;
	// singleplayer already auto starts a map
	if (!_serviceProvider->getNetwork().isMultiplayer())
		return;
	// not enough players connected yet
	if (_playersWaitingForSpawn.size() < _startPositions.size())
		return;
	info(LOG_SERVER, "starting the map");
	startMap();
}
Esempio n. 3
0
static void buildAllBlocks()
{
    auto e = mapVec.end();
    auto i = mapVec.begin();
    while(i!=e) {

        const Map *map = gCurMap = &(*(i++));
        const uint8_t *end = map->size + map->p;
        const uint8_t *p = map->p;

        startMap(p);

            while(1) {
                if(unlikely(end<=p)) break;
                bool done = buildBlock(p, end);
                if(done) break;
            }

        endMap(p);
    }
}
Esempio n. 4
0
static void buildBlockHeaders() {

    info("pass 1 -- walk all blocks and build headers ...");

    size_t nbBlocks = 0;
    size_t baseOffset = 0;
    size_t earlyMissCnt = 0;
    uint8_t buf[8+gHeaderSize];
    const auto sz = sizeof(buf);
    const auto startTime = usecs();
    const auto oneMeg = 1024 * 1024;

    for(const auto &map : mapVec) {

        startMap(0);

        while(1) {

            auto nbRead = read(map.fd, buf, sz);
            if(nbRead<(signed)sz) {
                break;
            }

            startBlock((uint8_t*)0);

            uint8_t *hash = 0;
            Block *prevBlock = 0;
            size_t blockSize = 0;

            getBlockHeader(blockSize, prevBlock, hash, earlyMissCnt, buf);
            if(unlikely(0==hash)) {
                break;
            }

            auto where = lseek(map.fd, (blockSize + 8) - sz, SEEK_CUR);
            auto blockOffset = where - blockSize;
            if(where<0) {
                break;
            }

            auto block = Block::alloc();
            block->init(hash, &map, blockSize, prevBlock, blockOffset);
            gBlockMap[hash] = block;
            endBlock((uint8_t*)0);
            ++nbBlocks;
        }
        baseOffset += map.size;

        auto now = usecs();
        auto elapsed = now - startTime;
        auto bytesPerSec = baseOffset / (elapsed*1e-6);
        auto bytesLeft = gChainSize - baseOffset;
        auto secsLeft = bytesLeft / bytesPerSec;
        fprintf(
            stderr,
            "%.2f%% (%.2f/%.2f Gigs) -- %6d blocks -- %.2f Megs/sec -- ETA %.0f secs -- ELAPSED %.0f secs            \r",
            (100.0*baseOffset)/gChainSize,
            baseOffset/(1000.0*oneMeg),
            gChainSize/(1000.0*oneMeg),
            (int)nbBlocks,
            bytesPerSec*1e-6,
            secsLeft,
            elapsed*1e-6
        );
        fflush(stderr);

        endMap(0);
    }

    if(0==nbBlocks) {
        warning("found no blocks - giving up");
        exit(1);
    }

    char msg[128];
    msg[0] = 0;
    if(0<earlyMissCnt) {
        sprintf(msg, ", %d early link misses", (int)earlyMissCnt);
    }

    auto elapsed = 1e-6*(usecs() - startTime);
    info(
        "pass 1 -- took %.0f secs, %6d blocks, %.2f Gigs, %.2f Megs/secs %s                                            ",
        elapsed,
        (int)nbBlocks,
        (gChainSize * 1e-9),
        (gChainSize * 1e-6) / elapsed,
        msg
    );
}