Browse Source

Add mouse wheel and level selection support

master
C. J. Howard 6 years ago
parent
commit
3974be075e
10 changed files with 401 additions and 33 deletions
  1. +1
    -1
      data
  2. +52
    -0
      src/application.cpp
  3. +22
    -1
      src/application.hpp
  4. +133
    -1
      src/controls.cpp
  5. +13
    -0
      src/controls.hpp
  6. +85
    -1
      src/input.cpp
  7. +17
    -0
      src/input.hpp
  8. +62
    -1
      src/states/splash-state.cpp
  9. +15
    -26
      src/states/title-state.cpp
  10. +1
    -2
      src/states/title-state.hpp

+ 1
- 1
data

@ -1 +1 @@
Subproject commit 8e817687dd5f843360a2cd90be66ae0e31ae9d4b
Subproject commit 20ee9d1816867003a3246bc8ce60c60df2c2c7b7

+ 52
- 0
src/application.cpp View File

@ -358,6 +358,9 @@ Application::Application(int argc, char* argv[]):
cameraRotateCCW.bindKey(keyboard, SDL_SCANCODE_E);
cameraZoomIn.bindKey(keyboard, SDL_SCANCODE_EQUALS);
cameraZoomOut.bindKey(keyboard, SDL_SCANCODE_MINUS);
cameraZoomIn.bindMouseWheelAxis(mouse, MouseWheelAxis::POSITIVE_Y);
cameraZoomOut.bindMouseWheelAxis(mouse, MouseWheelAxis::NEGATIVE_Y);
cameraToggleOverheadView.bindKey(keyboard, SDL_SCANCODE_R);
cameraToggleNestView.bindKey(keyboard, SDL_SCANCODE_F);
walkForward.bindKey(keyboard, SDL_SCANCODE_UP);
@ -599,4 +602,53 @@ void Application::activateMenuItem(std::size_t index)
menus[currentMenuIndex]->getItem(index)->deselect();
menus[currentMenuIndex]->getItem(index)->activate();
}
void Application::selectLevel(std::size_t index)
{
if (index > levelSelectorMenu->getItemCount())
{
std::cout << "Selected invalid level" << std::endl;
return;
}
MenuItem* previousItem = levelSelectorMenu->getItem(currentLevel - 1);
previousItem->deselect();
currentLevel = index + 1;
MenuItem* nextItem = levelSelectorMenu->getItem(currentLevel - 1);
nextItem->select();
}
void Application::activateLevel(std::size_t index)
{
if (index > levelSelectorMenu->getItemCount())
{
std::cout << "Activated invalid level" << std::endl;
return;
}
//levelSelectorMenu->getItem(currentLevel - 1)->deselect();
levelSelectorMenu->getItem(currentLevel - 1)->activate();
}
void Application::loadLevel()
{
if (currentLevel < 1 || currentLevel >= campaign.levels[currentWorld].size())
{
std::cout << "Attempted to load invalid level" << std::endl;
return;
}
const Level* level = &campaign.levels[currentWorld][currentLevel];
const Biome* biome = &biosphere.biomes[level->biome];
soilPass.setHorizonOTexture(biome->soilHorizonO);
soilPass.setHorizonATexture(biome->soilHorizonA);
soilPass.setHorizonBTexture(biome->soilHorizonB);
soilPass.setHorizonCTexture(biome->soilHorizonC);
std::string heightmap = std::string("data/textures/") + level->heightmap;
terrain.load(heightmap);
}

+ 22
- 1
src/application.hpp View File

