int v_redisplay_everything (void) { int x, y; int i, layer; char *s; printf ("%s", CLEAR_SCREEN); for (y=0;y<map_size_y;y++) { if (y&1) printf (" "); for (x=0;x<map_size_x/CELL_WIDTH;x++) { for (i=0;i<CELL_WIDTH;i++) { for (layer=LAYERS-1;layer>0;layer--) { s = map_at (layer, x, y); if (s[i] != ' ') { printf ("%c", s[i]); goto next_char; } } s = map_at (0, x, y); printf ("%c", s[i]); next_char: while (0) { } ; /* avoid compiler warning */ } } printf ("\n\n"); } #if 0 printf ("Press <Enter> to continue ..."); getchar (); #endif return 0; }
static unsigned long map_elf(int elf_fd, const Elf32_Ehdr *ehdr) { Elf32_Phdr phdr[ehdr->e_phnum]; unsigned int i; if (ehdr->e_type != ET_EXEC || ehdr->e_machine != EM_386 || ehdr->e_phentsize != sizeof(Elf32_Phdr) || ehdr->e_phnum < 1 || ehdr->e_phnum > 65536U/sizeof(Elf32_Phdr)) errx(1, "Malformed elf header"); if (lseek(elf_fd, ehdr->e_phoff, SEEK_SET) < 0) err(1, "Seeking to program headers"); if (read(elf_fd, phdr, sizeof(phdr)) != sizeof(phdr)) err(1, "Reading program headers"); for (i = 0; i < ehdr->e_phnum; i++) { if (phdr[i].p_type != PT_LOAD) continue; verbose("Section %i: size %i addr %p\n", i, phdr[i].p_memsz, (void *)phdr[i].p_paddr); map_at(elf_fd, from_guest_phys(phdr[i].p_paddr), phdr[i].p_offset, phdr[i].p_filesz); } return ehdr->e_entry; }
/*L:180 * An "initial ram disk" is a disk image loaded into memory along with the * kernel which the kernel can use to boot from without needing any drivers. * Most distributions now use this as standard: the initrd contains the code to * load the appropriate driver modules for the current machine. * * Importantly, James Morris works for RedHat, and Fedora uses initrds for its * kernels. He sent me this (and tells me when I break it). */ static unsigned long load_initrd(const char *name, unsigned long mem) { int ifd; struct stat st; unsigned long len; ifd = open_or_die(name, O_RDONLY); /* fstat() is needed to get the file size. */ if (fstat(ifd, &st) < 0) err(1, "fstat() on initrd '%s'", name); /* * We map the initrd at the top of memory, but mmap wants it to be * page-aligned, so we round the size up for that. */ len = page_align(st.st_size); map_at(ifd, from_guest_phys(mem - len), 0, st.st_size); /* * Once a file is mapped, you can close the file descriptor. It's a * little odd, but quite useful. */ close(ifd); verbose("mapped initrd %s size=%lu @ %p\n", name, len, (void*)mem-len); /* We return the initrd size. */ return len; }
int v_load_map (int sizex, int sizey, char *map) { int x, y, i; char *s, c; map_size_x = sizex * CELL_WIDTH; map_size_y = sizey; _map = (char*) malloc (map_size_x*map_size_y*LAYERS); memset (_map, ' ', map_size_x*map_size_y*LAYERS); for (x=0;x<sizex;x++) { for (y=0;y<sizey;y++) { s=map_at (MAP_LAYER, x, y); c=map[y*sizex + x]; for (i=0;i<NUM_COLONIES;i++) { if (c==colony_home_chars[i]) { s[1] = s[2] = c; goto ok; } } switch (c) { case ROCK_CELL: strncpy (s, " ## ", 4); break; case ' ': case EMPTY_CELL: strncpy (s, " ", 4); break; default: fprintf (stderr, "Warning: Illegal character in internal map (%c)\n", c); } ok: while (0) { } ; /* avoid compiler warning */ } } return v_redisplay_everything (); }
void position_setDirect (Entity e, VECTOR3 pos, SUBHEX ground) { FUNCOPEN (); EntComponent pc = entity_getAs (e, "position"); POSITION pdata = component_getData (pc); SUBHEX oldGround; if (pdata == NULL) { fprintf (stderr, "%s (#%d, ...): entity without position component\n", __FUNCTION__, entity_GUID (e)); FUNCCLOSE (); return; } pdata->pos = pos; oldGround = pdata->position ? hexPos_platter (pdata->position, 1) : NULL; entity_speak (e, "positionUpdate", NULL); if (oldGround != ground) position_messageGroundChange (pc, oldGround, ground); int x = 0, y = 0; v2c (&pos, &x, &y); assert (hexMagnitude (x, y) <= MapRadius); position_set (e, map_at (subhexData (ground, x, y))); FUNCCLOSE (); }
static Pos advance(const Pos &in, Dir d) { Pos p = in; do { p = step(p, d); } while (map_at(p) == MB_SKIP); return p; }
/* * This routine takes an open vmlinux image, which is in ELF, and maps it into * the Guest memory. ELF = Embedded Linking Format, which is the format used * by all modern binaries on Linux including the kernel. * * The ELF headers give *two* addresses: a physical address, and a virtual * address. We use the physical address; the Guest will map itself to the * virtual address. * * We return the starting address. */ static unsigned long map_elf(int elf_fd, const Elf32_Ehdr *ehdr) { Elf32_Phdr phdr[ehdr->e_phnum]; unsigned int i; /* * Sanity checks on the main ELF header: an x86 executable with a * reasonable number of correctly-sized program headers. */ if (ehdr->e_type != ET_EXEC || ehdr->e_machine != EM_386 || ehdr->e_phentsize != sizeof(Elf32_Phdr) || ehdr->e_phnum < 1 || ehdr->e_phnum > 65536U/sizeof(Elf32_Phdr)) errx(1, "Malformed elf header"); /* * An ELF executable contains an ELF header and a number of "program" * headers which indicate which parts ("segments") of the program to * load where. */ /* We read in all the program headers at once: */ if (lseek(elf_fd, ehdr->e_phoff, SEEK_SET) < 0) err(1, "Seeking to program headers"); if (read(elf_fd, phdr, sizeof(phdr)) != sizeof(phdr)) err(1, "Reading program headers"); /* * Try all the headers: there are usually only three. A read-only one, * a read-write one, and a "note" section which we don't load. */ for (i = 0; i < ehdr->e_phnum; i++) { /* If this isn't a loadable segment, we ignore it */ if (phdr[i].p_type != PT_LOAD) continue; verbose("Section %i: size %i addr %p\n", i, phdr[i].p_memsz, (void *)phdr[i].p_paddr); /* We map this section of the file at its physical address. */ map_at(elf_fd, from_guest_phys(phdr[i].p_paddr), phdr[i].p_offset, phdr[i].p_filesz); } /* The entry point is given in the ELF header. */ return ehdr->e_entry; }
static unsigned long load_initrd(const char *name, unsigned long mem) { int ifd; struct stat st; unsigned long len; ifd = open_or_die(name, O_RDONLY); if (fstat(ifd, &st) < 0) err(1, "fstat() on initrd '%s'", name); len = page_align(st.st_size); map_at(ifd, from_guest_phys(mem - len), 0, st.st_size); close(ifd); verbose("mapped initrd %s size=%lu @ %p\n", name, len, (void*)mem-len); return len; }
void position_placeOnHexStep (Entity e, HEX hex, HEXSTEP step) { POSITION pos = component_getData (entity_getAs (e, "position")); hexPos newPos; VECTOR3 newVector; SUBHEX oldGround, newGround; if (!pos) return; if (hex->type != HS_HEX) { ERROR ("Cannot place entity #%d on given hex (%p); it's a platter", entity_GUID (e), hex); return; } newPos = map_at ((SUBHEX)hex); newVector = hex_xyCoord2Space (hex->x, hex->y); newVector.y = step->height * HEX_SIZE_4; oldGround = pos->position ? hexPos_platter (pos->position, 1) : NULL; if (pos->position) map_freePos (pos->position); pos->position = newPos; pos->pos = newVector; entity_speak (e, "positionSet", NULL); newGround = hexPos_platter (newPos, 1); pos->over = step; hex_addOccupant (hex, step, e); entity_speak (e, "positionUpdate", NULL); if (oldGround != newGround) position_messageGroundChange (entity_getAs (e, "position"), oldGround, newGround); }
static bool readConfig() { bool ret = false; try { struct msvalue_s config(true); struct lua_State* L = luaL_newstate(); luaopen_base(L); luaL_openlibs(L); /*TODO::由启动参数指定配置路径*/ ConnectionServerPassword::getInstance().load(L); if (lua_tinker::dofile(L, "ServerConfig//ConnectionServerConfig.lua")) { aux_readluatable_byname(L, "ConnectionServerConfig", &config); } else { throw std::runtime_error("not found ServerConfig//ConnectionServerConfig.lua file"); } map<string, msvalue_s*>& _submapvalue = *config._map; selfIP = map_at(_submapvalue, string("selfIP"))->_str; portForClient = atoi(map_at(_submapvalue, string("portForClient"))->_str.c_str()); portForLogicServer = atoi(map_at(_submapvalue, string("portForLogicServer"))->_str.c_str()); gSelfID = atoi(map_at(_submapvalue, string("id"))->_str.c_str()); map<string, msvalue_s*>& etcdConfig = *map_at(_submapvalue, string("etcdservers"))->_map; for (auto& v : etcdConfig) { map<string, msvalue_s*>& oneconfig = *((v.second)->_map); etcdServers.push_back(std::make_tuple(map_at(oneconfig, string("ip"))->_str, atoi(map_at(oneconfig, string("port"))->_str.c_str()))); } lua_close(L); L = nullptr; ret = true; } catch (const std::exception& e) { errorExit(e.what()); } return ret; }
static char *map_at_pos (int layer, struct position *pos) { return map_at (layer, pos->x, pos->y); }