/** * @param load_callback Responsible for registering all the VFS callbacks * required for the game. After load_callback has been * run, assets are immediately loaded. * @param init_callback Runs after assets are loaded, and should set up game * objects to their initial state. * @param release_callback Runs just before the game quits, and should release * all assets and free dynamically allocated memory. */ void core_setup(const char *title, float view_width, float view_height, int window_width, int window_height, int window_mode, size_t game_memory_size) { lodge_window_initialize(); /* Store global references. */ core_global->view_width = view_width; core_global->view_height = view_height; /* Set up sound */ sound_init(&core_global->sound, (float *)core_global->sound_listener, core_global->sound_distance_max); /* Allocate game memory */ core_global->shared_memory.game_memory = malloc(game_memory_size); core_global->shared_memory.core = core_global; core_global->shared_memory.sound = &core_global->sound; core_global->shared_memory.assets = assets; core_global->shared_memory.vfs = vfs_global; core_global->shared_memory.input = &core_global->input; core_global->init_memory_callback(&core_global->shared_memory, 0); /* Seed random number generator. */ srand(time(NULL)); /* Set up window. */ core_global->graphics.view_width = view_width; core_global->graphics.view_height = view_height; core_global->graphics.window = lodge_window_create(title, window_width, window_height, window_mode, &core_window_create); if (!core_global->graphics.window) { core_error("Could not create window\n"); return; } /* Setup input. */ int ret = input_init(&core_global->input, core_global->graphics.window, &core_key_callback, &core_char_callback, &core_mousebutton_callback); if (ret != GRAPHICS_OK) { core_error("Input initialization failed (%d)\n", ret); graphics_free(&core_global->graphics); exit(ret); } lodge_window_set_resize_callback(core_global->graphics.window, &core_resize_callback); /* Load all assets */ core_load(); }
static void core_core(struct context *ctx, struct conn *conn, uint32_t events) { rstatus_t status; log_debug(LOG_VVERB, "event %04"PRIX32" on %c %d", events, conn->client ? 'c' : (conn->proxy ? 'p' : 's'), conn->sd); conn->events = events; /* error takes precedence over read | write */ if (events & EPOLLERR) { core_error(ctx, conn); return; } /* read takes precedence over write */ if (events & (EPOLLIN | EPOLLHUP)) { status = core_recv(ctx, conn); if (status != NC_OK || conn->done || conn->err) { core_close(ctx, conn); return; } } if (events & EPOLLOUT) { status = core_send(ctx, conn); if (status != NC_OK || conn->done || conn->err) { core_close(ctx, conn); return; } } }
rstatus_t core_core(void *arg, uint32_t events) { rstatus_t status; struct conn *conn = arg; struct context *ctx = conn_to_ctx(conn); log_debug(LOG_VVERB, "event %04"PRIX32" on %s %d", events, conn_get_type_string(conn), conn->sd); conn->events = events; /* error takes precedence over read | write */ if (events & EVENT_ERR) { if (conn->err && conn->dyn_mode) { loga("conn err on dnode EVENT_ERR: %d", conn->err); } core_error(ctx, conn); return DN_ERROR; } /* read takes precedence over write */ if (events & EVENT_READ) { status = core_recv(ctx, conn); if (status != DN_OK || conn->done || conn->err) { if (conn->dyn_mode) { if (conn->err) { loga("conn err on dnode EVENT_READ: %d", conn->err); core_close(ctx, conn); return DN_ERROR; } return DN_OK; } core_close(ctx, conn); return DN_ERROR; } } if (events & EVENT_WRITE) { status = core_send(ctx, conn); if (status != DN_OK || conn->done || conn->err) { if (conn->dyn_mode) { if (conn->err) { loga("conn err on dnode EVENT_WRITE: %d", conn->err); core_close(ctx, conn); return DN_ERROR; } return DN_OK; } core_close(ctx, conn); return DN_ERROR; } } return DN_OK; }
void computeExactFlags_temp(ConstRep* t, const Real &value) { // Chen Li: the following is incorrect: // uMSB = lMSB = value.MSB(); // because the value could be a BigFloat which is an interval. if (value.isExact()) { t->uMSB() = t->lMSB() = value.MSB(); } else { t->uMSB() = value.uMSB(); t->lMSB() = value.lMSB(); core_error("Leaves in DAG is not exact!", __FILE__, __LINE__, true); } t->sign() = value.sign(); // t->length() = value.length(); t->measure() = value.height(); // for rationals and integers, // measure = height. // BFMSS[2,5] bound. value.ULV_E(t->u25(), t->l25(), t->v2p(), t->v2m(), t->v5p(), t->v5m()); // The original BFMSS parameters can be set from the BFMSS[2,5] parameters. // Here we just need them locally. extLong u_e = t->u25() + t->v2p() + ceilLg5(t->v5p()); extLong l_e = t->l25() + t->v2m() + ceilLg5(t->v5m()); #ifdef ORIGINAL_BFMSS // To go back to the original BFMSS : t->u25() = u_e; t->l25() = l_e; t->v2p() = t->v2m() = t->v5p() = t->v5m() = EXTLONG_ZERO; #elif defined BFMSS_2_ONLY // To go back to BFMSS[2] only : t->u25() = t->u25() + ceilLg5(t->v5p()); t->l25() = t->l25() + ceilLg5(t->v5m()); t->v5p() = t->v5m() = EXTLONG_ZERO; #endif if (l_e == EXTLONG_ZERO) { // no divisions introduced t->high() = u_e; t->low() = EXTLONG_ONE - u_e; // - (u_e - 1) } else { t->high() = u_e - l_e + EXTLONG_ONE; t->low() = EXTLONG_TWO - t->high(); } t->lc() = l_e; t->tc() = u_e; // set BigRat value if (rationalReduceFlag) { t->ratFlag() = 1; t->ratValue() = new BigRat(value.BigRatValue()); } t->flagsComputed() = true; }
void DivRep::computeExactFlags() { if (!first->flagsComputed()) first->computeExactFlags(); if (!second->flagsComputed()) second->computeExactFlags(); if (!second->sign()) core_error("zero divisor.", __FILE__, __LINE__, true); if (!first->sign()) {// value must be exactly zero. reduceToZero(); return; } // rational node if (rationalReduceFlag) { if (first->ratFlag() > 0 && second->ratFlag() > 0) { BigRat val = (*(first->ratValue()))/(*(second->ratValue())); reduceToBigRat(val); ratFlag() = first->ratFlag() + second->ratFlag(); return; } else ratFlag() = -1; } // value is irrational. uMSB() = first->uMSB() - second->lMSB(); lMSB() = first->lMSB() - second->uMSB() - EXTLONG_ONE; sign() = first->sign() * second->sign(); extLong df = first->d_e(); extLong ds = second->d_e(); // extLong lf = first->length(); // extLong ls = second->length(); // length() = df * ls + ds * lf; measure() = (first->measure())*ds + (second->measure())*df; // BFMSS[2,5] bound. v2p() = first->v2p() + second->v2m(); v2m() = first->v2m() + second->v2p(); v5p() = first->v5p() + second->v5m(); v5m() = first->v5m() + second->v5p(); u25() = first->u25() + second->l25(); l25() = first->l25() + second->u25(); high() = first->high() + second->low(); low() = first->low() + second->high(); lc() = ds * first->lc() + df * second->tc(); tc() = core_min(ds * first->tc() + df * second->lc(), measure()); flagsComputed() = true; }
// // Debug Help Functions // void Expr::debug(int mode, int level, int depthLimit) const { std::cout << "-------- Expr debug() -----------" << std::endl; std::cout << "rep = " << rep << std::endl; if (mode == Expr::LIST_MODE) rep->debugList(level, depthLimit); else if (mode == Expr::TREE_MODE) rep->debugTree(level, 0, depthLimit); else core_error("unknown debugging mode", __FILE__, __LINE__, false); std::cout << "---- End Expr debug(): " << std::endl; }
void kaneton_dump(void) { cons_msg('#', "dumping kernel parameters:\n"); #if defined(___bootloader) cons_msg('#', " mode: bootloader\n"); core_error("kernel compiled in a bad way where ___bootloader" "is defined\n"); #elif defined(___kernel) cons_msg('#', " mode: kernel\n"); #else core_error("no mode defined\n"); #endif #if defined(___kaneton) cons_msg('#', " name: kaneton\n"); #else core_error("___kaneton not defined\n"); #endif #if (___wordsz == WORDSZ_32) cons_msg('#', " wordsize: 32-bit\n"); #elif (___wordsz == WORDSZ_64) cons_msg('#', " wordsize: 64-bit\n"); #elif (___wordsz == WORDSZ_128) cons_msg('#', " wordsize: 128-bit\n"); #else core_error("no word size defined\n"); #endif #if (___endian == ENDIAN_LITTLE) cons_msg('#', " endian: little\n"); #elif (___endian == ENDIAN_BIG) cons_msg('#', " endian: big\n"); #else core_error("no endian defined\n"); #endif }
void core_window_create(lodge_window_t window) { /* Set up ratio. */ int w, h; lodge_window_get_size(window, &w, &h); core_resize_callback(window, w, h); /* Set up graphics */ int ret = graphics_init(&core_global->graphics, &core_think, &core_render, core_global->fps_callback); if (ret != GRAPHICS_OK) { core_error("Graphics initialization failed (%d)\n", ret); graphics_free(&core_global->graphics); exit(ret); } /* Set up OpenGL. */ ret = graphics_opengl_init(&core_global->graphics); if (ret != GRAPHICS_OK) { core_error("opengl initialization failed (%d)\n", ret); exit(ret); } }
void MultRep::computeApproxValue(const extLong& relPrec, const extLong& absPrec) { if (lMSB() < EXTLONG_BIG && lMSB() > EXTLONG_SMALL) { extLong r = relPrec + EXTLONG_FOUR; extLong afr = - first->lMSB() + EXTLONG_ONE; extLong afa = second->uMSB() + absPrec + EXTLONG_FIVE; extLong af = afr > afa ? afr : afa; extLong asr = - second->lMSB() + EXTLONG_ONE; extLong asa = first->uMSB() + absPrec + EXTLONG_FIVE; extLong as = asr > asa ? asr : asa; appValue() = first->getAppValue(r, af)*second->getAppValue(r, as); } else { std::cerr << "lMSB = " << lMSB() << std::endl; core_error("a huge lMSB in MulRep", __FILE__, __LINE__, false); } }
rstatus_t core_core(void *arg, uint32_t events) { rstatus_t status; struct conn *conn = arg; struct context *ctx = conn_to_ctx(conn); if (conn->dyn_mode) { log_debug(LOG_VVERB, "event %04"PRIX32" on d_%c %d", events, conn->dnode_client ? 'c' : (conn->dnode_server ? 's' : 'p'), conn->sd); } else { log_debug(LOG_VVERB, "event %04"PRIX32" on %c %d", events, conn->client ? 'c' : (conn->proxy ? 'p' : 's'), conn->sd); } conn->events = events; /* error takes precedence over read | write */ if (events & EVENT_ERR) { core_error(ctx, conn); return DN_ERROR; } /* read takes precedence over write */ if (events & EVENT_READ) { status = core_recv(ctx, conn); if (status != DN_OK || conn->done || conn->err) { core_close(ctx, conn); return DN_ERROR; } } if (events & EVENT_WRITE) { status = core_send(ctx, conn); if (status != DN_OK || conn->done || conn->err) { core_close(ctx, conn); return DN_ERROR; } } return DN_OK; }
static void core_core(void *arg, uint32_t evflags) { rstatus_t status; struct conn *conn = (struct conn *) arg; struct context *ctx; if ((conn->proxy) || (conn->client)) { ctx = ((struct server_pool *) (conn -> owner)) -> ctx; } else { ctx = ((struct server_pool *) (((struct server *) (conn -> owner)) -> owner )) -> ctx; } log_debug(LOG_VVERB, "event %04"PRIX32" on %c %d", evflags, conn->client ? 'c' : (conn->proxy ? 'p' : 's'), conn->sd); conn->events = evflags; /* error takes precedence over read | write */ if (evflags & EV_ERR) { core_error(ctx, conn); return; } /* read takes precedence over write */ if (evflags & EV_READ) { status = core_recv(ctx, conn); if (status != NC_OK || conn->done || conn->err) { core_close(ctx, conn); return; } } if (evflags & EV_WRITE) { status = core_send(ctx, conn); if (status != NC_OK || conn->done || conn->err) { core_close(ctx, conn); return; } } }
void DivRep::computeApproxValue(const extLong& relPrec, const extLong& absPrec) { if (lMSB() < EXTLONG_BIG && lMSB() > EXTLONG_SMALL) { extLong rr = relPrec + EXTLONG_SEVEN; // These rules come from extLong ra = uMSB() + absPrec + EXTLONG_EIGHT; // Koji's Master Thesis, page 65 extLong ra2 = core_max(ra, EXTLONG_TWO); extLong r = core_min(rr, ra2); extLong af = - first->lMSB() + r; extLong as = - second->lMSB() + r; extLong pr = relPrec + EXTLONG_SIX; extLong pa = uMSB() + absPrec + EXTLONG_SEVEN; extLong p = core_min(pr, pa); // Seems to be an error: // p can be negative here! // Also, this does not conform to // Koji's thesis which has a default // relative precision (p.65). appValue() = first->getAppValue(r, af).div(second->getAppValue(r, as), p); } else { std::cerr << "lMSB = " << lMSB() << std::endl; core_error("a huge lMSB in DivRep", __FILE__, __LINE__, false); } }
void SqrtRep::computeExactFlags() { if (!child->flagsComputed()) child->computeExactFlags(); if (rationalReduceFlag) ratFlag() = -1; sign() = child->sign(); if (sign() < 0) core_error("squareroot is called with negative operand.", __FILE__, __LINE__, true); uMSB() = child->uMSB() / EXTLONG_TWO; lMSB() = child->lMSB() / EXTLONG_TWO; // length() = child->length(); measure() = child->measure(); // BFMSS[2,5] bound. if (child->v2p() + ceilLg5(child->v5p()) + child->u25() >= child->v2m() + ceilLg5(child->v5m()) + child->l25()) { extLong vtilda2 = child->v2p() + child->v2m(); v2p() = vtilda2 / EXTLONG_TWO; v2m() = child->v2m(); extLong vmod2; if (v2p().isInfty()) vmod2 = CORE_INFTY; else vmod2 = vtilda2 - EXTLONG_TWO*v2p(); // == vtilda2 % 2 extLong vtilda5 = child->v5p() + child->v5m(); v5p() = vtilda5 / EXTLONG_TWO; v5m() = child->v5m(); extLong vmod5; if (v5p().isInfty()) vmod5 = CORE_INFTY; else vmod5 = vtilda5 - EXTLONG_TWO*v5p(); // == vtilda5 % 2 u25() = (child->u25() + child->l25() + vmod2 + ceilLg5(vmod5) + EXTLONG_ONE) / EXTLONG_TWO; l25() = child->l25(); } else { extLong vtilda2 = child->v2p() + child->v2m(); v2p() = child->v2p(); v2m() = vtilda2 / EXTLONG_TWO; extLong vmod2; if (v2m().isInfty()) vmod2 = CORE_INFTY; else vmod2 = vtilda2 - EXTLONG_TWO*v2m(); // == vtilda2 % 2 extLong vtilda5 = child->v5p() + child->v5m(); v5p() = child->v5p(); v5m() = vtilda5 / EXTLONG_TWO; u25() = child->u25(); extLong vmod5; if (v5m().isInfty()) vmod5 = CORE_INFTY; else vmod5 = vtilda5 - EXTLONG_TWO*v5m(); // == vtilda5 % 2 l25() = (child->u25() + child->l25() + vmod2 + ceilLg5(vmod5) + EXTLONG_ONE) / EXTLONG_TWO; } high() = (child->high() +EXTLONG_ONE)/EXTLONG_TWO; low() = child->low() / EXTLONG_TWO; lc() = child->lc(); tc() = child->tc(); flagsComputed() = true; }// SqrtRep::computeExactFlags
void kaneton(t_init* bootloader) { /* * 1) */ init = bootloader; /* * 2) */ if (cons_init() != ERROR_NONE) core_error("cannot initialise the console manager\n"); /* * 3) */ printf("\n"); cons_msg('+', "%s\n", version); printf("\n"); /* * 4) */ #if (DEBUG & DEBUG_PARAMS) kaneton_dump(); #endif /* * 5) */ cons_msg('+', "starting malloc\n"); alloc_init(init->alloc, init->allocsz); /* * 6) */ cons_msg('+', "starting kernel manager\n"); kernel_init(); /* * 7) */ cons_msg('+', "kaneton started\n"); /* * XXX */ #if defined(CONF_ENABLE_CHECK) cons_msg('+', "running manual tests\n"); check_tests(); while(1) ; #endif #ifdef SERIAL cons_msg('+', "starting debug manager\n"); debug_init(); while(1) ; #endif /* * /XXX */ #ifdef APP APP(); #endif while(1) ; cons_msg('#', "kaneton is stopping...\n"); /* * 8) */ kernel_clean(); /* * 21) */ cons_msg('+', "system shutdown\n"); while (1) ; }
rstatus_t core_core(void *arg, uint32_t events) { rstatus_t status; struct conn *conn = arg; struct context *ctx = conn_to_ctx(conn); /* if (!conn->dyn_mode) { if (conn->client && !conn->proxy) { struct server_pool *sp = conn->owner; log_debug(LOG_VERB, "Client : '%.*s'", sp->name); } else if (!conn->client && !conn->proxy) { struct server *server = conn->owner; log_debug(LOG_VERB, "Storage server : '%.*s'", server->name); } else { struct server_pool *sp = conn->owner; log_debug(LOG_VERB, "Proxy : '%.*s'", sp->name); } } else { if (conn->dnode_client && !conn->dnode_server) { struct server_pool *sp = conn->owner; log_debug(LOG_VERB, "Dnode client : '%.*s'", sp->name); } else if (!conn->dnode_client && !conn->dnode_server) { struct server *server = conn->owner; log_debug(LOG_VERB, "Dnode peer : '%.*s'", server->name); } else { struct server_pool *sp = conn->owner; log_debug(LOG_VERB, "Dnode server : '%.*s'", sp->name); } } */ if (conn->dyn_mode) { log_debug(LOG_VVERB, "event %04"PRIX32" on d_%c %d", events, conn->dnode_client ? 'c' : (conn->dnode_server ? 's' : 'p'), conn->sd); } else { log_debug(LOG_VVERB, "event %04"PRIX32" on %c %d", events, conn->client ? 'c' : (conn->proxy ? 'p' : 's'), conn->sd); } conn->events = events; /* error takes precedence over read | write */ if (events & EVENT_ERR) { if (conn->err && conn->dyn_mode) { loga("conn err on dnode EVENT_ERR: %d", conn->err); } core_error(ctx, conn); return DN_ERROR; } /* read takes precedence over write */ if (events & EVENT_READ) { status = core_recv(ctx, conn); if (status != DN_OK || conn->done || conn->err) { if (conn->dyn_mode) { if (conn->err) { loga("conn err on dnode EVENT_READ: %d", conn->err); core_close(ctx, conn); return DN_ERROR; } return DN_OK; } core_close(ctx, conn); return DN_ERROR; } } if (events & EVENT_WRITE) { status = core_send(ctx, conn); if (status != DN_OK || conn->done || conn->err) { if (conn->dyn_mode) { if (conn->err) { loga("conn err on dnode EVENT_WRITE: %d", conn->err); core_close(ctx, conn); return DN_ERROR; } return DN_OK; } core_close(ctx, conn); return DN_ERROR; } } return DN_OK; }