CMakeList refactor

master
Vectozavr 2023-08-03 01:48:04 +03:00
parent d901be2638
commit f7d34c4812
20 changed files with 104 additions and 200 deletions

2
3dzavr

@ -1 +1 @@
Subproject commit c671537f8d0c7047b481e2c4766fa6ed5de9d0b6
Subproject commit a6c37ff6cfb910ed49d764ccc570761b530cfeb3

View File

@ -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)

View File

@ -2,17 +2,17 @@
// Created by Иван Ильин on 22.09.2021.
//
#include "Shooter.h"
#include <fstream>
#include <utility>
#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 <iostream>
#include <fstream>
#include <animation/Animations.h>
#include <io/SoundController.h>
#include <utils/EventHandler.h>
#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<void(const string&, const Vec3D&)>(
EventHandler::listen<void(const std::string&, const Vec3D&)>(
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<void(const ObjectNameTag &)>(
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<shared_ptr < Player>>
std::vector<std::shared_ptr<Player>>
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);

View File

@ -5,16 +5,15 @@
#ifndef SHOOTER_SHOOTER_H
#define SHOOTER_SHOOTER_H
#include "3dzavr/engine/Engine.h"
#include <Engine.h>
#include <gui/Window.h>
#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> player = std::make_shared<Player>(ObjectNameTag("Player"),
@ -28,7 +27,7 @@ private:
std::shared_ptr<ShooterClient> client = std::make_shared<ShooterClient>(player);
std::shared_ptr<ChatManager> chat = std::make_shared<ChatManager>();
bool isTypingMessage = false;
string message = "";
std::string message;
bool inGame = false;
int fireTraces = 0;

View File

@ -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";

View File

@ -1,8 +1,8 @@
#include "Chat.h"
#include <string>
#include <iostream>
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--)

View File

@ -1,23 +1,28 @@
//#ifndef SHOOTER_SHOOTERSERVER_H
#ifndef CHAT_H
#define CHAT_H
#ifndef SHOOTER_CHAT_H
#define SHOOTER_CHAT_H
#include <vector>
#include <string>
using namespace std;
class ChatManager final {
private:
std::vector<std::string> messages;
std::vector<std::string> 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
#endif

View File

@ -2,16 +2,19 @@
// Created by Иван Ильин on 25.05.2021.
//
#include "ShooterClient.h"
#include <SFML/Network/Ftp.hpp>
#include <string>
#include <utility>
#include "../3dzavr/engine/utils/Log.h"
#include "../3dzavr/engine/animation/Timeline.h"
#include <SFML/Network/Ftp.hpp>
#include <animation/Animations.h>
#include <animation/Timeline.h>
#include <utils/EventHandler.h>
#include <utils/Log.h>
#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(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<void(const string&, const Vec3D&)>(
EventHandler::call<void(const std::string&, const Vec3D&)>(
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<void(const string&, const Vec3D&)>(
EventHandler::call<void(const std::string&, const Vec3D&)>(
Event("add_bonus"), tmp, Vec3D(dbuff[0], dbuff[1], dbuff[2]));
break;

View File

@ -5,9 +5,11 @@
#ifndef SHOOTER_SHOOTERCLIENT_H
#define SHOOTER_SHOOTERCLIENT_H
#include "../3dzavr/engine/network/ClientUDP.h"
#include "../player/Player.h"
#include <SFML/Config.hpp>
#include <network/ClientUDP.h>
#include "../player/Player.h"
#include "Chat.h"
class ShooterClient final : public ClientUDP {
@ -30,9 +32,9 @@ private:
public:
explicit ShooterClient(std::shared_ptr<Player> 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;

View File

@ -2,8 +2,9 @@
// Created by Иван Ильин on 25.05.2021.
//
#include <utils/Log.h>
#include "ShooterServer.h"
#include "../3dzavr/engine/utils/Log.h"
#include "ShooterMsgType.h"
void ShooterServer::broadcast() {

View File

@ -5,7 +5,8 @@
#ifndef SHOOTER_SHOOTERSERVER_H
#define SHOOTER_SHOOTERSERVER_H
#include "../3dzavr/engine/network/ServerUDP.h"
#include <network/ServerUDP.h>
#include "../player/Player.h"
struct BonusInfo final {

View File

@ -2,14 +2,14 @@
// Created by Иван Ильин on 14.03.2021.
//
#include "Player.h"
#include <utility>
#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 <animation/Animations.h>
#include <utils/EventHandler.h>
#include <utils/Log.h>
#include <io/Screen.h>
#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});

View File

@ -5,11 +5,14 @@
#ifndef SHOOTER_PLAYER_H
#define SHOOTER_PLAYER_H
#include <SFML/Audio/Sound.hpp>
#include <utility>
#include "../3dzavr/engine/utils/ResourceManager.h"
#include "../3dzavr/engine/Camera.h"
#include "../3dzavr/engine/World.h"
#include <SFML/Audio/Sound.hpp>
#include <utils/ResourceManager.h>
#include <Camera.h>
#include <World.h>
#include "../weapon/Ak47.h"
#include "../weapon/Shotgun.h"
#include "../weapon/Gun.h"

View File

@ -4,9 +4,10 @@
#include <cmath>
#include <animation/Animations.h>
#include <utils/Log.h>
#include "PlayerController.h"
#include "../3dzavr/engine/utils/Log.h"
#include "../3dzavr/engine/animation/Animations.h"
PlayerController::PlayerController(std::shared_ptr<Player> player,
std::shared_ptr<Keyboard> keyboard,

View File

@ -5,9 +5,10 @@
#ifndef SHOOTER_PLAYERCONTROLLER_H
#define SHOOTER_PLAYERCONTROLLER_H
#include <io/Keyboard.h>
#include <io/Mouse.h>
#include "Player.h"
#include "../3dzavr/engine/io/Keyboard.h"
#include "../3dzavr/engine/io/Mouse.h"
class PlayerController final {
private:

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -2,11 +2,11 @@
// Created by Иван Ильин on 01.06.2021.
//
#include <utils/EventHandler.h>
#include <utils/Log.h>
#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;

View File

@ -5,15 +5,16 @@
#ifndef SHOOTER_WEAPON_H
#define SHOOTER_WEAPON_H
#include <string>
#include "../3dzavr/engine/World.h"
#include "../3dzavr/engine/Camera.h"
#include <SFML/Audio/Sound.hpp>
#include "../3dzavr/engine/Mesh.h"
#include "../3dzavr/engine/utils/Time.h"
#include "../3dzavr/engine/io/SoundController.h"
#include "../3dzavr/engine/Consts.h"
#include <io/SoundController.h>
#include <geometry/Mesh.h>
#include <utils/Time.h>
#include <Camera.h>
#include <Consts.h>
#include <World.h>
struct FireInformation final {
const std::map<ObjectNameTag, double> damagedPlayers;