Skip to content

Commit

Permalink
Merge branch 'master' into AnimationSpeedDependentOnSlope
Browse files Browse the repository at this point in the history
  • Loading branch information
Laguna1989 authored Jul 7, 2023
2 parents da30211 + 5730c90 commit 63df0d5
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 41 deletions.
3 changes: 1 addition & 2 deletions impl/game_client_lib/internal_state/end_lose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <imgui.h>

void EndLose::update(StateGame& /*state*/, float /*elapsed*/) { }

void EndLose::draw(StateGame& state)
{
if (!m_imageDefeat) {
Expand Down Expand Up @@ -48,6 +49,4 @@ void EndLose::draw(StateGame& state)
}
ImGui::PopStyleColor(3);
ImGui::End();

// TODO add some particle effects
}
3 changes: 1 addition & 2 deletions impl/game_client_lib/internal_state/end_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <imgui.h>

void EndWin::update(StateGame& /*state*/, float /*elapsed*/) { }

void EndWin::draw(StateGame& state)
{
if (!m_imageVictory) {
Expand Down Expand Up @@ -48,6 +49,4 @@ void EndWin::draw(StateGame& state)
}
ImGui::PopStyleColor(3);
ImGui::End();

// TODO add some particle effects
}
3 changes: 0 additions & 3 deletions impl/game_client_lib/internal_state/place_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ void PlaceUnits::update(StateGame& state, float /*elapsed*/)
m_selectedUnitType.clear();
}

