Huge refactoring v3

master
Vectozavr 2021-10-29 22:41:07 +07:00
parent 005869bc87
commit 61427ff2fd
3 changed files with 16 additions and 21 deletions

View File

@ -77,14 +77,12 @@ void Shooter::start() {
world->loadMap(ShooterConsts::MAP_OBJ, Vec3D{5, 5, 5});
player = std::make_shared<Player>(ObjectNameTag("Player"));
player->scale(Vec3D(3, 1, 3));
playerController = std::make_shared<PlayerController>(player, keyboard, mouse);
// TODO: encapsulate call backs inside Player
player->setAddTraceCallBack([this](const Vec3D& from, const Vec3D& to){ client->addTrace(from, to); addFireTrace(from, to); });
player->setDamagePlayerCallBack([this] (sf::Uint16 targetId, double damage) { client->damagePlayer(targetId, damage); });
player->setRayCastFunction([this](const Vec3D& from, const Vec3D& to) { return world->rayCast(from, to, "weapon Player"); });
player->setRayCastFunction([this](const Vec3D& from, const Vec3D& to) { return world->rayCast(from, to, "Player Weapon"); });
player->setTakeBonusCallBack([this] (const string& bonusName) { client->takeBonus(bonusName); });
player->setAddWeaponCallBack([this](std::shared_ptr<Weapon> weapon){ addWeapon(std::move(weapon)); });
player->setRemoveWeaponCallBack([this](std::shared_ptr<Weapon> weapon){ removeWeapon(std::move(weapon)); });
@ -97,9 +95,6 @@ void Shooter::start() {
world->addBody(player);
player->translate(Vec3D{0, 10, 0});
client = std::make_shared<ShooterClient>(player);
server = std::make_shared<ShooterServer>();
// connecting to the server
InitNetwork();
// Waiting for connect and updating server if it's same window

View File

@ -17,15 +17,13 @@
class Shooter final : public Engine {
private:
std::shared_ptr<Player> player;
std::shared_ptr<PlayerController> playerController;
sf::Sound backgroundNoise;
std::shared_ptr<Player> player = std::make_shared<Player>(ObjectNameTag("Player"));;
std::shared_ptr<PlayerController> playerController = std::make_shared<PlayerController>(player, keyboard, mouse);
Window mainMenu;
std::shared_ptr<ShooterServer> server;
std::shared_ptr<ShooterClient> client;
std::shared_ptr<ShooterServer> server = std::make_shared<ShooterServer>();
std::shared_ptr<ShooterClient> client = std::make_shared<ShooterClient>(player);
bool inGame = false;

View File

@ -24,10 +24,12 @@ void World::loadBody(const ObjectNameTag& tag, const string &filename, const Vec
IntersectionInformation World::rayCast(const Vec3D& from, const Vec3D& to, const std::string& skipTags) {
// make vector of tags, that we are going to escape
vector <string> tagsToSkip;
vector <std::string> tagsToSkip;
stringstream s(skipTags);
std::string t;
while (s >> t) tagsToSkip.push_back(t);
while (s >> t) {
tagsToSkip.push_back(t);
}
bool intersected = false;
Vec3D point{};
@ -38,13 +40,13 @@ IntersectionInformation World::rayCast(const Vec3D& from, const Vec3D& to, const
for(auto& [name, body] : _objects) {
// TODO: check this stuff:
//for (auto& escapeTag : tagsToSkip)
// if(name.str().find(escapeTag) != std::string::npos)
// continue;
if(name.str().find("Player") != std::string::npos || name.str().find("weapon") != std::string::npos) {
bool escapeThisBody = false;
for (auto& escapeTag : tagsToSkip) {
if (name.str().find(escapeTag) != std::string::npos) {
escapeThisBody = true;
}
}
if(escapeThisBody) {
continue;
}