Exemplo n.º 1
0
void SelectManager::selectRectangular()
{
	for(int i = 0; i < glwidgets->size (); i++)
	{
		if(glwidgets->at (i)->getIsMouseHere ())
		{
			glwidgets->at (i)->drawSelectionRectangle (curX, curY, false);
			bool anyModelSelected = false;
			bool anyVertexSelected = false;
			selectedModels.clear ();
			selectedVertices.clear ();
			glwidgets->at (i)->rectangularSelection (preX, preY, curX, curY, selectedModels, selectedVertices);
			for(int i = 0; i < selectedModels.size (); i++)
			{
				selectedModels.at (i)->setSelected (true);
				anyModelSelected = true;
			}
			for(int i = 0; i < selectedVertices.size (); i++)
			{
				selectedVertices.at (i)->setSelected (true);
				anyVertexSelected = true;
			}
			if(!anyModelSelected)
				diselectAll ();
			break;
		}
	}
	emit endState();
}
Exemplo n.º 2
0
void AddProcess(IntervalModel& interval, Process::ProcessModel* proc)
{
  interval.processes.add(proc);

  const auto& scenar = *dynamic_cast<ScenarioInterface*>(interval.parent());
  AddProcessAfterState(startState(interval, scenar), *proc);
  AddProcessBeforeState(endState(interval, scenar), *proc);
}
Exemplo n.º 3
0
void EraseProcess(
    IntervalModel& interval,
    const Id<Process::ProcessModel>& proc_id)
{
  auto& proc = interval.processes.at(proc_id);
  const auto& scenar = *dynamic_cast<ScenarioInterface*>(interval.parent());

  RemoveProcessAfterState(startState(interval, scenar), proc);
  RemoveProcessBeforeState(endState(interval, scenar), proc);

  interval.processes.erase(proc);
}
Exemplo n.º 4
0
void LoadingState::loadModuleData()
{
    const int SCREEN_WIDTH = _gameEngine->getUIManager()->getScreenWidth();
    const int SCREEN_HEIGHT = _gameEngine->getUIManager()->getScreenHeight();
    
    setProgressText("Tidying some space...", 0);

    //Make sure all data is cleared first
    game_quit_module();

    setProgressText("Calculating some math...", 10);
    BillboardSystem::get().reset();

    //initialize math objects
    make_turntosin();

    // Linking system
    setProgressText("Initializing module linking... ", 20);
    if (!link_build_vfs( "mp_data/link.txt", LinkList)) Log::get().warn("Failed to initialize module linking\n");

    // initialize the collision system
    setProgressText("Beautifying graphics...", 40);

    // Reset all loaded "profiles" in the "profile system".
    ProfileSystem::get().reset();

    // do some graphics initialization
    gfx_system_make_enviro();

    //Load players if needed
    if(!_playersToLoad.empty()) {
        setProgressText("Loading players...", 50);
        if(!loadPlayers()) {
			Log::get().warn("Failed to load players!\n");
            endState();
            return;
        }
    }

    // try to start a new module
    setProgressText("Loading module data...", 60);
    if(!game_begin_module(_loadModule)) {
		Log::get().warn("Failed to load module!\n");
        endState();
        return;
    }
    _currentModule->setImportPlayers(_playersToLoad);

    setProgressText("Almost done...", 90);

    // set up the cameras *after* game_begin_module() or the player devices will not be initialized
    // and camera_system_begin() will not set up thte correct view
    std::shared_ptr<CameraSystem> cameraSystem = CameraSystem::request(local_stats.player_count);

    // Fade out music when finished loading
    AudioSystem::get().stopMusic();

    // make sure the per-module configuration settings are correct
    config_synch(&egoboo_config_t::get(), true, false);

    // Complete!
    setProgressText("Finished!", 100);

    // Hit that gong
    AudioSystem::get().playSoundFull(AudioSystem::get().getGlobalSound(GSND_GAME_READY));

    //1 second delay to let music finish, this prevents a frame lag on module startup
    std::this_thread::sleep_for(std::chrono::seconds(2));

    //Add the start button once we are finished loading
    std::shared_ptr<Button> startButton = std::make_shared<Button>("Press Space to begin", SDLK_SPACE);
    startButton->setSize(400, 30);
    startButton->setPosition(SCREEN_WIDTH/2 - startButton->getWidth()/2, SCREEN_HEIGHT-50);
    startButton->setOnClickFunction(
        [cameraSystem]{

            //Have to do this function in the OpenGL context thread or else it will fail
            Ego::Graphics::TextureAtlasManager::get().loadTileSet();

            //Hush gong
            AudioSystem::get().fadeAllSounds();
            _gameEngine->setGameState(std::make_shared<PlayingState>(cameraSystem));
        });
    addComponent(startButton);

    //Hide the progress bar
    _progressBar->setVisible(false);
}
DebugObjectLoadingState::DebugObjectLoadingState() :
#ifdef _MSC_VER
    _finishedLoading( {
    0
}),
#else
    _finishedLoading(false),
