void NextRandomNumber128(unsigned long *i) { /* Take the existing four double-words and print some form of them to a string. Then do the same with a new seed value. Then create the MD5 signature of that string -- that's the new 128-bit number. */ unsigned long ii[5]; char string[256], *c; int x, y; memcpy(ii, aa, sizeof(unsigned long)*4); ii[4]=GetRandomSeed(); c=string; for(x=0; x<5; ++x) { for(y=0; y<8; ++y) { *c++=(char)('A' + (ii[x] & 0x0F)); ii[x]>>=4; } } md5(aa, string, c-string); memcpy(i, aa, sizeof(unsigned long)*4); }
void InitializeRNG ( void ) { SetRNGindex(GetRandomSeed()); sndindex=GetRandomSeed(); }
void FSsAnimeDecoder::SetAnimation(FSsModel* model, FSsAnimation* anime, FSsCellMapList* cellmap, USsProject* sspj) { //セルマップリストを取得 CurCellMapManager = cellmap; CurAnimation = anime; //アニメの基準枠を取得 CurAnimeCanvasSize = anime->Settings.CanvasSize; CurAnimePivot = anime->Settings.Pivot; //partStateをパーツ分作成する PartAnimeDic.Empty(); //パーツの数 size_t panum = anime->PartAnimes.Num(); for ( size_t i = 0 ; i < panum ; i++ ) { FSsPartAnime* panime = &anime->PartAnimes[i]; if(!PartAnimeDic.Contains(panime->PartName)) { PartAnimeDic.Add(panime->PartName); } PartAnimeDic[panime->PartName] = panime; } //パーツとパーツアニメを関連付ける size_t partNum = model->PartList.Num(); if ( PartState ) delete [] PartState; PartState = new FSsPartState[partNum](); SortList.Empty(); PartAnime.Empty(); for ( size_t i = 0 ; i < partNum ; i++ ) { FSsPart* p = &model->PartList[i]; if(!PartAnimeDic.Contains(p->PartName)) { PartAnimeDic.Add(p->PartName); // std::map互換のため、存在しないキーに対して要素NULLで追加する. } FSsPartAndAnime _temp; _temp.Key = p; _temp.Value = PartAnimeDic[p->PartName]; PartAnime.Add( _temp ); //親子関係の設定 if ( p->ParentIndex != -1 ) { PartState[i].Parent = &PartState[p->ParentIndex]; }else{ PartState[i].Parent = 0; } //継承率の設定 PartState[i].InheritRates = p->InheritRates; PartState[i].Index = i; if (sspj) { //インスタンスパーツの場合の初期設定 if ( p->Type == SsPartType::Instance ) { //参照アニメーションを取得 int32 AnimPackIndex, AnimationIndex; if(sspj->FindAnimationIndex(p->RefAnimePack, p->RefAnime, AnimPackIndex, AnimationIndex)) { FSsAnimePack* refpack = &sspj->AnimeList[AnimPackIndex]; FSsAnimation* refanime = &refpack->AnimeList[AnimationIndex]; FSsCellMapList* __cellmap = new FSsCellMapList(); __cellmap->Set( sspj , refpack ); // インスタンスパーツ再生用のDecoderを生成 FSsAnimeDecoder* animedecoder = new FSsAnimeDecoder(); animedecoder->SetAnimation( &refpack->Model , refanime , __cellmap , sspj ); // 描画先は親のCanvasなので、基準枠の設定はそちらに合わせる animedecoder->CurAnimeCanvasSize = CurAnimeCanvasSize; animedecoder->CurAnimePivot = CurAnimePivot; PartState[i].RefAnime = animedecoder; //親子関係を付ける animedecoder->PartState[0].Parent = &PartState[i]; } } //エフェクトデータの初期設定 if ( p->Type == SsPartType::Effect ) { int32 EffectIndex = sspj->FindEffectIndex( p->RefEffectName ); if(0 <= EffectIndex) { FSsEffectFile* f = &(sspj->EffectList[EffectIndex]); FSsEffectRenderer* er = new FSsEffectRenderer(); er->SetParentAnimeState( &PartState[i] ); er->SetCellmapManager( this->CurCellMapManager ); er->SetEffectData( &f->EffectData ); er->SetSeed(GetRandomSeed()); er->Reload(); er->Stop(); PartState[i].RefEffect = er; } } } SortList.Add( &PartState[i] ); } //アニメの最大フレーム数を取得 CurAnimeEndFrame = anime->Settings.FrameCount; CurAnimeFPS = anime->Settings.Fps; }
///現在の時間からパーツのアトリビュートの補間値を計算する void FSsAnimeDecoder::UpdateState( int nowTime , FSsPart* part , FSsPartAnime* anime , FSsPartState* state ) { //ステートの初期値を設定 state->Init(); state->InheritRates = part->InheritRates; if ( anime == 0 ){ IdentityMatrix( state->Matrix ); return ; } // 親の継承設定を引用する設定の場合、ここで参照先を親のものに変えておく。 if (part->InheritType == SsInheritType::Parent) { if ( state->Parent ) { state->InheritRates = state->Parent->InheritRates; } } bool size_x_key_find = false; bool size_y_key_find = false; state->IsVertexTransform = false; state->IsColorBlend = false; state->AlphaBlendType = part->AlphaBlendType; bool hidekey_find = false; if ( 0 < anime->Attributes.Num() ) { for(int i = 0; i < anime->Attributes.Num(); ++i) { FSsAttribute* attr = &(anime->Attributes[i]); switch( attr->Tag ) { case SsAttributeKind::Invalid: ///< 無効値。旧データからの変換時など break; case SsAttributeKind::Cell: ///< 参照セル { SsGetKeyValue( nowTime , attr , state->CellValue ); state->NoCells = false; } break; case SsAttributeKind::Posx: ///< 位置.X SsGetKeyValue( nowTime , attr , state->Position.X ); break; case SsAttributeKind::Posy: ///< 位置.Y SsGetKeyValue( nowTime , attr , state->Position.Y ); break; case SsAttributeKind::Posz: ///< 位置.Z SsGetKeyValue( nowTime , attr , state->Position.Z ); break; case SsAttributeKind::Rotx: ///< 回転.X SsGetKeyValue( nowTime , attr , state->Rotation.X ); break; case SsAttributeKind::Roty: ///< 回転.Y SsGetKeyValue( nowTime , attr , state->Rotation.Y ); break; case SsAttributeKind::Rotz: ///< 回転.Z SsGetKeyValue( nowTime , attr , state->Rotation.Z ); break; case SsAttributeKind::Sclx: ///< スケール.X SsGetKeyValue( nowTime , attr , state->Scale.X ); break; case SsAttributeKind::Scly: ///< スケール.Y SsGetKeyValue( nowTime , attr , state->Scale.Y ); break; case SsAttributeKind::Alpha: ///< 不透明度 SsGetKeyValue( nowTime , attr , state->Alpha ); break; case SsAttributeKind::Prio: ///< 優先度 SsGetKeyValue( nowTime , attr , state->Prio ); break; case SsAttributeKind::Fliph: ///< 左右反転(セルの原点を軸にする) SsGetKeyValue( nowTime , attr , state->HFlip ); break; case SsAttributeKind::Flipv: ///< 上下反転(セルの原点を軸にする) SsGetKeyValue( nowTime , attr , state->VFlip ); break; case SsAttributeKind::Hide: ///< 非表示 { int useTime = SsGetKeyValue( nowTime , attr , state->Hide ); // 非表示キーがないか、先頭の非表示キーより手前の場合は常に非表示にする。 if ( useTime > nowTime ) { state->Hide = true; } // 非表示キーがあり、かつ最初のキーフレームを取得した else { hidekey_find = true; } } break; case SsAttributeKind::Color: ///< カラーブレンド SsGetKeyValue( nowTime , attr , state->ColorValue ); state->IsColorBlend = true; break; case SsAttributeKind::Vertex: ///< 頂点変形 SsGetKeyValue( nowTime , attr , state->VertexValue ); state->IsVertexTransform = true; break; case SsAttributeKind::Pivotx: ///< 原点オフセット.X SsGetKeyValue( nowTime , attr , state->PivotOffset.X ); break; case SsAttributeKind::Pivoty: ///< 原点オフセット.Y SsGetKeyValue( nowTime , attr , state->PivotOffset.Y ); break; case SsAttributeKind::Anchorx: ///< アンカーポイント.X SsGetKeyValue( nowTime , attr , state->Anchor.X ); break; case SsAttributeKind::Anchory: ///< アンカーポイント.Y SsGetKeyValue( nowTime , attr , state->Anchor.Y ); break; case SsAttributeKind::Sizex: ///< 表示サイズ.X SsGetKeyValue( nowTime , attr , state->Size.X ); size_x_key_find = true; break; case SsAttributeKind::Sizey: ///< 表示サイズ.Y SsGetKeyValue( nowTime , attr , state->Size.Y ); size_y_key_find = true; break; case SsAttributeKind::Imgfliph: ///< イメージ左右反転(常にイメージの中央を原点とする) SsGetKeyValue( nowTime , attr , state->ImageFlipH ); break; case SsAttributeKind::Imgflipv: ///< イメージ上下反転(常にイメージの中央を原点とする) SsGetKeyValue( nowTime , attr , state->ImageFlipV ); break; case SsAttributeKind::Uvtx: ///< UVアニメ.移動.X SsGetKeyValue( nowTime , attr , state->UvTranslate.X ); break; case SsAttributeKind::Uvty: ///< UVアニメ.移動.Y SsGetKeyValue( nowTime , attr , state->UvTranslate.Y ); break; case SsAttributeKind::Uvrz: ///< UVアニメ.回転 SsGetKeyValue( nowTime , attr , state->UvRotation ); break; case SsAttributeKind::Uvsx: ///< UVアニメ.スケール.X SsGetKeyValue( nowTime , attr , state->UvScale.X ); break; case SsAttributeKind::Uvsy: ///< UVアニメ.スケール.Y SsGetKeyValue( nowTime , attr , state->UvScale.Y ); break; case SsAttributeKind::Boundr: ///< 当たり判定用の半径 SsGetKeyValue(nowTime, attr, state->BoundingRadius); break; case SsAttributeKind::User: ///< Ver.4 互換ユーザーデータ break; case SsAttributeKind::Instance: ///インスタンスパラメータ SsGetKeyValue(nowTime, attr, state->InstanceValue); break; } } } // カラー値だけアニメが無いと設定されないので初期値を入れておく。 // alpha はupdateで初期化されるのでOK // 当たり判定パーツ用のカラー。赤の半透明にする static const float sColorsForBoundsParts[] = {0.5f, 0.f, 0.f, 1.f}; for (int i = 0; i < (4*4) ; ++i) { if (state->NoCells) state->Colors[i] = sColorsForBoundsParts[i & 3]; else state->Colors[i] = 1.f; } // 継承 if (state->Parent) { // α if (state->Inherits_(SsAttributeKind::Alpha)) { state->Alpha *= state->Parent->Alpha; } // フリップの継承。継承ONだと親に対しての反転になる…ヤヤコシス if (state->Inherits_(SsAttributeKind::Fliph)) { state->HFlip = state->Parent->HFlip ^ state->HFlip; } if (state->Inherits_(SsAttributeKind::Flipv)) { state->VFlip = state->Parent->VFlip ^ state->VFlip; } // 引き継ぐ場合は親の値をそのまま引き継ぐ if (state->Inherits_(SsAttributeKind::Hide)) { state->Hide = state->Parent->Hide; } } // 非表示キーがないか、先頭の非表示キーより手前の場合は常に非表示にする。(継承関係なし) if (!hidekey_find) { state->Hide = true; } // 頂点の設定 if ( part->Type == SsPartType::Normal ) { FSsCell * cell = state->CellValue.Cell; if (cell && anime) { //サイズアトリビュートが指定されていない場合、セルのサイズを設定する if ( !size_x_key_find ) state->Size.X = cell->Size.X; if ( !size_y_key_find ) state->Size.Y = cell->Size.Y; } UpdateVertices(part , anime , state); } if(part->Type == SsPartType::Effect) { bool reload = false; FSsEffectRenderer * effectRender = state->RefEffect; if(effectRender) { if(state->Hide) { if(effectRender->GetPlayStatus()) { effectRender->Stop(); effectRender->Reload(); } } else { effectRender->SetSeed(GetRandomSeed()); effectRender->SetLoop(false); effectRender->Play(); } } } }
float RenderBuffers::GetPixelRandom(UINT32 x, UINT32 y, UINT32 offset) const { UINT32 randSeed = GetRandomSeed(x, y); float res = random_sequence[(randSeed+offset) % RAND_SEQUENCE_LEN]; return res; }
MTRand::MTRand() : m_MersenneRand(GetRandomSeed()) { }
cFastRandom::cFastRandom(void) : m_LinearRand(GetRandomSeed()) { }
int main(int argc, char **argv) { G4String macro = ""; G4bool showAll = false; BeamType beamType = kThirdBeam; G4bool forGrid = false; G4bool useTile = false; G4bool useQuarter = false; G4bool cutGeo = false; for (G4int i = 1; i < argc; i++) { if (G4String(argv[i]) == "-m") macro = argv[++i]; else if (G4String(argv[i]) == "-a") showAll = true; else if (G4String(argv[i]) == "-q") useQuarter = true; else if (G4String(argv[i]) == "-h") cutGeo = true; else if (G4String(argv[i]) == "-b"){ G4String type = *argv[++i]; if(type == "1") beamType = kFirstBeam; else if(type == "2") beamType = kSecondBeam; else if(type == "3") beamType = kThirdBeam; else if(type == "0") beamType = kElectronTest; else{ G4cout << "Beam type is wrong" << G4endl; PrintUsage(); return 1; } } else if (G4String(argv[i]) == "--grid") forGrid = true; else if (G4String(argv[i]) == "--tile") useTile = true; else { PrintUsage(); return 1; } } G4cout << "Beam type is " << beamType << G4endl; if (forGrid) { G4cout << "Small output mode" << G4endl; } // Remove? // Choose the Random engine CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine); unsigned int seed = GetRandomSeed(); if (seed == 0) seed = time(0); G4cout << "\nseed = " << seed << G4endl; CLHEP::HepRandom::setTheSeed(seed); G4Random::setTheSeed(seed); // Construct the default run manager // #ifdef G4MULTITHREADED G4MTRunManager *runManager = new G4MTRunManager(); runManager->SetNumberOfThreads(G4Threading::G4GetNumberOfCores()); //runManager->SetNumberOfThreads(1); #else G4RunManager *runManager = new G4RunManager(); #endif // Set mandatory initialization classes // // Detector construction runManager->SetUserInitialization(new BIDetectorConstruction(forGrid, useTile, cutGeo)); // Physics list //G4VModularPhysicsList *physicsList = new FTFP_BERT; //G4VModularPhysicsList *physicsList = new QGSP_BERT_HP; //G4VModularPhysicsList *physicsList = new QGSP_BIC_HP; G4VModularPhysicsList *physicsList = new Shielding; //G4VModularPhysicsList *physicsList = new BIDNAPhysicsList; physicsList->SetVerboseLevel(0); //physicsList->SetCutValue(1.*um, "proton"); //physicsList->SetCuts(); //physicsList->SetDefaultCutValue(100.*um); runManager->SetUserInitialization(physicsList); // Primary generator action and User action intialization runManager->SetUserInitialization(new BIActionInitialization(beamType, forGrid, useQuarter)); // Initialize G4 kernel // runManager->Initialize(); #ifdef G4VIS_USE // Initialize visualization G4VisManager *visManager = new G4VisExecutive; visManager->Initialize(); if (!showAll) { //Show only proton G4TrajectoryParticleFilter *filterp = new G4TrajectoryParticleFilter; filterp->Add("proton"); visManager->RegisterModel(filterp); } #endif // Get the pointer to the User Interface manager G4UImanager *UImanager = G4UImanager::GetUIpointer(); if (macro != "") { // batch mode G4String command = "/control/execute "; UImanager->ApplyCommand(command + macro); } else { // interactive mode : define UI session #ifdef G4UI_USE G4UIExecutive *ui = new G4UIExecutive(argc, argv); #ifdef G4VIS_USE UImanager->ApplyCommand("/control/execute init_vis.mac"); #else UImanager->ApplyCommand("/control/execute init.mac"); #endif if (ui->IsGUI()) { UImanager->ApplyCommand("/control/execute icons.mac"); } ui->SessionStart(); delete ui; #endif } // Job termination // Free the store: user actions, physics_list and detector_description are // owned and deleted by the run manager, so they should not be deleted // in the main() program ! #ifdef G4VIS_USE delete visManager; #endif delete runManager; return 0; }