Working on a messaging system for sf events
This commit is contained in:
@@ -86,19 +86,15 @@ int Camera::update(double delta_time) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Camera::look_at_center() {
|
||||
//std::cout << "X:" << position.x << std::endl;
|
||||
//std::cout << "Y:" << position.y << std::endl;
|
||||
//std::cout << "Z:" << position.z << std::endl;
|
||||
void Camera::update(SfEventPublisher* p, sf::Event e)
|
||||
{
|
||||
|
||||
//std::cout << "dx:" << direction.x << std::endl;
|
||||
//std::cout << "dy:" << direction.y << std::endl;
|
||||
}
|
||||
|
||||
void Camera::look_at_center() {
|
||||
|
||||
direction = CartToNormalizedSphere(sf::Vector3f(75, 75, 75) - position);
|
||||
|
||||
//std::cout << "dx:" << direction.x << std::endl;
|
||||
//std::cout << "dy:" << direction.y << std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
43
src/Input.cpp
Normal file
43
src/Input.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "Input.h"
|
||||
|
||||
|
||||
Input::Input() :
|
||||
keyboard_flags(sf::Keyboard::Key::KeyCount, false),
|
||||
mouse_flags(sf::Mouse::Button::ButtonCount, false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Input::~Input()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Input::consume_events(sf::RenderWindow *window) {
|
||||
|
||||
sf::Event e;
|
||||
while (window->pollEvent(e)) {
|
||||
event_queue.push_back(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Input::set_flags() {
|
||||
|
||||
for (auto e: event_queue) {
|
||||
if (e.type == sf::Event::KeyPressed) {
|
||||
held_keys.push_back(e.key.code);
|
||||
}
|
||||
else if (e.type == sf::Event::KeyReleased) {
|
||||
std::remove(held_keys.begin(), held_keys.end(), e.key.code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Input::dispatch_events() {
|
||||
|
||||
while (event_queue.size() != 0) {
|
||||
notify(event_queue.front());
|
||||
event_queue.pop_front();
|
||||
}
|
||||
}
|
||||
@@ -131,11 +131,11 @@ sf::Color Ray::Cast() {
|
||||
|
||||
switch (voxel_data) {
|
||||
case 5:
|
||||
return sf::Color(255, 120, 255, alpha);
|
||||
return sf::Color(255, 120, 255, static_cast<int>(alpha));
|
||||
case 6:
|
||||
return sf::Color(150, 80, 220, alpha);
|
||||
return sf::Color(150, 80, 220, static_cast<int>(alpha));
|
||||
default:
|
||||
return sf::Color(150, 80, 220, alpha);
|
||||
return sf::Color(150, 80, 220, static_cast<int>(alpha));
|
||||
}
|
||||
|
||||
dist++;
|
||||
|
||||
@@ -328,7 +328,7 @@ sf::Color Software_Caster::global_light(sf::Color in, sf::Vector3i mask) {
|
||||
|
||||
sf::Vector3f mask_f(mask);
|
||||
|
||||
in.a = in.a + acos(
|
||||
in.a = in.a + (int)acos(
|
||||
DotProduct(
|
||||
Normalize(lights.at(0).direction_cartesian),
|
||||
Normalize(mask_f)
|
||||
|
||||
32
src/main.cpp
32
src/main.cpp
@@ -5,6 +5,9 @@
|
||||
|
||||
#elif defined _WIN32
|
||||
#include <windows.h>
|
||||
|
||||
// As if hardware is ever going to move away from 1.2
|
||||
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
|
||||
#include <CL/cl.h>
|
||||
#include <CL/opencl.h>
|
||||
|
||||
@@ -32,6 +35,7 @@
|
||||
#include "Vector4.hpp"
|
||||
#include <Camera.h>
|
||||
#include "Software_Caster.h"
|
||||
#include "Input.h"
|
||||
|
||||
|
||||
const int WINDOW_X = 1920;
|
||||
@@ -79,20 +83,14 @@ int main() {
|
||||
t.create_program();
|
||||
t.create_buffers();
|
||||
|
||||
// Initialize the raycaster hardware, compat, or software
|
||||
|
||||
RayCaster *rc = new Hardware_Caster();
|
||||
//RayCaster *rc = new Software_Caster();
|
||||
|
||||
if (rc->init() != 1) {
|
||||
delete rc;
|
||||
// rc = new Hardware_Caster_Compat();
|
||||
// if (rc->init() != 0) {
|
||||
// delete rc;
|
||||
// rc = new Software_Caster();
|
||||
// }
|
||||
abort();
|
||||
}
|
||||
|
||||
// Set up the raycaster
|
||||
|
||||
std::cout << "map...";
|
||||
sf::Vector3i map_dim(MAP_X, MAP_Y, MAP_Z);
|
||||
Old_Map* map = new Old_Map(map_dim);
|
||||
@@ -147,8 +145,15 @@ int main() {
|
||||
bool mouse_enabled = true;
|
||||
bool reset = false;
|
||||
|
||||
|
||||
Input input_handler;
|
||||
input_handler.subscribe(camera, SfEventPublisher::Event_Class::KeyEvent);
|
||||
window.setKeyRepeatEnabled(false);
|
||||
|
||||
while (window.isOpen()) {
|
||||
|
||||
input_handler.consume_events(&window);
|
||||
input_handler.set_flags();
|
||||
// Poll for events from the user
|
||||
sf::Event event;
|
||||
while (window.pollEvent(event)) {
|
||||
@@ -156,6 +161,15 @@ int main() {
|
||||
if (event.type == sf::Event::Closed)
|
||||
window.close();
|
||||
|
||||
if (event.type == sf::Event::KeyPressed) {
|
||||
std::cout << event.key.code << std::endl;
|
||||
}
|
||||
if (event.type == sf::Event::KeyReleased) {
|
||||
std::cout << event.key.code << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (event.type == sf::Event::KeyPressed) {
|
||||
if (event.key.code == sf::Keyboard::M) {
|
||||
if (mouse_enabled)
|
||||
|
||||
Reference in New Issue
Block a user