Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
kswaldemar committed Nov 8, 2020
2 parents 5aaf033 + 45084df commit b9d1f97
Show file tree
Hide file tree
Showing 32 changed files with 399 additions and 232 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ jobs:
run: sudo apt install libglu1-mesa-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev

- uses: actions/checkout@v2

- name: Checkout submodules
uses: srt32/[email protected]
with:
args: git submodule update --init --recursive
submodules: true

- name: Configure CMake
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release

- name: Build
run: cmake --build build --target rewindviewer --parallel 6
32 changes: 32 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Windows

on: [push]

jobs:
build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Configure CMake
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release

- name: Build
run: cmake --build build --target rewindviewer --parallel 6 --config Release

- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: rewindviewer
path: build/Release/rewindviewer.exe
retention-days: 7

- name: Upload resources folder
uses: actions/upload-artifact@v2
with:
name: resources
path: resources
retention-days: 7
37 changes: 1 addition & 36 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
build
cmake-build-*
.idea

# Created by .ignore support plugin (hsz.mobi)
### C++ template
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app
.idea/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
[![RAIC](https://img.shields.io/badge/Russian%20AI%20Cup-2017-yellow.svg?style=flat-square)](http://russianaicup.ru/)
[![Build status](https://travis-ci.org/kswaldemar/rewind-viewer.svg?branch=master)](https://travis-ci.org/kswaldemar/rewind-viewer)
[![Linux](https://github.com/kswaldemar/rewind-viewer/workflows/Linux/badge.svg)](https://github.com/kswaldemar/rewind-viewer/actions?query=workflow%3ALinux)
[![Windows](https://github.com/kswaldemar/rewind-viewer/workflows/Windows/badge.svg)](https://github.com/kswaldemar/rewind-viewer/actions?query=workflow%3AWindows)
[![GitHub Releases](https://img.shields.io/github/release/kswaldemar/rewind-viewer.svg?style=flat-square)](https://github.com/kswaldemar/rewind-viewer/releases)

Fast Russain AI Cup championship match viewer with rewinding support written in OpenGL

Expand Down
3 changes: 2 additions & 1 deletion resources/shaders/circle.frag
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ void main() {
float delta = fwidth(dist);

float alpha = step(fs_in.radius, dist);
alpha += (1.0 - step(fs_in.radius - delta * line_width, dist)) * step(1, line_width);
alpha += (1.0 - step(fs_in.radius - delta * line_width, dist)) *
step(float(1), float(line_width));

frag_color = mix(fs_in.color, vec4(0.0), alpha);
}
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ set(CMAKE_CXX_STANDARD 14)

set(Sources
main.cpp

imgui_impl/imgui_impl_glfw.cpp
imgui_impl/imgui_impl_opengl3.cpp

cgutils/Shader.cpp
cgutils/Camera.cpp
cgutils/utils.cpp
cgutils/ResourceManager.cpp
common/Spinlock.cpp

viewer/UIController.cpp
viewer/Scene.cpp
viewer/Renderer.cpp
viewer/Config.cpp

viewer/Popup.cpp
viewer/RenderContext.cpp
viewer/ShaderCollection.cpp
viewer/Frame.cpp
Expand Down
13 changes: 13 additions & 0 deletions src/common/Spinlock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Created by Vladimir A. Kiselev on 08.11.2020.
//

#include "Spinlock.h"

void Spinlock::lock() {
while (lock_.test_and_set(std::memory_order_acquire))
;
}
void Spinlock::unlock() {
lock_.clear(std::memory_order_release);
}
16 changes: 16 additions & 0 deletions src/common/Spinlock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Created by Vladimir A. Kiselev on 08.11.2020.
//

#pragma once

#include <atomic>

class Spinlock {
public:
void lock();
void unlock();

private:
std::atomic_flag lock_ = ATOMIC_FLAG_INIT;
};
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void prepare_and_run_game_loop(GLFWwindow *window) {
// Read window events
glfwPollEvents();

if (!glfwGetWindowAttrib(window, GLFW_FOCUSED)) {
if (!conf.ui.update_unfocused && !glfwGetWindowAttrib(window, GLFW_FOCUSED)) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
continue;
}
Expand All @@ -187,6 +187,9 @@ void prepare_and_run_game_loop(GLFWwindow *window) {
glfwSetWindowShouldClose(window, true);
}

// Primitives send mode
net.set_immediate_mode(ui.immediate_mode_enabled());

// Non Ui related drawing
scene.update_and_render(cam);

Expand Down
5 changes: 5 additions & 0 deletions src/net/NetListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ void NetListener::run() {
}
}

void NetListener::set_immediate_mode(bool enable) {
immediate_mode_.store(enable);
}

void NetListener::stop() {
if (status_ != ConStatus::CLOSED) {
LOG_INFO("Stopping network listening");
Expand All @@ -74,6 +78,7 @@ void NetListener::serve_connection(CActiveSocket *client) {
// same for debug print
data[nbytes] = '\0';
LOG_V9("NetClient:: Message %d bytes, '%s'", nbytes, data);
handler_->set_immediate_mode(immediate_mode_.load());
// Strategy can send several messages in one block
handler_->handle_message(data, static_cast<uint32_t>(nbytes));
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/net/NetListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class NetListener {
/// Blocking call, should be running on personal thread
void run();

/// Immediate mode
/// Send primitives as soon as they come, do not wait 'end'
/// Called from render thread
void set_immediate_mode(bool enable);

void stop();

private:
Expand All @@ -50,4 +55,5 @@ class NetListener {
std::unique_ptr<ProtoHandler> handler_;

std::atomic<bool> stop_{false};
std::atomic<bool> immediate_mode_{false};
};
39 changes: 34 additions & 5 deletions src/net/ProtoHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,37 @@ void ProtoHandler::on_new_connection() {
reset_state();
}

void ProtoHandler::on_frame_end() {
scene_->add_frame(std::move(frame_));
void ProtoHandler::set_immediate_mode(bool enabled) {
send_mode_ = enabled ? Mode::IMMEDIATE : Mode::BATCH;
}

void ProtoHandler::on_message_processed(bool end_frame) {
if (send_mode_ == Mode::BATCH && !end_frame) {
return;
}

if (immediate_data_sent_) {
// Update last frame, because something already sent to it
scene_->add_frame_data(*frame_);
} else {
// Add new frame, nothing was appended to last one
scene_->add_frame(std::move(frame_));
frame_ = nullptr;
}
immediate_data_sent_ = !end_frame;
scene_->add_permanent_frame_data(permanent_frame_);
reset_state();

if (end_frame) {
reset_state();
} else {
if (!frame_) {
frame_ = std::make_shared<FrameEditor>();
frame_->set_layer_id(last_layer_id_);
} else {
frame_->clear();
}
permanent_frame_.clear();
}
}

FrameEditor &ProtoHandler::get_frame_editor() {
Expand All @@ -27,6 +54,7 @@ void ProtoHandler::reset_state() {
permanent_frame_.clear();
frame_ = std::make_shared<FrameEditor>();
use_permanent_ = false;
immediate_data_sent_ = false;
}

void ProtoHandler::set_layer(size_t layer) {
Expand All @@ -36,6 +64,7 @@ void ProtoHandler::set_layer(size_t layer) {
static_cast<size_t>(Frame::LAYERS_COUNT), clamped_layer);
}

frame_->set_layer_id(clamped_layer - 1);
permanent_frame_.set_layer_id(clamped_layer - 1);
last_layer_id_ = clamped_layer - 1;
frame_->set_layer_id(last_layer_id_);
permanent_frame_.set_layer_id(last_layer_id_);
}
17 changes: 15 additions & 2 deletions src/net/ProtoHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

class ProtoHandler {
public:
enum class Mode {
BATCH, /// Wait to 'end' primitive before sending data
IMMEDIATE /// Send primitives as soon as they come
};

explicit ProtoHandler(Scene *scene);
virtual ~ProtoHandler() = default;

Expand All @@ -19,9 +24,12 @@ class ProtoHandler {
/// Any saved data from old messages should be cleared on this call
virtual void on_new_connection();

void set_immediate_mode(bool enabled);

protected:
/// Should be called by specific handler when 'end_frame' received
void on_frame_end();
/// Should be called by specific handler after each processed message
/// @param end_frame - set when 'end_frame' received
void on_message_processed(bool end_frame);

/// Get frame editor for normal or permanent frame
/// Specific handler should use it to create primitives
Expand All @@ -40,4 +48,9 @@ class ProtoHandler {
std::shared_ptr<FrameEditor> frame_;
FrameEditor permanent_frame_;
bool use_permanent_ = false;

Mode send_mode_{Mode::BATCH};
// Data was transferred to last frame in immediate mode
bool immediate_data_sent_{false};
size_t last_layer_id_ = Frame::DEFAULT_LAYER;
};
9 changes: 3 additions & 6 deletions src/net/json_handler/JsonHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ void JsonHandler::process_json_message(const uint8_t *chunk_begin, const uint8_t
switch (type) {
case PrimitiveType::END: {
LOG_V8("JsonHandler::End");
on_frame_end();
break;
}
case PrimitiveType::CIRCLE: {
Expand All @@ -200,11 +199,7 @@ void JsonHandler::process_json_message(const uint8_t *chunk_begin, const uint8_t
case PrimitiveType::TRIANGLE: {
LOG_V8("JsonHandler::Triangle detected");
auto obj = j.get<pod::Triangle>();
if (obj.fill) {
ctx.add_filled_triangle(obj.points[0], obj.points[1], obj.points[2], obj.color);
} else {
ctx.add_polyline(obj.points, obj.color);
}
ctx.add_triangle(obj.points[0], obj.points[1], obj.points[2], obj.color, obj.fill);
break;
}
case PrimitiveType::POLYLINE: {
Expand Down Expand Up @@ -245,6 +240,8 @@ void JsonHandler::process_json_message(const uint8_t *chunk_begin, const uint8_t
}
case PrimitiveType::TYPES_COUNT: break;
}

on_message_processed(type == PrimitiveType::END);
} catch (const std::exception &e) {
LOG_WARN("JsonClient::Exception: %s", e.what());
}
Expand Down
Loading

0 comments on commit b9d1f97

Please sign in to comment.