// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // ++++ // ++++ get the index field /// ++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ int SelectIdx::getIndexField(int &numElem, char *&selArr) { int i; /// create selection array from index and selection coDoIntArr *idx = dynamic_cast<coDoIntArr *>(p_index->getCurrentObject()); if (!idx) { sendError("Could not open Object at index field port"); return STOP_PIPELINE; } numElem = idx->get_dim(0); // get 1st field size selArr = new char[numElem]; int *idxField = idx->getAddress(); // create a restarint construct coRestraint restraint; restraint.add(p_selection->getValue()); // mark all selected elements true, all others false for (i = 0; i < numElem; i++) if (restraint(idxField[i])) selArr[i] = 1; else selArr[i] = 0; return SUCCESS; }
/* * The `main loop' of the game abstracted so we can use it for other things * while still keeping our timesteps synchronous. Mix & Match whichever * functions that will be called at the major steps to achieve cool things. * * Accepts NULL for every argument except the restraint. */ void main_loop(struct Game *game, void (*level)(struct Game *), void (*update)(struct Game *), void (*display)(struct Game *), void (*restraint)(struct Game *, bool *)) { bool looping = true; while (game->running && looping) { game->current_time = (long int) SDL_GetTicks(); /* make sure our input state is constantly updated & able to quit anytime */ while (SDL_PollEvent(&game->event)){ switch (game->event.type) { case SDL_KEYDOWN: switch(game->event.key.keysym.sym) { case SDLK_ESCAPE: case SDL_QUIT: game->running = false; } } } /* handle level information if needed */ if (level) { level(game); } /* update the the game every 30 frames */ if (game->current_time - game->frame_time > THIRTY_FPS) { game->frame_time = game->current_time; if (update) { update(game); } } /* set up the display for drawing */ set_display(); /* draw the player, stars, and asteroids */ display_essentials(game); /* draw whatever else if something was provided */ if (display) { display(game); } render(&game->graphics); /* stop whatever loop we're in (animation, replaying, or the game loop) */ restraint(game, &looping); } }