mirror of https://github.com/auygun/kaliber.git
Compare commits
5 Commits
557eb517cb
...
068656ddc2
Author | SHA1 | Date |
---|---|---|
Attila Uygun | 068656ddc2 | |
Attila Uygun | 00f57bab05 | |
Attila Uygun | 3bc8785469 | |
Attila Uygun | 5c6e414a15 | |
Attila Uygun | 1d1452d4aa |
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:versionCode="19"
|
android:versionCode="22"
|
||||||
android:versionName="1.0.3">
|
android:versionName="1.0.4">
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
|
|
|
@ -35,7 +35,7 @@ TaskRunner* TaskRunner::GetThreadLocalTaskRunner() {
|
||||||
void TaskRunner::PostTask(const Location& from, Closure task) {
|
void TaskRunner::PostTask(const Location& from, Closure task) {
|
||||||
DCHECK(task) << LOCATION(from);
|
DCHECK(task) << LOCATION(from);
|
||||||
|
|
||||||
task_count_.fetch_add(1, std::memory_order_release);
|
task_count_.fetch_add(1, std::memory_order_relaxed);
|
||||||
std::lock_guard<std::mutex> scoped_lock(lock_);
|
std::lock_guard<std::mutex> scoped_lock(lock_);
|
||||||
queue_.emplace_back(from, std::move(task));
|
queue_.emplace_back(from, std::move(task));
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,11 @@ void TaskRunner::MultiConsumerRun() {
|
||||||
|
|
||||||
task_cb();
|
task_cb();
|
||||||
task_count_.fetch_sub(1, std::memory_order_release);
|
task_count_.fetch_sub(1, std::memory_order_release);
|
||||||
|
|
||||||
|
if (cancel_tasks_.load(std::memory_order_relaxed)) {
|
||||||
|
CancelTasksInternal();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +98,16 @@ void TaskRunner::SingleConsumerRun() {
|
||||||
|
|
||||||
task_cb();
|
task_cb();
|
||||||
task_count_.fetch_sub(1, std::memory_order_release);
|
task_count_.fetch_sub(1, std::memory_order_release);
|
||||||
|
|
||||||
|
if (cancel_tasks_.load(std::memory_order_relaxed)) {
|
||||||
|
CancelTasksInternal();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TaskRunner::CancelTasks() {
|
||||||
|
cancel_tasks_.store(true, std::memory_order_relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskRunner::WaitForCompletion() {
|
void TaskRunner::WaitForCompletion() {
|
||||||
|
@ -101,4 +115,11 @@ void TaskRunner::WaitForCompletion() {
|
||||||
std::this_thread::yield();
|
std::this_thread::yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TaskRunner::CancelTasksInternal() {
|
||||||
|
cancel_tasks_.store(false, std::memory_order_relaxed);
|
||||||
|
task_count_.store(0, std::memory_order_relaxed);
|
||||||
|
std::lock_guard<std::mutex> scoped_lock(lock_);
|
||||||
|
queue_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
|
|
@ -60,9 +60,9 @@ class TaskRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiConsumerRun();
|
void MultiConsumerRun();
|
||||||
|
|
||||||
void SingleConsumerRun();
|
void SingleConsumerRun();
|
||||||
|
|
||||||
|
void CancelTasks();
|
||||||
void WaitForCompletion();
|
void WaitForCompletion();
|
||||||
|
|
||||||
static void CreateThreadLocalTaskRunner();
|
static void CreateThreadLocalTaskRunner();
|
||||||
|
@ -74,9 +74,12 @@ class TaskRunner {
|
||||||
std::deque<Task> queue_;
|
std::deque<Task> queue_;
|
||||||
mutable std::mutex lock_;
|
mutable std::mutex lock_;
|
||||||
std::atomic<size_t> task_count_{0};
|
std::atomic<size_t> task_count_{0};
|
||||||
|
std::atomic<bool> cancel_tasks_{false};
|
||||||
|
|
||||||
static thread_local std::unique_ptr<TaskRunner> thread_local_task_runner;
|
static thread_local std::unique_ptr<TaskRunner> thread_local_task_runner;
|
||||||
|
|
||||||
|
void CancelTasksInternal();
|
||||||
|
|
||||||
TaskRunner(TaskRunner const&) = delete;
|
TaskRunner(TaskRunner const&) = delete;
|
||||||
TaskRunner& operator=(TaskRunner const&) = delete;
|
TaskRunner& operator=(TaskRunner const&) = delete;
|
||||||
};
|
};
|
||||||
|
|
|
@ -130,11 +130,11 @@ void Demo::Update(float delta_time) {
|
||||||
|
|
||||||
if (do_benchmark_) {
|
if (do_benchmark_) {
|
||||||
benchmark_time_ += delta_time;
|
benchmark_time_ += delta_time;
|
||||||
if (benchmark_time_ > 1) {
|
if (benchmark_time_ > 3) {
|
||||||
avarage_fps_ += Engine::Get().fps();
|
avarage_fps_ += Engine::Get().fps();
|
||||||
++num_benchmark_samples_;
|
++num_benchmark_samples_;
|
||||||
}
|
}
|
||||||
if (benchmark_time_ > 6) {
|
if (benchmark_time_ > 5) {
|
||||||
avarage_fps_ /= num_benchmark_samples_;
|
avarage_fps_ /= num_benchmark_samples_;
|
||||||
do_benchmark_ = false;
|
do_benchmark_ = false;
|
||||||
BenchmarkResult(avarage_fps_);
|
BenchmarkResult(avarage_fps_);
|
||||||
|
@ -166,14 +166,22 @@ void Demo::Update(float delta_time) {
|
||||||
UpdateGameState(delta_time);
|
UpdateGameState(delta_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Demo::ContextLost() {
|
||||||
|
if (do_benchmark_) {
|
||||||
|
benchmark_time_ = 0;
|
||||||
|
num_benchmark_samples_ = 0;
|
||||||
|
avarage_fps_ = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Demo::LostFocus() {}
|
void Demo::LostFocus() {}
|
||||||
|
|
||||||
void Demo::GainedFocus(bool from_interstitial_ad) {
|
void Demo::GainedFocus(bool from_interstitial_ad) {
|
||||||
DLOG << __func__ << " from_interstitial_ad: " << from_interstitial_ad;
|
DLOG << __func__ << " from_interstitial_ad: " << from_interstitial_ad;
|
||||||
if (!from_interstitial_ad) {
|
if (!from_interstitial_ad) {
|
||||||
if (saved_data_.root().get(kLaunchCount, Json::Value(0)).asInt() >
|
// if (saved_data_.root().get(kLaunchCount, Json::Value(0)).asInt() >
|
||||||
kLaunchCountBeforeAd)
|
// kLaunchCountBeforeAd)
|
||||||
Engine::Get().ShowInterstitialAd();
|
// Engine::Get().ShowInterstitialAd();
|
||||||
if (state_ == kGame)
|
if (state_ == kGame)
|
||||||
EnterMenuState();
|
EnterMenuState();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Demo final : public eng::Game {
|
||||||
|
|
||||||
void Update(float delta_time) final;
|
void Update(float delta_time) final;
|
||||||
|
|
||||||
void ContextLost() final {}
|
void ContextLost() final;
|
||||||
|
|
||||||
void LostFocus() final;
|
void LostFocus() final;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ using namespace eng;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
constexpr char kVersionStr[] = "Version 1.0.3";
|
constexpr char kVersionStr[] = "Version 1.0.4";
|
||||||
|
|
||||||
constexpr char kMenuOption[Menu::kOption_Max][10] = {"continue", "start",
|
constexpr char kMenuOption[Menu::kOption_Max][10] = {"continue", "start",
|
||||||
"credits", "exit"};
|
"credits", "exit"};
|
||||||
|
@ -201,6 +201,7 @@ bool Menu::Initialize() {
|
||||||
: RendererType::kOpenGL);
|
: RendererType::kOpenGL);
|
||||||
renderer_type_.SetEnabled(
|
renderer_type_.SetEnabled(
|
||||||
(Engine::Get().GetRendererType() == RendererType::kVulkan));
|
(Engine::Get().GetRendererType() == RendererType::kVulkan));
|
||||||
|
Engine::Get().ConsumeInputEvents();
|
||||||
},
|
},
|
||||||
true, Engine::Get().GetRendererType() == RendererType::kVulkan,
|
true, Engine::Get().GetRendererType() == RendererType::kVulkan,
|
||||||
kColorFadeOut, {Vector4f{1, 1, 1, 1}, Vector4f{1, 1, 1, 1}});
|
kColorFadeOut, {Vector4f{1, 1, 1, 1}, Vector4f{1, 1, 1, 1}});
|
||||||
|
|
|
@ -396,6 +396,10 @@ std::unique_ptr<InputEvent> Engine::GetNextInputEvent() {
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::ConsumeInputEvents() {
|
||||||
|
input_queue_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::StartRecording(const Json::Value& payload) {
|
void Engine::StartRecording(const Json::Value& payload) {
|
||||||
if (!replaying_ && !recording_) {
|
if (!replaying_ && !recording_) {
|
||||||
recording_ = true;
|
recording_ = true;
|
||||||
|
|
|
@ -84,6 +84,7 @@ class Engine : public PlatformObserver {
|
||||||
void RemoveCustomShader(const std::string& asset_name);
|
void RemoveCustomShader(const std::string& asset_name);
|
||||||
|
|
||||||
std::unique_ptr<InputEvent> GetNextInputEvent();
|
std::unique_ptr<InputEvent> GetNextInputEvent();
|
||||||
|
void ConsumeInputEvents();
|
||||||
|
|
||||||
void StartRecording(const Json::Value& payload);
|
void StartRecording(const Json::Value& payload);
|
||||||
void EndRecording(const std::string file_name);
|
void EndRecording(const std::string file_name);
|
||||||
|
|
|
@ -987,13 +987,13 @@ void RendererVulkan::Shutdown() {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
LOG << "Shutting down renderer.";
|
LOG << "Shutting down renderer.";
|
||||||
DestroyAllResources();
|
|
||||||
context_lost_ = true;
|
|
||||||
|
|
||||||
quit_.store(true, std::memory_order_relaxed);
|
quit_.store(true, std::memory_order_relaxed);
|
||||||
semaphore_.release();
|
semaphore_.release();
|
||||||
setup_thread_.join();
|
setup_thread_.join();
|
||||||
|
|
||||||
|
DestroyAllResources();
|
||||||
|
context_lost_ = true;
|
||||||
|
|
||||||
vkDeviceWaitIdle(device_);
|
vkDeviceWaitIdle(device_);
|
||||||
|
|
||||||
for (size_t i = 0; i < frames_.size(); ++i) {
|
for (size_t i = 0; i < frames_.size(); ++i) {
|
||||||
|
|
Loading…
Reference in New Issue