void init_outbreak(Outbreak * outbreak, SDL_Surface * screen) { outbreak->screen = screen; outbreak->player = make_player("Jeremy", INITIAL_PADDLE_X, INITIAL_PADDLE_Y, INITIAL_PADDLE_WIDTH, INITIAL_PADDLE_HEIGHT, resources.paddle_bmp); outbreak->ball = make_ball(INITIAL_BALL_X, INITIAL_BALL_Y, INITIAL_BALL_WIDTH, INITIAL_BALL_HEIGHT, resources.ball_bmp); outbreak->paused = FALSE; outbreak->quit = FALSE; magnetize_ball(outbreak->ball); outbreak->num_blocks = generate_level(outbreak->blocks, MAX_BLOCKS); }
/* Ready a game structure for actual use: */ void game_finalize(GameData *gd) { Level *lvl; TankList *tl; DrawBuffer *b; PList *pl; Screen *s; ASSERT_CONFIG(); /* Initialize most of the structures: */ s = screen_new (gd->data.config.is_fullscreen); pl = plist_new (); b = drawbuffer_new(gd->data.config.w, gd->data.config.h); lvl = level_new (b, gd->data.config.w, gd->data.config.h); tl = tanklist_new (lvl, pl); /* Generate our random level: */ generate_level(lvl, gd->data.config.gen); level_decorate(lvl); level_make_bases(lvl); /* Debug the starting data, if we're debugging: */ if(gd->is_debug) level_dump_bmp(lvl, "debug_start.bmp"); /* Start drawing! */ drawbuffer_set_default(b, color_rock); level_draw_all(lvl, b); screen_set_mode_level(s, b); /* Set up the players/GUI: */ if (gd->data.config.player_count == 1) init_single_player(s, tl, lvl); else if(gd->data.config.player_count == 2) init_double_player(s, tl, lvl); else { ERR_OUT("Don't know how to draw more than 2 players at once..."); exit(1); } /* Copy all of our variables into the GameData struct: */ gd->is_active = 1; gd->data.active.s = s; gd->data.active.pl = pl; gd->data.active.b = b; gd->data.active.lvl = lvl; gd->data.active.tl = tl; }
void skiplist_insert(SkipList_t *ptrSl, SlKey_t slKey, void *ptrValue) { int32_t cMaxLevel = ptrSl->cMaxLevel; int32_t ixLevel = generate_level(ptrSl); SkipListNode_t *ptrSlnNew = skiplist_alloc_node(cMaxLevel); ptrSlnNew->cLevel = (int16_t)ixLevel; ptrSlnNew->slKey = slKey; ptrSlnNew->ptrValue = ptrValue; SkipListNode_t **rgPtrSlnBuf = obtain_work_buffer(ptrSl); SkipListNode_t *ptrSlnCurr = ptrSl->ptrSlnHeader; int32_t i; for (i = ptrSl->cMaxLevel-1; i >= 0; i--) { SkipListNode_t *ptrSlnNext; int32_t cLinkWidth = 0; while ((ptrSlnNext = ptrSlnCurr->rgPtrSlnForward[i]) && ptrSlnNext->slKey < slKey) { cLinkWidth += ptrSlnCurr->rgCLinkWidth[i]; ptrSlnCurr = ptrSlnNext; } rgPtrSlnBuf[i] = ptrSlnCurr; if (i < cMaxLevel - 1) { ptrSlnNew->rgCLinkWidth[i+1] = cLinkWidth; } } ptrSlnNew->rgCLinkWidth[0] = 1; int32_t cLinkWidth = 0; for (i = 0; i <= ixLevel; i++) { ptrSlnCurr = rgPtrSlnBuf[i]; ptrSlnNew->rgPtrSlnForward[i] = ptrSlnCurr->rgPtrSlnForward[i]; ptrSlnCurr->rgPtrSlnForward[i] = ptrSlnNew; int32_t cOldWidth = ptrSlnCurr->rgCLinkWidth[i]; int32_t cTraveled = ptrSlnNew->rgCLinkWidth[i]; cLinkWidth += cTraveled; int32_t cNewWidth = cOldWidth - cLinkWidth; ptrSlnCurr->rgCLinkWidth[i] = cLinkWidth; ptrSlnNew->rgCLinkWidth[i] = cNewWidth < 0 ? 0 : cNewWidth; } for (i = ixLevel + 1; i < cMaxLevel; i++) { rgPtrSlnBuf[i]->rgCLinkWidth[i]++; } ptrSl->cSize++; release_work_buffer(rgPtrSlnBuf); }