// ================================================================================================================== int mainloop() { this->render.BeginScene(); { this->t = timer->GetTime(); ShaderRef fragmentShader = this->m_fragmentShader->Get(); float2 rot_rp; float3 rot_rpy; rot_rpy = trk_rotate_root->Get(); m_rootActor->Matrix().Identity(); m_rootActor->Matrix().RotateRPY(rot_rpy.x, rot_rpy.y, rot_rpy.z); for (int i = 0; i < 6; i++) { rot_rp = trk_rotate[i]->Get(); modelActors[i]->Transform().Identity(); modelActors[i]->Transform().RotateRPY(rot_rp.x, rot_rp.y, 0); } fragmentShader->SetSamplerSatate(render, "SampleType", m_textureSampler->GetSamplerState()); scene->PreRender(render); scene->Render(render); timer->Update(); } this->render.EndScene(); return 0; };
// ================================================================================================================== int mainloop() { m_postfx->BindInput(render); // pre fx-pass this->render.BeginScene(); { ShaderRef fragmentShader = this->m_fragmentShader->Get(); ShaderRef fxaaShader = this->m_fxFXAA->Get(); ShaderRef fishEyeShader = this->m_fxFishEye->Get(); m_rootActor->Matrix().Identity(); m_rootActor->Matrix().RotateRPY(t,0,0); fragmentShader->GetBRes("SampleType").Set(m_textureSampler->GetSamplerState()); float2 res = float2(); render.GetScreenSizef(res.x, res.y); fxaaShader->GetParam("FXAA").Get("resolution").SetF(res.x, res.y); fishEyeShader->GetParam("Fisheye").Get("theta").SetF(0.5); scene->PreRender(render); scene->Render(render); this->t += 0.01; } // render fx chain m_postfx->Render(render); this->render.EndScene(); return 0; };
// which entity belongs to which actor void Grafkit::SceneLoader::SceneLoaderHelper::BuildEntityMap(const ActorRef &actor) { int k = actor->GetEntityCount(); for (int i = 0; i < k; i++) { Entity3D *entity = actor->GetEntity(i); LOGGER(Log::Logger().Info(" Entity: %s %d {", entity->GetName().c_str(), m_cEntityID)); if (m_entity_map.find(entity) == m_entity_map.end()) { m_entity_map[entity] = m_cEntityID; m_entities.push_back(entity); m_entities_to_actors.push_back(assoc_t(m_cEntityID, m_cActorID)); // [m_cEntityID].push_back(m_cActorID); // model const ModelRef model = dynamic_cast<Model*>(entity); if (model.Valid()) { BuildMaterialMap(model); // ... ide jon, ami kell meg } // ... ide jon, ami kell meg ++m_cEntityID; } else { m_entities_to_actors.push_back(assoc_t(m_entity_map[entity], m_cActorID)); } LOGGER(Log::Logger().Info(" }")); } }
// Scatter-Gather Demo int main(int argc, const char * argv[]) { srand((unsigned int)time(NULL)); ActorSystem actorSystem("Scatter-Gather tester"); std::this_thread::sleep_for(std::chrono::seconds(5)); // Create a scatter actor ActorRef scatterMain = actorSystem.createActor(new ScatterActor()); // Send an init message to itself which will then spawn other actors scatterMain.send(scatterMain, new ScatterMsg(ScatterMsg::Type::INIT)); std::this_thread::sleep_for(std::chrono::seconds(60)); }
void request(const std::string& url, ActorRef<FileSourceRequest> req) { std::string path; if (url.size() <= 8 || url[8] == '/') { // This is an empty or absolute path. path = mbgl::util::percentDecode(url.substr(8)); } else { // This is a relative path. Prefix with the application root. path = root + "/" + mbgl::util::percentDecode(url.substr(8)); } Response response; struct stat buf; int result = stat(path.c_str(), &buf); if (result == 0 && S_ISDIR(buf.st_mode)) { response.error = std::make_unique<Response::Error>(Response::Error::Reason::NotFound); } else if (result == -1 && errno == ENOENT) { response.error = std::make_unique<Response::Error>(Response::Error::Reason::NotFound); } else { try { response.data = std::make_shared<std::string>(util::read_file(path)); } catch (...) { response.error = std::make_unique<Response::Error>( Response::Error::Reason::Other, util::toString(std::current_exception())); } } req.invoke(&FileSourceRequest::setResponse, response); }
// Builds map of object relations void Grafkit::SceneLoader::SceneLoaderHelper::BuildObjectMaps() { m_cTexID = 0; m_cMatID = 0; m_cEntityID = 0; m_cActorID = 0; // collect data ActorRef scenegraph = m_scene->GetRootNode(); std::stack<Actor*> stack; stack.push(scenegraph); LOGGER(Log::Logger().Info(" --- ENTITIY RELATIONS --- ")); // --- collect assoc. map and tree for serialization int i = 0, j = 0, k = 0, l = 0; while (!stack.empty()) { ActorRef node = stack.top(); stack.pop(); if (node.Valid()) { m_actors.push_back(node); m_actor_map[node] = m_cActorID; // yield LOGGER(Log::Logger().Info("Actor: %s %d {", node->GetName().c_str(), m_cActorID)); BuildEntityMap(node); LOGGER(Log::Logger().Info("}")); ++m_cActorID; // /yield // push next k = node->GetChildrenCount(); for (int i = 0; i < k; i++) stack.push(node->GetChild(i)); } } BuildActorMap(); BuildAnimationMap(); }
void MapSnapshotter::Impl::snapshot(ActorRef<MapSnapshotter::Callback> callback) { map.renderStill([this, callback = std::move(callback)] (std::exception_ptr error) mutable { // Create lambda that captures the current transform state // and can be used to translate for geographic to screen // coordinates assert (frontend.getTransformState()); PointForFn pointForFn { [=, center=map.getLatLng(), transformState = *frontend.getTransformState()] (const LatLng& latLng) { LatLng unwrappedLatLng = latLng.wrapped(); unwrappedLatLng.unwrapForShortestPath(center); Transform transform { transformState }; return transform.latLngToScreenCoordinate(unwrappedLatLng); }}; // Create lambda that captures the current transform state // and can be used to translate for geographic to screen // coordinates assert (frontend.getTransformState()); LatLngForFn latLngForFn { [=, transformState = *frontend.getTransformState()] (const ScreenCoordinate& screenCoordinate) { Transform transform { transformState }; return transform.screenCoordinateToLatLng(screenCoordinate); }}; // Collect all source attributions std::vector<std::string> attributions; for (auto source : map.getStyle().getSources()) { auto attribution = source->getAttribution(); if (attribution) { attributions.push_back(*attribution); } } // Invoke callback callback.invoke( &MapSnapshotter::Callback::operator(), error, error ? PremultipliedImage() : frontend.readStillImage(), std::move(attributions), std::move(pointForFn), std::move(latLngForFn) ); }); }
void push_sender(Framework& f, ActorRef ref, Address waiter, int64_t num) { int64_t msg; for (int64_t i = 0; i < num; ++i) ref.Push(msg, waiter); }
void send_sender(Framework& f, ActorRef ref, Address waiter, int64_t num) { auto addr = ref.GetAddress(); int64_t msg; for (int64_t i = 0; i < num; ++i) f.Send(msg, waiter, addr); }
int init() { // --- ezeket kell osszeszedni egy initwindowban const int screenWidth = m_window.getRealWidth(), screenHeight = m_window.getRealHeight(); const int VSYNC_ENABLED = 1, FULL_SCREEN = 0; this->render.Initialize(screenWidth, screenHeight, VSYNC_ENABLED, this->m_window.getHWnd(), FULL_SCREEN); // init file loader this->m_file_loader = new FileAssetFactory("./../assets/"); // -------------------------------------------------- // -- camera CameraRef camera = new Camera; //camera->SetPosition(0.0f, 0.0f, -10.0f); //camera->SetLookTo(0, 0, -1); // -- texture TextureResRef texture = new TextureRes(); texture = this->Load<TextureRes>(new TextureFromBitmap("normap", "textures/Normap.jpg")); // -- texture sampler m_textureSampler = new TextureSampler(); m_textureSampler->Initialize(render); // -- load shader m_vertexShader = Load<ShaderRes>(new VertexShaderLoader("vShader", "shaders/vertex.hlsl", "")); m_fragmentShader = Load<ShaderRes>(new PixelShaderLoader("pShader", "shaders/textured.hlsl", "")); // -- load music music = Load<MusicRes>(new MusicBassLoader("alpha_c_-_euh.ogg")); // -- precalc this->DoPrecalc(); // -- precalc utan egybol allitsuk be a synctrackert // Setup syctracker timer = new Timer(); timer->Initialize(music, music->Get()->GetLengthms(), 180, 8); timer->Connect(); valTracker = new ValueTracker(timer); // -- model ModelRef model = new Model; model->SetMaterial(new Material()); model->GetMaterial()->AddTexture(texture, "diffuse"); model = new Model(new Mesh()); model->SetName("cube"); model->GetMesh()->AddPointer("POSITION", GrafkitData::cubeVertexSize, GrafkitData::cubeVertices); model->GetMesh()->AddPointer("TEXCOORD", GrafkitData::cubeTextureUVsSize, GrafkitData::cubeTextureUVs); model->GetMesh()->AddPointer("NORMAL", GrafkitData::cubeVertexSize, GrafkitData::cubeNormals); model->GetMesh()->SetIndices(GrafkitData::cubeVertexCount, GrafkitData::cubeIndicesCount, GrafkitData::cubeIndices); model->GetMesh()->Build(render, m_vertexShader); // -- setup scene scene = new Scene(); this->cameraActor = new Actor(); cameraActor->AddEntity(camera); this->modelActor = new Actor(); modelActor->AddEntity(model); /* Alap right-handed koordinatarendszer szerint osszerakunk egy keresztet Ezeket adjuk hozza a belso kockahoz */ float3 cica[] = { { 1, 0, 0 }, /* Jobb */{ -1, 0, 0 }, /* Bal */ { 0, 1, 0 }, /* fent */{ 0,-1, 0 }, /* lent */ { 0, 0, -1 }, /* elol */{ 0, 0, 1 }, /* hatul */ }; char *names[] = { "r", "l", "u", "d", "f", "b" }; /*right, left, up, down, front, back*/ this->trk_rotate_root = valTracker->newFloat3Track("root", "r", "rpy"); // size_t i = 5; for (size_t i = 0; i < 6; i++) { ActorRef actor = new Actor(); actor->AddEntity(model); modelActor->AddChild(actor); modelActors[i] = actor; float3 v = cica[i]; v.x *= 3; v.y *= 3; v.z *= 3; actor->Matrix().Translate(v); this->trk_rotate[i] = valTracker->newFloat2Track("b", names[i], "rpy"); } ActorRef rootActor = new Actor(); cameraActor->Matrix().Translate(0,0,-10); rootActor->AddChild(cameraActor); rootActor->AddChild(modelActor); m_rootActor = rootActor; scene->BuildScene(render, m_vertexShader, m_fragmentShader); scene->Initialize(rootActor); scene->SetActiveCamera(0); // --- this->t = 0; return 0; };
int init() { // --- ezeket kell osszeszedni egy initwindowban const int screenWidth = m_window.getRealWidth(), screenHeight = m_window.getRealHeight(); const int VSYNC_ENABLED = 1, FULL_SCREEN = 0; this->render.Initialize(screenWidth, screenHeight, VSYNC_ENABLED, this->m_window.getHWnd(), FULL_SCREEN); // init file loader this->m_file_loader = new FileAssetFactory("./../../assets/postfx/"); // -------------------------------------------------- // -- camera CameraRef camera = new Camera; camera->SetPosition(0.0f, 0.0f, -10.0f); // -- texture TextureResRef texture = new TextureRes(); texture = this->Load<TextureRes>(new TextureFromBitmap("Normap.jpg")); // -- texture sampler m_textureSampler = new TextureSampler(); m_textureSampler->Initialize(render); // -- load shader m_vertexShader = Load<ShaderRes>(new ShaderLoader("vShader", "texture.hlsl", "TextureVertexShader", ST_Vertex)); m_fragmentShader = Load<ShaderRes>(new ShaderLoader("pShader", "texture.hlsl", "TexturePixelShader", ST_Pixel)); m_fxFXAA = Load<ShaderRes>(new ShaderLoader("xFXAA", "fxaa.hlsl", "FXAA", ST_Pixel)); m_fxFishEye = Load<ShaderRes>(new ShaderLoader("xFishEye", "fisheye.hlsl", "fisheyeProc", ST_Pixel)); // m_fxVhs = Load<ShaderRes>(new ShaderLoader("xVhs", "vhstape.hlsl", "TextureVertexShader", ST_Pixel)); // this->DoPrecalc(); // -- model ModelRef model = new Model; model->SetMaterial(new MaterialBase); model->GetMaterial()->AddTexture(texture, "diffuse"); SimpleMeshGenerator generator(render, m_vertexShader); generator["POSITION"] = (void*)GrafkitData::cubeVertices; generator["TEXCOORD"] = (void*)GrafkitData::cubeTextureUVs; generator(GrafkitData::cubeVertexLength, GrafkitData::cubeIndicesLength, GrafkitData::cubeIndices, model); // -- setup scene scene = new Scene(); ActorRef cameraActor = new Actor(); cameraActor->AddEntity(camera); ActorRef modelActor = new Actor(); modelActor->AddEntity(model); ActorRef modelActorL = new Actor(); modelActorL->AddEntity(model); modelActorL->Matrix().Translate(3, 0, 0); modelActor->AddChild(modelActorL); ActorRef modelActorR = new Actor(); modelActorR->AddEntity(model); modelActorR->Matrix().Translate(-3, 0, 0); modelActor->AddChild(modelActorR); ActorRef modelActorU = new Actor(); modelActorU->AddEntity(model); modelActorU->Matrix().Translate(0, 3, 0); modelActor->AddChild(modelActorU); ActorRef modelActorD = new Actor(); modelActorD->AddEntity(model); modelActorD->Matrix().Translate(0, -3, 0); modelActor->AddChild(modelActorD); ActorRef modelActorF = new Actor(); modelActorF->AddEntity(model); modelActorF->Matrix().Translate(0, 0, 3); modelActor->AddChild(modelActorF); ActorRef modelActorB = new Actor(); modelActorB->AddEntity(model); modelActorB->Matrix().Translate(0, 0, -3); modelActor->AddChild(modelActorB); // ActorRef lightActor = new Actor(); lightActor->AddEntity(light); ActorRef rootActor = new Actor(); rootActor->AddChild(cameraActor); rootActor->AddChild(modelActor); m_rootActor = rootActor; scene->SetRootNode(rootActor); scene->SetCameraNode(cameraActor); // scene->AddLightNode(lightActor); scene->SetVShader(m_vertexShader); scene->SetFShader(m_fragmentShader); // -- setup postfx size_t k = 0; m_postfx = new EffectComposer(); m_postfx->Initialize(render); k = m_postfx->AddPass(new EffectPass()); m_postfx->GetEffect(k)->Initialize(render, m_fxFXAA); k = m_postfx->AddPass(new EffectPass()); m_postfx->GetEffect(k)->Initialize(render, m_fxFishEye); // k = m_postfx->AddPass(new EffectPass()); m_postfx->GetEffect(k)->Initialize(render, m_fxVhs); // k = m_postfx->AddPass(new EffectPass()); m_postfx->GetEffect(k)->Initialize(render, sahder); // k = m_postfx->AddPass(new EffectPass()); m_postfx->GetEffect(k)->Initialize(render, sahder); // k = m_postfx->AddPass(new EffectPass()); m_postfx->GetEffect(k)->Initialize(render, sahder); // --- return 0; };