void CMenuState::HandleEvents(CGameEngine* game) { ALLEGRO_EVENT ev; // wait for an event (mouse movement, key press, etc.) al_wait_for_event(game->event_queue, &ev); switch(ev.type) { case ALLEGRO_EVENT_DISPLAY_CLOSE: game->Quit(); break; case ALLEGRO_EVENT_KEY_DOWN: if(ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) game->Quit(); else if(ev.keyboard.keycode == ALLEGRO_KEY_RIGHT) NextItem(); else if(ev.keyboard.keycode == ALLEGRO_KEY_LEFT) PrevItem(); else if(ev.keyboard.keycode == ALLEGRO_KEY_ENTER || ev.keyboard.keycode == ALLEGRO_KEY_SPACE) items[menuIndex]->Activate(game); break; } }
void MoveItemFirst(long ptr) { long next, prev, first, loc0, root; /* Check pointer */ CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Get pointer to common data */ loc0 = (long)RDB[ptr + LIST_PTR_COMMON]; CheckPointer(FUNCTION_NAME, "(loc0)", DATA_ARRAY, loc0); /* Get pointers to previous and next items */ prev = PrevItem(ptr); next = NextItem(ptr); /* Check if already first and put pointer */ if (prev < VALID_PTR) return; else WDB[prev + LIST_PTR_NEXT] = (double)next; /* Check if last and put pointer */ if (next < VALID_PTR) WDB[loc0 + LIST_COMMON_PTR_LAST] = (double)prev; else WDB[next + LIST_PTR_PREV] = (double)prev; /* Get pointer to first */ first = (long)RDB[loc0 + LIST_COMMON_PTR_FIRST]; CheckPointer(FUNCTION_NAME, "(first)", DATA_ARRAY, first); /* Put pointers */ WDB[first + LIST_PTR_PREV] = (double)ptr; WDB[ptr + LIST_PTR_NEXT] = (double)first; WDB[ptr + LIST_PTR_PREV] = NULLPTR; WDB[loc0 + LIST_COMMON_PTR_FIRST] = (double)ptr; /* Get pointer to root */ root = (long)RDB[loc0 + LIST_COMMON_PTR_ROOT]; /* Put pointer */ WDB[root] = (double)ptr; }
void RemoveItem(long ptr) { long prev, next, loc0, root; /* Check pointer */ CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Check if list is closed */ if ((long)RDB[ptr + LIST_PTR_DIRECT] > VALID_PTR) Die(FUNCTION_NAME, "Trying to remove an item from a closed list"); /* Get pointers to previous and next items */ prev = PrevItem(ptr); next = NextItem(ptr); /* Put pointers */ if (prev > VALID_PTR) WDB[prev + LIST_PTR_NEXT] = (double)next; if (next > VALID_PTR) WDB[next + LIST_PTR_PREV] = (double)prev; /* Get pointer to common data */ loc0 = (long)RDB[ptr + LIST_PTR_COMMON]; CheckPointer(FUNCTION_NAME, "(loc0)", DATA_ARRAY, loc0); /* Get pointer to root */ root = (long)RDB[loc0 + LIST_COMMON_PTR_ROOT]; /* Check root pointer */ if (root < 1) Die(FUNCTION_NAME, "Pointer error"); /* Replace pointers if item was first */ if (prev < VALID_PTR) { WDB[root] = (double)next; WDB[loc0 + LIST_COMMON_PTR_FIRST] = (double)next; } /* Replace last pointer if item was last */ if (next < VALID_PTR) WDB[loc0 + LIST_COMMON_PTR_LAST] = (double)prev; /* Update number of items */ WDB[loc0 + LIST_COMMON_N_ITEMS] = RDB[loc0 + LIST_COMMON_N_ITEMS] - 1.0; /* Reset root pointer if list is empty */ if ((long)RDB[loc0 + LIST_COMMON_N_ITEMS] == 0) WDB[root] = NULLPTR; }
double OTFSabXS(long rea, double E, double T, long id){ long nuc, sab1, sab2, nuc1, nuc2, mt, rea2, sab0, ptr, ncol; double f, xs1, xs2, T1, T2, xs; /* Check reaction pointer */ CheckPointer(FUNCTION_NAME, "(rea)", DATA_ARRAY, rea); /* Avoid compiler warning */ sab1 = -1; /* Get reaction mt and rea nuclide */ mt = (long)RDB[rea + REACTION_MT]; nuc = (long)RDB[rea + REACTION_PTR_NUCLIDE]; CheckPointer(FUNCTION_NAME, "(nuc)", DATA_ARRAY, nuc); if (E > RDB[nuc + NUCLIDE_SAB_EMAX]) return MicroXS(rea, E, id); /* Check that data exists */ if ((sab2 = (long)RDB[nuc + NUCLIDE_PTR_SAB]) < VALID_PTR ) Die(FUNCTION_NAME, "S(a,b) data not available for nuclide %s", GetText(nuc + NUCLIDE_PTR_NAME)); /* Find correct temperature */ while(sab2 > VALID_PTR) { if (RDB[sab2 + SAB_T] > T) break; sab2 = NextItem(sab2); } /* Check that sab was found */ if (sab2 < VALID_PTR) Die(FUNCTION_NAME, "S(a,b) OTF nuclide not found for %s", GetText(nuc + NUCLIDE_PTR_NAME)); sab1 = PrevItem(sab2); /* Check Pointers */ CheckPointer(FUNCTION_NAME, "(sab1)", DATA_ARRAY, sab1); CheckPointer(FUNCTION_NAME, "(sab2)", DATA_ARRAY, sab2); /* Temperatures */ T1 = RDB[sab1 + SAB_T]; T2 = RDB[sab2 + SAB_T]; /* Pointers to S(a,b) nuclides */ nuc1 = RDB[sab1 + SAB_PTR_ISO]; nuc2 = RDB[sab2 + SAB_PTR_ISO]; CheckPointer(FUNCTION_NAME, "(nuc1)", DATA_ARRAY, nuc1); CheckPointer(FUNCTION_NAME, "(nuc2)", DATA_ARRAY, nuc2); /* Find reaction pointers in S(a,b) data */ /* Elastic scattering xs = total xs in case of S(a,b) nuclides (which only have 1004 and 1002 reactions and total is calculated over them) */ if ((mt == 1) || (mt == 2)) rea2 = (long)RDB[nuc1 + NUCLIDE_PTR_TOTXS]; /* Find reaction at first temperature */ else { /* Pointer to reaction */ rea2 = (long)RDB[nuc1 + NUCLIDE_PTR_REA]; CheckPointer(FUNCTION_NAME, "(rea2)", DATA_ARRAY, rea2); /* JLe: Tässä voisi käyttää SeekList():iä */ while (rea2 > VALID_PTR) { if ((long)RDB[rea2 + REACTION_MT] == mt - 1000) break; rea2 = NextItem(rea2); } if (rea2 < VALID_PTR) Die(FUNCTION_NAME, "mt %ld not found for S(a,b) nuclide %s", mt, GetText(nuc1 + NUCLIDE_PTR_NAME)); } /* Get cross section */ xs1 = MicroXS(rea2, E, id); CheckValue(FUNCTION_NAME, "xs1", "", xs1, 0.0, 1E+10); if ((mt == 1) || (mt == 2)) rea2 = (long)RDB[nuc2 + NUCLIDE_PTR_TOTXS]; /* Find reaction at second temperature */ else { rea2 = (long)RDB[nuc2 + NUCLIDE_PTR_REA]; CheckPointer(FUNCTION_NAME, "(rea2)", DATA_ARRAY, rea2); /* JLe: Tässä voisi käyttää SeekList():iä */ while (rea2 > VALID_PTR) { if ((long)RDB[rea2 + REACTION_MT] == mt - 1000) break; rea2 = NextItem(rea2); } if (rea2 < VALID_PTR) Die(FUNCTION_NAME, "mt %ld not found for S(a,b) nuclide %s", mt, GetText(nuc1 + NUCLIDE_PTR_NAME)); } /* Get cross section */ xs2 = MicroXS(rea2, E, id); CheckValue(FUNCTION_NAME, "xs2", "", xs2, 0.0, 1E+10); /* Avoid compiler warning */ f = -1.0; /* Calculate factor */ if (T1 != T2) f = (T-T1)/(T2-T1); else Die(FUNCTION_NAME, "Division by zero"); /* Check value */ CheckValue(FUNCTION_NAME, "f", "", f, 0.0, 1.0); /* Get collision number */ ptr = (long)RDB[DATA_PTR_COLLISION_COUNT]; ncol = (long)GetPrivateData(ptr, id); /* Pointer to first item in sab list */ sab0 = (long)RDB[nuc + NUCLIDE_PTR_SAB]; /* Store values */ StoreValuePair(sab0 + SAB_PTR_PREV_FRAC, ncol, f, id); StoreValuePair(sab0 + SAB_PTR_PREV_SAB1, ncol, (double)sab1, id); xs = xs1 + f*(xs2-xs1); /* Tämä poistettiin juuri ennen 2.1.25:n jakelua, sillä se sotkee */ /* myöhemmin käytettävän kokonaisvaikutusalan arvon (JLe / 19.2.2016). */ /* StoreValuePair(rea + REACTION_PTR_PREV_XS, E, xs, id); */ /* Näillä voisi varmaan optimoida myös tuota rutiinin alkupäätä */ /* JLe: Jos palautettava arvo on samalla energialla aina sama, niin */ /* alkuun voi laittaa TestValuePair() -kutsun. Onko nuo kaksi ylempää */ /* tosiaan tarkoitus kiinnittää törmäykseen eikä energiaan? */ return xs; }
void FindInterfaceRegions(long loc0, long uni, long lvl, long recu, double x0, double y0, double z0, long idx0) { long loc1, loc2, nst, ptr, reg, n, cell, lat, lst, mat0, mat, nx, ny; long nr, i0, j0, i, j, type, surf, idx, idx1, ifcmat; double x, y, z, pitch, wdth, phi, rad; /* Check flag */ if ((long)RDB[loc0 + IFC_CALC_OUTPUT] == NO) return; /* Get interface material */ ifcmat = (long)RDB[loc0 + IFC_PTR_MAT]; /* Update level pointer or get pointer to first level and universe */ if (lvl < VALID_PTR) { lvl = (long)RDB[DATA_PTR_LVL0]; uni = (long)RDB[DATA_PTR_ROOT_UNIVERSE]; } else lvl = NextItem(lvl); /* Check level and universe pointers */ CheckPointer(FUNCTION_NAME, "(lvl)", DATA_ARRAY, lvl); CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni); /* Check infinite loop */ if (recu++ > 1000) Die(FUNCTION_NAME, "Infinite geometry loop involving universe %s", GetText(uni + UNIVERSE_PTR_NAME)); /* Coordinate transformation to local origin */ if ((ptr = (long)RDB[uni + UNIVERSE_PTR_TRANS]) > VALID_PTR) { x0 = x0 + RDB[ptr + TRANS_X0]; y0 = y0 + RDB[ptr + TRANS_Y0]; z0 = z0 + RDB[ptr + TRANS_Z0]; } /* Check symmetries */ if ((long)RDB[uni + UNIVERSE_PTR_SYM] > VALID_PTR) Error(0, "Interface output doesn't work with symmetries (to be fixed)"); /* Check universe type */ switch((long)RDB[uni + UNIVERSE_TYPE]) { case UNIVERSE_TYPE_NEST: { /***** Nest universe *************************************************/ /* Pointer to nest */ nst = (long)RDB[uni + UNIVERSE_PTR_NEST]; CheckPointer(FUNCTION_NAME, "(nst)", DATA_ARRAY, nst); /* Get pointer to regions */ reg = (long)RDB[nst + NEST_PTR_REGIONS]; CheckPointer(FUNCTION_NAME, "(reg)", DATA_ARRAY, reg); /* Loop over regions */ while (reg > VALID_PTR) { /* Get region index and update global index */ idx = (long)RDB[reg + NEST_REG_IDX]; idx1 = idx0 + ((long)RDB[lvl + LVL_ZONE_IDX_MULT])*idx; /* Check fill pointer */ if ((uni = RDB[reg + NEST_REG_PTR_FILL]) > VALID_PTR) { /* Filled region, call recursively */ FindInterfaceRegions(loc0, uni, lvl, recu, x0, y0, z0, idx1); } /* Next region */ reg = NextItem(reg); } /* Get pointer to outermost region */ reg = (long)RDB[nst + NEST_PTR_REGIONS]; reg = LastItem(reg); /* Get pointer to cell */ cell = (long)RDB[reg + NEST_REG_PTR_CELL]; CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, cell); /* Check that the region is not the only one and get pointer */ /* to material */ if ((PrevItem(reg) > VALID_PTR) && ((mat0 = (long)RDB[cell + CELL_PTR_MAT]) > VALID_PTR)) { /* Reset pointer */ mat = -1; /* Compare name */ if (mat0 == ifcmat) mat = mat0; /* Check if material was divided for burnup calculation */ if ((ptr = (long)RDB[mat0 + MATERIAL_DIV_PTR_PARENT]) > VALID_PTR) if (ptr == ifcmat) mat = mat0; /* Check match */ if (mat > VALID_PTR) { /* Get pointer to surface */ surf = (long)RDB[reg + NEST_REG_PTR_SURF_OUT]; CheckPointer(FUNCTION_NAME, "(surf)", DATA_ARRAY, surf); /* Check type */ if ((long)RDB[surf + SURFACE_TYPE] != SURF_CYL) Error(loc0, "Interface allowed only with cylindrical nests"); /* Pointer to parameter list */ ptr = (long)RDB[surf + SURFACE_PTR_PARAMS]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Get radius */ rad = RDB[ptr + 2]; /* Create new structure */ loc1 = NewItem(loc0 + IFC_PTR_OUT, IFC_OUT_LIST_BLOCK_SIZE); /* Put data */ WDB[loc1 + IFC_OUT_X0] = x0; WDB[loc1 + IFC_OUT_Y0] = y0; WDB[loc1 + IFC_OUT_R] = rad; WDB[loc1 + IFC_OUT_PTR_IFC] = (double)loc0; /* Add scoring regions */ reg = (long)RDB[nst + NEST_PTR_REGIONS]; while (reg > VALID_PTR) { /* Exclude last */ if (NextItem(reg) < VALID_PTR) break; /* Get pointer to cell */ cell = (long)RDB[reg + NEST_REG_PTR_CELL]; CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, cell); /* Pointer to material */ mat = (long)RDB[cell + CELL_PTR_MAT]; /* Check material pointer and fissile flag */ if (mat > VALID_PTR) if ((long)RDB[mat + MATERIAL_OPTIONS] & OPT_FISSILE_MAT) { /* Get region index global index */ idx = (long)RDB[reg + NEST_REG_IDX]; idx1 = idx0 + ((long)RDB[lvl + LVL_ZONE_IDX_MULT])*idx; /* Create new structure */ loc2 = NewItem(loc0 + IFC_PTR_SCORE, IFC_SCORE_LIST_BLOCK_SIZE); /* Put region index */ WDB[loc2 + IFC_SCORE_REG_IDX] = (double)idx1; /* Reset stat index */ WDB[loc2 + IFC_SCORE_STAT_IDX] = -1.0; /* Put pointers */ WDB[loc2 + IFC_SCORE_PTR_OUT] = (double)loc1; WDB[loc1 + IFC_OUT_PTR_SCORE] = (double)loc2; } /* Next region */ reg = NextItem(reg); } } } /* Break case */ break; /*********************************************************************/ } case UNIVERSE_TYPE_CELL: { /***** Cell universe *************************************************/ /* Pointer to cell list */ lst = (long)RDB[uni + UNIVERSE_PTR_CELL_LIST]; CheckPointer(FUNCTION_NAME, "(lst)", DATA_ARRAY, lst); /* Loop over cell list */ while (lst > VALID_PTR) { /* Get region index and update global index */ idx = (long)RDB[lst + CELL_LIST_REG_IDX]; idx1 = idx0 + ((long)RDB[lvl + LVL_ZONE_IDX_MULT])*idx; /* Pointer to cell */ cell = (long)RDB[lst + CELL_LIST_PTR_CELL]; CheckPointer(FUNCTION_NAME, "(cell)", DATA_ARRAY, cell); /* Check fill pointer */ if ((uni = RDB[cell + CELL_PTR_FILL]) > 0) { /* Filled region, call recursively */ FindInterfaceRegions(loc0, uni, lvl, recu, x0, y0, z0, idx1); } /* Next */ lst = NextItem(lst); } /* Break case */ break; /*********************************************************************/ } case UNIVERSE_TYPE_LATTICE: { /***** Lattice universe **********************************************/ /* Pointer to lattice */ lat = (long)RDB[uni + UNIVERSE_PTR_LAT]; CheckPointer(FUNCTION_NAME, "(lat)", DATA_ARRAY, lat); /* Check type */ if ((long)RDB[lat + LAT_TYPE] == LAT_TYPE_CLU) { /***** Circular array ********************************************/ /* Get pointer to rings */ reg = (long)RDB[lat + LAT_PTR_FILL]; CheckPointer(FUNCTION_NAME, "(reg)", DATA_ARRAY, reg); /* Reset index */ idx = 0; /* Loop over rings */ while (reg > VALID_PTR) { /* Pointer to items */ ptr = (long)RDB[reg + RING_PTR_FILL]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Number of sectors */ nr = (long)RDB[reg + RING_N_SEC]; /* Sector width */ wdth = 2.0*PI/((double)nr); /* Loop over sectors */ for (n = 0; n < (long)RDB[reg + RING_N_SEC]; n++) { /* Get global index and update local */ idx1 = idx0 + ((long)RDB[lvl + LVL_ZONE_IDX_MULT])*idx; idx++; /* Sector center angle */ phi = n*wdth + RDB[reg + RING_TILT]; /* Adjust */ while (phi < 0.0) phi = phi + 2.0*PI; while (phi >= 2.0*PI) phi = phi - 2.0*PI; /* Transfer co-ordinates */ x = x0 + RDB[reg + RING_RAD]*cos(phi); y = y0 + RDB[reg + RING_RAD]*sin(phi); z = z0; /* Pointer to universe */ uni = (long)RDB[ptr + n]; CheckPointer(FUNCTION_NAME, "(uni)", DATA_ARRAY, uni); /* Call recursively */ FindInterfaceRegions(loc0, uni, lvl, recu, x, y, z, idx1); } /* Next ring */ reg = NextItem(reg); } /*****************************************************************/ } else { /***** Simple types **********************************************/ /* Get parameters */ nx = (long)RDB[lat + LAT_NX]; ny = (long)RDB[lat + LAT_NY]; pitch = RDB[lat + LAT_PITCH]; type = (long)RDB[lat + LAT_TYPE]; /* Transfer coordinates */ x0 = x0 + RDB[lat + LAT_ORIG_X0]; y0 = y0 + RDB[lat + LAT_ORIG_Y0]; /* If even number of cells, shift origin by pitch/2 */ x0 = x0 + (1 - (nx % 2))*0.5*pitch; y0 = y0 + (1 - (ny % 2))*0.5*pitch; /* Get pointer to lattice cells */ ptr = (long)RDB[lat + LAT_PTR_FILL]; CheckPointer(FUNCTION_NAME, "(ptr)", DATA_ARRAY, ptr); /* Reset index */ idx = 0; /* Loop over items */ for (j0 = 0; j0 < ny; j0++) for (i0 = 0; i0 < nx; i0++) { /* Get global index and update local */ idx1 = idx0 + ((long)RDB[lvl + LVL_ZONE_IDX_MULT])*idx; idx++; /* Transfer to centered indexing system */ i = i0 - (long)(nx/2.0); j = j0 - (long)(ny/2.0); /* Avoid compiler warning */ x = 0.0; y = 0.0; z = z0; /* Calculate local coordinates */ if (type == LAT_TYPE_S) { x = x0 + i*pitch; y = y0 + j*pitch; } else if (type == LAT_TYPE_HX) { x = x0 + (i + COS60*j)*pitch; y = y0 + j*SIN60*pitch; } else if (type == LAT_TYPE_HY) { x = x0 + j*SIN60*pitch; y = y0 + (i + COS60*j)*pitch; } else Die (FUNCTION_NAME, "Unsupported lattice type %ld", type); /* Index to lattice element */ n = i0 + nx*j0; /* Call recursively */ if ((uni = (long)RDB[ptr + n]) > VALID_PTR) FindInterfaceRegions(loc0, uni, lvl, recu, x, y, z, idx1); } /*****************************************************************/ } /* Break case */ break; /*********************************************************************/ } } }
int Playlist::MQTTHandler(std::string topic, std::string msg) { LogDebug(VB_PLAYLIST, "Playlist::MQTTHandler('%s', '%s') while playing '%s'\n", topic.c_str(), msg.c_str(), m_name.c_str()); // note the leading /set/playlist will be removed from topic by now int pos = topic.find("/"); if (pos == std::string::npos) { LogWarn(VB_PLAYLIST, "Ignoring Invalid playlist topic: playlist/%s\n", topic.c_str()); return 0; } std::string newPlaylistName = topic.substr(0,pos); std::string topicEnd = topic.substr(pos); /* * NOTE: This because multiple playlist are not supported, the newPlaylistname value * is only considered when starting a playlist. All other actions will * apply to the current running playlist even if the names don't match */ // ALLPLAYLIST should be checked first to avoid name colision. if (topic == "ALLPLAYLISTS/stop/now") { StopNow(1); } else if (topic == "ALLPLAYLISTS/stop/graceful") { StopGracefully(1); } else if (topic == "ALLPLAYLISTS/stop/afterloop") { StopGracefully(1,1); // Playlist specific versions } else if (topicEnd == "/start") { // Play from begging keeping previous value of repeate Play(newPlaylistName.c_str(), 0, m_repeat); } else if (topicEnd == "/next") { NextItem(); } else if (topicEnd == "/prev") { PrevItem(); } else if (topicEnd == "/repeat") { SetRepeat(atoi(msg.c_str())); } else if (topicEnd == "/startPosition") { SetPosition(atoi(msg.c_str())); } else if (topicEnd == "/stop/now") { StopNow(1); } else if (topicEnd == "/stop/graceful") { StopGracefully(1); } else if (topicEnd == "/stop/afterloop") { StopGracefully(1); // These three are depgrecated and should be removed } else if (topic == "name/set") { LogInfo(VB_PLAYLIST, "playlist/%s is deprecated and will be removed in a future release\n", topic.c_str()); Play(msg.c_str(), m_sectionPosition, m_repeat); } else if (topic == "repeat/set") { LogInfo(VB_PLAYLIST, "playlist/%s is deprecated and will be removed in a future release\n", topic.c_str()); SetRepeat(atoi(msg.c_str())); } else if (topic == "sectionPosition/set") { LogInfo(VB_PLAYLIST, "playlist/%s is deprecated and will be removed in a future release\n", topic.c_str()); SetPosition(atoi(msg.c_str())); } else { LogWarn(VB_PLAYLIST, "Ignoring Invalid playlist topic: playlist/%s\n", topic.c_str()); return 0; } return 1; }