Browse Source

Modify level select and update data submodule

master
C. J. Howard 6 years ago
parent
commit
978a02495e
6 changed files with 120 additions and 78 deletions
  1. +1
    -1
      data
  2. +71
    -60
      src/application.cpp
  3. +9
    -2
      src/application.hpp
  4. +4
    -3
      src/configuration.hpp.in
  5. +7
    -2
      src/game/colony.cpp
  6. +28
    -10
      src/states/level-select-state.cpp

+ 1
- 1
data

@ -1 +1 @@
Subproject commit 5774a045d436a87c8ac7173df9131543bbebb99f
Subproject commit 4a8a34537127355eb7aac33c79df2d658732e8c7

+ 71
- 60
src/application.cpp View File

@ -590,7 +590,7 @@ bool Application::loadModels()
antHillModel = modelLoader->load("data/models/ant-hill.mdl");
nestModel = modelLoader->load("data/models/nest.mdl");
forcepsModel = modelLoader->load("data/models/forceps.mdl");
levelPlaceholderModel = modelLoader->load("data/models/level-placeholder.mdl");
biomeFloorModel = modelLoader->load("data/models/desert-floor.mdl");
if (!antModel || !antHillModel || !nestModel || !forcepsModel)
{
@ -603,11 +603,7 @@ bool Application::loadModels()
antHillModelInstance.setRotation(glm::angleAxis(glm::radians(90.0f), Vector3(1, 0, 0)));
nestModelInstance.setModel(nestModel);
forcepsModelInstance.setModel(forcepsModel);
for (int i = 0; i < 5; ++i)
{
levelPlaceholderModelInstances[i].setModel(levelPlaceholderModel);
}
biomeFloorModelInstance.setModel(biomeFloorModel);
return true;
}
@ -640,7 +636,7 @@ bool Application::loadScene()
// Setup skybox pass
skyboxPass.setRenderTarget(&defaultRenderTarget);
defaultCompositor.addPass(&skyboxPass);
//defaultCompositor.addPass(&skyboxPass);
// Setup soil pass
soilPass.setRenderTarget(&defaultRenderTarget);
@ -1166,6 +1162,13 @@ bool Application::loadUI()
cameraTranslationTween = new Tween<Vector3>(EaseFunction::OUT_CUBIC, 0.0f, 0.0f, Vector3(0.0f), Vector3(0.0f));
tweener->addTween(cameraTranslationTween);
// Preview level tweens
for (int i = 0; i < 5; ++i)
{
previewLevelTweens[i] = new Tween<Vector3>(EaseFunction::OUT_CUBIC, 0.0f, 0.0f, Vector3(0.0f), Vector3(0.0f));
tweener->addTween(previewLevelTweens[i]);
}
// Build menu system
selectedMenuItemIndex = 0;
mainMenu = new Menu();
@ -1380,7 +1383,8 @@ bool Application::loadGame()
currentLevelIndex = 0;
for (int i = 0; i < 5; ++i)
{
previewLevelIndices[i] = oldPreviewLevelIndices[i] = i;
previewLevelIndices[i] = i;
oldPreviewLevelIndices[i] = -1;
}
simulationPaused = false;
@ -1389,6 +1393,7 @@ bool Application::loadGame()
{
previewLevels[i] = new Level();
}
currentLevel = new Level();
// Create colony
colony = new Colony();
@ -1494,64 +1499,42 @@ void Application::enterLevelSelection()
changeState(levelSelectState);
}
/*
void Application::selectLevel(std::size_t index)
void Application::selectWorld(std::size_t index)
{
if (index > levelSelectorMenu->getItemCount())
{
std::cout << "Selected invalid level" << std::endl;
return;
}
MenuItem* previousItem = levelSelectorMenu->getItem(currentLevel - 1);
previousItem->deselect();
// Set current world and level
currentWorldIndex = static_cast<int>(index);
selectLevel(std::min<int>(campaign.getLevelCount(currentWorldIndex) - 1, currentLevelIndex));
currentLevel = index + 1;
// Setup rendering passes
const LevelParameterSet* levelParams = campaign.getLevelParams(currentWorldIndex, currentLevelIndex);
const Biome* biome = &biosphere.biomes[levelParams->biome];
soilPass.setHorizonOTexture(biome->soilHorizonO);
soilPass.setHorizonATexture(biome->soilHorizonA);
soilPass.setHorizonBTexture(biome->soilHorizonB);
soilPass.setHorizonCTexture(biome->soilHorizonC);
skyboxPass.setCubemap(biome->specularCubemap);
MenuItem* nextItem = levelSelectorMenu->getItem(currentLevel - 1);
nextItem->select();
for (int i = 0; i < 5; ++i)
{
previewLevels[i]->terrain.getSurfaceModel()->getGroup(0)->material = materialLoader->load("data/materials/debug-terrain-surface.mtl");
}
}
void Application::activateLevel(std::size_t index)
void Application::selectNextWorld()
{
if (index > levelSelectorMenu->getItemCount())
if (currentWorldIndex < campaign.getWorldCount() - 1)
{
std::cout << "Activated invalid level" << std::endl;
return;
selectWorld(currentWorldIndex + 1);
}
//levelSelectorMenu->getItem(currentLevel - 1)->deselect();
levelSelectorMenu->getItem(currentLevel - 1)->activate();
}
*/
// Level count: 16
// Max loaded levels: 5
// 0: [ 0] 1 2 3 4
// 1: 0 [ 1] 2 3 4
// 2: 0 1 [ 2] 3 4
// 3: 5 1 2 [ 3] 4
// 4: 5 6 2 3 [ 4]
// 5: [ 5] 6 7 3 4
// 6: 5 [ 6] 7 8 4
// 7: 5 6 [ 7] 8 9
// 8: 10 6 7 [ 8] 9
// 9: 10 11 7 8 [ 9]
//10: [10] 11 12 8 9
//11: 10 [11] 12 13 9
//12: 10 11 [12] 13 14
//13: 15 11 12 [13] 14
//14: 15 11 12 13 [14]
//15: [15] 11 12 13 14
// pointer index = currentLevel % 5;
void Application::selectPreviousWorld()
{
if (currentWorldIndex > 0)
{
selectWorld(currentWorldIndex - 1);
}
}
void Application::selectLevel(std::size_t index)
{
@ -1588,7 +1571,12 @@ void Application::selectLevel(std::size_t index)
{
oldPreviewLevelIndices[i] = previewLevelIndices[i];
// Load preview
// Load level preview
const LevelParameterSet* params = campaign.getLevelParams(currentWorldIndex, previewLevelIndices[i]);
previewLevels[i]->load(*params);
previewLevelSurfaces[i].setModel(previewLevels[i]->terrain.getSurfaceModel());
previewLevelSubsurfaces[i].setModel(previewLevels[i]->terrain.getSubsurfaceModel());
}
if (currentPreviewIndex == i)
@ -1605,7 +1593,24 @@ void Application::selectLevel(std::size_t index)
// Perform tweening
for (int i = 0; i < 5; ++i)
{
levelPlaceholderModelInstances[i].setTranslation(Vector3(ANTKEEPER_LEVEL_SPACING, 0.0f, 0.0f) * static_cast<float>(previewLevelIndices[i]));
Vector3 translation = Vector3(ANTKEEPER_LEVEL_SPACING, 0.0f, 0.0f) * static_cast<float>(previewLevelIndices[i]);
previewLevelSurfaces[i].setTranslation(translation);
previewLevelSubsurfaces[i].setTranslation(translation);
/*
previewLevelTweens[i]->stop();
if (currentPreviewIndex != i)
{
previewLevelTweens[i]->setTime(0.0f);
previewLevelTweens[i]->setDuration(0.5f);
previewLevelTweens[i]->setStartValue(camera.getTranslation());
previewLevelTweens[i]->setDeltaValue(difference);
previewLevelTweens[i]->setUpdateCallback(std::bind(&SceneObject::setTranslation, &previewLevelSubsurfaces[i], std::placeholders::_1));
previewLevelTweens[i]->start();
}
*/
}
// Set level ID label
@ -1632,7 +1637,7 @@ void Application::selectNextLevel()
// Setup camera tween
Vector3 difference = Vector3(ANTKEEPER_LEVEL_SPACING * currentLevelIndex, camera.getTranslation().y, camera.getTranslation().z) - camera.getTranslation();
cameraTranslationTween->setTime(0.0f);
cameraTranslationTween->setDuration(0.5f);
cameraTranslationTween->setDuration(1.0f);
cameraTranslationTween->setStartValue(camera.getTranslation());
cameraTranslationTween->setDeltaValue(difference);
cameraTranslationTween->setUpdateCallback(std::bind(&SceneObject::setTranslation, &camera, std::placeholders::_1));
@ -1649,7 +1654,7 @@ void Application::selectPreviousLevel()
// Setup camera tween
Vector3 difference = Vector3(ANTKEEPER_LEVEL_SPACING * currentLevelIndex, camera.getTranslation().y, camera.getTranslation().z) - camera.getTranslation();
cameraTranslationTween->setTime(0.0f);
cameraTranslationTween->setDuration(0.5f);
cameraTranslationTween->setDuration(1.0f);
cameraTranslationTween->setStartValue(camera.getTranslation());
cameraTranslationTween->setDeltaValue(difference);
cameraTranslationTween->setUpdateCallback(std::bind(&SceneObject::setTranslation, &camera, std::placeholders::_1));
@ -1659,7 +1664,13 @@ void Application::selectPreviousLevel()
void Application::enterSelectedLevel()
{
// Load level
const LevelParameterSet* levelParams = campaign.getLevelParams(currentWorldIndex, currentLevelIndex);
currentLevel->load(*levelParams);
currentLevel->terrain.getSurfaceModel()->getGroup(0)->material = materialLoader->load("data/materials/debug-terrain-surface.mtl");
// Change state
changeState(playState);
}
/*

+ 9
- 2
src/application.hpp View File

@ -92,6 +92,10 @@ public:
void selectMenuItem(std::size_t index);
void activateMenuItem(std::size_t index);
void selectWorld(std::size_t index);
void selectNextWorld();
void selectPreviousWorld();
void selectLevel(std::size_t index);
void selectNextLevel();
void selectPreviousLevel();
@ -160,7 +164,9 @@ public:
ModelInstance antModelInstance;
ModelInstance antHillModelInstance;
ModelInstance nestModelInstance;
ModelInstance levelPlaceholderModelInstances[5];
ModelInstance previewLevelSurfaces[5];
ModelInstance previewLevelSubsurfaces[5];
ModelInstance biomeFloorModelInstance;
// Graphics
Renderer renderer;
@ -333,6 +339,7 @@ public:
Tween<Vector4>* playButtonFadeTween;
Tween<Vector3>* cameraTranslationTween;
Tween<Vector3>* previewLevelTweens[5];
// Menus
std::size_t menuCount;
@ -351,7 +358,7 @@ public:
Model* antHillModel;
Model* nestModel;
Model* forcepsModel;
Model* levelPlaceholderModel;
Model* biomeFloorModel;
// Game variables
Biosphere biosphere;

+ 4
- 3
src/configuration.hpp.in View File

@ -27,11 +27,12 @@
#cmakedefine ANTKEEPER_DEBUG
// Terrain dimensions
const float ANTKEEPER_TERRAIN_WIDTH = 50.0f;
const float ANTKEEPER_TERRAIN_WIDTH = 100.0f;
const float ANTKEEPER_TERRAIN_BASE_HEIGHT = 35.7f;
const float ANTKEEPER_TERRAIN_DEPTH = 50.0f;
const float ANTKEEPER_TERRAIN_DEPTH = ANTKEEPER_TERRAIN_WIDTH;
const float ANTKEEPER_OCTREE_PADDING = 5.0f;
// Level selection
const float ANTKEEPER_LEVEL_SPACING = 4.5f;
const float ANTKEEPER_LEVEL_SPACING = 600.0f;
#endif // CONFIGURATION_HPP

+ 7
- 2
src/game/colony.cpp View File

@ -20,12 +20,17 @@
#include "colony.hpp"
#include "ant.hpp"
#include "pheromone.hpp"
#include "../configuration.hpp"
Colony::Colony():
antModel(nullptr)
{
antOctree = new Octree<Agent*>(5, AABB(Vector3(-26.0f), Vector3(26.0f)));
pheromoneOctree = new Octree<Pheromone*>(5, AABB(Vector3(-26.0f), Vector3(26.0f)));
Vector3 octreeMin = Vector3(-ANTKEEPER_TERRAIN_WIDTH, -ANTKEEPER_TERRAIN_BASE_HEIGHT, -ANTKEEPER_TERRAIN_DEPTH) * 0.5f - Vector3(ANTKEEPER_OCTREE_PADDING);
Vector3 octreeMax = Vector3( ANTKEEPER_TERRAIN_WIDTH, ANTKEEPER_TERRAIN_BASE_HEIGHT, ANTKEEPER_TERRAIN_DEPTH) * 0.5f + Vector3(ANTKEEPER_OCTREE_PADDING);
AABB octreeBounds(octreeMin, octreeMax);
antOctree = new Octree<Agent*>(5, octreeBounds);
pheromoneOctree = new Octree<Pheromone*>(5, octreeBounds);
}
Colony::~Colony()

+ 28
- 10
src/states/level-select-state.cpp View File

@ -20,6 +20,7 @@
#include "level-select-state.hpp"
#include "main-menu-state.hpp"
#include "../application.hpp"
#include "../configuration.hpp"
LevelSelectState::LevelSelectState(Application* application):
ApplicationState(application)
@ -33,16 +34,26 @@ void LevelSelectState::enter()
levelRotation = 0.0f;
for (int i = 0; i < 5; ++i)
{
ModelInstance* instance = &application->levelPlaceholderModelInstances[i];
instance->setRotation(glm::angleAxis(levelRotation, Vector3(0, 1, 0)));
application->defaultLayer->addObject(instance);
ModelInstance* surfaceInstance = &application->previewLevelSurfaces[i];
ModelInstance* subsurfaceInstance = &application->previewLevelSubsurfaces[i];
Quaternion rotation = glm::angleAxis(levelRotation, Vector3(0, 1, 0));
surfaceInstance->setRotation(rotation);
subsurfaceInstance->setRotation(rotation);
application->defaultLayer->addObject(surfaceInstance);
application->defaultLayer->addObject(subsurfaceInstance);
}
application->defaultLayer->addObject(&application->biomeFloorModelInstance);
//application->biomeFloorModelInstance.setTranslation(Vector3(0.0f, -ANTKEEPER_TERRAIN_BASE_HEIGHT, 0.0f));
application->levelIDLabel->setVisible(true);
application->levelNameLabel->setVisible(true);
application->selectWorld(0);
application->selectLevel(0);
application->camera.lookAt(Vector3(0, 8, 12), Vector3(0, 1, 0), Vector3(0, 1, 0));
application->camera.lookAt(Vector3(0, 150, 200), Vector3(0, 0, 0), Vector3(0, 1, 0));
}
void LevelSelectState::execute()
@ -59,11 +70,11 @@ void LevelSelectState::execute()
if (application->menuDown.isTriggered() && !application->menuDown.wasTriggered())
{
application->selectPreviousWorld();
}
else if (application->menuUp.isTriggered() && !application->menuUp.wasTriggered())
{
application->selectNextWorld();
}
if (application->menuSelect.isTriggered() && !application->menuSelect.wasTriggered())
@ -79,8 +90,12 @@ void LevelSelectState::execute()
levelRotation += glm::radians(5.0f) * application->dt;
for (int i = 0; i < 5; ++i)
{
ModelInstance* instance = &application->levelPlaceholderModelInstances[i];
instance->setRotation(glm::angleAxis(levelRotation, Vector3(0, 1, 0)));
ModelInstance* surfaceInstance = &application->previewLevelSurfaces[i];
ModelInstance* subsurfaceInstance = &application->previewLevelSubsurfaces[i];
Quaternion rotation = glm::angleAxis(levelRotation, Vector3(0, 1, 0));
//surfaceInstance->setRotation(rotation);
//subsurfaceInstance->setRotation(rotation);
}
}
@ -88,8 +103,11 @@ void LevelSelectState::exit()
{
for (int i = 0; i < 5; ++i)
{
ModelInstance* instance = &application->levelPlaceholderModelInstances[i];
application->defaultLayer->removeObject(instance);
ModelInstance* surfaceInstance = &application->previewLevelSurfaces[i];
ModelInstance* subsurfaceInstance = &application->previewLevelSubsurfaces[i];
application->defaultLayer->removeObject(surfaceInstance);
application->defaultLayer->removeObject(subsurfaceInstance);
}
application->levelIDLabel->setVisible(false);
application->levelNameLabel->setVisible(false);

Loading…
Cancel
Save