<commit_before>//============================================================================
// Name        : ShotSimulationService.cpp
// Author      : ITM13
// Version     : 1.0
// Description :
//============================================================================
#include "ShotSimulationService.h"
#include "..\..\shared\notifications\PlayerHitNotification.h"

#include <algorithm>
#include <vector>

using std::max;
using std::vector;
using cv::imread;
using shared::notifications::PlayerHitNotification;

namespace services {
	namespace simulation {
		ShotSimulationService::ShotSimulationService(SharedPtr<WebcamService> webcamService, NotificationQueue& playerHitQueue)
			: webcamService(webcamService), detectionService(), playerHitQueue(playerHitQueue) {
			gunShotImg = imread("resources/images/gunfire2_small.png", CV_LOAD_IMAGE_UNCHANGED);
			cheeseImg = imread("resources/images/cheese_small.png", CV_LOAD_IMAGE_UNCHANGED);
			wallExplosionImg = imread("resources/images/explosion_wall.png", CV_LOAD_IMAGE_UNCHANGED);
			wallExplosionHalfXSize = wallExplosionImg.cols / 2;
			wallExplosionHalfYSize = wallExplosionImg.rows / 2;

			robotExplosionImg = imread("resources/images/explosion_robot.png", CV_LOAD_IMAGE_UNCHANGED);
			robotExplosionHalfXSize = robotExplosionImg.cols / 2;
			robotExplosionHalfYSize = robotExplosionImg.rows / 2;

			webcamService->AddObserver(this);
		}

		ShotSimulationService::~ShotSimulationService()
		{
			webcamService->RemoveObserver(this);
			//do not delete, since it is a shared pointer
			webcamService = nullptr;
		}

		void ShotSimulationService::SimulateShot(Shot shot) {
			Poco::Mutex::ScopedLock lock(mutexThreadLock); //will be released after leaving scop
			shots.insert(ShotsSetType::ValueType(SimulationShot(shot)));
		}

		void ShotSimulationService::Update(WebcamService* observable) {
			if (shots.empty()) {
				return;
			}

			Poco::Mutex::ScopedLock lock(mutexThreadLock); //will be released after leaving scop

			try {
				Mat frame = observable->GetLastImage().clone();
				ShotsSetType::Iterator iter = shots.begin();
				vector<Shot> deleteShots;

				while (iter != shots.end()){
					
					if (iter->SimulateStartExplosion()) {
						//simulate gun explosion
						OverlayImage(frame, gunShotImg, iter->startPoint);<commit_msg>shot sim works<commit_after>//============================================================================
// Name        : ShotSimulationService.cpp
// Author      : ITM13
// Version     : 1.0
// Description :
//============================================================================
#include "ShotSimulationService.h"
#include "..\..\shared\notifications\PlayerHitNotification.h"

#include <algorithm>
#include <vector>

using std::max;
using std::vector;
using cv::imread;
using shared::notifications::PlayerHitNotification;

namespace services {
	namespace simulation {
		ShotSimulationService::ShotSimulationService(SharedPtr<WebcamService> webcamService, NotificationQueue& playerHitQueue)
			: webcamService(webcamService), detectionService(), playerHitQueue(playerHitQueue) {
			gunShotImg = imread("resources/images/gunfire2_small.png", CV_LOAD_IMAGE_UNCHANGED);
			cheeseImg = imread("resources/images/cheese_small.png", CV_LOAD_IMAGE_UNCHANGED);
			wallExplosionImg = imread("resources/images/explosion_wall.png", CV_LOAD_IMAGE_UNCHANGED);
			wallExplosionHalfXSize = wallExplosionImg.cols / 2;
			wallExplosionHalfYSize = wallExplosionImg.rows / 2;

			robotExplosionImg = imread("resources/images/explosion_robot.png", CV_LOAD_IMAGE_UNCHANGED);
			robotExplosionHalfXSize = robotExplosionImg.cols / 2;
			robotExplosionHalfYSize = robotExplosionImg.rows / 2;

			webcamService->AddObserver(this);
		}

		ShotSimulationService::~ShotSimulationService()
		{
			webcamService->RemoveObserver(this);
			//do not delete, since it is a shared pointer
			webcamService = nullptr;
		}

		void ShotSimulationService::SimulateShot(Shot shot) {
			Poco::Mutex::ScopedLock lock(mutexThreadLock); //will be released after leaving scop
			shots.insert(ShotsSetType::ValueType(SimulationShot(shot)));
		}

		void ShotSimulationService::Update(WebcamService* observable) {
			if (shots.empty()) {
				return;
			}

			Poco::Mutex::ScopedLock lock(mutexThreadLock); //will be released after leaving scop

			try {
				Mat frame = observable->GetLastImage();//.clone();
				ShotsSetType::Iterator iter = shots.begin();
				vector<Shot> deleteShots;

				while (iter != shots.end()){
					
					if (iter->SimulateStartExplosion()) {
						//simulate gun explosion
						OverlayImage(frame, gunShotImg, iter->startPoint);
{'fraction_non_alphanumeric': 0.17328441950798446, 'fraction_numerical': 0.003884333189469141, 'mean_word_length': 5.3406292749658, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '136951', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1346, 'n_words': 239}