Did this work?

This commit is contained in:
2017-10-05 23:30:12 -07:00
parent 2d2a854f0f
commit 58ef1da02a
19 changed files with 366 additions and 428 deletions

View File

@@ -110,43 +110,17 @@ bool Application::game_loop() {
// Time keeping
elapsed_time = elap_time();
// time between this and the last frame
delta_time = elapsed_time - current_time;
// Setup the time for the next tick
current_time = elapsed_time;
// If the delta exceeded 0.2f, then limit the max lag we'll allow
// 1 / float is how you get the fps. 0.2f == 5fps
if (delta_time > 0.2f)
delta_time = 0.2f;
// Add the the physics accumulator our delta
accumulator_time += delta_time;
// We want to keep our physics at a constant step size but we have a variable frame rate.
// 0.016 == physics preferred timestep
// 0.030 == average 30 fps frame rate
// we must run the physics step ~twice every render frame to keep consistency
int count = 0;
while ((accumulator_time - step_size) >= step_size) {
count++;
accumulator_time -= step_size;
// do physics at step size rate
for (int i = 0; i < 1000; i++) {
int x = 9;
int r = i + x * 4;
current_time = elapsed_time;
}
// ==== DELTA TIME LOCKED ====
}
std::cout << count << "\n";
// ==== FPS LOCKED ====
window->clear(sf::Color::Black);
@@ -172,6 +146,94 @@ bool Application::game_loop() {
fps.draw();
Gui::do_render();
ImGuiWindowFlags window_flags = ImGuiWindowFlags_MenuBar;
bool window_show = true;
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginMenu("Menu"))
{
ImGui::Button("asdoifjasodif");
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
ImGui::Begin("Window");
ImGui::InputText("filename", screenshot_buf, 128);
if (ImGui::Button("Take Screen shot")) {
std::string path = "../assets/";
std::string filename(screenshot_buf);
filename += ".png";
sf::Texture window_texture;
window_texture.create(window->getSize().x, window->getSize().y);
window_texture.update(*window);
sf::Image image = window_texture.copyToImage();
image.saveToFile(path + filename);
}
ImGui::NextColumn();
if (ImGui::Button("Pause")) {
paused = !paused;
if (paused)
Logger::log("Pausing", Logger::LogLevel::INFO);
else
Logger::log("Unpausing", Logger::LogLevel::INFO);
}
ImGui::End();
ImGui::Begin("Controller debugger");
ImDrawList* draw_list = ImGui::GetWindowDrawList();
static ImVec4 col = ImVec4(1.0f, 0.0f, 1.0f, 1.0f);
const ImVec2 p = ImGui::GetCursorScreenPos();
const ImU32 col32 = ImColor(col);
std::vector<float> axis_values = {
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::X) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::Y) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::U) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::R) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::Z) / 2,
sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::V) / 2
};
ImGui::Columns(3, "Axis's"); // 4-ways, with border
ImGui::Separator();
ImGui::Text("X Y"); ImGui::NextColumn();
ImGui::Text("U R"); ImGui::NextColumn();
ImGui::Text("Z V"); ImGui::NextColumn();
ImGui::Separator();
for (int i = 0; i < 3; i++) {
float offset = ImGui::GetColumnWidth(i);
draw_list->AddLine(ImVec2(p.x + 0 + offset * i, p.y + 50), ImVec2(p.x + 100 + offset * i, p.y + 50), col32, 1.0);
draw_list->AddLine(ImVec2(p.x + 50 + offset * i, p.y + 0), ImVec2(p.x + 50 + offset * i, p.y + 100), col32, 1.0);
draw_list->AddCircleFilled(ImVec2(p.x + axis_values[2 * i] + 50 + offset * i, p.y + axis_values[2 * i + 1] + 50), 6, col32, 32);
ImGui::Dummy(ImVec2(100, 100));
ImGui::NextColumn();
}
ImGui::End();
//ImGui::ShowTestWindow();
ImGui::Render();
// ImGUI messes up somthing in the SFML GL state, so we need a single draw call to right things
@@ -195,40 +257,3 @@ float Application::elap_time() {
return static_cast<float>(elapsed_time.count());
}
void Application::render_gui() {
ImGui::Begin("Window");
ImGui::InputText("filename", screenshot_buf, 128);
if (ImGui::Button("Take Screen shot")) {
std::string path = "../assets/";
std::string filename(screenshot_buf);
filename += ".png";
sf::Texture window_texture;
window_texture.create(window->getSize().x, window->getSize().y);
window_texture.update(*window);
sf::Image image = window_texture.copyToImage();
image.saveToFile(path + filename);
}
ImGui::NextColumn();
if (ImGui::Button("Pause")) {
paused = !paused;
if (paused)
Logger::log("Pausing", Logger::LogLevel::INFO);
else
Logger::log("Unpausing", Logger::LogLevel::INFO);
}
ImGui::End();
}
void Application::update_gui() {
}

