int main (int argc, char **argv) { int i; if (argc != 2) { fprintf(stderr, "Usage: %s <number of philosophers>\n", argv[0]); exit(EXIT_FAILURE); } num_philosof = strtol(argv[1], NULL, 10); if(num_philosof <= 0){ fprintf(stderr, "Number of philosophers must be up to 0.\n"); exit(EXIT_FAILURE); } // define neighborhood left = malloc(sizeof(int) * num_philosof); right = malloc(sizeof(int) * num_philosof); for(i=0; i<num_philosof; i++){ right[i] = (i+num_philosof-1) % num_philosof; left[i] = (i+1) % num_philosof; } // allocate mutex mutex = malloc (sizeof(sem_t)); if (sem_init(mutex, 0, 1) == -1) { fprintf(stderr, "Error initializing semaphore.\n"); exit(EXIT_FAILURE); } // allocate semaphore for each philosopher sem_p = malloc(sizeof(sem_t) * num_philosof); for(i=0; i<num_philosof; i++){ if (sem_init(&sem_p[i], 0, 1) == -1) { fprintf(stderr, "Error initializing semaphore.\n"); exit(EXIT_FAILURE); } } // allocate thread for each philosopher thread = malloc(sizeof(pthread_t) * num_philosof); // allocate states - all starts hungry state = malloc(sizeof(int) * num_philosof); initializeStates(); for(i=0; i < num_philosof; i++){ if(pthread_create(&thread[i], NULL, philosopher, (void *) i) != 0){ printf("Error creating threads \n"); } } for(i=0; i < num_philosof; i++){ pthread_join(thread[i], NULL); } return 0; }
/** * CxeViewfinderControlSymbian::CxeViewfinderControlSymbian */ CxeViewfinderControlSymbian::CxeViewfinderControlSymbian( CxeCameraDevice &cameraDevice, CxeCameraDeviceControl &cameraDeviceControl ) : CxeStateMachine("CxeViewfinderControlSymbian"), mCameraDevice( cameraDevice ), mCameraDeviceControl( cameraDeviceControl ), mUiWindow(NULL), mVideoWindow(NULL), mVideoContainer(NULL), mDirectViewfinder( NULL ), mDirectViewfinderInUse( true ) { CX_DEBUG_ENTER_FUNCTION(); qRegisterMetaType<CxeViewfinderControlSymbian::State>(); initializeStates(); // connect signals from cameraDevice, so we recieve events when camera reference changes connect(&mCameraDevice, SIGNAL(prepareForCameraDelete()), this,SLOT(prepareForCameraDelete())); connect(&mCameraDevice, SIGNAL(prepareForRelease()), this,SLOT(prepareForRelease())); connect(&mCameraDevice, SIGNAL(cameraAllocated(CxeError::Id)), this,SLOT(handleCameraAllocated(CxeError::Id))); CX_DEBUG_EXIT_FUNCTION(); }
void Application::initialize() { std::cout << "Initialisation de l'application\n"; font.LoadFromFile("./resources/cheeseburger.ttf"); activeState = NULL; sound = false; createWindow(); initializeStates(); MessageManager::getInstancePtr()->addListener(this); window.EnableKeyRepeat(false); }
Game::Game() : isCutscene(false), isPaused(false), currentLine(0), transitionTo(LEVEL_ONE), window(nullptr), isRunning(false), pauseImage(nullptr), pauseSelector(nullptr), audioHandler(new AudioHandler()), inputHandler(new InputHandler()), resourceManager(new ResourceManager()), gameSave(new GameSave()), fadeScreen(nullptr), currentState(nullptr), statesMap(), passedTime(0.0), currentSelection(PSelection::RESUME), selectorXPositionLeft {550, 550}, selectorYPositionLeft {400, 470}, selectorXPositionRight {930, 930}, selectorYPositionRight {400, 470} { this->window = new Window(Configuration::getScreenWidth(), Configuration::getScreenHeight(), Configuration::getWindowTitle()); assert(this->window != nullptr && "The window should not be null!"); initializeStates(); std::string path = "assets/images/Dialog/dialog"; std::string extension = ".png"; for(int i = 0; i < numLines; i++){ this->dialog[i] = nullptr; this->dialog[i] = getResources().get(path + Util::toString(i) + extension); if(this->dialog[i] == nullptr){ Log(ERROR) << "Invalid dialog image."; } } this->pauseImage = getResources().get("assets/images/pause_overlay.png"); this->pauseSelector = getResources().get("assets/images/cursor_regular.png"); this->pauseSelector->setWidth(50); this->isRunning = true; }
Boss::Boss(const double x_, const double y_, const std::string& path_, Player* const player_) : DynamicEntity(x_, y_, path_), potionsLeft(3), sawPlayer(false), potions(), life(8), hasShield(false), canWalk(true), player(player_), powerAnimation(nullptr), powerX(0.0), powerY(0.0), powerIsActivated(false), power(nullptr), powerClip{0,0,0,0}, powerFlip(SDL_FLIP_NONE), shieldAnimation(nullptr), shield(nullptr), shieldClip{0,0,0,0}, currentState(nullptr), animation(nullptr), statesMap(), dead(false) { initializeStates(); this->isRight = true; this->speed = 400.0; this->width = 360; this->height = 360; this->animation = new Animation(0, 0, this->width, this->height, 7, false); this->powerAnimation = new Animation(0, 0, 0, 0, 0, false); this->shieldAnimation = new Animation(0, 0, 340, 340, 6, false); this->shield = Game::instance().getResources().get("assets/images/shield.png"); this->shieldAnimation->changeAnimation(0,0,3,false,1); this->currentState = this->statesMap.at(IDLE); this->currentState->enter(); if(this->player == nullptr){ Log(WARN) << "Passing a null player to the Boss."; } }
CxeCameraDeviceControlSymbian::CxeCameraDeviceControlSymbian() : CxeStateMachine("CxeCameraDeviceControlSymbian"), mCameraDevice(NULL), mCameraIndex(Cxe::PrimaryCameraIndex), mCameraMode(Cxe::ImageMode) { CX_DEBUG_ENTER_FUNCTION(); #ifdef FORCE_SECONDARY_CAMERA mCameraIndex = Cxe::SecondaryCameraIndex; #endif qRegisterMetaType<CxeCameraDeviceControl::State>(); initializeStates(); mCameraDevice = new CxeCameraDevice(); //!@todo Temporary delay before reserving camera to avoid timing issues connect(&mReserveTimer, SIGNAL(timeout()), this, SLOT(doReserve())); mReserveTimer.setSingleShot(true); CX_DEBUG_EXIT_FUNCTION(); }
bool DoMApplication::initialize() { // Mostramos una splash screen. CSplash splash(TEXT(SPLASH_TEXTURE), RGB(255, 0, 255)); splash.ShowSplash(); // Inicializamos la base del motor de juego. if (!GenericApplication::initialize(TITLE)) { return false; } // Minimizamos la ventana principal, dejando solo la splash screen. Core::GraphicsManager::GetInstance()->minimizeWindow(); // Obtenemos el gestor de la interfaz gráfica de usuario. Core::GUIManager * guiManager = Core::GUIManager::GetInstance(); // Cargamos las distintas plantillas o esquemas de fichero que usaremos en // nuestro GUI (automáticamente cargan los archivos looknfeel e imageset). guiManager->loadScheme("OgreTray.scheme"); guiManager->loadScheme("MankindDefenders.scheme"); // Cargamos los archivos con las fuentes que usaremos. guiManager->loadFont("DejaVuSans-10.font"); guiManager->loadFont("FairChar-30.font"); // Establecemos cual será el puntero del ratón. guiManager->setDefaultMouseCursor("OgreTrayImages", "MouseArrow"); // Cerramos la splash screen. splash.CloseSplash(); // Restaurando la ventana principal. Core::GraphicsManager::GetInstance()->restoreWindow(); // Y finalmente tratamos de inicializar los estados. return initializeStates(); }
CxeFakeZoomControl::CxeFakeZoomControl() : CxeStateMachine("CxeFakeZoomControl") { initializeStates(); }