#endif
_loadingThread(),
_scrollableList(),
_moduleList(),
_toLoad(),
_currentLoader()
{
    const int SCREEN_WIDTH = _gameEngine->getUIManager()->getScreenWidth();
    const int SCREEN_HEIGHT = _gameEngine->getUIManager()->getScreenHeight();

    _scrollableList = std::make_shared<ScrollableList>();
    _scrollableList->setPosition(8, 8);
    _scrollableList->setSize(SCREEN_WIDTH - 16, SCREEN_HEIGHT - 56);

    _moduleList.emplace_back(new GlobalLoader());

    vfs_search_context_t *context = vfs_findFirst("/modules", "mod", VFS_SEARCH_DIR | VFS_SEARCH_BARE);

    while (context)
    {
        std::string moduleName = vfs_search_context_get_current(context);
        auto module = std::make_shared<ModuleLoader>(moduleName);
        _moduleList.emplace_back(module);
        vfs_findNext(&context);
    }
    vfs_findClose(&context);

    for (const auto &loader : _moduleList) {
        auto button = std::make_shared<Button>(loader->getModuleName());
        std::weak_ptr<ModuleLoader> loaderPtr = loader;
        button->setWidth(SCREEN_WIDTH - 72);
        button->setOnClickFunction([this, loaderPtr] { addToQueue(loaderPtr.lock()); });
        _scrollableList->addComponent(button);

        _currentLoader = loader;
        loader->loadObjectList();

        for (const auto &object : loader->getObjectList()) {
            std::weak_ptr<ObjectGUIContainer> objectPtr = object;
            object->setOnClick([this, objectPtr] { addToQueue(objectPtr.lock()); });
            _scrollableList->addComponent(object);
        }
    }
    _scrollableList->forceUpdate();
    addComponent(_scrollableList);

    std::shared_ptr<Button> back = std::make_shared<Button>("Back");
    back->setPosition(8, SCREEN_HEIGHT - 30 - 8);
    back->setSize(150, 30);
    back->setOnClickFunction([this] { endState(); });
    addComponent(back);

    std::shared_ptr<Button> loadAll = std::make_shared<Button>("Load All");
    loadAll->setPosition(SCREEN_WIDTH - 150 - 8, SCREEN_HEIGHT - 30 - 8);
    loadAll->setSize(150, 30);
    loadAll->setOnClickFunction([this] { for (const auto &a : _moduleList) addToQueue(a); });
    addComponent(loadAll);
}
Exemplo n.º 6
0
SelectPlayersState::SelectPlayersState() :
_playerButtons(),
_continueButton(std::make_shared<Button>("Select Module", SDLK_RETURN))
{
    //Load background
    std::shared_ptr<Image> background = std::make_shared<Image>("mp_data/menu/menu_selectplayers");
    background->setPosition(0, 0);
    background->setSize(GFX_WIDTH, GFX_HEIGHT);
    addComponent(background);

    //Add the buttons
    int yOffset = GFX_HEIGHT - 80;
    std::shared_ptr<Button> backButton = std::make_shared<Button>("Back", SDLK_ESCAPE);
    backButton->setPosition(20, yOffset);
    backButton->setSize(200, 30);
    backButton->setOnClickFunction(
        [this]{
        endState();
    });
    addComponent(backButton);

    yOffset -= backButton->getHeight() + 10;

    _continueButton->setPosition(20, yOffset);
    _continueButton->setSize(200, 30);
    _continueButton->setOnClickFunction(
        [this]{
        //Build list of all valid selected players
        std::list<std::string> selectedPlayersResult;
        for (const std::shared_ptr<LoadPlayerElement> &player : _selectedPlayers) {
            if (player != nullptr) {
                selectedPlayersResult.push_back(player->getProfile()->getPathname());
            }
        }

        //Do the select module screen next
        _gameEngine->pushGameState(std::make_shared<SelectModuleState>(selectedPlayersResult));
    });
    addComponent(_continueButton);
    _continueButton->setEnabled(false);

    //Tell them what this screen is all about
    std::shared_ptr<Label> infoText = std::make_shared<Label>("Select a character for each player that is going ot play.");
    infoText->setPosition(150, GFX_HEIGHT - 40);
    addComponent(infoText);

    //Players Label
    std::shared_ptr<Label> playersLabel = std::make_shared<Label>("PLAYERS");
    playersLabel->setPosition(20, 20);
    addComponent(playersLabel);

    std::shared_ptr<Label> characterLabel = std::make_shared<Label>("CHARACTER");
    characterLabel->setPosition(GFX_WIDTH / 3, 20);
    addComponent(characterLabel);

    yOffset = playersLabel->getY() + playersLabel->getHeight() + 20;
    for (int i = 0; i < 4; ++i) {
        std::shared_ptr<Label> playerLabel = std::make_shared<Label>(std::string("Player ") + std::to_string(i + 1));
        playerLabel->setPosition(40, yOffset);
        addComponent(playerLabel);

        std::shared_ptr<Button> playerButton = std::make_shared<Button>("Not playing");
        playerButton->setSize(200, 42);
        playerButton->setPosition(GFX_WIDTH / 3, yOffset - 10);
        playerButton->setOnClickFunction(
            [this, i]{
            _gameEngine->pushGameState(std::make_shared<SelectCharacterState>(_selectedPlayers[i]));
        }
        );
        addComponent(playerButton);

        yOffset += playerLabel->getHeight() + 50;

        //Initially select no character for each player
        _selectedPlayers.push_back(nullptr);
        _playerButtons.push_back(playerButton);
    }

    //Mark all loadable characters initially as unselected
    for (const std::shared_ptr<LoadPlayerElement> &save : ProfileSystem::get().getSavedPlayers())
    {
        save->setSelected(false);
    }
}
Exemplo n.º 7
0
InGameMenuState::InGameMenuState(GameState &gameState) :
    _slidyButtons(),
    _backgroundState(gameState)
{
    // Add the buttons
    int yOffset = Ego::GraphicsSystem::gfx_height-80;
    std::shared_ptr<Button> exitButton = std::make_shared<Button>(_currentModule->isExportValid() ? "Save and Exit" : "Abort and Exit", SDLK_q);
    exitButton->setPosition(20, yOffset);
    exitButton->setSize(200, 30);
    exitButton->setOnClickFunction(
    []{
        _gameEngine->setGameState(std::make_shared<MainMenuState>());
    });
    addComponent(exitButton);
    _slidyButtons.push_front(exitButton);

    yOffset -= exitButton->getHeight() + 10;

    std::shared_ptr<Button> optionsButton = std::make_shared<Button>("Options", SDLK_o);
    optionsButton->setPosition(20, yOffset);
    optionsButton->setSize(200, 30);
    optionsButton->setOnClickFunction(
        []{
            _gameEngine->pushGameState(std::make_shared<OptionsScreen>());
        });
    addComponent(optionsButton);
    _slidyButtons.push_front(optionsButton);

    yOffset -= optionsButton->getHeight() + 10;

    std::shared_ptr<Button> restartModuleButton = std::make_shared<Button>("Restart Module", SDLK_r);
    restartModuleButton->setPosition(20, yOffset);
    restartModuleButton->setSize(200, 30);
    restartModuleButton->setOnClickFunction(
    [this]{
        //Reload current module with current players
        _gameEngine->setGameState(std::make_shared<LoadingState>(_currentModule->getModuleProfile(), _currentModule->getImportPlayers()));
    });
    addComponent(restartModuleButton);
    _slidyButtons.push_front(restartModuleButton);

    yOffset -= restartModuleButton->getHeight() + 10;

    std::shared_ptr<Button> newGameButton = std::make_shared<Button>("Return to Module", SDLK_ESCAPE);
    newGameButton->setPosition(20, yOffset);
    newGameButton->setSize(200, 30);
    newGameButton->setOnClickFunction(
    [this]{
        endState();
    });
    addComponent(newGameButton);
    _slidyButtons.push_front(newGameButton);

    yOffset -= newGameButton->getHeight() + 10;

#ifdef _DEBUG
    std::shared_ptr<Button> debugButton = std::make_shared<Button>("Debug Particles", SDLK_p);
    debugButton->setPosition(20, yOffset);
    debugButton->setSize(200, 30);
    debugButton->setOnClickFunction(
    [this]{
        _gameEngine->pushGameState(std::make_shared<DebugParticlesScreen>());
    });
    addComponent(debugButton);
    _slidyButtons.push_front(debugButton);

    yOffset -= debugButton->getHeight() + 10;    
#endif
}
Exemplo n.º 8
0
DebugParticlesScreen::DebugParticlesScreen()
{
    const int SCREEN_WIDTH = _gameEngine->getUIManager()->getScreenWidth();
    const int SCREEN_HEIGHT = _gameEngine->getUIManager()->getScreenHeight();

    //Add the buttons
    std::shared_ptr<Button> backButton = std::make_shared<Button>("Back", SDLK_ESCAPE);
    backButton->setPosition(20, SCREEN_HEIGHT-80);
    backButton->setSize(200, 30);
    backButton->setOnClickFunction(
    [this]{
        endState();
    });
    addComponent(backButton);

    std::shared_ptr<Label> title = std::make_shared<Label>("==PARTICLE DEBUG SCREEN==");
    title->setPosition(10, 10);
    addComponent(title);

    std::shared_ptr<Label> usage = std::make_shared<Label>("Particle used: " + std::to_string(ParticleHandler::get().getCount()) + "/" + std::to_string(ParticleHandler::get().getDisplayLimit()));
    usage->setPosition(10, title->getY() + title->getHeight());
    addComponent(usage);

    std::shared_ptr<Label> invalid = std::make_shared<Label>("Invalid active particles: ");
    invalid->setPosition(10, usage->getY() + usage->getHeight());
    invalid->setColor(Ego::Math::Colour4f::red());
    addComponent(invalid);

    //Count who is using all the particles
    std::unordered_map<PIP_REF, size_t> usageCount;
    std::unordered_map<PIP_REF, size_t> terminatedCount;
    size_t invalidParticles = 0;
    for(const std::shared_ptr<Ego::Particle> &particle : ParticleHandler::get().iterator())
    {
        if(particle->getProfileID() == INVALID_PIP_REF || !PipStack.isLoaded(particle->getProfileID())) {
            invalidParticles++;
            log_warning("Invalid particle with ID: %d (CHR_REF=%d)\n", particle->getProfileID(), particle->getSpawnerProfile());
            continue;
        }

        if(particle->isTerminated()) {
            terminatedCount[particle->getProfileID()] += 1;
        }
        else {
            usageCount[particle->getProfileID()] += 1;
        }
    }

    std::shared_ptr<ScrollableList> scrollableList = std::make_shared<ScrollableList>();
    scrollableList->setPosition(invalid->getX(), invalid->getY() + invalid->getHeight() + 20);
    scrollableList->setSize(SCREEN_WIDTH-50, SCREEN_HEIGHT*0.75f-scrollableList->getY());
    addComponent(scrollableList);

    for(const auto &element : usageCount)
    {
        const std::shared_ptr<pip_t> &particleProfile = PipStack.get_ptr(element.first);

        std::stringstream labelString;
        labelString << element.second << " particle" << ((element.second > 0) ? "s: " : ":");
        labelString << particleProfile->getName();

        std::shared_ptr<Label> label = std::make_shared<Label>(labelString.str());
        label->setFont(_gameEngine->getUIManager()->getFont(UIManager::FONT_DEBUG));
        scrollableList->addComponent(label);
    }

    for(const auto &element : terminatedCount)
    {
        const std::shared_ptr<pip_t> &particleProfile = PipStack.get_ptr(element.first);

        std::stringstream labelString;
        labelString << element.second << " terminated particle" << ((element.second > 0) ? "s: " : ":");
        labelString << particleProfile->getName();

        std::shared_ptr<Label> label = std::make_shared<Label>(labelString.str());
        label->setFont(_gameEngine->getUIManager()->getFont(UIManager::FONT_DEBUG));
        label->setColor(Ego::Math::Colour4f::red());
        scrollableList->addComponent(label);
    }


    invalid->setText("Invalid active particles: " + std::to_string(invalidParticles));
    scrollableList->forceUpdate();
}
Exemplo n.º 9
0
void CreateCurvesFromAddresses(
        const QList<const Scenario::ConstraintModel*>& selected_constraints,
        const std::vector<Device::FullAddressSettings>& addresses,
        const iscore::CommandStackFacade& stack)
{
    if(selected_constraints.empty())
        return;

    // They should all be in the same scenario so we can select the first.
    // FIXME check that the other "cohesion" methods also use ScenarioInterface and not Scenario::ProcessModel
    auto scenar = dynamic_cast<Scenario::ScenarioInterface*>(
                                selected_constraints.first()->parent());


    int added_processes = 0;
    // Then create the commands
    auto big_macro = new Scenario::Command::AddMultipleProcessesToMultipleConstraintsMacro;

    for(const auto& constraint : selected_constraints)
    {
        // Generate brand new ids for the processes
        auto process_ids = getStrongIdRange<Process::ProcessModel>(addresses.size(), constraint->processes);
        auto macro_tuple = Scenario::Command::makeAddProcessMacro(*constraint, addresses.size());
        auto macro = std::get<0>(macro_tuple);
        auto& bigLayerVec = std::get<1>(macro_tuple);

        Path<Scenario::ConstraintModel> constraintPath{*constraint};
        const Scenario::StateModel& ss = startState(*constraint, *scenar);
        const auto& es = endState(*constraint, *scenar);

        std::vector<State::Address> existing_automations;
        for(const auto& proc : constraint->processes)
        {
            if(auto autom = dynamic_cast<const Automation::ProcessModel*>(&proc))
                existing_automations.push_back(autom->address());
        }

        int i = 0;
        for(const Device::FullAddressSettings& as : addresses)
        {
            // First, we skip the curve if there is already a curve
            // with this address in the constraint.
            if(contains(existing_automations, as.address))
                continue;

            // Then we set-up all the necessary values
            // min / max
            double min = as.domain.min.val.isNumeric()
                    ? State::convert::value<double>(as.domain.min)
                    : 0;

            double max = as.domain.max.val.isNumeric()
                    ? State::convert::value<double>(as.domain.max)
                    : 1;

            // start value / end value
            double start = std::min(min, max);
            double end = std::max(min, max);
            Process::MessageNode* s_node = Device::try_getNodeFromString(
                        ss.messages().rootNode(),
                        stringList(as.address));
            if(s_node)
            {
                if(auto val = s_node->value())
                {
                    start = State::convert::value<double>(*val);
                    min = std::min(start, min);
                    max = std::max(start, max);
                }
            }

            Process::MessageNode* e_node = Device::try_getNodeFromString(
                        es.messages().rootNode(),
                        stringList(as.address));
            if(e_node)
            {
                if(auto val = e_node->value())
                {
                    end = State::convert::value<double>(*val);
                    min = std::min(end, min);
                    max = std::max(end, max);
                }
            }

            // Send the command.
            macro->addCommand(new Scenario::Command::CreateCurveFromStates{
                                  Path<Scenario::ConstraintModel>{constraintPath},
                                  bigLayerVec[i],
                                  process_ids[i],
                                  as.address,
                                  start, end, min, max
                              });

            i++;
            added_processes++;
        }
        big_macro->addCommand(macro);
    }

    if(added_processes > 0)
    {
        CommandDispatcher<> disp{stack};
        disp.submitCommand(big_macro);
    }
    else
    {
        delete big_macro;
    }
}