View File

@@ -97,7 +97,7 @@ void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Even
default_impulse = 1.0f;
}
else if (held_event->code == sf::Keyboard::C) {
look_at(sf::Vector3f(128, 128, 10));
look_at_center();
}
else if (held_event->code == sf::Keyboard::Q) {
add_relative_impulse(Camera::DIRECTION::DOWN, default_impulse);
@@ -230,10 +230,9 @@ void Camera::update_gui() {
rendering = true;
}
void Camera::look_at(sf::Vector3f position)
{
void Camera::look_at_center() {
direction = CartToNormalizedSphere(position - this->position);
direction = CartToNormalizedSphere(sf::Vector3f(60, 60, 35) - position);
}
sf::Vector2f* Camera::get_direction_pointer() {

View File

@@ -1,48 +0,0 @@
#include "FrameWatcher.h"
#include <chrono>
FrameWatcher::FrameWatcher() {
}
FrameWatcher::~FrameWatcher()
{
}
void FrameWatcher::do_tick() {
elapsed_time = get_elapsed_time();
delta_time = elapsed_time - current_time;
current_time = elapsed_time;
if (delta_time > 0.2f)
delta_time = 0.2f;
accumulator_time += delta_time;
while ((accumulator_time - step_size) >= step_size) {
accumulator_time -= step_size;
// ==== DELTA TIME LOCKED ====
}
}
float FrameWatcher::get_elapsed_time() {
static std::chrono::time_point<std::chrono::system_clock> start;
static bool started = false;
if (!started) {
start = std::chrono::system_clock::now();
started = true;
}
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_time = now - start;
return static_cast<float>(elapsed_time.count());
}

View File

@@ -1,4 +1,4 @@
#include "Gui.h"
std::mutex Gui::container_lock;
#include "Gui.h"
std::mutex Gui::container_lock;
std::list<Gui*> Gui::renderable_container;

View File

@@ -112,6 +112,16 @@ void Input::handle_held_keys() {
}
void Input::dispatch_events() {
while (event_queue.size() != 0) {
notify_subscribers(std::move(event_queue.front()));
event_queue.pop_front();
}
}
void Input::render_gui() {
ImGui::Begin("Input Debugger");
@@ -282,111 +292,108 @@ void Input::transpose_sf_events(std::list<sf::Event> sf_event_queue) {
}
}
const std::vector<std::string> Input::key_strings = {
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
"Num0",
"Num1",
"Num2",
"Num3",
"Num4",
"Num5",
"Num6",
"Num7",
"Num8",
"Num9",
"Escape",
"LControl",
"LShift",
"LAlt",
"LSystem",
"RControl",
"RShift",
"RAlt",
"RSystem",
"Menu",
"LBracket",
"RBracket",
"SemiColon",
"Comma",
"Period",
"Quote",
"Slash",
"BackSlash",
"Tilde",
"Equal",
"Dash",
"Space",
"Return",
"BackSpace",
"Tab",
"PageUp",
"PageDown",
"End",
"Home",
"Insert",
"Delete",
"Add",
"Subtract",
"Multiply",
"Divide",
"Left",
"Right",
"Up",
"Down",
"Numpad0",
"Numpad1",
"Numpad2",
"Numpad3",
"Numpad4",
"Numpad5",
"Numpad6",
"Numpad7",
"Numpad8",
"Numpad9",
"F1" ,
"F2" ,
"F3" ,
"F4" ,
"F5" ,
"F6" ,
"F7" ,
"F8" ,
"F9" ,
"F10",
"F11",
"F12",
"F13",
"F14",
"F15",
const std::vector<std::string> Input::key_strings = {
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
"Num0",
"Num1",
"Num2",
"Num3",
"Num4",
"Num5",
"Num6",
"Num7",
"Num8",
"Num9",
"Escape",
"LControl",
"LShift",
"LAlt",
"LSystem",
"RControl",
"RShift",
"RAlt",
"RSystem",
"Menu",
"LBracket",
"RBracket",
"SemiColon",
"Comma",
"Period",
"Quote",
"Slash",
"BackSlash",
"Tilde",
"Equal",
"Dash",
"Space",
"Return",
"BackSpace",
"Tab",
"PageUp",
"PageDown",
"End",
"Home",
"Insert",
"Delete",
"Add",
"Subtract",
"Multiply",
"Divide",
"Left",
"Right",
"Up",
"Down",
"Numpad0",
"Numpad1",
"Numpad2",
"Numpad3",
"Numpad4",
"Numpad5",
"Numpad6",
"Numpad7",
"Numpad8",
"Numpad9",
"F1" ,
"F2" ,
"F3" ,
"F4" ,
"F5" ,
"F6" ,
"F7" ,
"F8" ,
"F9" ,
"F10",
"F11",
"F12",
"F13",
"F14",
"F15",
"Pause"
};
void Input::generate_events() {
}

View File

@@ -26,6 +26,14 @@ void NetworkInput::recieve_from_clients()
}
void NetworkInput::dispatch_events()
{
while (event_queue.size() != 0) {
notify_subscribers(std::move(event_queue.front()));
event_queue.pop_front();
}
}
void NetworkInput::threaded_client_listener(int port) {
listener.listen(port);

View File

@@ -42,10 +42,3 @@ void VrEventPublisher::notify_subscribers(std::unique_ptr<vr::Event> event) {
}
}
void VrEventPublisher::dispatch_events() {
while (event_queue.size() != 0) {
notify_subscribers(std::move(event_queue.front()));
event_queue.pop_front();
}
}

View File

@@ -215,7 +215,7 @@ void Old_Map::generate_terrain() {
for (int x = dimensions.x / 2; x < dimensions.x / 2 + dimensions.x / 64; x++) {
for (int y = dimensions.x / 2; y < dimensions.y / 2 + dimensions.x / 64; y++) {
for (int z = 5; z < 15; z++) {
for (int z = 0; z < 5; z++) {
voxel_data[x + dimensions.x * (y + dimensions.z * z)] = 6;
}
@@ -249,63 +249,63 @@ void Old_Map::generate_terrain() {
// Hand code in some constructions
//std::vector<std::vector<int>> maze =
// generate_maze(sf::Vector2i(8, 8), sf::Vector2i(0, 0));
std::vector<std::vector<int>> maze =
generate_maze(sf::Vector2i(8, 8), sf::Vector2i(0, 0));
//for (int x = 0; x < maze.size(); x++) {
// for (int y = 0; y < maze.at(0).size(); y++) {
//
// switch(maze.at(x).at(y)) {
//
// case 1: { // North
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 5;
// //voxel_data[x * 3 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
// //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
// break;
// }
// case 2: { // South
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + dimensions.z * 1)] = 5;
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
// //voxel_data[x * 3 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
// //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
// break;
// }
// case 3: { // East
// voxel_data[x * 3 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
// voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 5;
// //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
// //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
// break;
// }
// case 4: { // West
// voxel_data[x * 3 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 5;
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
// voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
// //voxel_data[x * 3 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
// //voxel_data[x * 3 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
// break;
// }
//
// }
//
//
for (int x = 0; x < maze.size(); x++) {
for (int y = 0; y < maze.at(0).size(); y++) {
switch(maze.at(x).at(y)) {
case 1: { // North
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 5;
//voxel_data[x * 3 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
//voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
break;
}
case 2: { // South
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + dimensions.z * 1)] = 5;
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
//voxel_data[x * 3 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
//voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
break;
}
case 3: { // East
voxel_data[x * 3 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 5;
//voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
//voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
break;
}
case 4: { // West
voxel_data[x * 3 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 5;
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
//voxel_data[x * 3 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
//voxel_data[x * 3 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
break;
}
}
}
}
//for (int x = 0; x < dimensions.x; x++) {
// for (int y = 0; y < dimensions.y; y++) {
// voxel_data[x + dimensions.x * (y + dimensions.z * 1)] = 6;
// }
//}
////for (int x = 0; x < dimensions.x; x++) {
//// for (int y = 0; y < dimensions.y; y++) {
//// voxel_data[x + dimensions.x * (y + dimensions.z * 1)] = 6;
//// }
////}
//set_voxel(sf::Vector3i(45, 70, 6), 6);
//set_voxel(sf::Vector3i(47, 70, 6), 6);
//set_voxel(sf::Vector3i(100, 100, 50), 1);
set_voxel(sf::Vector3i(45, 70, 6), 6);
set_voxel(sf::Vector3i(47, 70, 6), 6);
set_voxel(sf::Vector3i(100, 100, 50), 1);
}