@ -27,6 +27,7 @@ using namespace Emergent;
#include "game/terrain.hpp"
#include "game/level.hpp"
#include "game/biome.hpp"
#include "game/terrain.hpp"
#include "input.hpp"
#include "controls.hpp"
#include "settings.hpp"
@ -75,6 +76,11 @@ public:
void selectMenuItem(std::size_t index);
void activateMenuItem(std::size_t index);
void selectLevel(std::size_t index);
void activateLevel(std::size_t index);
void loadLevel();
private:
ApplicationState* state;
ApplicationState* nextState;
@ -171,14 +177,21 @@ public:
// Misc
Timer frameTimer;
// UI
// UI text
ParameterDict strings;
float dpi;
float fontSizePT;
float fontSizePX;
Font* menuFont;
// UI textures
Texture* splashTexture;
Texture* titleTexture;
Texture* levelActiveTexture;
Texture* levelInactiveTexture;
Texture* levelConnectorTexture;
// UI elements
Vector4 selectedColor;
Vector4 deselectedColor;
UIContainer* uiRootElement;
@ -212,6 +225,10 @@ public:
UILabel* returnToMainMenuLabel;
UILabel* quitToDesktopLabel;
UIContainer* levelSelectorContainer;
UIImage* levelSelections[10];
UIImage* levelConnectors[9];
BillboardBatch* uiBatch;
UIBatcher* uiBatcher;
UIRenderPass uiPass;
@ -254,6 +271,7 @@ public:
Menu* challengeMenu;
Menu* experimentMenu;
Menu* settingsMenu;
Menu* levelSelectorMenu;
// Models
Model* antModel;
@ -261,7 +279,10 @@ public:
// Game variables
Campaign campaign;
int currentWorld;
int currentLevel;
Biosphere biosphere;
Terrain terrain;
Colony* colony;
SurfaceCameraController* surfaceCam;

+ 133
- 1
src/controls.cpp View File

