void SimulationFlow::singleAction() { Scene* scene=Omega::instance().getScene().get(); if (!scene) throw logic_error("SimulationFlow::singleAction: no Scene object?!"); if(scene->subStepping) { LOG_INFO("Sub-stepping disabled when running simulation continuously."); scene->subStepping=false; } scene->moveToNextTimeStep(); if(scene->stopAtIter>0 && scene->iter==scene->stopAtIter) setTerminate(true); if(scene->stopAtTime>0 && scene->time==scene->stopAtTime) setTerminate(true); };
void Application::initialize() { u32 viewWidth, viewHeight; window_.getViewSize(viewWidth, viewHeight); bool ret = System::initialize(window_.getHandle().hWnd_, viewWidth, viewHeight); if(!ret){ setTerminate(); return; } //fractal::ParamDialog::show(TRUE); lgraphics::GraphicsDeviceRef& device = lgraphics::Graphics::getDevice(); f32 gray[4] = {0.7f, 0.7f, 0.7f, 1.0f}; device.setClearColor(gray); u32 backWidth, backHeight; device.getRenderTargetDesc(backWidth, backHeight); // カメラ設定 lscene::Scene& scene = System::getScene(); lscene::Camera& camera = scene.getCamera(); camera.perspectiveFov(45.0f/180.0f*PI, static_cast<lcore::f32>(viewWidth)/viewHeight, 0.001f, 1500.0f); camera_.initialize(camera, lmath::Vector3(2.0f, 20.0f, -6.0f), lmath::Vector3(0.0f, 18.0f, 0.0f)); scene.getLightEnv().getDirectionalLight().setColor(lmath::Vector4(5.5f, 5.5f, 5.0f, 1.0f)); lightDirection_ = scene.getLightEnv().getDirectionalLight().getDirection(); lightDirection_.set(-1, 1, -1, 0); lightDirection_.normalize(); scene.getLightEnv().getDirectionalLight().setDirection(lightDirection_); //System::getRenderer().setFlag(render::Renderer::Flag_HDR, true); { load::ModelLoader loader; if(loader.open("../data/model/1052.lm")){ render::Object* obj = LIME_NEW render::Object(); if(loader.load(*obj)){ lcore::swap(object_, obj); } LIME_DELETE(obj); } } { plane_ = render::DebugDraw::createPlane(100.0f, 2, 0xFFFFFFFFU); } { box_ = render::DebugDraw::createBox(4.0f, 0xFFFE0000U); box_->setPosition(lmath::Vector4(12.0f, 4.5f, 0.0f, 0.0f)); } { sphere_ = render::DebugDraw::createSphere(2.0f, 10, 0xFF00FF00U); sphere_->setPosition(lmath::Vector4(-12.0f, 4.5f, 0.0f, 0.0f)); } }
int checkJewel() { semopChecked(semID, &WaitPDragonJewel, 1); if (*numDragonJewel >= MAX_JEWEL) { printf("Dragon has more than maximum number of jewels, the simulation will terminate\n"); setTerminate(); semopChecked(semID, &SignalPDragonJewel, 1); return 1; } else if (*numDragonJewel <= MIN_JEWEL) { printf("Dragon has fewer than minimum number of jewels, the simulation will terminate\n"); setTerminate(); semopChecked(semID, &SignalPDragonJewel, 1); return 1; } else { semopChecked(semID, &SignalPDragonJewel, 1); return 0; } }
int checkHunter() { semopChecked(semID, &WaitPHunterLeave, 1); if (*numHunterLeave >= MAX_TREASUREHUNTER) { printf("Smaug has fought with more than maximum number of hunters, the simulation will terminate\n"); setTerminate(); semopChecked(semID, &SignalPHunterLeave, 1); return 1; } else { semopChecked(semID, &SignalPHunterLeave, 1); return 0; } }
int checkThief() { semopChecked(semID, &WaitPThiefLeave, 1); if (*numThiefLeave >= MAX_THIEF) { printf("Smaug has played with more than maximum number of thieves, the simulation will terminate\n"); setTerminate(); semopChecked(semID, &SignalPThiefLeave, 1); return 1; } else { semopChecked(semID, &SignalPThiefLeave, 1); return 0; } }
int checkCow() { semopChecked(semID, &WaitPCowEaten, 1); if (*numCowEaten >= MAX_COW) { printf("Smaug has eaten more than the maximum number of cows, the simulation will terminate\n"); setTerminate(); semopChecked(semID, &SignalPCowEaten, 1); return 1; } else { semopChecked(semID, &SignalPCowEaten, 1); return 0; } }
int checkSheep() { semopChecked(semID, &WaitPSheepEaten, 1); if (*numSheepEaten >= MAX_SHEEP) { printf("Smaug has eaten more than maximum number of sheep, the simulation will terminate\n"); setTerminate(); semopChecked(semID, &SignalPSheepEaten, 1); return 1; } else { semopChecked(semID, &SignalPSheepEaten, 1); return 0; } }
//smaug fights the treasure hunter void fight() { semopChecked(semID, &WaitNHunterPath, 1); *numHunterPath = *numHunterPath - 1; printf("DRAGONDRAGONDRAGON Smaug is ready to interact with a hunter waiting in the path\n"); semopChecked(semID, &SignalSHunterCave, 1); semopChecked(semID, &WaitSDragonFight, 1); printf("DRAGONDRAGONDRAGON Smaug starts fighting with the hunter\n"); int fightrand = (double)rand()/RAND_MAX; if (fightrand > THIEF_WIN) { semopChecked(semID, &WaitPDragonJewel, 1); *numDragonJewel = *numDragonJewel + 5; printf("DRAGONDRAGONDRAGON Smaug wins and gets 5 jewels, now smaug has %d jewels\n", *numDragonJewel); semopChecked(semID, &SignalPDragonJewel, 1); } else { semopChecked(semID, &WaitPDragonJewel, 1); printf("DRAGONDRAGONDRAGON The hunter fights well and will get rewarded with 10 jewels\n"); if(*numDragonJewel >= 10 ) { *numDragonJewel = *numDragonJewel - 10; printf("DRAGONDRAGONDRAGON Smaug gives 10 jewels, now it has %d jewels\n", *numDragonJewel); } else { printf("DRAGONDRAGONDRAGON Smaug does not have enough jewels, the simulation will terminate\n"); setTerminate(); terminateSimulation(); } semopChecked(semID, &SignalPDragonJewel, 1); } if(checkJewel()) { terminateSimulation(); } semopChecked(semID, &SignalSHunterFight, 1); }
//smaug plays with the thief void play() { semopChecked(semID, &WaitNThiefPath, 1); *numThiefPath = *numThiefPath - 1; printf("DRAGONDRAGONDRAGON Smaug is ready to interact with a thief waiting in the path\n"); semopChecked(semID, &SignalSThiefCave, 1); semopChecked(semID, &WaitSDragonPlay, 1); printf("DRAGONDRAGONDRAGON Smaug fights with the hunter\n"); int fightrand = (double)rand()/RAND_MAX; if (fightrand > HUNTER_WIN) { semopChecked(semID, &WaitPDragonJewel, 1); *numDragonJewel = *numDragonJewel + 20; printf("DRAGONDRAGONDRAGON Smaug wins and gets 20 jewels, now smaug has %d jewels\n", *numDragonJewel); semopChecked(semID, &SignalPDragonJewel, 1); } else { semopChecked(semID, &WaitPDragonJewel, 1); printf("DRAGONDRAGONDRAGON Smaug loses and loses 8 jewels\n"); if(*numDragonJewel >= 8) { *numDragonJewel = *numDragonJewel - 8; printf("DRAGONDRAGONDRAGON Smaug loses 8 jewels, now it has %d jewels\n", *numDragonJewel); } else { printf("DRAGONDRAGONDRAGON Smaug has only %d jewels, now simulation terminates\n", *numDragonJewel); setTerminate(); terminateSimulation(); } semopChecked(semID, &SignalPDragonJewel, 1); } if(checkJewel()) { terminateSimulation(); } semopChecked(semID, &SignalSThiefPlay, 1); }