// TODO move into create function
if (!m_imageEndPlacement) {
m_imageEndPlacement = std::make_shared<jt::Sprite>("assets/images/menus/end_placement.png",
jt::Recti { 0, 0, 483, 64 }, state.getGame()->gfx().textureManager());
Expand Down Expand Up @@ -185,7 +184,6 @@ void PlaceUnits::drawUnitTooltipForOneUnit(std::shared_ptr<UnitInterface> unit,
unit->getPlayerID(), unit->getInfo().type);

for (auto& upg : upgrades) {
// TODO load icon on create, not during update
if (!upg.icon) {
upg.icon = std::make_shared<jt::Sprite>(upg.info.iconPath, jt ::Recti { 0, 0, 64, 64 },
state.getGame()->gfx().textureManager());
Expand Down Expand Up @@ -241,7 +239,6 @@ void PlaceUnits::drawUnitUpgradeWindow(

const auto canAffordUpgrade = state.getPlacementManager()->getFunds() < cost;
ImGui::BeginDisabled(canAffordUpgrade);
// TODO avoid loading icons in draw
if (!upg.icon) {
upg.icon = std::make_shared<jt::Sprite>(upg.info.iconPath,
jt ::Recti { 0, 0, 256, 256 }, state.getGame()->gfx().textureManager());
Expand Down
1 change: 0 additions & 1 deletion impl/game_client_lib/state_game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class StateGame : public jt::GameState {
std::shared_ptr<jt::ObjectGroup<Unit>> getUnits();
std::shared_ptr<jt::ObjectGroup<Critter>> getCritters();

// TODO move to InternalStateManager
void transitionWaitForPlayersToSelectStartingUnits();
void transitionWaitForSimulationResultsToPlayback();
void transitionPlaybackToPlaceUnits();
Expand Down
15 changes: 5 additions & 10 deletions impl/game_client_lib/terrain_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ constexpr auto const chunkSizeHalf = chunkSize / 2.0f;

sf::Color const colorStone { 100, 100, 100 };

// clang-format off
sf::Color const colorMap[] {
// clang-format off
// dirt layer
{ 89, 60, 47 },
// grassy layer
Expand All @@ -23,8 +23,8 @@ sf::Color const colorMap[] {
{ 80, 80, 80 }, { 120, 120, 120 },
// mountain layer
{ 160, 160, 160 }, { 200, 200, 200 }
// clang-format on
};
// clang-format on

float getTerrainHeight(int y, float height)
{
Expand Down Expand Up @@ -107,10 +107,8 @@ void TerrainRenderer::doCreate()
m->sprite->setPosition(jt::Vector2f(0.0f, 0.0f));

// draw terrain grid texture
bool result = m->textureGrid.create(static_cast<unsigned int>(GP::GetScreenSize().x),
(void)m->textureGrid.create(static_cast<unsigned int>(GP::GetScreenSize().x),
static_cast<unsigned int>(GP::GetScreenSize().y));
// TODO check error
(void)result;
m->textureGrid.clear(sf::Color::Transparent);
drawTerrainGrid(m->textureGrid);
m->textureGrid.display();
Expand Down Expand Up @@ -219,12 +217,9 @@ void TerrainRenderer::updateFromTerrain()
auto texture = std::make_unique<sf::RenderTexture>();

// draw terrain texture from vertices
bool result { texture->create(static_cast<unsigned int>(GP::GetScreenSize().x),
static_cast<unsigned int>(GP::GetScreenSize().y)) };
// TODO check error
(void)result;
(void)texture->create(static_cast<unsigned int>(GP::GetScreenSize().x),
static_cast<unsigned int>(GP::GetScreenSize().y));
texture->clear(sf::Color::Black);
// texture.setSmooth(true);
for (auto const& e : grid) {
texture->draw(e);
}
Expand Down
10 changes: 1 addition & 9 deletions impl/game_client_lib/unit_placement/placement_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ void PlacementManager::doDraw() const
if (m_unitInfo) {
auto unlockedTypes = m_unlockedTypes;
auto allTypes = m_unitInfo->getTypes();
std::sort(unlockedTypes.begin(), unlockedTypes.end());
std::sort(allTypes.begin(), allTypes.end());
std::vector<std::string> purchaseTypes;
std::set_difference(allTypes.begin(), allTypes.end(), unlockedTypes.begin(),
Expand Down Expand Up @@ -244,11 +243,8 @@ void PlacementManager::placeUnit()
auto fieldPos = m_world->getMappedFieldPosition(
getGame()->input().mouse()->getMousePositionWorld(), posX, posY);
if (!isValidField(fieldPos, posX, posY)) {
// TODO Show some visual representation or play a sound that placing a unit here is
// not
getGame()->logger().info(
"tried to place unit in invalid position", { "PlacementManager" });
// possible.
return;
}

Expand Down Expand Up @@ -322,11 +318,7 @@ void PlacementManager::addFunds(int funds) { m_availableFunds += funds; }

int PlacementManager::getFunds() const { return m_availableFunds; }

void PlacementManager::unlockType(const std::string& type) const
{
// TODO check for duplicates
m_unlockedTypes.push_back(type);
}
void PlacementManager::unlockType(const std::string& type) const { m_unlockedTypes.insert(type); }

void PlacementManager::flashForUpgrade(std::string const& unitType)
{
Expand Down
3 changes: 2 additions & 1 deletion impl/game_client_lib/unit_placement/placement_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <array>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <vector>

Expand Down Expand Up @@ -74,7 +75,7 @@ class PlacementManager : public jt::GameObject {
std::shared_ptr<jt::SoundInterface> m_sfxPlaceUnit { nullptr };
std::shared_ptr<jt::SoundInterface> m_sfxBuyUpgrade { nullptr };

mutable std::vector<std::string> m_unlockedTypes {};
mutable std::set<std::string> m_unlockedTypes {};

mutable std::shared_ptr<UpgradeManager> m_upgrades { nullptr };

Expand Down
3 changes: 0 additions & 3 deletions impl/game_server_lib/game_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void GameServer::update(float elapsed)
auto botDataCopy = m_botData;
lock.unlock();

// TODO only pass in playerID of bot
performAI(botDataCopy);

startRoundSimulation();
Expand All @@ -64,7 +63,6 @@ void GameServer::update(float elapsed)
}
}

// TODO move out into separate AI class
void GameServer::performAI(std::map<int, PlayerInfo>& botDataCopy) const
{
if (!botDataCopy.empty()) {
Expand Down Expand Up @@ -146,7 +144,6 @@ void GameServer::handleMessage(
}

lock.unlock();
// TODO avoid double/triple parsing
if (m.type == MessageType::InitialPing) {
handleMessageInitialPing(messageContent, endpoint);
} else if (m.type == MessageType::AddBot) {
Expand Down
3 changes: 1 addition & 2 deletions impl/game_server_lib/game_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ class GameServer {
CompressorInterface& m_compressor;
ServerNetworkConnection m_connection;

// TODO allow spectators?
std::mutex m_mutex;
// TODO create a separate class to encapsulate common behavior

std::map<int, PlayerInfo> m_playerData;
std::map<int, PlayerInfo> m_botData;
bool m_matchHasStarted { false };
Expand Down
2 changes: 0 additions & 2 deletions impl/game_server_lib/game_simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,6 @@ void GameSimulation::handleScheduledAttacks(float timePerUpdate)
std::weak_ptr<SimulationObjectInterface> GameSimulation::getClosestTargetTo(
const jt::Vector2f& pos, int playerId)
{
// TODO using a SpatialObjectGrid might be useful here?

float minDistance = 999999999.9f;
std::shared_ptr<SimulationObjectInterface> target { nullptr };
for (auto const& obj : m_simulationObjects) {
Expand Down
1 change: 0 additions & 1 deletion impl/game_server_lib/units/ai/ai_cannon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void AiCannon::update(float elapsed, ServerUnit* unit, WorldInfoInterface& world
auto const dist = jt::MathHelper::length(dir);
jt::MathHelper::normalizeMe(dir);

// TODO account for actual height difference to target
auto const attackRange = unit->getUnitInfoFull().ai.range * terrainChunkSizeInPixel
+ world.getTerrainMappedFieldHeight(unit->getPosition()) * 10.0f;
if (dist > attackRange) {
Expand Down
1 change: 0 additions & 1 deletion impl/game_server_lib/units/ai/ai_ranged_combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void AiRangedCombat::update(float elapsed, ServerUnit* unit, WorldInfoInterface&
auto const dist = jt::MathHelper::length(dir);
jt::MathHelper::normalizeMe(dir);

// TODO account for actual height difference to target
auto const attackRange = unit->getUnitInfoFull().ai.range * terrainChunkSizeInPixel
+ world.getTerrainMappedFieldHeight(unit->getPosition()) * 10.0f;
if (dist > attackRange) {
Expand Down
1 change: 0 additions & 1 deletion impl/jamtemplate/common/audio/fades/sound_fade_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace jt {

// TODO This class should implement an interface.
class SoundFadeManager : public jt::SoundFadeManagerInterface {
public:
void volumeFade(std::weak_ptr<SoundInterface> sound, float durationInSeconds, float startVolume,
Expand Down
5 changes: 2 additions & 3 deletions impl/jamtemplate/common/performance_measurement.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "performance_measurement.hpp"
#include <functional>

float jt::getDurationInSecondsSince(std::chrono::time_point<std::chrono::system_clock> const& since)
{
Expand All @@ -7,11 +8,9 @@ float jt::getDurationInSecondsSince(std::chrono::time_point<std::chrono::system_
/ 1000.0f;
}

/// TODO change to template F&& f
float jt::measureTime(std::function<void(void)> const& f)
{
auto const start = std::chrono::system_clock::now();
/// TODO use invoke
f();
std::invoke(f);
return jt::getDurationInSecondsSince(start);
}

0 comments on commit 63df0d5

Please sign in to comment.