@ -38,6 +38,11 @@ void Control::setDeadzone(float value)
void Control::update()
{
if (!boundMouseWheelAxes.empty())
{
currentValue = 0.0f;
}
previousValue = currentValue;
}
@ -53,7 +58,7 @@ bool Control::wasTriggered() const
bool Control::isUnbound() const
{
return (boundKeys.empty() && boundMouseButtons.empty() && boundGamepadButtons.empty() && boundGamepadAxes.empty());
return (boundKeys.empty() && boundMouseButtons.empty() && boundMouseWheelAxes.empty() && boundGamepadButtons.empty() && boundGamepadAxes.empty());
}
void Control::bindKey(Keyboard* keyboard, int scancode)
@ -92,6 +97,24 @@ void Control::bindMouseButton(Mouse* mouse, int button)
boundMouseButtons.push_back(std::pair<Mouse*, int>(mouse, button));
}
void Control::bindMouseWheelAxis(Mouse* mouse, MouseWheelAxis axis)
{
// Checking if already observing this mouse
bool observing = false;
for (auto it: boundMouseWheelAxes)
{
if (it.first == mouse)
{
observing = true;
break;
}
}
if (!observing)
mouse->addMouseWheelObserver(static_cast<MouseWheelObserver*>(this));
boundMouseWheelAxes.push_back(std::pair<Mouse*, MouseWheelAxis>(mouse, axis));
}
void Control::bindGamepadButton(Gamepad* gamepad, int button)
{
bool observing = false;
@ -138,6 +161,27 @@ void Control::bind(const InputEvent& event)
bindMouseButton(event.mouseButton.first, event.mouseButton.second);
break;
case InputEvent::Type::MOUSE_WHEEL:
{
int x = std::get<1>(event.mouseWheel);
int y = std::get<2>(event.mouseWheel);
MouseWheelAxis axis;
if (x > 0)
axis = MouseWheelAxis::POSITIVE_X;
else if (x < 0)
axis = MouseWheelAxis::NEGATIVE_X;
else if (y > 0)
axis = MouseWheelAxis::POSITIVE_Y;
else if (y < 0)
axis = MouseWheelAxis::NEGATIVE_Y;
else
break;
bindMouseWheelAxis(std::get<0>(event.mouseWheel), axis);
break;
}
case InputEvent::Type::GAMEPAD_BUTTON:
bindGamepadButton(event.gamepadButton.first, event.gamepadButton.second);
break;
@ -189,6 +233,24 @@ void Control::unbind()
}
}
while (!boundMouseWheelAxes.empty())
{
// Remove the first bound mouse button and stop observing its mouse
Mouse* mouse = boundMouseWheelAxes.front().first;
mouse->removeMouseWheelObserver(static_cast<MouseWheelObserver*>(this));
boundMouseWheelAxes.pop_front();
// Remove other bound mouse buttons which are associated with the mouse
auto it = boundMouseWheelAxes.begin();
while (it != boundMouseWheelAxes.end())
{
if (it->first == mouse)
boundMouseWheelAxes.erase(it++);
else
++it;
}
}
while (!boundGamepadButtons.empty())
{
// Remove the first bound gamepad button and stop observing its gamepad
@ -274,6 +336,33 @@ void Control::mouseButtonReleased(int button, int x, int y)
}
}
void Control::mouseWheelScrolled(int x, int y)
{
for (auto it: boundMouseWheelAxes)
{
if (it.second == MouseWheelAxis::POSITIVE_X && x > 0)
{
currentValue += x;
break;
}
else if (it.second == MouseWheelAxis::NEGATIVE_X && x < 0)
{
currentValue -= x;
break;
}
else if (it.second == MouseWheelAxis::POSITIVE_Y && y > 0)
{
currentValue += y;
break;
}
else if (it.second == MouseWheelAxis::NEGATIVE_Y && y < 0)
{
currentValue -= y;
break;
}
}
}
void Control::gamepadButtonPressed(int button)
{
for (auto it: boundGamepadButtons)
@ -320,6 +409,11 @@ const std::list>* Control::getBoundMouseButtons() const
return &boundMouseButtons;
}
const std::list<std::pair<Mouse*, MouseWheelAxis>>* Control::getBoundMouseWheelAxes() const
{
return &boundMouseWheelAxes;
}
const std::list<std::pair<Gamepad*, int>>* Control::getBoundGamepadButtons() const
{
return &boundGamepadButtons;
@ -354,6 +448,7 @@ bool ControlProfile::save(const std::string& filename)
Control* control = it->second;
const std::list<std::pair<Keyboard*, int>>* boundKeys = control->getBoundKeys();
const std::list<std::pair<Mouse*, int>>* boundMouseButtons = control->getBoundMouseButtons();
const std::list<std::pair<Mouse*, MouseWheelAxis>>* boundMouseWheelAxes = control->getBoundMouseWheelAxes();
const std::list<std::pair<Gamepad*, int>>* boundGamepadButtons = control->getBoundGamepadButtons();
const std::list<std::tuple<Gamepad*, int, bool>>* boundGamepadAxes = control->getBoundGamepadAxes();
@ -369,6 +464,24 @@ bool ControlProfile::save(const std::string& filename)
file << "control\t" << it->first << "\tmouse\tbutton\t" << button << '\n';
}
for (auto boundMouseWheelAxis: *boundMouseWheelAxes)
{
MouseWheelAxis axis = boundMouseWheelAxis.second;
file << "control\t" << it->first << "\tmouse\twheel\t";
if (axis == MouseWheelAxis::POSITIVE_X)
file << "+x";
else if (axis == MouseWheelAxis::NEGATIVE_X)
file << "-x";
else if (axis == MouseWheelAxis::POSITIVE_Y)
file << "+y";
else if (axis == MouseWheelAxis::NEGATIVE_Y)
file << "-y";
else
file << "unknown";
file << '\n';
}
for (auto boundGamepadButton: *boundGamepadButtons)
{
const std::string& gamepadName = boundGamepadButton.first->getName();
@ -463,6 +576,25 @@ bool ControlProfile::load(const std::string& filename)
control->bindMouseButton(mouse, button);
}
else if (tokens[3] == "wheel")
{
MouseWheelAxis axis;
if (tokens[4] == "+x")
axis = MouseWheelAxis::POSITIVE_X;
else if (tokens[4] == "-x")
axis = MouseWheelAxis::NEGATIVE_X;
else if (tokens[4] == "+y")
axis = MouseWheelAxis::POSITIVE_Y;
else if (tokens[4] == "-y")
axis = MouseWheelAxis::NEGATIVE_Y;
else
{
std::cerr << "Invalid line \"" << line << "\" in control profile \"" << filename << "\"" << std::endl;
continue;
}
control->bindMouseWheelAxis(mouse, axis);
}
else
{
std::cerr << "Invalid line \"" << line << "\" in control profile \"" << filename << "\"" << std::endl;

+ 13
- 0
src/controls.hpp View File

@ -26,9 +26,18 @@
#include <tuple>
#include <map>
enum class MouseWheelAxis
{
POSITIVE_X,
NEGATIVE_X,
POSITIVE_Y,
NEGATIVE_Y
};
class Control:
public KeyObserver,
public MouseButtonObserver,
public MouseWheelObserver,
public GamepadButtonObserver,
public GamepadAxisObserver
{
@ -47,6 +56,7 @@ public:
void bindKey(Keyboard* keyboard, int scancode);
void bindMouseButton(Mouse* mouse, int button);
void bindMouseWheelAxis(Mouse* mouse, MouseWheelAxis axis);
void bindGamepadButton(Gamepad* gamepad, int button);
void bindGamepadAxis(Gamepad* gamepad, int axis, bool negative);
void bind(const InputEvent& event);
@ -57,12 +67,14 @@ public:
virtual void keyReleased(int scancode);
virtual void mouseButtonPressed(int button, int x, int y);
virtual void mouseButtonReleased(int button, int x, int y);
virtual void mouseWheelScrolled(int x, int y);
virtual void gamepadButtonPressed(int button);
virtual void gamepadButtonReleased(int button);
virtual void gamepadAxisMoved(int axis, bool negative, float value);
const std::list<std::pair<Keyboard*, int>>* getBoundKeys() const;
const std::list<std::pair<Mouse*, int>>* getBoundMouseButtons() const;
const std::list<std::pair<Mouse*, MouseWheelAxis>>* getBoundMouseWheelAxes() const;
const std::list<std::pair<Gamepad*, int>>* getBoundGamepadButtons() const;
const std::list<std::tuple<Gamepad*, int, bool>>* getBoundGamepadAxes() const;
@ -73,6 +85,7 @@ private:
std::list<std::pair<Keyboard*, int>> boundKeys;
std::list<std::pair<Mouse*, int>> boundMouseButtons;
std::list<std::pair<Mouse*, MouseWheelAxis>> boundMouseWheelAxes;
std::list<std::pair<Gamepad*, int>> boundGamepadButtons;
std::list<std::tuple<Gamepad*, int, bool>> boundGamepadAxes;
};

+ 85
- 1
src/input.cpp View File

@ -71,7 +71,8 @@ void Keyboard::release(int scancode)
Mouse::Mouse(const std::string& name):
InputDevice(name),
notifyingMotionObservers(false),
notifyingButtonObservers(false)
notifyingButtonObservers(false),
notifyingWheelObservers(false)
{}
Mouse::~Mouse()
@ -101,6 +102,18 @@ void Mouse::addMouseButtonObserver(MouseButtonObserver* observer)
}
}
void Mouse::addMouseWheelObserver(MouseWheelObserver* observer)
{
if (notifyingWheelObservers)
{
additionFlaggedWheelObservers.push_back(observer);
}
else
{
wheelObservers.push_back(observer);
}
}
void Mouse::removeMouseMotionObserver(MouseMotionObserver* observer)
{
if (notifyingMotionObservers)
@ -125,6 +138,18 @@ void Mouse::removeMouseButtonObserver(MouseButtonObserver* observer)
}
}
void Mouse::removeMouseWheelObserver(MouseWheelObserver* observer)
{
if (notifyingWheelObservers)
{
removalFlaggedWheelObservers.push_back(observer);
}
else
{
wheelObservers.remove(observer);
}
}
void Mouse::removeMouseMotionObservers()
{
motionObservers.clear();
@ -135,6 +160,11 @@ void Mouse::removeMouseButtonObservers()
buttonObservers.clear();
}
void Mouse::removeMouseWheelObservers()
{
wheelObservers.clear();
}
void Mouse::press(int button, int x, int y)
{
// Notify observers
@ -180,6 +210,20 @@ void Mouse::move(int x, int y)
processFlaggedMotionObservers();
}
void Mouse::scroll(int x, int y)
{
// Notify observers
notifyingWheelObservers = true;
for (auto observer: wheelObservers)
{
observer->mouseWheelScrolled(x, y);
}
notifyingWheelObservers = false;
// Process flags
processFlaggedWheelObservers();
}
void Mouse::processFlaggedMotionObservers()
{
// Remove observers which are flagged for removal
@ -214,6 +258,23 @@ void Mouse::processFlaggedButtonObservers()
additionFlaggedButtonObservers.clear();
}
void Mouse::processFlaggedWheelObservers()
{
// Remove observers which are flagged for removal
for (auto observer: removalFlaggedWheelObservers)
{
wheelObservers.remove(observer);
}
removalFlaggedWheelObservers.clear();
// Add observers which are flagged for addition
for (auto observer: additionFlaggedWheelObservers)
{
wheelObservers.push_back(observer);
}
additionFlaggedWheelObservers.clear();
}
Gamepad::Gamepad(const std::string& name):
InputDevice(name)
{}
@ -452,6 +513,15 @@ void SDLInputManager::update()
break;
}
case SDL_MOUSEWHEEL:
{
int direction = (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) ? -1 : 1;
int x = event.wheel.x * direction;
int y = event.wheel.y * direction;
mouse->scroll(x, y);
break;
}
case SDL_CONTROLLERBUTTONDOWN:
{
int instanceID = event.cbutton.which;
@ -660,6 +730,20 @@ void SDLInputManager::listen(InputEvent* inputEvent)
return;
}
// Check for mouse wheel events
eventCount = SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_MOUSEWHEEL, SDL_MOUSEWHEEL);
if (eventCount)
{
int direction = (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) ? -1 : 1;
int x = event.wheel.x * direction;
int y = event.wheel.y * direction;
inputEvent->type = InputEvent::Type::MOUSE_WHEEL;
std::get<0>(inputEvent->mouseWheel) = mouse;
std::get<1>(inputEvent->mouseWheel) = x;
std::get<2>(inputEvent->mouseWheel) = y;
return;
}
// Check for gamepad button events
eventCount = SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_CONTROLLERBUTTONDOWN, SDL_CONTROLLERBUTTONDOWN);
if (eventCount)

