//private void TilemapDemoState::buildScene() { if (m_tilemap.load("assets/maps/platform.tmx")) { auto entity = xy::Entity::create(m_messageBus); const auto& layers = m_tilemap.getLayers(); for (const auto& l : layers) { if (l->getType() == xy::tmx::Layer::Type::Object) { xy::Logger::log("found object layer - attempting to create physics components", xy::Logger::Type::Info); auto rb = m_tilemap.createRigidBody(m_messageBus, *l); entity->addComponent(rb); } else { auto drawable = m_tilemap.getDrawable(m_messageBus, *l, m_textureResource, m_shaderResource); if (drawable) { xy::Logger::log("created layer drawable, adding to scene..."); entity->addComponent(drawable); } } } m_scene.addEntity(entity, xy::Scene::Layer::BackFront); static const float radius = 30.f; auto body = xy::Component::create<xy::Physics::RigidBody>(m_messageBus, xy::Physics::BodyType::Dynamic); auto cs = xy::Physics::CollisionCircleShape(radius); cs.setDensity(0.9f); cs.setRestitution(1.f); body->addCollisionShape(cs); auto drawable = xy::Component::create<xy::SfDrawableComponent<sf::CircleShape>>(m_messageBus); drawable->getDrawable().setRadius(radius); drawable->getDrawable().setOrigin({ radius, radius }); drawable->getDrawable().setFillColor({ 255, 255, 255, 200 }); drawable->getDrawable().setOutlineThickness(2.f); auto cam = xy::Component::create<xy::Camera>(m_messageBus, getContext().defaultView); cam->lockTransform(xy::Camera::TransformLock::Rotation, true); cam->lockBounds(m_tilemap.getBounds()); entity = xy::Entity::create(m_messageBus); entity->setPosition(800.f, 400.f); entity->addComponent(body); entity->addComponent(drawable); auto camPtr = entity->addComponent(cam); ent = m_scene.addEntity(entity, xy::Scene::Layer::FrontFront); m_scene.setActiveCamera(camPtr); } }
TEST(SelectionTest, AddToSelection) { auto storageManager = std::make_shared<lc::storage::StorageManagerImpl>(); auto document = std::make_shared<lc::storage::DocumentImpl>(storageManager); auto docCanvas = std::make_shared<lc::viewer::DocumentCanvas>(document); auto layer = std::make_shared<lc::meta::Layer>(); std::shared_ptr<lc::operation::AddLayer> al = std::make_shared<lc::operation::AddLayer>(document, layer); al->execute(); auto builder = std::make_shared<lc::operation::EntityBuilder>(document); builder->appendEntity(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(0,0,0), lc::geo::Coordinate(0, 10, 0), layer)); builder->appendEntity(std::make_shared<lc::entity::Line>(lc::geo::Coordinate(10,0,0), lc::geo::Coordinate(10, 10, 0), layer)); builder->execute(); docCanvas->makeSelection(0, 0, 1, 1, false); docCanvas->closeSelection(); docCanvas->makeSelection(9, 0, 1, 1, false); docCanvas->closeSelection(); EXPECT_EQ(2, docCanvas->selectedDrawables().size()); unsigned int i = 0; docCanvas->entityContainer().each<const lc::entity::CADEntity>([&](lc::entity::CADEntity_CSPtr di) { if(docCanvas->getDrawable(di)->selected()) { i++; } }); EXPECT_TRUE(i == docCanvas->selectedDrawables().size()); }
void Bullet::render(sf::RenderTarget *target) { if(!dead && !enemy->isDead()) { // shape.SetPosition(x, y); target->Draw(getDrawable()); } }
void GraphicsComponent::setDrawableKey(stringType keyString) { //sets the drawable key this->drawableKey = keyString; auto sdlAssetManager = SDLAssetManager::getInstance(); //if we already have a reference to the drawable, then assign the reference if (sdlAssetManager->hasDrawable(keyString)) { auto drawable = sdlAssetManager->getDrawable(keyString); this->setDrawable(drawable); } //else we set our reference to null and handle it later within the //graphics system else { this->drawableReference = nullptr; } }
void GraphicsComponent::doDraw(int x, int y) { setPosition(x, y); drawer->draw(getDrawable(), priority); }
Floor::Floor(int numGhosts, int numDoors) { textureMap = new sf::Texture(); mapSprite = new sf::Sprite(); player = new Character(); monster = new Ghost[numGhosts]; door = new Door[numDoors]; closet = new Closet(); totalDoors = numDoors; totalGhosts = numGhosts; playerPosition = 0; addSpriteBoundaries(player->getSprite(), 0, 200, 400); // add player first at the left for (int i = 0; i < totalDoors; i++) { //door[i].getSprite()->setPosition(100 + getRandomInt(200, 600), 315); addSpriteBoundaries(door[i].getSprite(), 300, 700, 315); } if (numDoors == 0){ exit = new Exit(); addSpriteBoundaries(exit->getSprite(), 400, 700, 315); } for (int i = 0; i < totalGhosts; i++) { //monster[i].getSprite()->setPosition(100 + getRandomInt(200, 600), 400); addSpriteBoundaries(monster[i].getSprite(), 0, 700, 400); } //closet->getSprite()->setPosition(100 + getRandomInt(200, 600), 330); addSpriteBoundaries(closet->getSprite(), 0, 700, 330); textureMap->loadFromFile("brickwall.png"); mapSprite->scale(0.78125, 0.5859375); // 800 / 1024 and 600 / 1024 respectively //mapSprite->setTextureRect(sf::IntRect(0, 0, 800, 600)); mapSprite->setTexture(*textureMap); // push back in order of drawing objects.push_back(&getDrawable()); objects.push_back(&closet->getDrawable()); if (numDoors == 0){ objects.push_back(&exit->getDrawable()); for (int i = 0; i < numDoors; i++) { objects.push_back(&door[i].getDrawable()); playerPosition++; } playerPosition += 3; objects.push_back(&player->getDrawable()); for (int i = 0; i < numGhosts; i++) { objects.push_back(&monster[i].getDrawable()); } }else{ for (int i = 0; i < numDoors; i++) { objects.push_back(&door[i].getDrawable()); playerPosition++; } playerPosition += 2; objects.push_back(&player->getDrawable()); for (int i = 0; i < numGhosts; i++) { objects.push_back(&monster[i].getDrawable()); } } }
void LLFace::printDebugInfo() const { LLFacePool *poolp = getPool(); llinfos << "Object: " << getViewerObject()->mID << llendl; if (getDrawable()) { llinfos << "Type: " << LLPrimitive::pCodeToString(getDrawable()->getVObj()->getPCode()) << llendl; } if (getTexture()) { llinfos << "Texture: " << getTexture() << " Comps: " << (U32)getTexture()->getComponents() << llendl; } else { llinfos << "No texture: " << llendl; } llinfos << "Face: " << this << llendl; llinfos << "State: " << getState() << llendl; llinfos << "Geom Index Data:" << llendl; llinfos << "--------------------" << llendl; llinfos << "GI: " << mGeomIndex << " Count:" << mGeomCount << llendl; llinfos << "Face Index Data:" << llendl; llinfos << "--------------------" << llendl; llinfos << "II: " << mIndicesIndex << " Count:" << mIndicesCount << llendl; llinfos << llendl; if (poolp) { poolp->printDebugInfo(); S32 pool_references = 0; for (std::vector<LLFace*>::iterator iter = poolp->mReferences.begin(); iter != poolp->mReferences.end(); iter++) { LLFace *facep = *iter; if (facep == this) { llinfos << "Pool reference: " << pool_references << llendl; pool_references++; } } if (pool_references != 1) { llinfos << "Incorrect number of pool references!" << llendl; } } #if 0 llinfos << "Indices:" << llendl; llinfos << "--------------------" << llendl; const U32 *indicesp = getRawIndices(); S32 indices_count = getIndicesCount(); S32 geom_start = getGeomStart(); for (S32 i = 0; i < indices_count; i++) { llinfos << i << ":" << indicesp[i] << ":" << (S32)(indicesp[i] - geom_start) << llendl; } llinfos << llendl; llinfos << "Vertices:" << llendl; llinfos << "--------------------" << llendl; for (S32 i = 0; i < mGeomCount; i++) { llinfos << mGeomIndex + i << ":" << poolp->getVertex(mGeomIndex + i) << llendl; } llinfos << llendl; #endif }
void LLFace::dirtyTexture() { gPipeline.markTextured(getDrawable()); }
// 初期化処理 bool AdventureScene::init(SceneManager* smgr) { if (m_continue) { setLoadData(); } // 中段セーブデータの読み込み // データベースの生成 mp_rcdata = new Database(); mp_rcdata->createTable("img", "data/res/adventure/img.csv"); mp_rcdata->createTable("snd", "data/res/adventure/snd.csv"); mp_rsc = &smgr->getResources(); // リソースファイルのロード ImageResourceManager& ircmgr = smgr->getResources().images(); ircmgr.loadFromCSV(IMGLIST); SoundResourceManager& srcmgr = smgr->getResources().sounds(); srcmgr.loadFromCSV(SNDLIST); BlendResourceManager& brcmgr = smgr->getResources().blends(); brcmgr.loadFromCSV(BIMGLIST); //brcmgr.set("slidemask", "data/res/adventure/blend/slidemask.png"); //フォントハンドルの生成 FontResourceManager& frcmgr = smgr->getResources().fonts(); if (!frcmgr.hasKey("adventure_message_font")) { AddFontResourceEx(FONTPATH.c_str(), FR_PRIVATE, NULL); frcmgr.set("adventure_message_font", "しねきゃぷしょん", 24, 9, DX_FONTTYPE_ANTIALIASING_EDGE); } int fontHandle = frcmgr.get("adventure_message_font"); //シナリオリストの生成 Record rec; Table* scriptTable = new Table("data/res/adventure/scriptList.csv"); scriptTable->find([=](const Record& r) { return r.getStr("key") == m_scriptId; }).getRecord(rec); std::string path = rec.getStr("filename"); // シナリオデータの読み込み ScenarioScript script; //ローカル変数に変更 script.init(path); // タスクの登録処理 std::vector<std::string>::iterator it; InstructionExpression iExp; std::string line; while ((line = script.getLine()) != "") { Context context(line); bool result = iExp.interpret(context, smgr, this); assert("スクリプトの解釈に失敗しました." && result); } // 画面レイアウトの構築 // メッセージウィンドウの登録 DrawableRegister reg(this, mp_rsc); reg.addImage(REGISTER); //シナリオとキャラ名を表示するための初期設定 mp_animationTextBox = new DrawableAnimationTextBox(); mp_animationText = new DrawableAnimationText(); mp_animationText->setTextColor(255, 255, 255); mp_animationText->setUseAnimation(false); mp_animationTextBox->setSize(30, 3); mp_animationTextBox->setLineSpace(20); mp_animationTextBox->setTextColor(255, 255, 255); mp_animationTextBox->setPosition(20,420); mp_animationText->setFontHandle(fontHandle); mp_animationTextBox->setFontHandle(fontHandle); addDrawable("t", mp_animationText, 13); addDrawable("b", mp_animationTextBox, 13); mp_animationText->setIsVisible(true); mp_animationTextBox->setIsVisible(true); if (m_continue) { // 状態の復元 if (!m_BGKey.empty()) { // 背景の復元 Drawable* bg = getDrawable(m_BGKey); bg->setAlpha(kdna::MAX_ALPHA); bg->setIsVisible(true); } if (!m_leftCharKey.empty()) { Drawable* left = getDrawable(m_leftCharKey); left->setAlpha(kdna::MAX_ALPHA); left->setPosition(85, 100); // todo: 定数を使用するように変更 left->setIsVisible(true); } if (!m_rightCharKey.empty()) { Drawable* right = getDrawable(m_rightCharKey); right->setAlpha(kdna::MAX_ALPHA); right->setPosition(405, 100); // todo: 定数を使用するように変更 right->setIsVisible(true); } if (!m_BGMKey.empty()) { // BGMの再生 Sound* bgm = getSound(m_BGMKey); bgm->setVolume(100); bgm->play(); } } return true; }