void * start_routine(void * _impl) { IMPL(impl); impl->thread->run(); impl->is_running = false; pthread_exit(0); }
Thread::~Thread() { IMPL(impl); if (is_running()) { pthread_detach(impl->pth); } delete impl; }
const void * image_get_convert_table(videoformat srcfmt, videoformat dstfmt) { switch (FMT(srcfmt, dstfmt)) { #define IMPL(src, dst, size) \ case FMT(fmt_##src, fmt_##dst): \ if (!table_##src##_##dst) \ { \ void * tmp=malloc(size); \ create_tbl_##src##_##dst(tmp); \ table_##src##_##dst=(uint32_t*)tmp; \ } \ return table_##src##_##dst; IMPL(xrgb1555, xrgb8888, sizeof(uint32_t)*65536); IMPL(rgb565, xrgb8888, sizeof(uint32_t)*65536); #undef IMPL } return NULL; }
bool Thread::test_stop() { IMPL(impl); if (is_running() && impl->stop_flag) { impl->is_running = false; abort(); pthread_exit(0); } return false; }
static void context_cleanup(struct urf_context *ctx) { struct impl *impl = IMPL(ctx); if (impl) { deflateEnd(&impl->strm); fclose(impl->fp); free(impl->zbuf); free(impl->page); free(impl); } }
static bool xprintf(struct urf_context *ctx, const char *format, ...) { va_list ap; va_start(ap, format); int status = vfprintf(IMPL(ctx)->fp, format, ap); va_end(ap); if (status < 0) { URF_SET_ERRNO(ctx, "vfprintf"); return false; } return true; }
void Thread::start() throw (ThreadLibraryException) { IMPL(impl); if (impl->pth) { THROW(ThreadLibraryException, "Trying to start thread more than one time"); } impl->is_running = true; if (pthread_create(&impl->pth, thread_attr, start_routine, _impl)) { impl->is_running = false; impl->pth = 0; THROW(ThreadLibraryException, "pthread_create() returned non-zero"); } }
static bool rast_line(struct urf_context *ctx) { #ifdef NODEFLATE #if ASCII85 == 1 return xprint85(ctx, ctx->line_data, ctx->page_line_bytes); #else size_t i = 0; for (; i < ctx->page_line_bytes; ++i) { if (!xputc(ctx, ctx->line_data[i])) { return false; } } return true; #endif #else z_stream *strm = &IMPL(ctx)->strm; strm->avail_in = ctx->page_line_bytes; strm->next_in = (unsigned char*)ctx->line_data; do { strm->avail_out = IMPL(ctx)->zlen; strm->next_out = IMPL(ctx)->zbuf; int flush = (ctx->line_n < ctx->page_hdr->height) ? Z_NO_FLUSH : Z_FINISH; if (deflate(strm, flush) != Z_STREAM_ERROR) { size_t have = IMPL(ctx)->zlen - strm->avail_out; if (have) { #if ASCII85 == 1 if (!xprint85(ctx, IMPL(ctx)->zbuf, have)) { return false; } #else size_t i = 0; for (; i < have; ++i) { if (!xputc(ctx, IMPL(ctx)->zbuf[i])) { return false; } } #endif } } else { URF_SET_ERROR(ctx, "deflate", Z_ERRNO); return false; } } while (strm->avail_out == 0); return true; #endif }
/* <4ee669> ../game_shared/bot/nav_file.cpp:379 */ void CNavArea::Load(SteamFile *file, unsigned int version) { // load ID file->Read(&m_id, sizeof(unsigned int)); // update nextID to avoid collisions if (m_id >= IMPL(m_nextID)) IMPL(m_nextID) = m_id + 1; // load attribute flags file->Read(&m_attributeFlags, sizeof(unsigned char)); // load extent of area file->Read(&m_extent, 6 * sizeof(float)); m_center.x = (m_extent.lo.x + m_extent.hi.x) / 2.0f; m_center.y = (m_extent.lo.y + m_extent.hi.y) / 2.0f; m_center.z = (m_extent.lo.z + m_extent.hi.z) / 2.0f; // load heights of implicit corners file->Read(&m_neZ, sizeof(float)); file->Read(&m_swZ, sizeof(float)); // load connections (IDs) to adjacent areas // in the enum order NORTH, EAST, SOUTH, WEST for (int d = 0; d < NUM_DIRECTIONS; ++d) { // load number of connections for this direction unsigned int count; file->Read(&count, sizeof(unsigned int)); for (unsigned int i = 0; i < count; ++i) { NavConnect connect; file->Read(&connect.id, sizeof(unsigned int)); m_connect[d].push_back(connect); } } // Load hiding spots // load number of hiding spots unsigned char hidingSpotCount; file->Read(&hidingSpotCount, sizeof(unsigned char)); if (version == 1) { // load simple vector array Vector pos; for (int h = 0; h < hidingSpotCount; ++h) { file->Read(&pos, 3 * sizeof(float)); // create new hiding spot and put on master list HidingSpot *spot = new HidingSpot(&pos, HidingSpot::IN_COVER); m_hidingSpotList.push_back(spot); } } else { // load HidingSpot objects for this area for (int h = 0; h < hidingSpotCount; ++h) { // create new hiding spot and put on master list HidingSpot *spot = new HidingSpot; spot->Load(file, version); m_hidingSpotList.push_back(spot); } } // Load number of approach areas file->Read(&m_approachCount, sizeof(unsigned char)); // load approach area info (IDs) unsigned char type; for (int a = 0; a < m_approachCount; ++a) { file->Read(&m_approach[a].here.id, sizeof(unsigned int)); file->Read(&m_approach[a].prev.id, sizeof(unsigned int)); file->Read(&type, sizeof(unsigned char) ); m_approach[a].prevToHereHow = (NavTraverseType)type; file->Read(&m_approach[a].next.id, sizeof(unsigned int)); file->Read(&type, sizeof(unsigned char)); m_approach[a].hereToNextHow = (NavTraverseType)type; } // Load encounter paths for this area unsigned int count; file->Read(&count, sizeof(unsigned int)); if (version < 3) { // old data, read and discard for (unsigned int e = 0; e < count; ++e) { SpotEncounter encounter; file->Read(&encounter.from.id, sizeof(unsigned int)); file->Read(&encounter.to.id, sizeof(unsigned int)); file->Read(&encounter.path.from.x, 3 * sizeof(float)); file->Read(&encounter.path.to.x, 3 * sizeof(float)); // read list of spots along this path unsigned char spotCount; file->Read(&spotCount, sizeof(unsigned char)); for (int s = 0; s < spotCount; ++s) { Vector pos; file->Read(&pos, 3 * sizeof(float)); file->Read(&pos, sizeof(float)); } } return; } for (unsigned int e = 0; e < count; ++e) { SpotEncounter encounter; file->Read(&encounter.from.id, sizeof(unsigned int)); unsigned char dir; file->Read(&dir, sizeof(unsigned char)); encounter.fromDir = static_cast<NavDirType>(dir); file->Read(&encounter.to.id, sizeof(unsigned int)); file->Read(&dir, sizeof(unsigned char)); encounter.toDir = static_cast<NavDirType>(dir); // read list of spots along this path unsigned char spotCount; file->Read(&spotCount, sizeof(unsigned char)); SpotOrder order; for (int s = 0; s < spotCount; ++s) { file->Read(&order.id, sizeof(unsigned int)); unsigned char t; file->Read(&t, sizeof(unsigned char)); order.t = (float)t / 255.0f; encounter.spotList.push_back(order); } m_spotEncounterList.push_back(encounter); } if (version < 5) return; // Load Place data PlaceDirectory::EntryType entry; file->Read(&entry, sizeof(entry)); // convert entry to actual Place SetPlace(placeDirectory.EntryToPlace(entry)); }
VALUETEST (remainder_test1) VALUETEST (remainder_test2) typedef int (*proto_t) (volatile double *p, size_t n, size_t iters); typedef struct { const char *name; proto_t fn; } impl_t; #define IMPL(name) { #name, name ## _t } static impl_t test_list[] = { IMPL (__isnan), IMPL (__isnan_inl), IMPL (__isnan_builtin), IMPL (isnan), IMPL (__isinf), IMPL (__isinf_ns2), IMPL (__isinf_ns_builtin), IMPL (__isinf_builtin), IMPL (isinf), IMPL (__finite), IMPL (__finite_inl), IMPL (__isfinite_builtin), IMPL (isfinite),
name(T *p) { off = ((int)p - (int)base) >> align; } \ T& operator*() const { return *(T*)((int)base + (off << align)); } \ operator T*() const { return (T*)((int)base + (off << align)); } // NearPtr against absolute base. This is what would be used on // MCU platform. // Params: // base - base of the memoty region within which pointer will point // storage_t - size of pointer value (uint8_t, uint16_t, etc.); can be // signed type too if needed // T - type to point to // align - alignment of pointer, as power of 2 // For example, 16-bit NearPtr with alignment of 16 can address 1MB of memory template <int base, typename storage_t, typename T, int align = 0> class AbsNearPtr { IMPL(AbsNearPtr) }; // NearPtr against statically allocated array (note: must have external // linkage, i.e. defined globally w/o static keyword). template <const char *base, typename storage_t, typename T, int align = 0> class ArrayNearPtr { IMPL(ArrayNearPtr) }; // NearPtr against dynamic base store in a variable, for example, received // from malloc(). template <char*& base, typename storage_t, typename T, int align = 0> class VarNearPtr { IMPL(VarNearPtr) };
bool Thread::is_running() { IMPL(impl); return impl->pth != 0 && impl->is_running; }
void Thread::stop() { IMPL(impl); impl->stop_flag = true; }