+ 17
- 0
src/input.hpp View File

@ -49,6 +49,12 @@ public:
virtual void mouseButtonReleased(int button, int x, int y) = 0;
};
class MouseWheelObserver
{
public:
virtual void mouseWheelScrolled(int x, int y) = 0;
};
class GamepadButtonObserver
{
public:
@ -135,14 +141,18 @@ public:
void addMouseMotionObserver(MouseMotionObserver* observer);
void addMouseButtonObserver(MouseButtonObserver* observer);
void addMouseWheelObserver(MouseWheelObserver* observer);
void removeMouseMotionObserver(MouseMotionObserver* observer);
void removeMouseButtonObserver(MouseButtonObserver* observer);
void removeMouseWheelObserver(MouseWheelObserver* observer);
void removeMouseMotionObservers();
void removeMouseButtonObservers();
void removeMouseWheelObservers();
void press(int button, int x, int y);
void release(int button, int x, int y);
void move(int x, int y);
void scroll(int x, int y);
const glm::ivec2& getCurrentPosition() const;
const glm::ivec2& getPreviousPosition() const;
@ -150,17 +160,22 @@ public:
private:
void processFlaggedMotionObservers();
void processFlaggedButtonObservers();
void processFlaggedWheelObservers();
glm::ivec2 currentPosition;
glm::ivec2 previousPosition;
std::list<MouseMotionObserver*> motionObservers;
std::list<MouseButtonObserver*> buttonObservers;
std::list<MouseWheelObserver*> wheelObservers;
bool notifyingMotionObservers;
bool notifyingButtonObservers;
bool notifyingWheelObservers;
std::list<MouseMotionObserver*> additionFlaggedMotionObservers;
std::list<MouseButtonObserver*> additionFlaggedButtonObservers;
std::list<MouseWheelObserver*> additionFlaggedWheelObservers;
std::list<MouseMotionObserver*> removalFlaggedMotionObservers;
std::list<MouseButtonObserver*> removalFlaggedButtonObservers;
std::list<MouseWheelObserver*> removalFlaggedWheelObservers;
};
inline InputDevice::Type Mouse::getType() const
@ -216,6 +231,7 @@ public:
NONE,
KEY,
MOUSE_BUTTON,
MOUSE_WHEEL,
GAMEPAD_BUTTON,
GAMEPAD_AXIS
};
@ -225,6 +241,7 @@ public:
InputEvent::Type type;
std::pair<Keyboard*, int> key;
std::pair<Mouse*, int> mouseButton;
std::tuple<Mouse*, int, int> mouseWheel;
std::pair<Gamepad*, int> gamepadButton;
std::tuple<Gamepad*, int, int> gamepadAxis;
};

