diff --git a/3dzavr b/3dzavr index c671537..a6c37ff 160000 --- a/3dzavr +++ b/3dzavr @@ -1 +1 @@ -Subproject commit c671537f8d0c7047b481e2c4766fa6ed5de9d0b6 +Subproject commit a6c37ff6cfb910ed49d764ccc570761b530cfeb3 diff --git a/CMakeLists.txt b/CMakeLists.txt index 00c27d8..0091a24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.17) project(shooter) set(CMAKE_CXX_STANDARD 20) - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") add_executable(${CMAKE_PROJECT_NAME} @@ -30,122 +29,8 @@ add_executable(${CMAKE_PROJECT_NAME} network/ShooterMsgType.cpp network/Chat.cpp network/Chat.h - # 3d engine: - 3dzavr/engine/Consts.h - 3dzavr/engine/math/Vec4D.h - 3dzavr/engine/math/Vec4D.cpp - 3dzavr/engine/math/Vec3D.cpp - 3dzavr/engine/math/Vec3D.h - 3dzavr/engine/math/Vec2D.cpp - 3dzavr/engine/math/Vec2D.h - 3dzavr/engine/math/Matrix4x4.h - 3dzavr/engine/math/Matrix4x4.cpp - 3dzavr/engine/Triangle.h - 3dzavr/engine/Triangle.cpp - 3dzavr/engine/math/Plane.h - 3dzavr/engine/math/Plane.cpp - 3dzavr/engine/Mesh.h - 3dzavr/engine/Mesh.cpp - 3dzavr/engine/utils/Log.h - 3dzavr/engine/utils/Log.cpp - 3dzavr/engine/utils/Time.h - 3dzavr/engine/utils/Time.cpp - 3dzavr/engine/utils/Timer.cpp - 3dzavr/engine/utils/Timer.h - 3dzavr/engine/utils/ResourceManager.h - 3dzavr/engine/utils/ResourceManager.cpp - 3dzavr/engine/World.h - 3dzavr/engine/World.cpp - 3dzavr/engine/Camera.h - 3dzavr/engine/Camera.cpp - 3dzavr/engine/io/Screen.h - 3dzavr/engine/io/Screen.cpp - 3dzavr/engine/Engine.h - 3dzavr/engine/Engine.cpp - 3dzavr/engine/io/Keyboard.cpp - 3dzavr/engine/io/Keyboard.h - 3dzavr/engine/io/Mouse.cpp - 3dzavr/engine/io/Mouse.h - 3dzavr/engine/io/SoundController.cpp - 3dzavr/engine/io/SoundController.h - 3dzavr/engine/utils/ObjectController.cpp - 3dzavr/engine/utils/ObjectController.h - 3dzavr/engine/animation/Animation.h - 3dzavr/engine/animation/Timeline.cpp - 3dzavr/engine/animation/Timeline.h - 3dzavr/engine/animation/Interpolation.h - 3dzavr/engine/animation/Animation.cpp - 3dzavr/engine/animation/ATranslate.h - 3dzavr/engine/animation/AScale.h - 3dzavr/engine/animation/ARotate.h - 3dzavr/engine/animation/AWait.h - 3dzavr/engine/animation/AFunction.h - 3dzavr/engine/animation/AAttractToPoint.h - 3dzavr/engine/animation/ARotateRelativePoint.h - 3dzavr/engine/animation/ARotateLeft.h - 3dzavr/engine/animation/Interpolation.cpp - 3dzavr/engine/animation/Animations.h - 3dzavr/engine/animation/AShowCreation.h - 3dzavr/engine/animation/AShowUncreation.h - 3dzavr/engine/animation/ARotateLeftUpLookAt.h - 3dzavr/engine/animation/ADecompose.h - 3dzavr/engine/physics/RigidBody.cpp - 3dzavr/engine/physics/RigidBody.h - 3dzavr/engine/physics/Simplex.h - 3dzavr/engine/physics/HitBox.cpp - 3dzavr/engine/physics/HitBox.h - 3dzavr/engine/Object.cpp - 3dzavr/engine/Object.h - 3dzavr/engine/gui/Button.cpp - 3dzavr/engine/gui/Button.h - 3dzavr/engine/gui/Window.cpp - 3dzavr/engine/gui/Window.h - 3dzavr/engine/network/ClientUDP.cpp - 3dzavr/engine/network/ClientUDP.h - 3dzavr/engine/network/MsgType.cpp - 3dzavr/engine/network/MsgType.h - 3dzavr/engine/network/ReliableMsg.cpp - 3dzavr/engine/network/ReliableMsg.h - 3dzavr/engine/network/ServerUDP.cpp - 3dzavr/engine/network/ServerUDP.h - 3dzavr/engine/network/UDPConnection.cpp - 3dzavr/engine/network/UDPConnection.h - 3dzavr/engine/network/UDPSocket.cpp - 3dzavr/engine/network/UDPSocket.h - 3dzavr/engine/utils/EventHandler.cpp - 3dzavr/engine/utils/EventHandler.h) + ) -if(APPLE OR UNIX) - include_directories(/usr/local/include) -else() - set(SFML_DIR "C:/Libraries/SFML/lib/cmake/SFML") - set(SFML_STATIC_LIBRARIES TRUE) -endif() - -find_package(SFML 2.5.1 COMPONENTS graphics audio REQUIRED) - -if (SFML_FOUND) - include_directories(${SFML_INCLUDE_DIR}) -endif() - -target_link_libraries(${CMAKE_PROJECT_NAME} sfml-audio sfml-network sfml-graphics sfml-window sfml-system) - -# OpenGL part -if (APPLE) - set(GLEW_H /usr/local/Cellar/glew/2.1.0/include/GL) - set(GLFW_H /usr/local/Cellar/glfw/3.2.1/include/GLFW) - include_directories(${GLEW_H} ${GLFW_H}) - - set(GLEW_LINK /usr/local/Cellar/glew/2.1.0/lib/libGLEW.2.1.dylib) - set(GLFW_LINK /usr/local/Cellar/glfw/3.2.1/lib/libglfw.3.dylib) - link_libraries(${OPENGL} ${GLEW_LINK} ${GLFW_LINK}) - - target_link_libraries(${CMAKE_PROJECT_NAME} "-framework OpenGL") - target_link_libraries(${CMAKE_PROJECT_NAME} "-framework GLUT") -elseif(UNIX) - find_package(OpenGL REQUIRED) - find_package(GLUT REQUIRED) - - target_link_libraries(${CMAKE_PROJECT_NAME} ${OPENGL_LIBRARIES}) - target_link_libraries(${CMAKE_PROJECT_NAME} ${GLUT_LIBRARY}) -endif() +# include 3dzavr engine into our project +add_subdirectory(3dzavr/engine) +target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC 3DZAVR) diff --git a/Shooter.cpp b/Shooter.cpp index 469c432..c0c5320 100644 --- a/Shooter.cpp +++ b/Shooter.cpp @@ -2,17 +2,17 @@ // Created by Иван Ильин on 22.09.2021. // -#include "Shooter.h" -#include -#include -#include "3dzavr/engine/animation/Animations.h" -#include "ShooterConsts.h" -#include "3dzavr/engine/io/SoundController.h" -#include "network/Chat.h" -#include "3dzavr/engine/utils/EventHandler.h" #include +#include + +#include +#include +#include + +#include "Shooter.h" +#include "ShooterConsts.h" +#include "network/Chat.h" -using namespace std; // Read server/client settings and start both. // If client doesn't connect to the localhost - server doesn't start. void Shooter::initNetwork() { @@ -106,9 +106,9 @@ void Shooter::start() { [this](const std::string &weaponName, sf::Uint16 enemyId) { changeEnemyWeapon(weaponName, enemyId); }); - EventHandler::listen( + EventHandler::listen( Event("add_bonus"), - [this](const string &bonusName, const Vec3D &position) { addBonus(bonusName, position); } + [this](const std::string &bonusName, const Vec3D &position) { addBonus(bonusName, position); } ); EventHandler::listen( Event("remove_bonus"), @@ -205,7 +205,7 @@ void Shooter::update() { screen->setTitle(ShooterConsts::PROJECT_NAME); if (isTypingMessage) { - string symbols = screen->getInputSymbols(); + std::string symbols = screen->getInputSymbols(); for (char s : symbols) { if (s == (char)8) { //backspace message = message.substr(0, message.size() - 1); @@ -239,7 +239,7 @@ void Shooter::update() { void Shooter::drawChat() { sf::Color chatColor = isTypingMessage? sf::Color(50, 50, 50, 255) : sf::Color(50, 50, 50, chat->update(Time::deltaTime())); - string chatText = isTypingMessage ? chat->getChat() : chat->getChatPreview(); + std::string chatText = isTypingMessage ? chat->getChat() : chat->getChatPreview(); screen->drawText(chatText, Vec2D{ 10, (double)screen->height()*0.25 }, 20, chatColor); @@ -276,7 +276,7 @@ void Shooter::drawStatsTable() { screen->drawText(client->lastEvent(), Vec2D{10, 10}, 25, sf::Color(0, 0, 0, 100)); - vector> + std::vector> allPlayers; allPlayers.push_back(player); for (auto&[playerId, player] : client->players()) @@ -406,7 +406,7 @@ void Shooter::removeFireTrace(const ObjectNameTag &traceName) { world->removeBody(traceName); } -void Shooter::addBonus(const string &bonusName, const Vec3D &position) { +void Shooter::addBonus(const std::string &bonusName, const Vec3D &position) { std::string name = bonusName.substr(6, bonusName.size() - 3 - 5); diff --git a/Shooter.h b/Shooter.h index 6ff4c27..a26c3bc 100644 --- a/Shooter.h +++ b/Shooter.h @@ -5,16 +5,15 @@ #ifndef SHOOTER_SHOOTER_H #define SHOOTER_SHOOTER_H -#include "3dzavr/engine/Engine.h" +#include +#include + #include "player/Player.h" #include "player/PlayerController.h" #include "player/PlayerController.h" -#include "3dzavr/engine/gui/Window.h" - #include "network/ShooterClient.h" #include "network/ShooterServer.h" - class Shooter final : public Engine { private: std::shared_ptr player = std::make_shared(ObjectNameTag("Player"), @@ -28,7 +27,7 @@ private: std::shared_ptr client = std::make_shared(player); std::shared_ptr chat = std::make_shared(); bool isTypingMessage = false; - string message = ""; + std::string message; bool inGame = false; int fireTraces = 0; diff --git a/ShooterConsts.h b/ShooterConsts.h index d25c5fc..ef217db 100644 --- a/ShooterConsts.h +++ b/ShooterConsts.h @@ -6,6 +6,8 @@ #define SHOOTER_SHOOTERCONSTS_H namespace ShooterConsts { + + // Numeric constants const double GRAVITY = 35; const double HEALTH_MAX = 100; const double ABILITY_MAX = 10; @@ -17,6 +19,7 @@ namespace ShooterConsts { const double BONUS_RECHARGE_TIME = 30; const int MAX_MESSAGE_LENGTH = 70; + // String constants const std::string PLAYER_NAME = "Player"; const std::string PROJECT_NAME = "Shooter"; diff --git a/network/Chat.cpp b/network/Chat.cpp index 817f651..9abacfc 100644 --- a/network/Chat.cpp +++ b/network/Chat.cpp @@ -1,8 +1,8 @@ -#include "Chat.h" #include -#include -void ChatManager::addNewMessage(std::string author, std::string message) { +#include "Chat.h" + +void ChatManager::addNewMessage(const std::string& author, const std::string& message) { hide = 7.0; messages.push_back(message); authors.push_back(author); @@ -17,16 +17,18 @@ int ChatManager::update(double delta) { } std::string ChatManager::getChat() { - updateChat(); return chatStr; + updateChat(); + return chatStr; } std::string ChatManager::getChatPreview() { - updateChat(); return chatStrPrev; + updateChat(); + return chatStrPrev; } void ChatManager::updateChat() { if (isChatUpdate) { isChatUpdate = false; - int size = messages.size(); + size_t size = messages.size(); chatStr = ""; chatStrPrev = ""; for (int messageIndex = size - 1; messageIndex >= 0; messageIndex--) diff --git a/network/Chat.h b/network/Chat.h index 9a568f5..abe1a17 100644 --- a/network/Chat.h +++ b/network/Chat.h @@ -1,23 +1,28 @@ -//#ifndef SHOOTER_SHOOTERSERVER_H -#ifndef CHAT_H -#define CHAT_H +#ifndef SHOOTER_CHAT_H +#define SHOOTER_CHAT_H + #include #include -using namespace std; class ChatManager final { private: std::vector messages; std::vector authors; + bool isChatUpdate = true; - std::string chatStr = ""; - std::string chatStrPrev = ""; + std::string chatStr; + std::string chatStrPrev; + double hide = 0.0; - void updateChat(); + + void updateChat(); public: - void addNewMessage(std::string author, std::string message); + void addNewMessage(const std::string& author, const std::string& message); int update(double delta); + std::string getChat(); std::string getChatPreview(); }; -#endif \ No newline at end of file + + +#endif \ No newline at end of file diff --git a/network/ShooterClient.cpp b/network/ShooterClient.cpp index e39e666..84c6889 100644 --- a/network/ShooterClient.cpp +++ b/network/ShooterClient.cpp @@ -2,16 +2,19 @@ // Created by Иван Ильин on 25.05.2021. // -#include "ShooterClient.h" - -#include #include #include -#include "../3dzavr/engine/utils/Log.h" -#include "../3dzavr/engine/animation/Timeline.h" + +#include + +#include +#include +#include +#include + +#include "ShooterClient.h" #include "ShooterMsgType.h" -#include "../3dzavr/engine/animation/Animations.h" -#include "../3dzavr/engine/utils/EventHandler.h" + ShooterClient::ShooterClient(std::shared_ptr player) : _player(player) { @@ -143,7 +146,7 @@ void ShooterClient::processDisconnect(sf::Uint16 targetId) { } } -void ShooterClient::sendMessage(string message){ +void ShooterClient::sendMessage(const std::string& message){ if (message.length() == 0) return; @@ -153,7 +156,7 @@ void ShooterClient::sendMessage(string message){ _socket.send(packet, _socket.serverId()); } -void ShooterClient::sendChatMessage(string message, string name) { +void ShooterClient::sendChatMessage(const std::string& message, const std::string& name) { chatManager->addNewMessage(name, message); } @@ -164,7 +167,7 @@ void ShooterClient::processCustomPacket(sf::Packet &packet) { ShooterMsgType type; packet >> type; - string name, message; + std::string name, message; switch (type) { case ShooterMsgType::Kill: @@ -238,14 +241,14 @@ void ShooterClient::processCustomPacket(sf::Packet &packet) { break; case ShooterMsgType::InitBonuses: while (packet >> tmp >> dbuff[0] >> dbuff[1] >> dbuff[2]) { - EventHandler::call( + EventHandler::call( Event("add_bonus"), tmp, Vec3D(dbuff[0], dbuff[1], dbuff[2])); } break; case ShooterMsgType::AddBonus: packet >> tmp >> dbuff[0] >> dbuff[1] >> dbuff[2]; - EventHandler::call( + EventHandler::call( Event("add_bonus"), tmp, Vec3D(dbuff[0], dbuff[1], dbuff[2])); break; diff --git a/network/ShooterClient.h b/network/ShooterClient.h index 0560a02..59fe3df 100644 --- a/network/ShooterClient.h +++ b/network/ShooterClient.h @@ -5,9 +5,11 @@ #ifndef SHOOTER_SHOOTERCLIENT_H #define SHOOTER_SHOOTERCLIENT_H -#include "../3dzavr/engine/network/ClientUDP.h" -#include "../player/Player.h" #include + +#include + +#include "../player/Player.h" #include "Chat.h" class ShooterClient final : public ClientUDP { @@ -30,9 +32,9 @@ private: public: explicit ShooterClient(std::shared_ptr player); - void sendMessage(std::string message); + void sendMessage(const std::string& message); - void sendChatMessage(std::string message, std::string name); + void sendChatMessage(const std::string& message, const std::string& name); void updatePacket() override; diff --git a/network/ShooterServer.cpp b/network/ShooterServer.cpp index 350c692..4791c5b 100644 --- a/network/ShooterServer.cpp +++ b/network/ShooterServer.cpp @@ -2,8 +2,9 @@ // Created by Иван Ильин on 25.05.2021. // +#include + #include "ShooterServer.h" -#include "../3dzavr/engine/utils/Log.h" #include "ShooterMsgType.h" void ShooterServer::broadcast() { diff --git a/network/ShooterServer.h b/network/ShooterServer.h index b1e5e86..a619d47 100644 --- a/network/ShooterServer.h +++ b/network/ShooterServer.h @@ -5,7 +5,8 @@ #ifndef SHOOTER_SHOOTERSERVER_H #define SHOOTER_SHOOTERSERVER_H -#include "../3dzavr/engine/network/ServerUDP.h" +#include + #include "../player/Player.h" struct BonusInfo final { diff --git a/player/Player.cpp b/player/Player.cpp index 30e1f98..8c5f736 100644 --- a/player/Player.cpp +++ b/player/Player.cpp @@ -2,14 +2,14 @@ // Created by Иван Ильин on 14.03.2021. // -#include "Player.h" - #include -#include "../3dzavr/engine/io/Screen.h" -#include "../3dzavr/engine/utils/Log.h" -#include "../3dzavr/engine/animation/Animations.h" -#include "../3dzavr/engine/utils/EventHandler.h" +#include +#include +#include +#include + +#include "Player.h" Player::Player(ObjectNameTag name, const std::string &filename, const Vec3D &scale) : RigidBody(std::move(name), filename, scale) { setAcceleration(Vec3D{0, -ShooterConsts::GRAVITY, 0}); diff --git a/player/Player.h b/player/Player.h index ffc74c8..923e113 100644 --- a/player/Player.h +++ b/player/Player.h @@ -5,11 +5,14 @@ #ifndef SHOOTER_PLAYER_H #define SHOOTER_PLAYER_H -#include #include -#include "../3dzavr/engine/utils/ResourceManager.h" -#include "../3dzavr/engine/Camera.h" -#include "../3dzavr/engine/World.h" + +#include + +#include +#include +#include + #include "../weapon/Ak47.h" #include "../weapon/Shotgun.h" #include "../weapon/Gun.h" diff --git a/player/PlayerController.cpp b/player/PlayerController.cpp index db8daf5..5676c2c 100644 --- a/player/PlayerController.cpp +++ b/player/PlayerController.cpp @@ -4,9 +4,10 @@ #include +#include +#include + #include "PlayerController.h" -#include "../3dzavr/engine/utils/Log.h" -#include "../3dzavr/engine/animation/Animations.h" PlayerController::PlayerController(std::shared_ptr player, std::shared_ptr keyboard, diff --git a/player/PlayerController.h b/player/PlayerController.h index 5d08915..1edbe20 100644 --- a/player/PlayerController.h +++ b/player/PlayerController.h @@ -5,9 +5,10 @@ #ifndef SHOOTER_PLAYERCONTROLLER_H #define SHOOTER_PLAYERCONTROLLER_H +#include +#include + #include "Player.h" -#include "../3dzavr/engine/io/Keyboard.h" -#include "../3dzavr/engine/io/Mouse.h" class PlayerController final { private: diff --git a/weapon/Gun.h b/weapon/Gun.h index 328c9f6..ce2ed92 100644 --- a/weapon/Gun.h +++ b/weapon/Gun.h @@ -6,7 +6,6 @@ #define SHOOTER_GUN_H #include "Weapon.h" -#include "../3dzavr/engine/utils/ResourceManager.h" #include "../ShooterConsts.h" class Gun final : public Weapon { diff --git a/weapon/Rifle.h b/weapon/Rifle.h index bd6efef..00db26f 100644 --- a/weapon/Rifle.h +++ b/weapon/Rifle.h @@ -6,7 +6,6 @@ #define SHOOTER_RIFLE_H #include "Weapon.h" -#include "../3dzavr/engine/utils/ResourceManager.h" #include "../ShooterConsts.h" class Rifle final : public Weapon { diff --git a/weapon/Shotgun.h b/weapon/Shotgun.h index 0bb7a4f..8a5eaa3 100644 --- a/weapon/Shotgun.h +++ b/weapon/Shotgun.h @@ -6,7 +6,6 @@ #define SHOOTER_SHOTGUN_H #include "Weapon.h" -#include "../3dzavr/engine/utils/ResourceManager.h" #include "../ShooterConsts.h" class Shotgun final : public Weapon { diff --git a/weapon/Weapon.cpp b/weapon/Weapon.cpp index 7e73fc3..1452c71 100644 --- a/weapon/Weapon.cpp +++ b/weapon/Weapon.cpp @@ -2,11 +2,11 @@ // Created by Иван Ильин on 01.06.2021. // +#include +#include + #include "Weapon.h" -#include "../3dzavr/engine/utils/ResourceManager.h" -#include "../3dzavr/engine/utils/Log.h" #include "../ShooterConsts.h" -#include "../3dzavr/engine/utils/EventHandler.h" using namespace std; diff --git a/weapon/Weapon.h b/weapon/Weapon.h index bd21883..50a2b93 100644 --- a/weapon/Weapon.h +++ b/weapon/Weapon.h @@ -5,15 +5,16 @@ #ifndef SHOOTER_WEAPON_H #define SHOOTER_WEAPON_H - #include -#include "../3dzavr/engine/World.h" -#include "../3dzavr/engine/Camera.h" + #include -#include "../3dzavr/engine/Mesh.h" -#include "../3dzavr/engine/utils/Time.h" -#include "../3dzavr/engine/io/SoundController.h" -#include "../3dzavr/engine/Consts.h" + +#include +#include +#include +#include +#include +#include struct FireInformation final { const std::map damagedPlayers;