Skip to content

Commit

Permalink
hotfix: Add detection into a particular thread
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidPeicho committed Jul 10, 2017
1 parent 66a0b58 commit 82adbe0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
3 changes: 2 additions & 1 deletion samples/invaders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/samples/invaders/cmake_module
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(invaders-sample ptc ptcsampleengine ${SFML_LIBRARIES})
target_link_libraries(invaders-sample ptc ptcsampleengine
pthread ${SFML_LIBRARIES})
endif()
7 changes: 5 additions & 2 deletions samples/invaders/moving-actor.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <iostream>
#include "moving-actor.hpp"

namespace ptc {
Expand All @@ -23,7 +24,8 @@ MovingActor::update(float delta) {
void
MovingActor::moveLeft() {

position_.x -= delta_ * moveSpeed_;
//position_.x -= delta_ * moveSpeed_;
position_.x -= 0.65f * moveSpeed_;
updateBBox();
}

Expand All @@ -46,7 +48,8 @@ MovingActor::moveDown() {
void
MovingActor::moveRight() {

position_.x += delta_ * moveSpeed_;
//position_.x += delta_ * moveSpeed_;
position_.x += 0.65f * moveSpeed_;
updateBBox();

}
Expand Down
20 changes: 13 additions & 7 deletions samples/invaders/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ size_t World::GAME_HEIGHT = 640;
size_t World::PARTICLE_SIZE = 4;
float World::INIT_ARROW_SIDE_LEN = 4666.0f;
float World::ENEMY_SPEED = 16.0f;
float World::PLAYER_SPEED = 190.0f;
float World::PLAYER_SPEED = 50.0f;
float World::BULLET_SPEED = 220.0f;

float World::TIME_BETWEEN_SHOT = 1.15f;
Expand Down Expand Up @@ -99,9 +99,19 @@ World::World(sf::RenderWindow& window, const sf::Font& font)
}

ptc::Tracker::instance()->update();

registerEvents();

testT_ = std::make_shared<std::thread>([this] { this->scheduleRecognition(); });

}

void
World::scheduleRecognition() {
using namespace std::chrono_literals;
while (true) {
ptc::Tracker::instance()->update();
std::this_thread::sleep_for(6ms);
}
}

void
Expand Down Expand Up @@ -137,8 +147,6 @@ World::updateMenu() {

updateParticles();

if (!Tracker::instance()->update()) arrowSprite_.setScale(0.0f, 0.0f);

// Updates title scale function of time to create
// a dynamic menu.
auto titleScale = titleSprite_.getScale();
Expand Down Expand Up @@ -226,6 +234,7 @@ World::updateGame() {
auto& shieldRenderable = renderer_.getList("shield").front();

deltaTime_ = float(clock_.restart().asMilliseconds()) / 1000.0f;
playerActor_->setDelta(deltaTime_);

updateParticles();

Expand Down Expand Up @@ -295,7 +304,6 @@ World::updateGame() {

}

playerActor_->setDelta(deltaTime_);
// Resets player initial frame
if (timerPlayerAnimation_.getElapsedTime().asSeconds() >= TIME_PLAYER_ANIM) {
auto& renderable = renderer_.getList("player").front();
Expand All @@ -304,8 +312,6 @@ World::updateGame() {

ia_.update(deltaTime_, enemiesList, bulletsList, regionsPool_["bullet"]);

Tracker::instance()->update();

int shieldWidth = texturesPool_["shield"]->getSize().x;
shieldActor_->setPos(playerActor_->getPos().x - (shieldWidth) / 2 + 16.0f,
playerActor_->getPos().y - 16.0f);
Expand Down
8 changes: 8 additions & 0 deletions samples/invaders/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
#include <memory>
#include <unordered_map>
#include <list>
#include <thread>

#include <SFML/Graphics.hpp>
#include <input-processor.hpp>

#include <ptc.hpp>

#include <chrono>

#include "../game-engine/actor.hpp"
#include "../game-engine/texture-region.hpp"
#include "../game-engine/renderer.hpp"
Expand Down Expand Up @@ -110,6 +113,9 @@ class World {
drawParticles();

private:
void
scheduleRecognition();

void
setupMenu();

Expand Down Expand Up @@ -207,6 +213,8 @@ class World {
// Ui variables
int score = 0;

std::shared_ptr<std::thread> testT_;

};

} // namespace invader
Expand Down
2 changes: 1 addition & 1 deletion src/ptc-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace ptc {

int TrackerImpl::MIN_SIZE = 300;
unsigned int TrackerImpl::MAX_PTS_NB = 12;
double TrackerImpl::MIN_SCALE_FACTOR = 2.0;
double TrackerImpl::MIN_SCALE_FACTOR = 1.7;

TrackerImpl::TrackerImpl()
: h_{-1}, w_{-1}
Expand Down

0 comments on commit 82adbe0

Please sign in to comment.