/** * @return The flags that should be excluded from the missile delta. */ int Sv_MRCheck(pool_t *pool, const mobjdelta_t *mobj) { misrecord_t *mis; int exclude = 0; #ifdef _DEBUG if (!(mobj->mo.ddFlags & DDMF_MISSILE)) { App_Error("Sv_MRCheck: Not a missile.\n"); } #endif if ((mis = Sv_MRFind(pool, mobj->delta.id)) == NULL) { // No record for this; no basis for exclusion. return 0; } // Exclude each axis separately. If no change in momentum, exclude coord. if (!(mobj->delta.flags & MDF_MOM_X)) exclude |= MDF_ORIGIN_X; if (!(mobj->delta.flags & MDF_MOM_Y)) exclude |= MDF_ORIGIN_Y; if (!(mobj->delta.flags & MDF_MOM_Z)) exclude |= MDF_ORIGIN_Z; return exclude; }
void B_AppendDeviceDescToString(uint device, ddeventtype_t type, int id, ddstring_t* str) { inputdev_t *dev = I_GetDevice(device); const char* name; if(type != E_SYMBOLIC) { // Name of the device. Str_Append(str, dev->name); Str_Append(str, "-"); } switch(type) { case E_TOGGLE: if(dev->keys[id].name) { Str_Append(str, dev->keys[id].name); } else if(device == IDEV_KEYBOARD) { name = B_ShortNameForKey(id); if(name) Str_Append(str, name); else Str_Appendf(str, "code%03i", id); } else Str_Appendf(str, "button%i",id + 1); break; case E_AXIS: Str_Append(str, dev->axes[id].name); break; case E_ANGLE: Str_Appendf(str, "hat%i", id + 1); break; case E_SYMBOLIC: Str_Append(str, "sym"); break; default: App_Error("B_AppendDeviceDescToString: Invalid value, type = %i.", (int) type); break; } }
/** * Adds an entry for the mobj into the missile record. */ void Sv_MRAdd(pool_t *pool, const mobjdelta_t *delta) { thid_t id = delta->delta.id; mislink_t *hash = Sv_MRHash(pool, id); misrecord_t *mis; #ifdef _DEBUG if (!(delta->mo.ddFlags & DDMF_MISSILE)) { App_Error("Sv_MRAdd: Not a missile.\n"); } #endif // Try to find an existing entry. mis = Sv_MRFind(pool, id); // Create a new record if necessary. if (!mis) { mis = (misrecord_t *) Z_Malloc(sizeof(misrecord_t), PU_MAP, 0); mis->id = id; // Link it in. mis->next = NULL; mis->prev = hash->last; if (hash->last) hash->last->next = mis; hash->last = mis; if (!hash->first) hash->first = mis; } // Update the momentum. /* mis->momx = delta->mo.momx; mis->momy = delta->mo.momy; mis->momz = delta->mo.momz; */ }
/** * Sets up module state for running a busy task. After this the busy mode event * loop is started. The loop will run until the worker thread exits. */ static void beginTask(BusyTask* task) { DENG_ASSERT(task); if(!busyInited) { busy_Mutex = Sys_CreateMutex("BUSY_MUTEX"); } if(busyInited) { App_Error("Con_Busy: Already busy.\n"); } BusyVisual_PrepareResources(); Sys_Lock(busy_Mutex); busyDone = false; busyTaskEndedWithError = false; // This is now the current task. busyTask = task; Sys_Unlock(busy_Mutex); busyInited = true; de::ProgressWidget &prog = ClientWindow::main().busy().progress(); prog.show(); prog.setText(task->name); prog.setMode(task->mode & BUSYF_ACTIVITY? de::ProgressWidget::Indefinite : de::ProgressWidget::Ranged); // Start the busy worker thread, which will process the task in the // background while we keep the user occupied with nice animations. busyThread = Sys_StartThread(busyTask->worker, busyTask->workerData); Thread_SetCallback(busyThread, busyWorkerTerminated); busyTask->_startTime = Timer_RealSeconds(); }
Svg* Svg_FromDef(svgid_t uniqueId, const def_svgline_t* lines, uint lineCount) { uint finalLineCount, finalPointCount; const def_svgline_t* slIt; const Point2Rawf* spIt; dd_bool lineIsLoop; SvgLinePoint* dpIt, *prev; SvgLine* dlIt; uint i, j; Svg* svg; if(!lines || lineCount == 0) return NULL; svg = (Svg*)malloc(sizeof(*svg)); if(!svg) App_Error("Svg::FromDef: Failed on allocation of %lu bytes for new Svg.", (unsigned long) sizeof(*svg)); svg->id = uniqueId; svg->dlist = 0; // Count how many lines and points we actually need. finalLineCount = 0; finalPointCount = 0; slIt = lines; for(i = 0; i < lineCount; ++i, slIt++) { // Skip lines with missing vertices... if(slIt->numPoints < 2) continue; ++finalLineCount; finalPointCount += slIt->numPoints; if(slIt->numPoints > 2) { // If the end point is equal to the start point, we'll ommit it and // set this line up as a loop. if(FEQUAL(slIt->points[slIt->numPoints-1].x, slIt->points[0].x) && FEQUAL(slIt->points[slIt->numPoints-1].y, slIt->points[0].y)) { finalPointCount -= 1; } } } // Allocate the final point set. svg->numPoints = finalPointCount; svg->points = (SvgLinePoint*)malloc(sizeof(*svg->points) * svg->numPoints); if(!svg->points) App_Error("Svg::FromDef: Failed on allocation of %lu bytes for new SvgLinePoint set.", (unsigned long) (sizeof(*svg->points) * finalPointCount)); // Allocate the final line set. svg->lineCount = finalLineCount; svg->lines = (SvgLine*)malloc(sizeof(*svg->lines) * finalLineCount); if(!svg->lines) App_Error("Svg::FromDef: Failed on allocation of %lu bytes for new SvgLine set.", (unsigned long) (sizeof(*svg->lines) * finalLineCount)); // Setup the lines. slIt = lines; dlIt = svg->lines; dpIt = svg->points; for(i = 0; i < lineCount; ++i, slIt++) { // Skip lines with missing vertices... if(slIt->numPoints < 2) continue; // Determine how many points we'll need. dlIt->numPoints = slIt->numPoints; lineIsLoop = false; if(slIt->numPoints > 2) { // If the end point is equal to the start point, we'll ommit it and // set this line up as a loop. if(FEQUAL(slIt->points[slIt->numPoints-1].x, slIt->points[0].x) && FEQUAL(slIt->points[slIt->numPoints-1].y, slIt->points[0].y)) { dlIt->numPoints -= 1; lineIsLoop = true; } } // Copy points. spIt = slIt->points; dlIt->head = dpIt; prev = NULL; for(j = 0; j < dlIt->numPoints; ++j, spIt++) { SvgLinePoint* next = (j < dlIt->numPoints-1)? dpIt + 1 : NULL; dpIt->coords.x = spIt->x; dpIt->coords.y = spIt->y; // Link in list. dpIt->next = next; dpIt->prev = prev; // On to the next point! prev = dpIt; dpIt++; } // Link circularly? prev->next = lineIsLoop? dlIt->head : NULL; dlIt->head->prev = lineIsLoop? prev : NULL; // On to the next line! dlIt++; } return svg; }
int BusyMode_RunTasks(BusyTask* tasks, int numTasks) { const char* currentTaskName = NULL; BusyTask* task; int i, mode; int result = 0; if(BusyMode_Active()) { App_Error("BusyMode: Internal error, already busy..."); exit(1); // Unreachable. } if(!tasks || numTasks <= 0) return result; // Hmm, no work? // Pick the first task. task = tasks; int initialMode = task->mode; preBusySetup(initialMode); // Process tasks. for(i = 0; i < numTasks; ++i, task++) { // If no new task name is specified, continue using the name of the previous task. if(task->name) { if(task->name[0]) currentTaskName = task->name; else // Clear the name. currentTaskName = NULL; } mode = task->mode; /// @todo Kludge: Force BUSYF_STARTUP here so that the animation of one task /// is not drawn on top of the last frame of the previous. if(numTasks > 1) { mode |= BUSYF_STARTUP; } // kludge end // Null tasks are not processed (implicit success). if(!task->worker) continue; /** * Process the work. */ #ifdef __CLIENT__ // Is the worker updating its progress? if(task->maxProgress > 0) Con_InitProgress2(task->maxProgress, task->progressStart, task->progressEnd); #endif // Invoke the worker in a new thread. /// @todo Kludge: Presently a temporary local task is needed so that we can modify /// the task name and mode flags. { BusyTask* tmp = newTask(mode, task->worker, task->workerData, currentTaskName); result = runTask(tmp); // We are now done with this task. deleteTask(tmp); if(result) break; } // kludge end. } postBusyCleanup(); return result; }
/** * Adds a new node to a node pile. * Pos always has the index of the next node to check when allocating * a new node. Pos shouldn't be accessed outside this routine because its * value may prove to be outside the valid range. * * @param pile Ptr to nodepile to add the node to. * @param ptr Data to attach to the new node. */ nodeindex_t NP_New(nodepile_t *pile, void *ptr) { linknode_t *node; linknode_t *end = pile->nodes + pile->count; int i, newcount; linknode_t *newlist; dd_bool found; pile->pos %= pile->count; node = pile->nodes + pile->pos++; // Scan for an unused node, starting from current pos. i = 0; found = false; while(i < pile->count - 1 && !found) { if(node == end) node = pile->nodes + 1; // Wrap back to #1. if(!node->ptr) { // This is the one! found = true; } else { i++; node++; pile->pos++; } } if(!found) { // Damned, we ran out of nodes. Let's allocate more. if(pile->count == NP_MAX_NODES) { // This happens *theoretically* only in freakishly complex // maps with lots and lots of mobjs. App_Error("NP_New: Out of linknodes! Contact the developer.\n"); } // Double the number of nodes, but add at most 1024. if(pile->count >= 1024) newcount = pile->count + 1024; else newcount = pile->count * 2; if(newcount > NP_MAX_NODES) newcount = NP_MAX_NODES; newlist = (linknode_t *) Z_Malloc(sizeof(*newlist) * newcount, PU_MAP, 0); memcpy(newlist, pile->nodes, sizeof(*pile->nodes) * pile->count); memset(newlist + pile->count, 0, (newcount - pile->count) * sizeof(*newlist)); // Get rid of the old list and start using the new one. Z_Free(pile->nodes); pile->nodes = newlist; pile->pos = pile->count + 1; node = pile->nodes + pile->count; pile->count = newcount; } node->ptr = ptr; // Make it point to itself by default (a root, basically). node->next = node->prev = node - pile->nodes; return node->next; // Well, node's index, really. }
void App_Initialize(){ struct termios2 opt; struct UART_MAP_PIN map_pin; struct COMMON_SET_OSC osc; struct DRV_GPIO_ENABLE gpio_enable; struct DRV_GPIO_WRITE gpio_write; struct DRV_EXT_INTR_MAP_PIN ext_intr_map; struct DRV_EXT_INTR_CFG ext_intr_cfg; unsigned int mode; unsigned int bits; unsigned long long speed; struct spi_ioc_map_pin spi_map; int fd; drv_initialize(); // Load all driver is link // Common DRV osc.frc = 8000000L; osc.primary = 25000000L; osc.secondary = 25000000L; osc.low_power = 31000L; fd = drv_findFdByName("common"); ioctl(fd, COMMON_IOCTL_SET_OSC_FREQ, &osc); // UART DRV g_fd_uart0 = open("uart0", 0); if(g_fd_uart0 < 0) App_Error(); ioctl(g_fd_uart0, TCGETS2, &opt); opt.c_ispeed = 115200; opt.c_ospeed = 115200; opt.c_cflag &= ~CSIZE; opt.c_cflag |= CS8; opt.c_cflag &= ~CSTOPB; opt.c_cflag &= ~PARENB; opt.c_iflag &= ~INPCK; ioctl(g_fd_uart0, TCSETS2, &opt); map_pin.rx = UART_RX_PIN; map_pin.tx = UART_TX_PIN; ioctl(g_fd_uart0, UART_IOCTL_MAP_PIN, &map_pin); // GPIO g_fd_gpio = open("gpio", 0); if(g_fd_gpio < 0) LREP("open gpio failed\r\n"); else{ gpio_enable.pin = LED_STATUS; fd = ioctl(g_fd_gpio, DRV_GPIO_IOCTL_ENABLE, &gpio_enable); gpio_write.pin = LED_STATUS; gpio_write.value = DRV_GPIO_LOW; fd = ioctl(g_fd_gpio, DRV_GPIO_IOCTL_WRITE, &gpio_write); gpio_enable.pin = RESET_PIN; gpio_enable.dir = DRV_GPIO_OUTPUT; gpio_enable.opendrain = DRV_GPIO_OPEN_DRAIN_DISABLE; fd = ioctl(g_fd_gpio, DRV_GPIO_IOCTL_ENABLE, &gpio_enable); if(fd != 0){ LREP("enable gpio %d failed\r\n", RESET_PIN); } } // External interrupt g_fd_ext_intr_1 = open("ext_intr_1", 0); if(g_fd_ext_intr_1 < 0) LREP("open external interrupt failed\r\n"); else{ ext_intr_cfg.intr_type = DRV_EXT_INTR_RISING; ext_intr_cfg.prio = 2; fd = ioctl(g_fd_ext_intr_1, DRV_EXT_INTR_IOCTL_CFG, &ext_intr_cfg); if(fd != 0) LREP("config external interrupt failed\r\n"); ext_intr_map.rpin = EXT_INTR_PIN;// fd = ioctl(g_fd_ext_intr_1, DRV_EXT_INTR_IOCTL_MAP_PIN, &ext_intr_map); if(fd != 0) LREP("map external interrupt failed\r\n"); } // spi // g_fd_spi_1 = open("spi1", 0); // if(g_fd_spi_1 < 0) LREP("open spi device\r\n"); // else{ // mode = SPI_MODE_0; // bits = 8; // speed = 1000000L; // spi_map.sck = SPI_SCK_PIN; // spi_map.sdi = SPI_SDI_PIN; // spi_map.sdo = SPI_SDO_PIN; // spi_map.ss = SPI_SS_PIN; // // fd = ioctl(g_fd_spi_1, SPI_IOC_WR_MODE, &mode); // if (fd == -1) // LREP("can't set spi mode\r\n"); // /* // * bits per word // */ // fd = ioctl(g_fd_spi_1, SPI_IOC_WR_BITS_PER_WORD, &bits); // if (fd == -1) // LREP("can't set bits per word\r\n"); // /* // * max speed hz // */ // fd = ioctl(g_fd_spi_1, SPI_IOC_WR_MAX_SPEED_HZ, &speed); // if (fd == -1) // LREP("can't set max speed hz\r\n"); // fd = ioctl(g_fd_spi_1, SPI_IOC_WR_MAP_PIN, &spi_map); // if (fd == -1) // LREP("can't map pin\r\n"); // else{ // DRV_ADC_DISABLE_PIN(DRV_PIN_ADC(8)); // DRV_ADC_DISABLE_PIN(DRV_PIN_ADC(9)); // DRV_ADC_DISABLE_PIN(DRV_PIN_ADC(14)); // DRV_ADC_DISABLE_PIN(DRV_PIN_ADC(15)); // } // flash g_fd_flash = open("en25f80_1", 0); // if(g_fd_flash >= 0){ // fd = ioctl(g_fd_flash, EN25F80_IOC_WR_SPI_FD, &g_fd_spi_1); // if (fd < 0) // LREP("can't set fd\r\n"); // }else{ // LREP("open flash false\r\n"); // } // } }