+ 62
- 1
src/states/splash-state.cpp View File

@ -63,13 +63,16 @@ void SplashState::enter()
}
delete fontLoader;
// Load splash & title textures
// Load UI textures
application->textureLoader->setGamma(1.0f);
application->textureLoader->setCubemap(false);
application->textureLoader->setMipmapChain(false);
application->textureLoader->setMaxAnisotropy(1.0f);
application->splashTexture = application->textureLoader->load("data/textures/splash.png");
application->titleTexture = application->textureLoader->load("data/textures/title.png");
application->levelActiveTexture = application->textureLoader->load("data/textures/ui-level-active.png");
application->levelInactiveTexture = application->textureLoader->load("data/textures/ui-level-inactive.png");
application->levelConnectorTexture = application->textureLoader->load("data/textures/ui-level-connector.png");
// Get UI strings
std::string pressAnyKeyString;
@ -294,6 +297,45 @@ void SplashState::enter()
application->quitToDesktopLabel->setTranslation(Vector2(0.0f, application->menuFont->getMetrics().getHeight() * 2));
application->pauseMenuContainer->addChild(application->quitToDesktopLabel);
// Level selector
application->levelSelectorContainer = new UIContainer();
application->levelSelectorContainer->setDimensions(Vector2(application->levelActiveTexture->getWidth() * 10 + 48 * 9, application->levelActiveTexture->getHeight()));
application->levelSelectorContainer->setAnchor(Vector2(0.5f, 1.0f));
application->levelSelectorContainer->setTranslation(Vector2(0.0f, -application->levelActiveTexture->getHeight()));
application->levelSelectorContainer->setVisible(true);
application->levelSelectorContainer->setActive(true);
application->uiRootElement->addChild(application->levelSelectorContainer);
for (int i = 0; i < 10; ++i)
{
application->levelSelections[i] = new UIImage();
application->levelSelections[i]->setAnchor(Vector2(0.0f, 0.5f));
application->levelSelections[i]->setDimensions(Vector2(application->levelActiveTexture->getWidth(), application->levelActiveTexture->getHeight()));
application->levelSelections[i]->setTranslation(Vector2(i * 96.0f, 0.0f));
application->levelSelections[i]->setTexture(application->levelInactiveTexture);
application->levelSelections[i]->setVisible(true);
application->levelSelectorContainer->addChild(application->levelSelections[i]);
if (i < 9)
{
application->levelConnectors[i] = new UIImage();
application->levelConnectors[i]->setAnchor(Vector2(0.0f, 0.5f));
application->levelConnectors[i]->setDimensions(Vector2(application->levelConnectorTexture->getWidth(), application->levelConnectorTexture->getHeight()));
application->levelConnectors[i]->setTranslation(Vector2((i + 1) * 96.0f - 50.0f, 0.0f));
application->levelConnectors[i]->setTexture(application->levelConnectorTexture);
application->levelConnectors[i]->setVisible(true);
application->levelSelectorContainer->addChild(application->levelConnectors[i]);
}
}
application->titleImage = new UIImage();
application->titleImage->setAnchor(Vector2(0.5f, 0.0f));
application->titleImage->setDimensions(Vector2(application->titleTexture->getWidth(), application->titleTexture->getHeight()));
application->titleImage->setTranslation(Vector2(0.0f, (int)(application->height * (1.0f / 3.0f) - application->titleTexture->getHeight())));
application->titleImage->setTexture(application->titleTexture);
application->titleImage->setVisible(false);
application->uiRootElement->addChild(application->titleImage);
/*
UIContainer* pauseMenuContainer;
UILabel* pausedResumeLabel;
@ -492,6 +534,23 @@ void SplashState::enter()
application->selectedMenuItemIndex = 0;
application->selectMenuItem(application->selectedMenuItemIndex);
application->currentLevel = 0;
application->levelSelectorMenu = new Menu();
for (int i = 0; i < 10; ++i)
{
MenuItem* levelSelectionItem = application->levelSelectorMenu->addItem();
levelSelectionItem->setSelectedCallback(std::bind(UIImage::setTexture, application->levelSelections[i], application->levelActiveTexture));
levelSelectionItem->setDeselectedCallback(std::bind(UIImage::setTexture, application->levelSelections[i], application->levelInactiveTexture));
levelSelectionItem->setActivatedCallback(std::bind(Application::loadLevel, application));
application->levelSelections[i]->setMouseOverCallback(std::bind(Application::selectLevel, application, levelSelectionItem->getIndex()));
application->levelSelections[i]->setMouseMovedCallback(std::bind(Application::selectLevel, application, levelSelectionItem->getIndex()));
application->levelSelections[i]->setMousePressedCallback(std::bind(Application::activateLevel, application, levelSelectionItem->getIndex()));
}
// Models
application->antModel = application->modelLoader->load("data/models/debug-worker.mdl");
@ -507,6 +566,8 @@ void SplashState::enter()
// Load campaign
application->campaign.load("data/levels/");
application->currentWorld = 1;
application->currentLevel = 1;
// Setup screen fade-in transition
fadeIn = false;

+ 15
- 26
src/states/title-state.cpp View File

@ -77,39 +77,23 @@ void TitleState::enter()
application->sunlight.setColor(glm::vec3(1.0f));
application->sunlight.setDirection(glm::normalize(glm::vec3(0.5, -1, -0.5)));
const Level* level = &application->campaign.levels[1][1];
const Biome* biome = &application->biosphere.biomes[level->biome];
// Setup soil pass
application->soilPass.setRenderTarget(&application->defaultRenderTarget);
TextureLoader textureLoader;
/*application->soilPass.setHorizonOTexture(textureLoader.load("data/textures/debug-soil-horizon-o.png"));
application->soilPass.setHorizonATexture(textureLoader.load("data/textures/debug-soil-horizon-a.png"));
application->soilPass.setHorizonBTexture(textureLoader.load("data/textures/debug-soil-horizon-b.png"));
application->soilPass.setHorizonCTexture(textureLoader.load("data/textures/debug-soil-horizon-c.png"));*/
application->soilPass.setHorizonOTexture(biome->soilHorizonO);
application->soilPass.setHorizonATexture(biome->soilHorizonA);
application->soilPass.setHorizonBTexture(biome->soilHorizonB);
application->soilPass.setHorizonCTexture(biome->soilHorizonC);
application->defaultCompositor.addPass(&application->soilPass);
// Create terrain
std::string heightmap = std::string("data/textures/") + level->heightmap;
terrain.create(255, 255, Vector3(50, 20, 50));
terrain.load(heightmap);
terrain.getSurfaceModel()->getGroup(0)->material = application->materialLoader->load("data/materials/debug-terrain-surface.mtl");
terrainSurface.setModel(terrain.getSurfaceModel());
application->terrain.create(255, 255, Vector3(50, 20, 50));
application->terrain.getSurfaceModel()->getGroup(0)->material = application->materialLoader->load("data/materials/debug-terrain-surface.mtl");
terrainSurface.setModel(application->terrain.getSurfaceModel());
terrainSurface.setTranslation(Vector3(0, 0, 0));
terrainSubsurface.setModel(terrain.getSubsurfaceModel());
terrainSubsurface.setModel(application->terrain.getSubsurfaceModel());
terrainSubsurface.setTranslation(Vector3(0, 0, 0));
application->scene.getLayer(0)->addObject(&terrainSurface);
application->scene.getLayer(0)->addObject(&terrainSubsurface);
navmesh = terrain.getSurfaceNavmesh();
navmesh = application->terrain.getSurfaceNavmesh();
// Load level
application->loadLevel();
// Setup lighting pass
application->lightingPass.setRenderTarget(&application->defaultRenderTarget);
@ -169,7 +153,7 @@ void TitleState::enter()
application->surfaceCam->setCamera(&application->camera);
application->surfaceCam->setFocalPoint(Vector3(0.0f));
application->surfaceCam->setFocalDistance(300.0f);
application->surfaceCam->setElevation(glm::radians(32.5f));
application->surfaceCam->setElevation(glm::radians(35.0f));
application->surfaceCam->setAzimuth(glm::radians(-45.0f));
application->surfaceCam->setTargetFocalPoint(application->surfaceCam->getFocalPoint());
application->surfaceCam->setTargetFocalDistance(application->surfaceCam->getFocalDistance());
@ -371,11 +355,16 @@ void TitleState::execute()
}
// Zoom camera
float zoomFactor = application->surfaceCam->getFocalDistance() / 20.0f * dt / (1.0f / 60.0f);
float zoomFactor = application->surfaceCam->getFocalDistance() / 5.0f * dt / (1.0f / 60.0f);
if (application->cameraZoomIn.isTriggered())
application->surfaceCam->zoom(zoomFactor * application->cameraZoomIn.getCurrentValue());
if (application->cameraZoomOut.isTriggered())
application->surfaceCam->zoom(-zoomFactor * application->cameraZoomOut.getCurrentValue());
float minFocalDistance = 2.0f;
float maxFocalDistance = 500.0f;
application->surfaceCam->setTargetFocalDistance(std::min(std::max(application->surfaceCam->getTargetFocalDistance(), minFocalDistance), maxFocalDistance));
application->surfaceCam->update(dt);
// Navigate menu

+ 1
- 2
src/states/title-state.hpp View File

@ -25,7 +25,7 @@
#include "../game/ant.hpp"
#include "../game/colony.hpp"
#include "../game/terrain.hpp"
#include <emergent/emergent.hpp>
using namespace Emergent;
@ -62,7 +62,6 @@ private:
Colony colony;
Ant* ant;
Navmesh* navmesh;
Terrain terrain;
ModelInstance terrainSurface;
ModelInstance terrainSubsurface;
};

Loading…
Cancel
Save